* breakpoint.c (print_one_catch_fork, print_one_catch_vfork)
[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
EZ
30@syncodeindex vr fn
31@syncodeindex fn fn
c906108c
SS
32
33@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 34@c This is updated by GNU Press.
26829f2b 35@set EDITION Tenth
c906108c 36
87885426
FN
37@c !!set GDB edit command default editor
38@set EDITOR /bin/ex
c906108c 39
6c0e9fb3 40@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 41
c906108c 42@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 43@c manuals to an info tree.
03727ca6 44@dircategory Software development
96a2c332 45@direntry
03727ca6 46* Gdb: (gdb). The GNU debugger.
96a2c332
SS
47@end direntry
48
a67ec3f4 49@copying
28e7fd62 50Copyright @copyright{} 1988-2013 Free Software Foundation, Inc.
c906108c 51
e9c75b65 52Permission is granted to copy, distribute and/or modify this document
4f5d9f07 53under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 54any later version published by the Free Software Foundation; with the
959acfd1
EZ
55Invariant Sections being ``Free Software'' and ``Free Software Needs
56Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
57and with the Back-Cover Texts as in (a) below.
c906108c 58
b8533aec
DJ
59(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
60this GNU Manual. Buying copies from GNU Press supports the FSF in
61developing GNU and promoting software freedom.''
a67ec3f4
JM
62@end copying
63
64@ifnottex
65This file documents the @sc{gnu} debugger @value{GDBN}.
66
67This is the @value{EDITION} Edition, of @cite{Debugging with
68@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
69@ifset VERSION_PACKAGE
70@value{VERSION_PACKAGE}
71@end ifset
72Version @value{GDBVN}.
73
74@insertcopying
75@end ifnottex
c906108c
SS
76
77@titlepage
78@title Debugging with @value{GDBN}
79@subtitle The @sc{gnu} Source-Level Debugger
c906108c 80@sp 1
c906108c 81@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
82@ifset VERSION_PACKAGE
83@sp 1
84@subtitle @value{VERSION_PACKAGE}
85@end ifset
9e9c5ae7 86@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 87@page
c906108c
SS
88@tex
89{\parskip=0pt
c16158bc 90\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
91\hfill {\it Debugging with @value{GDBN}}\par
92\hfill \TeX{}info \texinfoversion\par
93}
94@end tex
53a5351d 95
c906108c 96@vskip 0pt plus 1filll
c906108c 97Published by the Free Software Foundation @*
c02a867d
EZ
9851 Franklin Street, Fifth Floor,
99Boston, MA 02110-1301, USA@*
26829f2b 100ISBN 978-0-9831592-3-0 @*
e9c75b65 101
a67ec3f4 102@insertcopying
c906108c
SS
103@end titlepage
104@page
105
6c0e9fb3 106@ifnottex
6d2ebf8b
SS
107@node Top, Summary, (dir), (dir)
108
c906108c
SS
109@top Debugging with @value{GDBN}
110
111This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
112
c16158bc
JM
113This is the @value{EDITION} Edition, for @value{GDBN}
114@ifset VERSION_PACKAGE
115@value{VERSION_PACKAGE}
116@end ifset
117Version @value{GDBVN}.
c906108c 118
28e7fd62 119Copyright (C) 1988-2013 Free Software Foundation, Inc.
6d2ebf8b 120
3fb6a982
JB
121This edition of the GDB manual is dedicated to the memory of Fred
122Fish. Fred was a long-standing contributor to GDB and to Free
123software in general. We will miss him.
124
6d2ebf8b
SS
125@menu
126* Summary:: Summary of @value{GDBN}
127* Sample Session:: A sample @value{GDBN} session
128
129* Invocation:: Getting in and out of @value{GDBN}
130* Commands:: @value{GDBN} commands
131* Running:: Running programs under @value{GDBN}
132* Stopping:: Stopping and continuing
bacec72f 133* Reverse Execution:: Running programs backward
a2311334 134* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
135* Stack:: Examining the stack
136* Source:: Examining source files
137* Data:: Examining data
edb3359d 138* Optimized Code:: Debugging optimized code
e2e0bcd1 139* Macros:: Preprocessor Macros
b37052ae 140* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 141* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
142
143* Languages:: Using @value{GDBN} with different languages
144
145* Symbols:: Examining the symbol table
146* Altering:: Altering execution
147* GDB Files:: @value{GDBN} files
148* Targets:: Specifying a debugging target
6b2f586d 149* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
150* Configurations:: Configuration-specific information
151* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 152* Extending GDB:: Extending @value{GDBN}
21c294e6 153* Interpreters:: Command Interpreters
c8f4133a 154* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 155* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 156* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 157* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 158* JIT Interface:: Using the JIT debugging interface.
d1feda86 159* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
160
161* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 162
39037522
TT
163@ifset SYSTEM_READLINE
164* Command Line Editing: (rluserman). Command Line Editing
165* Using History Interactively: (history). Using History Interactively
166@end ifset
167@ifclear SYSTEM_READLINE
6d2ebf8b
SS
168* Command Line Editing:: Command Line Editing
169* Using History Interactively:: Using History Interactively
39037522 170@end ifclear
4ceed123 171* In Memoriam:: In Memoriam
0869d01b 172* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 173* Installing GDB:: Installing GDB
eb12ee30 174* Maintenance Commands:: Maintenance Commands
e0ce93ac 175* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 176* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
177* Target Descriptions:: How targets can describe themselves to
178 @value{GDBN}
07e059b5
VP
179* Operating System Information:: Getting additional information from
180 the operating system
00bf0b85 181* Trace File Format:: GDB trace file format
90476074 182* Index Section Format:: .gdb_index section format
aab4e0ec
AC
183* Copying:: GNU General Public License says
184 how you can copy and share GDB
6826cf00 185* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
186* Concept Index:: Index of @value{GDBN} concepts
187* Command and Variable Index:: Index of @value{GDBN} commands, variables,
188 functions, and Python data types
6d2ebf8b
SS
189@end menu
190
6c0e9fb3 191@end ifnottex
c906108c 192
449f3b6c 193@contents
449f3b6c 194
6d2ebf8b 195@node Summary
c906108c
SS
196@unnumbered Summary of @value{GDBN}
197
198The purpose of a debugger such as @value{GDBN} is to allow you to see what is
199going on ``inside'' another program while it executes---or what another
200program was doing at the moment it crashed.
201
202@value{GDBN} can do four main kinds of things (plus other things in support of
203these) to help you catch bugs in the act:
204
205@itemize @bullet
206@item
207Start your program, specifying anything that might affect its behavior.
208
209@item
210Make your program stop on specified conditions.
211
212@item
213Examine what has happened, when your program has stopped.
214
215@item
216Change things in your program, so you can experiment with correcting the
217effects of one bug and go on to learn about another.
218@end itemize
219
49efadf5 220You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 221For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
222For more information, see @ref{C,,C and C++}.
223
6aecb9c2
JB
224Support for D is partial. For information on D, see
225@ref{D,,D}.
226
cce74817 227@cindex Modula-2
e632838e
AC
228Support for Modula-2 is partial. For information on Modula-2, see
229@ref{Modula-2,,Modula-2}.
c906108c 230
f4b8a18d
KW
231Support for OpenCL C is partial. For information on OpenCL C, see
232@ref{OpenCL C,,OpenCL C}.
233
cce74817
JM
234@cindex Pascal
235Debugging Pascal programs which use sets, subranges, file variables, or
236nested functions does not currently work. @value{GDBN} does not support
237entering expressions, printing values, or similar features using Pascal
238syntax.
c906108c 239
c906108c
SS
240@cindex Fortran
241@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 242it may be necessary to refer to some variables with a trailing
cce74817 243underscore.
c906108c 244
b37303ee
AF
245@value{GDBN} can be used to debug programs written in Objective-C,
246using either the Apple/NeXT or the GNU Objective-C runtime.
247
c906108c
SS
248@menu
249* Free Software:: Freely redistributable software
984359d2 250* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
251* Contributors:: Contributors to GDB
252@end menu
253
6d2ebf8b 254@node Free Software
79a6e687 255@unnumberedsec Free Software
c906108c 256
5d161b24 257@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
258General Public License
259(GPL). The GPL gives you the freedom to copy or adapt a licensed
260program---but every person getting a copy also gets with it the
261freedom to modify that copy (which means that they must get access to
262the source code), and the freedom to distribute further copies.
263Typical software companies use copyrights to limit your freedoms; the
264Free Software Foundation uses the GPL to preserve these freedoms.
265
266Fundamentally, the General Public License is a license which says that
267you have these freedoms and that you cannot take these freedoms away
268from anyone else.
269
984359d2 270@node Free Documentation
2666264b 271@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
272
273The biggest deficiency in the free software community today is not in
274the software---it is the lack of good free documentation that we can
275include with the free software. Many of our most important
276programs do not come with free reference manuals and free introductory
277texts. Documentation is an essential part of any software package;
278when an important free software package does not come with a free
279manual and a free tutorial, that is a major gap. We have many such
280gaps today.
281
282Consider Perl, for instance. The tutorial manuals that people
283normally use are non-free. How did this come about? Because the
284authors of those manuals published them with restrictive terms---no
285copying, no modification, source files not available---which exclude
286them from the free software world.
287
288That wasn't the first time this sort of thing happened, and it was far
289from the last. Many times we have heard a GNU user eagerly describe a
290manual that he is writing, his intended contribution to the community,
291only to learn that he had ruined everything by signing a publication
292contract to make it non-free.
293
294Free documentation, like free software, is a matter of freedom, not
295price. The problem with the non-free manual is not that publishers
296charge a price for printed copies---that in itself is fine. (The Free
297Software Foundation sells printed copies of manuals, too.) The
298problem is the restrictions on the use of the manual. Free manuals
299are available in source code form, and give you permission to copy and
300modify. Non-free manuals do not allow this.
301
302The criteria of freedom for a free manual are roughly the same as for
303free software. Redistribution (including the normal kinds of
304commercial redistribution) must be permitted, so that the manual can
305accompany every copy of the program, both on-line and on paper.
306
307Permission for modification of the technical content is crucial too.
308When people modify the software, adding or changing features, if they
309are conscientious they will change the manual too---so they can
310provide accurate and clear documentation for the modified program. A
311manual that leaves you no choice but to write a new manual to document
312a changed version of the program is not really available to our
313community.
314
315Some kinds of limits on the way modification is handled are
316acceptable. For example, requirements to preserve the original
317author's copyright notice, the distribution terms, or the list of
318authors, are ok. It is also no problem to require modified versions
319to include notice that they were modified. Even entire sections that
320may not be deleted or changed are acceptable, as long as they deal
321with nontechnical topics (like this one). These kinds of restrictions
322are acceptable because they don't obstruct the community's normal use
323of the manual.
324
325However, it must be possible to modify all the @emph{technical}
326content of the manual, and then distribute the result in all the usual
327media, through all the usual channels. Otherwise, the restrictions
328obstruct the use of the manual, it is not free, and we need another
329manual to replace it.
330
331Please spread the word about this issue. Our community continues to
332lose manuals to proprietary publishing. If we spread the word that
333free software needs free reference manuals and free tutorials, perhaps
334the next person who wants to contribute by writing documentation will
335realize, before it is too late, that only free manuals contribute to
336the free software community.
337
338If you are writing documentation, please insist on publishing it under
339the GNU Free Documentation License or another free documentation
340license. Remember that this decision requires your approval---you
341don't have to let the publisher decide. Some commercial publishers
342will use a free license if you insist, but they will not propose the
343option; it is up to you to raise the issue and say firmly that this is
344what you want. If the publisher you are dealing with refuses, please
345try other publishers. If you're not sure whether a proposed license
42584a72 346is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
347
348You can encourage commercial publishers to sell more free, copylefted
349manuals and tutorials by buying them, and particularly by buying
350copies from the publishers that paid for their writing or for major
351improvements. Meanwhile, try to avoid buying non-free documentation
352at all. Check the distribution terms of a manual before you buy it,
353and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
354Check the history of the book, and try to reward the publishers that
355have paid or pay the authors to work on it.
959acfd1
EZ
356
357The Free Software Foundation maintains a list of free documentation
358published by other publishers, at
359@url{http://www.fsf.org/doc/other-free-books.html}.
360
6d2ebf8b 361@node Contributors
96a2c332
SS
362@unnumberedsec Contributors to @value{GDBN}
363
364Richard Stallman was the original author of @value{GDBN}, and of many
365other @sc{gnu} programs. Many others have contributed to its
366development. This section attempts to credit major contributors. One
367of the virtues of free software is that everyone is free to contribute
368to it; with regret, we cannot actually acknowledge everyone here. The
369file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
370blow-by-blow account.
371
372Changes much prior to version 2.0 are lost in the mists of time.
373
374@quotation
375@emph{Plea:} Additions to this section are particularly welcome. If you
376or your friends (or enemies, to be evenhanded) have been unfairly
377omitted from this list, we would like to add your names!
378@end quotation
379
380So that they may not regard their many labors as thankless, we
381particularly thank those who shepherded @value{GDBN} through major
382releases:
7ba3cf9c 383Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
384Jim Blandy (release 4.18);
385Jason Molenda (release 4.17);
386Stan Shebs (release 4.14);
387Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
388Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
389John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
390Jim Kingdon (releases 3.5, 3.4, and 3.3);
391and Randy Smith (releases 3.2, 3.1, and 3.0).
392
393Richard Stallman, assisted at various times by Peter TerMaat, Chris
394Hanson, and Richard Mlynarik, handled releases through 2.8.
395
b37052ae
EZ
396Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
397in @value{GDBN}, with significant additional contributions from Per
398Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
399demangler. Early work on C@t{++} was by Peter TerMaat (who also did
400much general update work leading to release 3.0).
c906108c 401
b37052ae 402@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
403object-file formats; BFD was a joint project of David V.
404Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
405
406David Johnson wrote the original COFF support; Pace Willison did
407the original support for encapsulated COFF.
408
0179ffac 409Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
410
411Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
412Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
413support.
414Jean-Daniel Fekete contributed Sun 386i support.
415Chris Hanson improved the HP9000 support.
416Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
417David Johnson contributed Encore Umax support.
418Jyrki Kuoppala contributed Altos 3068 support.
419Jeff Law contributed HP PA and SOM support.
420Keith Packard contributed NS32K support.
421Doug Rabson contributed Acorn Risc Machine support.
422Bob Rusk contributed Harris Nighthawk CX-UX support.
423Chris Smith contributed Convex support (and Fortran debugging).
424Jonathan Stone contributed Pyramid support.
425Michael Tiemann contributed SPARC support.
426Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
427Pace Willison contributed Intel 386 support.
428Jay Vosburgh contributed Symmetry support.
a37295f9 429Marko Mlinar contributed OpenRISC 1000 support.
c906108c 430
1104b9e7 431Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
432
433Rich Schaefer and Peter Schauer helped with support of SunOS shared
434libraries.
435
436Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
437about several machine instruction sets.
438
439Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
440remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
441contributed remote debugging modules for the i960, VxWorks, A29K UDI,
442and RDI targets, respectively.
443
444Brian Fox is the author of the readline libraries providing
445command-line editing and command history.
446
7a292a7a
SS
447Andrew Beers of SUNY Buffalo wrote the language-switching code, the
448Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 449
5d161b24 450Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 451He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 452symbols.
c906108c 453
f24c5e49
KI
454Hitachi America (now Renesas America), Ltd. sponsored the support for
455H8/300, H8/500, and Super-H processors.
c906108c
SS
456
457NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
458
f24c5e49
KI
459Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
460processors.
c906108c
SS
461
462Toshiba sponsored the support for the TX39 Mips processor.
463
464Matsushita sponsored the support for the MN10200 and MN10300 processors.
465
96a2c332 466Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
467
468Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
469watchpoints.
470
471Michael Snyder added support for tracepoints.
472
473Stu Grossman wrote gdbserver.
474
475Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 476nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
477
478The following people at the Hewlett-Packard Company contributed
479support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 480(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
481compiler, and the Text User Interface (nee Terminal User Interface):
482Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
483Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
484provided HP-specific information in this manual.
c906108c 485
b37052ae
EZ
486DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
487Robert Hoehne made significant contributions to the DJGPP port.
488
96a2c332
SS
489Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
490development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
491fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
492Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
493Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
494Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
495Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
496addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
497JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
498Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
499Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
500Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
501Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
502Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
503Zuhn have made contributions both large and small.
c906108c 504
ffed4509
AC
505Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
506Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
507
e2e0bcd1
JB
508Jim Blandy added support for preprocessor macros, while working for Red
509Hat.
c906108c 510
a9967aef
AC
511Andrew Cagney designed @value{GDBN}'s architecture vector. Many
512people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
513Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
514Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
515Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
516with the migration of old architectures to this new framework.
517
c5e30d01
AC
518Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
519unwinder framework, this consisting of a fresh new design featuring
520frame IDs, independent frame sniffers, and the sentinel frame. Mark
521Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
522libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 523trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
524complete rewrite of the architecture's frame code, were carried out by
525Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
526Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
527Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
528Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
529Weigand.
530
ca3bf3bd
DJ
531Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
532Tensilica, Inc.@: contributed support for Xtensa processors. Others
533who have worked on the Xtensa port of @value{GDBN} in the past include
534Steve Tjiang, John Newlin, and Scott Foehner.
535
08be9d71
ME
536Michael Eager and staff of Xilinx, Inc., contributed support for the
537Xilinx MicroBlaze architecture.
538
6d2ebf8b 539@node Sample Session
c906108c
SS
540@chapter A Sample @value{GDBN} Session
541
542You can use this manual at your leisure to read all about @value{GDBN}.
543However, a handful of commands are enough to get started using the
544debugger. This chapter illustrates those commands.
545
546@iftex
547In this sample session, we emphasize user input like this: @b{input},
548to make it easier to pick out from the surrounding output.
549@end iftex
550
551@c FIXME: this example may not be appropriate for some configs, where
552@c FIXME...primary interest is in remote use.
553
554One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
555processor) exhibits the following bug: sometimes, when we change its
556quote strings from the default, the commands used to capture one macro
557definition within another stop working. In the following short @code{m4}
558session, we define a macro @code{foo} which expands to @code{0000}; we
559then use the @code{m4} built-in @code{defn} to define @code{bar} as the
560same thing. However, when we change the open quote string to
561@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
562procedure fails to define a new synonym @code{baz}:
563
564@smallexample
565$ @b{cd gnu/m4}
566$ @b{./m4}
567@b{define(foo,0000)}
568
569@b{foo}
5700000
571@b{define(bar,defn(`foo'))}
572
573@b{bar}
5740000
575@b{changequote(<QUOTE>,<UNQUOTE>)}
576
577@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
578@b{baz}
c8aa23ab 579@b{Ctrl-d}
c906108c
SS
580m4: End of input: 0: fatal error: EOF in string
581@end smallexample
582
583@noindent
584Let us use @value{GDBN} to try to see what is going on.
585
c906108c
SS
586@smallexample
587$ @b{@value{GDBP} m4}
588@c FIXME: this falsifies the exact text played out, to permit smallbook
589@c FIXME... format to come out better.
590@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 591 of it under certain conditions; type "show copying" to see
c906108c 592 the conditions.
5d161b24 593There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
594 for details.
595
596@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
597(@value{GDBP})
598@end smallexample
c906108c
SS
599
600@noindent
601@value{GDBN} reads only enough symbol data to know where to find the
602rest when needed; as a result, the first prompt comes up very quickly.
603We now tell @value{GDBN} to use a narrower display width than usual, so
604that examples fit in this manual.
605
606@smallexample
607(@value{GDBP}) @b{set width 70}
608@end smallexample
609
610@noindent
611We need to see how the @code{m4} built-in @code{changequote} works.
612Having looked at the source, we know the relevant subroutine is
613@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
614@code{break} command.
615
616@smallexample
617(@value{GDBP}) @b{break m4_changequote}
618Breakpoint 1 at 0x62f4: file builtin.c, line 879.
619@end smallexample
620
621@noindent
622Using the @code{run} command, we start @code{m4} running under @value{GDBN}
623control; as long as control does not reach the @code{m4_changequote}
624subroutine, the program runs as usual:
625
626@smallexample
627(@value{GDBP}) @b{run}
628Starting program: /work/Editorial/gdb/gnu/m4/m4
629@b{define(foo,0000)}
630
631@b{foo}
6320000
633@end smallexample
634
635@noindent
636To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
637suspends execution of @code{m4}, displaying information about the
638context where it stops.
639
640@smallexample
641@b{changequote(<QUOTE>,<UNQUOTE>)}
642
5d161b24 643Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
644 at builtin.c:879
645879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
646@end smallexample
647
648@noindent
649Now we use the command @code{n} (@code{next}) to advance execution to
650the next line of the current function.
651
652@smallexample
653(@value{GDBP}) @b{n}
654882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
655 : nil,
656@end smallexample
657
658@noindent
659@code{set_quotes} looks like a promising subroutine. We can go into it
660by using the command @code{s} (@code{step}) instead of @code{next}.
661@code{step} goes to the next line to be executed in @emph{any}
662subroutine, so it steps into @code{set_quotes}.
663
664@smallexample
665(@value{GDBP}) @b{s}
666set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
667 at input.c:530
668530 if (lquote != def_lquote)
669@end smallexample
670
671@noindent
672The display that shows the subroutine where @code{m4} is now
673suspended (and its arguments) is called a stack frame display. It
674shows a summary of the stack. We can use the @code{backtrace}
675command (which can also be spelled @code{bt}), to see where we are
676in the stack as a whole: the @code{backtrace} command displays a
677stack frame for each active subroutine.
678
679@smallexample
680(@value{GDBP}) @b{bt}
681#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
682 at input.c:530
5d161b24 683#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
684 at builtin.c:882
685#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
686#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
687 at macro.c:71
688#4 0x79dc in expand_input () at macro.c:40
689#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
690@end smallexample
691
692@noindent
693We step through a few more lines to see what happens. The first two
694times, we can use @samp{s}; the next two times we use @code{n} to avoid
695falling into the @code{xstrdup} subroutine.
696
697@smallexample
698(@value{GDBP}) @b{s}
6990x3b5c 532 if (rquote != def_rquote)
700(@value{GDBP}) @b{s}
7010x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
702def_lquote : xstrdup(lq);
703(@value{GDBP}) @b{n}
704536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
705 : xstrdup(rq);
706(@value{GDBP}) @b{n}
707538 len_lquote = strlen(rquote);
708@end smallexample
709
710@noindent
711The last line displayed looks a little odd; we can examine the variables
712@code{lquote} and @code{rquote} to see if they are in fact the new left
713and right quotes we specified. We use the command @code{p}
714(@code{print}) to see their values.
715
716@smallexample
717(@value{GDBP}) @b{p lquote}
718$1 = 0x35d40 "<QUOTE>"
719(@value{GDBP}) @b{p rquote}
720$2 = 0x35d50 "<UNQUOTE>"
721@end smallexample
722
723@noindent
724@code{lquote} and @code{rquote} are indeed the new left and right quotes.
725To look at some context, we can display ten lines of source
726surrounding the current line with the @code{l} (@code{list}) command.
727
728@smallexample
729(@value{GDBP}) @b{l}
730533 xfree(rquote);
731534
732535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
733 : xstrdup (lq);
734536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
735 : xstrdup (rq);
736537
737538 len_lquote = strlen(rquote);
738539 len_rquote = strlen(lquote);
739540 @}
740541
741542 void
742@end smallexample
743
744@noindent
745Let us step past the two lines that set @code{len_lquote} and
746@code{len_rquote}, and then examine the values of those variables.
747
748@smallexample
749(@value{GDBP}) @b{n}
750539 len_rquote = strlen(lquote);
751(@value{GDBP}) @b{n}
752540 @}
753(@value{GDBP}) @b{p len_lquote}
754$3 = 9
755(@value{GDBP}) @b{p len_rquote}
756$4 = 7
757@end smallexample
758
759@noindent
760That certainly looks wrong, assuming @code{len_lquote} and
761@code{len_rquote} are meant to be the lengths of @code{lquote} and
762@code{rquote} respectively. We can set them to better values using
763the @code{p} command, since it can print the value of
764any expression---and that expression can include subroutine calls and
765assignments.
766
767@smallexample
768(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
769$5 = 7
770(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
771$6 = 9
772@end smallexample
773
774@noindent
775Is that enough to fix the problem of using the new quotes with the
776@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
777executing with the @code{c} (@code{continue}) command, and then try the
778example that caused trouble initially:
779
780@smallexample
781(@value{GDBP}) @b{c}
782Continuing.
783
784@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
785
786baz
7870000
788@end smallexample
789
790@noindent
791Success! The new quotes now work just as well as the default ones. The
792problem seems to have been just the two typos defining the wrong
793lengths. We allow @code{m4} exit by giving it an EOF as input:
794
795@smallexample
c8aa23ab 796@b{Ctrl-d}
c906108c
SS
797Program exited normally.
798@end smallexample
799
800@noindent
801The message @samp{Program exited normally.} is from @value{GDBN}; it
802indicates @code{m4} has finished executing. We can end our @value{GDBN}
803session with the @value{GDBN} @code{quit} command.
804
805@smallexample
806(@value{GDBP}) @b{quit}
807@end smallexample
c906108c 808
6d2ebf8b 809@node Invocation
c906108c
SS
810@chapter Getting In and Out of @value{GDBN}
811
812This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 813The essentials are:
c906108c 814@itemize @bullet
5d161b24 815@item
53a5351d 816type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 817@item
c8aa23ab 818type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
819@end itemize
820
821@menu
822* Invoking GDB:: How to start @value{GDBN}
823* Quitting GDB:: How to quit @value{GDBN}
824* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 825* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
826@end menu
827
6d2ebf8b 828@node Invoking GDB
c906108c
SS
829@section Invoking @value{GDBN}
830
c906108c
SS
831Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
832@value{GDBN} reads commands from the terminal until you tell it to exit.
833
834You can also run @code{@value{GDBP}} with a variety of arguments and options,
835to specify more of your debugging environment at the outset.
836
c906108c
SS
837The command-line options described here are designed
838to cover a variety of situations; in some environments, some of these
5d161b24 839options may effectively be unavailable.
c906108c
SS
840
841The most usual way to start @value{GDBN} is with one argument,
842specifying an executable program:
843
474c8240 844@smallexample
c906108c 845@value{GDBP} @var{program}
474c8240 846@end smallexample
c906108c 847
c906108c
SS
848@noindent
849You can also start with both an executable program and a core file
850specified:
851
474c8240 852@smallexample
c906108c 853@value{GDBP} @var{program} @var{core}
474c8240 854@end smallexample
c906108c
SS
855
856You can, instead, specify a process ID as a second argument, if you want
857to debug a running process:
858
474c8240 859@smallexample
c906108c 860@value{GDBP} @var{program} 1234
474c8240 861@end smallexample
c906108c
SS
862
863@noindent
864would attach @value{GDBN} to process @code{1234} (unless you also have a file
865named @file{1234}; @value{GDBN} does check for a core file first).
866
c906108c 867Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
868complete operating system; when you use @value{GDBN} as a remote
869debugger attached to a bare board, there may not be any notion of
870``process'', and there is often no way to get a core dump. @value{GDBN}
871will warn you if it is unable to attach or to read core dumps.
c906108c 872
aa26fa3a
TT
873You can optionally have @code{@value{GDBP}} pass any arguments after the
874executable file to the inferior using @code{--args}. This option stops
875option processing.
474c8240 876@smallexample
3f94c067 877@value{GDBP} --args gcc -O2 -c foo.c
474c8240 878@end smallexample
aa26fa3a
TT
879This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
880@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
881
96a2c332 882You can run @code{@value{GDBP}} without printing the front material, which describes
c906108c
SS
883@value{GDBN}'s non-warranty, by specifying @code{-silent}:
884
885@smallexample
886@value{GDBP} -silent
887@end smallexample
888
889@noindent
890You can further control how @value{GDBN} starts up by using command-line
891options. @value{GDBN} itself can remind you of the options available.
892
893@noindent
894Type
895
474c8240 896@smallexample
c906108c 897@value{GDBP} -help
474c8240 898@end smallexample
c906108c
SS
899
900@noindent
901to display all available options and briefly describe their use
902(@samp{@value{GDBP} -h} is a shorter equivalent).
903
904All options and command line arguments you give are processed
905in sequential order. The order makes a difference when the
906@samp{-x} option is used.
907
908
909@menu
c906108c
SS
910* File Options:: Choosing files
911* Mode Options:: Choosing modes
6fc08d32 912* Startup:: What @value{GDBN} does during startup
c906108c
SS
913@end menu
914
6d2ebf8b 915@node File Options
79a6e687 916@subsection Choosing Files
c906108c 917
2df3850c 918When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
919specifying an executable file and core file (or process ID). This is
920the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 921@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
922first argument that does not have an associated option flag as
923equivalent to the @samp{-se} option followed by that argument; and the
924second argument that does not have an associated option flag, if any, as
925equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
926If the second argument begins with a decimal digit, @value{GDBN} will
927first attempt to attach to it as a process, and if that fails, attempt
928to open it as a corefile. If you have a corefile whose name begins with
b383017d 929a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 930prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
931
932If @value{GDBN} has not been configured to included core file support,
933such as for most embedded targets, then it will complain about a second
934argument and ignore it.
c906108c
SS
935
936Many options have both long and short forms; both are shown in the
937following list. @value{GDBN} also recognizes the long forms if you truncate
938them, so long as enough of the option is present to be unambiguous.
939(If you prefer, you can flag option arguments with @samp{--} rather
940than @samp{-}, though we illustrate the more usual convention.)
941
d700128c
EZ
942@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
943@c way, both those who look for -foo and --foo in the index, will find
944@c it.
945
c906108c
SS
946@table @code
947@item -symbols @var{file}
948@itemx -s @var{file}
d700128c
EZ
949@cindex @code{--symbols}
950@cindex @code{-s}
c906108c
SS
951Read symbol table from file @var{file}.
952
953@item -exec @var{file}
954@itemx -e @var{file}
d700128c
EZ
955@cindex @code{--exec}
956@cindex @code{-e}
7a292a7a
SS
957Use file @var{file} as the executable file to execute when appropriate,
958and for examining pure data in conjunction with a core dump.
c906108c
SS
959
960@item -se @var{file}
d700128c 961@cindex @code{--se}
c906108c
SS
962Read symbol table from file @var{file} and use it as the executable
963file.
964
c906108c
SS
965@item -core @var{file}
966@itemx -c @var{file}
d700128c
EZ
967@cindex @code{--core}
968@cindex @code{-c}
b383017d 969Use file @var{file} as a core dump to examine.
c906108c 970
19837790
MS
971@item -pid @var{number}
972@itemx -p @var{number}
973@cindex @code{--pid}
974@cindex @code{-p}
975Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
976
977@item -command @var{file}
978@itemx -x @var{file}
d700128c
EZ
979@cindex @code{--command}
980@cindex @code{-x}
95433b34
JB
981Execute commands from file @var{file}. The contents of this file is
982evaluated exactly as the @code{source} command would.
8150ff9c 983@xref{Command Files,, Command files}.
c906108c 984
8a5a3c82
AS
985@item -eval-command @var{command}
986@itemx -ex @var{command}
987@cindex @code{--eval-command}
988@cindex @code{-ex}
989Execute a single @value{GDBN} command.
990
991This option may be used multiple times to call multiple commands. It may
992also be interleaved with @samp{-command} as required.
993
994@smallexample
995@value{GDBP} -ex 'target sim' -ex 'load' \
996 -x setbreakpoints -ex 'run' a.out
997@end smallexample
998
8320cc4f
JK
999@item -init-command @var{file}
1000@itemx -ix @var{file}
1001@cindex @code{--init-command}
1002@cindex @code{-ix}
2d7b58e8
JK
1003Execute commands from file @var{file} before loading the inferior (but
1004after loading gdbinit files).
8320cc4f
JK
1005@xref{Startup}.
1006
1007@item -init-eval-command @var{command}
1008@itemx -iex @var{command}
1009@cindex @code{--init-eval-command}
1010@cindex @code{-iex}
2d7b58e8
JK
1011Execute a single @value{GDBN} command before loading the inferior (but
1012after loading gdbinit files).
8320cc4f
JK
1013@xref{Startup}.
1014
c906108c
SS
1015@item -directory @var{directory}
1016@itemx -d @var{directory}
d700128c
EZ
1017@cindex @code{--directory}
1018@cindex @code{-d}
4b505b12 1019Add @var{directory} to the path to search for source and script files.
c906108c 1020
c906108c
SS
1021@item -r
1022@itemx -readnow
d700128c
EZ
1023@cindex @code{--readnow}
1024@cindex @code{-r}
c906108c
SS
1025Read each symbol file's entire symbol table immediately, rather than
1026the default, which is to read it incrementally as it is needed.
1027This makes startup slower, but makes future operations faster.
53a5351d 1028
c906108c
SS
1029@end table
1030
6d2ebf8b 1031@node Mode Options
79a6e687 1032@subsection Choosing Modes
c906108c
SS
1033
1034You can run @value{GDBN} in various alternative modes---for example, in
1035batch mode or quiet mode.
1036
1037@table @code
bf88dd68 1038@anchor{-nx}
c906108c
SS
1039@item -nx
1040@itemx -n
d700128c
EZ
1041@cindex @code{--nx}
1042@cindex @code{-n}
07540c15
DE
1043Do not execute commands found in any initialization file.
1044There are three init files, loaded in the following order:
1045
1046@table @code
1047@item @file{system.gdbinit}
1048This is the system-wide init file.
1049Its location is specified with the @code{--with-system-gdbinit}
1050configure option (@pxref{System-wide configuration}).
1051It is loaded first when @value{GDBN} starts, before command line options
1052have been processed.
1053@item @file{~/.gdbinit}
1054This is the init file in your home directory.
1055It is loaded next, after @file{system.gdbinit}, and before
1056command options have been processed.
1057@item @file{./.gdbinit}
1058This is the init file in the current directory.
1059It is loaded last, after command line options other than @code{-x} and
1060@code{-ex} have been processed. Command line options @code{-x} and
1061@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1062@end table
1063
1064For further documentation on startup processing, @xref{Startup}.
1065For documentation on how to write command files,
1066@xref{Command Files,,Command Files}.
1067
1068@anchor{-nh}
1069@item -nh
1070@cindex @code{--nh}
1071Do not execute commands found in @file{~/.gdbinit}, the init file
1072in your home directory.
1073@xref{Startup}.
c906108c
SS
1074
1075@item -quiet
d700128c 1076@itemx -silent
c906108c 1077@itemx -q
d700128c
EZ
1078@cindex @code{--quiet}
1079@cindex @code{--silent}
1080@cindex @code{-q}
c906108c
SS
1081``Quiet''. Do not print the introductory and copyright messages. These
1082messages are also suppressed in batch mode.
1083
1084@item -batch
d700128c 1085@cindex @code{--batch}
c906108c
SS
1086Run in batch mode. Exit with status @code{0} after processing all the
1087command files specified with @samp{-x} (and all commands from
1088initialization files, if not inhibited with @samp{-n}). Exit with
1089nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1090in the command files. Batch mode also disables pagination, sets unlimited
1091terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1092off} were in effect (@pxref{Messages/Warnings}).
c906108c 1093
2df3850c
JM
1094Batch mode may be useful for running @value{GDBN} as a filter, for
1095example to download and run a program on another computer; in order to
1096make this more useful, the message
c906108c 1097
474c8240 1098@smallexample
c906108c 1099Program exited normally.
474c8240 1100@end smallexample
c906108c
SS
1101
1102@noindent
2df3850c
JM
1103(which is ordinarily issued whenever a program running under
1104@value{GDBN} control terminates) is not issued when running in batch
1105mode.
1106
1a088d06
AS
1107@item -batch-silent
1108@cindex @code{--batch-silent}
1109Run in batch mode exactly like @samp{-batch}, but totally silently. All
1110@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1111unaffected). This is much quieter than @samp{-silent} and would be useless
1112for an interactive session.
1113
1114This is particularly useful when using targets that give @samp{Loading section}
1115messages, for example.
1116
1117Note that targets that give their output via @value{GDBN}, as opposed to
1118writing directly to @code{stdout}, will also be made silent.
1119
4b0ad762
AS
1120@item -return-child-result
1121@cindex @code{--return-child-result}
1122The return code from @value{GDBN} will be the return code from the child
1123process (the process being debugged), with the following exceptions:
1124
1125@itemize @bullet
1126@item
1127@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1128internal error. In this case the exit code is the same as it would have been
1129without @samp{-return-child-result}.
1130@item
1131The user quits with an explicit value. E.g., @samp{quit 1}.
1132@item
1133The child process never runs, or is not allowed to terminate, in which case
1134the exit code will be -1.
1135@end itemize
1136
1137This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1138when @value{GDBN} is being used as a remote program loader or simulator
1139interface.
1140
2df3850c
JM
1141@item -nowindows
1142@itemx -nw
d700128c
EZ
1143@cindex @code{--nowindows}
1144@cindex @code{-nw}
2df3850c 1145``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1146(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1147interface. If no GUI is available, this option has no effect.
1148
1149@item -windows
1150@itemx -w
d700128c
EZ
1151@cindex @code{--windows}
1152@cindex @code{-w}
2df3850c
JM
1153If @value{GDBN} includes a GUI, then this option requires it to be
1154used if possible.
c906108c
SS
1155
1156@item -cd @var{directory}
d700128c 1157@cindex @code{--cd}
c906108c
SS
1158Run @value{GDBN} using @var{directory} as its working directory,
1159instead of the current directory.
1160
aae1c79a
DE
1161@item -data-directory @var{directory}
1162@cindex @code{--data-directory}
1163Run @value{GDBN} using @var{directory} as its data directory.
1164The data directory is where @value{GDBN} searches for its
1165auxiliary files. @xref{Data Files}.
1166
c906108c
SS
1167@item -fullname
1168@itemx -f
d700128c
EZ
1169@cindex @code{--fullname}
1170@cindex @code{-f}
7a292a7a
SS
1171@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1172subprocess. It tells @value{GDBN} to output the full file name and line
1173number in a standard, recognizable fashion each time a stack frame is
1174displayed (which includes each time your program stops). This
1175recognizable format looks like two @samp{\032} characters, followed by
1176the file name, line number and character position separated by colons,
1177and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1178@samp{\032} characters as a signal to display the source code for the
1179frame.
c906108c 1180
d700128c
EZ
1181@item -annotate @var{level}
1182@cindex @code{--annotate}
1183This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1184effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1185(@pxref{Annotations}). The annotation @var{level} controls how much
1186information @value{GDBN} prints together with its prompt, values of
1187expressions, source lines, and other types of output. Level 0 is the
1188normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1189@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1190that control @value{GDBN}, and level 2 has been deprecated.
1191
265eeb58 1192The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1193(@pxref{GDB/MI}).
d700128c 1194
aa26fa3a
TT
1195@item --args
1196@cindex @code{--args}
1197Change interpretation of command line so that arguments following the
1198executable file are passed as command line arguments to the inferior.
1199This option stops option processing.
1200
2df3850c
JM
1201@item -baud @var{bps}
1202@itemx -b @var{bps}
d700128c
EZ
1203@cindex @code{--baud}
1204@cindex @code{-b}
c906108c
SS
1205Set the line speed (baud rate or bits per second) of any serial
1206interface used by @value{GDBN} for remote debugging.
c906108c 1207
f47b1503
AS
1208@item -l @var{timeout}
1209@cindex @code{-l}
1210Set the timeout (in seconds) of any communication used by @value{GDBN}
1211for remote debugging.
1212
c906108c 1213@item -tty @var{device}
d700128c
EZ
1214@itemx -t @var{device}
1215@cindex @code{--tty}
1216@cindex @code{-t}
c906108c
SS
1217Run using @var{device} for your program's standard input and output.
1218@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1219
53a5351d 1220@c resolve the situation of these eventually
c4555f82
SC
1221@item -tui
1222@cindex @code{--tui}
d0d5df6f
AC
1223Activate the @dfn{Text User Interface} when starting. The Text User
1224Interface manages several text windows on the terminal, showing
1225source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1226(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1227option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1228Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d
JM
1229
1230@c @item -xdb
d700128c 1231@c @cindex @code{--xdb}
53a5351d
JM
1232@c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1233@c For information, see the file @file{xdb_trans.html}, which is usually
1234@c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1235@c systems.
1236
d700128c
EZ
1237@item -interpreter @var{interp}
1238@cindex @code{--interpreter}
1239Use the interpreter @var{interp} for interface with the controlling
1240program or device. This option is meant to be set by programs which
94bbb2c0 1241communicate with @value{GDBN} using it as a back end.
21c294e6 1242@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1243
da0f9dcd 1244@samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
2fcf52f0 1245@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
6b5e8c01 1246The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
6c74ac8b
AC
1247previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1248selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1249@sc{gdb/mi} interfaces are no longer supported.
d700128c
EZ
1250
1251@item -write
1252@cindex @code{--write}
1253Open the executable and core files for both reading and writing. This
1254is equivalent to the @samp{set write on} command inside @value{GDBN}
1255(@pxref{Patching}).
1256
1257@item -statistics
1258@cindex @code{--statistics}
1259This option causes @value{GDBN} to print statistics about time and
1260memory usage after it completes each command and returns to the prompt.
1261
1262@item -version
1263@cindex @code{--version}
1264This option causes @value{GDBN} to print its version number and
1265no-warranty blurb, and exit.
1266
c906108c
SS
1267@end table
1268
6fc08d32 1269@node Startup
79a6e687 1270@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1271@cindex @value{GDBN} startup
1272
1273Here's the description of what @value{GDBN} does during session startup:
1274
1275@enumerate
1276@item
1277Sets up the command interpreter as specified by the command line
1278(@pxref{Mode Options, interpreter}).
1279
1280@item
1281@cindex init file
098b41a6
JG
1282Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1283used when building @value{GDBN}; @pxref{System-wide configuration,
1284 ,System-wide configuration and settings}) and executes all the commands in
1285that file.
1286
bf88dd68 1287@anchor{Home Directory Init File}
098b41a6
JG
1288@item
1289Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1290DOS/Windows systems, the home directory is the one pointed to by the
1291@code{HOME} environment variable.} and executes all the commands in
1292that file.
1293
2d7b58e8
JK
1294@anchor{Option -init-eval-command}
1295@item
1296Executes commands and command files specified by the @samp{-iex} and
1297@samp{-ix} options in their specified order. Usually you should use the
1298@samp{-ex} and @samp{-x} options instead, but this way you can apply
1299settings before @value{GDBN} init files get executed and before inferior
1300gets loaded.
1301
6fc08d32
EZ
1302@item
1303Processes command line options and operands.
1304
bf88dd68 1305@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1306@item
1307Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1308working directory as long as @samp{set auto-load local-gdbinit} is set to
1309@samp{on} (@pxref{Init File in the Current Directory}).
1310This is only done if the current directory is
119b882a
EZ
1311different from your home directory. Thus, you can have more than one
1312init file, one generic in your home directory, and another, specific
1313to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1314@value{GDBN}.
1315
a86caf66
DE
1316@item
1317If the command line specified a program to debug, or a process to
1318attach to, or a core file, @value{GDBN} loads any auto-loaded
1319scripts provided for the program or for its loaded shared libraries.
1320@xref{Auto-loading}.
1321
1322If you wish to disable the auto-loading during startup,
1323you must do something like the following:
1324
1325@smallexample
bf88dd68 1326$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1327@end smallexample
1328
8320cc4f
JK
1329Option @samp{-ex} does not work because the auto-loading is then turned
1330off too late.
a86caf66 1331
6fc08d32 1332@item
6fe37d23
JK
1333Executes commands and command files specified by the @samp{-ex} and
1334@samp{-x} options in their specified order. @xref{Command Files}, for
1335more details about @value{GDBN} command files.
6fc08d32
EZ
1336
1337@item
1338Reads the command history recorded in the @dfn{history file}.
d620b259 1339@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1340files where @value{GDBN} records it.
1341@end enumerate
1342
1343Init files use the same syntax as @dfn{command files} (@pxref{Command
1344Files}) and are processed by @value{GDBN} in the same way. The init
1345file in your home directory can set options (such as @samp{set
1346complaints}) that affect subsequent processing of command line options
1347and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1348option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1349
098b41a6
JG
1350To display the list of init files loaded by gdb at startup, you
1351can use @kbd{gdb --help}.
1352
6fc08d32
EZ
1353@cindex init file name
1354@cindex @file{.gdbinit}
119b882a 1355@cindex @file{gdb.ini}
8807d78b 1356The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1357The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1358the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1359port of @value{GDBN} uses the standard name, but if it finds a
1360@file{gdb.ini} file in your home directory, it warns you about that
1361and suggests to rename the file to the standard name.
119b882a 1362
6fc08d32 1363
6d2ebf8b 1364@node Quitting GDB
c906108c
SS
1365@section Quitting @value{GDBN}
1366@cindex exiting @value{GDBN}
1367@cindex leaving @value{GDBN}
1368
1369@table @code
1370@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1371@kindex q @r{(@code{quit})}
96a2c332
SS
1372@item quit @r{[}@var{expression}@r{]}
1373@itemx q
1374To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1375@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1376do not supply @var{expression}, @value{GDBN} will terminate normally;
1377otherwise it will terminate using the result of @var{expression} as the
1378error code.
c906108c
SS
1379@end table
1380
1381@cindex interrupt
c8aa23ab 1382An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1383terminates the action of any @value{GDBN} command that is in progress and
1384returns to @value{GDBN} command level. It is safe to type the interrupt
1385character at any time because @value{GDBN} does not allow it to take effect
1386until a time when it is safe.
1387
c906108c
SS
1388If you have been using @value{GDBN} to control an attached process or
1389device, you can release it with the @code{detach} command
79a6e687 1390(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1391
6d2ebf8b 1392@node Shell Commands
79a6e687 1393@section Shell Commands
c906108c
SS
1394
1395If you need to execute occasional shell commands during your
1396debugging session, there is no need to leave or suspend @value{GDBN}; you can
1397just use the @code{shell} command.
1398
1399@table @code
1400@kindex shell
ed59ded5 1401@kindex !
c906108c 1402@cindex shell escape
ed59ded5
DE
1403@item shell @var{command-string}
1404@itemx !@var{command-string}
1405Invoke a standard shell to execute @var{command-string}.
1406Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1407If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1408shell to run. Otherwise @value{GDBN} uses the default shell
1409(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1410@end table
1411
1412The utility @code{make} is often needed in development environments.
1413You do not have to use the @code{shell} command for this purpose in
1414@value{GDBN}:
1415
1416@table @code
1417@kindex make
1418@cindex calling make
1419@item make @var{make-args}
1420Execute the @code{make} program with the specified
1421arguments. This is equivalent to @samp{shell make @var{make-args}}.
1422@end table
1423
79a6e687
BW
1424@node Logging Output
1425@section Logging Output
0fac0b41 1426@cindex logging @value{GDBN} output
9c16f35a 1427@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1428
1429You may want to save the output of @value{GDBN} commands to a file.
1430There are several commands to control @value{GDBN}'s logging.
1431
1432@table @code
1433@kindex set logging
1434@item set logging on
1435Enable logging.
1436@item set logging off
1437Disable logging.
9c16f35a 1438@cindex logging file name
0fac0b41
DJ
1439@item set logging file @var{file}
1440Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1441@item set logging overwrite [on|off]
1442By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1443you want @code{set logging on} to overwrite the logfile instead.
1444@item set logging redirect [on|off]
1445By default, @value{GDBN} output will go to both the terminal and the logfile.
1446Set @code{redirect} if you want output to go only to the log file.
1447@kindex show logging
1448@item show logging
1449Show the current values of the logging settings.
1450@end table
1451
6d2ebf8b 1452@node Commands
c906108c
SS
1453@chapter @value{GDBN} Commands
1454
1455You can abbreviate a @value{GDBN} command to the first few letters of the command
1456name, if that abbreviation is unambiguous; and you can repeat certain
1457@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1458key to get @value{GDBN} to fill out the rest of a word in a command (or to
1459show you the alternatives available, if there is more than one possibility).
1460
1461@menu
1462* Command Syntax:: How to give commands to @value{GDBN}
1463* Completion:: Command completion
1464* Help:: How to ask @value{GDBN} for help
1465@end menu
1466
6d2ebf8b 1467@node Command Syntax
79a6e687 1468@section Command Syntax
c906108c
SS
1469
1470A @value{GDBN} command is a single line of input. There is no limit on
1471how long it can be. It starts with a command name, which is followed by
1472arguments whose meaning depends on the command name. For example, the
1473command @code{step} accepts an argument which is the number of times to
1474step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1475with no arguments. Some commands do not allow any arguments.
c906108c
SS
1476
1477@cindex abbreviation
1478@value{GDBN} command names may always be truncated if that abbreviation is
1479unambiguous. Other possible command abbreviations are listed in the
1480documentation for individual commands. In some cases, even ambiguous
1481abbreviations are allowed; for example, @code{s} is specially defined as
1482equivalent to @code{step} even though there are other commands whose
1483names start with @code{s}. You can test abbreviations by using them as
1484arguments to the @code{help} command.
1485
1486@cindex repeating commands
41afff9a 1487@kindex RET @r{(repeat last command)}
c906108c 1488A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1489repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1490will not repeat this way; these are commands whose unintentional
1491repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1492repeat. User-defined commands can disable this feature; see
1493@ref{Define, dont-repeat}.
c906108c
SS
1494
1495The @code{list} and @code{x} commands, when you repeat them with
1496@key{RET}, construct new arguments rather than repeating
1497exactly as typed. This permits easy scanning of source or memory.
1498
1499@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1500output, in a way similar to the common utility @code{more}
79a6e687 1501(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1502@key{RET} too many in this situation, @value{GDBN} disables command
1503repetition after any command that generates this sort of display.
1504
41afff9a 1505@kindex # @r{(a comment)}
c906108c
SS
1506@cindex comment
1507Any text from a @kbd{#} to the end of the line is a comment; it does
1508nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1509Files,,Command Files}).
c906108c 1510
88118b3a 1511@cindex repeating command sequences
c8aa23ab
EZ
1512@kindex Ctrl-o @r{(operate-and-get-next)}
1513The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1514commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1515then fetches the next line relative to the current line from the history
1516for editing.
1517
6d2ebf8b 1518@node Completion
79a6e687 1519@section Command Completion
c906108c
SS
1520
1521@cindex completion
1522@cindex word completion
1523@value{GDBN} can fill in the rest of a word in a command for you, if there is
1524only one possibility; it can also show you what the valid possibilities
1525are for the next word in a command, at any time. This works for @value{GDBN}
1526commands, @value{GDBN} subcommands, and the names of symbols in your program.
1527
1528Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1529of a word. If there is only one possibility, @value{GDBN} fills in the
1530word, and waits for you to finish the command (or press @key{RET} to
1531enter it). For example, if you type
1532
1533@c FIXME "@key" does not distinguish its argument sufficiently to permit
1534@c complete accuracy in these examples; space introduced for clarity.
1535@c If texinfo enhancements make it unnecessary, it would be nice to
1536@c replace " @key" by "@key" in the following...
474c8240 1537@smallexample
c906108c 1538(@value{GDBP}) info bre @key{TAB}
474c8240 1539@end smallexample
c906108c
SS
1540
1541@noindent
1542@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1543the only @code{info} subcommand beginning with @samp{bre}:
1544
474c8240 1545@smallexample
c906108c 1546(@value{GDBP}) info breakpoints
474c8240 1547@end smallexample
c906108c
SS
1548
1549@noindent
1550You can either press @key{RET} at this point, to run the @code{info
1551breakpoints} command, or backspace and enter something else, if
1552@samp{breakpoints} does not look like the command you expected. (If you
1553were sure you wanted @code{info breakpoints} in the first place, you
1554might as well just type @key{RET} immediately after @samp{info bre},
1555to exploit command abbreviations rather than command completion).
1556
1557If there is more than one possibility for the next word when you press
1558@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1559characters and try again, or just press @key{TAB} a second time;
1560@value{GDBN} displays all the possible completions for that word. For
1561example, you might want to set a breakpoint on a subroutine whose name
1562begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1563just sounds the bell. Typing @key{TAB} again displays all the
1564function names in your program that begin with those characters, for
1565example:
1566
474c8240 1567@smallexample
c906108c
SS
1568(@value{GDBP}) b make_ @key{TAB}
1569@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1570make_a_section_from_file make_environ
1571make_abs_section make_function_type
1572make_blockvector make_pointer_type
1573make_cleanup make_reference_type
c906108c
SS
1574make_command make_symbol_completion_list
1575(@value{GDBP}) b make_
474c8240 1576@end smallexample
c906108c
SS
1577
1578@noindent
1579After displaying the available possibilities, @value{GDBN} copies your
1580partial input (@samp{b make_} in the example) so you can finish the
1581command.
1582
1583If you just want to see the list of alternatives in the first place, you
b37052ae 1584can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1585means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1586key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1587one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c
SS
1588
1589@cindex quotes in commands
1590@cindex completion of quoted strings
1591Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1592parentheses or other characters that @value{GDBN} normally excludes from
1593its notion of a word. To permit word completion to work in this
1594situation, you may enclose words in @code{'} (single quote marks) in
1595@value{GDBN} commands.
c906108c 1596
c906108c 1597The most likely situation where you might need this is in typing the
b37052ae
EZ
1598name of a C@t{++} function. This is because C@t{++} allows function
1599overloading (multiple definitions of the same function, distinguished
1600by argument type). For example, when you want to set a breakpoint you
1601may need to distinguish whether you mean the version of @code{name}
1602that takes an @code{int} parameter, @code{name(int)}, or the version
1603that takes a @code{float} parameter, @code{name(float)}. To use the
1604word-completion facilities in this situation, type a single quote
1605@code{'} at the beginning of the function name. This alerts
1606@value{GDBN} that it may need to consider more information than usual
1607when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1608
474c8240 1609@smallexample
96a2c332 1610(@value{GDBP}) b 'bubble( @kbd{M-?}
c906108c
SS
1611bubble(double,double) bubble(int,int)
1612(@value{GDBP}) b 'bubble(
474c8240 1613@end smallexample
c906108c
SS
1614
1615In some cases, @value{GDBN} can tell that completing a name requires using
1616quotes. When this happens, @value{GDBN} inserts the quote for you (while
1617completing as much as it can) if you do not type the quote in the first
1618place:
1619
474c8240 1620@smallexample
c906108c
SS
1621(@value{GDBP}) b bub @key{TAB}
1622@exdent @value{GDBN} alters your input line to the following, and rings a bell:
1623(@value{GDBP}) b 'bubble(
474c8240 1624@end smallexample
c906108c
SS
1625
1626@noindent
1627In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1628you have not yet started typing the argument list when you ask for
1629completion on an overloaded symbol.
1630
79a6e687
BW
1631For more information about overloaded functions, see @ref{C Plus Plus
1632Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1633overload-resolution off} to disable overload resolution;
79a6e687 1634see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1635
65d12d83
TT
1636@cindex completion of structure field names
1637@cindex structure field name completion
1638@cindex completion of union field names
1639@cindex union field name completion
1640When completing in an expression which looks up a field in a
1641structure, @value{GDBN} also tries@footnote{The completer can be
1642confused by certain kinds of invalid expressions. Also, it only
1643examines the static type of the expression, not the dynamic type.} to
1644limit completions to the field names available in the type of the
1645left-hand-side:
1646
1647@smallexample
1648(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1649magic to_fputs to_rewind
1650to_data to_isatty to_write
1651to_delete to_put to_write_async_safe
1652to_flush to_read
65d12d83
TT
1653@end smallexample
1654
1655@noindent
1656This is because the @code{gdb_stdout} is a variable of the type
1657@code{struct ui_file} that is defined in @value{GDBN} sources as
1658follows:
1659
1660@smallexample
1661struct ui_file
1662@{
1663 int *magic;
1664 ui_file_flush_ftype *to_flush;
1665 ui_file_write_ftype *to_write;
01124a23 1666 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1667 ui_file_fputs_ftype *to_fputs;
1668 ui_file_read_ftype *to_read;
1669 ui_file_delete_ftype *to_delete;
1670 ui_file_isatty_ftype *to_isatty;
1671 ui_file_rewind_ftype *to_rewind;
1672 ui_file_put_ftype *to_put;
1673 void *to_data;
1674@}
1675@end smallexample
1676
c906108c 1677
6d2ebf8b 1678@node Help
79a6e687 1679@section Getting Help
c906108c
SS
1680@cindex online documentation
1681@kindex help
1682
5d161b24 1683You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1684using the command @code{help}.
1685
1686@table @code
41afff9a 1687@kindex h @r{(@code{help})}
c906108c
SS
1688@item help
1689@itemx h
1690You can use @code{help} (abbreviated @code{h}) with no arguments to
1691display a short list of named classes of commands:
1692
1693@smallexample
1694(@value{GDBP}) help
1695List of classes of commands:
1696
2df3850c 1697aliases -- Aliases of other commands
c906108c 1698breakpoints -- Making program stop at certain points
2df3850c 1699data -- Examining data
c906108c 1700files -- Specifying and examining files
2df3850c
JM
1701internals -- Maintenance commands
1702obscure -- Obscure features
1703running -- Running the program
1704stack -- Examining the stack
c906108c
SS
1705status -- Status inquiries
1706support -- Support facilities
12c27660 1707tracepoints -- Tracing of program execution without
96a2c332 1708 stopping the program
c906108c 1709user-defined -- User-defined commands
c906108c 1710
5d161b24 1711Type "help" followed by a class name for a list of
c906108c 1712commands in that class.
5d161b24 1713Type "help" followed by command name for full
c906108c
SS
1714documentation.
1715Command name abbreviations are allowed if unambiguous.
1716(@value{GDBP})
1717@end smallexample
96a2c332 1718@c the above line break eliminates huge line overfull...
c906108c
SS
1719
1720@item help @var{class}
1721Using one of the general help classes as an argument, you can get a
1722list of the individual commands in that class. For example, here is the
1723help display for the class @code{status}:
1724
1725@smallexample
1726(@value{GDBP}) help status
1727Status inquiries.
1728
1729List of commands:
1730
1731@c Line break in "show" line falsifies real output, but needed
1732@c to fit in smallbook page size.
2df3850c 1733info -- Generic command for showing things
12c27660 1734 about the program being debugged
2df3850c 1735show -- Generic command for showing things
12c27660 1736 about the debugger
c906108c 1737
5d161b24 1738Type "help" followed by command name for full
c906108c
SS
1739documentation.
1740Command name abbreviations are allowed if unambiguous.
1741(@value{GDBP})
1742@end smallexample
1743
1744@item help @var{command}
1745With a command name as @code{help} argument, @value{GDBN} displays a
1746short paragraph on how to use that command.
1747
6837a0a2
DB
1748@kindex apropos
1749@item apropos @var{args}
09d4efe1 1750The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1751commands, and their documentation, for the regular expression specified in
99e008fe 1752@var{args}. It prints out all matches found. For example:
6837a0a2
DB
1753
1754@smallexample
16899756 1755apropos alias
6837a0a2
DB
1756@end smallexample
1757
b37052ae
EZ
1758@noindent
1759results in:
6837a0a2
DB
1760
1761@smallexample
6d2ebf8b 1762@c @group
16899756
DE
1763alias -- Define a new command that is an alias of an existing command
1764aliases -- Aliases of other commands
1765d -- Delete some breakpoints or auto-display expressions
1766del -- Delete some breakpoints or auto-display expressions
1767delete -- Delete some breakpoints or auto-display expressions
6d2ebf8b 1768@c @end group
6837a0a2
DB
1769@end smallexample
1770
c906108c
SS
1771@kindex complete
1772@item complete @var{args}
1773The @code{complete @var{args}} command lists all the possible completions
1774for the beginning of a command. Use @var{args} to specify the beginning of the
1775command you want completed. For example:
1776
1777@smallexample
1778complete i
1779@end smallexample
1780
1781@noindent results in:
1782
1783@smallexample
1784@group
2df3850c
JM
1785if
1786ignore
c906108c
SS
1787info
1788inspect
c906108c
SS
1789@end group
1790@end smallexample
1791
1792@noindent This is intended for use by @sc{gnu} Emacs.
1793@end table
1794
1795In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1796and @code{show} to inquire about the state of your program, or the state
1797of @value{GDBN} itself. Each command supports many topics of inquiry; this
1798manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1799under @code{info} and under @code{show} in the Command, Variable, and
1800Function Index point to all the sub-commands. @xref{Command and Variable
1801Index}.
c906108c
SS
1802
1803@c @group
1804@table @code
1805@kindex info
41afff9a 1806@kindex i @r{(@code{info})}
c906108c
SS
1807@item info
1808This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1809program. For example, you can show the arguments passed to a function
c906108c
SS
1810with @code{info args}, list the registers currently in use with @code{info
1811registers}, or list the breakpoints you have set with @code{info breakpoints}.
1812You can get a complete list of the @code{info} sub-commands with
1813@w{@code{help info}}.
1814
1815@kindex set
1816@item set
5d161b24 1817You can assign the result of an expression to an environment variable with
c906108c
SS
1818@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1819@code{set prompt $}.
1820
1821@kindex show
1822@item show
5d161b24 1823In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
1824@value{GDBN} itself.
1825You can change most of the things you can @code{show}, by using the
1826related command @code{set}; for example, you can control what number
1827system is used for displays with @code{set radix}, or simply inquire
1828which is currently in use with @code{show radix}.
1829
1830@kindex info set
1831To display all the settable parameters and their current
1832values, you can use @code{show} with no arguments; you may also use
1833@code{info set}. Both commands produce the same display.
1834@c FIXME: "info set" violates the rule that "info" is for state of
1835@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1836@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1837@end table
1838@c @end group
1839
1840Here are three miscellaneous @code{show} subcommands, all of which are
1841exceptional in lacking corresponding @code{set} commands:
1842
1843@table @code
1844@kindex show version
9c16f35a 1845@cindex @value{GDBN} version number
c906108c
SS
1846@item show version
1847Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
1848information in @value{GDBN} bug-reports. If multiple versions of
1849@value{GDBN} are in use at your site, you may need to determine which
1850version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1851commands are introduced, and old ones may wither away. Also, many
1852system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 1853variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
1854The version number is the same as the one announced when you start
1855@value{GDBN}.
c906108c
SS
1856
1857@kindex show copying
09d4efe1 1858@kindex info copying
9c16f35a 1859@cindex display @value{GDBN} copyright
c906108c 1860@item show copying
09d4efe1 1861@itemx info copying
c906108c
SS
1862Display information about permission for copying @value{GDBN}.
1863
1864@kindex show warranty
09d4efe1 1865@kindex info warranty
c906108c 1866@item show warranty
09d4efe1 1867@itemx info warranty
2df3850c 1868Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 1869if your version of @value{GDBN} comes with one.
2df3850c 1870
c906108c
SS
1871@end table
1872
6d2ebf8b 1873@node Running
c906108c
SS
1874@chapter Running Programs Under @value{GDBN}
1875
1876When you run a program under @value{GDBN}, you must first generate
1877debugging information when you compile it.
7a292a7a
SS
1878
1879You may start @value{GDBN} with its arguments, if any, in an environment
1880of your choice. If you are doing native debugging, you may redirect
1881your program's input and output, debug an already running process, or
1882kill a child process.
c906108c
SS
1883
1884@menu
1885* Compilation:: Compiling for debugging
1886* Starting:: Starting your program
c906108c
SS
1887* Arguments:: Your program's arguments
1888* Environment:: Your program's environment
c906108c
SS
1889
1890* Working Directory:: Your program's working directory
1891* Input/Output:: Your program's input and output
1892* Attach:: Debugging an already-running process
1893* Kill Process:: Killing the child process
c906108c 1894
6c95b8df 1895* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 1896* Threads:: Debugging programs with multiple threads
6c95b8df 1897* Forks:: Debugging forks
5c95884b 1898* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
1899@end menu
1900
6d2ebf8b 1901@node Compilation
79a6e687 1902@section Compiling for Debugging
c906108c
SS
1903
1904In order to debug a program effectively, you need to generate
1905debugging information when you compile it. This debugging information
1906is stored in the object file; it describes the data type of each
1907variable or function and the correspondence between source line numbers
1908and addresses in the executable code.
1909
1910To request debugging information, specify the @samp{-g} option when you run
1911the compiler.
1912
514c4d71 1913Programs that are to be shipped to your customers are compiled with
edb3359d 1914optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
1915compilers are unable to handle the @samp{-g} and @samp{-O} options
1916together. Using those compilers, you cannot generate optimized
c906108c
SS
1917executables containing debugging information.
1918
514c4d71 1919@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
1920without @samp{-O}, making it possible to debug optimized code. We
1921recommend that you @emph{always} use @samp{-g} whenever you compile a
1922program. You may think your program is correct, but there is no sense
edb3359d 1923in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
1924
1925Older versions of the @sc{gnu} C compiler permitted a variant option
1926@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1927format; if your @sc{gnu} C compiler has this option, do not use it.
1928
514c4d71
EZ
1929@value{GDBN} knows about preprocessor macros and can show you their
1930expansion (@pxref{Macros}). Most compilers do not include information
1931about preprocessor macros in the debugging information if you specify
e0f8f636
TT
1932the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1933the @sc{gnu} C compiler, provides macro information if you are using
1934the DWARF debugging format, and specify the option @option{-g3}.
1935
1936@xref{Debugging Options,,Options for Debugging Your Program or GCC,
1937gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1938information on @value{NGCC} options affecting debug information.
1939
1940You will have the best debugging experience if you use the latest
1941version of the DWARF debugging format that your compiler supports.
1942DWARF is currently the most expressive and best supported debugging
1943format in @value{GDBN}.
514c4d71 1944
c906108c 1945@need 2000
6d2ebf8b 1946@node Starting
79a6e687 1947@section Starting your Program
c906108c
SS
1948@cindex starting
1949@cindex running
1950
1951@table @code
1952@kindex run
41afff9a 1953@kindex r @r{(@code{run})}
c906108c
SS
1954@item run
1955@itemx r
7a292a7a
SS
1956Use the @code{run} command to start your program under @value{GDBN}.
1957You must first specify the program name (except on VxWorks) with an
1958argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1959@value{GDBN}}), or by using the @code{file} or @code{exec-file} command
79a6e687 1960(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
1961
1962@end table
1963
c906108c
SS
1964If you are running your program in an execution environment that
1965supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
1966that process run your program. In some environments without processes,
1967@code{run} jumps to the start of your program. Other targets,
1968like @samp{remote}, are always running. If you get an error
1969message like this one:
1970
1971@smallexample
1972The "remote" target does not support "run".
1973Try "help target" or "continue".
1974@end smallexample
1975
1976@noindent
1977then use @code{continue} to run your program. You may need @code{load}
1978first (@pxref{load}).
c906108c
SS
1979
1980The execution of a program is affected by certain information it
1981receives from its superior. @value{GDBN} provides ways to specify this
1982information, which you must do @emph{before} starting your program. (You
1983can change it after starting your program, but such changes only affect
1984your program the next time you start it.) This information may be
1985divided into four categories:
1986
1987@table @asis
1988@item The @emph{arguments.}
1989Specify the arguments to give your program as the arguments of the
1990@code{run} command. If a shell is available on your target, the shell
1991is used to pass the arguments, so that you may use normal conventions
1992(such as wildcard expansion or variable substitution) in describing
1993the arguments.
1994In Unix systems, you can control which shell is used with the
1995@code{SHELL} environment variable.
79a6e687 1996@xref{Arguments, ,Your Program's Arguments}.
c906108c
SS
1997
1998@item The @emph{environment.}
1999Your program normally inherits its environment from @value{GDBN}, but you can
2000use the @value{GDBN} commands @code{set environment} and @code{unset
2001environment} to change parts of the environment that affect
79a6e687 2002your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2003
2004@item The @emph{working directory.}
2005Your program inherits its working directory from @value{GDBN}. You can set
2006the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
79a6e687 2007@xref{Working Directory, ,Your Program's Working Directory}.
c906108c
SS
2008
2009@item The @emph{standard input and output.}
2010Your program normally uses the same device for standard input and
2011standard output as @value{GDBN} is using. You can redirect input and output
2012in the @code{run} command line, or you can use the @code{tty} command to
2013set a different device for your program.
79a6e687 2014@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2015
2016@cindex pipes
2017@emph{Warning:} While input and output redirection work, you cannot use
2018pipes to pass the output of the program you are debugging to another
2019program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2020wrong program.
2021@end table
c906108c
SS
2022
2023When you issue the @code{run} command, your program begins to execute
79a6e687 2024immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2025of how to arrange for your program to stop. Once your program has
2026stopped, you may call functions in your program, using the @code{print}
2027or @code{call} commands. @xref{Data, ,Examining Data}.
2028
2029If the modification time of your symbol file has changed since the last
2030time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2031table, and reads it again. When it does this, @value{GDBN} tries to retain
2032your current breakpoints.
2033
4e8b0763
JB
2034@table @code
2035@kindex start
2036@item start
2037@cindex run to main procedure
2038The name of the main procedure can vary from language to language.
2039With C or C@t{++}, the main procedure name is always @code{main}, but
2040other languages such as Ada do not require a specific name for their
2041main procedure. The debugger provides a convenient way to start the
2042execution of the program and to stop at the beginning of the main
2043procedure, depending on the language used.
2044
2045The @samp{start} command does the equivalent of setting a temporary
2046breakpoint at the beginning of the main procedure and then invoking
2047the @samp{run} command.
2048
f018e82f
EZ
2049@cindex elaboration phase
2050Some programs contain an @dfn{elaboration} phase where some startup code is
2051executed before the main procedure is called. This depends on the
2052languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2053constructors for static and global objects are executed before
2054@code{main} is called. It is therefore possible that the debugger stops
2055before reaching the main procedure. However, the temporary breakpoint
2056will remain to halt execution.
2057
2058Specify the arguments to give to your program as arguments to the
2059@samp{start} command. These arguments will be given verbatim to the
2060underlying @samp{run} command. Note that the same arguments will be
2061reused if no argument is provided during subsequent calls to
2062@samp{start} or @samp{run}.
2063
2064It is sometimes necessary to debug the program during elaboration. In
2065these cases, using the @code{start} command would stop the execution of
2066your program too late, as the program would have already completed the
2067elaboration phase. Under these circumstances, insert breakpoints in your
2068elaboration code before running your program.
ccd213ac
DJ
2069
2070@kindex set exec-wrapper
2071@item set exec-wrapper @var{wrapper}
2072@itemx show exec-wrapper
2073@itemx unset exec-wrapper
2074When @samp{exec-wrapper} is set, the specified wrapper is used to
2075launch programs for debugging. @value{GDBN} starts your program
2076with a shell command of the form @kbd{exec @var{wrapper}
2077@var{program}}. Quoting is added to @var{program} and its
2078arguments, but not to @var{wrapper}, so you should add quotes if
2079appropriate for your shell. The wrapper runs until it executes
2080your program, and then @value{GDBN} takes control.
2081
2082You can use any program that eventually calls @code{execve} with
2083its arguments as a wrapper. Several standard Unix utilities do
2084this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2085with @code{exec "$@@"} will also work.
2086
2087For example, you can use @code{env} to pass an environment variable to
2088the debugged program, without setting the variable in your shell's
2089environment:
2090
2091@smallexample
2092(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2093(@value{GDBP}) run
2094@end smallexample
2095
2096This command is available when debugging locally on most targets, excluding
2097@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2098
10568435
JK
2099@kindex set disable-randomization
2100@item set disable-randomization
2101@itemx set disable-randomization on
2102This option (enabled by default in @value{GDBN}) will turn off the native
2103randomization of the virtual address space of the started program. This option
2104is useful for multiple debugging sessions to make the execution better
2105reproducible and memory addresses reusable across debugging sessions.
2106
03583c20
UW
2107This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2108On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2109
2110@smallexample
2111(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2112@end smallexample
2113
2114@item set disable-randomization off
2115Leave the behavior of the started executable unchanged. Some bugs rear their
2116ugly heads only when the program is loaded at certain addresses. If your bug
2117disappears when you run the program under @value{GDBN}, that might be because
2118@value{GDBN} by default disables the address randomization on platforms, such
2119as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2120disable-randomization off} to try to reproduce such elusive bugs.
2121
03583c20
UW
2122On targets where it is available, virtual address space randomization
2123protects the programs against certain kinds of security attacks. In these
10568435
JK
2124cases the attacker needs to know the exact location of a concrete executable
2125code. Randomizing its location makes it impossible to inject jumps misusing
2126a code at its expected addresses.
2127
2128Prelinking shared libraries provides a startup performance advantage but it
2129makes addresses in these libraries predictable for privileged processes by
2130having just unprivileged access at the target system. Reading the shared
2131library binary gives enough information for assembling the malicious code
2132misusing it. Still even a prelinked shared library can get loaded at a new
2133random address just requiring the regular relocation process during the
2134startup. Shared libraries not already prelinked are always loaded at
2135a randomly chosen address.
2136
2137Position independent executables (PIE) contain position independent code
2138similar to the shared libraries and therefore such executables get loaded at
2139a randomly chosen address upon startup. PIE executables always load even
2140already prelinked shared libraries at a random address. You can build such
2141executable using @command{gcc -fPIE -pie}.
2142
2143Heap (malloc storage), stack and custom mmap areas are always placed randomly
2144(as long as the randomization is enabled).
2145
2146@item show disable-randomization
2147Show the current setting of the explicit disable of the native randomization of
2148the virtual address space of the started program.
2149
4e8b0763
JB
2150@end table
2151
6d2ebf8b 2152@node Arguments
79a6e687 2153@section Your Program's Arguments
c906108c
SS
2154
2155@cindex arguments (to your program)
2156The arguments to your program can be specified by the arguments of the
5d161b24 2157@code{run} command.
c906108c
SS
2158They are passed to a shell, which expands wildcard characters and
2159performs redirection of I/O, and thence to your program. Your
2160@code{SHELL} environment variable (if it exists) specifies what shell
2161@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2162the default shell (@file{/bin/sh} on Unix).
2163
2164On non-Unix systems, the program is usually invoked directly by
2165@value{GDBN}, which emulates I/O redirection via the appropriate system
2166calls, and the wildcard characters are expanded by the startup code of
2167the program, not by the shell.
c906108c
SS
2168
2169@code{run} with no arguments uses the same arguments used by the previous
2170@code{run}, or those set by the @code{set args} command.
2171
c906108c 2172@table @code
41afff9a 2173@kindex set args
c906108c
SS
2174@item set args
2175Specify the arguments to be used the next time your program is run. If
2176@code{set args} has no arguments, @code{run} executes your program
2177with no arguments. Once you have run your program with arguments,
2178using @code{set args} before the next @code{run} is the only way to run
2179it again without arguments.
2180
2181@kindex show args
2182@item show args
2183Show the arguments to give your program when it is started.
2184@end table
2185
6d2ebf8b 2186@node Environment
79a6e687 2187@section Your Program's Environment
c906108c
SS
2188
2189@cindex environment (of your program)
2190The @dfn{environment} consists of a set of environment variables and
2191their values. Environment variables conventionally record such things as
2192your user name, your home directory, your terminal type, and your search
2193path for programs to run. Usually you set up environment variables with
2194the shell and they are inherited by all the other programs you run. When
2195debugging, it can be useful to try running your program with a modified
2196environment without having to start @value{GDBN} over again.
2197
2198@table @code
2199@kindex path
2200@item path @var{directory}
2201Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2202(the search path for executables) that will be passed to your program.
2203The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2204You may specify several directory names, separated by whitespace or by a
2205system-dependent separator character (@samp{:} on Unix, @samp{;} on
2206MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2207is moved to the front, so it is searched sooner.
c906108c
SS
2208
2209You can use the string @samp{$cwd} to refer to whatever is the current
2210working directory at the time @value{GDBN} searches the path. If you
2211use @samp{.} instead, it refers to the directory where you executed the
2212@code{path} command. @value{GDBN} replaces @samp{.} in the
2213@var{directory} argument (with the current path) before adding
2214@var{directory} to the search path.
2215@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2216@c document that, since repeating it would be a no-op.
2217
2218@kindex show paths
2219@item show paths
2220Display the list of search paths for executables (the @code{PATH}
2221environment variable).
2222
2223@kindex show environment
2224@item show environment @r{[}@var{varname}@r{]}
2225Print the value of environment variable @var{varname} to be given to
2226your program when it starts. If you do not supply @var{varname},
2227print the names and values of all environment variables to be given to
2228your program. You can abbreviate @code{environment} as @code{env}.
2229
2230@kindex set environment
53a5351d 2231@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c
SS
2232Set environment variable @var{varname} to @var{value}. The value
2233changes for your program only, not for @value{GDBN} itself. @var{value} may
2234be any string; the values of environment variables are just strings, and
2235any interpretation is supplied by your program itself. The @var{value}
2236parameter is optional; if it is eliminated, the variable is set to a
2237null value.
2238@c "any string" here does not include leading, trailing
2239@c blanks. Gnu asks: does anyone care?
2240
2241For example, this command:
2242
474c8240 2243@smallexample
c906108c 2244set env USER = foo
474c8240 2245@end smallexample
c906108c
SS
2246
2247@noindent
d4f3574e 2248tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2249@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2250are not actually required.)
2251
2252@kindex unset environment
2253@item unset environment @var{varname}
2254Remove variable @var{varname} from the environment to be passed to your
2255program. This is different from @samp{set env @var{varname} =};
2256@code{unset environment} removes the variable from the environment,
2257rather than assigning it an empty value.
2258@end table
2259
d4f3574e
SS
2260@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2261the shell indicated
c906108c
SS
2262by your @code{SHELL} environment variable if it exists (or
2263@code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2264that runs an initialization file---such as @file{.cshrc} for C-shell, or
2265@file{.bashrc} for BASH---any variables you set in that file affect
2266your program. You may wish to move setting of environment variables to
2267files that are only run when you sign on, such as @file{.login} or
2268@file{.profile}.
2269
6d2ebf8b 2270@node Working Directory
79a6e687 2271@section Your Program's Working Directory
c906108c
SS
2272
2273@cindex working directory (of your program)
2274Each time you start your program with @code{run}, it inherits its
2275working directory from the current working directory of @value{GDBN}.
2276The @value{GDBN} working directory is initially whatever it inherited
2277from its parent process (typically the shell), but you can specify a new
2278working directory in @value{GDBN} with the @code{cd} command.
2279
2280The @value{GDBN} working directory also serves as a default for the commands
2281that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
79a6e687 2282Specify Files}.
c906108c
SS
2283
2284@table @code
2285@kindex cd
721c2651 2286@cindex change working directory
f3c8a52a
JK
2287@item cd @r{[}@var{directory}@r{]}
2288Set the @value{GDBN} working directory to @var{directory}. If not
2289given, @var{directory} uses @file{'~'}.
c906108c
SS
2290
2291@kindex pwd
2292@item pwd
2293Print the @value{GDBN} working directory.
2294@end table
2295
60bf7e09
EZ
2296It is generally impossible to find the current working directory of
2297the process being debugged (since a program can change its directory
2298during its run). If you work on a system where @value{GDBN} is
2299configured with the @file{/proc} support, you can use the @code{info
2300proc} command (@pxref{SVR4 Process Information}) to find out the
2301current working directory of the debuggee.
2302
6d2ebf8b 2303@node Input/Output
79a6e687 2304@section Your Program's Input and Output
c906108c
SS
2305
2306@cindex redirection
2307@cindex i/o
2308@cindex terminal
2309By default, the program you run under @value{GDBN} does input and output to
5d161b24 2310the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2311to its own terminal modes to interact with you, but it records the terminal
2312modes your program was using and switches back to them when you continue
2313running your program.
2314
2315@table @code
2316@kindex info terminal
2317@item info terminal
2318Displays information recorded by @value{GDBN} about the terminal modes your
2319program is using.
2320@end table
2321
2322You can redirect your program's input and/or output using shell
2323redirection with the @code{run} command. For example,
2324
474c8240 2325@smallexample
c906108c 2326run > outfile
474c8240 2327@end smallexample
c906108c
SS
2328
2329@noindent
2330starts your program, diverting its output to the file @file{outfile}.
2331
2332@kindex tty
2333@cindex controlling terminal
2334Another way to specify where your program should do input and output is
2335with the @code{tty} command. This command accepts a file name as
2336argument, and causes this file to be the default for future @code{run}
2337commands. It also resets the controlling terminal for the child
2338process, for future @code{run} commands. For example,
2339
474c8240 2340@smallexample
c906108c 2341tty /dev/ttyb
474c8240 2342@end smallexample
c906108c
SS
2343
2344@noindent
2345directs that processes started with subsequent @code{run} commands
2346default to do input and output on the terminal @file{/dev/ttyb} and have
2347that as their controlling terminal.
2348
2349An explicit redirection in @code{run} overrides the @code{tty} command's
2350effect on the input/output device, but not its effect on the controlling
2351terminal.
2352
2353When you use the @code{tty} command or redirect input in the @code{run}
2354command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2355for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2356for @code{set inferior-tty}.
2357
2358@cindex inferior tty
2359@cindex set inferior controlling terminal
2360You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2361display the name of the terminal that will be used for future runs of your
2362program.
2363
2364@table @code
2365@item set inferior-tty /dev/ttyb
2366@kindex set inferior-tty
2367Set the tty for the program being debugged to /dev/ttyb.
2368
2369@item show inferior-tty
2370@kindex show inferior-tty
2371Show the current tty for the program being debugged.
2372@end table
c906108c 2373
6d2ebf8b 2374@node Attach
79a6e687 2375@section Debugging an Already-running Process
c906108c
SS
2376@kindex attach
2377@cindex attach
2378
2379@table @code
2380@item attach @var{process-id}
2381This command attaches to a running process---one that was started
2382outside @value{GDBN}. (@code{info files} shows your active
2383targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2384find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2385or with the @samp{jobs -l} shell command.
2386
2387@code{attach} does not repeat if you press @key{RET} a second time after
2388executing the command.
2389@end table
2390
2391To use @code{attach}, your program must be running in an environment
2392which supports processes; for example, @code{attach} does not work for
2393programs on bare-board targets that lack an operating system. You must
2394also have permission to send the process a signal.
2395
2396When you use @code{attach}, the debugger finds the program running in
2397the process first by looking in the current working directory, then (if
2398the program is not found) by using the source file search path
79a6e687 2399(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2400the @code{file} command to load the program. @xref{Files, ,Commands to
2401Specify Files}.
2402
2403The first thing @value{GDBN} does after arranging to debug the specified
2404process is to stop it. You can examine and modify an attached process
53a5351d
JM
2405with all the @value{GDBN} commands that are ordinarily available when
2406you start processes with @code{run}. You can insert breakpoints; you
2407can step and continue; you can modify storage. If you would rather the
2408process continue running, you may use the @code{continue} command after
c906108c
SS
2409attaching @value{GDBN} to the process.
2410
2411@table @code
2412@kindex detach
2413@item detach
2414When you have finished debugging the attached process, you can use the
2415@code{detach} command to release it from @value{GDBN} control. Detaching
2416the process continues its execution. After the @code{detach} command,
2417that process and @value{GDBN} become completely independent once more, and you
2418are ready to @code{attach} another process or start one with @code{run}.
2419@code{detach} does not repeat if you press @key{RET} again after
2420executing the command.
2421@end table
2422
159fcc13
JK
2423If you exit @value{GDBN} while you have an attached process, you detach
2424that process. If you use the @code{run} command, you kill that process.
2425By default, @value{GDBN} asks for confirmation if you try to do either of these
2426things; you can control whether or not you need to confirm by using the
2427@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2428Messages}).
c906108c 2429
6d2ebf8b 2430@node Kill Process
79a6e687 2431@section Killing the Child Process
c906108c
SS
2432
2433@table @code
2434@kindex kill
2435@item kill
2436Kill the child process in which your program is running under @value{GDBN}.
2437@end table
2438
2439This command is useful if you wish to debug a core dump instead of a
2440running process. @value{GDBN} ignores any core dump file while your program
2441is running.
2442
2443On some operating systems, a program cannot be executed outside @value{GDBN}
2444while you have breakpoints set on it inside @value{GDBN}. You can use the
2445@code{kill} command in this situation to permit running your program
2446outside the debugger.
2447
2448The @code{kill} command is also useful if you wish to recompile and
2449relink your program, since on many systems it is impossible to modify an
2450executable file while it is running in a process. In this case, when you
2451next type @code{run}, @value{GDBN} notices that the file has changed, and
2452reads the symbol table again (while trying to preserve your current
2453breakpoint settings).
2454
6c95b8df
PA
2455@node Inferiors and Programs
2456@section Debugging Multiple Inferiors and Programs
b77209e0 2457
6c95b8df
PA
2458@value{GDBN} lets you run and debug multiple programs in a single
2459session. In addition, @value{GDBN} on some systems may let you run
2460several programs simultaneously (otherwise you have to exit from one
2461before starting another). In the most general case, you can have
2462multiple threads of execution in each of multiple processes, launched
2463from multiple executables.
b77209e0
PA
2464
2465@cindex inferior
2466@value{GDBN} represents the state of each program execution with an
2467object called an @dfn{inferior}. An inferior typically corresponds to
2468a process, but is more general and applies also to targets that do not
2469have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2470may be retained after a process exits. Inferiors have unique
2471identifiers that are different from process ids. Usually each
2472inferior will also have its own distinct address space, although some
2473embedded targets may have several inferiors running in different parts
2474of a single address space. Each inferior may in turn have multiple
2475threads running in it.
b77209e0 2476
6c95b8df
PA
2477To find out what inferiors exist at any moment, use @w{@code{info
2478inferiors}}:
b77209e0
PA
2479
2480@table @code
2481@kindex info inferiors
2482@item info inferiors
2483Print a list of all inferiors currently being managed by @value{GDBN}.
3a1ff0b6
PA
2484
2485@value{GDBN} displays for each inferior (in this order):
2486
2487@enumerate
2488@item
2489the inferior number assigned by @value{GDBN}
2490
2491@item
2492the target system's inferior identifier
6c95b8df
PA
2493
2494@item
2495the name of the executable the inferior is running.
2496
3a1ff0b6
PA
2497@end enumerate
2498
2499@noindent
2500An asterisk @samp{*} preceding the @value{GDBN} inferior number
2501indicates the current inferior.
2502
2503For example,
2277426b 2504@end table
3a1ff0b6
PA
2505@c end table here to get a little more width for example
2506
2507@smallexample
2508(@value{GDBP}) info inferiors
6c95b8df
PA
2509 Num Description Executable
2510 2 process 2307 hello
2511* 1 process 3401 goodbye
3a1ff0b6 2512@end smallexample
2277426b
PA
2513
2514To switch focus between inferiors, use the @code{inferior} command:
2515
2516@table @code
3a1ff0b6
PA
2517@kindex inferior @var{infno}
2518@item inferior @var{infno}
2519Make inferior number @var{infno} the current inferior. The argument
2520@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2521in the first field of the @samp{info inferiors} display.
2277426b
PA
2522@end table
2523
6c95b8df
PA
2524
2525You can get multiple executables into a debugging session via the
2526@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2527systems @value{GDBN} can add inferiors to the debug session
2528automatically by following calls to @code{fork} and @code{exec}. To
2529remove inferiors from the debugging session use the
af624141 2530@w{@code{remove-inferiors}} command.
6c95b8df
PA
2531
2532@table @code
2533@kindex add-inferior
2534@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2535Adds @var{n} inferiors to be run using @var{executable} as the
2536executable. @var{n} defaults to 1. If no executable is specified,
2537the inferiors begins empty, with no program. You can still assign or
2538change the program assigned to the inferior at any time by using the
2539@code{file} command with the executable name as its argument.
2540
2541@kindex clone-inferior
2542@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2543Adds @var{n} inferiors ready to execute the same program as inferior
2544@var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2545number of the current inferior. This is a convenient command when you
2546want to run another instance of the inferior you are debugging.
2547
2548@smallexample
2549(@value{GDBP}) info inferiors
2550 Num Description Executable
2551* 1 process 29964 helloworld
2552(@value{GDBP}) clone-inferior
2553Added inferior 2.
25541 inferiors added.
2555(@value{GDBP}) info inferiors
2556 Num Description Executable
2557 2 <null> helloworld
2558* 1 process 29964 helloworld
2559@end smallexample
2560
2561You can now simply switch focus to inferior 2 and run it.
2562
af624141
MS
2563@kindex remove-inferiors
2564@item remove-inferiors @var{infno}@dots{}
2565Removes the inferior or inferiors @var{infno}@dots{}. It is not
2566possible to remove an inferior that is running with this command. For
2567those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2568
2569@end table
2570
2571To quit debugging one of the running inferiors that is not the current
2572inferior, you can either detach from it by using the @w{@code{detach
2573inferior}} command (allowing it to run independently), or kill it
af624141 2574using the @w{@code{kill inferiors}} command:
2277426b
PA
2575
2576@table @code
af624141
MS
2577@kindex detach inferiors @var{infno}@dots{}
2578@item detach inferior @var{infno}@dots{}
2579Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2580inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2581still stays on the list of inferiors shown by @code{info inferiors},
2582but its Description will show @samp{<null>}.
2583
2584@kindex kill inferiors @var{infno}@dots{}
2585@item kill inferiors @var{infno}@dots{}
2586Kill the inferior or inferiors identified by @value{GDBN} inferior
2587number(s) @var{infno}@dots{}. Note that the inferior's entry still
2588stays on the list of inferiors shown by @code{info inferiors}, but its
2589Description will show @samp{<null>}.
2277426b
PA
2590@end table
2591
6c95b8df 2592After the successful completion of a command such as @code{detach},
af624141 2593@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2594a normal process exit, the inferior is still valid and listed with
2595@code{info inferiors}, ready to be restarted.
2596
2597
2277426b
PA
2598To be notified when inferiors are started or exit under @value{GDBN}'s
2599control use @w{@code{set print inferior-events}}:
b77209e0 2600
2277426b 2601@table @code
b77209e0
PA
2602@kindex set print inferior-events
2603@cindex print messages on inferior start and exit
2604@item set print inferior-events
2605@itemx set print inferior-events on
2606@itemx set print inferior-events off
2607The @code{set print inferior-events} command allows you to enable or
2608disable printing of messages when @value{GDBN} notices that new
2609inferiors have started or that inferiors have exited or have been
2610detached. By default, these messages will not be printed.
2611
2612@kindex show print inferior-events
2613@item show print inferior-events
2614Show whether messages will be printed when @value{GDBN} detects that
2615inferiors have started, exited or have been detached.
2616@end table
2617
6c95b8df
PA
2618Many commands will work the same with multiple programs as with a
2619single program: e.g., @code{print myglobal} will simply display the
2620value of @code{myglobal} in the current inferior.
2621
2622
2623Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2624get more info about the relationship of inferiors, programs, address
2625spaces in a debug session. You can do that with the @w{@code{maint
2626info program-spaces}} command.
2627
2628@table @code
2629@kindex maint info program-spaces
2630@item maint info program-spaces
2631Print a list of all program spaces currently being managed by
2632@value{GDBN}.
2633
2634@value{GDBN} displays for each program space (in this order):
2635
2636@enumerate
2637@item
2638the program space number assigned by @value{GDBN}
2639
2640@item
2641the name of the executable loaded into the program space, with e.g.,
2642the @code{file} command.
2643
2644@end enumerate
2645
2646@noindent
2647An asterisk @samp{*} preceding the @value{GDBN} program space number
2648indicates the current program space.
2649
2650In addition, below each program space line, @value{GDBN} prints extra
2651information that isn't suitable to display in tabular form. For
2652example, the list of inferiors bound to the program space.
2653
2654@smallexample
2655(@value{GDBP}) maint info program-spaces
2656 Id Executable
2657 2 goodbye
2658 Bound inferiors: ID 1 (process 21561)
2659* 1 hello
2660@end smallexample
2661
2662Here we can see that no inferior is running the program @code{hello},
2663while @code{process 21561} is running the program @code{goodbye}. On
2664some targets, it is possible that multiple inferiors are bound to the
2665same program space. The most common example is that of debugging both
2666the parent and child processes of a @code{vfork} call. For example,
2667
2668@smallexample
2669(@value{GDBP}) maint info program-spaces
2670 Id Executable
2671* 1 vfork-test
2672 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2673@end smallexample
2674
2675Here, both inferior 2 and inferior 1 are running in the same program
2676space as a result of inferior 1 having executed a @code{vfork} call.
2677@end table
2678
6d2ebf8b 2679@node Threads
79a6e687 2680@section Debugging Programs with Multiple Threads
c906108c
SS
2681
2682@cindex threads of execution
2683@cindex multiple threads
2684@cindex switching threads
2685In some operating systems, such as HP-UX and Solaris, a single program
2686may have more than one @dfn{thread} of execution. The precise semantics
2687of threads differ from one operating system to another, but in general
2688the threads of a single program are akin to multiple processes---except
2689that they share one address space (that is, they can all examine and
2690modify the same variables). On the other hand, each thread has its own
2691registers and execution stack, and perhaps private memory.
2692
2693@value{GDBN} provides these facilities for debugging multi-thread
2694programs:
2695
2696@itemize @bullet
2697@item automatic notification of new threads
2698@item @samp{thread @var{threadno}}, a command to switch among threads
2699@item @samp{info threads}, a command to inquire about existing threads
5d161b24 2700@item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
c906108c
SS
2701a command to apply a command to a list of threads
2702@item thread-specific breakpoints
93815fbf
VP
2703@item @samp{set print thread-events}, which controls printing of
2704messages on thread start and exit.
17a37d48
PP
2705@item @samp{set libthread-db-search-path @var{path}}, which lets
2706the user specify which @code{libthread_db} to use if the default choice
2707isn't compatible with the program.
c906108c
SS
2708@end itemize
2709
c906108c
SS
2710@quotation
2711@emph{Warning:} These facilities are not yet available on every
2712@value{GDBN} configuration where the operating system supports threads.
2713If your @value{GDBN} does not support threads, these commands have no
2714effect. For example, a system without thread support shows no output
2715from @samp{info threads}, and always rejects the @code{thread} command,
2716like this:
2717
2718@smallexample
2719(@value{GDBP}) info threads
2720(@value{GDBP}) thread 1
2721Thread ID 1 not known. Use the "info threads" command to
2722see the IDs of currently known threads.
2723@end smallexample
2724@c FIXME to implementors: how hard would it be to say "sorry, this GDB
2725@c doesn't support threads"?
2726@end quotation
c906108c
SS
2727
2728@cindex focus of debugging
2729@cindex current thread
2730The @value{GDBN} thread debugging facility allows you to observe all
2731threads while your program runs---but whenever @value{GDBN} takes
2732control, one thread in particular is always the focus of debugging.
2733This thread is called the @dfn{current thread}. Debugging commands show
2734program information from the perspective of the current thread.
2735
41afff9a 2736@cindex @code{New} @var{systag} message
c906108c
SS
2737@cindex thread identifier (system)
2738@c FIXME-implementors!! It would be more helpful if the [New...] message
2739@c included GDB's numeric thread handle, so you could just go to that
2740@c thread without first checking `info threads'.
2741Whenever @value{GDBN} detects a new thread in your program, it displays
2742the target system's identification for the thread with a message in the
2743form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2744whose form varies depending on the particular system. For example, on
8807d78b 2745@sc{gnu}/Linux, you might see
c906108c 2746
474c8240 2747@smallexample
08e796bc 2748[New Thread 0x41e02940 (LWP 25582)]
474c8240 2749@end smallexample
c906108c
SS
2750
2751@noindent
2752when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2753the @var{systag} is simply something like @samp{process 368}, with no
2754further qualifier.
2755
2756@c FIXME!! (1) Does the [New...] message appear even for the very first
2757@c thread of a program, or does it only appear for the
6ca652b0 2758@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
2759@c program?
2760@c (2) *Is* there necessarily a first thread always? Or do some
2761@c multithread systems permit starting a program with multiple
5d161b24 2762@c threads ab initio?
c906108c
SS
2763
2764@cindex thread number
2765@cindex thread identifier (GDB)
2766For debugging purposes, @value{GDBN} associates its own thread
2767number---always a single integer---with each thread in your program.
2768
2769@table @code
2770@kindex info threads
60f98dde
MS
2771@item info threads @r{[}@var{id}@dots{}@r{]}
2772Display a summary of all threads currently in your program. Optional
2773argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2774means to print information only about the specified thread or threads.
2775@value{GDBN} displays for each thread (in this order):
c906108c
SS
2776
2777@enumerate
09d4efe1
EZ
2778@item
2779the thread number assigned by @value{GDBN}
c906108c 2780
09d4efe1
EZ
2781@item
2782the target system's thread identifier (@var{systag})
c906108c 2783
4694da01
TT
2784@item
2785the thread's name, if one is known. A thread can either be named by
2786the user (see @code{thread name}, below), or, in some cases, by the
2787program itself.
2788
09d4efe1
EZ
2789@item
2790the current stack frame summary for that thread
c906108c
SS
2791@end enumerate
2792
2793@noindent
2794An asterisk @samp{*} to the left of the @value{GDBN} thread number
2795indicates the current thread.
2796
5d161b24 2797For example,
c906108c
SS
2798@end table
2799@c end table here to get a little more width for example
2800
2801@smallexample
2802(@value{GDBP}) info threads
13fd8b81
TT
2803 Id Target Id Frame
2804 3 process 35 thread 27 0x34e5 in sigpause ()
2805 2 process 35 thread 23 0x34e5 in sigpause ()
2806* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
c906108c
SS
2807 at threadtest.c:68
2808@end smallexample
53a5351d 2809
c45da7e6
EZ
2810On Solaris, you can display more information about user threads with a
2811Solaris-specific command:
2812
2813@table @code
2814@item maint info sol-threads
2815@kindex maint info sol-threads
2816@cindex thread info (Solaris)
2817Display info on Solaris user threads.
2818@end table
2819
c906108c
SS
2820@table @code
2821@kindex thread @var{threadno}
2822@item thread @var{threadno}
2823Make thread number @var{threadno} the current thread. The command
2824argument @var{threadno} is the internal @value{GDBN} thread number, as
2825shown in the first field of the @samp{info threads} display.
2826@value{GDBN} responds by displaying the system identifier of the thread
2827you selected, and its current stack frame summary:
2828
2829@smallexample
c906108c 2830(@value{GDBP}) thread 2
13fd8b81
TT
2831[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2832#0 some_function (ignore=0x0) at example.c:8
28338 printf ("hello\n");
c906108c
SS
2834@end smallexample
2835
2836@noindent
2837As with the @samp{[New @dots{}]} message, the form of the text after
2838@samp{Switching to} depends on your system's conventions for identifying
5d161b24 2839threads.
c906108c 2840
6aed2dbc
SS
2841@vindex $_thread@r{, convenience variable}
2842The debugger convenience variable @samp{$_thread} contains the number
2843of the current thread. You may find this useful in writing breakpoint
2844conditional expressions, command scripts, and so forth. See
2845@xref{Convenience Vars,, Convenience Variables}, for general
2846information on convenience variables.
2847
9c16f35a 2848@kindex thread apply
638ac427 2849@cindex apply command to several threads
13fd8b81 2850@item thread apply [@var{threadno} | all] @var{command}
839c27b7
EZ
2851The @code{thread apply} command allows you to apply the named
2852@var{command} to one or more threads. Specify the numbers of the
2853threads that you want affected with the command argument
2854@var{threadno}. It can be a single thread number, one of the numbers
2855shown in the first field of the @samp{info threads} display; or it
2856could be a range of thread numbers, as in @code{2-4}. To apply a
2857command to all threads, type @kbd{thread apply all @var{command}}.
93815fbf 2858
4694da01
TT
2859@kindex thread name
2860@cindex name a thread
2861@item thread name [@var{name}]
2862This command assigns a name to the current thread. If no argument is
2863given, any existing user-specified name is removed. The thread name
2864appears in the @samp{info threads} display.
2865
2866On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2867determine the name of the thread as given by the OS. On these
2868systems, a name specified with @samp{thread name} will override the
2869system-give name, and removing the user-specified name will cause
2870@value{GDBN} to once again display the system-specified name.
2871
60f98dde
MS
2872@kindex thread find
2873@cindex search for a thread
2874@item thread find [@var{regexp}]
2875Search for and display thread ids whose name or @var{systag}
2876matches the supplied regular expression.
2877
2878As well as being the complement to the @samp{thread name} command,
2879this command also allows you to identify a thread by its target
2880@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
2881is the LWP id.
2882
2883@smallexample
2884(@value{GDBN}) thread find 26688
2885Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2886(@value{GDBN}) info thread 4
2887 Id Target Id Frame
2888 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2889@end smallexample
2890
93815fbf
VP
2891@kindex set print thread-events
2892@cindex print messages on thread start and exit
2893@item set print thread-events
2894@itemx set print thread-events on
2895@itemx set print thread-events off
2896The @code{set print thread-events} command allows you to enable or
2897disable printing of messages when @value{GDBN} notices that new threads have
2898started or that threads have exited. By default, these messages will
2899be printed if detection of these events is supported by the target.
2900Note that these messages cannot be disabled on all targets.
2901
2902@kindex show print thread-events
2903@item show print thread-events
2904Show whether messages will be printed when @value{GDBN} detects that threads
2905have started and exited.
c906108c
SS
2906@end table
2907
79a6e687 2908@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
2909more information about how @value{GDBN} behaves when you stop and start
2910programs with multiple threads.
2911
79a6e687 2912@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 2913watchpoints in programs with multiple threads.
c906108c 2914
bf88dd68 2915@anchor{set libthread-db-search-path}
17a37d48
PP
2916@table @code
2917@kindex set libthread-db-search-path
2918@cindex search path for @code{libthread_db}
2919@item set libthread-db-search-path @r{[}@var{path}@r{]}
2920If this variable is set, @var{path} is a colon-separated list of
2921directories @value{GDBN} will use to search for @code{libthread_db}.
2922If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 2923its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
2924Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
2925macro.
17a37d48
PP
2926
2927On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2928@code{libthread_db} library to obtain information about threads in the
2929inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
2930to find @code{libthread_db}. @value{GDBN} also consults first if inferior
2931specific thread debugging library loading is enabled
2932by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
2933
2934A special entry @samp{$sdir} for @samp{libthread-db-search-path}
2935refers to the default system directories that are
bf88dd68
JK
2936normally searched for loading shared libraries. The @samp{$sdir} entry
2937is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
2938(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
2939
2940A special entry @samp{$pdir} for @samp{libthread-db-search-path}
2941refers to the directory from which @code{libpthread}
2942was loaded in the inferior process.
17a37d48
PP
2943
2944For any @code{libthread_db} library @value{GDBN} finds in above directories,
2945@value{GDBN} attempts to initialize it with the current inferior process.
2946If this initialization fails (which could happen because of a version
2947mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2948will unload @code{libthread_db}, and continue with the next directory.
2949If none of @code{libthread_db} libraries initialize successfully,
2950@value{GDBN} will issue a warning and thread debugging will be disabled.
2951
2952Setting @code{libthread-db-search-path} is currently implemented
2953only on some platforms.
2954
2955@kindex show libthread-db-search-path
2956@item show libthread-db-search-path
2957Display current libthread_db search path.
02d868e8
PP
2958
2959@kindex set debug libthread-db
2960@kindex show debug libthread-db
2961@cindex debugging @code{libthread_db}
2962@item set debug libthread-db
2963@itemx show debug libthread-db
2964Turns on or off display of @code{libthread_db}-related events.
2965Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
2966@end table
2967
6c95b8df
PA
2968@node Forks
2969@section Debugging Forks
c906108c
SS
2970
2971@cindex fork, debugging programs which call
2972@cindex multiple processes
2973@cindex processes, multiple
53a5351d
JM
2974On most systems, @value{GDBN} has no special support for debugging
2975programs which create additional processes using the @code{fork}
2976function. When a program forks, @value{GDBN} will continue to debug the
2977parent process and the child process will run unimpeded. If you have
2978set a breakpoint in any code which the child then executes, the child
2979will get a @code{SIGTRAP} signal which (unless it catches the signal)
2980will cause it to terminate.
c906108c
SS
2981
2982However, if you want to debug the child process there is a workaround
2983which isn't too painful. Put a call to @code{sleep} in the code which
2984the child process executes after the fork. It may be useful to sleep
2985only if a certain environment variable is set, or a certain file exists,
2986so that the delay need not occur when you don't want to run @value{GDBN}
2987on the child. While the child is sleeping, use the @code{ps} program to
2988get its process ID. Then tell @value{GDBN} (a new invocation of
2989@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 2990the child process (@pxref{Attach}). From that point on you can debug
c906108c 2991the child process just like any other process which you attached to.
c906108c 2992
b51970ac
DJ
2993On some systems, @value{GDBN} provides support for debugging programs that
2994create additional processes using the @code{fork} or @code{vfork} functions.
2995Currently, the only platforms with this feature are HP-UX (11.x and later
a6b151f1 2996only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
c906108c
SS
2997
2998By default, when a program forks, @value{GDBN} will continue to debug
2999the parent process and the child process will run unimpeded.
3000
3001If you want to follow the child process instead of the parent process,
3002use the command @w{@code{set follow-fork-mode}}.
3003
3004@table @code
3005@kindex set follow-fork-mode
3006@item set follow-fork-mode @var{mode}
3007Set the debugger response to a program call of @code{fork} or
3008@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3009process. The @var{mode} argument can be:
c906108c
SS
3010
3011@table @code
3012@item parent
3013The original process is debugged after a fork. The child process runs
2df3850c 3014unimpeded. This is the default.
c906108c
SS
3015
3016@item child
3017The new process is debugged after a fork. The parent process runs
3018unimpeded.
3019
c906108c
SS
3020@end table
3021
9c16f35a 3022@kindex show follow-fork-mode
c906108c 3023@item show follow-fork-mode
2df3850c 3024Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3025@end table
3026
5c95884b
MS
3027@cindex debugging multiple processes
3028On Linux, if you want to debug both the parent and child processes, use the
3029command @w{@code{set detach-on-fork}}.
3030
3031@table @code
3032@kindex set detach-on-fork
3033@item set detach-on-fork @var{mode}
3034Tells gdb whether to detach one of the processes after a fork, or
3035retain debugger control over them both.
3036
3037@table @code
3038@item on
3039The child process (or parent process, depending on the value of
3040@code{follow-fork-mode}) will be detached and allowed to run
3041independently. This is the default.
3042
3043@item off
3044Both processes will be held under the control of @value{GDBN}.
3045One process (child or parent, depending on the value of
3046@code{follow-fork-mode}) is debugged as usual, while the other
3047is held suspended.
3048
3049@end table
3050
11310833
NR
3051@kindex show detach-on-fork
3052@item show detach-on-fork
3053Show whether detach-on-fork mode is on/off.
5c95884b
MS
3054@end table
3055
2277426b
PA
3056If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3057will retain control of all forked processes (including nested forks).
3058You can list the forked processes under the control of @value{GDBN} by
3059using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3060to another by using the @code{inferior} command (@pxref{Inferiors and
3061Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3062
3063To quit debugging one of the forked processes, you can either detach
af624141
MS
3064from it by using the @w{@code{detach inferiors}} command (allowing it
3065to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3066command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3067and Programs}.
5c95884b 3068
c906108c
SS
3069If you ask to debug a child process and a @code{vfork} is followed by an
3070@code{exec}, @value{GDBN} executes the new target up to the first
3071breakpoint in the new target. If you have a breakpoint set on
3072@code{main} in your original program, the breakpoint will also be set on
3073the child process's @code{main}.
3074
2277426b
PA
3075On some systems, when a child process is spawned by @code{vfork}, you
3076cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3077
3078If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3079call executes, the new target restarts. To restart the parent
3080process, use the @code{file} command with the parent executable name
3081as its argument. By default, after an @code{exec} call executes,
3082@value{GDBN} discards the symbols of the previous executable image.
3083You can change this behaviour with the @w{@code{set follow-exec-mode}}
3084command.
3085
3086@table @code
3087@kindex set follow-exec-mode
3088@item set follow-exec-mode @var{mode}
3089
3090Set debugger response to a program call of @code{exec}. An
3091@code{exec} call replaces the program image of a process.
3092
3093@code{follow-exec-mode} can be:
3094
3095@table @code
3096@item new
3097@value{GDBN} creates a new inferior and rebinds the process to this
3098new inferior. The program the process was running before the
3099@code{exec} call can be restarted afterwards by restarting the
3100original inferior.
3101
3102For example:
3103
3104@smallexample
3105(@value{GDBP}) info inferiors
3106(gdb) info inferior
3107 Id Description Executable
3108* 1 <null> prog1
3109(@value{GDBP}) run
3110process 12020 is executing new program: prog2
3111Program exited normally.
3112(@value{GDBP}) info inferiors
3113 Id Description Executable
3114* 2 <null> prog2
3115 1 <null> prog1
3116@end smallexample
3117
3118@item same
3119@value{GDBN} keeps the process bound to the same inferior. The new
3120executable image replaces the previous executable loaded in the
3121inferior. Restarting the inferior after the @code{exec} call, with
3122e.g., the @code{run} command, restarts the executable the process was
3123running after the @code{exec} call. This is the default mode.
3124
3125For example:
3126
3127@smallexample
3128(@value{GDBP}) info inferiors
3129 Id Description Executable
3130* 1 <null> prog1
3131(@value{GDBP}) run
3132process 12020 is executing new program: prog2
3133Program exited normally.
3134(@value{GDBP}) info inferiors
3135 Id Description Executable
3136* 1 <null> prog2
3137@end smallexample
3138
3139@end table
3140@end table
c906108c
SS
3141
3142You can use the @code{catch} command to make @value{GDBN} stop whenever
3143a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3144Catchpoints, ,Setting Catchpoints}.
c906108c 3145
5c95884b 3146@node Checkpoint/Restart
79a6e687 3147@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3148
3149@cindex checkpoint
3150@cindex restart
3151@cindex bookmark
3152@cindex snapshot of a process
3153@cindex rewind program state
3154
3155On certain operating systems@footnote{Currently, only
3156@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3157program's state, called a @dfn{checkpoint}, and come back to it
3158later.
3159
3160Returning to a checkpoint effectively undoes everything that has
3161happened in the program since the @code{checkpoint} was saved. This
3162includes changes in memory, registers, and even (within some limits)
3163system state. Effectively, it is like going back in time to the
3164moment when the checkpoint was saved.
3165
3166Thus, if you're stepping thru a program and you think you're
3167getting close to the point where things go wrong, you can save
3168a checkpoint. Then, if you accidentally go too far and miss
3169the critical statement, instead of having to restart your program
3170from the beginning, you can just go back to the checkpoint and
3171start again from there.
3172
3173This can be especially useful if it takes a lot of time or
3174steps to reach the point where you think the bug occurs.
3175
3176To use the @code{checkpoint}/@code{restart} method of debugging:
3177
3178@table @code
3179@kindex checkpoint
3180@item checkpoint
3181Save a snapshot of the debugged program's current execution state.
3182The @code{checkpoint} command takes no arguments, but each checkpoint
3183is assigned a small integer id, similar to a breakpoint id.
3184
3185@kindex info checkpoints
3186@item info checkpoints
3187List the checkpoints that have been saved in the current debugging
3188session. For each checkpoint, the following information will be
3189listed:
3190
3191@table @code
3192@item Checkpoint ID
3193@item Process ID
3194@item Code Address
3195@item Source line, or label
3196@end table
3197
3198@kindex restart @var{checkpoint-id}
3199@item restart @var{checkpoint-id}
3200Restore the program state that was saved as checkpoint number
3201@var{checkpoint-id}. All program variables, registers, stack frames
3202etc.@: will be returned to the values that they had when the checkpoint
3203was saved. In essence, gdb will ``wind back the clock'' to the point
3204in time when the checkpoint was saved.
3205
3206Note that breakpoints, @value{GDBN} variables, command history etc.
3207are not affected by restoring a checkpoint. In general, a checkpoint
3208only restores things that reside in the program being debugged, not in
3209the debugger.
3210
b8db102d
MS
3211@kindex delete checkpoint @var{checkpoint-id}
3212@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3213Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3214
3215@end table
3216
3217Returning to a previously saved checkpoint will restore the user state
3218of the program being debugged, plus a significant subset of the system
3219(OS) state, including file pointers. It won't ``un-write'' data from
3220a file, but it will rewind the file pointer to the previous location,
3221so that the previously written data can be overwritten. For files
3222opened in read mode, the pointer will also be restored so that the
3223previously read data can be read again.
3224
3225Of course, characters that have been sent to a printer (or other
3226external device) cannot be ``snatched back'', and characters received
3227from eg.@: a serial device can be removed from internal program buffers,
3228but they cannot be ``pushed back'' into the serial pipeline, ready to
3229be received again. Similarly, the actual contents of files that have
3230been changed cannot be restored (at this time).
3231
3232However, within those constraints, you actually can ``rewind'' your
3233program to a previously saved point in time, and begin debugging it
3234again --- and you can change the course of events so as to debug a
3235different execution path this time.
3236
3237@cindex checkpoints and process id
3238Finally, there is one bit of internal program state that will be
3239different when you return to a checkpoint --- the program's process
3240id. Each checkpoint will have a unique process id (or @var{pid}),
3241and each will be different from the program's original @var{pid}.
3242If your program has saved a local copy of its process id, this could
3243potentially pose a problem.
3244
79a6e687 3245@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3246
3247On some systems such as @sc{gnu}/Linux, address space randomization
3248is performed on new processes for security reasons. This makes it
3249difficult or impossible to set a breakpoint, or watchpoint, on an
3250absolute address if you have to restart the program, since the
3251absolute location of a symbol will change from one execution to the
3252next.
3253
3254A checkpoint, however, is an @emph{identical} copy of a process.
3255Therefore if you create a checkpoint at (eg.@:) the start of main,
3256and simply return to that checkpoint instead of restarting the
3257process, you can avoid the effects of address randomization and
3258your symbols will all stay in the same place.
3259
6d2ebf8b 3260@node Stopping
c906108c
SS
3261@chapter Stopping and Continuing
3262
3263The principal purposes of using a debugger are so that you can stop your
3264program before it terminates; or so that, if your program runs into
3265trouble, you can investigate and find out why.
3266
7a292a7a
SS
3267Inside @value{GDBN}, your program may stop for any of several reasons,
3268such as a signal, a breakpoint, or reaching a new line after a
3269@value{GDBN} command such as @code{step}. You may then examine and
3270change variables, set new breakpoints or remove old ones, and then
3271continue execution. Usually, the messages shown by @value{GDBN} provide
3272ample explanation of the status of your program---but you can also
3273explicitly request this information at any time.
c906108c
SS
3274
3275@table @code
3276@kindex info program
3277@item info program
3278Display information about the status of your program: whether it is
7a292a7a 3279running or not, what process it is, and why it stopped.
c906108c
SS
3280@end table
3281
3282@menu
3283* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3284* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3285* Skipping Over Functions and Files::
3286 Skipping over functions and files
c906108c 3287* Signals:: Signals
c906108c 3288* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3289@end menu
3290
6d2ebf8b 3291@node Breakpoints
79a6e687 3292@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3293
3294@cindex breakpoints
3295A @dfn{breakpoint} makes your program stop whenever a certain point in
3296the program is reached. For each breakpoint, you can add conditions to
3297control in finer detail whether your program stops. You can set
3298breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3299Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3300should stop by line number, function name or exact address in the
3301program.
3302
09d4efe1
EZ
3303On some systems, you can set breakpoints in shared libraries before
3304the executable is run. There is a minor limitation on HP-UX systems:
3305you must wait until the executable is run in order to set breakpoints
3306in shared library routines that are not called directly by the program
3307(for example, routines that are arguments in a @code{pthread_create}
3308call).
c906108c
SS
3309
3310@cindex watchpoints
fd60e0df 3311@cindex data breakpoints
c906108c
SS
3312@cindex memory tracing
3313@cindex breakpoint on memory address
3314@cindex breakpoint on variable modification
3315A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3316when the value of an expression changes. The expression may be a value
0ced0c34 3317of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3318combined by operators, such as @samp{a + b}. This is sometimes called
3319@dfn{data breakpoints}. You must use a different command to set
79a6e687 3320watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3321from that, you can manage a watchpoint like any other breakpoint: you
3322enable, disable, and delete both breakpoints and watchpoints using the
3323same commands.
c906108c
SS
3324
3325You can arrange to have values from your program displayed automatically
3326whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3327Automatic Display}.
c906108c
SS
3328
3329@cindex catchpoints
3330@cindex breakpoint on events
3331A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3332when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3333exception or the loading of a library. As with watchpoints, you use a
3334different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3335Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3336other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3337@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3338
3339@cindex breakpoint numbers
3340@cindex numbers for breakpoints
3341@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3342catchpoint when you create it; these numbers are successive integers
3343starting with one. In many of the commands for controlling various
3344features of breakpoints you use the breakpoint number to say which
3345breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3346@dfn{disabled}; if disabled, it has no effect on your program until you
3347enable it again.
3348
c5394b80
JM
3349@cindex breakpoint ranges
3350@cindex ranges of breakpoints
3351Some @value{GDBN} commands accept a range of breakpoints on which to
3352operate. A breakpoint range is either a single breakpoint number, like
3353@samp{5}, or two such numbers, in increasing order, separated by a
3354hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
d52fb0e9 3355all breakpoints in that range are operated on.
c5394b80 3356
c906108c
SS
3357@menu
3358* Set Breaks:: Setting breakpoints
3359* Set Watchpoints:: Setting watchpoints
3360* Set Catchpoints:: Setting catchpoints
3361* Delete Breaks:: Deleting breakpoints
3362* Disabling:: Disabling breakpoints
3363* Conditions:: Break conditions
3364* Break Commands:: Breakpoint command lists
e7e0cddf 3365* Dynamic Printf:: Dynamic printf
6149aea9 3366* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3367* Static Probe Points:: Listing static probe points
d4f3574e 3368* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3369* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3370@end menu
3371
6d2ebf8b 3372@node Set Breaks
79a6e687 3373@subsection Setting Breakpoints
c906108c 3374
5d161b24 3375@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3376@c consider in particular declaration with/without initialization.
3377@c
3378@c FIXME 2 is there stuff on this already? break at fun start, already init?
3379
3380@kindex break
41afff9a
EZ
3381@kindex b @r{(@code{break})}
3382@vindex $bpnum@r{, convenience variable}
c906108c
SS
3383@cindex latest breakpoint
3384Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3385@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3386number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3387Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3388convenience variables.
3389
c906108c 3390@table @code
2a25a5ba
EZ
3391@item break @var{location}
3392Set a breakpoint at the given @var{location}, which can specify a
3393function name, a line number, or an address of an instruction.
3394(@xref{Specify Location}, for a list of all the possible ways to
3395specify a @var{location}.) The breakpoint will stop your program just
3396before it executes any of the code in the specified @var{location}.
3397
c906108c 3398When using source languages that permit overloading of symbols, such as
2a25a5ba 3399C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3400@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3401that situation.
c906108c 3402
45ac276d 3403It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3404only if a specific thread (@pxref{Thread-Specific Breakpoints})
3405or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3406
c906108c
SS
3407@item break
3408When called without any arguments, @code{break} sets a breakpoint at
3409the next instruction to be executed in the selected stack frame
3410(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3411innermost, this makes your program stop as soon as control
3412returns to that frame. This is similar to the effect of a
3413@code{finish} command in the frame inside the selected frame---except
3414that @code{finish} does not leave an active breakpoint. If you use
3415@code{break} without an argument in the innermost frame, @value{GDBN} stops
3416the next time it reaches the current location; this may be useful
3417inside loops.
3418
3419@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3420least one instruction has been executed. If it did not do this, you
3421would be unable to proceed past a breakpoint without first disabling the
3422breakpoint. This rule applies whether or not the breakpoint already
3423existed when your program stopped.
3424
3425@item break @dots{} if @var{cond}
3426Set a breakpoint with condition @var{cond}; evaluate the expression
3427@var{cond} each time the breakpoint is reached, and stop only if the
3428value is nonzero---that is, if @var{cond} evaluates as true.
3429@samp{@dots{}} stands for one of the possible arguments described
3430above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3431,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3432
3433@kindex tbreak
3434@item tbreak @var{args}
3435Set a breakpoint enabled only for one stop. @var{args} are the
3436same as for the @code{break} command, and the breakpoint is set in the same
3437way, but the breakpoint is automatically deleted after the first time your
79a6e687 3438program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3439
c906108c 3440@kindex hbreak
ba04e063 3441@cindex hardware breakpoints
c906108c 3442@item hbreak @var{args}
d4f3574e
SS
3443Set a hardware-assisted breakpoint. @var{args} are the same as for the
3444@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3445breakpoint requires hardware support and some target hardware may not
3446have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3447debugging, so you can set a breakpoint at an instruction without
3448changing the instruction. This can be used with the new trap-generation
09d4efe1 3449provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3450will generate traps when a program accesses some data or instruction
3451address that is assigned to the debug registers. However the hardware
3452breakpoint registers can take a limited number of breakpoints. For
3453example, on the DSU, only two data breakpoints can be set at a time, and
3454@value{GDBN} will reject this command if more than two are used. Delete
3455or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3456(@pxref{Disabling, ,Disabling Breakpoints}).
3457@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3458For remote targets, you can restrict the number of hardware
3459breakpoints @value{GDBN} will use, see @ref{set remote
3460hardware-breakpoint-limit}.
501eef12 3461
c906108c
SS
3462@kindex thbreak
3463@item thbreak @var{args}
3464Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3465are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3466the same way. However, like the @code{tbreak} command,
c906108c
SS
3467the breakpoint is automatically deleted after the
3468first time your program stops there. Also, like the @code{hbreak}
5d161b24 3469command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3470may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3471See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3472
3473@kindex rbreak
3474@cindex regular expression
8bd10a10 3475@cindex breakpoints at functions matching a regexp
c45da7e6 3476@cindex set breakpoints in many functions
c906108c 3477@item rbreak @var{regex}
c906108c 3478Set breakpoints on all functions matching the regular expression
11cf8741
JM
3479@var{regex}. This command sets an unconditional breakpoint on all
3480matches, printing a list of all breakpoints it set. Once these
3481breakpoints are set, they are treated just like the breakpoints set with
3482the @code{break} command. You can delete them, disable them, or make
3483them conditional the same way as any other breakpoint.
3484
3485The syntax of the regular expression is the standard one used with tools
3486like @file{grep}. Note that this is different from the syntax used by
3487shells, so for instance @code{foo*} matches all functions that include
3488an @code{fo} followed by zero or more @code{o}s. There is an implicit
3489@code{.*} leading and trailing the regular expression you supply, so to
3490match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3491
f7dc1244 3492@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3493When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3494breakpoints on overloaded functions that are not members of any special
3495classes.
c906108c 3496
f7dc1244
EZ
3497@cindex set breakpoints on all functions
3498The @code{rbreak} command can be used to set breakpoints in
3499@strong{all} the functions in a program, like this:
3500
3501@smallexample
3502(@value{GDBP}) rbreak .
3503@end smallexample
3504
8bd10a10
CM
3505@item rbreak @var{file}:@var{regex}
3506If @code{rbreak} is called with a filename qualification, it limits
3507the search for functions matching the given regular expression to the
3508specified @var{file}. This can be used, for example, to set breakpoints on
3509every function in a given file:
3510
3511@smallexample
3512(@value{GDBP}) rbreak file.c:.
3513@end smallexample
3514
3515The colon separating the filename qualifier from the regex may
3516optionally be surrounded by spaces.
3517
c906108c
SS
3518@kindex info breakpoints
3519@cindex @code{$_} and @code{info breakpoints}
e5a67952
MS
3520@item info breakpoints @r{[}@var{n}@dots{}@r{]}
3521@itemx info break @r{[}@var{n}@dots{}@r{]}
c906108c 3522Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 3523not deleted. Optional argument @var{n} means print information only
e5a67952
MS
3524about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3525For each breakpoint, following columns are printed:
c906108c
SS
3526
3527@table @emph
3528@item Breakpoint Numbers
3529@item Type
3530Breakpoint, watchpoint, or catchpoint.
3531@item Disposition
3532Whether the breakpoint is marked to be disabled or deleted when hit.
3533@item Enabled or Disabled
3534Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 3535that are not enabled.
c906108c 3536@item Address
fe6fbf8b 3537Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
3538pending breakpoint whose address is not yet known, this field will
3539contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3540library that has the symbol or line referred by breakpoint is loaded.
3541See below for details. A breakpoint with several locations will
3b784c4f 3542have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
3543@item What
3544Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
3545line number. For a pending breakpoint, the original string passed to
3546the breakpoint command will be listed as it cannot be resolved until
3547the appropriate shared library is loaded in the future.
c906108c
SS
3548@end table
3549
3550@noindent
83364271
LM
3551If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3552``target''. If mode is ``host'', breakpoint condition evaluation is done by
3553@value{GDBN} on the host's side. If it is ``target'', then the condition
3554is evaluated by the target. The @code{info break} command shows
3555the condition on the line following the affected breakpoint, together with
3556its condition evaluation mode in between parentheses.
3557
3558Breakpoint commands, if any, are listed after that. A pending breakpoint is
3559allowed to have a condition specified for it. The condition is not parsed for
3560validity until a shared library is loaded that allows the pending
3561breakpoint to resolve to a valid location.
c906108c
SS
3562
3563@noindent
3564@code{info break} with a breakpoint
3565number @var{n} as argument lists only that breakpoint. The
3566convenience variable @code{$_} and the default examining-address for
3567the @code{x} command are set to the address of the last breakpoint
79a6e687 3568listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
3569
3570@noindent
3571@code{info break} displays a count of the number of times the breakpoint
3572has been hit. This is especially useful in conjunction with the
3573@code{ignore} command. You can ignore a large number of breakpoint
3574hits, look at the breakpoint info to see how many times the breakpoint
3575was hit, and then run again, ignoring one less than that number. This
3576will get you quickly to the last hit of that breakpoint.
816338b5
SS
3577
3578@noindent
3579For a breakpoints with an enable count (xref) greater than 1,
3580@code{info break} also displays that count.
3581
c906108c
SS
3582@end table
3583
3584@value{GDBN} allows you to set any number of breakpoints at the same place in
3585your program. There is nothing silly or meaningless about this. When
3586the breakpoints are conditional, this is even useful
79a6e687 3587(@pxref{Conditions, ,Break Conditions}).
c906108c 3588
2e9132cc
EZ
3589@cindex multiple locations, breakpoints
3590@cindex breakpoints, multiple locations
fcda367b 3591It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
3592in your program. Examples of this situation are:
3593
3594@itemize @bullet
f8eba3c6
TT
3595@item
3596Multiple functions in the program may have the same name.
3597
fe6fbf8b
VP
3598@item
3599For a C@t{++} constructor, the @value{NGCC} compiler generates several
3600instances of the function body, used in different cases.
3601
3602@item
3603For a C@t{++} template function, a given line in the function can
3604correspond to any number of instantiations.
3605
3606@item
3607For an inlined function, a given source line can correspond to
3608several places where that function is inlined.
fe6fbf8b
VP
3609@end itemize
3610
3611In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 3612the relevant locations.
fe6fbf8b 3613
3b784c4f
EZ
3614A breakpoint with multiple locations is displayed in the breakpoint
3615table using several rows---one header row, followed by one row for
3616each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3617address column. The rows for individual locations contain the actual
3618addresses for locations, and show the functions to which those
3619locations belong. The number column for a location is of the form
fe6fbf8b
VP
3620@var{breakpoint-number}.@var{location-number}.
3621
3622For example:
3b784c4f 3623
fe6fbf8b
VP
3624@smallexample
3625Num Type Disp Enb Address What
36261 breakpoint keep y <MULTIPLE>
3627 stop only if i==1
3628 breakpoint already hit 1 time
36291.1 y 0x080486a2 in void foo<int>() at t.cc:8
36301.2 y 0x080486ca in void foo<double>() at t.cc:8
3631@end smallexample
3632
3633Each location can be individually enabled or disabled by passing
3634@var{breakpoint-number}.@var{location-number} as argument to the
3b784c4f
EZ
3635@code{enable} and @code{disable} commands. Note that you cannot
3636delete the individual locations from the list, you can only delete the
16bfc218 3637entire list of locations that belong to their parent breakpoint (with
3b784c4f
EZ
3638the @kbd{delete @var{num}} command, where @var{num} is the number of
3639the parent breakpoint, 1 in the above example). Disabling or enabling
3640the parent breakpoint (@pxref{Disabling}) affects all of the locations
3641that belong to that breakpoint.
fe6fbf8b 3642
2650777c 3643@cindex pending breakpoints
fe6fbf8b 3644It's quite common to have a breakpoint inside a shared library.
3b784c4f 3645Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
3646and possibly repeatedly, as the program is executed. To support
3647this use case, @value{GDBN} updates breakpoint locations whenever
3648any shared library is loaded or unloaded. Typically, you would
fcda367b 3649set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
3650debugging session, when the library is not loaded, and when the
3651symbols from the library are not available. When you try to set
3652breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 3653a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
3654is not yet resolved.
3655
3656After the program is run, whenever a new shared library is loaded,
3657@value{GDBN} reevaluates all the breakpoints. When a newly loaded
3658shared library contains the symbol or line referred to by some
3659pending breakpoint, that breakpoint is resolved and becomes an
3660ordinary breakpoint. When a library is unloaded, all breakpoints
3661that refer to its symbols or source lines become pending again.
3662
3663This logic works for breakpoints with multiple locations, too. For
3664example, if you have a breakpoint in a C@t{++} template function, and
3665a newly loaded shared library has an instantiation of that template,
3666a new location is added to the list of locations for the breakpoint.
3667
3668Except for having unresolved address, pending breakpoints do not
3669differ from regular breakpoints. You can set conditions or commands,
3670enable and disable them and perform other breakpoint operations.
3671
3672@value{GDBN} provides some additional commands for controlling what
3673happens when the @samp{break} command cannot resolve breakpoint
3674address specification to an address:
dd79a6cf
JJ
3675
3676@kindex set breakpoint pending
3677@kindex show breakpoint pending
3678@table @code
3679@item set breakpoint pending auto
3680This is the default behavior. When @value{GDBN} cannot find the breakpoint
3681location, it queries you whether a pending breakpoint should be created.
3682
3683@item set breakpoint pending on
3684This indicates that an unrecognized breakpoint location should automatically
3685result in a pending breakpoint being created.
3686
3687@item set breakpoint pending off
3688This indicates that pending breakpoints are not to be created. Any
3689unrecognized breakpoint location results in an error. This setting does
3690not affect any pending breakpoints previously created.
3691
3692@item show breakpoint pending
3693Show the current behavior setting for creating pending breakpoints.
3694@end table
2650777c 3695
fe6fbf8b
VP
3696The settings above only affect the @code{break} command and its
3697variants. Once breakpoint is set, it will be automatically updated
3698as shared libraries are loaded and unloaded.
2650777c 3699
765dc015
VP
3700@cindex automatic hardware breakpoints
3701For some targets, @value{GDBN} can automatically decide if hardware or
3702software breakpoints should be used, depending on whether the
3703breakpoint address is read-only or read-write. This applies to
3704breakpoints set with the @code{break} command as well as to internal
3705breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 3706breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
3707breakpoints.
3708
3709You can control this automatic behaviour with the following commands::
3710
3711@kindex set breakpoint auto-hw
3712@kindex show breakpoint auto-hw
3713@table @code
3714@item set breakpoint auto-hw on
3715This is the default behavior. When @value{GDBN} sets a breakpoint, it
3716will try to use the target memory map to decide if software or hardware
3717breakpoint must be used.
3718
3719@item set breakpoint auto-hw off
3720This indicates @value{GDBN} should not automatically select breakpoint
3721type. If the target provides a memory map, @value{GDBN} will warn when
3722trying to set software breakpoint at a read-only address.
3723@end table
3724
74960c60
VP
3725@value{GDBN} normally implements breakpoints by replacing the program code
3726at the breakpoint address with a special instruction, which, when
3727executed, given control to the debugger. By default, the program
3728code is so modified only when the program is resumed. As soon as
3729the program stops, @value{GDBN} restores the original instructions. This
3730behaviour guards against leaving breakpoints inserted in the
3731target should gdb abrubptly disconnect. However, with slow remote
3732targets, inserting and removing breakpoint can reduce the performance.
3733This behavior can be controlled with the following commands::
3734
3735@kindex set breakpoint always-inserted
3736@kindex show breakpoint always-inserted
3737@table @code
3738@item set breakpoint always-inserted off
33e5cbd6
PA
3739All breakpoints, including newly added by the user, are inserted in
3740the target only when the target is resumed. All breakpoints are
3741removed from the target when it stops.
74960c60
VP
3742
3743@item set breakpoint always-inserted on
3744Causes all breakpoints to be inserted in the target at all times. If
3745the user adds a new breakpoint, or changes an existing breakpoint, the
3746breakpoints in the target are updated immediately. A breakpoint is
3747removed from the target only when breakpoint itself is removed.
33e5cbd6
PA
3748
3749@cindex non-stop mode, and @code{breakpoint always-inserted}
3750@item set breakpoint always-inserted auto
3751This is the default mode. If @value{GDBN} is controlling the inferior
3752in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3753@code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3754controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3755@code{breakpoint always-inserted} mode is off.
74960c60 3756@end table
765dc015 3757
83364271
LM
3758@value{GDBN} handles conditional breakpoints by evaluating these conditions
3759when a breakpoint breaks. If the condition is true, then the process being
3760debugged stops, otherwise the process is resumed.
3761
3762If the target supports evaluating conditions on its end, @value{GDBN} may
3763download the breakpoint, together with its conditions, to it.
3764
3765This feature can be controlled via the following commands:
3766
3767@kindex set breakpoint condition-evaluation
3768@kindex show breakpoint condition-evaluation
3769@table @code
3770@item set breakpoint condition-evaluation host
3771This option commands @value{GDBN} to evaluate the breakpoint
3772conditions on the host's side. Unconditional breakpoints are sent to
3773the target which in turn receives the triggers and reports them back to GDB
3774for condition evaluation. This is the standard evaluation mode.
3775
3776@item set breakpoint condition-evaluation target
3777This option commands @value{GDBN} to download breakpoint conditions
3778to the target at the moment of their insertion. The target
3779is responsible for evaluating the conditional expression and reporting
3780breakpoint stop events back to @value{GDBN} whenever the condition
3781is true. Due to limitations of target-side evaluation, some conditions
3782cannot be evaluated there, e.g., conditions that depend on local data
3783that is only known to the host. Examples include
3784conditional expressions involving convenience variables, complex types
3785that cannot be handled by the agent expression parser and expressions
3786that are too long to be sent over to the target, specially when the
3787target is a remote system. In these cases, the conditions will be
3788evaluated by @value{GDBN}.
3789
3790@item set breakpoint condition-evaluation auto
3791This is the default mode. If the target supports evaluating breakpoint
3792conditions on its end, @value{GDBN} will download breakpoint conditions to
3793the target (limitations mentioned previously apply). If the target does
3794not support breakpoint condition evaluation, then @value{GDBN} will fallback
3795to evaluating all these conditions on the host's side.
3796@end table
3797
3798
c906108c
SS
3799@cindex negative breakpoint numbers
3800@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
3801@value{GDBN} itself sometimes sets breakpoints in your program for
3802special purposes, such as proper handling of @code{longjmp} (in C
3803programs). These internal breakpoints are assigned negative numbers,
3804starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 3805You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 3806@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
3807
3808
6d2ebf8b 3809@node Set Watchpoints
79a6e687 3810@subsection Setting Watchpoints
c906108c
SS
3811
3812@cindex setting watchpoints
c906108c
SS
3813You can use a watchpoint to stop execution whenever the value of an
3814expression changes, without having to predict a particular place where
fd60e0df
EZ
3815this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3816The expression may be as simple as the value of a single variable, or
3817as complex as many variables combined by operators. Examples include:
3818
3819@itemize @bullet
3820@item
3821A reference to the value of a single variable.
3822
3823@item
3824An address cast to an appropriate data type. For example,
3825@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3826address (assuming an @code{int} occupies 4 bytes).
3827
3828@item
3829An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3830expression can use any operators valid in the program's native
3831language (@pxref{Languages}).
3832@end itemize
c906108c 3833
fa4727a6
DJ
3834You can set a watchpoint on an expression even if the expression can
3835not be evaluated yet. For instance, you can set a watchpoint on
3836@samp{*global_ptr} before @samp{global_ptr} is initialized.
3837@value{GDBN} will stop when your program sets @samp{global_ptr} and
3838the expression produces a valid value. If the expression becomes
3839valid in some other way than changing a variable (e.g.@: if the memory
3840pointed to by @samp{*global_ptr} becomes readable as the result of a
3841@code{malloc} call), @value{GDBN} may not stop until the next time
3842the expression changes.
3843
82f2d802
EZ
3844@cindex software watchpoints
3845@cindex hardware watchpoints
c906108c 3846Depending on your system, watchpoints may be implemented in software or
2df3850c 3847hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
3848program and testing the variable's value each time, which is hundreds of
3849times slower than normal execution. (But this may still be worth it, to
3850catch errors where you have no clue what part of your program is the
3851culprit.)
3852
37e4754d 3853On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
82f2d802
EZ
3854x86-based targets, @value{GDBN} includes support for hardware
3855watchpoints, which do not slow down the running of your program.
c906108c
SS
3856
3857@table @code
3858@kindex watch
9c06b0b4 3859@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
3860Set a watchpoint for an expression. @value{GDBN} will break when the
3861expression @var{expr} is written into by the program and its value
3862changes. The simplest (and the most popular) use of this command is
3863to watch the value of a single variable:
3864
3865@smallexample
3866(@value{GDBP}) watch foo
3867@end smallexample
c906108c 3868
d8b2a693 3869If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
9c06b0b4 3870argument, @value{GDBN} breaks only when the thread identified by
d8b2a693
JB
3871@var{threadnum} changes the value of @var{expr}. If any other threads
3872change the value of @var{expr}, @value{GDBN} will not break. Note
3873that watchpoints restricted to a single thread in this way only work
3874with Hardware Watchpoints.
3875
06a64a0b
TT
3876Ordinarily a watchpoint respects the scope of variables in @var{expr}
3877(see below). The @code{-location} argument tells @value{GDBN} to
3878instead watch the memory referred to by @var{expr}. In this case,
3879@value{GDBN} will evaluate @var{expr}, take the address of the result,
3880and watch the memory at that address. The type of the result is used
3881to determine the size of the watched memory. If the expression's
3882result does not have an address, then @value{GDBN} will print an
3883error.
3884
9c06b0b4
TJB
3885The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3886of masked watchpoints, if the current architecture supports this
3887feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3888Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
3889to an address to watch. The mask specifies that some bits of an address
3890(the bits which are reset in the mask) should be ignored when matching
3891the address accessed by the inferior against the watchpoint address.
3892Thus, a masked watchpoint watches many addresses simultaneously---those
3893addresses whose unmasked bits are identical to the unmasked bits in the
3894watchpoint address. The @code{mask} argument implies @code{-location}.
3895Examples:
3896
3897@smallexample
3898(@value{GDBP}) watch foo mask 0xffff00ff
3899(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
3900@end smallexample
3901
c906108c 3902@kindex rwatch
9c06b0b4 3903@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
3904Set a watchpoint that will break when the value of @var{expr} is read
3905by the program.
c906108c
SS
3906
3907@kindex awatch
9c06b0b4 3908@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
3909Set a watchpoint that will break when @var{expr} is either read from
3910or written into by the program.
c906108c 3911
e5a67952
MS
3912@kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
3913@item info watchpoints @r{[}@var{n}@dots{}@r{]}
d77f58be
SS
3914This command prints a list of watchpoints, using the same format as
3915@code{info break} (@pxref{Set Breaks}).
c906108c
SS
3916@end table
3917
65d79d4b
SDJ
3918If you watch for a change in a numerically entered address you need to
3919dereference it, as the address itself is just a constant number which will
3920never change. @value{GDBN} refuses to create a watchpoint that watches
3921a never-changing value:
3922
3923@smallexample
3924(@value{GDBP}) watch 0x600850
3925Cannot watch constant value 0x600850.
3926(@value{GDBP}) watch *(int *) 0x600850
3927Watchpoint 1: *(int *) 6293584
3928@end smallexample
3929
c906108c
SS
3930@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3931watchpoints execute very quickly, and the debugger reports a change in
3932value at the exact instruction where the change occurs. If @value{GDBN}
3933cannot set a hardware watchpoint, it sets a software watchpoint, which
3934executes more slowly and reports the change in value at the next
82f2d802
EZ
3935@emph{statement}, not the instruction, after the change occurs.
3936
82f2d802
EZ
3937@cindex use only software watchpoints
3938You can force @value{GDBN} to use only software watchpoints with the
3939@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3940zero, @value{GDBN} will never try to use hardware watchpoints, even if
3941the underlying system supports them. (Note that hardware-assisted
3942watchpoints that were set @emph{before} setting
3943@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 3944mechanism of watching expression values.)
c906108c 3945
9c16f35a
EZ
3946@table @code
3947@item set can-use-hw-watchpoints
3948@kindex set can-use-hw-watchpoints
3949Set whether or not to use hardware watchpoints.
3950
3951@item show can-use-hw-watchpoints
3952@kindex show can-use-hw-watchpoints
3953Show the current mode of using hardware watchpoints.
3954@end table
3955
3956For remote targets, you can restrict the number of hardware
3957watchpoints @value{GDBN} will use, see @ref{set remote
3958hardware-breakpoint-limit}.
3959
c906108c
SS
3960When you issue the @code{watch} command, @value{GDBN} reports
3961
474c8240 3962@smallexample
c906108c 3963Hardware watchpoint @var{num}: @var{expr}
474c8240 3964@end smallexample
c906108c
SS
3965
3966@noindent
3967if it was able to set a hardware watchpoint.
3968
7be570e7
JM
3969Currently, the @code{awatch} and @code{rwatch} commands can only set
3970hardware watchpoints, because accesses to data that don't change the
3971value of the watched expression cannot be detected without examining
3972every instruction as it is being executed, and @value{GDBN} does not do
3973that currently. If @value{GDBN} finds that it is unable to set a
3974hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3975will print a message like this:
3976
3977@smallexample
3978Expression cannot be implemented with read/access watchpoint.
3979@end smallexample
3980
3981Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3982data type of the watched expression is wider than what a hardware
3983watchpoint on the target machine can handle. For example, some systems
3984can only watch regions that are up to 4 bytes wide; on such systems you
3985cannot set hardware watchpoints for an expression that yields a
3986double-precision floating-point number (which is typically 8 bytes
3987wide). As a work-around, it might be possible to break the large region
3988into a series of smaller ones and watch them with separate watchpoints.
3989
3990If you set too many hardware watchpoints, @value{GDBN} might be unable
3991to insert all of them when you resume the execution of your program.
3992Since the precise number of active watchpoints is unknown until such
3993time as the program is about to be resumed, @value{GDBN} might not be
3994able to warn you about this when you set the watchpoints, and the
3995warning will be printed only when the program is resumed:
3996
3997@smallexample
3998Hardware watchpoint @var{num}: Could not insert watchpoint
3999@end smallexample
4000
4001@noindent
4002If this happens, delete or disable some of the watchpoints.
4003
fd60e0df
EZ
4004Watching complex expressions that reference many variables can also
4005exhaust the resources available for hardware-assisted watchpoints.
4006That's because @value{GDBN} needs to watch every variable in the
4007expression with separately allocated resources.
4008
c906108c 4009If you call a function interactively using @code{print} or @code{call},
2df3850c 4010any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4011kind of breakpoint or the call completes.
4012
7be570e7
JM
4013@value{GDBN} automatically deletes watchpoints that watch local
4014(automatic) variables, or expressions that involve such variables, when
4015they go out of scope, that is, when the execution leaves the block in
4016which these variables were defined. In particular, when the program
4017being debugged terminates, @emph{all} local variables go out of scope,
4018and so only watchpoints that watch global variables remain set. If you
4019rerun the program, you will need to set all such watchpoints again. One
4020way of doing that would be to set a code breakpoint at the entry to the
4021@code{main} function and when it breaks, set all the watchpoints.
4022
c906108c
SS
4023@cindex watchpoints and threads
4024@cindex threads and watchpoints
d983da9c
DJ
4025In multi-threaded programs, watchpoints will detect changes to the
4026watched expression from every thread.
4027
4028@quotation
4029@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4030have only limited usefulness. If @value{GDBN} creates a software
4031watchpoint, it can only watch the value of an expression @emph{in a
4032single thread}. If you are confident that the expression can only
4033change due to the current thread's activity (and if you are also
4034confident that no other thread can become current), then you can use
4035software watchpoints as usual. However, @value{GDBN} may not notice
4036when a non-current thread's activity changes the expression. (Hardware
4037watchpoints, in contrast, watch an expression in all threads.)
c906108c 4038@end quotation
c906108c 4039
501eef12
AC
4040@xref{set remote hardware-watchpoint-limit}.
4041
6d2ebf8b 4042@node Set Catchpoints
79a6e687 4043@subsection Setting Catchpoints
d4f3574e 4044@cindex catchpoints, setting
c906108c
SS
4045@cindex exception handlers
4046@cindex event handling
4047
4048You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4049kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4050shared library. Use the @code{catch} command to set a catchpoint.
4051
4052@table @code
4053@kindex catch
4054@item catch @var{event}
4055Stop when @var{event} occurs. @var{event} can be any of the following:
4056@table @code
4057@item throw
4644b6e3 4058@cindex stop on C@t{++} exceptions
b37052ae 4059The throwing of a C@t{++} exception.
c906108c
SS
4060
4061@item catch
b37052ae 4062The catching of a C@t{++} exception.
c906108c 4063
8936fcda
JB
4064@item exception
4065@cindex Ada exception catching
4066@cindex catch Ada exceptions
4067An Ada exception being raised. If an exception name is specified
4068at the end of the command (eg @code{catch exception Program_Error}),
4069the debugger will stop only when this specific exception is raised.
4070Otherwise, the debugger stops execution when any Ada exception is raised.
4071
87f67dba
JB
4072When inserting an exception catchpoint on a user-defined exception whose
4073name is identical to one of the exceptions defined by the language, the
4074fully qualified name must be used as the exception name. Otherwise,
4075@value{GDBN} will assume that it should stop on the pre-defined exception
4076rather than the user-defined one. For instance, assuming an exception
4077called @code{Constraint_Error} is defined in package @code{Pck}, then
4078the command to use to catch such exceptions is @kbd{catch exception
4079Pck.Constraint_Error}.
4080
8936fcda
JB
4081@item exception unhandled
4082An exception that was raised but is not handled by the program.
4083
4084@item assert
4085A failed Ada assertion.
4086
c906108c 4087@item exec
4644b6e3 4088@cindex break on fork/exec
5ee187d7
DJ
4089A call to @code{exec}. This is currently only available for HP-UX
4090and @sc{gnu}/Linux.
c906108c 4091
a96d9b2e 4092@item syscall
ee8e71d4 4093@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
a96d9b2e
SDJ
4094@cindex break on a system call.
4095A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4096syscall is a mechanism for application programs to request a service
4097from the operating system (OS) or one of the OS system services.
4098@value{GDBN} can catch some or all of the syscalls issued by the
4099debuggee, and show the related information for each syscall. If no
4100argument is specified, calls to and returns from all system calls
4101will be caught.
4102
4103@var{name} can be any system call name that is valid for the
4104underlying OS. Just what syscalls are valid depends on the OS. On
4105GNU and Unix systems, you can find the full list of valid syscall
4106names on @file{/usr/include/asm/unistd.h}.
4107
4108@c For MS-Windows, the syscall names and the corresponding numbers
4109@c can be found, e.g., on this URL:
4110@c http://www.metasploit.com/users/opcode/syscalls.html
4111@c but we don't support Windows syscalls yet.
4112
4113Normally, @value{GDBN} knows in advance which syscalls are valid for
4114each OS, so you can use the @value{GDBN} command-line completion
4115facilities (@pxref{Completion,, command completion}) to list the
4116available choices.
4117
4118You may also specify the system call numerically. A syscall's
4119number is the value passed to the OS's syscall dispatcher to
4120identify the requested service. When you specify the syscall by its
4121name, @value{GDBN} uses its database of syscalls to convert the name
4122into the corresponding numeric code, but using the number directly
4123may be useful if @value{GDBN}'s database does not have the complete
4124list of syscalls on your system (e.g., because @value{GDBN} lags
4125behind the OS upgrades).
4126
4127The example below illustrates how this command works if you don't provide
4128arguments to it:
4129
4130@smallexample
4131(@value{GDBP}) catch syscall
4132Catchpoint 1 (syscall)
4133(@value{GDBP}) r
4134Starting program: /tmp/catch-syscall
4135
4136Catchpoint 1 (call to syscall 'close'), \
4137 0xffffe424 in __kernel_vsyscall ()
4138(@value{GDBP}) c
4139Continuing.
4140
4141Catchpoint 1 (returned from syscall 'close'), \
4142 0xffffe424 in __kernel_vsyscall ()
4143(@value{GDBP})
4144@end smallexample
4145
4146Here is an example of catching a system call by name:
4147
4148@smallexample
4149(@value{GDBP}) catch syscall chroot
4150Catchpoint 1 (syscall 'chroot' [61])
4151(@value{GDBP}) r
4152Starting program: /tmp/catch-syscall
4153
4154Catchpoint 1 (call to syscall 'chroot'), \
4155 0xffffe424 in __kernel_vsyscall ()
4156(@value{GDBP}) c
4157Continuing.
4158
4159Catchpoint 1 (returned from syscall 'chroot'), \
4160 0xffffe424 in __kernel_vsyscall ()
4161(@value{GDBP})
4162@end smallexample
4163
4164An example of specifying a system call numerically. In the case
4165below, the syscall number has a corresponding entry in the XML
4166file, so @value{GDBN} finds its name and prints it:
4167
4168@smallexample
4169(@value{GDBP}) catch syscall 252
4170Catchpoint 1 (syscall(s) 'exit_group')
4171(@value{GDBP}) r
4172Starting program: /tmp/catch-syscall
4173
4174Catchpoint 1 (call to syscall 'exit_group'), \
4175 0xffffe424 in __kernel_vsyscall ()
4176(@value{GDBP}) c
4177Continuing.
4178
4179Program exited normally.
4180(@value{GDBP})
4181@end smallexample
4182
4183However, there can be situations when there is no corresponding name
4184in XML file for that syscall number. In this case, @value{GDBN} prints
4185a warning message saying that it was not able to find the syscall name,
4186but the catchpoint will be set anyway. See the example below:
4187
4188@smallexample
4189(@value{GDBP}) catch syscall 764
4190warning: The number '764' does not represent a known syscall.
4191Catchpoint 2 (syscall 764)
4192(@value{GDBP})
4193@end smallexample
4194
4195If you configure @value{GDBN} using the @samp{--without-expat} option,
4196it will not be able to display syscall names. Also, if your
4197architecture does not have an XML file describing its system calls,
4198you will not be able to see the syscall names. It is important to
4199notice that these two features are used for accessing the syscall
4200name database. In either case, you will see a warning like this:
4201
4202@smallexample
4203(@value{GDBP}) catch syscall
4204warning: Could not open "syscalls/i386-linux.xml"
4205warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4206GDB will not be able to display syscall names.
4207Catchpoint 1 (syscall)
4208(@value{GDBP})
4209@end smallexample
4210
4211Of course, the file name will change depending on your architecture and system.
4212
4213Still using the example above, you can also try to catch a syscall by its
4214number. In this case, you would see something like:
4215
4216@smallexample
4217(@value{GDBP}) catch syscall 252
4218Catchpoint 1 (syscall(s) 252)
4219@end smallexample
4220
4221Again, in this case @value{GDBN} would not be able to display syscall's names.
4222
c906108c 4223@item fork
5ee187d7
DJ
4224A call to @code{fork}. This is currently only available for HP-UX
4225and @sc{gnu}/Linux.
c906108c
SS
4226
4227@item vfork
5ee187d7
DJ
4228A call to @code{vfork}. This is currently only available for HP-UX
4229and @sc{gnu}/Linux.
c906108c 4230
edcc5120
TT
4231@item load @r{[}regexp@r{]}
4232@itemx unload @r{[}regexp@r{]}
4233The loading or unloading of a shared library. If @var{regexp} is
4234given, then the catchpoint will stop only if the regular expression
4235matches one of the affected libraries.
4236
c906108c
SS
4237@end table
4238
4239@item tcatch @var{event}
4240Set a catchpoint that is enabled only for one stop. The catchpoint is
4241automatically deleted after the first time the event is caught.
4242
4243@end table
4244
4245Use the @code{info break} command to list the current catchpoints.
4246
b37052ae 4247There are currently some limitations to C@t{++} exception handling
c906108c
SS
4248(@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4249
4250@itemize @bullet
4251@item
4252If you call a function interactively, @value{GDBN} normally returns
4253control to you when the function has finished executing. If the call
4254raises an exception, however, the call may bypass the mechanism that
4255returns control to you and cause your program either to abort or to
4256simply continue running until it hits a breakpoint, catches a signal
4257that @value{GDBN} is listening for, or exits. This is the case even if
4258you set a catchpoint for the exception; catchpoints on exceptions are
4259disabled within interactive calls.
4260
4261@item
4262You cannot raise an exception interactively.
4263
4264@item
4265You cannot install an exception handler interactively.
4266@end itemize
4267
4268@cindex raise exceptions
4269Sometimes @code{catch} is not the best way to debug exception handling:
4270if you need to know exactly where an exception is raised, it is better to
4271stop @emph{before} the exception handler is called, since that way you
4272can see the stack before any unwinding takes place. If you set a
4273breakpoint in an exception handler instead, it may not be easy to find
4274out where the exception was raised.
4275
4276To stop just before an exception handler is called, you need some
b37052ae 4277knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
c906108c
SS
4278raised by calling a library function named @code{__raise_exception}
4279which has the following ANSI C interface:
4280
474c8240 4281@smallexample
c906108c 4282 /* @var{addr} is where the exception identifier is stored.
d4f3574e
SS
4283 @var{id} is the exception identifier. */
4284 void __raise_exception (void **addr, void *id);
474c8240 4285@end smallexample
c906108c
SS
4286
4287@noindent
4288To make the debugger catch all exceptions before any stack
4289unwinding takes place, set a breakpoint on @code{__raise_exception}
79a6e687 4290(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
c906108c 4291
79a6e687 4292With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
c906108c
SS
4293that depends on the value of @var{id}, you can stop your program when
4294a specific exception is raised. You can use multiple conditional
4295breakpoints to stop your program when any of a number of exceptions are
4296raised.
4297
4298
6d2ebf8b 4299@node Delete Breaks
79a6e687 4300@subsection Deleting Breakpoints
c906108c
SS
4301
4302@cindex clearing breakpoints, watchpoints, catchpoints
4303@cindex deleting breakpoints, watchpoints, catchpoints
4304It is often necessary to eliminate a breakpoint, watchpoint, or
4305catchpoint once it has done its job and you no longer want your program
4306to stop there. This is called @dfn{deleting} the breakpoint. A
4307breakpoint that has been deleted no longer exists; it is forgotten.
4308
4309With the @code{clear} command you can delete breakpoints according to
4310where they are in your program. With the @code{delete} command you can
4311delete individual breakpoints, watchpoints, or catchpoints by specifying
4312their breakpoint numbers.
4313
4314It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4315automatically ignores breakpoints on the first instruction to be executed
4316when you continue execution without changing the execution address.
4317
4318@table @code
4319@kindex clear
4320@item clear
4321Delete any breakpoints at the next instruction to be executed in the
79a6e687 4322selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4323the innermost frame is selected, this is a good way to delete a
4324breakpoint where your program just stopped.
4325
2a25a5ba
EZ
4326@item clear @var{location}
4327Delete any breakpoints set at the specified @var{location}.
4328@xref{Specify Location}, for the various forms of @var{location}; the
4329most useful ones are listed below:
4330
4331@table @code
c906108c
SS
4332@item clear @var{function}
4333@itemx clear @var{filename}:@var{function}
09d4efe1 4334Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4335
4336@item clear @var{linenum}
4337@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4338Delete any breakpoints set at or within the code of the specified
4339@var{linenum} of the specified @var{filename}.
2a25a5ba 4340@end table
c906108c
SS
4341
4342@cindex delete breakpoints
4343@kindex delete
41afff9a 4344@kindex d @r{(@code{delete})}
c5394b80
JM
4345@item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4346Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4347ranges specified as arguments. If no argument is specified, delete all
c906108c
SS
4348breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4349confirm off}). You can abbreviate this command as @code{d}.
4350@end table
4351
6d2ebf8b 4352@node Disabling
79a6e687 4353@subsection Disabling Breakpoints
c906108c 4354
4644b6e3 4355@cindex enable/disable a breakpoint
c906108c
SS
4356Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4357prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4358it had been deleted, but remembers the information on the breakpoint so
4359that you can @dfn{enable} it again later.
4360
4361You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4362the @code{enable} and @code{disable} commands, optionally specifying
4363one or more breakpoint numbers as arguments. Use @code{info break} to
4364print a list of all breakpoints, watchpoints, and catchpoints if you
4365do not know which numbers to use.
c906108c 4366
3b784c4f
EZ
4367Disabling and enabling a breakpoint that has multiple locations
4368affects all of its locations.
4369
816338b5
SS
4370A breakpoint, watchpoint, or catchpoint can have any of several
4371different states of enablement:
c906108c
SS
4372
4373@itemize @bullet
4374@item
4375Enabled. The breakpoint stops your program. A breakpoint set
4376with the @code{break} command starts out in this state.
4377@item
4378Disabled. The breakpoint has no effect on your program.
4379@item
4380Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4381disabled.
c906108c 4382@item
816338b5
SS
4383Enabled for a count. The breakpoint stops your program for the next
4384N times, then becomes disabled.
4385@item
c906108c 4386Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4387immediately after it does so it is deleted permanently. A breakpoint
4388set with the @code{tbreak} command starts out in this state.
c906108c
SS
4389@end itemize
4390
4391You can use the following commands to enable or disable breakpoints,
4392watchpoints, and catchpoints:
4393
4394@table @code
c906108c 4395@kindex disable
41afff9a 4396@kindex dis @r{(@code{disable})}
c5394b80 4397@item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4398Disable the specified breakpoints---or all breakpoints, if none are
4399listed. A disabled breakpoint has no effect but is not forgotten. All
4400options such as ignore-counts, conditions and commands are remembered in
4401case the breakpoint is enabled again later. You may abbreviate
4402@code{disable} as @code{dis}.
4403
c906108c 4404@kindex enable
c5394b80 4405@item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4406Enable the specified breakpoints (or all defined breakpoints). They
4407become effective once again in stopping your program.
4408
c5394b80 4409@item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
c906108c
SS
4410Enable the specified breakpoints temporarily. @value{GDBN} disables any
4411of these breakpoints immediately after stopping your program.
4412
816338b5
SS
4413@item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4414Enable the specified breakpoints temporarily. @value{GDBN} records
4415@var{count} with each of the specified breakpoints, and decrements a
4416breakpoint's count when it is hit. When any count reaches 0,
4417@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4418count (@pxref{Conditions, ,Break Conditions}), that will be
4419decremented to 0 before @var{count} is affected.
4420
c5394b80 4421@item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
c906108c
SS
4422Enable the specified breakpoints to work once, then die. @value{GDBN}
4423deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4424Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4425@end table
4426
d4f3574e
SS
4427@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4428@c confusing: tbreak is also initially enabled.
c906108c 4429Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 4430,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
4431subsequently, they become disabled or enabled only when you use one of
4432the commands above. (The command @code{until} can set and delete a
4433breakpoint of its own, but it does not change the state of your other
4434breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 4435Stepping}.)
c906108c 4436
6d2ebf8b 4437@node Conditions
79a6e687 4438@subsection Break Conditions
c906108c
SS
4439@cindex conditional breakpoints
4440@cindex breakpoint conditions
4441
4442@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 4443@c in particular for a watchpoint?
c906108c
SS
4444The simplest sort of breakpoint breaks every time your program reaches a
4445specified place. You can also specify a @dfn{condition} for a
4446breakpoint. A condition is just a Boolean expression in your
4447programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4448a condition evaluates the expression each time your program reaches it,
4449and your program stops only if the condition is @emph{true}.
4450
4451This is the converse of using assertions for program validation; in that
4452situation, you want to stop when the assertion is violated---that is,
4453when the condition is false. In C, if you want to test an assertion expressed
4454by the condition @var{assert}, you should set the condition
4455@samp{! @var{assert}} on the appropriate breakpoint.
4456
4457Conditions are also accepted for watchpoints; you may not need them,
4458since a watchpoint is inspecting the value of an expression anyhow---but
4459it might be simpler, say, to just set a watchpoint on a variable name,
4460and specify a condition that tests whether the new value is an interesting
4461one.
4462
4463Break conditions can have side effects, and may even call functions in
4464your program. This can be useful, for example, to activate functions
4465that log program progress, or to use your own print functions to
99e008fe 4466format special data structures. The effects are completely predictable
c906108c
SS
4467unless there is another enabled breakpoint at the same address. (In
4468that case, @value{GDBN} might see the other breakpoint first and stop your
4469program without checking the condition of this one.) Note that
d4f3574e
SS
4470breakpoint commands are usually more convenient and flexible than break
4471conditions for the
c906108c 4472purpose of performing side effects when a breakpoint is reached
79a6e687 4473(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 4474
83364271
LM
4475Breakpoint conditions can also be evaluated on the target's side if
4476the target supports it. Instead of evaluating the conditions locally,
4477@value{GDBN} encodes the expression into an agent expression
4478(@pxref{Agent Expressions}) suitable for execution on the target,
4479independently of @value{GDBN}. Global variables become raw memory
4480locations, locals become stack accesses, and so forth.
4481
4482In this case, @value{GDBN} will only be notified of a breakpoint trigger
4483when its condition evaluates to true. This mechanism may provide faster
4484response times depending on the performance characteristics of the target
4485since it does not need to keep @value{GDBN} informed about
4486every breakpoint trigger, even those with false conditions.
4487
c906108c
SS
4488Break conditions can be specified when a breakpoint is set, by using
4489@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 4490Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 4491with the @code{condition} command.
53a5351d 4492
c906108c
SS
4493You can also use the @code{if} keyword with the @code{watch} command.
4494The @code{catch} command does not recognize the @code{if} keyword;
4495@code{condition} is the only way to impose a further condition on a
4496catchpoint.
c906108c
SS
4497
4498@table @code
4499@kindex condition
4500@item condition @var{bnum} @var{expression}
4501Specify @var{expression} as the break condition for breakpoint,
4502watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4503breakpoint @var{bnum} stops your program only if the value of
4504@var{expression} is true (nonzero, in C). When you use
4505@code{condition}, @value{GDBN} checks @var{expression} immediately for
4506syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
4507referents in the context of your breakpoint. If @var{expression} uses
4508symbols not referenced in the context of the breakpoint, @value{GDBN}
4509prints an error message:
4510
474c8240 4511@smallexample
d4f3574e 4512No symbol "foo" in current context.
474c8240 4513@end smallexample
d4f3574e
SS
4514
4515@noindent
c906108c
SS
4516@value{GDBN} does
4517not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
4518command (or a command that sets a breakpoint with a condition, like
4519@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
4520
4521@item condition @var{bnum}
4522Remove the condition from breakpoint number @var{bnum}. It becomes
4523an ordinary unconditional breakpoint.
4524@end table
4525
4526@cindex ignore count (of breakpoint)
4527A special case of a breakpoint condition is to stop only when the
4528breakpoint has been reached a certain number of times. This is so
4529useful that there is a special way to do it, using the @dfn{ignore
4530count} of the breakpoint. Every breakpoint has an ignore count, which
4531is an integer. Most of the time, the ignore count is zero, and
4532therefore has no effect. But if your program reaches a breakpoint whose
4533ignore count is positive, then instead of stopping, it just decrements
4534the ignore count by one and continues. As a result, if the ignore count
4535value is @var{n}, the breakpoint does not stop the next @var{n} times
4536your program reaches it.
4537
4538@table @code
4539@kindex ignore
4540@item ignore @var{bnum} @var{count}
4541Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4542The next @var{count} times the breakpoint is reached, your program's
4543execution does not stop; other than to decrement the ignore count, @value{GDBN}
4544takes no action.
4545
4546To make the breakpoint stop the next time it is reached, specify
4547a count of zero.
4548
4549When you use @code{continue} to resume execution of your program from a
4550breakpoint, you can specify an ignore count directly as an argument to
4551@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 4552Stepping,,Continuing and Stepping}.
c906108c
SS
4553
4554If a breakpoint has a positive ignore count and a condition, the
4555condition is not checked. Once the ignore count reaches zero,
4556@value{GDBN} resumes checking the condition.
4557
4558You could achieve the effect of the ignore count with a condition such
4559as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4560is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 4561Variables}.
c906108c
SS
4562@end table
4563
4564Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4565
4566
6d2ebf8b 4567@node Break Commands
79a6e687 4568@subsection Breakpoint Command Lists
c906108c
SS
4569
4570@cindex breakpoint commands
4571You can give any breakpoint (or watchpoint or catchpoint) a series of
4572commands to execute when your program stops due to that breakpoint. For
4573example, you might want to print the values of certain expressions, or
4574enable other breakpoints.
4575
4576@table @code
4577@kindex commands
ca91424e 4578@kindex end@r{ (breakpoint commands)}
95a42b64 4579@item commands @r{[}@var{range}@dots{}@r{]}
c906108c
SS
4580@itemx @dots{} @var{command-list} @dots{}
4581@itemx end
95a42b64 4582Specify a list of commands for the given breakpoints. The commands
c906108c
SS
4583themselves appear on the following lines. Type a line containing just
4584@code{end} to terminate the commands.
4585
4586To remove all commands from a breakpoint, type @code{commands} and
4587follow it immediately with @code{end}; that is, give no commands.
4588
95a42b64
TT
4589With no argument, @code{commands} refers to the last breakpoint,
4590watchpoint, or catchpoint set (not to the breakpoint most recently
4591encountered). If the most recent breakpoints were set with a single
4592command, then the @code{commands} will apply to all the breakpoints
4593set by that command. This applies to breakpoints set by
86b17b60
PA
4594@code{rbreak}, and also applies when a single @code{break} command
4595creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4596Expressions}).
c906108c
SS
4597@end table
4598
4599Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4600disabled within a @var{command-list}.
4601
4602You can use breakpoint commands to start your program up again. Simply
4603use the @code{continue} command, or @code{step}, or any other command
4604that resumes execution.
4605
4606Any other commands in the command list, after a command that resumes
4607execution, are ignored. This is because any time you resume execution
4608(even with a simple @code{next} or @code{step}), you may encounter
4609another breakpoint---which could have its own command list, leading to
4610ambiguities about which list to execute.
4611
4612@kindex silent
4613If the first command you specify in a command list is @code{silent}, the
4614usual message about stopping at a breakpoint is not printed. This may
4615be desirable for breakpoints that are to print a specific message and
4616then continue. If none of the remaining commands print anything, you
4617see no sign that the breakpoint was reached. @code{silent} is
4618meaningful only at the beginning of a breakpoint command list.
4619
4620The commands @code{echo}, @code{output}, and @code{printf} allow you to
4621print precisely controlled output, and are often useful in silent
79a6e687 4622breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
4623
4624For example, here is how you could use breakpoint commands to print the
4625value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4626
474c8240 4627@smallexample
c906108c
SS
4628break foo if x>0
4629commands
4630silent
4631printf "x is %d\n",x
4632cont
4633end
474c8240 4634@end smallexample
c906108c
SS
4635
4636One application for breakpoint commands is to compensate for one bug so
4637you can test for another. Put a breakpoint just after the erroneous line
4638of code, give it a condition to detect the case in which something
4639erroneous has been done, and give it commands to assign correct values
4640to any variables that need them. End with the @code{continue} command
4641so that your program does not stop, and start with the @code{silent}
4642command so that no output is produced. Here is an example:
4643
474c8240 4644@smallexample
c906108c
SS
4645break 403
4646commands
4647silent
4648set x = y + 4
4649cont
4650end
474c8240 4651@end smallexample
c906108c 4652
e7e0cddf
SS
4653@node Dynamic Printf
4654@subsection Dynamic Printf
4655
4656@cindex dynamic printf
4657@cindex dprintf
4658The dynamic printf command @code{dprintf} combines a breakpoint with
4659formatted printing of your program's data to give you the effect of
4660inserting @code{printf} calls into your program on-the-fly, without
4661having to recompile it.
4662
4663In its most basic form, the output goes to the GDB console. However,
4664you can set the variable @code{dprintf-style} for alternate handling.
4665For instance, you can ask to format the output by calling your
4666program's @code{printf} function. This has the advantage that the
4667characters go to the program's output device, so they can recorded in
4668redirects to files and so forth.
4669
d3ce09f5
SS
4670If you are doing remote debugging with a stub or agent, you can also
4671ask to have the printf handled by the remote agent. In addition to
4672ensuring that the output goes to the remote program's device along
4673with any other output the program might produce, you can also ask that
4674the dprintf remain active even after disconnecting from the remote
4675target. Using the stub/agent is also more efficient, as it can do
4676everything without needing to communicate with @value{GDBN}.
4677
e7e0cddf
SS
4678@table @code
4679@kindex dprintf
4680@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4681Whenever execution reaches @var{location}, print the values of one or
4682more @var{expressions} under the control of the string @var{template}.
4683To print several values, separate them with commas.
4684
4685@item set dprintf-style @var{style}
4686Set the dprintf output to be handled in one of several different
4687styles enumerated below. A change of style affects all existing
4688dynamic printfs immediately. (If you need individual control over the
4689print commands, simply define normal breakpoints with
4690explicitly-supplied command lists.)
4691
4692@item gdb
4693@kindex dprintf-style gdb
4694Handle the output using the @value{GDBN} @code{printf} command.
4695
4696@item call
4697@kindex dprintf-style call
4698Handle the output by calling a function in your program (normally
4699@code{printf}).
4700
d3ce09f5
SS
4701@item agent
4702@kindex dprintf-style agent
4703Have the remote debugging agent (such as @code{gdbserver}) handle
4704the output itself. This style is only available for agents that
4705support running commands on the target.
4706
e7e0cddf
SS
4707@item set dprintf-function @var{function}
4708Set the function to call if the dprintf style is @code{call}. By
4709default its value is @code{printf}. You may set it to any expression.
4710that @value{GDBN} can evaluate to a function, as per the @code{call}
4711command.
4712
4713@item set dprintf-channel @var{channel}
4714Set a ``channel'' for dprintf. If set to a non-empty value,
4715@value{GDBN} will evaluate it as an expression and pass the result as
4716a first argument to the @code{dprintf-function}, in the manner of
4717@code{fprintf} and similar functions. Otherwise, the dprintf format
4718string will be the first argument, in the manner of @code{printf}.
4719
4720As an example, if you wanted @code{dprintf} output to go to a logfile
4721that is a standard I/O stream assigned to the variable @code{mylog},
4722you could do the following:
4723
4724@example
4725(gdb) set dprintf-style call
4726(gdb) set dprintf-function fprintf
4727(gdb) set dprintf-channel mylog
4728(gdb) dprintf 25,"at line 25, glob=%d\n",glob
4729Dprintf 1 at 0x123456: file main.c, line 25.
4730(gdb) info break
47311 dprintf keep y 0x00123456 in main at main.c:25
4732 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4733 continue
4734(gdb)
4735@end example
4736
4737Note that the @code{info break} displays the dynamic printf commands
4738as normal breakpoint commands; you can thus easily see the effect of
4739the variable settings.
4740
d3ce09f5
SS
4741@item set disconnected-dprintf on
4742@itemx set disconnected-dprintf off
4743@kindex set disconnected-dprintf
4744Choose whether @code{dprintf} commands should continue to run if
4745@value{GDBN} has disconnected from the target. This only applies
4746if the @code{dprintf-style} is @code{agent}.
4747
4748@item show disconnected-dprintf off
4749@kindex show disconnected-dprintf
4750Show the current choice for disconnected @code{dprintf}.
4751
e7e0cddf
SS
4752@end table
4753
4754@value{GDBN} does not check the validity of function and channel,
4755relying on you to supply values that are meaningful for the contexts
4756in which they are being used. For instance, the function and channel
4757may be the values of local variables, but if that is the case, then
4758all enabled dynamic prints must be at locations within the scope of
4759those locals. If evaluation fails, @value{GDBN} will report an error.
4760
6149aea9
PA
4761@node Save Breakpoints
4762@subsection How to save breakpoints to a file
4763
4764To save breakpoint definitions to a file use the @w{@code{save
4765breakpoints}} command.
4766
4767@table @code
4768@kindex save breakpoints
4769@cindex save breakpoints to a file for future sessions
4770@item save breakpoints [@var{filename}]
4771This command saves all current breakpoint definitions together with
4772their commands and ignore counts, into a file @file{@var{filename}}
4773suitable for use in a later debugging session. This includes all
4774types of breakpoints (breakpoints, watchpoints, catchpoints,
4775tracepoints). To read the saved breakpoint definitions, use the
4776@code{source} command (@pxref{Command Files}). Note that watchpoints
4777with expressions involving local variables may fail to be recreated
4778because it may not be possible to access the context where the
4779watchpoint is valid anymore. Because the saved breakpoint definitions
4780are simply a sequence of @value{GDBN} commands that recreate the
4781breakpoints, you can edit the file in your favorite editing program,
4782and remove the breakpoint definitions you're not interested in, or
4783that can no longer be recreated.
4784@end table
4785
62e5f89c
SDJ
4786@node Static Probe Points
4787@subsection Static Probe Points
4788
4789@cindex static probe point, SystemTap
4790@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
4791for Statically Defined Tracing, and the probes are designed to have a tiny
4792runtime code and data footprint, and no dynamic relocations. They are
4793usable from assembly, C and C@t{++} languages. See
4794@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
4795for a good reference on how the @acronym{SDT} probes are implemented.
4796
4797Currently, @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
4798@acronym{SDT} probes are supported on ELF-compatible systems. See
4799@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
4800for more information on how to add @code{SystemTap} @acronym{SDT} probes
4801in your applications.
4802
4803@cindex semaphores on static probe points
4804Some probes have an associated semaphore variable; for instance, this
4805happens automatically if you defined your probe using a DTrace-style
4806@file{.d} file. If your probe has a semaphore, @value{GDBN} will
4807automatically enable it when you specify a breakpoint using the
4808@samp{-probe-stap} notation. But, if you put a breakpoint at a probe's
4809location by some other method (e.g., @code{break file:line}), then
4810@value{GDBN} will not automatically set the semaphore.
4811
4812You can examine the available static static probes using @code{info
4813probes}, with optional arguments:
4814
4815@table @code
4816@kindex info probes
4817@item info probes stap @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
4818If given, @var{provider} is a regular expression used to match against provider
4819names when selecting which probes to list. If omitted, probes by all
4820probes from all providers are listed.
4821
4822If given, @var{name} is a regular expression to match against probe names
4823when selecting which probes to list. If omitted, probe names are not
4824considered when deciding whether to display them.
4825
4826If given, @var{objfile} is a regular expression used to select which
4827object files (executable or shared libraries) to examine. If not
4828given, all object files are considered.
4829
4830@item info probes all
4831List the available static probes, from all types.
4832@end table
4833
4834@vindex $_probe_arg@r{, convenience variable}
4835A probe may specify up to twelve arguments. These are available at the
4836point at which the probe is defined---that is, when the current PC is
4837at the probe's location. The arguments are available using the
4838convenience variables (@pxref{Convenience Vars})
4839@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. Each probe argument is
4840an integer of the appropriate size; types are not preserved. The
4841convenience variable @code{$_probe_argc} holds the number of arguments
4842at the current probe point.
4843
4844These variables are always available, but attempts to access them at
4845any location other than a probe point will cause @value{GDBN} to give
4846an error message.
4847
4848
c906108c 4849@c @ifclear BARETARGET
6d2ebf8b 4850@node Error in Breakpoints
d4f3574e 4851@subsection ``Cannot insert breakpoints''
c906108c 4852
fa3a767f
PA
4853If you request too many active hardware-assisted breakpoints and
4854watchpoints, you will see this error message:
d4f3574e
SS
4855
4856@c FIXME: the precise wording of this message may change; the relevant
4857@c source change is not committed yet (Sep 3, 1999).
4858@smallexample
4859Stopped; cannot insert breakpoints.
4860You may have requested too many hardware breakpoints and watchpoints.
4861@end smallexample
4862
4863@noindent
4864This message is printed when you attempt to resume the program, since
4865only then @value{GDBN} knows exactly how many hardware breakpoints and
4866watchpoints it needs to insert.
4867
4868When this message is printed, you need to disable or remove some of the
4869hardware-assisted breakpoints and watchpoints, and then continue.
4870
79a6e687 4871@node Breakpoint-related Warnings
1485d690
KB
4872@subsection ``Breakpoint address adjusted...''
4873@cindex breakpoint address adjusted
4874
4875Some processor architectures place constraints on the addresses at
4876which breakpoints may be placed. For architectures thus constrained,
4877@value{GDBN} will attempt to adjust the breakpoint's address to comply
4878with the constraints dictated by the architecture.
4879
4880One example of such an architecture is the Fujitsu FR-V. The FR-V is
4881a VLIW architecture in which a number of RISC-like instructions may be
4882bundled together for parallel execution. The FR-V architecture
4883constrains the location of a breakpoint instruction within such a
4884bundle to the instruction with the lowest address. @value{GDBN}
4885honors this constraint by adjusting a breakpoint's address to the
4886first in the bundle.
4887
4888It is not uncommon for optimized code to have bundles which contain
4889instructions from different source statements, thus it may happen that
4890a breakpoint's address will be adjusted from one source statement to
4891another. Since this adjustment may significantly alter @value{GDBN}'s
4892breakpoint related behavior from what the user expects, a warning is
4893printed when the breakpoint is first set and also when the breakpoint
4894is hit.
4895
4896A warning like the one below is printed when setting a breakpoint
4897that's been subject to address adjustment:
4898
4899@smallexample
4900warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4901@end smallexample
4902
4903Such warnings are printed both for user settable and @value{GDBN}'s
4904internal breakpoints. If you see one of these warnings, you should
4905verify that a breakpoint set at the adjusted address will have the
4906desired affect. If not, the breakpoint in question may be removed and
b383017d 4907other breakpoints may be set which will have the desired behavior.
1485d690
KB
4908E.g., it may be sufficient to place the breakpoint at a later
4909instruction. A conditional breakpoint may also be useful in some
4910cases to prevent the breakpoint from triggering too often.
4911
4912@value{GDBN} will also issue a warning when stopping at one of these
4913adjusted breakpoints:
4914
4915@smallexample
4916warning: Breakpoint 1 address previously adjusted from 0x00010414
4917to 0x00010410.
4918@end smallexample
4919
4920When this warning is encountered, it may be too late to take remedial
4921action except in cases where the breakpoint is hit earlier or more
4922frequently than expected.
d4f3574e 4923
6d2ebf8b 4924@node Continuing and Stepping
79a6e687 4925@section Continuing and Stepping
c906108c
SS
4926
4927@cindex stepping
4928@cindex continuing
4929@cindex resuming execution
4930@dfn{Continuing} means resuming program execution until your program
4931completes normally. In contrast, @dfn{stepping} means executing just
4932one more ``step'' of your program, where ``step'' may mean either one
4933line of source code, or one machine instruction (depending on what
7a292a7a
SS
4934particular command you use). Either when continuing or when stepping,
4935your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e
SS
4936it stops due to a signal, you may want to use @code{handle}, or use
4937@samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
c906108c
SS
4938
4939@table @code
4940@kindex continue
41afff9a
EZ
4941@kindex c @r{(@code{continue})}
4942@kindex fg @r{(resume foreground execution)}
c906108c
SS
4943@item continue @r{[}@var{ignore-count}@r{]}
4944@itemx c @r{[}@var{ignore-count}@r{]}
4945@itemx fg @r{[}@var{ignore-count}@r{]}
4946Resume program execution, at the address where your program last stopped;
4947any breakpoints set at that address are bypassed. The optional argument
4948@var{ignore-count} allows you to specify a further number of times to
4949ignore a breakpoint at this location; its effect is like that of
79a6e687 4950@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
4951
4952The argument @var{ignore-count} is meaningful only when your program
4953stopped due to a breakpoint. At other times, the argument to
4954@code{continue} is ignored.
4955
d4f3574e
SS
4956The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4957debugged program is deemed to be the foreground program) are provided
4958purely for convenience, and have exactly the same behavior as
4959@code{continue}.
c906108c
SS
4960@end table
4961
4962To resume execution at a different place, you can use @code{return}
79a6e687 4963(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 4964calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 4965Different Address}) to go to an arbitrary location in your program.
c906108c
SS
4966
4967A typical technique for using stepping is to set a breakpoint
79a6e687 4968(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
4969beginning of the function or the section of your program where a problem
4970is believed to lie, run your program until it stops at that breakpoint,
4971and then step through the suspect area, examining the variables that are
4972interesting, until you see the problem happen.
4973
4974@table @code
4975@kindex step
41afff9a 4976@kindex s @r{(@code{step})}
c906108c
SS
4977@item step
4978Continue running your program until control reaches a different source
4979line, then stop it and return control to @value{GDBN}. This command is
4980abbreviated @code{s}.
4981
4982@quotation
4983@c "without debugging information" is imprecise; actually "without line
4984@c numbers in the debugging information". (gcc -g1 has debugging info but
4985@c not line numbers). But it seems complex to try to make that
4986@c distinction here.
4987@emph{Warning:} If you use the @code{step} command while control is
4988within a function that was compiled without debugging information,
4989execution proceeds until control reaches a function that does have
4990debugging information. Likewise, it will not step into a function which
4991is compiled without debugging information. To step through functions
4992without debugging information, use the @code{stepi} command, described
4993below.
4994@end quotation
4995
4a92d011
EZ
4996The @code{step} command only stops at the first instruction of a source
4997line. This prevents the multiple stops that could otherwise occur in
4998@code{switch} statements, @code{for} loops, etc. @code{step} continues
4999to stop if a function that has debugging information is called within
5000the line. In other words, @code{step} @emph{steps inside} any functions
5001called within the line.
c906108c 5002
d4f3574e
SS
5003Also, the @code{step} command only enters a function if there is line
5004number information for the function. Otherwise it acts like the
5d161b24 5005@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5006on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5007was any debugging information about the routine.
c906108c
SS
5008
5009@item step @var{count}
5010Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5011breakpoint is reached, or a signal not related to stepping occurs before
5012@var{count} steps, stepping stops right away.
c906108c
SS
5013
5014@kindex next
41afff9a 5015@kindex n @r{(@code{next})}
c906108c
SS
5016@item next @r{[}@var{count}@r{]}
5017Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5018This is similar to @code{step}, but function calls that appear within
5019the line of code are executed without stopping. Execution stops when
5020control reaches a different line of code at the original stack level
5021that was executing when you gave the @code{next} command. This command
5022is abbreviated @code{n}.
c906108c
SS
5023
5024An argument @var{count} is a repeat count, as for @code{step}.
5025
5026
5027@c FIX ME!! Do we delete this, or is there a way it fits in with
5028@c the following paragraph? --- Vctoria
5029@c
5030@c @code{next} within a function that lacks debugging information acts like
5031@c @code{step}, but any function calls appearing within the code of the
5032@c function are executed without stopping.
5033
d4f3574e
SS
5034The @code{next} command only stops at the first instruction of a
5035source line. This prevents multiple stops that could otherwise occur in
4a92d011 5036@code{switch} statements, @code{for} loops, etc.
c906108c 5037
b90a5f51
CF
5038@kindex set step-mode
5039@item set step-mode
5040@cindex functions without line info, and stepping
5041@cindex stepping into functions with no line info
5042@itemx set step-mode on
4a92d011 5043The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5044stop at the first instruction of a function which contains no debug line
5045information rather than stepping over it.
5046
4a92d011
EZ
5047This is useful in cases where you may be interested in inspecting the
5048machine instructions of a function which has no symbolic info and do not
5049want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5050
5051@item set step-mode off
4a92d011 5052Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5053debug information. This is the default.
5054
9c16f35a
EZ
5055@item show step-mode
5056Show whether @value{GDBN} will stop in or step over functions without
5057source line debug information.
5058
c906108c 5059@kindex finish
8dfa32fc 5060@kindex fin @r{(@code{finish})}
c906108c
SS
5061@item finish
5062Continue running until just after function in the selected stack frame
8dfa32fc
JB
5063returns. Print the returned value (if any). This command can be
5064abbreviated as @code{fin}.
c906108c
SS
5065
5066Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5067,Returning from a Function}).
c906108c
SS
5068
5069@kindex until
41afff9a 5070@kindex u @r{(@code{until})}
09d4efe1 5071@cindex run until specified location
c906108c
SS
5072@item until
5073@itemx u
5074Continue running until a source line past the current line, in the
5075current stack frame, is reached. This command is used to avoid single
5076stepping through a loop more than once. It is like the @code{next}
5077command, except that when @code{until} encounters a jump, it
5078automatically continues execution until the program counter is greater
5079than the address of the jump.
5080
5081This means that when you reach the end of a loop after single stepping
5082though it, @code{until} makes your program continue execution until it
5083exits the loop. In contrast, a @code{next} command at the end of a loop
5084simply steps back to the beginning of the loop, which forces you to step
5085through the next iteration.
5086
5087@code{until} always stops your program if it attempts to exit the current
5088stack frame.
5089
5090@code{until} may produce somewhat counterintuitive results if the order
5091of machine code does not match the order of the source lines. For
5092example, in the following excerpt from a debugging session, the @code{f}
5093(@code{frame}) command shows that execution is stopped at line
5094@code{206}; yet when we use @code{until}, we get to line @code{195}:
5095
474c8240 5096@smallexample
c906108c
SS
5097(@value{GDBP}) f
5098#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5099206 expand_input();
5100(@value{GDBP}) until
5101195 for ( ; argc > 0; NEXTARG) @{
474c8240 5102@end smallexample
c906108c
SS
5103
5104This happened because, for execution efficiency, the compiler had
5105generated code for the loop closure test at the end, rather than the
5106start, of the loop---even though the test in a C @code{for}-loop is
5107written before the body of the loop. The @code{until} command appeared
5108to step back to the beginning of the loop when it advanced to this
5109expression; however, it has not really gone to an earlier
5110statement---not in terms of the actual machine code.
5111
5112@code{until} with no argument works by means of single
5113instruction stepping, and hence is slower than @code{until} with an
5114argument.
5115
5116@item until @var{location}
5117@itemx u @var{location}
5118Continue running your program until either the specified location is
5119reached, or the current stack frame returns. @var{location} is any of
2a25a5ba
EZ
5120the forms described in @ref{Specify Location}.
5121This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5122hence is quicker than @code{until} without an argument. The specified
5123location is actually reached only if it is in the current frame. This
5124implies that @code{until} can be used to skip over recursive function
5125invocations. For instance in the code below, if the current location is
5126line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5127line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5128invocations have returned.
5129
5130@smallexample
513194 int factorial (int value)
513295 @{
513396 if (value > 1) @{
513497 value *= factorial (value - 1);
513598 @}
513699 return (value);
5137100 @}
5138@end smallexample
5139
5140
5141@kindex advance @var{location}
984359d2 5142@item advance @var{location}
09d4efe1 5143Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5144required, which should be of one of the forms described in
5145@ref{Specify Location}.
5146Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5147frame. This command is similar to @code{until}, but @code{advance} will
5148not skip over recursive function calls, and the target location doesn't
5149have to be in the same frame as the current one.
5150
c906108c
SS
5151
5152@kindex stepi
41afff9a 5153@kindex si @r{(@code{stepi})}
c906108c 5154@item stepi
96a2c332 5155@itemx stepi @var{arg}
c906108c
SS
5156@itemx si
5157Execute one machine instruction, then stop and return to the debugger.
5158
5159It is often useful to do @samp{display/i $pc} when stepping by machine
5160instructions. This makes @value{GDBN} automatically display the next
5161instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5162Display,, Automatic Display}.
c906108c
SS
5163
5164An argument is a repeat count, as in @code{step}.
5165
5166@need 750
5167@kindex nexti
41afff9a 5168@kindex ni @r{(@code{nexti})}
c906108c 5169@item nexti
96a2c332 5170@itemx nexti @var{arg}
c906108c
SS
5171@itemx ni
5172Execute one machine instruction, but if it is a function call,
5173proceed until the function returns.
5174
5175An argument is a repeat count, as in @code{next}.
5176@end table
5177
aad1c02c
TT
5178@node Skipping Over Functions and Files
5179@section Skipping Over Functions and Files
1bfeeb0f
JL
5180@cindex skipping over functions and files
5181
5182The program you are debugging may contain some functions which are
5183uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
5184skip a function or all functions in a file when stepping.
5185
5186For example, consider the following C function:
5187
5188@smallexample
5189101 int func()
5190102 @{
5191103 foo(boring());
5192104 bar(boring());
5193105 @}
5194@end smallexample
5195
5196@noindent
5197Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5198are not interested in stepping through @code{boring}. If you run @code{step}
5199at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5200step over both @code{foo} and @code{boring}!
5201
5202One solution is to @code{step} into @code{boring} and use the @code{finish}
5203command to immediately exit it. But this can become tedious if @code{boring}
5204is called from many places.
5205
5206A more flexible solution is to execute @kbd{skip boring}. This instructs
5207@value{GDBN} never to step into @code{boring}. Now when you execute
5208@code{step} at line 103, you'll step over @code{boring} and directly into
5209@code{foo}.
5210
5211You can also instruct @value{GDBN} to skip all functions in a file, with, for
5212example, @code{skip file boring.c}.
5213
5214@table @code
5215@kindex skip function
5216@item skip @r{[}@var{linespec}@r{]}
5217@itemx skip function @r{[}@var{linespec}@r{]}
5218After running this command, the function named by @var{linespec} or the
5219function containing the line named by @var{linespec} will be skipped over when
983fb131 5220stepping. @xref{Specify Location}.
1bfeeb0f
JL
5221
5222If you do not specify @var{linespec}, the function you're currently debugging
5223will be skipped.
5224
5225(If you have a function called @code{file} that you want to skip, use
5226@kbd{skip function file}.)
5227
5228@kindex skip file
5229@item skip file @r{[}@var{filename}@r{]}
5230After running this command, any function whose source lives in @var{filename}
5231will be skipped over when stepping.
5232
5233If you do not specify @var{filename}, functions whose source lives in the file
5234you're currently debugging will be skipped.
5235@end table
5236
5237Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5238These are the commands for managing your list of skips:
5239
5240@table @code
5241@kindex info skip
5242@item info skip @r{[}@var{range}@r{]}
5243Print details about the specified skip(s). If @var{range} is not specified,
5244print a table with details about all functions and files marked for skipping.
5245@code{info skip} prints the following information about each skip:
5246
5247@table @emph
5248@item Identifier
5249A number identifying this skip.
5250@item Type
5251The type of this skip, either @samp{function} or @samp{file}.
5252@item Enabled or Disabled
5253Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5254@item Address
5255For function skips, this column indicates the address in memory of the function
5256being skipped. If you've set a function skip on a function which has not yet
5257been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5258which has the function is loaded, @code{info skip} will show the function's
5259address here.
5260@item What
5261For file skips, this field contains the filename being skipped. For functions
5262skips, this field contains the function name and its line number in the file
5263where it is defined.
5264@end table
5265
5266@kindex skip delete
5267@item skip delete @r{[}@var{range}@r{]}
5268Delete the specified skip(s). If @var{range} is not specified, delete all
5269skips.
5270
5271@kindex skip enable
5272@item skip enable @r{[}@var{range}@r{]}
5273Enable the specified skip(s). If @var{range} is not specified, enable all
5274skips.
5275
5276@kindex skip disable
5277@item skip disable @r{[}@var{range}@r{]}
5278Disable the specified skip(s). If @var{range} is not specified, disable all
5279skips.
5280
5281@end table
5282
6d2ebf8b 5283@node Signals
c906108c
SS
5284@section Signals
5285@cindex signals
5286
5287A signal is an asynchronous event that can happen in a program. The
5288operating system defines the possible kinds of signals, and gives each
5289kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 5290signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
5291@code{SIGSEGV} is the signal a program gets from referencing a place in
5292memory far away from all the areas in use; @code{SIGALRM} occurs when
5293the alarm clock timer goes off (which happens only if your program has
5294requested an alarm).
5295
5296@cindex fatal signals
5297Some signals, including @code{SIGALRM}, are a normal part of the
5298functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 5299errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
5300program has not specified in advance some other way to handle the signal.
5301@code{SIGINT} does not indicate an error in your program, but it is normally
5302fatal so it can carry out the purpose of the interrupt: to kill the program.
5303
5304@value{GDBN} has the ability to detect any occurrence of a signal in your
5305program. You can tell @value{GDBN} in advance what to do for each kind of
5306signal.
5307
5308@cindex handling signals
24f93129
EZ
5309Normally, @value{GDBN} is set up to let the non-erroneous signals like
5310@code{SIGALRM} be silently passed to your program
5311(so as not to interfere with their role in the program's functioning)
c906108c
SS
5312but to stop your program immediately whenever an error signal happens.
5313You can change these settings with the @code{handle} command.
5314
5315@table @code
5316@kindex info signals
09d4efe1 5317@kindex info handle
c906108c 5318@item info signals
96a2c332 5319@itemx info handle
c906108c
SS
5320Print a table of all the kinds of signals and how @value{GDBN} has been told to
5321handle each one. You can use this to see the signal numbers of all
5322the defined types of signals.
5323
45ac1734
EZ
5324@item info signals @var{sig}
5325Similar, but print information only about the specified signal number.
5326
d4f3574e 5327@code{info handle} is an alias for @code{info signals}.
c906108c
SS
5328
5329@kindex handle
45ac1734 5330@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5ece1a18
EZ
5331Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
5332can be the number of a signal or its name (with or without the
24f93129 5333@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 5334@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
5335known signals. Optional arguments @var{keywords}, described below,
5336say what change to make.
c906108c
SS
5337@end table
5338
5339@c @group
5340The keywords allowed by the @code{handle} command can be abbreviated.
5341Their full names are:
5342
5343@table @code
5344@item nostop
5345@value{GDBN} should not stop your program when this signal happens. It may
5346still print a message telling you that the signal has come in.
5347
5348@item stop
5349@value{GDBN} should stop your program when this signal happens. This implies
5350the @code{print} keyword as well.
5351
5352@item print
5353@value{GDBN} should print a message when this signal happens.
5354
5355@item noprint
5356@value{GDBN} should not mention the occurrence of the signal at all. This
5357implies the @code{nostop} keyword as well.
5358
5359@item pass
5ece1a18 5360@itemx noignore
c906108c
SS
5361@value{GDBN} should allow your program to see this signal; your program
5362can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 5363and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
5364
5365@item nopass
5ece1a18 5366@itemx ignore
c906108c 5367@value{GDBN} should not allow your program to see this signal.
5ece1a18 5368@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
5369@end table
5370@c @end group
5371
d4f3574e
SS
5372When a signal stops your program, the signal is not visible to the
5373program until you
c906108c
SS
5374continue. Your program sees the signal then, if @code{pass} is in
5375effect for the signal in question @emph{at that time}. In other words,
5376after @value{GDBN} reports a signal, you can use the @code{handle}
5377command with @code{pass} or @code{nopass} to control whether your
5378program sees that signal when you continue.
5379
24f93129
EZ
5380The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5381non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5382@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5383erroneous signals.
5384
c906108c
SS
5385You can also use the @code{signal} command to prevent your program from
5386seeing a signal, or cause it to see a signal it normally would not see,
5387or to give it any signal at any time. For example, if your program stopped
5388due to some sort of memory reference error, you might store correct
5389values into the erroneous variables and continue, hoping to see more
5390execution; but your program would probably terminate immediately as
5391a result of the fatal signal once it saw the signal. To prevent this,
5392you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 5393Program a Signal}.
c906108c 5394
4aa995e1
PA
5395@cindex extra signal information
5396@anchor{extra signal information}
5397
5398On some targets, @value{GDBN} can inspect extra signal information
5399associated with the intercepted signal, before it is actually
5400delivered to the program being debugged. This information is exported
5401by the convenience variable @code{$_siginfo}, and consists of data
5402that is passed by the kernel to the signal handler at the time of the
5403receipt of a signal. The data type of the information itself is
5404target dependent. You can see the data type using the @code{ptype
5405$_siginfo} command. On Unix systems, it typically corresponds to the
5406standard @code{siginfo_t} type, as defined in the @file{signal.h}
5407system header.
5408
5409Here's an example, on a @sc{gnu}/Linux system, printing the stray
5410referenced address that raised a segmentation fault.
5411
5412@smallexample
5413@group
5414(@value{GDBP}) continue
5415Program received signal SIGSEGV, Segmentation fault.
54160x0000000000400766 in main ()
541769 *(int *)p = 0;
5418(@value{GDBP}) ptype $_siginfo
5419type = struct @{
5420 int si_signo;
5421 int si_errno;
5422 int si_code;
5423 union @{
5424 int _pad[28];
5425 struct @{...@} _kill;
5426 struct @{...@} _timer;
5427 struct @{...@} _rt;
5428 struct @{...@} _sigchld;
5429 struct @{...@} _sigfault;
5430 struct @{...@} _sigpoll;
5431 @} _sifields;
5432@}
5433(@value{GDBP}) ptype $_siginfo._sifields._sigfault
5434type = struct @{
5435 void *si_addr;
5436@}
5437(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5438$1 = (void *) 0x7ffff7ff7000
5439@end group
5440@end smallexample
5441
5442Depending on target support, @code{$_siginfo} may also be writable.
5443
6d2ebf8b 5444@node Thread Stops
79a6e687 5445@section Stopping and Starting Multi-thread Programs
c906108c 5446
0606b73b
SL
5447@cindex stopped threads
5448@cindex threads, stopped
5449
5450@cindex continuing threads
5451@cindex threads, continuing
5452
5453@value{GDBN} supports debugging programs with multiple threads
5454(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5455are two modes of controlling execution of your program within the
5456debugger. In the default mode, referred to as @dfn{all-stop mode},
5457when any thread in your program stops (for example, at a breakpoint
5458or while being stepped), all other threads in the program are also stopped by
5459@value{GDBN}. On some targets, @value{GDBN} also supports
5460@dfn{non-stop mode}, in which other threads can continue to run freely while
5461you examine the stopped thread in the debugger.
5462
5463@menu
5464* All-Stop Mode:: All threads stop when GDB takes control
5465* Non-Stop Mode:: Other threads continue to execute
5466* Background Execution:: Running your program asynchronously
5467* Thread-Specific Breakpoints:: Controlling breakpoints
5468* Interrupted System Calls:: GDB may interfere with system calls
d914c394 5469* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
5470@end menu
5471
5472@node All-Stop Mode
5473@subsection All-Stop Mode
5474
5475@cindex all-stop mode
5476
5477In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5478@emph{all} threads of execution stop, not just the current thread. This
5479allows you to examine the overall state of the program, including
5480switching between threads, without worrying that things may change
5481underfoot.
5482
5483Conversely, whenever you restart the program, @emph{all} threads start
5484executing. @emph{This is true even when single-stepping} with commands
5485like @code{step} or @code{next}.
5486
5487In particular, @value{GDBN} cannot single-step all threads in lockstep.
5488Since thread scheduling is up to your debugging target's operating
5489system (not controlled by @value{GDBN}), other threads may
5490execute more than one statement while the current thread completes a
5491single step. Moreover, in general other threads stop in the middle of a
5492statement, rather than at a clean statement boundary, when the program
5493stops.
5494
5495You might even find your program stopped in another thread after
5496continuing or even single-stepping. This happens whenever some other
5497thread runs into a breakpoint, a signal, or an exception before the
5498first thread completes whatever you requested.
5499
5500@cindex automatic thread selection
5501@cindex switching threads automatically
5502@cindex threads, automatic switching
5503Whenever @value{GDBN} stops your program, due to a breakpoint or a
5504signal, it automatically selects the thread where that breakpoint or
5505signal happened. @value{GDBN} alerts you to the context switch with a
5506message such as @samp{[Switching to Thread @var{n}]} to identify the
5507thread.
5508
5509On some OSes, you can modify @value{GDBN}'s default behavior by
5510locking the OS scheduler to allow only a single thread to run.
5511
5512@table @code
5513@item set scheduler-locking @var{mode}
5514@cindex scheduler locking mode
5515@cindex lock scheduler
5516Set the scheduler locking mode. If it is @code{off}, then there is no
5517locking and any thread may run at any time. If @code{on}, then only the
5518current thread may run when the inferior is resumed. The @code{step}
5519mode optimizes for single-stepping; it prevents other threads
5520from preempting the current thread while you are stepping, so that
5521the focus of debugging does not change unexpectedly.
5522Other threads only rarely (or never) get a chance to run
5523when you step. They are more likely to run when you @samp{next} over a
5524function call, and they are completely free to run when you use commands
5525like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5526thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5527the current thread away from the thread that you are debugging.
5528
5529@item show scheduler-locking
5530Display the current scheduler locking mode.
5531@end table
5532
d4db2f36
PA
5533@cindex resume threads of multiple processes simultaneously
5534By default, when you issue one of the execution commands such as
5535@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5536threads of the current inferior to run. For example, if @value{GDBN}
5537is attached to two inferiors, each with two threads, the
5538@code{continue} command resumes only the two threads of the current
5539inferior. This is useful, for example, when you debug a program that
5540forks and you want to hold the parent stopped (so that, for instance,
5541it doesn't run to exit), while you debug the child. In other
5542situations, you may not be interested in inspecting the current state
5543of any of the processes @value{GDBN} is attached to, and you may want
5544to resume them all until some breakpoint is hit. In the latter case,
5545you can instruct @value{GDBN} to allow all threads of all the
5546inferiors to run with the @w{@code{set schedule-multiple}} command.
5547
5548@table @code
5549@kindex set schedule-multiple
5550@item set schedule-multiple
5551Set the mode for allowing threads of multiple processes to be resumed
5552when an execution command is issued. When @code{on}, all threads of
5553all processes are allowed to run. When @code{off}, only the threads
5554of the current process are resumed. The default is @code{off}. The
5555@code{scheduler-locking} mode takes precedence when set to @code{on},
5556or while you are stepping and set to @code{step}.
5557
5558@item show schedule-multiple
5559Display the current mode for resuming the execution of threads of
5560multiple processes.
5561@end table
5562
0606b73b
SL
5563@node Non-Stop Mode
5564@subsection Non-Stop Mode
5565
5566@cindex non-stop mode
5567
5568@c This section is really only a place-holder, and needs to be expanded
5569@c with more details.
5570
5571For some multi-threaded targets, @value{GDBN} supports an optional
5572mode of operation in which you can examine stopped program threads in
5573the debugger while other threads continue to execute freely. This
5574minimizes intrusion when debugging live systems, such as programs
5575where some threads have real-time constraints or must continue to
5576respond to external events. This is referred to as @dfn{non-stop} mode.
5577
5578In non-stop mode, when a thread stops to report a debugging event,
5579@emph{only} that thread is stopped; @value{GDBN} does not stop other
5580threads as well, in contrast to the all-stop mode behavior. Additionally,
5581execution commands such as @code{continue} and @code{step} apply by default
5582only to the current thread in non-stop mode, rather than all threads as
5583in all-stop mode. This allows you to control threads explicitly in
5584ways that are not possible in all-stop mode --- for example, stepping
5585one thread while allowing others to run freely, stepping
5586one thread while holding all others stopped, or stepping several threads
5587independently and simultaneously.
5588
5589To enter non-stop mode, use this sequence of commands before you run
5590or attach to your program:
5591
0606b73b
SL
5592@smallexample
5593# Enable the async interface.
c6ebd6cf 5594set target-async 1
0606b73b 5595
0606b73b
SL
5596# If using the CLI, pagination breaks non-stop.
5597set pagination off
5598
5599# Finally, turn it on!
5600set non-stop on
5601@end smallexample
5602
5603You can use these commands to manipulate the non-stop mode setting:
5604
5605@table @code
5606@kindex set non-stop
5607@item set non-stop on
5608Enable selection of non-stop mode.
5609@item set non-stop off
5610Disable selection of non-stop mode.
5611@kindex show non-stop
5612@item show non-stop
5613Show the current non-stop enablement setting.
5614@end table
5615
5616Note these commands only reflect whether non-stop mode is enabled,
5617not whether the currently-executing program is being run in non-stop mode.
5618In particular, the @code{set non-stop} preference is only consulted when
5619@value{GDBN} starts or connects to the target program, and it is generally
5620not possible to switch modes once debugging has started. Furthermore,
5621since not all targets support non-stop mode, even when you have enabled
5622non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5623default.
5624
5625In non-stop mode, all execution commands apply only to the current thread
5626by default. That is, @code{continue} only continues one thread.
5627To continue all threads, issue @code{continue -a} or @code{c -a}.
5628
5629You can use @value{GDBN}'s background execution commands
5630(@pxref{Background Execution}) to run some threads in the background
5631while you continue to examine or step others from @value{GDBN}.
5632The MI execution commands (@pxref{GDB/MI Program Execution}) are
5633always executed asynchronously in non-stop mode.
5634
5635Suspending execution is done with the @code{interrupt} command when
5636running in the background, or @kbd{Ctrl-c} during foreground execution.
5637In all-stop mode, this stops the whole process;
5638but in non-stop mode the interrupt applies only to the current thread.
5639To stop the whole program, use @code{interrupt -a}.
5640
5641Other execution commands do not currently support the @code{-a} option.
5642
5643In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5644that thread current, as it does in all-stop mode. This is because the
5645thread stop notifications are asynchronous with respect to @value{GDBN}'s
5646command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5647changed to a different thread just as you entered a command to operate on the
5648previously current thread.
5649
5650@node Background Execution
5651@subsection Background Execution
5652
5653@cindex foreground execution
5654@cindex background execution
5655@cindex asynchronous execution
5656@cindex execution, foreground, background and asynchronous
5657
5658@value{GDBN}'s execution commands have two variants: the normal
5659foreground (synchronous) behavior, and a background
5660(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5661the program to report that some thread has stopped before prompting for
5662another command. In background execution, @value{GDBN} immediately gives
5663a command prompt so that you can issue other commands while your program runs.
5664
32fc0df9
PA
5665You need to explicitly enable asynchronous mode before you can use
5666background execution commands. You can use these commands to
5667manipulate the asynchronous mode setting:
5668
5669@table @code
5670@kindex set target-async
5671@item set target-async on
5672Enable asynchronous mode.
5673@item set target-async off
5674Disable asynchronous mode.
5675@kindex show target-async
5676@item show target-async
5677Show the current target-async setting.
5678@end table
5679
5680If the target doesn't support async mode, @value{GDBN} issues an error
5681message if you attempt to use the background execution commands.
5682
0606b73b
SL
5683To specify background execution, add a @code{&} to the command. For example,
5684the background form of the @code{continue} command is @code{continue&}, or
5685just @code{c&}. The execution commands that accept background execution
5686are:
5687
5688@table @code
5689@kindex run&
5690@item run
5691@xref{Starting, , Starting your Program}.
5692
5693@item attach
5694@kindex attach&
5695@xref{Attach, , Debugging an Already-running Process}.
5696
5697@item step
5698@kindex step&
5699@xref{Continuing and Stepping, step}.
5700
5701@item stepi
5702@kindex stepi&
5703@xref{Continuing and Stepping, stepi}.
5704
5705@item next
5706@kindex next&
5707@xref{Continuing and Stepping, next}.
5708
7ce58dd2
DE
5709@item nexti
5710@kindex nexti&
5711@xref{Continuing and Stepping, nexti}.
5712
0606b73b
SL
5713@item continue
5714@kindex continue&
5715@xref{Continuing and Stepping, continue}.
5716
5717@item finish
5718@kindex finish&
5719@xref{Continuing and Stepping, finish}.
5720
5721@item until
5722@kindex until&
5723@xref{Continuing and Stepping, until}.
5724
5725@end table
5726
5727Background execution is especially useful in conjunction with non-stop
5728mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5729However, you can also use these commands in the normal all-stop mode with
5730the restriction that you cannot issue another execution command until the
5731previous one finishes. Examples of commands that are valid in all-stop
5732mode while the program is running include @code{help} and @code{info break}.
5733
5734You can interrupt your program while it is running in the background by
5735using the @code{interrupt} command.
5736
5737@table @code
5738@kindex interrupt
5739@item interrupt
5740@itemx interrupt -a
5741
5742Suspend execution of the running program. In all-stop mode,
5743@code{interrupt} stops the whole process, but in non-stop mode, it stops
5744only the current thread. To stop the whole program in non-stop mode,
5745use @code{interrupt -a}.
5746@end table
5747
0606b73b
SL
5748@node Thread-Specific Breakpoints
5749@subsection Thread-Specific Breakpoints
5750
c906108c 5751When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 5752Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
5753breakpoints on all threads, or on a particular thread.
5754
5755@table @code
5756@cindex breakpoints and threads
5757@cindex thread breakpoints
5758@kindex break @dots{} thread @var{threadno}
5759@item break @var{linespec} thread @var{threadno}
5760@itemx break @var{linespec} thread @var{threadno} if @dots{}
5761@var{linespec} specifies source lines; there are several ways of
2a25a5ba
EZ
5762writing them (@pxref{Specify Location}), but the effect is always to
5763specify some source line.
c906108c
SS
5764
5765Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5766to specify that you only want @value{GDBN} to stop the program when a
5767particular thread reaches this breakpoint. @var{threadno} is one of the
5768numeric thread identifiers assigned by @value{GDBN}, shown in the first
5769column of the @samp{info threads} display.
5770
5771If you do not specify @samp{thread @var{threadno}} when you set a
5772breakpoint, the breakpoint applies to @emph{all} threads of your
5773program.
5774
5775You can use the @code{thread} qualifier on conditional breakpoints as
b6199126
DJ
5776well; in this case, place @samp{thread @var{threadno}} before or
5777after the breakpoint condition, like this:
c906108c
SS
5778
5779@smallexample
2df3850c 5780(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
5781@end smallexample
5782
5783@end table
5784
0606b73b
SL
5785@node Interrupted System Calls
5786@subsection Interrupted System Calls
c906108c 5787
36d86913
MC
5788@cindex thread breakpoints and system calls
5789@cindex system calls and thread breakpoints
5790@cindex premature return from system calls
0606b73b
SL
5791There is an unfortunate side effect when using @value{GDBN} to debug
5792multi-threaded programs. If one thread stops for a
36d86913
MC
5793breakpoint, or for some other reason, and another thread is blocked in a
5794system call, then the system call may return prematurely. This is a
5795consequence of the interaction between multiple threads and the signals
5796that @value{GDBN} uses to implement breakpoints and other events that
5797stop execution.
5798
5799To handle this problem, your program should check the return value of
5800each system call and react appropriately. This is good programming
5801style anyways.
5802
5803For example, do not write code like this:
5804
5805@smallexample
5806 sleep (10);
5807@end smallexample
5808
5809The call to @code{sleep} will return early if a different thread stops
5810at a breakpoint or for some other reason.
5811
5812Instead, write this:
5813
5814@smallexample
5815 int unslept = 10;
5816 while (unslept > 0)
5817 unslept = sleep (unslept);
5818@end smallexample
5819
5820A system call is allowed to return early, so the system is still
5821conforming to its specification. But @value{GDBN} does cause your
5822multi-threaded program to behave differently than it would without
5823@value{GDBN}.
5824
5825Also, @value{GDBN} uses internal breakpoints in the thread library to
5826monitor certain events such as thread creation and thread destruction.
5827When such an event happens, a system call in another thread may return
5828prematurely, even though your program does not appear to stop.
5829
d914c394
SS
5830@node Observer Mode
5831@subsection Observer Mode
5832
5833If you want to build on non-stop mode and observe program behavior
5834without any chance of disruption by @value{GDBN}, you can set
5835variables to disable all of the debugger's attempts to modify state,
5836whether by writing memory, inserting breakpoints, etc. These operate
5837at a low level, intercepting operations from all commands.
5838
5839When all of these are set to @code{off}, then @value{GDBN} is said to
5840be @dfn{observer mode}. As a convenience, the variable
5841@code{observer} can be set to disable these, plus enable non-stop
5842mode.
5843
5844Note that @value{GDBN} will not prevent you from making nonsensical
5845combinations of these settings. For instance, if you have enabled
5846@code{may-insert-breakpoints} but disabled @code{may-write-memory},
5847then breakpoints that work by writing trap instructions into the code
5848stream will still not be able to be placed.
5849
5850@table @code
5851
5852@kindex observer
5853@item set observer on
5854@itemx set observer off
5855When set to @code{on}, this disables all the permission variables
5856below (except for @code{insert-fast-tracepoints}), plus enables
5857non-stop debugging. Setting this to @code{off} switches back to
5858normal debugging, though remaining in non-stop mode.
5859
5860@item show observer
5861Show whether observer mode is on or off.
5862
5863@kindex may-write-registers
5864@item set may-write-registers on
5865@itemx set may-write-registers off
5866This controls whether @value{GDBN} will attempt to alter the values of
5867registers, such as with assignment expressions in @code{print}, or the
5868@code{jump} command. It defaults to @code{on}.
5869
5870@item show may-write-registers
5871Show the current permission to write registers.
5872
5873@kindex may-write-memory
5874@item set may-write-memory on
5875@itemx set may-write-memory off
5876This controls whether @value{GDBN} will attempt to alter the contents
5877of memory, such as with assignment expressions in @code{print}. It
5878defaults to @code{on}.
5879
5880@item show may-write-memory
5881Show the current permission to write memory.
5882
5883@kindex may-insert-breakpoints
5884@item set may-insert-breakpoints on
5885@itemx set may-insert-breakpoints off
5886This controls whether @value{GDBN} will attempt to insert breakpoints.
5887This affects all breakpoints, including internal breakpoints defined
5888by @value{GDBN}. It defaults to @code{on}.
5889
5890@item show may-insert-breakpoints
5891Show the current permission to insert breakpoints.
5892
5893@kindex may-insert-tracepoints
5894@item set may-insert-tracepoints on
5895@itemx set may-insert-tracepoints off
5896This controls whether @value{GDBN} will attempt to insert (regular)
5897tracepoints at the beginning of a tracing experiment. It affects only
5898non-fast tracepoints, fast tracepoints being under the control of
5899@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5900
5901@item show may-insert-tracepoints
5902Show the current permission to insert tracepoints.
5903
5904@kindex may-insert-fast-tracepoints
5905@item set may-insert-fast-tracepoints on
5906@itemx set may-insert-fast-tracepoints off
5907This controls whether @value{GDBN} will attempt to insert fast
5908tracepoints at the beginning of a tracing experiment. It affects only
5909fast tracepoints, regular (non-fast) tracepoints being under the
5910control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5911
5912@item show may-insert-fast-tracepoints
5913Show the current permission to insert fast tracepoints.
5914
5915@kindex may-interrupt
5916@item set may-interrupt on
5917@itemx set may-interrupt off
5918This controls whether @value{GDBN} will attempt to interrupt or stop
5919program execution. When this variable is @code{off}, the
5920@code{interrupt} command will have no effect, nor will
5921@kbd{Ctrl-c}. It defaults to @code{on}.
5922
5923@item show may-interrupt
5924Show the current permission to interrupt or stop the program.
5925
5926@end table
c906108c 5927
bacec72f
MS
5928@node Reverse Execution
5929@chapter Running programs backward
5930@cindex reverse execution
5931@cindex running programs backward
5932
5933When you are debugging a program, it is not unusual to realize that
5934you have gone too far, and some event of interest has already happened.
5935If the target environment supports it, @value{GDBN} can allow you to
5936``rewind'' the program by running it backward.
5937
5938A target environment that supports reverse execution should be able
5939to ``undo'' the changes in machine state that have taken place as the
5940program was executing normally. Variables, registers etc.@: should
5941revert to their previous values. Obviously this requires a great
5942deal of sophistication on the part of the target environment; not
5943all target environments can support reverse execution.
5944
5945When a program is executed in reverse, the instructions that
5946have most recently been executed are ``un-executed'', in reverse
5947order. The program counter runs backward, following the previous
5948thread of execution in reverse. As each instruction is ``un-executed'',
5949the values of memory and/or registers that were changed by that
5950instruction are reverted to their previous states. After executing
5951a piece of source code in reverse, all side effects of that code
5952should be ``undone'', and all variables should be returned to their
5953prior values@footnote{
5954Note that some side effects are easier to undo than others. For instance,
5955memory and registers are relatively easy, but device I/O is hard. Some
5956targets may be able undo things like device I/O, and some may not.
5957
5958The contract between @value{GDBN} and the reverse executing target
5959requires only that the target do something reasonable when
5960@value{GDBN} tells it to execute backwards, and then report the
5961results back to @value{GDBN}. Whatever the target reports back to
5962@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5963assumes that the memory and registers that the target reports are in a
5964consistant state, but @value{GDBN} accepts whatever it is given.
5965}.
5966
5967If you are debugging in a target environment that supports
5968reverse execution, @value{GDBN} provides the following commands.
5969
5970@table @code
5971@kindex reverse-continue
5972@kindex rc @r{(@code{reverse-continue})}
5973@item reverse-continue @r{[}@var{ignore-count}@r{]}
5974@itemx rc @r{[}@var{ignore-count}@r{]}
5975Beginning at the point where your program last stopped, start executing
5976in reverse. Reverse execution will stop for breakpoints and synchronous
5977exceptions (signals), just like normal execution. Behavior of
5978asynchronous signals depends on the target environment.
5979
5980@kindex reverse-step
5981@kindex rs @r{(@code{step})}
5982@item reverse-step @r{[}@var{count}@r{]}
5983Run the program backward until control reaches the start of a
5984different source line; then stop it, and return control to @value{GDBN}.
5985
5986Like the @code{step} command, @code{reverse-step} will only stop
5987at the beginning of a source line. It ``un-executes'' the previously
5988executed source line. If the previous source line included calls to
5989debuggable functions, @code{reverse-step} will step (backward) into
5990the called function, stopping at the beginning of the @emph{last}
5991statement in the called function (typically a return statement).
5992
5993Also, as with the @code{step} command, if non-debuggable functions are
5994called, @code{reverse-step} will run thru them backward without stopping.
5995
5996@kindex reverse-stepi
5997@kindex rsi @r{(@code{reverse-stepi})}
5998@item reverse-stepi @r{[}@var{count}@r{]}
5999Reverse-execute one machine instruction. Note that the instruction
6000to be reverse-executed is @emph{not} the one pointed to by the program
6001counter, but the instruction executed prior to that one. For instance,
6002if the last instruction was a jump, @code{reverse-stepi} will take you
6003back from the destination of the jump to the jump instruction itself.
6004
6005@kindex reverse-next
6006@kindex rn @r{(@code{reverse-next})}
6007@item reverse-next @r{[}@var{count}@r{]}
6008Run backward to the beginning of the previous line executed in
6009the current (innermost) stack frame. If the line contains function
6010calls, they will be ``un-executed'' without stopping. Starting from
6011the first line of a function, @code{reverse-next} will take you back
6012to the caller of that function, @emph{before} the function was called,
6013just as the normal @code{next} command would take you from the last
6014line of a function back to its return to its caller
16af530a 6015@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6016
6017@kindex reverse-nexti
6018@kindex rni @r{(@code{reverse-nexti})}
6019@item reverse-nexti @r{[}@var{count}@r{]}
6020Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6021in reverse, except that called functions are ``un-executed'' atomically.
6022That is, if the previously executed instruction was a return from
540aa8e7 6023another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6024in reverse until the call to that function (from the current stack
6025frame) is reached.
6026
6027@kindex reverse-finish
6028@item reverse-finish
6029Just as the @code{finish} command takes you to the point where the
6030current function returns, @code{reverse-finish} takes you to the point
6031where it was called. Instead of ending up at the end of the current
6032function invocation, you end up at the beginning.
6033
6034@kindex set exec-direction
6035@item set exec-direction
6036Set the direction of target execution.
984359d2 6037@item set exec-direction reverse
bacec72f
MS
6038@cindex execute forward or backward in time
6039@value{GDBN} will perform all execution commands in reverse, until the
6040exec-direction mode is changed to ``forward''. Affected commands include
6041@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6042command cannot be used in reverse mode.
6043@item set exec-direction forward
6044@value{GDBN} will perform all execution commands in the normal fashion.
6045This is the default.
6046@end table
6047
c906108c 6048
a2311334
EZ
6049@node Process Record and Replay
6050@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6051@cindex process record and replay
6052@cindex recording inferior's execution and replaying it
6053
8e05493c
EZ
6054On some platforms, @value{GDBN} provides a special @dfn{process record
6055and replay} target that can record a log of the process execution, and
6056replay it later with both forward and reverse execution commands.
a2311334
EZ
6057
6058@cindex replay mode
6059When this target is in use, if the execution log includes the record
6060for the next instruction, @value{GDBN} will debug in @dfn{replay
6061mode}. In the replay mode, the inferior does not really execute code
6062instructions. Instead, all the events that normally happen during
6063code execution are taken from the execution log. While code is not
6064really executed in replay mode, the values of registers (including the
6065program counter register) and the memory of the inferior are still
8e05493c
EZ
6066changed as they normally would. Their contents are taken from the
6067execution log.
a2311334
EZ
6068
6069@cindex record mode
6070If the record for the next instruction is not in the execution log,
6071@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6072inferior executes normally, and @value{GDBN} records the execution log
6073for future replay.
6074
8e05493c
EZ
6075The process record and replay target supports reverse execution
6076(@pxref{Reverse Execution}), even if the platform on which the
6077inferior runs does not. However, the reverse execution is limited in
6078this case by the range of the instructions recorded in the execution
6079log. In other words, reverse execution on platforms that don't
6080support it directly can only be done in the replay mode.
6081
6082When debugging in the reverse direction, @value{GDBN} will work in
6083replay mode as long as the execution log includes the record for the
6084previous instruction; otherwise, it will work in record mode, if the
6085platform supports reverse execution, or stop if not.
6086
a2311334
EZ
6087For architecture environments that support process record and replay,
6088@value{GDBN} provides the following commands:
53cc454a
HZ
6089
6090@table @code
6091@kindex target record
6092@kindex record
6093@kindex rec
6094@item target record
a2311334
EZ
6095This command starts the process record and replay target. The process
6096record and replay target can only debug a process that is already
6097running. Therefore, you need first to start the process with the
6098@kbd{run} or @kbd{start} commands, and then start the recording with
6099the @kbd{target record} command.
6100
6101Both @code{record} and @code{rec} are aliases of @code{target record}.
6102
6103@cindex displaced stepping, and process record and replay
6104Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6105will be automatically disabled when process record and replay target
6106is started. That's because the process record and replay target
6107doesn't support displaced stepping.
6108
6109@cindex non-stop mode, and process record and replay
6110@cindex asynchronous execution, and process record and replay
6111If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
6112the asynchronous execution mode (@pxref{Background Execution}), the
6113process record and replay target cannot be started because it doesn't
6114support these two modes.
53cc454a
HZ
6115
6116@kindex record stop
6117@kindex rec s
6118@item record stop
a2311334
EZ
6119Stop the process record and replay target. When process record and
6120replay target stops, the entire execution log will be deleted and the
6121inferior will either be terminated, or will remain in its final state.
53cc454a 6122
a2311334
EZ
6123When you stop the process record and replay target in record mode (at
6124the end of the execution log), the inferior will be stopped at the
6125next instruction that would have been recorded. In other words, if
6126you record for a while and then stop recording, the inferior process
6127will be left in the same state as if the recording never happened.
53cc454a 6128
a2311334
EZ
6129On the other hand, if the process record and replay target is stopped
6130while in replay mode (that is, not at the end of the execution log,
6131but at some earlier point), the inferior process will become ``live''
6132at that earlier state, and it will then be possible to continue the
6133usual ``live'' debugging of the process from that state.
53cc454a 6134
a2311334
EZ
6135When the inferior process exits, or @value{GDBN} detaches from it,
6136process record and replay target will automatically stop itself.
53cc454a 6137
24e933df
HZ
6138@kindex record save
6139@item record save @var{filename}
6140Save the execution log to a file @file{@var{filename}}.
6141Default filename is @file{gdb_record.@var{process_id}}, where
6142@var{process_id} is the process ID of the inferior.
6143
6144@kindex record restore
6145@item record restore @var{filename}
6146Restore the execution log from a file @file{@var{filename}}.
6147File must have been created with @code{record save}.
6148
53cc454a
HZ
6149@kindex set record insn-number-max
6150@item set record insn-number-max @var{limit}
6151Set the limit of instructions to be recorded. Default value is 200000.
6152
a2311334
EZ
6153If @var{limit} is a positive number, then @value{GDBN} will start
6154deleting instructions from the log once the number of the record
6155instructions becomes greater than @var{limit}. For every new recorded
6156instruction, @value{GDBN} will delete the earliest recorded
6157instruction to keep the number of recorded instructions at the limit.
6158(Since deleting recorded instructions loses information, @value{GDBN}
6159lets you control what happens when the limit is reached, by means of
6160the @code{stop-at-limit} option, described below.)
53cc454a 6161
a2311334
EZ
6162If @var{limit} is zero, @value{GDBN} will never delete recorded
6163instructions from the execution log. The number of recorded
6164instructions is unlimited in this case.
53cc454a
HZ
6165
6166@kindex show record insn-number-max
6167@item show record insn-number-max
a2311334 6168Show the limit of instructions to be recorded.
53cc454a
HZ
6169
6170@kindex set record stop-at-limit
a2311334
EZ
6171@item set record stop-at-limit
6172Control the behavior when the number of recorded instructions reaches
6173the limit. If ON (the default), @value{GDBN} will stop when the limit
6174is reached for the first time and ask you whether you want to stop the
6175inferior or continue running it and recording the execution log. If
6176you decide to continue recording, each new recorded instruction will
6177cause the oldest one to be deleted.
53cc454a 6178
a2311334
EZ
6179If this option is OFF, @value{GDBN} will automatically delete the
6180oldest record to make room for each new one, without asking.
53cc454a
HZ
6181
6182@kindex show record stop-at-limit
6183@item show record stop-at-limit
a2311334 6184Show the current setting of @code{stop-at-limit}.
53cc454a 6185
bb08c432
HZ
6186@kindex set record memory-query
6187@item set record memory-query
6188Control the behavior when @value{GDBN} is unable to record memory
6189changes caused by an instruction. If ON, @value{GDBN} will query
6190whether to stop the inferior in that case.
6191
6192If this option is OFF (the default), @value{GDBN} will automatically
6193ignore the effect of such instructions on memory. Later, when
6194@value{GDBN} replays this execution log, it will mark the log of this
6195instruction as not accessible, and it will not affect the replay
6196results.
6197
6198@kindex show record memory-query
6199@item show record memory-query
6200Show the current setting of @code{memory-query}.
6201
29153c24
MS
6202@kindex info record
6203@item info record
6204Show various statistics about the state of process record and its
6205in-memory execution log buffer, including:
6206
6207@itemize @bullet
6208@item
6209Whether in record mode or replay mode.
6210@item
6211Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6212@item
6213Highest recorded instruction number.
6214@item
6215Current instruction about to be replayed (if in replay mode).
6216@item
6217Number of instructions contained in the execution log.
6218@item
6219Maximum number of instructions that may be contained in the execution log.
6220@end itemize
53cc454a
HZ
6221
6222@kindex record delete
6223@kindex rec del
6224@item record delete
a2311334 6225When record target runs in replay mode (``in the past''), delete the
53cc454a 6226subsequent execution log and begin to record a new execution log starting
a2311334 6227from the current address. This means you will abandon the previously
53cc454a
HZ
6228recorded ``future'' and begin recording a new ``future''.
6229@end table
6230
6231
6d2ebf8b 6232@node Stack
c906108c
SS
6233@chapter Examining the Stack
6234
6235When your program has stopped, the first thing you need to know is where it
6236stopped and how it got there.
6237
6238@cindex call stack
5d161b24
DB
6239Each time your program performs a function call, information about the call
6240is generated.
6241That information includes the location of the call in your program,
6242the arguments of the call,
c906108c 6243and the local variables of the function being called.
5d161b24 6244The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
6245The stack frames are allocated in a region of memory called the @dfn{call
6246stack}.
6247
6248When your program stops, the @value{GDBN} commands for examining the
6249stack allow you to see all of this information.
6250
6251@cindex selected frame
6252One of the stack frames is @dfn{selected} by @value{GDBN} and many
6253@value{GDBN} commands refer implicitly to the selected frame. In
6254particular, whenever you ask @value{GDBN} for the value of a variable in
6255your program, the value is found in the selected frame. There are
6256special @value{GDBN} commands to select whichever frame you are
79a6e687 6257interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
6258
6259When your program stops, @value{GDBN} automatically selects the
5d161b24 6260currently executing frame and describes it briefly, similar to the
79a6e687 6261@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
6262
6263@menu
6264* Frames:: Stack frames
6265* Backtrace:: Backtraces
6266* Selection:: Selecting a frame
6267* Frame Info:: Information on a frame
c906108c
SS
6268
6269@end menu
6270
6d2ebf8b 6271@node Frames
79a6e687 6272@section Stack Frames
c906108c 6273
d4f3574e 6274@cindex frame, definition
c906108c
SS
6275@cindex stack frame
6276The call stack is divided up into contiguous pieces called @dfn{stack
6277frames}, or @dfn{frames} for short; each frame is the data associated
6278with one call to one function. The frame contains the arguments given
6279to the function, the function's local variables, and the address at
6280which the function is executing.
6281
6282@cindex initial frame
6283@cindex outermost frame
6284@cindex innermost frame
6285When your program is started, the stack has only one frame, that of the
6286function @code{main}. This is called the @dfn{initial} frame or the
6287@dfn{outermost} frame. Each time a function is called, a new frame is
6288made. Each time a function returns, the frame for that function invocation
6289is eliminated. If a function is recursive, there can be many frames for
6290the same function. The frame for the function in which execution is
6291actually occurring is called the @dfn{innermost} frame. This is the most
6292recently created of all the stack frames that still exist.
6293
6294@cindex frame pointer
6295Inside your program, stack frames are identified by their addresses. A
6296stack frame consists of many bytes, each of which has its own address; each
6297kind of computer has a convention for choosing one byte whose
6298address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
6299in a register called the @dfn{frame pointer register}
6300(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c
SS
6301
6302@cindex frame number
6303@value{GDBN} assigns numbers to all existing stack frames, starting with
6304zero for the innermost frame, one for the frame that called it,
6305and so on upward. These numbers do not really exist in your program;
6306they are assigned by @value{GDBN} to give you a way of designating stack
6307frames in @value{GDBN} commands.
6308
6d2ebf8b
SS
6309@c The -fomit-frame-pointer below perennially causes hbox overflow
6310@c underflow problems.
c906108c
SS
6311@cindex frameless execution
6312Some compilers provide a way to compile functions so that they operate
e22ea452 6313without stack frames. (For example, the @value{NGCC} option
474c8240 6314@smallexample
6d2ebf8b 6315@samp{-fomit-frame-pointer}
474c8240 6316@end smallexample
6d2ebf8b 6317generates functions without a frame.)
c906108c
SS
6318This is occasionally done with heavily used library functions to save
6319the frame setup time. @value{GDBN} has limited facilities for dealing
6320with these function invocations. If the innermost function invocation
6321has no stack frame, @value{GDBN} nevertheless regards it as though
6322it had a separate frame, which is numbered zero as usual, allowing
6323correct tracing of the function call chain. However, @value{GDBN} has
6324no provision for frameless functions elsewhere in the stack.
6325
6326@table @code
d4f3574e 6327@kindex frame@r{, command}
41afff9a 6328@cindex current stack frame
c906108c 6329@item frame @var{args}
5d161b24 6330The @code{frame} command allows you to move from one stack frame to another,
c906108c 6331and to print the stack frame you select. @var{args} may be either the
5d161b24
DB
6332address of the frame or the stack frame number. Without an argument,
6333@code{frame} prints the current stack frame.
c906108c
SS
6334
6335@kindex select-frame
41afff9a 6336@cindex selecting frame silently
c906108c
SS
6337@item select-frame
6338The @code{select-frame} command allows you to move from one stack frame
6339to another without printing the frame. This is the silent version of
6340@code{frame}.
6341@end table
6342
6d2ebf8b 6343@node Backtrace
c906108c
SS
6344@section Backtraces
6345
09d4efe1
EZ
6346@cindex traceback
6347@cindex call stack traces
c906108c
SS
6348A backtrace is a summary of how your program got where it is. It shows one
6349line per frame, for many frames, starting with the currently executing
6350frame (frame zero), followed by its caller (frame one), and on up the
6351stack.
6352
6353@table @code
6354@kindex backtrace
41afff9a 6355@kindex bt @r{(@code{backtrace})}
c906108c
SS
6356@item backtrace
6357@itemx bt
6358Print a backtrace of the entire stack: one line per frame for all
6359frames in the stack.
6360
6361You can stop the backtrace at any time by typing the system interrupt
c8aa23ab 6362character, normally @kbd{Ctrl-c}.
c906108c
SS
6363
6364@item backtrace @var{n}
6365@itemx bt @var{n}
6366Similar, but print only the innermost @var{n} frames.
6367
6368@item backtrace -@var{n}
6369@itemx bt -@var{n}
6370Similar, but print only the outermost @var{n} frames.
0f061b69
NR
6371
6372@item backtrace full
0f061b69 6373@itemx bt full
dd74f6ae
NR
6374@itemx bt full @var{n}
6375@itemx bt full -@var{n}
e7109c7e 6376Print the values of the local variables also. @var{n} specifies the
286ba84d 6377number of frames to print, as described above.
c906108c
SS
6378@end table
6379
6380@kindex where
6381@kindex info stack
c906108c
SS
6382The names @code{where} and @code{info stack} (abbreviated @code{info s})
6383are additional aliases for @code{backtrace}.
6384
839c27b7
EZ
6385@cindex multiple threads, backtrace
6386In a multi-threaded program, @value{GDBN} by default shows the
6387backtrace only for the current thread. To display the backtrace for
6388several or all of the threads, use the command @code{thread apply}
6389(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
6390apply all backtrace}, @value{GDBN} will display the backtrace for all
6391the threads; this is handy when you debug a core dump of a
6392multi-threaded program.
6393
c906108c
SS
6394Each line in the backtrace shows the frame number and the function name.
6395The program counter value is also shown---unless you use @code{set
6396print address off}. The backtrace also shows the source file name and
6397line number, as well as the arguments to the function. The program
6398counter value is omitted if it is at the beginning of the code for that
6399line number.
6400
6401Here is an example of a backtrace. It was made with the command
6402@samp{bt 3}, so it shows the innermost three frames.
6403
6404@smallexample
6405@group
5d161b24 6406#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 6407 at builtin.c:993
4f5376b2 6408#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
6409#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6410 at macro.c:71
6411(More stack frames follow...)
6412@end group
6413@end smallexample
6414
6415@noindent
6416The display for frame zero does not begin with a program counter
6417value, indicating that your program has stopped at the beginning of the
6418code for line @code{993} of @code{builtin.c}.
6419
4f5376b2
JB
6420@noindent
6421The value of parameter @code{data} in frame 1 has been replaced by
6422@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
6423only if it is a scalar (integer, pointer, enumeration, etc). See command
6424@kbd{set print frame-arguments} in @ref{Print Settings} for more details
6425on how to configure the way function parameter values are printed.
6426
585fdaa1 6427@cindex optimized out, in backtrace
18999be5
EZ
6428@cindex function call arguments, optimized out
6429If your program was compiled with optimizations, some compilers will
6430optimize away arguments passed to functions if those arguments are
6431never used after the call. Such optimizations generate code that
6432passes arguments through registers, but doesn't store those arguments
6433in the stack frame. @value{GDBN} has no way of displaying such
6434arguments in stack frames other than the innermost one. Here's what
6435such a backtrace might look like:
6436
6437@smallexample
6438@group
6439#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6440 at builtin.c:993
585fdaa1
PA
6441#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6442#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
6443 at macro.c:71
6444(More stack frames follow...)
6445@end group
6446@end smallexample
6447
6448@noindent
6449The values of arguments that were not saved in their stack frames are
585fdaa1 6450shown as @samp{<optimized out>}.
18999be5
EZ
6451
6452If you need to display the values of such optimized-out arguments,
6453either deduce that from other variables whose values depend on the one
6454you are interested in, or recompile without optimizations.
6455
a8f24a35
EZ
6456@cindex backtrace beyond @code{main} function
6457@cindex program entry point
6458@cindex startup code, and backtrace
25d29d70
AC
6459Most programs have a standard user entry point---a place where system
6460libraries and startup code transition into user code. For C this is
d416eeec
EZ
6461@code{main}@footnote{
6462Note that embedded programs (the so-called ``free-standing''
6463environment) are not required to have a @code{main} function as the
6464entry point. They could even have multiple entry points.}.
6465When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
6466it will terminate the backtrace, to avoid tracing into highly
6467system-specific (and generally uninteresting) code.
6468
6469If you need to examine the startup code, or limit the number of levels
6470in a backtrace, you can change this behavior:
95f90d25
DJ
6471
6472@table @code
25d29d70
AC
6473@item set backtrace past-main
6474@itemx set backtrace past-main on
4644b6e3 6475@kindex set backtrace
25d29d70
AC
6476Backtraces will continue past the user entry point.
6477
6478@item set backtrace past-main off
95f90d25
DJ
6479Backtraces will stop when they encounter the user entry point. This is the
6480default.
6481
25d29d70 6482@item show backtrace past-main
4644b6e3 6483@kindex show backtrace
25d29d70
AC
6484Display the current user entry point backtrace policy.
6485
2315ffec
RC
6486@item set backtrace past-entry
6487@itemx set backtrace past-entry on
a8f24a35 6488Backtraces will continue past the internal entry point of an application.
2315ffec
RC
6489This entry point is encoded by the linker when the application is built,
6490and is likely before the user entry point @code{main} (or equivalent) is called.
6491
6492@item set backtrace past-entry off
d3e8051b 6493Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
6494application. This is the default.
6495
6496@item show backtrace past-entry
6497Display the current internal entry point backtrace policy.
6498
25d29d70
AC
6499@item set backtrace limit @var{n}
6500@itemx set backtrace limit 0
6501@cindex backtrace limit
6502Limit the backtrace to @var{n} levels. A value of zero means
6503unlimited.
95f90d25 6504
25d29d70
AC
6505@item show backtrace limit
6506Display the current limit on backtrace levels.
95f90d25
DJ
6507@end table
6508
6d2ebf8b 6509@node Selection
79a6e687 6510@section Selecting a Frame
c906108c
SS
6511
6512Most commands for examining the stack and other data in your program work on
6513whichever stack frame is selected at the moment. Here are the commands for
6514selecting a stack frame; all of them finish by printing a brief description
6515of the stack frame just selected.
6516
6517@table @code
d4f3574e 6518@kindex frame@r{, selecting}
41afff9a 6519@kindex f @r{(@code{frame})}
c906108c
SS
6520@item frame @var{n}
6521@itemx f @var{n}
6522Select frame number @var{n}. Recall that frame zero is the innermost
6523(currently executing) frame, frame one is the frame that called the
6524innermost one, and so on. The highest-numbered frame is the one for
6525@code{main}.
6526
6527@item frame @var{addr}
6528@itemx f @var{addr}
6529Select the frame at address @var{addr}. This is useful mainly if the
6530chaining of stack frames has been damaged by a bug, making it
6531impossible for @value{GDBN} to assign numbers properly to all frames. In
6532addition, this can be useful when your program has multiple stacks and
6533switches between them.
6534
c906108c
SS
6535On the SPARC architecture, @code{frame} needs two addresses to
6536select an arbitrary frame: a frame pointer and a stack pointer.
6537
eb17f351 6538On the @acronym{MIPS} and Alpha architecture, it needs two addresses: a stack
c906108c
SS
6539pointer and a program counter.
6540
6541On the 29k architecture, it needs three addresses: a register stack
6542pointer, a program counter, and a memory stack pointer.
c906108c
SS
6543
6544@kindex up
6545@item up @var{n}
6546Move @var{n} frames up the stack. For positive numbers @var{n}, this
6547advances toward the outermost frame, to higher frame numbers, to frames
6548that have existed longer. @var{n} defaults to one.
6549
6550@kindex down
41afff9a 6551@kindex do @r{(@code{down})}
c906108c
SS
6552@item down @var{n}
6553Move @var{n} frames down the stack. For positive numbers @var{n}, this
6554advances toward the innermost frame, to lower frame numbers, to frames
6555that were created more recently. @var{n} defaults to one. You may
6556abbreviate @code{down} as @code{do}.
6557@end table
6558
6559All of these commands end by printing two lines of output describing the
6560frame. The first line shows the frame number, the function name, the
6561arguments, and the source file and line number of execution in that
5d161b24 6562frame. The second line shows the text of that source line.
c906108c
SS
6563
6564@need 1000
6565For example:
6566
6567@smallexample
6568@group
6569(@value{GDBP}) up
6570#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6571 at env.c:10
657210 read_input_file (argv[i]);
6573@end group
6574@end smallexample
6575
6576After such a printout, the @code{list} command with no arguments
6577prints ten lines centered on the point of execution in the frame.
87885426
FN
6578You can also edit the program at the point of execution with your favorite
6579editing program by typing @code{edit}.
79a6e687 6580@xref{List, ,Printing Source Lines},
87885426 6581for details.
c906108c
SS
6582
6583@table @code
6584@kindex down-silently
6585@kindex up-silently
6586@item up-silently @var{n}
6587@itemx down-silently @var{n}
6588These two commands are variants of @code{up} and @code{down},
6589respectively; they differ in that they do their work silently, without
6590causing display of the new frame. They are intended primarily for use
6591in @value{GDBN} command scripts, where the output might be unnecessary and
6592distracting.
6593@end table
6594
6d2ebf8b 6595@node Frame Info
79a6e687 6596@section Information About a Frame
c906108c
SS
6597
6598There are several other commands to print information about the selected
6599stack frame.
6600
6601@table @code
6602@item frame
6603@itemx f
6604When used without any argument, this command does not change which
6605frame is selected, but prints a brief description of the currently
6606selected stack frame. It can be abbreviated @code{f}. With an
6607argument, this command is used to select a stack frame.
79a6e687 6608@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6609
6610@kindex info frame
41afff9a 6611@kindex info f @r{(@code{info frame})}
c906108c
SS
6612@item info frame
6613@itemx info f
6614This command prints a verbose description of the selected stack frame,
6615including:
6616
6617@itemize @bullet
5d161b24
DB
6618@item
6619the address of the frame
c906108c
SS
6620@item
6621the address of the next frame down (called by this frame)
6622@item
6623the address of the next frame up (caller of this frame)
6624@item
6625the language in which the source code corresponding to this frame is written
6626@item
6627the address of the frame's arguments
6628@item
d4f3574e
SS
6629the address of the frame's local variables
6630@item
c906108c
SS
6631the program counter saved in it (the address of execution in the caller frame)
6632@item
6633which registers were saved in the frame
6634@end itemize
6635
6636@noindent The verbose description is useful when
6637something has gone wrong that has made the stack format fail to fit
6638the usual conventions.
6639
6640@item info frame @var{addr}
6641@itemx info f @var{addr}
6642Print a verbose description of the frame at address @var{addr}, without
6643selecting that frame. The selected frame remains unchanged by this
6644command. This requires the same kind of address (more than one for some
6645architectures) that you specify in the @code{frame} command.
79a6e687 6646@xref{Selection, ,Selecting a Frame}.
c906108c
SS
6647
6648@kindex info args
6649@item info args
6650Print the arguments of the selected frame, each on a separate line.
6651
6652@item info locals
6653@kindex info locals
6654Print the local variables of the selected frame, each on a separate
6655line. These are all variables (declared either static or automatic)
6656accessible at the point of execution of the selected frame.
6657
c906108c
SS
6658@end table
6659
c906108c 6660
6d2ebf8b 6661@node Source
c906108c
SS
6662@chapter Examining Source Files
6663
6664@value{GDBN} can print parts of your program's source, since the debugging
6665information recorded in the program tells @value{GDBN} what source files were
6666used to build it. When your program stops, @value{GDBN} spontaneously prints
6667the line where it stopped. Likewise, when you select a stack frame
79a6e687 6668(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
6669execution in that frame has stopped. You can print other portions of
6670source files by explicit command.
6671
7a292a7a 6672If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 6673prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 6674@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
6675
6676@menu
6677* List:: Printing source lines
2a25a5ba 6678* Specify Location:: How to specify code locations
87885426 6679* Edit:: Editing source files
c906108c 6680* Search:: Searching source files
c906108c
SS
6681* Source Path:: Specifying source directories
6682* Machine Code:: Source and machine code
6683@end menu
6684
6d2ebf8b 6685@node List
79a6e687 6686@section Printing Source Lines
c906108c
SS
6687
6688@kindex list
41afff9a 6689@kindex l @r{(@code{list})}
c906108c 6690To print lines from a source file, use the @code{list} command
5d161b24 6691(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
6692There are several ways to specify what part of the file you want to
6693print; see @ref{Specify Location}, for the full list.
c906108c
SS
6694
6695Here are the forms of the @code{list} command most commonly used:
6696
6697@table @code
6698@item list @var{linenum}
6699Print lines centered around line number @var{linenum} in the
6700current source file.
6701
6702@item list @var{function}
6703Print lines centered around the beginning of function
6704@var{function}.
6705
6706@item list
6707Print more lines. If the last lines printed were printed with a
6708@code{list} command, this prints lines following the last lines
6709printed; however, if the last line printed was a solitary line printed
6710as part of displaying a stack frame (@pxref{Stack, ,Examining the
6711Stack}), this prints lines centered around that line.
6712
6713@item list -
6714Print lines just before the lines last printed.
6715@end table
6716
9c16f35a 6717@cindex @code{list}, how many lines to display
c906108c
SS
6718By default, @value{GDBN} prints ten source lines with any of these forms of
6719the @code{list} command. You can change this using @code{set listsize}:
6720
6721@table @code
6722@kindex set listsize
6723@item set listsize @var{count}
6724Make the @code{list} command display @var{count} source lines (unless
6725the @code{list} argument explicitly specifies some other number).
6fc1c773
YQ
6726Setting @var{count} to -1 means there's no limit and 0 means suppress
6727display of source lines.
c906108c
SS
6728
6729@kindex show listsize
6730@item show listsize
6731Display the number of lines that @code{list} prints.
6732@end table
6733
6734Repeating a @code{list} command with @key{RET} discards the argument,
6735so it is equivalent to typing just @code{list}. This is more useful
6736than listing the same lines again. An exception is made for an
6737argument of @samp{-}; that argument is preserved in repetition so that
6738each repetition moves up in the source file.
6739
c906108c
SS
6740In general, the @code{list} command expects you to supply zero, one or two
6741@dfn{linespecs}. Linespecs specify source lines; there are several ways
2a25a5ba
EZ
6742of writing them (@pxref{Specify Location}), but the effect is always
6743to specify some source line.
6744
c906108c
SS
6745Here is a complete description of the possible arguments for @code{list}:
6746
6747@table @code
6748@item list @var{linespec}
6749Print lines centered around the line specified by @var{linespec}.
6750
6751@item list @var{first},@var{last}
6752Print lines from @var{first} to @var{last}. Both arguments are
2a25a5ba
EZ
6753linespecs. When a @code{list} command has two linespecs, and the
6754source file of the second linespec is omitted, this refers to
6755the same source file as the first linespec.
c906108c
SS
6756
6757@item list ,@var{last}
6758Print lines ending with @var{last}.
6759
6760@item list @var{first},
6761Print lines starting with @var{first}.
6762
6763@item list +
6764Print lines just after the lines last printed.
6765
6766@item list -
6767Print lines just before the lines last printed.
6768
6769@item list
6770As described in the preceding table.
6771@end table
6772
2a25a5ba
EZ
6773@node Specify Location
6774@section Specifying a Location
6775@cindex specifying location
6776@cindex linespec
c906108c 6777
2a25a5ba
EZ
6778Several @value{GDBN} commands accept arguments that specify a location
6779of your program's code. Since @value{GDBN} is a source-level
6780debugger, a location usually specifies some line in the source code;
6781for that reason, locations are also known as @dfn{linespecs}.
c906108c 6782
2a25a5ba
EZ
6783Here are all the different ways of specifying a code location that
6784@value{GDBN} understands:
c906108c 6785
2a25a5ba
EZ
6786@table @code
6787@item @var{linenum}
6788Specifies the line number @var{linenum} of the current source file.
c906108c 6789
2a25a5ba
EZ
6790@item -@var{offset}
6791@itemx +@var{offset}
6792Specifies the line @var{offset} lines before or after the @dfn{current
6793line}. For the @code{list} command, the current line is the last one
6794printed; for the breakpoint commands, this is the line at which
6795execution stopped in the currently selected @dfn{stack frame}
6796(@pxref{Frames, ,Frames}, for a description of stack frames.) When
6797used as the second of the two linespecs in a @code{list} command,
6798this specifies the line @var{offset} lines up or down from the first
6799linespec.
6800
6801@item @var{filename}:@var{linenum}
6802Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
6803If @var{filename} is a relative file name, then it will match any
6804source file name with the same trailing components. For example, if
6805@var{filename} is @samp{gcc/expr.c}, then it will match source file
6806name of @file{/build/trunk/gcc/expr.c}, but not
6807@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
6808
6809@item @var{function}
6810Specifies the line that begins the body of the function @var{function}.
2a25a5ba 6811For example, in C, this is the line with the open brace.
c906108c 6812
9ef07c8c
TT
6813@item @var{function}:@var{label}
6814Specifies the line where @var{label} appears in @var{function}.
6815
c906108c 6816@item @var{filename}:@var{function}
2a25a5ba
EZ
6817Specifies the line that begins the body of the function @var{function}
6818in the file @var{filename}. You only need the file name with a
6819function name to avoid ambiguity when there are identically named
6820functions in different source files.
c906108c 6821
0f5238ed
TT
6822@item @var{label}
6823Specifies the line at which the label named @var{label} appears.
6824@value{GDBN} searches for the label in the function corresponding to
6825the currently selected stack frame. If there is no current selected
6826stack frame (for instance, if the inferior is not running), then
6827@value{GDBN} will not search for a label.
6828
c906108c 6829@item *@var{address}
2a25a5ba
EZ
6830Specifies the program address @var{address}. For line-oriented
6831commands, such as @code{list} and @code{edit}, this specifies a source
6832line that contains @var{address}. For @code{break} and other
6833breakpoint oriented commands, this can be used to set breakpoints in
6834parts of your program which do not have debugging information or
6835source files.
6836
6837Here @var{address} may be any expression valid in the current working
6838language (@pxref{Languages, working language}) that specifies a code
5fa54e5d
EZ
6839address. In addition, as a convenience, @value{GDBN} extends the
6840semantics of expressions used in locations to cover the situations
6841that frequently happen during debugging. Here are the various forms
6842of @var{address}:
2a25a5ba
EZ
6843
6844@table @code
6845@item @var{expression}
6846Any expression valid in the current working language.
6847
6848@item @var{funcaddr}
6849An address of a function or procedure derived from its name. In C,
6850C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
6851simply the function's name @var{function} (and actually a special case
6852of a valid expression). In Pascal and Modula-2, this is
6853@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
6854(although the Pascal form also works).
6855
6856This form specifies the address of the function's first instruction,
6857before the stack frame and arguments have been set up.
6858
6859@item '@var{filename}'::@var{funcaddr}
6860Like @var{funcaddr} above, but also specifies the name of the source
6861file explicitly. This is useful if the name of the function does not
6862specify the function unambiguously, e.g., if there are several
6863functions with identical names in different source files.
c906108c
SS
6864@end table
6865
62e5f89c
SDJ
6866@cindex breakpoint at static probe point
6867@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
6868The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
6869applications to embed static probes. @xref{Static Probe Points}, for more
6870information on finding and using static probes. This form of linespec
6871specifies the location of such a static probe.
6872
6873If @var{objfile} is given, only probes coming from that shared library
6874or executable matching @var{objfile} as a regular expression are considered.
6875If @var{provider} is given, then only probes from that provider are considered.
6876If several probes match the spec, @value{GDBN} will insert a breakpoint at
6877each one of those probes.
6878
2a25a5ba
EZ
6879@end table
6880
6881
87885426 6882@node Edit
79a6e687 6883@section Editing Source Files
87885426
FN
6884@cindex editing source files
6885
6886@kindex edit
6887@kindex e @r{(@code{edit})}
6888To edit the lines in a source file, use the @code{edit} command.
6889The editing program of your choice
6890is invoked with the current line set to
6891the active line in the program.
6892Alternatively, there are several ways to specify what part of the file you
2a25a5ba 6893want to print if you want to see other parts of the program:
87885426
FN
6894
6895@table @code
2a25a5ba
EZ
6896@item edit @var{location}
6897Edit the source file specified by @code{location}. Editing starts at
6898that @var{location}, e.g., at the specified source line of the
6899specified file. @xref{Specify Location}, for all the possible forms
6900of the @var{location} argument; here are the forms of the @code{edit}
6901command most commonly used:
87885426 6902
2a25a5ba 6903@table @code
87885426
FN
6904@item edit @var{number}
6905Edit the current source file with @var{number} as the active line number.
6906
6907@item edit @var{function}
6908Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 6909@end table
87885426 6910
87885426
FN
6911@end table
6912
79a6e687 6913@subsection Choosing your Editor
87885426
FN
6914You can customize @value{GDBN} to use any editor you want
6915@footnote{
6916The only restriction is that your editor (say @code{ex}), recognizes the
6917following command-line syntax:
10998722 6918@smallexample
87885426 6919ex +@var{number} file
10998722 6920@end smallexample
15387254
EZ
6921The optional numeric value +@var{number} specifies the number of the line in
6922the file where to start editing.}.
6923By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
6924by setting the environment variable @code{EDITOR} before using
6925@value{GDBN}. For example, to configure @value{GDBN} to use the
6926@code{vi} editor, you could use these commands with the @code{sh} shell:
6927@smallexample
87885426
FN
6928EDITOR=/usr/bin/vi
6929export EDITOR
15387254 6930gdb @dots{}
10998722 6931@end smallexample
87885426 6932or in the @code{csh} shell,
10998722 6933@smallexample
87885426 6934setenv EDITOR /usr/bin/vi
15387254 6935gdb @dots{}
10998722 6936@end smallexample
87885426 6937
6d2ebf8b 6938@node Search
79a6e687 6939@section Searching Source Files
15387254 6940@cindex searching source files
c906108c
SS
6941
6942There are two commands for searching through the current source file for a
6943regular expression.
6944
6945@table @code
6946@kindex search
6947@kindex forward-search
1e96de83 6948@kindex fo @r{(@code{forward-search})}
c906108c
SS
6949@item forward-search @var{regexp}
6950@itemx search @var{regexp}
6951The command @samp{forward-search @var{regexp}} checks each line,
6952starting with the one following the last line listed, for a match for
5d161b24 6953@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
6954synonym @samp{search @var{regexp}} or abbreviate the command name as
6955@code{fo}.
6956
09d4efe1 6957@kindex reverse-search
c906108c
SS
6958@item reverse-search @var{regexp}
6959The command @samp{reverse-search @var{regexp}} checks each line, starting
6960with the one before the last line listed and going backward, for a match
6961for @var{regexp}. It lists the line that is found. You can abbreviate
6962this command as @code{rev}.
6963@end table
c906108c 6964
6d2ebf8b 6965@node Source Path
79a6e687 6966@section Specifying Source Directories
c906108c
SS
6967
6968@cindex source path
6969@cindex directories for source files
6970Executable programs sometimes do not record the directories of the source
6971files from which they were compiled, just the names. Even when they do,
6972the directories could be moved between the compilation and your debugging
6973session. @value{GDBN} has a list of directories to search for source files;
6974this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
6975it tries all the directories in the list, in the order they are present
0b66e38c
EZ
6976in the list, until it finds a file with the desired name.
6977
6978For example, suppose an executable references the file
6979@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
6980@file{/mnt/cross}. The file is first looked up literally; if this
6981fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
6982fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
6983message is printed. @value{GDBN} does not look up the parts of the
6984source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
6985Likewise, the subdirectories of the source path are not searched: if
6986the source path is @file{/mnt/cross}, and the binary refers to
6987@file{foo.c}, @value{GDBN} would not find it under
6988@file{/mnt/cross/usr/src/foo-1.0/lib}.
6989
6990Plain file names, relative file names with leading directories, file
6991names containing dots, etc.@: are all treated as described above; for
6992instance, if the source path is @file{/mnt/cross}, and the source file
6993is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
6994@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
6995that---@file{/mnt/cross/foo.c}.
6996
6997Note that the executable search path is @emph{not} used to locate the
cd852561 6998source files.
c906108c
SS
6999
7000Whenever you reset or rearrange the source path, @value{GDBN} clears out
7001any information it has cached about where source files are found and where
7002each line is in the file.
7003
7004@kindex directory
7005@kindex dir
d4f3574e
SS
7006When you start @value{GDBN}, its source path includes only @samp{cdir}
7007and @samp{cwd}, in that order.
c906108c
SS
7008To add other directories, use the @code{directory} command.
7009
4b505b12
AS
7010The search path is used to find both program source files and @value{GDBN}
7011script files (read using the @samp{-command} option and @samp{source} command).
7012
30daae6c
JB
7013In addition to the source path, @value{GDBN} provides a set of commands
7014that manage a list of source path substitution rules. A @dfn{substitution
7015rule} specifies how to rewrite source directories stored in the program's
7016debug information in case the sources were moved to a different
7017directory between compilation and debugging. A rule is made of
7018two strings, the first specifying what needs to be rewritten in
7019the path, and the second specifying how it should be rewritten.
7020In @ref{set substitute-path}, we name these two parts @var{from} and
7021@var{to} respectively. @value{GDBN} does a simple string replacement
7022of @var{from} with @var{to} at the start of the directory part of the
7023source file name, and uses that result instead of the original file
7024name to look up the sources.
7025
7026Using the previous example, suppose the @file{foo-1.0} tree has been
7027moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 7028@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
7029@file{/mnt/cross}. The first lookup will then be
7030@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7031of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
7032substitution rule, use the @code{set substitute-path} command
7033(@pxref{set substitute-path}).
7034
7035To avoid unexpected substitution results, a rule is applied only if the
7036@var{from} part of the directory name ends at a directory separator.
7037For instance, a rule substituting @file{/usr/source} into
7038@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7039not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 7040is applied only at the beginning of the directory name, this rule will
30daae6c
JB
7041not be applied to @file{/root/usr/source/baz.c} either.
7042
7043In many cases, you can achieve the same result using the @code{directory}
7044command. However, @code{set substitute-path} can be more efficient in
7045the case where the sources are organized in a complex tree with multiple
7046subdirectories. With the @code{directory} command, you need to add each
7047subdirectory of your project. If you moved the entire tree while
7048preserving its internal organization, then @code{set substitute-path}
7049allows you to direct the debugger to all the sources with one single
7050command.
7051
7052@code{set substitute-path} is also more than just a shortcut command.
7053The source path is only used if the file at the original location no
7054longer exists. On the other hand, @code{set substitute-path} modifies
7055the debugger behavior to look at the rewritten location instead. So, if
7056for any reason a source file that is not relevant to your executable is
7057located at the original location, a substitution rule is the only
3f94c067 7058method available to point @value{GDBN} at the new location.
30daae6c 7059
29b0e8a2
JM
7060@cindex @samp{--with-relocated-sources}
7061@cindex default source path substitution
7062You can configure a default source path substitution rule by
7063configuring @value{GDBN} with the
7064@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
7065should be the name of a directory under @value{GDBN}'s configured
7066prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7067directory names in debug information under @var{dir} will be adjusted
7068automatically if the installed @value{GDBN} is moved to a new
7069location. This is useful if @value{GDBN}, libraries or executables
7070with debug information and corresponding source code are being moved
7071together.
7072
c906108c
SS
7073@table @code
7074@item directory @var{dirname} @dots{}
7075@item dir @var{dirname} @dots{}
7076Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
7077directory names may be given to this command, separated by @samp{:}
7078(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7079part of absolute file names) or
c906108c
SS
7080whitespace. You may specify a directory that is already in the source
7081path; this moves it forward, so @value{GDBN} searches it sooner.
7082
7083@kindex cdir
7084@kindex cwd
41afff9a 7085@vindex $cdir@r{, convenience variable}
d3e8051b 7086@vindex $cwd@r{, convenience variable}
c906108c
SS
7087@cindex compilation directory
7088@cindex current directory
7089@cindex working directory
7090@cindex directory, current
7091@cindex directory, compilation
7092You can use the string @samp{$cdir} to refer to the compilation
7093directory (if one is recorded), and @samp{$cwd} to refer to the current
7094working directory. @samp{$cwd} is not the same as @samp{.}---the former
7095tracks the current working directory as it changes during your @value{GDBN}
7096session, while the latter is immediately expanded to the current
7097directory at the time you add an entry to the source path.
7098
7099@item directory
cd852561 7100Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
7101
7102@c RET-repeat for @code{directory} is explicitly disabled, but since
7103@c repeating it would be a no-op we do not say that. (thanks to RMS)
7104
99e7ae30
DE
7105@item set directories @var{path-list}
7106@kindex set directories
7107Set the source path to @var{path-list}.
7108@samp{$cdir:$cwd} are added if missing.
7109
c906108c
SS
7110@item show directories
7111@kindex show directories
7112Print the source path: show which directories it contains.
30daae6c
JB
7113
7114@anchor{set substitute-path}
7115@item set substitute-path @var{from} @var{to}
7116@kindex set substitute-path
7117Define a source path substitution rule, and add it at the end of the
7118current list of existing substitution rules. If a rule with the same
7119@var{from} was already defined, then the old rule is also deleted.
7120
7121For example, if the file @file{/foo/bar/baz.c} was moved to
7122@file{/mnt/cross/baz.c}, then the command
7123
7124@smallexample
7125(@value{GDBP}) set substitute-path /usr/src /mnt/cross
7126@end smallexample
7127
7128@noindent
7129will tell @value{GDBN} to replace @samp{/usr/src} with
7130@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
7131@file{baz.c} even though it was moved.
7132
7133In the case when more than one substitution rule have been defined,
7134the rules are evaluated one by one in the order where they have been
7135defined. The first one matching, if any, is selected to perform
7136the substitution.
7137
7138For instance, if we had entered the following commands:
7139
7140@smallexample
7141(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
7142(@value{GDBP}) set substitute-path /usr/src /mnt/src
7143@end smallexample
7144
7145@noindent
7146@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
7147@file{/mnt/include/defs.h} by using the first rule. However, it would
7148use the second rule to rewrite @file{/usr/src/lib/foo.c} into
7149@file{/mnt/src/lib/foo.c}.
7150
7151
7152@item unset substitute-path [path]
7153@kindex unset substitute-path
7154If a path is specified, search the current list of substitution rules
7155for a rule that would rewrite that path. Delete that rule if found.
7156A warning is emitted by the debugger if no rule could be found.
7157
7158If no path is specified, then all substitution rules are deleted.
7159
7160@item show substitute-path [path]
7161@kindex show substitute-path
7162If a path is specified, then print the source path substitution rule
7163which would rewrite that path, if any.
7164
7165If no path is specified, then print all existing source path substitution
7166rules.
7167
c906108c
SS
7168@end table
7169
7170If your source path is cluttered with directories that are no longer of
7171interest, @value{GDBN} may sometimes cause confusion by finding the wrong
7172versions of source. You can correct the situation as follows:
7173
7174@enumerate
7175@item
cd852561 7176Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
7177
7178@item
7179Use @code{directory} with suitable arguments to reinstall the
7180directories you want in the source path. You can add all the
7181directories in one command.
7182@end enumerate
7183
6d2ebf8b 7184@node Machine Code
79a6e687 7185@section Source and Machine Code
15387254 7186@cindex source line and its code address
c906108c
SS
7187
7188You can use the command @code{info line} to map source lines to program
7189addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
7190a range of addresses as machine instructions. You can use the command
7191@code{set disassemble-next-line} to set whether to disassemble next
7192source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 7193mode, the @code{info line} command causes the arrow to point to the
5d161b24 7194line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
7195well as hex.
7196
7197@table @code
7198@kindex info line
7199@item info line @var{linespec}
7200Print the starting and ending addresses of the compiled code for
7201source line @var{linespec}. You can specify source lines in any of
2a25a5ba 7202the ways documented in @ref{Specify Location}.
c906108c
SS
7203@end table
7204
7205For example, we can use @code{info line} to discover the location of
7206the object code for the first line of function
7207@code{m4_changequote}:
7208
d4f3574e
SS
7209@c FIXME: I think this example should also show the addresses in
7210@c symbolic form, as they usually would be displayed.
c906108c 7211@smallexample
96a2c332 7212(@value{GDBP}) info line m4_changequote
c906108c
SS
7213Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
7214@end smallexample
7215
7216@noindent
15387254 7217@cindex code address and its source line
c906108c
SS
7218We can also inquire (using @code{*@var{addr}} as the form for
7219@var{linespec}) what source line covers a particular address:
7220@smallexample
7221(@value{GDBP}) info line *0x63ff
7222Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
7223@end smallexample
7224
7225@cindex @code{$_} and @code{info line}
15387254 7226@cindex @code{x} command, default address
41afff9a 7227@kindex x@r{(examine), and} info line
c906108c
SS
7228After @code{info line}, the default address for the @code{x} command
7229is changed to the starting address of the line, so that @samp{x/i} is
7230sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 7231,Examining Memory}). Also, this address is saved as the value of the
c906108c 7232convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 7233Variables}).
c906108c
SS
7234
7235@table @code
7236@kindex disassemble
7237@cindex assembly instructions
7238@cindex instructions, assembly
7239@cindex machine instructions
7240@cindex listing machine instructions
7241@item disassemble
d14508fe 7242@itemx disassemble /m
9b117ef3 7243@itemx disassemble /r
c906108c 7244This specialized command dumps a range of memory as machine
d14508fe 7245instructions. It can also print mixed source+disassembly by specifying
9b117ef3
HZ
7246the @code{/m} modifier and print the raw instructions in hex as well as
7247in symbolic form by specifying the @code{/r}.
d14508fe 7248The default memory range is the function surrounding the
c906108c
SS
7249program counter of the selected frame. A single argument to this
7250command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
7251surrounding this value. When two arguments are given, they should
7252be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
7253arguments specify a range of addresses to dump, in one of two forms:
7254
7255@table @code
7256@item @var{start},@var{end}
7257the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7258@item @var{start},+@var{length}
7259the addresses from @var{start} (inclusive) to
7260@code{@var{start}+@var{length}} (exclusive).
7261@end table
7262
7263@noindent
7264When 2 arguments are specified, the name of the function is also
7265printed (since there could be several functions in the given range).
21a0512e
PP
7266
7267The argument(s) can be any expression yielding a numeric value, such as
7268@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
7269
7270If the range of memory being disassembled contains current program counter,
7271the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
7272@end table
7273
c906108c
SS
7274The following example shows the disassembly of a range of addresses of
7275HP PA-RISC 2.0 code:
7276
7277@smallexample
21a0512e 7278(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 7279Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
7280 0x32c4 <main+204>: addil 0,dp
7281 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
7282 0x32cc <main+212>: ldil 0x3000,r31
7283 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
7284 0x32d4 <main+220>: ldo 0(r31),rp
7285 0x32d8 <main+224>: addil -0x800,dp
7286 0x32dc <main+228>: ldo 0x588(r1),r26
7287 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
7288End of assembler dump.
7289@end smallexample
c906108c 7290
2b28d209
PP
7291Here is an example showing mixed source+assembly for Intel x86, when the
7292program is stopped just after function prologue:
d14508fe
DE
7293
7294@smallexample
7295(@value{GDBP}) disas /m main
7296Dump of assembler code for function main:
72975 @{
9c419145
PP
7298 0x08048330 <+0>: push %ebp
7299 0x08048331 <+1>: mov %esp,%ebp
7300 0x08048333 <+3>: sub $0x8,%esp
7301 0x08048336 <+6>: and $0xfffffff0,%esp
7302 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
7303
73046 printf ("Hello.\n");
9c419145
PP
7305=> 0x0804833c <+12>: movl $0x8048440,(%esp)
7306 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
7307
73087 return 0;
73098 @}
9c419145
PP
7310 0x08048348 <+24>: mov $0x0,%eax
7311 0x0804834d <+29>: leave
7312 0x0804834e <+30>: ret
d14508fe
DE
7313
7314End of assembler dump.
7315@end smallexample
7316
53a71c06
CR
7317Here is another example showing raw instructions in hex for AMD x86-64,
7318
7319@smallexample
7320(gdb) disas /r 0x400281,+10
7321Dump of assembler code from 0x400281 to 0x40028b:
7322 0x0000000000400281: 38 36 cmp %dh,(%rsi)
7323 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
7324 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
7325 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
7326End of assembler dump.
7327@end smallexample
7328
c906108c
SS
7329Some architectures have more than one commonly-used set of instruction
7330mnemonics or other syntax.
7331
76d17f34
EZ
7332For programs that were dynamically linked and use shared libraries,
7333instructions that call functions or branch to locations in the shared
7334libraries might show a seemingly bogus location---it's actually a
7335location of the relocation table. On some architectures, @value{GDBN}
7336might be able to resolve these to actual function names.
7337
c906108c 7338@table @code
d4f3574e 7339@kindex set disassembly-flavor
d4f3574e
SS
7340@cindex Intel disassembly flavor
7341@cindex AT&T disassembly flavor
7342@item set disassembly-flavor @var{instruction-set}
c906108c
SS
7343Select the instruction set to use when disassembling the
7344program via the @code{disassemble} or @code{x/i} commands.
7345
7346Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
7347can set @var{instruction-set} to either @code{intel} or @code{att}.
7348The default is @code{att}, the AT&T flavor used by default by Unix
7349assemblers for x86-based targets.
9c16f35a
EZ
7350
7351@kindex show disassembly-flavor
7352@item show disassembly-flavor
7353Show the current setting of the disassembly flavor.
c906108c
SS
7354@end table
7355
91440f57
HZ
7356@table @code
7357@kindex set disassemble-next-line
7358@kindex show disassemble-next-line
7359@item set disassemble-next-line
7360@itemx show disassemble-next-line
32ae1842
EZ
7361Control whether or not @value{GDBN} will disassemble the next source
7362line or instruction when execution stops. If ON, @value{GDBN} will
7363display disassembly of the next source line when execution of the
7364program being debugged stops. This is @emph{in addition} to
7365displaying the source line itself, which @value{GDBN} always does if
7366possible. If the next source line cannot be displayed for some reason
7367(e.g., if @value{GDBN} cannot find the source file, or there's no line
7368info in the debug info), @value{GDBN} will display disassembly of the
7369next @emph{instruction} instead of showing the next source line. If
7370AUTO, @value{GDBN} will display disassembly of next instruction only
7371if the source line cannot be displayed. This setting causes
7372@value{GDBN} to display some feedback when you step through a function
7373with no line info or whose source file is unavailable. The default is
7374OFF, which means never display the disassembly of the next line or
7375instruction.
91440f57
HZ
7376@end table
7377
c906108c 7378
6d2ebf8b 7379@node Data
c906108c
SS
7380@chapter Examining Data
7381
7382@cindex printing data
7383@cindex examining data
7384@kindex print
7385@kindex inspect
c906108c 7386The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
7387command (abbreviated @code{p}), or its synonym @code{inspect}. It
7388evaluates and prints the value of an expression of the language your
7389program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
7390Different Languages}). It may also print the expression using a
7391Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
7392
7393@table @code
d4f3574e
SS
7394@item print @var{expr}
7395@itemx print /@var{f} @var{expr}
7396@var{expr} is an expression (in the source language). By default the
7397value of @var{expr} is printed in a format appropriate to its data type;
c906108c 7398you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 7399@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 7400Formats}.
c906108c
SS
7401
7402@item print
7403@itemx print /@var{f}
15387254 7404@cindex reprint the last value
d4f3574e 7405If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 7406@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
7407conveniently inspect the same value in an alternative format.
7408@end table
7409
7410A more low-level way of examining data is with the @code{x} command.
7411It examines data in memory at a specified address and prints it in a
79a6e687 7412specified format. @xref{Memory, ,Examining Memory}.
c906108c 7413
7a292a7a 7414If you are interested in information about types, or about how the
d4f3574e
SS
7415fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7416command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 7417Table}.
c906108c 7418
06fc020f
SCR
7419@cindex exploring hierarchical data structures
7420@kindex explore
7421Another way of examining values of expressions and type information is
7422through the Python extension command @code{explore} (available only if
7423the @value{GDBN} build is configured with @code{--with-python}). It
7424offers an interactive way to start at the highest level (or, the most
7425abstract level) of the data type of an expression (or, the data type
7426itself) and explore all the way down to leaf scalar values/fields
7427embedded in the higher level data types.
7428
7429@table @code
7430@item explore @var{arg}
7431@var{arg} is either an expression (in the source language), or a type
7432visible in the current context of the program being debugged.
7433@end table
7434
7435The working of the @code{explore} command can be illustrated with an
7436example. If a data type @code{struct ComplexStruct} is defined in your
7437C program as
7438
7439@smallexample
7440struct SimpleStruct
7441@{
7442 int i;
7443 double d;
7444@};
7445
7446struct ComplexStruct
7447@{
7448 struct SimpleStruct *ss_p;
7449 int arr[10];
7450@};
7451@end smallexample
7452
7453@noindent
7454followed by variable declarations as
7455
7456@smallexample
7457struct SimpleStruct ss = @{ 10, 1.11 @};
7458struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
7459@end smallexample
7460
7461@noindent
7462then, the value of the variable @code{cs} can be explored using the
7463@code{explore} command as follows.
7464
7465@smallexample
7466(gdb) explore cs
7467The value of `cs' is a struct/class of type `struct ComplexStruct' with
7468the following fields:
7469
7470 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
7471 arr = <Enter 1 to explore this field of type `int [10]'>
7472
7473Enter the field number of choice:
7474@end smallexample
7475
7476@noindent
7477Since the fields of @code{cs} are not scalar values, you are being
7478prompted to chose the field you want to explore. Let's say you choose
7479the field @code{ss_p} by entering @code{0}. Then, since this field is a
7480pointer, you will be asked if it is pointing to a single value. From
7481the declaration of @code{cs} above, it is indeed pointing to a single
7482value, hence you enter @code{y}. If you enter @code{n}, then you will
7483be asked if it were pointing to an array of values, in which case this
7484field will be explored as if it were an array.
7485
7486@smallexample
7487`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
7488Continue exploring it as a pointer to a single value [y/n]: y
7489The value of `*(cs.ss_p)' is a struct/class of type `struct
7490SimpleStruct' with the following fields:
7491
7492 i = 10 .. (Value of type `int')
7493 d = 1.1100000000000001 .. (Value of type `double')
7494
7495Press enter to return to parent value:
7496@end smallexample
7497
7498@noindent
7499If the field @code{arr} of @code{cs} was chosen for exploration by
7500entering @code{1} earlier, then since it is as array, you will be
7501prompted to enter the index of the element in the array that you want
7502to explore.
7503
7504@smallexample
7505`cs.arr' is an array of `int'.
7506Enter the index of the element you want to explore in `cs.arr': 5
7507
7508`(cs.arr)[5]' is a scalar value of type `int'.
7509
7510(cs.arr)[5] = 4
7511
7512Press enter to return to parent value:
7513@end smallexample
7514
7515In general, at any stage of exploration, you can go deeper towards the
7516leaf values by responding to the prompts appropriately, or hit the
7517return key to return to the enclosing data structure (the @i{higher}
7518level data structure).
7519
7520Similar to exploring values, you can use the @code{explore} command to
7521explore types. Instead of specifying a value (which is typically a
7522variable name or an expression valid in the current context of the
7523program being debugged), you specify a type name. If you consider the
7524same example as above, your can explore the type
7525@code{struct ComplexStruct} by passing the argument
7526@code{struct ComplexStruct} to the @code{explore} command.
7527
7528@smallexample
7529(gdb) explore struct ComplexStruct
7530@end smallexample
7531
7532@noindent
7533By responding to the prompts appropriately in the subsequent interactive
7534session, you can explore the type @code{struct ComplexStruct} in a
7535manner similar to how the value @code{cs} was explored in the above
7536example.
7537
7538The @code{explore} command also has two sub-commands,
7539@code{explore value} and @code{explore type}. The former sub-command is
7540a way to explicitly specify that value exploration of the argument is
7541being invoked, while the latter is a way to explicitly specify that type
7542exploration of the argument is being invoked.
7543
7544@table @code
7545@item explore value @var{expr}
7546@cindex explore value
7547This sub-command of @code{explore} explores the value of the
7548expression @var{expr} (if @var{expr} is an expression valid in the
7549current context of the program being debugged). The behavior of this
7550command is identical to that of the behavior of the @code{explore}
7551command being passed the argument @var{expr}.
7552
7553@item explore type @var{arg}
7554@cindex explore type
7555This sub-command of @code{explore} explores the type of @var{arg} (if
7556@var{arg} is a type visible in the current context of program being
7557debugged), or the type of the value/expression @var{arg} (if @var{arg}
7558is an expression valid in the current context of the program being
7559debugged). If @var{arg} is a type, then the behavior of this command is
7560identical to that of the @code{explore} command being passed the
7561argument @var{arg}. If @var{arg} is an expression, then the behavior of
7562this command will be identical to that of the @code{explore} command
7563being passed the type of @var{arg} as the argument.
7564@end table
7565
c906108c
SS
7566@menu
7567* Expressions:: Expressions
6ba66d6a 7568* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
7569* Variables:: Program variables
7570* Arrays:: Artificial arrays
7571* Output Formats:: Output formats
7572* Memory:: Examining memory
7573* Auto Display:: Automatic display
7574* Print Settings:: Print settings
4c374409 7575* Pretty Printing:: Python pretty printing
c906108c
SS
7576* Value History:: Value history
7577* Convenience Vars:: Convenience variables
a72c3253 7578* Convenience Funs:: Convenience functions
c906108c 7579* Registers:: Registers
c906108c 7580* Floating Point Hardware:: Floating point hardware
53c69bd7 7581* Vector Unit:: Vector Unit
721c2651 7582* OS Information:: Auxiliary data provided by operating system
29e57380 7583* Memory Region Attributes:: Memory region attributes
16d9dec6 7584* Dump/Restore Files:: Copy between memory and a file
384ee23f 7585* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
7586* Character Sets:: Debugging programs that use a different
7587 character set than GDB does
09d4efe1 7588* Caching Remote Data:: Data caching for remote targets
08388c79 7589* Searching Memory:: Searching memory for a sequence of bytes
c906108c
SS
7590@end menu
7591
6d2ebf8b 7592@node Expressions
c906108c
SS
7593@section Expressions
7594
7595@cindex expressions
7596@code{print} and many other @value{GDBN} commands accept an expression and
7597compute its value. Any kind of constant, variable or operator defined
7598by the programming language you are using is valid in an expression in
e2e0bcd1
JB
7599@value{GDBN}. This includes conditional expressions, function calls,
7600casts, and string constants. It also includes preprocessor macros, if
7601you compiled your program to include this information; see
7602@ref{Compilation}.
c906108c 7603
15387254 7604@cindex arrays in expressions
d4f3574e
SS
7605@value{GDBN} supports array constants in expressions input by
7606the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
7607you can use the command @code{print @{1, 2, 3@}} to create an array
7608of three integers. If you pass an array to a function or assign it
7609to a program variable, @value{GDBN} copies the array to memory that
7610is @code{malloc}ed in the target program.
c906108c 7611
c906108c
SS
7612Because C is so widespread, most of the expressions shown in examples in
7613this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
7614Languages}, for information on how to use expressions in other
7615languages.
7616
7617In this section, we discuss operators that you can use in @value{GDBN}
7618expressions regardless of your programming language.
7619
15387254 7620@cindex casts, in expressions
c906108c
SS
7621Casts are supported in all languages, not just in C, because it is so
7622useful to cast a number into a pointer in order to examine a structure
7623at that address in memory.
7624@c FIXME: casts supported---Mod2 true?
c906108c
SS
7625
7626@value{GDBN} supports these operators, in addition to those common
7627to programming languages:
7628
7629@table @code
7630@item @@
7631@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 7632@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
7633
7634@item ::
7635@samp{::} allows you to specify a variable in terms of the file or
79a6e687 7636function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
7637
7638@cindex @{@var{type}@}
7639@cindex type casting memory
7640@cindex memory, viewing as typed object
7641@cindex casts, to view memory
7642@item @{@var{type}@} @var{addr}
7643Refers to an object of type @var{type} stored at address @var{addr} in
7644memory. @var{addr} may be any expression whose value is an integer or
7645pointer (but parentheses are required around binary operators, just as in
7646a cast). This construct is allowed regardless of what kind of data is
7647normally supposed to reside at @var{addr}.
7648@end table
7649
6ba66d6a
JB
7650@node Ambiguous Expressions
7651@section Ambiguous Expressions
7652@cindex ambiguous expressions
7653
7654Expressions can sometimes contain some ambiguous elements. For instance,
7655some programming languages (notably Ada, C@t{++} and Objective-C) permit
7656a single function name to be defined several times, for application in
7657different contexts. This is called @dfn{overloading}. Another example
7658involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
7659templates and is typically instantiated several times, resulting in
7660the same function name being defined in different contexts.
7661
7662In some cases and depending on the language, it is possible to adjust
7663the expression to remove the ambiguity. For instance in C@t{++}, you
7664can specify the signature of the function you want to break on, as in
7665@kbd{break @var{function}(@var{types})}. In Ada, using the fully
7666qualified name of your function often makes the expression unambiguous
7667as well.
7668
7669When an ambiguity that needs to be resolved is detected, the debugger
7670has the capability to display a menu of numbered choices for each
7671possibility, and then waits for the selection with the prompt @samp{>}.
7672The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
7673aborts the current command. If the command in which the expression was
7674used allows more than one choice to be selected, the next option in the
7675menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
7676choices.
7677
7678For example, the following session excerpt shows an attempt to set a
7679breakpoint at the overloaded symbol @code{String::after}.
7680We choose three particular definitions of that function name:
7681
7682@c FIXME! This is likely to change to show arg type lists, at least
7683@smallexample
7684@group
7685(@value{GDBP}) b String::after
7686[0] cancel
7687[1] all
7688[2] file:String.cc; line number:867
7689[3] file:String.cc; line number:860
7690[4] file:String.cc; line number:875
7691[5] file:String.cc; line number:853
7692[6] file:String.cc; line number:846
7693[7] file:String.cc; line number:735
7694> 2 4 6
7695Breakpoint 1 at 0xb26c: file String.cc, line 867.
7696Breakpoint 2 at 0xb344: file String.cc, line 875.
7697Breakpoint 3 at 0xafcc: file String.cc, line 846.
7698Multiple breakpoints were set.
7699Use the "delete" command to delete unwanted
7700 breakpoints.
7701(@value{GDBP})
7702@end group
7703@end smallexample
7704
7705@table @code
7706@kindex set multiple-symbols
7707@item set multiple-symbols @var{mode}
7708@cindex multiple-symbols menu
7709
7710This option allows you to adjust the debugger behavior when an expression
7711is ambiguous.
7712
7713By default, @var{mode} is set to @code{all}. If the command with which
7714the expression is used allows more than one choice, then @value{GDBN}
7715automatically selects all possible choices. For instance, inserting
7716a breakpoint on a function using an ambiguous name results in a breakpoint
7717inserted on each possible match. However, if a unique choice must be made,
7718then @value{GDBN} uses the menu to help you disambiguate the expression.
7719For instance, printing the address of an overloaded function will result
7720in the use of the menu.
7721
7722When @var{mode} is set to @code{ask}, the debugger always uses the menu
7723when an ambiguity is detected.
7724
7725Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7726an error due to the ambiguity and the command is aborted.
7727
7728@kindex show multiple-symbols
7729@item show multiple-symbols
7730Show the current value of the @code{multiple-symbols} setting.
7731@end table
7732
6d2ebf8b 7733@node Variables
79a6e687 7734@section Program Variables
c906108c
SS
7735
7736The most common kind of expression to use is the name of a variable
7737in your program.
7738
7739Variables in expressions are understood in the selected stack frame
79a6e687 7740(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
7741
7742@itemize @bullet
7743@item
7744global (or file-static)
7745@end itemize
7746
5d161b24 7747@noindent or
c906108c
SS
7748
7749@itemize @bullet
7750@item
7751visible according to the scope rules of the
7752programming language from the point of execution in that frame
5d161b24 7753@end itemize
c906108c
SS
7754
7755@noindent This means that in the function
7756
474c8240 7757@smallexample
c906108c
SS
7758foo (a)
7759 int a;
7760@{
7761 bar (a);
7762 @{
7763 int b = test ();
7764 bar (b);
7765 @}
7766@}
474c8240 7767@end smallexample
c906108c
SS
7768
7769@noindent
7770you can examine and use the variable @code{a} whenever your program is
7771executing within the function @code{foo}, but you can only use or
7772examine the variable @code{b} while your program is executing inside
7773the block where @code{b} is declared.
7774
7775@cindex variable name conflict
7776There is an exception: you can refer to a variable or function whose
7777scope is a single source file even if the current execution point is not
7778in this file. But it is possible to have more than one such variable or
7779function with the same name (in different source files). If that
7780happens, referring to that name has unpredictable effects. If you wish,
72384ba3 7781you can specify a static variable in a particular function or file by
15387254 7782using the colon-colon (@code{::}) notation:
c906108c 7783
d4f3574e 7784@cindex colon-colon, context for variables/functions
12c27660 7785@ifnotinfo
c906108c 7786@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 7787@cindex @code{::}, context for variables/functions
12c27660 7788@end ifnotinfo
474c8240 7789@smallexample
c906108c
SS
7790@var{file}::@var{variable}
7791@var{function}::@var{variable}
474c8240 7792@end smallexample
c906108c
SS
7793
7794@noindent
7795Here @var{file} or @var{function} is the name of the context for the
7796static @var{variable}. In the case of file names, you can use quotes to
7797make sure @value{GDBN} parses the file name as a single word---for example,
7798to print a global value of @code{x} defined in @file{f2.c}:
7799
474c8240 7800@smallexample
c906108c 7801(@value{GDBP}) p 'f2.c'::x
474c8240 7802@end smallexample
c906108c 7803
72384ba3
PH
7804The @code{::} notation is normally used for referring to
7805static variables, since you typically disambiguate uses of local variables
7806in functions by selecting the appropriate frame and using the
7807simple name of the variable. However, you may also use this notation
7808to refer to local variables in frames enclosing the selected frame:
7809
7810@smallexample
7811void
7812foo (int a)
7813@{
7814 if (a < 10)
7815 bar (a);
7816 else
7817 process (a); /* Stop here */
7818@}
7819
7820int
7821bar (int a)
7822@{
7823 foo (a + 5);
7824@}
7825@end smallexample
7826
7827@noindent
7828For example, if there is a breakpoint at the commented line,
7829here is what you might see
7830when the program stops after executing the call @code{bar(0)}:
7831
7832@smallexample
7833(@value{GDBP}) p a
7834$1 = 10
7835(@value{GDBP}) p bar::a
7836$2 = 5
7837(@value{GDBP}) up 2
7838#2 0x080483d0 in foo (a=5) at foobar.c:12
7839(@value{GDBP}) p a
7840$3 = 5
7841(@value{GDBP}) p bar::a
7842$4 = 0
7843@end smallexample
7844
b37052ae 7845@cindex C@t{++} scope resolution
72384ba3 7846These uses of @samp{::} are very rarely in conflict with the very similar
b37052ae 7847use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
c906108c
SS
7848scope resolution operator in @value{GDBN} expressions.
7849@c FIXME: Um, so what happens in one of those rare cases where it's in
7850@c conflict?? --mew
c906108c
SS
7851
7852@cindex wrong values
7853@cindex variable values, wrong
15387254
EZ
7854@cindex function entry/exit, wrong values of variables
7855@cindex optimized code, wrong values of variables
c906108c
SS
7856@quotation
7857@emph{Warning:} Occasionally, a local variable may appear to have the
7858wrong value at certain points in a function---just after entry to a new
7859scope, and just before exit.
7860@end quotation
7861You may see this problem when you are stepping by machine instructions.
7862This is because, on most machines, it takes more than one instruction to
7863set up a stack frame (including local variable definitions); if you are
7864stepping by machine instructions, variables may appear to have the wrong
7865values until the stack frame is completely built. On exit, it usually
7866also takes more than one machine instruction to destroy a stack frame;
7867after you begin stepping through that group of instructions, local
7868variable definitions may be gone.
7869
7870This may also happen when the compiler does significant optimizations.
7871To be sure of always seeing accurate values, turn off all optimization
7872when compiling.
7873
d4f3574e
SS
7874@cindex ``No symbol "foo" in current context''
7875Another possible effect of compiler optimizations is to optimize
7876unused variables out of existence, or assign variables to registers (as
7877opposed to memory addresses). Depending on the support for such cases
7878offered by the debug info format used by the compiler, @value{GDBN}
7879might not be able to display values for such local variables. If that
7880happens, @value{GDBN} will print a message like this:
7881
474c8240 7882@smallexample
d4f3574e 7883No symbol "foo" in current context.
474c8240 7884@end smallexample
d4f3574e
SS
7885
7886To solve such problems, either recompile without optimizations, or use a
7887different debug info format, if the compiler supports several such
e0f8f636
TT
7888formats. @xref{Compilation}, for more information on choosing compiler
7889options. @xref{C, ,C and C@t{++}}, for more information about debug
7890info formats that are best suited to C@t{++} programs.
d4f3574e 7891
ab1adacd
EZ
7892If you ask to print an object whose contents are unknown to
7893@value{GDBN}, e.g., because its data type is not completely specified
7894by the debug information, @value{GDBN} will say @samp{<incomplete
7895type>}. @xref{Symbols, incomplete type}, for more about this.
7896
36b11add
JK
7897If you append @kbd{@@entry} string to a function parameter name you get its
7898value at the time the function got called. If the value is not available an
7899error message is printed. Entry values are available only with some compilers.
7900Entry values are normally also printed at the function parameter list according
7901to @ref{set print entry-values}.
7902
7903@smallexample
7904Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
790529 i++;
7906(gdb) next
790730 e (i);
7908(gdb) print i
7909$1 = 31
7910(gdb) print i@@entry
7911$2 = 30
7912@end smallexample
7913
3a60f64e
JK
7914Strings are identified as arrays of @code{char} values without specified
7915signedness. Arrays of either @code{signed char} or @code{unsigned char} get
7916printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
7917@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
7918defines literal string type @code{"char"} as @code{char} without a sign.
7919For program code
7920
7921@smallexample
7922char var0[] = "A";
7923signed char var1[] = "A";
7924@end smallexample
7925
7926You get during debugging
7927@smallexample
7928(gdb) print var0
7929$1 = "A"
7930(gdb) print var1
7931$2 = @{65 'A', 0 '\0'@}
7932@end smallexample
7933
6d2ebf8b 7934@node Arrays
79a6e687 7935@section Artificial Arrays
c906108c
SS
7936
7937@cindex artificial array
15387254 7938@cindex arrays
41afff9a 7939@kindex @@@r{, referencing memory as an array}
c906108c
SS
7940It is often useful to print out several successive objects of the
7941same type in memory; a section of an array, or an array of
7942dynamically determined size for which only a pointer exists in the
7943program.
7944
7945You can do this by referring to a contiguous span of memory as an
7946@dfn{artificial array}, using the binary operator @samp{@@}. The left
7947operand of @samp{@@} should be the first element of the desired array
7948and be an individual object. The right operand should be the desired length
7949of the array. The result is an array value whose elements are all of
7950the type of the left argument. The first element is actually the left
7951argument; the second element comes from bytes of memory immediately
7952following those that hold the first element, and so on. Here is an
7953example. If a program says
7954
474c8240 7955@smallexample
c906108c 7956int *array = (int *) malloc (len * sizeof (int));
474c8240 7957@end smallexample
c906108c
SS
7958
7959@noindent
7960you can print the contents of @code{array} with
7961
474c8240 7962@smallexample
c906108c 7963p *array@@len
474c8240 7964@end smallexample
c906108c
SS
7965
7966The left operand of @samp{@@} must reside in memory. Array values made
7967with @samp{@@} in this way behave just like other arrays in terms of
7968subscripting, and are coerced to pointers when used in expressions.
7969Artificial arrays most often appear in expressions via the value history
79a6e687 7970(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
7971
7972Another way to create an artificial array is to use a cast.
7973This re-interprets a value as if it were an array.
7974The value need not be in memory:
474c8240 7975@smallexample
c906108c
SS
7976(@value{GDBP}) p/x (short[2])0x12345678
7977$1 = @{0x1234, 0x5678@}
474c8240 7978@end smallexample
c906108c
SS
7979
7980As a convenience, if you leave the array length out (as in
c3f6f71d 7981@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 7982the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 7983@smallexample
c906108c
SS
7984(@value{GDBP}) p/x (short[])0x12345678
7985$2 = @{0x1234, 0x5678@}
474c8240 7986@end smallexample
c906108c
SS
7987
7988Sometimes the artificial array mechanism is not quite enough; in
7989moderately complex data structures, the elements of interest may not
7990actually be adjacent---for example, if you are interested in the values
7991of pointers in an array. One useful work-around in this situation is
7992to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 7993Variables}) as a counter in an expression that prints the first
c906108c
SS
7994interesting value, and then repeat that expression via @key{RET}. For
7995instance, suppose you have an array @code{dtab} of pointers to
7996structures, and you are interested in the values of a field @code{fv}
7997in each structure. Here is an example of what you might type:
7998
474c8240 7999@smallexample
c906108c
SS
8000set $i = 0
8001p dtab[$i++]->fv
8002@key{RET}
8003@key{RET}
8004@dots{}
474c8240 8005@end smallexample
c906108c 8006
6d2ebf8b 8007@node Output Formats
79a6e687 8008@section Output Formats
c906108c
SS
8009
8010@cindex formatted output
8011@cindex output formats
8012By default, @value{GDBN} prints a value according to its data type. Sometimes
8013this is not what you want. For example, you might want to print a number
8014in hex, or a pointer in decimal. Or you might want to view data in memory
8015at a certain address as a character string or as an instruction. To do
8016these things, specify an @dfn{output format} when you print a value.
8017
8018The simplest use of output formats is to say how to print a value
8019already computed. This is done by starting the arguments of the
8020@code{print} command with a slash and a format letter. The format
8021letters supported are:
8022
8023@table @code
8024@item x
8025Regard the bits of the value as an integer, and print the integer in
8026hexadecimal.
8027
8028@item d
8029Print as integer in signed decimal.
8030
8031@item u
8032Print as integer in unsigned decimal.
8033
8034@item o
8035Print as integer in octal.
8036
8037@item t
8038Print as integer in binary. The letter @samp{t} stands for ``two''.
8039@footnote{@samp{b} cannot be used because these format letters are also
8040used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 8041see @ref{Memory,,Examining Memory}.}
c906108c
SS
8042
8043@item a
8044@cindex unknown address, locating
3d67e040 8045@cindex locate address
c906108c
SS
8046Print as an address, both absolute in hexadecimal and as an offset from
8047the nearest preceding symbol. You can use this format used to discover
8048where (in what function) an unknown address is located:
8049
474c8240 8050@smallexample
c906108c
SS
8051(@value{GDBP}) p/a 0x54320
8052$3 = 0x54320 <_initialize_vx+396>
474c8240 8053@end smallexample
c906108c 8054
3d67e040
EZ
8055@noindent
8056The command @code{info symbol 0x54320} yields similar results.
8057@xref{Symbols, info symbol}.
8058
c906108c 8059@item c
51274035
EZ
8060Regard as an integer and print it as a character constant. This
8061prints both the numerical value and its character representation. The
8062character representation is replaced with the octal escape @samp{\nnn}
8063for characters outside the 7-bit @sc{ascii} range.
c906108c 8064
ea37ba09
DJ
8065Without this format, @value{GDBN} displays @code{char},
8066@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
8067constants. Single-byte members of vectors are displayed as integer
8068data.
8069
c906108c
SS
8070@item f
8071Regard the bits of the value as a floating point number and print
8072using typical floating point syntax.
ea37ba09
DJ
8073
8074@item s
8075@cindex printing strings
8076@cindex printing byte arrays
8077Regard as a string, if possible. With this format, pointers to single-byte
8078data are displayed as null-terminated strings and arrays of single-byte data
8079are displayed as fixed-length strings. Other values are displayed in their
8080natural types.
8081
8082Without this format, @value{GDBN} displays pointers to and arrays of
8083@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
8084strings. Single-byte members of a vector are displayed as an integer
8085array.
a6bac58e
TT
8086
8087@item r
8088@cindex raw printing
8089Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
8090use a Python-based pretty-printer, if one is available (@pxref{Pretty
8091Printing}). This typically results in a higher-level display of the
8092value's contents. The @samp{r} format bypasses any Python
8093pretty-printer which might exist.
c906108c
SS
8094@end table
8095
8096For example, to print the program counter in hex (@pxref{Registers}), type
8097
474c8240 8098@smallexample
c906108c 8099p/x $pc
474c8240 8100@end smallexample
c906108c
SS
8101
8102@noindent
8103Note that no space is required before the slash; this is because command
8104names in @value{GDBN} cannot contain a slash.
8105
8106To reprint the last value in the value history with a different format,
8107you can use the @code{print} command with just a format and no
8108expression. For example, @samp{p/x} reprints the last value in hex.
8109
6d2ebf8b 8110@node Memory
79a6e687 8111@section Examining Memory
c906108c
SS
8112
8113You can use the command @code{x} (for ``examine'') to examine memory in
8114any of several formats, independently of your program's data types.
8115
8116@cindex examining memory
8117@table @code
41afff9a 8118@kindex x @r{(examine memory)}
c906108c
SS
8119@item x/@var{nfu} @var{addr}
8120@itemx x @var{addr}
8121@itemx x
8122Use the @code{x} command to examine memory.
8123@end table
8124
8125@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
8126much memory to display and how to format it; @var{addr} is an
8127expression giving the address where you want to start displaying memory.
8128If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
8129Several commands set convenient defaults for @var{addr}.
8130
8131@table @r
8132@item @var{n}, the repeat count
8133The repeat count is a decimal integer; the default is 1. It specifies
8134how much memory (counting by units @var{u}) to display.
8135@c This really is **decimal**; unaffected by 'set radix' as of GDB
8136@c 4.1.2.
8137
8138@item @var{f}, the display format
51274035
EZ
8139The display format is one of the formats used by @code{print}
8140(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
8141@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
8142The default is @samp{x} (hexadecimal) initially. The default changes
8143each time you use either @code{x} or @code{print}.
c906108c
SS
8144
8145@item @var{u}, the unit size
8146The unit size is any of
8147
8148@table @code
8149@item b
8150Bytes.
8151@item h
8152Halfwords (two bytes).
8153@item w
8154Words (four bytes). This is the initial default.
8155@item g
8156Giant words (eight bytes).
8157@end table
8158
8159Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
8160default unit the next time you use @code{x}. For the @samp{i} format,
8161the unit size is ignored and is normally not written. For the @samp{s} format,
8162the unit size defaults to @samp{b}, unless it is explicitly given.
8163Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
816432-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
8165Note that the results depend on the programming language of the
8166current compilation unit. If the language is C, the @samp{s}
8167modifier will use the UTF-16 encoding while @samp{w} will use
8168UTF-32. The encoding is set by the programming language and cannot
8169be altered.
c906108c
SS
8170
8171@item @var{addr}, starting display address
8172@var{addr} is the address where you want @value{GDBN} to begin displaying
8173memory. The expression need not have a pointer value (though it may);
8174it is always interpreted as an integer address of a byte of memory.
8175@xref{Expressions, ,Expressions}, for more information on expressions. The default for
8176@var{addr} is usually just after the last address examined---but several
8177other commands also set the default address: @code{info breakpoints} (to
8178the address of the last breakpoint listed), @code{info line} (to the
8179starting address of a line), and @code{print} (if you use it to display
8180a value from memory).
8181@end table
8182
8183For example, @samp{x/3uh 0x54320} is a request to display three halfwords
8184(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
8185starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
8186words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 8187@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c
SS
8188
8189Since the letters indicating unit sizes are all distinct from the
8190letters specifying output formats, you do not have to remember whether
8191unit size or format comes first; either order works. The output
8192specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
8193(However, the count @var{n} must come first; @samp{wx4} does not work.)
8194
8195Even though the unit size @var{u} is ignored for the formats @samp{s}
8196and @samp{i}, you might still want to use a count @var{n}; for example,
8197@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
8198including any operands. For convenience, especially when used with
8199the @code{display} command, the @samp{i} format also prints branch delay
8200slot instructions, if any, beyond the count specified, which immediately
8201follow the last instruction that is within the count. The command
8202@code{disassemble} gives an alternative way of inspecting machine
8203instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c
SS
8204
8205All the defaults for the arguments to @code{x} are designed to make it
8206easy to continue scanning memory with minimal specifications each time
8207you use @code{x}. For example, after you have inspected three machine
8208instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
8209with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
8210the repeat count @var{n} is used again; the other arguments default as
8211for successive uses of @code{x}.
8212
2b28d209
PP
8213When examining machine instructions, the instruction at current program
8214counter is shown with a @code{=>} marker. For example:
8215
8216@smallexample
8217(@value{GDBP}) x/5i $pc-6
8218 0x804837f <main+11>: mov %esp,%ebp
8219 0x8048381 <main+13>: push %ecx
8220 0x8048382 <main+14>: sub $0x4,%esp
8221=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
8222 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
8223@end smallexample
8224
c906108c
SS
8225@cindex @code{$_}, @code{$__}, and value history
8226The addresses and contents printed by the @code{x} command are not saved
8227in the value history because there is often too much of them and they
8228would get in the way. Instead, @value{GDBN} makes these values available for
8229subsequent use in expressions as values of the convenience variables
8230@code{$_} and @code{$__}. After an @code{x} command, the last address
8231examined is available for use in expressions in the convenience variable
8232@code{$_}. The contents of that address, as examined, are available in
8233the convenience variable @code{$__}.
8234
8235If the @code{x} command has a repeat count, the address and contents saved
8236are from the last memory unit printed; this is not the same as the last
8237address printed if several units were printed on the last line of output.
8238
09d4efe1
EZ
8239@cindex remote memory comparison
8240@cindex verify remote memory image
8241When you are debugging a program running on a remote target machine
ea35711c 8242(@pxref{Remote Debugging}), you may wish to verify the program's image in the
09d4efe1
EZ
8243remote machine's memory against the executable file you downloaded to
8244the target. The @code{compare-sections} command is provided for such
8245situations.
8246
8247@table @code
8248@kindex compare-sections
8249@item compare-sections @r{[}@var{section-name}@r{]}
8250Compare the data of a loadable section @var{section-name} in the
8251executable file of the program being debugged with the same section in
8252the remote machine's memory, and report any mismatches. With no
8253arguments, compares all loadable sections. This command's
8254availability depends on the target's support for the @code{"qCRC"}
8255remote request.
8256@end table
8257
6d2ebf8b 8258@node Auto Display
79a6e687 8259@section Automatic Display
c906108c
SS
8260@cindex automatic display
8261@cindex display of expressions
8262
8263If you find that you want to print the value of an expression frequently
8264(to see how it changes), you might want to add it to the @dfn{automatic
8265display list} so that @value{GDBN} prints its value each time your program stops.
8266Each expression added to the list is given a number to identify it;
8267to remove an expression from the list, you specify that number.
8268The automatic display looks like this:
8269
474c8240 8270@smallexample
c906108c
SS
82712: foo = 38
82723: bar[5] = (struct hack *) 0x3804
474c8240 8273@end smallexample
c906108c
SS
8274
8275@noindent
8276This display shows item numbers, expressions and their current values. As with
8277displays you request manually using @code{x} or @code{print}, you can
8278specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
8279whether to use @code{print} or @code{x} depending your format
8280specification---it uses @code{x} if you specify either the @samp{i}
8281or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
8282
8283@table @code
8284@kindex display
d4f3574e
SS
8285@item display @var{expr}
8286Add the expression @var{expr} to the list of expressions to display
c906108c
SS
8287each time your program stops. @xref{Expressions, ,Expressions}.
8288
8289@code{display} does not repeat if you press @key{RET} again after using it.
8290
d4f3574e 8291@item display/@var{fmt} @var{expr}
c906108c 8292For @var{fmt} specifying only a display format and not a size or
d4f3574e 8293count, add the expression @var{expr} to the auto-display list but
c906108c 8294arrange to display it each time in the specified format @var{fmt}.
79a6e687 8295@xref{Output Formats,,Output Formats}.
c906108c
SS
8296
8297@item display/@var{fmt} @var{addr}
8298For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
8299number of units, add the expression @var{addr} as a memory address to
8300be examined each time your program stops. Examining means in effect
79a6e687 8301doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
8302@end table
8303
8304For example, @samp{display/i $pc} can be helpful, to see the machine
8305instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 8306is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
8307
8308@table @code
8309@kindex delete display
8310@kindex undisplay
8311@item undisplay @var{dnums}@dots{}
8312@itemx delete display @var{dnums}@dots{}
c9174737
PA
8313Remove items from the list of expressions to display. Specify the
8314numbers of the displays that you want affected with the command
8315argument @var{dnums}. It can be a single display number, one of the
8316numbers shown in the first field of the @samp{info display} display;
8317or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8318
8319@code{undisplay} does not repeat if you press @key{RET} after using it.
8320(Otherwise you would just get the error @samp{No display number @dots{}}.)
8321
8322@kindex disable display
8323@item disable display @var{dnums}@dots{}
8324Disable the display of item numbers @var{dnums}. A disabled display
8325item is not printed automatically, but is not forgotten. It may be
c9174737
PA
8326enabled again later. Specify the numbers of the displays that you
8327want affected with the command argument @var{dnums}. It can be a
8328single display number, one of the numbers shown in the first field of
8329the @samp{info display} display; or it could be a range of display
8330numbers, as in @code{2-4}.
c906108c
SS
8331
8332@kindex enable display
8333@item enable display @var{dnums}@dots{}
8334Enable display of item numbers @var{dnums}. It becomes effective once
8335again in auto display of its expression, until you specify otherwise.
c9174737
PA
8336Specify the numbers of the displays that you want affected with the
8337command argument @var{dnums}. It can be a single display number, one
8338of the numbers shown in the first field of the @samp{info display}
8339display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
8340
8341@item display
8342Display the current values of the expressions on the list, just as is
8343done when your program stops.
8344
8345@kindex info display
8346@item info display
8347Print the list of expressions previously set up to display
8348automatically, each one with its item number, but without showing the
8349values. This includes disabled expressions, which are marked as such.
8350It also includes expressions which would not be displayed right now
8351because they refer to automatic variables not currently available.
8352@end table
8353
15387254 8354@cindex display disabled out of scope
c906108c
SS
8355If a display expression refers to local variables, then it does not make
8356sense outside the lexical context for which it was set up. Such an
8357expression is disabled when execution enters a context where one of its
8358variables is not defined. For example, if you give the command
8359@code{display last_char} while inside a function with an argument
8360@code{last_char}, @value{GDBN} displays this argument while your program
8361continues to stop inside that function. When it stops elsewhere---where
8362there is no variable @code{last_char}---the display is disabled
8363automatically. The next time your program stops where @code{last_char}
8364is meaningful, you can enable the display expression once again.
8365
6d2ebf8b 8366@node Print Settings
79a6e687 8367@section Print Settings
c906108c
SS
8368
8369@cindex format options
8370@cindex print settings
8371@value{GDBN} provides the following ways to control how arrays, structures,
8372and symbols are printed.
8373
8374@noindent
8375These settings are useful for debugging programs in any language:
8376
8377@table @code
4644b6e3 8378@kindex set print
c906108c
SS
8379@item set print address
8380@itemx set print address on
4644b6e3 8381@cindex print/don't print memory addresses
c906108c
SS
8382@value{GDBN} prints memory addresses showing the location of stack
8383traces, structure values, pointer values, breakpoints, and so forth,
8384even when it also displays the contents of those addresses. The default
8385is @code{on}. For example, this is what a stack frame display looks like with
8386@code{set print address on}:
8387
8388@smallexample
8389@group
8390(@value{GDBP}) f
8391#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8392 at input.c:530
8393530 if (lquote != def_lquote)
8394@end group
8395@end smallexample
8396
8397@item set print address off
8398Do not print addresses when displaying their contents. For example,
8399this is the same stack frame displayed with @code{set print address off}:
8400
8401@smallexample
8402@group
8403(@value{GDBP}) set print addr off
8404(@value{GDBP}) f
8405#0 set_quotes (lq="<<", rq=">>") at input.c:530
8406530 if (lquote != def_lquote)
8407@end group
8408@end smallexample
8409
8410You can use @samp{set print address off} to eliminate all machine
8411dependent displays from the @value{GDBN} interface. For example, with
8412@code{print address off}, you should get the same text for backtraces on
8413all machines---whether or not they involve pointer arguments.
8414
4644b6e3 8415@kindex show print
c906108c
SS
8416@item show print address
8417Show whether or not addresses are to be printed.
8418@end table
8419
8420When @value{GDBN} prints a symbolic address, it normally prints the
8421closest earlier symbol plus an offset. If that symbol does not uniquely
8422identify the address (for example, it is a name whose scope is a single
8423source file), you may need to clarify. One way to do this is with
8424@code{info line}, for example @samp{info line *0x4537}. Alternately,
8425you can set @value{GDBN} to print the source file and line number when
8426it prints a symbolic address:
8427
8428@table @code
c906108c 8429@item set print symbol-filename on
9c16f35a
EZ
8430@cindex source file and line of a symbol
8431@cindex symbol, source file and line
c906108c
SS
8432Tell @value{GDBN} to print the source file name and line number of a
8433symbol in the symbolic form of an address.
8434
8435@item set print symbol-filename off
8436Do not print source file name and line number of a symbol. This is the
8437default.
8438
c906108c
SS
8439@item show print symbol-filename
8440Show whether or not @value{GDBN} will print the source file name and
8441line number of a symbol in the symbolic form of an address.
8442@end table
8443
8444Another situation where it is helpful to show symbol filenames and line
8445numbers is when disassembling code; @value{GDBN} shows you the line
8446number and source file that corresponds to each instruction.
8447
8448Also, you may wish to see the symbolic form only if the address being
8449printed is reasonably close to the closest earlier symbol:
8450
8451@table @code
c906108c 8452@item set print max-symbolic-offset @var{max-offset}
4644b6e3 8453@cindex maximum value for offset of closest symbol
c906108c
SS
8454Tell @value{GDBN} to only display the symbolic form of an address if the
8455offset between the closest earlier symbol and the address is less than
5d161b24 8456@var{max-offset}. The default is 0, which tells @value{GDBN}
c906108c
SS
8457to always print the symbolic form of an address if any symbol precedes it.
8458
c906108c
SS
8459@item show print max-symbolic-offset
8460Ask how large the maximum offset is that @value{GDBN} prints in a
8461symbolic address.
8462@end table
8463
8464@cindex wild pointer, interpreting
8465@cindex pointer, finding referent
8466If you have a pointer and you are not sure where it points, try
8467@samp{set print symbol-filename on}. Then you can determine the name
8468and source file location of the variable where it points, using
8469@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
8470For example, here @value{GDBN} shows that a variable @code{ptt} points
8471at another variable @code{t}, defined in @file{hi2.c}:
8472
474c8240 8473@smallexample
c906108c
SS
8474(@value{GDBP}) set print symbol-filename on
8475(@value{GDBP}) p/a ptt
8476$4 = 0xe008 <t in hi2.c>
474c8240 8477@end smallexample
c906108c
SS
8478
8479@quotation
8480@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
8481does not show the symbol name and filename of the referent, even with
8482the appropriate @code{set print} options turned on.
8483@end quotation
8484
9cb709b6
TT
8485You can also enable @samp{/a}-like formatting all the time using
8486@samp{set print symbol on}:
8487
8488@table @code
8489@item set print symbol on
8490Tell @value{GDBN} to print the symbol corresponding to an address, if
8491one exists.
8492
8493@item set print symbol off
8494Tell @value{GDBN} not to print the symbol corresponding to an
8495address. In this mode, @value{GDBN} will still print the symbol
8496corresponding to pointers to functions. This is the default.
8497
8498@item show print symbol
8499Show whether @value{GDBN} will display the symbol corresponding to an
8500address.
8501@end table
8502
c906108c
SS
8503Other settings control how different kinds of objects are printed:
8504
8505@table @code
c906108c
SS
8506@item set print array
8507@itemx set print array on
4644b6e3 8508@cindex pretty print arrays
c906108c
SS
8509Pretty print arrays. This format is more convenient to read,
8510but uses more space. The default is off.
8511
8512@item set print array off
8513Return to compressed format for arrays.
8514
c906108c
SS
8515@item show print array
8516Show whether compressed or pretty format is selected for displaying
8517arrays.
8518
3c9c013a
JB
8519@cindex print array indexes
8520@item set print array-indexes
8521@itemx set print array-indexes on
8522Print the index of each element when displaying arrays. May be more
8523convenient to locate a given element in the array or quickly find the
8524index of a given element in that printed array. The default is off.
8525
8526@item set print array-indexes off
8527Stop printing element indexes when displaying arrays.
8528
8529@item show print array-indexes
8530Show whether the index of each element is printed when displaying
8531arrays.
8532
c906108c 8533@item set print elements @var{number-of-elements}
4644b6e3 8534@cindex number of array elements to print
9c16f35a 8535@cindex limit on number of printed array elements
c906108c
SS
8536Set a limit on how many elements of an array @value{GDBN} will print.
8537If @value{GDBN} is printing a large array, it stops printing after it has
8538printed the number of elements set by the @code{set print elements} command.
8539This limit also applies to the display of strings.
d4f3574e 8540When @value{GDBN} starts, this limit is set to 200.
c906108c
SS
8541Setting @var{number-of-elements} to zero means that the printing is unlimited.
8542
c906108c
SS
8543@item show print elements
8544Display the number of elements of a large array that @value{GDBN} will print.
8545If the number is 0, then the printing is unlimited.
8546
b4740add 8547@item set print frame-arguments @var{value}
a0381d3a 8548@kindex set print frame-arguments
b4740add
JB
8549@cindex printing frame argument values
8550@cindex print all frame argument values
8551@cindex print frame argument values for scalars only
8552@cindex do not print frame argument values
8553This command allows to control how the values of arguments are printed
8554when the debugger prints a frame (@pxref{Frames}). The possible
8555values are:
8556
8557@table @code
8558@item all
4f5376b2 8559The values of all arguments are printed.
b4740add
JB
8560
8561@item scalars
8562Print the value of an argument only if it is a scalar. The value of more
8563complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
8564by @code{@dots{}}. This is the default. Here is an example where
8565only scalar arguments are shown:
b4740add
JB
8566
8567@smallexample
8568#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
8569 at frame-args.c:23
8570@end smallexample
8571
8572@item none
8573None of the argument values are printed. Instead, the value of each argument
8574is replaced by @code{@dots{}}. In this case, the example above now becomes:
8575
8576@smallexample
8577#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
8578 at frame-args.c:23
8579@end smallexample
8580@end table
8581
4f5376b2
JB
8582By default, only scalar arguments are printed. This command can be used
8583to configure the debugger to print the value of all arguments, regardless
8584of their type. However, it is often advantageous to not print the value
8585of more complex parameters. For instance, it reduces the amount of
8586information printed in each frame, making the backtrace more readable.
8587Also, it improves performance when displaying Ada frames, because
8588the computation of large arguments can sometimes be CPU-intensive,
8589especially in large applications. Setting @code{print frame-arguments}
8590to @code{scalars} (the default) or @code{none} avoids this computation,
8591thus speeding up the display of each Ada frame.
b4740add
JB
8592
8593@item show print frame-arguments
8594Show how the value of arguments should be displayed when printing a frame.
8595
36b11add 8596@anchor{set print entry-values}
e18b2753
JK
8597@item set print entry-values @var{value}
8598@kindex set print entry-values
8599Set printing of frame argument values at function entry. In some cases
8600@value{GDBN} can determine the value of function argument which was passed by
8601the function caller, even if the value was modified inside the called function
8602and therefore is different. With optimized code, the current value could be
8603unavailable, but the entry value may still be known.
8604
8605The default value is @code{default} (see below for its description). Older
8606@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
8607this feature will behave in the @code{default} setting the same way as with the
8608@code{no} setting.
8609
8610This functionality is currently supported only by DWARF 2 debugging format and
8611the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
8612@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
8613this information.
8614
8615The @var{value} parameter can be one of the following:
8616
8617@table @code
8618@item no
8619Print only actual parameter values, never print values from function entry
8620point.
8621@smallexample
8622#0 equal (val=5)
8623#0 different (val=6)
8624#0 lost (val=<optimized out>)
8625#0 born (val=10)
8626#0 invalid (val=<optimized out>)
8627@end smallexample
8628
8629@item only
8630Print only parameter values from function entry point. The actual parameter
8631values are never printed.
8632@smallexample
8633#0 equal (val@@entry=5)
8634#0 different (val@@entry=5)
8635#0 lost (val@@entry=5)
8636#0 born (val@@entry=<optimized out>)
8637#0 invalid (val@@entry=<optimized out>)
8638@end smallexample
8639
8640@item preferred
8641Print only parameter values from function entry point. If value from function
8642entry point is not known while the actual value is known, print the actual
8643value for such parameter.
8644@smallexample
8645#0 equal (val@@entry=5)
8646#0 different (val@@entry=5)
8647#0 lost (val@@entry=5)
8648#0 born (val=10)
8649#0 invalid (val@@entry=<optimized out>)
8650@end smallexample
8651
8652@item if-needed
8653Print actual parameter values. If actual parameter value is not known while
8654value from function entry point is known, print the entry point value for such
8655parameter.
8656@smallexample
8657#0 equal (val=5)
8658#0 different (val=6)
8659#0 lost (val@@entry=5)
8660#0 born (val=10)
8661#0 invalid (val=<optimized out>)
8662@end smallexample
8663
8664@item both
8665Always print both the actual parameter value and its value from function entry
8666point, even if values of one or both are not available due to compiler
8667optimizations.
8668@smallexample
8669#0 equal (val=5, val@@entry=5)
8670#0 different (val=6, val@@entry=5)
8671#0 lost (val=<optimized out>, val@@entry=5)
8672#0 born (val=10, val@@entry=<optimized out>)
8673#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
8674@end smallexample
8675
8676@item compact
8677Print the actual parameter value if it is known and also its value from
8678function entry point if it is known. If neither is known, print for the actual
8679value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
8680values are known and identical, print the shortened
8681@code{param=param@@entry=VALUE} notation.
8682@smallexample
8683#0 equal (val=val@@entry=5)
8684#0 different (val=6, val@@entry=5)
8685#0 lost (val@@entry=5)
8686#0 born (val=10)
8687#0 invalid (val=<optimized out>)
8688@end smallexample
8689
8690@item default
8691Always print the actual parameter value. Print also its value from function
8692entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
8693if both values are known and identical, print the shortened
8694@code{param=param@@entry=VALUE} notation.
8695@smallexample
8696#0 equal (val=val@@entry=5)
8697#0 different (val=6, val@@entry=5)
8698#0 lost (val=<optimized out>, val@@entry=5)
8699#0 born (val=10)
8700#0 invalid (val=<optimized out>)
8701@end smallexample
8702@end table
8703
8704For analysis messages on possible failures of frame argument values at function
8705entry resolution see @ref{set debug entry-values}.
8706
8707@item show print entry-values
8708Show the method being used for printing of frame argument values at function
8709entry.
8710
9c16f35a
EZ
8711@item set print repeats
8712@cindex repeated array elements
8713Set the threshold for suppressing display of repeated array
d3e8051b 8714elements. When the number of consecutive identical elements of an
9c16f35a
EZ
8715array exceeds the threshold, @value{GDBN} prints the string
8716@code{"<repeats @var{n} times>"}, where @var{n} is the number of
8717identical repetitions, instead of displaying the identical elements
8718themselves. Setting the threshold to zero will cause all elements to
8719be individually printed. The default threshold is 10.
8720
8721@item show print repeats
8722Display the current threshold for printing repeated identical
8723elements.
8724
c906108c 8725@item set print null-stop
4644b6e3 8726@cindex @sc{null} elements in arrays
c906108c 8727Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 8728@sc{null} is encountered. This is useful when large arrays actually
c906108c 8729contain only short strings.
d4f3574e 8730The default is off.
c906108c 8731
9c16f35a
EZ
8732@item show print null-stop
8733Show whether @value{GDBN} stops printing an array on the first
8734@sc{null} character.
8735
c906108c 8736@item set print pretty on
9c16f35a
EZ
8737@cindex print structures in indented form
8738@cindex indentation in structure display
5d161b24 8739Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
8740per line, like this:
8741
8742@smallexample
8743@group
8744$1 = @{
8745 next = 0x0,
8746 flags = @{
8747 sweet = 1,
8748 sour = 1
8749 @},
8750 meat = 0x54 "Pork"
8751@}
8752@end group
8753@end smallexample
8754
8755@item set print pretty off
8756Cause @value{GDBN} to print structures in a compact format, like this:
8757
8758@smallexample
8759@group
8760$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
8761meat = 0x54 "Pork"@}
8762@end group
8763@end smallexample
8764
8765@noindent
8766This is the default format.
8767
c906108c
SS
8768@item show print pretty
8769Show which format @value{GDBN} is using to print structures.
8770
c906108c 8771@item set print sevenbit-strings on
4644b6e3
EZ
8772@cindex eight-bit characters in strings
8773@cindex octal escapes in strings
c906108c
SS
8774Print using only seven-bit characters; if this option is set,
8775@value{GDBN} displays any eight-bit characters (in strings or
8776character values) using the notation @code{\}@var{nnn}. This setting is
8777best if you are working in English (@sc{ascii}) and you use the
8778high-order bit of characters as a marker or ``meta'' bit.
8779
8780@item set print sevenbit-strings off
8781Print full eight-bit characters. This allows the use of more
8782international character sets, and is the default.
8783
c906108c
SS
8784@item show print sevenbit-strings
8785Show whether or not @value{GDBN} is printing only seven-bit characters.
8786
c906108c 8787@item set print union on
4644b6e3 8788@cindex unions in structures, printing
9c16f35a
EZ
8789Tell @value{GDBN} to print unions which are contained in structures
8790and other unions. This is the default setting.
c906108c
SS
8791
8792@item set print union off
9c16f35a
EZ
8793Tell @value{GDBN} not to print unions which are contained in
8794structures and other unions. @value{GDBN} will print @code{"@{...@}"}
8795instead.
c906108c 8796
c906108c
SS
8797@item show print union
8798Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 8799structures and other unions.
c906108c
SS
8800
8801For example, given the declarations
8802
8803@smallexample
8804typedef enum @{Tree, Bug@} Species;
8805typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 8806typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
8807 Bug_forms;
8808
8809struct thing @{
8810 Species it;
8811 union @{
8812 Tree_forms tree;
8813 Bug_forms bug;
8814 @} form;
8815@};
8816
8817struct thing foo = @{Tree, @{Acorn@}@};
8818@end smallexample
8819
8820@noindent
8821with @code{set print union on} in effect @samp{p foo} would print
8822
8823@smallexample
8824$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
8825@end smallexample
8826
8827@noindent
8828and with @code{set print union off} in effect it would print
8829
8830@smallexample
8831$1 = @{it = Tree, form = @{...@}@}
8832@end smallexample
9c16f35a
EZ
8833
8834@noindent
8835@code{set print union} affects programs written in C-like languages
8836and in Pascal.
c906108c
SS
8837@end table
8838
c906108c
SS
8839@need 1000
8840@noindent
b37052ae 8841These settings are of interest when debugging C@t{++} programs:
c906108c
SS
8842
8843@table @code
4644b6e3 8844@cindex demangling C@t{++} names
c906108c
SS
8845@item set print demangle
8846@itemx set print demangle on
b37052ae 8847Print C@t{++} names in their source form rather than in the encoded
c906108c 8848(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 8849linkage. The default is on.
c906108c 8850
c906108c 8851@item show print demangle
b37052ae 8852Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 8853
c906108c
SS
8854@item set print asm-demangle
8855@itemx set print asm-demangle on
b37052ae 8856Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
8857in assembler code printouts such as instruction disassemblies.
8858The default is off.
8859
c906108c 8860@item show print asm-demangle
b37052ae 8861Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
8862or demangled form.
8863
b37052ae
EZ
8864@cindex C@t{++} symbol decoding style
8865@cindex symbol decoding style, C@t{++}
a8f24a35 8866@kindex set demangle-style
c906108c
SS
8867@item set demangle-style @var{style}
8868Choose among several encoding schemes used by different compilers to
b37052ae 8869represent C@t{++} names. The choices for @var{style} are currently:
c906108c
SS
8870
8871@table @code
8872@item auto
8873Allow @value{GDBN} to choose a decoding style by inspecting your program.
891df0ea 8874This is the default.
c906108c
SS
8875
8876@item gnu
b37052ae 8877Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
c906108c
SS
8878
8879@item hp
b37052ae 8880Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
c906108c
SS
8881
8882@item lucid
b37052ae 8883Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
c906108c
SS
8884
8885@item arm
b37052ae 8886Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
c906108c
SS
8887@strong{Warning:} this setting alone is not sufficient to allow
8888debugging @code{cfront}-generated executables. @value{GDBN} would
8889require further enhancement to permit that.
8890
8891@end table
8892If you omit @var{style}, you will see a list of possible formats.
8893
c906108c 8894@item show demangle-style
b37052ae 8895Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 8896
c906108c
SS
8897@item set print object
8898@itemx set print object on
4644b6e3 8899@cindex derived type of an object, printing
9c16f35a 8900@cindex display derived types
c906108c
SS
8901When displaying a pointer to an object, identify the @emph{actual}
8902(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
8903the virtual function table. Note that the virtual function table is
8904required---this feature can only work for objects that have run-time
8905type identification; a single virtual method in the object's declared
8264ba82
AG
8906type is sufficient. Note that this setting is also taken into account when
8907working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
8908
8909@item set print object off
8910Display only the declared type of objects, without reference to the
8911virtual function table. This is the default setting.
8912
c906108c
SS
8913@item show print object
8914Show whether actual, or declared, object types are displayed.
8915
c906108c
SS
8916@item set print static-members
8917@itemx set print static-members on
4644b6e3 8918@cindex static members of C@t{++} objects
b37052ae 8919Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
8920
8921@item set print static-members off
b37052ae 8922Do not print static members when displaying a C@t{++} object.
c906108c 8923
c906108c 8924@item show print static-members
9c16f35a
EZ
8925Show whether C@t{++} static members are printed or not.
8926
8927@item set print pascal_static-members
8928@itemx set print pascal_static-members on
d3e8051b
EZ
8929@cindex static members of Pascal objects
8930@cindex Pascal objects, static members display
9c16f35a
EZ
8931Print static members when displaying a Pascal object. The default is on.
8932
8933@item set print pascal_static-members off
8934Do not print static members when displaying a Pascal object.
8935
8936@item show print pascal_static-members
8937Show whether Pascal static members are printed or not.
c906108c
SS
8938
8939@c These don't work with HP ANSI C++ yet.
c906108c
SS
8940@item set print vtbl
8941@itemx set print vtbl on
4644b6e3 8942@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
8943@cindex virtual functions (C@t{++}) display
8944@cindex VTBL display
b37052ae 8945Pretty print C@t{++} virtual function tables. The default is off.
c906108c 8946(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 8947ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
8948
8949@item set print vtbl off
b37052ae 8950Do not pretty print C@t{++} virtual function tables.
c906108c 8951
c906108c 8952@item show print vtbl
b37052ae 8953Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 8954@end table
c906108c 8955
4c374409
JK
8956@node Pretty Printing
8957@section Pretty Printing
8958
8959@value{GDBN} provides a mechanism to allow pretty-printing of values using
8960Python code. It greatly simplifies the display of complex objects. This
8961mechanism works for both MI and the CLI.
8962
7b51bc51
DE
8963@menu
8964* Pretty-Printer Introduction:: Introduction to pretty-printers
8965* Pretty-Printer Example:: An example pretty-printer
8966* Pretty-Printer Commands:: Pretty-printer commands
8967@end menu
8968
8969@node Pretty-Printer Introduction
8970@subsection Pretty-Printer Introduction
8971
8972When @value{GDBN} prints a value, it first sees if there is a pretty-printer
8973registered for the value. If there is then @value{GDBN} invokes the
8974pretty-printer to print the value. Otherwise the value is printed normally.
8975
8976Pretty-printers are normally named. This makes them easy to manage.
8977The @samp{info pretty-printer} command will list all the installed
8978pretty-printers with their names.
8979If a pretty-printer can handle multiple data types, then its
8980@dfn{subprinters} are the printers for the individual data types.
8981Each such subprinter has its own name.
4e04c971 8982The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
8983
8984Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
8985Typically they are automatically loaded and registered when the corresponding
8986debug information is loaded, thus making them available without having to
8987do anything special.
8988
8989There are three places where a pretty-printer can be registered.
8990
8991@itemize @bullet
8992@item
8993Pretty-printers registered globally are available when debugging
8994all inferiors.
8995
8996@item
8997Pretty-printers registered with a program space are available only
8998when debugging that program.
8999@xref{Progspaces In Python}, for more details on program spaces in Python.
9000
9001@item
9002Pretty-printers registered with an objfile are loaded and unloaded
9003with the corresponding objfile (e.g., shared library).
9004@xref{Objfiles In Python}, for more details on objfiles in Python.
9005@end itemize
9006
9007@xref{Selecting Pretty-Printers}, for further information on how
9008pretty-printers are selected,
9009
9010@xref{Writing a Pretty-Printer}, for implementing pretty printers
9011for new types.
9012
9013@node Pretty-Printer Example
9014@subsection Pretty-Printer Example
9015
9016Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
9017
9018@smallexample
9019(@value{GDBP}) print s
9020$1 = @{
9021 static npos = 4294967295,
9022 _M_dataplus = @{
9023 <std::allocator<char>> = @{
9024 <__gnu_cxx::new_allocator<char>> = @{
9025 <No data fields>@}, <No data fields>
9026 @},
9027 members of std::basic_string<char, std::char_traits<char>,
9028 std::allocator<char> >::_Alloc_hider:
9029 _M_p = 0x804a014 "abcd"
9030 @}
9031@}
9032@end smallexample
9033
9034With a pretty-printer for @code{std::string} only the contents are printed:
9035
9036@smallexample
9037(@value{GDBP}) print s
9038$2 = "abcd"
9039@end smallexample
9040
7b51bc51
DE
9041@node Pretty-Printer Commands
9042@subsection Pretty-Printer Commands
9043@cindex pretty-printer commands
9044
9045@table @code
9046@kindex info pretty-printer
9047@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9048Print the list of installed pretty-printers.
9049This includes disabled pretty-printers, which are marked as such.
9050
9051@var{object-regexp} is a regular expression matching the objects
9052whose pretty-printers to list.
9053Objects can be @code{global}, the program space's file
9054(@pxref{Progspaces In Python}),
9055and the object files within that program space (@pxref{Objfiles In Python}).
9056@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
9057looks up a printer from these three objects.
9058
9059@var{name-regexp} is a regular expression matching the name of the printers
9060to list.
9061
9062@kindex disable pretty-printer
9063@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9064Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9065A disabled pretty-printer is not forgotten, it may be enabled again later.
9066
9067@kindex enable pretty-printer
9068@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9069Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9070@end table
9071
9072Example:
9073
9074Suppose we have three pretty-printers installed: one from library1.so
9075named @code{foo} that prints objects of type @code{foo}, and
9076another from library2.so named @code{bar} that prints two types of objects,
9077@code{bar1} and @code{bar2}.
9078
9079@smallexample
9080(gdb) info pretty-printer
9081library1.so:
9082 foo
9083library2.so:
9084 bar
9085 bar1
9086 bar2
9087(gdb) info pretty-printer library2
9088library2.so:
9089 bar
9090 bar1
9091 bar2
9092(gdb) disable pretty-printer library1
90931 printer disabled
90942 of 3 printers enabled
9095(gdb) info pretty-printer
9096library1.so:
9097 foo [disabled]
9098library2.so:
9099 bar
9100 bar1
9101 bar2
9102(gdb) disable pretty-printer library2 bar:bar1
91031 printer disabled
91041 of 3 printers enabled
9105(gdb) info pretty-printer library2
9106library1.so:
9107 foo [disabled]
9108library2.so:
9109 bar
9110 bar1 [disabled]
9111 bar2
9112(gdb) disable pretty-printer library2 bar
91131 printer disabled
91140 of 3 printers enabled
9115(gdb) info pretty-printer library2
9116library1.so:
9117 foo [disabled]
9118library2.so:
9119 bar [disabled]
9120 bar1 [disabled]
9121 bar2
9122@end smallexample
9123
9124Note that for @code{bar} the entire printer can be disabled,
9125as can each individual subprinter.
4c374409 9126
6d2ebf8b 9127@node Value History
79a6e687 9128@section Value History
c906108c
SS
9129
9130@cindex value history
9c16f35a 9131@cindex history of values printed by @value{GDBN}
5d161b24
DB
9132Values printed by the @code{print} command are saved in the @value{GDBN}
9133@dfn{value history}. This allows you to refer to them in other expressions.
9134Values are kept until the symbol table is re-read or discarded
9135(for example with the @code{file} or @code{symbol-file} commands).
9136When the symbol table changes, the value history is discarded,
9137since the values may contain pointers back to the types defined in the
c906108c
SS
9138symbol table.
9139
9140@cindex @code{$}
9141@cindex @code{$$}
9142@cindex history number
9143The values printed are given @dfn{history numbers} by which you can
9144refer to them. These are successive integers starting with one.
9145@code{print} shows you the history number assigned to a value by
9146printing @samp{$@var{num} = } before the value; here @var{num} is the
9147history number.
9148
9149To refer to any previous value, use @samp{$} followed by the value's
9150history number. The way @code{print} labels its output is designed to
9151remind you of this. Just @code{$} refers to the most recent value in
9152the history, and @code{$$} refers to the value before that.
9153@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
9154is the value just prior to @code{$$}, @code{$$1} is equivalent to
9155@code{$$}, and @code{$$0} is equivalent to @code{$}.
9156
9157For example, suppose you have just printed a pointer to a structure and
9158want to see the contents of the structure. It suffices to type
9159
474c8240 9160@smallexample
c906108c 9161p *$
474c8240 9162@end smallexample
c906108c
SS
9163
9164If you have a chain of structures where the component @code{next} points
9165to the next one, you can print the contents of the next one with this:
9166
474c8240 9167@smallexample
c906108c 9168p *$.next
474c8240 9169@end smallexample
c906108c
SS
9170
9171@noindent
9172You can print successive links in the chain by repeating this
9173command---which you can do by just typing @key{RET}.
9174
9175Note that the history records values, not expressions. If the value of
9176@code{x} is 4 and you type these commands:
9177
474c8240 9178@smallexample
c906108c
SS
9179print x
9180set x=5
474c8240 9181@end smallexample
c906108c
SS
9182
9183@noindent
9184then the value recorded in the value history by the @code{print} command
9185remains 4 even though the value of @code{x} has changed.
9186
9187@table @code
9188@kindex show values
9189@item show values
9190Print the last ten values in the value history, with their item numbers.
9191This is like @samp{p@ $$9} repeated ten times, except that @code{show
9192values} does not change the history.
9193
9194@item show values @var{n}
9195Print ten history values centered on history item number @var{n}.
9196
9197@item show values +
9198Print ten history values just after the values last printed. If no more
9199values are available, @code{show values +} produces no display.
9200@end table
9201
9202Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
9203same effect as @samp{show values +}.
9204
6d2ebf8b 9205@node Convenience Vars
79a6e687 9206@section Convenience Variables
c906108c
SS
9207
9208@cindex convenience variables
9c16f35a 9209@cindex user-defined variables
c906108c
SS
9210@value{GDBN} provides @dfn{convenience variables} that you can use within
9211@value{GDBN} to hold on to a value and refer to it later. These variables
9212exist entirely within @value{GDBN}; they are not part of your program, and
9213setting a convenience variable has no direct effect on further execution
9214of your program. That is why you can use them freely.
9215
9216Convenience variables are prefixed with @samp{$}. Any name preceded by
9217@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 9218the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 9219(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 9220by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
9221
9222You can save a value in a convenience variable with an assignment
9223expression, just as you would set a variable in your program.
9224For example:
9225
474c8240 9226@smallexample
c906108c 9227set $foo = *object_ptr
474c8240 9228@end smallexample
c906108c
SS
9229
9230@noindent
9231would save in @code{$foo} the value contained in the object pointed to by
9232@code{object_ptr}.
9233
9234Using a convenience variable for the first time creates it, but its
9235value is @code{void} until you assign a new value. You can alter the
9236value with another assignment at any time.
9237
9238Convenience variables have no fixed types. You can assign a convenience
9239variable any type of value, including structures and arrays, even if
9240that variable already has a value of a different type. The convenience
9241variable, when used as an expression, has the type of its current value.
9242
9243@table @code
9244@kindex show convenience
f47f77df 9245@cindex show all user variables and functions
c906108c 9246@item show convenience
f47f77df
DE
9247Print a list of convenience variables used so far, and their values,
9248as well as a list of the convenience functions.
d4f3574e 9249Abbreviated @code{show conv}.
53e5f3cf
AS
9250
9251@kindex init-if-undefined
9252@cindex convenience variables, initializing
9253@item init-if-undefined $@var{variable} = @var{expression}
9254Set a convenience variable if it has not already been set. This is useful
9255for user-defined commands that keep some state. It is similar, in concept,
9256to using local static variables with initializers in C (except that
9257convenience variables are global). It can also be used to allow users to
9258override default values used in a command script.
9259
9260If the variable is already defined then the expression is not evaluated so
9261any side-effects do not occur.
c906108c
SS
9262@end table
9263
9264One of the ways to use a convenience variable is as a counter to be
9265incremented or a pointer to be advanced. For example, to print
9266a field from successive elements of an array of structures:
9267
474c8240 9268@smallexample
c906108c
SS
9269set $i = 0
9270print bar[$i++]->contents
474c8240 9271@end smallexample
c906108c 9272
d4f3574e
SS
9273@noindent
9274Repeat that command by typing @key{RET}.
c906108c
SS
9275
9276Some convenience variables are created automatically by @value{GDBN} and given
9277values likely to be useful.
9278
9279@table @code
41afff9a 9280@vindex $_@r{, convenience variable}
c906108c
SS
9281@item $_
9282The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 9283the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
9284commands which provide a default address for @code{x} to examine also
9285set @code{$_} to that address; these commands include @code{info line}
9286and @code{info breakpoint}. The type of @code{$_} is @code{void *}
9287except when set by the @code{x} command, in which case it is a pointer
9288to the type of @code{$__}.
9289
41afff9a 9290@vindex $__@r{, convenience variable}
c906108c
SS
9291@item $__
9292The variable @code{$__} is automatically set by the @code{x} command
9293to the value found in the last address examined. Its type is chosen
9294to match the format in which the data was printed.
9295
9296@item $_exitcode
41afff9a 9297@vindex $_exitcode@r{, convenience variable}
c906108c
SS
9298The variable @code{$_exitcode} is automatically set to the exit code when
9299the program being debugged terminates.
4aa995e1 9300
62e5f89c
SDJ
9301@item $_probe_argc
9302@itemx $_probe_arg0@dots{}$_probe_arg11
9303Arguments to a static probe. @xref{Static Probe Points}.
9304
0fb4aa4b
PA
9305@item $_sdata
9306@vindex $_sdata@r{, inspect, convenience variable}
9307The variable @code{$_sdata} contains extra collected static tracepoint
9308data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
9309@code{$_sdata} could be empty, if not inspecting a trace buffer, or
9310if extra static tracepoint data has not been collected.
9311
4aa995e1
PA
9312@item $_siginfo
9313@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
9314The variable @code{$_siginfo} contains extra signal information
9315(@pxref{extra signal information}). Note that @code{$_siginfo}
9316could be empty, if the application has not yet received any signals.
9317For example, it will be empty before you execute the @code{run} command.
711e434b
PM
9318
9319@item $_tlb
9320@vindex $_tlb@r{, convenience variable}
9321The variable @code{$_tlb} is automatically set when debugging
9322applications running on MS-Windows in native mode or connected to
9323gdbserver that supports the @code{qGetTIBAddr} request.
9324@xref{General Query Packets}.
9325This variable contains the address of the thread information block.
9326
c906108c
SS
9327@end table
9328
53a5351d
JM
9329On HP-UX systems, if you refer to a function or variable name that
9330begins with a dollar sign, @value{GDBN} searches for a user or system
9331name first, before it searches for a convenience variable.
c906108c 9332
a72c3253
DE
9333@node Convenience Funs
9334@section Convenience Functions
9335
bc3b79fd
TJB
9336@cindex convenience functions
9337@value{GDBN} also supplies some @dfn{convenience functions}. These
9338have a syntax similar to convenience variables. A convenience
9339function can be used in an expression just like an ordinary function;
9340however, a convenience function is implemented internally to
9341@value{GDBN}.
9342
a72c3253
DE
9343These functions require @value{GDBN} to be configured with
9344@code{Python} support.
9345
9346@table @code
9347
9348@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
9349@findex $_memeq@r{, convenience function}
9350Returns one if the @var{length} bytes at the addresses given by
9351@var{buf1} and @var{buf2} are equal.
9352Otherwise it returns zero.
9353
9354@item $_regex(@var{str}, @var{regex})
9355@findex $_regex@r{, convenience function}
9356Returns one if the string @var{str} matches the regular expression
9357@var{regex}. Otherwise it returns zero.
9358The syntax of the regular expression is that specified by @code{Python}'s
9359regular expression support.
9360
9361@item $_streq(@var{str1}, @var{str2})
9362@findex $_streq@r{, convenience function}
9363Returns one if the strings @var{str1} and @var{str2} are equal.
9364Otherwise it returns zero.
9365
9366@item $_strlen(@var{str})
9367@findex $_strlen@r{, convenience function}
9368Returns the length of string @var{str}.
9369
9370@end table
9371
9372@value{GDBN} provides the ability to list and get help on
9373convenience functions.
9374
bc3b79fd
TJB
9375@table @code
9376@item help function
9377@kindex help function
9378@cindex show all convenience functions
9379Print a list of all convenience functions.
9380@end table
9381
6d2ebf8b 9382@node Registers
c906108c
SS
9383@section Registers
9384
9385@cindex registers
9386You can refer to machine register contents, in expressions, as variables
9387with names starting with @samp{$}. The names of registers are different
9388for each machine; use @code{info registers} to see the names used on
9389your machine.
9390
9391@table @code
9392@kindex info registers
9393@item info registers
9394Print the names and values of all registers except floating-point
c85508ee 9395and vector registers (in the selected stack frame).
c906108c
SS
9396
9397@kindex info all-registers
9398@cindex floating point registers
9399@item info all-registers
9400Print the names and values of all registers, including floating-point
c85508ee 9401and vector registers (in the selected stack frame).
c906108c
SS
9402
9403@item info registers @var{regname} @dots{}
9404Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24
DB
9405As discussed in detail below, register values are normally relative to
9406the selected stack frame. @var{regname} may be any register name valid on
c906108c
SS
9407the machine you are using, with or without the initial @samp{$}.
9408@end table
9409
e09f16f9
EZ
9410@cindex stack pointer register
9411@cindex program counter register
9412@cindex process status register
9413@cindex frame pointer register
9414@cindex standard registers
c906108c
SS
9415@value{GDBN} has four ``standard'' register names that are available (in
9416expressions) on most machines---whenever they do not conflict with an
9417architecture's canonical mnemonics for registers. The register names
9418@code{$pc} and @code{$sp} are used for the program counter register and
9419the stack pointer. @code{$fp} is used for a register that contains a
9420pointer to the current stack frame, and @code{$ps} is used for a
9421register that contains the processor status. For example,
9422you could print the program counter in hex with
9423
474c8240 9424@smallexample
c906108c 9425p/x $pc
474c8240 9426@end smallexample
c906108c
SS
9427
9428@noindent
9429or print the instruction to be executed next with
9430
474c8240 9431@smallexample
c906108c 9432x/i $pc
474c8240 9433@end smallexample
c906108c
SS
9434
9435@noindent
9436or add four to the stack pointer@footnote{This is a way of removing
9437one word from the stack, on machines where stacks grow downward in
9438memory (most machines, nowadays). This assumes that the innermost
9439stack frame is selected; setting @code{$sp} is not allowed when other
9440stack frames are selected. To pop entire frames off the stack,
9441regardless of machine architecture, use @code{return};
79a6e687 9442see @ref{Returning, ,Returning from a Function}.} with
c906108c 9443
474c8240 9444@smallexample
c906108c 9445set $sp += 4
474c8240 9446@end smallexample
c906108c
SS
9447
9448Whenever possible, these four standard register names are available on
9449your machine even though the machine has different canonical mnemonics,
9450so long as there is no conflict. The @code{info registers} command
9451shows the canonical names. For example, on the SPARC, @code{info
9452registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
9453can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
9454is an alias for the @sc{eflags} register.
c906108c
SS
9455
9456@value{GDBN} always considers the contents of an ordinary register as an
9457integer when the register is examined in this way. Some machines have
9458special registers which can hold nothing but floating point; these
9459registers are considered to have floating point values. There is no way
9460to refer to the contents of an ordinary register as floating point value
9461(although you can @emph{print} it as a floating point value with
9462@samp{print/f $@var{regname}}).
9463
9464Some registers have distinct ``raw'' and ``virtual'' data formats. This
9465means that the data format in which the register contents are saved by
9466the operating system is not the same one that your program normally
9467sees. For example, the registers of the 68881 floating point
9468coprocessor are always saved in ``extended'' (raw) format, but all C
9469programs expect to work with ``double'' (virtual) format. In such
5d161b24 9470cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
9471that makes sense for your program), but the @code{info registers} command
9472prints the data in both formats.
9473
36b80e65
EZ
9474@cindex SSE registers (x86)
9475@cindex MMX registers (x86)
9476Some machines have special registers whose contents can be interpreted
9477in several different ways. For example, modern x86-based machines
9478have SSE and MMX registers that can hold several values packed
9479together in several different formats. @value{GDBN} refers to such
9480registers in @code{struct} notation:
9481
9482@smallexample
9483(@value{GDBP}) print $xmm1
9484$1 = @{
9485 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
9486 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
9487 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
9488 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
9489 v4_int32 = @{0, 20657912, 11, 13@},
9490 v2_int64 = @{88725056443645952, 55834574859@},
9491 uint128 = 0x0000000d0000000b013b36f800000000
9492@}
9493@end smallexample
9494
9495@noindent
9496To set values of such registers, you need to tell @value{GDBN} which
9497view of the register you wish to change, as if you were assigning
9498value to a @code{struct} member:
9499
9500@smallexample
9501 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
9502@end smallexample
9503
c906108c 9504Normally, register values are relative to the selected stack frame
79a6e687 9505(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
9506value that the register would contain if all stack frames farther in
9507were exited and their saved registers restored. In order to see the
9508true contents of hardware registers, you must select the innermost
9509frame (with @samp{frame 0}).
9510
9511However, @value{GDBN} must deduce where registers are saved, from the machine
9512code generated by your compiler. If some registers are not saved, or if
9513@value{GDBN} is unable to locate the saved registers, the selected stack
9514frame makes no difference.
9515
6d2ebf8b 9516@node Floating Point Hardware
79a6e687 9517@section Floating Point Hardware
c906108c
SS
9518@cindex floating point
9519
9520Depending on the configuration, @value{GDBN} may be able to give
9521you more information about the status of the floating point hardware.
9522
9523@table @code
9524@kindex info float
9525@item info float
9526Display hardware-dependent information about the floating
9527point unit. The exact contents and layout vary depending on the
9528floating point chip. Currently, @samp{info float} is supported on
9529the ARM and x86 machines.
9530@end table
c906108c 9531
e76f1f2e
AC
9532@node Vector Unit
9533@section Vector Unit
9534@cindex vector unit
9535
9536Depending on the configuration, @value{GDBN} may be able to give you
9537more information about the status of the vector unit.
9538
9539@table @code
9540@kindex info vector
9541@item info vector
9542Display information about the vector unit. The exact contents and
9543layout vary depending on the hardware.
9544@end table
9545
721c2651 9546@node OS Information
79a6e687 9547@section Operating System Auxiliary Information
721c2651
EZ
9548@cindex OS information
9549
9550@value{GDBN} provides interfaces to useful OS facilities that can help
9551you debug your program.
9552
b383017d
RM
9553@cindex auxiliary vector
9554@cindex vector, auxiliary
b383017d
RM
9555Some operating systems supply an @dfn{auxiliary vector} to programs at
9556startup. This is akin to the arguments and environment that you
9557specify for a program, but contains a system-dependent variety of
9558binary values that tell system libraries important details about the
9559hardware, operating system, and process. Each value's purpose is
9560identified by an integer tag; the meanings are well-known but system-specific.
9561Depending on the configuration and operating system facilities,
9c16f35a
EZ
9562@value{GDBN} may be able to show you this information. For remote
9563targets, this functionality may further depend on the remote stub's
427c3a89
DJ
9564support of the @samp{qXfer:auxv:read} packet, see
9565@ref{qXfer auxiliary vector read}.
b383017d
RM
9566
9567@table @code
9568@kindex info auxv
9569@item info auxv
9570Display the auxiliary vector of the inferior, which can be either a
e4937fc1 9571live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
9572numerically, and also shows names and text descriptions for recognized
9573tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 9574pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
9575most appropriate form for a recognized tag, and in hexadecimal for
9576an unrecognized tag.
9577@end table
9578
85d4a676
SS
9579On some targets, @value{GDBN} can access operating system-specific
9580information and show it to you. The types of information available
9581will differ depending on the type of operating system running on the
9582target. The mechanism used to fetch the data is described in
9583@ref{Operating System Information}. For remote targets, this
9584functionality depends on the remote stub's support of the
07e059b5
VP
9585@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
9586
9587@table @code
a61408f8 9588@kindex info os
85d4a676
SS
9589@item info os @var{infotype}
9590
9591Display OS information of the requested type.
a61408f8 9592
85d4a676
SS
9593On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
9594
9595@anchor{linux info os infotypes}
9596@table @code
07e059b5 9597@kindex info os processes
85d4a676 9598@item processes
07e059b5 9599Display the list of processes on the target. For each process,
85d4a676
SS
9600@value{GDBN} prints the process identifier, the name of the user, the
9601command corresponding to the process, and the list of processor cores
9602that the process is currently running on. (To understand what these
9603properties mean, for this and the following info types, please consult
9604the general @sc{gnu}/Linux documentation.)
9605
9606@kindex info os procgroups
9607@item procgroups
9608Display the list of process groups on the target. For each process,
9609@value{GDBN} prints the identifier of the process group that it belongs
9610to, the command corresponding to the process group leader, the process
9611identifier, and the command line of the process. The list is sorted
9612first by the process group identifier, then by the process identifier,
9613so that processes belonging to the same process group are grouped together
9614and the process group leader is listed first.
9615
9616@kindex info os threads
9617@item threads
9618Display the list of threads running on the target. For each thread,
9619@value{GDBN} prints the identifier of the process that the thread
9620belongs to, the command of the process, the thread identifier, and the
9621processor core that it is currently running on. The main thread of a
9622process is not listed.
9623
9624@kindex info os files
9625@item files
9626Display the list of open file descriptors on the target. For each
9627file descriptor, @value{GDBN} prints the identifier of the process
9628owning the descriptor, the command of the owning process, the value
9629of the descriptor, and the target of the descriptor.
9630
9631@kindex info os sockets
9632@item sockets
9633Display the list of Internet-domain sockets on the target. For each
9634socket, @value{GDBN} prints the address and port of the local and
9635remote endpoints, the current state of the connection, the creator of
9636the socket, the IP address family of the socket, and the type of the
9637connection.
9638
9639@kindex info os shm
9640@item shm
9641Display the list of all System V shared-memory regions on the target.
9642For each shared-memory region, @value{GDBN} prints the region key,
9643the shared-memory identifier, the access permissions, the size of the
9644region, the process that created the region, the process that last
9645attached to or detached from the region, the current number of live
9646attaches to the region, and the times at which the region was last
9647attached to, detach from, and changed.
9648
9649@kindex info os semaphores
9650@item semaphores
9651Display the list of all System V semaphore sets on the target. For each
9652semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
9653set identifier, the access permissions, the number of semaphores in the
9654set, the user and group of the owner and creator of the semaphore set,
9655and the times at which the semaphore set was operated upon and changed.
9656
9657@kindex info os msg
9658@item msg
9659Display the list of all System V message queues on the target. For each
9660message queue, @value{GDBN} prints the message queue key, the message
9661queue identifier, the access permissions, the current number of bytes
9662on the queue, the current number of messages on the queue, the processes
9663that last sent and received a message on the queue, the user and group
9664of the owner and creator of the message queue, the times at which a
9665message was last sent and received on the queue, and the time at which
9666the message queue was last changed.
9667
9668@kindex info os modules
9669@item modules
9670Display the list of all loaded kernel modules on the target. For each
9671module, @value{GDBN} prints the module name, the size of the module in
9672bytes, the number of times the module is used, the dependencies of the
9673module, the status of the module, and the address of the loaded module
9674in memory.
9675@end table
9676
9677@item info os
9678If @var{infotype} is omitted, then list the possible values for
9679@var{infotype} and the kind of OS information available for each
9680@var{infotype}. If the target does not return a list of possible
9681types, this command will report an error.
07e059b5 9682@end table
721c2651 9683
29e57380 9684@node Memory Region Attributes
79a6e687 9685@section Memory Region Attributes
29e57380
C
9686@cindex memory region attributes
9687
b383017d 9688@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
9689required by regions of your target's memory. @value{GDBN} uses
9690attributes to determine whether to allow certain types of memory
9691accesses; whether to use specific width accesses; and whether to cache
9692target memory. By default the description of memory regions is
9693fetched from the target (if the current target supports this), but the
9694user can override the fetched regions.
29e57380
C
9695
9696Defined memory regions can be individually enabled and disabled. When a
9697memory region is disabled, @value{GDBN} uses the default attributes when
9698accessing memory in that region. Similarly, if no memory regions have
9699been defined, @value{GDBN} uses the default attributes when accessing
9700all memory.
9701
b383017d 9702When a memory region is defined, it is given a number to identify it;
29e57380
C
9703to enable, disable, or remove a memory region, you specify that number.
9704
9705@table @code
9706@kindex mem
bfac230e 9707@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
9708Define a memory region bounded by @var{lower} and @var{upper} with
9709attributes @var{attributes}@dots{}, and add it to the list of regions
9710monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 9711case: it is treated as the target's maximum memory address.
bfac230e 9712(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 9713
fd79ecee
DJ
9714@item mem auto
9715Discard any user changes to the memory regions and use target-supplied
9716regions, if available, or no regions if the target does not support.
9717
29e57380
C
9718@kindex delete mem
9719@item delete mem @var{nums}@dots{}
09d4efe1
EZ
9720Remove memory regions @var{nums}@dots{} from the list of regions
9721monitored by @value{GDBN}.
29e57380
C
9722
9723@kindex disable mem
9724@item disable mem @var{nums}@dots{}
09d4efe1 9725Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 9726A disabled memory region is not forgotten.
29e57380
C
9727It may be enabled again later.
9728
9729@kindex enable mem
9730@item enable mem @var{nums}@dots{}
09d4efe1 9731Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
9732
9733@kindex info mem
9734@item info mem
9735Print a table of all defined memory regions, with the following columns
09d4efe1 9736for each region:
29e57380
C
9737
9738@table @emph
9739@item Memory Region Number
9740@item Enabled or Disabled.
b383017d 9741Enabled memory regions are marked with @samp{y}.
29e57380
C
9742Disabled memory regions are marked with @samp{n}.
9743
9744@item Lo Address
9745The address defining the inclusive lower bound of the memory region.
9746
9747@item Hi Address
9748The address defining the exclusive upper bound of the memory region.
9749
9750@item Attributes
9751The list of attributes set for this memory region.
9752@end table
9753@end table
9754
9755
9756@subsection Attributes
9757
b383017d 9758@subsubsection Memory Access Mode
29e57380
C
9759The access mode attributes set whether @value{GDBN} may make read or
9760write accesses to a memory region.
9761
9762While these attributes prevent @value{GDBN} from performing invalid
9763memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 9764etc.@: from accessing memory.
29e57380
C
9765
9766@table @code
9767@item ro
9768Memory is read only.
9769@item wo
9770Memory is write only.
9771@item rw
6ca652b0 9772Memory is read/write. This is the default.
29e57380
C
9773@end table
9774
9775@subsubsection Memory Access Size
d3e8051b 9776The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
9777accesses in the memory region. Often memory mapped device registers
9778require specific sized accesses. If no access size attribute is
9779specified, @value{GDBN} may use accesses of any size.
9780
9781@table @code
9782@item 8
9783Use 8 bit memory accesses.
9784@item 16
9785Use 16 bit memory accesses.
9786@item 32
9787Use 32 bit memory accesses.
9788@item 64
9789Use 64 bit memory accesses.
9790@end table
9791
9792@c @subsubsection Hardware/Software Breakpoints
9793@c The hardware/software breakpoint attributes set whether @value{GDBN}
9794@c will use hardware or software breakpoints for the internal breakpoints
9795@c used by the step, next, finish, until, etc. commands.
9796@c
9797@c @table @code
9798@c @item hwbreak
b383017d 9799@c Always use hardware breakpoints
29e57380
C
9800@c @item swbreak (default)
9801@c @end table
9802
9803@subsubsection Data Cache
9804The data cache attributes set whether @value{GDBN} will cache target
9805memory. While this generally improves performance by reducing debug
9806protocol overhead, it can lead to incorrect results because @value{GDBN}
9807does not know about volatile variables or memory mapped device
9808registers.
9809
9810@table @code
9811@item cache
b383017d 9812Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
9813@item nocache
9814Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
9815@end table
9816
4b5752d0
VP
9817@subsection Memory Access Checking
9818@value{GDBN} can be instructed to refuse accesses to memory that is
9819not explicitly described. This can be useful if accessing such
9820regions has undesired effects for a specific target, or to provide
9821better error checking. The following commands control this behaviour.
9822
9823@table @code
9824@kindex set mem inaccessible-by-default
9825@item set mem inaccessible-by-default [on|off]
9826If @code{on} is specified, make @value{GDBN} treat memory not
9827explicitly described by the memory ranges as non-existent and refuse accesses
9828to such memory. The checks are only performed if there's at least one
9829memory range defined. If @code{off} is specified, make @value{GDBN}
9830treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 9831The default value is @code{on}.
4b5752d0
VP
9832@kindex show mem inaccessible-by-default
9833@item show mem inaccessible-by-default
9834Show the current handling of accesses to unknown memory.
9835@end table
9836
9837
29e57380 9838@c @subsubsection Memory Write Verification
b383017d 9839@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
9840@c will re-reads data after each write to verify the write was successful.
9841@c
9842@c @table @code
9843@c @item verify
9844@c @item noverify (default)
9845@c @end table
9846
16d9dec6 9847@node Dump/Restore Files
79a6e687 9848@section Copy Between Memory and a File
16d9dec6
MS
9849@cindex dump/restore files
9850@cindex append data to a file
9851@cindex dump data to a file
9852@cindex restore data from a file
16d9dec6 9853
df5215a6
JB
9854You can use the commands @code{dump}, @code{append}, and
9855@code{restore} to copy data between target memory and a file. The
9856@code{dump} and @code{append} commands write data to a file, and the
9857@code{restore} command reads data from a file back into the inferior's
9858memory. Files may be in binary, Motorola S-record, Intel hex, or
9859Tektronix Hex format; however, @value{GDBN} can only append to binary
9860files.
9861
9862@table @code
9863
9864@kindex dump
9865@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
9866@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
9867Dump the contents of memory from @var{start_addr} to @var{end_addr},
9868or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 9869
df5215a6 9870The @var{format} parameter may be any one of:
16d9dec6 9871@table @code
df5215a6
JB
9872@item binary
9873Raw binary form.
9874@item ihex
9875Intel hex format.
9876@item srec
9877Motorola S-record format.
9878@item tekhex
9879Tektronix Hex format.
9880@end table
9881
9882@value{GDBN} uses the same definitions of these formats as the
9883@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
9884@var{format} is omitted, @value{GDBN} dumps the data in raw binary
9885form.
9886
9887@kindex append
9888@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
9889@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
9890Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 9891or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
9892(@value{GDBN} can only append data to files in raw binary form.)
9893
9894@kindex restore
9895@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
9896Restore the contents of file @var{filename} into memory. The
9897@code{restore} command can automatically recognize any known @sc{bfd}
9898file format, except for raw binary. To restore a raw binary file you
9899must specify the optional keyword @code{binary} after the filename.
16d9dec6 9900
b383017d 9901If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
9902contained in the file. Binary files always start at address zero, so
9903they will be restored at address @var{bias}. Other bfd files have
9904a built-in location; they will be restored at offset @var{bias}
9905from that location.
9906
9907If @var{start} and/or @var{end} are non-zero, then only data between
9908file offset @var{start} and file offset @var{end} will be restored.
b383017d 9909These offsets are relative to the addresses in the file, before
16d9dec6
MS
9910the @var{bias} argument is applied.
9911
9912@end table
9913
384ee23f
EZ
9914@node Core File Generation
9915@section How to Produce a Core File from Your Program
9916@cindex dump core from inferior
9917
9918A @dfn{core file} or @dfn{core dump} is a file that records the memory
9919image of a running process and its process status (register values
9920etc.). Its primary use is post-mortem debugging of a program that
9921crashed while it ran outside a debugger. A program that crashes
9922automatically produces a core file, unless this feature is disabled by
9923the user. @xref{Files}, for information on invoking @value{GDBN} in
9924the post-mortem debugging mode.
9925
9926Occasionally, you may wish to produce a core file of the program you
9927are debugging in order to preserve a snapshot of its state.
9928@value{GDBN} has a special command for that.
9929
9930@table @code
9931@kindex gcore
9932@kindex generate-core-file
9933@item generate-core-file [@var{file}]
9934@itemx gcore [@var{file}]
9935Produce a core dump of the inferior process. The optional argument
9936@var{file} specifies the file name where to put the core dump. If not
9937specified, the file name defaults to @file{core.@var{pid}}, where
9938@var{pid} is the inferior process ID.
9939
9940Note that this command is implemented only for some systems (as of
05b4bd79 9941this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
384ee23f
EZ
9942@end table
9943
a0eb71c5
KB
9944@node Character Sets
9945@section Character Sets
9946@cindex character sets
9947@cindex charset
9948@cindex translating between character sets
9949@cindex host character set
9950@cindex target character set
9951
9952If the program you are debugging uses a different character set to
9953represent characters and strings than the one @value{GDBN} uses itself,
9954@value{GDBN} can automatically translate between the character sets for
9955you. The character set @value{GDBN} uses we call the @dfn{host
9956character set}; the one the inferior program uses we call the
9957@dfn{target character set}.
9958
9959For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
9960uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 9961remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
9962running on an IBM mainframe, which uses the @sc{ebcdic} character set,
9963then the host character set is Latin-1, and the target character set is
9964@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 9965target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
9966@sc{ebcdic} and Latin 1 as you print character or string values, or use
9967character and string literals in expressions.
9968
9969@value{GDBN} has no way to automatically recognize which character set
9970the inferior program uses; you must tell it, using the @code{set
9971target-charset} command, described below.
9972
9973Here are the commands for controlling @value{GDBN}'s character set
9974support:
9975
9976@table @code
9977@item set target-charset @var{charset}
9978@kindex set target-charset
10af6951
EZ
9979Set the current target character set to @var{charset}. To display the
9980list of supported target character sets, type
9981@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 9982
a0eb71c5
KB
9983@item set host-charset @var{charset}
9984@kindex set host-charset
9985Set the current host character set to @var{charset}.
9986
9987By default, @value{GDBN} uses a host character set appropriate to the
9988system it is running on; you can override that default using the
732f6a93
TT
9989@code{set host-charset} command. On some systems, @value{GDBN} cannot
9990automatically determine the appropriate host character set. In this
9991case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
9992
9993@value{GDBN} can only use certain character sets as its host character
c1b6b909 9994set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 9995@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
9996
9997@item set charset @var{charset}
9998@kindex set charset
e33d66ec 9999Set the current host and target character sets to @var{charset}. As
10af6951
EZ
10000above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
10001@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
10002for both host and target.
10003
a0eb71c5 10004@item show charset
a0eb71c5 10005@kindex show charset
10af6951 10006Show the names of the current host and target character sets.
e33d66ec 10007
10af6951 10008@item show host-charset
a0eb71c5 10009@kindex show host-charset
10af6951 10010Show the name of the current host character set.
e33d66ec 10011
10af6951 10012@item show target-charset
a0eb71c5 10013@kindex show target-charset
10af6951 10014Show the name of the current target character set.
a0eb71c5 10015
10af6951
EZ
10016@item set target-wide-charset @var{charset}
10017@kindex set target-wide-charset
10018Set the current target's wide character set to @var{charset}. This is
10019the character set used by the target's @code{wchar_t} type. To
10020display the list of supported wide character sets, type
10021@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
10022
10023@item show target-wide-charset
10024@kindex show target-wide-charset
10025Show the name of the current target's wide character set.
a0eb71c5
KB
10026@end table
10027
a0eb71c5
KB
10028Here is an example of @value{GDBN}'s character set support in action.
10029Assume that the following source code has been placed in the file
10030@file{charset-test.c}:
10031
10032@smallexample
10033#include <stdio.h>
10034
10035char ascii_hello[]
10036 = @{72, 101, 108, 108, 111, 44, 32, 119,
10037 111, 114, 108, 100, 33, 10, 0@};
10038char ibm1047_hello[]
10039 = @{200, 133, 147, 147, 150, 107, 64, 166,
10040 150, 153, 147, 132, 90, 37, 0@};
10041
10042main ()
10043@{
10044 printf ("Hello, world!\n");
10045@}
10998722 10046@end smallexample
a0eb71c5
KB
10047
10048In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
10049containing the string @samp{Hello, world!} followed by a newline,
10050encoded in the @sc{ascii} and @sc{ibm1047} character sets.
10051
10052We compile the program, and invoke the debugger on it:
10053
10054@smallexample
10055$ gcc -g charset-test.c -o charset-test
10056$ gdb -nw charset-test
10057GNU gdb 2001-12-19-cvs
10058Copyright 2001 Free Software Foundation, Inc.
10059@dots{}
f7dc1244 10060(@value{GDBP})
10998722 10061@end smallexample
a0eb71c5
KB
10062
10063We can use the @code{show charset} command to see what character sets
10064@value{GDBN} is currently using to interpret and display characters and
10065strings:
10066
10067@smallexample
f7dc1244 10068(@value{GDBP}) show charset
e33d66ec 10069The current host and target character set is `ISO-8859-1'.
f7dc1244 10070(@value{GDBP})
10998722 10071@end smallexample
a0eb71c5
KB
10072
10073For the sake of printing this manual, let's use @sc{ascii} as our
10074initial character set:
10075@smallexample
f7dc1244
EZ
10076(@value{GDBP}) set charset ASCII
10077(@value{GDBP}) show charset
e33d66ec 10078The current host and target character set is `ASCII'.
f7dc1244 10079(@value{GDBP})
10998722 10080@end smallexample
a0eb71c5
KB
10081
10082Let's assume that @sc{ascii} is indeed the correct character set for our
10083host system --- in other words, let's assume that if @value{GDBN} prints
10084characters using the @sc{ascii} character set, our terminal will display
10085them properly. Since our current target character set is also
10086@sc{ascii}, the contents of @code{ascii_hello} print legibly:
10087
10088@smallexample
f7dc1244 10089(@value{GDBP}) print ascii_hello
a0eb71c5 10090$1 = 0x401698 "Hello, world!\n"
f7dc1244 10091(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10092$2 = 72 'H'
f7dc1244 10093(@value{GDBP})
10998722 10094@end smallexample
a0eb71c5
KB
10095
10096@value{GDBN} uses the target character set for character and string
10097literals you use in expressions:
10098
10099@smallexample
f7dc1244 10100(@value{GDBP}) print '+'
a0eb71c5 10101$3 = 43 '+'
f7dc1244 10102(@value{GDBP})
10998722 10103@end smallexample
a0eb71c5
KB
10104
10105The @sc{ascii} character set uses the number 43 to encode the @samp{+}
10106character.
10107
10108@value{GDBN} relies on the user to tell it which character set the
10109target program uses. If we print @code{ibm1047_hello} while our target
10110character set is still @sc{ascii}, we get jibberish:
10111
10112@smallexample
f7dc1244 10113(@value{GDBP}) print ibm1047_hello
a0eb71c5 10114$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 10115(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10116$5 = 200 '\310'
f7dc1244 10117(@value{GDBP})
10998722 10118@end smallexample
a0eb71c5 10119
e33d66ec 10120If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
10121@value{GDBN} tells us the character sets it supports:
10122
10123@smallexample
f7dc1244 10124(@value{GDBP}) set target-charset
b383017d 10125ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 10126(@value{GDBP}) set target-charset
10998722 10127@end smallexample
a0eb71c5
KB
10128
10129We can select @sc{ibm1047} as our target character set, and examine the
10130program's strings again. Now the @sc{ascii} string is wrong, but
10131@value{GDBN} translates the contents of @code{ibm1047_hello} from the
10132target character set, @sc{ibm1047}, to the host character set,
10133@sc{ascii}, and they display correctly:
10134
10135@smallexample
f7dc1244
EZ
10136(@value{GDBP}) set target-charset IBM1047
10137(@value{GDBP}) show charset
e33d66ec
EZ
10138The current host character set is `ASCII'.
10139The current target character set is `IBM1047'.
f7dc1244 10140(@value{GDBP}) print ascii_hello
a0eb71c5 10141$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 10142(@value{GDBP}) print ascii_hello[0]
a0eb71c5 10143$7 = 72 '\110'
f7dc1244 10144(@value{GDBP}) print ibm1047_hello
a0eb71c5 10145$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 10146(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 10147$9 = 200 'H'
f7dc1244 10148(@value{GDBP})
10998722 10149@end smallexample
a0eb71c5
KB
10150
10151As above, @value{GDBN} uses the target character set for character and
10152string literals you use in expressions:
10153
10154@smallexample
f7dc1244 10155(@value{GDBP}) print '+'
a0eb71c5 10156$10 = 78 '+'
f7dc1244 10157(@value{GDBP})
10998722 10158@end smallexample
a0eb71c5 10159
e33d66ec 10160The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
10161character.
10162
09d4efe1
EZ
10163@node Caching Remote Data
10164@section Caching Data of Remote Targets
10165@cindex caching data of remote targets
10166
4e5d721f 10167@value{GDBN} caches data exchanged between the debugger and a
ea35711c 10168remote target (@pxref{Remote Debugging}). Such caching generally improves
09d4efe1 10169performance, because it reduces the overhead of the remote protocol by
4e5d721f
DE
10170bundling memory reads and writes into large chunks. Unfortunately, simply
10171caching everything would lead to incorrect results, since @value{GDBN}
10172does not necessarily know anything about volatile values, memory-mapped I/O
29b090c0
DE
10173addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
10174memory can be changed @emph{while} a gdb command is executing.
10175Therefore, by default, @value{GDBN} only caches data
10176known to be on the stack@footnote{In non-stop mode, it is moderately
10177rare for a running thread to modify the stack of a stopped thread
10178in a way that would interfere with a backtrace, and caching of
10179stack reads provides a significant speed up of remote backtraces.}.
10180Other regions of memory can be explicitly marked as
4e5d721f 10181cacheable; see @pxref{Memory Region Attributes}.
09d4efe1
EZ
10182
10183@table @code
10184@kindex set remotecache
10185@item set remotecache on
10186@itemx set remotecache off
4e5d721f
DE
10187This option no longer does anything; it exists for compatibility
10188with old scripts.
09d4efe1
EZ
10189
10190@kindex show remotecache
10191@item show remotecache
4e5d721f
DE
10192Show the current state of the obsolete remotecache flag.
10193
10194@kindex set stack-cache
10195@item set stack-cache on
10196@itemx set stack-cache off
10197Enable or disable caching of stack accesses. When @code{ON}, use
10198caching. By default, this option is @code{ON}.
10199
10200@kindex show stack-cache
10201@item show stack-cache
10202Show the current state of data caching for memory accesses.
09d4efe1
EZ
10203
10204@kindex info dcache
4e5d721f 10205@item info dcache @r{[}line@r{]}
09d4efe1 10206Print the information about the data cache performance. The
4e5d721f
DE
10207information displayed includes the dcache width and depth, and for
10208each cache line, its number, address, and how many times it was
10209referenced. This command is useful for debugging the data cache
10210operation.
10211
10212If a line number is specified, the contents of that line will be
10213printed in hex.
1a532630
PP
10214
10215@item set dcache size @var{size}
10216@cindex dcache size
10217@kindex set dcache size
10218Set maximum number of entries in dcache (dcache depth above).
10219
10220@item set dcache line-size @var{line-size}
10221@cindex dcache line-size
10222@kindex set dcache line-size
10223Set number of bytes each dcache entry caches (dcache width above).
10224Must be a power of 2.
10225
10226@item show dcache size
10227@kindex show dcache size
10228Show maximum number of dcache entries. See also @ref{Caching Remote Data, info dcache}.
10229
10230@item show dcache line-size
10231@kindex show dcache line-size
10232Show default size of dcache lines. See also @ref{Caching Remote Data, info dcache}.
10233
09d4efe1
EZ
10234@end table
10235
08388c79
DE
10236@node Searching Memory
10237@section Search Memory
10238@cindex searching memory
10239
10240Memory can be searched for a particular sequence of bytes with the
10241@code{find} command.
10242
10243@table @code
10244@kindex find
10245@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10246@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10247Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
10248etc. The search begins at address @var{start_addr} and continues for either
10249@var{len} bytes or through to @var{end_addr} inclusive.
10250@end table
10251
10252@var{s} and @var{n} are optional parameters.
10253They may be specified in either order, apart or together.
10254
10255@table @r
10256@item @var{s}, search query size
10257The size of each search query value.
10258
10259@table @code
10260@item b
10261bytes
10262@item h
10263halfwords (two bytes)
10264@item w
10265words (four bytes)
10266@item g
10267giant words (eight bytes)
10268@end table
10269
10270All values are interpreted in the current language.
10271This means, for example, that if the current source language is C/C@t{++}
10272then searching for the string ``hello'' includes the trailing '\0'.
10273
10274If the value size is not specified, it is taken from the
10275value's type in the current language.
10276This is useful when one wants to specify the search
10277pattern as a mixture of types.
10278Note that this means, for example, that in the case of C-like languages
10279a search for an untyped 0x42 will search for @samp{(int) 0x42}
10280which is typically four bytes.
10281
10282@item @var{n}, maximum number of finds
10283The maximum number of matches to print. The default is to print all finds.
10284@end table
10285
10286You can use strings as search values. Quote them with double-quotes
10287 (@code{"}).
10288The string value is copied into the search pattern byte by byte,
10289regardless of the endianness of the target and the size specification.
10290
10291The address of each match found is printed as well as a count of the
10292number of matches found.
10293
10294The address of the last value found is stored in convenience variable
10295@samp{$_}.
10296A count of the number of matches is stored in @samp{$numfound}.
10297
10298For example, if stopped at the @code{printf} in this function:
10299
10300@smallexample
10301void
10302hello ()
10303@{
10304 static char hello[] = "hello-hello";
10305 static struct @{ char c; short s; int i; @}
10306 __attribute__ ((packed)) mixed
10307 = @{ 'c', 0x1234, 0x87654321 @};
10308 printf ("%s\n", hello);
10309@}
10310@end smallexample
10311
10312@noindent
10313you get during debugging:
10314
10315@smallexample
10316(gdb) find &hello[0], +sizeof(hello), "hello"
103170x804956d <hello.1620+6>
103181 pattern found
10319(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
103200x8049567 <hello.1620>
103210x804956d <hello.1620+6>
103222 patterns found
10323(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
103240x8049567 <hello.1620>
103251 pattern found
10326(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
103270x8049560 <mixed.1625>
103281 pattern found
10329(gdb) print $numfound
10330$1 = 1
10331(gdb) print $_
10332$2 = (void *) 0x8049560
10333@end smallexample
a0eb71c5 10334
edb3359d
DJ
10335@node Optimized Code
10336@chapter Debugging Optimized Code
10337@cindex optimized code, debugging
10338@cindex debugging optimized code
10339
10340Almost all compilers support optimization. With optimization
10341disabled, the compiler generates assembly code that corresponds
10342directly to your source code, in a simplistic way. As the compiler
10343applies more powerful optimizations, the generated assembly code
10344diverges from your original source code. With help from debugging
10345information generated by the compiler, @value{GDBN} can map from
10346the running program back to constructs from your original source.
10347
10348@value{GDBN} is more accurate with optimization disabled. If you
10349can recompile without optimization, it is easier to follow the
10350progress of your program during debugging. But, there are many cases
10351where you may need to debug an optimized version.
10352
10353When you debug a program compiled with @samp{-g -O}, remember that the
10354optimizer has rearranged your code; the debugger shows you what is
10355really there. Do not be too surprised when the execution path does not
10356exactly match your source file! An extreme example: if you define a
10357variable, but never use it, @value{GDBN} never sees that
10358variable---because the compiler optimizes it out of existence.
10359
10360Some things do not work as well with @samp{-g -O} as with just
10361@samp{-g}, particularly on machines with instruction scheduling. If in
10362doubt, recompile with @samp{-g} alone, and if this fixes the problem,
10363please report it to us as a bug (including a test case!).
10364@xref{Variables}, for more information about debugging optimized code.
10365
10366@menu
10367* Inline Functions:: How @value{GDBN} presents inlining
111c6489 10368* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
10369@end menu
10370
10371@node Inline Functions
10372@section Inline Functions
10373@cindex inline functions, debugging
10374
10375@dfn{Inlining} is an optimization that inserts a copy of the function
10376body directly at each call site, instead of jumping to a shared
10377routine. @value{GDBN} displays inlined functions just like
10378non-inlined functions. They appear in backtraces. You can view their
10379arguments and local variables, step into them with @code{step}, skip
10380them with @code{next}, and escape from them with @code{finish}.
10381You can check whether a function was inlined by using the
10382@code{info frame} command.
10383
10384For @value{GDBN} to support inlined functions, the compiler must
10385record information about inlining in the debug information ---
10386@value{NGCC} using the @sc{dwarf 2} format does this, and several
10387other compilers do also. @value{GDBN} only supports inlined functions
10388when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
10389do not emit two required attributes (@samp{DW_AT_call_file} and
10390@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
10391function calls with earlier versions of @value{NGCC}. It instead
10392displays the arguments and local variables of inlined functions as
10393local variables in the caller.
10394
10395The body of an inlined function is directly included at its call site;
10396unlike a non-inlined function, there are no instructions devoted to
10397the call. @value{GDBN} still pretends that the call site and the
10398start of the inlined function are different instructions. Stepping to
10399the call site shows the call site, and then stepping again shows
10400the first line of the inlined function, even though no additional
10401instructions are executed.
10402
10403This makes source-level debugging much clearer; you can see both the
10404context of the call and then the effect of the call. Only stepping by
10405a single instruction using @code{stepi} or @code{nexti} does not do
10406this; single instruction steps always show the inlined body.
10407
10408There are some ways that @value{GDBN} does not pretend that inlined
10409function calls are the same as normal calls:
10410
10411@itemize @bullet
edb3359d
DJ
10412@item
10413Setting breakpoints at the call site of an inlined function may not
10414work, because the call site does not contain any code. @value{GDBN}
10415may incorrectly move the breakpoint to the next line of the enclosing
10416function, after the call. This limitation will be removed in a future
10417version of @value{GDBN}; until then, set a breakpoint on an earlier line
10418or inside the inlined function instead.
10419
10420@item
10421@value{GDBN} cannot locate the return value of inlined calls after
10422using the @code{finish} command. This is a limitation of compiler-generated
10423debugging information; after @code{finish}, you can step to the next line
10424and print a variable where your program stored the return value.
10425
10426@end itemize
10427
111c6489
JK
10428@node Tail Call Frames
10429@section Tail Call Frames
10430@cindex tail call frames, debugging
10431
10432Function @code{B} can call function @code{C} in its very last statement. In
10433unoptimized compilation the call of @code{C} is immediately followed by return
10434instruction at the end of @code{B} code. Optimizing compiler may replace the
10435call and return in function @code{B} into one jump to function @code{C}
10436instead. Such use of a jump instruction is called @dfn{tail call}.
10437
10438During execution of function @code{C}, there will be no indication in the
10439function call stack frames that it was tail-called from @code{B}. If function
10440@code{A} regularly calls function @code{B} which tail-calls function @code{C},
10441then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
10442some cases @value{GDBN} can determine that @code{C} was tail-called from
10443@code{B}, and it will then create fictitious call frame for that, with the
10444return address set up as if @code{B} called @code{C} normally.
10445
10446This functionality is currently supported only by DWARF 2 debugging format and
10447the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
10448@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10449this information.
10450
10451@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
10452kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
10453
10454@smallexample
10455(gdb) x/i $pc - 2
10456 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
10457(gdb) info frame
10458Stack level 1, frame at 0x7fffffffda30:
10459 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
10460 tail call frame, caller of frame at 0x7fffffffda30
10461 source language c++.
10462 Arglist at unknown address.
10463 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
10464@end smallexample
10465
10466The detection of all the possible code path executions can find them ambiguous.
10467There is no execution history stored (possible @ref{Reverse Execution} is never
10468used for this purpose) and the last known caller could have reached the known
10469callee by multiple different jump sequences. In such case @value{GDBN} still
10470tries to show at least all the unambiguous top tail callers and all the
10471unambiguous bottom tail calees, if any.
10472
10473@table @code
e18b2753 10474@anchor{set debug entry-values}
111c6489
JK
10475@item set debug entry-values
10476@kindex set debug entry-values
10477When set to on, enables printing of analysis messages for both frame argument
10478values at function entry and tail calls. It will show all the possible valid
10479tail calls code paths it has considered. It will also print the intersection
10480of them with the final unambiguous (possibly partial or even empty) code path
10481result.
10482
10483@item show debug entry-values
10484@kindex show debug entry-values
10485Show the current state of analysis messages printing for both frame argument
10486values at function entry and tail calls.
10487@end table
10488
10489The analysis messages for tail calls can for example show why the virtual tail
10490call frame for function @code{c} has not been recognized (due to the indirect
10491reference by variable @code{x}):
10492
10493@smallexample
10494static void __attribute__((noinline, noclone)) c (void);
10495void (*x) (void) = c;
10496static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10497static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
10498int main (void) @{ x (); return 0; @}
10499
10500Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
10501DW_TAG_GNU_call_site 0x40039a in main
10502a () at t.c:3
105033 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10504(gdb) bt
10505#0 a () at t.c:3
10506#1 0x000000000040039a in main () at t.c:5
10507@end smallexample
10508
10509Another possibility is an ambiguous virtual tail call frames resolution:
10510
10511@smallexample
10512int i;
10513static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
10514static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
10515static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
10516static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
10517static void __attribute__((noinline, noclone)) b (void)
10518@{ if (i) c (); else e (); @}
10519static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
10520int main (void) @{ a (); return 0; @}
10521
10522tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
10523tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
10524tailcall: reduced: 0x4004d2(a) |
10525(gdb) bt
10526#0 f () at t.c:2
10527#1 0x00000000004004d2 in a () at t.c:8
10528#2 0x0000000000400395 in main () at t.c:9
10529@end smallexample
10530
5048e516
JK
10531@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
10532@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
10533
10534@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
10535@ifset HAVE_MAKEINFO_CLICK
10536@set ARROW @click{}
10537@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
10538@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
10539@end ifset
10540@ifclear HAVE_MAKEINFO_CLICK
10541@set ARROW ->
10542@set CALLSEQ1B @value{CALLSEQ1A}
10543@set CALLSEQ2B @value{CALLSEQ2A}
10544@end ifclear
10545
10546Frames #0 and #2 are real, #1 is a virtual tail call frame.
10547The code can have possible execution paths @value{CALLSEQ1B} or
10548@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
10549
10550@code{initial:} state shows some random possible calling sequence @value{GDBN}
10551has found. It then finds another possible calling sequcen - that one is
10552prefixed by @code{compare:}. The non-ambiguous intersection of these two is
10553printed as the @code{reduced:} calling sequence. That one could have many
10554futher @code{compare:} and @code{reduced:} statements as long as there remain
10555any non-ambiguous sequence entries.
10556
10557For the frame of function @code{b} in both cases there are different possible
10558@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
10559also ambigous. The only non-ambiguous frame is the one for function @code{a},
10560therefore this one is displayed to the user while the ambiguous frames are
10561omitted.
edb3359d 10562
e18b2753
JK
10563There can be also reasons why printing of frame argument values at function
10564entry may fail:
10565
10566@smallexample
10567int v;
10568static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
10569static void __attribute__((noinline, noclone)) a (int i);
10570static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
10571static void __attribute__((noinline, noclone)) a (int i)
10572@{ if (i) b (i - 1); else c (0); @}
10573int main (void) @{ a (5); return 0; @}
10574
10575(gdb) bt
10576#0 c (i=i@@entry=0) at t.c:2
10577#1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
10578function "a" at 0x400420 can call itself via tail calls
10579i=<optimized out>) at t.c:6
10580#2 0x000000000040036e in main () at t.c:7
10581@end smallexample
10582
10583@value{GDBN} cannot find out from the inferior state if and how many times did
10584function @code{a} call itself (via function @code{b}) as these calls would be
10585tail calls. Such tail calls would modify thue @code{i} variable, therefore
10586@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
10587prints @code{<optimized out>} instead.
10588
e2e0bcd1
JB
10589@node Macros
10590@chapter C Preprocessor Macros
10591
49efadf5 10592Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
10593``preprocessor macros'' which expand into strings of tokens.
10594@value{GDBN} can evaluate expressions containing macro invocations, show
10595the result of macro expansion, and show a macro's definition, including
10596where it was defined.
10597
10598You may need to compile your program specially to provide @value{GDBN}
10599with information about preprocessor macros. Most compilers do not
10600include macros in their debugging information, even when you compile
10601with the @option{-g} flag. @xref{Compilation}.
10602
10603A program may define a macro at one point, remove that definition later,
10604and then provide a different definition after that. Thus, at different
10605points in the program, a macro may have different definitions, or have
10606no definition at all. If there is a current stack frame, @value{GDBN}
10607uses the macros in scope at that frame's source code line. Otherwise,
10608@value{GDBN} uses the macros in scope at the current listing location;
10609see @ref{List}.
10610
e2e0bcd1
JB
10611Whenever @value{GDBN} evaluates an expression, it always expands any
10612macro invocations present in the expression. @value{GDBN} also provides
10613the following commands for working with macros explicitly.
10614
10615@table @code
10616
10617@kindex macro expand
10618@cindex macro expansion, showing the results of preprocessor
10619@cindex preprocessor macro expansion, showing the results of
10620@cindex expanding preprocessor macros
10621@item macro expand @var{expression}
10622@itemx macro exp @var{expression}
10623Show the results of expanding all preprocessor macro invocations in
10624@var{expression}. Since @value{GDBN} simply expands macros, but does
10625not parse the result, @var{expression} need not be a valid expression;
10626it can be any string of tokens.
10627
09d4efe1 10628@kindex macro exp1
e2e0bcd1
JB
10629@item macro expand-once @var{expression}
10630@itemx macro exp1 @var{expression}
4644b6e3 10631@cindex expand macro once
e2e0bcd1
JB
10632@i{(This command is not yet implemented.)} Show the results of
10633expanding those preprocessor macro invocations that appear explicitly in
10634@var{expression}. Macro invocations appearing in that expansion are
10635left unchanged. This command allows you to see the effect of a
10636particular macro more clearly, without being confused by further
10637expansions. Since @value{GDBN} simply expands macros, but does not
10638parse the result, @var{expression} need not be a valid expression; it
10639can be any string of tokens.
10640
475b0867 10641@kindex info macro
e2e0bcd1 10642@cindex macro definition, showing
9b158ba0 10643@cindex definition of a macro, showing
10644@cindex macros, from debug info
71eba9c2 10645@item info macro [-a|-all] [--] @var{macro}
10646Show the current definition or all definitions of the named @var{macro},
10647and describe the source location or compiler command-line where that
10648definition was established. The optional double dash is to signify the end of
10649argument processing and the beginning of @var{macro} for non C-like macros where
10650the macro may begin with a hyphen.
e2e0bcd1 10651
9b158ba0 10652@kindex info macros
10653@item info macros @var{linespec}
10654Show all macro definitions that are in effect at the location specified
10655by @var{linespec}, and describe the source location or compiler
10656command-line where those definitions were established.
10657
e2e0bcd1
JB
10658@kindex macro define
10659@cindex user-defined macros
10660@cindex defining macros interactively
10661@cindex macros, user-defined
10662@item macro define @var{macro} @var{replacement-list}
10663@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
10664Introduce a definition for a preprocessor macro named @var{macro},
10665invocations of which are replaced by the tokens given in
10666@var{replacement-list}. The first form of this command defines an
10667``object-like'' macro, which takes no arguments; the second form
10668defines a ``function-like'' macro, which takes the arguments given in
10669@var{arglist}.
10670
10671A definition introduced by this command is in scope in every
10672expression evaluated in @value{GDBN}, until it is removed with the
10673@code{macro undef} command, described below. The definition overrides
10674all definitions for @var{macro} present in the program being debugged,
10675as well as any previous user-supplied definition.
e2e0bcd1
JB
10676
10677@kindex macro undef
10678@item macro undef @var{macro}
d7d9f01e
TT
10679Remove any user-supplied definition for the macro named @var{macro}.
10680This command only affects definitions provided with the @code{macro
10681define} command, described above; it cannot remove definitions present
10682in the program being debugged.
e2e0bcd1 10683
09d4efe1
EZ
10684@kindex macro list
10685@item macro list
d7d9f01e 10686List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
10687@end table
10688
10689@cindex macros, example of debugging with
10690Here is a transcript showing the above commands in action. First, we
10691show our source files:
10692
10693@smallexample
10694$ cat sample.c
10695#include <stdio.h>
10696#include "sample.h"
10697
10698#define M 42
10699#define ADD(x) (M + x)
10700
10701main ()
10702@{
10703#define N 28
10704 printf ("Hello, world!\n");
10705#undef N
10706 printf ("We're so creative.\n");
10707#define N 1729
10708 printf ("Goodbye, world!\n");
10709@}
10710$ cat sample.h
10711#define Q <
10712$
10713@end smallexample
10714
e0f8f636
TT
10715Now, we compile the program using the @sc{gnu} C compiler,
10716@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
10717minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
10718and @option{-gdwarf-4}; we recommend always choosing the most recent
10719version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
10720includes information about preprocessor macros in the debugging
e2e0bcd1
JB
10721information.
10722
10723@smallexample
10724$ gcc -gdwarf-2 -g3 sample.c -o sample
10725$
10726@end smallexample
10727
10728Now, we start @value{GDBN} on our sample program:
10729
10730@smallexample
10731$ gdb -nw sample
10732GNU gdb 2002-05-06-cvs
10733Copyright 2002 Free Software Foundation, Inc.
10734GDB is free software, @dots{}
f7dc1244 10735(@value{GDBP})
e2e0bcd1
JB
10736@end smallexample
10737
10738We can expand macros and examine their definitions, even when the
10739program is not running. @value{GDBN} uses the current listing position
10740to decide which macro definitions are in scope:
10741
10742@smallexample
f7dc1244 10743(@value{GDBP}) list main
e2e0bcd1
JB
107443
107454 #define M 42
107465 #define ADD(x) (M + x)
107476
107487 main ()
107498 @{
107509 #define N 28
1075110 printf ("Hello, world!\n");
1075211 #undef N
1075312 printf ("We're so creative.\n");
f7dc1244 10754(@value{GDBP}) info macro ADD
e2e0bcd1
JB
10755Defined at /home/jimb/gdb/macros/play/sample.c:5
10756#define ADD(x) (M + x)
f7dc1244 10757(@value{GDBP}) info macro Q
e2e0bcd1
JB
10758Defined at /home/jimb/gdb/macros/play/sample.h:1
10759 included at /home/jimb/gdb/macros/play/sample.c:2
10760#define Q <
f7dc1244 10761(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 10762expands to: (42 + 1)
f7dc1244 10763(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 10764expands to: once (M + 1)
f7dc1244 10765(@value{GDBP})
e2e0bcd1
JB
10766@end smallexample
10767
d7d9f01e 10768In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
10769the macro invocation explicit in the original text --- the invocation of
10770@code{ADD} --- but does not expand the invocation of the macro @code{M},
10771which was introduced by @code{ADD}.
10772
3f94c067
BW
10773Once the program is running, @value{GDBN} uses the macro definitions in
10774force at the source line of the current stack frame:
e2e0bcd1
JB
10775
10776@smallexample
f7dc1244 10777(@value{GDBP}) break main
e2e0bcd1 10778Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 10779(@value{GDBP}) run
b383017d 10780Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
10781
10782Breakpoint 1, main () at sample.c:10
1078310 printf ("Hello, world!\n");
f7dc1244 10784(@value{GDBP})
e2e0bcd1
JB
10785@end smallexample
10786
10787At line 10, the definition of the macro @code{N} at line 9 is in force:
10788
10789@smallexample
f7dc1244 10790(@value{GDBP}) info macro N
e2e0bcd1
JB
10791Defined at /home/jimb/gdb/macros/play/sample.c:9
10792#define N 28
f7dc1244 10793(@value{GDBP}) macro expand N Q M
e2e0bcd1 10794expands to: 28 < 42
f7dc1244 10795(@value{GDBP}) print N Q M
e2e0bcd1 10796$1 = 1
f7dc1244 10797(@value{GDBP})
e2e0bcd1
JB
10798@end smallexample
10799
10800As we step over directives that remove @code{N}'s definition, and then
10801give it a new definition, @value{GDBN} finds the definition (or lack
10802thereof) in force at each point:
10803
10804@smallexample
f7dc1244 10805(@value{GDBP}) next
e2e0bcd1
JB
10806Hello, world!
1080712 printf ("We're so creative.\n");
f7dc1244 10808(@value{GDBP}) info macro N
e2e0bcd1
JB
10809The symbol `N' has no definition as a C/C++ preprocessor macro
10810at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 10811(@value{GDBP}) next
e2e0bcd1
JB
10812We're so creative.
1081314 printf ("Goodbye, world!\n");
f7dc1244 10814(@value{GDBP}) info macro N
e2e0bcd1
JB
10815Defined at /home/jimb/gdb/macros/play/sample.c:13
10816#define N 1729
f7dc1244 10817(@value{GDBP}) macro expand N Q M
e2e0bcd1 10818expands to: 1729 < 42
f7dc1244 10819(@value{GDBP}) print N Q M
e2e0bcd1 10820$2 = 0
f7dc1244 10821(@value{GDBP})
e2e0bcd1
JB
10822@end smallexample
10823
484086b7
JK
10824In addition to source files, macros can be defined on the compilation command
10825line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
10826such a way, @value{GDBN} displays the location of their definition as line zero
10827of the source file submitted to the compiler.
10828
10829@smallexample
10830(@value{GDBP}) info macro __STDC__
10831Defined at /home/jimb/gdb/macros/play/sample.c:0
10832-D__STDC__=1
10833(@value{GDBP})
10834@end smallexample
10835
e2e0bcd1 10836
b37052ae
EZ
10837@node Tracepoints
10838@chapter Tracepoints
10839@c This chapter is based on the documentation written by Michael
10840@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
10841
10842@cindex tracepoints
10843In some applications, it is not feasible for the debugger to interrupt
10844the program's execution long enough for the developer to learn
10845anything helpful about its behavior. If the program's correctness
10846depends on its real-time behavior, delays introduced by a debugger
10847might cause the program to change its behavior drastically, or perhaps
10848fail, even when the code itself is correct. It is useful to be able
10849to observe the program's behavior without interrupting it.
10850
10851Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
10852specify locations in the program, called @dfn{tracepoints}, and
10853arbitrary expressions to evaluate when those tracepoints are reached.
10854Later, using the @code{tfind} command, you can examine the values
10855those expressions had when the program hit the tracepoints. The
10856expressions may also denote objects in memory---structures or arrays,
10857for example---whose values @value{GDBN} should record; while visiting
10858a particular tracepoint, you may inspect those objects as if they were
10859in memory at that moment. However, because @value{GDBN} records these
10860values without interacting with you, it can do so quickly and
10861unobtrusively, hopefully not disturbing the program's behavior.
10862
10863The tracepoint facility is currently available only for remote
9d29849a
JB
10864targets. @xref{Targets}. In addition, your remote target must know
10865how to collect trace data. This functionality is implemented in the
10866remote stub; however, none of the stubs distributed with @value{GDBN}
10867support tracepoints as of this writing. The format of the remote
10868packets used to implement tracepoints are described in @ref{Tracepoint
10869Packets}.
b37052ae 10870
00bf0b85
SS
10871It is also possible to get trace data from a file, in a manner reminiscent
10872of corefiles; you specify the filename, and use @code{tfind} to search
10873through the file. @xref{Trace Files}, for more details.
10874
b37052ae
EZ
10875This chapter describes the tracepoint commands and features.
10876
10877@menu
b383017d
RM
10878* Set Tracepoints::
10879* Analyze Collected Data::
10880* Tracepoint Variables::
00bf0b85 10881* Trace Files::
b37052ae
EZ
10882@end menu
10883
10884@node Set Tracepoints
10885@section Commands to Set Tracepoints
10886
10887Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
10888tracepoints can be set. A tracepoint is actually a special type of
10889breakpoint (@pxref{Set Breaks}), so you can manipulate it using
10890standard breakpoint commands. For instance, as with breakpoints,
10891tracepoint numbers are successive integers starting from one, and many
10892of the commands associated with tracepoints take the tracepoint number
10893as their argument, to identify which tracepoint to work on.
b37052ae
EZ
10894
10895For each tracepoint, you can specify, in advance, some arbitrary set
10896of data that you want the target to collect in the trace buffer when
10897it hits that tracepoint. The collected data can include registers,
10898local variables, or global data. Later, you can use @value{GDBN}
10899commands to examine the values these data had at the time the
10900tracepoint was hit.
10901
7d13fe92
SS
10902Tracepoints do not support every breakpoint feature. Ignore counts on
10903tracepoints have no effect, and tracepoints cannot run @value{GDBN}
10904commands when they are hit. Tracepoints may not be thread-specific
10905either.
1042e4c0 10906
7a697b8d
SS
10907@cindex fast tracepoints
10908Some targets may support @dfn{fast tracepoints}, which are inserted in
10909a different way (such as with a jump instead of a trap), that is
10910faster but possibly restricted in where they may be installed.
10911
0fb4aa4b
PA
10912@cindex static tracepoints
10913@cindex markers, static tracepoints
10914@cindex probing markers, static tracepoints
10915Regular and fast tracepoints are dynamic tracing facilities, meaning
10916that they can be used to insert tracepoints at (almost) any location
10917in the target. Some targets may also support controlling @dfn{static
10918tracepoints} from @value{GDBN}. With static tracing, a set of
10919instrumentation points, also known as @dfn{markers}, are embedded in
10920the target program, and can be activated or deactivated by name or
10921address. These are usually placed at locations which facilitate
10922investigating what the target is actually doing. @value{GDBN}'s
10923support for static tracing includes being able to list instrumentation
10924points, and attach them with @value{GDBN} defined high level
10925tracepoints that expose the whole range of convenience of
8786b2bd 10926@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
10927registers values and values of global or local (to the instrumentation
10928point) variables; tracepoint conditions and trace state variables.
10929The act of installing a @value{GDBN} static tracepoint on an
10930instrumentation point, or marker, is referred to as @dfn{probing} a
10931static tracepoint marker.
10932
fa593d66
PA
10933@code{gdbserver} supports tracepoints on some target systems.
10934@xref{Server,,Tracepoints support in @code{gdbserver}}.
10935
b37052ae
EZ
10936This section describes commands to set tracepoints and associated
10937conditions and actions.
10938
10939@menu
b383017d
RM
10940* Create and Delete Tracepoints::
10941* Enable and Disable Tracepoints::
10942* Tracepoint Passcounts::
782b2b07 10943* Tracepoint Conditions::
f61e138d 10944* Trace State Variables::
b383017d
RM
10945* Tracepoint Actions::
10946* Listing Tracepoints::
0fb4aa4b 10947* Listing Static Tracepoint Markers::
79a6e687 10948* Starting and Stopping Trace Experiments::
c9429232 10949* Tracepoint Restrictions::
b37052ae
EZ
10950@end menu
10951
10952@node Create and Delete Tracepoints
10953@subsection Create and Delete Tracepoints
10954
10955@table @code
10956@cindex set tracepoint
10957@kindex trace
1042e4c0 10958@item trace @var{location}
b37052ae 10959The @code{trace} command is very similar to the @code{break} command.
1042e4c0
SS
10960Its argument @var{location} can be a source line, a function name, or
10961an address in the target program. @xref{Specify Location}. The
10962@code{trace} command defines a tracepoint, which is a point in the
10963target program where the debugger will briefly stop, collect some
10964data, and then allow the program to continue. Setting a tracepoint or
1e4d1764
YQ
10965changing its actions takes effect immediately if the remote stub
10966supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
10967in tracing}).
10968If remote stub doesn't support the @samp{InstallInTrace} feature, all
10969these changes don't take effect until the next @code{tstart}
1042e4c0 10970command, and once a trace experiment is running, further changes will
bfccc43c
YQ
10971not have any effect until the next trace experiment starts. In addition,
10972@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
10973address is not yet resolved. (This is similar to pending breakpoints.)
10974Pending tracepoints are not downloaded to the target and not installed
10975until they are resolved. The resolution of pending tracepoints requires
10976@value{GDBN} support---when debugging with the remote target, and
10977@value{GDBN} disconnects from the remote stub (@pxref{disconnected
10978tracing}), pending tracepoints can not be resolved (and downloaded to
10979the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
10980
10981Here are some examples of using the @code{trace} command:
10982
10983@smallexample
10984(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
10985
10986(@value{GDBP}) @b{trace +2} // 2 lines forward
10987
10988(@value{GDBP}) @b{trace my_function} // first source line of function
10989
10990(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
10991
10992(@value{GDBP}) @b{trace *0x2117c4} // an address
10993@end smallexample
10994
10995@noindent
10996You can abbreviate @code{trace} as @code{tr}.
10997
782b2b07
SS
10998@item trace @var{location} if @var{cond}
10999Set a tracepoint with condition @var{cond}; evaluate the expression
11000@var{cond} each time the tracepoint is reached, and collect data only
11001if the value is nonzero---that is, if @var{cond} evaluates as true.
11002@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
11003information on tracepoint conditions.
11004
7a697b8d
SS
11005@item ftrace @var{location} [ if @var{cond} ]
11006@cindex set fast tracepoint
74c761c1 11007@cindex fast tracepoints, setting
7a697b8d
SS
11008@kindex ftrace
11009The @code{ftrace} command sets a fast tracepoint. For targets that
11010support them, fast tracepoints will use a more efficient but possibly
11011less general technique to trigger data collection, such as a jump
11012instruction instead of a trap, or some sort of hardware support. It
11013may not be possible to create a fast tracepoint at the desired
11014location, in which case the command will exit with an explanatory
11015message.
11016
11017@value{GDBN} handles arguments to @code{ftrace} exactly as for
11018@code{trace}.
11019
405f8e94
SS
11020On 32-bit x86-architecture systems, fast tracepoints normally need to
11021be placed at an instruction that is 5 bytes or longer, but can be
11022placed at 4-byte instructions if the low 64K of memory of the target
11023program is available to install trampolines. Some Unix-type systems,
11024such as @sc{gnu}/Linux, exclude low addresses from the program's
11025address space; but for instance with the Linux kernel it is possible
11026to let @value{GDBN} use this area by doing a @command{sysctl} command
11027to set the @code{mmap_min_addr} kernel parameter, as in
11028
11029@example
11030sudo sysctl -w vm.mmap_min_addr=32768
11031@end example
11032
11033@noindent
11034which sets the low address to 32K, which leaves plenty of room for
11035trampolines. The minimum address should be set to a page boundary.
11036
0fb4aa4b 11037@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
11038@cindex set static tracepoint
11039@cindex static tracepoints, setting
11040@cindex probe static tracepoint marker
0fb4aa4b
PA
11041@kindex strace
11042The @code{strace} command sets a static tracepoint. For targets that
11043support it, setting a static tracepoint probes a static
11044instrumentation point, or marker, found at @var{location}. It may not
11045be possible to set a static tracepoint at the desired location, in
11046which case the command will exit with an explanatory message.
11047
11048@value{GDBN} handles arguments to @code{strace} exactly as for
11049@code{trace}, with the addition that the user can also specify
11050@code{-m @var{marker}} as @var{location}. This probes the marker
11051identified by the @var{marker} string identifier. This identifier
11052depends on the static tracepoint backend library your program is
11053using. You can find all the marker identifiers in the @samp{ID} field
11054of the @code{info static-tracepoint-markers} command output.
11055@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
11056Markers}. For example, in the following small program using the UST
11057tracing engine:
11058
11059@smallexample
11060main ()
11061@{
11062 trace_mark(ust, bar33, "str %s", "FOOBAZ");
11063@}
11064@end smallexample
11065
11066@noindent
11067the marker id is composed of joining the first two arguments to the
11068@code{trace_mark} call with a slash, which translates to:
11069
11070@smallexample
11071(@value{GDBP}) info static-tracepoint-markers
11072Cnt Enb ID Address What
110731 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
11074 Data: "str %s"
11075[etc...]
11076@end smallexample
11077
11078@noindent
11079so you may probe the marker above with:
11080
11081@smallexample
11082(@value{GDBP}) strace -m ust/bar33
11083@end smallexample
11084
11085Static tracepoints accept an extra collect action --- @code{collect
11086$_sdata}. This collects arbitrary user data passed in the probe point
11087call to the tracing library. In the UST example above, you'll see
11088that the third argument to @code{trace_mark} is a printf-like format
11089string. The user data is then the result of running that formating
11090string against the following arguments. Note that @code{info
11091static-tracepoint-markers} command output lists that format string in
11092the @samp{Data:} field.
11093
11094You can inspect this data when analyzing the trace buffer, by printing
11095the $_sdata variable like any other variable available to
11096@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
11097
b37052ae
EZ
11098@vindex $tpnum
11099@cindex last tracepoint number
11100@cindex recent tracepoint number
11101@cindex tracepoint number
11102The convenience variable @code{$tpnum} records the tracepoint number
11103of the most recently set tracepoint.
11104
11105@kindex delete tracepoint
11106@cindex tracepoint deletion
11107@item delete tracepoint @r{[}@var{num}@r{]}
11108Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
11109default is to delete all tracepoints. Note that the regular
11110@code{delete} command can remove tracepoints also.
b37052ae
EZ
11111
11112Examples:
11113
11114@smallexample
11115(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
11116
11117(@value{GDBP}) @b{delete trace} // remove all tracepoints
11118@end smallexample
11119
11120@noindent
11121You can abbreviate this command as @code{del tr}.
11122@end table
11123
11124@node Enable and Disable Tracepoints
11125@subsection Enable and Disable Tracepoints
11126
1042e4c0
SS
11127These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
11128
b37052ae
EZ
11129@table @code
11130@kindex disable tracepoint
11131@item disable tracepoint @r{[}@var{num}@r{]}
11132Disable tracepoint @var{num}, or all tracepoints if no argument
11133@var{num} is given. A disabled tracepoint will have no effect during
d248b706 11134a trace experiment, but it is not forgotten. You can re-enable
b37052ae 11135a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
11136If the command is issued during a trace experiment and the debug target
11137has support for disabling tracepoints during a trace experiment, then the
11138change will be effective immediately. Otherwise, it will be applied to the
11139next trace experiment.
b37052ae
EZ
11140
11141@kindex enable tracepoint
11142@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
11143Enable tracepoint @var{num}, or all tracepoints. If this command is
11144issued during a trace experiment and the debug target supports enabling
11145tracepoints during a trace experiment, then the enabled tracepoints will
11146become effective immediately. Otherwise, they will become effective the
11147next time a trace experiment is run.
b37052ae
EZ
11148@end table
11149
11150@node Tracepoint Passcounts
11151@subsection Tracepoint Passcounts
11152
11153@table @code
11154@kindex passcount
11155@cindex tracepoint pass count
11156@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
11157Set the @dfn{passcount} of a tracepoint. The passcount is a way to
11158automatically stop a trace experiment. If a tracepoint's passcount is
11159@var{n}, then the trace experiment will be automatically stopped on
11160the @var{n}'th time that tracepoint is hit. If the tracepoint number
11161@var{num} is not specified, the @code{passcount} command sets the
11162passcount of the most recently defined tracepoint. If no passcount is
11163given, the trace experiment will run until stopped explicitly by the
11164user.
11165
11166Examples:
11167
11168@smallexample
b383017d 11169(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 11170@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
11171
11172(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 11173@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
11174(@value{GDBP}) @b{trace foo}
11175(@value{GDBP}) @b{pass 3}
11176(@value{GDBP}) @b{trace bar}
11177(@value{GDBP}) @b{pass 2}
11178(@value{GDBP}) @b{trace baz}
11179(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
11180@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
11181@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
11182@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
11183@end smallexample
11184@end table
11185
782b2b07
SS
11186@node Tracepoint Conditions
11187@subsection Tracepoint Conditions
11188@cindex conditional tracepoints
11189@cindex tracepoint conditions
11190
11191The simplest sort of tracepoint collects data every time your program
11192reaches a specified place. You can also specify a @dfn{condition} for
11193a tracepoint. A condition is just a Boolean expression in your
11194programming language (@pxref{Expressions, ,Expressions}). A
11195tracepoint with a condition evaluates the expression each time your
11196program reaches it, and data collection happens only if the condition
11197is true.
11198
11199Tracepoint conditions can be specified when a tracepoint is set, by
11200using @samp{if} in the arguments to the @code{trace} command.
11201@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
11202also be set or changed at any time with the @code{condition} command,
11203just as with breakpoints.
11204
11205Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
11206the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 11207expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
11208suitable for execution on the target, independently of @value{GDBN}.
11209Global variables become raw memory locations, locals become stack
11210accesses, and so forth.
11211
11212For instance, suppose you have a function that is usually called
11213frequently, but should not be called after an error has occurred. You
11214could use the following tracepoint command to collect data about calls
11215of that function that happen while the error code is propagating
11216through the program; an unconditional tracepoint could end up
11217collecting thousands of useless trace frames that you would have to
11218search through.
11219
11220@smallexample
11221(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
11222@end smallexample
11223
f61e138d
SS
11224@node Trace State Variables
11225@subsection Trace State Variables
11226@cindex trace state variables
11227
11228A @dfn{trace state variable} is a special type of variable that is
11229created and managed by target-side code. The syntax is the same as
11230that for GDB's convenience variables (a string prefixed with ``$''),
11231but they are stored on the target. They must be created explicitly,
11232using a @code{tvariable} command. They are always 64-bit signed
11233integers.
11234
11235Trace state variables are remembered by @value{GDBN}, and downloaded
11236to the target along with tracepoint information when the trace
11237experiment starts. There are no intrinsic limits on the number of
11238trace state variables, beyond memory limitations of the target.
11239
11240@cindex convenience variables, and trace state variables
11241Although trace state variables are managed by the target, you can use
11242them in print commands and expressions as if they were convenience
11243variables; @value{GDBN} will get the current value from the target
11244while the trace experiment is running. Trace state variables share
11245the same namespace as other ``$'' variables, which means that you
11246cannot have trace state variables with names like @code{$23} or
11247@code{$pc}, nor can you have a trace state variable and a convenience
11248variable with the same name.
11249
11250@table @code
11251
11252@item tvariable $@var{name} [ = @var{expression} ]
11253@kindex tvariable
11254The @code{tvariable} command creates a new trace state variable named
11255@code{$@var{name}}, and optionally gives it an initial value of
11256@var{expression}. @var{expression} is evaluated when this command is
11257entered; the result will be converted to an integer if possible,
11258otherwise @value{GDBN} will report an error. A subsequent
11259@code{tvariable} command specifying the same name does not create a
11260variable, but instead assigns the supplied initial value to the
11261existing variable of that name, overwriting any previous initial
11262value. The default initial value is 0.
11263
11264@item info tvariables
11265@kindex info tvariables
11266List all the trace state variables along with their initial values.
11267Their current values may also be displayed, if the trace experiment is
11268currently running.
11269
11270@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
11271@kindex delete tvariable
11272Delete the given trace state variables, or all of them if no arguments
11273are specified.
11274
11275@end table
11276
b37052ae
EZ
11277@node Tracepoint Actions
11278@subsection Tracepoint Action Lists
11279
11280@table @code
11281@kindex actions
11282@cindex tracepoint actions
11283@item actions @r{[}@var{num}@r{]}
11284This command will prompt for a list of actions to be taken when the
11285tracepoint is hit. If the tracepoint number @var{num} is not
11286specified, this command sets the actions for the one that was most
11287recently defined (so that you can define a tracepoint and then say
11288@code{actions} without bothering about its number). You specify the
11289actions themselves on the following lines, one action at a time, and
11290terminate the actions list with a line containing just @code{end}. So
7d13fe92 11291far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
11292@code{while-stepping}.
11293
5a9351ae
SS
11294@code{actions} is actually equivalent to @code{commands} (@pxref{Break
11295Commands, ,Breakpoint Command Lists}), except that only the defined
11296actions are allowed; any other @value{GDBN} command is rejected.
11297
b37052ae
EZ
11298@cindex remove actions from a tracepoint
11299To remove all actions from a tracepoint, type @samp{actions @var{num}}
11300and follow it immediately with @samp{end}.
11301
11302@smallexample
11303(@value{GDBP}) @b{collect @var{data}} // collect some data
11304
6826cf00 11305(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 11306
6826cf00 11307(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
11308@end smallexample
11309
11310In the following example, the action list begins with @code{collect}
11311commands indicating the things to be collected when the tracepoint is
11312hit. Then, in order to single-step and collect additional data
11313following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
11314followed by the list of things to be collected after each step in a
11315sequence of single steps. The @code{while-stepping} command is
11316terminated by its own separate @code{end} command. Lastly, the action
11317list is terminated by an @code{end} command.
b37052ae
EZ
11318
11319@smallexample
11320(@value{GDBP}) @b{trace foo}
11321(@value{GDBP}) @b{actions}
11322Enter actions for tracepoint 1, one per line:
11323> collect bar,baz
11324> collect $regs
11325> while-stepping 12
5a9351ae 11326 > collect $pc, arr[i]
b37052ae
EZ
11327 > end
11328end
11329@end smallexample
11330
11331@kindex collect @r{(tracepoints)}
3065dfb6 11332@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
11333Collect values of the given expressions when the tracepoint is hit.
11334This command accepts a comma-separated list of any valid expressions.
11335In addition to global, static, or local variables, the following
11336special arguments are supported:
11337
11338@table @code
11339@item $regs
0fb4aa4b 11340Collect all registers.
b37052ae
EZ
11341
11342@item $args
0fb4aa4b 11343Collect all function arguments.
b37052ae
EZ
11344
11345@item $locals
0fb4aa4b
PA
11346Collect all local variables.
11347
6710bf39
SS
11348@item $_ret
11349Collect the return address. This is helpful if you want to see more
11350of a backtrace.
11351
62e5f89c
SDJ
11352@item $_probe_argc
11353Collects the number of arguments from the static probe at which the
11354tracepoint is located.
11355@xref{Static Probe Points}.
11356
11357@item $_probe_arg@var{n}
11358@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
11359from the static probe at which the tracepoint is located.
11360@xref{Static Probe Points}.
11361
0fb4aa4b
PA
11362@item $_sdata
11363@vindex $_sdata@r{, collect}
11364Collect static tracepoint marker specific data. Only available for
11365static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
11366Lists}. On the UST static tracepoints library backend, an
11367instrumentation point resembles a @code{printf} function call. The
11368tracing library is able to collect user specified data formatted to a
11369character string using the format provided by the programmer that
11370instrumented the program. Other backends have similar mechanisms.
11371Here's an example of a UST marker call:
11372
11373@smallexample
11374 const char master_name[] = "$your_name";
11375 trace_mark(channel1, marker1, "hello %s", master_name)
11376@end smallexample
11377
11378In this case, collecting @code{$_sdata} collects the string
11379@samp{hello $yourname}. When analyzing the trace buffer, you can
11380inspect @samp{$_sdata} like any other variable available to
11381@value{GDBN}.
b37052ae
EZ
11382@end table
11383
11384You can give several consecutive @code{collect} commands, each one
11385with a single argument, or one @code{collect} command with several
5a9351ae 11386arguments separated by commas; the effect is the same.
b37052ae 11387
3065dfb6
SS
11388The optional @var{mods} changes the usual handling of the arguments.
11389@code{s} requests that pointers to chars be handled as strings, in
11390particular collecting the contents of the memory being pointed at, up
11391to the first zero. The upper bound is by default the value of the
11392@code{print elements} variable; if @code{s} is followed by a decimal
11393number, that is the upper bound instead. So for instance
11394@samp{collect/s25 mystr} collects as many as 25 characters at
11395@samp{mystr}.
11396
f5c37c66
EZ
11397The command @code{info scope} (@pxref{Symbols, info scope}) is
11398particularly useful for figuring out what data to collect.
11399
6da95a67
SS
11400@kindex teval @r{(tracepoints)}
11401@item teval @var{expr1}, @var{expr2}, @dots{}
11402Evaluate the given expressions when the tracepoint is hit. This
11403command accepts a comma-separated list of expressions. The results
11404are discarded, so this is mainly useful for assigning values to trace
11405state variables (@pxref{Trace State Variables}) without adding those
11406values to the trace buffer, as would be the case if the @code{collect}
11407action were used.
11408
b37052ae
EZ
11409@kindex while-stepping @r{(tracepoints)}
11410@item while-stepping @var{n}
c9429232 11411Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 11412collecting new data after each step. The @code{while-stepping}
c9429232
SS
11413command is followed by the list of what to collect while stepping
11414(followed by its own @code{end} command):
b37052ae
EZ
11415
11416@smallexample
11417> while-stepping 12
11418 > collect $regs, myglobal
11419 > end
11420>
11421@end smallexample
11422
11423@noindent
7d13fe92
SS
11424Note that @code{$pc} is not automatically collected by
11425@code{while-stepping}; you need to explicitly collect that register if
11426you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 11427@code{stepping}.
236f1d4d
SS
11428
11429@item set default-collect @var{expr1}, @var{expr2}, @dots{}
11430@kindex set default-collect
11431@cindex default collection action
11432This variable is a list of expressions to collect at each tracepoint
11433hit. It is effectively an additional @code{collect} action prepended
11434to every tracepoint action list. The expressions are parsed
11435individually for each tracepoint, so for instance a variable named
11436@code{xyz} may be interpreted as a global for one tracepoint, and a
11437local for another, as appropriate to the tracepoint's location.
11438
11439@item show default-collect
11440@kindex show default-collect
11441Show the list of expressions that are collected by default at each
11442tracepoint hit.
11443
b37052ae
EZ
11444@end table
11445
11446@node Listing Tracepoints
11447@subsection Listing Tracepoints
11448
11449@table @code
e5a67952
MS
11450@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
11451@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 11452@cindex information about tracepoints
e5a67952 11453@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
11454Display information about the tracepoint @var{num}. If you don't
11455specify a tracepoint number, displays information about all the
11456tracepoints defined so far. The format is similar to that used for
11457@code{info breakpoints}; in fact, @code{info tracepoints} is the same
11458command, simply restricting itself to tracepoints.
11459
11460A tracepoint's listing may include additional information specific to
11461tracing:
b37052ae
EZ
11462
11463@itemize @bullet
11464@item
b37052ae 11465its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
11466
11467@item
11468the state about installed on target of each location
b37052ae
EZ
11469@end itemize
11470
11471@smallexample
11472(@value{GDBP}) @b{info trace}
1042e4c0
SS
11473Num Type Disp Enb Address What
114741 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
11475 while-stepping 20
11476 collect globfoo, $regs
11477 end
11478 collect globfoo2
11479 end
1042e4c0 11480 pass count 1200
f2a8bc8a
YQ
114812 tracepoint keep y <MULTIPLE>
11482 collect $eip
114832.1 y 0x0804859c in func4 at change-loc.h:35
11484 installed on target
114852.2 y 0xb7ffc480 in func4 at change-loc.h:35
11486 installed on target
114872.3 y <PENDING> set_tracepoint
114883 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
11489 not installed on target
b37052ae
EZ
11490(@value{GDBP})
11491@end smallexample
11492
11493@noindent
11494This command can be abbreviated @code{info tp}.
11495@end table
11496
0fb4aa4b
PA
11497@node Listing Static Tracepoint Markers
11498@subsection Listing Static Tracepoint Markers
11499
11500@table @code
11501@kindex info static-tracepoint-markers
11502@cindex information about static tracepoint markers
11503@item info static-tracepoint-markers
11504Display information about all static tracepoint markers defined in the
11505program.
11506
11507For each marker, the following columns are printed:
11508
11509@table @emph
11510@item Count
11511An incrementing counter, output to help readability. This is not a
11512stable identifier.
11513@item ID
11514The marker ID, as reported by the target.
11515@item Enabled or Disabled
11516Probed markers are tagged with @samp{y}. @samp{n} identifies marks
11517that are not enabled.
11518@item Address
11519Where the marker is in your program, as a memory address.
11520@item What
11521Where the marker is in the source for your program, as a file and line
11522number. If the debug information included in the program does not
11523allow @value{GDBN} to locate the source of the marker, this column
11524will be left blank.
11525@end table
11526
11527@noindent
11528In addition, the following information may be printed for each marker:
11529
11530@table @emph
11531@item Data
11532User data passed to the tracing library by the marker call. In the
11533UST backend, this is the format string passed as argument to the
11534marker call.
11535@item Static tracepoints probing the marker
11536The list of static tracepoints attached to the marker.
11537@end table
11538
11539@smallexample
11540(@value{GDBP}) info static-tracepoint-markers
11541Cnt ID Enb Address What
115421 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
11543 Data: number1 %d number2 %d
11544 Probed by static tracepoints: #2
115452 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
11546 Data: str %s
11547(@value{GDBP})
11548@end smallexample
11549@end table
11550
79a6e687
BW
11551@node Starting and Stopping Trace Experiments
11552@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
11553
11554@table @code
f196051f 11555@kindex tstart [ @var{notes} ]
b37052ae
EZ
11556@cindex start a new trace experiment
11557@cindex collected data discarded
11558@item tstart
f196051f
SS
11559This command starts the trace experiment, and begins collecting data.
11560It has the side effect of discarding all the data collected in the
11561trace buffer during the previous trace experiment. If any arguments
11562are supplied, they are taken as a note and stored with the trace
11563experiment's state. The notes may be arbitrary text, and are
11564especially useful with disconnected tracing in a multi-user context;
11565the notes can explain what the trace is doing, supply user contact
11566information, and so forth.
11567
11568@kindex tstop [ @var{notes} ]
b37052ae
EZ
11569@cindex stop a running trace experiment
11570@item tstop
f196051f
SS
11571This command stops the trace experiment. If any arguments are
11572supplied, they are recorded with the experiment as a note. This is
11573useful if you are stopping a trace started by someone else, for
11574instance if the trace is interfering with the system's behavior and
11575needs to be stopped quickly.
b37052ae 11576
68c71a2e 11577@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
11578automatically if any tracepoint's passcount is reached
11579(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
11580
11581@kindex tstatus
11582@cindex status of trace data collection
11583@cindex trace experiment, status of
11584@item tstatus
11585This command displays the status of the current trace data
11586collection.
11587@end table
11588
11589Here is an example of the commands we described so far:
11590
11591@smallexample
11592(@value{GDBP}) @b{trace gdb_c_test}
11593(@value{GDBP}) @b{actions}
11594Enter actions for tracepoint #1, one per line.
11595> collect $regs,$locals,$args
11596> while-stepping 11
11597 > collect $regs
11598 > end
11599> end
11600(@value{GDBP}) @b{tstart}
11601 [time passes @dots{}]
11602(@value{GDBP}) @b{tstop}
11603@end smallexample
11604
03f2bd59 11605@anchor{disconnected tracing}
d5551862
SS
11606@cindex disconnected tracing
11607You can choose to continue running the trace experiment even if
11608@value{GDBN} disconnects from the target, voluntarily or
11609involuntarily. For commands such as @code{detach}, the debugger will
11610ask what you want to do with the trace. But for unexpected
11611terminations (@value{GDBN} crash, network outage), it would be
11612unfortunate to lose hard-won trace data, so the variable
11613@code{disconnected-tracing} lets you decide whether the trace should
11614continue running without @value{GDBN}.
11615
11616@table @code
11617@item set disconnected-tracing on
11618@itemx set disconnected-tracing off
11619@kindex set disconnected-tracing
11620Choose whether a tracing run should continue to run if @value{GDBN}
11621has disconnected from the target. Note that @code{detach} or
11622@code{quit} will ask you directly what to do about a running trace no
11623matter what this variable's setting, so the variable is mainly useful
11624for handling unexpected situations, such as loss of the network.
11625
11626@item show disconnected-tracing
11627@kindex show disconnected-tracing
11628Show the current choice for disconnected tracing.
11629
11630@end table
11631
11632When you reconnect to the target, the trace experiment may or may not
11633still be running; it might have filled the trace buffer in the
11634meantime, or stopped for one of the other reasons. If it is running,
11635it will continue after reconnection.
11636
11637Upon reconnection, the target will upload information about the
11638tracepoints in effect. @value{GDBN} will then compare that
11639information to the set of tracepoints currently defined, and attempt
11640to match them up, allowing for the possibility that the numbers may
11641have changed due to creation and deletion in the meantime. If one of
11642the target's tracepoints does not match any in @value{GDBN}, the
11643debugger will create a new tracepoint, so that you have a number with
11644which to specify that tracepoint. This matching-up process is
11645necessarily heuristic, and it may result in useless tracepoints being
11646created; you may simply delete them if they are of no use.
b37052ae 11647
4daf5ac0
SS
11648@cindex circular trace buffer
11649If your target agent supports a @dfn{circular trace buffer}, then you
11650can run a trace experiment indefinitely without filling the trace
11651buffer; when space runs out, the agent deletes already-collected trace
11652frames, oldest first, until there is enough room to continue
11653collecting. This is especially useful if your tracepoints are being
11654hit too often, and your trace gets terminated prematurely because the
11655buffer is full. To ask for a circular trace buffer, simply set
81896e36 11656@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
11657including during tracing; if the agent can do it, it will change
11658buffer handling on the fly, otherwise it will not take effect until
11659the next run.
11660
11661@table @code
11662@item set circular-trace-buffer on
11663@itemx set circular-trace-buffer off
11664@kindex set circular-trace-buffer
11665Choose whether a tracing run should use a linear or circular buffer
11666for trace data. A linear buffer will not lose any trace data, but may
11667fill up prematurely, while a circular buffer will discard old trace
11668data, but it will have always room for the latest tracepoint hits.
11669
11670@item show circular-trace-buffer
11671@kindex show circular-trace-buffer
11672Show the current choice for the trace buffer. Note that this may not
11673match the agent's current buffer handling, nor is it guaranteed to
11674match the setting that might have been in effect during a past run,
11675for instance if you are looking at frames from a trace file.
11676
11677@end table
11678
f196051f
SS
11679@table @code
11680@item set trace-user @var{text}
11681@kindex set trace-user
11682
11683@item show trace-user
11684@kindex show trace-user
11685
11686@item set trace-notes @var{text}
11687@kindex set trace-notes
11688Set the trace run's notes.
11689
11690@item show trace-notes
11691@kindex show trace-notes
11692Show the trace run's notes.
11693
11694@item set trace-stop-notes @var{text}
11695@kindex set trace-stop-notes
11696Set the trace run's stop notes. The handling of the note is as for
11697@code{tstop} arguments; the set command is convenient way to fix a
11698stop note that is mistaken or incomplete.
11699
11700@item show trace-stop-notes
11701@kindex show trace-stop-notes
11702Show the trace run's stop notes.
11703
11704@end table
11705
c9429232
SS
11706@node Tracepoint Restrictions
11707@subsection Tracepoint Restrictions
11708
11709@cindex tracepoint restrictions
11710There are a number of restrictions on the use of tracepoints. As
11711described above, tracepoint data gathering occurs on the target
11712without interaction from @value{GDBN}. Thus the full capabilities of
11713the debugger are not available during data gathering, and then at data
11714examination time, you will be limited by only having what was
11715collected. The following items describe some common problems, but it
11716is not exhaustive, and you may run into additional difficulties not
11717mentioned here.
11718
11719@itemize @bullet
11720
11721@item
11722Tracepoint expressions are intended to gather objects (lvalues). Thus
11723the full flexibility of GDB's expression evaluator is not available.
11724You cannot call functions, cast objects to aggregate types, access
11725convenience variables or modify values (except by assignment to trace
11726state variables). Some language features may implicitly call
11727functions (for instance Objective-C fields with accessors), and therefore
11728cannot be collected either.
11729
11730@item
11731Collection of local variables, either individually or in bulk with
11732@code{$locals} or @code{$args}, during @code{while-stepping} may
11733behave erratically. The stepping action may enter a new scope (for
11734instance by stepping into a function), or the location of the variable
11735may change (for instance it is loaded into a register). The
11736tracepoint data recorded uses the location information for the
11737variables that is correct for the tracepoint location. When the
11738tracepoint is created, it is not possible, in general, to determine
11739where the steps of a @code{while-stepping} sequence will advance the
11740program---particularly if a conditional branch is stepped.
11741
11742@item
11743Collection of an incompletely-initialized or partially-destroyed object
11744may result in something that @value{GDBN} cannot display, or displays
11745in a misleading way.
11746
11747@item
11748When @value{GDBN} displays a pointer to character it automatically
11749dereferences the pointer to also display characters of the string
11750being pointed to. However, collecting the pointer during tracing does
11751not automatically collect the string. You need to explicitly
11752dereference the pointer and provide size information if you want to
11753collect not only the pointer, but the memory pointed to. For example,
11754@code{*ptr@@50} can be used to collect the 50 element array pointed to
11755by @code{ptr}.
11756
11757@item
11758It is not possible to collect a complete stack backtrace at a
11759tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 11760bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
11761(adjust to use the name of the actual stack pointer register on your
11762target architecture, and the amount of stack you wish to capture).
11763Then the @code{backtrace} command will show a partial backtrace when
11764using a trace frame. The number of stack frames that can be examined
11765depends on the sizes of the frames in the collected stack. Note that
11766if you ask for a block so large that it goes past the bottom of the
11767stack, the target agent may report an error trying to read from an
11768invalid address.
11769
af54718e
SS
11770@item
11771If you do not collect registers at a tracepoint, @value{GDBN} can
11772infer that the value of @code{$pc} must be the same as the address of
11773the tracepoint and use that when you are looking at a trace frame
11774for that tracepoint. However, this cannot work if the tracepoint has
11775multiple locations (for instance if it was set in a function that was
11776inlined), or if it has a @code{while-stepping} loop. In those cases
11777@value{GDBN} will warn you that it can't infer @code{$pc}, and default
11778it to zero.
11779
c9429232
SS
11780@end itemize
11781
b37052ae 11782@node Analyze Collected Data
79a6e687 11783@section Using the Collected Data
b37052ae
EZ
11784
11785After the tracepoint experiment ends, you use @value{GDBN} commands
11786for examining the trace data. The basic idea is that each tracepoint
11787collects a trace @dfn{snapshot} every time it is hit and another
11788snapshot every time it single-steps. All these snapshots are
11789consecutively numbered from zero and go into a buffer, and you can
11790examine them later. The way you examine them is to @dfn{focus} on a
11791specific trace snapshot. When the remote stub is focused on a trace
11792snapshot, it will respond to all @value{GDBN} requests for memory and
11793registers by reading from the buffer which belongs to that snapshot,
11794rather than from @emph{real} memory or registers of the program being
11795debugged. This means that @strong{all} @value{GDBN} commands
11796(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
11797behave as if we were currently debugging the program state as it was
11798when the tracepoint occurred. Any requests for data that are not in
11799the buffer will fail.
11800
11801@menu
11802* tfind:: How to select a trace snapshot
11803* tdump:: How to display all data for a snapshot
6149aea9 11804* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
11805@end menu
11806
11807@node tfind
11808@subsection @code{tfind @var{n}}
11809
11810@kindex tfind
11811@cindex select trace snapshot
11812@cindex find trace snapshot
11813The basic command for selecting a trace snapshot from the buffer is
11814@code{tfind @var{n}}, which finds trace snapshot number @var{n},
11815counting from zero. If no argument @var{n} is given, the next
11816snapshot is selected.
11817
11818Here are the various forms of using the @code{tfind} command.
11819
11820@table @code
11821@item tfind start
11822Find the first snapshot in the buffer. This is a synonym for
11823@code{tfind 0} (since 0 is the number of the first snapshot).
11824
11825@item tfind none
11826Stop debugging trace snapshots, resume @emph{live} debugging.
11827
11828@item tfind end
11829Same as @samp{tfind none}.
11830
11831@item tfind
11832No argument means find the next trace snapshot.
11833
11834@item tfind -
11835Find the previous trace snapshot before the current one. This permits
11836retracing earlier steps.
11837
11838@item tfind tracepoint @var{num}
11839Find the next snapshot associated with tracepoint @var{num}. Search
11840proceeds forward from the last examined trace snapshot. If no
11841argument @var{num} is given, it means find the next snapshot collected
11842for the same tracepoint as the current snapshot.
11843
11844@item tfind pc @var{addr}
11845Find the next snapshot associated with the value @var{addr} of the
11846program counter. Search proceeds forward from the last examined trace
11847snapshot. If no argument @var{addr} is given, it means find the next
11848snapshot with the same value of PC as the current snapshot.
11849
11850@item tfind outside @var{addr1}, @var{addr2}
11851Find the next snapshot whose PC is outside the given range of
081dfbf7 11852addresses (exclusive).
b37052ae
EZ
11853
11854@item tfind range @var{addr1}, @var{addr2}
11855Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 11856@var{addr2} (inclusive).
b37052ae
EZ
11857
11858@item tfind line @r{[}@var{file}:@r{]}@var{n}
11859Find the next snapshot associated with the source line @var{n}. If
11860the optional argument @var{file} is given, refer to line @var{n} in
11861that source file. Search proceeds forward from the last examined
11862trace snapshot. If no argument @var{n} is given, it means find the
11863next line other than the one currently being examined; thus saying
11864@code{tfind line} repeatedly can appear to have the same effect as
11865stepping from line to line in a @emph{live} debugging session.
11866@end table
11867
11868The default arguments for the @code{tfind} commands are specifically
11869designed to make it easy to scan through the trace buffer. For
11870instance, @code{tfind} with no argument selects the next trace
11871snapshot, and @code{tfind -} with no argument selects the previous
11872trace snapshot. So, by giving one @code{tfind} command, and then
11873simply hitting @key{RET} repeatedly you can examine all the trace
11874snapshots in order. Or, by saying @code{tfind -} and then hitting
11875@key{RET} repeatedly you can examine the snapshots in reverse order.
11876The @code{tfind line} command with no argument selects the snapshot
11877for the next source line executed. The @code{tfind pc} command with
11878no argument selects the next snapshot with the same program counter
11879(PC) as the current frame. The @code{tfind tracepoint} command with
11880no argument selects the next trace snapshot collected by the same
11881tracepoint as the current one.
11882
11883In addition to letting you scan through the trace buffer manually,
11884these commands make it easy to construct @value{GDBN} scripts that
11885scan through the trace buffer and print out whatever collected data
11886you are interested in. Thus, if we want to examine the PC, FP, and SP
11887registers from each trace frame in the buffer, we can say this:
11888
11889@smallexample
11890(@value{GDBP}) @b{tfind start}
11891(@value{GDBP}) @b{while ($trace_frame != -1)}
11892> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
11893 $trace_frame, $pc, $sp, $fp
11894> tfind
11895> end
11896
11897Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
11898Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
11899Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
11900Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
11901Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
11902Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
11903Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
11904Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
11905Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
11906Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
11907Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
11908@end smallexample
11909
11910Or, if we want to examine the variable @code{X} at each source line in
11911the buffer:
11912
11913@smallexample
11914(@value{GDBP}) @b{tfind start}
11915(@value{GDBP}) @b{while ($trace_frame != -1)}
11916> printf "Frame %d, X == %d\n", $trace_frame, X
11917> tfind line
11918> end
11919
11920Frame 0, X = 1
11921Frame 7, X = 2
11922Frame 13, X = 255
11923@end smallexample
11924
11925@node tdump
11926@subsection @code{tdump}
11927@kindex tdump
11928@cindex dump all data collected at tracepoint
11929@cindex tracepoint data, display
11930
11931This command takes no arguments. It prints all the data collected at
11932the current trace snapshot.
11933
11934@smallexample
11935(@value{GDBP}) @b{trace 444}
11936(@value{GDBP}) @b{actions}
11937Enter actions for tracepoint #2, one per line:
11938> collect $regs, $locals, $args, gdb_long_test
11939> end
11940
11941(@value{GDBP}) @b{tstart}
11942
11943(@value{GDBP}) @b{tfind line 444}
11944#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
11945at gdb_test.c:444
11946444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
11947
11948(@value{GDBP}) @b{tdump}
11949Data collected at tracepoint 2, trace frame 1:
11950d0 0xc4aa0085 -995491707
11951d1 0x18 24
11952d2 0x80 128
11953d3 0x33 51
11954d4 0x71aea3d 119204413
11955d5 0x22 34
11956d6 0xe0 224
11957d7 0x380035 3670069
11958a0 0x19e24a 1696330
11959a1 0x3000668 50333288
11960a2 0x100 256
11961a3 0x322000 3284992
11962a4 0x3000698 50333336
11963a5 0x1ad3cc 1758156
11964fp 0x30bf3c 0x30bf3c
11965sp 0x30bf34 0x30bf34
11966ps 0x0 0
11967pc 0x20b2c8 0x20b2c8
11968fpcontrol 0x0 0
11969fpstatus 0x0 0
11970fpiaddr 0x0 0
11971p = 0x20e5b4 "gdb-test"
11972p1 = (void *) 0x11
11973p2 = (void *) 0x22
11974p3 = (void *) 0x33
11975p4 = (void *) 0x44
11976p5 = (void *) 0x55
11977p6 = (void *) 0x66
11978gdb_long_test = 17 '\021'
11979
11980(@value{GDBP})
11981@end smallexample
11982
af54718e
SS
11983@code{tdump} works by scanning the tracepoint's current collection
11984actions and printing the value of each expression listed. So
11985@code{tdump} can fail, if after a run, you change the tracepoint's
11986actions to mention variables that were not collected during the run.
11987
11988Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
11989uses the collected value of @code{$pc} to distinguish between trace
11990frames that were collected at the tracepoint hit, and frames that were
11991collected while stepping. This allows it to correctly choose whether
11992to display the basic list of collections, or the collections from the
11993body of the while-stepping loop. However, if @code{$pc} was not collected,
11994then @code{tdump} will always attempt to dump using the basic collection
11995list, and may fail if a while-stepping frame does not include all the
11996same data that is collected at the tracepoint hit.
11997@c This is getting pretty arcane, example would be good.
11998
6149aea9
PA
11999@node save tracepoints
12000@subsection @code{save tracepoints @var{filename}}
12001@kindex save tracepoints
b37052ae
EZ
12002@kindex save-tracepoints
12003@cindex save tracepoints for future sessions
12004
12005This command saves all current tracepoint definitions together with
12006their actions and passcounts, into a file @file{@var{filename}}
12007suitable for use in a later debugging session. To read the saved
12008tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
12009Files}). The @w{@code{save-tracepoints}} command is a deprecated
12010alias for @w{@code{save tracepoints}}
b37052ae
EZ
12011
12012@node Tracepoint Variables
12013@section Convenience Variables for Tracepoints
12014@cindex tracepoint variables
12015@cindex convenience variables for tracepoints
12016
12017@table @code
12018@vindex $trace_frame
12019@item (int) $trace_frame
12020The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
12021snapshot is selected.
12022
12023@vindex $tracepoint
12024@item (int) $tracepoint
12025The tracepoint for the current trace snapshot.
12026
12027@vindex $trace_line
12028@item (int) $trace_line
12029The line number for the current trace snapshot.
12030
12031@vindex $trace_file
12032@item (char []) $trace_file
12033The source file for the current trace snapshot.
12034
12035@vindex $trace_func
12036@item (char []) $trace_func
12037The name of the function containing @code{$tracepoint}.
12038@end table
12039
12040Note: @code{$trace_file} is not suitable for use in @code{printf},
12041use @code{output} instead.
12042
12043Here's a simple example of using these convenience variables for
12044stepping through all the trace snapshots and printing some of their
f61e138d
SS
12045data. Note that these are not the same as trace state variables,
12046which are managed by the target.
b37052ae
EZ
12047
12048@smallexample
12049(@value{GDBP}) @b{tfind start}
12050
12051(@value{GDBP}) @b{while $trace_frame != -1}
12052> output $trace_file
12053> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
12054> tfind
12055> end
12056@end smallexample
12057
00bf0b85
SS
12058@node Trace Files
12059@section Using Trace Files
12060@cindex trace files
12061
12062In some situations, the target running a trace experiment may no
12063longer be available; perhaps it crashed, or the hardware was needed
12064for a different activity. To handle these cases, you can arrange to
12065dump the trace data into a file, and later use that file as a source
12066of trace data, via the @code{target tfile} command.
12067
12068@table @code
12069
12070@kindex tsave
12071@item tsave [ -r ] @var{filename}
12072Save the trace data to @var{filename}. By default, this command
12073assumes that @var{filename} refers to the host filesystem, so if
12074necessary @value{GDBN} will copy raw trace data up from the target and
12075then save it. If the target supports it, you can also supply the
12076optional argument @code{-r} (``remote'') to direct the target to save
12077the data directly into @var{filename} in its own filesystem, which may be
12078more efficient if the trace buffer is very large. (Note, however, that
12079@code{target tfile} can only read from files accessible to the host.)
12080
12081@kindex target tfile
12082@kindex tfile
12083@item target tfile @var{filename}
12084Use the file named @var{filename} as a source of trace data. Commands
12085that examine data work as they do with a live target, but it is not
12086possible to run any new trace experiments. @code{tstatus} will report
12087the state of the trace run at the moment the data was saved, as well
12088as the current trace frame you are examining. @var{filename} must be
12089on a filesystem accessible to the host.
12090
12091@end table
12092
df0cd8c5
JB
12093@node Overlays
12094@chapter Debugging Programs That Use Overlays
12095@cindex overlays
12096
12097If your program is too large to fit completely in your target system's
12098memory, you can sometimes use @dfn{overlays} to work around this
12099problem. @value{GDBN} provides some support for debugging programs that
12100use overlays.
12101
12102@menu
12103* How Overlays Work:: A general explanation of overlays.
12104* Overlay Commands:: Managing overlays in @value{GDBN}.
12105* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
12106 mapped by asking the inferior.
12107* Overlay Sample Program:: A sample program using overlays.
12108@end menu
12109
12110@node How Overlays Work
12111@section How Overlays Work
12112@cindex mapped overlays
12113@cindex unmapped overlays
12114@cindex load address, overlay's
12115@cindex mapped address
12116@cindex overlay area
12117
12118Suppose you have a computer whose instruction address space is only 64
12119kilobytes long, but which has much more memory which can be accessed by
12120other means: special instructions, segment registers, or memory
12121management hardware, for example. Suppose further that you want to
12122adapt a program which is larger than 64 kilobytes to run on this system.
12123
12124One solution is to identify modules of your program which are relatively
12125independent, and need not call each other directly; call these modules
12126@dfn{overlays}. Separate the overlays from the main program, and place
12127their machine code in the larger memory. Place your main program in
12128instruction memory, but leave at least enough space there to hold the
12129largest overlay as well.
12130
12131Now, to call a function located in an overlay, you must first copy that
12132overlay's machine code from the large memory into the space set aside
12133for it in the instruction memory, and then jump to its entry point
12134there.
12135
c928edc0
AC
12136@c NB: In the below the mapped area's size is greater or equal to the
12137@c size of all overlays. This is intentional to remind the developer
12138@c that overlays don't necessarily need to be the same size.
12139
474c8240 12140@smallexample
df0cd8c5 12141@group
c928edc0
AC
12142 Data Instruction Larger
12143Address Space Address Space Address Space
12144+-----------+ +-----------+ +-----------+
12145| | | | | |
12146+-----------+ +-----------+ +-----------+<-- overlay 1
12147| program | | main | .----| overlay 1 | load address
12148| variables | | program | | +-----------+
12149| and heap | | | | | |
12150+-----------+ | | | +-----------+<-- overlay 2
12151| | +-----------+ | | | load address
12152+-----------+ | | | .-| overlay 2 |
12153 | | | | | |
12154 mapped --->+-----------+ | | +-----------+
12155 address | | | | | |
12156 | overlay | <-' | | |
12157 | area | <---' +-----------+<-- overlay 3
12158 | | <---. | | load address
12159 +-----------+ `--| overlay 3 |
12160 | | | |
12161 +-----------+ | |
12162 +-----------+
12163 | |
12164 +-----------+
12165
12166 @anchor{A code overlay}A code overlay
df0cd8c5 12167@end group
474c8240 12168@end smallexample
df0cd8c5 12169
c928edc0
AC
12170The diagram (@pxref{A code overlay}) shows a system with separate data
12171and instruction address spaces. To map an overlay, the program copies
12172its code from the larger address space to the instruction address space.
12173Since the overlays shown here all use the same mapped address, only one
12174may be mapped at a time. For a system with a single address space for
12175data and instructions, the diagram would be similar, except that the
12176program variables and heap would share an address space with the main
12177program and the overlay area.
df0cd8c5
JB
12178
12179An overlay loaded into instruction memory and ready for use is called a
12180@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
12181instruction memory. An overlay not present (or only partially present)
12182in instruction memory is called @dfn{unmapped}; its @dfn{load address}
12183is its address in the larger memory. The mapped address is also called
12184the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
12185called the @dfn{load memory address}, or @dfn{LMA}.
12186
12187Unfortunately, overlays are not a completely transparent way to adapt a
12188program to limited instruction memory. They introduce a new set of
12189global constraints you must keep in mind as you design your program:
12190
12191@itemize @bullet
12192
12193@item
12194Before calling or returning to a function in an overlay, your program
12195must make sure that overlay is actually mapped. Otherwise, the call or
12196return will transfer control to the right address, but in the wrong
12197overlay, and your program will probably crash.
12198
12199@item
12200If the process of mapping an overlay is expensive on your system, you
12201will need to choose your overlays carefully to minimize their effect on
12202your program's performance.
12203
12204@item
12205The executable file you load onto your system must contain each
12206overlay's instructions, appearing at the overlay's load address, not its
12207mapped address. However, each overlay's instructions must be relocated
12208and its symbols defined as if the overlay were at its mapped address.
12209You can use GNU linker scripts to specify different load and relocation
12210addresses for pieces of your program; see @ref{Overlay Description,,,
12211ld.info, Using ld: the GNU linker}.
12212
12213@item
12214The procedure for loading executable files onto your system must be able
12215to load their contents into the larger address space as well as the
12216instruction and data spaces.
12217
12218@end itemize
12219
12220The overlay system described above is rather simple, and could be
12221improved in many ways:
12222
12223@itemize @bullet
12224
12225@item
12226If your system has suitable bank switch registers or memory management
12227hardware, you could use those facilities to make an overlay's load area
12228contents simply appear at their mapped address in instruction space.
12229This would probably be faster than copying the overlay to its mapped
12230area in the usual way.
12231
12232@item
12233If your overlays are small enough, you could set aside more than one
12234overlay area, and have more than one overlay mapped at a time.
12235
12236@item
12237You can use overlays to manage data, as well as instructions. In
12238general, data overlays are even less transparent to your design than
12239code overlays: whereas code overlays only require care when you call or
12240return to functions, data overlays require care every time you access
12241the data. Also, if you change the contents of a data overlay, you
12242must copy its contents back out to its load address before you can copy a
12243different data overlay into the same mapped area.
12244
12245@end itemize
12246
12247
12248@node Overlay Commands
12249@section Overlay Commands
12250
12251To use @value{GDBN}'s overlay support, each overlay in your program must
12252correspond to a separate section of the executable file. The section's
12253virtual memory address and load memory address must be the overlay's
12254mapped and load addresses. Identifying overlays with sections allows
12255@value{GDBN} to determine the appropriate address of a function or
12256variable, depending on whether the overlay is mapped or not.
12257
12258@value{GDBN}'s overlay commands all start with the word @code{overlay};
12259you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
12260
12261@table @code
12262@item overlay off
4644b6e3 12263@kindex overlay
df0cd8c5
JB
12264Disable @value{GDBN}'s overlay support. When overlay support is
12265disabled, @value{GDBN} assumes that all functions and variables are
12266always present at their mapped addresses. By default, @value{GDBN}'s
12267overlay support is disabled.
12268
12269@item overlay manual
df0cd8c5
JB
12270@cindex manual overlay debugging
12271Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
12272relies on you to tell it which overlays are mapped, and which are not,
12273using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
12274commands described below.
12275
12276@item overlay map-overlay @var{overlay}
12277@itemx overlay map @var{overlay}
df0cd8c5
JB
12278@cindex map an overlay
12279Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
12280be the name of the object file section containing the overlay. When an
12281overlay is mapped, @value{GDBN} assumes it can find the overlay's
12282functions and variables at their mapped addresses. @value{GDBN} assumes
12283that any other overlays whose mapped ranges overlap that of
12284@var{overlay} are now unmapped.
12285
12286@item overlay unmap-overlay @var{overlay}
12287@itemx overlay unmap @var{overlay}
df0cd8c5
JB
12288@cindex unmap an overlay
12289Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
12290must be the name of the object file section containing the overlay.
12291When an overlay is unmapped, @value{GDBN} assumes it can find the
12292overlay's functions and variables at their load addresses.
12293
12294@item overlay auto
df0cd8c5
JB
12295Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
12296consults a data structure the overlay manager maintains in the inferior
12297to see which overlays are mapped. For details, see @ref{Automatic
12298Overlay Debugging}.
12299
12300@item overlay load-target
12301@itemx overlay load
df0cd8c5
JB
12302@cindex reloading the overlay table
12303Re-read the overlay table from the inferior. Normally, @value{GDBN}
12304re-reads the table @value{GDBN} automatically each time the inferior
12305stops, so this command should only be necessary if you have changed the
12306overlay mapping yourself using @value{GDBN}. This command is only
12307useful when using automatic overlay debugging.
12308
12309@item overlay list-overlays
12310@itemx overlay list
12311@cindex listing mapped overlays
12312Display a list of the overlays currently mapped, along with their mapped
12313addresses, load addresses, and sizes.
12314
12315@end table
12316
12317Normally, when @value{GDBN} prints a code address, it includes the name
12318of the function the address falls in:
12319
474c8240 12320@smallexample
f7dc1244 12321(@value{GDBP}) print main
df0cd8c5 12322$3 = @{int ()@} 0x11a0 <main>
474c8240 12323@end smallexample
df0cd8c5
JB
12324@noindent
12325When overlay debugging is enabled, @value{GDBN} recognizes code in
12326unmapped overlays, and prints the names of unmapped functions with
12327asterisks around them. For example, if @code{foo} is a function in an
12328unmapped overlay, @value{GDBN} prints it this way:
12329
474c8240 12330@smallexample
f7dc1244 12331(@value{GDBP}) overlay list
df0cd8c5 12332No sections are mapped.
f7dc1244 12333(@value{GDBP}) print foo
df0cd8c5 12334$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 12335@end smallexample
df0cd8c5
JB
12336@noindent
12337When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
12338name normally:
12339
474c8240 12340@smallexample
f7dc1244 12341(@value{GDBP}) overlay list
b383017d 12342Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 12343 mapped at 0x1016 - 0x104a
f7dc1244 12344(@value{GDBP}) print foo
df0cd8c5 12345$6 = @{int (int)@} 0x1016 <foo>
474c8240 12346@end smallexample
df0cd8c5
JB
12347
12348When overlay debugging is enabled, @value{GDBN} can find the correct
12349address for functions and variables in an overlay, whether or not the
12350overlay is mapped. This allows most @value{GDBN} commands, like
12351@code{break} and @code{disassemble}, to work normally, even on unmapped
12352code. However, @value{GDBN}'s breakpoint support has some limitations:
12353
12354@itemize @bullet
12355@item
12356@cindex breakpoints in overlays
12357@cindex overlays, setting breakpoints in
12358You can set breakpoints in functions in unmapped overlays, as long as
12359@value{GDBN} can write to the overlay at its load address.
12360@item
12361@value{GDBN} can not set hardware or simulator-based breakpoints in
12362unmapped overlays. However, if you set a breakpoint at the end of your
12363overlay manager (and tell @value{GDBN} which overlays are now mapped, if
12364you are using manual overlay management), @value{GDBN} will re-set its
12365breakpoints properly.
12366@end itemize
12367
12368
12369@node Automatic Overlay Debugging
12370@section Automatic Overlay Debugging
12371@cindex automatic overlay debugging
12372
12373@value{GDBN} can automatically track which overlays are mapped and which
12374are not, given some simple co-operation from the overlay manager in the
12375inferior. If you enable automatic overlay debugging with the
12376@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
12377looks in the inferior's memory for certain variables describing the
12378current state of the overlays.
12379
12380Here are the variables your overlay manager must define to support
12381@value{GDBN}'s automatic overlay debugging:
12382
12383@table @asis
12384
12385@item @code{_ovly_table}:
12386This variable must be an array of the following structures:
12387
474c8240 12388@smallexample
df0cd8c5
JB
12389struct
12390@{
12391 /* The overlay's mapped address. */
12392 unsigned long vma;
12393
12394 /* The size of the overlay, in bytes. */
12395 unsigned long size;
12396
12397 /* The overlay's load address. */
12398 unsigned long lma;
12399
12400 /* Non-zero if the overlay is currently mapped;
12401 zero otherwise. */
12402 unsigned long mapped;
12403@}
474c8240 12404@end smallexample
df0cd8c5
JB
12405
12406@item @code{_novlys}:
12407This variable must be a four-byte signed integer, holding the total
12408number of elements in @code{_ovly_table}.
12409
12410@end table
12411
12412To decide whether a particular overlay is mapped or not, @value{GDBN}
12413looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
12414@code{lma} members equal the VMA and LMA of the overlay's section in the
12415executable file. When @value{GDBN} finds a matching entry, it consults
12416the entry's @code{mapped} member to determine whether the overlay is
12417currently mapped.
12418
81d46470 12419In addition, your overlay manager may define a function called
def71bfa 12420@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
12421will silently set a breakpoint there. If the overlay manager then
12422calls this function whenever it has changed the overlay table, this
12423will enable @value{GDBN} to accurately keep track of which overlays
12424are in program memory, and update any breakpoints that may be set
b383017d 12425in overlays. This will allow breakpoints to work even if the
81d46470
MS
12426overlays are kept in ROM or other non-writable memory while they
12427are not being executed.
df0cd8c5
JB
12428
12429@node Overlay Sample Program
12430@section Overlay Sample Program
12431@cindex overlay example program
12432
12433When linking a program which uses overlays, you must place the overlays
12434at their load addresses, while relocating them to run at their mapped
12435addresses. To do this, you must write a linker script (@pxref{Overlay
12436Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
12437since linker scripts are specific to a particular host system, target
12438architecture, and target memory layout, this manual cannot provide
12439portable sample code demonstrating @value{GDBN}'s overlay support.
12440
12441However, the @value{GDBN} source distribution does contain an overlaid
12442program, with linker scripts for a few systems, as part of its test
12443suite. The program consists of the following files from
12444@file{gdb/testsuite/gdb.base}:
12445
12446@table @file
12447@item overlays.c
12448The main program file.
12449@item ovlymgr.c
12450A simple overlay manager, used by @file{overlays.c}.
12451@item foo.c
12452@itemx bar.c
12453@itemx baz.c
12454@itemx grbx.c
12455Overlay modules, loaded and used by @file{overlays.c}.
12456@item d10v.ld
12457@itemx m32r.ld
12458Linker scripts for linking the test program on the @code{d10v-elf}
12459and @code{m32r-elf} targets.
12460@end table
12461
12462You can build the test program using the @code{d10v-elf} GCC
12463cross-compiler like this:
12464
474c8240 12465@smallexample
df0cd8c5
JB
12466$ d10v-elf-gcc -g -c overlays.c
12467$ d10v-elf-gcc -g -c ovlymgr.c
12468$ d10v-elf-gcc -g -c foo.c
12469$ d10v-elf-gcc -g -c bar.c
12470$ d10v-elf-gcc -g -c baz.c
12471$ d10v-elf-gcc -g -c grbx.c
12472$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
12473 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 12474@end smallexample
df0cd8c5
JB
12475
12476The build process is identical for any other architecture, except that
12477you must substitute the appropriate compiler and linker script for the
12478target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
12479
12480
6d2ebf8b 12481@node Languages
c906108c
SS
12482@chapter Using @value{GDBN} with Different Languages
12483@cindex languages
12484
c906108c
SS
12485Although programming languages generally have common aspects, they are
12486rarely expressed in the same manner. For instance, in ANSI C,
12487dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
12488Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 12489represented (and displayed) differently. Hex numbers in C appear as
c906108c 12490@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
12491
12492@cindex working language
12493Language-specific information is built into @value{GDBN} for some languages,
12494allowing you to express operations like the above in your program's
12495native language, and allowing @value{GDBN} to output values in a manner
12496consistent with the syntax of your program's native language. The
12497language you use to build expressions is called the @dfn{working
12498language}.
12499
12500@menu
12501* Setting:: Switching between source languages
12502* Show:: Displaying the language
c906108c 12503* Checks:: Type and range checks
79a6e687
BW
12504* Supported Languages:: Supported languages
12505* Unsupported Languages:: Unsupported languages
c906108c
SS
12506@end menu
12507
6d2ebf8b 12508@node Setting
79a6e687 12509@section Switching Between Source Languages
c906108c
SS
12510
12511There are two ways to control the working language---either have @value{GDBN}
12512set it automatically, or select it manually yourself. You can use the
12513@code{set language} command for either purpose. On startup, @value{GDBN}
12514defaults to setting the language automatically. The working language is
12515used to determine how expressions you type are interpreted, how values
12516are printed, etc.
12517
12518In addition to the working language, every source file that
12519@value{GDBN} knows about has its own working language. For some object
12520file formats, the compiler might indicate which language a particular
12521source file is in. However, most of the time @value{GDBN} infers the
12522language from the name of the file. The language of a source file
b37052ae 12523controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 12524show each frame appropriately for its own language. There is no way to
d4f3574e
SS
12525set the language of a source file from within @value{GDBN}, but you can
12526set the language associated with a filename extension. @xref{Show, ,
79a6e687 12527Displaying the Language}.
c906108c
SS
12528
12529This is most commonly a problem when you use a program, such
5d161b24 12530as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
12531another language. In that case, make the
12532program use @code{#line} directives in its C output; that way
12533@value{GDBN} will know the correct language of the source code of the original
12534program, and will display that source code, not the generated C code.
12535
12536@menu
12537* Filenames:: Filename extensions and languages.
12538* Manually:: Setting the working language manually
12539* Automatically:: Having @value{GDBN} infer the source language
12540@end menu
12541
6d2ebf8b 12542@node Filenames
79a6e687 12543@subsection List of Filename Extensions and Languages
c906108c
SS
12544
12545If a source file name ends in one of the following extensions, then
12546@value{GDBN} infers that its language is the one indicated.
12547
12548@table @file
e07c999f
PH
12549@item .ada
12550@itemx .ads
12551@itemx .adb
12552@itemx .a
12553Ada source file.
c906108c
SS
12554
12555@item .c
12556C source file
12557
12558@item .C
12559@itemx .cc
12560@itemx .cp
12561@itemx .cpp
12562@itemx .cxx
12563@itemx .c++
b37052ae 12564C@t{++} source file
c906108c 12565
6aecb9c2
JB
12566@item .d
12567D source file
12568
b37303ee
AF
12569@item .m
12570Objective-C source file
12571
c906108c
SS
12572@item .f
12573@itemx .F
12574Fortran source file
12575
c906108c
SS
12576@item .mod
12577Modula-2 source file
c906108c
SS
12578
12579@item .s
12580@itemx .S
12581Assembler source file. This actually behaves almost like C, but
12582@value{GDBN} does not skip over function prologues when stepping.
12583@end table
12584
12585In addition, you may set the language associated with a filename
79a6e687 12586extension. @xref{Show, , Displaying the Language}.
c906108c 12587
6d2ebf8b 12588@node Manually
79a6e687 12589@subsection Setting the Working Language
c906108c
SS
12590
12591If you allow @value{GDBN} to set the language automatically,
12592expressions are interpreted the same way in your debugging session and
12593your program.
12594
12595@kindex set language
12596If you wish, you may set the language manually. To do this, issue the
12597command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 12598a language, such as
c906108c 12599@code{c} or @code{modula-2}.
c906108c
SS
12600For a list of the supported languages, type @samp{set language}.
12601
c906108c
SS
12602Setting the language manually prevents @value{GDBN} from updating the working
12603language automatically. This can lead to confusion if you try
12604to debug a program when the working language is not the same as the
12605source language, when an expression is acceptable to both
12606languages---but means different things. For instance, if the current
12607source file were written in C, and @value{GDBN} was parsing Modula-2, a
12608command such as:
12609
474c8240 12610@smallexample
c906108c 12611print a = b + c
474c8240 12612@end smallexample
c906108c
SS
12613
12614@noindent
12615might not have the effect you intended. In C, this means to add
12616@code{b} and @code{c} and place the result in @code{a}. The result
12617printed would be the value of @code{a}. In Modula-2, this means to compare
12618@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 12619
6d2ebf8b 12620@node Automatically
79a6e687 12621@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
12622
12623To have @value{GDBN} set the working language automatically, use
12624@samp{set language local} or @samp{set language auto}. @value{GDBN}
12625then infers the working language. That is, when your program stops in a
12626frame (usually by encountering a breakpoint), @value{GDBN} sets the
12627working language to the language recorded for the function in that
12628frame. If the language for a frame is unknown (that is, if the function
12629or block corresponding to the frame was defined in a source file that
12630does not have a recognized extension), the current working language is
12631not changed, and @value{GDBN} issues a warning.
12632
12633This may not seem necessary for most programs, which are written
12634entirely in one source language. However, program modules and libraries
12635written in one source language can be used by a main program written in
12636a different source language. Using @samp{set language auto} in this
12637case frees you from having to set the working language manually.
12638
6d2ebf8b 12639@node Show
79a6e687 12640@section Displaying the Language
c906108c
SS
12641
12642The following commands help you find out which language is the
12643working language, and also what language source files were written in.
12644
c906108c
SS
12645@table @code
12646@item show language
9c16f35a 12647@kindex show language
c906108c
SS
12648Display the current working language. This is the
12649language you can use with commands such as @code{print} to
12650build and compute expressions that may involve variables in your program.
12651
12652@item info frame
4644b6e3 12653@kindex info frame@r{, show the source language}
5d161b24 12654Display the source language for this frame. This language becomes the
c906108c 12655working language if you use an identifier from this frame.
79a6e687 12656@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
12657information listed here.
12658
12659@item info source
4644b6e3 12660@kindex info source@r{, show the source language}
c906108c 12661Display the source language of this source file.
5d161b24 12662@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
12663information listed here.
12664@end table
12665
12666In unusual circumstances, you may have source files with extensions
12667not in the standard list. You can then set the extension associated
12668with a language explicitly:
12669
c906108c 12670@table @code
09d4efe1 12671@item set extension-language @var{ext} @var{language}
9c16f35a 12672@kindex set extension-language
09d4efe1
EZ
12673Tell @value{GDBN} that source files with extension @var{ext} are to be
12674assumed as written in the source language @var{language}.
c906108c
SS
12675
12676@item info extensions
9c16f35a 12677@kindex info extensions
c906108c
SS
12678List all the filename extensions and the associated languages.
12679@end table
12680
6d2ebf8b 12681@node Checks
79a6e687 12682@section Type and Range Checking
c906108c 12683
c906108c
SS
12684Some languages are designed to guard you against making seemingly common
12685errors through a series of compile- and run-time checks. These include
a451cb65 12686checking the type of arguments to functions and operators and making
c906108c
SS
12687sure mathematical overflows are caught at run time. Checks such as
12688these help to ensure a program's correctness once it has been compiled
a451cb65 12689by eliminating type mismatches and providing active checks for range
c906108c
SS
12690errors when your program is running.
12691
a451cb65
KS
12692By default @value{GDBN} checks for these errors according to the
12693rules of the current source language. Although @value{GDBN} does not check
12694the statements in your program, it can check expressions entered directly
12695into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
12696
12697@menu
12698* Type Checking:: An overview of type checking
12699* Range Checking:: An overview of range checking
12700@end menu
12701
12702@cindex type checking
12703@cindex checks, type
6d2ebf8b 12704@node Type Checking
79a6e687 12705@subsection An Overview of Type Checking
c906108c 12706
a451cb65 12707Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
12708arguments to operators and functions have to be of the correct type,
12709otherwise an error occurs. These checks prevent type mismatch
12710errors from ever causing any run-time problems. For example,
12711
12712@smallexample
a451cb65
KS
12713int klass::my_method(char *b) @{ return b ? 1 : 2; @}
12714
12715(@value{GDBP}) print obj.my_method (0)
12716$1 = 2
c906108c 12717@exdent but
a451cb65
KS
12718(@value{GDBP}) print obj.my_method (0x1234)
12719Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
12720@end smallexample
12721
a451cb65
KS
12722The second example fails because in C@t{++} the integer constant
12723@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 12724
a451cb65
KS
12725For the expressions you use in @value{GDBN} commands, you can tell
12726@value{GDBN} to not enforce strict type checking or
5d161b24 12727to treat any mismatches as errors and abandon the expression;
a451cb65
KS
12728When type checking is disabled, @value{GDBN} successfully evaluates
12729expressions like the second example above.
c906108c 12730
a451cb65 12731Even if type checking is off, there may be other reasons
5d161b24
DB
12732related to type that prevent @value{GDBN} from evaluating an expression.
12733For instance, @value{GDBN} does not know how to add an @code{int} and
12734a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
12735with the language in use and usually arise from expressions which make
12736little sense to evaluate anyway.
c906108c 12737
a451cb65 12738@value{GDBN} provides some additional commands for controlling type checking:
c906108c 12739
c906108c
SS
12740@kindex set check type
12741@kindex show check type
12742@table @code
c906108c
SS
12743@item set check type on
12744@itemx set check type off
a451cb65 12745Set strict type checking on or off. If any type mismatches occur in
d4f3574e 12746evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
12747message and aborts evaluation of the expression.
12748
a451cb65
KS
12749@item show check type
12750Show the current setting of type checking and whether @value{GDBN}
12751is enforcing strict type checking rules.
c906108c
SS
12752@end table
12753
12754@cindex range checking
12755@cindex checks, range
6d2ebf8b 12756@node Range Checking
79a6e687 12757@subsection An Overview of Range Checking
c906108c
SS
12758
12759In some languages (such as Modula-2), it is an error to exceed the
12760bounds of a type; this is enforced with run-time checks. Such range
12761checking is meant to ensure program correctness by making sure
12762computations do not overflow, or indices on an array element access do
12763not exceed the bounds of the array.
12764
12765For expressions you use in @value{GDBN} commands, you can tell
12766@value{GDBN} to treat range errors in one of three ways: ignore them,
12767always treat them as errors and abandon the expression, or issue
12768warnings but evaluate the expression anyway.
12769
12770A range error can result from numerical overflow, from exceeding an
12771array index bound, or when you type a constant that is not a member
12772of any type. Some languages, however, do not treat overflows as an
12773error. In many implementations of C, mathematical overflow causes the
12774result to ``wrap around'' to lower values---for example, if @var{m} is
12775the largest integer value, and @var{s} is the smallest, then
12776
474c8240 12777@smallexample
c906108c 12778@var{m} + 1 @result{} @var{s}
474c8240 12779@end smallexample
c906108c
SS
12780
12781This, too, is specific to individual languages, and in some cases
79a6e687
BW
12782specific to individual compilers or machines. @xref{Supported Languages, ,
12783Supported Languages}, for further details on specific languages.
c906108c
SS
12784
12785@value{GDBN} provides some additional commands for controlling the range checker:
12786
c906108c
SS
12787@kindex set check range
12788@kindex show check range
12789@table @code
12790@item set check range auto
12791Set range checking on or off based on the current working language.
79a6e687 12792@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
12793each language.
12794
12795@item set check range on
12796@itemx set check range off
12797Set range checking on or off, overriding the default setting for the
12798current working language. A warning is issued if the setting does not
c3f6f71d
JM
12799match the language default. If a range error occurs and range checking is on,
12800then a message is printed and evaluation of the expression is aborted.
c906108c
SS
12801
12802@item set check range warn
12803Output messages when the @value{GDBN} range checker detects a range error,
12804but attempt to evaluate the expression anyway. Evaluating the
12805expression may still be impossible for other reasons, such as accessing
12806memory that the process does not own (a typical example from many Unix
12807systems).
12808
12809@item show range
12810Show the current setting of the range checker, and whether or not it is
12811being set automatically by @value{GDBN}.
12812@end table
c906108c 12813
79a6e687
BW
12814@node Supported Languages
12815@section Supported Languages
c906108c 12816
a766d390
DE
12817@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
12818OpenCL C, Pascal, assembly, Modula-2, and Ada.
cce74817 12819@c This is false ...
c906108c
SS
12820Some @value{GDBN} features may be used in expressions regardless of the
12821language you use: the @value{GDBN} @code{@@} and @code{::} operators,
12822and the @samp{@{type@}addr} construct (@pxref{Expressions,
12823,Expressions}) can be used with the constructs of any supported
12824language.
12825
12826The following sections detail to what degree each source language is
12827supported by @value{GDBN}. These sections are not meant to be language
12828tutorials or references, but serve only as a reference guide to what the
12829@value{GDBN} expression parser accepts, and what input and output
12830formats should look like for different languages. There are many good
12831books written on each of these languages; please look to these for a
12832language reference or tutorial.
12833
c906108c 12834@menu
b37303ee 12835* C:: C and C@t{++}
6aecb9c2 12836* D:: D
a766d390 12837* Go:: Go
b383017d 12838* Objective-C:: Objective-C
f4b8a18d 12839* OpenCL C:: OpenCL C
09d4efe1 12840* Fortran:: Fortran
9c16f35a 12841* Pascal:: Pascal
b37303ee 12842* Modula-2:: Modula-2
e07c999f 12843* Ada:: Ada
c906108c
SS
12844@end menu
12845
6d2ebf8b 12846@node C
b37052ae 12847@subsection C and C@t{++}
7a292a7a 12848
b37052ae
EZ
12849@cindex C and C@t{++}
12850@cindex expressions in C or C@t{++}
c906108c 12851
b37052ae 12852Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
12853to both languages. Whenever this is the case, we discuss those languages
12854together.
12855
41afff9a
EZ
12856@cindex C@t{++}
12857@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
12858@cindex @sc{gnu} C@t{++}
12859The C@t{++} debugging facilities are jointly implemented by the C@t{++}
12860compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
12861effectively, you must compile your C@t{++} programs with a supported
12862C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
12863compiler (@code{aCC}).
12864
c906108c 12865@menu
b37052ae
EZ
12866* C Operators:: C and C@t{++} operators
12867* C Constants:: C and C@t{++} constants
79a6e687 12868* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
12869* C Defaults:: Default settings for C and C@t{++}
12870* C Checks:: C and C@t{++} type and range checks
c906108c 12871* Debugging C:: @value{GDBN} and C
79a6e687 12872* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 12873* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 12874@end menu
c906108c 12875
6d2ebf8b 12876@node C Operators
79a6e687 12877@subsubsection C and C@t{++} Operators
7a292a7a 12878
b37052ae 12879@cindex C and C@t{++} operators
c906108c
SS
12880
12881Operators must be defined on values of specific types. For instance,
12882@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 12883often defined on groups of types.
c906108c 12884
b37052ae 12885For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
12886
12887@itemize @bullet
53a5351d 12888
c906108c 12889@item
c906108c 12890@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 12891specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
12892
12893@item
d4f3574e
SS
12894@emph{Floating-point types} include @code{float}, @code{double}, and
12895@code{long double} (if supported by the target platform).
c906108c
SS
12896
12897@item
53a5351d 12898@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
12899
12900@item
12901@emph{Scalar types} include all of the above.
53a5351d 12902
c906108c
SS
12903@end itemize
12904
12905@noindent
12906The following operators are supported. They are listed here
12907in order of increasing precedence:
12908
12909@table @code
12910@item ,
12911The comma or sequencing operator. Expressions in a comma-separated list
12912are evaluated from left to right, with the result of the entire
12913expression being the last expression evaluated.
12914
12915@item =
12916Assignment. The value of an assignment expression is the value
12917assigned. Defined on scalar types.
12918
12919@item @var{op}=
12920Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
12921and translated to @w{@code{@var{a} = @var{a op b}}}.
d4f3574e 12922@w{@code{@var{op}=}} and @code{=} have the same precedence.
c906108c
SS
12923@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
12924@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
12925
12926@item ?:
12927The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
12928of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
12929integral type.
12930
12931@item ||
12932Logical @sc{or}. Defined on integral types.
12933
12934@item &&
12935Logical @sc{and}. Defined on integral types.
12936
12937@item |
12938Bitwise @sc{or}. Defined on integral types.
12939
12940@item ^
12941Bitwise exclusive-@sc{or}. Defined on integral types.
12942
12943@item &
12944Bitwise @sc{and}. Defined on integral types.
12945
12946@item ==@r{, }!=
12947Equality and inequality. Defined on scalar types. The value of these
12948expressions is 0 for false and non-zero for true.
12949
12950@item <@r{, }>@r{, }<=@r{, }>=
12951Less than, greater than, less than or equal, greater than or equal.
12952Defined on scalar types. The value of these expressions is 0 for false
12953and non-zero for true.
12954
12955@item <<@r{, }>>
12956left shift, and right shift. Defined on integral types.
12957
12958@item @@
12959The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
12960
12961@item +@r{, }-
12962Addition and subtraction. Defined on integral types, floating-point types and
12963pointer types.
12964
12965@item *@r{, }/@r{, }%
12966Multiplication, division, and modulus. Multiplication and division are
12967defined on integral and floating-point types. Modulus is defined on
12968integral types.
12969
12970@item ++@r{, }--
12971Increment and decrement. When appearing before a variable, the
12972operation is performed before the variable is used in an expression;
12973when appearing after it, the variable's value is used before the
12974operation takes place.
12975
12976@item *
12977Pointer dereferencing. Defined on pointer types. Same precedence as
12978@code{++}.
12979
12980@item &
12981Address operator. Defined on variables. Same precedence as @code{++}.
12982
b37052ae
EZ
12983For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
12984allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 12985to examine the address
b37052ae 12986where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 12987stored.
c906108c
SS
12988
12989@item -
12990Negative. Defined on integral and floating-point types. Same
12991precedence as @code{++}.
12992
12993@item !
12994Logical negation. Defined on integral types. Same precedence as
12995@code{++}.
12996
12997@item ~
12998Bitwise complement operator. Defined on integral types. Same precedence as
12999@code{++}.
13000
13001
13002@item .@r{, }->
13003Structure member, and pointer-to-structure member. For convenience,
13004@value{GDBN} regards the two as equivalent, choosing whether to dereference a
13005pointer based on the stored type information.
13006Defined on @code{struct} and @code{union} data.
13007
c906108c
SS
13008@item .*@r{, }->*
13009Dereferences of pointers to members.
c906108c
SS
13010
13011@item []
13012Array indexing. @code{@var{a}[@var{i}]} is defined as
13013@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
13014
13015@item ()
13016Function parameter list. Same precedence as @code{->}.
13017
c906108c 13018@item ::
b37052ae 13019C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 13020and @code{class} types.
c906108c
SS
13021
13022@item ::
7a292a7a
SS
13023Doubled colons also represent the @value{GDBN} scope operator
13024(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
13025above.
c906108c
SS
13026@end table
13027
c906108c
SS
13028If an operator is redefined in the user code, @value{GDBN} usually
13029attempts to invoke the redefined version instead of using the operator's
13030predefined meaning.
c906108c 13031
6d2ebf8b 13032@node C Constants
79a6e687 13033@subsubsection C and C@t{++} Constants
c906108c 13034
b37052ae 13035@cindex C and C@t{++} constants
c906108c 13036
b37052ae 13037@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 13038following ways:
c906108c
SS
13039
13040@itemize @bullet
13041@item
13042Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
13043specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
13044by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
13045@samp{l}, specifying that the constant should be treated as a
13046@code{long} value.
13047
13048@item
13049Floating point constants are a sequence of digits, followed by a decimal
13050point, followed by a sequence of digits, and optionally followed by an
13051exponent. An exponent is of the form:
13052@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
13053sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
13054A floating-point constant may also end with a letter @samp{f} or
13055@samp{F}, specifying that the constant should be treated as being of
13056the @code{float} (as opposed to the default @code{double}) type; or with
13057a letter @samp{l} or @samp{L}, which specifies a @code{long double}
13058constant.
c906108c
SS
13059
13060@item
13061Enumerated constants consist of enumerated identifiers, or their
13062integral equivalents.
13063
13064@item
13065Character constants are a single character surrounded by single quotes
13066(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 13067(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
13068be represented by a letter or by @dfn{escape sequences}, which are of
13069the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
13070of the character's ordinal value; or of the form @samp{\@var{x}}, where
13071@samp{@var{x}} is a predefined special character---for example,
13072@samp{\n} for newline.
13073
e0f8f636
TT
13074Wide character constants can be written by prefixing a character
13075constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
13076form of @samp{x}. The target wide character set is used when
13077computing the value of this constant (@pxref{Character Sets}).
13078
c906108c 13079@item
96a2c332
SS
13080String constants are a sequence of character constants surrounded by
13081double quotes (@code{"}). Any valid character constant (as described
13082above) may appear. Double quotes within the string must be preceded by
13083a backslash, so for instance @samp{"a\"b'c"} is a string of five
13084characters.
c906108c 13085
e0f8f636
TT
13086Wide string constants can be written by prefixing a string constant
13087with @samp{L}, as in C. The target wide character set is used when
13088computing the value of this constant (@pxref{Character Sets}).
13089
c906108c
SS
13090@item
13091Pointer constants are an integral value. You can also write pointers
13092to constants using the C operator @samp{&}.
13093
13094@item
13095Array constants are comma-separated lists surrounded by braces @samp{@{}
13096and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
13097integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
13098and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
13099@end itemize
13100
79a6e687
BW
13101@node C Plus Plus Expressions
13102@subsubsection C@t{++} Expressions
b37052ae
EZ
13103
13104@cindex expressions in C@t{++}
13105@value{GDBN} expression handling can interpret most C@t{++} expressions.
13106
0179ffac
DC
13107@cindex debugging C@t{++} programs
13108@cindex C@t{++} compilers
13109@cindex debug formats and C@t{++}
13110@cindex @value{NGCC} and C@t{++}
c906108c 13111@quotation
e0f8f636
TT
13112@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
13113the proper compiler and the proper debug format. Currently,
13114@value{GDBN} works best when debugging C@t{++} code that is compiled
13115with the most recent version of @value{NGCC} possible. The DWARF
13116debugging format is preferred; @value{NGCC} defaults to this on most
13117popular platforms. Other compilers and/or debug formats are likely to
13118work badly or not at all when using @value{GDBN} to debug C@t{++}
13119code. @xref{Compilation}.
c906108c 13120@end quotation
c906108c
SS
13121
13122@enumerate
13123
13124@cindex member functions
13125@item
13126Member function calls are allowed; you can use expressions like
13127
474c8240 13128@smallexample
c906108c 13129count = aml->GetOriginal(x, y)
474c8240 13130@end smallexample
c906108c 13131
41afff9a 13132@vindex this@r{, inside C@t{++} member functions}
b37052ae 13133@cindex namespace in C@t{++}
c906108c
SS
13134@item
13135While a member function is active (in the selected stack frame), your
13136expressions have the same namespace available as the member function;
13137that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
13138pointer @code{this} following the same rules as C@t{++}. @code{using}
13139declarations in the current scope are also respected by @value{GDBN}.
c906108c 13140
c906108c 13141@cindex call overloaded functions
d4f3574e 13142@cindex overloaded functions, calling
b37052ae 13143@cindex type conversions in C@t{++}
c906108c
SS
13144@item
13145You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 13146call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
13147perform overload resolution involving user-defined type conversions,
13148calls to constructors, or instantiations of templates that do not exist
13149in the program. It also cannot handle ellipsis argument lists or
13150default arguments.
13151
13152It does perform integral conversions and promotions, floating-point
13153promotions, arithmetic conversions, pointer conversions, conversions of
13154class objects to base classes, and standard conversions such as those of
13155functions or arrays to pointers; it requires an exact match on the
13156number of function arguments.
13157
13158Overload resolution is always performed, unless you have specified
79a6e687
BW
13159@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
13160,@value{GDBN} Features for C@t{++}}.
c906108c 13161
d4f3574e 13162You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
13163explicit function signature to call an overloaded function, as in
13164@smallexample
13165p 'foo(char,int)'('x', 13)
13166@end smallexample
d4f3574e 13167
c906108c 13168The @value{GDBN} command-completion facility can simplify this;
79a6e687 13169see @ref{Completion, ,Command Completion}.
c906108c 13170
c906108c
SS
13171@cindex reference declarations
13172@item
b37052ae
EZ
13173@value{GDBN} understands variables declared as C@t{++} references; you can use
13174them in expressions just as you do in C@t{++} source---they are automatically
c906108c
SS
13175dereferenced.
13176
13177In the parameter list shown when @value{GDBN} displays a frame, the values of
13178reference variables are not displayed (unlike other variables); this
13179avoids clutter, since references are often used for large structures.
13180The @emph{address} of a reference variable is always shown, unless
13181you have specified @samp{set print address off}.
13182
13183@item
b37052ae 13184@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
13185expressions can use it just as expressions in your program do. Since
13186one scope may be defined in another, you can use @code{::} repeatedly if
13187necessary, for example in an expression like
13188@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 13189resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 13190debugging (@pxref{Variables, ,Program Variables}).
c906108c 13191
e0f8f636
TT
13192@item
13193@value{GDBN} performs argument-dependent lookup, following the C@t{++}
13194specification.
13195@end enumerate
c906108c 13196
6d2ebf8b 13197@node C Defaults
79a6e687 13198@subsubsection C and C@t{++} Defaults
7a292a7a 13199
b37052ae 13200@cindex C and C@t{++} defaults
c906108c 13201
a451cb65
KS
13202If you allow @value{GDBN} to set range checking automatically, it
13203defaults to @code{off} whenever the working language changes to
b37052ae 13204C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 13205selects the working language.
c906108c
SS
13206
13207If you allow @value{GDBN} to set the language automatically, it
13208recognizes source files whose names end with @file{.c}, @file{.C}, or
13209@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 13210these files, it sets the working language to C or C@t{++}.
79a6e687 13211@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
13212for further details.
13213
6d2ebf8b 13214@node C Checks
79a6e687 13215@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 13216
b37052ae 13217@cindex C and C@t{++} checks
c906108c 13218
a451cb65
KS
13219By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
13220checking is used. However, if you turn type checking off, @value{GDBN}
13221will allow certain non-standard conversions, such as promoting integer
13222constants to pointers.
c906108c
SS
13223
13224Range checking, if turned on, is done on mathematical operations. Array
13225indices are not checked, since they are often used to index a pointer
13226that is not itself an array.
c906108c 13227
6d2ebf8b 13228@node Debugging C
c906108c 13229@subsubsection @value{GDBN} and C
c906108c
SS
13230
13231The @code{set print union} and @code{show print union} commands apply to
13232the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
13233inside a @code{struct} or @code{class} is also printed. Otherwise, it
13234appears as @samp{@{...@}}.
c906108c
SS
13235
13236The @code{@@} operator aids in the debugging of dynamic arrays, formed
13237with pointers and a memory allocation function. @xref{Expressions,
13238,Expressions}.
13239
79a6e687
BW
13240@node Debugging C Plus Plus
13241@subsubsection @value{GDBN} Features for C@t{++}
c906108c 13242
b37052ae 13243@cindex commands for C@t{++}
7a292a7a 13244
b37052ae
EZ
13245Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
13246designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
13247
13248@table @code
13249@cindex break in overloaded functions
13250@item @r{breakpoint menus}
13251When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
13252@value{GDBN} has the capability to display a menu of possible breakpoint
13253locations to help you specify which function definition you want.
13254@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 13255
b37052ae 13256@cindex overloading in C@t{++}
c906108c
SS
13257@item rbreak @var{regex}
13258Setting breakpoints using regular expressions is helpful for setting
13259breakpoints on overloaded functions that are not members of any special
13260classes.
79a6e687 13261@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 13262
b37052ae 13263@cindex C@t{++} exception handling
c906108c
SS
13264@item catch throw
13265@itemx catch catch
b37052ae 13266Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 13267Catchpoints, , Setting Catchpoints}.
c906108c
SS
13268
13269@cindex inheritance
13270@item ptype @var{typename}
13271Print inheritance relationships as well as other information for type
13272@var{typename}.
13273@xref{Symbols, ,Examining the Symbol Table}.
13274
c4aeac85
TT
13275@item info vtbl @var{expression}.
13276The @code{info vtbl} command can be used to display the virtual
13277method tables of the object computed by @var{expression}. This shows
13278one entry per virtual table; there may be multiple virtual tables when
13279multiple inheritance is in use.
13280
b37052ae 13281@cindex C@t{++} symbol display
c906108c
SS
13282@item set print demangle
13283@itemx show print demangle
13284@itemx set print asm-demangle
13285@itemx show print asm-demangle
b37052ae
EZ
13286Control whether C@t{++} symbols display in their source form, both when
13287displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 13288@xref{Print Settings, ,Print Settings}.
c906108c
SS
13289
13290@item set print object
13291@itemx show print object
13292Choose whether to print derived (actual) or declared types of objects.
79a6e687 13293@xref{Print Settings, ,Print Settings}.
c906108c
SS
13294
13295@item set print vtbl
13296@itemx show print vtbl
13297Control the format for printing virtual function tables.
79a6e687 13298@xref{Print Settings, ,Print Settings}.
c906108c 13299(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 13300ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
13301
13302@kindex set overload-resolution
d4f3574e 13303@cindex overloaded functions, overload resolution
c906108c 13304@item set overload-resolution on
b37052ae 13305Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
13306is on. For overloaded functions, @value{GDBN} evaluates the arguments
13307and searches for a function whose signature matches the argument types,
79a6e687
BW
13308using the standard C@t{++} conversion rules (see @ref{C Plus Plus
13309Expressions, ,C@t{++} Expressions}, for details).
13310If it cannot find a match, it emits a message.
c906108c
SS
13311
13312@item set overload-resolution off
b37052ae 13313Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
13314overloaded functions that are not class member functions, @value{GDBN}
13315chooses the first function of the specified name that it finds in the
13316symbol table, whether or not its arguments are of the correct type. For
13317overloaded functions that are class member functions, @value{GDBN}
13318searches for a function whose signature @emph{exactly} matches the
13319argument types.
c906108c 13320
9c16f35a
EZ
13321@kindex show overload-resolution
13322@item show overload-resolution
13323Show the current setting of overload resolution.
13324
c906108c
SS
13325@item @r{Overloaded symbol names}
13326You can specify a particular definition of an overloaded symbol, using
b37052ae 13327the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
13328@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
13329also use the @value{GDBN} command-line word completion facilities to list the
13330available choices, or to finish the type list for you.
79a6e687 13331@xref{Completion,, Command Completion}, for details on how to do this.
c906108c 13332@end table
c906108c 13333
febe4383
TJB
13334@node Decimal Floating Point
13335@subsubsection Decimal Floating Point format
13336@cindex decimal floating point format
13337
13338@value{GDBN} can examine, set and perform computations with numbers in
13339decimal floating point format, which in the C language correspond to the
13340@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
13341specified by the extension to support decimal floating-point arithmetic.
13342
13343There are two encodings in use, depending on the architecture: BID (Binary
13344Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
99e008fe 13345PowerPC. @value{GDBN} will use the appropriate encoding for the configured
febe4383
TJB
13346target.
13347
13348Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
13349to manipulate decimal floating point numbers, it is not possible to convert
13350(using a cast, for example) integers wider than 32-bit to decimal float.
13351
13352In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
13353point computations, error checking in decimal float operations ignores
13354underflow, overflow and divide by zero exceptions.
13355
4acd40f3 13356In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
13357to inspect @code{_Decimal128} values stored in floating point registers.
13358See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 13359
6aecb9c2
JB
13360@node D
13361@subsection D
13362
13363@cindex D
13364@value{GDBN} can be used to debug programs written in D and compiled with
13365GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
13366specific feature --- dynamic arrays.
13367
a766d390
DE
13368@node Go
13369@subsection Go
13370
13371@cindex Go (programming language)
13372@value{GDBN} can be used to debug programs written in Go and compiled with
13373@file{gccgo} or @file{6g} compilers.
13374
13375Here is a summary of the Go-specific features and restrictions:
13376
13377@table @code
13378@cindex current Go package
13379@item The current Go package
13380The name of the current package does not need to be specified when
13381specifying global variables and functions.
13382
13383For example, given the program:
13384
13385@example
13386package main
13387var myglob = "Shall we?"
13388func main () @{
13389 // ...
13390@}
13391@end example
13392
13393When stopped inside @code{main} either of these work:
13394
13395@example
13396(gdb) p myglob
13397(gdb) p main.myglob
13398@end example
13399
13400@cindex builtin Go types
13401@item Builtin Go types
13402The @code{string} type is recognized by @value{GDBN} and is printed
13403as a string.
13404
13405@cindex builtin Go functions
13406@item Builtin Go functions
13407The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
13408function and handles it internally.
a766d390
DE
13409
13410@cindex restrictions on Go expressions
13411@item Restrictions on Go expressions
13412All Go operators are supported except @code{&^}.
13413The Go @code{_} ``blank identifier'' is not supported.
13414Automatic dereferencing of pointers is not supported.
50f042b9 13415@end table
a766d390 13416
b37303ee
AF
13417@node Objective-C
13418@subsection Objective-C
13419
13420@cindex Objective-C
13421This section provides information about some commands and command
721c2651
EZ
13422options that are useful for debugging Objective-C code. See also
13423@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
13424few more commands specific to Objective-C support.
b37303ee
AF
13425
13426@menu
b383017d
RM
13427* Method Names in Commands::
13428* The Print Command with Objective-C::
b37303ee
AF
13429@end menu
13430
c8f4133a 13431@node Method Names in Commands
b37303ee
AF
13432@subsubsection Method Names in Commands
13433
13434The following commands have been extended to accept Objective-C method
13435names as line specifications:
13436
13437@kindex clear@r{, and Objective-C}
13438@kindex break@r{, and Objective-C}
13439@kindex info line@r{, and Objective-C}
13440@kindex jump@r{, and Objective-C}
13441@kindex list@r{, and Objective-C}
13442@itemize
13443@item @code{clear}
13444@item @code{break}
13445@item @code{info line}
13446@item @code{jump}
13447@item @code{list}
13448@end itemize
13449
13450A fully qualified Objective-C method name is specified as
13451
13452@smallexample
13453-[@var{Class} @var{methodName}]
13454@end smallexample
13455
c552b3bb
JM
13456where the minus sign is used to indicate an instance method and a
13457plus sign (not shown) is used to indicate a class method. The class
13458name @var{Class} and method name @var{methodName} are enclosed in
13459brackets, similar to the way messages are specified in Objective-C
13460source code. For example, to set a breakpoint at the @code{create}
13461instance method of class @code{Fruit} in the program currently being
13462debugged, enter:
b37303ee
AF
13463
13464@smallexample
13465break -[Fruit create]
13466@end smallexample
13467
13468To list ten program lines around the @code{initialize} class method,
13469enter:
13470
13471@smallexample
13472list +[NSText initialize]
13473@end smallexample
13474
c552b3bb
JM
13475In the current version of @value{GDBN}, the plus or minus sign is
13476required. In future versions of @value{GDBN}, the plus or minus
13477sign will be optional, but you can use it to narrow the search. It
13478is also possible to specify just a method name:
b37303ee
AF
13479
13480@smallexample
13481break create
13482@end smallexample
13483
13484You must specify the complete method name, including any colons. If
13485your program's source files contain more than one @code{create} method,
13486you'll be presented with a numbered list of classes that implement that
13487method. Indicate your choice by number, or type @samp{0} to exit if
13488none apply.
13489
13490As another example, to clear a breakpoint established at the
13491@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
13492
13493@smallexample
13494clear -[NSWindow makeKeyAndOrderFront:]
13495@end smallexample
13496
13497@node The Print Command with Objective-C
13498@subsubsection The Print Command With Objective-C
721c2651 13499@cindex Objective-C, print objects
c552b3bb
JM
13500@kindex print-object
13501@kindex po @r{(@code{print-object})}
b37303ee 13502
c552b3bb 13503The print command has also been extended to accept methods. For example:
b37303ee
AF
13504
13505@smallexample
c552b3bb 13506print -[@var{object} hash]
b37303ee
AF
13507@end smallexample
13508
13509@cindex print an Objective-C object description
c552b3bb
JM
13510@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
13511@noindent
13512will tell @value{GDBN} to send the @code{hash} message to @var{object}
13513and print the result. Also, an additional command has been added,
13514@code{print-object} or @code{po} for short, which is meant to print
13515the description of an object. However, this command may only work
13516with certain Objective-C libraries that have a particular hook
13517function, @code{_NSPrintForDebugger}, defined.
b37303ee 13518
f4b8a18d
KW
13519@node OpenCL C
13520@subsection OpenCL C
13521
13522@cindex OpenCL C
13523This section provides information about @value{GDBN}s OpenCL C support.
13524
13525@menu
13526* OpenCL C Datatypes::
13527* OpenCL C Expressions::
13528* OpenCL C Operators::
13529@end menu
13530
13531@node OpenCL C Datatypes
13532@subsubsection OpenCL C Datatypes
13533
13534@cindex OpenCL C Datatypes
13535@value{GDBN} supports the builtin scalar and vector datatypes specified
13536by OpenCL 1.1. In addition the half- and double-precision floating point
13537data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
13538extensions are also known to @value{GDBN}.
13539
13540@node OpenCL C Expressions
13541@subsubsection OpenCL C Expressions
13542
13543@cindex OpenCL C Expressions
13544@value{GDBN} supports accesses to vector components including the access as
13545lvalue where possible. Since OpenCL C is based on C99 most C expressions
13546supported by @value{GDBN} can be used as well.
13547
13548@node OpenCL C Operators
13549@subsubsection OpenCL C Operators
13550
13551@cindex OpenCL C Operators
13552@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
13553vector data types.
13554
09d4efe1
EZ
13555@node Fortran
13556@subsection Fortran
13557@cindex Fortran-specific support in @value{GDBN}
13558
814e32d7
WZ
13559@value{GDBN} can be used to debug programs written in Fortran, but it
13560currently supports only the features of Fortran 77 language.
13561
13562@cindex trailing underscore, in Fortran symbols
13563Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
13564among them) append an underscore to the names of variables and
13565functions. When you debug programs compiled by those compilers, you
13566will need to refer to variables and functions with a trailing
13567underscore.
13568
13569@menu
13570* Fortran Operators:: Fortran operators and expressions
13571* Fortran Defaults:: Default settings for Fortran
79a6e687 13572* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
13573@end menu
13574
13575@node Fortran Operators
79a6e687 13576@subsubsection Fortran Operators and Expressions
814e32d7
WZ
13577
13578@cindex Fortran operators and expressions
13579
13580Operators must be defined on values of specific types. For instance,
13581@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 13582arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
13583
13584@table @code
13585@item **
99e008fe 13586The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
13587of the second one.
13588
13589@item :
13590The range operator. Normally used in the form of array(low:high) to
13591represent a section of array.
68837c9d
MD
13592
13593@item %
13594The access component operator. Normally used to access elements in derived
13595types. Also suitable for unions. As unions aren't part of regular Fortran,
13596this can only happen when accessing a register that uses a gdbarch-defined
13597union type.
814e32d7
WZ
13598@end table
13599
13600@node Fortran Defaults
13601@subsubsection Fortran Defaults
13602
13603@cindex Fortran Defaults
13604
13605Fortran symbols are usually case-insensitive, so @value{GDBN} by
13606default uses case-insensitive matches for Fortran symbols. You can
13607change that with the @samp{set case-insensitive} command, see
13608@ref{Symbols}, for the details.
13609
79a6e687
BW
13610@node Special Fortran Commands
13611@subsubsection Special Fortran Commands
814e32d7
WZ
13612
13613@cindex Special Fortran commands
13614
db2e3e2e
BW
13615@value{GDBN} has some commands to support Fortran-specific features,
13616such as displaying common blocks.
814e32d7 13617
09d4efe1
EZ
13618@table @code
13619@cindex @code{COMMON} blocks, Fortran
13620@kindex info common
13621@item info common @r{[}@var{common-name}@r{]}
13622This command prints the values contained in the Fortran @code{COMMON}
13623block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 13624all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
13625printed.
13626@end table
13627
9c16f35a
EZ
13628@node Pascal
13629@subsection Pascal
13630
13631@cindex Pascal support in @value{GDBN}, limitations
13632Debugging Pascal programs which use sets, subranges, file variables, or
13633nested functions does not currently work. @value{GDBN} does not support
13634entering expressions, printing values, or similar features using Pascal
13635syntax.
13636
13637The Pascal-specific command @code{set print pascal_static-members}
13638controls whether static members of Pascal objects are displayed.
13639@xref{Print Settings, pascal_static-members}.
13640
09d4efe1 13641@node Modula-2
c906108c 13642@subsection Modula-2
7a292a7a 13643
d4f3574e 13644@cindex Modula-2, @value{GDBN} support
c906108c
SS
13645
13646The extensions made to @value{GDBN} to support Modula-2 only support
13647output from the @sc{gnu} Modula-2 compiler (which is currently being
13648developed). Other Modula-2 compilers are not currently supported, and
13649attempting to debug executables produced by them is most likely
13650to give an error as @value{GDBN} reads in the executable's symbol
13651table.
13652
13653@cindex expressions in Modula-2
13654@menu
13655* M2 Operators:: Built-in operators
13656* Built-In Func/Proc:: Built-in functions and procedures
13657* M2 Constants:: Modula-2 constants
72019c9c 13658* M2 Types:: Modula-2 types
c906108c
SS
13659* M2 Defaults:: Default settings for Modula-2
13660* Deviations:: Deviations from standard Modula-2
13661* M2 Checks:: Modula-2 type and range checks
13662* M2 Scope:: The scope operators @code{::} and @code{.}
13663* GDB/M2:: @value{GDBN} and Modula-2
13664@end menu
13665
6d2ebf8b 13666@node M2 Operators
c906108c
SS
13667@subsubsection Operators
13668@cindex Modula-2 operators
13669
13670Operators must be defined on values of specific types. For instance,
13671@code{+} is defined on numbers, but not on structures. Operators are
13672often defined on groups of types. For the purposes of Modula-2, the
13673following definitions hold:
13674
13675@itemize @bullet
13676
13677@item
13678@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
13679their subranges.
13680
13681@item
13682@emph{Character types} consist of @code{CHAR} and its subranges.
13683
13684@item
13685@emph{Floating-point types} consist of @code{REAL}.
13686
13687@item
13688@emph{Pointer types} consist of anything declared as @code{POINTER TO
13689@var{type}}.
13690
13691@item
13692@emph{Scalar types} consist of all of the above.
13693
13694@item
13695@emph{Set types} consist of @code{SET} and @code{BITSET} types.
13696
13697@item
13698@emph{Boolean types} consist of @code{BOOLEAN}.
13699@end itemize
13700
13701@noindent
13702The following operators are supported, and appear in order of
13703increasing precedence:
13704
13705@table @code
13706@item ,
13707Function argument or array index separator.
13708
13709@item :=
13710Assignment. The value of @var{var} @code{:=} @var{value} is
13711@var{value}.
13712
13713@item <@r{, }>
13714Less than, greater than on integral, floating-point, or enumerated
13715types.
13716
13717@item <=@r{, }>=
96a2c332 13718Less than or equal to, greater than or equal to
c906108c
SS
13719on integral, floating-point and enumerated types, or set inclusion on
13720set types. Same precedence as @code{<}.
13721
13722@item =@r{, }<>@r{, }#
13723Equality and two ways of expressing inequality, valid on scalar types.
13724Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
13725available for inequality, since @code{#} conflicts with the script
13726comment character.
13727
13728@item IN
13729Set membership. Defined on set types and the types of their members.
13730Same precedence as @code{<}.
13731
13732@item OR
13733Boolean disjunction. Defined on boolean types.
13734
13735@item AND@r{, }&
d4f3574e 13736Boolean conjunction. Defined on boolean types.
c906108c
SS
13737
13738@item @@
13739The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13740
13741@item +@r{, }-
13742Addition and subtraction on integral and floating-point types, or union
13743and difference on set types.
13744
13745@item *
13746Multiplication on integral and floating-point types, or set intersection
13747on set types.
13748
13749@item /
13750Division on floating-point types, or symmetric set difference on set
13751types. Same precedence as @code{*}.
13752
13753@item DIV@r{, }MOD
13754Integer division and remainder. Defined on integral types. Same
13755precedence as @code{*}.
13756
13757@item -
99e008fe 13758Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
13759
13760@item ^
13761Pointer dereferencing. Defined on pointer types.
13762
13763@item NOT
13764Boolean negation. Defined on boolean types. Same precedence as
13765@code{^}.
13766
13767@item .
13768@code{RECORD} field selector. Defined on @code{RECORD} data. Same
13769precedence as @code{^}.
13770
13771@item []
13772Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
13773
13774@item ()
13775Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
13776as @code{^}.
13777
13778@item ::@r{, }.
13779@value{GDBN} and Modula-2 scope operators.
13780@end table
13781
13782@quotation
72019c9c 13783@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
13784treats the use of the operator @code{IN}, or the use of operators
13785@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
13786@code{<=}, and @code{>=} on sets as an error.
13787@end quotation
13788
cb51c4e0 13789
6d2ebf8b 13790@node Built-In Func/Proc
79a6e687 13791@subsubsection Built-in Functions and Procedures
cb51c4e0 13792@cindex Modula-2 built-ins
c906108c
SS
13793
13794Modula-2 also makes available several built-in procedures and functions.
13795In describing these, the following metavariables are used:
13796
13797@table @var
13798
13799@item a
13800represents an @code{ARRAY} variable.
13801
13802@item c
13803represents a @code{CHAR} constant or variable.
13804
13805@item i
13806represents a variable or constant of integral type.
13807
13808@item m
13809represents an identifier that belongs to a set. Generally used in the
13810same function with the metavariable @var{s}. The type of @var{s} should
13811be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
13812
13813@item n
13814represents a variable or constant of integral or floating-point type.
13815
13816@item r
13817represents a variable or constant of floating-point type.
13818
13819@item t
13820represents a type.
13821
13822@item v
13823represents a variable.
13824
13825@item x
13826represents a variable or constant of one of many types. See the
13827explanation of the function for details.
13828@end table
13829
13830All Modula-2 built-in procedures also return a result, described below.
13831
13832@table @code
13833@item ABS(@var{n})
13834Returns the absolute value of @var{n}.
13835
13836@item CAP(@var{c})
13837If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 13838equivalent, otherwise it returns its argument.
c906108c
SS
13839
13840@item CHR(@var{i})
13841Returns the character whose ordinal value is @var{i}.
13842
13843@item DEC(@var{v})
c3f6f71d 13844Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
13845
13846@item DEC(@var{v},@var{i})
13847Decrements the value in the variable @var{v} by @var{i}. Returns the
13848new value.
13849
13850@item EXCL(@var{m},@var{s})
13851Removes the element @var{m} from the set @var{s}. Returns the new
13852set.
13853
13854@item FLOAT(@var{i})
13855Returns the floating point equivalent of the integer @var{i}.
13856
13857@item HIGH(@var{a})
13858Returns the index of the last member of @var{a}.
13859
13860@item INC(@var{v})
c3f6f71d 13861Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
13862
13863@item INC(@var{v},@var{i})
13864Increments the value in the variable @var{v} by @var{i}. Returns the
13865new value.
13866
13867@item INCL(@var{m},@var{s})
13868Adds the element @var{m} to the set @var{s} if it is not already
13869there. Returns the new set.
13870
13871@item MAX(@var{t})
13872Returns the maximum value of the type @var{t}.
13873
13874@item MIN(@var{t})
13875Returns the minimum value of the type @var{t}.
13876
13877@item ODD(@var{i})
13878Returns boolean TRUE if @var{i} is an odd number.
13879
13880@item ORD(@var{x})
13881Returns the ordinal value of its argument. For example, the ordinal
c3f6f71d
JM
13882value of a character is its @sc{ascii} value (on machines supporting the
13883@sc{ascii} character set). @var{x} must be of an ordered type, which include
c906108c
SS
13884integral, character and enumerated types.
13885
13886@item SIZE(@var{x})
13887Returns the size of its argument. @var{x} can be a variable or a type.
13888
13889@item TRUNC(@var{r})
13890Returns the integral part of @var{r}.
13891
844781a1
GM
13892@item TSIZE(@var{x})
13893Returns the size of its argument. @var{x} can be a variable or a type.
13894
c906108c
SS
13895@item VAL(@var{t},@var{i})
13896Returns the member of the type @var{t} whose ordinal value is @var{i}.
13897@end table
13898
13899@quotation
13900@emph{Warning:} Sets and their operations are not yet supported, so
13901@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
13902an error.
13903@end quotation
13904
13905@cindex Modula-2 constants
6d2ebf8b 13906@node M2 Constants
c906108c
SS
13907@subsubsection Constants
13908
13909@value{GDBN} allows you to express the constants of Modula-2 in the following
13910ways:
13911
13912@itemize @bullet
13913
13914@item
13915Integer constants are simply a sequence of digits. When used in an
13916expression, a constant is interpreted to be type-compatible with the
13917rest of the expression. Hexadecimal integers are specified by a
13918trailing @samp{H}, and octal integers by a trailing @samp{B}.
13919
13920@item
13921Floating point constants appear as a sequence of digits, followed by a
13922decimal point and another sequence of digits. An optional exponent can
13923then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
13924@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
13925digits of the floating point constant must be valid decimal (base 10)
13926digits.
13927
13928@item
13929Character constants consist of a single character enclosed by a pair of
13930like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 13931also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
13932followed by a @samp{C}.
13933
13934@item
13935String constants consist of a sequence of characters enclosed by a
13936pair of like quotes, either single (@code{'}) or double (@code{"}).
13937Escape sequences in the style of C are also allowed. @xref{C
79a6e687 13938Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
13939sequences.
13940
13941@item
13942Enumerated constants consist of an enumerated identifier.
13943
13944@item
13945Boolean constants consist of the identifiers @code{TRUE} and
13946@code{FALSE}.
13947
13948@item
13949Pointer constants consist of integral values only.
13950
13951@item
13952Set constants are not yet supported.
13953@end itemize
13954
72019c9c
GM
13955@node M2 Types
13956@subsubsection Modula-2 Types
13957@cindex Modula-2 types
13958
13959Currently @value{GDBN} can print the following data types in Modula-2
13960syntax: array types, record types, set types, pointer types, procedure
13961types, enumerated types, subrange types and base types. You can also
13962print the contents of variables declared using these type.
13963This section gives a number of simple source code examples together with
13964sample @value{GDBN} sessions.
13965
13966The first example contains the following section of code:
13967
13968@smallexample
13969VAR
13970 s: SET OF CHAR ;
13971 r: [20..40] ;
13972@end smallexample
13973
13974@noindent
13975and you can request @value{GDBN} to interrogate the type and value of
13976@code{r} and @code{s}.
13977
13978@smallexample
13979(@value{GDBP}) print s
13980@{'A'..'C', 'Z'@}
13981(@value{GDBP}) ptype s
13982SET OF CHAR
13983(@value{GDBP}) print r
1398421
13985(@value{GDBP}) ptype r
13986[20..40]
13987@end smallexample
13988
13989@noindent
13990Likewise if your source code declares @code{s} as:
13991
13992@smallexample
13993VAR
13994 s: SET ['A'..'Z'] ;
13995@end smallexample
13996
13997@noindent
13998then you may query the type of @code{s} by:
13999
14000@smallexample
14001(@value{GDBP}) ptype s
14002type = SET ['A'..'Z']
14003@end smallexample
14004
14005@noindent
14006Note that at present you cannot interactively manipulate set
14007expressions using the debugger.
14008
14009The following example shows how you might declare an array in Modula-2
14010and how you can interact with @value{GDBN} to print its type and contents:
14011
14012@smallexample
14013VAR
14014 s: ARRAY [-10..10] OF CHAR ;
14015@end smallexample
14016
14017@smallexample
14018(@value{GDBP}) ptype s
14019ARRAY [-10..10] OF CHAR
14020@end smallexample
14021
14022Note that the array handling is not yet complete and although the type
14023is printed correctly, expression handling still assumes that all
14024arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 14025above.
72019c9c
GM
14026
14027Here are some more type related Modula-2 examples:
14028
14029@smallexample
14030TYPE
14031 colour = (blue, red, yellow, green) ;
14032 t = [blue..yellow] ;
14033VAR
14034 s: t ;
14035BEGIN
14036 s := blue ;
14037@end smallexample
14038
14039@noindent
14040The @value{GDBN} interaction shows how you can query the data type
14041and value of a variable.
14042
14043@smallexample
14044(@value{GDBP}) print s
14045$1 = blue
14046(@value{GDBP}) ptype t
14047type = [blue..yellow]
14048@end smallexample
14049
14050@noindent
14051In this example a Modula-2 array is declared and its contents
14052displayed. Observe that the contents are written in the same way as
14053their @code{C} counterparts.
14054
14055@smallexample
14056VAR
14057 s: ARRAY [1..5] OF CARDINAL ;
14058BEGIN
14059 s[1] := 1 ;
14060@end smallexample
14061
14062@smallexample
14063(@value{GDBP}) print s
14064$1 = @{1, 0, 0, 0, 0@}
14065(@value{GDBP}) ptype s
14066type = ARRAY [1..5] OF CARDINAL
14067@end smallexample
14068
14069The Modula-2 language interface to @value{GDBN} also understands
14070pointer types as shown in this example:
14071
14072@smallexample
14073VAR
14074 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
14075BEGIN
14076 NEW(s) ;
14077 s^[1] := 1 ;
14078@end smallexample
14079
14080@noindent
14081and you can request that @value{GDBN} describes the type of @code{s}.
14082
14083@smallexample
14084(@value{GDBP}) ptype s
14085type = POINTER TO ARRAY [1..5] OF CARDINAL
14086@end smallexample
14087
14088@value{GDBN} handles compound types as we can see in this example.
14089Here we combine array types, record types, pointer types and subrange
14090types:
14091
14092@smallexample
14093TYPE
14094 foo = RECORD
14095 f1: CARDINAL ;
14096 f2: CHAR ;
14097 f3: myarray ;
14098 END ;
14099
14100 myarray = ARRAY myrange OF CARDINAL ;
14101 myrange = [-2..2] ;
14102VAR
14103 s: POINTER TO ARRAY myrange OF foo ;
14104@end smallexample
14105
14106@noindent
14107and you can ask @value{GDBN} to describe the type of @code{s} as shown
14108below.
14109
14110@smallexample
14111(@value{GDBP}) ptype s
14112type = POINTER TO ARRAY [-2..2] OF foo = RECORD
14113 f1 : CARDINAL;
14114 f2 : CHAR;
14115 f3 : ARRAY [-2..2] OF CARDINAL;
14116END
14117@end smallexample
14118
6d2ebf8b 14119@node M2 Defaults
79a6e687 14120@subsubsection Modula-2 Defaults
c906108c
SS
14121@cindex Modula-2 defaults
14122
14123If type and range checking are set automatically by @value{GDBN}, they
14124both default to @code{on} whenever the working language changes to
d4f3574e 14125Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
14126selected the working language.
14127
14128If you allow @value{GDBN} to set the language automatically, then entering
14129code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
14130working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
14131Infer the Source Language}, for further details.
c906108c 14132
6d2ebf8b 14133@node Deviations
79a6e687 14134@subsubsection Deviations from Standard Modula-2
c906108c
SS
14135@cindex Modula-2, deviations from
14136
14137A few changes have been made to make Modula-2 programs easier to debug.
14138This is done primarily via loosening its type strictness:
14139
14140@itemize @bullet
14141@item
14142Unlike in standard Modula-2, pointer constants can be formed by
14143integers. This allows you to modify pointer variables during
14144debugging. (In standard Modula-2, the actual address contained in a
14145pointer variable is hidden from you; it can only be modified
14146through direct assignment to another pointer variable or expression that
14147returned a pointer.)
14148
14149@item
14150C escape sequences can be used in strings and characters to represent
14151non-printable characters. @value{GDBN} prints out strings with these
14152escape sequences embedded. Single non-printable characters are
14153printed using the @samp{CHR(@var{nnn})} format.
14154
14155@item
14156The assignment operator (@code{:=}) returns the value of its right-hand
14157argument.
14158
14159@item
14160All built-in procedures both modify @emph{and} return their argument.
14161@end itemize
14162
6d2ebf8b 14163@node M2 Checks
79a6e687 14164@subsubsection Modula-2 Type and Range Checks
c906108c
SS
14165@cindex Modula-2 checks
14166
14167@quotation
14168@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
14169range checking.
14170@end quotation
14171@c FIXME remove warning when type/range checks added
14172
14173@value{GDBN} considers two Modula-2 variables type equivalent if:
14174
14175@itemize @bullet
14176@item
14177They are of types that have been declared equivalent via a @code{TYPE
14178@var{t1} = @var{t2}} statement
14179
14180@item
14181They have been declared on the same line. (Note: This is true of the
14182@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
14183@end itemize
14184
14185As long as type checking is enabled, any attempt to combine variables
14186whose types are not equivalent is an error.
14187
14188Range checking is done on all mathematical operations, assignment, array
14189index bounds, and all built-in functions and procedures.
14190
6d2ebf8b 14191@node M2 Scope
79a6e687 14192@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 14193@cindex scope
41afff9a 14194@cindex @code{.}, Modula-2 scope operator
c906108c
SS
14195@cindex colon, doubled as scope operator
14196@ifinfo
41afff9a 14197@vindex colon-colon@r{, in Modula-2}
c906108c
SS
14198@c Info cannot handle :: but TeX can.
14199@end ifinfo
a67ec3f4 14200@ifnotinfo
41afff9a 14201@vindex ::@r{, in Modula-2}
a67ec3f4 14202@end ifnotinfo
c906108c
SS
14203
14204There are a few subtle differences between the Modula-2 scope operator
14205(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
14206similar syntax:
14207
474c8240 14208@smallexample
c906108c
SS
14209
14210@var{module} . @var{id}
14211@var{scope} :: @var{id}
474c8240 14212@end smallexample
c906108c
SS
14213
14214@noindent
14215where @var{scope} is the name of a module or a procedure,
14216@var{module} the name of a module, and @var{id} is any declared
14217identifier within your program, except another module.
14218
14219Using the @code{::} operator makes @value{GDBN} search the scope
14220specified by @var{scope} for the identifier @var{id}. If it is not
14221found in the specified scope, then @value{GDBN} searches all scopes
14222enclosing the one specified by @var{scope}.
14223
14224Using the @code{.} operator makes @value{GDBN} search the current scope for
14225the identifier specified by @var{id} that was imported from the
14226definition module specified by @var{module}. With this operator, it is
14227an error if the identifier @var{id} was not imported from definition
14228module @var{module}, or if @var{id} is not an identifier in
14229@var{module}.
14230
6d2ebf8b 14231@node GDB/M2
c906108c
SS
14232@subsubsection @value{GDBN} and Modula-2
14233
14234Some @value{GDBN} commands have little use when debugging Modula-2 programs.
14235Five subcommands of @code{set print} and @code{show print} apply
b37052ae 14236specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 14237@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 14238apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
14239analogue in Modula-2.
14240
14241The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 14242with any language, is not useful with Modula-2. Its
c906108c 14243intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 14244created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 14245address can be specified by an integral constant, the construct
d4f3574e 14246@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
14247
14248@cindex @code{#} in Modula-2
14249In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
14250interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 14251
e07c999f
PH
14252@node Ada
14253@subsection Ada
14254@cindex Ada
14255
14256The extensions made to @value{GDBN} for Ada only support
14257output from the @sc{gnu} Ada (GNAT) compiler.
14258Other Ada compilers are not currently supported, and
14259attempting to debug executables produced by them is most likely
14260to be difficult.
14261
14262
14263@cindex expressions in Ada
14264@menu
14265* Ada Mode Intro:: General remarks on the Ada syntax
14266 and semantics supported by Ada mode
14267 in @value{GDBN}.
14268* Omissions from Ada:: Restrictions on the Ada expression syntax.
14269* Additions to Ada:: Extensions of the Ada expression syntax.
14270* Stopping Before Main Program:: Debugging the program during elaboration.
20924a55
JB
14271* Ada Tasks:: Listing and setting breakpoints in tasks.
14272* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
14273* Ravenscar Profile:: Tasking Support when using the Ravenscar
14274 Profile
e07c999f
PH
14275* Ada Glitches:: Known peculiarities of Ada mode.
14276@end menu
14277
14278@node Ada Mode Intro
14279@subsubsection Introduction
14280@cindex Ada mode, general
14281
14282The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
14283syntax, with some extensions.
14284The philosophy behind the design of this subset is
14285
14286@itemize @bullet
14287@item
14288That @value{GDBN} should provide basic literals and access to operations for
14289arithmetic, dereferencing, field selection, indexing, and subprogram calls,
14290leaving more sophisticated computations to subprograms written into the
14291program (which therefore may be called from @value{GDBN}).
14292
14293@item
14294That type safety and strict adherence to Ada language restrictions
14295are not particularly important to the @value{GDBN} user.
14296
14297@item
14298That brevity is important to the @value{GDBN} user.
14299@end itemize
14300
f3a2dd1a
JB
14301Thus, for brevity, the debugger acts as if all names declared in
14302user-written packages are directly visible, even if they are not visible
14303according to Ada rules, thus making it unnecessary to fully qualify most
14304names with their packages, regardless of context. Where this causes
14305ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
14306
14307The debugger will start in Ada mode if it detects an Ada main program.
14308As for other languages, it will enter Ada mode when stopped in a program that
14309was translated from an Ada source file.
14310
14311While in Ada mode, you may use `@t{--}' for comments. This is useful
14312mostly for documenting command files. The standard @value{GDBN} comment
14313(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
14314middle (to allow based literals).
14315
14316The debugger supports limited overloading. Given a subprogram call in which
14317the function symbol has multiple definitions, it will use the number of
14318actual parameters and some information about their types to attempt to narrow
14319the set of definitions. It also makes very limited use of context, preferring
14320procedures to functions in the context of the @code{call} command, and
14321functions to procedures elsewhere.
14322
14323@node Omissions from Ada
14324@subsubsection Omissions from Ada
14325@cindex Ada, omissions from
14326
14327Here are the notable omissions from the subset:
14328
14329@itemize @bullet
14330@item
14331Only a subset of the attributes are supported:
14332
14333@itemize @minus
14334@item
14335@t{'First}, @t{'Last}, and @t{'Length}
14336 on array objects (not on types and subtypes).
14337
14338@item
14339@t{'Min} and @t{'Max}.
14340
14341@item
14342@t{'Pos} and @t{'Val}.
14343
14344@item
14345@t{'Tag}.
14346
14347@item
14348@t{'Range} on array objects (not subtypes), but only as the right
14349operand of the membership (@code{in}) operator.
14350
14351@item
14352@t{'Access}, @t{'Unchecked_Access}, and
14353@t{'Unrestricted_Access} (a GNAT extension).
14354
14355@item
14356@t{'Address}.
14357@end itemize
14358
14359@item
14360The names in
14361@code{Characters.Latin_1} are not available and
14362concatenation is not implemented. Thus, escape characters in strings are
14363not currently available.
14364
14365@item
14366Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
14367equality of representations. They will generally work correctly
14368for strings and arrays whose elements have integer or enumeration types.
14369They may not work correctly for arrays whose element
14370types have user-defined equality, for arrays of real values
14371(in particular, IEEE-conformant floating point, because of negative
14372zeroes and NaNs), and for arrays whose elements contain unused bits with
14373indeterminate values.
14374
14375@item
14376The other component-by-component array operations (@code{and}, @code{or},
14377@code{xor}, @code{not}, and relational tests other than equality)
14378are not implemented.
14379
14380@item
860701dc
PH
14381@cindex array aggregates (Ada)
14382@cindex record aggregates (Ada)
14383@cindex aggregates (Ada)
14384There is limited support for array and record aggregates. They are
14385permitted only on the right sides of assignments, as in these examples:
14386
14387@smallexample
077e0a52
JB
14388(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
14389(@value{GDBP}) set An_Array := (1, others => 0)
14390(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
14391(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
14392(@value{GDBP}) set A_Record := (1, "Peter", True);
14393(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
14394@end smallexample
14395
14396Changing a
14397discriminant's value by assigning an aggregate has an
14398undefined effect if that discriminant is used within the record.
14399However, you can first modify discriminants by directly assigning to
14400them (which normally would not be allowed in Ada), and then performing an
14401aggregate assignment. For example, given a variable @code{A_Rec}
14402declared to have a type such as:
14403
14404@smallexample
14405type Rec (Len : Small_Integer := 0) is record
14406 Id : Integer;
14407 Vals : IntArray (1 .. Len);
14408end record;
14409@end smallexample
14410
14411you can assign a value with a different size of @code{Vals} with two
14412assignments:
14413
14414@smallexample
077e0a52
JB
14415(@value{GDBP}) set A_Rec.Len := 4
14416(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
14417@end smallexample
14418
14419As this example also illustrates, @value{GDBN} is very loose about the usual
14420rules concerning aggregates. You may leave out some of the
14421components of an array or record aggregate (such as the @code{Len}
14422component in the assignment to @code{A_Rec} above); they will retain their
14423original values upon assignment. You may freely use dynamic values as
14424indices in component associations. You may even use overlapping or
14425redundant component associations, although which component values are
14426assigned in such cases is not defined.
e07c999f
PH
14427
14428@item
14429Calls to dispatching subprograms are not implemented.
14430
14431@item
14432The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
14433than that of real Ada. It makes only limited use of the context in
14434which a subexpression appears to resolve its meaning, and it is much
14435looser in its rules for allowing type matches. As a result, some
14436function calls will be ambiguous, and the user will be asked to choose
14437the proper resolution.
e07c999f
PH
14438
14439@item
14440The @code{new} operator is not implemented.
14441
14442@item
14443Entry calls are not implemented.
14444
14445@item
14446Aside from printing, arithmetic operations on the native VAX floating-point
14447formats are not supported.
14448
14449@item
14450It is not possible to slice a packed array.
158c7665
PH
14451
14452@item
14453The names @code{True} and @code{False}, when not part of a qualified name,
14454are interpreted as if implicitly prefixed by @code{Standard}, regardless of
14455context.
14456Should your program
14457redefine these names in a package or procedure (at best a dubious practice),
14458you will have to use fully qualified names to access their new definitions.
e07c999f
PH
14459@end itemize
14460
14461@node Additions to Ada
14462@subsubsection Additions to Ada
14463@cindex Ada, deviations from
14464
14465As it does for other languages, @value{GDBN} makes certain generic
14466extensions to Ada (@pxref{Expressions}):
14467
14468@itemize @bullet
14469@item
ae21e955
BW
14470If the expression @var{E} is a variable residing in memory (typically
14471a local variable or array element) and @var{N} is a positive integer,
14472then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
14473@var{N}-1 adjacent variables following it in memory as an array. In
14474Ada, this operator is generally not necessary, since its prime use is
14475in displaying parts of an array, and slicing will usually do this in
14476Ada. However, there are occasional uses when debugging programs in
14477which certain debugging information has been optimized away.
e07c999f
PH
14478
14479@item
ae21e955
BW
14480@code{@var{B}::@var{var}} means ``the variable named @var{var} that
14481appears in function or file @var{B}.'' When @var{B} is a file name,
14482you must typically surround it in single quotes.
e07c999f
PH
14483
14484@item
14485The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
14486@var{type} that appears at address @var{addr}.''
14487
14488@item
14489A name starting with @samp{$} is a convenience variable
14490(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
14491@end itemize
14492
ae21e955
BW
14493In addition, @value{GDBN} provides a few other shortcuts and outright
14494additions specific to Ada:
e07c999f
PH
14495
14496@itemize @bullet
14497@item
14498The assignment statement is allowed as an expression, returning
14499its right-hand operand as its value. Thus, you may enter
14500
14501@smallexample
077e0a52
JB
14502(@value{GDBP}) set x := y + 3
14503(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
14504@end smallexample
14505
14506@item
14507The semicolon is allowed as an ``operator,'' returning as its value
14508the value of its right-hand operand.
14509This allows, for example,
14510complex conditional breaks:
14511
14512@smallexample
077e0a52
JB
14513(@value{GDBP}) break f
14514(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
14515@end smallexample
14516
14517@item
14518Rather than use catenation and symbolic character names to introduce special
14519characters into strings, one may instead use a special bracket notation,
14520which is also used to print strings. A sequence of characters of the form
14521@samp{["@var{XX}"]} within a string or character literal denotes the
14522(single) character whose numeric encoding is @var{XX} in hexadecimal. The
14523sequence of characters @samp{["""]} also denotes a single quotation mark
14524in strings. For example,
14525@smallexample
14526 "One line.["0a"]Next line.["0a"]"
14527@end smallexample
14528@noindent
ae21e955
BW
14529contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
14530after each period.
e07c999f
PH
14531
14532@item
14533The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
14534@t{'Max} is optional (and is ignored in any case). For example, it is valid
14535to write
14536
14537@smallexample
077e0a52 14538(@value{GDBP}) print 'max(x, y)
e07c999f
PH
14539@end smallexample
14540
14541@item
14542When printing arrays, @value{GDBN} uses positional notation when the
14543array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
14544For example, a one-dimensional array of three integers with a lower bound
14545of 3 might print as
e07c999f
PH
14546
14547@smallexample
14548(3 => 10, 17, 1)
14549@end smallexample
14550
14551@noindent
14552That is, in contrast to valid Ada, only the first component has a @code{=>}
14553clause.
14554
14555@item
14556You may abbreviate attributes in expressions with any unique,
14557multi-character subsequence of
14558their names (an exact match gets preference).
14559For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
14560in place of @t{a'length}.
14561
14562@item
14563@cindex quoting Ada internal identifiers
14564Since Ada is case-insensitive, the debugger normally maps identifiers you type
14565to lower case. The GNAT compiler uses upper-case characters for
14566some of its internal identifiers, which are normally of no interest to users.
14567For the rare occasions when you actually have to look at them,
14568enclose them in angle brackets to avoid the lower-case mapping.
14569For example,
14570@smallexample
077e0a52 14571(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
14572@end smallexample
14573
14574@item
14575Printing an object of class-wide type or dereferencing an
14576access-to-class-wide value will display all the components of the object's
14577specific type (as indicated by its run-time tag). Likewise, component
14578selection on such a value will operate on the specific type of the
14579object.
14580
14581@end itemize
14582
14583@node Stopping Before Main Program
14584@subsubsection Stopping at the Very Beginning
14585
14586@cindex breakpointing Ada elaboration code
14587It is sometimes necessary to debug the program during elaboration, and
14588before reaching the main procedure.
14589As defined in the Ada Reference
14590Manual, the elaboration code is invoked from a procedure called
14591@code{adainit}. To run your program up to the beginning of
14592elaboration, simply use the following two commands:
14593@code{tbreak adainit} and @code{run}.
14594
20924a55
JB
14595@node Ada Tasks
14596@subsubsection Extensions for Ada Tasks
14597@cindex Ada, tasking
14598
14599Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
14600@value{GDBN} provides the following task-related commands:
14601
14602@table @code
14603@kindex info tasks
14604@item info tasks
14605This command shows a list of current Ada tasks, as in the following example:
14606
14607
14608@smallexample
14609@iftex
14610@leftskip=0.5cm
14611@end iftex
14612(@value{GDBP}) info tasks
14613 ID TID P-ID Pri State Name
14614 1 8088000 0 15 Child Activation Wait main_task
14615 2 80a4000 1 15 Accept Statement b
14616 3 809a800 1 15 Child Activation Wait a
32cd1edc 14617* 4 80ae800 3 15 Runnable c
20924a55
JB
14618
14619@end smallexample
14620
14621@noindent
14622In this listing, the asterisk before the last task indicates it to be the
14623task currently being inspected.
14624
14625@table @asis
14626@item ID
14627Represents @value{GDBN}'s internal task number.
14628
14629@item TID
14630The Ada task ID.
14631
14632@item P-ID
14633The parent's task ID (@value{GDBN}'s internal task number).
14634
14635@item Pri
14636The base priority of the task.
14637
14638@item State
14639Current state of the task.
14640
14641@table @code
14642@item Unactivated
14643The task has been created but has not been activated. It cannot be
14644executing.
14645
20924a55
JB
14646@item Runnable
14647The task is not blocked for any reason known to Ada. (It may be waiting
14648for a mutex, though.) It is conceptually "executing" in normal mode.
14649
14650@item Terminated
14651The task is terminated, in the sense of ARM 9.3 (5). Any dependents
14652that were waiting on terminate alternatives have been awakened and have
14653terminated themselves.
14654
14655@item Child Activation Wait
14656The task is waiting for created tasks to complete activation.
14657
14658@item Accept Statement
14659The task is waiting on an accept or selective wait statement.
14660
14661@item Waiting on entry call
14662The task is waiting on an entry call.
14663
14664@item Async Select Wait
14665The task is waiting to start the abortable part of an asynchronous
14666select statement.
14667
14668@item Delay Sleep
14669The task is waiting on a select statement with only a delay
14670alternative open.
14671
14672@item Child Termination Wait
14673The task is sleeping having completed a master within itself, and is
14674waiting for the tasks dependent on that master to become terminated or
14675waiting on a terminate Phase.
14676
14677@item Wait Child in Term Alt
14678The task is sleeping waiting for tasks on terminate alternatives to
14679finish terminating.
14680
14681@item Accepting RV with @var{taskno}
14682The task is accepting a rendez-vous with the task @var{taskno}.
14683@end table
14684
14685@item Name
14686Name of the task in the program.
14687
14688@end table
14689
14690@kindex info task @var{taskno}
14691@item info task @var{taskno}
14692This command shows detailled informations on the specified task, as in
14693the following example:
14694@smallexample
14695@iftex
14696@leftskip=0.5cm
14697@end iftex
14698(@value{GDBP}) info tasks
14699 ID TID P-ID Pri State Name
14700 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 14701* 2 807c468 1 15 Runnable task_1
20924a55
JB
14702(@value{GDBP}) info task 2
14703Ada Task: 0x807c468
14704Name: task_1
14705Thread: 0x807f378
14706Parent: 1 (main_task)
14707Base Priority: 15
14708State: Runnable
14709@end smallexample
14710
14711@item task
14712@kindex task@r{ (Ada)}
14713@cindex current Ada task ID
14714This command prints the ID of the current task.
14715
14716@smallexample
14717@iftex
14718@leftskip=0.5cm
14719@end iftex
14720(@value{GDBP}) info tasks
14721 ID TID P-ID Pri State Name
14722 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 14723* 2 807c458 1 15 Runnable t
20924a55
JB
14724(@value{GDBP}) task
14725[Current task is 2]
14726@end smallexample
14727
14728@item task @var{taskno}
14729@cindex Ada task switching
14730This command is like the @code{thread @var{threadno}}
14731command (@pxref{Threads}). It switches the context of debugging
14732from the current task to the given task.
14733
14734@smallexample
14735@iftex
14736@leftskip=0.5cm
14737@end iftex
14738(@value{GDBP}) info tasks
14739 ID TID P-ID Pri State Name
14740 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 14741* 2 807c458 1 15 Runnable t
20924a55
JB
14742(@value{GDBP}) task 1
14743[Switching to task 1]
14744#0 0x8067726 in pthread_cond_wait ()
14745(@value{GDBP}) bt
14746#0 0x8067726 in pthread_cond_wait ()
14747#1 0x8056714 in system.os_interface.pthread_cond_wait ()
14748#2 0x805cb63 in system.task_primitives.operations.sleep ()
14749#3 0x806153e in system.tasking.stages.activate_tasks ()
14750#4 0x804aacc in un () at un.adb:5
14751@end smallexample
14752
45ac276d
JB
14753@item break @var{linespec} task @var{taskno}
14754@itemx break @var{linespec} task @var{taskno} if @dots{}
14755@cindex breakpoints and tasks, in Ada
14756@cindex task breakpoints, in Ada
14757@kindex break @dots{} task @var{taskno}@r{ (Ada)}
14758These commands are like the @code{break @dots{} thread @dots{}}
14759command (@pxref{Thread Stops}).
14760@var{linespec} specifies source lines, as described
14761in @ref{Specify Location}.
14762
14763Use the qualifier @samp{task @var{taskno}} with a breakpoint command
14764to specify that you only want @value{GDBN} to stop the program when a
14765particular Ada task reaches this breakpoint. @var{taskno} is one of the
14766numeric task identifiers assigned by @value{GDBN}, shown in the first
14767column of the @samp{info tasks} display.
14768
14769If you do not specify @samp{task @var{taskno}} when you set a
14770breakpoint, the breakpoint applies to @emph{all} tasks of your
14771program.
14772
14773You can use the @code{task} qualifier on conditional breakpoints as
14774well; in this case, place @samp{task @var{taskno}} before the
14775breakpoint condition (before the @code{if}).
14776
14777For example,
14778
14779@smallexample
14780@iftex
14781@leftskip=0.5cm
14782@end iftex
14783(@value{GDBP}) info tasks
14784 ID TID P-ID Pri State Name
14785 1 140022020 0 15 Child Activation Wait main_task
14786 2 140045060 1 15 Accept/Select Wait t2
14787 3 140044840 1 15 Runnable t1
14788* 4 140056040 1 15 Runnable t3
14789(@value{GDBP}) b 15 task 2
14790Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
14791(@value{GDBP}) cont
14792Continuing.
14793task # 1 running
14794task # 2 running
14795
14796Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1479715 flush;
14798(@value{GDBP}) info tasks
14799 ID TID P-ID Pri State Name
14800 1 140022020 0 15 Child Activation Wait main_task
14801* 2 140045060 1 15 Runnable t2
14802 3 140044840 1 15 Runnable t1
14803 4 140056040 1 15 Delay Sleep t3
14804@end smallexample
20924a55
JB
14805@end table
14806
14807@node Ada Tasks and Core Files
14808@subsubsection Tasking Support when Debugging Core Files
14809@cindex Ada tasking and core file debugging
14810
14811When inspecting a core file, as opposed to debugging a live program,
14812tasking support may be limited or even unavailable, depending on
14813the platform being used.
14814For instance, on x86-linux, the list of tasks is available, but task
14815switching is not supported. On Tru64, however, task switching will work
14816as usual.
14817
14818On certain platforms, including Tru64, the debugger needs to perform some
14819memory writes in order to provide Ada tasking support. When inspecting
14820a core file, this means that the core file must be opened with read-write
14821privileges, using the command @samp{"set write on"} (@pxref{Patching}).
14822Under these circumstances, you should make a backup copy of the core
14823file before inspecting it with @value{GDBN}.
14824
6e1bb179
JB
14825@node Ravenscar Profile
14826@subsubsection Tasking Support when using the Ravenscar Profile
14827@cindex Ravenscar Profile
14828
14829The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
14830specifically designed for systems with safety-critical real-time
14831requirements.
14832
14833@table @code
14834@kindex set ravenscar task-switching on
14835@cindex task switching with program using Ravenscar Profile
14836@item set ravenscar task-switching on
14837Allows task switching when debugging a program that uses the Ravenscar
14838Profile. This is the default.
14839
14840@kindex set ravenscar task-switching off
14841@item set ravenscar task-switching off
14842Turn off task switching when debugging a program that uses the Ravenscar
14843Profile. This is mostly intended to disable the code that adds support
14844for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
14845the Ravenscar runtime is preventing @value{GDBN} from working properly.
14846To be effective, this command should be run before the program is started.
14847
14848@kindex show ravenscar task-switching
14849@item show ravenscar task-switching
14850Show whether it is possible to switch from task to task in a program
14851using the Ravenscar Profile.
14852
14853@end table
14854
e07c999f
PH
14855@node Ada Glitches
14856@subsubsection Known Peculiarities of Ada Mode
14857@cindex Ada, problems
14858
14859Besides the omissions listed previously (@pxref{Omissions from Ada}),
14860we know of several problems with and limitations of Ada mode in
14861@value{GDBN},
14862some of which will be fixed with planned future releases of the debugger
14863and the GNU Ada compiler.
14864
14865@itemize @bullet
e07c999f
PH
14866@item
14867Static constants that the compiler chooses not to materialize as objects in
14868storage are invisible to the debugger.
14869
14870@item
14871Named parameter associations in function argument lists are ignored (the
14872argument lists are treated as positional).
14873
14874@item
14875Many useful library packages are currently invisible to the debugger.
14876
14877@item
14878Fixed-point arithmetic, conversions, input, and output is carried out using
14879floating-point arithmetic, and may give results that only approximate those on
14880the host machine.
14881
e07c999f
PH
14882@item
14883The GNAT compiler never generates the prefix @code{Standard} for any of
14884the standard symbols defined by the Ada language. @value{GDBN} knows about
14885this: it will strip the prefix from names when you use it, and will never
14886look for a name you have so qualified among local symbols, nor match against
14887symbols in other packages or subprograms. If you have
14888defined entities anywhere in your program other than parameters and
14889local variables whose simple names match names in @code{Standard},
14890GNAT's lack of qualification here can cause confusion. When this happens,
14891you can usually resolve the confusion
14892by qualifying the problematic names with package
14893@code{Standard} explicitly.
14894@end itemize
14895
95433b34
JB
14896Older versions of the compiler sometimes generate erroneous debugging
14897information, resulting in the debugger incorrectly printing the value
14898of affected entities. In some cases, the debugger is able to work
14899around an issue automatically. In other cases, the debugger is able
14900to work around the issue, but the work-around has to be specifically
14901enabled.
14902
14903@kindex set ada trust-PAD-over-XVS
14904@kindex show ada trust-PAD-over-XVS
14905@table @code
14906
14907@item set ada trust-PAD-over-XVS on
14908Configure GDB to strictly follow the GNAT encoding when computing the
14909value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
14910types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
14911a complete description of the encoding used by the GNAT compiler).
14912This is the default.
14913
14914@item set ada trust-PAD-over-XVS off
14915This is related to the encoding using by the GNAT compiler. If @value{GDBN}
14916sometimes prints the wrong value for certain entities, changing @code{ada
14917trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
14918the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
14919@code{off}, but this incurs a slight performance penalty, so it is
14920recommended to leave this setting to @code{on} unless necessary.
14921
14922@end table
14923
79a6e687
BW
14924@node Unsupported Languages
14925@section Unsupported Languages
4e562065
JB
14926
14927@cindex unsupported languages
14928@cindex minimal language
14929In addition to the other fully-supported programming languages,
14930@value{GDBN} also provides a pseudo-language, called @code{minimal}.
14931It does not represent a real programming language, but provides a set
14932of capabilities close to what the C or assembly languages provide.
14933This should allow most simple operations to be performed while debugging
14934an application that uses a language currently not supported by @value{GDBN}.
14935
14936If the language is set to @code{auto}, @value{GDBN} will automatically
14937select this language if the current frame corresponds to an unsupported
14938language.
14939
6d2ebf8b 14940@node Symbols
c906108c
SS
14941@chapter Examining the Symbol Table
14942
d4f3574e 14943The commands described in this chapter allow you to inquire about the
c906108c
SS
14944symbols (names of variables, functions and types) defined in your
14945program. This information is inherent in the text of your program and
14946does not change as your program executes. @value{GDBN} finds it in your
14947program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
14948(@pxref{File Options, ,Choosing Files}), or by one of the
14949file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
14950
14951@cindex symbol names
14952@cindex names of symbols
14953@cindex quoting names
14954Occasionally, you may need to refer to symbols that contain unusual
14955characters, which @value{GDBN} ordinarily treats as word delimiters. The
14956most frequent case is in referring to static variables in other
79a6e687 14957source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
14958are recorded in object files as debugging symbols, but @value{GDBN} would
14959ordinarily parse a typical file name, like @file{foo.c}, as the three words
14960@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
14961@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
14962
474c8240 14963@smallexample
c906108c 14964p 'foo.c'::x
474c8240 14965@end smallexample
c906108c
SS
14966
14967@noindent
14968looks up the value of @code{x} in the scope of the file @file{foo.c}.
14969
14970@table @code
a8f24a35
EZ
14971@cindex case-insensitive symbol names
14972@cindex case sensitivity in symbol names
14973@kindex set case-sensitive
14974@item set case-sensitive on
14975@itemx set case-sensitive off
14976@itemx set case-sensitive auto
14977Normally, when @value{GDBN} looks up symbols, it matches their names
14978with case sensitivity determined by the current source language.
14979Occasionally, you may wish to control that. The command @code{set
14980case-sensitive} lets you do that by specifying @code{on} for
14981case-sensitive matches or @code{off} for case-insensitive ones. If
14982you specify @code{auto}, case sensitivity is reset to the default
14983suitable for the source language. The default is case-sensitive
14984matches for all languages except for Fortran, for which the default is
14985case-insensitive matches.
14986
9c16f35a
EZ
14987@kindex show case-sensitive
14988@item show case-sensitive
a8f24a35
EZ
14989This command shows the current setting of case sensitivity for symbols
14990lookups.
14991
53342f27
TT
14992@kindex set print type methods
14993@item set print type methods
14994@itemx set print type methods on
14995@itemx set print type methods off
14996Normally, when @value{GDBN} prints a class, it displays any methods
14997declared in that class. You can control this behavior either by
14998passing the appropriate flag to @code{ptype}, or using @command{set
14999print type methods}. Specifying @code{on} will cause @value{GDBN} to
15000display the methods; this is the default. Specifying @code{off} will
15001cause @value{GDBN} to omit the methods.
15002
15003@kindex show print type methods
15004@item show print type methods
15005This command shows the current setting of method display when printing
15006classes.
15007
15008@kindex set print type typedefs
15009@item set print type typedefs
15010@itemx set print type typedefs on
15011@itemx set print type typedefs off
15012
15013Normally, when @value{GDBN} prints a class, it displays any typedefs
15014defined in that class. You can control this behavior either by
15015passing the appropriate flag to @code{ptype}, or using @command{set
15016print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
15017display the typedef definitions; this is the default. Specifying
15018@code{off} will cause @value{GDBN} to omit the typedef definitions.
15019Note that this controls whether the typedef definition itself is
15020printed, not whether typedef names are substituted when printing other
15021types.
15022
15023@kindex show print type typedefs
15024@item show print type typedefs
15025This command shows the current setting of typedef display when
15026printing classes.
15027
c906108c 15028@kindex info address
b37052ae 15029@cindex address of a symbol
c906108c
SS
15030@item info address @var{symbol}
15031Describe where the data for @var{symbol} is stored. For a register
15032variable, this says which register it is kept in. For a non-register
15033local variable, this prints the stack-frame offset at which the variable
15034is always stored.
15035
15036Note the contrast with @samp{print &@var{symbol}}, which does not work
15037at all for a register variable, and for a stack local variable prints
15038the exact address of the current instantiation of the variable.
15039
3d67e040 15040@kindex info symbol
b37052ae 15041@cindex symbol from address
9c16f35a 15042@cindex closest symbol and offset for an address
3d67e040
EZ
15043@item info symbol @var{addr}
15044Print the name of a symbol which is stored at the address @var{addr}.
15045If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
15046nearest symbol and an offset from it:
15047
474c8240 15048@smallexample
3d67e040
EZ
15049(@value{GDBP}) info symbol 0x54320
15050_initialize_vx + 396 in section .text
474c8240 15051@end smallexample
3d67e040
EZ
15052
15053@noindent
15054This is the opposite of the @code{info address} command. You can use
15055it to find out the name of a variable or a function given its address.
15056
c14c28ba
PP
15057For dynamically linked executables, the name of executable or shared
15058library containing the symbol is also printed:
15059
15060@smallexample
15061(@value{GDBP}) info symbol 0x400225
15062_start + 5 in section .text of /tmp/a.out
15063(@value{GDBP}) info symbol 0x2aaaac2811cf
15064__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
15065@end smallexample
15066
c906108c 15067@kindex whatis
53342f27 15068@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
15069Print the data type of @var{arg}, which can be either an expression
15070or a name of a data type. With no argument, print the data type of
15071@code{$}, the last value in the value history.
15072
15073If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
15074is not actually evaluated, and any side-effecting operations (such as
15075assignments or function calls) inside it do not take place.
15076
15077If @var{arg} is a variable or an expression, @code{whatis} prints its
15078literal type as it is used in the source code. If the type was
15079defined using a @code{typedef}, @code{whatis} will @emph{not} print
15080the data type underlying the @code{typedef}. If the type of the
15081variable or the expression is a compound data type, such as
15082@code{struct} or @code{class}, @code{whatis} never prints their
15083fields or methods. It just prints the @code{struct}/@code{class}
15084name (a.k.a.@: its @dfn{tag}). If you want to see the members of
15085such a compound data type, use @code{ptype}.
15086
15087If @var{arg} is a type name that was defined using @code{typedef},
15088@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
15089Unrolling means that @code{whatis} will show the underlying type used
15090in the @code{typedef} declaration of @var{arg}. However, if that
15091underlying type is also a @code{typedef}, @code{whatis} will not
15092unroll it.
15093
15094For C code, the type names may also have the form @samp{class
15095@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
15096@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 15097
53342f27
TT
15098@var{flags} can be used to modify how the type is displayed.
15099Available flags are:
15100
15101@table @code
15102@item r
15103Display in ``raw'' form. Normally, @value{GDBN} substitutes template
15104parameters and typedefs defined in a class when printing the class'
15105members. The @code{/r} flag disables this.
15106
15107@item m
15108Do not print methods defined in the class.
15109
15110@item M
15111Print methods defined in the class. This is the default, but the flag
15112exists in case you change the default with @command{set print type methods}.
15113
15114@item t
15115Do not print typedefs defined in the class. Note that this controls
15116whether the typedef definition itself is printed, not whether typedef
15117names are substituted when printing other types.
15118
15119@item T
15120Print typedefs defined in the class. This is the default, but the flag
15121exists in case you change the default with @command{set print type typedefs}.
15122@end table
15123
c906108c 15124@kindex ptype
53342f27 15125@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
15126@code{ptype} accepts the same arguments as @code{whatis}, but prints a
15127detailed description of the type, instead of just the name of the type.
15128@xref{Expressions, ,Expressions}.
c906108c 15129
177bc839
JK
15130Contrary to @code{whatis}, @code{ptype} always unrolls any
15131@code{typedef}s in its argument declaration, whether the argument is
15132a variable, expression, or a data type. This means that @code{ptype}
15133of a variable or an expression will not print literally its type as
15134present in the source code---use @code{whatis} for that. @code{typedef}s at
15135the pointer or reference targets are also unrolled. Only @code{typedef}s of
15136fields, methods and inner @code{class typedef}s of @code{struct}s,
15137@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
15138
c906108c
SS
15139For example, for this variable declaration:
15140
474c8240 15141@smallexample
177bc839
JK
15142typedef double real_t;
15143struct complex @{ real_t real; double imag; @};
15144typedef struct complex complex_t;
15145complex_t var;
15146real_t *real_pointer_var;
474c8240 15147@end smallexample
c906108c
SS
15148
15149@noindent
15150the two commands give this output:
15151
474c8240 15152@smallexample
c906108c 15153@group
177bc839
JK
15154(@value{GDBP}) whatis var
15155type = complex_t
15156(@value{GDBP}) ptype var
15157type = struct complex @{
15158 real_t real;
15159 double imag;
15160@}
15161(@value{GDBP}) whatis complex_t
15162type = struct complex
15163(@value{GDBP}) whatis struct complex
c906108c 15164type = struct complex
177bc839 15165(@value{GDBP}) ptype struct complex
c906108c 15166type = struct complex @{
177bc839 15167 real_t real;
c906108c
SS
15168 double imag;
15169@}
177bc839
JK
15170(@value{GDBP}) whatis real_pointer_var
15171type = real_t *
15172(@value{GDBP}) ptype real_pointer_var
15173type = double *
c906108c 15174@end group
474c8240 15175@end smallexample
c906108c
SS
15176
15177@noindent
15178As with @code{whatis}, using @code{ptype} without an argument refers to
15179the type of @code{$}, the last value in the value history.
15180
ab1adacd
EZ
15181@cindex incomplete type
15182Sometimes, programs use opaque data types or incomplete specifications
15183of complex data structure. If the debug information included in the
15184program does not allow @value{GDBN} to display a full declaration of
15185the data type, it will say @samp{<incomplete type>}. For example,
15186given these declarations:
15187
15188@smallexample
15189 struct foo;
15190 struct foo *fooptr;
15191@end smallexample
15192
15193@noindent
15194but no definition for @code{struct foo} itself, @value{GDBN} will say:
15195
15196@smallexample
ddb50cd7 15197 (@value{GDBP}) ptype foo
ab1adacd
EZ
15198 $1 = <incomplete type>
15199@end smallexample
15200
15201@noindent
15202``Incomplete type'' is C terminology for data types that are not
15203completely specified.
15204
c906108c
SS
15205@kindex info types
15206@item info types @var{regexp}
15207@itemx info types
09d4efe1
EZ
15208Print a brief description of all types whose names match the regular
15209expression @var{regexp} (or all types in your program, if you supply
15210no argument). Each complete typename is matched as though it were a
15211complete line; thus, @samp{i type value} gives information on all
15212types in your program whose names include the string @code{value}, but
15213@samp{i type ^value$} gives information only on types whose complete
15214name is @code{value}.
c906108c
SS
15215
15216This command differs from @code{ptype} in two ways: first, like
15217@code{whatis}, it does not print a detailed description; second, it
15218lists all source files where a type is defined.
15219
18a9fc12
TT
15220@kindex info type-printers
15221@item info type-printers
15222Versions of @value{GDBN} that ship with Python scripting enabled may
15223have ``type printers'' available. When using @command{ptype} or
15224@command{whatis}, these printers are consulted when the name of a type
15225is needed. @xref{Type Printing API}, for more information on writing
15226type printers.
15227
15228@code{info type-printers} displays all the available type printers.
15229
15230@kindex enable type-printer
15231@kindex disable type-printer
15232@item enable type-printer @var{name}@dots{}
15233@item disable type-printer @var{name}@dots{}
15234These commands can be used to enable or disable type printers.
15235
b37052ae
EZ
15236@kindex info scope
15237@cindex local variables
09d4efe1 15238@item info scope @var{location}
b37052ae 15239List all the variables local to a particular scope. This command
09d4efe1
EZ
15240accepts a @var{location} argument---a function name, a source line, or
15241an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
15242to the scope defined by that location. (@xref{Specify Location}, for
15243details about supported forms of @var{location}.) For example:
b37052ae
EZ
15244
15245@smallexample
15246(@value{GDBP}) @b{info scope command_line_handler}
15247Scope for command_line_handler:
15248Symbol rl is an argument at stack/frame offset 8, length 4.
15249Symbol linebuffer is in static storage at address 0x150a18, length 4.
15250Symbol linelength is in static storage at address 0x150a1c, length 4.
15251Symbol p is a local variable in register $esi, length 4.
15252Symbol p1 is a local variable in register $ebx, length 4.
15253Symbol nline is a local variable in register $edx, length 4.
15254Symbol repeat is a local variable at frame offset -8, length 4.
15255@end smallexample
15256
f5c37c66
EZ
15257@noindent
15258This command is especially useful for determining what data to collect
15259during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
15260collect}.
15261
c906108c
SS
15262@kindex info source
15263@item info source
919d772c
JB
15264Show information about the current source file---that is, the source file for
15265the function containing the current point of execution:
15266@itemize @bullet
15267@item
15268the name of the source file, and the directory containing it,
15269@item
15270the directory it was compiled in,
15271@item
15272its length, in lines,
15273@item
15274which programming language it is written in,
15275@item
15276whether the executable includes debugging information for that file, and
15277if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
15278@item
15279whether the debugging information includes information about
15280preprocessor macros.
15281@end itemize
15282
c906108c
SS
15283
15284@kindex info sources
15285@item info sources
15286Print the names of all source files in your program for which there is
15287debugging information, organized into two lists: files whose symbols
15288have already been read, and files whose symbols will be read when needed.
15289
15290@kindex info functions
15291@item info functions
15292Print the names and data types of all defined functions.
15293
15294@item info functions @var{regexp}
15295Print the names and data types of all defined functions
15296whose names contain a match for regular expression @var{regexp}.
15297Thus, @samp{info fun step} finds all functions whose names
15298include @code{step}; @samp{info fun ^step} finds those whose names
b383017d 15299start with @code{step}. If a function name contains characters
c1468174 15300that conflict with the regular expression language (e.g.@:
1c5dfdad 15301@samp{operator*()}), they may be quoted with a backslash.
c906108c
SS
15302
15303@kindex info variables
15304@item info variables
0fe7935b 15305Print the names and data types of all variables that are defined
6ca652b0 15306outside of functions (i.e.@: excluding local variables).
c906108c
SS
15307
15308@item info variables @var{regexp}
15309Print the names and data types of all variables (except for local
15310variables) whose names contain a match for regular expression
15311@var{regexp}.
15312
b37303ee 15313@kindex info classes
721c2651 15314@cindex Objective-C, classes and selectors
b37303ee
AF
15315@item info classes
15316@itemx info classes @var{regexp}
15317Display all Objective-C classes in your program, or
15318(with the @var{regexp} argument) all those matching a particular regular
15319expression.
15320
15321@kindex info selectors
15322@item info selectors
15323@itemx info selectors @var{regexp}
15324Display all Objective-C selectors in your program, or
15325(with the @var{regexp} argument) all those matching a particular regular
15326expression.
15327
c906108c
SS
15328@ignore
15329This was never implemented.
15330@kindex info methods
15331@item info methods
15332@itemx info methods @var{regexp}
15333The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
15334methods within C@t{++} program, or (with the @var{regexp} argument) a
15335specific set of methods found in the various C@t{++} classes. Many
15336C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
15337from the @code{ptype} command can be overwhelming and hard to use. The
15338@code{info-methods} command filters the methods, printing only those
15339which match the regular-expression @var{regexp}.
15340@end ignore
15341
9c16f35a 15342@cindex opaque data types
c906108c
SS
15343@kindex set opaque-type-resolution
15344@item set opaque-type-resolution on
15345Tell @value{GDBN} to resolve opaque types. An opaque type is a type
15346declared as a pointer to a @code{struct}, @code{class}, or
15347@code{union}---for example, @code{struct MyType *}---that is used in one
15348source file although the full declaration of @code{struct MyType} is in
15349another source file. The default is on.
15350
15351A change in the setting of this subcommand will not take effect until
15352the next time symbols for a file are loaded.
15353
15354@item set opaque-type-resolution off
15355Tell @value{GDBN} not to resolve opaque types. In this case, the type
15356is printed as follows:
15357@smallexample
15358@{<no data fields>@}
15359@end smallexample
15360
15361@kindex show opaque-type-resolution
15362@item show opaque-type-resolution
15363Show whether opaque types are resolved or not.
c906108c
SS
15364
15365@kindex maint print symbols
15366@cindex symbol dump
15367@kindex maint print psymbols
15368@cindex partial symbol dump
15369@item maint print symbols @var{filename}
15370@itemx maint print psymbols @var{filename}
15371@itemx maint print msymbols @var{filename}
15372Write a dump of debugging symbol data into the file @var{filename}.
15373These commands are used to debug the @value{GDBN} symbol-reading code. Only
15374symbols with debugging data are included. If you use @samp{maint print
15375symbols}, @value{GDBN} includes all the symbols for which it has already
15376collected full details: that is, @var{filename} reflects symbols for
15377only those files whose symbols @value{GDBN} has read. You can use the
15378command @code{info sources} to find out which files these are. If you
15379use @samp{maint print psymbols} instead, the dump shows information about
15380symbols that @value{GDBN} only knows partially---that is, symbols defined in
15381files that @value{GDBN} has skimmed, but not yet read completely. Finally,
15382@samp{maint print msymbols} dumps just the minimal symbol information
15383required for each object file from which @value{GDBN} has read some symbols.
79a6e687 15384@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 15385@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 15386
5e7b2f39
JB
15387@kindex maint info symtabs
15388@kindex maint info psymtabs
44ea7b70
JB
15389@cindex listing @value{GDBN}'s internal symbol tables
15390@cindex symbol tables, listing @value{GDBN}'s internal
15391@cindex full symbol tables, listing @value{GDBN}'s internal
15392@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
15393@item maint info symtabs @r{[} @var{regexp} @r{]}
15394@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
15395
15396List the @code{struct symtab} or @code{struct partial_symtab}
15397structures whose names match @var{regexp}. If @var{regexp} is not
15398given, list them all. The output includes expressions which you can
15399copy into a @value{GDBN} debugging this one to examine a particular
15400structure in more detail. For example:
15401
15402@smallexample
5e7b2f39 15403(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
15404@{ objfile /home/gnu/build/gdb/gdb
15405 ((struct objfile *) 0x82e69d0)
b383017d 15406 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
15407 ((struct partial_symtab *) 0x8474b10)
15408 readin no
15409 fullname (null)
15410 text addresses 0x814d3c8 -- 0x8158074
15411 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
15412 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
15413 dependencies (none)
15414 @}
15415@}
5e7b2f39 15416(@value{GDBP}) maint info symtabs
44ea7b70
JB
15417(@value{GDBP})
15418@end smallexample
15419@noindent
15420We see that there is one partial symbol table whose filename contains
15421the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
15422and we see that @value{GDBN} has not read in any symtabs yet at all.
15423If we set a breakpoint on a function, that will cause @value{GDBN} to
15424read the symtab for the compilation unit containing that function:
15425
15426@smallexample
15427(@value{GDBP}) break dwarf2_psymtab_to_symtab
15428Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
15429line 1574.
5e7b2f39 15430(@value{GDBP}) maint info symtabs
b383017d 15431@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 15432 ((struct objfile *) 0x82e69d0)
b383017d 15433 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
15434 ((struct symtab *) 0x86c1f38)
15435 dirname (null)
15436 fullname (null)
15437 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 15438 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
15439 debugformat DWARF 2
15440 @}
15441@}
b383017d 15442(@value{GDBP})
44ea7b70 15443@end smallexample
c906108c
SS
15444@end table
15445
44ea7b70 15446
6d2ebf8b 15447@node Altering
c906108c
SS
15448@chapter Altering Execution
15449
15450Once you think you have found an error in your program, you might want to
15451find out for certain whether correcting the apparent error would lead to
15452correct results in the rest of the run. You can find the answer by
15453experiment, using the @value{GDBN} features for altering execution of the
15454program.
15455
15456For example, you can store new values into variables or memory
7a292a7a
SS
15457locations, give your program a signal, restart it at a different
15458address, or even return prematurely from a function.
c906108c
SS
15459
15460@menu
15461* Assignment:: Assignment to variables
15462* Jumping:: Continuing at a different address
c906108c 15463* Signaling:: Giving your program a signal
c906108c
SS
15464* Returning:: Returning from a function
15465* Calling:: Calling your program's functions
15466* Patching:: Patching your program
15467@end menu
15468
6d2ebf8b 15469@node Assignment
79a6e687 15470@section Assignment to Variables
c906108c
SS
15471
15472@cindex assignment
15473@cindex setting variables
15474To alter the value of a variable, evaluate an assignment expression.
15475@xref{Expressions, ,Expressions}. For example,
15476
474c8240 15477@smallexample
c906108c 15478print x=4
474c8240 15479@end smallexample
c906108c
SS
15480
15481@noindent
15482stores the value 4 into the variable @code{x}, and then prints the
5d161b24 15483value of the assignment expression (which is 4).
c906108c
SS
15484@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
15485information on operators in supported languages.
c906108c
SS
15486
15487@kindex set variable
15488@cindex variables, setting
15489If you are not interested in seeing the value of the assignment, use the
15490@code{set} command instead of the @code{print} command. @code{set} is
15491really the same as @code{print} except that the expression's value is
15492not printed and is not put in the value history (@pxref{Value History,
79a6e687 15493,Value History}). The expression is evaluated only for its effects.
c906108c 15494
c906108c
SS
15495If the beginning of the argument string of the @code{set} command
15496appears identical to a @code{set} subcommand, use the @code{set
15497variable} command instead of just @code{set}. This command is identical
15498to @code{set} except for its lack of subcommands. For example, if your
15499program has a variable @code{width}, you get an error if you try to set
15500a new value with just @samp{set width=13}, because @value{GDBN} has the
15501command @code{set width}:
15502
474c8240 15503@smallexample
c906108c
SS
15504(@value{GDBP}) whatis width
15505type = double
15506(@value{GDBP}) p width
15507$4 = 13
15508(@value{GDBP}) set width=47
15509Invalid syntax in expression.
474c8240 15510@end smallexample
c906108c
SS
15511
15512@noindent
15513The invalid expression, of course, is @samp{=47}. In
15514order to actually set the program's variable @code{width}, use
15515
474c8240 15516@smallexample
c906108c 15517(@value{GDBP}) set var width=47
474c8240 15518@end smallexample
53a5351d 15519
c906108c
SS
15520Because the @code{set} command has many subcommands that can conflict
15521with the names of program variables, it is a good idea to use the
15522@code{set variable} command instead of just @code{set}. For example, if
15523your program has a variable @code{g}, you run into problems if you try
15524to set a new value with just @samp{set g=4}, because @value{GDBN} has
15525the command @code{set gnutarget}, abbreviated @code{set g}:
15526
474c8240 15527@smallexample
c906108c
SS
15528@group
15529(@value{GDBP}) whatis g
15530type = double
15531(@value{GDBP}) p g
15532$1 = 1
15533(@value{GDBP}) set g=4
2df3850c 15534(@value{GDBP}) p g
c906108c
SS
15535$2 = 1
15536(@value{GDBP}) r
15537The program being debugged has been started already.
15538Start it from the beginning? (y or n) y
15539Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
15540"/home/smith/cc_progs/a.out": can't open to read symbols:
15541 Invalid bfd target.
c906108c
SS
15542(@value{GDBP}) show g
15543The current BFD target is "=4".
15544@end group
474c8240 15545@end smallexample
c906108c
SS
15546
15547@noindent
15548The program variable @code{g} did not change, and you silently set the
15549@code{gnutarget} to an invalid value. In order to set the variable
15550@code{g}, use
15551
474c8240 15552@smallexample
c906108c 15553(@value{GDBP}) set var g=4
474c8240 15554@end smallexample
c906108c
SS
15555
15556@value{GDBN} allows more implicit conversions in assignments than C; you can
15557freely store an integer value into a pointer variable or vice versa,
15558and you can convert any structure to any other structure that is the
15559same length or shorter.
15560@comment FIXME: how do structs align/pad in these conversions?
15561@comment /doc@cygnus.com 18dec1990
15562
15563To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
15564construct to generate a value of specified type at a specified address
15565(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
15566to memory location @code{0x83040} as an integer (which implies a certain size
15567and representation in memory), and
15568
474c8240 15569@smallexample
c906108c 15570set @{int@}0x83040 = 4
474c8240 15571@end smallexample
c906108c
SS
15572
15573@noindent
15574stores the value 4 into that memory location.
15575
6d2ebf8b 15576@node Jumping
79a6e687 15577@section Continuing at a Different Address
c906108c
SS
15578
15579Ordinarily, when you continue your program, you do so at the place where
15580it stopped, with the @code{continue} command. You can instead continue at
15581an address of your own choosing, with the following commands:
15582
15583@table @code
15584@kindex jump
c1d780c2 15585@kindex j @r{(@code{jump})}
c906108c 15586@item jump @var{linespec}
c1d780c2 15587@itemx j @var{linespec}
2a25a5ba 15588@itemx jump @var{location}
c1d780c2 15589@itemx j @var{location}
2a25a5ba
EZ
15590Resume execution at line @var{linespec} or at address given by
15591@var{location}. Execution stops again immediately if there is a
15592breakpoint there. @xref{Specify Location}, for a description of the
15593different forms of @var{linespec} and @var{location}. It is common
15594practice to use the @code{tbreak} command in conjunction with
15595@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
15596
15597The @code{jump} command does not change the current stack frame, or
15598the stack pointer, or the contents of any memory location or any
15599register other than the program counter. If line @var{linespec} is in
15600a different function from the one currently executing, the results may
15601be bizarre if the two functions expect different patterns of arguments or
15602of local variables. For this reason, the @code{jump} command requests
15603confirmation if the specified line is not in the function currently
15604executing. However, even bizarre results are predictable if you are
15605well acquainted with the machine-language code of your program.
c906108c
SS
15606@end table
15607
c906108c 15608@c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
53a5351d
JM
15609On many systems, you can get much the same effect as the @code{jump}
15610command by storing a new value into the register @code{$pc}. The
15611difference is that this does not start your program running; it only
15612changes the address of where it @emph{will} run when you continue. For
15613example,
c906108c 15614
474c8240 15615@smallexample
c906108c 15616set $pc = 0x485
474c8240 15617@end smallexample
c906108c
SS
15618
15619@noindent
15620makes the next @code{continue} command or stepping command execute at
15621address @code{0x485}, rather than at the address where your program stopped.
79a6e687 15622@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
15623
15624The most common occasion to use the @code{jump} command is to back
15625up---perhaps with more breakpoints set---over a portion of a program
15626that has already executed, in order to examine its execution in more
15627detail.
15628
c906108c 15629@c @group
6d2ebf8b 15630@node Signaling
79a6e687 15631@section Giving your Program a Signal
9c16f35a 15632@cindex deliver a signal to a program
c906108c
SS
15633
15634@table @code
15635@kindex signal
15636@item signal @var{signal}
15637Resume execution where your program stopped, but immediately give it the
15638signal @var{signal}. @var{signal} can be the name or the number of a
15639signal. For example, on many systems @code{signal 2} and @code{signal
15640SIGINT} are both ways of sending an interrupt signal.
15641
15642Alternatively, if @var{signal} is zero, continue execution without
15643giving a signal. This is useful when your program stopped on account of
ae606bee 15644a signal and would ordinarily see the signal when resumed with the
c906108c
SS
15645@code{continue} command; @samp{signal 0} causes it to resume without a
15646signal.
15647
15648@code{signal} does not repeat when you press @key{RET} a second time
15649after executing the command.
15650@end table
15651@c @end group
15652
15653Invoking the @code{signal} command is not the same as invoking the
15654@code{kill} utility from the shell. Sending a signal with @code{kill}
15655causes @value{GDBN} to decide what to do with the signal depending on
15656the signal handling tables (@pxref{Signals}). The @code{signal} command
15657passes the signal directly to your program.
15658
c906108c 15659
6d2ebf8b 15660@node Returning
79a6e687 15661@section Returning from a Function
c906108c
SS
15662
15663@table @code
15664@cindex returning from a function
15665@kindex return
15666@item return
15667@itemx return @var{expression}
15668You can cancel execution of a function call with the @code{return}
15669command. If you give an
15670@var{expression} argument, its value is used as the function's return
15671value.
15672@end table
15673
15674When you use @code{return}, @value{GDBN} discards the selected stack frame
15675(and all frames within it). You can think of this as making the
15676discarded frame return prematurely. If you wish to specify a value to
15677be returned, give that value as the argument to @code{return}.
15678
15679This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 15680Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
15681innermost remaining frame. That frame becomes selected. The
15682specified value is stored in the registers used for returning values
15683of functions.
15684
15685The @code{return} command does not resume execution; it leaves the
15686program stopped in the state that would exist if the function had just
15687returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 15688and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
15689selected stack frame returns naturally.
15690
61ff14c6
JK
15691@value{GDBN} needs to know how the @var{expression} argument should be set for
15692the inferior. The concrete registers assignment depends on the OS ABI and the
15693type being returned by the selected stack frame. For example it is common for
15694OS ABI to return floating point values in FPU registers while integer values in
15695CPU registers. Still some ABIs return even floating point values in CPU
15696registers. Larger integer widths (such as @code{long long int}) also have
15697specific placement rules. @value{GDBN} already knows the OS ABI from its
15698current target so it needs to find out also the type being returned to make the
15699assignment into the right register(s).
15700
15701Normally, the selected stack frame has debug info. @value{GDBN} will always
15702use the debug info instead of the implicit type of @var{expression} when the
15703debug info is available. For example, if you type @kbd{return -1}, and the
15704function in the current stack frame is declared to return a @code{long long
15705int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
15706into a @code{long long int}:
15707
15708@smallexample
15709Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1571029 return 31;
15711(@value{GDBP}) return -1
15712Make func return now? (y or n) y
15713#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1571443 printf ("result=%lld\n", func ());
15715(@value{GDBP})
15716@end smallexample
15717
15718However, if the selected stack frame does not have a debug info, e.g., if the
15719function was compiled without debug info, @value{GDBN} has to find out the type
15720to return from user. Specifying a different type by mistake may set the value
15721in different inferior registers than the caller code expects. For example,
15722typing @kbd{return -1} with its implicit type @code{int} would set only a part
15723of a @code{long long int} result for a debug info less function (on 32-bit
15724architectures). Therefore the user is required to specify the return type by
15725an appropriate cast explicitly:
15726
15727@smallexample
15728Breakpoint 2, 0x0040050b in func ()
15729(@value{GDBP}) return -1
15730Return value type not available for selected stack frame.
15731Please use an explicit cast of the value to return.
15732(@value{GDBP}) return (long long int) -1
15733Make selected stack frame return now? (y or n) y
15734#0 0x00400526 in main ()
15735(@value{GDBP})
15736@end smallexample
15737
6d2ebf8b 15738@node Calling
79a6e687 15739@section Calling Program Functions
c906108c 15740
f8568604 15741@table @code
c906108c 15742@cindex calling functions
f8568604
EZ
15743@cindex inferior functions, calling
15744@item print @var{expr}
d3e8051b 15745Evaluate the expression @var{expr} and display the resulting value.
f8568604
EZ
15746@var{expr} may include calls to functions in the program being
15747debugged.
15748
c906108c 15749@kindex call
c906108c
SS
15750@item call @var{expr}
15751Evaluate the expression @var{expr} without displaying @code{void}
15752returned values.
c906108c
SS
15753
15754You can use this variant of the @code{print} command if you want to
f8568604
EZ
15755execute a function from your program that does not return anything
15756(a.k.a.@: @dfn{a void function}), but without cluttering the output
15757with @code{void} returned values that @value{GDBN} will otherwise
15758print. If the result is not void, it is printed and saved in the
15759value history.
15760@end table
15761
9c16f35a
EZ
15762It is possible for the function you call via the @code{print} or
15763@code{call} command to generate a signal (e.g., if there's a bug in
15764the function, or if you passed it incorrect arguments). What happens
15765in that case is controlled by the @code{set unwindonsignal} command.
15766
7cd1089b
PM
15767Similarly, with a C@t{++} program it is possible for the function you
15768call via the @code{print} or @code{call} command to generate an
15769exception that is not handled due to the constraints of the dummy
15770frame. In this case, any exception that is raised in the frame, but has
15771an out-of-frame exception handler will not be found. GDB builds a
15772dummy-frame for the inferior function call, and the unwinder cannot
15773seek for exception handlers outside of this dummy-frame. What happens
15774in that case is controlled by the
15775@code{set unwind-on-terminating-exception} command.
15776
9c16f35a
EZ
15777@table @code
15778@item set unwindonsignal
15779@kindex set unwindonsignal
15780@cindex unwind stack in called functions
15781@cindex call dummy stack unwinding
15782Set unwinding of the stack if a signal is received while in a function
15783that @value{GDBN} called in the program being debugged. If set to on,
15784@value{GDBN} unwinds the stack it created for the call and restores
15785the context to what it was before the call. If set to off (the
15786default), @value{GDBN} stops in the frame where the signal was
15787received.
15788
15789@item show unwindonsignal
15790@kindex show unwindonsignal
15791Show the current setting of stack unwinding in the functions called by
15792@value{GDBN}.
7cd1089b
PM
15793
15794@item set unwind-on-terminating-exception
15795@kindex set unwind-on-terminating-exception
15796@cindex unwind stack in called functions with unhandled exceptions
15797@cindex call dummy stack unwinding on unhandled exception.
15798Set unwinding of the stack if a C@t{++} exception is raised, but left
15799unhandled while in a function that @value{GDBN} called in the program being
15800debugged. If set to on (the default), @value{GDBN} unwinds the stack
15801it created for the call and restores the context to what it was before
15802the call. If set to off, @value{GDBN} the exception is delivered to
15803the default C@t{++} exception handler and the inferior terminated.
15804
15805@item show unwind-on-terminating-exception
15806@kindex show unwind-on-terminating-exception
15807Show the current setting of stack unwinding in the functions called by
15808@value{GDBN}.
15809
9c16f35a
EZ
15810@end table
15811
f8568604
EZ
15812@cindex weak alias functions
15813Sometimes, a function you wish to call is actually a @dfn{weak alias}
15814for another function. In such case, @value{GDBN} might not pick up
15815the type information, including the types of the function arguments,
15816which causes @value{GDBN} to call the inferior function incorrectly.
15817As a result, the called function will function erroneously and may
15818even crash. A solution to that is to use the name of the aliased
15819function instead.
c906108c 15820
6d2ebf8b 15821@node Patching
79a6e687 15822@section Patching Programs
7a292a7a 15823
c906108c
SS
15824@cindex patching binaries
15825@cindex writing into executables
c906108c 15826@cindex writing into corefiles
c906108c 15827
7a292a7a
SS
15828By default, @value{GDBN} opens the file containing your program's
15829executable code (or the corefile) read-only. This prevents accidental
15830alterations to machine code; but it also prevents you from intentionally
15831patching your program's binary.
c906108c
SS
15832
15833If you'd like to be able to patch the binary, you can specify that
15834explicitly with the @code{set write} command. For example, you might
15835want to turn on internal debugging flags, or even to make emergency
15836repairs.
15837
15838@table @code
15839@kindex set write
15840@item set write on
15841@itemx set write off
7a292a7a 15842If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 15843core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
15844off} (the default), @value{GDBN} opens them read-only.
15845
15846If you have already loaded a file, you must load it again (using the
7a292a7a
SS
15847@code{exec-file} or @code{core-file} command) after changing @code{set
15848write}, for your new setting to take effect.
c906108c
SS
15849
15850@item show write
15851@kindex show write
7a292a7a
SS
15852Display whether executable files and core files are opened for writing
15853as well as reading.
c906108c
SS
15854@end table
15855
6d2ebf8b 15856@node GDB Files
c906108c
SS
15857@chapter @value{GDBN} Files
15858
7a292a7a
SS
15859@value{GDBN} needs to know the file name of the program to be debugged,
15860both in order to read its symbol table and in order to start your
15861program. To debug a core dump of a previous run, you must also tell
15862@value{GDBN} the name of the core dump file.
c906108c
SS
15863
15864@menu
15865* Files:: Commands to specify files
5b5d99cf 15866* Separate Debug Files:: Debugging information in separate files
608e2dbb 15867* MiniDebugInfo:: Debugging information in a special section
9291a0cd 15868* Index Files:: Index files speed up GDB
c906108c 15869* Symbol Errors:: Errors reading symbol files
b14b1491 15870* Data Files:: GDB data files
c906108c
SS
15871@end menu
15872
6d2ebf8b 15873@node Files
79a6e687 15874@section Commands to Specify Files
c906108c 15875
7a292a7a 15876@cindex symbol table
c906108c 15877@cindex core dump file
7a292a7a
SS
15878
15879You may want to specify executable and core dump file names. The usual
15880way to do this is at start-up time, using the arguments to
15881@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
15882Out of @value{GDBN}}).
c906108c
SS
15883
15884Occasionally it is necessary to change to a different file during a
397ca115
EZ
15885@value{GDBN} session. Or you may run @value{GDBN} and forget to
15886specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
15887via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
15888Program}). In these situations the @value{GDBN} commands to specify
0869d01b 15889new files are useful.
c906108c
SS
15890
15891@table @code
15892@cindex executable file
15893@kindex file
15894@item file @var{filename}
15895Use @var{filename} as the program to be debugged. It is read for its
15896symbols and for the contents of pure memory. It is also the program
15897executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
15898directory and the file is not found in the @value{GDBN} working directory,
15899@value{GDBN} uses the environment variable @code{PATH} as a list of
15900directories to search, just as the shell does when looking for a program
15901to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
15902and your program, using the @code{path} command.
15903
fc8be69e
EZ
15904@cindex unlinked object files
15905@cindex patching object files
15906You can load unlinked object @file{.o} files into @value{GDBN} using
15907the @code{file} command. You will not be able to ``run'' an object
15908file, but you can disassemble functions and inspect variables. Also,
15909if the underlying BFD functionality supports it, you could use
15910@kbd{gdb -write} to patch object files using this technique. Note
15911that @value{GDBN} can neither interpret nor modify relocations in this
15912case, so branches and some initialized variables will appear to go to
15913the wrong place. But this feature is still handy from time to time.
15914
c906108c
SS
15915@item file
15916@code{file} with no argument makes @value{GDBN} discard any information it
15917has on both executable file and the symbol table.
15918
15919@kindex exec-file
15920@item exec-file @r{[} @var{filename} @r{]}
15921Specify that the program to be run (but not the symbol table) is found
15922in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
15923if necessary to locate your program. Omitting @var{filename} means to
15924discard information on the executable file.
15925
15926@kindex symbol-file
15927@item symbol-file @r{[} @var{filename} @r{]}
15928Read symbol table information from file @var{filename}. @code{PATH} is
15929searched when necessary. Use the @code{file} command to get both symbol
15930table and program to run from the same file.
15931
15932@code{symbol-file} with no argument clears out @value{GDBN} information on your
15933program's symbol table.
15934
ae5a43e0
DJ
15935The @code{symbol-file} command causes @value{GDBN} to forget the contents of
15936some breakpoints and auto-display expressions. This is because they may
15937contain pointers to the internal data recording symbols and data types,
15938which are part of the old symbol table data being discarded inside
15939@value{GDBN}.
c906108c
SS
15940
15941@code{symbol-file} does not repeat if you press @key{RET} again after
15942executing it once.
15943
15944When @value{GDBN} is configured for a particular environment, it
15945understands debugging information in whatever format is the standard
15946generated for that environment; you may use either a @sc{gnu} compiler, or
15947other compilers that adhere to the local conventions.
c906108c 15948Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 15949using @code{@value{NGCC}} you can generate debugging information for
c906108c 15950optimized code.
c906108c
SS
15951
15952For most kinds of object files, with the exception of old SVR3 systems
15953using COFF, the @code{symbol-file} command does not normally read the
15954symbol table in full right away. Instead, it scans the symbol table
15955quickly to find which source files and which symbols are present. The
15956details are read later, one source file at a time, as they are needed.
15957
15958The purpose of this two-stage reading strategy is to make @value{GDBN}
15959start up faster. For the most part, it is invisible except for
15960occasional pauses while the symbol table details for a particular source
15961file are being read. (The @code{set verbose} command can turn these
15962pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 15963Warnings and Messages}.)
c906108c 15964
c906108c
SS
15965We have not implemented the two-stage strategy for COFF yet. When the
15966symbol table is stored in COFF format, @code{symbol-file} reads the
15967symbol table data in full right away. Note that ``stabs-in-COFF''
15968still does the two-stage strategy, since the debug info is actually
15969in stabs format.
15970
15971@kindex readnow
15972@cindex reading symbols immediately
15973@cindex symbols, reading immediately
6ac33a4e
TT
15974@item symbol-file @r{[} -readnow @r{]} @var{filename}
15975@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
15976You can override the @value{GDBN} two-stage strategy for reading symbol
15977tables by using the @samp{-readnow} option with any of the commands that
15978load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 15979entire symbol table available.
c906108c 15980
c906108c
SS
15981@c FIXME: for now no mention of directories, since this seems to be in
15982@c flux. 13mar1992 status is that in theory GDB would look either in
15983@c current dir or in same dir as myprog; but issues like competing
15984@c GDB's, or clutter in system dirs, mean that in practice right now
15985@c only current dir is used. FFish says maybe a special GDB hierarchy
15986@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
15987@c files.
15988
c906108c 15989@kindex core-file
09d4efe1 15990@item core-file @r{[}@var{filename}@r{]}
4644b6e3 15991@itemx core
c906108c
SS
15992Specify the whereabouts of a core dump file to be used as the ``contents
15993of memory''. Traditionally, core files contain only some parts of the
15994address space of the process that generated them; @value{GDBN} can access the
15995executable file itself for other parts.
15996
15997@code{core-file} with no argument specifies that no core file is
15998to be used.
15999
16000Note that the core file is ignored when your program is actually running
7a292a7a
SS
16001under @value{GDBN}. So, if you have been running your program and you
16002wish to debug a core file instead, you must kill the subprocess in which
16003the program is running. To do this, use the @code{kill} command
79a6e687 16004(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 16005
c906108c
SS
16006@kindex add-symbol-file
16007@cindex dynamic linking
16008@item add-symbol-file @var{filename} @var{address}
a94ab193 16009@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
24bdad53 16010@itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
96a2c332
SS
16011The @code{add-symbol-file} command reads additional symbol table
16012information from the file @var{filename}. You would use this command
16013when @var{filename} has been dynamically loaded (by some other means)
16014into the program that is running. @var{address} should be the memory
16015address at which the file has been loaded; @value{GDBN} cannot figure
d167840f 16016this out for itself. You can additionally specify an arbitrary number
24bdad53 16017of @samp{-s @var{section} @var{address}} pairs, to give an explicit
d167840f
EZ
16018section name and base address for that section. You can specify any
16019@var{address} as an expression.
c906108c
SS
16020
16021The symbol table of the file @var{filename} is added to the symbol table
16022originally read with the @code{symbol-file} command. You can use the
96a2c332
SS
16023@code{add-symbol-file} command any number of times; the new symbol data
16024thus read keeps adding to the old. To discard all old symbol data
16025instead, use the @code{symbol-file} command without any arguments.
c906108c 16026
17d9d558
JB
16027@cindex relocatable object files, reading symbols from
16028@cindex object files, relocatable, reading symbols from
16029@cindex reading symbols from relocatable object files
16030@cindex symbols, reading from relocatable object files
16031@cindex @file{.o} files, reading symbols from
16032Although @var{filename} is typically a shared library file, an
16033executable file, or some other object file which has been fully
16034relocated for loading into a process, you can also load symbolic
16035information from relocatable @file{.o} files, as long as:
16036
16037@itemize @bullet
16038@item
16039the file's symbolic information refers only to linker symbols defined in
16040that file, not to symbols defined by other object files,
16041@item
16042every section the file's symbolic information refers to has actually
16043been loaded into the inferior, as it appears in the file, and
16044@item
16045you can determine the address at which every section was loaded, and
16046provide these to the @code{add-symbol-file} command.
16047@end itemize
16048
16049@noindent
16050Some embedded operating systems, like Sun Chorus and VxWorks, can load
16051relocatable files into an already running program; such systems
16052typically make the requirements above easy to meet. However, it's
16053important to recognize that many native systems use complex link
49efadf5 16054procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
16055assembly, for example) that make the requirements difficult to meet. In
16056general, one cannot assume that using @code{add-symbol-file} to read a
16057relocatable object file's symbolic information will have the same effect
16058as linking the relocatable object file into the program in the normal
16059way.
16060
c906108c
SS
16061@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
16062
c45da7e6
EZ
16063@kindex add-symbol-file-from-memory
16064@cindex @code{syscall DSO}
16065@cindex load symbols from memory
16066@item add-symbol-file-from-memory @var{address}
16067Load symbols from the given @var{address} in a dynamically loaded
16068object file whose image is mapped directly into the inferior's memory.
16069For example, the Linux kernel maps a @code{syscall DSO} into each
16070process's address space; this DSO provides kernel-specific code for
16071some system calls. The argument can be any expression whose
16072evaluation yields the address of the file's shared object file header.
16073For this command to work, you must have used @code{symbol-file} or
16074@code{exec-file} commands in advance.
16075
09d4efe1
EZ
16076@kindex add-shared-symbol-files
16077@kindex assf
16078@item add-shared-symbol-files @var{library-file}
16079@itemx assf @var{library-file}
16080The @code{add-shared-symbol-files} command can currently be used only
16081in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
16082alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
16083@value{GDBN} automatically looks for shared libraries, however if
16084@value{GDBN} does not find yours, you can invoke
16085@code{add-shared-symbol-files}. It takes one argument: the shared
16086library's file name. @code{assf} is a shorthand alias for
16087@code{add-shared-symbol-files}.
c906108c 16088
c906108c 16089@kindex section
09d4efe1
EZ
16090@item section @var{section} @var{addr}
16091The @code{section} command changes the base address of the named
16092@var{section} of the exec file to @var{addr}. This can be used if the
16093exec file does not contain section addresses, (such as in the
16094@code{a.out} format), or when the addresses specified in the file
16095itself are wrong. Each section must be changed separately. The
16096@code{info files} command, described below, lists all the sections and
16097their addresses.
c906108c
SS
16098
16099@kindex info files
16100@kindex info target
16101@item info files
16102@itemx info target
7a292a7a
SS
16103@code{info files} and @code{info target} are synonymous; both print the
16104current target (@pxref{Targets, ,Specifying a Debugging Target}),
16105including the names of the executable and core dump files currently in
16106use by @value{GDBN}, and the files from which symbols were loaded. The
16107command @code{help target} lists all possible targets rather than
16108current ones.
16109
fe95c787
MS
16110@kindex maint info sections
16111@item maint info sections
16112Another command that can give you extra information about program sections
16113is @code{maint info sections}. In addition to the section information
16114displayed by @code{info files}, this command displays the flags and file
16115offset of each section in the executable and core dump files. In addition,
16116@code{maint info sections} provides the following command options (which
16117may be arbitrarily combined):
16118
16119@table @code
16120@item ALLOBJ
16121Display sections for all loaded object files, including shared libraries.
16122@item @var{sections}
6600abed 16123Display info only for named @var{sections}.
fe95c787
MS
16124@item @var{section-flags}
16125Display info only for sections for which @var{section-flags} are true.
16126The section flags that @value{GDBN} currently knows about are:
16127@table @code
16128@item ALLOC
16129Section will have space allocated in the process when loaded.
16130Set for all sections except those containing debug information.
16131@item LOAD
16132Section will be loaded from the file into the child process memory.
16133Set for pre-initialized code and data, clear for @code{.bss} sections.
16134@item RELOC
16135Section needs to be relocated before loading.
16136@item READONLY
16137Section cannot be modified by the child process.
16138@item CODE
16139Section contains executable code only.
6600abed 16140@item DATA
fe95c787
MS
16141Section contains data only (no executable code).
16142@item ROM
16143Section will reside in ROM.
16144@item CONSTRUCTOR
16145Section contains data for constructor/destructor lists.
16146@item HAS_CONTENTS
16147Section is not empty.
16148@item NEVER_LOAD
16149An instruction to the linker to not output the section.
16150@item COFF_SHARED_LIBRARY
16151A notification to the linker that the section contains
16152COFF shared library information.
16153@item IS_COMMON
16154Section contains common symbols.
16155@end table
16156@end table
6763aef9 16157@kindex set trust-readonly-sections
9c16f35a 16158@cindex read-only sections
6763aef9
MS
16159@item set trust-readonly-sections on
16160Tell @value{GDBN} that readonly sections in your object file
6ca652b0 16161really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
16162In that case, @value{GDBN} can fetch values from these sections
16163out of the object file, rather than from the target program.
16164For some targets (notably embedded ones), this can be a significant
16165enhancement to debugging performance.
16166
16167The default is off.
16168
16169@item set trust-readonly-sections off
15110bc3 16170Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
16171the contents of the section might change while the program is running,
16172and must therefore be fetched from the target when needed.
9c16f35a
EZ
16173
16174@item show trust-readonly-sections
16175Show the current setting of trusting readonly sections.
c906108c
SS
16176@end table
16177
16178All file-specifying commands allow both absolute and relative file names
16179as arguments. @value{GDBN} always converts the file name to an absolute file
16180name and remembers it that way.
16181
c906108c 16182@cindex shared libraries
9cceb671
DJ
16183@anchor{Shared Libraries}
16184@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
9c16f35a 16185and IBM RS/6000 AIX shared libraries.
53a5351d 16186
9cceb671
DJ
16187On MS-Windows @value{GDBN} must be linked with the Expat library to support
16188shared libraries. @xref{Expat}.
16189
c906108c
SS
16190@value{GDBN} automatically loads symbol definitions from shared libraries
16191when you use the @code{run} command, or when you examine a core file.
16192(Before you issue the @code{run} command, @value{GDBN} does not understand
16193references to a function in a shared library, however---unless you are
16194debugging a core file).
53a5351d
JM
16195
16196On HP-UX, if the program loads a library explicitly, @value{GDBN}
16197automatically loads the symbols at the time of the @code{shl_load} call.
16198
c906108c
SS
16199@c FIXME: some @value{GDBN} release may permit some refs to undef
16200@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
16201@c FIXME...lib; check this from time to time when updating manual
16202
b7209cb4
FF
16203There are times, however, when you may wish to not automatically load
16204symbol definitions from shared libraries, such as when they are
16205particularly large or there are many of them.
16206
16207To control the automatic loading of shared library symbols, use the
16208commands:
16209
16210@table @code
16211@kindex set auto-solib-add
16212@item set auto-solib-add @var{mode}
16213If @var{mode} is @code{on}, symbols from all shared object libraries
16214will be loaded automatically when the inferior begins execution, you
16215attach to an independently started inferior, or when the dynamic linker
16216informs @value{GDBN} that a new library has been loaded. If @var{mode}
16217is @code{off}, symbols must be loaded manually, using the
16218@code{sharedlibrary} command. The default value is @code{on}.
16219
dcaf7c2c
EZ
16220@cindex memory used for symbol tables
16221If your program uses lots of shared libraries with debug info that
16222takes large amounts of memory, you can decrease the @value{GDBN}
16223memory footprint by preventing it from automatically loading the
16224symbols from shared libraries. To that end, type @kbd{set
16225auto-solib-add off} before running the inferior, then load each
16226library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 16227@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
16228the libraries whose symbols you want to be loaded.
16229
b7209cb4
FF
16230@kindex show auto-solib-add
16231@item show auto-solib-add
16232Display the current autoloading mode.
16233@end table
16234
c45da7e6 16235@cindex load shared library
b7209cb4
FF
16236To explicitly load shared library symbols, use the @code{sharedlibrary}
16237command:
16238
c906108c
SS
16239@table @code
16240@kindex info sharedlibrary
16241@kindex info share
55333a84
DE
16242@item info share @var{regex}
16243@itemx info sharedlibrary @var{regex}
16244Print the names of the shared libraries which are currently loaded
16245that match @var{regex}. If @var{regex} is omitted then print
16246all shared libraries that are loaded.
c906108c
SS
16247
16248@kindex sharedlibrary
16249@kindex share
16250@item sharedlibrary @var{regex}
16251@itemx share @var{regex}
c906108c
SS
16252Load shared object library symbols for files matching a
16253Unix regular expression.
16254As with files loaded automatically, it only loads shared libraries
16255required by your program for a core file or after typing @code{run}. If
16256@var{regex} is omitted all shared libraries required by your program are
16257loaded.
c45da7e6
EZ
16258
16259@item nosharedlibrary
16260@kindex nosharedlibrary
16261@cindex unload symbols from shared libraries
16262Unload all shared object library symbols. This discards all symbols
16263that have been loaded from all shared libraries. Symbols from shared
16264libraries that were loaded by explicit user requests are not
16265discarded.
c906108c
SS
16266@end table
16267
721c2651 16268Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
16269when any of shared library events happen. The best way to do this is
16270to use @code{catch load} and @code{catch unload} (@pxref{Set
16271Catchpoints}).
16272
16273@value{GDBN} also supports the the @code{set stop-on-solib-events}
16274command for this. This command exists for historical reasons. It is
16275less useful than setting a catchpoint, because it does not allow for
16276conditions or commands as a catchpoint does.
721c2651
EZ
16277
16278@table @code
16279@item set stop-on-solib-events
16280@kindex set stop-on-solib-events
16281This command controls whether @value{GDBN} should give you control
16282when the dynamic linker notifies it about some shared library event.
16283The most common event of interest is loading or unloading of a new
16284shared library.
16285
16286@item show stop-on-solib-events
16287@kindex show stop-on-solib-events
16288Show whether @value{GDBN} stops and gives you control when shared
16289library events happen.
16290@end table
16291
f5ebfba0 16292Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
16293configurations. @value{GDBN} needs to have access to the target's libraries;
16294this can be accomplished either by providing copies of the libraries
16295on the host system, or by asking @value{GDBN} to automatically retrieve the
16296libraries from the target. If copies of the target libraries are
16297provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
16298copies on the target can be stripped as long as the copies on the host are
16299not.
16300
59b7b46f
EZ
16301@cindex where to look for shared libraries
16302For remote debugging, you need to tell @value{GDBN} where the target
16303libraries are, so that it can load the correct copies---otherwise, it
16304may try to load the host's libraries. @value{GDBN} has two variables
16305to specify the search directories for target libraries.
f5ebfba0
DJ
16306
16307@table @code
59b7b46f 16308@cindex prefix for shared library file names
f822c95b 16309@cindex system root, alternate
f5ebfba0 16310@kindex set solib-absolute-prefix
f822c95b
DJ
16311@kindex set sysroot
16312@item set sysroot @var{path}
16313Use @var{path} as the system root for the program being debugged. Any
16314absolute shared library paths will be prefixed with @var{path}; many
16315runtime loaders store the absolute paths to the shared library in the
16316target program's memory. If you use @code{set sysroot} to find shared
16317libraries, they need to be laid out in the same way that they are on
16318the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
16319under @var{path}.
16320
f1838a98
UW
16321If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
16322retrieve the target libraries from the remote system. This is only
16323supported when using a remote target that supports the @code{remote get}
16324command (@pxref{File Transfer,,Sending files to a remote system}).
16325The part of @var{path} following the initial @file{remote:}
16326(if present) is used as system root prefix on the remote file system.
16327@footnote{If you want to specify a local system root using a directory
16328that happens to be named @file{remote:}, you need to use some equivalent
16329variant of the name like @file{./remote:}.}
16330
ab38a727
PA
16331For targets with an MS-DOS based filesystem, such as MS-Windows and
16332SymbianOS, @value{GDBN} tries prefixing a few variants of the target
16333absolute file name with @var{path}. But first, on Unix hosts,
16334@value{GDBN} converts all backslash directory separators into forward
16335slashes, because the backslash is not a directory separator on Unix:
16336
16337@smallexample
16338 c:\foo\bar.dll @result{} c:/foo/bar.dll
16339@end smallexample
16340
16341Then, @value{GDBN} attempts prefixing the target file name with
16342@var{path}, and looks for the resulting file name in the host file
16343system:
16344
16345@smallexample
16346 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
16347@end smallexample
16348
16349If that does not find the shared library, @value{GDBN} tries removing
16350the @samp{:} character from the drive spec, both for convenience, and,
16351for the case of the host file system not supporting file names with
16352colons:
16353
16354@smallexample
16355 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
16356@end smallexample
16357
16358This makes it possible to have a system root that mirrors a target
16359with more than one drive. E.g., you may want to setup your local
16360copies of the target system shared libraries like so (note @samp{c} vs
16361@samp{z}):
16362
16363@smallexample
16364 @file{/path/to/sysroot/c/sys/bin/foo.dll}
16365 @file{/path/to/sysroot/c/sys/bin/bar.dll}
16366 @file{/path/to/sysroot/z/sys/bin/bar.dll}
16367@end smallexample
16368
16369@noindent
16370and point the system root at @file{/path/to/sysroot}, so that
16371@value{GDBN} can find the correct copies of both
16372@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
16373
16374If that still does not find the shared library, @value{GDBN} tries
16375removing the whole drive spec from the target file name:
16376
16377@smallexample
16378 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
16379@end smallexample
16380
16381This last lookup makes it possible to not care about the drive name,
16382if you don't want or need to.
16383
f822c95b
DJ
16384The @code{set solib-absolute-prefix} command is an alias for @code{set
16385sysroot}.
16386
16387@cindex default system root
59b7b46f 16388@cindex @samp{--with-sysroot}
f822c95b
DJ
16389You can set the default system root by using the configure-time
16390@samp{--with-sysroot} option. If the system root is inside
16391@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
16392@samp{--exec-prefix}), then the default system root will be updated
16393automatically if the installed @value{GDBN} is moved to a new
16394location.
16395
16396@kindex show sysroot
16397@item show sysroot
f5ebfba0
DJ
16398Display the current shared library prefix.
16399
16400@kindex set solib-search-path
16401@item set solib-search-path @var{path}
f822c95b
DJ
16402If this variable is set, @var{path} is a colon-separated list of
16403directories to search for shared libraries. @samp{solib-search-path}
16404is used after @samp{sysroot} fails to locate the library, or if the
16405path to the library is relative instead of absolute. If you want to
16406use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 16407@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 16408finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 16409it to a nonexistent directory may interfere with automatic loading
f822c95b 16410of shared library symbols.
f5ebfba0
DJ
16411
16412@kindex show solib-search-path
16413@item show solib-search-path
16414Display the current shared library search path.
ab38a727
PA
16415
16416@cindex DOS file-name semantics of file names.
16417@kindex set target-file-system-kind (unix|dos-based|auto)
16418@kindex show target-file-system-kind
16419@item set target-file-system-kind @var{kind}
16420Set assumed file system kind for target reported file names.
16421
16422Shared library file names as reported by the target system may not
16423make sense as is on the system @value{GDBN} is running on. For
16424example, when remote debugging a target that has MS-DOS based file
16425system semantics, from a Unix host, the target may be reporting to
16426@value{GDBN} a list of loaded shared libraries with file names such as
16427@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
16428drive letters, so the @samp{c:\} prefix is not normally understood as
16429indicating an absolute file name, and neither is the backslash
16430normally considered a directory separator character. In that case,
16431the native file system would interpret this whole absolute file name
16432as a relative file name with no directory components. This would make
16433it impossible to point @value{GDBN} at a copy of the remote target's
16434shared libraries on the host using @code{set sysroot}, and impractical
16435with @code{set solib-search-path}. Setting
16436@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
16437to interpret such file names similarly to how the target would, and to
16438map them to file names valid on @value{GDBN}'s native file system
16439semantics. The value of @var{kind} can be @code{"auto"}, in addition
16440to one of the supported file system kinds. In that case, @value{GDBN}
16441tries to determine the appropriate file system variant based on the
16442current target's operating system (@pxref{ABI, ,Configuring the
16443Current ABI}). The supported file system settings are:
16444
16445@table @code
16446@item unix
16447Instruct @value{GDBN} to assume the target file system is of Unix
16448kind. Only file names starting the forward slash (@samp{/}) character
16449are considered absolute, and the directory separator character is also
16450the forward slash.
16451
16452@item dos-based
16453Instruct @value{GDBN} to assume the target file system is DOS based.
16454File names starting with either a forward slash, or a drive letter
16455followed by a colon (e.g., @samp{c:}), are considered absolute, and
16456both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
16457considered directory separators.
16458
16459@item auto
16460Instruct @value{GDBN} to use the file system kind associated with the
16461target operating system (@pxref{ABI, ,Configuring the Current ABI}).
16462This is the default.
16463@end table
f5ebfba0
DJ
16464@end table
16465
c011a4f4
DE
16466@cindex file name canonicalization
16467@cindex base name differences
16468When processing file names provided by the user, @value{GDBN}
16469frequently needs to compare them to the file names recorded in the
16470program's debug info. Normally, @value{GDBN} compares just the
16471@dfn{base names} of the files as strings, which is reasonably fast
16472even for very large programs. (The base name of a file is the last
16473portion of its name, after stripping all the leading directories.)
16474This shortcut in comparison is based upon the assumption that files
16475cannot have more than one base name. This is usually true, but
16476references to files that use symlinks or similar filesystem
16477facilities violate that assumption. If your program records files
16478using such facilities, or if you provide file names to @value{GDBN}
16479using symlinks etc., you can set @code{basenames-may-differ} to
16480@code{true} to instruct @value{GDBN} to completely canonicalize each
16481pair of file names it needs to compare. This will make file-name
16482comparisons accurate, but at a price of a significant slowdown.
16483
16484@table @code
16485@item set basenames-may-differ
16486@kindex set basenames-may-differ
16487Set whether a source file may have multiple base names.
16488
16489@item show basenames-may-differ
16490@kindex show basenames-may-differ
16491Show whether a source file may have multiple base names.
16492@end table
5b5d99cf
JB
16493
16494@node Separate Debug Files
16495@section Debugging Information in Separate Files
16496@cindex separate debugging information files
16497@cindex debugging information in separate files
16498@cindex @file{.debug} subdirectories
16499@cindex debugging information directory, global
f307c045 16500@cindex global debugging information directories
c7e83d54
EZ
16501@cindex build ID, and separate debugging files
16502@cindex @file{.build-id} directory
5b5d99cf
JB
16503
16504@value{GDBN} allows you to put a program's debugging information in a
16505file separate from the executable itself, in a way that allows
16506@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
16507Since debugging information can be very large---sometimes larger
16508than the executable code itself---some systems distribute debugging
5b5d99cf
JB
16509information for their executables in separate files, which users can
16510install only when they need to debug a problem.
16511
c7e83d54
EZ
16512@value{GDBN} supports two ways of specifying the separate debug info
16513file:
5b5d99cf
JB
16514
16515@itemize @bullet
16516@item
c7e83d54
EZ
16517The executable contains a @dfn{debug link} that specifies the name of
16518the separate debug info file. The separate debug file's name is
16519usually @file{@var{executable}.debug}, where @var{executable} is the
16520name of the corresponding executable file without leading directories
16521(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
16522debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
16523checksum for the debug file, which @value{GDBN} uses to validate that
16524the executable and the debug file came from the same build.
c7e83d54
EZ
16525
16526@item
7e27a47a 16527The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 16528also present in the corresponding debug info file. (This is supported
7e27a47a
EZ
16529only on some operating systems, notably those which use the ELF format
16530for binary files and the @sc{gnu} Binutils.) For more details about
16531this feature, see the description of the @option{--build-id}
16532command-line option in @ref{Options, , Command Line Options, ld.info,
16533The GNU Linker}. The debug info file's name is not specified
16534explicitly by the build ID, but can be computed from the build ID, see
16535below.
d3750b24
JK
16536@end itemize
16537
c7e83d54
EZ
16538Depending on the way the debug info file is specified, @value{GDBN}
16539uses two different methods of looking for the debug file:
d3750b24
JK
16540
16541@itemize @bullet
16542@item
c7e83d54
EZ
16543For the ``debug link'' method, @value{GDBN} looks up the named file in
16544the directory of the executable file, then in a subdirectory of that
f307c045
JK
16545directory named @file{.debug}, and finally under each one of the global debug
16546directories, in a subdirectory whose name is identical to the leading
c7e83d54
EZ
16547directories of the executable's absolute file name.
16548
16549@item
83f83d7f 16550For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
16551@file{.build-id} subdirectory of each one of the global debug directories for
16552a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
16553first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
16554are the rest of the bit string. (Real build ID strings are 32 or more
16555hex characters, not 10.)
c7e83d54
EZ
16556@end itemize
16557
16558So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
16559@file{/usr/bin/ls}, which has a debug link that specifies the
16560file @file{ls.debug}, and a build ID whose value in hex is
f307c045 16561@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
16562@file{/usr/lib/debug}, then @value{GDBN} will look for the following
16563debug information files, in the indicated order:
16564
16565@itemize @minus
16566@item
16567@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 16568@item
c7e83d54 16569@file{/usr/bin/ls.debug}
5b5d99cf 16570@item
c7e83d54 16571@file{/usr/bin/.debug/ls.debug}
5b5d99cf 16572@item
c7e83d54 16573@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 16574@end itemize
5b5d99cf 16575
1564a261
JK
16576@anchor{debug-file-directory}
16577Global debugging info directories default to what is set by @value{GDBN}
16578configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
16579you can also set the global debugging info directories, and view the list
16580@value{GDBN} is currently using.
5b5d99cf
JB
16581
16582@table @code
16583
16584@kindex set debug-file-directory
24ddea62
JK
16585@item set debug-file-directory @var{directories}
16586Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
16587information files to @var{directory}. Multiple path components can be set
16588concatenating them by a path separator.
5b5d99cf
JB
16589
16590@kindex show debug-file-directory
16591@item show debug-file-directory
24ddea62 16592Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
16593information files.
16594
16595@end table
16596
16597@cindex @code{.gnu_debuglink} sections
c7e83d54 16598@cindex debug link sections
5b5d99cf
JB
16599A debug link is a special section of the executable file named
16600@code{.gnu_debuglink}. The section must contain:
16601
16602@itemize
16603@item
16604A filename, with any leading directory components removed, followed by
16605a zero byte,
16606@item
16607zero to three bytes of padding, as needed to reach the next four-byte
16608boundary within the section, and
16609@item
16610a four-byte CRC checksum, stored in the same endianness used for the
16611executable file itself. The checksum is computed on the debugging
16612information file's full contents by the function given below, passing
16613zero as the @var{crc} argument.
16614@end itemize
16615
16616Any executable file format can carry a debug link, as long as it can
16617contain a section named @code{.gnu_debuglink} with the contents
16618described above.
16619
d3750b24 16620@cindex @code{.note.gnu.build-id} sections
c7e83d54 16621@cindex build ID sections
7e27a47a
EZ
16622The build ID is a special section in the executable file (and in other
16623ELF binary files that @value{GDBN} may consider). This section is
16624often named @code{.note.gnu.build-id}, but that name is not mandatory.
16625It contains unique identification for the built files---the ID remains
16626the same across multiple builds of the same build tree. The default
16627algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
16628content for the build ID string. The same section with an identical
16629value is present in the original built binary with symbols, in its
16630stripped variant, and in the separate debugging information file.
d3750b24 16631
5b5d99cf
JB
16632The debugging information file itself should be an ordinary
16633executable, containing a full set of linker symbols, sections, and
16634debugging information. The sections of the debugging information file
c7e83d54
EZ
16635should have the same names, addresses, and sizes as the original file,
16636but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
16637in an ordinary executable.
16638
7e27a47a 16639The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
16640@samp{objcopy} utility that can produce
16641the separated executable / debugging information file pairs using the
16642following commands:
16643
16644@smallexample
16645@kbd{objcopy --only-keep-debug foo foo.debug}
16646@kbd{strip -g foo}
c7e83d54
EZ
16647@end smallexample
16648
16649@noindent
16650These commands remove the debugging
83f83d7f
JK
16651information from the executable file @file{foo} and place it in the file
16652@file{foo.debug}. You can use the first, second or both methods to link the
16653two files:
16654
16655@itemize @bullet
16656@item
16657The debug link method needs the following additional command to also leave
16658behind a debug link in @file{foo}:
16659
16660@smallexample
16661@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
16662@end smallexample
16663
16664Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 16665a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
16666foo.debug} has the same functionality as the two @code{objcopy} commands and
16667the @code{ln -s} command above, together.
16668
16669@item
16670Build ID gets embedded into the main executable using @code{ld --build-id} or
16671the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
16672compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 16673utilities (Binutils) package since version 2.18.
83f83d7f
JK
16674@end itemize
16675
16676@noindent
d3750b24 16677
99e008fe
EZ
16678@cindex CRC algorithm definition
16679The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
16680IEEE 802.3 using the polynomial:
16681
16682@c TexInfo requires naked braces for multi-digit exponents for Tex
16683@c output, but this causes HTML output to barf. HTML has to be set using
16684@c raw commands. So we end up having to specify this equation in 2
16685@c different ways!
16686@ifhtml
16687@display
16688@html
16689 <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>
16690 + <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
16691@end html
16692@end display
16693@end ifhtml
16694@ifnothtml
16695@display
16696 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
16697 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
16698@end display
16699@end ifnothtml
16700
16701The function is computed byte at a time, taking the least
16702significant bit of each byte first. The initial pattern
16703@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
16704the final result is inverted to ensure trailing zeros also affect the
16705CRC.
16706
16707@emph{Note:} This is the same CRC polynomial as used in handling the
16708@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
16709, @value{GDBN} Remote Serial Protocol}). However in the
16710case of the Remote Serial Protocol, the CRC is computed @emph{most}
16711significant bit first, and the result is not inverted, so trailing
16712zeros have no effect on the CRC value.
16713
16714To complete the description, we show below the code of the function
16715which produces the CRC used in @code{.gnu_debuglink}. Inverting the
16716initially supplied @code{crc} argument means that an initial call to
16717this function passing in zero will start computing the CRC using
16718@code{0xffffffff}.
5b5d99cf 16719
4644b6e3 16720@kindex gnu_debuglink_crc32
5b5d99cf
JB
16721@smallexample
16722unsigned long
16723gnu_debuglink_crc32 (unsigned long crc,
16724 unsigned char *buf, size_t len)
16725@{
16726 static const unsigned long crc32_table[256] =
16727 @{
16728 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
16729 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
16730 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
16731 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
16732 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
16733 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
16734 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
16735 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
16736 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
16737 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
16738 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
16739 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
16740 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
16741 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
16742 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
16743 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
16744 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
16745 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
16746 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
16747 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
16748 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
16749 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
16750 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
16751 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
16752 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
16753 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
16754 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
16755 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
16756 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
16757 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
16758 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
16759 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
16760 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
16761 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
16762 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
16763 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
16764 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
16765 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
16766 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
16767 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
16768 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
16769 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
16770 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
16771 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
16772 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
16773 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
16774 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
16775 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
16776 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
16777 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
16778 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
16779 0x2d02ef8d
16780 @};
16781 unsigned char *end;
16782
16783 crc = ~crc & 0xffffffff;
16784 for (end = buf + len; buf < end; ++buf)
16785 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 16786 return ~crc & 0xffffffff;
5b5d99cf
JB
16787@}
16788@end smallexample
16789
c7e83d54
EZ
16790@noindent
16791This computation does not apply to the ``build ID'' method.
16792
608e2dbb
TT
16793@node MiniDebugInfo
16794@section Debugging information in a special section
16795@cindex separate debug sections
16796@cindex @samp{.gnu_debugdata} section
16797
16798Some systems ship pre-built executables and libraries that have a
16799special @samp{.gnu_debugdata} section. This feature is called
16800@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
16801is used to supply extra symbols for backtraces.
16802
16803The intent of this section is to provide extra minimal debugging
16804information for use in simple backtraces. It is not intended to be a
16805replacement for full separate debugging information (@pxref{Separate
16806Debug Files}). The example below shows the intended use; however,
16807@value{GDBN} does not currently put restrictions on what sort of
16808debugging information might be included in the section.
16809
16810@value{GDBN} has support for this extension. If the section exists,
16811then it is used provided that no other source of debugging information
16812can be found, and that @value{GDBN} was configured with LZMA support.
16813
16814This section can be easily created using @command{objcopy} and other
16815standard utilities:
16816
16817@smallexample
16818# Extract the dynamic symbols from the main binary, there is no need
16819# to also have these in the normal symbol table
16820nm -D @var{binary} --format=posix --defined-only \
16821 | awk '@{ print $1 @}' | sort > dynsyms
16822
16823# Extract all the text (i.e. function) symbols from the debuginfo .
16824nm @var{binary} --format=posix --defined-only \
16825 | awk '@{ if ($2 == "T" || $2 == "t") print $1 @}' \
16826 | sort > funcsyms
16827
16828# Keep all the function symbols not already in the dynamic symbol
16829# table.
16830comm -13 dynsyms funcsyms > keep_symbols
16831
16832# Copy the full debuginfo, keeping only a minimal set of symbols and
16833# removing some unnecessary sections.
16834objcopy -S --remove-section .gdb_index --remove-section .comment \
16835 --keep-symbols=keep_symbols @var{binary} mini_debuginfo
16836
16837# Inject the compressed data into the .gnu_debugdata section of the
16838# original binary.
16839xz mini_debuginfo
16840objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
16841@end smallexample
5b5d99cf 16842
9291a0cd
TT
16843@node Index Files
16844@section Index Files Speed Up @value{GDBN}
16845@cindex index files
16846@cindex @samp{.gdb_index} section
16847
16848When @value{GDBN} finds a symbol file, it scans the symbols in the
16849file in order to construct an internal symbol table. This lets most
16850@value{GDBN} operations work quickly---at the cost of a delay early
16851on. For large programs, this delay can be quite lengthy, so
16852@value{GDBN} provides a way to build an index, which speeds up
16853startup.
16854
16855The index is stored as a section in the symbol file. @value{GDBN} can
16856write the index to a file, then you can put it into the symbol file
16857using @command{objcopy}.
16858
16859To create an index file, use the @code{save gdb-index} command:
16860
16861@table @code
16862@item save gdb-index @var{directory}
16863@kindex save gdb-index
16864Create an index file for each symbol file currently known by
16865@value{GDBN}. Each file is named after its corresponding symbol file,
16866with @samp{.gdb-index} appended, and is written into the given
16867@var{directory}.
16868@end table
16869
16870Once you have created an index file you can merge it into your symbol
16871file, here named @file{symfile}, using @command{objcopy}:
16872
16873@smallexample
16874$ objcopy --add-section .gdb_index=symfile.gdb-index \
16875 --set-section-flags .gdb_index=readonly symfile symfile
16876@end smallexample
16877
e615022a
DE
16878@value{GDBN} will normally ignore older versions of @file{.gdb_index}
16879sections that have been deprecated. Usually they are deprecated because
16880they are missing a new feature or have performance issues.
16881To tell @value{GDBN} to use a deprecated index section anyway
16882specify @code{set use-deprecated-index-sections on}.
16883The default is @code{off}.
16884This can speed up startup, but may result in some functionality being lost.
16885@xref{Index Section Format}.
16886
16887@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
16888must be done before gdb reads the file. The following will not work:
16889
16890@smallexample
16891$ gdb -ex "set use-deprecated-index-sections on" <program>
16892@end smallexample
16893
16894Instead you must do, for example,
16895
16896@smallexample
16897$ gdb -iex "set use-deprecated-index-sections on" <program>
16898@end smallexample
16899
9291a0cd
TT
16900There are currently some limitation on indices. They only work when
16901for DWARF debugging information, not stabs. And, they do not
16902currently work for programs using Ada.
16903
6d2ebf8b 16904@node Symbol Errors
79a6e687 16905@section Errors Reading Symbol Files
c906108c
SS
16906
16907While reading a symbol file, @value{GDBN} occasionally encounters problems,
16908such as symbol types it does not recognize, or known bugs in compiler
16909output. By default, @value{GDBN} does not notify you of such problems, since
16910they are relatively common and primarily of interest to people
16911debugging compilers. If you are interested in seeing information
16912about ill-constructed symbol tables, you can either ask @value{GDBN} to print
16913only one message about each such type of problem, no matter how many
16914times the problem occurs; or you can ask @value{GDBN} to print more messages,
16915to see how many times the problems occur, with the @code{set
79a6e687
BW
16916complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
16917Messages}).
c906108c
SS
16918
16919The messages currently printed, and their meanings, include:
16920
16921@table @code
16922@item inner block not inside outer block in @var{symbol}
16923
16924The symbol information shows where symbol scopes begin and end
16925(such as at the start of a function or a block of statements). This
16926error indicates that an inner scope block is not fully contained
16927in its outer scope blocks.
16928
16929@value{GDBN} circumvents the problem by treating the inner block as if it had
16930the same scope as the outer block. In the error message, @var{symbol}
16931may be shown as ``@code{(don't know)}'' if the outer block is not a
16932function.
16933
16934@item block at @var{address} out of order
16935
16936The symbol information for symbol scope blocks should occur in
16937order of increasing addresses. This error indicates that it does not
16938do so.
16939
16940@value{GDBN} does not circumvent this problem, and has trouble
16941locating symbols in the source file whose symbols it is reading. (You
16942can often determine what source file is affected by specifying
79a6e687
BW
16943@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
16944Messages}.)
c906108c
SS
16945
16946@item bad block start address patched
16947
16948The symbol information for a symbol scope block has a start address
16949smaller than the address of the preceding source line. This is known
16950to occur in the SunOS 4.1.1 (and earlier) C compiler.
16951
16952@value{GDBN} circumvents the problem by treating the symbol scope block as
16953starting on the previous source line.
16954
16955@item bad string table offset in symbol @var{n}
16956
16957@cindex foo
16958Symbol number @var{n} contains a pointer into the string table which is
16959larger than the size of the string table.
16960
16961@value{GDBN} circumvents the problem by considering the symbol to have the
16962name @code{foo}, which may cause other problems if many symbols end up
16963with this name.
16964
16965@item unknown symbol type @code{0x@var{nn}}
16966
7a292a7a
SS
16967The symbol information contains new data types that @value{GDBN} does
16968not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 16969uncomprehended information, in hexadecimal.
c906108c 16970
7a292a7a
SS
16971@value{GDBN} circumvents the error by ignoring this symbol information.
16972This usually allows you to debug your program, though certain symbols
c906108c 16973are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
16974debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
16975on @code{complain}, then go up to the function @code{read_dbx_symtab}
16976and examine @code{*bufp} to see the symbol.
c906108c
SS
16977
16978@item stub type has NULL name
c906108c 16979
7a292a7a 16980@value{GDBN} could not find the full definition for a struct or class.
c906108c 16981
7a292a7a 16982@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 16983The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
16984information that recent versions of the compiler should have output for
16985it.
c906108c
SS
16986
16987@item info mismatch between compiler and debugger
16988
16989@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 16990
c906108c
SS
16991@end table
16992
b14b1491
TT
16993@node Data Files
16994@section GDB Data Files
16995
16996@cindex prefix for data files
16997@value{GDBN} will sometimes read an auxiliary data file. These files
16998are kept in a directory known as the @dfn{data directory}.
16999
17000You can set the data directory's name, and view the name @value{GDBN}
17001is currently using.
17002
17003@table @code
17004@kindex set data-directory
17005@item set data-directory @var{directory}
17006Set the directory which @value{GDBN} searches for auxiliary data files
17007to @var{directory}.
17008
17009@kindex show data-directory
17010@item show data-directory
17011Show the directory @value{GDBN} searches for auxiliary data files.
17012@end table
17013
17014@cindex default data directory
17015@cindex @samp{--with-gdb-datadir}
17016You can set the default data directory by using the configure-time
17017@samp{--with-gdb-datadir} option. If the data directory is inside
17018@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17019@samp{--exec-prefix}), then the default data directory will be updated
17020automatically if the installed @value{GDBN} is moved to a new
17021location.
17022
aae1c79a
DE
17023The data directory may also be specified with the
17024@code{--data-directory} command line option.
17025@xref{Mode Options}.
17026
6d2ebf8b 17027@node Targets
c906108c 17028@chapter Specifying a Debugging Target
7a292a7a 17029
c906108c 17030@cindex debugging target
c906108c 17031A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
17032
17033Often, @value{GDBN} runs in the same host environment as your program;
17034in that case, the debugging target is specified as a side effect when
17035you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
17036flexibility---for example, running @value{GDBN} on a physically separate
17037host, or controlling a standalone system over a serial port or a
53a5351d
JM
17038realtime system over a TCP/IP connection---you can use the @code{target}
17039command to specify one of the target types configured for @value{GDBN}
79a6e687 17040(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 17041
a8f24a35
EZ
17042@cindex target architecture
17043It is possible to build @value{GDBN} for several different @dfn{target
17044architectures}. When @value{GDBN} is built like that, you can choose
17045one of the available architectures with the @kbd{set architecture}
17046command.
17047
17048@table @code
17049@kindex set architecture
17050@kindex show architecture
17051@item set architecture @var{arch}
17052This command sets the current target architecture to @var{arch}. The
17053value of @var{arch} can be @code{"auto"}, in addition to one of the
17054supported architectures.
17055
17056@item show architecture
17057Show the current target architecture.
9c16f35a
EZ
17058
17059@item set processor
17060@itemx processor
17061@kindex set processor
17062@kindex show processor
17063These are alias commands for, respectively, @code{set architecture}
17064and @code{show architecture}.
a8f24a35
EZ
17065@end table
17066
c906108c
SS
17067@menu
17068* Active Targets:: Active targets
17069* Target Commands:: Commands for managing targets
c906108c 17070* Byte Order:: Choosing target byte order
c906108c
SS
17071@end menu
17072
6d2ebf8b 17073@node Active Targets
79a6e687 17074@section Active Targets
7a292a7a 17075
c906108c
SS
17076@cindex stacking targets
17077@cindex active targets
17078@cindex multiple targets
17079
8ea5bce5 17080There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
17081recording sessions. Core files belong to the process class, making core file
17082and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
17083on multiple active targets, one in each class. This allows you to (for
17084example) start a process and inspect its activity, while still having access to
17085the executable file after the process finishes. Or if you start process
17086recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
17087presented a virtual layer of the recording target, while the process target
17088remains stopped at the chronologically last point of the process execution.
17089
17090Use the @code{core-file} and @code{exec-file} commands to select a new core
17091file or executable target (@pxref{Files, ,Commands to Specify Files}). To
17092specify as a target a process that is already running, use the @code{attach}
17093command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 17094
6d2ebf8b 17095@node Target Commands
79a6e687 17096@section Commands for Managing Targets
c906108c
SS
17097
17098@table @code
17099@item target @var{type} @var{parameters}
7a292a7a
SS
17100Connects the @value{GDBN} host environment to a target machine or
17101process. A target is typically a protocol for talking to debugging
17102facilities. You use the argument @var{type} to specify the type or
17103protocol of the target machine.
c906108c
SS
17104
17105Further @var{parameters} are interpreted by the target protocol, but
17106typically include things like device names or host names to connect
17107with, process numbers, and baud rates.
c906108c
SS
17108
17109The @code{target} command does not repeat if you press @key{RET} again
17110after executing the command.
17111
17112@kindex help target
17113@item help target
17114Displays the names of all targets available. To display targets
17115currently selected, use either @code{info target} or @code{info files}
79a6e687 17116(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
17117
17118@item help target @var{name}
17119Describe a particular target, including any parameters necessary to
17120select it.
17121
17122@kindex set gnutarget
17123@item set gnutarget @var{args}
5d161b24 17124@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 17125knows whether it is reading an @dfn{executable},
5d161b24
DB
17126a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
17127with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
17128with @code{gnutarget} the @code{target} refers to a program, not a machine.
17129
d4f3574e 17130@quotation
c906108c
SS
17131@emph{Warning:} To specify a file format with @code{set gnutarget},
17132you must know the actual BFD name.
d4f3574e 17133@end quotation
c906108c 17134
d4f3574e 17135@noindent
79a6e687 17136@xref{Files, , Commands to Specify Files}.
c906108c 17137
5d161b24 17138@kindex show gnutarget
c906108c
SS
17139@item show gnutarget
17140Use the @code{show gnutarget} command to display what file format
17141@code{gnutarget} is set to read. If you have not set @code{gnutarget},
17142@value{GDBN} will determine the file format for each file automatically,
17143and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
17144@end table
17145
4644b6e3 17146@cindex common targets
c906108c
SS
17147Here are some common targets (available, or not, depending on the GDB
17148configuration):
c906108c
SS
17149
17150@table @code
4644b6e3 17151@kindex target
c906108c 17152@item target exec @var{program}
4644b6e3 17153@cindex executable file target
c906108c
SS
17154An executable file. @samp{target exec @var{program}} is the same as
17155@samp{exec-file @var{program}}.
17156
c906108c 17157@item target core @var{filename}
4644b6e3 17158@cindex core dump file target
c906108c
SS
17159A core dump file. @samp{target core @var{filename}} is the same as
17160@samp{core-file @var{filename}}.
c906108c 17161
1a10341b 17162@item target remote @var{medium}
4644b6e3 17163@cindex remote target
1a10341b
JB
17164A remote system connected to @value{GDBN} via a serial line or network
17165connection. This command tells @value{GDBN} to use its own remote
17166protocol over @var{medium} for debugging. @xref{Remote Debugging}.
17167
17168For example, if you have a board connected to @file{/dev/ttya} on the
17169machine running @value{GDBN}, you could say:
17170
17171@smallexample
17172target remote /dev/ttya
17173@end smallexample
17174
17175@code{target remote} supports the @code{load} command. This is only
17176useful if you have some other way of getting the stub to the target
17177system, and you can put it somewhere in memory where it won't get
17178clobbered by the download.
c906108c 17179
ee8e71d4 17180@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 17181@cindex built-in simulator target
2df3850c 17182Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 17183In general,
474c8240 17184@smallexample
104c1213
JM
17185 target sim
17186 load
17187 run
474c8240 17188@end smallexample
d4f3574e 17189@noindent
104c1213 17190works; however, you cannot assume that a specific memory map, device
d4f3574e 17191drivers, or even basic I/O is available, although some simulators do
104c1213
JM
17192provide these. For info about any processor-specific simulator details,
17193see the appropriate section in @ref{Embedded Processors, ,Embedded
17194Processors}.
17195
c906108c
SS
17196@end table
17197
104c1213 17198Some configurations may include these targets as well:
c906108c
SS
17199
17200@table @code
17201
c906108c 17202@item target nrom @var{dev}
4644b6e3 17203@cindex NetROM ROM emulator target
c906108c
SS
17204NetROM ROM emulator. This target only supports downloading.
17205
c906108c
SS
17206@end table
17207
5d161b24 17208Different targets are available on different configurations of @value{GDBN};
c906108c 17209your configuration may have more or fewer targets.
c906108c 17210
721c2651
EZ
17211Many remote targets require you to download the executable's code once
17212you've successfully established a connection. You may wish to control
3d00d119
DJ
17213various aspects of this process.
17214
17215@table @code
721c2651
EZ
17216
17217@item set hash
17218@kindex set hash@r{, for remote monitors}
17219@cindex hash mark while downloading
17220This command controls whether a hash mark @samp{#} is displayed while
17221downloading a file to the remote monitor. If on, a hash mark is
17222displayed after each S-record is successfully downloaded to the
17223monitor.
17224
17225@item show hash
17226@kindex show hash@r{, for remote monitors}
17227Show the current status of displaying the hash mark.
17228
17229@item set debug monitor
17230@kindex set debug monitor
17231@cindex display remote monitor communications
17232Enable or disable display of communications messages between
17233@value{GDBN} and the remote monitor.
17234
17235@item show debug monitor
17236@kindex show debug monitor
17237Show the current status of displaying communications between
17238@value{GDBN} and the remote monitor.
a8f24a35 17239@end table
c906108c
SS
17240
17241@table @code
17242
17243@kindex load @var{filename}
17244@item load @var{filename}
8edfe269 17245@anchor{load}
c906108c
SS
17246Depending on what remote debugging facilities are configured into
17247@value{GDBN}, the @code{load} command may be available. Where it exists, it
17248is meant to make @var{filename} (an executable) available for debugging
17249on the remote system---by downloading, or dynamic linking, for example.
17250@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
17251the @code{add-symbol-file} command.
17252
17253If your @value{GDBN} does not have a @code{load} command, attempting to
17254execute it gets the error message ``@code{You can't do that when your
17255target is @dots{}}''
c906108c
SS
17256
17257The file is loaded at whatever address is specified in the executable.
17258For some object file formats, you can specify the load address when you
17259link the program; for other formats, like a.out, the object file format
17260specifies a fixed address.
17261@c FIXME! This would be a good place for an xref to the GNU linker doc.
17262
68437a39
DJ
17263Depending on the remote side capabilities, @value{GDBN} may be able to
17264load programs into flash memory.
17265
c906108c
SS
17266@code{load} does not repeat if you press @key{RET} again after using it.
17267@end table
17268
6d2ebf8b 17269@node Byte Order
79a6e687 17270@section Choosing Target Byte Order
7a292a7a 17271
c906108c
SS
17272@cindex choosing target byte order
17273@cindex target byte order
c906108c 17274
eb17f351 17275Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
17276offer the ability to run either big-endian or little-endian byte
17277orders. Usually the executable or symbol will include a bit to
17278designate the endian-ness, and you will not need to worry about
17279which to use. However, you may still find it useful to adjust
d4f3574e 17280@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
17281
17282@table @code
4644b6e3 17283@kindex set endian
c906108c
SS
17284@item set endian big
17285Instruct @value{GDBN} to assume the target is big-endian.
17286
c906108c
SS
17287@item set endian little
17288Instruct @value{GDBN} to assume the target is little-endian.
17289
c906108c
SS
17290@item set endian auto
17291Instruct @value{GDBN} to use the byte order associated with the
17292executable.
17293
17294@item show endian
17295Display @value{GDBN}'s current idea of the target byte order.
17296
17297@end table
17298
17299Note that these commands merely adjust interpretation of symbolic
17300data on the host, and that they have absolutely no effect on the
17301target system.
17302
ea35711c
DJ
17303
17304@node Remote Debugging
17305@chapter Debugging Remote Programs
c906108c
SS
17306@cindex remote debugging
17307
17308If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
17309@value{GDBN} in the usual way, it is often useful to use remote debugging.
17310For example, you might use remote debugging on an operating system kernel,
c906108c
SS
17311or on a small system which does not have a general purpose operating system
17312powerful enough to run a full-featured debugger.
17313
17314Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
17315to make this work with particular debugging targets. In addition,
5d161b24 17316@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
17317but not specific to any particular target system) which you can use if you
17318write the remote stubs---the code that runs on the remote system to
17319communicate with @value{GDBN}.
17320
17321Other remote targets may be available in your
17322configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 17323
6b2f586d 17324@menu
07f31aa6 17325* Connecting:: Connecting to a remote target
a6b151f1 17326* File Transfer:: Sending files to a remote system
6b2f586d 17327* Server:: Using the gdbserver program
79a6e687
BW
17328* Remote Configuration:: Remote configuration
17329* Remote Stub:: Implementing a remote stub
6b2f586d
AC
17330@end menu
17331
07f31aa6 17332@node Connecting
79a6e687 17333@section Connecting to a Remote Target
07f31aa6
DJ
17334
17335On the @value{GDBN} host machine, you will need an unstripped copy of
d3e8051b 17336your program, since @value{GDBN} needs symbol and debugging information.
07f31aa6
DJ
17337Start up @value{GDBN} as usual, using the name of the local copy of your
17338program as the first argument.
17339
86941c27
JB
17340@cindex @code{target remote}
17341@value{GDBN} can communicate with the target over a serial line, or
17342over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
17343each case, @value{GDBN} uses the same protocol for debugging your
17344program; only the medium carrying the debugging packets varies. The
17345@code{target remote} command establishes a connection to the target.
17346Its arguments indicate which medium to use:
17347
17348@table @code
17349
17350@item target remote @var{serial-device}
07f31aa6 17351@cindex serial line, @code{target remote}
86941c27
JB
17352Use @var{serial-device} to communicate with the target. For example,
17353to use a serial line connected to the device named @file{/dev/ttyb}:
17354
17355@smallexample
17356target remote /dev/ttyb
17357@end smallexample
17358
07f31aa6
DJ
17359If you're using a serial line, you may want to give @value{GDBN} the
17360@w{@samp{--baud}} option, or use the @code{set remotebaud} command
79a6e687 17361(@pxref{Remote Configuration, set remotebaud}) before the
9c16f35a 17362@code{target} command.
07f31aa6 17363
86941c27
JB
17364@item target remote @code{@var{host}:@var{port}}
17365@itemx target remote @code{tcp:@var{host}:@var{port}}
17366@cindex @acronym{TCP} port, @code{target remote}
17367Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
17368The @var{host} may be either a host name or a numeric @acronym{IP}
17369address; @var{port} must be a decimal number. The @var{host} could be
17370the target machine itself, if it is directly connected to the net, or
17371it might be a terminal server which in turn has a serial line to the
17372target.
07f31aa6 17373
86941c27
JB
17374For example, to connect to port 2828 on a terminal server named
17375@code{manyfarms}:
07f31aa6
DJ
17376
17377@smallexample
17378target remote manyfarms:2828
17379@end smallexample
17380
86941c27
JB
17381If your remote target is actually running on the same machine as your
17382debugger session (e.g.@: a simulator for your target running on the
17383same host), you can omit the hostname. For example, to connect to
17384port 1234 on your local machine:
07f31aa6
DJ
17385
17386@smallexample
17387target remote :1234
17388@end smallexample
17389@noindent
17390
17391Note that the colon is still required here.
17392
86941c27
JB
17393@item target remote @code{udp:@var{host}:@var{port}}
17394@cindex @acronym{UDP} port, @code{target remote}
17395Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
17396connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
17397
17398@smallexample
17399target remote udp:manyfarms:2828
17400@end smallexample
17401
86941c27
JB
17402When using a @acronym{UDP} connection for remote debugging, you should
17403keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
17404can silently drop packets on busy or unreliable networks, which will
17405cause havoc with your debugging session.
17406
66b8c7f6
JB
17407@item target remote | @var{command}
17408@cindex pipe, @code{target remote} to
17409Run @var{command} in the background and communicate with it using a
17410pipe. The @var{command} is a shell command, to be parsed and expanded
17411by the system's command shell, @code{/bin/sh}; it should expect remote
17412protocol packets on its standard input, and send replies on its
17413standard output. You could use this to run a stand-alone simulator
17414that speaks the remote debugging protocol, to make net connections
17415using programs like @code{ssh}, or for other similar tricks.
17416
17417If @var{command} closes its standard output (perhaps by exiting),
17418@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
17419program has already exited, this will have no effect.)
17420
86941c27 17421@end table
07f31aa6 17422
86941c27 17423Once the connection has been established, you can use all the usual
8edfe269
DJ
17424commands to examine and change data. The remote program is already
17425running; you can use @kbd{step} and @kbd{continue}, and you do not
17426need to use @kbd{run}.
07f31aa6
DJ
17427
17428@cindex interrupting remote programs
17429@cindex remote programs, interrupting
17430Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 17431interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
17432program. This may or may not succeed, depending in part on the hardware
17433and the serial drivers the remote system uses. If you type the
17434interrupt character once again, @value{GDBN} displays this prompt:
17435
17436@smallexample
17437Interrupted while waiting for the program.
17438Give up (and stop debugging it)? (y or n)
17439@end smallexample
17440
17441If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
17442(If you decide you want to try again later, you can use @samp{target
17443remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
17444goes back to waiting.
17445
17446@table @code
17447@kindex detach (remote)
17448@item detach
17449When you have finished debugging the remote program, you can use the
17450@code{detach} command to release it from @value{GDBN} control.
17451Detaching from the target normally resumes its execution, but the results
17452will depend on your particular remote stub. After the @code{detach}
17453command, @value{GDBN} is free to connect to another target.
17454
17455@kindex disconnect
17456@item disconnect
17457The @code{disconnect} command behaves like @code{detach}, except that
17458the target is generally not resumed. It will wait for @value{GDBN}
17459(this instance or another one) to connect and continue debugging. After
17460the @code{disconnect} command, @value{GDBN} is again free to connect to
17461another target.
09d4efe1
EZ
17462
17463@cindex send command to remote monitor
fad38dfa
EZ
17464@cindex extend @value{GDBN} for remote targets
17465@cindex add new commands for external monitor
09d4efe1
EZ
17466@kindex monitor
17467@item monitor @var{cmd}
fad38dfa
EZ
17468This command allows you to send arbitrary commands directly to the
17469remote monitor. Since @value{GDBN} doesn't care about the commands it
17470sends like this, this command is the way to extend @value{GDBN}---you
17471can add new commands that only the external monitor will understand
17472and implement.
07f31aa6
DJ
17473@end table
17474
a6b151f1
DJ
17475@node File Transfer
17476@section Sending files to a remote system
17477@cindex remote target, file transfer
17478@cindex file transfer
17479@cindex sending files to remote systems
17480
17481Some remote targets offer the ability to transfer files over the same
17482connection used to communicate with @value{GDBN}. This is convenient
17483for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
17484running @code{gdbserver} over a network interface. For other targets,
17485e.g.@: embedded devices with only a single serial port, this may be
17486the only way to upload or download files.
17487
17488Not all remote targets support these commands.
17489
17490@table @code
17491@kindex remote put
17492@item remote put @var{hostfile} @var{targetfile}
17493Copy file @var{hostfile} from the host system (the machine running
17494@value{GDBN}) to @var{targetfile} on the target system.
17495
17496@kindex remote get
17497@item remote get @var{targetfile} @var{hostfile}
17498Copy file @var{targetfile} from the target system to @var{hostfile}
17499on the host system.
17500
17501@kindex remote delete
17502@item remote delete @var{targetfile}
17503Delete @var{targetfile} from the target system.
17504
17505@end table
17506
6f05cf9f 17507@node Server
79a6e687 17508@section Using the @code{gdbserver} Program
6f05cf9f
AC
17509
17510@kindex gdbserver
17511@cindex remote connection without stubs
17512@code{gdbserver} is a control program for Unix-like systems, which
17513allows you to connect your program with a remote @value{GDBN} via
17514@code{target remote}---but without linking in the usual debugging stub.
17515
17516@code{gdbserver} is not a complete replacement for the debugging stubs,
17517because it requires essentially the same operating-system facilities
17518that @value{GDBN} itself does. In fact, a system that can run
17519@code{gdbserver} to connect to a remote @value{GDBN} could also run
17520@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
17521because it is a much smaller program than @value{GDBN} itself. It is
17522also easier to port than all of @value{GDBN}, so you may be able to get
17523started more quickly on a new system by using @code{gdbserver}.
17524Finally, if you develop code for real-time systems, you may find that
17525the tradeoffs involved in real-time operation make it more convenient to
17526do as much development work as possible on another system, for example
17527by cross-compiling. You can use @code{gdbserver} to make a similar
17528choice for debugging.
17529
17530@value{GDBN} and @code{gdbserver} communicate via either a serial line
17531or a TCP connection, using the standard @value{GDBN} remote serial
17532protocol.
17533
2d717e4f
DJ
17534@quotation
17535@emph{Warning:} @code{gdbserver} does not have any built-in security.
17536Do not run @code{gdbserver} connected to any public network; a
17537@value{GDBN} connection to @code{gdbserver} provides access to the
17538target system with the same privileges as the user running
17539@code{gdbserver}.
17540@end quotation
17541
17542@subsection Running @code{gdbserver}
17543@cindex arguments, to @code{gdbserver}
d9b1a651 17544@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
17545
17546Run @code{gdbserver} on the target system. You need a copy of the
17547program you want to debug, including any libraries it requires.
6f05cf9f
AC
17548@code{gdbserver} does not need your program's symbol table, so you can
17549strip the program if necessary to save space. @value{GDBN} on the host
17550system does all the symbol handling.
17551
17552To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 17553the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
17554syntax is:
17555
17556@smallexample
17557target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
17558@end smallexample
17559
e0f9f062
DE
17560@var{comm} is either a device name (to use a serial line), or a TCP
17561hostname and portnumber, or @code{-} or @code{stdio} to use
17562stdin/stdout of @code{gdbserver}.
17563For example, to debug Emacs with the argument
6f05cf9f
AC
17564@samp{foo.txt} and communicate with @value{GDBN} over the serial port
17565@file{/dev/com1}:
17566
17567@smallexample
17568target> gdbserver /dev/com1 emacs foo.txt
17569@end smallexample
17570
17571@code{gdbserver} waits passively for the host @value{GDBN} to communicate
17572with it.
17573
17574To use a TCP connection instead of a serial line:
17575
17576@smallexample
17577target> gdbserver host:2345 emacs foo.txt
17578@end smallexample
17579
17580The only difference from the previous example is the first argument,
17581specifying that you are communicating with the host @value{GDBN} via
17582TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
17583expect a TCP connection from machine @samp{host} to local TCP port 2345.
17584(Currently, the @samp{host} part is ignored.) You can choose any number
17585you want for the port number as long as it does not conflict with any
17586TCP ports already in use on the target system (for example, @code{23} is
17587reserved for @code{telnet}).@footnote{If you choose a port number that
17588conflicts with another service, @code{gdbserver} prints an error message
17589and exits.} You must use the same port number with the host @value{GDBN}
17590@code{target remote} command.
17591
e0f9f062
DE
17592The @code{stdio} connection is useful when starting @code{gdbserver}
17593with ssh:
17594
17595@smallexample
17596(gdb) target remote | ssh -T hostname gdbserver - hello
17597@end smallexample
17598
17599The @samp{-T} option to ssh is provided because we don't need a remote pty,
17600and we don't want escape-character handling. Ssh does this by default when
17601a command is provided, the flag is provided to make it explicit.
17602You could elide it if you want to.
17603
17604Programs started with stdio-connected gdbserver have @file{/dev/null} for
17605@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
17606display through a pipe connected to gdbserver.
17607Both @code{stdout} and @code{stderr} use the same pipe.
17608
2d717e4f 17609@subsubsection Attaching to a Running Program
d9b1a651
EZ
17610@cindex attach to a program, @code{gdbserver}
17611@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 17612
56460a61
DJ
17613On some targets, @code{gdbserver} can also attach to running programs.
17614This is accomplished via the @code{--attach} argument. The syntax is:
17615
17616@smallexample
2d717e4f 17617target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
17618@end smallexample
17619
17620@var{pid} is the process ID of a currently running process. It isn't necessary
17621to point @code{gdbserver} at a binary for the running process.
17622
b1fe9455 17623@pindex pidof
b1fe9455
DJ
17624You can debug processes by name instead of process ID if your target has the
17625@code{pidof} utility:
17626
17627@smallexample
2d717e4f 17628target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
17629@end smallexample
17630
f822c95b 17631In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
17632has multiple threads, most versions of @code{pidof} support the
17633@code{-s} option to only return the first process ID.
17634
2d717e4f 17635@subsubsection Multi-Process Mode for @code{gdbserver}
d9b1a651
EZ
17636@cindex @code{gdbserver}, multiple processes
17637@cindex multiple processes with @code{gdbserver}
2d717e4f
DJ
17638
17639When you connect to @code{gdbserver} using @code{target remote},
17640@code{gdbserver} debugs the specified program only once. When the
17641program exits, or you detach from it, @value{GDBN} closes the connection
17642and @code{gdbserver} exits.
17643
6e6c6f50 17644If you connect using @kbd{target extended-remote}, @code{gdbserver}
2d717e4f
DJ
17645enters multi-process mode. When the debugged program exits, or you
17646detach from it, @value{GDBN} stays connected to @code{gdbserver} even
17647though no program is running. The @code{run} and @code{attach}
17648commands instruct @code{gdbserver} to run or attach to a new program.
17649The @code{run} command uses @code{set remote exec-file} (@pxref{set
17650remote exec-file}) to select the program to run. Command line
17651arguments are supported, except for wildcard expansion and I/O
17652redirection (@pxref{Arguments}).
17653
d9b1a651 17654@cindex @option{--multi}, @code{gdbserver} option
2d717e4f
DJ
17655To start @code{gdbserver} without supplying an initial command to run
17656or process ID to attach, use the @option{--multi} command line option.
6e6c6f50 17657Then you can connect using @kbd{target extended-remote} and start
2d717e4f
DJ
17658the program you want to debug.
17659
03f2bd59
JK
17660In multi-process mode @code{gdbserver} does not automatically exit unless you
17661use the option @option{--once}. You can terminate it by using
17662@code{monitor exit} (@pxref{Monitor Commands for gdbserver}). Note that the
17663conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
17664connects to it (@kbd{target remote} or @kbd{target extended-remote}). The
17665@option{--multi} option to @code{gdbserver} has no influence on that.
17666
17667@subsubsection TCP port allocation lifecycle of @code{gdbserver}
17668
17669This section applies only when @code{gdbserver} is run to listen on a TCP port.
17670
17671@code{gdbserver} normally terminates after all of its debugged processes have
17672terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
17673extended-remote}, @code{gdbserver} stays running even with no processes left.
17674@value{GDBN} normally terminates the spawned debugged process on its exit,
17675which normally also terminates @code{gdbserver} in the @kbd{target remote}
17676mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
17677cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
17678stays running even in the @kbd{target remote} mode.
17679
17680When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
17681Such reconnecting is useful for features like @ref{disconnected tracing}. For
17682completeness, at most one @value{GDBN} can be connected at a time.
17683
17684@cindex @option{--once}, @code{gdbserver} option
17685By default, @code{gdbserver} keeps the listening TCP port open, so that
17686additional connections are possible. However, if you start @code{gdbserver}
17687with the @option{--once} option, it will stop listening for any further
17688connection attempts after connecting to the first @value{GDBN} session. This
17689means no further connections to @code{gdbserver} will be possible after the
17690first one. It also means @code{gdbserver} will terminate after the first
17691connection with remote @value{GDBN} has closed, even for unexpectedly closed
17692connections and even in the @kbd{target extended-remote} mode. The
17693@option{--once} option allows reusing the same port number for connecting to
17694multiple instances of @code{gdbserver} running on the same host, since each
17695instance closes its port after the first connection.
2d717e4f
DJ
17696
17697@subsubsection Other Command-Line Arguments for @code{gdbserver}
17698
d9b1a651 17699@cindex @option{--debug}, @code{gdbserver} option
62709adf 17700The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
17701status information about the debugging process.
17702@cindex @option{--remote-debug}, @code{gdbserver} option
17703The @option{--remote-debug} option tells @code{gdbserver} to display
62709adf
PA
17704remote protocol debug output. These options are intended for
17705@code{gdbserver} development and for bug reports to the developers.
2d717e4f 17706
d9b1a651 17707@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
17708The @option{--wrapper} option specifies a wrapper to launch programs
17709for debugging. The option should be followed by the name of the
17710wrapper, then any command-line arguments to pass to the wrapper, then
17711@kbd{--} indicating the end of the wrapper arguments.
17712
17713@code{gdbserver} runs the specified wrapper program with a combined
17714command line including the wrapper arguments, then the name of the
17715program to debug, then any arguments to the program. The wrapper
17716runs until it executes your program, and then @value{GDBN} gains control.
17717
17718You can use any program that eventually calls @code{execve} with
17719its arguments as a wrapper. Several standard Unix utilities do
17720this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
17721with @code{exec "$@@"} will also work.
17722
17723For example, you can use @code{env} to pass an environment variable to
17724the debugged program, without setting the variable in @code{gdbserver}'s
17725environment:
17726
17727@smallexample
17728$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
17729@end smallexample
17730
2d717e4f
DJ
17731@subsection Connecting to @code{gdbserver}
17732
17733Run @value{GDBN} on the host system.
17734
17735First make sure you have the necessary symbol files. Load symbols for
f822c95b
DJ
17736your application using the @code{file} command before you connect. Use
17737@code{set sysroot} to locate target libraries (unless your @value{GDBN}
2d717e4f 17738was compiled with the correct sysroot using @code{--with-sysroot}).
f822c95b
DJ
17739
17740The symbol file and target libraries must exactly match the executable
17741and libraries on the target, with one exception: the files on the host
17742system should not be stripped, even if the files on the target system
17743are. Mismatched or missing files will lead to confusing results
17744during debugging. On @sc{gnu}/Linux targets, mismatched or missing
17745files may also prevent @code{gdbserver} from debugging multi-threaded
17746programs.
17747
79a6e687 17748Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f
AC
17749For TCP connections, you must start up @code{gdbserver} prior to using
17750the @code{target remote} command. Otherwise you may get an error whose
17751text depends on the host system, but which usually looks something like
2d717e4f 17752@samp{Connection refused}. Don't use the @code{load}
397ca115 17753command in @value{GDBN} when using @code{gdbserver}, since the program is
f822c95b 17754already on the target.
07f31aa6 17755
79a6e687 17756@subsection Monitor Commands for @code{gdbserver}
c74d0ad8 17757@cindex monitor commands, for @code{gdbserver}
2d717e4f 17758@anchor{Monitor Commands for gdbserver}
c74d0ad8
DJ
17759
17760During a @value{GDBN} session using @code{gdbserver}, you can use the
17761@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 17762Here are the available commands.
c74d0ad8
DJ
17763
17764@table @code
17765@item monitor help
17766List the available monitor commands.
17767
17768@item monitor set debug 0
17769@itemx monitor set debug 1
17770Disable or enable general debugging messages.
17771
17772@item monitor set remote-debug 0
17773@itemx monitor set remote-debug 1
17774Disable or enable specific debugging messages associated with the remote
17775protocol (@pxref{Remote Protocol}).
17776
cdbfd419
PP
17777@item monitor set libthread-db-search-path [PATH]
17778@cindex gdbserver, search path for @code{libthread_db}
17779When this command is issued, @var{path} is a colon-separated list of
17780directories to search for @code{libthread_db} (@pxref{Threads,,set
17781libthread-db-search-path}). If you omit @var{path},
84e578fb 17782@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 17783
98a5dd13
DE
17784The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
17785not supported in @code{gdbserver}.
17786
2d717e4f
DJ
17787@item monitor exit
17788Tell gdbserver to exit immediately. This command should be followed by
17789@code{disconnect} to close the debugging session. @code{gdbserver} will
17790detach from any attached processes and kill any processes it created.
17791Use @code{monitor exit} to terminate @code{gdbserver} at the end
17792of a multi-process mode debug session.
17793
c74d0ad8
DJ
17794@end table
17795
fa593d66
PA
17796@subsection Tracepoints support in @code{gdbserver}
17797@cindex tracepoints support in @code{gdbserver}
17798
0fb4aa4b
PA
17799On some targets, @code{gdbserver} supports tracepoints, fast
17800tracepoints and static tracepoints.
fa593d66 17801
0fb4aa4b 17802For fast or static tracepoints to work, a special library called the
fa593d66
PA
17803@dfn{in-process agent} (IPA), must be loaded in the inferior process.
17804This library is built and distributed as an integral part of
0fb4aa4b
PA
17805@code{gdbserver}. In addition, support for static tracepoints
17806requires building the in-process agent library with static tracepoints
17807support. At present, the UST (LTTng Userspace Tracer,
17808@url{http://lttng.org/ust}) tracing engine is supported. This support
17809is automatically available if UST development headers are found in the
17810standard include path when @code{gdbserver} is built, or if
17811@code{gdbserver} was explicitly configured using @option{--with-ust}
17812to point at such headers. You can explicitly disable the support
17813using @option{--with-ust=no}.
fa593d66
PA
17814
17815There are several ways to load the in-process agent in your program:
17816
17817@table @code
17818@item Specifying it as dependency at link time
17819
17820You can link your program dynamically with the in-process agent
17821library. On most systems, this is accomplished by adding
17822@code{-linproctrace} to the link command.
17823
17824@item Using the system's preloading mechanisms
17825
17826You can force loading the in-process agent at startup time by using
17827your system's support for preloading shared libraries. Many Unixes
17828support the concept of preloading user defined libraries. In most
17829cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
17830in the environment. See also the description of @code{gdbserver}'s
17831@option{--wrapper} command line option.
17832
17833@item Using @value{GDBN} to force loading the agent at run time
17834
17835On some systems, you can force the inferior to load a shared library,
17836by calling a dynamic loader function in the inferior that takes care
17837of dynamically looking up and loading a shared library. On most Unix
17838systems, the function is @code{dlopen}. You'll use the @code{call}
17839command for that. For example:
17840
17841@smallexample
17842(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
17843@end smallexample
17844
17845Note that on most Unix systems, for the @code{dlopen} function to be
17846available, the program needs to be linked with @code{-ldl}.
17847@end table
17848
17849On systems that have a userspace dynamic loader, like most Unix
17850systems, when you connect to @code{gdbserver} using @code{target
17851remote}, you'll find that the program is stopped at the dynamic
17852loader's entry point, and no shared library has been loaded in the
17853program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
17854case, before being able to use any of the fast or static tracepoints
17855features, you need to let the loader run and load the shared
17856libraries. The simplest way to do that is to run the program to the
17857main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
17858@code{gdbserver} like so:
17859
17860@smallexample
17861$ gdbserver :9999 myprogram
17862@end smallexample
17863
17864Start GDB and connect to @code{gdbserver} like so, and run to main:
17865
17866@smallexample
17867$ gdb myprogram
17868(@value{GDBP}) target remote myhost:9999
178690x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
17870(@value{GDBP}) b main
17871(@value{GDBP}) continue
17872@end smallexample
17873
17874The in-process tracing agent library should now be loaded into the
17875process; you can confirm it with the @code{info sharedlibrary}
17876command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
17877process. You are now ready to install fast tracepoints, list static
17878tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
17879tracing.
17880
79a6e687
BW
17881@node Remote Configuration
17882@section Remote Configuration
501eef12 17883
9c16f35a
EZ
17884@kindex set remote
17885@kindex show remote
17886This section documents the configuration options available when
17887debugging remote programs. For the options related to the File I/O
fc320d37 17888extensions of the remote protocol, see @ref{system,
9c16f35a 17889system-call-allowed}.
501eef12
AC
17890
17891@table @code
9c16f35a 17892@item set remoteaddresssize @var{bits}
d3e8051b 17893@cindex address size for remote targets
9c16f35a
EZ
17894@cindex bits in remote address
17895Set the maximum size of address in a memory packet to the specified
17896number of bits. @value{GDBN} will mask off the address bits above
17897that number, when it passes addresses to the remote target. The
17898default value is the number of bits in the target's address.
17899
17900@item show remoteaddresssize
17901Show the current value of remote address size in bits.
17902
17903@item set remotebaud @var{n}
17904@cindex baud rate for remote targets
17905Set the baud rate for the remote serial I/O to @var{n} baud. The
17906value is used to set the speed of the serial port used for debugging
17907remote targets.
17908
17909@item show remotebaud
17910Show the current speed of the remote connection.
17911
17912@item set remotebreak
17913@cindex interrupt remote programs
17914@cindex BREAK signal instead of Ctrl-C
9a6253be 17915@anchor{set remotebreak}
9c16f35a 17916If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 17917when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 17918on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
17919character instead. The default is off, since most remote systems
17920expect to see @samp{Ctrl-C} as the interrupt signal.
17921
17922@item show remotebreak
17923Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
17924interrupt the remote program.
17925
23776285
MR
17926@item set remoteflow on
17927@itemx set remoteflow off
17928@kindex set remoteflow
17929Enable or disable hardware flow control (@code{RTS}/@code{CTS})
17930on the serial port used to communicate to the remote target.
17931
17932@item show remoteflow
17933@kindex show remoteflow
17934Show the current setting of hardware flow control.
17935
9c16f35a
EZ
17936@item set remotelogbase @var{base}
17937Set the base (a.k.a.@: radix) of logging serial protocol
17938communications to @var{base}. Supported values of @var{base} are:
17939@code{ascii}, @code{octal}, and @code{hex}. The default is
17940@code{ascii}.
17941
17942@item show remotelogbase
17943Show the current setting of the radix for logging remote serial
17944protocol.
17945
17946@item set remotelogfile @var{file}
17947@cindex record serial communications on file
17948Record remote serial communications on the named @var{file}. The
17949default is not to record at all.
17950
17951@item show remotelogfile.
17952Show the current setting of the file name on which to record the
17953serial communications.
17954
17955@item set remotetimeout @var{num}
17956@cindex timeout for serial communications
17957@cindex remote timeout
17958Set the timeout limit to wait for the remote target to respond to
17959@var{num} seconds. The default is 2 seconds.
17960
17961@item show remotetimeout
17962Show the current number of seconds to wait for the remote target
17963responses.
17964
17965@cindex limit hardware breakpoints and watchpoints
17966@cindex remote target, limit break- and watchpoints
501eef12
AC
17967@anchor{set remote hardware-watchpoint-limit}
17968@anchor{set remote hardware-breakpoint-limit}
17969@item set remote hardware-watchpoint-limit @var{limit}
17970@itemx set remote hardware-breakpoint-limit @var{limit}
17971Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
17972watchpoints. A limit of -1, the default, is treated as unlimited.
2d717e4f 17973
480a3f21
PW
17974@cindex limit hardware watchpoints length
17975@cindex remote target, limit watchpoints length
17976@anchor{set remote hardware-watchpoint-length-limit}
17977@item set remote hardware-watchpoint-length-limit @var{limit}
17978Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
17979a remote hardware watchpoint. A limit of -1, the default, is treated
17980as unlimited.
17981
17982@item show remote hardware-watchpoint-length-limit
17983Show the current limit (in bytes) of the maximum length of
17984a remote hardware watchpoint.
17985
2d717e4f
DJ
17986@item set remote exec-file @var{filename}
17987@itemx show remote exec-file
17988@anchor{set remote exec-file}
17989@cindex executable file, for remote target
17990Select the file used for @code{run} with @code{target
17991extended-remote}. This should be set to a filename valid on the
17992target system. If it is not set, the target will use a default
17993filename (e.g.@: the last program run).
84603566 17994
9a7071a8
JB
17995@item set remote interrupt-sequence
17996@cindex interrupt remote programs
17997@cindex select Ctrl-C, BREAK or BREAK-g
17998Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
17999@samp{BREAK-g} as the
18000sequence to the remote target in order to interrupt the execution.
18001@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
18002is high level of serial line for some certain time.
18003Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
18004It is @code{BREAK} signal followed by character @code{g}.
18005
18006@item show interrupt-sequence
18007Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
18008is sent by @value{GDBN} to interrupt the remote program.
18009@code{BREAK-g} is BREAK signal followed by @code{g} and
18010also known as Magic SysRq g.
18011
18012@item set remote interrupt-on-connect
18013@cindex send interrupt-sequence on start
18014Specify whether interrupt-sequence is sent to remote target when
18015@value{GDBN} connects to it. This is mostly needed when you debug
18016Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
18017which is known as Magic SysRq g in order to connect @value{GDBN}.
18018
18019@item show interrupt-on-connect
18020Show whether interrupt-sequence is sent
18021to remote target when @value{GDBN} connects to it.
18022
84603566
SL
18023@kindex set tcp
18024@kindex show tcp
18025@item set tcp auto-retry on
18026@cindex auto-retry, for remote TCP target
18027Enable auto-retry for remote TCP connections. This is useful if the remote
18028debugging agent is launched in parallel with @value{GDBN}; there is a race
18029condition because the agent may not become ready to accept the connection
18030before @value{GDBN} attempts to connect. When auto-retry is
18031enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
18032to establish the connection using the timeout specified by
18033@code{set tcp connect-timeout}.
18034
18035@item set tcp auto-retry off
18036Do not auto-retry failed TCP connections.
18037
18038@item show tcp auto-retry
18039Show the current auto-retry setting.
18040
18041@item set tcp connect-timeout @var{seconds}
18042@cindex connection timeout, for remote TCP target
18043@cindex timeout, for remote target connection
18044Set the timeout for establishing a TCP connection to the remote target to
18045@var{seconds}. The timeout affects both polling to retry failed connections
18046(enabled by @code{set tcp auto-retry on}) and waiting for connections
18047that are merely slow to complete, and represents an approximate cumulative
18048value.
18049
18050@item show tcp connect-timeout
18051Show the current connection timeout setting.
501eef12
AC
18052@end table
18053
427c3a89
DJ
18054@cindex remote packets, enabling and disabling
18055The @value{GDBN} remote protocol autodetects the packets supported by
18056your debugging stub. If you need to override the autodetection, you
18057can use these commands to enable or disable individual packets. Each
18058packet can be set to @samp{on} (the remote target supports this
18059packet), @samp{off} (the remote target does not support this packet),
18060or @samp{auto} (detect remote target support for this packet). They
18061all default to @samp{auto}. For more information about each packet,
18062see @ref{Remote Protocol}.
18063
18064During normal use, you should not have to use any of these commands.
18065If you do, that may be a bug in your remote debugging stub, or a bug
18066in @value{GDBN}. You may want to report the problem to the
18067@value{GDBN} developers.
18068
cfa9d6d9
DJ
18069For each packet @var{name}, the command to enable or disable the
18070packet is @code{set remote @var{name}-packet}. The available settings
18071are:
427c3a89 18072
cfa9d6d9 18073@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
18074@item Command Name
18075@tab Remote Packet
18076@tab Related Features
18077
cfa9d6d9 18078@item @code{fetch-register}
427c3a89
DJ
18079@tab @code{p}
18080@tab @code{info registers}
18081
cfa9d6d9 18082@item @code{set-register}
427c3a89
DJ
18083@tab @code{P}
18084@tab @code{set}
18085
cfa9d6d9 18086@item @code{binary-download}
427c3a89
DJ
18087@tab @code{X}
18088@tab @code{load}, @code{set}
18089
cfa9d6d9 18090@item @code{read-aux-vector}
427c3a89
DJ
18091@tab @code{qXfer:auxv:read}
18092@tab @code{info auxv}
18093
cfa9d6d9 18094@item @code{symbol-lookup}
427c3a89
DJ
18095@tab @code{qSymbol}
18096@tab Detecting multiple threads
18097
2d717e4f
DJ
18098@item @code{attach}
18099@tab @code{vAttach}
18100@tab @code{attach}
18101
cfa9d6d9 18102@item @code{verbose-resume}
427c3a89
DJ
18103@tab @code{vCont}
18104@tab Stepping or resuming multiple threads
18105
2d717e4f
DJ
18106@item @code{run}
18107@tab @code{vRun}
18108@tab @code{run}
18109
cfa9d6d9 18110@item @code{software-breakpoint}
427c3a89
DJ
18111@tab @code{Z0}
18112@tab @code{break}
18113
cfa9d6d9 18114@item @code{hardware-breakpoint}
427c3a89
DJ
18115@tab @code{Z1}
18116@tab @code{hbreak}
18117
cfa9d6d9 18118@item @code{write-watchpoint}
427c3a89
DJ
18119@tab @code{Z2}
18120@tab @code{watch}
18121
cfa9d6d9 18122@item @code{read-watchpoint}
427c3a89
DJ
18123@tab @code{Z3}
18124@tab @code{rwatch}
18125
cfa9d6d9 18126@item @code{access-watchpoint}
427c3a89
DJ
18127@tab @code{Z4}
18128@tab @code{awatch}
18129
cfa9d6d9
DJ
18130@item @code{target-features}
18131@tab @code{qXfer:features:read}
18132@tab @code{set architecture}
18133
18134@item @code{library-info}
18135@tab @code{qXfer:libraries:read}
18136@tab @code{info sharedlibrary}
18137
18138@item @code{memory-map}
18139@tab @code{qXfer:memory-map:read}
18140@tab @code{info mem}
18141
0fb4aa4b
PA
18142@item @code{read-sdata-object}
18143@tab @code{qXfer:sdata:read}
18144@tab @code{print $_sdata}
18145
cfa9d6d9
DJ
18146@item @code{read-spu-object}
18147@tab @code{qXfer:spu:read}
18148@tab @code{info spu}
18149
18150@item @code{write-spu-object}
18151@tab @code{qXfer:spu:write}
18152@tab @code{info spu}
18153
4aa995e1
PA
18154@item @code{read-siginfo-object}
18155@tab @code{qXfer:siginfo:read}
18156@tab @code{print $_siginfo}
18157
18158@item @code{write-siginfo-object}
18159@tab @code{qXfer:siginfo:write}
18160@tab @code{set $_siginfo}
18161
dc146f7c
VP
18162@item @code{threads}
18163@tab @code{qXfer:threads:read}
18164@tab @code{info threads}
18165
cfa9d6d9 18166@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
18167@tab @code{qGetTLSAddr}
18168@tab Displaying @code{__thread} variables
18169
711e434b
PM
18170@item @code{get-thread-information-block-address}
18171@tab @code{qGetTIBAddr}
18172@tab Display MS-Windows Thread Information Block.
18173
08388c79
DE
18174@item @code{search-memory}
18175@tab @code{qSearch:memory}
18176@tab @code{find}
18177
427c3a89
DJ
18178@item @code{supported-packets}
18179@tab @code{qSupported}
18180@tab Remote communications parameters
18181
cfa9d6d9 18182@item @code{pass-signals}
89be2091
DJ
18183@tab @code{QPassSignals}
18184@tab @code{handle @var{signal}}
18185
9b224c5e
PA
18186@item @code{program-signals}
18187@tab @code{QProgramSignals}
18188@tab @code{handle @var{signal}}
18189
a6b151f1
DJ
18190@item @code{hostio-close-packet}
18191@tab @code{vFile:close}
18192@tab @code{remote get}, @code{remote put}
18193
18194@item @code{hostio-open-packet}
18195@tab @code{vFile:open}
18196@tab @code{remote get}, @code{remote put}
18197
18198@item @code{hostio-pread-packet}
18199@tab @code{vFile:pread}
18200@tab @code{remote get}, @code{remote put}
18201
18202@item @code{hostio-pwrite-packet}
18203@tab @code{vFile:pwrite}
18204@tab @code{remote get}, @code{remote put}
18205
18206@item @code{hostio-unlink-packet}
18207@tab @code{vFile:unlink}
18208@tab @code{remote delete}
a6f3e723 18209
b9e7b9c3
UW
18210@item @code{hostio-readlink-packet}
18211@tab @code{vFile:readlink}
18212@tab Host I/O
18213
a6f3e723
SL
18214@item @code{noack-packet}
18215@tab @code{QStartNoAckMode}
18216@tab Packet acknowledgment
07e059b5
VP
18217
18218@item @code{osdata}
18219@tab @code{qXfer:osdata:read}
18220@tab @code{info os}
0b16c5cf
PA
18221
18222@item @code{query-attached}
18223@tab @code{qAttached}
18224@tab Querying remote process attach state.
b3b9301e
PA
18225
18226@item @code{traceframe-info}
18227@tab @code{qXfer:traceframe-info:read}
18228@tab Traceframe info
03583c20 18229
1e4d1764
YQ
18230@item @code{install-in-trace}
18231@tab @code{InstallInTrace}
18232@tab Install tracepoint in tracing
18233
03583c20
UW
18234@item @code{disable-randomization}
18235@tab @code{QDisableRandomization}
18236@tab @code{set disable-randomization}
83364271
LM
18237
18238@item @code{conditional-breakpoints-packet}
18239@tab @code{Z0 and Z1}
18240@tab @code{Support for target-side breakpoint condition evaluation}
427c3a89
DJ
18241@end multitable
18242
79a6e687
BW
18243@node Remote Stub
18244@section Implementing a Remote Stub
7a292a7a 18245
8e04817f
AC
18246@cindex debugging stub, example
18247@cindex remote stub, example
18248@cindex stub example, remote debugging
18249The stub files provided with @value{GDBN} implement the target side of the
18250communication protocol, and the @value{GDBN} side is implemented in the
18251@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
18252these subroutines to communicate, and ignore the details. (If you're
18253implementing your own stub file, you can still ignore the details: start
18254with one of the existing stub files. @file{sparc-stub.c} is the best
18255organized, and therefore the easiest to read.)
18256
104c1213
JM
18257@cindex remote serial debugging, overview
18258To debug a program running on another machine (the debugging
18259@dfn{target} machine), you must first arrange for all the usual
18260prerequisites for the program to run by itself. For example, for a C
18261program, you need:
c906108c 18262
104c1213
JM
18263@enumerate
18264@item
18265A startup routine to set up the C runtime environment; these usually
18266have a name like @file{crt0}. The startup routine may be supplied by
18267your hardware supplier, or you may have to write your own.
96baa820 18268
5d161b24 18269@item
d4f3574e 18270A C subroutine library to support your program's
104c1213 18271subroutine calls, notably managing input and output.
96baa820 18272
104c1213
JM
18273@item
18274A way of getting your program to the other machine---for example, a
18275download program. These are often supplied by the hardware
18276manufacturer, but you may have to write your own from hardware
18277documentation.
18278@end enumerate
96baa820 18279
104c1213
JM
18280The next step is to arrange for your program to use a serial port to
18281communicate with the machine where @value{GDBN} is running (the @dfn{host}
18282machine). In general terms, the scheme looks like this:
96baa820 18283
104c1213
JM
18284@table @emph
18285@item On the host,
18286@value{GDBN} already understands how to use this protocol; when everything
18287else is set up, you can simply use the @samp{target remote} command
18288(@pxref{Targets,,Specifying a Debugging Target}).
18289
18290@item On the target,
18291you must link with your program a few special-purpose subroutines that
18292implement the @value{GDBN} remote serial protocol. The file containing these
18293subroutines is called a @dfn{debugging stub}.
18294
18295On certain remote targets, you can use an auxiliary program
18296@code{gdbserver} instead of linking a stub into your program.
79a6e687 18297@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 18298@end table
96baa820 18299
104c1213
JM
18300The debugging stub is specific to the architecture of the remote
18301machine; for example, use @file{sparc-stub.c} to debug programs on
18302@sc{sparc} boards.
96baa820 18303
104c1213
JM
18304@cindex remote serial stub list
18305These working remote stubs are distributed with @value{GDBN}:
96baa820 18306
104c1213
JM
18307@table @code
18308
18309@item i386-stub.c
41afff9a 18310@cindex @file{i386-stub.c}
104c1213
JM
18311@cindex Intel
18312@cindex i386
18313For Intel 386 and compatible architectures.
18314
18315@item m68k-stub.c
41afff9a 18316@cindex @file{m68k-stub.c}
104c1213
JM
18317@cindex Motorola 680x0
18318@cindex m680x0
18319For Motorola 680x0 architectures.
18320
18321@item sh-stub.c
41afff9a 18322@cindex @file{sh-stub.c}
172c2a43 18323@cindex Renesas
104c1213 18324@cindex SH
172c2a43 18325For Renesas SH architectures.
104c1213
JM
18326
18327@item sparc-stub.c
41afff9a 18328@cindex @file{sparc-stub.c}
104c1213
JM
18329@cindex Sparc
18330For @sc{sparc} architectures.
18331
18332@item sparcl-stub.c
41afff9a 18333@cindex @file{sparcl-stub.c}
104c1213
JM
18334@cindex Fujitsu
18335@cindex SparcLite
18336For Fujitsu @sc{sparclite} architectures.
18337
18338@end table
18339
18340The @file{README} file in the @value{GDBN} distribution may list other
18341recently added stubs.
18342
18343@menu
18344* Stub Contents:: What the stub can do for you
18345* Bootstrapping:: What you must do for the stub
18346* Debug Session:: Putting it all together
104c1213
JM
18347@end menu
18348
6d2ebf8b 18349@node Stub Contents
79a6e687 18350@subsection What the Stub Can Do for You
104c1213
JM
18351
18352@cindex remote serial stub
18353The debugging stub for your architecture supplies these three
18354subroutines:
18355
18356@table @code
18357@item set_debug_traps
4644b6e3 18358@findex set_debug_traps
104c1213
JM
18359@cindex remote serial stub, initialization
18360This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
18361program stops. You must call this subroutine explicitly in your
18362program's startup code.
104c1213
JM
18363
18364@item handle_exception
4644b6e3 18365@findex handle_exception
104c1213
JM
18366@cindex remote serial stub, main routine
18367This is the central workhorse, but your program never calls it
18368explicitly---the setup code arranges for @code{handle_exception} to
18369run when a trap is triggered.
18370
18371@code{handle_exception} takes control when your program stops during
18372execution (for example, on a breakpoint), and mediates communications
18373with @value{GDBN} on the host machine. This is where the communications
18374protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 18375representative on the target machine. It begins by sending summary
104c1213
JM
18376information on the state of your program, then continues to execute,
18377retrieving and transmitting any information @value{GDBN} needs, until you
18378execute a @value{GDBN} command that makes your program resume; at that point,
18379@code{handle_exception} returns control to your own code on the target
5d161b24 18380machine.
104c1213
JM
18381
18382@item breakpoint
18383@cindex @code{breakpoint} subroutine, remote
18384Use this auxiliary subroutine to make your program contain a
18385breakpoint. Depending on the particular situation, this may be the only
18386way for @value{GDBN} to get control. For instance, if your target
18387machine has some sort of interrupt button, you won't need to call this;
18388pressing the interrupt button transfers control to
18389@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
18390simply receiving characters on the serial port may also trigger a trap;
18391again, in that situation, you don't need to call @code{breakpoint} from
18392your own program---simply running @samp{target remote} from the host
5d161b24 18393@value{GDBN} session gets control.
104c1213
JM
18394
18395Call @code{breakpoint} if none of these is true, or if you simply want
18396to make certain your program stops at a predetermined point for the
18397start of your debugging session.
18398@end table
18399
6d2ebf8b 18400@node Bootstrapping
79a6e687 18401@subsection What You Must Do for the Stub
104c1213
JM
18402
18403@cindex remote stub, support routines
18404The debugging stubs that come with @value{GDBN} are set up for a particular
18405chip architecture, but they have no information about the rest of your
18406debugging target machine.
18407
18408First of all you need to tell the stub how to communicate with the
18409serial port.
18410
18411@table @code
18412@item int getDebugChar()
4644b6e3 18413@findex getDebugChar
104c1213
JM
18414Write this subroutine to read a single character from the serial port.
18415It may be identical to @code{getchar} for your target system; a
18416different name is used to allow you to distinguish the two if you wish.
18417
18418@item void putDebugChar(int)
4644b6e3 18419@findex putDebugChar
104c1213 18420Write this subroutine to write a single character to the serial port.
5d161b24 18421It may be identical to @code{putchar} for your target system; a
104c1213
JM
18422different name is used to allow you to distinguish the two if you wish.
18423@end table
18424
18425@cindex control C, and remote debugging
18426@cindex interrupting remote targets
18427If you want @value{GDBN} to be able to stop your program while it is
18428running, you need to use an interrupt-driven serial driver, and arrange
18429for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
18430character). That is the character which @value{GDBN} uses to tell the
18431remote system to stop.
18432
18433Getting the debugging target to return the proper status to @value{GDBN}
18434probably requires changes to the standard stub; one quick and dirty way
18435is to just execute a breakpoint instruction (the ``dirty'' part is that
18436@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
18437
18438Other routines you need to supply are:
18439
18440@table @code
18441@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 18442@findex exceptionHandler
104c1213
JM
18443Write this function to install @var{exception_address} in the exception
18444handling tables. You need to do this because the stub does not have any
18445way of knowing what the exception handling tables on your target system
18446are like (for example, the processor's table might be in @sc{rom},
18447containing entries which point to a table in @sc{ram}).
18448@var{exception_number} is the exception number which should be changed;
18449its meaning is architecture-dependent (for example, different numbers
18450might represent divide by zero, misaligned access, etc). When this
18451exception occurs, control should be transferred directly to
18452@var{exception_address}, and the processor state (stack, registers,
18453and so on) should be just as it is when a processor exception occurs. So if
18454you want to use a jump instruction to reach @var{exception_address}, it
18455should be a simple jump, not a jump to subroutine.
18456
18457For the 386, @var{exception_address} should be installed as an interrupt
18458gate so that interrupts are masked while the handler runs. The gate
18459should be at privilege level 0 (the most privileged level). The
18460@sc{sparc} and 68k stubs are able to mask interrupts themselves without
18461help from @code{exceptionHandler}.
18462
18463@item void flush_i_cache()
4644b6e3 18464@findex flush_i_cache
d4f3574e 18465On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
18466instruction cache, if any, on your target machine. If there is no
18467instruction cache, this subroutine may be a no-op.
18468
18469On target machines that have instruction caches, @value{GDBN} requires this
18470function to make certain that the state of your program is stable.
18471@end table
18472
18473@noindent
18474You must also make sure this library routine is available:
18475
18476@table @code
18477@item void *memset(void *, int, int)
4644b6e3 18478@findex memset
104c1213
JM
18479This is the standard library function @code{memset} that sets an area of
18480memory to a known value. If you have one of the free versions of
18481@code{libc.a}, @code{memset} can be found there; otherwise, you must
18482either obtain it from your hardware manufacturer, or write your own.
18483@end table
18484
18485If you do not use the GNU C compiler, you may need other standard
18486library subroutines as well; this varies from one stub to another,
18487but in general the stubs are likely to use any of the common library
e22ea452 18488subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
18489
18490
6d2ebf8b 18491@node Debug Session
79a6e687 18492@subsection Putting it All Together
104c1213
JM
18493
18494@cindex remote serial debugging summary
18495In summary, when your program is ready to debug, you must follow these
18496steps.
18497
18498@enumerate
18499@item
6d2ebf8b 18500Make sure you have defined the supporting low-level routines
79a6e687 18501(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
18502@display
18503@code{getDebugChar}, @code{putDebugChar},
18504@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
18505@end display
18506
18507@item
2fb860fc
PA
18508Insert these lines in your program's startup code, before the main
18509procedure is called:
104c1213 18510
474c8240 18511@smallexample
104c1213
JM
18512set_debug_traps();
18513breakpoint();
474c8240 18514@end smallexample
104c1213 18515
2fb860fc
PA
18516On some machines, when a breakpoint trap is raised, the hardware
18517automatically makes the PC point to the instruction after the
18518breakpoint. If your machine doesn't do that, you may need to adjust
18519@code{handle_exception} to arrange for it to return to the instruction
18520after the breakpoint on this first invocation, so that your program
18521doesn't keep hitting the initial breakpoint instead of making
18522progress.
18523
104c1213
JM
18524@item
18525For the 680x0 stub only, you need to provide a variable called
18526@code{exceptionHook}. Normally you just use:
18527
474c8240 18528@smallexample
104c1213 18529void (*exceptionHook)() = 0;
474c8240 18530@end smallexample
104c1213 18531
d4f3574e 18532@noindent
104c1213 18533but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 18534function in your program, that function is called when
104c1213
JM
18535@code{@value{GDBN}} continues after stopping on a trap (for example, bus
18536error). The function indicated by @code{exceptionHook} is called with
18537one parameter: an @code{int} which is the exception number.
18538
18539@item
18540Compile and link together: your program, the @value{GDBN} debugging stub for
18541your target architecture, and the supporting subroutines.
18542
18543@item
18544Make sure you have a serial connection between your target machine and
18545the @value{GDBN} host, and identify the serial port on the host.
18546
18547@item
18548@c The "remote" target now provides a `load' command, so we should
18549@c document that. FIXME.
18550Download your program to your target machine (or get it there by
18551whatever means the manufacturer provides), and start it.
18552
18553@item
07f31aa6 18554Start @value{GDBN} on the host, and connect to the target
79a6e687 18555(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 18556
104c1213
JM
18557@end enumerate
18558
8e04817f
AC
18559@node Configurations
18560@chapter Configuration-Specific Information
104c1213 18561
8e04817f
AC
18562While nearly all @value{GDBN} commands are available for all native and
18563cross versions of the debugger, there are some exceptions. This chapter
18564describes things that are only available in certain configurations.
104c1213 18565
8e04817f
AC
18566There are three major categories of configurations: native
18567configurations, where the host and target are the same, embedded
18568operating system configurations, which are usually the same for several
18569different processor architectures, and bare embedded processors, which
18570are quite different from each other.
104c1213 18571
8e04817f
AC
18572@menu
18573* Native::
18574* Embedded OS::
18575* Embedded Processors::
18576* Architectures::
18577@end menu
104c1213 18578
8e04817f
AC
18579@node Native
18580@section Native
104c1213 18581
8e04817f
AC
18582This section describes details specific to particular native
18583configurations.
6cf7e474 18584
8e04817f
AC
18585@menu
18586* HP-UX:: HP-UX
7561d450 18587* BSD libkvm Interface:: Debugging BSD kernel memory images
8e04817f
AC
18588* SVR4 Process Information:: SVR4 process information
18589* DJGPP Native:: Features specific to the DJGPP port
78c47bea 18590* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 18591* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 18592* Darwin:: Features specific to Darwin
8e04817f 18593@end menu
6cf7e474 18594
8e04817f
AC
18595@node HP-UX
18596@subsection HP-UX
104c1213 18597
8e04817f
AC
18598On HP-UX systems, if you refer to a function or variable name that
18599begins with a dollar sign, @value{GDBN} searches for a user or system
18600name first, before it searches for a convenience variable.
104c1213 18601
9c16f35a 18602
7561d450
MK
18603@node BSD libkvm Interface
18604@subsection BSD libkvm Interface
18605
18606@cindex libkvm
18607@cindex kernel memory image
18608@cindex kernel crash dump
18609
18610BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
18611interface that provides a uniform interface for accessing kernel virtual
18612memory images, including live systems and crash dumps. @value{GDBN}
18613uses this interface to allow you to debug live kernels and kernel crash
18614dumps on many native BSD configurations. This is implemented as a
18615special @code{kvm} debugging target. For debugging a live system, load
18616the currently running kernel into @value{GDBN} and connect to the
18617@code{kvm} target:
18618
18619@smallexample
18620(@value{GDBP}) @b{target kvm}
18621@end smallexample
18622
18623For debugging crash dumps, provide the file name of the crash dump as an
18624argument:
18625
18626@smallexample
18627(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
18628@end smallexample
18629
18630Once connected to the @code{kvm} target, the following commands are
18631available:
18632
18633@table @code
18634@kindex kvm
18635@item kvm pcb
721c2651 18636Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
18637
18638@item kvm proc
18639Set current context from proc address. This command isn't available on
18640modern FreeBSD systems.
18641@end table
18642
8e04817f 18643@node SVR4 Process Information
79a6e687 18644@subsection SVR4 Process Information
60bf7e09
EZ
18645@cindex /proc
18646@cindex examine process image
18647@cindex process info via @file{/proc}
104c1213 18648
60bf7e09
EZ
18649Many versions of SVR4 and compatible systems provide a facility called
18650@samp{/proc} that can be used to examine the image of a running
451b7c33
TT
18651process using file-system subroutines.
18652
18653If @value{GDBN} is configured for an operating system with this
18654facility, the command @code{info proc} is available to report
18655information about the process running your program, or about any
18656process running on your system. This includes, as of this writing,
18657@sc{gnu}/Linux, OSF/1 (Digital Unix), Solaris, and Irix, but
18658not HP-UX, for example.
18659
18660This command may also work on core files that were created on a system
18661that has the @samp{/proc} facility.
104c1213 18662
8e04817f
AC
18663@table @code
18664@kindex info proc
60bf7e09 18665@cindex process ID
8e04817f 18666@item info proc
60bf7e09
EZ
18667@itemx info proc @var{process-id}
18668Summarize available information about any running process. If a
18669process ID is specified by @var{process-id}, display information about
18670that process; otherwise display information about the program being
18671debugged. The summary includes the debugged process ID, the command
18672line used to invoke it, its current working directory, and its
18673executable file's absolute file name.
18674
18675On some systems, @var{process-id} can be of the form
18676@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
18677within a process. If the optional @var{pid} part is missing, it means
18678a thread from the process being debugged (the leading @samp{/} still
18679needs to be present, or else @value{GDBN} will interpret the number as
18680a process ID rather than a thread ID).
6cf7e474 18681
0c631110
TT
18682@item info proc cmdline
18683@cindex info proc cmdline
18684Show the original command line of the process. This command is
18685specific to @sc{gnu}/Linux.
18686
18687@item info proc cwd
18688@cindex info proc cwd
18689Show the current working directory of the process. This command is
18690specific to @sc{gnu}/Linux.
18691
18692@item info proc exe
18693@cindex info proc exe
18694Show the name of executable of the process. This command is specific
18695to @sc{gnu}/Linux.
18696
8e04817f 18697@item info proc mappings
60bf7e09
EZ
18698@cindex memory address space mappings
18699Report the memory address space ranges accessible in the program, with
18700information on whether the process has read, write, or execute access
18701rights to each range. On @sc{gnu}/Linux systems, each memory range
18702includes the object file which is mapped to that range, instead of the
18703memory access rights to that range.
18704
18705@item info proc stat
18706@itemx info proc status
18707@cindex process detailed status information
18708These subcommands are specific to @sc{gnu}/Linux systems. They show
18709the process-related information, including the user ID and group ID;
18710how many threads are there in the process; its virtual memory usage;
18711the signals that are pending, blocked, and ignored; its TTY; its
18712consumption of system and user time; its stack size; its @samp{nice}
2eecc4ab 18713value; etc. For more information, see the @samp{proc} man page
60bf7e09
EZ
18714(type @kbd{man 5 proc} from your shell prompt).
18715
18716@item info proc all
18717Show all the information about the process described under all of the
18718above @code{info proc} subcommands.
18719
8e04817f
AC
18720@ignore
18721@comment These sub-options of 'info proc' were not included when
18722@comment procfs.c was re-written. Keep their descriptions around
18723@comment against the day when someone finds the time to put them back in.
18724@kindex info proc times
18725@item info proc times
18726Starting time, user CPU time, and system CPU time for your program and
18727its children.
6cf7e474 18728
8e04817f
AC
18729@kindex info proc id
18730@item info proc id
18731Report on the process IDs related to your program: its own process ID,
18732the ID of its parent, the process group ID, and the session ID.
8e04817f 18733@end ignore
721c2651
EZ
18734
18735@item set procfs-trace
18736@kindex set procfs-trace
18737@cindex @code{procfs} API calls
18738This command enables and disables tracing of @code{procfs} API calls.
18739
18740@item show procfs-trace
18741@kindex show procfs-trace
18742Show the current state of @code{procfs} API call tracing.
18743
18744@item set procfs-file @var{file}
18745@kindex set procfs-file
18746Tell @value{GDBN} to write @code{procfs} API trace to the named
18747@var{file}. @value{GDBN} appends the trace info to the previous
18748contents of the file. The default is to display the trace on the
18749standard output.
18750
18751@item show procfs-file
18752@kindex show procfs-file
18753Show the file to which @code{procfs} API trace is written.
18754
18755@item proc-trace-entry
18756@itemx proc-trace-exit
18757@itemx proc-untrace-entry
18758@itemx proc-untrace-exit
18759@kindex proc-trace-entry
18760@kindex proc-trace-exit
18761@kindex proc-untrace-entry
18762@kindex proc-untrace-exit
18763These commands enable and disable tracing of entries into and exits
18764from the @code{syscall} interface.
18765
18766@item info pidlist
18767@kindex info pidlist
18768@cindex process list, QNX Neutrino
18769For QNX Neutrino only, this command displays the list of all the
18770processes and all the threads within each process.
18771
18772@item info meminfo
18773@kindex info meminfo
18774@cindex mapinfo list, QNX Neutrino
18775For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 18776@end table
104c1213 18777
8e04817f
AC
18778@node DJGPP Native
18779@subsection Features for Debugging @sc{djgpp} Programs
18780@cindex @sc{djgpp} debugging
18781@cindex native @sc{djgpp} debugging
18782@cindex MS-DOS-specific commands
104c1213 18783
514c4d71
EZ
18784@cindex DPMI
18785@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
18786MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
18787that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
18788top of real-mode DOS systems and their emulations.
104c1213 18789
8e04817f
AC
18790@value{GDBN} supports native debugging of @sc{djgpp} programs, and
18791defines a few commands specific to the @sc{djgpp} port. This
18792subsection describes those commands.
104c1213 18793
8e04817f
AC
18794@table @code
18795@kindex info dos
18796@item info dos
18797This is a prefix of @sc{djgpp}-specific commands which print
18798information about the target system and important OS structures.
f1251bdd 18799
8e04817f
AC
18800@kindex sysinfo
18801@cindex MS-DOS system info
18802@cindex free memory information (MS-DOS)
18803@item info dos sysinfo
18804This command displays assorted information about the underlying
18805platform: the CPU type and features, the OS version and flavor, the
18806DPMI version, and the available conventional and DPMI memory.
104c1213 18807
8e04817f
AC
18808@cindex GDT
18809@cindex LDT
18810@cindex IDT
18811@cindex segment descriptor tables
18812@cindex descriptor tables display
18813@item info dos gdt
18814@itemx info dos ldt
18815@itemx info dos idt
18816These 3 commands display entries from, respectively, Global, Local,
18817and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
18818tables are data structures which store a descriptor for each segment
18819that is currently in use. The segment's selector is an index into a
18820descriptor table; the table entry for that index holds the
18821descriptor's base address and limit, and its attributes and access
18822rights.
104c1213 18823
8e04817f
AC
18824A typical @sc{djgpp} program uses 3 segments: a code segment, a data
18825segment (used for both data and the stack), and a DOS segment (which
18826allows access to DOS/BIOS data structures and absolute addresses in
18827conventional memory). However, the DPMI host will usually define
18828additional segments in order to support the DPMI environment.
d4f3574e 18829
8e04817f
AC
18830@cindex garbled pointers
18831These commands allow to display entries from the descriptor tables.
18832Without an argument, all entries from the specified table are
18833displayed. An argument, which should be an integer expression, means
18834display a single entry whose index is given by the argument. For
18835example, here's a convenient way to display information about the
18836debugged program's data segment:
104c1213 18837
8e04817f
AC
18838@smallexample
18839@exdent @code{(@value{GDBP}) info dos ldt $ds}
18840@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
18841@end smallexample
104c1213 18842
8e04817f
AC
18843@noindent
18844This comes in handy when you want to see whether a pointer is outside
18845the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 18846
8e04817f
AC
18847@cindex page tables display (MS-DOS)
18848@item info dos pde
18849@itemx info dos pte
18850These two commands display entries from, respectively, the Page
18851Directory and the Page Tables. Page Directories and Page Tables are
18852data structures which control how virtual memory addresses are mapped
18853into physical addresses. A Page Table includes an entry for every
18854page of memory that is mapped into the program's address space; there
18855may be several Page Tables, each one holding up to 4096 entries. A
18856Page Directory has up to 4096 entries, one each for every Page Table
18857that is currently in use.
104c1213 18858
8e04817f
AC
18859Without an argument, @kbd{info dos pde} displays the entire Page
18860Directory, and @kbd{info dos pte} displays all the entries in all of
18861the Page Tables. An argument, an integer expression, given to the
18862@kbd{info dos pde} command means display only that entry from the Page
18863Directory table. An argument given to the @kbd{info dos pte} command
18864means display entries from a single Page Table, the one pointed to by
18865the specified entry in the Page Directory.
104c1213 18866
8e04817f
AC
18867@cindex direct memory access (DMA) on MS-DOS
18868These commands are useful when your program uses @dfn{DMA} (Direct
18869Memory Access), which needs physical addresses to program the DMA
18870controller.
104c1213 18871
8e04817f 18872These commands are supported only with some DPMI servers.
104c1213 18873
8e04817f
AC
18874@cindex physical address from linear address
18875@item info dos address-pte @var{addr}
18876This command displays the Page Table entry for a specified linear
514c4d71
EZ
18877address. The argument @var{addr} is a linear address which should
18878already have the appropriate segment's base address added to it,
18879because this command accepts addresses which may belong to @emph{any}
18880segment. For example, here's how to display the Page Table entry for
18881the page where a variable @code{i} is stored:
104c1213 18882
b383017d 18883@smallexample
8e04817f
AC
18884@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
18885@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 18886@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 18887@end smallexample
104c1213 18888
8e04817f
AC
18889@noindent
18890This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 18891whose physical base address is @code{0x02698000}, and shows all the
8e04817f 18892attributes of that page.
104c1213 18893
8e04817f
AC
18894Note that you must cast the addresses of variables to a @code{char *},
18895since otherwise the value of @code{__djgpp_base_address}, the base
18896address of all variables and functions in a @sc{djgpp} program, will
18897be added using the rules of C pointer arithmetics: if @code{i} is
18898declared an @code{int}, @value{GDBN} will add 4 times the value of
18899@code{__djgpp_base_address} to the address of @code{i}.
104c1213 18900
8e04817f
AC
18901Here's another example, it displays the Page Table entry for the
18902transfer buffer:
104c1213 18903
8e04817f
AC
18904@smallexample
18905@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
18906@exdent @code{Page Table entry for address 0x29110:}
18907@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
18908@end smallexample
104c1213 18909
8e04817f
AC
18910@noindent
18911(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
189123rd member of the @code{_go32_info_block} structure.) The output
18913clearly shows that this DPMI server maps the addresses in conventional
18914memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
18915linear (@code{0x29110}) addresses are identical.
104c1213 18916
8e04817f
AC
18917This command is supported only with some DPMI servers.
18918@end table
104c1213 18919
c45da7e6 18920@cindex DOS serial data link, remote debugging
a8f24a35
EZ
18921In addition to native debugging, the DJGPP port supports remote
18922debugging via a serial data link. The following commands are specific
18923to remote serial debugging in the DJGPP port of @value{GDBN}.
18924
18925@table @code
18926@kindex set com1base
18927@kindex set com1irq
18928@kindex set com2base
18929@kindex set com2irq
18930@kindex set com3base
18931@kindex set com3irq
18932@kindex set com4base
18933@kindex set com4irq
18934@item set com1base @var{addr}
18935This command sets the base I/O port address of the @file{COM1} serial
18936port.
18937
18938@item set com1irq @var{irq}
18939This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
18940for the @file{COM1} serial port.
18941
18942There are similar commands @samp{set com2base}, @samp{set com3irq},
18943etc.@: for setting the port address and the @code{IRQ} lines for the
18944other 3 COM ports.
18945
18946@kindex show com1base
18947@kindex show com1irq
18948@kindex show com2base
18949@kindex show com2irq
18950@kindex show com3base
18951@kindex show com3irq
18952@kindex show com4base
18953@kindex show com4irq
18954The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
18955display the current settings of the base address and the @code{IRQ}
18956lines used by the COM ports.
c45da7e6
EZ
18957
18958@item info serial
18959@kindex info serial
18960@cindex DOS serial port status
18961This command prints the status of the 4 DOS serial ports. For each
18962port, it prints whether it's active or not, its I/O base address and
18963IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
18964counts of various errors encountered so far.
a8f24a35
EZ
18965@end table
18966
18967
78c47bea 18968@node Cygwin Native
79a6e687 18969@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
18970@cindex MS Windows debugging
18971@cindex native Cygwin debugging
18972@cindex Cygwin-specific commands
18973
be448670 18974@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
18975DLLs with and without symbolic debugging information.
18976
18977@cindex Ctrl-BREAK, MS-Windows
18978@cindex interrupt debuggee on MS-Windows
18979MS-Windows programs that call @code{SetConsoleMode} to switch off the
18980special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
18981by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
18982supports @kbd{C-@key{BREAK}} as an alternative interrupt key
18983sequence, which can be used to interrupt the debuggee even if it
18984ignores @kbd{C-c}.
18985
18986There are various additional Cygwin-specific commands, described in
18987this section. Working with DLLs that have no debugging symbols is
18988described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
18989
18990@table @code
18991@kindex info w32
18992@item info w32
db2e3e2e 18993This is a prefix of MS Windows-specific commands which print
78c47bea
PM
18994information about the target system and important OS structures.
18995
18996@item info w32 selector
18997This command displays information returned by
18998the Win32 API @code{GetThreadSelectorEntry} function.
18999It takes an optional argument that is evaluated to
19000a long value to give the information about this given selector.
19001Without argument, this command displays information
d3e8051b 19002about the six segment registers.
78c47bea 19003
711e434b
PM
19004@item info w32 thread-information-block
19005This command displays thread specific information stored in the
19006Thread Information Block (readable on the X86 CPU family using @code{$fs}
19007selector for 32-bit programs and @code{$gs} for 64-bit programs).
19008
78c47bea
PM
19009@kindex info dll
19010@item info dll
db2e3e2e 19011This is a Cygwin-specific alias of @code{info shared}.
78c47bea
PM
19012
19013@kindex dll-symbols
19014@item dll-symbols
19015This command loads symbols from a dll similarly to
19016add-sym command but without the need to specify a base address.
19017
be90c084 19018@kindex set cygwin-exceptions
e16b02ee
EZ
19019@cindex debugging the Cygwin DLL
19020@cindex Cygwin DLL, debugging
be90c084 19021@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
19022If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
19023happen inside the Cygwin DLL. If @var{mode} is @code{off},
19024@value{GDBN} will delay recognition of exceptions, and may ignore some
19025exceptions which seem to be caused by internal Cygwin DLL
19026``bookkeeping''. This option is meant primarily for debugging the
19027Cygwin DLL itself; the default value is @code{off} to avoid annoying
19028@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
19029
19030@kindex show cygwin-exceptions
19031@item show cygwin-exceptions
e16b02ee
EZ
19032Displays whether @value{GDBN} will break on exceptions that happen
19033inside the Cygwin DLL itself.
be90c084 19034
b383017d 19035@kindex set new-console
78c47bea 19036@item set new-console @var{mode}
b383017d 19037If @var{mode} is @code{on} the debuggee will
78c47bea 19038be started in a new console on next start.
e03e5e7b 19039If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
19040be started in the same console as the debugger.
19041
19042@kindex show new-console
19043@item show new-console
19044Displays whether a new console is used
19045when the debuggee is started.
19046
19047@kindex set new-group
19048@item set new-group @var{mode}
19049This boolean value controls whether the debuggee should
19050start a new group or stay in the same group as the debugger.
19051This affects the way the Windows OS handles
c8aa23ab 19052@samp{Ctrl-C}.
78c47bea
PM
19053
19054@kindex show new-group
19055@item show new-group
19056Displays current value of new-group boolean.
19057
19058@kindex set debugevents
19059@item set debugevents
219eec71
EZ
19060This boolean value adds debug output concerning kernel events related
19061to the debuggee seen by the debugger. This includes events that
19062signal thread and process creation and exit, DLL loading and
19063unloading, console interrupts, and debugging messages produced by the
19064Windows @code{OutputDebugString} API call.
78c47bea
PM
19065
19066@kindex set debugexec
19067@item set debugexec
b383017d 19068This boolean value adds debug output concerning execute events
219eec71 19069(such as resume thread) seen by the debugger.
78c47bea
PM
19070
19071@kindex set debugexceptions
19072@item set debugexceptions
219eec71
EZ
19073This boolean value adds debug output concerning exceptions in the
19074debuggee seen by the debugger.
78c47bea
PM
19075
19076@kindex set debugmemory
19077@item set debugmemory
219eec71
EZ
19078This boolean value adds debug output concerning debuggee memory reads
19079and writes by the debugger.
78c47bea
PM
19080
19081@kindex set shell
19082@item set shell
19083This boolean values specifies whether the debuggee is called
19084via a shell or directly (default value is on).
19085
19086@kindex show shell
19087@item show shell
19088Displays if the debuggee will be started with a shell.
19089
19090@end table
19091
be448670 19092@menu
79a6e687 19093* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
19094@end menu
19095
79a6e687
BW
19096@node Non-debug DLL Symbols
19097@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
19098@cindex DLLs with no debugging symbols
19099@cindex Minimal symbols and DLLs
19100
19101Very often on windows, some of the DLLs that your program relies on do
19102not include symbolic debugging information (for example,
db2e3e2e 19103@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 19104symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 19105information contained in the DLL's export table. This section
be448670
CF
19106describes working with such symbols, known internally to @value{GDBN} as
19107``minimal symbols''.
19108
19109Note that before the debugged program has started execution, no DLLs
db2e3e2e 19110will have been loaded. The easiest way around this problem is simply to
be448670 19111start the program --- either by setting a breakpoint or letting the
db2e3e2e 19112program run once to completion. It is also possible to force
be448670 19113@value{GDBN} to load a particular DLL before starting the executable ---
12c27660 19114see the shared library information in @ref{Files}, or the
db2e3e2e 19115@code{dll-symbols} command in @ref{Cygwin Native}. Currently,
be448670
CF
19116explicitly loading symbols from a DLL with no debugging information will
19117cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
19118which may adversely affect symbol lookup performance.
19119
79a6e687 19120@subsubsection DLL Name Prefixes
be448670
CF
19121
19122In keeping with the naming conventions used by the Microsoft debugging
19123tools, DLL export symbols are made available with a prefix based on the
19124DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
19125also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 19126sufficient. In some cases there will be name clashes within a program
be448670
CF
19127(particularly if the executable itself includes full debugging symbols)
19128necessitating the use of the fully qualified name when referring to the
99e008fe 19129contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
19130exclamation mark (``!'') being interpreted as a language operator.
19131
19132Note that the internal name of the DLL may be all upper-case, even
99e008fe 19133though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
19134symbols within @value{GDBN} are @emph{case-sensitive} this may cause
19135some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
19136@code{info variables} commands or even @code{maint print msymbols}
19137(@pxref{Symbols}). Here's an example:
be448670
CF
19138
19139@smallexample
f7dc1244 19140(@value{GDBP}) info function CreateFileA
be448670
CF
19141All functions matching regular expression "CreateFileA":
19142
19143Non-debugging symbols:
191440x77e885f4 CreateFileA
191450x77e885f4 KERNEL32!CreateFileA
19146@end smallexample
19147
19148@smallexample
f7dc1244 19149(@value{GDBP}) info function !
be448670
CF
19150All functions matching regular expression "!":
19151
19152Non-debugging symbols:
191530x6100114c cygwin1!__assert
191540x61004034 cygwin1!_dll_crt0@@0
191550x61004240 cygwin1!dll_crt0(per_process *)
19156[etc...]
19157@end smallexample
19158
79a6e687 19159@subsubsection Working with Minimal Symbols
be448670
CF
19160
19161Symbols extracted from a DLL's export table do not contain very much
19162type information. All that @value{GDBN} can do is guess whether a symbol
19163refers to a function or variable depending on the linker section that
19164contains the symbol. Also note that the actual contents of the memory
19165contained in a DLL are not available unless the program is running. This
19166means that you cannot examine the contents of a variable or disassemble
19167a function within a DLL without a running program.
19168
19169Variables are generally treated as pointers and dereferenced
19170automatically. For this reason, it is often necessary to prefix a
19171variable name with the address-of operator (``&'') and provide explicit
19172type information in the command. Here's an example of the type of
19173problem:
19174
19175@smallexample
f7dc1244 19176(@value{GDBP}) print 'cygwin1!__argv'
be448670
CF
19177$1 = 268572168
19178@end smallexample
19179
19180@smallexample
f7dc1244 19181(@value{GDBP}) x 'cygwin1!__argv'
be448670
CF
191820x10021610: "\230y\""
19183@end smallexample
19184
19185And two possible solutions:
19186
19187@smallexample
f7dc1244 19188(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
19189$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
19190@end smallexample
19191
19192@smallexample
f7dc1244 19193(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 191940x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 19195(@value{GDBP}) x/x 0x10021608
be448670 191960x10021608: 0x0022fd98
f7dc1244 19197(@value{GDBP}) x/s 0x0022fd98
be448670
CF
191980x22fd98: "/cygdrive/c/mydirectory/myprogram"
19199@end smallexample
19200
19201Setting a break point within a DLL is possible even before the program
19202starts execution. However, under these circumstances, @value{GDBN} can't
19203examine the initial instructions of the function in order to skip the
19204function's frame set-up code. You can work around this by using ``*&''
19205to set the breakpoint at a raw memory address:
19206
19207@smallexample
f7dc1244 19208(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
19209Breakpoint 1 at 0x1e04eff0
19210@end smallexample
19211
19212The author of these extensions is not entirely convinced that setting a
19213break point within a shared DLL like @file{kernel32.dll} is completely
19214safe.
19215
14d6dd68 19216@node Hurd Native
79a6e687 19217@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
19218@cindex @sc{gnu} Hurd debugging
19219
19220This subsection describes @value{GDBN} commands specific to the
19221@sc{gnu} Hurd native debugging.
19222
19223@table @code
19224@item set signals
19225@itemx set sigs
19226@kindex set signals@r{, Hurd command}
19227@kindex set sigs@r{, Hurd command}
19228This command toggles the state of inferior signal interception by
19229@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
19230affected by this command. @code{sigs} is a shorthand alias for
19231@code{signals}.
19232
19233@item show signals
19234@itemx show sigs
19235@kindex show signals@r{, Hurd command}
19236@kindex show sigs@r{, Hurd command}
19237Show the current state of intercepting inferior's signals.
19238
19239@item set signal-thread
19240@itemx set sigthread
19241@kindex set signal-thread
19242@kindex set sigthread
19243This command tells @value{GDBN} which thread is the @code{libc} signal
19244thread. That thread is run when a signal is delivered to a running
19245process. @code{set sigthread} is the shorthand alias of @code{set
19246signal-thread}.
19247
19248@item show signal-thread
19249@itemx show sigthread
19250@kindex show signal-thread
19251@kindex show sigthread
19252These two commands show which thread will run when the inferior is
19253delivered a signal.
19254
19255@item set stopped
19256@kindex set stopped@r{, Hurd command}
19257This commands tells @value{GDBN} that the inferior process is stopped,
19258as with the @code{SIGSTOP} signal. The stopped process can be
19259continued by delivering a signal to it.
19260
19261@item show stopped
19262@kindex show stopped@r{, Hurd command}
19263This command shows whether @value{GDBN} thinks the debuggee is
19264stopped.
19265
19266@item set exceptions
19267@kindex set exceptions@r{, Hurd command}
19268Use this command to turn off trapping of exceptions in the inferior.
19269When exception trapping is off, neither breakpoints nor
19270single-stepping will work. To restore the default, set exception
19271trapping on.
19272
19273@item show exceptions
19274@kindex show exceptions@r{, Hurd command}
19275Show the current state of trapping exceptions in the inferior.
19276
19277@item set task pause
19278@kindex set task@r{, Hurd commands}
19279@cindex task attributes (@sc{gnu} Hurd)
19280@cindex pause current task (@sc{gnu} Hurd)
19281This command toggles task suspension when @value{GDBN} has control.
19282Setting it to on takes effect immediately, and the task is suspended
19283whenever @value{GDBN} gets control. Setting it to off will take
19284effect the next time the inferior is continued. If this option is set
19285to off, you can use @code{set thread default pause on} or @code{set
19286thread pause on} (see below) to pause individual threads.
19287
19288@item show task pause
19289@kindex show task@r{, Hurd commands}
19290Show the current state of task suspension.
19291
19292@item set task detach-suspend-count
19293@cindex task suspend count
19294@cindex detach from task, @sc{gnu} Hurd
19295This command sets the suspend count the task will be left with when
19296@value{GDBN} detaches from it.
19297
19298@item show task detach-suspend-count
19299Show the suspend count the task will be left with when detaching.
19300
19301@item set task exception-port
19302@itemx set task excp
19303@cindex task exception port, @sc{gnu} Hurd
19304This command sets the task exception port to which @value{GDBN} will
19305forward exceptions. The argument should be the value of the @dfn{send
19306rights} of the task. @code{set task excp} is a shorthand alias.
19307
19308@item set noninvasive
19309@cindex noninvasive task options
19310This command switches @value{GDBN} to a mode that is the least
19311invasive as far as interfering with the inferior is concerned. This
19312is the same as using @code{set task pause}, @code{set exceptions}, and
19313@code{set signals} to values opposite to the defaults.
19314
19315@item info send-rights
19316@itemx info receive-rights
19317@itemx info port-rights
19318@itemx info port-sets
19319@itemx info dead-names
19320@itemx info ports
19321@itemx info psets
19322@cindex send rights, @sc{gnu} Hurd
19323@cindex receive rights, @sc{gnu} Hurd
19324@cindex port rights, @sc{gnu} Hurd
19325@cindex port sets, @sc{gnu} Hurd
19326@cindex dead names, @sc{gnu} Hurd
19327These commands display information about, respectively, send rights,
19328receive rights, port rights, port sets, and dead names of a task.
19329There are also shorthand aliases: @code{info ports} for @code{info
19330port-rights} and @code{info psets} for @code{info port-sets}.
19331
19332@item set thread pause
19333@kindex set thread@r{, Hurd command}
19334@cindex thread properties, @sc{gnu} Hurd
19335@cindex pause current thread (@sc{gnu} Hurd)
19336This command toggles current thread suspension when @value{GDBN} has
19337control. Setting it to on takes effect immediately, and the current
19338thread is suspended whenever @value{GDBN} gets control. Setting it to
19339off will take effect the next time the inferior is continued.
19340Normally, this command has no effect, since when @value{GDBN} has
19341control, the whole task is suspended. However, if you used @code{set
19342task pause off} (see above), this command comes in handy to suspend
19343only the current thread.
19344
19345@item show thread pause
19346@kindex show thread@r{, Hurd command}
19347This command shows the state of current thread suspension.
19348
19349@item set thread run
d3e8051b 19350This command sets whether the current thread is allowed to run.
14d6dd68
EZ
19351
19352@item show thread run
19353Show whether the current thread is allowed to run.
19354
19355@item set thread detach-suspend-count
19356@cindex thread suspend count, @sc{gnu} Hurd
19357@cindex detach from thread, @sc{gnu} Hurd
19358This command sets the suspend count @value{GDBN} will leave on a
19359thread when detaching. This number is relative to the suspend count
19360found by @value{GDBN} when it notices the thread; use @code{set thread
19361takeover-suspend-count} to force it to an absolute value.
19362
19363@item show thread detach-suspend-count
19364Show the suspend count @value{GDBN} will leave on the thread when
19365detaching.
19366
19367@item set thread exception-port
19368@itemx set thread excp
19369Set the thread exception port to which to forward exceptions. This
19370overrides the port set by @code{set task exception-port} (see above).
19371@code{set thread excp} is the shorthand alias.
19372
19373@item set thread takeover-suspend-count
19374Normally, @value{GDBN}'s thread suspend counts are relative to the
19375value @value{GDBN} finds when it notices each thread. This command
19376changes the suspend counts to be absolute instead.
19377
19378@item set thread default
19379@itemx show thread default
19380@cindex thread default settings, @sc{gnu} Hurd
19381Each of the above @code{set thread} commands has a @code{set thread
19382default} counterpart (e.g., @code{set thread default pause}, @code{set
19383thread default exception-port}, etc.). The @code{thread default}
19384variety of commands sets the default thread properties for all
19385threads; you can then change the properties of individual threads with
19386the non-default commands.
19387@end table
19388
a80b95ba
TG
19389@node Darwin
19390@subsection Darwin
19391@cindex Darwin
19392
19393@value{GDBN} provides the following commands specific to the Darwin target:
19394
19395@table @code
19396@item set debug darwin @var{num}
19397@kindex set debug darwin
19398When set to a non zero value, enables debugging messages specific to
19399the Darwin support. Higher values produce more verbose output.
19400
19401@item show debug darwin
19402@kindex show debug darwin
19403Show the current state of Darwin messages.
19404
19405@item set debug mach-o @var{num}
19406@kindex set debug mach-o
19407When set to a non zero value, enables debugging messages while
19408@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
19409file format used on Darwin for object and executable files.) Higher
19410values produce more verbose output. This is a command to diagnose
19411problems internal to @value{GDBN} and should not be needed in normal
19412usage.
19413
19414@item show debug mach-o
19415@kindex show debug mach-o
19416Show the current state of Mach-O file messages.
19417
19418@item set mach-exceptions on
19419@itemx set mach-exceptions off
19420@kindex set mach-exceptions
19421On Darwin, faults are first reported as a Mach exception and are then
19422mapped to a Posix signal. Use this command to turn on trapping of
19423Mach exceptions in the inferior. This might be sometimes useful to
19424better understand the cause of a fault. The default is off.
19425
19426@item show mach-exceptions
19427@kindex show mach-exceptions
19428Show the current state of exceptions trapping.
19429@end table
19430
a64548ea 19431
8e04817f
AC
19432@node Embedded OS
19433@section Embedded Operating Systems
104c1213 19434
8e04817f
AC
19435This section describes configurations involving the debugging of
19436embedded operating systems that are available for several different
19437architectures.
d4f3574e 19438
8e04817f
AC
19439@menu
19440* VxWorks:: Using @value{GDBN} with VxWorks
19441@end menu
104c1213 19442
8e04817f
AC
19443@value{GDBN} includes the ability to debug programs running on
19444various real-time operating systems.
104c1213 19445
8e04817f
AC
19446@node VxWorks
19447@subsection Using @value{GDBN} with VxWorks
104c1213 19448
8e04817f 19449@cindex VxWorks
104c1213 19450
8e04817f 19451@table @code
104c1213 19452
8e04817f
AC
19453@kindex target vxworks
19454@item target vxworks @var{machinename}
19455A VxWorks system, attached via TCP/IP. The argument @var{machinename}
19456is the target system's machine name or IP address.
104c1213 19457
8e04817f 19458@end table
104c1213 19459
8e04817f
AC
19460On VxWorks, @code{load} links @var{filename} dynamically on the
19461current target system as well as adding its symbols in @value{GDBN}.
104c1213 19462
8e04817f
AC
19463@value{GDBN} enables developers to spawn and debug tasks running on networked
19464VxWorks targets from a Unix host. Already-running tasks spawned from
19465the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
19466both the Unix host and on the VxWorks target. The program
19467@code{@value{GDBP}} is installed and executed on the Unix host. (It may be
19468installed with the name @code{vxgdb}, to distinguish it from a
19469@value{GDBN} for debugging programs on the host itself.)
104c1213 19470
8e04817f
AC
19471@table @code
19472@item VxWorks-timeout @var{args}
19473@kindex vxworks-timeout
19474All VxWorks-based targets now support the option @code{vxworks-timeout}.
19475This option is set by the user, and @var{args} represents the number of
19476seconds @value{GDBN} waits for responses to rpc's. You might use this if
19477your VxWorks target is a slow software simulator or is on the far side
19478of a thin network line.
19479@end table
104c1213 19480
8e04817f
AC
19481The following information on connecting to VxWorks was current when
19482this manual was produced; newer releases of VxWorks may use revised
19483procedures.
104c1213 19484
4644b6e3 19485@findex INCLUDE_RDB
8e04817f
AC
19486To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
19487to include the remote debugging interface routines in the VxWorks
19488library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
19489VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
19490kernel. The resulting kernel contains @file{rdb.a}, and spawns the
19491source debugging task @code{tRdbTask} when VxWorks is booted. For more
19492information on configuring and remaking VxWorks, see the manufacturer's
19493manual.
19494@c VxWorks, see the @cite{VxWorks Programmer's Guide}.
104c1213 19495
8e04817f
AC
19496Once you have included @file{rdb.a} in your VxWorks system image and set
19497your Unix execution search path to find @value{GDBN}, you are ready to
19498run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
19499@code{vxgdb}, depending on your installation).
104c1213 19500
8e04817f 19501@value{GDBN} comes up showing the prompt:
104c1213 19502
474c8240 19503@smallexample
8e04817f 19504(vxgdb)
474c8240 19505@end smallexample
104c1213 19506
8e04817f
AC
19507@menu
19508* VxWorks Connection:: Connecting to VxWorks
19509* VxWorks Download:: VxWorks download
19510* VxWorks Attach:: Running tasks
19511@end menu
104c1213 19512
8e04817f
AC
19513@node VxWorks Connection
19514@subsubsection Connecting to VxWorks
104c1213 19515
8e04817f
AC
19516The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
19517network. To connect to a target whose host name is ``@code{tt}'', type:
104c1213 19518
474c8240 19519@smallexample
8e04817f 19520(vxgdb) target vxworks tt
474c8240 19521@end smallexample
104c1213 19522
8e04817f
AC
19523@need 750
19524@value{GDBN} displays messages like these:
104c1213 19525
8e04817f
AC
19526@smallexample
19527Attaching remote machine across net...
19528Connected to tt.
19529@end smallexample
104c1213 19530
8e04817f
AC
19531@need 1000
19532@value{GDBN} then attempts to read the symbol tables of any object modules
19533loaded into the VxWorks target since it was last booted. @value{GDBN} locates
19534these files by searching the directories listed in the command search
79a6e687 19535path (@pxref{Environment, ,Your Program's Environment}); if it fails
8e04817f 19536to find an object file, it displays a message such as:
5d161b24 19537
474c8240 19538@smallexample
8e04817f 19539prog.o: No such file or directory.
474c8240 19540@end smallexample
104c1213 19541
8e04817f
AC
19542When this happens, add the appropriate directory to the search path with
19543the @value{GDBN} command @code{path}, and execute the @code{target}
19544command again.
104c1213 19545
8e04817f 19546@node VxWorks Download
79a6e687 19547@subsubsection VxWorks Download
104c1213 19548
8e04817f
AC
19549@cindex download to VxWorks
19550If you have connected to the VxWorks target and you want to debug an
19551object that has not yet been loaded, you can use the @value{GDBN}
19552@code{load} command to download a file from Unix to VxWorks
19553incrementally. The object file given as an argument to the @code{load}
19554command is actually opened twice: first by the VxWorks target in order
19555to download the code, then by @value{GDBN} in order to read the symbol
19556table. This can lead to problems if the current working directories on
19557the two systems differ. If both systems have NFS mounted the same
19558filesystems, you can avoid these problems by using absolute paths.
19559Otherwise, it is simplest to set the working directory on both systems
19560to the directory in which the object file resides, and then to reference
19561the file by its name, without any path. For instance, a program
19562@file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
19563and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
19564program, type this on VxWorks:
104c1213 19565
474c8240 19566@smallexample
8e04817f 19567-> cd "@var{vxpath}/vw/demo/rdb"
474c8240 19568@end smallexample
104c1213 19569
8e04817f
AC
19570@noindent
19571Then, in @value{GDBN}, type:
104c1213 19572
474c8240 19573@smallexample
8e04817f
AC
19574(vxgdb) cd @var{hostpath}/vw/demo/rdb
19575(vxgdb) load prog.o
474c8240 19576@end smallexample
104c1213 19577
8e04817f 19578@value{GDBN} displays a response similar to this:
104c1213 19579
8e04817f
AC
19580@smallexample
19581Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
19582@end smallexample
104c1213 19583
8e04817f
AC
19584You can also use the @code{load} command to reload an object module
19585after editing and recompiling the corresponding source file. Note that
19586this makes @value{GDBN} delete all currently-defined breakpoints,
19587auto-displays, and convenience variables, and to clear the value
19588history. (This is necessary in order to preserve the integrity of
19589debugger's data structures that reference the target system's symbol
19590table.)
104c1213 19591
8e04817f 19592@node VxWorks Attach
79a6e687 19593@subsubsection Running Tasks
104c1213
JM
19594
19595@cindex running VxWorks tasks
19596You can also attach to an existing task using the @code{attach} command as
19597follows:
19598
474c8240 19599@smallexample
104c1213 19600(vxgdb) attach @var{task}
474c8240 19601@end smallexample
104c1213
JM
19602
19603@noindent
19604where @var{task} is the VxWorks hexadecimal task ID. The task can be running
19605or suspended when you attach to it. Running tasks are suspended at
19606the time of attachment.
19607
6d2ebf8b 19608@node Embedded Processors
104c1213
JM
19609@section Embedded Processors
19610
19611This section goes into details specific to particular embedded
19612configurations.
19613
c45da7e6
EZ
19614@cindex send command to simulator
19615Whenever a specific embedded processor has a simulator, @value{GDBN}
19616allows to send an arbitrary command to the simulator.
19617
19618@table @code
19619@item sim @var{command}
19620@kindex sim@r{, a command}
19621Send an arbitrary @var{command} string to the simulator. Consult the
19622documentation for the specific simulator in use for information about
19623acceptable commands.
19624@end table
19625
7d86b5d5 19626
104c1213 19627@menu
c45da7e6 19628* ARM:: ARM RDI
172c2a43 19629* M32R/D:: Renesas M32R/D
104c1213 19630* M68K:: Motorola M68K
08be9d71 19631* MicroBlaze:: Xilinx MicroBlaze
104c1213 19632* MIPS Embedded:: MIPS Embedded
a37295f9 19633* OpenRISC 1000:: OpenRisc 1000
4acd40f3 19634* PowerPC Embedded:: PowerPC Embedded
984359d2 19635* PA:: HP PA Embedded
104c1213
JM
19636* Sparclet:: Tsqware Sparclet
19637* Sparclite:: Fujitsu Sparclite
104c1213 19638* Z8000:: Zilog Z8000
a64548ea
EZ
19639* AVR:: Atmel AVR
19640* CRIS:: CRIS
19641* Super-H:: Renesas Super-H
104c1213
JM
19642@end menu
19643
6d2ebf8b 19644@node ARM
104c1213 19645@subsection ARM
c45da7e6 19646@cindex ARM RDI
104c1213
JM
19647
19648@table @code
8e04817f
AC
19649@kindex target rdi
19650@item target rdi @var{dev}
19651ARM Angel monitor, via RDI library interface to ADP protocol. You may
19652use this target to communicate with both boards running the Angel
19653monitor, or with the EmbeddedICE JTAG debug device.
19654
19655@kindex target rdp
19656@item target rdp @var{dev}
19657ARM Demon monitor.
19658
19659@end table
19660
e2f4edfd
EZ
19661@value{GDBN} provides the following ARM-specific commands:
19662
19663@table @code
19664@item set arm disassembler
19665@kindex set arm
19666This commands selects from a list of disassembly styles. The
19667@code{"std"} style is the standard style.
19668
19669@item show arm disassembler
19670@kindex show arm
19671Show the current disassembly style.
19672
19673@item set arm apcs32
19674@cindex ARM 32-bit mode
19675This command toggles ARM operation mode between 32-bit and 26-bit.
19676
19677@item show arm apcs32
19678Display the current usage of the ARM 32-bit mode.
19679
19680@item set arm fpu @var{fputype}
19681This command sets the ARM floating-point unit (FPU) type. The
19682argument @var{fputype} can be one of these:
19683
19684@table @code
19685@item auto
19686Determine the FPU type by querying the OS ABI.
19687@item softfpa
19688Software FPU, with mixed-endian doubles on little-endian ARM
19689processors.
19690@item fpa
19691GCC-compiled FPA co-processor.
19692@item softvfp
19693Software FPU with pure-endian doubles.
19694@item vfp
19695VFP co-processor.
19696@end table
19697
19698@item show arm fpu
19699Show the current type of the FPU.
19700
19701@item set arm abi
19702This command forces @value{GDBN} to use the specified ABI.
19703
19704@item show arm abi
19705Show the currently used ABI.
19706
0428b8f5
DJ
19707@item set arm fallback-mode (arm|thumb|auto)
19708@value{GDBN} uses the symbol table, when available, to determine
19709whether instructions are ARM or Thumb. This command controls
19710@value{GDBN}'s default behavior when the symbol table is not
19711available. The default is @samp{auto}, which causes @value{GDBN} to
19712use the current execution mode (from the @code{T} bit in the @code{CPSR}
19713register).
19714
19715@item show arm fallback-mode
19716Show the current fallback instruction mode.
19717
19718@item set arm force-mode (arm|thumb|auto)
19719This command overrides use of the symbol table to determine whether
19720instructions are ARM or Thumb. The default is @samp{auto}, which
19721causes @value{GDBN} to use the symbol table and then the setting
19722of @samp{set arm fallback-mode}.
19723
19724@item show arm force-mode
19725Show the current forced instruction mode.
19726
e2f4edfd
EZ
19727@item set debug arm
19728Toggle whether to display ARM-specific debugging messages from the ARM
19729target support subsystem.
19730
19731@item show debug arm
19732Show whether ARM-specific debugging messages are enabled.
19733@end table
19734
c45da7e6
EZ
19735The following commands are available when an ARM target is debugged
19736using the RDI interface:
19737
19738@table @code
19739@item rdilogfile @r{[}@var{file}@r{]}
19740@kindex rdilogfile
19741@cindex ADP (Angel Debugger Protocol) logging
19742Set the filename for the ADP (Angel Debugger Protocol) packet log.
19743With an argument, sets the log file to the specified @var{file}. With
19744no argument, show the current log file name. The default log file is
19745@file{rdi.log}.
19746
19747@item rdilogenable @r{[}@var{arg}@r{]}
19748@kindex rdilogenable
19749Control logging of ADP packets. With an argument of 1 or @code{"yes"}
19750enables logging, with an argument 0 or @code{"no"} disables it. With
19751no arguments displays the current setting. When logging is enabled,
19752ADP packets exchanged between @value{GDBN} and the RDI target device
19753are logged to a file.
19754
19755@item set rdiromatzero
19756@kindex set rdiromatzero
19757@cindex ROM at zero address, RDI
19758Tell @value{GDBN} whether the target has ROM at address 0. If on,
19759vector catching is disabled, so that zero address can be used. If off
19760(the default), vector catching is enabled. For this command to take
19761effect, it needs to be invoked prior to the @code{target rdi} command.
19762
19763@item show rdiromatzero
19764@kindex show rdiromatzero
19765Show the current setting of ROM at zero address.
19766
19767@item set rdiheartbeat
19768@kindex set rdiheartbeat
19769@cindex RDI heartbeat
19770Enable or disable RDI heartbeat packets. It is not recommended to
19771turn on this option, since it confuses ARM and EPI JTAG interface, as
19772well as the Angel monitor.
19773
19774@item show rdiheartbeat
19775@kindex show rdiheartbeat
19776Show the setting of RDI heartbeat packets.
19777@end table
19778
ee8e71d4
EZ
19779@table @code
19780@item target sim @r{[}@var{simargs}@r{]} @dots{}
19781The @value{GDBN} ARM simulator accepts the following optional arguments.
19782
19783@table @code
19784@item --swi-support=@var{type}
19785Tell the simulator which SWI interfaces to support.
19786@var{type} may be a comma separated list of the following values.
19787The default value is @code{all}.
19788
19789@table @code
19790@item none
19791@item demon
19792@item angel
19793@item redboot
19794@item all
19795@end table
19796@end table
19797@end table
e2f4edfd 19798
8e04817f 19799@node M32R/D
ba04e063 19800@subsection Renesas M32R/D and M32R/SDI
8e04817f
AC
19801
19802@table @code
8e04817f
AC
19803@kindex target m32r
19804@item target m32r @var{dev}
172c2a43 19805Renesas M32R/D ROM monitor.
8e04817f 19806
fb3e19c0
KI
19807@kindex target m32rsdi
19808@item target m32rsdi @var{dev}
19809Renesas M32R SDI server, connected via parallel port to the board.
721c2651
EZ
19810@end table
19811
19812The following @value{GDBN} commands are specific to the M32R monitor:
19813
19814@table @code
19815@item set download-path @var{path}
19816@kindex set download-path
19817@cindex find downloadable @sc{srec} files (M32R)
d3e8051b 19818Set the default path for finding downloadable @sc{srec} files.
721c2651
EZ
19819
19820@item show download-path
19821@kindex show download-path
19822Show the default path for downloadable @sc{srec} files.
fb3e19c0 19823
721c2651
EZ
19824@item set board-address @var{addr}
19825@kindex set board-address
19826@cindex M32-EVA target board address
19827Set the IP address for the M32R-EVA target board.
19828
19829@item show board-address
19830@kindex show board-address
19831Show the current IP address of the target board.
19832
19833@item set server-address @var{addr}
19834@kindex set server-address
19835@cindex download server address (M32R)
19836Set the IP address for the download server, which is the @value{GDBN}'s
19837host machine.
19838
19839@item show server-address
19840@kindex show server-address
19841Display the IP address of the download server.
19842
19843@item upload @r{[}@var{file}@r{]}
19844@kindex upload@r{, M32R}
19845Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
19846upload capability. If no @var{file} argument is given, the current
19847executable file is uploaded.
19848
19849@item tload @r{[}@var{file}@r{]}
19850@kindex tload@r{, M32R}
19851Test the @code{upload} command.
8e04817f
AC
19852@end table
19853
ba04e063
EZ
19854The following commands are available for M32R/SDI:
19855
19856@table @code
19857@item sdireset
19858@kindex sdireset
19859@cindex reset SDI connection, M32R
19860This command resets the SDI connection.
19861
19862@item sdistatus
19863@kindex sdistatus
19864This command shows the SDI connection status.
19865
19866@item debug_chaos
19867@kindex debug_chaos
19868@cindex M32R/Chaos debugging
19869Instructs the remote that M32R/Chaos debugging is to be used.
19870
19871@item use_debug_dma
19872@kindex use_debug_dma
19873Instructs the remote to use the DEBUG_DMA method of accessing memory.
19874
19875@item use_mon_code
19876@kindex use_mon_code
19877Instructs the remote to use the MON_CODE method of accessing memory.
19878
19879@item use_ib_break
19880@kindex use_ib_break
19881Instructs the remote to set breakpoints by IB break.
19882
19883@item use_dbt_break
19884@kindex use_dbt_break
19885Instructs the remote to set breakpoints by DBT.
19886@end table
19887
8e04817f
AC
19888@node M68K
19889@subsection M68k
19890
7ce59000
DJ
19891The Motorola m68k configuration includes ColdFire support, and a
19892target command for the following ROM monitor.
8e04817f
AC
19893
19894@table @code
19895
8e04817f
AC
19896@kindex target dbug
19897@item target dbug @var{dev}
19898dBUG ROM monitor for Motorola ColdFire.
19899
8e04817f
AC
19900@end table
19901
08be9d71
ME
19902@node MicroBlaze
19903@subsection MicroBlaze
19904@cindex Xilinx MicroBlaze
19905@cindex XMD, Xilinx Microprocessor Debugger
19906
19907The MicroBlaze is a soft-core processor supported on various Xilinx
19908FPGAs, such as Spartan or Virtex series. Boards with these processors
19909usually have JTAG ports which connect to a host system running the Xilinx
19910Embedded Development Kit (EDK) or Software Development Kit (SDK).
19911This host system is used to download the configuration bitstream to
19912the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
19913communicates with the target board using the JTAG interface and
19914presents a @code{gdbserver} interface to the board. By default
19915@code{xmd} uses port @code{1234}. (While it is possible to change
19916this default port, it requires the use of undocumented @code{xmd}
19917commands. Contact Xilinx support if you need to do this.)
19918
19919Use these GDB commands to connect to the MicroBlaze target processor.
19920
19921@table @code
19922@item target remote :1234
19923Use this command to connect to the target if you are running @value{GDBN}
19924on the same system as @code{xmd}.
19925
19926@item target remote @var{xmd-host}:1234
19927Use this command to connect to the target if it is connected to @code{xmd}
19928running on a different system named @var{xmd-host}.
19929
19930@item load
19931Use this command to download a program to the MicroBlaze target.
19932
19933@item set debug microblaze @var{n}
19934Enable MicroBlaze-specific debugging messages if non-zero.
19935
19936@item show debug microblaze @var{n}
19937Show MicroBlaze-specific debugging level.
19938@end table
19939
8e04817f 19940@node MIPS Embedded
eb17f351 19941@subsection @acronym{MIPS} Embedded
8e04817f 19942
eb17f351
EZ
19943@cindex @acronym{MIPS} boards
19944@value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
19945@acronym{MIPS} board attached to a serial line. This is available when
cc30c4bd 19946you configure @value{GDBN} with @samp{--target=mips-elf}.
104c1213 19947
8e04817f
AC
19948@need 1000
19949Use these @value{GDBN} commands to specify the connection to your target board:
104c1213 19950
8e04817f
AC
19951@table @code
19952@item target mips @var{port}
19953@kindex target mips @var{port}
19954To run a program on the board, start up @code{@value{GDBP}} with the
19955name of your program as the argument. To connect to the board, use the
19956command @samp{target mips @var{port}}, where @var{port} is the name of
19957the serial port connected to the board. If the program has not already
19958been downloaded to the board, you may use the @code{load} command to
19959download it. You can then use all the usual @value{GDBN} commands.
104c1213 19960
8e04817f
AC
19961For example, this sequence connects to the target board through a serial
19962port, and loads and runs a program called @var{prog} through the
19963debugger:
104c1213 19964
474c8240 19965@smallexample
8e04817f
AC
19966host$ @value{GDBP} @var{prog}
19967@value{GDBN} is free software and @dots{}
19968(@value{GDBP}) target mips /dev/ttyb
19969(@value{GDBP}) load @var{prog}
19970(@value{GDBP}) run
474c8240 19971@end smallexample
104c1213 19972
8e04817f
AC
19973@item target mips @var{hostname}:@var{portnumber}
19974On some @value{GDBN} host configurations, you can specify a TCP
19975connection (for instance, to a serial line managed by a terminal
19976concentrator) instead of a serial port, using the syntax
19977@samp{@var{hostname}:@var{portnumber}}.
104c1213 19978
8e04817f
AC
19979@item target pmon @var{port}
19980@kindex target pmon @var{port}
19981PMON ROM monitor.
104c1213 19982
8e04817f
AC
19983@item target ddb @var{port}
19984@kindex target ddb @var{port}
19985NEC's DDB variant of PMON for Vr4300.
104c1213 19986
8e04817f
AC
19987@item target lsi @var{port}
19988@kindex target lsi @var{port}
19989LSI variant of PMON.
104c1213 19990
8e04817f
AC
19991@kindex target r3900
19992@item target r3900 @var{dev}
19993Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
104c1213 19994
8e04817f
AC
19995@kindex target array
19996@item target array @var{dev}
19997Array Tech LSI33K RAID controller board.
104c1213 19998
8e04817f 19999@end table
104c1213 20000
104c1213 20001
8e04817f 20002@noindent
eb17f351 20003@value{GDBN} also supports these special commands for @acronym{MIPS} targets:
104c1213 20004
8e04817f 20005@table @code
8e04817f
AC
20006@item set mipsfpu double
20007@itemx set mipsfpu single
20008@itemx set mipsfpu none
a64548ea 20009@itemx set mipsfpu auto
8e04817f
AC
20010@itemx show mipsfpu
20011@kindex set mipsfpu
20012@kindex show mipsfpu
eb17f351
EZ
20013@cindex @acronym{MIPS} remote floating point
20014@cindex floating point, @acronym{MIPS} remote
20015If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
20016coprocessor, you should use the command @samp{set mipsfpu none} (if you
20017need this, you may wish to put the command in your @value{GDBN} init
20018file). This tells @value{GDBN} how to find the return value of
20019functions which return floating point values. It also allows
20020@value{GDBN} to avoid saving the floating point registers when calling
20021functions on the board. If you are using a floating point coprocessor
20022with only single precision floating point support, as on the @sc{r4650}
20023processor, use the command @samp{set mipsfpu single}. The default
20024double precision floating point coprocessor may be selected using
20025@samp{set mipsfpu double}.
104c1213 20026
8e04817f
AC
20027In previous versions the only choices were double precision or no
20028floating point, so @samp{set mipsfpu on} will select double precision
20029and @samp{set mipsfpu off} will select no floating point.
104c1213 20030
8e04817f
AC
20031As usual, you can inquire about the @code{mipsfpu} variable with
20032@samp{show mipsfpu}.
104c1213 20033
8e04817f
AC
20034@item set timeout @var{seconds}
20035@itemx set retransmit-timeout @var{seconds}
20036@itemx show timeout
20037@itemx show retransmit-timeout
eb17f351
EZ
20038@cindex @code{timeout}, @acronym{MIPS} protocol
20039@cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
8e04817f
AC
20040@kindex set timeout
20041@kindex show timeout
20042@kindex set retransmit-timeout
20043@kindex show retransmit-timeout
eb17f351 20044You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
8e04817f
AC
20045remote protocol, with the @code{set timeout @var{seconds}} command. The
20046default is 5 seconds. Similarly, you can control the timeout used while
a6f3e723 20047waiting for an acknowledgment of a packet with the @code{set
8e04817f
AC
20048retransmit-timeout @var{seconds}} command. The default is 3 seconds.
20049You can inspect both values with @code{show timeout} and @code{show
20050retransmit-timeout}. (These commands are @emph{only} available when
cc30c4bd 20051@value{GDBN} is configured for @samp{--target=mips-elf}.)
104c1213 20052
8e04817f
AC
20053The timeout set by @code{set timeout} does not apply when @value{GDBN}
20054is waiting for your program to stop. In that case, @value{GDBN} waits
20055forever because it has no way of knowing how long the program is going
20056to run before stopping.
ba04e063
EZ
20057
20058@item set syn-garbage-limit @var{num}
eb17f351
EZ
20059@kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
20060@cindex synchronize with remote @acronym{MIPS} target
ba04e063
EZ
20061Limit the maximum number of characters @value{GDBN} should ignore when
20062it tries to synchronize with the remote target. The default is 10
20063characters. Setting the limit to -1 means there's no limit.
20064
20065@item show syn-garbage-limit
eb17f351 20066@kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
ba04e063
EZ
20067Show the current limit on the number of characters to ignore when
20068trying to synchronize with the remote system.
20069
20070@item set monitor-prompt @var{prompt}
eb17f351 20071@kindex set monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
20072@cindex remote monitor prompt
20073Tell @value{GDBN} to expect the specified @var{prompt} string from the
20074remote monitor. The default depends on the target:
20075@table @asis
20076@item pmon target
20077@samp{PMON}
20078@item ddb target
20079@samp{NEC010}
20080@item lsi target
20081@samp{PMON>}
20082@end table
20083
20084@item show monitor-prompt
eb17f351 20085@kindex show monitor-prompt@r{, @acronym{MIPS} remote}
ba04e063
EZ
20086Show the current strings @value{GDBN} expects as the prompt from the
20087remote monitor.
20088
20089@item set monitor-warnings
eb17f351 20090@kindex set monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
20091Enable or disable monitor warnings about hardware breakpoints. This
20092has effect only for the @code{lsi} target. When on, @value{GDBN} will
20093display warning messages whose codes are returned by the @code{lsi}
20094PMON monitor for breakpoint commands.
20095
20096@item show monitor-warnings
eb17f351 20097@kindex show monitor-warnings@r{, @acronym{MIPS} remote}
ba04e063
EZ
20098Show the current setting of printing monitor warnings.
20099
20100@item pmon @var{command}
eb17f351 20101@kindex pmon@r{, @acronym{MIPS} remote}
ba04e063
EZ
20102@cindex send PMON command
20103This command allows sending an arbitrary @var{command} string to the
20104monitor. The monitor must be in debug mode for this to work.
8e04817f 20105@end table
104c1213 20106
a37295f9
MM
20107@node OpenRISC 1000
20108@subsection OpenRISC 1000
20109@cindex OpenRISC 1000
20110
20111@cindex or1k boards
20112See OR1k Architecture document (@uref{www.opencores.org}) for more information
20113about platform and commands.
20114
20115@table @code
20116
20117@kindex target jtag
20118@item target jtag jtag://@var{host}:@var{port}
20119
20120Connects to remote JTAG server.
20121JTAG remote server can be either an or1ksim or JTAG server,
20122connected via parallel port to the board.
20123
20124Example: @code{target jtag jtag://localhost:9999}
20125
20126@kindex or1ksim
20127@item or1ksim @var{command}
20128If connected to @code{or1ksim} OpenRISC 1000 Architectural
20129Simulator, proprietary commands can be executed.
20130
20131@kindex info or1k spr
20132@item info or1k spr
20133Displays spr groups.
20134
20135@item info or1k spr @var{group}
20136@itemx info or1k spr @var{groupno}
20137Displays register names in selected group.
20138
20139@item info or1k spr @var{group} @var{register}
20140@itemx info or1k spr @var{register}
20141@itemx info or1k spr @var{groupno} @var{registerno}
20142@itemx info or1k spr @var{registerno}
20143Shows information about specified spr register.
20144
20145@kindex spr
20146@item spr @var{group} @var{register} @var{value}
20147@itemx spr @var{register @var{value}}
20148@itemx spr @var{groupno} @var{registerno @var{value}}
20149@itemx spr @var{registerno @var{value}}
20150Writes @var{value} to specified spr register.
20151@end table
20152
20153Some implementations of OpenRISC 1000 Architecture also have hardware trace.
20154It is very similar to @value{GDBN} trace, except it does not interfere with normal
20155program execution and is thus much faster. Hardware breakpoints/watchpoint
20156triggers can be set using:
20157@table @code
20158@item $LEA/$LDATA
20159Load effective address/data
20160@item $SEA/$SDATA
20161Store effective address/data
20162@item $AEA/$ADATA
20163Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
20164@item $FETCH
20165Fetch data
20166@end table
20167
20168When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
20169@code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
20170
20171@code{htrace} commands:
20172@cindex OpenRISC 1000 htrace
20173@table @code
20174@kindex hwatch
20175@item hwatch @var{conditional}
d3e8051b 20176Set hardware watchpoint on combination of Load/Store Effective Address(es)
a37295f9
MM
20177or Data. For example:
20178
20179@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
20180
20181@code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
20182
4644b6e3 20183@kindex htrace
a37295f9
MM
20184@item htrace info
20185Display information about current HW trace configuration.
20186
a37295f9
MM
20187@item htrace trigger @var{conditional}
20188Set starting criteria for HW trace.
20189
a37295f9
MM
20190@item htrace qualifier @var{conditional}
20191Set acquisition qualifier for HW trace.
20192
a37295f9
MM
20193@item htrace stop @var{conditional}
20194Set HW trace stopping criteria.
20195
f153cc92 20196@item htrace record [@var{data}]*
a37295f9
MM
20197Selects the data to be recorded, when qualifier is met and HW trace was
20198triggered.
20199
a37295f9 20200@item htrace enable
a37295f9
MM
20201@itemx htrace disable
20202Enables/disables the HW trace.
20203
f153cc92 20204@item htrace rewind [@var{filename}]
a37295f9
MM
20205Clears currently recorded trace data.
20206
20207If filename is specified, new trace file is made and any newly collected data
20208will be written there.
20209
f153cc92 20210@item htrace print [@var{start} [@var{len}]]
a37295f9
MM
20211Prints trace buffer, using current record configuration.
20212
a37295f9
MM
20213@item htrace mode continuous
20214Set continuous trace mode.
20215
a37295f9
MM
20216@item htrace mode suspend
20217Set suspend trace mode.
20218
20219@end table
20220
4acd40f3
TJB
20221@node PowerPC Embedded
20222@subsection PowerPC Embedded
104c1213 20223
66b73624
TJB
20224@cindex DVC register
20225@value{GDBN} supports using the DVC (Data Value Compare) register to
20226implement in hardware simple hardware watchpoint conditions of the form:
20227
20228@smallexample
20229(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
20230 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
20231@end smallexample
20232
e09342b5
TJB
20233The DVC register will be automatically used when @value{GDBN} detects
20234such pattern in a condition expression, and the created watchpoint uses one
20235debug register (either the @code{exact-watchpoints} option is on and the
20236variable is scalar, or the variable has a length of one byte). This feature
20237is available in native @value{GDBN} running on a Linux kernel version 2.6.34
20238or newer.
20239
20240When running on PowerPC embedded processors, @value{GDBN} automatically uses
20241ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
20242in which case watchpoints using only one debug register are created when
20243watching variables of scalar types.
20244
20245You can create an artificial array to watch an arbitrary memory
20246region using one of the following commands (@pxref{Expressions}):
20247
20248@smallexample
20249(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
20250(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
20251@end smallexample
66b73624 20252
9c06b0b4
TJB
20253PowerPC embedded processors support masked watchpoints. See the discussion
20254about the @code{mask} argument in @ref{Set Watchpoints}.
20255
f1310107
TJB
20256@cindex ranged breakpoint
20257PowerPC embedded processors support hardware accelerated
20258@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
20259the inferior whenever it executes an instruction at any address within
20260the range it specifies. To set a ranged breakpoint in @value{GDBN},
20261use the @code{break-range} command.
20262
55eddb0f
DJ
20263@value{GDBN} provides the following PowerPC-specific commands:
20264
104c1213 20265@table @code
f1310107
TJB
20266@kindex break-range
20267@item break-range @var{start-location}, @var{end-location}
20268Set a breakpoint for an address range.
20269@var{start-location} and @var{end-location} can specify a function name,
20270a line number, an offset of lines from the current line or from the start
20271location, or an address of an instruction (see @ref{Specify Location},
20272for a list of all the possible ways to specify a @var{location}.)
20273The breakpoint will stop execution of the inferior whenever it
20274executes an instruction at any address within the specified range,
20275(including @var{start-location} and @var{end-location}.)
20276
55eddb0f
DJ
20277@kindex set powerpc
20278@item set powerpc soft-float
20279@itemx show powerpc soft-float
20280Force @value{GDBN} to use (or not use) a software floating point calling
20281convention. By default, @value{GDBN} selects the calling convention based
20282on the selected architecture and the provided executable file.
20283
20284@item set powerpc vector-abi
20285@itemx show powerpc vector-abi
20286Force @value{GDBN} to use the specified calling convention for vector
20287arguments and return values. The valid options are @samp{auto};
20288@samp{generic}, to avoid vector registers even if they are present;
20289@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
20290registers. By default, @value{GDBN} selects the calling convention
20291based on the selected architecture and the provided executable file.
20292
e09342b5
TJB
20293@item set powerpc exact-watchpoints
20294@itemx show powerpc exact-watchpoints
20295Allow @value{GDBN} to use only one debug register when watching a variable
20296of scalar type, thus assuming that the variable is accessed through the
20297address of its first byte.
20298
8e04817f
AC
20299@kindex target dink32
20300@item target dink32 @var{dev}
20301DINK32 ROM monitor.
104c1213 20302
8e04817f
AC
20303@kindex target ppcbug
20304@item target ppcbug @var{dev}
20305@kindex target ppcbug1
20306@item target ppcbug1 @var{dev}
20307PPCBUG ROM monitor for PowerPC.
104c1213 20308
8e04817f
AC
20309@kindex target sds
20310@item target sds @var{dev}
20311SDS monitor, running on a PowerPC board (such as Motorola's ADS).
c45da7e6 20312@end table
8e04817f 20313
c45da7e6 20314@cindex SDS protocol
d52fb0e9 20315The following commands specific to the SDS protocol are supported
55eddb0f 20316by @value{GDBN}:
c45da7e6
EZ
20317
20318@table @code
20319@item set sdstimeout @var{nsec}
20320@kindex set sdstimeout
20321Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
20322default is 2 seconds.
20323
20324@item show sdstimeout
20325@kindex show sdstimeout
20326Show the current value of the SDS timeout.
20327
20328@item sds @var{command}
20329@kindex sds@r{, a command}
20330Send the specified @var{command} string to the SDS monitor.
8e04817f
AC
20331@end table
20332
c45da7e6 20333
8e04817f
AC
20334@node PA
20335@subsection HP PA Embedded
104c1213
JM
20336
20337@table @code
20338
8e04817f
AC
20339@kindex target op50n
20340@item target op50n @var{dev}
20341OP50N monitor, running on an OKI HPPA board.
20342
20343@kindex target w89k
20344@item target w89k @var{dev}
20345W89K monitor, running on a Winbond HPPA board.
104c1213
JM
20346
20347@end table
20348
8e04817f
AC
20349@node Sparclet
20350@subsection Tsqware Sparclet
104c1213 20351
8e04817f
AC
20352@cindex Sparclet
20353
20354@value{GDBN} enables developers to debug tasks running on
20355Sparclet targets from a Unix host.
20356@value{GDBN} uses code that runs on
20357both the Unix host and on the Sparclet target. The program
20358@code{@value{GDBP}} is installed and executed on the Unix host.
104c1213 20359
8e04817f
AC
20360@table @code
20361@item remotetimeout @var{args}
20362@kindex remotetimeout
20363@value{GDBN} supports the option @code{remotetimeout}.
20364This option is set by the user, and @var{args} represents the number of
20365seconds @value{GDBN} waits for responses.
104c1213
JM
20366@end table
20367
8e04817f
AC
20368@cindex compiling, on Sparclet
20369When compiling for debugging, include the options @samp{-g} to get debug
20370information and @samp{-Ttext} to relocate the program to where you wish to
20371load it on the target. You may also want to add the options @samp{-n} or
20372@samp{-N} in order to reduce the size of the sections. Example:
104c1213 20373
474c8240 20374@smallexample
8e04817f 20375sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
474c8240 20376@end smallexample
104c1213 20377
8e04817f 20378You can use @code{objdump} to verify that the addresses are what you intended:
104c1213 20379
474c8240 20380@smallexample
8e04817f 20381sparclet-aout-objdump --headers --syms prog
474c8240 20382@end smallexample
104c1213 20383
8e04817f
AC
20384@cindex running, on Sparclet
20385Once you have set
20386your Unix execution search path to find @value{GDBN}, you are ready to
20387run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
20388(or @code{sparclet-aout-gdb}, depending on your installation).
104c1213 20389
8e04817f
AC
20390@value{GDBN} comes up showing the prompt:
20391
474c8240 20392@smallexample
8e04817f 20393(gdbslet)
474c8240 20394@end smallexample
104c1213
JM
20395
20396@menu
8e04817f
AC
20397* Sparclet File:: Setting the file to debug
20398* Sparclet Connection:: Connecting to Sparclet
20399* Sparclet Download:: Sparclet download
20400* Sparclet Execution:: Running and debugging
104c1213
JM
20401@end menu
20402
8e04817f 20403@node Sparclet File
79a6e687 20404@subsubsection Setting File to Debug
104c1213 20405
8e04817f 20406The @value{GDBN} command @code{file} lets you choose with program to debug.
104c1213 20407
474c8240 20408@smallexample
8e04817f 20409(gdbslet) file prog
474c8240 20410@end smallexample
104c1213 20411
8e04817f
AC
20412@need 1000
20413@value{GDBN} then attempts to read the symbol table of @file{prog}.
20414@value{GDBN} locates
20415the file by searching the directories listed in the command search
20416path.
12c27660 20417If the file was compiled with debug information (option @samp{-g}), source
8e04817f
AC
20418files will be searched as well.
20419@value{GDBN} locates
20420the source files by searching the directories listed in the directory search
79a6e687 20421path (@pxref{Environment, ,Your Program's Environment}).
8e04817f
AC
20422If it fails
20423to find a file, it displays a message such as:
104c1213 20424
474c8240 20425@smallexample
8e04817f 20426prog: No such file or directory.
474c8240 20427@end smallexample
104c1213 20428
8e04817f
AC
20429When this happens, add the appropriate directories to the search paths with
20430the @value{GDBN} commands @code{path} and @code{dir}, and execute the
20431@code{target} command again.
104c1213 20432
8e04817f
AC
20433@node Sparclet Connection
20434@subsubsection Connecting to Sparclet
104c1213 20435
8e04817f
AC
20436The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
20437To connect to a target on serial port ``@code{ttya}'', type:
104c1213 20438
474c8240 20439@smallexample
8e04817f
AC
20440(gdbslet) target sparclet /dev/ttya
20441Remote target sparclet connected to /dev/ttya
20442main () at ../prog.c:3
474c8240 20443@end smallexample
104c1213 20444
8e04817f
AC
20445@need 750
20446@value{GDBN} displays messages like these:
104c1213 20447
474c8240 20448@smallexample
8e04817f 20449Connected to ttya.
474c8240 20450@end smallexample
104c1213 20451
8e04817f 20452@node Sparclet Download
79a6e687 20453@subsubsection Sparclet Download
104c1213 20454
8e04817f
AC
20455@cindex download to Sparclet
20456Once connected to the Sparclet target,
20457you can use the @value{GDBN}
20458@code{load} command to download the file from the host to the target.
20459The file name and load offset should be given as arguments to the @code{load}
20460command.
20461Since the file format is aout, the program must be loaded to the starting
20462address. You can use @code{objdump} to find out what this value is. The load
20463offset is an offset which is added to the VMA (virtual memory address)
20464of each of the file's sections.
20465For instance, if the program
20466@file{prog} was linked to text address 0x1201000, with data at 0x12010160
20467and bss at 0x12010170, in @value{GDBN}, type:
104c1213 20468
474c8240 20469@smallexample
8e04817f
AC
20470(gdbslet) load prog 0x12010000
20471Loading section .text, size 0xdb0 vma 0x12010000
474c8240 20472@end smallexample
104c1213 20473
8e04817f
AC
20474If the code is loaded at a different address then what the program was linked
20475to, you may need to use the @code{section} and @code{add-symbol-file} commands
20476to tell @value{GDBN} where to map the symbol table.
20477
20478@node Sparclet Execution
79a6e687 20479@subsubsection Running and Debugging
8e04817f
AC
20480
20481@cindex running and debugging Sparclet programs
20482You can now begin debugging the task using @value{GDBN}'s execution control
20483commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
20484manual for the list of commands.
20485
474c8240 20486@smallexample
8e04817f
AC
20487(gdbslet) b main
20488Breakpoint 1 at 0x12010000: file prog.c, line 3.
20489(gdbslet) run
20490Starting program: prog
20491Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
204923 char *symarg = 0;
20493(gdbslet) step
204944 char *execarg = "hello!";
20495(gdbslet)
474c8240 20496@end smallexample
8e04817f
AC
20497
20498@node Sparclite
20499@subsection Fujitsu Sparclite
104c1213
JM
20500
20501@table @code
20502
8e04817f
AC
20503@kindex target sparclite
20504@item target sparclite @var{dev}
20505Fujitsu sparclite boards, used only for the purpose of loading.
20506You must use an additional command to debug the program.
20507For example: target remote @var{dev} using @value{GDBN} standard
20508remote protocol.
104c1213
JM
20509
20510@end table
20511
8e04817f
AC
20512@node Z8000
20513@subsection Zilog Z8000
104c1213 20514
8e04817f
AC
20515@cindex Z8000
20516@cindex simulator, Z8000
20517@cindex Zilog Z8000 simulator
104c1213 20518
8e04817f
AC
20519When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
20520a Z8000 simulator.
20521
20522For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
20523unsegmented variant of the Z8000 architecture) or the Z8001 (the
20524segmented variant). The simulator recognizes which architecture is
20525appropriate by inspecting the object code.
104c1213 20526
8e04817f
AC
20527@table @code
20528@item target sim @var{args}
20529@kindex sim
20530@kindex target sim@r{, with Z8000}
20531Debug programs on a simulated CPU. If the simulator supports setup
20532options, specify them via @var{args}.
104c1213
JM
20533@end table
20534
8e04817f
AC
20535@noindent
20536After specifying this target, you can debug programs for the simulated
20537CPU in the same style as programs for your host computer; use the
20538@code{file} command to load a new program image, the @code{run} command
20539to run your program, and so on.
20540
20541As well as making available all the usual machine registers
20542(@pxref{Registers, ,Registers}), the Z8000 simulator provides three
20543additional items of information as specially named registers:
104c1213
JM
20544
20545@table @code
20546
8e04817f
AC
20547@item cycles
20548Counts clock-ticks in the simulator.
104c1213 20549
8e04817f
AC
20550@item insts
20551Counts instructions run in the simulator.
104c1213 20552
8e04817f
AC
20553@item time
20554Execution time in 60ths of a second.
104c1213 20555
8e04817f 20556@end table
104c1213 20557
8e04817f
AC
20558You can refer to these values in @value{GDBN} expressions with the usual
20559conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
20560conditional breakpoint that suspends only after at least 5000
20561simulated clock ticks.
104c1213 20562
a64548ea
EZ
20563@node AVR
20564@subsection Atmel AVR
20565@cindex AVR
20566
20567When configured for debugging the Atmel AVR, @value{GDBN} supports the
20568following AVR-specific commands:
20569
20570@table @code
20571@item info io_registers
20572@kindex info io_registers@r{, AVR}
20573@cindex I/O registers (Atmel AVR)
20574This command displays information about the AVR I/O registers. For
20575each register, @value{GDBN} prints its number and value.
20576@end table
20577
20578@node CRIS
20579@subsection CRIS
20580@cindex CRIS
20581
20582When configured for debugging CRIS, @value{GDBN} provides the
20583following CRIS-specific commands:
20584
20585@table @code
20586@item set cris-version @var{ver}
20587@cindex CRIS version
e22e55c9
OF
20588Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
20589The CRIS version affects register names and sizes. This command is useful in
20590case autodetection of the CRIS version fails.
a64548ea
EZ
20591
20592@item show cris-version
20593Show the current CRIS version.
20594
20595@item set cris-dwarf2-cfi
20596@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
20597Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
20598Change to @samp{off} when using @code{gcc-cris} whose version is below
20599@code{R59}.
a64548ea
EZ
20600
20601@item show cris-dwarf2-cfi
20602Show the current state of using DWARF-2 CFI.
e22e55c9
OF
20603
20604@item set cris-mode @var{mode}
20605@cindex CRIS mode
20606Set the current CRIS mode to @var{mode}. It should only be changed when
20607debugging in guru mode, in which case it should be set to
20608@samp{guru} (the default is @samp{normal}).
20609
20610@item show cris-mode
20611Show the current CRIS mode.
a64548ea
EZ
20612@end table
20613
20614@node Super-H
20615@subsection Renesas Super-H
20616@cindex Super-H
20617
20618For the Renesas Super-H processor, @value{GDBN} provides these
20619commands:
20620
20621@table @code
c055b101
CV
20622@item set sh calling-convention @var{convention}
20623@kindex set sh calling-convention
20624Set the calling-convention used when calling functions from @value{GDBN}.
20625Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
20626With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
20627convention. If the DWARF-2 information of the called function specifies
20628that the function follows the Renesas calling convention, the function
20629is called using the Renesas calling convention. If the calling convention
20630is set to @samp{renesas}, the Renesas calling convention is always used,
20631regardless of the DWARF-2 information. This can be used to override the
20632default of @samp{gcc} if debug information is missing, or the compiler
20633does not emit the DWARF-2 calling convention entry for a function.
20634
20635@item show sh calling-convention
20636@kindex show sh calling-convention
20637Show the current calling convention setting.
20638
a64548ea
EZ
20639@end table
20640
20641
8e04817f
AC
20642@node Architectures
20643@section Architectures
104c1213 20644
8e04817f
AC
20645This section describes characteristics of architectures that affect
20646all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 20647
8e04817f 20648@menu
9c16f35a 20649* i386::
8e04817f
AC
20650* Alpha::
20651* MIPS::
a64548ea 20652* HPPA:: HP PA architecture
23d964e7 20653* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 20654* PowerPC::
8e04817f 20655@end menu
104c1213 20656
9c16f35a 20657@node i386
db2e3e2e 20658@subsection x86 Architecture-specific Issues
9c16f35a
EZ
20659
20660@table @code
20661@item set struct-convention @var{mode}
20662@kindex set struct-convention
20663@cindex struct return convention
20664@cindex struct/union returned in registers
20665Set the convention used by the inferior to return @code{struct}s and
20666@code{union}s from functions to @var{mode}. Possible values of
20667@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
20668default). @code{"default"} or @code{"pcc"} means that @code{struct}s
20669are returned on the stack, while @code{"reg"} means that a
20670@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
20671be returned in a register.
20672
20673@item show struct-convention
20674@kindex show struct-convention
20675Show the current setting of the convention to return @code{struct}s
20676from functions.
20677@end table
20678
8e04817f
AC
20679@node Alpha
20680@subsection Alpha
104c1213 20681
8e04817f 20682See the following section.
104c1213 20683
8e04817f 20684@node MIPS
eb17f351 20685@subsection @acronym{MIPS}
104c1213 20686
8e04817f 20687@cindex stack on Alpha
eb17f351 20688@cindex stack on @acronym{MIPS}
8e04817f 20689@cindex Alpha stack
eb17f351
EZ
20690@cindex @acronym{MIPS} stack
20691Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
20692sometimes requires @value{GDBN} to search backward in the object code to
20693find the beginning of a function.
104c1213 20694
eb17f351 20695@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
20696To improve response time (especially for embedded applications, where
20697@value{GDBN} may be restricted to a slow serial line for this search)
20698you may want to limit the size of this search, using one of these
20699commands:
104c1213 20700
8e04817f 20701@table @code
eb17f351 20702@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
20703@item set heuristic-fence-post @var{limit}
20704Restrict @value{GDBN} to examining at most @var{limit} bytes in its
20705search for the beginning of a function. A value of @var{0} (the
20706default) means there is no limit. However, except for @var{0}, the
20707larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
20708and therefore the longer it takes to run. You should only need to use
20709this command when debugging a stripped executable.
104c1213 20710
8e04817f
AC
20711@item show heuristic-fence-post
20712Display the current limit.
20713@end table
104c1213
JM
20714
20715@noindent
8e04817f 20716These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 20717for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 20718
eb17f351 20719Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
20720programs:
20721
20722@table @code
a64548ea
EZ
20723@item set mips abi @var{arg}
20724@kindex set mips abi
eb17f351
EZ
20725@cindex set ABI for @acronym{MIPS}
20726Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
20727values of @var{arg} are:
20728
20729@table @samp
20730@item auto
20731The default ABI associated with the current binary (this is the
20732default).
20733@item o32
20734@item o64
20735@item n32
20736@item n64
20737@item eabi32
20738@item eabi64
a64548ea
EZ
20739@end table
20740
20741@item show mips abi
20742@kindex show mips abi
eb17f351 20743Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 20744
4cc0665f
MR
20745@item set mips compression @var{arg}
20746@kindex set mips compression
20747@cindex code compression, @acronym{MIPS}
20748Tell @value{GDBN} which @acronym{MIPS} compressed
20749@acronym{ISA, Instruction Set Architecture} encoding is used by the
20750inferior. @value{GDBN} uses this for code disassembly and other
20751internal interpretation purposes. This setting is only referred to
20752when no executable has been associated with the debugging session or
20753the executable does not provide information about the encoding it uses.
20754Otherwise this setting is automatically updated from information
20755provided by the executable.
20756
20757Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
20758The default compressed @acronym{ISA} encoding is @samp{mips16}, as
20759executables containing @acronym{MIPS16} code frequently are not
20760identified as such.
20761
20762This setting is ``sticky''; that is, it retains its value across
20763debugging sessions until reset either explicitly with this command or
20764implicitly from an executable.
20765
20766The compiler and/or assembler typically add symbol table annotations to
20767identify functions compiled for the @acronym{MIPS16} or
20768@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
20769are present, @value{GDBN} uses them in preference to the global
20770compressed @acronym{ISA} encoding setting.
20771
20772@item show mips compression
20773@kindex show mips compression
20774Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
20775@value{GDBN} to debug the inferior.
20776
a64548ea
EZ
20777@item set mipsfpu
20778@itemx show mipsfpu
20779@xref{MIPS Embedded, set mipsfpu}.
20780
20781@item set mips mask-address @var{arg}
20782@kindex set mips mask-address
eb17f351 20783@cindex @acronym{MIPS} addresses, masking
a64548ea 20784This command determines whether the most-significant 32 bits of 64-bit
eb17f351 20785@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
20786@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
20787setting, which lets @value{GDBN} determine the correct value.
20788
20789@item show mips mask-address
20790@kindex show mips mask-address
eb17f351 20791Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
20792not.
20793
20794@item set remote-mips64-transfers-32bit-regs
20795@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
20796This command controls compatibility with 64-bit @acronym{MIPS} targets that
20797transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
20798that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
20799and 64 bits for other registers, set this option to @samp{on}.
20800
20801@item show remote-mips64-transfers-32bit-regs
20802@kindex show remote-mips64-transfers-32bit-regs
eb17f351 20803Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
20804
20805@item set debug mips
20806@kindex set debug mips
eb17f351 20807This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
20808target code in @value{GDBN}.
20809
20810@item show debug mips
20811@kindex show debug mips
eb17f351 20812Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
20813@end table
20814
20815
20816@node HPPA
20817@subsection HPPA
20818@cindex HPPA support
20819
d3e8051b 20820When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
20821following special commands:
20822
20823@table @code
20824@item set debug hppa
20825@kindex set debug hppa
db2e3e2e 20826This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
20827messages are to be displayed.
20828
20829@item show debug hppa
20830Show whether HPPA debugging messages are displayed.
20831
20832@item maint print unwind @var{address}
20833@kindex maint print unwind@r{, HPPA}
20834This command displays the contents of the unwind table entry at the
20835given @var{address}.
20836
20837@end table
20838
104c1213 20839
23d964e7
UW
20840@node SPU
20841@subsection Cell Broadband Engine SPU architecture
20842@cindex Cell Broadband Engine
20843@cindex SPU
20844
20845When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
20846it provides the following special commands:
20847
20848@table @code
20849@item info spu event
20850@kindex info spu
20851Display SPU event facility status. Shows current event mask
20852and pending event status.
20853
20854@item info spu signal
20855Display SPU signal notification facility status. Shows pending
20856signal-control word and signal notification mode of both signal
20857notification channels.
20858
20859@item info spu mailbox
20860Display SPU mailbox facility status. Shows all pending entries,
20861in order of processing, in each of the SPU Write Outbound,
20862SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
20863
20864@item info spu dma
20865Display MFC DMA status. Shows all pending commands in the MFC
20866DMA queue. For each entry, opcode, tag, class IDs, effective
20867and local store addresses and transfer size are shown.
20868
20869@item info spu proxydma
20870Display MFC Proxy-DMA status. Shows all pending commands in the MFC
20871Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
20872and local store addresses and transfer size are shown.
20873
20874@end table
20875
3285f3fe
UW
20876When @value{GDBN} is debugging a combined PowerPC/SPU application
20877on the Cell Broadband Engine, it provides in addition the following
20878special commands:
20879
20880@table @code
20881@item set spu stop-on-load @var{arg}
20882@kindex set spu
20883Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
20884will give control to the user when a new SPE thread enters its @code{main}
20885function. The default is @code{off}.
20886
20887@item show spu stop-on-load
20888@kindex show spu
20889Show whether to stop for new SPE threads.
20890
ff1a52c6
UW
20891@item set spu auto-flush-cache @var{arg}
20892Set whether to automatically flush the software-managed cache. When set to
20893@code{on}, @value{GDBN} will automatically cause the SPE software-managed
20894cache to be flushed whenever SPE execution stops. This provides a consistent
20895view of PowerPC memory that is accessed via the cache. If an application
20896does not use the software-managed cache, this option has no effect.
20897
20898@item show spu auto-flush-cache
20899Show whether to automatically flush the software-managed cache.
20900
3285f3fe
UW
20901@end table
20902
4acd40f3
TJB
20903@node PowerPC
20904@subsection PowerPC
20905@cindex PowerPC architecture
20906
20907When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
20908pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
20909numbers stored in the floating point registers. These values must be stored
20910in two consecutive registers, always starting at an even register like
20911@code{f0} or @code{f2}.
20912
20913The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
20914by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
20915@code{f2} and @code{f3} for @code{$dl1} and so on.
20916
aeac0ff9 20917For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
20918wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
20919
23d964e7 20920
8e04817f
AC
20921@node Controlling GDB
20922@chapter Controlling @value{GDBN}
20923
20924You can alter the way @value{GDBN} interacts with you by using the
20925@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 20926data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
20927described here.
20928
20929@menu
20930* Prompt:: Prompt
20931* Editing:: Command editing
d620b259 20932* Command History:: Command history
8e04817f
AC
20933* Screen Size:: Screen size
20934* Numbers:: Numbers
1e698235 20935* ABI:: Configuring the current ABI
bf88dd68 20936* Auto-loading:: Automatically loading associated files
8e04817f
AC
20937* Messages/Warnings:: Optional warnings and messages
20938* Debugging Output:: Optional messages about internal happenings
14fb1bac 20939* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
20940@end menu
20941
20942@node Prompt
20943@section Prompt
104c1213 20944
8e04817f 20945@cindex prompt
104c1213 20946
8e04817f
AC
20947@value{GDBN} indicates its readiness to read a command by printing a string
20948called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
20949can change the prompt string with the @code{set prompt} command. For
20950instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
20951the prompt in one of the @value{GDBN} sessions so that you can always tell
20952which one you are talking to.
104c1213 20953
8e04817f
AC
20954@emph{Note:} @code{set prompt} does not add a space for you after the
20955prompt you set. This allows you to set a prompt which ends in a space
20956or a prompt that does not.
104c1213 20957
8e04817f
AC
20958@table @code
20959@kindex set prompt
20960@item set prompt @var{newprompt}
20961Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 20962
8e04817f
AC
20963@kindex show prompt
20964@item show prompt
20965Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
20966@end table
20967
fa3a4f15
PM
20968Versions of @value{GDBN} that ship with Python scripting enabled have
20969prompt extensions. The commands for interacting with these extensions
20970are:
20971
20972@table @code
20973@kindex set extended-prompt
20974@item set extended-prompt @var{prompt}
20975Set an extended prompt that allows for substitutions.
20976@xref{gdb.prompt}, for a list of escape sequences that can be used for
20977substitution. Any escape sequences specified as part of the prompt
20978string are replaced with the corresponding strings each time the prompt
20979is displayed.
20980
20981For example:
20982
20983@smallexample
20984set extended-prompt Current working directory: \w (gdb)
20985@end smallexample
20986
20987Note that when an extended-prompt is set, it takes control of the
20988@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
20989
20990@kindex show extended-prompt
20991@item show extended-prompt
20992Prints the extended prompt. Any escape sequences specified as part of
20993the prompt string with @code{set extended-prompt}, are replaced with the
20994corresponding strings each time the prompt is displayed.
20995@end table
20996
8e04817f 20997@node Editing
79a6e687 20998@section Command Editing
8e04817f
AC
20999@cindex readline
21000@cindex command line editing
104c1213 21001
703663ab 21002@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
21003@sc{gnu} library provides consistent behavior for programs which provide a
21004command line interface to the user. Advantages are @sc{gnu} Emacs-style
21005or @dfn{vi}-style inline editing of commands, @code{csh}-like history
21006substitution, and a storage and recall of command history across
21007debugging sessions.
104c1213 21008
8e04817f
AC
21009You may control the behavior of command line editing in @value{GDBN} with the
21010command @code{set}.
104c1213 21011
8e04817f
AC
21012@table @code
21013@kindex set editing
21014@cindex editing
21015@item set editing
21016@itemx set editing on
21017Enable command line editing (enabled by default).
104c1213 21018
8e04817f
AC
21019@item set editing off
21020Disable command line editing.
104c1213 21021
8e04817f
AC
21022@kindex show editing
21023@item show editing
21024Show whether command line editing is enabled.
104c1213
JM
21025@end table
21026
39037522
TT
21027@ifset SYSTEM_READLINE
21028@xref{Command Line Editing, , , rluserman, GNU Readline Library},
21029@end ifset
21030@ifclear SYSTEM_READLINE
21031@xref{Command Line Editing},
21032@end ifclear
21033for more details about the Readline
703663ab
EZ
21034interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
21035encouraged to read that chapter.
21036
d620b259 21037@node Command History
79a6e687 21038@section Command History
703663ab 21039@cindex command history
8e04817f
AC
21040
21041@value{GDBN} can keep track of the commands you type during your
21042debugging sessions, so that you can be certain of precisely what
21043happened. Use these commands to manage the @value{GDBN} command
21044history facility.
104c1213 21045
703663ab 21046@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
21047package, to provide the history facility.
21048@ifset SYSTEM_READLINE
21049@xref{Using History Interactively, , , history, GNU History Library},
21050@end ifset
21051@ifclear SYSTEM_READLINE
21052@xref{Using History Interactively},
21053@end ifclear
21054for the detailed description of the History library.
703663ab 21055
d620b259 21056To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
21057the state which is seen by users, prefix it with @samp{server }
21058(@pxref{Server Prefix}). This
d620b259
NR
21059means that this command will not affect the command history, nor will it
21060affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
21061pressed on a line by itself.
21062
21063@cindex @code{server}, command prefix
21064The server prefix does not affect the recording of values into the value
21065history; to print a value without recording it into the value history,
21066use the @code{output} command instead of the @code{print} command.
21067
703663ab
EZ
21068Here is the description of @value{GDBN} commands related to command
21069history.
21070
104c1213 21071@table @code
8e04817f
AC
21072@cindex history substitution
21073@cindex history file
21074@kindex set history filename
4644b6e3 21075@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
21076@item set history filename @var{fname}
21077Set the name of the @value{GDBN} command history file to @var{fname}.
21078This is the file where @value{GDBN} reads an initial command history
21079list, and where it writes the command history from this session when it
21080exits. You can access this list through history expansion or through
21081the history command editing characters listed below. This file defaults
21082to the value of the environment variable @code{GDBHISTFILE}, or to
21083@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
21084is not set.
104c1213 21085
9c16f35a
EZ
21086@cindex save command history
21087@kindex set history save
8e04817f
AC
21088@item set history save
21089@itemx set history save on
21090Record command history in a file, whose name may be specified with the
21091@code{set history filename} command. By default, this option is disabled.
104c1213 21092
8e04817f
AC
21093@item set history save off
21094Stop recording command history in a file.
104c1213 21095
8e04817f 21096@cindex history size
9c16f35a 21097@kindex set history size
6fc08d32 21098@cindex @env{HISTSIZE}, environment variable
8e04817f
AC
21099@item set history size @var{size}
21100Set the number of commands which @value{GDBN} keeps in its history list.
21101This defaults to the value of the environment variable
21102@code{HISTSIZE}, or to 256 if this variable is not set.
104c1213
JM
21103@end table
21104
8e04817f 21105History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
21106@ifset SYSTEM_READLINE
21107@xref{Event Designators, , , history, GNU History Library},
21108@end ifset
21109@ifclear SYSTEM_READLINE
21110@xref{Event Designators},
21111@end ifclear
21112for more details.
8e04817f 21113
703663ab 21114@cindex history expansion, turn on/off
8e04817f
AC
21115Since @kbd{!} is also the logical not operator in C, history expansion
21116is off by default. If you decide to enable history expansion with the
21117@code{set history expansion on} command, you may sometimes need to
21118follow @kbd{!} (when it is used as logical not, in an expression) with
21119a space or a tab to prevent it from being expanded. The readline
21120history facilities do not attempt substitution on the strings
21121@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
21122
21123The commands to control history expansion are:
104c1213
JM
21124
21125@table @code
8e04817f
AC
21126@item set history expansion on
21127@itemx set history expansion
703663ab 21128@kindex set history expansion
8e04817f 21129Enable history expansion. History expansion is off by default.
104c1213 21130
8e04817f
AC
21131@item set history expansion off
21132Disable history expansion.
104c1213 21133
8e04817f
AC
21134@c @group
21135@kindex show history
21136@item show history
21137@itemx show history filename
21138@itemx show history save
21139@itemx show history size
21140@itemx show history expansion
21141These commands display the state of the @value{GDBN} history parameters.
21142@code{show history} by itself displays all four states.
21143@c @end group
21144@end table
21145
21146@table @code
9c16f35a
EZ
21147@kindex show commands
21148@cindex show last commands
21149@cindex display command history
8e04817f
AC
21150@item show commands
21151Display the last ten commands in the command history.
104c1213 21152
8e04817f
AC
21153@item show commands @var{n}
21154Print ten commands centered on command number @var{n}.
21155
21156@item show commands +
21157Print ten commands just after the commands last printed.
104c1213
JM
21158@end table
21159
8e04817f 21160@node Screen Size
79a6e687 21161@section Screen Size
8e04817f
AC
21162@cindex size of screen
21163@cindex pauses in output
104c1213 21164
8e04817f
AC
21165Certain commands to @value{GDBN} may produce large amounts of
21166information output to the screen. To help you read all of it,
21167@value{GDBN} pauses and asks you for input at the end of each page of
21168output. Type @key{RET} when you want to continue the output, or @kbd{q}
21169to discard the remaining output. Also, the screen width setting
21170determines when to wrap lines of output. Depending on what is being
21171printed, @value{GDBN} tries to break the line at a readable place,
21172rather than simply letting it overflow onto the following line.
21173
21174Normally @value{GDBN} knows the size of the screen from the terminal
21175driver software. For example, on Unix @value{GDBN} uses the termcap data base
21176together with the value of the @code{TERM} environment variable and the
21177@code{stty rows} and @code{stty cols} settings. If this is not correct,
21178you can override it with the @code{set height} and @code{set
21179width} commands:
21180
21181@table @code
21182@kindex set height
21183@kindex set width
21184@kindex show width
21185@kindex show height
21186@item set height @var{lpp}
21187@itemx show height
21188@itemx set width @var{cpl}
21189@itemx show width
21190These @code{set} commands specify a screen height of @var{lpp} lines and
21191a screen width of @var{cpl} characters. The associated @code{show}
21192commands display the current settings.
104c1213 21193
8e04817f
AC
21194If you specify a height of zero lines, @value{GDBN} does not pause during
21195output no matter how long the output is. This is useful if output is to a
21196file or to an editor buffer.
104c1213 21197
8e04817f
AC
21198Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
21199from wrapping its output.
9c16f35a
EZ
21200
21201@item set pagination on
21202@itemx set pagination off
21203@kindex set pagination
21204Turn the output pagination on or off; the default is on. Turning
7c953934
TT
21205pagination off is the alternative to @code{set height 0}. Note that
21206running @value{GDBN} with the @option{--batch} option (@pxref{Mode
21207Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
21208
21209@item show pagination
21210@kindex show pagination
21211Show the current pagination mode.
104c1213
JM
21212@end table
21213
8e04817f
AC
21214@node Numbers
21215@section Numbers
21216@cindex number representation
21217@cindex entering numbers
104c1213 21218
8e04817f
AC
21219You can always enter numbers in octal, decimal, or hexadecimal in
21220@value{GDBN} by the usual conventions: octal numbers begin with
21221@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
21222begin with @samp{0x}. Numbers that neither begin with @samp{0} or
21223@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2122410; likewise, the default display for numbers---when no particular
21225format is specified---is base 10. You can change the default base for
21226both input and output with the commands described below.
104c1213 21227
8e04817f
AC
21228@table @code
21229@kindex set input-radix
21230@item set input-radix @var{base}
21231Set the default base for numeric input. Supported choices
21232for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 21233specified either unambiguously or using the current input radix; for
8e04817f 21234example, any of
104c1213 21235
8e04817f 21236@smallexample
9c16f35a
EZ
21237set input-radix 012
21238set input-radix 10.
21239set input-radix 0xa
8e04817f 21240@end smallexample
104c1213 21241
8e04817f 21242@noindent
9c16f35a 21243sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
21244leaves the input radix unchanged, no matter what it was, since
21245@samp{10}, being without any leading or trailing signs of its base, is
21246interpreted in the current radix. Thus, if the current radix is 16,
21247@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
21248change the radix.
104c1213 21249
8e04817f
AC
21250@kindex set output-radix
21251@item set output-radix @var{base}
21252Set the default base for numeric display. Supported choices
21253for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
eb2dae08 21254specified either unambiguously or using the current input radix.
104c1213 21255
8e04817f
AC
21256@kindex show input-radix
21257@item show input-radix
21258Display the current default base for numeric input.
104c1213 21259
8e04817f
AC
21260@kindex show output-radix
21261@item show output-radix
21262Display the current default base for numeric display.
9c16f35a
EZ
21263
21264@item set radix @r{[}@var{base}@r{]}
21265@itemx show radix
21266@kindex set radix
21267@kindex show radix
21268These commands set and show the default base for both input and output
21269of numbers. @code{set radix} sets the radix of input and output to
21270the same base; without an argument, it resets the radix back to its
21271default value of 10.
21272
8e04817f 21273@end table
104c1213 21274
1e698235 21275@node ABI
79a6e687 21276@section Configuring the Current ABI
1e698235
DJ
21277
21278@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
21279application automatically. However, sometimes you need to override its
21280conclusions. Use these commands to manage @value{GDBN}'s view of the
21281current ABI.
21282
98b45e30
DJ
21283@cindex OS ABI
21284@kindex set osabi
b4e9345d 21285@kindex show osabi
98b45e30
DJ
21286
21287One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 21288system targets, either via remote debugging or native emulation.
98b45e30
DJ
21289@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
21290but you can override its conclusion using the @code{set osabi} command.
21291One example where this is useful is in debugging of binaries which use
21292an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
21293not have the same identifying marks that the standard C library for your
21294platform provides.
21295
21296@table @code
21297@item show osabi
21298Show the OS ABI currently in use.
21299
21300@item set osabi
21301With no argument, show the list of registered available OS ABI's.
21302
21303@item set osabi @var{abi}
21304Set the current OS ABI to @var{abi}.
21305@end table
21306
1e698235 21307@cindex float promotion
1e698235
DJ
21308
21309Generally, the way that an argument of type @code{float} is passed to a
21310function depends on whether the function is prototyped. For a prototyped
21311(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
21312according to the architecture's convention for @code{float}. For unprototyped
21313(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
21314@code{double} and then passed.
21315
21316Unfortunately, some forms of debug information do not reliably indicate whether
21317a function is prototyped. If @value{GDBN} calls a function that is not marked
21318as prototyped, it consults @kbd{set coerce-float-to-double}.
21319
21320@table @code
a8f24a35 21321@kindex set coerce-float-to-double
1e698235
DJ
21322@item set coerce-float-to-double
21323@itemx set coerce-float-to-double on
21324Arguments of type @code{float} will be promoted to @code{double} when passed
21325to an unprototyped function. This is the default setting.
21326
21327@item set coerce-float-to-double off
21328Arguments of type @code{float} will be passed directly to unprototyped
21329functions.
9c16f35a
EZ
21330
21331@kindex show coerce-float-to-double
21332@item show coerce-float-to-double
21333Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
21334@end table
21335
f1212245
DJ
21336@kindex set cp-abi
21337@kindex show cp-abi
21338@value{GDBN} needs to know the ABI used for your program's C@t{++}
21339objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
21340used to build your application. @value{GDBN} only fully supports
21341programs with a single C@t{++} ABI; if your program contains code using
21342multiple C@t{++} ABI's or if @value{GDBN} can not identify your
21343program's ABI correctly, you can tell @value{GDBN} which ABI to use.
21344Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
21345before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
21346``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
21347use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
21348``auto''.
21349
21350@table @code
21351@item show cp-abi
21352Show the C@t{++} ABI currently in use.
21353
21354@item set cp-abi
21355With no argument, show the list of supported C@t{++} ABI's.
21356
21357@item set cp-abi @var{abi}
21358@itemx set cp-abi auto
21359Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
21360@end table
21361
bf88dd68
JK
21362@node Auto-loading
21363@section Automatically loading associated files
21364@cindex auto-loading
21365
21366@value{GDBN} sometimes reads files with commands and settings automatically,
21367without being explicitly told so by the user. We call this feature
21368@dfn{auto-loading}. While auto-loading is useful for automatically adapting
21369@value{GDBN} to the needs of your project, it can sometimes produce unexpected
21370results or introduce security risks (e.g., if the file comes from untrusted
21371sources).
21372
c1668e4e
JK
21373Note that loading of these associated files (including the local @file{.gdbinit}
21374file) requires accordingly configured @code{auto-load safe-path}
21375(@pxref{Auto-loading safe path}).
21376
bf88dd68
JK
21377For these reasons, @value{GDBN} includes commands and options to let you
21378control when to auto-load files and which files should be auto-loaded.
21379
21380@table @code
21381@anchor{set auto-load off}
21382@kindex set auto-load off
21383@item set auto-load off
21384Globally disable loading of all auto-loaded files.
21385You may want to use this command with the @samp{-iex} option
21386(@pxref{Option -init-eval-command}) such as:
21387@smallexample
21388$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
21389@end smallexample
21390
21391Be aware that system init file (@pxref{System-wide configuration})
21392and init files from your home directory (@pxref{Home Directory Init File})
21393still get read (as they come from generally trusted directories).
21394To prevent @value{GDBN} from auto-loading even those init files, use the
21395@option{-nx} option (@pxref{Mode Options}), in addition to
21396@code{set auto-load no}.
21397
21398@anchor{show auto-load}
21399@kindex show auto-load
21400@item show auto-load
21401Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
21402or disabled.
21403
21404@smallexample
21405(gdb) show auto-load
21406gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
21407libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
21408local-gdbinit: Auto-loading of .gdbinit script from current directory
21409 is on.
bf88dd68 21410python-scripts: Auto-loading of Python scripts is on.
bccbefd2 21411safe-path: List of directories from which it is safe to auto-load files
1564a261 21412 is $debugdir:$datadir/auto-load.
7349ff92 21413scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 21414 is $debugdir:$datadir/auto-load.
bf88dd68
JK
21415@end smallexample
21416
21417@anchor{info auto-load}
21418@kindex info auto-load
21419@item info auto-load
21420Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
21421not.
21422
21423@smallexample
21424(gdb) info auto-load
21425gdb-scripts:
21426Loaded Script
21427Yes /home/user/gdb/gdb-gdb.gdb
21428libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
21429local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
21430 loaded.
bf88dd68
JK
21431python-scripts:
21432Loaded Script
21433Yes /home/user/gdb/gdb-gdb.py
21434@end smallexample
21435@end table
21436
21437These are various kinds of files @value{GDBN} can automatically load:
21438
21439@itemize @bullet
21440@item
21441@xref{objfile-gdb.py file}, controlled by @ref{set auto-load python-scripts}.
21442@item
21443@xref{objfile-gdb.gdb file}, controlled by @ref{set auto-load gdb-scripts}.
21444@item
21445@xref{dotdebug_gdb_scripts section},
21446controlled by @ref{set auto-load python-scripts}.
21447@item
21448@xref{Init File in the Current Directory},
21449controlled by @ref{set auto-load local-gdbinit}.
21450@item
21451@xref{libthread_db.so.1 file}, controlled by @ref{set auto-load libthread-db}.
21452@end itemize
21453
21454These are @value{GDBN} control commands for the auto-loading:
21455
21456@multitable @columnfractions .5 .5
21457@item @xref{set auto-load off}.
21458@tab Disable auto-loading globally.
21459@item @xref{show auto-load}.
21460@tab Show setting of all kinds of files.
21461@item @xref{info auto-load}.
21462@tab Show state of all kinds of files.
21463@item @xref{set auto-load gdb-scripts}.
21464@tab Control for @value{GDBN} command scripts.
21465@item @xref{show auto-load gdb-scripts}.
21466@tab Show setting of @value{GDBN} command scripts.
21467@item @xref{info auto-load gdb-scripts}.
21468@tab Show state of @value{GDBN} command scripts.
21469@item @xref{set auto-load python-scripts}.
21470@tab Control for @value{GDBN} Python scripts.
21471@item @xref{show auto-load python-scripts}.
21472@tab Show setting of @value{GDBN} Python scripts.
21473@item @xref{info auto-load python-scripts}.
21474@tab Show state of @value{GDBN} Python scripts.
7349ff92
JK
21475@item @xref{set auto-load scripts-directory}.
21476@tab Control for @value{GDBN} auto-loaded scripts location.
21477@item @xref{show auto-load scripts-directory}.
21478@tab Show @value{GDBN} auto-loaded scripts location.
bf88dd68
JK
21479@item @xref{set auto-load local-gdbinit}.
21480@tab Control for init file in the current directory.
21481@item @xref{show auto-load local-gdbinit}.
21482@tab Show setting of init file in the current directory.
21483@item @xref{info auto-load local-gdbinit}.
21484@tab Show state of init file in the current directory.
21485@item @xref{set auto-load libthread-db}.
21486@tab Control for thread debugging library.
21487@item @xref{show auto-load libthread-db}.
21488@tab Show setting of thread debugging library.
21489@item @xref{info auto-load libthread-db}.
21490@tab Show state of thread debugging library.
bccbefd2
JK
21491@item @xref{set auto-load safe-path}.
21492@tab Control directories trusted for automatic loading.
21493@item @xref{show auto-load safe-path}.
21494@tab Show directories trusted for automatic loading.
21495@item @xref{add-auto-load-safe-path}.
21496@tab Add directory trusted for automatic loading.
bf88dd68
JK
21497@end multitable
21498
21499@menu
21500* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
21501* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
21502* objfile-gdb.gdb file:: @samp{set/show/info auto-load gdb-script}
bccbefd2 21503* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
4dc84fd1 21504* Auto-loading verbose mode:: @samp{set/show debug auto-load}
bf88dd68
JK
21505@xref{Python Auto-loading}.
21506@end menu
21507
21508@node Init File in the Current Directory
21509@subsection Automatically loading init file in the current directory
21510@cindex auto-loading init file in the current directory
21511
21512By default, @value{GDBN} reads and executes the canned sequences of commands
21513from init file (if any) in the current working directory,
21514see @ref{Init File in the Current Directory during Startup}.
21515
c1668e4e
JK
21516Note that loading of this local @file{.gdbinit} file also requires accordingly
21517configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21518
bf88dd68
JK
21519@table @code
21520@anchor{set auto-load local-gdbinit}
21521@kindex set auto-load local-gdbinit
21522@item set auto-load local-gdbinit [on|off]
21523Enable or disable the auto-loading of canned sequences of commands
21524(@pxref{Sequences}) found in init file in the current directory.
21525
21526@anchor{show auto-load local-gdbinit}
21527@kindex show auto-load local-gdbinit
21528@item show auto-load local-gdbinit
21529Show whether auto-loading of canned sequences of commands from init file in the
21530current directory is enabled or disabled.
21531
21532@anchor{info auto-load local-gdbinit}
21533@kindex info auto-load local-gdbinit
21534@item info auto-load local-gdbinit
21535Print whether canned sequences of commands from init file in the
21536current directory have been auto-loaded.
21537@end table
21538
21539@node libthread_db.so.1 file
21540@subsection Automatically loading thread debugging library
21541@cindex auto-loading libthread_db.so.1
21542
21543This feature is currently present only on @sc{gnu}/Linux native hosts.
21544
21545@value{GDBN} reads in some cases thread debugging library from places specific
21546to the inferior (@pxref{set libthread-db-search-path}).
21547
21548The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
21549without checking this @samp{set auto-load libthread-db} switch as system
21550libraries have to be trusted in general. In all other cases of
21551@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
21552auto-load libthread-db} is enabled before trying to open such thread debugging
21553library.
21554
c1668e4e
JK
21555Note that loading of this debugging library also requires accordingly configured
21556@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21557
bf88dd68
JK
21558@table @code
21559@anchor{set auto-load libthread-db}
21560@kindex set auto-load libthread-db
21561@item set auto-load libthread-db [on|off]
21562Enable or disable the auto-loading of inferior specific thread debugging library.
21563
21564@anchor{show auto-load libthread-db}
21565@kindex show auto-load libthread-db
21566@item show auto-load libthread-db
21567Show whether auto-loading of inferior specific thread debugging library is
21568enabled or disabled.
21569
21570@anchor{info auto-load libthread-db}
21571@kindex info auto-load libthread-db
21572@item info auto-load libthread-db
21573Print the list of all loaded inferior specific thread debugging libraries and
21574for each such library print list of inferior @var{pid}s using it.
21575@end table
21576
21577@node objfile-gdb.gdb file
21578@subsection The @file{@var{objfile}-gdb.gdb} file
21579@cindex auto-loading @file{@var{objfile}-gdb.gdb}
21580
21581@value{GDBN} tries to load an @file{@var{objfile}-gdb.gdb} file containing
21582canned sequences of commands (@pxref{Sequences}), as long as @samp{set
21583auto-load gdb-scripts} is set to @samp{on}.
21584
c1668e4e
JK
21585Note that loading of this script file also requires accordingly configured
21586@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21587
bf88dd68
JK
21588For more background refer to the similar Python scripts auto-loading
21589description (@pxref{objfile-gdb.py file}).
21590
21591@table @code
21592@anchor{set auto-load gdb-scripts}
21593@kindex set auto-load gdb-scripts
21594@item set auto-load gdb-scripts [on|off]
21595Enable or disable the auto-loading of canned sequences of commands scripts.
21596
21597@anchor{show auto-load gdb-scripts}
21598@kindex show auto-load gdb-scripts
21599@item show auto-load gdb-scripts
21600Show whether auto-loading of canned sequences of commands scripts is enabled or
21601disabled.
21602
21603@anchor{info auto-load gdb-scripts}
21604@kindex info auto-load gdb-scripts
21605@cindex print list of auto-loaded canned sequences of commands scripts
21606@item info auto-load gdb-scripts [@var{regexp}]
21607Print the list of all canned sequences of commands scripts that @value{GDBN}
21608auto-loaded.
21609@end table
21610
21611If @var{regexp} is supplied only canned sequences of commands scripts with
21612matching names are printed.
21613
bccbefd2
JK
21614@node Auto-loading safe path
21615@subsection Security restriction for auto-loading
21616@cindex auto-loading safe-path
21617
21618As the files of inferior can come from untrusted source (such as submitted by
21619an application user) @value{GDBN} does not always load any files automatically.
21620@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
21621directories trusted for loading files not explicitly requested by user.
202cbf1c 21622Each directory can also be a shell wildcard pattern.
bccbefd2
JK
21623
21624If the path is not set properly you will see a warning and the file will not
21625get loaded:
21626
21627@smallexample
21628$ ./gdb -q ./gdb
21629Reading symbols from /home/user/gdb/gdb...done.
21630warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
21631 declined by your `auto-load safe-path' set
21632 to "$debugdir:$datadir/auto-load".
bccbefd2 21633warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
21634 declined by your `auto-load safe-path' set
21635 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
21636@end smallexample
21637
21638The list of trusted directories is controlled by the following commands:
21639
21640@table @code
21641@anchor{set auto-load safe-path}
21642@kindex set auto-load safe-path
af2c1515 21643@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
21644Set the list of directories (and their subdirectories) trusted for automatic
21645loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
21646Each directory can also be a shell wildcard pattern; wildcards do not match
21647directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
21648(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
21649If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
21650its default value as specified during @value{GDBN} compilation.
21651
d9242c17 21652The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
21653systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
21654to the @env{PATH} environment variable.
21655
21656@anchor{show auto-load safe-path}
21657@kindex show auto-load safe-path
21658@item show auto-load safe-path
21659Show the list of directories trusted for automatic loading and execution of
21660scripts.
21661
21662@anchor{add-auto-load-safe-path}
21663@kindex add-auto-load-safe-path
21664@item add-auto-load-safe-path
21665Add an entry (or list of entries) the list of directories trusted for automatic
21666loading and execution of scripts. Multiple entries may be delimited by the
d9242c17 21667host platform path separator in use.
bccbefd2
JK
21668@end table
21669
7349ff92 21670This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
21671to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
21672substitution applies the same as for @ref{set auto-load scripts-directory}.
21673The default @code{set auto-load safe-path} value can be also overriden by
21674@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 21675
6dea1fbd
JK
21676Setting this variable to @file{/} disables this security protection,
21677corresponding @value{GDBN} configuration option is
21678@option{--without-auto-load-safe-path}.
bccbefd2
JK
21679This variable is supposed to be set to the system directories writable by the
21680system superuser only. Users can add their source directories in init files in
21681their home directories (@pxref{Home Directory Init File}). See also deprecated
21682init file in the current directory
21683(@pxref{Init File in the Current Directory during Startup}).
21684
21685To force @value{GDBN} to load the files it declined to load in the previous
21686example, you could use one of the following ways:
21687
0511cc75
JK
21688@table @asis
21689@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
21690Specify this trusted directory (or a file) as additional component of the list.
21691You have to specify also any existing directories displayed by
21692by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
21693
174bb630 21694@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
21695Specify this directory as in the previous case but just for a single
21696@value{GDBN} session.
21697
af2c1515 21698@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
21699Disable auto-loading safety for a single @value{GDBN} session.
21700This assumes all the files you debug during this @value{GDBN} session will come
21701from trusted sources.
21702
21703@item @kbd{./configure --without-auto-load-safe-path}
21704During compilation of @value{GDBN} you may disable any auto-loading safety.
21705This assumes all the files you will ever debug with this @value{GDBN} come from
21706trusted sources.
0511cc75 21707@end table
bccbefd2
JK
21708
21709On the other hand you can also explicitly forbid automatic files loading which
21710also suppresses any such warning messages:
21711
0511cc75 21712@table @asis
174bb630 21713@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
21714You can use @value{GDBN} command-line option for a single @value{GDBN} session.
21715
0511cc75 21716@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
21717Disable auto-loading globally for the user
21718(@pxref{Home Directory Init File}). While it is improbable, you could also
21719use system init file instead (@pxref{System-wide configuration}).
0511cc75 21720@end table
bccbefd2
JK
21721
21722This setting applies to the file names as entered by user. If no entry matches
21723@value{GDBN} tries as a last resort to also resolve all the file names into
21724their canonical form (typically resolving symbolic links) and compare the
21725entries again. @value{GDBN} already canonicalizes most of the filenames on its
21726own before starting the comparison so a canonical form of directories is
21727recommended to be entered.
21728
4dc84fd1
JK
21729@node Auto-loading verbose mode
21730@subsection Displaying files tried for auto-load
21731@cindex auto-loading verbose mode
21732
21733For better visibility of all the file locations where you can place scripts to
21734be auto-loaded with inferior --- or to protect yourself against accidental
21735execution of untrusted scripts --- @value{GDBN} provides a feature for printing
21736all the files attempted to be loaded. Both existing and non-existing files may
21737be printed.
21738
21739For example the list of directories from which it is safe to auto-load files
21740(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
21741may not be too obvious while setting it up.
21742
21743@smallexample
0070f25a 21744(gdb) set debug auto-load on
4dc84fd1
JK
21745(gdb) file ~/src/t/true
21746auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
21747 for objfile "/tmp/true".
21748auto-load: Updating directories of "/usr:/opt".
21749auto-load: Using directory "/usr".
21750auto-load: Using directory "/opt".
21751warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
21752 by your `auto-load safe-path' set to "/usr:/opt".
21753@end smallexample
21754
21755@table @code
21756@anchor{set debug auto-load}
21757@kindex set debug auto-load
21758@item set debug auto-load [on|off]
21759Set whether to print the filenames attempted to be auto-loaded.
21760
21761@anchor{show debug auto-load}
21762@kindex show debug auto-load
21763@item show debug auto-load
21764Show whether printing of the filenames attempted to be auto-loaded is turned
21765on or off.
21766@end table
21767
8e04817f 21768@node Messages/Warnings
79a6e687 21769@section Optional Warnings and Messages
104c1213 21770
9c16f35a
EZ
21771@cindex verbose operation
21772@cindex optional warnings
8e04817f
AC
21773By default, @value{GDBN} is silent about its inner workings. If you are
21774running on a slow machine, you may want to use the @code{set verbose}
21775command. This makes @value{GDBN} tell you when it does a lengthy
21776internal operation, so you will not think it has crashed.
104c1213 21777
8e04817f
AC
21778Currently, the messages controlled by @code{set verbose} are those
21779which announce that the symbol table for a source file is being read;
79a6e687 21780see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 21781
8e04817f
AC
21782@table @code
21783@kindex set verbose
21784@item set verbose on
21785Enables @value{GDBN} output of certain informational messages.
104c1213 21786
8e04817f
AC
21787@item set verbose off
21788Disables @value{GDBN} output of certain informational messages.
104c1213 21789
8e04817f
AC
21790@kindex show verbose
21791@item show verbose
21792Displays whether @code{set verbose} is on or off.
21793@end table
104c1213 21794
8e04817f
AC
21795By default, if @value{GDBN} encounters bugs in the symbol table of an
21796object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
21797find this information useful (@pxref{Symbol Errors, ,Errors Reading
21798Symbol Files}).
104c1213 21799
8e04817f 21800@table @code
104c1213 21801
8e04817f
AC
21802@kindex set complaints
21803@item set complaints @var{limit}
21804Permits @value{GDBN} to output @var{limit} complaints about each type of
21805unusual symbols before becoming silent about the problem. Set
21806@var{limit} to zero to suppress all complaints; set it to a large number
21807to prevent complaints from being suppressed.
104c1213 21808
8e04817f
AC
21809@kindex show complaints
21810@item show complaints
21811Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 21812
8e04817f 21813@end table
104c1213 21814
d837706a 21815@anchor{confirmation requests}
8e04817f
AC
21816By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
21817lot of stupid questions to confirm certain commands. For example, if
21818you try to run a program which is already running:
104c1213 21819
474c8240 21820@smallexample
8e04817f
AC
21821(@value{GDBP}) run
21822The program being debugged has been started already.
21823Start it from the beginning? (y or n)
474c8240 21824@end smallexample
104c1213 21825
8e04817f
AC
21826If you are willing to unflinchingly face the consequences of your own
21827commands, you can disable this ``feature'':
104c1213 21828
8e04817f 21829@table @code
104c1213 21830
8e04817f
AC
21831@kindex set confirm
21832@cindex flinching
21833@cindex confirmation
21834@cindex stupid questions
21835@item set confirm off
7c953934
TT
21836Disables confirmation requests. Note that running @value{GDBN} with
21837the @option{--batch} option (@pxref{Mode Options, -batch}) also
21838automatically disables confirmation requests.
104c1213 21839
8e04817f
AC
21840@item set confirm on
21841Enables confirmation requests (the default).
104c1213 21842
8e04817f
AC
21843@kindex show confirm
21844@item show confirm
21845Displays state of confirmation requests.
21846
21847@end table
104c1213 21848
16026cd7
AS
21849@cindex command tracing
21850If you need to debug user-defined commands or sourced files you may find it
21851useful to enable @dfn{command tracing}. In this mode each command will be
21852printed as it is executed, prefixed with one or more @samp{+} symbols, the
21853quantity denoting the call depth of each command.
21854
21855@table @code
21856@kindex set trace-commands
21857@cindex command scripts, debugging
21858@item set trace-commands on
21859Enable command tracing.
21860@item set trace-commands off
21861Disable command tracing.
21862@item show trace-commands
21863Display the current state of command tracing.
21864@end table
21865
8e04817f 21866@node Debugging Output
79a6e687 21867@section Optional Messages about Internal Happenings
4644b6e3
EZ
21868@cindex optional debugging messages
21869
da316a69
EZ
21870@value{GDBN} has commands that enable optional debugging messages from
21871various @value{GDBN} subsystems; normally these commands are of
21872interest to @value{GDBN} maintainers, or when reporting a bug. This
21873section documents those commands.
21874
104c1213 21875@table @code
a8f24a35
EZ
21876@kindex set exec-done-display
21877@item set exec-done-display
21878Turns on or off the notification of asynchronous commands'
21879completion. When on, @value{GDBN} will print a message when an
21880asynchronous command finishes its execution. The default is off.
21881@kindex show exec-done-display
21882@item show exec-done-display
21883Displays the current setting of asynchronous command completion
21884notification.
4644b6e3
EZ
21885@kindex set debug
21886@cindex gdbarch debugging info
a8f24a35 21887@cindex architecture debugging info
8e04817f 21888@item set debug arch
a8f24a35 21889Turns on or off display of gdbarch debugging info. The default is off
4644b6e3 21890@kindex show debug
8e04817f
AC
21891@item show debug arch
21892Displays the current state of displaying gdbarch debugging info.
721c2651
EZ
21893@item set debug aix-thread
21894@cindex AIX threads
21895Display debugging messages about inner workings of the AIX thread
21896module.
21897@item show debug aix-thread
21898Show the current state of AIX thread debugging info display.
900e11f9
JK
21899@item set debug check-physname
21900@cindex physname
21901Check the results of the ``physname'' computation. When reading DWARF
21902debugging information for C@t{++}, @value{GDBN} attempts to compute
21903each entity's name. @value{GDBN} can do this computation in two
21904different ways, depending on exactly what information is present.
21905When enabled, this setting causes @value{GDBN} to compute the names
21906both ways and display any discrepancies.
21907@item show debug check-physname
21908Show the current state of ``physname'' checking.
d97bc12b
DE
21909@item set debug dwarf2-die
21910@cindex DWARF2 DIEs
21911Dump DWARF2 DIEs after they are read in.
21912The value is the number of nesting levels to print.
21913A value of zero turns off the display.
21914@item show debug dwarf2-die
21915Show the current state of DWARF2 DIE debugging.
45cfd468
DE
21916@item set debug dwarf2-read
21917@cindex DWARF2 Reading
21918Turns on or off display of debugging messages related to reading
21919DWARF debug info. The default is off.
21920@item show debug dwarf2-read
21921Show the current state of DWARF2 reader debugging.
237fc4c9
PA
21922@item set debug displaced
21923@cindex displaced stepping debugging info
21924Turns on or off display of @value{GDBN} debugging info for the
21925displaced stepping support. The default is off.
21926@item show debug displaced
21927Displays the current state of displaying @value{GDBN} debugging info
21928related to displaced stepping.
8e04817f 21929@item set debug event
4644b6e3 21930@cindex event debugging info
a8f24a35 21931Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 21932default is off.
8e04817f
AC
21933@item show debug event
21934Displays the current state of displaying @value{GDBN} event debugging
21935info.
8e04817f 21936@item set debug expression
4644b6e3 21937@cindex expression debugging info
721c2651
EZ
21938Turns on or off display of debugging info about @value{GDBN}
21939expression parsing. The default is off.
8e04817f 21940@item show debug expression
721c2651
EZ
21941Displays the current state of displaying debugging info about
21942@value{GDBN} expression parsing.
7453dc06 21943@item set debug frame
4644b6e3 21944@cindex frame debugging info
7453dc06
AC
21945Turns on or off display of @value{GDBN} frame debugging info. The
21946default is off.
7453dc06
AC
21947@item show debug frame
21948Displays the current state of displaying @value{GDBN} frame debugging
21949info.
cbe54154
PA
21950@item set debug gnu-nat
21951@cindex @sc{gnu}/Hurd debug messages
21952Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
21953@item show debug gnu-nat
21954Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
21955@item set debug infrun
21956@cindex inferior debugging info
21957Turns on or off display of @value{GDBN} debugging info for running the inferior.
21958The default is off. @file{infrun.c} contains GDB's runtime state machine used
21959for implementing operations such as single-stepping the inferior.
21960@item show debug infrun
21961Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
21962@item set debug jit
21963@cindex just-in-time compilation, debugging messages
21964Turns on or off debugging messages from JIT debug support.
21965@item show debug jit
21966Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
21967@item set debug lin-lwp
21968@cindex @sc{gnu}/Linux LWP debug messages
21969@cindex Linux lightweight processes
721c2651 21970Turns on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
21971@item show debug lin-lwp
21972Show the current state of Linux LWP debugging messages.
c9b6281a
YQ
21973@item set debug notification
21974@cindex remote async notification debugging info
21975Turns on or off debugging messages about remote async notification.
21976The default is off.
21977@item show debug notification
21978Displays the current state of remote async notification debugging messages.
2b4855ab 21979@item set debug observer
4644b6e3 21980@cindex observer debugging info
2b4855ab
AC
21981Turns on or off display of @value{GDBN} observer debugging. This
21982includes info such as the notification of observable events.
2b4855ab
AC
21983@item show debug observer
21984Displays the current state of observer debugging.
8e04817f 21985@item set debug overload
4644b6e3 21986@cindex C@t{++} overload debugging info
8e04817f 21987Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 21988info. This includes info such as ranking of functions, etc. The default
8e04817f 21989is off.
8e04817f
AC
21990@item show debug overload
21991Displays the current state of displaying @value{GDBN} C@t{++} overload
21992debugging info.
92981e24
TT
21993@cindex expression parser, debugging info
21994@cindex debug expression parser
21995@item set debug parser
21996Turns on or off the display of expression parser debugging output.
21997Internally, this sets the @code{yydebug} variable in the expression
21998parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
21999details. The default is off.
22000@item show debug parser
22001Show the current state of expression parser debugging.
8e04817f
AC
22002@cindex packets, reporting on stdout
22003@cindex serial connections, debugging
605a56cb
DJ
22004@cindex debug remote protocol
22005@cindex remote protocol debugging
22006@cindex display remote packets
8e04817f
AC
22007@item set debug remote
22008Turns on or off display of reports on all packets sent back and forth across
22009the serial line to the remote machine. The info is printed on the
22010@value{GDBN} standard output stream. The default is off.
8e04817f
AC
22011@item show debug remote
22012Displays the state of display of remote packets.
8e04817f
AC
22013@item set debug serial
22014Turns on or off display of @value{GDBN} serial debugging info. The
22015default is off.
8e04817f
AC
22016@item show debug serial
22017Displays the current state of displaying @value{GDBN} serial debugging
22018info.
c45da7e6
EZ
22019@item set debug solib-frv
22020@cindex FR-V shared-library debugging
22021Turns on or off debugging messages for FR-V shared-library code.
22022@item show debug solib-frv
22023Display the current state of FR-V shared-library code debugging
22024messages.
45cfd468
DE
22025@item set debug symtab-create
22026@cindex symbol table creation
22027Turns on or off display of debugging messages related to symbol table creation.
22028The default is off.
22029@item show debug symtab-create
22030Show the current state of symbol table creation debugging.
8e04817f 22031@item set debug target
4644b6e3 22032@cindex target debugging info
8e04817f
AC
22033Turns on or off display of @value{GDBN} target debugging info. This info
22034includes what is going on at the target level of GDB, as it happens. The
701b08bb
DJ
22035default is 0. Set it to 1 to track events, and to 2 to also track the
22036value of large memory transfers. Changes to this flag do not take effect
22037until the next time you connect to a target or use the @code{run} command.
8e04817f
AC
22038@item show debug target
22039Displays the current state of displaying @value{GDBN} target debugging
22040info.
75feb17d
DJ
22041@item set debug timestamp
22042@cindex timestampping debugging info
22043Turns on or off display of timestamps with @value{GDBN} debugging info.
22044When enabled, seconds and microseconds are displayed before each debugging
22045message.
22046@item show debug timestamp
22047Displays the current state of displaying timestamps with @value{GDBN}
22048debugging info.
c45da7e6 22049@item set debugvarobj
4644b6e3 22050@cindex variable object debugging info
8e04817f
AC
22051Turns on or off display of @value{GDBN} variable object debugging
22052info. The default is off.
c45da7e6 22053@item show debugvarobj
8e04817f
AC
22054Displays the current state of displaying @value{GDBN} variable object
22055debugging info.
e776119f
DJ
22056@item set debug xml
22057@cindex XML parser debugging
22058Turns on or off debugging messages for built-in XML parsers.
22059@item show debug xml
22060Displays the current state of XML debugging messages.
8e04817f 22061@end table
104c1213 22062
14fb1bac
JB
22063@node Other Misc Settings
22064@section Other Miscellaneous Settings
22065@cindex miscellaneous settings
22066
22067@table @code
22068@kindex set interactive-mode
22069@item set interactive-mode
7bfc9434
JB
22070If @code{on}, forces @value{GDBN} to assume that GDB was started
22071in a terminal. In practice, this means that @value{GDBN} should wait
22072for the user to answer queries generated by commands entered at
22073the command prompt. If @code{off}, forces @value{GDBN} to operate
22074in the opposite mode, and it uses the default answers to all queries.
22075If @code{auto} (the default), @value{GDBN} tries to determine whether
22076its standard input is a terminal, and works in interactive-mode if it
22077is, non-interactively otherwise.
14fb1bac
JB
22078
22079In the vast majority of cases, the debugger should be able to guess
22080correctly which mode should be used. But this setting can be useful
22081in certain specific cases, such as running a MinGW @value{GDBN}
22082inside a cygwin window.
22083
22084@kindex show interactive-mode
22085@item show interactive-mode
22086Displays whether the debugger is operating in interactive mode or not.
22087@end table
22088
d57a3c85
TJB
22089@node Extending GDB
22090@chapter Extending @value{GDBN}
22091@cindex extending GDB
22092
5a56e9c5
DE
22093@value{GDBN} provides three mechanisms for extension. The first is based
22094on composition of @value{GDBN} commands, the second is based on the
22095Python scripting language, and the third is for defining new aliases of
22096existing commands.
d57a3c85 22097
5a56e9c5 22098To facilitate the use of the first two extensions, @value{GDBN} is capable
95433b34
JB
22099of evaluating the contents of a file. When doing so, @value{GDBN}
22100can recognize which scripting language is being used by looking at
22101the filename extension. Files with an unrecognized filename extension
22102are always treated as a @value{GDBN} Command Files.
22103@xref{Command Files,, Command files}.
22104
22105You can control how @value{GDBN} evaluates these files with the following
22106setting:
22107
22108@table @code
22109@kindex set script-extension
22110@kindex show script-extension
22111@item set script-extension off
22112All scripts are always evaluated as @value{GDBN} Command Files.
22113
22114@item set script-extension soft
22115The debugger determines the scripting language based on filename
22116extension. If this scripting language is supported, @value{GDBN}
22117evaluates the script using that language. Otherwise, it evaluates
22118the file as a @value{GDBN} Command File.
22119
22120@item set script-extension strict
22121The debugger determines the scripting language based on filename
22122extension, and evaluates the script using that language. If the
22123language is not supported, then the evaluation fails.
22124
22125@item show script-extension
22126Display the current value of the @code{script-extension} option.
22127
22128@end table
22129
d57a3c85
TJB
22130@menu
22131* Sequences:: Canned Sequences of Commands
22132* Python:: Scripting @value{GDBN} using Python
5a56e9c5 22133* Aliases:: Creating new spellings of existing commands
d57a3c85
TJB
22134@end menu
22135
8e04817f 22136@node Sequences
d57a3c85 22137@section Canned Sequences of Commands
104c1213 22138
8e04817f 22139Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 22140Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
22141commands for execution as a unit: user-defined commands and command
22142files.
104c1213 22143
8e04817f 22144@menu
fcc73fe3
EZ
22145* Define:: How to define your own commands
22146* Hooks:: Hooks for user-defined commands
22147* Command Files:: How to write scripts of commands to be stored in a file
22148* Output:: Commands for controlled output
8e04817f 22149@end menu
104c1213 22150
8e04817f 22151@node Define
d57a3c85 22152@subsection User-defined Commands
104c1213 22153
8e04817f 22154@cindex user-defined command
fcc73fe3 22155@cindex arguments, to user-defined commands
8e04817f
AC
22156A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
22157which you assign a new name as a command. This is done with the
22158@code{define} command. User commands may accept up to 10 arguments
22159separated by whitespace. Arguments are accessed within the user command
c03c782f 22160via @code{$arg0@dots{}$arg9}. A trivial example:
104c1213 22161
8e04817f
AC
22162@smallexample
22163define adder
22164 print $arg0 + $arg1 + $arg2
c03c782f 22165end
8e04817f 22166@end smallexample
104c1213
JM
22167
22168@noindent
8e04817f 22169To execute the command use:
104c1213 22170
8e04817f
AC
22171@smallexample
22172adder 1 2 3
22173@end smallexample
104c1213 22174
8e04817f
AC
22175@noindent
22176This defines the command @code{adder}, which prints the sum of
22177its three arguments. Note the arguments are text substitutions, so they may
22178reference variables, use complex expressions, or even perform inferior
22179functions calls.
104c1213 22180
fcc73fe3
EZ
22181@cindex argument count in user-defined commands
22182@cindex how many arguments (user-defined commands)
c03c782f
AS
22183In addition, @code{$argc} may be used to find out how many arguments have
22184been passed. This expands to a number in the range 0@dots{}10.
22185
22186@smallexample
22187define adder
22188 if $argc == 2
22189 print $arg0 + $arg1
22190 end
22191 if $argc == 3
22192 print $arg0 + $arg1 + $arg2
22193 end
22194end
22195@end smallexample
22196
104c1213 22197@table @code
104c1213 22198
8e04817f
AC
22199@kindex define
22200@item define @var{commandname}
22201Define a command named @var{commandname}. If there is already a command
22202by that name, you are asked to confirm that you want to redefine it.
adb483fe
DJ
22203@var{commandname} may be a bare command name consisting of letters,
22204numbers, dashes, and underscores. It may also start with any predefined
22205prefix command. For example, @samp{define target my-target} creates
22206a user-defined @samp{target my-target} command.
104c1213 22207
8e04817f
AC
22208The definition of the command is made up of other @value{GDBN} command lines,
22209which are given following the @code{define} command. The end of these
22210commands is marked by a line containing @code{end}.
104c1213 22211
8e04817f 22212@kindex document
ca91424e 22213@kindex end@r{ (user-defined commands)}
8e04817f
AC
22214@item document @var{commandname}
22215Document the user-defined command @var{commandname}, so that it can be
22216accessed by @code{help}. The command @var{commandname} must already be
22217defined. This command reads lines of documentation just as @code{define}
22218reads the lines of the command definition, ending with @code{end}.
22219After the @code{document} command is finished, @code{help} on command
22220@var{commandname} displays the documentation you have written.
104c1213 22221
8e04817f
AC
22222You may use the @code{document} command again to change the
22223documentation of a command. Redefining the command with @code{define}
22224does not change the documentation.
104c1213 22225
c45da7e6
EZ
22226@kindex dont-repeat
22227@cindex don't repeat command
22228@item dont-repeat
22229Used inside a user-defined command, this tells @value{GDBN} that this
22230command should not be repeated when the user hits @key{RET}
22231(@pxref{Command Syntax, repeat last command}).
22232
8e04817f
AC
22233@kindex help user-defined
22234@item help user-defined
7d74f244
DE
22235List all user-defined commands and all python commands defined in class
22236COMAND_USER. The first line of the documentation or docstring is
22237included (if any).
104c1213 22238
8e04817f
AC
22239@kindex show user
22240@item show user
22241@itemx show user @var{commandname}
22242Display the @value{GDBN} commands used to define @var{commandname} (but
22243not its documentation). If no @var{commandname} is given, display the
22244definitions for all user-defined commands.
7d74f244 22245This does not work for user-defined python commands.
104c1213 22246
fcc73fe3 22247@cindex infinite recursion in user-defined commands
20f01a46
DH
22248@kindex show max-user-call-depth
22249@kindex set max-user-call-depth
22250@item show max-user-call-depth
5ca0cb28
DH
22251@itemx set max-user-call-depth
22252The value of @code{max-user-call-depth} controls how many recursion
3f94c067 22253levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 22254infinite recursion and aborts the command.
7d74f244 22255This does not apply to user-defined python commands.
104c1213
JM
22256@end table
22257
fcc73fe3
EZ
22258In addition to the above commands, user-defined commands frequently
22259use control flow commands, described in @ref{Command Files}.
22260
8e04817f
AC
22261When user-defined commands are executed, the
22262commands of the definition are not printed. An error in any command
22263stops execution of the user-defined command.
104c1213 22264
8e04817f
AC
22265If used interactively, commands that would ask for confirmation proceed
22266without asking when used inside a user-defined command. Many @value{GDBN}
22267commands that normally print messages to say what they are doing omit the
22268messages when used in a user-defined command.
104c1213 22269
8e04817f 22270@node Hooks
d57a3c85 22271@subsection User-defined Command Hooks
8e04817f
AC
22272@cindex command hooks
22273@cindex hooks, for commands
22274@cindex hooks, pre-command
104c1213 22275
8e04817f 22276@kindex hook
8e04817f
AC
22277You may define @dfn{hooks}, which are a special kind of user-defined
22278command. Whenever you run the command @samp{foo}, if the user-defined
22279command @samp{hook-foo} exists, it is executed (with no arguments)
22280before that command.
104c1213 22281
8e04817f
AC
22282@cindex hooks, post-command
22283@kindex hookpost
8e04817f
AC
22284A hook may also be defined which is run after the command you executed.
22285Whenever you run the command @samp{foo}, if the user-defined command
22286@samp{hookpost-foo} exists, it is executed (with no arguments) after
22287that command. Post-execution hooks may exist simultaneously with
22288pre-execution hooks, for the same command.
104c1213 22289
8e04817f 22290It is valid for a hook to call the command which it hooks. If this
9f1c6395 22291occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 22292
8e04817f
AC
22293@c It would be nice if hookpost could be passed a parameter indicating
22294@c if the command it hooks executed properly or not. FIXME!
104c1213 22295
8e04817f
AC
22296@kindex stop@r{, a pseudo-command}
22297In addition, a pseudo-command, @samp{stop} exists. Defining
22298(@samp{hook-stop}) makes the associated commands execute every time
22299execution stops in your program: before breakpoint commands are run,
22300displays are printed, or the stack frame is printed.
104c1213 22301
8e04817f
AC
22302For example, to ignore @code{SIGALRM} signals while
22303single-stepping, but treat them normally during normal execution,
22304you could define:
104c1213 22305
474c8240 22306@smallexample
8e04817f
AC
22307define hook-stop
22308handle SIGALRM nopass
22309end
104c1213 22310
8e04817f
AC
22311define hook-run
22312handle SIGALRM pass
22313end
104c1213 22314
8e04817f 22315define hook-continue
d3e8051b 22316handle SIGALRM pass
8e04817f 22317end
474c8240 22318@end smallexample
104c1213 22319
d3e8051b 22320As a further example, to hook at the beginning and end of the @code{echo}
b383017d 22321command, and to add extra text to the beginning and end of the message,
8e04817f 22322you could define:
104c1213 22323
474c8240 22324@smallexample
8e04817f
AC
22325define hook-echo
22326echo <<<---
22327end
104c1213 22328
8e04817f
AC
22329define hookpost-echo
22330echo --->>>\n
22331end
104c1213 22332
8e04817f
AC
22333(@value{GDBP}) echo Hello World
22334<<<---Hello World--->>>
22335(@value{GDBP})
104c1213 22336
474c8240 22337@end smallexample
104c1213 22338
8e04817f
AC
22339You can define a hook for any single-word command in @value{GDBN}, but
22340not for command aliases; you should define a hook for the basic command
c1468174 22341name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
22342@c FIXME! So how does Joe User discover whether a command is an alias
22343@c or not?
adb483fe
DJ
22344You can hook a multi-word command by adding @code{hook-} or
22345@code{hookpost-} to the last word of the command, e.g.@:
22346@samp{define target hook-remote} to add a hook to @samp{target remote}.
22347
8e04817f
AC
22348If an error occurs during the execution of your hook, execution of
22349@value{GDBN} commands stops and @value{GDBN} issues a prompt
22350(before the command that you actually typed had a chance to run).
104c1213 22351
8e04817f
AC
22352If you try to define a hook which does not match any known command, you
22353get a warning from the @code{define} command.
c906108c 22354
8e04817f 22355@node Command Files
d57a3c85 22356@subsection Command Files
c906108c 22357
8e04817f 22358@cindex command files
fcc73fe3 22359@cindex scripting commands
6fc08d32
EZ
22360A command file for @value{GDBN} is a text file made of lines that are
22361@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
22362also be included. An empty line in a command file does nothing; it
22363does not mean to repeat the last command, as it would from the
22364terminal.
c906108c 22365
6fc08d32 22366You can request the execution of a command file with the @code{source}
95433b34
JB
22367command. Note that the @code{source} command is also used to evaluate
22368scripts that are not Command Files. The exact behavior can be configured
22369using the @code{script-extension} setting.
22370@xref{Extending GDB,, Extending GDB}.
c906108c 22371
8e04817f
AC
22372@table @code
22373@kindex source
ca91424e 22374@cindex execute commands from a file
3f7b2faa 22375@item source [-s] [-v] @var{filename}
8e04817f 22376Execute the command file @var{filename}.
c906108c
SS
22377@end table
22378
fcc73fe3
EZ
22379The lines in a command file are generally executed sequentially,
22380unless the order of execution is changed by one of the
22381@emph{flow-control commands} described below. The commands are not
a71ec265
DH
22382printed as they are executed. An error in any command terminates
22383execution of the command file and control is returned to the console.
c906108c 22384
08001717
DE
22385@value{GDBN} first searches for @var{filename} in the current directory.
22386If the file is not found there, and @var{filename} does not specify a
22387directory, then @value{GDBN} also looks for the file on the source search path
22388(specified with the @samp{directory} command);
22389except that @file{$cdir} is not searched because the compilation directory
22390is not relevant to scripts.
4b505b12 22391
3f7b2faa
DE
22392If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
22393on the search path even if @var{filename} specifies a directory.
22394The search is done by appending @var{filename} to each element of the
22395search path. So, for example, if @var{filename} is @file{mylib/myscript}
22396and the search path contains @file{/home/user} then @value{GDBN} will
22397look for the script @file{/home/user/mylib/myscript}.
22398The search is also done if @var{filename} is an absolute path.
22399For example, if @var{filename} is @file{/tmp/myscript} and
22400the search path contains @file{/home/user} then @value{GDBN} will
22401look for the script @file{/home/user/tmp/myscript}.
22402For DOS-like systems, if @var{filename} contains a drive specification,
22403it is stripped before concatenation. For example, if @var{filename} is
22404@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
22405will look for the script @file{c:/tmp/myscript}.
22406
16026cd7
AS
22407If @code{-v}, for verbose mode, is given then @value{GDBN} displays
22408each command as it is executed. The option must be given before
22409@var{filename}, and is interpreted as part of the filename anywhere else.
22410
8e04817f
AC
22411Commands that would ask for confirmation if used interactively proceed
22412without asking when used in a command file. Many @value{GDBN} commands that
22413normally print messages to say what they are doing omit the messages
22414when called from command files.
c906108c 22415
8e04817f
AC
22416@value{GDBN} also accepts command input from standard input. In this
22417mode, normal output goes to standard output and error output goes to
22418standard error. Errors in a command file supplied on standard input do
6fc08d32 22419not terminate execution of the command file---execution continues with
8e04817f 22420the next command.
c906108c 22421
474c8240 22422@smallexample
8e04817f 22423gdb < cmds > log 2>&1
474c8240 22424@end smallexample
c906108c 22425
8e04817f
AC
22426(The syntax above will vary depending on the shell used.) This example
22427will execute commands from the file @file{cmds}. All output and errors
22428would be directed to @file{log}.
c906108c 22429
fcc73fe3
EZ
22430Since commands stored on command files tend to be more general than
22431commands typed interactively, they frequently need to deal with
22432complicated situations, such as different or unexpected values of
22433variables and symbols, changes in how the program being debugged is
22434built, etc. @value{GDBN} provides a set of flow-control commands to
22435deal with these complexities. Using these commands, you can write
22436complex scripts that loop over data structures, execute commands
22437conditionally, etc.
22438
22439@table @code
22440@kindex if
22441@kindex else
22442@item if
22443@itemx else
22444This command allows to include in your script conditionally executed
22445commands. The @code{if} command takes a single argument, which is an
22446expression to evaluate. It is followed by a series of commands that
22447are executed only if the expression is true (its value is nonzero).
22448There can then optionally be an @code{else} line, followed by a series
22449of commands that are only executed if the expression was false. The
22450end of the list is marked by a line containing @code{end}.
22451
22452@kindex while
22453@item while
22454This command allows to write loops. Its syntax is similar to
22455@code{if}: the command takes a single argument, which is an expression
22456to evaluate, and must be followed by the commands to execute, one per
22457line, terminated by an @code{end}. These commands are called the
22458@dfn{body} of the loop. The commands in the body of @code{while} are
22459executed repeatedly as long as the expression evaluates to true.
22460
22461@kindex loop_break
22462@item loop_break
22463This command exits the @code{while} loop in whose body it is included.
22464Execution of the script continues after that @code{while}s @code{end}
22465line.
22466
22467@kindex loop_continue
22468@item loop_continue
22469This command skips the execution of the rest of the body of commands
22470in the @code{while} loop in whose body it is included. Execution
22471branches to the beginning of the @code{while} loop, where it evaluates
22472the controlling expression.
ca91424e
EZ
22473
22474@kindex end@r{ (if/else/while commands)}
22475@item end
22476Terminate the block of commands that are the body of @code{if},
22477@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
22478@end table
22479
22480
8e04817f 22481@node Output
d57a3c85 22482@subsection Commands for Controlled Output
c906108c 22483
8e04817f
AC
22484During the execution of a command file or a user-defined command, normal
22485@value{GDBN} output is suppressed; the only output that appears is what is
22486explicitly printed by the commands in the definition. This section
22487describes three commands useful for generating exactly the output you
22488want.
c906108c
SS
22489
22490@table @code
8e04817f
AC
22491@kindex echo
22492@item echo @var{text}
22493@c I do not consider backslash-space a standard C escape sequence
22494@c because it is not in ANSI.
22495Print @var{text}. Nonprinting characters can be included in
22496@var{text} using C escape sequences, such as @samp{\n} to print a
22497newline. @strong{No newline is printed unless you specify one.}
22498In addition to the standard C escape sequences, a backslash followed
22499by a space stands for a space. This is useful for displaying a
22500string with spaces at the beginning or the end, since leading and
22501trailing spaces are otherwise trimmed from all arguments.
22502To print @samp{@w{ }and foo =@w{ }}, use the command
22503@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 22504
8e04817f
AC
22505A backslash at the end of @var{text} can be used, as in C, to continue
22506the command onto subsequent lines. For example,
c906108c 22507
474c8240 22508@smallexample
8e04817f
AC
22509echo This is some text\n\
22510which is continued\n\
22511onto several lines.\n
474c8240 22512@end smallexample
c906108c 22513
8e04817f 22514produces the same output as
c906108c 22515
474c8240 22516@smallexample
8e04817f
AC
22517echo This is some text\n
22518echo which is continued\n
22519echo onto several lines.\n
474c8240 22520@end smallexample
c906108c 22521
8e04817f
AC
22522@kindex output
22523@item output @var{expression}
22524Print the value of @var{expression} and nothing but that value: no
22525newlines, no @samp{$@var{nn} = }. The value is not entered in the
22526value history either. @xref{Expressions, ,Expressions}, for more information
22527on expressions.
c906108c 22528
8e04817f
AC
22529@item output/@var{fmt} @var{expression}
22530Print the value of @var{expression} in format @var{fmt}. You can use
22531the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 22532Formats}, for more information.
c906108c 22533
8e04817f 22534@kindex printf
82160952
EZ
22535@item printf @var{template}, @var{expressions}@dots{}
22536Print the values of one or more @var{expressions} under the control of
22537the string @var{template}. To print several values, make
22538@var{expressions} be a comma-separated list of individual expressions,
22539which may be either numbers or pointers. Their values are printed as
22540specified by @var{template}, exactly as a C program would do by
22541executing the code below:
c906108c 22542
474c8240 22543@smallexample
82160952 22544printf (@var{template}, @var{expressions}@dots{});
474c8240 22545@end smallexample
c906108c 22546
82160952
EZ
22547As in @code{C} @code{printf}, ordinary characters in @var{template}
22548are printed verbatim, while @dfn{conversion specification} introduced
22549by the @samp{%} character cause subsequent @var{expressions} to be
22550evaluated, their values converted and formatted according to type and
22551style information encoded in the conversion specifications, and then
22552printed.
22553
8e04817f 22554For example, you can print two values in hex like this:
c906108c 22555
8e04817f
AC
22556@smallexample
22557printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
22558@end smallexample
c906108c 22559
82160952
EZ
22560@code{printf} supports all the standard @code{C} conversion
22561specifications, including the flags and modifiers between the @samp{%}
22562character and the conversion letter, with the following exceptions:
22563
22564@itemize @bullet
22565@item
22566The argument-ordering modifiers, such as @samp{2$}, are not supported.
22567
22568@item
22569The modifier @samp{*} is not supported for specifying precision or
22570width.
22571
22572@item
22573The @samp{'} flag (for separation of digits into groups according to
22574@code{LC_NUMERIC'}) is not supported.
22575
22576@item
22577The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
22578supported.
22579
22580@item
22581The conversion letter @samp{n} (as in @samp{%n}) is not supported.
22582
22583@item
22584The conversion letters @samp{a} and @samp{A} are not supported.
22585@end itemize
22586
22587@noindent
22588Note that the @samp{ll} type modifier is supported only if the
22589underlying @code{C} implementation used to build @value{GDBN} supports
22590the @code{long long int} type, and the @samp{L} type modifier is
22591supported only if @code{long double} type is available.
22592
22593As in @code{C}, @code{printf} supports simple backslash-escape
22594sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
22595@samp{\a}, and @samp{\f}, that consist of backslash followed by a
22596single character. Octal and hexadecimal escape sequences are not
22597supported.
1a619819
LM
22598
22599Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
22600(@dfn{Decimal Floating Point}) types using the following length modifiers
22601together with a floating point specifier.
1a619819
LM
22602letters:
22603
22604@itemize @bullet
22605@item
22606@samp{H} for printing @code{Decimal32} types.
22607
22608@item
22609@samp{D} for printing @code{Decimal64} types.
22610
22611@item
22612@samp{DD} for printing @code{Decimal128} types.
22613@end itemize
22614
22615If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 22616support for the three length modifiers for DFP types, other modifiers
3b784c4f 22617such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
22618
22619In case there is no such @code{C} support, no additional modifiers will be
22620available and the value will be printed in the standard way.
22621
22622Here's an example of printing DFP types using the above conversion letters:
22623@smallexample
0aea4bf3 22624printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
22625@end smallexample
22626
f1421989
HZ
22627@kindex eval
22628@item eval @var{template}, @var{expressions}@dots{}
22629Convert the values of one or more @var{expressions} under the control of
22630the string @var{template} to a command line, and call it.
22631
c906108c
SS
22632@end table
22633
d57a3c85
TJB
22634@node Python
22635@section Scripting @value{GDBN} using Python
22636@cindex python scripting
22637@cindex scripting with python
22638
22639You can script @value{GDBN} using the @uref{http://www.python.org/,
22640Python programming language}. This feature is available only if
22641@value{GDBN} was configured using @option{--with-python}.
22642
9279c692
JB
22643@cindex python directory
22644Python scripts used by @value{GDBN} should be installed in
22645@file{@var{data-directory}/python}, where @var{data-directory} is
9eeee977
DE
22646the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
22647This directory, known as the @dfn{python directory},
9279c692
JB
22648is automatically added to the Python Search Path in order to allow
22649the Python interpreter to locate all scripts installed at this location.
22650
5e239b84
PM
22651Additionally, @value{GDBN} commands and convenience functions which
22652are written in Python and are located in the
22653@file{@var{data-directory}/python/gdb/command} or
22654@file{@var{data-directory}/python/gdb/function} directories are
22655automatically imported when @value{GDBN} starts.
22656
d57a3c85
TJB
22657@menu
22658* Python Commands:: Accessing Python from @value{GDBN}.
22659* Python API:: Accessing @value{GDBN} from Python.
bf88dd68 22660* Python Auto-loading:: Automatically loading Python code.
0e3509db 22661* Python modules:: Python modules provided by @value{GDBN}.
d57a3c85
TJB
22662@end menu
22663
22664@node Python Commands
22665@subsection Python Commands
22666@cindex python commands
22667@cindex commands to access python
22668
8315665e 22669@value{GDBN} provides two commands for accessing the Python interpreter,
d57a3c85
TJB
22670and one related setting:
22671
22672@table @code
8315665e
YPK
22673@kindex python-interactive
22674@kindex pi
22675@item python-interactive @r{[}@var{command}@r{]}
22676@itemx pi @r{[}@var{command}@r{]}
22677Without an argument, the @code{python-interactive} command can be used
e3480f4a
YPK
22678to start an interactive Python prompt. To return to @value{GDBN},
22679type the @code{EOF} character (e.g., @kbd{Ctrl-D} on an empty prompt).
8315665e
YPK
22680
22681Alternatively, a single-line Python command can be given as an
22682argument and evaluated. If the command is an expression, the result
22683will be printed; otherwise, nothing will be printed. For example:
22684
22685@smallexample
22686(@value{GDBP}) python-interactive 2 + 3
226875
22688@end smallexample
22689
d57a3c85 22690@kindex python
8315665e
YPK
22691@kindex py
22692@item python @r{[}@var{command}@r{]}
22693@itemx py @r{[}@var{command}@r{]}
d57a3c85
TJB
22694The @code{python} command can be used to evaluate Python code.
22695
22696If given an argument, the @code{python} command will evaluate the
22697argument as a Python command. For example:
22698
22699@smallexample
22700(@value{GDBP}) python print 23
2270123
22702@end smallexample
22703
22704If you do not provide an argument to @code{python}, it will act as a
22705multi-line command, like @code{define}. In this case, the Python
22706script is made up of subsequent command lines, given after the
22707@code{python} command. This command list is terminated using a line
22708containing @code{end}. For example:
22709
22710@smallexample
22711(@value{GDBP}) python
22712Type python script
22713End with a line saying just "end".
22714>print 23
22715>end
2271623
22717@end smallexample
22718
713389e0
PM
22719@kindex set python print-stack
22720@item set python print-stack
80b6e756
PM
22721By default, @value{GDBN} will print only the message component of a
22722Python exception when an error occurs in a Python script. This can be
22723controlled using @code{set python print-stack}: if @code{full}, then
22724full Python stack printing is enabled; if @code{none}, then Python stack
22725and message printing is disabled; if @code{message}, the default, only
22726the message component of the error is printed.
d57a3c85
TJB
22727@end table
22728
95433b34
JB
22729It is also possible to execute a Python script from the @value{GDBN}
22730interpreter:
22731
22732@table @code
22733@item source @file{script-name}
22734The script name must end with @samp{.py} and @value{GDBN} must be configured
22735to recognize the script language based on filename extension using
22736the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
22737
22738@item python execfile ("script-name")
22739This method is based on the @code{execfile} Python built-in function,
22740and thus is always available.
22741@end table
22742
d57a3c85
TJB
22743@node Python API
22744@subsection Python API
22745@cindex python api
22746@cindex programming in python
22747
22748@cindex python stdout
22749@cindex python pagination
22750At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
22751@code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
22752A Python program which outputs to one of these streams may have its
22753output interrupted by the user (@pxref{Screen Size}). In this
22754situation, a Python @code{KeyboardInterrupt} exception is thrown.
22755
22756@menu
22757* Basic Python:: Basic Python Functions.
06e65f44
TT
22758* Exception Handling:: How Python exceptions are translated.
22759* Values From Inferior:: Python representation of values.
4c374409
JK
22760* Types In Python:: Python representation of types.
22761* Pretty Printing API:: Pretty-printing values.
a6bac58e 22762* Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
7b51bc51 22763* Writing a Pretty-Printer:: Writing a Pretty-Printer.
18a9fc12 22764* Type Printing API:: Pretty-printing types.
595939de 22765* Inferiors In Python:: Python representation of inferiors (processes)
505500db 22766* Events In Python:: Listening for events from @value{GDBN}.
595939de 22767* Threads In Python:: Accessing inferior threads from Python.
d8906c6f 22768* Commands In Python:: Implementing new commands in Python.
d7b32ed3 22769* Parameters In Python:: Adding new @value{GDBN} parameters.
bc3b79fd 22770* Functions In Python:: Writing new convenience functions.
fa33c3cd 22771* Progspaces In Python:: Program spaces.
89c73ade 22772* Objfiles In Python:: Object files.
f3e9a817
PM
22773* Frames In Python:: Accessing inferior stack frames from Python.
22774* Blocks In Python:: Accessing frame blocks from Python.
22775* Symbols In Python:: Python representation of symbols.
22776* Symbol Tables In Python:: Python representation of symbol tables.
adc36818 22777* Breakpoints In Python:: Manipulating breakpoints using Python.
cc72b2a2
KP
22778* Finish Breakpoints in Python:: Setting Breakpoints on function return
22779 using Python.
984359d2 22780* Lazy Strings In Python:: Python representation of lazy strings.
d57a3c85
TJB
22781@end menu
22782
22783@node Basic Python
22784@subsubsection Basic Python
22785
22786@cindex python functions
22787@cindex python module
22788@cindex gdb module
22789@value{GDBN} introduces a new Python module, named @code{gdb}. All
22790methods and classes added by @value{GDBN} are placed in this module.
22791@value{GDBN} automatically @code{import}s the @code{gdb} module for
22792use in all scripts evaluated by the @code{python} command.
22793
9279c692 22794@findex gdb.PYTHONDIR
d812018b 22795@defvar gdb.PYTHONDIR
9279c692
JB
22796A string containing the python directory (@pxref{Python}).
22797@end defvar
22798
d57a3c85 22799@findex gdb.execute
d812018b 22800@defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]})
d57a3c85
TJB
22801Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
22802If a GDB exception happens while @var{command} runs, it is
22803translated as described in @ref{Exception Handling,,Exception Handling}.
12453b93
TJB
22804
22805@var{from_tty} specifies whether @value{GDBN} ought to consider this
22806command as having originated from the user invoking it interactively.
22807It must be a boolean value. If omitted, it defaults to @code{False}.
bc9f0842
TT
22808
22809By default, any output produced by @var{command} is sent to
22810@value{GDBN}'s standard output. If the @var{to_string} parameter is
22811@code{True}, then output will be collected by @code{gdb.execute} and
22812returned as a string. The default is @code{False}, in which case the
5da1313b
JK
22813return value is @code{None}. If @var{to_string} is @code{True}, the
22814@value{GDBN} virtual terminal will be temporarily set to unlimited width
22815and height, and its pagination will be disabled; @pxref{Screen Size}.
d57a3c85
TJB
22816@end defun
22817
adc36818 22818@findex gdb.breakpoints
d812018b 22819@defun gdb.breakpoints ()
adc36818
PM
22820Return a sequence holding all of @value{GDBN}'s breakpoints.
22821@xref{Breakpoints In Python}, for more information.
22822@end defun
22823
8f500870 22824@findex gdb.parameter
d812018b 22825@defun gdb.parameter (parameter)
d57a3c85
TJB
22826Return the value of a @value{GDBN} parameter. @var{parameter} is a
22827string naming the parameter to look up; @var{parameter} may contain
22828spaces if the parameter has a multi-part name. For example,
22829@samp{print object} is a valid parameter name.
22830
22831If the named parameter does not exist, this function throws a
621c8364
TT
22832@code{gdb.error} (@pxref{Exception Handling}). Otherwise, the
22833parameter's value is converted to a Python value of the appropriate
22834type, and returned.
d57a3c85
TJB
22835@end defun
22836
08c637de 22837@findex gdb.history
d812018b 22838@defun gdb.history (number)
08c637de
TJB
22839Return a value from @value{GDBN}'s value history (@pxref{Value
22840History}). @var{number} indicates which history element to return.
22841If @var{number} is negative, then @value{GDBN} will take its absolute value
22842and count backward from the last element (i.e., the most recent element) to
22843find the value to return. If @var{number} is zero, then @value{GDBN} will
a0c36267 22844return the most recent element. If the element specified by @var{number}
621c8364 22845doesn't exist in the value history, a @code{gdb.error} exception will be
08c637de
TJB
22846raised.
22847
22848If no exception is raised, the return value is always an instance of
22849@code{gdb.Value} (@pxref{Values From Inferior}).
22850@end defun
22851
57a1d736 22852@findex gdb.parse_and_eval
d812018b 22853@defun gdb.parse_and_eval (expression)
57a1d736
TT
22854Parse @var{expression} as an expression in the current language,
22855evaluate it, and return the result as a @code{gdb.Value}.
22856@var{expression} must be a string.
22857
22858This function can be useful when implementing a new command
22859(@pxref{Commands In Python}), as it provides a way to parse the
22860command's argument as an expression. It is also useful simply to
22861compute values, for example, it is the only way to get the value of a
22862convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
22863@end defun
22864
7efc75aa
SCR
22865@findex gdb.find_pc_line
22866@defun gdb.find_pc_line (pc)
22867Return the @code{gdb.Symtab_and_line} object corresponding to the
22868@var{pc} value. @xref{Symbol Tables In Python}. If an invalid
22869value of @var{pc} is passed as an argument, then the @code{symtab} and
22870@code{line} attributes of the returned @code{gdb.Symtab_and_line} object
22871will be @code{None} and 0 respectively.
22872@end defun
22873
ca5c20b6 22874@findex gdb.post_event
d812018b 22875@defun gdb.post_event (event)
ca5c20b6
PM
22876Put @var{event}, a callable object taking no arguments, into
22877@value{GDBN}'s internal event queue. This callable will be invoked at
22878some later point, during @value{GDBN}'s event processing. Events
22879posted using @code{post_event} will be run in the order in which they
22880were posted; however, there is no way to know when they will be
22881processed relative to other events inside @value{GDBN}.
22882
22883@value{GDBN} is not thread-safe. If your Python program uses multiple
22884threads, you must be careful to only call @value{GDBN}-specific
22885functions in the main @value{GDBN} thread. @code{post_event} ensures
22886this. For example:
22887
22888@smallexample
22889(@value{GDBP}) python
22890>import threading
22891>
22892>class Writer():
22893> def __init__(self, message):
22894> self.message = message;
22895> def __call__(self):
22896> gdb.write(self.message)
22897>
22898>class MyThread1 (threading.Thread):
22899> def run (self):
22900> gdb.post_event(Writer("Hello "))
22901>
22902>class MyThread2 (threading.Thread):
22903> def run (self):
22904> gdb.post_event(Writer("World\n"))
22905>
22906>MyThread1().start()
22907>MyThread2().start()
22908>end
22909(@value{GDBP}) Hello World
22910@end smallexample
22911@end defun
22912
99c3dc11 22913@findex gdb.write
d812018b 22914@defun gdb.write (string @r{[}, stream{]})
99c3dc11
PM
22915Print a string to @value{GDBN}'s paginated output stream. The
22916optional @var{stream} determines the stream to print to. The default
22917stream is @value{GDBN}'s standard output stream. Possible stream
22918values are:
22919
22920@table @code
22921@findex STDOUT
22922@findex gdb.STDOUT
d812018b 22923@item gdb.STDOUT
99c3dc11
PM
22924@value{GDBN}'s standard output stream.
22925
22926@findex STDERR
22927@findex gdb.STDERR
d812018b 22928@item gdb.STDERR
99c3dc11
PM
22929@value{GDBN}'s standard error stream.
22930
22931@findex STDLOG
22932@findex gdb.STDLOG
d812018b 22933@item gdb.STDLOG
99c3dc11
PM
22934@value{GDBN}'s log stream (@pxref{Logging Output}).
22935@end table
22936
d57a3c85 22937Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
99c3dc11
PM
22938call this function and will automatically direct the output to the
22939relevant stream.
d57a3c85
TJB
22940@end defun
22941
22942@findex gdb.flush
d812018b 22943@defun gdb.flush ()
99c3dc11
PM
22944Flush the buffer of a @value{GDBN} paginated stream so that the
22945contents are displayed immediately. @value{GDBN} will flush the
22946contents of a stream automatically when it encounters a newline in the
22947buffer. The optional @var{stream} determines the stream to flush. The
22948default stream is @value{GDBN}'s standard output stream. Possible
22949stream values are:
22950
22951@table @code
22952@findex STDOUT
22953@findex gdb.STDOUT
d812018b 22954@item gdb.STDOUT
99c3dc11
PM
22955@value{GDBN}'s standard output stream.
22956
22957@findex STDERR
22958@findex gdb.STDERR
d812018b 22959@item gdb.STDERR
99c3dc11
PM
22960@value{GDBN}'s standard error stream.
22961
22962@findex STDLOG
22963@findex gdb.STDLOG
d812018b 22964@item gdb.STDLOG
99c3dc11
PM
22965@value{GDBN}'s log stream (@pxref{Logging Output}).
22966
22967@end table
22968
22969Flushing @code{sys.stdout} or @code{sys.stderr} will automatically
22970call this function for the relevant stream.
d57a3c85
TJB
22971@end defun
22972
f870a310 22973@findex gdb.target_charset
d812018b 22974@defun gdb.target_charset ()
f870a310
TT
22975Return the name of the current target character set (@pxref{Character
22976Sets}). This differs from @code{gdb.parameter('target-charset')} in
22977that @samp{auto} is never returned.
22978@end defun
22979
22980@findex gdb.target_wide_charset
d812018b 22981@defun gdb.target_wide_charset ()
f870a310
TT
22982Return the name of the current target wide character set
22983(@pxref{Character Sets}). This differs from
22984@code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
22985never returned.
22986@end defun
22987
cb2e07a6 22988@findex gdb.solib_name
d812018b 22989@defun gdb.solib_name (address)
cb2e07a6
PM
22990Return the name of the shared library holding the given @var{address}
22991as a string, or @code{None}.
22992@end defun
22993
22994@findex gdb.decode_line
d812018b 22995@defun gdb.decode_line @r{[}expression@r{]}
cb2e07a6
PM
22996Return locations of the line specified by @var{expression}, or of the
22997current line if no argument was given. This function returns a Python
22998tuple containing two elements. The first element contains a string
22999holding any unparsed section of @var{expression} (or @code{None} if
23000the expression has been fully parsed). The second element contains
23001either @code{None} or another tuple that contains all the locations
23002that match the expression represented as @code{gdb.Symtab_and_line}
23003objects (@pxref{Symbol Tables In Python}). If @var{expression} is
23004provided, it is decoded the way that @value{GDBN}'s inbuilt
23005@code{break} or @code{edit} commands do (@pxref{Specify Location}).
23006@end defun
23007
d812018b 23008@defun gdb.prompt_hook (current_prompt)
fa3a4f15
PM
23009@anchor{prompt_hook}
23010
d17b6f81
PM
23011If @var{prompt_hook} is callable, @value{GDBN} will call the method
23012assigned to this operation before a prompt is displayed by
23013@value{GDBN}.
23014
23015The parameter @code{current_prompt} contains the current @value{GDBN}
23016prompt. This method must return a Python string, or @code{None}. If
23017a string is returned, the @value{GDBN} prompt will be set to that
23018string. If @code{None} is returned, @value{GDBN} will continue to use
23019the current prompt.
23020
23021Some prompts cannot be substituted in @value{GDBN}. Secondary prompts
23022such as those used by readline for command input, and annotation
23023related prompts are prohibited from being changed.
d812018b 23024@end defun
d17b6f81 23025
d57a3c85
TJB
23026@node Exception Handling
23027@subsubsection Exception Handling
23028@cindex python exceptions
23029@cindex exceptions, python
23030
23031When executing the @code{python} command, Python exceptions
23032uncaught within the Python code are translated to calls to
23033@value{GDBN} error-reporting mechanism. If the command that called
23034@code{python} does not handle the error, @value{GDBN} will
23035terminate it and print an error message containing the Python
23036exception name, the associated value, and the Python call stack
23037backtrace at the point where the exception was raised. Example:
23038
23039@smallexample
23040(@value{GDBP}) python print foo
23041Traceback (most recent call last):
23042 File "<string>", line 1, in <module>
23043NameError: name 'foo' is not defined
23044@end smallexample
23045
621c8364
TT
23046@value{GDBN} errors that happen in @value{GDBN} commands invoked by
23047Python code are converted to Python exceptions. The type of the
23048Python exception depends on the error.
23049
23050@ftable @code
23051@item gdb.error
23052This is the base class for most exceptions generated by @value{GDBN}.
23053It is derived from @code{RuntimeError}, for compatibility with earlier
23054versions of @value{GDBN}.
23055
23056If an error occurring in @value{GDBN} does not fit into some more
23057specific category, then the generated exception will have this type.
23058
23059@item gdb.MemoryError
23060This is a subclass of @code{gdb.error} which is thrown when an
23061operation tried to access invalid memory in the inferior.
23062
23063@item KeyboardInterrupt
23064User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
23065prompt) is translated to a Python @code{KeyboardInterrupt} exception.
23066@end ftable
23067
23068In all cases, your exception handler will see the @value{GDBN} error
23069message as its value and the Python call stack backtrace at the Python
23070statement closest to where the @value{GDBN} error occured as the
d57a3c85
TJB
23071traceback.
23072
07ca107c
DE
23073@findex gdb.GdbError
23074When implementing @value{GDBN} commands in Python via @code{gdb.Command},
23075it is useful to be able to throw an exception that doesn't cause a
23076traceback to be printed. For example, the user may have invoked the
23077command incorrectly. Use the @code{gdb.GdbError} exception
23078to handle this case. Example:
23079
23080@smallexample
23081(gdb) python
23082>class HelloWorld (gdb.Command):
23083> """Greet the whole world."""
23084> def __init__ (self):
7d74f244 23085> super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
07ca107c
DE
23086> def invoke (self, args, from_tty):
23087> argv = gdb.string_to_argv (args)
23088> if len (argv) != 0:
23089> raise gdb.GdbError ("hello-world takes no arguments")
23090> print "Hello, World!"
23091>HelloWorld ()
23092>end
23093(gdb) hello-world 42
23094hello-world takes no arguments
23095@end smallexample
23096
a08702d6
TJB
23097@node Values From Inferior
23098@subsubsection Values From Inferior
23099@cindex values from inferior, with Python
23100@cindex python, working with values from inferior
23101
23102@cindex @code{gdb.Value}
23103@value{GDBN} provides values it obtains from the inferior program in
23104an object of type @code{gdb.Value}. @value{GDBN} uses this object
23105for its internal bookkeeping of the inferior's values, and for
23106fetching values when necessary.
23107
23108Inferior values that are simple scalars can be used directly in
23109Python expressions that are valid for the value's data type. Here's
23110an example for an integer or floating-point value @code{some_val}:
23111
23112@smallexample
23113bar = some_val + 2
23114@end smallexample
23115
23116@noindent
23117As result of this, @code{bar} will also be a @code{gdb.Value} object
23118whose values are of the same type as those of @code{some_val}.
23119
23120Inferior values that are structures or instances of some class can
23121be accessed using the Python @dfn{dictionary syntax}. For example, if
23122@code{some_val} is a @code{gdb.Value} instance holding a structure, you
23123can access its @code{foo} element with:
23124
23125@smallexample
23126bar = some_val['foo']
23127@end smallexample
23128
23129Again, @code{bar} will also be a @code{gdb.Value} object.
23130
5374244e
PM
23131A @code{gdb.Value} that represents a function can be executed via
23132inferior function call. Any arguments provided to the call must match
23133the function's prototype, and must be provided in the order specified
23134by that prototype.
23135
23136For example, @code{some_val} is a @code{gdb.Value} instance
23137representing a function that takes two integers as arguments. To
23138execute this function, call it like so:
23139
23140@smallexample
23141result = some_val (10,20)
23142@end smallexample
23143
23144Any values returned from a function call will be stored as a
23145@code{gdb.Value}.
23146
c0c6f777 23147The following attributes are provided:
a08702d6 23148
def2b000 23149@table @code
d812018b 23150@defvar Value.address
c0c6f777
TJB
23151If this object is addressable, this read-only attribute holds a
23152@code{gdb.Value} object representing the address. Otherwise,
23153this attribute holds @code{None}.
d812018b 23154@end defvar
c0c6f777 23155
def2b000 23156@cindex optimized out value in Python
d812018b 23157@defvar Value.is_optimized_out
def2b000
TJB
23158This read-only boolean attribute is true if the compiler optimized out
23159this value, thus it is not available for fetching from the inferior.
d812018b 23160@end defvar
2c74e833 23161
d812018b 23162@defvar Value.type
2c74e833 23163The type of this @code{gdb.Value}. The value of this attribute is a
44592cc4 23164@code{gdb.Type} object (@pxref{Types In Python}).
d812018b 23165@end defvar
03f17ccf 23166
d812018b 23167@defvar Value.dynamic_type
03f17ccf 23168The dynamic type of this @code{gdb.Value}. This uses C@t{++} run-time
fccd1d1e
EZ
23169type information (@acronym{RTTI}) to determine the dynamic type of the
23170value. If this value is of class type, it will return the class in
23171which the value is embedded, if any. If this value is of pointer or
23172reference to a class type, it will compute the dynamic type of the
23173referenced object, and return a pointer or reference to that type,
23174respectively. In all other cases, it will return the value's static
23175type.
23176
23177Note that this feature will only work when debugging a C@t{++} program
23178that includes @acronym{RTTI} for the object in question. Otherwise,
23179it will just return the static type of the value as in @kbd{ptype foo}
23180(@pxref{Symbols, ptype}).
d812018b 23181@end defvar
22dbab46
PK
23182
23183@defvar Value.is_lazy
23184The value of this read-only boolean attribute is @code{True} if this
23185@code{gdb.Value} has not yet been fetched from the inferior.
23186@value{GDBN} does not fetch values until necessary, for efficiency.
23187For example:
23188
23189@smallexample
23190myval = gdb.parse_and_eval ('somevar')
23191@end smallexample
23192
23193The value of @code{somevar} is not fetched at this time. It will be
23194fetched when the value is needed, or when the @code{fetch_lazy}
23195method is invoked.
23196@end defvar
def2b000
TJB
23197@end table
23198
23199The following methods are provided:
23200
23201@table @code
d812018b 23202@defun Value.__init__ (@var{val})
e8467610
TT
23203Many Python values can be converted directly to a @code{gdb.Value} via
23204this object initializer. Specifically:
23205
23206@table @asis
23207@item Python boolean
23208A Python boolean is converted to the boolean type from the current
23209language.
23210
23211@item Python integer
23212A Python integer is converted to the C @code{long} type for the
23213current architecture.
23214
23215@item Python long
23216A Python long is converted to the C @code{long long} type for the
23217current architecture.
23218
23219@item Python float
23220A Python float is converted to the C @code{double} type for the
23221current architecture.
23222
23223@item Python string
23224A Python string is converted to a target string, using the current
23225target encoding.
23226
23227@item @code{gdb.Value}
23228If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
23229
23230@item @code{gdb.LazyString}
23231If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
23232Python}), then the lazy string's @code{value} method is called, and
23233its result is used.
23234@end table
d812018b 23235@end defun
e8467610 23236
d812018b 23237@defun Value.cast (type)
14ff2235
PM
23238Return a new instance of @code{gdb.Value} that is the result of
23239casting this instance to the type described by @var{type}, which must
23240be a @code{gdb.Type} object. If the cast cannot be performed for some
23241reason, this method throws an exception.
d812018b 23242@end defun
14ff2235 23243
d812018b 23244@defun Value.dereference ()
def2b000
TJB
23245For pointer data types, this method returns a new @code{gdb.Value} object
23246whose contents is the object pointed to by the pointer. For example, if
23247@code{foo} is a C pointer to an @code{int}, declared in your C program as
a08702d6
TJB
23248
23249@smallexample
23250int *foo;
23251@end smallexample
23252
23253@noindent
23254then you can use the corresponding @code{gdb.Value} to access what
23255@code{foo} points to like this:
23256
23257@smallexample
23258bar = foo.dereference ()
23259@end smallexample
23260
23261The result @code{bar} will be a @code{gdb.Value} object holding the
23262value pointed to by @code{foo}.
7b282c5a
SCR
23263
23264A similar function @code{Value.referenced_value} exists which also
23265returns @code{gdb.Value} objects corresonding to the values pointed to
23266by pointer values (and additionally, values referenced by reference
23267values). However, the behavior of @code{Value.dereference}
23268differs from @code{Value.referenced_value} by the fact that the
23269behavior of @code{Value.dereference} is identical to applying the C
23270unary operator @code{*} on a given value. For example, consider a
23271reference to a pointer @code{ptrref}, declared in your C@t{++} program
23272as
23273
23274@smallexample
23275typedef int *intptr;
23276...
23277int val = 10;
23278intptr ptr = &val;
23279intptr &ptrref = ptr;
23280@end smallexample
23281
23282Though @code{ptrref} is a reference value, one can apply the method
23283@code{Value.dereference} to the @code{gdb.Value} object corresponding
23284to it and obtain a @code{gdb.Value} which is identical to that
23285corresponding to @code{val}. However, if you apply the method
23286@code{Value.referenced_value}, the result would be a @code{gdb.Value}
23287object identical to that corresponding to @code{ptr}.
23288
23289@smallexample
23290py_ptrref = gdb.parse_and_eval ("ptrref")
23291py_val = py_ptrref.dereference ()
23292py_ptr = py_ptrref.referenced_value ()
23293@end smallexample
23294
23295The @code{gdb.Value} object @code{py_val} is identical to that
23296corresponding to @code{val}, and @code{py_ptr} is identical to that
23297corresponding to @code{ptr}. In general, @code{Value.dereference} can
23298be applied whenever the C unary operator @code{*} can be applied
23299to the corresponding C value. For those cases where applying both
23300@code{Value.dereference} and @code{Value.referenced_value} is allowed,
23301the results obtained need not be identical (as we have seen in the above
23302example). The results are however identical when applied on
23303@code{gdb.Value} objects corresponding to pointers (@code{gdb.Value}
23304objects with type code @code{TYPE_CODE_PTR}) in a C/C@t{++} program.
23305@end defun
23306
23307@defun Value.referenced_value ()
23308For pointer or reference data types, this method returns a new
23309@code{gdb.Value} object corresponding to the value referenced by the
23310pointer/reference value. For pointer data types,
23311@code{Value.dereference} and @code{Value.referenced_value} produce
23312identical results. The difference between these methods is that
23313@code{Value.dereference} cannot get the values referenced by reference
23314values. For example, consider a reference to an @code{int}, declared
23315in your C@t{++} program as
23316
23317@smallexample
23318int val = 10;
23319int &ref = val;
23320@end smallexample
23321
23322@noindent
23323then applying @code{Value.dereference} to the @code{gdb.Value} object
23324corresponding to @code{ref} will result in an error, while applying
23325@code{Value.referenced_value} will result in a @code{gdb.Value} object
23326identical to that corresponding to @code{val}.
23327
23328@smallexample
23329py_ref = gdb.parse_and_eval ("ref")
23330er_ref = py_ref.dereference () # Results in error
23331py_val = py_ref.referenced_value () # Returns the referenced value
23332@end smallexample
23333
23334The @code{gdb.Value} object @code{py_val} is identical to that
23335corresponding to @code{val}.
d812018b 23336@end defun
a08702d6 23337
d812018b 23338@defun Value.dynamic_cast (type)
f9ffd4bb
TT
23339Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
23340operator were used. Consult a C@t{++} reference for details.
d812018b 23341@end defun
f9ffd4bb 23342
d812018b 23343@defun Value.reinterpret_cast (type)
f9ffd4bb
TT
23344Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
23345operator were used. Consult a C@t{++} reference for details.
d812018b 23346@end defun
f9ffd4bb 23347
d812018b 23348@defun Value.string (@r{[}encoding@r{[}, errors@r{[}, length@r{]]]})
b6cb8e7d
TJB
23349If this @code{gdb.Value} represents a string, then this method
23350converts the contents to a Python string. Otherwise, this method will
23351throw an exception.
23352
23353Strings are recognized in a language-specific way; whether a given
23354@code{gdb.Value} represents a string is determined by the current
23355language.
23356
23357For C-like languages, a value is a string if it is a pointer to or an
23358array of characters or ints. The string is assumed to be terminated
fbb8f299
PM
23359by a zero of the appropriate width. However if the optional length
23360argument is given, the string will be converted to that given length,
23361ignoring any embedded zeros that the string may contain.
b6cb8e7d
TJB
23362
23363If the optional @var{encoding} argument is given, it must be a string
23364naming the encoding of the string in the @code{gdb.Value}, such as
23365@code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
23366the same encodings as the corresponding argument to Python's
23367@code{string.decode} method, and the Python codec machinery will be used
23368to convert the string. If @var{encoding} is not given, or if
23369@var{encoding} is the empty string, then either the @code{target-charset}
23370(@pxref{Character Sets}) will be used, or a language-specific encoding
23371will be used, if the current language is able to supply one.
23372
23373The optional @var{errors} argument is the same as the corresponding
23374argument to Python's @code{string.decode} method.
fbb8f299
PM
23375
23376If the optional @var{length} argument is given, the string will be
23377fetched and converted to the given length.
d812018b 23378@end defun
be759fcf 23379
d812018b 23380@defun Value.lazy_string (@r{[}encoding @r{[}, length@r{]]})
be759fcf
PM
23381If this @code{gdb.Value} represents a string, then this method
23382converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
23383In Python}). Otherwise, this method will throw an exception.
23384
23385If the optional @var{encoding} argument is given, it must be a string
23386naming the encoding of the @code{gdb.LazyString}. Some examples are:
23387@samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
23388@var{encoding} argument is an encoding that @value{GDBN} does
23389recognize, @value{GDBN} will raise an error.
23390
23391When a lazy string is printed, the @value{GDBN} encoding machinery is
23392used to convert the string during printing. If the optional
23393@var{encoding} argument is not provided, or is an empty string,
23394@value{GDBN} will automatically select the encoding most suitable for
23395the string type. For further information on encoding in @value{GDBN}
23396please see @ref{Character Sets}.
23397
23398If the optional @var{length} argument is given, the string will be
23399fetched and encoded to the length of characters specified. If
23400the @var{length} argument is not provided, the string will be fetched
23401and encoded until a null of appropriate width is found.
d812018b 23402@end defun
22dbab46
PK
23403
23404@defun Value.fetch_lazy ()
23405If the @code{gdb.Value} object is currently a lazy value
23406(@code{gdb.Value.is_lazy} is @code{True}), then the value is
23407fetched from the inferior. Any errors that occur in the process
23408will produce a Python exception.
23409
23410If the @code{gdb.Value} object is not a lazy value, this method
23411has no effect.
23412
23413This method does not return a value.
23414@end defun
23415
def2b000 23416@end table
b6cb8e7d 23417
2c74e833
TT
23418@node Types In Python
23419@subsubsection Types In Python
23420@cindex types in Python
23421@cindex Python, working with types
23422
23423@tindex gdb.Type
23424@value{GDBN} represents types from the inferior using the class
23425@code{gdb.Type}.
23426
23427The following type-related functions are available in the @code{gdb}
23428module:
23429
23430@findex gdb.lookup_type
d812018b 23431@defun gdb.lookup_type (name @r{[}, block@r{]})
2c74e833
TT
23432This function looks up a type by name. @var{name} is the name of the
23433type to look up. It must be a string.
23434
5107b149
PM
23435If @var{block} is given, then @var{name} is looked up in that scope.
23436Otherwise, it is searched for globally.
23437
2c74e833
TT
23438Ordinarily, this function will return an instance of @code{gdb.Type}.
23439If the named type cannot be found, it will throw an exception.
23440@end defun
23441
a73bb892
PK
23442If the type is a structure or class type, or an enum type, the fields
23443of that type can be accessed using the Python @dfn{dictionary syntax}.
23444For example, if @code{some_type} is a @code{gdb.Type} instance holding
23445a structure type, you can access its @code{foo} field with:
23446
23447@smallexample
23448bar = some_type['foo']
23449@end smallexample
23450
23451@code{bar} will be a @code{gdb.Field} object; see below under the
23452description of the @code{Type.fields} method for a description of the
23453@code{gdb.Field} class.
23454
2c74e833
TT
23455An instance of @code{Type} has the following attributes:
23456
23457@table @code
d812018b 23458@defvar Type.code
2c74e833
TT
23459The type code for this type. The type code will be one of the
23460@code{TYPE_CODE_} constants defined below.
d812018b 23461@end defvar
2c74e833 23462
d812018b 23463@defvar Type.sizeof
2c74e833
TT
23464The size of this type, in target @code{char} units. Usually, a
23465target's @code{char} type will be an 8-bit byte. However, on some
23466unusual platforms, this type may have a different size.
d812018b 23467@end defvar
2c74e833 23468
d812018b 23469@defvar Type.tag
2c74e833
TT
23470The tag name for this type. The tag name is the name after
23471@code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
23472languages have this concept. If this type has no tag name, then
23473@code{None} is returned.
d812018b 23474@end defvar
2c74e833
TT
23475@end table
23476
23477The following methods are provided:
23478
23479@table @code
d812018b 23480@defun Type.fields ()
2c74e833
TT
23481For structure and union types, this method returns the fields. Range
23482types have two fields, the minimum and maximum values. Enum types
23483have one field per enum constant. Function and method types have one
23484field per parameter. The base types of C@t{++} classes are also
23485represented as fields. If the type has no fields, or does not fit
23486into one of these categories, an empty sequence will be returned.
23487
a73bb892 23488Each field is a @code{gdb.Field} object, with some pre-defined attributes:
2c74e833
TT
23489@table @code
23490@item bitpos
23491This attribute is not available for @code{static} fields (as in
23492C@t{++} or Java). For non-@code{static} fields, the value is the bit
a9f54f60
TT
23493position of the field. For @code{enum} fields, the value is the
23494enumeration member's integer representation.
2c74e833
TT
23495
23496@item name
23497The name of the field, or @code{None} for anonymous fields.
23498
23499@item artificial
23500This is @code{True} if the field is artificial, usually meaning that
23501it was provided by the compiler and not the user. This attribute is
23502always provided, and is @code{False} if the field is not artificial.
23503
bfd31e71
PM
23504@item is_base_class
23505This is @code{True} if the field represents a base class of a C@t{++}
23506structure. This attribute is always provided, and is @code{False}
23507if the field is not a base class of the type that is the argument of
23508@code{fields}, or if that type was not a C@t{++} class.
23509
2c74e833
TT
23510@item bitsize
23511If the field is packed, or is a bitfield, then this will have a
23512non-zero value, which is the size of the field in bits. Otherwise,
23513this will be zero; in this case the field's size is given by its type.
23514
23515@item type
23516The type of the field. This is usually an instance of @code{Type},
23517but it can be @code{None} in some situations.
23518@end table
d812018b 23519@end defun
2c74e833 23520
d812018b 23521@defun Type.array (@var{n1} @r{[}, @var{n2}@r{]})
702c2711
TT
23522Return a new @code{gdb.Type} object which represents an array of this
23523type. If one argument is given, it is the inclusive upper bound of
23524the array; in this case the lower bound is zero. If two arguments are
23525given, the first argument is the lower bound of the array, and the
23526second argument is the upper bound of the array. An array's length
23527must not be negative, but the bounds can be.
d812018b 23528@end defun
702c2711 23529
a72c3253
DE
23530@defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
23531Return a new @code{gdb.Type} object which represents a vector of this
23532type. If one argument is given, it is the inclusive upper bound of
23533the vector; in this case the lower bound is zero. If two arguments are
23534given, the first argument is the lower bound of the vector, and the
23535second argument is the upper bound of the vector. A vector's length
23536must not be negative, but the bounds can be.
23537
23538The difference between an @code{array} and a @code{vector} is that
23539arrays behave like in C: when used in expressions they decay to a pointer
23540to the first element whereas vectors are treated as first class values.
23541@end defun
23542
d812018b 23543@defun Type.const ()
2c74e833
TT
23544Return a new @code{gdb.Type} object which represents a
23545@code{const}-qualified variant of this type.
d812018b 23546@end defun
2c74e833 23547
d812018b 23548@defun Type.volatile ()
2c74e833
TT
23549Return a new @code{gdb.Type} object which represents a
23550@code{volatile}-qualified variant of this type.
d812018b 23551@end defun
2c74e833 23552
d812018b 23553@defun Type.unqualified ()
2c74e833
TT
23554Return a new @code{gdb.Type} object which represents an unqualified
23555variant of this type. That is, the result is neither @code{const} nor
23556@code{volatile}.
d812018b 23557@end defun
2c74e833 23558
d812018b 23559@defun Type.range ()
361ae042
PM
23560Return a Python @code{Tuple} object that contains two elements: the
23561low bound of the argument type and the high bound of that type. If
23562the type does not have a range, @value{GDBN} will raise a
621c8364 23563@code{gdb.error} exception (@pxref{Exception Handling}).
d812018b 23564@end defun
361ae042 23565
d812018b 23566@defun Type.reference ()
2c74e833
TT
23567Return a new @code{gdb.Type} object which represents a reference to this
23568type.
d812018b 23569@end defun
2c74e833 23570
d812018b 23571@defun Type.pointer ()
7a6973ad
TT
23572Return a new @code{gdb.Type} object which represents a pointer to this
23573type.
d812018b 23574@end defun
7a6973ad 23575
d812018b 23576@defun Type.strip_typedefs ()
2c74e833
TT
23577Return a new @code{gdb.Type} that represents the real type,
23578after removing all layers of typedefs.
d812018b 23579@end defun
2c74e833 23580
d812018b 23581@defun Type.target ()
2c74e833
TT
23582Return a new @code{gdb.Type} object which represents the target type
23583of this type.
23584
23585For a pointer type, the target type is the type of the pointed-to
23586object. For an array type (meaning C-like arrays), the target type is
23587the type of the elements of the array. For a function or method type,
23588the target type is the type of the return value. For a complex type,
23589the target type is the type of the elements. For a typedef, the
23590target type is the aliased type.
23591
23592If the type does not have a target, this method will throw an
23593exception.
d812018b 23594@end defun
2c74e833 23595
d812018b 23596@defun Type.template_argument (n @r{[}, block@r{]})
2c74e833
TT
23597If this @code{gdb.Type} is an instantiation of a template, this will
23598return a new @code{gdb.Type} which represents the type of the
23599@var{n}th template argument.
23600
23601If this @code{gdb.Type} is not a template type, this will throw an
23602exception. Ordinarily, only C@t{++} code will have template types.
23603
5107b149
PM
23604If @var{block} is given, then @var{name} is looked up in that scope.
23605Otherwise, it is searched for globally.
d812018b 23606@end defun
2c74e833
TT
23607@end table
23608
23609
23610Each type has a code, which indicates what category this type falls
23611into. The available type categories are represented by constants
23612defined in the @code{gdb} module:
23613
23614@table @code
23615@findex TYPE_CODE_PTR
23616@findex gdb.TYPE_CODE_PTR
d812018b 23617@item gdb.TYPE_CODE_PTR
2c74e833
TT
23618The type is a pointer.
23619
23620@findex TYPE_CODE_ARRAY
23621@findex gdb.TYPE_CODE_ARRAY
d812018b 23622@item gdb.TYPE_CODE_ARRAY
2c74e833
TT
23623The type is an array.
23624
23625@findex TYPE_CODE_STRUCT
23626@findex gdb.TYPE_CODE_STRUCT
d812018b 23627@item gdb.TYPE_CODE_STRUCT
2c74e833
TT
23628The type is a structure.
23629
23630@findex TYPE_CODE_UNION
23631@findex gdb.TYPE_CODE_UNION
d812018b 23632@item gdb.TYPE_CODE_UNION
2c74e833
TT
23633The type is a union.
23634
23635@findex TYPE_CODE_ENUM
23636@findex gdb.TYPE_CODE_ENUM
d812018b 23637@item gdb.TYPE_CODE_ENUM
2c74e833
TT
23638The type is an enum.
23639
23640@findex TYPE_CODE_FLAGS
23641@findex gdb.TYPE_CODE_FLAGS
d812018b 23642@item gdb.TYPE_CODE_FLAGS
2c74e833
TT
23643A bit flags type, used for things such as status registers.
23644
23645@findex TYPE_CODE_FUNC
23646@findex gdb.TYPE_CODE_FUNC
d812018b 23647@item gdb.TYPE_CODE_FUNC
2c74e833
TT
23648The type is a function.
23649
23650@findex TYPE_CODE_INT
23651@findex gdb.TYPE_CODE_INT
d812018b 23652@item gdb.TYPE_CODE_INT
2c74e833
TT
23653The type is an integer type.
23654
23655@findex TYPE_CODE_FLT
23656@findex gdb.TYPE_CODE_FLT
d812018b 23657@item gdb.TYPE_CODE_FLT
2c74e833
TT
23658A floating point type.
23659
23660@findex TYPE_CODE_VOID
23661@findex gdb.TYPE_CODE_VOID
d812018b 23662@item gdb.TYPE_CODE_VOID
2c74e833
TT
23663The special type @code{void}.
23664
23665@findex TYPE_CODE_SET
23666@findex gdb.TYPE_CODE_SET
d812018b 23667@item gdb.TYPE_CODE_SET
2c74e833
TT
23668A Pascal set type.
23669
23670@findex TYPE_CODE_RANGE
23671@findex gdb.TYPE_CODE_RANGE
d812018b 23672@item gdb.TYPE_CODE_RANGE
2c74e833
TT
23673A range type, that is, an integer type with bounds.
23674
23675@findex TYPE_CODE_STRING
23676@findex gdb.TYPE_CODE_STRING
d812018b 23677@item gdb.TYPE_CODE_STRING
2c74e833
TT
23678A string type. Note that this is only used for certain languages with
23679language-defined string types; C strings are not represented this way.
23680
23681@findex TYPE_CODE_BITSTRING
23682@findex gdb.TYPE_CODE_BITSTRING
d812018b 23683@item gdb.TYPE_CODE_BITSTRING
6b1755ce 23684A string of bits. It is deprecated.
2c74e833
TT
23685
23686@findex TYPE_CODE_ERROR
23687@findex gdb.TYPE_CODE_ERROR
d812018b 23688@item gdb.TYPE_CODE_ERROR
2c74e833
TT
23689An unknown or erroneous type.
23690
23691@findex TYPE_CODE_METHOD
23692@findex gdb.TYPE_CODE_METHOD
d812018b 23693@item gdb.TYPE_CODE_METHOD
2c74e833
TT
23694A method type, as found in C@t{++} or Java.
23695
23696@findex TYPE_CODE_METHODPTR
23697@findex gdb.TYPE_CODE_METHODPTR
d812018b 23698@item gdb.TYPE_CODE_METHODPTR
2c74e833
TT
23699A pointer-to-member-function.
23700
23701@findex TYPE_CODE_MEMBERPTR
23702@findex gdb.TYPE_CODE_MEMBERPTR
d812018b 23703@item gdb.TYPE_CODE_MEMBERPTR
2c74e833
TT
23704A pointer-to-member.
23705
23706@findex TYPE_CODE_REF
23707@findex gdb.TYPE_CODE_REF
d812018b 23708@item gdb.TYPE_CODE_REF
2c74e833
TT
23709A reference type.
23710
23711@findex TYPE_CODE_CHAR
23712@findex gdb.TYPE_CODE_CHAR
d812018b 23713@item gdb.TYPE_CODE_CHAR
2c74e833
TT
23714A character type.
23715
23716@findex TYPE_CODE_BOOL
23717@findex gdb.TYPE_CODE_BOOL
d812018b 23718@item gdb.TYPE_CODE_BOOL
2c74e833
TT
23719A boolean type.
23720
23721@findex TYPE_CODE_COMPLEX
23722@findex gdb.TYPE_CODE_COMPLEX
d812018b 23723@item gdb.TYPE_CODE_COMPLEX
2c74e833
TT
23724A complex float type.
23725
23726@findex TYPE_CODE_TYPEDEF
23727@findex gdb.TYPE_CODE_TYPEDEF
d812018b 23728@item gdb.TYPE_CODE_TYPEDEF
2c74e833
TT
23729A typedef to some other type.
23730
23731@findex TYPE_CODE_NAMESPACE
23732@findex gdb.TYPE_CODE_NAMESPACE
d812018b 23733@item gdb.TYPE_CODE_NAMESPACE
2c74e833
TT
23734A C@t{++} namespace.
23735
23736@findex TYPE_CODE_DECFLOAT
23737@findex gdb.TYPE_CODE_DECFLOAT
d812018b 23738@item gdb.TYPE_CODE_DECFLOAT
2c74e833
TT
23739A decimal floating point type.
23740
23741@findex TYPE_CODE_INTERNAL_FUNCTION
23742@findex gdb.TYPE_CODE_INTERNAL_FUNCTION
d812018b 23743@item gdb.TYPE_CODE_INTERNAL_FUNCTION
2c74e833
TT
23744A function internal to @value{GDBN}. This is the type used to represent
23745convenience functions.
23746@end table
23747
0e3509db
DE
23748Further support for types is provided in the @code{gdb.types}
23749Python module (@pxref{gdb.types}).
23750
4c374409
JK
23751@node Pretty Printing API
23752@subsubsection Pretty Printing API
a6bac58e 23753
4c374409 23754An example output is provided (@pxref{Pretty Printing}).
a6bac58e
TT
23755
23756A pretty-printer is just an object that holds a value and implements a
23757specific interface, defined here.
23758
d812018b 23759@defun pretty_printer.children (self)
a6bac58e
TT
23760@value{GDBN} will call this method on a pretty-printer to compute the
23761children of the pretty-printer's value.
23762
23763This method must return an object conforming to the Python iterator
23764protocol. Each item returned by the iterator must be a tuple holding
23765two elements. The first element is the ``name'' of the child; the
23766second element is the child's value. The value can be any Python
23767object which is convertible to a @value{GDBN} value.
23768
23769This method is optional. If it does not exist, @value{GDBN} will act
23770as though the value has no children.
d812018b 23771@end defun
a6bac58e 23772
d812018b 23773@defun pretty_printer.display_hint (self)
a6bac58e
TT
23774The CLI may call this method and use its result to change the
23775formatting of a value. The result will also be supplied to an MI
23776consumer as a @samp{displayhint} attribute of the variable being
23777printed.
23778
23779This method is optional. If it does exist, this method must return a
23780string.
23781
23782Some display hints are predefined by @value{GDBN}:
23783
23784@table @samp
23785@item array
23786Indicate that the object being printed is ``array-like''. The CLI
23787uses this to respect parameters such as @code{set print elements} and
23788@code{set print array}.
23789
23790@item map
23791Indicate that the object being printed is ``map-like'', and that the
23792children of this value can be assumed to alternate between keys and
23793values.
23794
23795@item string
23796Indicate that the object being printed is ``string-like''. If the
23797printer's @code{to_string} method returns a Python string of some
23798kind, then @value{GDBN} will call its internal language-specific
23799string-printing function to format the string. For the CLI this means
23800adding quotation marks, possibly escaping some characters, respecting
23801@code{set print elements}, and the like.
23802@end table
d812018b 23803@end defun
a6bac58e 23804
d812018b 23805@defun pretty_printer.to_string (self)
a6bac58e
TT
23806@value{GDBN} will call this method to display the string
23807representation of the value passed to the object's constructor.
23808
23809When printing from the CLI, if the @code{to_string} method exists,
23810then @value{GDBN} will prepend its result to the values returned by
23811@code{children}. Exactly how this formatting is done is dependent on
23812the display hint, and may change as more hints are added. Also,
23813depending on the print settings (@pxref{Print Settings}), the CLI may
23814print just the result of @code{to_string} in a stack trace, omitting
23815the result of @code{children}.
23816
23817If this method returns a string, it is printed verbatim.
23818
23819Otherwise, if this method returns an instance of @code{gdb.Value},
23820then @value{GDBN} prints this value. This may result in a call to
23821another pretty-printer.
23822
23823If instead the method returns a Python value which is convertible to a
23824@code{gdb.Value}, then @value{GDBN} performs the conversion and prints
23825the resulting value. Again, this may result in a call to another
23826pretty-printer. Python scalars (integers, floats, and booleans) and
23827strings are convertible to @code{gdb.Value}; other types are not.
23828
79f283fe
PM
23829Finally, if this method returns @code{None} then no further operations
23830are peformed in this method and nothing is printed.
23831
a6bac58e 23832If the result is not one of these types, an exception is raised.
d812018b 23833@end defun
a6bac58e 23834
464b3efb
TT
23835@value{GDBN} provides a function which can be used to look up the
23836default pretty-printer for a @code{gdb.Value}:
23837
23838@findex gdb.default_visualizer
d812018b 23839@defun gdb.default_visualizer (value)
464b3efb
TT
23840This function takes a @code{gdb.Value} object as an argument. If a
23841pretty-printer for this value exists, then it is returned. If no such
23842printer exists, then this returns @code{None}.
23843@end defun
23844
a6bac58e
TT
23845@node Selecting Pretty-Printers
23846@subsubsection Selecting Pretty-Printers
23847
23848The Python list @code{gdb.pretty_printers} contains an array of
967cf477 23849functions or callable objects that have been registered via addition
7b51bc51
DE
23850as a pretty-printer. Printers in this list are called @code{global}
23851printers, they're available when debugging all inferiors.
fa33c3cd 23852Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
a6bac58e
TT
23853Each @code{gdb.Objfile} also contains a @code{pretty_printers}
23854attribute.
23855
7b51bc51 23856Each function on these lists is passed a single @code{gdb.Value}
a6bac58e 23857argument and should return a pretty-printer object conforming to the
4c374409 23858interface definition above (@pxref{Pretty Printing API}). If a function
a6bac58e
TT
23859cannot create a pretty-printer for the value, it should return
23860@code{None}.
23861
23862@value{GDBN} first checks the @code{pretty_printers} attribute of each
fa33c3cd 23863@code{gdb.Objfile} in the current program space and iteratively calls
7b51bc51
DE
23864each enabled lookup routine in the list for that @code{gdb.Objfile}
23865until it receives a pretty-printer object.
fa33c3cd
DE
23866If no pretty-printer is found in the objfile lists, @value{GDBN} then
23867searches the pretty-printer list of the current program space,
967cf477 23868calling each enabled function until an object is returned.
a6bac58e 23869After these lists have been exhausted, it tries the global
967cf477 23870@code{gdb.pretty_printers} list, again calling each enabled function until an
a6bac58e
TT
23871object is returned.
23872
23873The order in which the objfiles are searched is not specified. For a
23874given list, functions are always invoked from the head of the list,
23875and iterated over sequentially until the end of the list, or a printer
23876object is returned.
23877
7b51bc51
DE
23878For various reasons a pretty-printer may not work.
23879For example, the underlying data structure may have changed and
23880the pretty-printer is out of date.
23881
23882The consequences of a broken pretty-printer are severe enough that
23883@value{GDBN} provides support for enabling and disabling individual
23884printers. For example, if @code{print frame-arguments} is on,
23885a backtrace can become highly illegible if any argument is printed
23886with a broken printer.
23887
23888Pretty-printers are enabled and disabled by attaching an @code{enabled}
23889attribute to the registered function or callable object. If this attribute
23890is present and its value is @code{False}, the printer is disabled, otherwise
23891the printer is enabled.
23892
23893@node Writing a Pretty-Printer
23894@subsubsection Writing a Pretty-Printer
23895@cindex writing a pretty-printer
23896
23897A pretty-printer consists of two parts: a lookup function to detect
23898if the type is supported, and the printer itself.
23899
a6bac58e 23900Here is an example showing how a @code{std::string} printer might be
7b51bc51
DE
23901written. @xref{Pretty Printing API}, for details on the API this class
23902must provide.
a6bac58e
TT
23903
23904@smallexample
7b51bc51 23905class StdStringPrinter(object):
a6bac58e
TT
23906 "Print a std::string"
23907
7b51bc51 23908 def __init__(self, val):
a6bac58e
TT
23909 self.val = val
23910
7b51bc51 23911 def to_string(self):
a6bac58e
TT
23912 return self.val['_M_dataplus']['_M_p']
23913
7b51bc51 23914 def display_hint(self):
a6bac58e
TT
23915 return 'string'
23916@end smallexample
23917
23918And here is an example showing how a lookup function for the printer
23919example above might be written.
23920
23921@smallexample
7b51bc51 23922def str_lookup_function(val):
a6bac58e 23923 lookup_tag = val.type.tag
a6bac58e
TT
23924 if lookup_tag == None:
23925 return None
7b51bc51
DE
23926 regex = re.compile("^std::basic_string<char,.*>$")
23927 if regex.match(lookup_tag):
23928 return StdStringPrinter(val)
a6bac58e
TT
23929 return None
23930@end smallexample
23931
23932The example lookup function extracts the value's type, and attempts to
23933match it to a type that it can pretty-print. If it is a type the
23934printer can pretty-print, it will return a printer object. If not, it
23935returns @code{None}.
23936
23937We recommend that you put your core pretty-printers into a Python
23938package. If your pretty-printers are for use with a library, we
23939further recommend embedding a version number into the package name.
23940This practice will enable @value{GDBN} to load multiple versions of
23941your pretty-printers at the same time, because they will have
23942different names.
23943
bf88dd68 23944You should write auto-loaded code (@pxref{Python Auto-loading}) such that it
a6bac58e
TT
23945can be evaluated multiple times without changing its meaning. An
23946ideal auto-load file will consist solely of @code{import}s of your
23947printer modules, followed by a call to a register pretty-printers with
23948the current objfile.
23949
23950Taken as a whole, this approach will scale nicely to multiple
23951inferiors, each potentially using a different library version.
23952Embedding a version number in the Python package name will ensure that
23953@value{GDBN} is able to load both sets of printers simultaneously.
23954Then, because the search for pretty-printers is done by objfile, and
23955because your auto-loaded code took care to register your library's
23956printers with a specific objfile, @value{GDBN} will find the correct
23957printers for the specific version of the library used by each
23958inferior.
23959
4c374409 23960To continue the @code{std::string} example (@pxref{Pretty Printing API}),
a6bac58e
TT
23961this code might appear in @code{gdb.libstdcxx.v6}:
23962
23963@smallexample
7b51bc51 23964def register_printers(objfile):
ae6f0d5b 23965 objfile.pretty_printers.append(str_lookup_function)
a6bac58e
TT
23966@end smallexample
23967
23968@noindent
23969And then the corresponding contents of the auto-load file would be:
23970
23971@smallexample
23972import gdb.libstdcxx.v6
7b51bc51 23973gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
a6bac58e
TT
23974@end smallexample
23975
7b51bc51
DE
23976The previous example illustrates a basic pretty-printer.
23977There are a few things that can be improved on.
23978The printer doesn't have a name, making it hard to identify in a
23979list of installed printers. The lookup function has a name, but
23980lookup functions can have arbitrary, even identical, names.
967cf477 23981
7b51bc51
DE
23982Second, the printer only handles one type, whereas a library typically has
23983several types. One could install a lookup function for each desired type
23984in the library, but one could also have a single lookup function recognize
23985several types. The latter is the conventional way this is handled.
23986If a pretty-printer can handle multiple data types, then its
23987@dfn{subprinters} are the printers for the individual data types.
967cf477 23988
7b51bc51
DE
23989The @code{gdb.printing} module provides a formal way of solving these
23990problems (@pxref{gdb.printing}).
23991Here is another example that handles multiple types.
967cf477 23992
7b51bc51
DE
23993These are the types we are going to pretty-print:
23994
23995@smallexample
23996struct foo @{ int a, b; @};
23997struct bar @{ struct foo x, y; @};
23998@end smallexample
23999
24000Here are the printers:
24001
24002@smallexample
24003class fooPrinter:
24004 """Print a foo object."""
24005
24006 def __init__(self, val):
24007 self.val = val
24008
24009 def to_string(self):
24010 return ("a=<" + str(self.val["a"]) +
24011 "> b=<" + str(self.val["b"]) + ">")
24012
24013class barPrinter:
24014 """Print a bar object."""
24015
24016 def __init__(self, val):
24017 self.val = val
24018
24019 def to_string(self):
24020 return ("x=<" + str(self.val["x"]) +
24021 "> y=<" + str(self.val["y"]) + ">")
24022@end smallexample
24023
24024This example doesn't need a lookup function, that is handled by the
24025@code{gdb.printing} module. Instead a function is provided to build up
24026the object that handles the lookup.
24027
24028@smallexample
24029import gdb.printing
24030
24031def build_pretty_printer():
24032 pp = gdb.printing.RegexpCollectionPrettyPrinter(
24033 "my_library")
24034 pp.add_printer('foo', '^foo$', fooPrinter)
24035 pp.add_printer('bar', '^bar$', barPrinter)
24036 return pp
24037@end smallexample
24038
24039And here is the autoload support:
24040
24041@smallexample
24042import gdb.printing
24043import my_library
24044gdb.printing.register_pretty_printer(
24045 gdb.current_objfile(),
24046 my_library.build_pretty_printer())
24047@end smallexample
24048
24049Finally, when this printer is loaded into @value{GDBN}, here is the
24050corresponding output of @samp{info pretty-printer}:
24051
24052@smallexample
24053(gdb) info pretty-printer
24054my_library.so:
24055 my_library
24056 foo
24057 bar
24058@end smallexample
967cf477 24059
18a9fc12
TT
24060@node Type Printing API
24061@subsubsection Type Printing API
24062@cindex type printing API for Python
24063
24064@value{GDBN} provides a way for Python code to customize type display.
24065This is mainly useful for substituting canonical typedef names for
24066types.
24067
24068@cindex type printer
24069A @dfn{type printer} is just a Python object conforming to a certain
24070protocol. A simple base class implementing the protocol is provided;
24071see @ref{gdb.types}. A type printer must supply at least:
24072
24073@defivar type_printer enabled
24074A boolean which is True if the printer is enabled, and False
24075otherwise. This is manipulated by the @code{enable type-printer}
24076and @code{disable type-printer} commands.
24077@end defivar
24078
24079@defivar type_printer name
24080The name of the type printer. This must be a string. This is used by
24081the @code{enable type-printer} and @code{disable type-printer}
24082commands.
24083@end defivar
24084
24085@defmethod type_printer instantiate (self)
24086This is called by @value{GDBN} at the start of type-printing. It is
24087only called if the type printer is enabled. This method must return a
24088new object that supplies a @code{recognize} method, as described below.
24089@end defmethod
24090
24091
24092When displaying a type, say via the @code{ptype} command, @value{GDBN}
24093will compute a list of type recognizers. This is done by iterating
24094first over the per-objfile type printers (@pxref{Objfiles In Python}),
24095followed by the per-progspace type printers (@pxref{Progspaces In
24096Python}), and finally the global type printers.
24097
24098@value{GDBN} will call the @code{instantiate} method of each enabled
24099type printer. If this method returns @code{None}, then the result is
24100ignored; otherwise, it is appended to the list of recognizers.
24101
24102Then, when @value{GDBN} is going to display a type name, it iterates
24103over the list of recognizers. For each one, it calls the recognition
24104function, stopping if the function returns a non-@code{None} value.
24105The recognition function is defined as:
24106
24107@defmethod type_recognizer recognize (self, type)
24108If @var{type} is not recognized, return @code{None}. Otherwise,
24109return a string which is to be printed as the name of @var{type}.
24110@var{type} will be an instance of @code{gdb.Type} (@pxref{Types In
24111Python}).
24112@end defmethod
24113
24114@value{GDBN} uses this two-pass approach so that type printers can
24115efficiently cache information without holding on to it too long. For
24116example, it can be convenient to look up type information in a type
24117printer and hold it for a recognizer's lifetime; if a single pass were
24118done then type printers would have to make use of the event system in
24119order to avoid holding information that could become stale as the
24120inferior changed.
24121
595939de
PM
24122@node Inferiors In Python
24123@subsubsection Inferiors In Python
505500db 24124@cindex inferiors in Python
595939de
PM
24125
24126@findex gdb.Inferior
24127Programs which are being run under @value{GDBN} are called inferiors
24128(@pxref{Inferiors and Programs}). Python scripts can access
24129information about and manipulate inferiors controlled by @value{GDBN}
24130via objects of the @code{gdb.Inferior} class.
24131
24132The following inferior-related functions are available in the @code{gdb}
24133module:
24134
d812018b 24135@defun gdb.inferiors ()
595939de
PM
24136Return a tuple containing all inferior objects.
24137@end defun
24138
d812018b 24139@defun gdb.selected_inferior ()
2aa48337
KP
24140Return an object representing the current inferior.
24141@end defun
24142
595939de
PM
24143A @code{gdb.Inferior} object has the following attributes:
24144
24145@table @code
d812018b 24146@defvar Inferior.num
595939de 24147ID of inferior, as assigned by GDB.
d812018b 24148@end defvar
595939de 24149
d812018b 24150@defvar Inferior.pid
595939de
PM
24151Process ID of the inferior, as assigned by the underlying operating
24152system.
d812018b 24153@end defvar
595939de 24154
d812018b 24155@defvar Inferior.was_attached
595939de
PM
24156Boolean signaling whether the inferior was created using `attach', or
24157started by @value{GDBN} itself.
d812018b 24158@end defvar
595939de
PM
24159@end table
24160
24161A @code{gdb.Inferior} object has the following methods:
24162
24163@table @code
d812018b 24164@defun Inferior.is_valid ()
29703da4
PM
24165Returns @code{True} if the @code{gdb.Inferior} object is valid,
24166@code{False} if not. A @code{gdb.Inferior} object will become invalid
24167if the inferior no longer exists within @value{GDBN}. All other
24168@code{gdb.Inferior} methods will throw an exception if it is invalid
24169at the time the method is called.
d812018b 24170@end defun
29703da4 24171
d812018b 24172@defun Inferior.threads ()
595939de
PM
24173This method returns a tuple holding all the threads which are valid
24174when it is called. If there are no valid threads, the method will
24175return an empty tuple.
d812018b 24176@end defun
595939de 24177
2678e2af 24178@findex Inferior.read_memory
d812018b 24179@defun Inferior.read_memory (address, length)
595939de
PM
24180Read @var{length} bytes of memory from the inferior, starting at
24181@var{address}. Returns a buffer object, which behaves much like an array
2678e2af 24182or a string. It can be modified and given to the
9a27f2c6
PK
24183@code{Inferior.write_memory} function. In @code{Python} 3, the return
24184value is a @code{memoryview} object.
d812018b 24185@end defun
595939de 24186
2678e2af 24187@findex Inferior.write_memory
d812018b 24188@defun Inferior.write_memory (address, buffer @r{[}, length@r{]})
595939de
PM
24189Write the contents of @var{buffer} to the inferior, starting at
24190@var{address}. The @var{buffer} parameter must be a Python object
24191which supports the buffer protocol, i.e., a string, an array or the
2678e2af 24192object returned from @code{Inferior.read_memory}. If given, @var{length}
595939de 24193determines the number of bytes from @var{buffer} to be written.
d812018b 24194@end defun
595939de
PM
24195
24196@findex gdb.search_memory
d812018b 24197@defun Inferior.search_memory (address, length, pattern)
595939de
PM
24198Search a region of the inferior memory starting at @var{address} with
24199the given @var{length} using the search pattern supplied in
24200@var{pattern}. The @var{pattern} parameter must be a Python object
24201which supports the buffer protocol, i.e., a string, an array or the
24202object returned from @code{gdb.read_memory}. Returns a Python @code{Long}
24203containing the address where the pattern was found, or @code{None} if
24204the pattern could not be found.
d812018b 24205@end defun
595939de
PM
24206@end table
24207
505500db
SW
24208@node Events In Python
24209@subsubsection Events In Python
24210@cindex inferior events in Python
24211
24212@value{GDBN} provides a general event facility so that Python code can be
24213notified of various state changes, particularly changes that occur in
24214the inferior.
24215
24216An @dfn{event} is just an object that describes some state change. The
24217type of the object and its attributes will vary depending on the details
24218of the change. All the existing events are described below.
24219
24220In order to be notified of an event, you must register an event handler
24221with an @dfn{event registry}. An event registry is an object in the
24222@code{gdb.events} module which dispatches particular events. A registry
24223provides methods to register and unregister event handlers:
24224
24225@table @code
d812018b 24226@defun EventRegistry.connect (object)
505500db
SW
24227Add the given callable @var{object} to the registry. This object will be
24228called when an event corresponding to this registry occurs.
d812018b 24229@end defun
505500db 24230
d812018b 24231@defun EventRegistry.disconnect (object)
505500db
SW
24232Remove the given @var{object} from the registry. Once removed, the object
24233will no longer receive notifications of events.
d812018b 24234@end defun
505500db
SW
24235@end table
24236
24237Here is an example:
24238
24239@smallexample
24240def exit_handler (event):
24241 print "event type: exit"
24242 print "exit code: %d" % (event.exit_code)
24243
24244gdb.events.exited.connect (exit_handler)
24245@end smallexample
24246
24247In the above example we connect our handler @code{exit_handler} to the
24248registry @code{events.exited}. Once connected, @code{exit_handler} gets
24249called when the inferior exits. The argument @dfn{event} in this example is
24250of type @code{gdb.ExitedEvent}. As you can see in the example the
24251@code{ExitedEvent} object has an attribute which indicates the exit code of
24252the inferior.
24253
24254The following is a listing of the event registries that are available and
24255details of the events they emit:
24256
24257@table @code
24258
24259@item events.cont
24260Emits @code{gdb.ThreadEvent}.
24261
24262Some events can be thread specific when @value{GDBN} is running in non-stop
24263mode. When represented in Python, these events all extend
24264@code{gdb.ThreadEvent}. Note, this event is not emitted directly; instead,
24265events which are emitted by this or other modules might extend this event.
24266Examples of these events are @code{gdb.BreakpointEvent} and
24267@code{gdb.ContinueEvent}.
24268
24269@table @code
d812018b 24270@defvar ThreadEvent.inferior_thread
505500db
SW
24271In non-stop mode this attribute will be set to the specific thread which was
24272involved in the emitted event. Otherwise, it will be set to @code{None}.
d812018b 24273@end defvar
505500db
SW
24274@end table
24275
24276Emits @code{gdb.ContinueEvent} which extends @code{gdb.ThreadEvent}.
24277
24278This event indicates that the inferior has been continued after a stop. For
24279inherited attribute refer to @code{gdb.ThreadEvent} above.
24280
24281@item events.exited
24282Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
cb6be26b 24283@code{events.ExitedEvent} has two attributes:
505500db 24284@table @code
d812018b 24285@defvar ExitedEvent.exit_code
cb6be26b
KP
24286An integer representing the exit code, if available, which the inferior
24287has returned. (The exit code could be unavailable if, for example,
24288@value{GDBN} detaches from the inferior.) If the exit code is unavailable,
24289the attribute does not exist.
24290@end defvar
24291@defvar ExitedEvent inferior
24292A reference to the inferior which triggered the @code{exited} event.
d812018b 24293@end defvar
505500db
SW
24294@end table
24295
24296@item events.stop
24297Emits @code{gdb.StopEvent} which extends @code{gdb.ThreadEvent}.
24298
24299Indicates that the inferior has stopped. All events emitted by this registry
24300extend StopEvent. As a child of @code{gdb.ThreadEvent}, @code{gdb.StopEvent}
24301will indicate the stopped thread when @value{GDBN} is running in non-stop
24302mode. Refer to @code{gdb.ThreadEvent} above for more details.
24303
24304Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}.
24305
24306This event indicates that the inferior or one of its threads has received as
24307signal. @code{gdb.SignalEvent} has the following attributes:
24308
24309@table @code
d812018b 24310@defvar SignalEvent.stop_signal
505500db
SW
24311A string representing the signal received by the inferior. A list of possible
24312signal values can be obtained by running the command @code{info signals} in
24313the @value{GDBN} command prompt.
d812018b 24314@end defvar
505500db
SW
24315@end table
24316
24317Also emits @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
24318
6839b47f
KP
24319@code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
24320been hit, and has the following attributes:
505500db
SW
24321
24322@table @code
d812018b 24323@defvar BreakpointEvent.breakpoints
6839b47f
KP
24324A sequence containing references to all the breakpoints (type
24325@code{gdb.Breakpoint}) that were hit.
505500db 24326@xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
d812018b
PK
24327@end defvar
24328@defvar BreakpointEvent.breakpoint
6839b47f
KP
24329A reference to the first breakpoint that was hit.
24330This function is maintained for backward compatibility and is now deprecated
d812018b
PK
24331in favor of the @code{gdb.BreakpointEvent.breakpoints} attribute.
24332@end defvar
505500db
SW
24333@end table
24334
20c168b5
KP
24335@item events.new_objfile
24336Emits @code{gdb.NewObjFileEvent} which indicates that a new object file has
24337been loaded by @value{GDBN}. @code{gdb.NewObjFileEvent} has one attribute:
24338
24339@table @code
24340@defvar NewObjFileEvent.new_objfile
24341A reference to the object file (@code{gdb.Objfile}) which has been loaded.
24342@xref{Objfiles In Python}, for details of the @code{gdb.Objfile} object.
24343@end defvar
24344@end table
24345
505500db
SW
24346@end table
24347
595939de
PM
24348@node Threads In Python
24349@subsubsection Threads In Python
24350@cindex threads in python
24351
24352@findex gdb.InferiorThread
24353Python scripts can access information about, and manipulate inferior threads
24354controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
24355
24356The following thread-related functions are available in the @code{gdb}
24357module:
24358
24359@findex gdb.selected_thread
d812018b 24360@defun gdb.selected_thread ()
595939de
PM
24361This function returns the thread object for the selected thread. If there
24362is no selected thread, this will return @code{None}.
24363@end defun
24364
24365A @code{gdb.InferiorThread} object has the following attributes:
24366
24367@table @code
d812018b 24368@defvar InferiorThread.name
4694da01
TT
24369The name of the thread. If the user specified a name using
24370@code{thread name}, then this returns that name. Otherwise, if an
24371OS-supplied name is available, then it is returned. Otherwise, this
24372returns @code{None}.
24373
24374This attribute can be assigned to. The new value must be a string
24375object, which sets the new name, or @code{None}, which removes any
24376user-specified thread name.
d812018b 24377@end defvar
4694da01 24378
d812018b 24379@defvar InferiorThread.num
595939de 24380ID of the thread, as assigned by GDB.
d812018b 24381@end defvar
595939de 24382
d812018b 24383@defvar InferiorThread.ptid
595939de
PM
24384ID of the thread, as assigned by the operating system. This attribute is a
24385tuple containing three integers. The first is the Process ID (PID); the second
24386is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
24387Either the LWPID or TID may be 0, which indicates that the operating system
24388does not use that identifier.
d812018b 24389@end defvar
595939de
PM
24390@end table
24391
24392A @code{gdb.InferiorThread} object has the following methods:
24393
dc3b15be 24394@table @code
d812018b 24395@defun InferiorThread.is_valid ()
29703da4
PM
24396Returns @code{True} if the @code{gdb.InferiorThread} object is valid,
24397@code{False} if not. A @code{gdb.InferiorThread} object will become
24398invalid if the thread exits, or the inferior that the thread belongs
24399is deleted. All other @code{gdb.InferiorThread} methods will throw an
24400exception if it is invalid at the time the method is called.
d812018b 24401@end defun
29703da4 24402
d812018b 24403@defun InferiorThread.switch ()
595939de
PM
24404This changes @value{GDBN}'s currently selected thread to the one represented
24405by this object.
d812018b 24406@end defun
595939de 24407
d812018b 24408@defun InferiorThread.is_stopped ()
595939de 24409Return a Boolean indicating whether the thread is stopped.
d812018b 24410@end defun
595939de 24411
d812018b 24412@defun InferiorThread.is_running ()
595939de 24413Return a Boolean indicating whether the thread is running.
d812018b 24414@end defun
595939de 24415
d812018b 24416@defun InferiorThread.is_exited ()
595939de 24417Return a Boolean indicating whether the thread is exited.
d812018b 24418@end defun
595939de
PM
24419@end table
24420
d8906c6f
TJB
24421@node Commands In Python
24422@subsubsection Commands In Python
24423
24424@cindex commands in python
24425@cindex python commands
d8906c6f
TJB
24426You can implement new @value{GDBN} CLI commands in Python. A CLI
24427command is implemented using an instance of the @code{gdb.Command}
24428class, most commonly using a subclass.
24429
f05e2e1d 24430@defun Command.__init__ (name, @var{command_class} @r{[}, @var{completer_class} @r{[}, @var{prefix}@r{]]})
d8906c6f
TJB
24431The object initializer for @code{Command} registers the new command
24432with @value{GDBN}. This initializer is normally invoked from the
24433subclass' own @code{__init__} method.
24434
24435@var{name} is the name of the command. If @var{name} consists of
24436multiple words, then the initial words are looked for as prefix
24437commands. In this case, if one of the prefix commands does not exist,
24438an exception is raised.
24439
24440There is no support for multi-line commands.
24441
cc924cad 24442@var{command_class} should be one of the @samp{COMMAND_} constants
d8906c6f
TJB
24443defined below. This argument tells @value{GDBN} how to categorize the
24444new command in the help system.
24445
cc924cad 24446@var{completer_class} is an optional argument. If given, it should be
d8906c6f
TJB
24447one of the @samp{COMPLETE_} constants defined below. This argument
24448tells @value{GDBN} how to perform completion for this command. If not
24449given, @value{GDBN} will attempt to complete using the object's
24450@code{complete} method (see below); if no such method is found, an
24451error will occur when completion is attempted.
24452
24453@var{prefix} is an optional argument. If @code{True}, then the new
24454command is a prefix command; sub-commands of this command may be
24455registered.
24456
24457The help text for the new command is taken from the Python
24458documentation string for the command's class, if there is one. If no
24459documentation string is provided, the default value ``This command is
24460not documented.'' is used.
d812018b 24461@end defun
d8906c6f 24462
a0c36267 24463@cindex don't repeat Python command
d812018b 24464@defun Command.dont_repeat ()
d8906c6f
TJB
24465By default, a @value{GDBN} command is repeated when the user enters a
24466blank line at the command prompt. A command can suppress this
24467behavior by invoking the @code{dont_repeat} method. This is similar
24468to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
d812018b 24469@end defun
d8906c6f 24470
d812018b 24471@defun Command.invoke (argument, from_tty)
d8906c6f
TJB
24472This method is called by @value{GDBN} when this command is invoked.
24473
24474@var{argument} is a string. It is the argument to the command, after
24475leading and trailing whitespace has been stripped.
24476
24477@var{from_tty} is a boolean argument. When true, this means that the
24478command was entered by the user at the terminal; when false it means
24479that the command came from elsewhere.
24480
24481If this method throws an exception, it is turned into a @value{GDBN}
24482@code{error} call. Otherwise, the return value is ignored.
07ca107c
DE
24483
24484@findex gdb.string_to_argv
24485To break @var{argument} up into an argv-like string use
24486@code{gdb.string_to_argv}. This function behaves identically to
24487@value{GDBN}'s internal argument lexer @code{buildargv}.
24488It is recommended to use this for consistency.
24489Arguments are separated by spaces and may be quoted.
24490Example:
24491
24492@smallexample
24493print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
24494['1', '2 "3', '4 "5', "6 '7"]
24495@end smallexample
24496
d812018b 24497@end defun
d8906c6f 24498
a0c36267 24499@cindex completion of Python commands
d812018b 24500@defun Command.complete (text, word)
d8906c6f
TJB
24501This method is called by @value{GDBN} when the user attempts
24502completion on this command. All forms of completion are handled by
a0c36267
EZ
24503this method, that is, the @key{TAB} and @key{M-?} key bindings
24504(@pxref{Completion}), and the @code{complete} command (@pxref{Help,
24505complete}).
d8906c6f
TJB
24506
24507The arguments @var{text} and @var{word} are both strings. @var{text}
24508holds the complete command line up to the cursor's location.
24509@var{word} holds the last word of the command line; this is computed
24510using a word-breaking heuristic.
24511
24512The @code{complete} method can return several values:
24513@itemize @bullet
24514@item
24515If the return value is a sequence, the contents of the sequence are
24516used as the completions. It is up to @code{complete} to ensure that the
24517contents actually do complete the word. A zero-length sequence is
24518allowed, it means that there were no completions available. Only
24519string elements of the sequence are used; other elements in the
24520sequence are ignored.
24521
24522@item
24523If the return value is one of the @samp{COMPLETE_} constants defined
24524below, then the corresponding @value{GDBN}-internal completion
24525function is invoked, and its result is used.
24526
24527@item
24528All other results are treated as though there were no available
24529completions.
24530@end itemize
d812018b 24531@end defun
d8906c6f 24532
d8906c6f
TJB
24533When a new command is registered, it must be declared as a member of
24534some general class of commands. This is used to classify top-level
24535commands in the on-line help system; note that prefix commands are not
24536listed under their own category but rather that of their top-level
24537command. The available classifications are represented by constants
24538defined in the @code{gdb} module:
24539
24540@table @code
24541@findex COMMAND_NONE
24542@findex gdb.COMMAND_NONE
d812018b 24543@item gdb.COMMAND_NONE
d8906c6f
TJB
24544The command does not belong to any particular class. A command in
24545this category will not be displayed in any of the help categories.
24546
24547@findex COMMAND_RUNNING
24548@findex gdb.COMMAND_RUNNING
d812018b 24549@item gdb.COMMAND_RUNNING
d8906c6f
TJB
24550The command is related to running the inferior. For example,
24551@code{start}, @code{step}, and @code{continue} are in this category.
a0c36267 24552Type @kbd{help running} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24553commands in this category.
24554
24555@findex COMMAND_DATA
24556@findex gdb.COMMAND_DATA
d812018b 24557@item gdb.COMMAND_DATA
d8906c6f
TJB
24558The command is related to data or variables. For example,
24559@code{call}, @code{find}, and @code{print} are in this category. Type
a0c36267 24560@kbd{help data} at the @value{GDBN} prompt to see a list of commands
d8906c6f
TJB
24561in this category.
24562
24563@findex COMMAND_STACK
24564@findex gdb.COMMAND_STACK
d812018b 24565@item gdb.COMMAND_STACK
d8906c6f
TJB
24566The command has to do with manipulation of the stack. For example,
24567@code{backtrace}, @code{frame}, and @code{return} are in this
a0c36267 24568category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
d8906c6f
TJB
24569list of commands in this category.
24570
24571@findex COMMAND_FILES
24572@findex gdb.COMMAND_FILES
d812018b 24573@item gdb.COMMAND_FILES
d8906c6f
TJB
24574This class is used for file-related commands. For example,
24575@code{file}, @code{list} and @code{section} are in this category.
a0c36267 24576Type @kbd{help files} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24577commands in this category.
24578
24579@findex COMMAND_SUPPORT
24580@findex gdb.COMMAND_SUPPORT
d812018b 24581@item gdb.COMMAND_SUPPORT
d8906c6f
TJB
24582This should be used for ``support facilities'', generally meaning
24583things that are useful to the user when interacting with @value{GDBN},
24584but not related to the state of the inferior. For example,
24585@code{help}, @code{make}, and @code{shell} are in this category. Type
a0c36267 24586@kbd{help support} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24587commands in this category.
24588
24589@findex COMMAND_STATUS
24590@findex gdb.COMMAND_STATUS
d812018b 24591@item gdb.COMMAND_STATUS
d8906c6f
TJB
24592The command is an @samp{info}-related command, that is, related to the
24593state of @value{GDBN} itself. For example, @code{info}, @code{macro},
a0c36267 24594and @code{show} are in this category. Type @kbd{help status} at the
d8906c6f
TJB
24595@value{GDBN} prompt to see a list of commands in this category.
24596
24597@findex COMMAND_BREAKPOINTS
24598@findex gdb.COMMAND_BREAKPOINTS
d812018b 24599@item gdb.COMMAND_BREAKPOINTS
d8906c6f 24600The command has to do with breakpoints. For example, @code{break},
a0c36267 24601@code{clear}, and @code{delete} are in this category. Type @kbd{help
d8906c6f
TJB
24602breakpoints} at the @value{GDBN} prompt to see a list of commands in
24603this category.
24604
24605@findex COMMAND_TRACEPOINTS
24606@findex gdb.COMMAND_TRACEPOINTS
d812018b 24607@item gdb.COMMAND_TRACEPOINTS
d8906c6f
TJB
24608The command has to do with tracepoints. For example, @code{trace},
24609@code{actions}, and @code{tfind} are in this category. Type
a0c36267 24610@kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24611commands in this category.
24612
7d74f244
DE
24613@findex COMMAND_USER
24614@findex gdb.COMMAND_USER
24615@item gdb.COMMAND_USER
24616The command is a general purpose command for the user, and typically
24617does not fit in one of the other categories.
24618Type @kbd{help user-defined} at the @value{GDBN} prompt to see
24619a list of commands in this category, as well as the list of gdb macros
24620(@pxref{Sequences}).
24621
d8906c6f
TJB
24622@findex COMMAND_OBSCURE
24623@findex gdb.COMMAND_OBSCURE
d812018b 24624@item gdb.COMMAND_OBSCURE
d8906c6f
TJB
24625The command is only used in unusual circumstances, or is not of
24626general interest to users. For example, @code{checkpoint},
a0c36267 24627@code{fork}, and @code{stop} are in this category. Type @kbd{help
d8906c6f
TJB
24628obscure} at the @value{GDBN} prompt to see a list of commands in this
24629category.
24630
24631@findex COMMAND_MAINTENANCE
24632@findex gdb.COMMAND_MAINTENANCE
d812018b 24633@item gdb.COMMAND_MAINTENANCE
d8906c6f
TJB
24634The command is only useful to @value{GDBN} maintainers. The
24635@code{maintenance} and @code{flushregs} commands are in this category.
a0c36267 24636Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
d8906c6f
TJB
24637commands in this category.
24638@end table
24639
d8906c6f
TJB
24640A new command can use a predefined completion function, either by
24641specifying it via an argument at initialization, or by returning it
24642from the @code{complete} method. These predefined completion
24643constants are all defined in the @code{gdb} module:
24644
24645@table @code
24646@findex COMPLETE_NONE
24647@findex gdb.COMPLETE_NONE
d812018b 24648@item gdb.COMPLETE_NONE
d8906c6f
TJB
24649This constant means that no completion should be done.
24650
24651@findex COMPLETE_FILENAME
24652@findex gdb.COMPLETE_FILENAME
d812018b 24653@item gdb.COMPLETE_FILENAME
d8906c6f
TJB
24654This constant means that filename completion should be performed.
24655
24656@findex COMPLETE_LOCATION
24657@findex gdb.COMPLETE_LOCATION
d812018b 24658@item gdb.COMPLETE_LOCATION
d8906c6f
TJB
24659This constant means that location completion should be done.
24660@xref{Specify Location}.
24661
24662@findex COMPLETE_COMMAND
24663@findex gdb.COMPLETE_COMMAND
d812018b 24664@item gdb.COMPLETE_COMMAND
d8906c6f
TJB
24665This constant means that completion should examine @value{GDBN}
24666command names.
24667
24668@findex COMPLETE_SYMBOL
24669@findex gdb.COMPLETE_SYMBOL
d812018b 24670@item gdb.COMPLETE_SYMBOL
d8906c6f
TJB
24671This constant means that completion should be done using symbol names
24672as the source.
24673@end table
24674
24675The following code snippet shows how a trivial CLI command can be
24676implemented in Python:
24677
24678@smallexample
24679class HelloWorld (gdb.Command):
24680 """Greet the whole world."""
24681
24682 def __init__ (self):
7d74f244 24683 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
d8906c6f
TJB
24684
24685 def invoke (self, arg, from_tty):
24686 print "Hello, World!"
24687
24688HelloWorld ()
24689@end smallexample
24690
24691The last line instantiates the class, and is necessary to trigger the
24692registration of the command with @value{GDBN}. Depending on how the
24693Python code is read into @value{GDBN}, you may need to import the
24694@code{gdb} module explicitly.
24695
d7b32ed3
PM
24696@node Parameters In Python
24697@subsubsection Parameters In Python
24698
24699@cindex parameters in python
24700@cindex python parameters
24701@tindex gdb.Parameter
24702@tindex Parameter
24703You can implement new @value{GDBN} parameters using Python. A new
24704parameter is implemented as an instance of the @code{gdb.Parameter}
24705class.
24706
24707Parameters are exposed to the user via the @code{set} and
24708@code{show} commands. @xref{Help}.
24709
24710There are many parameters that already exist and can be set in
24711@value{GDBN}. Two examples are: @code{set follow fork} and
24712@code{set charset}. Setting these parameters influences certain
24713behavior in @value{GDBN}. Similarly, you can define parameters that
24714can be used to influence behavior in custom Python scripts and commands.
24715
d812018b 24716@defun Parameter.__init__ (name, @var{command-class}, @var{parameter-class} @r{[}, @var{enum-sequence}@r{]})
d7b32ed3
PM
24717The object initializer for @code{Parameter} registers the new
24718parameter with @value{GDBN}. This initializer is normally invoked
24719from the subclass' own @code{__init__} method.
24720
24721@var{name} is the name of the new parameter. If @var{name} consists
24722of multiple words, then the initial words are looked for as prefix
24723parameters. An example of this can be illustrated with the
24724@code{set print} set of parameters. If @var{name} is
24725@code{print foo}, then @code{print} will be searched as the prefix
24726parameter. In this case the parameter can subsequently be accessed in
24727@value{GDBN} as @code{set print foo}.
24728
24729If @var{name} consists of multiple words, and no prefix parameter group
24730can be found, an exception is raised.
24731
24732@var{command-class} should be one of the @samp{COMMAND_} constants
24733(@pxref{Commands In Python}). This argument tells @value{GDBN} how to
24734categorize the new parameter in the help system.
24735
24736@var{parameter-class} should be one of the @samp{PARAM_} constants
24737defined below. This argument tells @value{GDBN} the type of the new
24738parameter; this information is used for input validation and
24739completion.
24740
24741If @var{parameter-class} is @code{PARAM_ENUM}, then
24742@var{enum-sequence} must be a sequence of strings. These strings
24743represent the possible values for the parameter.
24744
24745If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
24746of a fourth argument will cause an exception to be thrown.
24747
24748The help text for the new parameter is taken from the Python
24749documentation string for the parameter's class, if there is one. If
24750there is no documentation string, a default value is used.
d812018b 24751@end defun
d7b32ed3 24752
d812018b 24753@defvar Parameter.set_doc
d7b32ed3
PM
24754If this attribute exists, and is a string, then its value is used as
24755the help text for this parameter's @code{set} command. The value is
24756examined when @code{Parameter.__init__} is invoked; subsequent changes
24757have no effect.
d812018b 24758@end defvar
d7b32ed3 24759
d812018b 24760@defvar Parameter.show_doc
d7b32ed3
PM
24761If this attribute exists, and is a string, then its value is used as
24762the help text for this parameter's @code{show} command. The value is
24763examined when @code{Parameter.__init__} is invoked; subsequent changes
24764have no effect.
d812018b 24765@end defvar
d7b32ed3 24766
d812018b 24767@defvar Parameter.value
d7b32ed3
PM
24768The @code{value} attribute holds the underlying value of the
24769parameter. It can be read and assigned to just as any other
24770attribute. @value{GDBN} does validation when assignments are made.
d812018b 24771@end defvar
d7b32ed3 24772
ecec24e6
PM
24773There are two methods that should be implemented in any
24774@code{Parameter} class. These are:
24775
d812018b 24776@defun Parameter.get_set_string (self)
ecec24e6
PM
24777@value{GDBN} will call this method when a @var{parameter}'s value has
24778been changed via the @code{set} API (for example, @kbd{set foo off}).
24779The @code{value} attribute has already been populated with the new
24780value and may be used in output. This method must return a string.
d812018b 24781@end defun
ecec24e6 24782
d812018b 24783@defun Parameter.get_show_string (self, svalue)
ecec24e6
PM
24784@value{GDBN} will call this method when a @var{parameter}'s
24785@code{show} API has been invoked (for example, @kbd{show foo}). The
24786argument @code{svalue} receives the string representation of the
24787current value. This method must return a string.
d812018b 24788@end defun
d7b32ed3
PM
24789
24790When a new parameter is defined, its type must be specified. The
24791available types are represented by constants defined in the @code{gdb}
24792module:
24793
24794@table @code
24795@findex PARAM_BOOLEAN
24796@findex gdb.PARAM_BOOLEAN
d812018b 24797@item gdb.PARAM_BOOLEAN
d7b32ed3
PM
24798The value is a plain boolean. The Python boolean values, @code{True}
24799and @code{False} are the only valid values.
24800
24801@findex PARAM_AUTO_BOOLEAN
24802@findex gdb.PARAM_AUTO_BOOLEAN
d812018b 24803@item gdb.PARAM_AUTO_BOOLEAN
d7b32ed3
PM
24804The value has three possible states: true, false, and @samp{auto}. In
24805Python, true and false are represented using boolean constants, and
24806@samp{auto} is represented using @code{None}.
24807
24808@findex PARAM_UINTEGER
24809@findex gdb.PARAM_UINTEGER
d812018b 24810@item gdb.PARAM_UINTEGER
d7b32ed3
PM
24811The value is an unsigned integer. The value of 0 should be
24812interpreted to mean ``unlimited''.
24813
24814@findex PARAM_INTEGER
24815@findex gdb.PARAM_INTEGER
d812018b 24816@item gdb.PARAM_INTEGER
d7b32ed3
PM
24817The value is a signed integer. The value of 0 should be interpreted
24818to mean ``unlimited''.
24819
24820@findex PARAM_STRING
24821@findex gdb.PARAM_STRING
d812018b 24822@item gdb.PARAM_STRING
d7b32ed3
PM
24823The value is a string. When the user modifies the string, any escape
24824sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
24825translated into corresponding characters and encoded into the current
24826host charset.
24827
24828@findex PARAM_STRING_NOESCAPE
24829@findex gdb.PARAM_STRING_NOESCAPE
d812018b 24830@item gdb.PARAM_STRING_NOESCAPE
d7b32ed3
PM
24831The value is a string. When the user modifies the string, escapes are
24832passed through untranslated.
24833
24834@findex PARAM_OPTIONAL_FILENAME
24835@findex gdb.PARAM_OPTIONAL_FILENAME
d812018b 24836@item gdb.PARAM_OPTIONAL_FILENAME
d7b32ed3
PM
24837The value is a either a filename (a string), or @code{None}.
24838
24839@findex PARAM_FILENAME
24840@findex gdb.PARAM_FILENAME
d812018b 24841@item gdb.PARAM_FILENAME
d7b32ed3
PM
24842The value is a filename. This is just like
24843@code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
24844
24845@findex PARAM_ZINTEGER
24846@findex gdb.PARAM_ZINTEGER
d812018b 24847@item gdb.PARAM_ZINTEGER
d7b32ed3
PM
24848The value is an integer. This is like @code{PARAM_INTEGER}, except 0
24849is interpreted as itself.
24850
24851@findex PARAM_ENUM
24852@findex gdb.PARAM_ENUM
d812018b 24853@item gdb.PARAM_ENUM
d7b32ed3
PM
24854The value is a string, which must be one of a collection string
24855constants provided when the parameter is created.
24856@end table
24857
bc3b79fd
TJB
24858@node Functions In Python
24859@subsubsection Writing new convenience functions
24860
24861@cindex writing convenience functions
24862@cindex convenience functions in python
24863@cindex python convenience functions
24864@tindex gdb.Function
24865@tindex Function
24866You can implement new convenience functions (@pxref{Convenience Vars})
24867in Python. A convenience function is an instance of a subclass of the
24868class @code{gdb.Function}.
24869
d812018b 24870@defun Function.__init__ (name)
bc3b79fd
TJB
24871The initializer for @code{Function} registers the new function with
24872@value{GDBN}. The argument @var{name} is the name of the function,
24873a string. The function will be visible to the user as a convenience
24874variable of type @code{internal function}, whose name is the same as
24875the given @var{name}.
24876
24877The documentation for the new function is taken from the documentation
24878string for the new class.
d812018b 24879@end defun
bc3b79fd 24880
d812018b 24881@defun Function.invoke (@var{*args})
bc3b79fd
TJB
24882When a convenience function is evaluated, its arguments are converted
24883to instances of @code{gdb.Value}, and then the function's
24884@code{invoke} method is called. Note that @value{GDBN} does not
24885predetermine the arity of convenience functions. Instead, all
24886available arguments are passed to @code{invoke}, following the
24887standard Python calling convention. In particular, a convenience
24888function can have default values for parameters without ill effect.
24889
24890The return value of this method is used as its value in the enclosing
24891expression. If an ordinary Python value is returned, it is converted
24892to a @code{gdb.Value} following the usual rules.
d812018b 24893@end defun
bc3b79fd
TJB
24894
24895The following code snippet shows how a trivial convenience function can
24896be implemented in Python:
24897
24898@smallexample
24899class Greet (gdb.Function):
24900 """Return string to greet someone.
24901Takes a name as argument."""
24902
24903 def __init__ (self):
24904 super (Greet, self).__init__ ("greet")
24905
24906 def invoke (self, name):
24907 return "Hello, %s!" % name.string ()
24908
24909Greet ()
24910@end smallexample
24911
24912The last line instantiates the class, and is necessary to trigger the
24913registration of the function with @value{GDBN}. Depending on how the
24914Python code is read into @value{GDBN}, you may need to import the
24915@code{gdb} module explicitly.
24916
dc939229
TT
24917Now you can use the function in an expression:
24918
24919@smallexample
24920(gdb) print $greet("Bob")
24921$1 = "Hello, Bob!"
24922@end smallexample
24923
fa33c3cd
DE
24924@node Progspaces In Python
24925@subsubsection Program Spaces In Python
24926
24927@cindex progspaces in python
24928@tindex gdb.Progspace
24929@tindex Progspace
24930A program space, or @dfn{progspace}, represents a symbolic view
24931of an address space.
24932It consists of all of the objfiles of the program.
24933@xref{Objfiles In Python}.
24934@xref{Inferiors and Programs, program spaces}, for more details
24935about program spaces.
24936
24937The following progspace-related functions are available in the
24938@code{gdb} module:
24939
24940@findex gdb.current_progspace
d812018b 24941@defun gdb.current_progspace ()
fa33c3cd
DE
24942This function returns the program space of the currently selected inferior.
24943@xref{Inferiors and Programs}.
24944@end defun
24945
24946@findex gdb.progspaces
d812018b 24947@defun gdb.progspaces ()
fa33c3cd
DE
24948Return a sequence of all the progspaces currently known to @value{GDBN}.
24949@end defun
24950
24951Each progspace is represented by an instance of the @code{gdb.Progspace}
24952class.
24953
d812018b 24954@defvar Progspace.filename
fa33c3cd 24955The file name of the progspace as a string.
d812018b 24956@end defvar
fa33c3cd 24957
d812018b 24958@defvar Progspace.pretty_printers
fa33c3cd
DE
24959The @code{pretty_printers} attribute is a list of functions. It is
24960used to look up pretty-printers. A @code{Value} is passed to each
24961function in order; if the function returns @code{None}, then the
24962search continues. Otherwise, the return value should be an object
4c374409 24963which is used to format the value. @xref{Pretty Printing API}, for more
fa33c3cd 24964information.
d812018b 24965@end defvar
fa33c3cd 24966
18a9fc12
TT
24967@defvar Progspace.type_printers
24968The @code{type_printers} attribute is a list of type printer objects.
24969@xref{Type Printing API}, for more information.
24970@end defvar
24971
89c73ade
TT
24972@node Objfiles In Python
24973@subsubsection Objfiles In Python
24974
24975@cindex objfiles in python
24976@tindex gdb.Objfile
24977@tindex Objfile
24978@value{GDBN} loads symbols for an inferior from various
24979symbol-containing files (@pxref{Files}). These include the primary
24980executable file, any shared libraries used by the inferior, and any
24981separate debug info files (@pxref{Separate Debug Files}).
24982@value{GDBN} calls these symbol-containing files @dfn{objfiles}.
24983
24984The following objfile-related functions are available in the
24985@code{gdb} module:
24986
24987@findex gdb.current_objfile
d812018b 24988@defun gdb.current_objfile ()
bf88dd68 24989When auto-loading a Python script (@pxref{Python Auto-loading}), @value{GDBN}
89c73ade
TT
24990sets the ``current objfile'' to the corresponding objfile. This
24991function returns the current objfile. If there is no current objfile,
24992this function returns @code{None}.
24993@end defun
24994
24995@findex gdb.objfiles
d812018b 24996@defun gdb.objfiles ()
89c73ade
TT
24997Return a sequence of all the objfiles current known to @value{GDBN}.
24998@xref{Objfiles In Python}.
24999@end defun
25000
25001Each objfile is represented by an instance of the @code{gdb.Objfile}
25002class.
25003
d812018b 25004@defvar Objfile.filename
89c73ade 25005The file name of the objfile as a string.
d812018b 25006@end defvar
89c73ade 25007
d812018b 25008@defvar Objfile.pretty_printers
89c73ade
TT
25009The @code{pretty_printers} attribute is a list of functions. It is
25010used to look up pretty-printers. A @code{Value} is passed to each
25011function in order; if the function returns @code{None}, then the
25012search continues. Otherwise, the return value should be an object
4c374409 25013which is used to format the value. @xref{Pretty Printing API}, for more
a6bac58e 25014information.
d812018b 25015@end defvar
89c73ade 25016
18a9fc12
TT
25017@defvar Objfile.type_printers
25018The @code{type_printers} attribute is a list of type printer objects.
25019@xref{Type Printing API}, for more information.
25020@end defvar
25021
29703da4
PM
25022A @code{gdb.Objfile} object has the following methods:
25023
d812018b 25024@defun Objfile.is_valid ()
29703da4
PM
25025Returns @code{True} if the @code{gdb.Objfile} object is valid,
25026@code{False} if not. A @code{gdb.Objfile} object can become invalid
25027if the object file it refers to is not loaded in @value{GDBN} any
25028longer. All other @code{gdb.Objfile} methods will throw an exception
25029if it is invalid at the time the method is called.
d812018b 25030@end defun
29703da4 25031
f8f6f20b 25032@node Frames In Python
f3e9a817 25033@subsubsection Accessing inferior stack frames from Python.
f8f6f20b
TJB
25034
25035@cindex frames in python
25036When the debugged program stops, @value{GDBN} is able to analyze its call
25037stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
25038represents a frame in the stack. A @code{gdb.Frame} object is only valid
25039while its corresponding frame exists in the inferior's stack. If you try
621c8364
TT
25040to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
25041exception (@pxref{Exception Handling}).
f8f6f20b
TJB
25042
25043Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
25044operator, like:
25045
25046@smallexample
25047(@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
25048True
25049@end smallexample
25050
25051The following frame-related functions are available in the @code{gdb} module:
25052
25053@findex gdb.selected_frame
d812018b 25054@defun gdb.selected_frame ()
f8f6f20b
TJB
25055Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
25056@end defun
25057
d8e22779 25058@findex gdb.newest_frame
d812018b 25059@defun gdb.newest_frame ()
d8e22779
TT
25060Return the newest frame object for the selected thread.
25061@end defun
25062
d812018b 25063@defun gdb.frame_stop_reason_string (reason)
f8f6f20b
TJB
25064Return a string explaining the reason why @value{GDBN} stopped unwinding
25065frames, as expressed by the given @var{reason} code (an integer, see the
25066@code{unwind_stop_reason} method further down in this section).
25067@end defun
25068
25069A @code{gdb.Frame} object has the following methods:
25070
25071@table @code
d812018b 25072@defun Frame.is_valid ()
f8f6f20b
TJB
25073Returns true if the @code{gdb.Frame} object is valid, false if not.
25074A frame object can become invalid if the frame it refers to doesn't
25075exist anymore in the inferior. All @code{gdb.Frame} methods will throw
25076an exception if it is invalid at the time the method is called.
d812018b 25077@end defun
f8f6f20b 25078
d812018b 25079@defun Frame.name ()
f8f6f20b
TJB
25080Returns the function name of the frame, or @code{None} if it can't be
25081obtained.
d812018b 25082@end defun
f8f6f20b 25083
d812018b 25084@defun Frame.type ()
ccfc3d6e
TT
25085Returns the type of the frame. The value can be one of:
25086@table @code
25087@item gdb.NORMAL_FRAME
25088An ordinary stack frame.
25089
25090@item gdb.DUMMY_FRAME
25091A fake stack frame that was created by @value{GDBN} when performing an
25092inferior function call.
25093
25094@item gdb.INLINE_FRAME
25095A frame representing an inlined function. The function was inlined
25096into a @code{gdb.NORMAL_FRAME} that is older than this one.
25097
111c6489
JK
25098@item gdb.TAILCALL_FRAME
25099A frame representing a tail call. @xref{Tail Call Frames}.
25100
ccfc3d6e
TT
25101@item gdb.SIGTRAMP_FRAME
25102A signal trampoline frame. This is the frame created by the OS when
25103it calls into a signal handler.
25104
25105@item gdb.ARCH_FRAME
25106A fake stack frame representing a cross-architecture call.
25107
25108@item gdb.SENTINEL_FRAME
25109This is like @code{gdb.NORMAL_FRAME}, but it is only used for the
25110newest frame.
25111@end table
d812018b 25112@end defun
f8f6f20b 25113
d812018b 25114@defun Frame.unwind_stop_reason ()
f8f6f20b
TJB
25115Return an integer representing the reason why it's not possible to find
25116more frames toward the outermost frame. Use
25117@code{gdb.frame_stop_reason_string} to convert the value returned by this
a7fc3f37
KP
25118function to a string. The value can be one of:
25119
25120@table @code
25121@item gdb.FRAME_UNWIND_NO_REASON
25122No particular reason (older frames should be available).
25123
25124@item gdb.FRAME_UNWIND_NULL_ID
25125The previous frame's analyzer returns an invalid result.
25126
25127@item gdb.FRAME_UNWIND_OUTERMOST
25128This frame is the outermost.
25129
25130@item gdb.FRAME_UNWIND_UNAVAILABLE
25131Cannot unwind further, because that would require knowing the
25132values of registers or memory that have not been collected.
25133
25134@item gdb.FRAME_UNWIND_INNER_ID
25135This frame ID looks like it ought to belong to a NEXT frame,
25136but we got it for a PREV frame. Normally, this is a sign of
25137unwinder failure. It could also indicate stack corruption.
25138
25139@item gdb.FRAME_UNWIND_SAME_ID
25140This frame has the same ID as the previous one. That means
25141that unwinding further would almost certainly give us another
25142frame with exactly the same ID, so break the chain. Normally,
25143this is a sign of unwinder failure. It could also indicate
25144stack corruption.
25145
25146@item gdb.FRAME_UNWIND_NO_SAVED_PC
25147The frame unwinder did not find any saved PC, but we needed
25148one to unwind further.
2231f1fb
KP
25149
25150@item gdb.FRAME_UNWIND_FIRST_ERROR
25151Any stop reason greater or equal to this value indicates some kind
25152of error. This special value facilitates writing code that tests
25153for errors in unwinding in a way that will work correctly even if
25154the list of the other values is modified in future @value{GDBN}
25155versions. Using it, you could write:
25156@smallexample
25157reason = gdb.selected_frame().unwind_stop_reason ()
25158reason_str = gdb.frame_stop_reason_string (reason)
25159if reason >= gdb.FRAME_UNWIND_FIRST_ERROR:
25160 print "An error occured: %s" % reason_str
25161@end smallexample
a7fc3f37
KP
25162@end table
25163
d812018b 25164@end defun
f8f6f20b 25165
d812018b 25166@defun Frame.pc ()
f8f6f20b 25167Returns the frame's resume address.
d812018b 25168@end defun
f8f6f20b 25169
d812018b 25170@defun Frame.block ()
f3e9a817 25171Return the frame's code block. @xref{Blocks In Python}.
d812018b 25172@end defun
f3e9a817 25173
d812018b 25174@defun Frame.function ()
f3e9a817
PM
25175Return the symbol for the function corresponding to this frame.
25176@xref{Symbols In Python}.
d812018b 25177@end defun
f3e9a817 25178
d812018b 25179@defun Frame.older ()
f8f6f20b 25180Return the frame that called this frame.
d812018b 25181@end defun
f8f6f20b 25182
d812018b 25183@defun Frame.newer ()
f8f6f20b 25184Return the frame called by this frame.
d812018b 25185@end defun
f8f6f20b 25186
d812018b 25187@defun Frame.find_sal ()
f3e9a817
PM
25188Return the frame's symtab and line object.
25189@xref{Symbol Tables In Python}.
d812018b 25190@end defun
f3e9a817 25191
d812018b 25192@defun Frame.read_var (variable @r{[}, block@r{]})
dc00d89f
PM
25193Return the value of @var{variable} in this frame. If the optional
25194argument @var{block} is provided, search for the variable from that
25195block; otherwise start at the frame's current block (which is
25196determined by the frame's current program counter). @var{variable}
25197must be a string or a @code{gdb.Symbol} object. @var{block} must be a
25198@code{gdb.Block} object.
d812018b 25199@end defun
f3e9a817 25200
d812018b 25201@defun Frame.select ()
f3e9a817
PM
25202Set this frame to be the selected frame. @xref{Stack, ,Examining the
25203Stack}.
d812018b 25204@end defun
f3e9a817
PM
25205@end table
25206
25207@node Blocks In Python
25208@subsubsection Accessing frame blocks from Python.
25209
25210@cindex blocks in python
25211@tindex gdb.Block
25212
25213Within each frame, @value{GDBN} maintains information on each block
25214stored in that frame. These blocks are organized hierarchically, and
25215are represented individually in Python as a @code{gdb.Block}.
25216Please see @ref{Frames In Python}, for a more in-depth discussion on
25217frames. Furthermore, see @ref{Stack, ,Examining the Stack}, for more
25218detailed technical information on @value{GDBN}'s book-keeping of the
25219stack.
25220
bdb1994d 25221A @code{gdb.Block} is iterable. The iterator returns the symbols
56af09aa
SCR
25222(@pxref{Symbols In Python}) local to the block. Python programs
25223should not assume that a specific block object will always contain a
25224given symbol, since changes in @value{GDBN} features and
25225infrastructure may cause symbols move across blocks in a symbol
25226table.
bdb1994d 25227
f3e9a817
PM
25228The following block-related functions are available in the @code{gdb}
25229module:
25230
25231@findex gdb.block_for_pc
d812018b 25232@defun gdb.block_for_pc (pc)
f3e9a817
PM
25233Return the @code{gdb.Block} containing the given @var{pc} value. If the
25234block cannot be found for the @var{pc} value specified, the function
25235will return @code{None}.
25236@end defun
25237
29703da4
PM
25238A @code{gdb.Block} object has the following methods:
25239
25240@table @code
d812018b 25241@defun Block.is_valid ()
29703da4
PM
25242Returns @code{True} if the @code{gdb.Block} object is valid,
25243@code{False} if not. A block object can become invalid if the block it
25244refers to doesn't exist anymore in the inferior. All other
25245@code{gdb.Block} methods will throw an exception if it is invalid at
bdb1994d
TT
25246the time the method is called. The block's validity is also checked
25247during iteration over symbols of the block.
d812018b 25248@end defun
29703da4
PM
25249@end table
25250
f3e9a817
PM
25251A @code{gdb.Block} object has the following attributes:
25252
25253@table @code
d812018b 25254@defvar Block.start
f3e9a817 25255The start address of the block. This attribute is not writable.
d812018b 25256@end defvar
f3e9a817 25257
d812018b 25258@defvar Block.end
f3e9a817 25259The end address of the block. This attribute is not writable.
d812018b 25260@end defvar
f3e9a817 25261
d812018b 25262@defvar Block.function
f3e9a817
PM
25263The name of the block represented as a @code{gdb.Symbol}. If the
25264block is not named, then this attribute holds @code{None}. This
25265attribute is not writable.
d812018b 25266@end defvar
f3e9a817 25267
d812018b 25268@defvar Block.superblock
f3e9a817
PM
25269The block containing this block. If this parent block does not exist,
25270this attribute holds @code{None}. This attribute is not writable.
d812018b 25271@end defvar
9df2fbc4
PM
25272
25273@defvar Block.global_block
25274The global block associated with this block. This attribute is not
25275writable.
25276@end defvar
25277
25278@defvar Block.static_block
25279The static block associated with this block. This attribute is not
25280writable.
25281@end defvar
25282
25283@defvar Block.is_global
25284@code{True} if the @code{gdb.Block} object is a global block,
25285@code{False} if not. This attribute is not
25286writable.
25287@end defvar
25288
25289@defvar Block.is_static
25290@code{True} if the @code{gdb.Block} object is a static block,
25291@code{False} if not. This attribute is not writable.
25292@end defvar
f3e9a817
PM
25293@end table
25294
25295@node Symbols In Python
25296@subsubsection Python representation of Symbols.
25297
25298@cindex symbols in python
25299@tindex gdb.Symbol
25300
25301@value{GDBN} represents every variable, function and type as an
25302entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
25303Similarly, Python represents these symbols in @value{GDBN} with the
25304@code{gdb.Symbol} object.
25305
25306The following symbol-related functions are available in the @code{gdb}
25307module:
25308
25309@findex gdb.lookup_symbol
d812018b 25310@defun gdb.lookup_symbol (name @r{[}, block @r{[}, domain@r{]]})
f3e9a817
PM
25311This function searches for a symbol by name. The search scope can be
25312restricted to the parameters defined in the optional domain and block
25313arguments.
25314
25315@var{name} is the name of the symbol. It must be a string. The
25316optional @var{block} argument restricts the search to symbols visible
25317in that @var{block}. The @var{block} argument must be a
6e6fbe60
DE
25318@code{gdb.Block} object. If omitted, the block for the current frame
25319is used. The optional @var{domain} argument restricts
f3e9a817
PM
25320the search to the domain type. The @var{domain} argument must be a
25321domain constant defined in the @code{gdb} module and described later
25322in this chapter.
6e6fbe60
DE
25323
25324The result is a tuple of two elements.
25325The first element is a @code{gdb.Symbol} object or @code{None} if the symbol
25326is not found.
25327If the symbol is found, the second element is @code{True} if the symbol
82809774 25328is a field of a method's object (e.g., @code{this} in C@t{++}),
6e6fbe60
DE
25329otherwise it is @code{False}.
25330If the symbol is not found, the second element is @code{False}.
25331@end defun
25332
25333@findex gdb.lookup_global_symbol
d812018b 25334@defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
6e6fbe60
DE
25335This function searches for a global symbol by name.
25336The search scope can be restricted to by the domain argument.
25337
25338@var{name} is the name of the symbol. It must be a string.
25339The optional @var{domain} argument restricts the search to the domain type.
25340The @var{domain} argument must be a domain constant defined in the @code{gdb}
25341module and described later in this chapter.
25342
25343The result is a @code{gdb.Symbol} object or @code{None} if the symbol
25344is not found.
f3e9a817
PM
25345@end defun
25346
25347A @code{gdb.Symbol} object has the following attributes:
25348
25349@table @code
d812018b 25350@defvar Symbol.type
457e09f0
DE
25351The type of the symbol or @code{None} if no type is recorded.
25352This attribute is represented as a @code{gdb.Type} object.
25353@xref{Types In Python}. This attribute is not writable.
d812018b 25354@end defvar
457e09f0 25355
d812018b 25356@defvar Symbol.symtab
f3e9a817
PM
25357The symbol table in which the symbol appears. This attribute is
25358represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
25359Python}. This attribute is not writable.
d812018b 25360@end defvar
f3e9a817 25361
64e7d9dd
TT
25362@defvar Symbol.line
25363The line number in the source code at which the symbol was defined.
25364This is an integer.
25365@end defvar
25366
d812018b 25367@defvar Symbol.name
f3e9a817 25368The name of the symbol as a string. This attribute is not writable.
d812018b 25369@end defvar
f3e9a817 25370
d812018b 25371@defvar Symbol.linkage_name
f3e9a817
PM
25372The name of the symbol, as used by the linker (i.e., may be mangled).
25373This attribute is not writable.
d812018b 25374@end defvar
f3e9a817 25375
d812018b 25376@defvar Symbol.print_name
f3e9a817
PM
25377The name of the symbol in a form suitable for output. This is either
25378@code{name} or @code{linkage_name}, depending on whether the user
25379asked @value{GDBN} to display demangled or mangled names.
d812018b 25380@end defvar
f3e9a817 25381
d812018b 25382@defvar Symbol.addr_class
f3e9a817
PM
25383The address class of the symbol. This classifies how to find the value
25384of a symbol. Each address class is a constant defined in the
25385@code{gdb} module and described later in this chapter.
d812018b 25386@end defvar
f3e9a817 25387
f0823d2c
TT
25388@defvar Symbol.needs_frame
25389This is @code{True} if evaluating this symbol's value requires a frame
25390(@pxref{Frames In Python}) and @code{False} otherwise. Typically,
25391local variables will require a frame, but other symbols will not.
035d1e5b 25392@end defvar
f0823d2c 25393
d812018b 25394@defvar Symbol.is_argument
f3e9a817 25395@code{True} if the symbol is an argument of a function.
d812018b 25396@end defvar
f3e9a817 25397
d812018b 25398@defvar Symbol.is_constant
f3e9a817 25399@code{True} if the symbol is a constant.
d812018b 25400@end defvar
f3e9a817 25401
d812018b 25402@defvar Symbol.is_function
f3e9a817 25403@code{True} if the symbol is a function or a method.
d812018b 25404@end defvar
f3e9a817 25405
d812018b 25406@defvar Symbol.is_variable
f3e9a817 25407@code{True} if the symbol is a variable.
d812018b 25408@end defvar
f3e9a817
PM
25409@end table
25410
29703da4
PM
25411A @code{gdb.Symbol} object has the following methods:
25412
25413@table @code
d812018b 25414@defun Symbol.is_valid ()
29703da4
PM
25415Returns @code{True} if the @code{gdb.Symbol} object is valid,
25416@code{False} if not. A @code{gdb.Symbol} object can become invalid if
25417the symbol it refers to does not exist in @value{GDBN} any longer.
25418All other @code{gdb.Symbol} methods will throw an exception if it is
25419invalid at the time the method is called.
d812018b 25420@end defun
f0823d2c
TT
25421
25422@defun Symbol.value (@r{[}frame@r{]})
25423Compute the value of the symbol, as a @code{gdb.Value}. For
25424functions, this computes the address of the function, cast to the
25425appropriate type. If the symbol requires a frame in order to compute
25426its value, then @var{frame} must be given. If @var{frame} is not
25427given, or if @var{frame} is invalid, then this method will throw an
25428exception.
25429@end defun
29703da4
PM
25430@end table
25431
f3e9a817
PM
25432The available domain categories in @code{gdb.Symbol} are represented
25433as constants in the @code{gdb} module:
25434
25435@table @code
25436@findex SYMBOL_UNDEF_DOMAIN
25437@findex gdb.SYMBOL_UNDEF_DOMAIN
d812018b 25438@item gdb.SYMBOL_UNDEF_DOMAIN
f3e9a817
PM
25439This is used when a domain has not been discovered or none of the
25440following domains apply. This usually indicates an error either
25441in the symbol information or in @value{GDBN}'s handling of symbols.
25442@findex SYMBOL_VAR_DOMAIN
25443@findex gdb.SYMBOL_VAR_DOMAIN
d812018b 25444@item gdb.SYMBOL_VAR_DOMAIN
f3e9a817
PM
25445This domain contains variables, function names, typedef names and enum
25446type values.
25447@findex SYMBOL_STRUCT_DOMAIN
25448@findex gdb.SYMBOL_STRUCT_DOMAIN
d812018b 25449@item gdb.SYMBOL_STRUCT_DOMAIN
f3e9a817
PM
25450This domain holds struct, union and enum type names.
25451@findex SYMBOL_LABEL_DOMAIN
25452@findex gdb.SYMBOL_LABEL_DOMAIN
d812018b 25453@item gdb.SYMBOL_LABEL_DOMAIN
f3e9a817
PM
25454This domain contains names of labels (for gotos).
25455@findex SYMBOL_VARIABLES_DOMAIN
25456@findex gdb.SYMBOL_VARIABLES_DOMAIN
d812018b 25457@item gdb.SYMBOL_VARIABLES_DOMAIN
f3e9a817
PM
25458This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
25459contains everything minus functions and types.
25460@findex SYMBOL_FUNCTIONS_DOMAIN
25461@findex gdb.SYMBOL_FUNCTIONS_DOMAIN
d812018b 25462@item gdb.SYMBOL_FUNCTION_DOMAIN
f3e9a817
PM
25463This domain contains all functions.
25464@findex SYMBOL_TYPES_DOMAIN
25465@findex gdb.SYMBOL_TYPES_DOMAIN
d812018b 25466@item gdb.SYMBOL_TYPES_DOMAIN
f3e9a817
PM
25467This domain contains all types.
25468@end table
25469
25470The available address class categories in @code{gdb.Symbol} are represented
25471as constants in the @code{gdb} module:
25472
25473@table @code
25474@findex SYMBOL_LOC_UNDEF
25475@findex gdb.SYMBOL_LOC_UNDEF
d812018b 25476@item gdb.SYMBOL_LOC_UNDEF
f3e9a817
PM
25477If this is returned by address class, it indicates an error either in
25478the symbol information or in @value{GDBN}'s handling of symbols.
25479@findex SYMBOL_LOC_CONST
25480@findex gdb.SYMBOL_LOC_CONST
d812018b 25481@item gdb.SYMBOL_LOC_CONST
f3e9a817
PM
25482Value is constant int.
25483@findex SYMBOL_LOC_STATIC
25484@findex gdb.SYMBOL_LOC_STATIC
d812018b 25485@item gdb.SYMBOL_LOC_STATIC
f3e9a817
PM
25486Value is at a fixed address.
25487@findex SYMBOL_LOC_REGISTER
25488@findex gdb.SYMBOL_LOC_REGISTER
d812018b 25489@item gdb.SYMBOL_LOC_REGISTER
f3e9a817
PM
25490Value is in a register.
25491@findex SYMBOL_LOC_ARG
25492@findex gdb.SYMBOL_LOC_ARG
d812018b 25493@item gdb.SYMBOL_LOC_ARG
f3e9a817
PM
25494Value is an argument. This value is at the offset stored within the
25495symbol inside the frame's argument list.
25496@findex SYMBOL_LOC_REF_ARG
25497@findex gdb.SYMBOL_LOC_REF_ARG
d812018b 25498@item gdb.SYMBOL_LOC_REF_ARG
f3e9a817
PM
25499Value address is stored in the frame's argument list. Just like
25500@code{LOC_ARG} except that the value's address is stored at the
25501offset, not the value itself.
25502@findex SYMBOL_LOC_REGPARM_ADDR
25503@findex gdb.SYMBOL_LOC_REGPARM_ADDR
d812018b 25504@item gdb.SYMBOL_LOC_REGPARM_ADDR
f3e9a817
PM
25505Value is a specified register. Just like @code{LOC_REGISTER} except
25506the register holds the address of the argument instead of the argument
25507itself.
25508@findex SYMBOL_LOC_LOCAL
25509@findex gdb.SYMBOL_LOC_LOCAL
d812018b 25510@item gdb.SYMBOL_LOC_LOCAL
f3e9a817
PM
25511Value is a local variable.
25512@findex SYMBOL_LOC_TYPEDEF
25513@findex gdb.SYMBOL_LOC_TYPEDEF
d812018b 25514@item gdb.SYMBOL_LOC_TYPEDEF
f3e9a817
PM
25515Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
25516have this class.
25517@findex SYMBOL_LOC_BLOCK
25518@findex gdb.SYMBOL_LOC_BLOCK
d812018b 25519@item gdb.SYMBOL_LOC_BLOCK
f3e9a817
PM
25520Value is a block.
25521@findex SYMBOL_LOC_CONST_BYTES
25522@findex gdb.SYMBOL_LOC_CONST_BYTES
d812018b 25523@item gdb.SYMBOL_LOC_CONST_BYTES
f3e9a817
PM
25524Value is a byte-sequence.
25525@findex SYMBOL_LOC_UNRESOLVED
25526@findex gdb.SYMBOL_LOC_UNRESOLVED
d812018b 25527@item gdb.SYMBOL_LOC_UNRESOLVED
f3e9a817
PM
25528Value is at a fixed address, but the address of the variable has to be
25529determined from the minimal symbol table whenever the variable is
25530referenced.
25531@findex SYMBOL_LOC_OPTIMIZED_OUT
25532@findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
d812018b 25533@item gdb.SYMBOL_LOC_OPTIMIZED_OUT
f3e9a817
PM
25534The value does not actually exist in the program.
25535@findex SYMBOL_LOC_COMPUTED
25536@findex gdb.SYMBOL_LOC_COMPUTED
d812018b 25537@item gdb.SYMBOL_LOC_COMPUTED
f3e9a817
PM
25538The value's address is a computed location.
25539@end table
25540
25541@node Symbol Tables In Python
25542@subsubsection Symbol table representation in Python.
25543
25544@cindex symbol tables in python
25545@tindex gdb.Symtab
25546@tindex gdb.Symtab_and_line
25547
25548Access to symbol table data maintained by @value{GDBN} on the inferior
25549is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
25550@code{gdb.Symtab}. Symbol table and line data for a frame is returned
25551from the @code{find_sal} method in @code{gdb.Frame} object.
25552@xref{Frames In Python}.
25553
25554For more information on @value{GDBN}'s symbol table management, see
25555@ref{Symbols, ,Examining the Symbol Table}, for more information.
25556
25557A @code{gdb.Symtab_and_line} object has the following attributes:
25558
25559@table @code
d812018b 25560@defvar Symtab_and_line.symtab
f3e9a817
PM
25561The symbol table object (@code{gdb.Symtab}) for this frame.
25562This attribute is not writable.
d812018b 25563@end defvar
f3e9a817 25564
d812018b 25565@defvar Symtab_and_line.pc
3c15d565
SCR
25566Indicates the start of the address range occupied by code for the
25567current source line. This attribute is not writable.
d812018b 25568@end defvar
f3e9a817 25569
ee0bf529
SCR
25570@defvar Symtab_and_line.last
25571Indicates the end of the address range occupied by code for the current
25572source line. This attribute is not writable.
25573@end defvar
25574
d812018b 25575@defvar Symtab_and_line.line
f3e9a817
PM
25576Indicates the current line number for this object. This
25577attribute is not writable.
d812018b 25578@end defvar
f3e9a817
PM
25579@end table
25580
29703da4
PM
25581A @code{gdb.Symtab_and_line} object has the following methods:
25582
25583@table @code
d812018b 25584@defun Symtab_and_line.is_valid ()
29703da4
PM
25585Returns @code{True} if the @code{gdb.Symtab_and_line} object is valid,
25586@code{False} if not. A @code{gdb.Symtab_and_line} object can become
25587invalid if the Symbol table and line object it refers to does not
25588exist in @value{GDBN} any longer. All other
25589@code{gdb.Symtab_and_line} methods will throw an exception if it is
25590invalid at the time the method is called.
d812018b 25591@end defun
29703da4
PM
25592@end table
25593
f3e9a817
PM
25594A @code{gdb.Symtab} object has the following attributes:
25595
25596@table @code
d812018b 25597@defvar Symtab.filename
f3e9a817 25598The symbol table's source filename. This attribute is not writable.
d812018b 25599@end defvar
f3e9a817 25600
d812018b 25601@defvar Symtab.objfile
f3e9a817
PM
25602The symbol table's backing object file. @xref{Objfiles In Python}.
25603This attribute is not writable.
d812018b 25604@end defvar
f3e9a817
PM
25605@end table
25606
29703da4 25607A @code{gdb.Symtab} object has the following methods:
f3e9a817
PM
25608
25609@table @code
d812018b 25610@defun Symtab.is_valid ()
29703da4
PM
25611Returns @code{True} if the @code{gdb.Symtab} object is valid,
25612@code{False} if not. A @code{gdb.Symtab} object can become invalid if
25613the symbol table it refers to does not exist in @value{GDBN} any
25614longer. All other @code{gdb.Symtab} methods will throw an exception
25615if it is invalid at the time the method is called.
d812018b 25616@end defun
29703da4 25617
d812018b 25618@defun Symtab.fullname ()
f3e9a817 25619Return the symbol table's source absolute file name.
d812018b 25620@end defun
a20ee7a4
SCR
25621
25622@defun Symtab.global_block ()
25623Return the global block of the underlying symbol table.
25624@xref{Blocks In Python}.
25625@end defun
25626
25627@defun Symtab.static_block ()
25628Return the static block of the underlying symbol table.
25629@xref{Blocks In Python}.
25630@end defun
f8f6f20b
TJB
25631@end table
25632
adc36818
PM
25633@node Breakpoints In Python
25634@subsubsection Manipulating breakpoints using Python
25635
25636@cindex breakpoints in python
25637@tindex gdb.Breakpoint
25638
25639Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
25640class.
25641
d812018b 25642@defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
adc36818
PM
25643Create a new breakpoint. @var{spec} is a string naming the
25644location of the breakpoint, or an expression that defines a
25645watchpoint. The contents can be any location recognized by the
25646@code{break} command, or in the case of a watchpoint, by the @code{watch}
25647command. The optional @var{type} denotes the breakpoint to create
25648from the types defined later in this chapter. This argument can be
d812018b
PK
25649either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}. @var{type}
25650defaults to @code{gdb.BP_BREAKPOINT}. The optional @var{internal} argument
84f4c1fe
PM
25651allows the breakpoint to become invisible to the user. The breakpoint
25652will neither be reported when created, nor will it be listed in the
25653output from @code{info breakpoints} (but will be listed with the
25654@code{maint info breakpoints} command). The optional @var{wp_class}
adc36818 25655argument defines the class of watchpoint to create, if @var{type} is
d812018b
PK
25656@code{gdb.BP_WATCHPOINT}. If a watchpoint class is not provided, it is
25657assumed to be a @code{gdb.WP_WRITE} class.
25658@end defun
adc36818 25659
d812018b 25660@defun Breakpoint.stop (self)
7371cf6d
PM
25661The @code{gdb.Breakpoint} class can be sub-classed and, in
25662particular, you may choose to implement the @code{stop} method.
25663If this method is defined as a sub-class of @code{gdb.Breakpoint},
25664it will be called when the inferior reaches any location of a
25665breakpoint which instantiates that sub-class. If the method returns
25666@code{True}, the inferior will be stopped at the location of the
25667breakpoint, otherwise the inferior will continue.
25668
25669If there are multiple breakpoints at the same location with a
25670@code{stop} method, each one will be called regardless of the
25671return status of the previous. This ensures that all @code{stop}
25672methods have a chance to execute at that location. In this scenario
25673if one of the methods returns @code{True} but the others return
25674@code{False}, the inferior will still be stopped.
25675
99f5279d
PM
25676You should not alter the execution state of the inferior (i.e.@:, step,
25677next, etc.), alter the current frame context (i.e.@:, change the current
25678active frame), or alter, add or delete any breakpoint. As a general
25679rule, you should not alter any data within @value{GDBN} or the inferior
25680at this time.
25681
7371cf6d
PM
25682Example @code{stop} implementation:
25683
25684@smallexample
25685class MyBreakpoint (gdb.Breakpoint):
25686 def stop (self):
25687 inf_val = gdb.parse_and_eval("foo")
25688 if inf_val == 3:
25689 return True
25690 return False
25691@end smallexample
d812018b 25692@end defun
7371cf6d 25693
adc36818
PM
25694The available watchpoint types represented by constants are defined in the
25695@code{gdb} module:
25696
25697@table @code
25698@findex WP_READ
25699@findex gdb.WP_READ
d812018b 25700@item gdb.WP_READ
adc36818
PM
25701Read only watchpoint.
25702
25703@findex WP_WRITE
25704@findex gdb.WP_WRITE
d812018b 25705@item gdb.WP_WRITE
adc36818
PM
25706Write only watchpoint.
25707
25708@findex WP_ACCESS
25709@findex gdb.WP_ACCESS
d812018b 25710@item gdb.WP_ACCESS
adc36818
PM
25711Read/Write watchpoint.
25712@end table
25713
d812018b 25714@defun Breakpoint.is_valid ()
adc36818
PM
25715Return @code{True} if this @code{Breakpoint} object is valid,
25716@code{False} otherwise. A @code{Breakpoint} object can become invalid
25717if the user deletes the breakpoint. In this case, the object still
25718exists, but the underlying breakpoint does not. In the cases of
25719watchpoint scope, the watchpoint remains valid even if execution of the
25720inferior leaves the scope of that watchpoint.
d812018b 25721@end defun
adc36818 25722
d812018b 25723@defun Breakpoint.delete
94b6973e
PM
25724Permanently deletes the @value{GDBN} breakpoint. This also
25725invalidates the Python @code{Breakpoint} object. Any further access
25726to this object's attributes or methods will raise an error.
d812018b 25727@end defun
94b6973e 25728
d812018b 25729@defvar Breakpoint.enabled
adc36818
PM
25730This attribute is @code{True} if the breakpoint is enabled, and
25731@code{False} otherwise. This attribute is writable.
d812018b 25732@end defvar
adc36818 25733
d812018b 25734@defvar Breakpoint.silent
adc36818
PM
25735This attribute is @code{True} if the breakpoint is silent, and
25736@code{False} otherwise. This attribute is writable.
25737
25738Note that a breakpoint can also be silent if it has commands and the
25739first command is @code{silent}. This is not reported by the
25740@code{silent} attribute.
d812018b 25741@end defvar
adc36818 25742
d812018b 25743@defvar Breakpoint.thread
adc36818
PM
25744If the breakpoint is thread-specific, this attribute holds the thread
25745id. If the breakpoint is not thread-specific, this attribute is
25746@code{None}. This attribute is writable.
d812018b 25747@end defvar
adc36818 25748
d812018b 25749@defvar Breakpoint.task
adc36818
PM
25750If the breakpoint is Ada task-specific, this attribute holds the Ada task
25751id. If the breakpoint is not task-specific (or the underlying
25752language is not Ada), this attribute is @code{None}. This attribute
25753is writable.
d812018b 25754@end defvar
adc36818 25755
d812018b 25756@defvar Breakpoint.ignore_count
adc36818
PM
25757This attribute holds the ignore count for the breakpoint, an integer.
25758This attribute is writable.
d812018b 25759@end defvar
adc36818 25760
d812018b 25761@defvar Breakpoint.number
adc36818
PM
25762This attribute holds the breakpoint's number --- the identifier used by
25763the user to manipulate the breakpoint. This attribute is not writable.
d812018b 25764@end defvar
adc36818 25765
d812018b 25766@defvar Breakpoint.type
adc36818
PM
25767This attribute holds the breakpoint's type --- the identifier used to
25768determine the actual breakpoint type or use-case. This attribute is not
25769writable.
d812018b 25770@end defvar
adc36818 25771
d812018b 25772@defvar Breakpoint.visible
84f4c1fe
PM
25773This attribute tells whether the breakpoint is visible to the user
25774when set, or when the @samp{info breakpoints} command is run. This
25775attribute is not writable.
d812018b 25776@end defvar
84f4c1fe 25777
adc36818
PM
25778The available types are represented by constants defined in the @code{gdb}
25779module:
25780
25781@table @code
25782@findex BP_BREAKPOINT
25783@findex gdb.BP_BREAKPOINT
d812018b 25784@item gdb.BP_BREAKPOINT
adc36818
PM
25785Normal code breakpoint.
25786
25787@findex BP_WATCHPOINT
25788@findex gdb.BP_WATCHPOINT
d812018b 25789@item gdb.BP_WATCHPOINT
adc36818
PM
25790Watchpoint breakpoint.
25791
25792@findex BP_HARDWARE_WATCHPOINT
25793@findex gdb.BP_HARDWARE_WATCHPOINT
d812018b 25794@item gdb.BP_HARDWARE_WATCHPOINT
adc36818
PM
25795Hardware assisted watchpoint.
25796
25797@findex BP_READ_WATCHPOINT
25798@findex gdb.BP_READ_WATCHPOINT
d812018b 25799@item gdb.BP_READ_WATCHPOINT
adc36818
PM
25800Hardware assisted read watchpoint.
25801
25802@findex BP_ACCESS_WATCHPOINT
25803@findex gdb.BP_ACCESS_WATCHPOINT
d812018b 25804@item gdb.BP_ACCESS_WATCHPOINT
adc36818
PM
25805Hardware assisted access watchpoint.
25806@end table
25807
d812018b 25808@defvar Breakpoint.hit_count
adc36818
PM
25809This attribute holds the hit count for the breakpoint, an integer.
25810This attribute is writable, but currently it can only be set to zero.
d812018b 25811@end defvar
adc36818 25812
d812018b 25813@defvar Breakpoint.location
adc36818
PM
25814This attribute holds the location of the breakpoint, as specified by
25815the user. It is a string. If the breakpoint does not have a location
25816(that is, it is a watchpoint) the attribute's value is @code{None}. This
25817attribute is not writable.
d812018b 25818@end defvar
adc36818 25819
d812018b 25820@defvar Breakpoint.expression
adc36818
PM
25821This attribute holds a breakpoint expression, as specified by
25822the user. It is a string. If the breakpoint does not have an
25823expression (the breakpoint is not a watchpoint) the attribute's value
25824is @code{None}. This attribute is not writable.
d812018b 25825@end defvar
adc36818 25826
d812018b 25827@defvar Breakpoint.condition
adc36818
PM
25828This attribute holds the condition of the breakpoint, as specified by
25829the user. It is a string. If there is no condition, this attribute's
25830value is @code{None}. This attribute is writable.
d812018b 25831@end defvar
adc36818 25832
d812018b 25833@defvar Breakpoint.commands
adc36818
PM
25834This attribute holds the commands attached to the breakpoint. If
25835there are commands, this attribute's value is a string holding all the
25836commands, separated by newlines. If there are no commands, this
25837attribute is @code{None}. This attribute is not writable.
d812018b 25838@end defvar
adc36818 25839
cc72b2a2
KP
25840@node Finish Breakpoints in Python
25841@subsubsection Finish Breakpoints
25842
25843@cindex python finish breakpoints
25844@tindex gdb.FinishBreakpoint
25845
25846A finish breakpoint is a temporary breakpoint set at the return address of
25847a frame, based on the @code{finish} command. @code{gdb.FinishBreakpoint}
25848extends @code{gdb.Breakpoint}. The underlying breakpoint will be disabled
25849and deleted when the execution will run out of the breakpoint scope (i.e.@:
25850@code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
25851Finish breakpoints are thread specific and must be create with the right
25852thread selected.
25853
25854@defun FinishBreakpoint.__init__ (@r{[}frame@r{]} @r{[}, internal@r{]})
25855Create a finish breakpoint at the return address of the @code{gdb.Frame}
25856object @var{frame}. If @var{frame} is not provided, this defaults to the
25857newest frame. The optional @var{internal} argument allows the breakpoint to
25858become invisible to the user. @xref{Breakpoints In Python}, for further
25859details about this argument.
25860@end defun
25861
25862@defun FinishBreakpoint.out_of_scope (self)
25863In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN}
25864@code{return} command, @dots{}), a function may not properly terminate, and
25865thus never hit the finish breakpoint. When @value{GDBN} notices such a
25866situation, the @code{out_of_scope} callback will be triggered.
25867
25868You may want to sub-class @code{gdb.FinishBreakpoint} and override this
25869method:
25870
25871@smallexample
25872class MyFinishBreakpoint (gdb.FinishBreakpoint)
25873 def stop (self):
25874 print "normal finish"
25875 return True
25876
25877 def out_of_scope ():
25878 print "abnormal finish"
25879@end smallexample
25880@end defun
25881
25882@defvar FinishBreakpoint.return_value
25883When @value{GDBN} is stopped at a finish breakpoint and the frame
25884used to build the @code{gdb.FinishBreakpoint} object had debug symbols, this
25885attribute will contain a @code{gdb.Value} object corresponding to the return
25886value of the function. The value will be @code{None} if the function return
25887type is @code{void} or if the return value was not computable. This attribute
25888is not writable.
25889@end defvar
25890
be759fcf
PM
25891@node Lazy Strings In Python
25892@subsubsection Python representation of lazy strings.
25893
25894@cindex lazy strings in python
25895@tindex gdb.LazyString
25896
25897A @dfn{lazy string} is a string whose contents is not retrieved or
25898encoded until it is needed.
25899
25900A @code{gdb.LazyString} is represented in @value{GDBN} as an
25901@code{address} that points to a region of memory, an @code{encoding}
25902that will be used to encode that region of memory, and a @code{length}
25903to delimit the region of memory that represents the string. The
25904difference between a @code{gdb.LazyString} and a string wrapped within
25905a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
25906differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
25907retrieved and encoded during printing, while a @code{gdb.Value}
25908wrapping a string is immediately retrieved and encoded on creation.
25909
25910A @code{gdb.LazyString} object has the following functions:
25911
d812018b 25912@defun LazyString.value ()
be759fcf
PM
25913Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
25914will point to the string in memory, but will lose all the delayed
25915retrieval, encoding and handling that @value{GDBN} applies to a
25916@code{gdb.LazyString}.
d812018b 25917@end defun
be759fcf 25918
d812018b 25919@defvar LazyString.address
be759fcf
PM
25920This attribute holds the address of the string. This attribute is not
25921writable.
d812018b 25922@end defvar
be759fcf 25923
d812018b 25924@defvar LazyString.length
be759fcf
PM
25925This attribute holds the length of the string in characters. If the
25926length is -1, then the string will be fetched and encoded up to the
25927first null of appropriate width. This attribute is not writable.
d812018b 25928@end defvar
be759fcf 25929
d812018b 25930@defvar LazyString.encoding
be759fcf
PM
25931This attribute holds the encoding that will be applied to the string
25932when the string is printed by @value{GDBN}. If the encoding is not
25933set, or contains an empty string, then @value{GDBN} will select the
25934most appropriate encoding when the string is printed. This attribute
25935is not writable.
d812018b 25936@end defvar
be759fcf 25937
d812018b 25938@defvar LazyString.type
be759fcf
PM
25939This attribute holds the type that is represented by the lazy string's
25940type. For a lazy string this will always be a pointer type. To
25941resolve this to the lazy string's character type, use the type's
25942@code{target} method. @xref{Types In Python}. This attribute is not
25943writable.
d812018b 25944@end defvar
be759fcf 25945
bf88dd68
JK
25946@node Python Auto-loading
25947@subsection Python Auto-loading
25948@cindex Python auto-loading
8a1ea21f
DE
25949
25950When a new object file is read (for example, due to the @code{file}
25951command, or because the inferior has loaded a shared library),
25952@value{GDBN} will look for Python support scripts in several ways:
3708f05e
JK
25953@file{@var{objfile}-gdb.py} (@pxref{objfile-gdb.py file})
25954and @code{.debug_gdb_scripts} section
25955(@pxref{dotdebug_gdb_scripts section}).
8a1ea21f
DE
25956
25957The auto-loading feature is useful for supplying application-specific
25958debugging commands and scripts.
25959
dbaefcf7
DE
25960Auto-loading can be enabled or disabled,
25961and the list of auto-loaded scripts can be printed.
8a1ea21f
DE
25962
25963@table @code
bf88dd68
JK
25964@anchor{set auto-load python-scripts}
25965@kindex set auto-load python-scripts
25966@item set auto-load python-scripts [on|off]
a86caf66 25967Enable or disable the auto-loading of Python scripts.
8a1ea21f 25968
bf88dd68
JK
25969@anchor{show auto-load python-scripts}
25970@kindex show auto-load python-scripts
25971@item show auto-load python-scripts
a86caf66 25972Show whether auto-loading of Python scripts is enabled or disabled.
dbaefcf7 25973
bf88dd68
JK
25974@anchor{info auto-load python-scripts}
25975@kindex info auto-load python-scripts
25976@cindex print list of auto-loaded Python scripts
25977@item info auto-load python-scripts [@var{regexp}]
25978Print the list of all Python scripts that @value{GDBN} auto-loaded.
75fc9810 25979
bf88dd68 25980Also printed is the list of Python scripts that were mentioned in
75fc9810 25981the @code{.debug_gdb_scripts} section and were not found
8e0583c8 25982(@pxref{dotdebug_gdb_scripts section}).
75fc9810
DE
25983This is useful because their names are not printed when @value{GDBN}
25984tries to load them and fails. There may be many of them, and printing
25985an error message for each one is problematic.
25986
bf88dd68 25987If @var{regexp} is supplied only Python scripts with matching names are printed.
dbaefcf7 25988
75fc9810
DE
25989Example:
25990
dbaefcf7 25991@smallexample
bf88dd68 25992(gdb) info auto-load python-scripts
bccbefd2
JK
25993Loaded Script
25994Yes py-section-script.py
25995 full name: /tmp/py-section-script.py
25996No my-foo-pretty-printers.py
dbaefcf7 25997@end smallexample
8a1ea21f
DE
25998@end table
25999
26000When reading an auto-loaded file, @value{GDBN} sets the
26001@dfn{current objfile}. This is available via the @code{gdb.current_objfile}
26002function (@pxref{Objfiles In Python}). This can be useful for
26003registering objfile-specific pretty-printers.
26004
3708f05e
JK
26005@menu
26006* objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
26007* dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
26008* Which flavor to choose?::
26009@end menu
26010
8a1ea21f
DE
26011@node objfile-gdb.py file
26012@subsubsection The @file{@var{objfile}-gdb.py} file
26013@cindex @file{@var{objfile}-gdb.py}
26014
26015When a new object file is read, @value{GDBN} looks for
7349ff92 26016a file named @file{@var{objfile}-gdb.py} (we call it @var{script-name} below),
8a1ea21f
DE
26017where @var{objfile} is the object file's real name, formed by ensuring
26018that the file name is absolute, following all symlinks, and resolving
26019@code{.} and @code{..} components. If this file exists and is
26020readable, @value{GDBN} will evaluate it as a Python script.
26021
1564a261 26022If this file does not exist, then @value{GDBN} will look for
c1668e4e
JK
26023@var{script-name} file in all of the directories as specified below.
26024
26025Note that loading of this script file also requires accordingly configured
26026@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
7349ff92 26027
e9687799
JK
26028For object files using @file{.exe} suffix @value{GDBN} tries to load first the
26029scripts normally according to its @file{.exe} filename. But if no scripts are
26030found @value{GDBN} also tries script filenames matching the object file without
26031its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
26032is attempted on any platform. This makes the script filenames compatible
26033between Unix and MS-Windows hosts.
26034
7349ff92
JK
26035@table @code
26036@anchor{set auto-load scripts-directory}
26037@kindex set auto-load scripts-directory
26038@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
26039Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
26040may be delimited by the host platform path separator in use
26041(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
26042
26043Each entry here needs to be covered also by the security setting
26044@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
26045
26046@anchor{with-auto-load-dir}
1564a261
JK
26047This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
26048@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
26049configuration option @option{--with-auto-load-dir}.
26050
26051Any reference to @file{$debugdir} will get replaced by
26052@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
26053reference to @file{$datadir} will get replaced by @var{data-directory} which is
26054determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
26055@file{$datadir} must be placed as a directory component --- either alone or
26056delimited by @file{/} or @file{\} directory separators, depending on the host
26057platform.
7349ff92
JK
26058
26059The list of directories uses path separator (@samp{:} on GNU and Unix
26060systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26061to the @env{PATH} environment variable.
26062
26063@anchor{show auto-load scripts-directory}
26064@kindex show auto-load scripts-directory
26065@item show auto-load scripts-directory
26066Show @value{GDBN} auto-loaded scripts location.
26067@end table
8a1ea21f
DE
26068
26069@value{GDBN} does not track which files it has already auto-loaded this way.
26070@value{GDBN} will load the associated script every time the corresponding
26071@var{objfile} is opened.
26072So your @file{-gdb.py} file should be careful to avoid errors if it
26073is evaluated more than once.
26074
8e0583c8 26075@node dotdebug_gdb_scripts section
8a1ea21f
DE
26076@subsubsection The @code{.debug_gdb_scripts} section
26077@cindex @code{.debug_gdb_scripts} section
26078
26079For systems using file formats like ELF and COFF,
26080when @value{GDBN} loads a new object file
26081it will look for a special section named @samp{.debug_gdb_scripts}.
26082If this section exists, its contents is a list of names of scripts to load.
26083
26084@value{GDBN} will look for each specified script file first in the
26085current directory and then along the source search path
26086(@pxref{Source Path, ,Specifying Source Directories}),
26087except that @file{$cdir} is not searched, since the compilation
26088directory is not relevant to scripts.
26089
26090Entries can be placed in section @code{.debug_gdb_scripts} with,
26091for example, this GCC macro:
26092
26093@example
a3a7127e 26094/* Note: The "MS" section flags are to remove duplicates. */
8a1ea21f
DE
26095#define DEFINE_GDB_SCRIPT(script_name) \
26096 asm("\
26097.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
26098.byte 1\n\
26099.asciz \"" script_name "\"\n\
26100.popsection \n\
26101");
26102@end example
26103
26104@noindent
26105Then one can reference the macro in a header or source file like this:
26106
26107@example
26108DEFINE_GDB_SCRIPT ("my-app-scripts.py")
26109@end example
26110
26111The script name may include directories if desired.
26112
c1668e4e
JK
26113Note that loading of this script file also requires accordingly configured
26114@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26115
8a1ea21f
DE
26116If the macro is put in a header, any application or library
26117using this header will get a reference to the specified script.
26118
26119@node Which flavor to choose?
26120@subsubsection Which flavor to choose?
26121
26122Given the multiple ways of auto-loading Python scripts, it might not always
26123be clear which one to choose. This section provides some guidance.
26124
26125Benefits of the @file{-gdb.py} way:
26126
26127@itemize @bullet
26128@item
26129Can be used with file formats that don't support multiple sections.
26130
26131@item
26132Ease of finding scripts for public libraries.
26133
26134Scripts specified in the @code{.debug_gdb_scripts} section are searched for
26135in the source search path.
26136For publicly installed libraries, e.g., @file{libstdc++}, there typically
26137isn't a source directory in which to find the script.
26138
26139@item
26140Doesn't require source code additions.
26141@end itemize
26142
26143Benefits of the @code{.debug_gdb_scripts} way:
26144
26145@itemize @bullet
26146@item
26147Works with static linking.
26148
26149Scripts for libraries done the @file{-gdb.py} way require an objfile to
26150trigger their loading. When an application is statically linked the only
26151objfile available is the executable, and it is cumbersome to attach all the
26152scripts from all the input libraries to the executable's @file{-gdb.py} script.
26153
26154@item
26155Works with classes that are entirely inlined.
26156
26157Some classes can be entirely inlined, and thus there may not be an associated
26158shared library to attach a @file{-gdb.py} script to.
26159
26160@item
26161Scripts needn't be copied out of the source tree.
26162
26163In some circumstances, apps can be built out of large collections of internal
26164libraries, and the build infrastructure necessary to install the
26165@file{-gdb.py} scripts in a place where @value{GDBN} can find them is
26166cumbersome. It may be easier to specify the scripts in the
26167@code{.debug_gdb_scripts} section as relative paths, and add a path to the
26168top of the source tree to the source search path.
26169@end itemize
26170
0e3509db
DE
26171@node Python modules
26172@subsection Python modules
26173@cindex python modules
26174
fa3a4f15 26175@value{GDBN} comes with several modules to assist writing Python code.
0e3509db
DE
26176
26177@menu
7b51bc51 26178* gdb.printing:: Building and registering pretty-printers.
0e3509db 26179* gdb.types:: Utilities for working with types.
fa3a4f15 26180* gdb.prompt:: Utilities for prompt value substitution.
0e3509db
DE
26181@end menu
26182
7b51bc51
DE
26183@node gdb.printing
26184@subsubsection gdb.printing
26185@cindex gdb.printing
26186
26187This module provides a collection of utilities for working with
26188pretty-printers.
26189
26190@table @code
26191@item PrettyPrinter (@var{name}, @var{subprinters}=None)
26192This class specifies the API that makes @samp{info pretty-printer},
26193@samp{enable pretty-printer} and @samp{disable pretty-printer} work.
26194Pretty-printers should generally inherit from this class.
26195
26196@item SubPrettyPrinter (@var{name})
26197For printers that handle multiple types, this class specifies the
26198corresponding API for the subprinters.
26199
26200@item RegexpCollectionPrettyPrinter (@var{name})
26201Utility class for handling multiple printers, all recognized via
26202regular expressions.
26203@xref{Writing a Pretty-Printer}, for an example.
26204
cafec441
TT
26205@item FlagEnumerationPrinter (@var{name})
26206A pretty-printer which handles printing of @code{enum} values. Unlike
26207@value{GDBN}'s built-in @code{enum} printing, this printer attempts to
26208work properly when there is some overlap between the enumeration
26209constants. @var{name} is the name of the printer and also the name of
26210the @code{enum} type to look up.
26211
9c15afc4 26212@item register_pretty_printer (@var{obj}, @var{printer}, @var{replace}=False)
7b51bc51 26213Register @var{printer} with the pretty-printer list of @var{obj}.
9c15afc4
DE
26214If @var{replace} is @code{True} then any existing copy of the printer
26215is replaced. Otherwise a @code{RuntimeError} exception is raised
26216if a printer with the same name already exists.
7b51bc51
DE
26217@end table
26218
0e3509db
DE
26219@node gdb.types
26220@subsubsection gdb.types
7b51bc51 26221@cindex gdb.types
0e3509db
DE
26222
26223This module provides a collection of utilities for working with
18a9fc12 26224@code{gdb.Type} objects.
0e3509db
DE
26225
26226@table @code
26227@item get_basic_type (@var{type})
26228Return @var{type} with const and volatile qualifiers stripped,
26229and with typedefs and C@t{++} references converted to the underlying type.
26230
26231C@t{++} example:
26232
26233@smallexample
26234typedef const int const_int;
26235const_int foo (3);
26236const_int& foo_ref (foo);
26237int main () @{ return 0; @}
26238@end smallexample
26239
26240Then in gdb:
26241
26242@smallexample
26243(gdb) start
26244(gdb) python import gdb.types
26245(gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
26246(gdb) python print gdb.types.get_basic_type(foo_ref.type)
26247int
26248@end smallexample
26249
26250@item has_field (@var{type}, @var{field})
26251Return @code{True} if @var{type}, assumed to be a type with fields
26252(e.g., a structure or union), has field @var{field}.
26253
26254@item make_enum_dict (@var{enum_type})
26255Return a Python @code{dictionary} type produced from @var{enum_type}.
5110b5df 26256
0aaaf063 26257@item deep_items (@var{type})
5110b5df
PK
26258Returns a Python iterator similar to the standard
26259@code{gdb.Type.iteritems} method, except that the iterator returned
0aaaf063 26260by @code{deep_items} will recursively traverse anonymous struct or
5110b5df
PK
26261union fields. For example:
26262
26263@smallexample
26264struct A
26265@{
26266 int a;
26267 union @{
26268 int b0;
26269 int b1;
26270 @};
26271@};
26272@end smallexample
26273
26274@noindent
26275Then in @value{GDBN}:
26276@smallexample
26277(@value{GDBP}) python import gdb.types
26278(@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
26279(@value{GDBP}) python print struct_a.keys ()
26280@{['a', '']@}
0aaaf063 26281(@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
5110b5df
PK
26282@{['a', 'b0', 'b1']@}
26283@end smallexample
26284
18a9fc12
TT
26285@item get_type_recognizers ()
26286Return a list of the enabled type recognizers for the current context.
26287This is called by @value{GDBN} during the type-printing process
26288(@pxref{Type Printing API}).
26289
26290@item apply_type_recognizers (recognizers, type_obj)
26291Apply the type recognizers, @var{recognizers}, to the type object
26292@var{type_obj}. If any recognizer returns a string, return that
26293string. Otherwise, return @code{None}. This is called by
26294@value{GDBN} during the type-printing process (@pxref{Type Printing
26295API}).
26296
26297@item register_type_printer (locus, printer)
26298This is a convenience function to register a type printer.
26299@var{printer} is the type printer to register. It must implement the
26300type printer protocol. @var{locus} is either a @code{gdb.Objfile}, in
26301which case the printer is registered with that objfile; a
26302@code{gdb.Progspace}, in which case the printer is registered with
26303that progspace; or @code{None}, in which case the printer is
26304registered globally.
26305
26306@item TypePrinter
26307This is a base class that implements the type printer protocol. Type
26308printers are encouraged, but not required, to derive from this class.
26309It defines a constructor:
26310
26311@defmethod TypePrinter __init__ (self, name)
26312Initialize the type printer with the given name. The new printer
26313starts in the enabled state.
26314@end defmethod
26315
0e3509db 26316@end table
fa3a4f15
PM
26317
26318@node gdb.prompt
26319@subsubsection gdb.prompt
26320@cindex gdb.prompt
26321
26322This module provides a method for prompt value-substitution.
26323
26324@table @code
26325@item substitute_prompt (@var{string})
26326Return @var{string} with escape sequences substituted by values. Some
26327escape sequences take arguments. You can specify arguments inside
26328``@{@}'' immediately following the escape sequence.
26329
26330The escape sequences you can pass to this function are:
26331
26332@table @code
26333@item \\
26334Substitute a backslash.
26335@item \e
26336Substitute an ESC character.
26337@item \f
26338Substitute the selected frame; an argument names a frame parameter.
26339@item \n
26340Substitute a newline.
26341@item \p
26342Substitute a parameter's value; the argument names the parameter.
26343@item \r
26344Substitute a carriage return.
26345@item \t
26346Substitute the selected thread; an argument names a thread parameter.
26347@item \v
26348Substitute the version of GDB.
26349@item \w
26350Substitute the current working directory.
26351@item \[
26352Begin a sequence of non-printing characters. These sequences are
26353typically used with the ESC character, and are not counted in the string
26354length. Example: ``\[\e[0;34m\](gdb)\[\e[0m\]'' will return a
26355blue-colored ``(gdb)'' prompt where the length is five.
26356@item \]
26357End a sequence of non-printing characters.
26358@end table
26359
26360For example:
26361
26362@smallexample
26363substitute_prompt (``frame: \f,
26364 print arguments: \p@{print frame-arguments@}'')
26365@end smallexample
26366
26367@exdent will return the string:
26368
26369@smallexample
26370"frame: main, print arguments: scalars"
26371@end smallexample
26372@end table
0e3509db 26373
5a56e9c5
DE
26374@node Aliases
26375@section Creating new spellings of existing commands
26376@cindex aliases for commands
26377
26378It is often useful to define alternate spellings of existing commands.
26379For example, if a new @value{GDBN} command defined in Python has
26380a long name to type, it is handy to have an abbreviated version of it
26381that involves less typing.
26382
26383@value{GDBN} itself uses aliases. For example @samp{s} is an alias
26384of the @samp{step} command even though it is otherwise an ambiguous
26385abbreviation of other commands like @samp{set} and @samp{show}.
26386
26387Aliases are also used to provide shortened or more common versions
26388of multi-word commands. For example, @value{GDBN} provides the
26389@samp{tty} alias of the @samp{set inferior-tty} command.
26390
26391You can define a new alias with the @samp{alias} command.
26392
26393@table @code
26394
26395@kindex alias
26396@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
26397
26398@end table
26399
26400@var{ALIAS} specifies the name of the new alias.
26401Each word of @var{ALIAS} must consist of letters, numbers, dashes and
26402underscores.
26403
26404@var{COMMAND} specifies the name of an existing command
26405that is being aliased.
26406
26407The @samp{-a} option specifies that the new alias is an abbreviation
26408of the command. Abbreviations are not shown in command
26409lists displayed by the @samp{help} command.
26410
26411The @samp{--} option specifies the end of options,
26412and is useful when @var{ALIAS} begins with a dash.
26413
26414Here is a simple example showing how to make an abbreviation
26415of a command so that there is less to type.
26416Suppose you were tired of typing @samp{disas}, the current
26417shortest unambiguous abbreviation of the @samp{disassemble} command
26418and you wanted an even shorter version named @samp{di}.
26419The following will accomplish this.
26420
26421@smallexample
26422(gdb) alias -a di = disas
26423@end smallexample
26424
26425Note that aliases are different from user-defined commands.
26426With a user-defined command, you also need to write documentation
26427for it with the @samp{document} command.
26428An alias automatically picks up the documentation of the existing command.
26429
26430Here is an example where we make @samp{elms} an abbreviation of
26431@samp{elements} in the @samp{set print elements} command.
26432This is to show that you can make an abbreviation of any part
26433of a command.
26434
26435@smallexample
26436(gdb) alias -a set print elms = set print elements
26437(gdb) alias -a show print elms = show print elements
26438(gdb) set p elms 20
26439(gdb) show p elms
26440Limit on string chars or array elements to print is 200.
26441@end smallexample
26442
26443Note that if you are defining an alias of a @samp{set} command,
26444and you want to have an alias for the corresponding @samp{show}
26445command, then you need to define the latter separately.
26446
26447Unambiguously abbreviated commands are allowed in @var{COMMAND} and
26448@var{ALIAS}, just as they are normally.
26449
26450@smallexample
26451(gdb) alias -a set pr elms = set p ele
26452@end smallexample
26453
26454Finally, here is an example showing the creation of a one word
26455alias for a more complex command.
26456This creates alias @samp{spe} of the command @samp{set print elements}.
26457
26458@smallexample
26459(gdb) alias spe = set print elements
26460(gdb) spe 20
26461@end smallexample
26462
21c294e6
AC
26463@node Interpreters
26464@chapter Command Interpreters
26465@cindex command interpreters
26466
26467@value{GDBN} supports multiple command interpreters, and some command
26468infrastructure to allow users or user interface writers to switch
26469between interpreters or run commands in other interpreters.
26470
26471@value{GDBN} currently supports two command interpreters, the console
26472interpreter (sometimes called the command-line interpreter or @sc{cli})
26473and the machine interface interpreter (or @sc{gdb/mi}). This manual
26474describes both of these interfaces in great detail.
26475
26476By default, @value{GDBN} will start with the console interpreter.
26477However, the user may choose to start @value{GDBN} with another
26478interpreter by specifying the @option{-i} or @option{--interpreter}
26479startup options. Defined interpreters include:
26480
26481@table @code
26482@item console
26483@cindex console interpreter
26484The traditional console or command-line interpreter. This is the most often
26485used interpreter with @value{GDBN}. With no interpreter specified at runtime,
26486@value{GDBN} will use this interpreter.
26487
26488@item mi
26489@cindex mi interpreter
26490The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
26491by programs wishing to use @value{GDBN} as a backend for a debugger GUI
26492or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
26493Interface}.
26494
26495@item mi2
26496@cindex mi2 interpreter
26497The current @sc{gdb/mi} interface.
26498
26499@item mi1
26500@cindex mi1 interpreter
26501The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
26502
26503@end table
26504
26505@cindex invoke another interpreter
26506The interpreter being used by @value{GDBN} may not be dynamically
26507switched at runtime. Although possible, this could lead to a very
26508precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
26509enters the command "interpreter-set console" in a console view,
26510@value{GDBN} would switch to using the console interpreter, rendering
26511the IDE inoperable!
26512
26513@kindex interpreter-exec
26514Although you may only choose a single interpreter at startup, you may execute
26515commands in any interpreter from the current interpreter using the appropriate
26516command. If you are running the console interpreter, simply use the
26517@code{interpreter-exec} command:
26518
26519@smallexample
26520interpreter-exec mi "-data-list-register-names"
26521@end smallexample
26522
26523@sc{gdb/mi} has a similar command, although it is only available in versions of
26524@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
26525
8e04817f
AC
26526@node TUI
26527@chapter @value{GDBN} Text User Interface
26528@cindex TUI
d0d5df6f 26529@cindex Text User Interface
c906108c 26530
8e04817f
AC
26531@menu
26532* TUI Overview:: TUI overview
26533* TUI Keys:: TUI key bindings
7cf36c78 26534* TUI Single Key Mode:: TUI single key mode
db2e3e2e 26535* TUI Commands:: TUI-specific commands
8e04817f
AC
26536* TUI Configuration:: TUI configuration variables
26537@end menu
c906108c 26538
46ba6afa 26539The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
26540interface which uses the @code{curses} library to show the source
26541file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
26542commands in separate text windows. The TUI mode is supported only
26543on platforms where a suitable version of the @code{curses} library
26544is available.
d0d5df6f 26545
46ba6afa 26546The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 26547@samp{@value{GDBP} -tui}.
46ba6afa
BW
26548You can also switch in and out of TUI mode while @value{GDBN} runs by
26549using various TUI commands and key bindings, such as @kbd{C-x C-a}.
26550@xref{TUI Keys, ,TUI Key Bindings}.
c906108c 26551
8e04817f 26552@node TUI Overview
79a6e687 26553@section TUI Overview
c906108c 26554
46ba6afa 26555In TUI mode, @value{GDBN} can display several text windows:
c906108c 26556
8e04817f
AC
26557@table @emph
26558@item command
26559This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
26560prompt and the @value{GDBN} output. The @value{GDBN} input is still
26561managed using readline.
c906108c 26562
8e04817f
AC
26563@item source
26564The source window shows the source file of the program. The current
46ba6afa 26565line and active breakpoints are displayed in this window.
c906108c 26566
8e04817f
AC
26567@item assembly
26568The assembly window shows the disassembly output of the program.
c906108c 26569
8e04817f 26570@item register
46ba6afa
BW
26571This window shows the processor registers. Registers are highlighted
26572when their values change.
c906108c
SS
26573@end table
26574
269c21fe 26575The source and assembly windows show the current program position
46ba6afa
BW
26576by highlighting the current line and marking it with a @samp{>} marker.
26577Breakpoints are indicated with two markers. The first marker
269c21fe
SC
26578indicates the breakpoint type:
26579
26580@table @code
26581@item B
26582Breakpoint which was hit at least once.
26583
26584@item b
26585Breakpoint which was never hit.
26586
26587@item H
26588Hardware breakpoint which was hit at least once.
26589
26590@item h
26591Hardware breakpoint which was never hit.
269c21fe
SC
26592@end table
26593
26594The second marker indicates whether the breakpoint is enabled or not:
26595
26596@table @code
26597@item +
26598Breakpoint is enabled.
26599
26600@item -
26601Breakpoint is disabled.
269c21fe
SC
26602@end table
26603
46ba6afa
BW
26604The source, assembly and register windows are updated when the current
26605thread changes, when the frame changes, or when the program counter
26606changes.
26607
26608These windows are not all visible at the same time. The command
26609window is always visible. The others can be arranged in several
26610layouts:
c906108c 26611
8e04817f
AC
26612@itemize @bullet
26613@item
46ba6afa 26614source only,
2df3850c 26615
8e04817f 26616@item
46ba6afa 26617assembly only,
8e04817f
AC
26618
26619@item
46ba6afa 26620source and assembly,
8e04817f
AC
26621
26622@item
46ba6afa 26623source and registers, or
c906108c 26624
8e04817f 26625@item
46ba6afa 26626assembly and registers.
8e04817f 26627@end itemize
c906108c 26628
46ba6afa 26629A status line above the command window shows the following information:
b7bb15bc
SC
26630
26631@table @emph
26632@item target
46ba6afa 26633Indicates the current @value{GDBN} target.
b7bb15bc
SC
26634(@pxref{Targets, ,Specifying a Debugging Target}).
26635
26636@item process
46ba6afa 26637Gives the current process or thread number.
b7bb15bc
SC
26638When no process is being debugged, this field is set to @code{No process}.
26639
26640@item function
26641Gives the current function name for the selected frame.
26642The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 26643When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
26644the string @code{??} is displayed.
26645
26646@item line
26647Indicates the current line number for the selected frame.
46ba6afa 26648When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
26649
26650@item pc
26651Indicates the current program counter address.
b7bb15bc
SC
26652@end table
26653
8e04817f
AC
26654@node TUI Keys
26655@section TUI Key Bindings
26656@cindex TUI key bindings
c906108c 26657
8e04817f 26658The TUI installs several key bindings in the readline keymaps
39037522
TT
26659@ifset SYSTEM_READLINE
26660(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
26661@end ifset
26662@ifclear SYSTEM_READLINE
26663(@pxref{Command Line Editing}).
26664@end ifclear
26665The following key bindings are installed for both TUI mode and the
26666@value{GDBN} standard mode.
c906108c 26667
8e04817f
AC
26668@table @kbd
26669@kindex C-x C-a
26670@item C-x C-a
26671@kindex C-x a
26672@itemx C-x a
26673@kindex C-x A
26674@itemx C-x A
46ba6afa
BW
26675Enter or leave the TUI mode. When leaving the TUI mode,
26676the curses window management stops and @value{GDBN} operates using
26677its standard mode, writing on the terminal directly. When reentering
26678the TUI mode, control is given back to the curses windows.
8e04817f 26679The screen is then refreshed.
c906108c 26680
8e04817f
AC
26681@kindex C-x 1
26682@item C-x 1
26683Use a TUI layout with only one window. The layout will
26684either be @samp{source} or @samp{assembly}. When the TUI mode
26685is not active, it will switch to the TUI mode.
2df3850c 26686
8e04817f 26687Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 26688
8e04817f
AC
26689@kindex C-x 2
26690@item C-x 2
26691Use a TUI layout with at least two windows. When the current
46ba6afa 26692layout already has two windows, the next layout with two windows is used.
8e04817f
AC
26693When a new layout is chosen, one window will always be common to the
26694previous layout and the new one.
c906108c 26695
8e04817f 26696Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 26697
72ffddc9
SC
26698@kindex C-x o
26699@item C-x o
26700Change the active window. The TUI associates several key bindings
46ba6afa 26701(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
26702gives the focus to the next TUI window.
26703
26704Think of it as the Emacs @kbd{C-x o} binding.
26705
7cf36c78
SC
26706@kindex C-x s
26707@item C-x s
46ba6afa
BW
26708Switch in and out of the TUI SingleKey mode that binds single
26709keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
26710@end table
26711
46ba6afa 26712The following key bindings only work in the TUI mode:
5d161b24 26713
46ba6afa 26714@table @asis
8e04817f 26715@kindex PgUp
46ba6afa 26716@item @key{PgUp}
8e04817f 26717Scroll the active window one page up.
c906108c 26718
8e04817f 26719@kindex PgDn
46ba6afa 26720@item @key{PgDn}
8e04817f 26721Scroll the active window one page down.
c906108c 26722
8e04817f 26723@kindex Up
46ba6afa 26724@item @key{Up}
8e04817f 26725Scroll the active window one line up.
c906108c 26726
8e04817f 26727@kindex Down
46ba6afa 26728@item @key{Down}
8e04817f 26729Scroll the active window one line down.
c906108c 26730
8e04817f 26731@kindex Left
46ba6afa 26732@item @key{Left}
8e04817f 26733Scroll the active window one column left.
c906108c 26734
8e04817f 26735@kindex Right
46ba6afa 26736@item @key{Right}
8e04817f 26737Scroll the active window one column right.
c906108c 26738
8e04817f 26739@kindex C-L
46ba6afa 26740@item @kbd{C-L}
8e04817f 26741Refresh the screen.
8e04817f 26742@end table
c906108c 26743
46ba6afa
BW
26744Because the arrow keys scroll the active window in the TUI mode, they
26745are not available for their normal use by readline unless the command
26746window has the focus. When another window is active, you must use
26747other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
26748and @kbd{C-f} to control the command window.
8e04817f 26749
7cf36c78
SC
26750@node TUI Single Key Mode
26751@section TUI Single Key Mode
26752@cindex TUI single key mode
26753
46ba6afa
BW
26754The TUI also provides a @dfn{SingleKey} mode, which binds several
26755frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
26756switch into this mode, where the following key bindings are used:
7cf36c78
SC
26757
26758@table @kbd
26759@kindex c @r{(SingleKey TUI key)}
26760@item c
26761continue
26762
26763@kindex d @r{(SingleKey TUI key)}
26764@item d
26765down
26766
26767@kindex f @r{(SingleKey TUI key)}
26768@item f
26769finish
26770
26771@kindex n @r{(SingleKey TUI key)}
26772@item n
26773next
26774
26775@kindex q @r{(SingleKey TUI key)}
26776@item q
46ba6afa 26777exit the SingleKey mode.
7cf36c78
SC
26778
26779@kindex r @r{(SingleKey TUI key)}
26780@item r
26781run
26782
26783@kindex s @r{(SingleKey TUI key)}
26784@item s
26785step
26786
26787@kindex u @r{(SingleKey TUI key)}
26788@item u
26789up
26790
26791@kindex v @r{(SingleKey TUI key)}
26792@item v
26793info locals
26794
26795@kindex w @r{(SingleKey TUI key)}
26796@item w
26797where
7cf36c78
SC
26798@end table
26799
26800Other keys temporarily switch to the @value{GDBN} command prompt.
26801The key that was pressed is inserted in the editing buffer so that
26802it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
26803with the TUI SingleKey mode. Once the command is entered the TUI
26804SingleKey mode is restored. The only way to permanently leave
7f9087cb 26805this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
26806
26807
8e04817f 26808@node TUI Commands
db2e3e2e 26809@section TUI-specific Commands
8e04817f
AC
26810@cindex TUI commands
26811
26812The TUI has specific commands to control the text windows.
46ba6afa
BW
26813These commands are always available, even when @value{GDBN} is not in
26814the TUI mode. When @value{GDBN} is in the standard mode, most
26815of these commands will automatically switch to the TUI mode.
c906108c 26816
ff12863f
PA
26817Note that if @value{GDBN}'s @code{stdout} is not connected to a
26818terminal, or @value{GDBN} has been started with the machine interface
26819interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
26820these commands will fail with an error, because it would not be
26821possible or desirable to enable curses window management.
26822
c906108c 26823@table @code
3d757584
SC
26824@item info win
26825@kindex info win
26826List and give the size of all displayed windows.
26827
8e04817f 26828@item layout next
4644b6e3 26829@kindex layout
8e04817f 26830Display the next layout.
2df3850c 26831
8e04817f 26832@item layout prev
8e04817f 26833Display the previous layout.
c906108c 26834
8e04817f 26835@item layout src
8e04817f 26836Display the source window only.
c906108c 26837
8e04817f 26838@item layout asm
8e04817f 26839Display the assembly window only.
c906108c 26840
8e04817f 26841@item layout split
8e04817f 26842Display the source and assembly window.
c906108c 26843
8e04817f 26844@item layout regs
8e04817f
AC
26845Display the register window together with the source or assembly window.
26846
46ba6afa 26847@item focus next
8e04817f 26848@kindex focus
46ba6afa
BW
26849Make the next window active for scrolling.
26850
26851@item focus prev
26852Make the previous window active for scrolling.
26853
26854@item focus src
26855Make the source window active for scrolling.
26856
26857@item focus asm
26858Make the assembly window active for scrolling.
26859
26860@item focus regs
26861Make the register window active for scrolling.
26862
26863@item focus cmd
26864Make the command window active for scrolling.
c906108c 26865
8e04817f
AC
26866@item refresh
26867@kindex refresh
7f9087cb 26868Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 26869
6a1b180d
SC
26870@item tui reg float
26871@kindex tui reg
26872Show the floating point registers in the register window.
26873
26874@item tui reg general
26875Show the general registers in the register window.
26876
26877@item tui reg next
26878Show the next register group. The list of register groups as well as
26879their order is target specific. The predefined register groups are the
26880following: @code{general}, @code{float}, @code{system}, @code{vector},
26881@code{all}, @code{save}, @code{restore}.
26882
26883@item tui reg system
26884Show the system registers in the register window.
26885
8e04817f
AC
26886@item update
26887@kindex update
26888Update the source window and the current execution point.
c906108c 26889
8e04817f
AC
26890@item winheight @var{name} +@var{count}
26891@itemx winheight @var{name} -@var{count}
26892@kindex winheight
26893Change the height of the window @var{name} by @var{count}
26894lines. Positive counts increase the height, while negative counts
26895decrease it.
2df3850c 26896
46ba6afa
BW
26897@item tabset @var{nchars}
26898@kindex tabset
c45da7e6 26899Set the width of tab stops to be @var{nchars} characters.
c906108c
SS
26900@end table
26901
8e04817f 26902@node TUI Configuration
79a6e687 26903@section TUI Configuration Variables
8e04817f 26904@cindex TUI configuration variables
c906108c 26905
46ba6afa 26906Several configuration variables control the appearance of TUI windows.
c906108c 26907
8e04817f
AC
26908@table @code
26909@item set tui border-kind @var{kind}
26910@kindex set tui border-kind
26911Select the border appearance for the source, assembly and register windows.
26912The possible values are the following:
26913@table @code
26914@item space
26915Use a space character to draw the border.
c906108c 26916
8e04817f 26917@item ascii
46ba6afa 26918Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 26919
8e04817f
AC
26920@item acs
26921Use the Alternate Character Set to draw the border. The border is
26922drawn using character line graphics if the terminal supports them.
8e04817f 26923@end table
c78b4128 26924
8e04817f
AC
26925@item set tui border-mode @var{mode}
26926@kindex set tui border-mode
46ba6afa
BW
26927@itemx set tui active-border-mode @var{mode}
26928@kindex set tui active-border-mode
26929Select the display attributes for the borders of the inactive windows
26930or the active window. The @var{mode} can be one of the following:
8e04817f
AC
26931@table @code
26932@item normal
26933Use normal attributes to display the border.
c906108c 26934
8e04817f
AC
26935@item standout
26936Use standout mode.
c906108c 26937
8e04817f
AC
26938@item reverse
26939Use reverse video mode.
c906108c 26940
8e04817f
AC
26941@item half
26942Use half bright mode.
c906108c 26943
8e04817f
AC
26944@item half-standout
26945Use half bright and standout mode.
c906108c 26946
8e04817f
AC
26947@item bold
26948Use extra bright or bold mode.
c78b4128 26949
8e04817f
AC
26950@item bold-standout
26951Use extra bright or bold and standout mode.
8e04817f 26952@end table
8e04817f 26953@end table
c78b4128 26954
8e04817f
AC
26955@node Emacs
26956@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 26957
8e04817f
AC
26958@cindex Emacs
26959@cindex @sc{gnu} Emacs
26960A special interface allows you to use @sc{gnu} Emacs to view (and
26961edit) the source files for the program you are debugging with
26962@value{GDBN}.
c906108c 26963
8e04817f
AC
26964To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
26965executable file you want to debug as an argument. This command starts
26966@value{GDBN} as a subprocess of Emacs, with input and output through a newly
26967created Emacs buffer.
26968@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 26969
5e252a2e 26970Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 26971things:
c906108c 26972
8e04817f
AC
26973@itemize @bullet
26974@item
5e252a2e
NR
26975All ``terminal'' input and output goes through an Emacs buffer, called
26976the GUD buffer.
c906108c 26977
8e04817f
AC
26978This applies both to @value{GDBN} commands and their output, and to the input
26979and output done by the program you are debugging.
bf0184be 26980
8e04817f
AC
26981This is useful because it means that you can copy the text of previous
26982commands and input them again; you can even use parts of the output
26983in this way.
bf0184be 26984
8e04817f
AC
26985All the facilities of Emacs' Shell mode are available for interacting
26986with your program. In particular, you can send signals the usual
26987way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
26988stop.
bf0184be
ND
26989
26990@item
8e04817f 26991@value{GDBN} displays source code through Emacs.
bf0184be 26992
8e04817f
AC
26993Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
26994source file for that frame and puts an arrow (@samp{=>}) at the
26995left margin of the current line. Emacs uses a separate buffer for
26996source display, and splits the screen to show both your @value{GDBN} session
26997and the source.
bf0184be 26998
8e04817f
AC
26999Explicit @value{GDBN} @code{list} or search commands still produce output as
27000usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
27001@end itemize
27002
27003We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
27004a graphical mode, enabled by default, which provides further buffers
27005that can control the execution and describe the state of your program.
27006@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 27007
64fabec2
AC
27008If you specify an absolute file name when prompted for the @kbd{M-x
27009gdb} argument, then Emacs sets your current working directory to where
27010your program resides. If you only specify the file name, then Emacs
7a9dd1b2 27011sets your current working directory to the directory associated
64fabec2
AC
27012with the previous buffer. In this case, @value{GDBN} may find your
27013program by searching your environment's @code{PATH} variable, but on
27014some operating systems it might not find the source. So, although the
27015@value{GDBN} input and output session proceeds normally, the auxiliary
27016buffer does not display the current source and line of execution.
27017
27018The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
27019line of the GUD buffer and this serves as a default for the commands
27020that specify files for @value{GDBN} to operate on. @xref{Files,
27021,Commands to Specify Files}.
64fabec2
AC
27022
27023By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
27024need to call @value{GDBN} by a different name (for example, if you
27025keep several configurations around, with different names) you can
27026customize the Emacs variable @code{gud-gdb-command-name} to run the
27027one you want.
8e04817f 27028
5e252a2e 27029In the GUD buffer, you can use these special Emacs commands in
8e04817f 27030addition to the standard Shell mode commands:
c906108c 27031
8e04817f
AC
27032@table @kbd
27033@item C-h m
5e252a2e 27034Describe the features of Emacs' GUD Mode.
c906108c 27035
64fabec2 27036@item C-c C-s
8e04817f
AC
27037Execute to another source line, like the @value{GDBN} @code{step} command; also
27038update the display window to show the current file and location.
c906108c 27039
64fabec2 27040@item C-c C-n
8e04817f
AC
27041Execute to next source line in this function, skipping all function
27042calls, like the @value{GDBN} @code{next} command. Then update the display window
27043to show the current file and location.
c906108c 27044
64fabec2 27045@item C-c C-i
8e04817f
AC
27046Execute one instruction, like the @value{GDBN} @code{stepi} command; update
27047display window accordingly.
c906108c 27048
8e04817f
AC
27049@item C-c C-f
27050Execute until exit from the selected stack frame, like the @value{GDBN}
27051@code{finish} command.
c906108c 27052
64fabec2 27053@item C-c C-r
8e04817f
AC
27054Continue execution of your program, like the @value{GDBN} @code{continue}
27055command.
b433d00b 27056
64fabec2 27057@item C-c <
8e04817f
AC
27058Go up the number of frames indicated by the numeric argument
27059(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
27060like the @value{GDBN} @code{up} command.
b433d00b 27061
64fabec2 27062@item C-c >
8e04817f
AC
27063Go down the number of frames indicated by the numeric argument, like the
27064@value{GDBN} @code{down} command.
8e04817f 27065@end table
c906108c 27066
7f9087cb 27067In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 27068tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 27069
5e252a2e
NR
27070In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
27071separate frame which shows a backtrace when the GUD buffer is current.
27072Move point to any frame in the stack and type @key{RET} to make it
27073become the current frame and display the associated source in the
27074source buffer. Alternatively, click @kbd{Mouse-2} to make the
27075selected frame become the current one. In graphical mode, the
27076speedbar displays watch expressions.
64fabec2 27077
8e04817f
AC
27078If you accidentally delete the source-display buffer, an easy way to get
27079it back is to type the command @code{f} in the @value{GDBN} buffer, to
27080request a frame display; when you run under Emacs, this recreates
27081the source buffer if necessary to show you the context of the current
27082frame.
c906108c 27083
8e04817f
AC
27084The source files displayed in Emacs are in ordinary Emacs buffers
27085which are visiting the source files in the usual way. You can edit
27086the files with these buffers if you wish; but keep in mind that @value{GDBN}
27087communicates with Emacs in terms of line numbers. If you add or
27088delete lines from the text, the line numbers that @value{GDBN} knows cease
27089to correspond properly with the code.
b383017d 27090
5e252a2e
NR
27091A more detailed description of Emacs' interaction with @value{GDBN} is
27092given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
27093Emacs Manual}).
c906108c 27094
922fbb7b
AC
27095@node GDB/MI
27096@chapter The @sc{gdb/mi} Interface
27097
27098@unnumberedsec Function and Purpose
27099
27100@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
27101@sc{gdb/mi} is a line based machine oriented text interface to
27102@value{GDBN} and is activated by specifying using the
27103@option{--interpreter} command line option (@pxref{Mode Options}). It
27104is specifically intended to support the development of systems which
27105use the debugger as just one small component of a larger system.
922fbb7b
AC
27106
27107This chapter is a specification of the @sc{gdb/mi} interface. It is written
27108in the form of a reference manual.
27109
27110Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
27111features described below are incomplete and subject to change
27112(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
27113
27114@unnumberedsec Notation and Terminology
27115
27116@cindex notational conventions, for @sc{gdb/mi}
27117This chapter uses the following notation:
27118
27119@itemize @bullet
27120@item
27121@code{|} separates two alternatives.
27122
27123@item
27124@code{[ @var{something} ]} indicates that @var{something} is optional:
27125it may or may not be given.
27126
27127@item
27128@code{( @var{group} )*} means that @var{group} inside the parentheses
27129may repeat zero or more times.
27130
27131@item
27132@code{( @var{group} )+} means that @var{group} inside the parentheses
27133may repeat one or more times.
27134
27135@item
27136@code{"@var{string}"} means a literal @var{string}.
27137@end itemize
27138
27139@ignore
27140@heading Dependencies
27141@end ignore
27142
922fbb7b 27143@menu
c3b108f7 27144* GDB/MI General Design::
922fbb7b
AC
27145* GDB/MI Command Syntax::
27146* GDB/MI Compatibility with CLI::
af6eff6f 27147* GDB/MI Development and Front Ends::
922fbb7b 27148* GDB/MI Output Records::
ef21caaf 27149* GDB/MI Simple Examples::
922fbb7b 27150* GDB/MI Command Description Format::
ef21caaf 27151* GDB/MI Breakpoint Commands::
3fa7bf06 27152* GDB/MI Catchpoint Commands::
a2c02241
NR
27153* GDB/MI Program Context::
27154* GDB/MI Thread Commands::
5d77fe44 27155* GDB/MI Ada Tasking Commands::
a2c02241
NR
27156* GDB/MI Program Execution::
27157* GDB/MI Stack Manipulation::
27158* GDB/MI Variable Objects::
922fbb7b 27159* GDB/MI Data Manipulation::
a2c02241
NR
27160* GDB/MI Tracepoint Commands::
27161* GDB/MI Symbol Query::
351ff01a 27162* GDB/MI File Commands::
922fbb7b
AC
27163@ignore
27164* GDB/MI Kod Commands::
27165* GDB/MI Memory Overlay Commands::
27166* GDB/MI Signal Handling Commands::
27167@end ignore
922fbb7b 27168* GDB/MI Target Manipulation::
a6b151f1 27169* GDB/MI File Transfer Commands::
ef21caaf 27170* GDB/MI Miscellaneous Commands::
922fbb7b
AC
27171@end menu
27172
c3b108f7
VP
27173@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27174@node GDB/MI General Design
27175@section @sc{gdb/mi} General Design
27176@cindex GDB/MI General Design
27177
27178Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
27179parts---commands sent to @value{GDBN}, responses to those commands
27180and notifications. Each command results in exactly one response,
27181indicating either successful completion of the command, or an error.
27182For the commands that do not resume the target, the response contains the
27183requested information. For the commands that resume the target, the
27184response only indicates whether the target was successfully resumed.
27185Notifications is the mechanism for reporting changes in the state of the
27186target, or in @value{GDBN} state, that cannot conveniently be associated with
27187a command and reported as part of that command response.
27188
27189The important examples of notifications are:
27190@itemize @bullet
27191
27192@item
27193Exec notifications. These are used to report changes in
27194target state---when a target is resumed, or stopped. It would not
27195be feasible to include this information in response of resuming
27196commands, because one resume commands can result in multiple events in
27197different threads. Also, quite some time may pass before any event
27198happens in the target, while a frontend needs to know whether the resuming
27199command itself was successfully executed.
27200
27201@item
27202Console output, and status notifications. Console output
27203notifications are used to report output of CLI commands, as well as
27204diagnostics for other commands. Status notifications are used to
27205report the progress of a long-running operation. Naturally, including
27206this information in command response would mean no output is produced
27207until the command is finished, which is undesirable.
27208
27209@item
27210General notifications. Commands may have various side effects on
27211the @value{GDBN} or target state beyond their official purpose. For example,
27212a command may change the selected thread. Although such changes can
27213be included in command response, using notification allows for more
27214orthogonal frontend design.
27215
27216@end itemize
27217
27218There's no guarantee that whenever an MI command reports an error,
27219@value{GDBN} or the target are in any specific state, and especially,
27220the state is not reverted to the state before the MI command was
27221processed. Therefore, whenever an MI command results in an error,
27222we recommend that the frontend refreshes all the information shown in
27223the user interface.
27224
508094de
NR
27225
27226@menu
27227* Context management::
27228* Asynchronous and non-stop modes::
27229* Thread groups::
27230@end menu
27231
27232@node Context management
c3b108f7
VP
27233@subsection Context management
27234
27235In most cases when @value{GDBN} accesses the target, this access is
27236done in context of a specific thread and frame (@pxref{Frames}).
27237Often, even when accessing global data, the target requires that a thread
27238be specified. The CLI interface maintains the selected thread and frame,
27239and supplies them to target on each command. This is convenient,
27240because a command line user would not want to specify that information
27241explicitly on each command, and because user interacts with
27242@value{GDBN} via a single terminal, so no confusion is possible as
27243to what thread and frame are the current ones.
27244
27245In the case of MI, the concept of selected thread and frame is less
27246useful. First, a frontend can easily remember this information
27247itself. Second, a graphical frontend can have more than one window,
27248each one used for debugging a different thread, and the frontend might
27249want to access additional threads for internal purposes. This
27250increases the risk that by relying on implicitly selected thread, the
27251frontend may be operating on a wrong one. Therefore, each MI command
27252should explicitly specify which thread and frame to operate on. To
27253make it possible, each MI command accepts the @samp{--thread} and
27254@samp{--frame} options, the value to each is @value{GDBN} identifier
27255for thread and frame to operate on.
27256
27257Usually, each top-level window in a frontend allows the user to select
27258a thread and a frame, and remembers the user selection for further
27259operations. However, in some cases @value{GDBN} may suggest that the
27260current thread be changed. For example, when stopping on a breakpoint
27261it is reasonable to switch to the thread where breakpoint is hit. For
27262another example, if the user issues the CLI @samp{thread} command via
27263the frontend, it is desirable to change the frontend's selected thread to the
27264one specified by user. @value{GDBN} communicates the suggestion to
27265change current thread using the @samp{=thread-selected} notification.
27266No such notification is available for the selected frame at the moment.
27267
27268Note that historically, MI shares the selected thread with CLI, so
27269frontends used the @code{-thread-select} to execute commands in the
27270right context. However, getting this to work right is cumbersome. The
27271simplest way is for frontend to emit @code{-thread-select} command
27272before every command. This doubles the number of commands that need
27273to be sent. The alternative approach is to suppress @code{-thread-select}
27274if the selected thread in @value{GDBN} is supposed to be identical to the
27275thread the frontend wants to operate on. However, getting this
27276optimization right can be tricky. In particular, if the frontend
27277sends several commands to @value{GDBN}, and one of the commands changes the
27278selected thread, then the behaviour of subsequent commands will
27279change. So, a frontend should either wait for response from such
27280problematic commands, or explicitly add @code{-thread-select} for
27281all subsequent commands. No frontend is known to do this exactly
27282right, so it is suggested to just always pass the @samp{--thread} and
27283@samp{--frame} options.
27284
508094de 27285@node Asynchronous and non-stop modes
c3b108f7
VP
27286@subsection Asynchronous command execution and non-stop mode
27287
27288On some targets, @value{GDBN} is capable of processing MI commands
27289even while the target is running. This is called @dfn{asynchronous
27290command execution} (@pxref{Background Execution}). The frontend may
27291specify a preferrence for asynchronous execution using the
27292@code{-gdb-set target-async 1} command, which should be emitted before
27293either running the executable or attaching to the target. After the
27294frontend has started the executable or attached to the target, it can
27295find if asynchronous execution is enabled using the
27296@code{-list-target-features} command.
27297
27298Even if @value{GDBN} can accept a command while target is running,
27299many commands that access the target do not work when the target is
27300running. Therefore, asynchronous command execution is most useful
27301when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
27302it is possible to examine the state of one thread, while other threads
27303are running.
27304
27305When a given thread is running, MI commands that try to access the
27306target in the context of that thread may not work, or may work only on
27307some targets. In particular, commands that try to operate on thread's
27308stack will not work, on any target. Commands that read memory, or
27309modify breakpoints, may work or not work, depending on the target. Note
27310that even commands that operate on global state, such as @code{print},
27311@code{set}, and breakpoint commands, still access the target in the
27312context of a specific thread, so frontend should try to find a
27313stopped thread and perform the operation on that thread (using the
27314@samp{--thread} option).
27315
27316Which commands will work in the context of a running thread is
27317highly target dependent. However, the two commands
27318@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
27319to find the state of a thread, will always work.
27320
508094de 27321@node Thread groups
c3b108f7
VP
27322@subsection Thread groups
27323@value{GDBN} may be used to debug several processes at the same time.
27324On some platfroms, @value{GDBN} may support debugging of several
27325hardware systems, each one having several cores with several different
27326processes running on each core. This section describes the MI
27327mechanism to support such debugging scenarios.
27328
27329The key observation is that regardless of the structure of the
27330target, MI can have a global list of threads, because most commands that
27331accept the @samp{--thread} option do not need to know what process that
27332thread belongs to. Therefore, it is not necessary to introduce
27333neither additional @samp{--process} option, nor an notion of the
27334current process in the MI interface. The only strictly new feature
27335that is required is the ability to find how the threads are grouped
27336into processes.
27337
27338To allow the user to discover such grouping, and to support arbitrary
27339hierarchy of machines/cores/processes, MI introduces the concept of a
27340@dfn{thread group}. Thread group is a collection of threads and other
27341thread groups. A thread group always has a string identifier, a type,
27342and may have additional attributes specific to the type. A new
27343command, @code{-list-thread-groups}, returns the list of top-level
27344thread groups, which correspond to processes that @value{GDBN} is
27345debugging at the moment. By passing an identifier of a thread group
27346to the @code{-list-thread-groups} command, it is possible to obtain
27347the members of specific thread group.
27348
27349To allow the user to easily discover processes, and other objects, he
27350wishes to debug, a concept of @dfn{available thread group} is
27351introduced. Available thread group is an thread group that
27352@value{GDBN} is not debugging, but that can be attached to, using the
27353@code{-target-attach} command. The list of available top-level thread
27354groups can be obtained using @samp{-list-thread-groups --available}.
27355In general, the content of a thread group may be only retrieved only
27356after attaching to that thread group.
27357
a79b8f6e
VP
27358Thread groups are related to inferiors (@pxref{Inferiors and
27359Programs}). Each inferior corresponds to a thread group of a special
27360type @samp{process}, and some additional operations are permitted on
27361such thread groups.
27362
922fbb7b
AC
27363@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27364@node GDB/MI Command Syntax
27365@section @sc{gdb/mi} Command Syntax
27366
27367@menu
27368* GDB/MI Input Syntax::
27369* GDB/MI Output Syntax::
922fbb7b
AC
27370@end menu
27371
27372@node GDB/MI Input Syntax
27373@subsection @sc{gdb/mi} Input Syntax
27374
27375@cindex input syntax for @sc{gdb/mi}
27376@cindex @sc{gdb/mi}, input syntax
27377@table @code
27378@item @var{command} @expansion{}
27379@code{@var{cli-command} | @var{mi-command}}
27380
27381@item @var{cli-command} @expansion{}
27382@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
27383@var{cli-command} is any existing @value{GDBN} CLI command.
27384
27385@item @var{mi-command} @expansion{}
27386@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
27387@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
27388
27389@item @var{token} @expansion{}
27390"any sequence of digits"
27391
27392@item @var{option} @expansion{}
27393@code{"-" @var{parameter} [ " " @var{parameter} ]}
27394
27395@item @var{parameter} @expansion{}
27396@code{@var{non-blank-sequence} | @var{c-string}}
27397
27398@item @var{operation} @expansion{}
27399@emph{any of the operations described in this chapter}
27400
27401@item @var{non-blank-sequence} @expansion{}
27402@emph{anything, provided it doesn't contain special characters such as
27403"-", @var{nl}, """ and of course " "}
27404
27405@item @var{c-string} @expansion{}
27406@code{""" @var{seven-bit-iso-c-string-content} """}
27407
27408@item @var{nl} @expansion{}
27409@code{CR | CR-LF}
27410@end table
27411
27412@noindent
27413Notes:
27414
27415@itemize @bullet
27416@item
27417The CLI commands are still handled by the @sc{mi} interpreter; their
27418output is described below.
27419
27420@item
27421The @code{@var{token}}, when present, is passed back when the command
27422finishes.
27423
27424@item
27425Some @sc{mi} commands accept optional arguments as part of the parameter
27426list. Each option is identified by a leading @samp{-} (dash) and may be
27427followed by an optional argument parameter. Options occur first in the
27428parameter list and can be delimited from normal parameters using
27429@samp{--} (this is useful when some parameters begin with a dash).
27430@end itemize
27431
27432Pragmatics:
27433
27434@itemize @bullet
27435@item
27436We want easy access to the existing CLI syntax (for debugging).
27437
27438@item
27439We want it to be easy to spot a @sc{mi} operation.
27440@end itemize
27441
27442@node GDB/MI Output Syntax
27443@subsection @sc{gdb/mi} Output Syntax
27444
27445@cindex output syntax of @sc{gdb/mi}
27446@cindex @sc{gdb/mi}, output syntax
27447The output from @sc{gdb/mi} consists of zero or more out-of-band records
27448followed, optionally, by a single result record. This result record
27449is for the most recent command. The sequence of output records is
594fe323 27450terminated by @samp{(gdb)}.
922fbb7b
AC
27451
27452If an input command was prefixed with a @code{@var{token}} then the
27453corresponding output for that command will also be prefixed by that same
27454@var{token}.
27455
27456@table @code
27457@item @var{output} @expansion{}
594fe323 27458@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
27459
27460@item @var{result-record} @expansion{}
27461@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
27462
27463@item @var{out-of-band-record} @expansion{}
27464@code{@var{async-record} | @var{stream-record}}
27465
27466@item @var{async-record} @expansion{}
27467@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
27468
27469@item @var{exec-async-output} @expansion{}
27470@code{[ @var{token} ] "*" @var{async-output}}
27471
27472@item @var{status-async-output} @expansion{}
27473@code{[ @var{token} ] "+" @var{async-output}}
27474
27475@item @var{notify-async-output} @expansion{}
27476@code{[ @var{token} ] "=" @var{async-output}}
27477
27478@item @var{async-output} @expansion{}
27479@code{@var{async-class} ( "," @var{result} )* @var{nl}}
27480
27481@item @var{result-class} @expansion{}
27482@code{"done" | "running" | "connected" | "error" | "exit"}
27483
27484@item @var{async-class} @expansion{}
27485@code{"stopped" | @var{others}} (where @var{others} will be added
27486depending on the needs---this is still in development).
27487
27488@item @var{result} @expansion{}
27489@code{ @var{variable} "=" @var{value}}
27490
27491@item @var{variable} @expansion{}
27492@code{ @var{string} }
27493
27494@item @var{value} @expansion{}
27495@code{ @var{const} | @var{tuple} | @var{list} }
27496
27497@item @var{const} @expansion{}
27498@code{@var{c-string}}
27499
27500@item @var{tuple} @expansion{}
27501@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
27502
27503@item @var{list} @expansion{}
27504@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
27505@var{result} ( "," @var{result} )* "]" }
27506
27507@item @var{stream-record} @expansion{}
27508@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
27509
27510@item @var{console-stream-output} @expansion{}
27511@code{"~" @var{c-string}}
27512
27513@item @var{target-stream-output} @expansion{}
27514@code{"@@" @var{c-string}}
27515
27516@item @var{log-stream-output} @expansion{}
27517@code{"&" @var{c-string}}
27518
27519@item @var{nl} @expansion{}
27520@code{CR | CR-LF}
27521
27522@item @var{token} @expansion{}
27523@emph{any sequence of digits}.
27524@end table
27525
27526@noindent
27527Notes:
27528
27529@itemize @bullet
27530@item
27531All output sequences end in a single line containing a period.
27532
27533@item
721c02de
VP
27534The @code{@var{token}} is from the corresponding request. Note that
27535for all async output, while the token is allowed by the grammar and
27536may be output by future versions of @value{GDBN} for select async
27537output messages, it is generally omitted. Frontends should treat
27538all async output as reporting general changes in the state of the
27539target and there should be no need to associate async output to any
27540prior command.
922fbb7b
AC
27541
27542@item
27543@cindex status output in @sc{gdb/mi}
27544@var{status-async-output} contains on-going status information about the
27545progress of a slow operation. It can be discarded. All status output is
27546prefixed by @samp{+}.
27547
27548@item
27549@cindex async output in @sc{gdb/mi}
27550@var{exec-async-output} contains asynchronous state change on the target
27551(stopped, started, disappeared). All async output is prefixed by
27552@samp{*}.
27553
27554@item
27555@cindex notify output in @sc{gdb/mi}
27556@var{notify-async-output} contains supplementary information that the
27557client should handle (e.g., a new breakpoint information). All notify
27558output is prefixed by @samp{=}.
27559
27560@item
27561@cindex console output in @sc{gdb/mi}
27562@var{console-stream-output} is output that should be displayed as is in the
27563console. It is the textual response to a CLI command. All the console
27564output is prefixed by @samp{~}.
27565
27566@item
27567@cindex target output in @sc{gdb/mi}
27568@var{target-stream-output} is the output produced by the target program.
27569All the target output is prefixed by @samp{@@}.
27570
27571@item
27572@cindex log output in @sc{gdb/mi}
27573@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
27574instance messages that should be displayed as part of an error log. All
27575the log output is prefixed by @samp{&}.
27576
27577@item
27578@cindex list output in @sc{gdb/mi}
27579New @sc{gdb/mi} commands should only output @var{lists} containing
27580@var{values}.
27581
27582
27583@end itemize
27584
27585@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
27586details about the various output records.
27587
922fbb7b
AC
27588@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27589@node GDB/MI Compatibility with CLI
27590@section @sc{gdb/mi} Compatibility with CLI
27591
27592@cindex compatibility, @sc{gdb/mi} and CLI
27593@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 27594
a2c02241
NR
27595For the developers convenience CLI commands can be entered directly,
27596but there may be some unexpected behaviour. For example, commands
27597that query the user will behave as if the user replied yes, breakpoint
27598command lists are not executed and some CLI commands, such as
27599@code{if}, @code{when} and @code{define}, prompt for further input with
27600@samp{>}, which is not valid MI output.
ef21caaf
NR
27601
27602This feature may be removed at some stage in the future and it is
a2c02241
NR
27603recommended that front ends use the @code{-interpreter-exec} command
27604(@pxref{-interpreter-exec}).
922fbb7b 27605
af6eff6f
NR
27606@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27607@node GDB/MI Development and Front Ends
27608@section @sc{gdb/mi} Development and Front Ends
27609@cindex @sc{gdb/mi} development
27610
27611The application which takes the MI output and presents the state of the
27612program being debugged to the user is called a @dfn{front end}.
27613
27614Although @sc{gdb/mi} is still incomplete, it is currently being used
27615by a variety of front ends to @value{GDBN}. This makes it difficult
27616to introduce new functionality without breaking existing usage. This
27617section tries to minimize the problems by describing how the protocol
27618might change.
27619
27620Some changes in MI need not break a carefully designed front end, and
27621for these the MI version will remain unchanged. The following is a
27622list of changes that may occur within one level, so front ends should
27623parse MI output in a way that can handle them:
27624
27625@itemize @bullet
27626@item
27627New MI commands may be added.
27628
27629@item
27630New fields may be added to the output of any MI command.
27631
36ece8b3
NR
27632@item
27633The range of values for fields with specified values, e.g.,
9f708cb2 27634@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 27635
af6eff6f
NR
27636@c The format of field's content e.g type prefix, may change so parse it
27637@c at your own risk. Yes, in general?
27638
27639@c The order of fields may change? Shouldn't really matter but it might
27640@c resolve inconsistencies.
27641@end itemize
27642
27643If the changes are likely to break front ends, the MI version level
27644will be increased by one. This will allow the front end to parse the
27645output according to the MI version. Apart from mi0, new versions of
27646@value{GDBN} will not support old versions of MI and it will be the
27647responsibility of the front end to work with the new one.
27648
27649@c Starting with mi3, add a new command -mi-version that prints the MI
27650@c version?
27651
27652The best way to avoid unexpected changes in MI that might break your front
27653end is to make your project known to @value{GDBN} developers and
7a9a6b69 27654follow development on @email{gdb@@sourceware.org} and
fa0f268d 27655@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
27656@cindex mailing lists
27657
922fbb7b
AC
27658@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27659@node GDB/MI Output Records
27660@section @sc{gdb/mi} Output Records
27661
27662@menu
27663* GDB/MI Result Records::
27664* GDB/MI Stream Records::
82f68b1c 27665* GDB/MI Async Records::
54516a0b 27666* GDB/MI Breakpoint Information::
c3b108f7 27667* GDB/MI Frame Information::
dc146f7c 27668* GDB/MI Thread Information::
4368ebeb 27669* GDB/MI Ada Exception Information::
922fbb7b
AC
27670@end menu
27671
27672@node GDB/MI Result Records
27673@subsection @sc{gdb/mi} Result Records
27674
27675@cindex result records in @sc{gdb/mi}
27676@cindex @sc{gdb/mi}, result records
27677In addition to a number of out-of-band notifications, the response to a
27678@sc{gdb/mi} command includes one of the following result indications:
27679
27680@table @code
27681@findex ^done
27682@item "^done" [ "," @var{results} ]
27683The synchronous operation was successful, @code{@var{results}} are the return
27684values.
27685
27686@item "^running"
27687@findex ^running
8e9c5e02
VP
27688This result record is equivalent to @samp{^done}. Historically, it
27689was output instead of @samp{^done} if the command has resumed the
27690target. This behaviour is maintained for backward compatibility, but
27691all frontends should treat @samp{^done} and @samp{^running}
27692identically and rely on the @samp{*running} output record to determine
27693which threads are resumed.
922fbb7b 27694
ef21caaf
NR
27695@item "^connected"
27696@findex ^connected
3f94c067 27697@value{GDBN} has connected to a remote target.
ef21caaf 27698
922fbb7b
AC
27699@item "^error" "," @var{c-string}
27700@findex ^error
27701The operation failed. The @code{@var{c-string}} contains the corresponding
27702error message.
ef21caaf
NR
27703
27704@item "^exit"
27705@findex ^exit
3f94c067 27706@value{GDBN} has terminated.
ef21caaf 27707
922fbb7b
AC
27708@end table
27709
27710@node GDB/MI Stream Records
27711@subsection @sc{gdb/mi} Stream Records
27712
27713@cindex @sc{gdb/mi}, stream records
27714@cindex stream records in @sc{gdb/mi}
27715@value{GDBN} internally maintains a number of output streams: the console, the
27716target, and the log. The output intended for each of these streams is
27717funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
27718
27719Each stream record begins with a unique @dfn{prefix character} which
27720identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
27721Syntax}). In addition to the prefix, each stream record contains a
27722@code{@var{string-output}}. This is either raw text (with an implicit new
27723line) or a quoted C string (which does not contain an implicit newline).
27724
27725@table @code
27726@item "~" @var{string-output}
27727The console output stream contains text that should be displayed in the
27728CLI console window. It contains the textual responses to CLI commands.
27729
27730@item "@@" @var{string-output}
27731The target output stream contains any textual output from the running
ef21caaf
NR
27732target. This is only present when GDB's event loop is truly
27733asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
27734
27735@item "&" @var{string-output}
27736The log stream contains debugging messages being produced by @value{GDBN}'s
27737internals.
27738@end table
27739
82f68b1c
VP
27740@node GDB/MI Async Records
27741@subsection @sc{gdb/mi} Async Records
922fbb7b 27742
82f68b1c
VP
27743@cindex async records in @sc{gdb/mi}
27744@cindex @sc{gdb/mi}, async records
27745@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 27746additional changes that have occurred. Those changes can either be a
82f68b1c 27747consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
27748target activity (e.g., target stopped).
27749
8eb41542 27750The following is the list of possible async records:
922fbb7b
AC
27751
27752@table @code
034dad6f 27753
e1ac3328
VP
27754@item *running,thread-id="@var{thread}"
27755The target is now running. The @var{thread} field tells which
27756specific thread is now running, and can be @samp{all} if all threads
27757are running. The frontend should assume that no interaction with a
27758running thread is possible after this notification is produced.
27759The frontend should not assume that this notification is output
27760only once for any command. @value{GDBN} may emit this notification
27761several times, either for different threads, because it cannot resume
27762all threads together, or even for a single thread, if the thread must
27763be stepped though some code before letting it run freely.
27764
dc146f7c 27765@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
27766The target has stopped. The @var{reason} field can have one of the
27767following values:
034dad6f
BR
27768
27769@table @code
27770@item breakpoint-hit
27771A breakpoint was reached.
27772@item watchpoint-trigger
27773A watchpoint was triggered.
27774@item read-watchpoint-trigger
27775A read watchpoint was triggered.
27776@item access-watchpoint-trigger
27777An access watchpoint was triggered.
27778@item function-finished
27779An -exec-finish or similar CLI command was accomplished.
27780@item location-reached
27781An -exec-until or similar CLI command was accomplished.
27782@item watchpoint-scope
27783A watchpoint has gone out of scope.
27784@item end-stepping-range
27785An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
27786similar CLI command was accomplished.
27787@item exited-signalled
27788The inferior exited because of a signal.
27789@item exited
27790The inferior exited.
27791@item exited-normally
27792The inferior exited normally.
27793@item signal-received
27794A signal was received by the inferior.
36dfb11c
TT
27795@item solib-event
27796The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
27797This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
27798set or when a @code{catch load} or @code{catch unload} catchpoint is
27799in use (@pxref{Set Catchpoints}).
36dfb11c
TT
27800@item fork
27801The inferior has forked. This is reported when @code{catch fork}
27802(@pxref{Set Catchpoints}) has been used.
27803@item vfork
27804The inferior has vforked. This is reported in when @code{catch vfork}
27805(@pxref{Set Catchpoints}) has been used.
27806@item syscall-entry
27807The inferior entered a system call. This is reported when @code{catch
27808syscall} (@pxref{Set Catchpoints}) has been used.
27809@item syscall-entry
27810The inferior returned from a system call. This is reported when
27811@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
27812@item exec
27813The inferior called @code{exec}. This is reported when @code{catch exec}
27814(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
27815@end table
27816
c3b108f7
VP
27817The @var{id} field identifies the thread that directly caused the stop
27818-- for example by hitting a breakpoint. Depending on whether all-stop
27819mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
27820stop all threads, or only the thread that directly triggered the stop.
27821If all threads are stopped, the @var{stopped} field will have the
27822value of @code{"all"}. Otherwise, the value of the @var{stopped}
27823field will be a list of thread identifiers. Presently, this list will
27824always include a single thread, but frontend should be prepared to see
dc146f7c
VP
27825several threads in the list. The @var{core} field reports the
27826processor core on which the stop event has happened. This field may be absent
27827if such information is not available.
c3b108f7 27828
a79b8f6e
VP
27829@item =thread-group-added,id="@var{id}"
27830@itemx =thread-group-removed,id="@var{id}"
27831A thread group was either added or removed. The @var{id} field
27832contains the @value{GDBN} identifier of the thread group. When a thread
27833group is added, it generally might not be associated with a running
27834process. When a thread group is removed, its id becomes invalid and
27835cannot be used in any way.
27836
27837@item =thread-group-started,id="@var{id}",pid="@var{pid}"
27838A thread group became associated with a running program,
27839either because the program was just started or the thread group
27840was attached to a program. The @var{id} field contains the
27841@value{GDBN} identifier of the thread group. The @var{pid} field
27842contains process identifier, specific to the operating system.
27843
8cf64490 27844@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
27845A thread group is no longer associated with a running program,
27846either because the program has exited, or because it was detached
c3b108f7 27847from. The @var{id} field contains the @value{GDBN} identifier of the
8cf64490
TT
27848thread group. @var{code} is the exit code of the inferior; it exists
27849only when the inferior exited with some code.
c3b108f7
VP
27850
27851@item =thread-created,id="@var{id}",group-id="@var{gid}"
27852@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 27853A thread either was created, or has exited. The @var{id} field
c3b108f7
VP
27854contains the @value{GDBN} identifier of the thread. The @var{gid}
27855field identifies the thread group this thread belongs to.
66bb093b
VP
27856
27857@item =thread-selected,id="@var{id}"
27858Informs that the selected thread was changed as result of the last
27859command. This notification is not emitted as result of @code{-thread-select}
27860command but is emitted whenever an MI command that is not documented
27861to change the selected thread actually changes it. In particular,
27862invoking, directly or indirectly (via user-defined command), the CLI
27863@code{thread} command, will generate this notification.
27864
27865We suggest that in response to this notification, front ends
27866highlight the selected thread and cause subsequent commands to apply to
27867that thread.
27868
c86cf029
VP
27869@item =library-loaded,...
27870Reports that a new library file was loaded by the program. This
27871notification has 4 fields---@var{id}, @var{target-name},
134eb42c 27872@var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
c86cf029
VP
27873opaque identifier of the library. For remote debugging case,
27874@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
27875library file on the target, and on the host respectively. For native
27876debugging, both those fields have the same value. The
f1cbe1d3
TT
27877@var{symbols-loaded} field is emitted only for backward compatibility
27878and should not be relied on to convey any useful information. The
27879@var{thread-group} field, if present, specifies the id of the thread
27880group in whose context the library was loaded. If the field is
27881absent, it means the library was loaded in the context of all present
27882thread groups.
c86cf029
VP
27883
27884@item =library-unloaded,...
134eb42c 27885Reports that a library was unloaded by the program. This notification
c86cf029 27886has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
27887the same meaning as for the @code{=library-loaded} notification.
27888The @var{thread-group} field, if present, specifies the id of the
27889thread group in whose context the library was unloaded. If the field is
27890absent, it means the library was unloaded in the context of all present
27891thread groups.
c86cf029 27892
201b4506
YQ
27893@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
27894@itemx =traceframe-changed,end
27895Reports that the trace frame was changed and its new number is
27896@var{tfnum}. The number of the tracepoint associated with this trace
27897frame is @var{tpnum}.
27898
bb25a15c
YQ
27899@item =tsv-created,name=@var{name},value=@var{value}
27900Reports that the new trace state variable @var{name} is created with
27901value @var{value}.
27902
27903@item =tsv-deleted,name=@var{name}
27904@itemx =tsv-deleted
27905Reports that the trace state variable @var{name} is deleted or all
27906trace state variables are deleted.
27907
8d3788bd
VP
27908@item =breakpoint-created,bkpt=@{...@}
27909@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 27910@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
27911Reports that a breakpoint was created, modified, or deleted,
27912respectively. Only user-visible breakpoints are reported to the MI
27913user.
27914
27915The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
27916breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
27917@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
27918
27919Note that if a breakpoint is emitted in the result record of a
27920command, then it will not also be emitted in an async record.
27921
82a90ccf
YQ
27922@item =record-started,thread-group="@var{id}"
27923@itemx =record-stopped,thread-group="@var{id}"
27924Execution log recording was either started or stopped on an
27925inferior. The @var{id} is the @value{GDBN} identifier of the thread
27926group corresponding to the affected inferior.
27927
5b9afe8a
YQ
27928@item =cmd-param-changed,param=@var{param},value=@var{value}
27929Reports that a parameter of the command @code{set @var{param}} is
27930changed to @var{value}. In the multi-word @code{set} command,
27931the @var{param} is the whole parameter list to @code{set} command.
27932For example, In command @code{set check type on}, @var{param}
27933is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
27934
27935@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
27936Reports that bytes from @var{addr} to @var{data} + @var{len} were
27937written in an inferior. The @var{id} is the identifier of the
27938thread group corresponding to the affected inferior. The optional
27939@code{type="code"} part is reported if the memory written to holds
27940executable code.
82f68b1c
VP
27941@end table
27942
54516a0b
TT
27943@node GDB/MI Breakpoint Information
27944@subsection @sc{gdb/mi} Breakpoint Information
27945
27946When @value{GDBN} reports information about a breakpoint, a
27947tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
27948following fields:
27949
27950@table @code
27951@item number
27952The breakpoint number. For a breakpoint that represents one location
27953of a multi-location breakpoint, this will be a dotted pair, like
27954@samp{1.2}.
27955
27956@item type
27957The type of the breakpoint. For ordinary breakpoints this will be
27958@samp{breakpoint}, but many values are possible.
27959
8ac3646f
TT
27960@item catch-type
27961If the type of the breakpoint is @samp{catchpoint}, then this
27962indicates the exact type of catchpoint.
27963
54516a0b
TT
27964@item disp
27965This is the breakpoint disposition---either @samp{del}, meaning that
27966the breakpoint will be deleted at the next stop, or @samp{keep},
27967meaning that the breakpoint will not be deleted.
27968
27969@item enabled
27970This indicates whether the breakpoint is enabled, in which case the
27971value is @samp{y}, or disabled, in which case the value is @samp{n}.
27972Note that this is not the same as the field @code{enable}.
27973
27974@item addr
27975The address of the breakpoint. This may be a hexidecimal number,
27976giving the address; or the string @samp{<PENDING>}, for a pending
27977breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
27978multiple locations. This field will not be present if no address can
27979be determined. For example, a watchpoint does not have an address.
27980
27981@item func
27982If known, the function in which the breakpoint appears.
27983If not known, this field is not present.
27984
27985@item filename
27986The name of the source file which contains this function, if known.
27987If not known, this field is not present.
27988
27989@item fullname
27990The full file name of the source file which contains this function, if
27991known. If not known, this field is not present.
27992
27993@item line
27994The line number at which this breakpoint appears, if known.
27995If not known, this field is not present.
27996
27997@item at
27998If the source file is not known, this field may be provided. If
27999provided, this holds the address of the breakpoint, possibly followed
28000by a symbol name.
28001
28002@item pending
28003If this breakpoint is pending, this field is present and holds the
28004text used to set the breakpoint, as entered by the user.
28005
28006@item evaluated-by
28007Where this breakpoint's condition is evaluated, either @samp{host} or
28008@samp{target}.
28009
28010@item thread
28011If this is a thread-specific breakpoint, then this identifies the
28012thread in which the breakpoint can trigger.
28013
28014@item task
28015If this breakpoint is restricted to a particular Ada task, then this
28016field will hold the task identifier.
28017
28018@item cond
28019If the breakpoint is conditional, this is the condition expression.
28020
28021@item ignore
28022The ignore count of the breakpoint.
28023
28024@item enable
28025The enable count of the breakpoint.
28026
28027@item traceframe-usage
28028FIXME.
28029
28030@item static-tracepoint-marker-string-id
28031For a static tracepoint, the name of the static tracepoint marker.
28032
28033@item mask
28034For a masked watchpoint, this is the mask.
28035
28036@item pass
28037A tracepoint's pass count.
28038
28039@item original-location
28040The location of the breakpoint as originally specified by the user.
28041This field is optional.
28042
28043@item times
28044The number of times the breakpoint has been hit.
28045
28046@item installed
28047This field is only given for tracepoints. This is either @samp{y},
28048meaning that the tracepoint is installed, or @samp{n}, meaning that it
28049is not.
28050
28051@item what
28052Some extra data, the exact contents of which are type-dependent.
28053
28054@end table
28055
28056For example, here is what the output of @code{-break-insert}
28057(@pxref{GDB/MI Breakpoint Commands}) might be:
28058
28059@smallexample
28060-> -break-insert main
28061<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28062 enabled="y",addr="0x08048564",func="main",file="myprog.c",
28063 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
28064<- (gdb)
28065@end smallexample
28066
c3b108f7
VP
28067@node GDB/MI Frame Information
28068@subsection @sc{gdb/mi} Frame Information
28069
28070Response from many MI commands includes an information about stack
28071frame. This information is a tuple that may have the following
28072fields:
28073
28074@table @code
28075@item level
28076The level of the stack frame. The innermost frame has the level of
28077zero. This field is always present.
28078
28079@item func
28080The name of the function corresponding to the frame. This field may
28081be absent if @value{GDBN} is unable to determine the function name.
28082
28083@item addr
28084The code address for the frame. This field is always present.
28085
28086@item file
28087The name of the source files that correspond to the frame's code
28088address. This field may be absent.
28089
28090@item line
28091The source line corresponding to the frames' code address. This field
28092may be absent.
28093
28094@item from
28095The name of the binary file (either executable or shared library) the
28096corresponds to the frame's code address. This field may be absent.
28097
28098@end table
82f68b1c 28099
dc146f7c
VP
28100@node GDB/MI Thread Information
28101@subsection @sc{gdb/mi} Thread Information
28102
28103Whenever @value{GDBN} has to report an information about a thread, it
28104uses a tuple with the following fields:
28105
28106@table @code
28107@item id
28108The numeric id assigned to the thread by @value{GDBN}. This field is
28109always present.
28110
28111@item target-id
28112Target-specific string identifying the thread. This field is always present.
28113
28114@item details
28115Additional information about the thread provided by the target.
28116It is supposed to be human-readable and not interpreted by the
28117frontend. This field is optional.
28118
28119@item state
28120Either @samp{stopped} or @samp{running}, depending on whether the
28121thread is presently running. This field is always present.
28122
28123@item core
28124The value of this field is an integer number of the processor core the
28125thread was last seen on. This field is optional.
28126@end table
28127
956a9fb9
JB
28128@node GDB/MI Ada Exception Information
28129@subsection @sc{gdb/mi} Ada Exception Information
28130
28131Whenever a @code{*stopped} record is emitted because the program
28132stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
28133@value{GDBN} provides the name of the exception that was raised via
28134the @code{exception-name} field.
922fbb7b 28135
ef21caaf
NR
28136@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28137@node GDB/MI Simple Examples
28138@section Simple Examples of @sc{gdb/mi} Interaction
28139@cindex @sc{gdb/mi}, simple examples
28140
28141This subsection presents several simple examples of interaction using
28142the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
28143following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
28144the output received from @sc{gdb/mi}.
28145
d3e8051b 28146Note the line breaks shown in the examples are here only for
ef21caaf
NR
28147readability, they don't appear in the real output.
28148
79a6e687 28149@subheading Setting a Breakpoint
ef21caaf
NR
28150
28151Setting a breakpoint generates synchronous output which contains detailed
28152information of the breakpoint.
28153
28154@smallexample
28155-> -break-insert main
28156<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28157 enabled="y",addr="0x08048564",func="main",file="myprog.c",
28158 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
28159<- (gdb)
28160@end smallexample
28161
28162@subheading Program Execution
28163
28164Program execution generates asynchronous records and MI gives the
28165reason that execution stopped.
28166
28167@smallexample
28168-> -exec-run
28169<- ^running
28170<- (gdb)
a47ec5fe 28171<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
28172 frame=@{addr="0x08048564",func="main",
28173 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
28174 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
28175<- (gdb)
28176-> -exec-continue
28177<- ^running
28178<- (gdb)
28179<- *stopped,reason="exited-normally"
28180<- (gdb)
28181@end smallexample
28182
3f94c067 28183@subheading Quitting @value{GDBN}
ef21caaf 28184
3f94c067 28185Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
28186
28187@smallexample
28188-> (gdb)
28189<- -gdb-exit
28190<- ^exit
28191@end smallexample
28192
a6b29f87
VP
28193Please note that @samp{^exit} is printed immediately, but it might
28194take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
28195performs necessary cleanups, including killing programs being debugged
28196or disconnecting from debug hardware, so the frontend should wait till
28197@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
28198fails to exit in reasonable time.
28199
a2c02241 28200@subheading A Bad Command
ef21caaf
NR
28201
28202Here's what happens if you pass a non-existent command:
28203
28204@smallexample
28205-> -rubbish
28206<- ^error,msg="Undefined MI command: rubbish"
594fe323 28207<- (gdb)
ef21caaf
NR
28208@end smallexample
28209
28210
922fbb7b
AC
28211@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28212@node GDB/MI Command Description Format
28213@section @sc{gdb/mi} Command Description Format
28214
28215The remaining sections describe blocks of commands. Each block of
28216commands is laid out in a fashion similar to this section.
28217
922fbb7b
AC
28218@subheading Motivation
28219
28220The motivation for this collection of commands.
28221
28222@subheading Introduction
28223
28224A brief introduction to this collection of commands as a whole.
28225
28226@subheading Commands
28227
28228For each command in the block, the following is described:
28229
28230@subsubheading Synopsis
28231
28232@smallexample
28233 -command @var{args}@dots{}
28234@end smallexample
28235
922fbb7b
AC
28236@subsubheading Result
28237
265eeb58 28238@subsubheading @value{GDBN} Command
922fbb7b 28239
265eeb58 28240The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
28241
28242@subsubheading Example
28243
ef21caaf
NR
28244Example(s) formatted for readability. Some of the described commands have
28245not been implemented yet and these are labeled N.A.@: (not available).
28246
28247
922fbb7b 28248@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
28249@node GDB/MI Breakpoint Commands
28250@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
28251
28252@cindex breakpoint commands for @sc{gdb/mi}
28253@cindex @sc{gdb/mi}, breakpoint commands
28254This section documents @sc{gdb/mi} commands for manipulating
28255breakpoints.
28256
28257@subheading The @code{-break-after} Command
28258@findex -break-after
28259
28260@subsubheading Synopsis
28261
28262@smallexample
28263 -break-after @var{number} @var{count}
28264@end smallexample
28265
28266The breakpoint number @var{number} is not in effect until it has been
28267hit @var{count} times. To see how this is reflected in the output of
28268the @samp{-break-list} command, see the description of the
28269@samp{-break-list} command below.
28270
28271@subsubheading @value{GDBN} Command
28272
28273The corresponding @value{GDBN} command is @samp{ignore}.
28274
28275@subsubheading Example
28276
28277@smallexample
594fe323 28278(gdb)
922fbb7b 28279-break-insert main
a47ec5fe
AR
28280^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28281enabled="y",addr="0x000100d0",func="main",file="hello.c",
948d5102 28282fullname="/home/foo/hello.c",line="5",times="0"@}
594fe323 28283(gdb)
922fbb7b
AC
28284-break-after 1 3
28285~
28286^done
594fe323 28287(gdb)
922fbb7b
AC
28288-break-list
28289^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28290hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28291@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28292@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28293@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28294@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28295@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28296body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
28297addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28298line="5",times="0",ignore="3"@}]@}
594fe323 28299(gdb)
922fbb7b
AC
28300@end smallexample
28301
28302@ignore
28303@subheading The @code{-break-catch} Command
28304@findex -break-catch
48cb2d85 28305@end ignore
922fbb7b
AC
28306
28307@subheading The @code{-break-commands} Command
28308@findex -break-commands
922fbb7b 28309
48cb2d85
VP
28310@subsubheading Synopsis
28311
28312@smallexample
28313 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
28314@end smallexample
28315
28316Specifies the CLI commands that should be executed when breakpoint
28317@var{number} is hit. The parameters @var{command1} to @var{commandN}
28318are the commands. If no command is specified, any previously-set
28319commands are cleared. @xref{Break Commands}. Typical use of this
28320functionality is tracing a program, that is, printing of values of
28321some variables whenever breakpoint is hit and then continuing.
28322
28323@subsubheading @value{GDBN} Command
28324
28325The corresponding @value{GDBN} command is @samp{commands}.
28326
28327@subsubheading Example
28328
28329@smallexample
28330(gdb)
28331-break-insert main
28332^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28333enabled="y",addr="0x000100d0",func="main",file="hello.c",
28334fullname="/home/foo/hello.c",line="5",times="0"@}
28335(gdb)
28336-break-commands 1 "print v" "continue"
28337^done
28338(gdb)
28339@end smallexample
922fbb7b
AC
28340
28341@subheading The @code{-break-condition} Command
28342@findex -break-condition
28343
28344@subsubheading Synopsis
28345
28346@smallexample
28347 -break-condition @var{number} @var{expr}
28348@end smallexample
28349
28350Breakpoint @var{number} will stop the program only if the condition in
28351@var{expr} is true. The condition becomes part of the
28352@samp{-break-list} output (see the description of the @samp{-break-list}
28353command below).
28354
28355@subsubheading @value{GDBN} Command
28356
28357The corresponding @value{GDBN} command is @samp{condition}.
28358
28359@subsubheading Example
28360
28361@smallexample
594fe323 28362(gdb)
922fbb7b
AC
28363-break-condition 1 1
28364^done
594fe323 28365(gdb)
922fbb7b
AC
28366-break-list
28367^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28368hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28369@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28370@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28371@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28372@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28373@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28374body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
28375addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28376line="5",cond="1",times="0",ignore="3"@}]@}
594fe323 28377(gdb)
922fbb7b
AC
28378@end smallexample
28379
28380@subheading The @code{-break-delete} Command
28381@findex -break-delete
28382
28383@subsubheading Synopsis
28384
28385@smallexample
28386 -break-delete ( @var{breakpoint} )+
28387@end smallexample
28388
28389Delete the breakpoint(s) whose number(s) are specified in the argument
28390list. This is obviously reflected in the breakpoint list.
28391
79a6e687 28392@subsubheading @value{GDBN} Command
922fbb7b
AC
28393
28394The corresponding @value{GDBN} command is @samp{delete}.
28395
28396@subsubheading Example
28397
28398@smallexample
594fe323 28399(gdb)
922fbb7b
AC
28400-break-delete 1
28401^done
594fe323 28402(gdb)
922fbb7b
AC
28403-break-list
28404^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28405hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28406@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28407@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28408@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28409@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28410@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28411body=[]@}
594fe323 28412(gdb)
922fbb7b
AC
28413@end smallexample
28414
28415@subheading The @code{-break-disable} Command
28416@findex -break-disable
28417
28418@subsubheading Synopsis
28419
28420@smallexample
28421 -break-disable ( @var{breakpoint} )+
28422@end smallexample
28423
28424Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
28425break list is now set to @samp{n} for the named @var{breakpoint}(s).
28426
28427@subsubheading @value{GDBN} Command
28428
28429The corresponding @value{GDBN} command is @samp{disable}.
28430
28431@subsubheading Example
28432
28433@smallexample
594fe323 28434(gdb)
922fbb7b
AC
28435-break-disable 2
28436^done
594fe323 28437(gdb)
922fbb7b
AC
28438-break-list
28439^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28440hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28441@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28442@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28443@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28444@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28445@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28446body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102
NR
28447addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28448line="5",times="0"@}]@}
594fe323 28449(gdb)
922fbb7b
AC
28450@end smallexample
28451
28452@subheading The @code{-break-enable} Command
28453@findex -break-enable
28454
28455@subsubheading Synopsis
28456
28457@smallexample
28458 -break-enable ( @var{breakpoint} )+
28459@end smallexample
28460
28461Enable (previously disabled) @var{breakpoint}(s).
28462
28463@subsubheading @value{GDBN} Command
28464
28465The corresponding @value{GDBN} command is @samp{enable}.
28466
28467@subsubheading Example
28468
28469@smallexample
594fe323 28470(gdb)
922fbb7b
AC
28471-break-enable 2
28472^done
594fe323 28473(gdb)
922fbb7b
AC
28474-break-list
28475^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28476hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28477@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28478@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28479@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28480@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28481@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28482body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
28483addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28484line="5",times="0"@}]@}
594fe323 28485(gdb)
922fbb7b
AC
28486@end smallexample
28487
28488@subheading The @code{-break-info} Command
28489@findex -break-info
28490
28491@subsubheading Synopsis
28492
28493@smallexample
28494 -break-info @var{breakpoint}
28495@end smallexample
28496
28497@c REDUNDANT???
28498Get information about a single breakpoint.
28499
54516a0b
TT
28500The result is a table of breakpoints. @xref{GDB/MI Breakpoint
28501Information}, for details on the format of each breakpoint in the
28502table.
28503
79a6e687 28504@subsubheading @value{GDBN} Command
922fbb7b
AC
28505
28506The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
28507
28508@subsubheading Example
28509N.A.
28510
28511@subheading The @code{-break-insert} Command
28512@findex -break-insert
28513
28514@subsubheading Synopsis
28515
28516@smallexample
18148017 28517 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 28518 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 28519 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
28520@end smallexample
28521
28522@noindent
afe8ab22 28523If specified, @var{location}, can be one of:
922fbb7b
AC
28524
28525@itemize @bullet
28526@item function
28527@c @item +offset
28528@c @item -offset
28529@c @item linenum
28530@item filename:linenum
28531@item filename:function
28532@item *address
28533@end itemize
28534
28535The possible optional parameters of this command are:
28536
28537@table @samp
28538@item -t
948d5102 28539Insert a temporary breakpoint.
922fbb7b
AC
28540@item -h
28541Insert a hardware breakpoint.
afe8ab22
VP
28542@item -f
28543If @var{location} cannot be parsed (for example if it
28544refers to unknown files or functions), create a pending
28545breakpoint. Without this flag, @value{GDBN} will report
28546an error, and won't create a breakpoint, if @var{location}
28547cannot be parsed.
41447f92
VP
28548@item -d
28549Create a disabled breakpoint.
18148017
VP
28550@item -a
28551Create a tracepoint. @xref{Tracepoints}. When this parameter
28552is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
28553@item -c @var{condition}
28554Make the breakpoint conditional on @var{condition}.
28555@item -i @var{ignore-count}
28556Initialize the @var{ignore-count}.
28557@item -p @var{thread-id}
28558Restrict the breakpoint to the specified @var{thread-id}.
922fbb7b
AC
28559@end table
28560
28561@subsubheading Result
28562
54516a0b
TT
28563@xref{GDB/MI Breakpoint Information}, for details on the format of the
28564resulting breakpoint.
922fbb7b
AC
28565
28566Note: this format is open to change.
28567@c An out-of-band breakpoint instead of part of the result?
28568
28569@subsubheading @value{GDBN} Command
28570
28571The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 28572@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
28573
28574@subsubheading Example
28575
28576@smallexample
594fe323 28577(gdb)
922fbb7b 28578-break-insert main
948d5102
NR
28579^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
28580fullname="/home/foo/recursive2.c,line="4",times="0"@}
594fe323 28581(gdb)
922fbb7b 28582-break-insert -t foo
948d5102
NR
28583^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
28584fullname="/home/foo/recursive2.c,line="11",times="0"@}
594fe323 28585(gdb)
922fbb7b
AC
28586-break-list
28587^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28588hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28589@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28590@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28591@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28592@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28593@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28594body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
28595addr="0x0001072c", func="main",file="recursive2.c",
28596fullname="/home/foo/recursive2.c,"line="4",times="0"@},
922fbb7b 28597bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102
NR
28598addr="0x00010774",func="foo",file="recursive2.c",
28599fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
594fe323 28600(gdb)
496ee73e
KS
28601@c -break-insert -r foo.*
28602@c ~int foo(int, int);
28603@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
28604@c "fullname="/home/foo/recursive2.c",line="11",times="0"@}
28605@c (gdb)
922fbb7b
AC
28606@end smallexample
28607
28608@subheading The @code{-break-list} Command
28609@findex -break-list
28610
28611@subsubheading Synopsis
28612
28613@smallexample
28614 -break-list
28615@end smallexample
28616
28617Displays the list of inserted breakpoints, showing the following fields:
28618
28619@table @samp
28620@item Number
28621number of the breakpoint
28622@item Type
28623type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
28624@item Disposition
28625should the breakpoint be deleted or disabled when it is hit: @samp{keep}
28626or @samp{nokeep}
28627@item Enabled
28628is the breakpoint enabled or no: @samp{y} or @samp{n}
28629@item Address
28630memory location at which the breakpoint is set
28631@item What
28632logical location of the breakpoint, expressed by function name, file
28633name, line number
28634@item Times
28635number of times the breakpoint has been hit
28636@end table
28637
28638If there are no breakpoints or watchpoints, the @code{BreakpointTable}
28639@code{body} field is an empty list.
28640
28641@subsubheading @value{GDBN} Command
28642
28643The corresponding @value{GDBN} command is @samp{info break}.
28644
28645@subsubheading Example
28646
28647@smallexample
594fe323 28648(gdb)
922fbb7b
AC
28649-break-list
28650^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28651hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28652@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28653@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28654@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28655@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28656@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28657body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28658addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
28659bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102
NR
28660addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
28661line="13",times="0"@}]@}
594fe323 28662(gdb)
922fbb7b
AC
28663@end smallexample
28664
28665Here's an example of the result when there are no breakpoints:
28666
28667@smallexample
594fe323 28668(gdb)
922fbb7b
AC
28669-break-list
28670^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28671hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28672@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28673@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28674@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28675@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28676@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28677body=[]@}
594fe323 28678(gdb)
922fbb7b
AC
28679@end smallexample
28680
18148017
VP
28681@subheading The @code{-break-passcount} Command
28682@findex -break-passcount
28683
28684@subsubheading Synopsis
28685
28686@smallexample
28687 -break-passcount @var{tracepoint-number} @var{passcount}
28688@end smallexample
28689
28690Set the passcount for tracepoint @var{tracepoint-number} to
28691@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
28692is not a tracepoint, error is emitted. This corresponds to CLI
28693command @samp{passcount}.
28694
922fbb7b
AC
28695@subheading The @code{-break-watch} Command
28696@findex -break-watch
28697
28698@subsubheading Synopsis
28699
28700@smallexample
28701 -break-watch [ -a | -r ]
28702@end smallexample
28703
28704Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 28705@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 28706read from or on a write to the memory location. With the @samp{-r}
d3e8051b 28707option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
28708trigger only when the memory location is accessed for reading. Without
28709either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 28710i.e., it will trigger when the memory location is accessed for writing.
79a6e687 28711@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
28712
28713Note that @samp{-break-list} will report a single list of watchpoints and
28714breakpoints inserted.
28715
28716@subsubheading @value{GDBN} Command
28717
28718The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
28719@samp{rwatch}.
28720
28721@subsubheading Example
28722
28723Setting a watchpoint on a variable in the @code{main} function:
28724
28725@smallexample
594fe323 28726(gdb)
922fbb7b
AC
28727-break-watch x
28728^done,wpt=@{number="2",exp="x"@}
594fe323 28729(gdb)
922fbb7b
AC
28730-exec-continue
28731^running
0869d01b
NR
28732(gdb)
28733*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 28734value=@{old="-268439212",new="55"@},
76ff342d 28735frame=@{func="main",args=[],file="recursive2.c",
948d5102 28736fullname="/home/foo/bar/recursive2.c",line="5"@}
594fe323 28737(gdb)
922fbb7b
AC
28738@end smallexample
28739
28740Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
28741the program execution twice: first for the variable changing value, then
28742for the watchpoint going out of scope.
28743
28744@smallexample
594fe323 28745(gdb)
922fbb7b
AC
28746-break-watch C
28747^done,wpt=@{number="5",exp="C"@}
594fe323 28748(gdb)
922fbb7b
AC
28749-exec-continue
28750^running
0869d01b
NR
28751(gdb)
28752*stopped,reason="watchpoint-trigger",
922fbb7b
AC
28753wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
28754frame=@{func="callee4",args=[],
76ff342d
DJ
28755file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28756fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 28757(gdb)
922fbb7b
AC
28758-exec-continue
28759^running
0869d01b
NR
28760(gdb)
28761*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
28762frame=@{func="callee3",args=[@{name="strarg",
28763value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
28764file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28765fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 28766(gdb)
922fbb7b
AC
28767@end smallexample
28768
28769Listing breakpoints and watchpoints, at different points in the program
28770execution. Note that once the watchpoint goes out of scope, it is
28771deleted.
28772
28773@smallexample
594fe323 28774(gdb)
922fbb7b
AC
28775-break-watch C
28776^done,wpt=@{number="2",exp="C"@}
594fe323 28777(gdb)
922fbb7b
AC
28778-break-list
28779^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28780hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28781@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28782@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28783@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28784@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28785@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28786body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28787addr="0x00010734",func="callee4",
948d5102
NR
28788file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28789fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
922fbb7b
AC
28790bkpt=@{number="2",type="watchpoint",disp="keep",
28791enabled="y",addr="",what="C",times="0"@}]@}
594fe323 28792(gdb)
922fbb7b
AC
28793-exec-continue
28794^running
0869d01b
NR
28795(gdb)
28796*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
28797value=@{old="-276895068",new="3"@},
28798frame=@{func="callee4",args=[],
76ff342d
DJ
28799file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28800fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
594fe323 28801(gdb)
922fbb7b
AC
28802-break-list
28803^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28804hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28805@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28806@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28807@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28808@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28809@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28810body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28811addr="0x00010734",func="callee4",
948d5102
NR
28812file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28813fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
922fbb7b
AC
28814bkpt=@{number="2",type="watchpoint",disp="keep",
28815enabled="y",addr="",what="C",times="-5"@}]@}
594fe323 28816(gdb)
922fbb7b
AC
28817-exec-continue
28818^running
28819^done,reason="watchpoint-scope",wpnum="2",
28820frame=@{func="callee3",args=[@{name="strarg",
28821value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
28822file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28823fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 28824(gdb)
922fbb7b
AC
28825-break-list
28826^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28827hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28828@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28829@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28830@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28831@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28832@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28833body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28834addr="0x00010734",func="callee4",
948d5102
NR
28835file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28836fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
28837times="1"@}]@}
594fe323 28838(gdb)
922fbb7b
AC
28839@end smallexample
28840
3fa7bf06
MG
28841
28842@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28843@node GDB/MI Catchpoint Commands
28844@section @sc{gdb/mi} Catchpoint Commands
28845
28846This section documents @sc{gdb/mi} commands for manipulating
28847catchpoints.
28848
28849@subheading The @code{-catch-load} Command
28850@findex -catch-load
28851
28852@subsubheading Synopsis
28853
28854@smallexample
28855 -catch-load [ -t ] [ -d ] @var{regexp}
28856@end smallexample
28857
28858Add a catchpoint for library load events. If the @samp{-t} option is used,
28859the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
28860Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
28861in a disabled state. The @samp{regexp} argument is a regular
28862expression used to match the name of the loaded library.
28863
28864
28865@subsubheading @value{GDBN} Command
28866
28867The corresponding @value{GDBN} command is @samp{catch load}.
28868
28869@subsubheading Example
28870
28871@smallexample
28872-catch-load -t foo.so
28873^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 28874what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
28875(gdb)
28876@end smallexample
28877
28878
28879@subheading The @code{-catch-unload} Command
28880@findex -catch-unload
28881
28882@subsubheading Synopsis
28883
28884@smallexample
28885 -catch-unload [ -t ] [ -d ] @var{regexp}
28886@end smallexample
28887
28888Add a catchpoint for library unload events. If the @samp{-t} option is
28889used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
28890Breakpoints}). If the @samp{-d} option is used, the catchpoint is
28891created in a disabled state. The @samp{regexp} argument is a regular
28892expression used to match the name of the unloaded library.
28893
28894@subsubheading @value{GDBN} Command
28895
28896The corresponding @value{GDBN} command is @samp{catch unload}.
28897
28898@subsubheading Example
28899
28900@smallexample
28901-catch-unload -d bar.so
28902^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 28903what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
28904(gdb)
28905@end smallexample
28906
28907
922fbb7b 28908@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
28909@node GDB/MI Program Context
28910@section @sc{gdb/mi} Program Context
922fbb7b 28911
a2c02241
NR
28912@subheading The @code{-exec-arguments} Command
28913@findex -exec-arguments
922fbb7b 28914
922fbb7b
AC
28915
28916@subsubheading Synopsis
28917
28918@smallexample
a2c02241 28919 -exec-arguments @var{args}
922fbb7b
AC
28920@end smallexample
28921
a2c02241
NR
28922Set the inferior program arguments, to be used in the next
28923@samp{-exec-run}.
922fbb7b 28924
a2c02241 28925@subsubheading @value{GDBN} Command
922fbb7b 28926
a2c02241 28927The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 28928
a2c02241 28929@subsubheading Example
922fbb7b 28930
fbc5282e
MK
28931@smallexample
28932(gdb)
28933-exec-arguments -v word
28934^done
28935(gdb)
28936@end smallexample
922fbb7b 28937
a2c02241 28938
9901a55b 28939@ignore
a2c02241
NR
28940@subheading The @code{-exec-show-arguments} Command
28941@findex -exec-show-arguments
28942
28943@subsubheading Synopsis
28944
28945@smallexample
28946 -exec-show-arguments
28947@end smallexample
28948
28949Print the arguments of the program.
922fbb7b
AC
28950
28951@subsubheading @value{GDBN} Command
28952
a2c02241 28953The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
28954
28955@subsubheading Example
a2c02241 28956N.A.
9901a55b 28957@end ignore
922fbb7b 28958
922fbb7b 28959
a2c02241
NR
28960@subheading The @code{-environment-cd} Command
28961@findex -environment-cd
922fbb7b 28962
a2c02241 28963@subsubheading Synopsis
922fbb7b
AC
28964
28965@smallexample
a2c02241 28966 -environment-cd @var{pathdir}
922fbb7b
AC
28967@end smallexample
28968
a2c02241 28969Set @value{GDBN}'s working directory.
922fbb7b 28970
a2c02241 28971@subsubheading @value{GDBN} Command
922fbb7b 28972
a2c02241
NR
28973The corresponding @value{GDBN} command is @samp{cd}.
28974
28975@subsubheading Example
922fbb7b
AC
28976
28977@smallexample
594fe323 28978(gdb)
a2c02241
NR
28979-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
28980^done
594fe323 28981(gdb)
922fbb7b
AC
28982@end smallexample
28983
28984
a2c02241
NR
28985@subheading The @code{-environment-directory} Command
28986@findex -environment-directory
922fbb7b
AC
28987
28988@subsubheading Synopsis
28989
28990@smallexample
a2c02241 28991 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
28992@end smallexample
28993
a2c02241
NR
28994Add directories @var{pathdir} to beginning of search path for source files.
28995If the @samp{-r} option is used, the search path is reset to the default
28996search path. If directories @var{pathdir} are supplied in addition to the
28997@samp{-r} option, the search path is first reset and then addition
28998occurs as normal.
28999Multiple directories may be specified, separated by blanks. Specifying
29000multiple directories in a single command
29001results in the directories added to the beginning of the
29002search path in the same order they were presented in the command.
29003If blanks are needed as
29004part of a directory name, double-quotes should be used around
29005the name. In the command output, the path will show up separated
d3e8051b 29006by the system directory-separator character. The directory-separator
a2c02241
NR
29007character must not be used
29008in any directory name.
29009If no directories are specified, the current search path is displayed.
922fbb7b
AC
29010
29011@subsubheading @value{GDBN} Command
29012
a2c02241 29013The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
29014
29015@subsubheading Example
29016
922fbb7b 29017@smallexample
594fe323 29018(gdb)
a2c02241
NR
29019-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29020^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29021(gdb)
a2c02241
NR
29022-environment-directory ""
29023^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29024(gdb)
a2c02241
NR
29025-environment-directory -r /home/jjohnstn/src/gdb /usr/src
29026^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 29027(gdb)
a2c02241
NR
29028-environment-directory -r
29029^done,source-path="$cdir:$cwd"
594fe323 29030(gdb)
922fbb7b
AC
29031@end smallexample
29032
29033
a2c02241
NR
29034@subheading The @code{-environment-path} Command
29035@findex -environment-path
922fbb7b
AC
29036
29037@subsubheading Synopsis
29038
29039@smallexample
a2c02241 29040 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29041@end smallexample
29042
a2c02241
NR
29043Add directories @var{pathdir} to beginning of search path for object files.
29044If the @samp{-r} option is used, the search path is reset to the original
29045search path that existed at gdb start-up. If directories @var{pathdir} are
29046supplied in addition to the
29047@samp{-r} option, the search path is first reset and then addition
29048occurs as normal.
29049Multiple directories may be specified, separated by blanks. Specifying
29050multiple directories in a single command
29051results in the directories added to the beginning of the
29052search path in the same order they were presented in the command.
29053If blanks are needed as
29054part of a directory name, double-quotes should be used around
29055the name. In the command output, the path will show up separated
d3e8051b 29056by the system directory-separator character. The directory-separator
a2c02241
NR
29057character must not be used
29058in any directory name.
29059If no directories are specified, the current path is displayed.
29060
922fbb7b
AC
29061
29062@subsubheading @value{GDBN} Command
29063
a2c02241 29064The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
29065
29066@subsubheading Example
29067
922fbb7b 29068@smallexample
594fe323 29069(gdb)
a2c02241
NR
29070-environment-path
29071^done,path="/usr/bin"
594fe323 29072(gdb)
a2c02241
NR
29073-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
29074^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 29075(gdb)
a2c02241
NR
29076-environment-path -r /usr/local/bin
29077^done,path="/usr/local/bin:/usr/bin"
594fe323 29078(gdb)
922fbb7b
AC
29079@end smallexample
29080
29081
a2c02241
NR
29082@subheading The @code{-environment-pwd} Command
29083@findex -environment-pwd
922fbb7b
AC
29084
29085@subsubheading Synopsis
29086
29087@smallexample
a2c02241 29088 -environment-pwd
922fbb7b
AC
29089@end smallexample
29090
a2c02241 29091Show the current working directory.
922fbb7b 29092
79a6e687 29093@subsubheading @value{GDBN} Command
922fbb7b 29094
a2c02241 29095The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
29096
29097@subsubheading Example
29098
922fbb7b 29099@smallexample
594fe323 29100(gdb)
a2c02241
NR
29101-environment-pwd
29102^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 29103(gdb)
922fbb7b
AC
29104@end smallexample
29105
a2c02241
NR
29106@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29107@node GDB/MI Thread Commands
29108@section @sc{gdb/mi} Thread Commands
29109
29110
29111@subheading The @code{-thread-info} Command
29112@findex -thread-info
922fbb7b
AC
29113
29114@subsubheading Synopsis
29115
29116@smallexample
8e8901c5 29117 -thread-info [ @var{thread-id} ]
922fbb7b
AC
29118@end smallexample
29119
8e8901c5
VP
29120Reports information about either a specific thread, if
29121the @var{thread-id} parameter is present, or about all
29122threads. When printing information about all threads,
29123also reports the current thread.
29124
79a6e687 29125@subsubheading @value{GDBN} Command
922fbb7b 29126
8e8901c5
VP
29127The @samp{info thread} command prints the same information
29128about all threads.
922fbb7b 29129
4694da01 29130@subsubheading Result
922fbb7b 29131
4694da01
TT
29132The result is a list of threads. The following attributes are
29133defined for a given thread:
29134
29135@table @samp
29136@item current
29137This field exists only for the current thread. It has the value @samp{*}.
29138
29139@item id
29140The identifier that @value{GDBN} uses to refer to the thread.
29141
29142@item target-id
29143The identifier that the target uses to refer to the thread.
29144
29145@item details
29146Extra information about the thread, in a target-specific format. This
29147field is optional.
29148
29149@item name
29150The name of the thread. If the user specified a name using the
29151@code{thread name} command, then this name is given. Otherwise, if
29152@value{GDBN} can extract the thread name from the target, then that
29153name is given. If @value{GDBN} cannot find the thread name, then this
29154field is omitted.
29155
29156@item frame
29157The stack frame currently executing in the thread.
922fbb7b 29158
4694da01
TT
29159@item state
29160The thread's state. The @samp{state} field may have the following
29161values:
c3b108f7
VP
29162
29163@table @code
29164@item stopped
29165The thread is stopped. Frame information is available for stopped
29166threads.
29167
29168@item running
29169The thread is running. There's no frame information for running
29170threads.
29171
29172@end table
29173
4694da01
TT
29174@item core
29175If @value{GDBN} can find the CPU core on which this thread is running,
29176then this field is the core identifier. This field is optional.
29177
29178@end table
29179
29180@subsubheading Example
29181
29182@smallexample
29183-thread-info
29184^done,threads=[
29185@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
29186 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
29187 args=[]@},state="running"@},
29188@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
29189 frame=@{level="0",addr="0x0804891f",func="foo",
29190 args=[@{name="i",value="10"@}],
29191 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
29192 state="running"@}],
29193current-thread-id="1"
29194(gdb)
29195@end smallexample
29196
a2c02241
NR
29197@subheading The @code{-thread-list-ids} Command
29198@findex -thread-list-ids
922fbb7b 29199
a2c02241 29200@subsubheading Synopsis
922fbb7b 29201
a2c02241
NR
29202@smallexample
29203 -thread-list-ids
29204@end smallexample
922fbb7b 29205
a2c02241
NR
29206Produces a list of the currently known @value{GDBN} thread ids. At the
29207end of the list it also prints the total number of such threads.
922fbb7b 29208
c3b108f7
VP
29209This command is retained for historical reasons, the
29210@code{-thread-info} command should be used instead.
29211
922fbb7b
AC
29212@subsubheading @value{GDBN} Command
29213
a2c02241 29214Part of @samp{info threads} supplies the same information.
922fbb7b
AC
29215
29216@subsubheading Example
29217
922fbb7b 29218@smallexample
594fe323 29219(gdb)
a2c02241
NR
29220-thread-list-ids
29221^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 29222current-thread-id="1",number-of-threads="3"
594fe323 29223(gdb)
922fbb7b
AC
29224@end smallexample
29225
a2c02241
NR
29226
29227@subheading The @code{-thread-select} Command
29228@findex -thread-select
922fbb7b
AC
29229
29230@subsubheading Synopsis
29231
29232@smallexample
a2c02241 29233 -thread-select @var{threadnum}
922fbb7b
AC
29234@end smallexample
29235
a2c02241
NR
29236Make @var{threadnum} the current thread. It prints the number of the new
29237current thread, and the topmost frame for that thread.
922fbb7b 29238
c3b108f7
VP
29239This command is deprecated in favor of explicitly using the
29240@samp{--thread} option to each command.
29241
922fbb7b
AC
29242@subsubheading @value{GDBN} Command
29243
a2c02241 29244The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
29245
29246@subsubheading Example
922fbb7b
AC
29247
29248@smallexample
594fe323 29249(gdb)
a2c02241
NR
29250-exec-next
29251^running
594fe323 29252(gdb)
a2c02241
NR
29253*stopped,reason="end-stepping-range",thread-id="2",line="187",
29254file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 29255(gdb)
a2c02241
NR
29256-thread-list-ids
29257^done,
29258thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
29259number-of-threads="3"
594fe323 29260(gdb)
a2c02241
NR
29261-thread-select 3
29262^done,new-thread-id="3",
29263frame=@{level="0",func="vprintf",
29264args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
29265@{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
594fe323 29266(gdb)
922fbb7b
AC
29267@end smallexample
29268
5d77fe44
JB
29269@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29270@node GDB/MI Ada Tasking Commands
29271@section @sc{gdb/mi} Ada Tasking Commands
29272
29273@subheading The @code{-ada-task-info} Command
29274@findex -ada-task-info
29275
29276@subsubheading Synopsis
29277
29278@smallexample
29279 -ada-task-info [ @var{task-id} ]
29280@end smallexample
29281
29282Reports information about either a specific Ada task, if the
29283@var{task-id} parameter is present, or about all Ada tasks.
29284
29285@subsubheading @value{GDBN} Command
29286
29287The @samp{info tasks} command prints the same information
29288about all Ada tasks (@pxref{Ada Tasks}).
29289
29290@subsubheading Result
29291
29292The result is a table of Ada tasks. The following columns are
29293defined for each Ada task:
29294
29295@table @samp
29296@item current
29297This field exists only for the current thread. It has the value @samp{*}.
29298
29299@item id
29300The identifier that @value{GDBN} uses to refer to the Ada task.
29301
29302@item task-id
29303The identifier that the target uses to refer to the Ada task.
29304
29305@item thread-id
29306The identifier of the thread corresponding to the Ada task.
29307
29308This field should always exist, as Ada tasks are always implemented
29309on top of a thread. But if @value{GDBN} cannot find this corresponding
29310thread for any reason, the field is omitted.
29311
29312@item parent-id
29313This field exists only when the task was created by another task.
29314In this case, it provides the ID of the parent task.
29315
29316@item priority
29317The base priority of the task.
29318
29319@item state
29320The current state of the task. For a detailed description of the
29321possible states, see @ref{Ada Tasks}.
29322
29323@item name
29324The name of the task.
29325
29326@end table
29327
29328@subsubheading Example
29329
29330@smallexample
29331-ada-task-info
29332^done,tasks=@{nr_rows="3",nr_cols="8",
29333hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
29334@{width="3",alignment="1",col_name="id",colhdr="ID"@},
29335@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
29336@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
29337@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
29338@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
29339@{width="22",alignment="-1",col_name="state",colhdr="State"@},
29340@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
29341body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
29342state="Child Termination Wait",name="main_task"@}]@}
29343(gdb)
29344@end smallexample
29345
a2c02241
NR
29346@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29347@node GDB/MI Program Execution
29348@section @sc{gdb/mi} Program Execution
922fbb7b 29349
ef21caaf 29350These are the asynchronous commands which generate the out-of-band
3f94c067 29351record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
29352asynchronously with remote targets and this interaction is mimicked in
29353other cases.
922fbb7b 29354
922fbb7b
AC
29355@subheading The @code{-exec-continue} Command
29356@findex -exec-continue
29357
29358@subsubheading Synopsis
29359
29360@smallexample
540aa8e7 29361 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
29362@end smallexample
29363
540aa8e7
MS
29364Resumes the execution of the inferior program, which will continue
29365to execute until it reaches a debugger stop event. If the
29366@samp{--reverse} option is specified, execution resumes in reverse until
29367it reaches a stop event. Stop events may include
29368@itemize @bullet
29369@item
29370breakpoints or watchpoints
29371@item
29372signals or exceptions
29373@item
29374the end of the process (or its beginning under @samp{--reverse})
29375@item
29376the end or beginning of a replay log if one is being used.
29377@end itemize
29378In all-stop mode (@pxref{All-Stop
29379Mode}), may resume only one thread, or all threads, depending on the
29380value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 29381specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
29382ignored in all-stop mode. If the @samp{--thread-group} options is
29383specified, then all threads in that thread group are resumed.
922fbb7b
AC
29384
29385@subsubheading @value{GDBN} Command
29386
29387The corresponding @value{GDBN} corresponding is @samp{continue}.
29388
29389@subsubheading Example
29390
29391@smallexample
29392-exec-continue
29393^running
594fe323 29394(gdb)
922fbb7b 29395@@Hello world
a47ec5fe
AR
29396*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
29397func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
29398line="13"@}
594fe323 29399(gdb)
922fbb7b
AC
29400@end smallexample
29401
29402
29403@subheading The @code{-exec-finish} Command
29404@findex -exec-finish
29405
29406@subsubheading Synopsis
29407
29408@smallexample
540aa8e7 29409 -exec-finish [--reverse]
922fbb7b
AC
29410@end smallexample
29411
ef21caaf
NR
29412Resumes the execution of the inferior program until the current
29413function is exited. Displays the results returned by the function.
540aa8e7
MS
29414If the @samp{--reverse} option is specified, resumes the reverse
29415execution of the inferior program until the point where current
29416function was called.
922fbb7b
AC
29417
29418@subsubheading @value{GDBN} Command
29419
29420The corresponding @value{GDBN} command is @samp{finish}.
29421
29422@subsubheading Example
29423
29424Function returning @code{void}.
29425
29426@smallexample
29427-exec-finish
29428^running
594fe323 29429(gdb)
922fbb7b
AC
29430@@hello from foo
29431*stopped,reason="function-finished",frame=@{func="main",args=[],
948d5102 29432file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
594fe323 29433(gdb)
922fbb7b
AC
29434@end smallexample
29435
29436Function returning other than @code{void}. The name of the internal
29437@value{GDBN} variable storing the result is printed, together with the
29438value itself.
29439
29440@smallexample
29441-exec-finish
29442^running
594fe323 29443(gdb)
922fbb7b
AC
29444*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
29445args=[@{name="a",value="1"],@{name="b",value="9"@}@},
948d5102 29446file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
922fbb7b 29447gdb-result-var="$1",return-value="0"
594fe323 29448(gdb)
922fbb7b
AC
29449@end smallexample
29450
29451
29452@subheading The @code{-exec-interrupt} Command
29453@findex -exec-interrupt
29454
29455@subsubheading Synopsis
29456
29457@smallexample
c3b108f7 29458 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
29459@end smallexample
29460
ef21caaf
NR
29461Interrupts the background execution of the target. Note how the token
29462associated with the stop message is the one for the execution command
29463that has been interrupted. The token for the interrupt itself only
29464appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
29465interrupt a non-running program, an error message will be printed.
29466
c3b108f7
VP
29467Note that when asynchronous execution is enabled, this command is
29468asynchronous just like other execution commands. That is, first the
29469@samp{^done} response will be printed, and the target stop will be
29470reported after that using the @samp{*stopped} notification.
29471
29472In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
29473All threads (in all inferiors) will be interrupted if the
29474@samp{--all} option is specified. If the @samp{--thread-group}
29475option is specified, all threads in that group will be interrupted.
c3b108f7 29476
922fbb7b
AC
29477@subsubheading @value{GDBN} Command
29478
29479The corresponding @value{GDBN} command is @samp{interrupt}.
29480
29481@subsubheading Example
29482
29483@smallexample
594fe323 29484(gdb)
922fbb7b
AC
29485111-exec-continue
29486111^running
29487
594fe323 29488(gdb)
922fbb7b
AC
29489222-exec-interrupt
29490222^done
594fe323 29491(gdb)
922fbb7b 29492111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 29493frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
948d5102 29494fullname="/home/foo/bar/try.c",line="13"@}
594fe323 29495(gdb)
922fbb7b 29496
594fe323 29497(gdb)
922fbb7b
AC
29498-exec-interrupt
29499^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 29500(gdb)
922fbb7b
AC
29501@end smallexample
29502
83eba9b7
VP
29503@subheading The @code{-exec-jump} Command
29504@findex -exec-jump
29505
29506@subsubheading Synopsis
29507
29508@smallexample
29509 -exec-jump @var{location}
29510@end smallexample
29511
29512Resumes execution of the inferior program at the location specified by
29513parameter. @xref{Specify Location}, for a description of the
29514different forms of @var{location}.
29515
29516@subsubheading @value{GDBN} Command
29517
29518The corresponding @value{GDBN} command is @samp{jump}.
29519
29520@subsubheading Example
29521
29522@smallexample
29523-exec-jump foo.c:10
29524*running,thread-id="all"
29525^running
29526@end smallexample
29527
922fbb7b
AC
29528
29529@subheading The @code{-exec-next} Command
29530@findex -exec-next
29531
29532@subsubheading Synopsis
29533
29534@smallexample
540aa8e7 29535 -exec-next [--reverse]
922fbb7b
AC
29536@end smallexample
29537
ef21caaf
NR
29538Resumes execution of the inferior program, stopping when the beginning
29539of the next source line is reached.
922fbb7b 29540
540aa8e7
MS
29541If the @samp{--reverse} option is specified, resumes reverse execution
29542of the inferior program, stopping at the beginning of the previous
29543source line. If you issue this command on the first line of a
29544function, it will take you back to the caller of that function, to the
29545source line where the function was called.
29546
29547
922fbb7b
AC
29548@subsubheading @value{GDBN} Command
29549
29550The corresponding @value{GDBN} command is @samp{next}.
29551
29552@subsubheading Example
29553
29554@smallexample
29555-exec-next
29556^running
594fe323 29557(gdb)
922fbb7b 29558*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 29559(gdb)
922fbb7b
AC
29560@end smallexample
29561
29562
29563@subheading The @code{-exec-next-instruction} Command
29564@findex -exec-next-instruction
29565
29566@subsubheading Synopsis
29567
29568@smallexample
540aa8e7 29569 -exec-next-instruction [--reverse]
922fbb7b
AC
29570@end smallexample
29571
ef21caaf
NR
29572Executes one machine instruction. If the instruction is a function
29573call, continues until the function returns. If the program stops at an
29574instruction in the middle of a source line, the address will be
29575printed as well.
922fbb7b 29576
540aa8e7
MS
29577If the @samp{--reverse} option is specified, resumes reverse execution
29578of the inferior program, stopping at the previous instruction. If the
29579previously executed instruction was a return from another function,
29580it will continue to execute in reverse until the call to that function
29581(from the current stack frame) is reached.
29582
922fbb7b
AC
29583@subsubheading @value{GDBN} Command
29584
29585The corresponding @value{GDBN} command is @samp{nexti}.
29586
29587@subsubheading Example
29588
29589@smallexample
594fe323 29590(gdb)
922fbb7b
AC
29591-exec-next-instruction
29592^running
29593
594fe323 29594(gdb)
922fbb7b
AC
29595*stopped,reason="end-stepping-range",
29596addr="0x000100d4",line="5",file="hello.c"
594fe323 29597(gdb)
922fbb7b
AC
29598@end smallexample
29599
29600
29601@subheading The @code{-exec-return} Command
29602@findex -exec-return
29603
29604@subsubheading Synopsis
29605
29606@smallexample
29607 -exec-return
29608@end smallexample
29609
29610Makes current function return immediately. Doesn't execute the inferior.
29611Displays the new current frame.
29612
29613@subsubheading @value{GDBN} Command
29614
29615The corresponding @value{GDBN} command is @samp{return}.
29616
29617@subsubheading Example
29618
29619@smallexample
594fe323 29620(gdb)
922fbb7b
AC
29621200-break-insert callee4
29622200^done,bkpt=@{number="1",addr="0x00010734",
29623file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29624(gdb)
922fbb7b
AC
29625000-exec-run
29626000^running
594fe323 29627(gdb)
a47ec5fe 29628000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 29629frame=@{func="callee4",args=[],
76ff342d
DJ
29630file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29631fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 29632(gdb)
922fbb7b
AC
29633205-break-delete
29634205^done
594fe323 29635(gdb)
922fbb7b
AC
29636111-exec-return
29637111^done,frame=@{level="0",func="callee3",
29638args=[@{name="strarg",
29639value="0x11940 \"A string argument.\""@}],
76ff342d
DJ
29640file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29641fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
594fe323 29642(gdb)
922fbb7b
AC
29643@end smallexample
29644
29645
29646@subheading The @code{-exec-run} Command
29647@findex -exec-run
29648
29649@subsubheading Synopsis
29650
29651@smallexample
a79b8f6e 29652 -exec-run [--all | --thread-group N]
922fbb7b
AC
29653@end smallexample
29654
ef21caaf
NR
29655Starts execution of the inferior from the beginning. The inferior
29656executes until either a breakpoint is encountered or the program
29657exits. In the latter case the output will include an exit code, if
29658the program has exited exceptionally.
922fbb7b 29659
a79b8f6e
VP
29660When no option is specified, the current inferior is started. If the
29661@samp{--thread-group} option is specified, it should refer to a thread
29662group of type @samp{process}, and that thread group will be started.
29663If the @samp{--all} option is specified, then all inferiors will be started.
29664
922fbb7b
AC
29665@subsubheading @value{GDBN} Command
29666
29667The corresponding @value{GDBN} command is @samp{run}.
29668
ef21caaf 29669@subsubheading Examples
922fbb7b
AC
29670
29671@smallexample
594fe323 29672(gdb)
922fbb7b
AC
29673-break-insert main
29674^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 29675(gdb)
922fbb7b
AC
29676-exec-run
29677^running
594fe323 29678(gdb)
a47ec5fe 29679*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 29680frame=@{func="main",args=[],file="recursive2.c",
948d5102 29681fullname="/home/foo/bar/recursive2.c",line="4"@}
594fe323 29682(gdb)
922fbb7b
AC
29683@end smallexample
29684
ef21caaf
NR
29685@noindent
29686Program exited normally:
29687
29688@smallexample
594fe323 29689(gdb)
ef21caaf
NR
29690-exec-run
29691^running
594fe323 29692(gdb)
ef21caaf
NR
29693x = 55
29694*stopped,reason="exited-normally"
594fe323 29695(gdb)
ef21caaf
NR
29696@end smallexample
29697
29698@noindent
29699Program exited exceptionally:
29700
29701@smallexample
594fe323 29702(gdb)
ef21caaf
NR
29703-exec-run
29704^running
594fe323 29705(gdb)
ef21caaf
NR
29706x = 55
29707*stopped,reason="exited",exit-code="01"
594fe323 29708(gdb)
ef21caaf
NR
29709@end smallexample
29710
29711Another way the program can terminate is if it receives a signal such as
29712@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
29713
29714@smallexample
594fe323 29715(gdb)
ef21caaf
NR
29716*stopped,reason="exited-signalled",signal-name="SIGINT",
29717signal-meaning="Interrupt"
29718@end smallexample
29719
922fbb7b 29720
a2c02241
NR
29721@c @subheading -exec-signal
29722
29723
29724@subheading The @code{-exec-step} Command
29725@findex -exec-step
922fbb7b
AC
29726
29727@subsubheading Synopsis
29728
29729@smallexample
540aa8e7 29730 -exec-step [--reverse]
922fbb7b
AC
29731@end smallexample
29732
a2c02241
NR
29733Resumes execution of the inferior program, stopping when the beginning
29734of the next source line is reached, if the next source line is not a
29735function call. If it is, stop at the first instruction of the called
540aa8e7
MS
29736function. If the @samp{--reverse} option is specified, resumes reverse
29737execution of the inferior program, stopping at the beginning of the
29738previously executed source line.
922fbb7b
AC
29739
29740@subsubheading @value{GDBN} Command
29741
a2c02241 29742The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
29743
29744@subsubheading Example
29745
29746Stepping into a function:
29747
29748@smallexample
29749-exec-step
29750^running
594fe323 29751(gdb)
922fbb7b
AC
29752*stopped,reason="end-stepping-range",
29753frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 29754@{name="b",value="0"@}],file="recursive2.c",
948d5102 29755fullname="/home/foo/bar/recursive2.c",line="11"@}
594fe323 29756(gdb)
922fbb7b
AC
29757@end smallexample
29758
29759Regular stepping:
29760
29761@smallexample
29762-exec-step
29763^running
594fe323 29764(gdb)
922fbb7b 29765*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 29766(gdb)
922fbb7b
AC
29767@end smallexample
29768
29769
29770@subheading The @code{-exec-step-instruction} Command
29771@findex -exec-step-instruction
29772
29773@subsubheading Synopsis
29774
29775@smallexample
540aa8e7 29776 -exec-step-instruction [--reverse]
922fbb7b
AC
29777@end smallexample
29778
540aa8e7
MS
29779Resumes the inferior which executes one machine instruction. If the
29780@samp{--reverse} option is specified, resumes reverse execution of the
29781inferior program, stopping at the previously executed instruction.
29782The output, once @value{GDBN} has stopped, will vary depending on
29783whether we have stopped in the middle of a source line or not. In the
29784former case, the address at which the program stopped will be printed
29785as well.
922fbb7b
AC
29786
29787@subsubheading @value{GDBN} Command
29788
29789The corresponding @value{GDBN} command is @samp{stepi}.
29790
29791@subsubheading Example
29792
29793@smallexample
594fe323 29794(gdb)
922fbb7b
AC
29795-exec-step-instruction
29796^running
29797
594fe323 29798(gdb)
922fbb7b 29799*stopped,reason="end-stepping-range",
76ff342d 29800frame=@{func="foo",args=[],file="try.c",
948d5102 29801fullname="/home/foo/bar/try.c",line="10"@}
594fe323 29802(gdb)
922fbb7b
AC
29803-exec-step-instruction
29804^running
29805
594fe323 29806(gdb)
922fbb7b 29807*stopped,reason="end-stepping-range",
76ff342d 29808frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
948d5102 29809fullname="/home/foo/bar/try.c",line="10"@}
594fe323 29810(gdb)
922fbb7b
AC
29811@end smallexample
29812
29813
29814@subheading The @code{-exec-until} Command
29815@findex -exec-until
29816
29817@subsubheading Synopsis
29818
29819@smallexample
29820 -exec-until [ @var{location} ]
29821@end smallexample
29822
ef21caaf
NR
29823Executes the inferior until the @var{location} specified in the
29824argument is reached. If there is no argument, the inferior executes
29825until a source line greater than the current one is reached. The
29826reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
29827
29828@subsubheading @value{GDBN} Command
29829
29830The corresponding @value{GDBN} command is @samp{until}.
29831
29832@subsubheading Example
29833
29834@smallexample
594fe323 29835(gdb)
922fbb7b
AC
29836-exec-until recursive2.c:6
29837^running
594fe323 29838(gdb)
922fbb7b
AC
29839x = 55
29840*stopped,reason="location-reached",frame=@{func="main",args=[],
948d5102 29841file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
594fe323 29842(gdb)
922fbb7b
AC
29843@end smallexample
29844
29845@ignore
29846@subheading -file-clear
29847Is this going away????
29848@end ignore
29849
351ff01a 29850@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
29851@node GDB/MI Stack Manipulation
29852@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 29853
922fbb7b 29854
a2c02241
NR
29855@subheading The @code{-stack-info-frame} Command
29856@findex -stack-info-frame
922fbb7b
AC
29857
29858@subsubheading Synopsis
29859
29860@smallexample
a2c02241 29861 -stack-info-frame
922fbb7b
AC
29862@end smallexample
29863
a2c02241 29864Get info on the selected frame.
922fbb7b
AC
29865
29866@subsubheading @value{GDBN} Command
29867
a2c02241
NR
29868The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
29869(without arguments).
922fbb7b
AC
29870
29871@subsubheading Example
29872
29873@smallexample
594fe323 29874(gdb)
a2c02241
NR
29875-stack-info-frame
29876^done,frame=@{level="1",addr="0x0001076c",func="callee3",
29877file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29878fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
594fe323 29879(gdb)
922fbb7b
AC
29880@end smallexample
29881
a2c02241
NR
29882@subheading The @code{-stack-info-depth} Command
29883@findex -stack-info-depth
922fbb7b
AC
29884
29885@subsubheading Synopsis
29886
29887@smallexample
a2c02241 29888 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
29889@end smallexample
29890
a2c02241
NR
29891Return the depth of the stack. If the integer argument @var{max-depth}
29892is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
29893
29894@subsubheading @value{GDBN} Command
29895
a2c02241 29896There's no equivalent @value{GDBN} command.
922fbb7b
AC
29897
29898@subsubheading Example
29899
a2c02241
NR
29900For a stack with frame levels 0 through 11:
29901
922fbb7b 29902@smallexample
594fe323 29903(gdb)
a2c02241
NR
29904-stack-info-depth
29905^done,depth="12"
594fe323 29906(gdb)
a2c02241
NR
29907-stack-info-depth 4
29908^done,depth="4"
594fe323 29909(gdb)
a2c02241
NR
29910-stack-info-depth 12
29911^done,depth="12"
594fe323 29912(gdb)
a2c02241
NR
29913-stack-info-depth 11
29914^done,depth="11"
594fe323 29915(gdb)
a2c02241
NR
29916-stack-info-depth 13
29917^done,depth="12"
594fe323 29918(gdb)
922fbb7b
AC
29919@end smallexample
29920
a2c02241
NR
29921@subheading The @code{-stack-list-arguments} Command
29922@findex -stack-list-arguments
922fbb7b
AC
29923
29924@subsubheading Synopsis
29925
29926@smallexample
3afae151 29927 -stack-list-arguments @var{print-values}
a2c02241 29928 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
29929@end smallexample
29930
a2c02241
NR
29931Display a list of the arguments for the frames between @var{low-frame}
29932and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
29933@var{high-frame} are not provided, list the arguments for the whole
29934call stack. If the two arguments are equal, show the single frame
29935at the corresponding level. It is an error if @var{low-frame} is
29936larger than the actual number of frames. On the other hand,
29937@var{high-frame} may be larger than the actual number of frames, in
29938which case only existing frames will be returned.
a2c02241 29939
3afae151
VP
29940If @var{print-values} is 0 or @code{--no-values}, print only the names of
29941the variables; if it is 1 or @code{--all-values}, print also their
29942values; and if it is 2 or @code{--simple-values}, print the name,
29943type and value for simple data types, and the name and type for arrays,
29944structures and unions.
922fbb7b 29945
b3372f91
VP
29946Use of this command to obtain arguments in a single frame is
29947deprecated in favor of the @samp{-stack-list-variables} command.
29948
922fbb7b
AC
29949@subsubheading @value{GDBN} Command
29950
a2c02241
NR
29951@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
29952@samp{gdb_get_args} command which partially overlaps with the
29953functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
29954
29955@subsubheading Example
922fbb7b 29956
a2c02241 29957@smallexample
594fe323 29958(gdb)
a2c02241
NR
29959-stack-list-frames
29960^done,
29961stack=[
29962frame=@{level="0",addr="0x00010734",func="callee4",
29963file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29964fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
29965frame=@{level="1",addr="0x0001076c",func="callee3",
29966file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29967fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
29968frame=@{level="2",addr="0x0001078c",func="callee2",
29969file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29970fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
29971frame=@{level="3",addr="0x000107b4",func="callee1",
29972file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29973fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
29974frame=@{level="4",addr="0x000107e0",func="main",
29975file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29976fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
594fe323 29977(gdb)
a2c02241
NR
29978-stack-list-arguments 0
29979^done,
29980stack-args=[
29981frame=@{level="0",args=[]@},
29982frame=@{level="1",args=[name="strarg"]@},
29983frame=@{level="2",args=[name="intarg",name="strarg"]@},
29984frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
29985frame=@{level="4",args=[]@}]
594fe323 29986(gdb)
a2c02241
NR
29987-stack-list-arguments 1
29988^done,
29989stack-args=[
29990frame=@{level="0",args=[]@},
29991frame=@{level="1",
29992 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
29993frame=@{level="2",args=[
29994@{name="intarg",value="2"@},
29995@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
29996@{frame=@{level="3",args=[
29997@{name="intarg",value="2"@},
29998@{name="strarg",value="0x11940 \"A string argument.\""@},
29999@{name="fltarg",value="3.5"@}]@},
30000frame=@{level="4",args=[]@}]
594fe323 30001(gdb)
a2c02241
NR
30002-stack-list-arguments 0 2 2
30003^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 30004(gdb)
a2c02241
NR
30005-stack-list-arguments 1 2 2
30006^done,stack-args=[frame=@{level="2",
30007args=[@{name="intarg",value="2"@},
30008@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 30009(gdb)
a2c02241
NR
30010@end smallexample
30011
30012@c @subheading -stack-list-exception-handlers
922fbb7b 30013
a2c02241
NR
30014
30015@subheading The @code{-stack-list-frames} Command
30016@findex -stack-list-frames
1abaf70c
BR
30017
30018@subsubheading Synopsis
30019
30020@smallexample
a2c02241 30021 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
1abaf70c
BR
30022@end smallexample
30023
a2c02241
NR
30024List the frames currently on the stack. For each frame it displays the
30025following info:
30026
30027@table @samp
30028@item @var{level}
d3e8051b 30029The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
30030@item @var{addr}
30031The @code{$pc} value for that frame.
30032@item @var{func}
30033Function name.
30034@item @var{file}
30035File name of the source file where the function lives.
7d288aaa
TT
30036@item @var{fullname}
30037The full file name of the source file where the function lives.
a2c02241
NR
30038@item @var{line}
30039Line number corresponding to the @code{$pc}.
7d288aaa
TT
30040@item @var{from}
30041The shared library where this function is defined. This is only given
30042if the frame's function is not known.
a2c02241
NR
30043@end table
30044
30045If invoked without arguments, this command prints a backtrace for the
30046whole stack. If given two integer arguments, it shows the frames whose
30047levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
30048are equal, it shows the single frame at the corresponding level. It is
30049an error if @var{low-frame} is larger than the actual number of
a5451f4e 30050frames. On the other hand, @var{high-frame} may be larger than the
2ab1eb7a 30051actual number of frames, in which case only existing frames will be returned.
1abaf70c
BR
30052
30053@subsubheading @value{GDBN} Command
30054
a2c02241 30055The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
30056
30057@subsubheading Example
30058
a2c02241
NR
30059Full stack backtrace:
30060
1abaf70c 30061@smallexample
594fe323 30062(gdb)
a2c02241
NR
30063-stack-list-frames
30064^done,stack=
30065[frame=@{level="0",addr="0x0001076c",func="foo",
30066 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
30067frame=@{level="1",addr="0x000107a4",func="foo",
30068 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30069frame=@{level="2",addr="0x000107a4",func="foo",
30070 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30071frame=@{level="3",addr="0x000107a4",func="foo",
30072 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30073frame=@{level="4",addr="0x000107a4",func="foo",
30074 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30075frame=@{level="5",addr="0x000107a4",func="foo",
30076 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30077frame=@{level="6",addr="0x000107a4",func="foo",
30078 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30079frame=@{level="7",addr="0x000107a4",func="foo",
30080 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30081frame=@{level="8",addr="0x000107a4",func="foo",
30082 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30083frame=@{level="9",addr="0x000107a4",func="foo",
30084 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30085frame=@{level="10",addr="0x000107a4",func="foo",
30086 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30087frame=@{level="11",addr="0x00010738",func="main",
30088 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
594fe323 30089(gdb)
1abaf70c
BR
30090@end smallexample
30091
a2c02241 30092Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 30093
a2c02241 30094@smallexample
594fe323 30095(gdb)
a2c02241
NR
30096-stack-list-frames 3 5
30097^done,stack=
30098[frame=@{level="3",addr="0x000107a4",func="foo",
30099 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30100frame=@{level="4",addr="0x000107a4",func="foo",
30101 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30102frame=@{level="5",addr="0x000107a4",func="foo",
30103 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 30104(gdb)
a2c02241 30105@end smallexample
922fbb7b 30106
a2c02241 30107Show a single frame:
922fbb7b
AC
30108
30109@smallexample
594fe323 30110(gdb)
a2c02241
NR
30111-stack-list-frames 3 3
30112^done,stack=
30113[frame=@{level="3",addr="0x000107a4",func="foo",
30114 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
594fe323 30115(gdb)
922fbb7b
AC
30116@end smallexample
30117
922fbb7b 30118
a2c02241
NR
30119@subheading The @code{-stack-list-locals} Command
30120@findex -stack-list-locals
57c22c6c 30121
a2c02241 30122@subsubheading Synopsis
922fbb7b
AC
30123
30124@smallexample
a2c02241 30125 -stack-list-locals @var{print-values}
922fbb7b
AC
30126@end smallexample
30127
a2c02241
NR
30128Display the local variable names for the selected frame. If
30129@var{print-values} is 0 or @code{--no-values}, print only the names of
30130the variables; if it is 1 or @code{--all-values}, print also their
30131values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 30132type and value for simple data types, and the name and type for arrays,
a2c02241
NR
30133structures and unions. In this last case, a frontend can immediately
30134display the value of simple data types and create variable objects for
d3e8051b 30135other data types when the user wishes to explore their values in
a2c02241 30136more detail.
922fbb7b 30137
b3372f91
VP
30138This command is deprecated in favor of the
30139@samp{-stack-list-variables} command.
30140
922fbb7b
AC
30141@subsubheading @value{GDBN} Command
30142
a2c02241 30143@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
30144
30145@subsubheading Example
922fbb7b
AC
30146
30147@smallexample
594fe323 30148(gdb)
a2c02241
NR
30149-stack-list-locals 0
30150^done,locals=[name="A",name="B",name="C"]
594fe323 30151(gdb)
a2c02241
NR
30152-stack-list-locals --all-values
30153^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
30154 @{name="C",value="@{1, 2, 3@}"@}]
30155-stack-list-locals --simple-values
30156^done,locals=[@{name="A",type="int",value="1"@},
30157 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 30158(gdb)
922fbb7b
AC
30159@end smallexample
30160
b3372f91
VP
30161@subheading The @code{-stack-list-variables} Command
30162@findex -stack-list-variables
30163
30164@subsubheading Synopsis
30165
30166@smallexample
30167 -stack-list-variables @var{print-values}
30168@end smallexample
30169
30170Display the names of local variables and function arguments for the selected frame. If
30171@var{print-values} is 0 or @code{--no-values}, print only the names of
30172the variables; if it is 1 or @code{--all-values}, print also their
30173values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 30174type and value for simple data types, and the name and type for arrays,
b3372f91
VP
30175structures and unions.
30176
30177@subsubheading Example
30178
30179@smallexample
30180(gdb)
30181-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 30182^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
30183(gdb)
30184@end smallexample
30185
922fbb7b 30186
a2c02241
NR
30187@subheading The @code{-stack-select-frame} Command
30188@findex -stack-select-frame
922fbb7b
AC
30189
30190@subsubheading Synopsis
30191
30192@smallexample
a2c02241 30193 -stack-select-frame @var{framenum}
922fbb7b
AC
30194@end smallexample
30195
a2c02241
NR
30196Change the selected frame. Select a different frame @var{framenum} on
30197the stack.
922fbb7b 30198
c3b108f7
VP
30199This command in deprecated in favor of passing the @samp{--frame}
30200option to every command.
30201
922fbb7b
AC
30202@subsubheading @value{GDBN} Command
30203
a2c02241
NR
30204The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
30205@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
30206
30207@subsubheading Example
30208
30209@smallexample
594fe323 30210(gdb)
a2c02241 30211-stack-select-frame 2
922fbb7b 30212^done
594fe323 30213(gdb)
922fbb7b
AC
30214@end smallexample
30215
30216@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30217@node GDB/MI Variable Objects
30218@section @sc{gdb/mi} Variable Objects
922fbb7b 30219
a1b5960f 30220@ignore
922fbb7b 30221
a2c02241 30222@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 30223
a2c02241
NR
30224For the implementation of a variable debugger window (locals, watched
30225expressions, etc.), we are proposing the adaptation of the existing code
30226used by @code{Insight}.
922fbb7b 30227
a2c02241 30228The two main reasons for that are:
922fbb7b 30229
a2c02241
NR
30230@enumerate 1
30231@item
30232It has been proven in practice (it is already on its second generation).
922fbb7b 30233
a2c02241
NR
30234@item
30235It will shorten development time (needless to say how important it is
30236now).
30237@end enumerate
922fbb7b 30238
a2c02241
NR
30239The original interface was designed to be used by Tcl code, so it was
30240slightly changed so it could be used through @sc{gdb/mi}. This section
30241describes the @sc{gdb/mi} operations that will be available and gives some
30242hints about their use.
922fbb7b 30243
a2c02241
NR
30244@emph{Note}: In addition to the set of operations described here, we
30245expect the @sc{gui} implementation of a variable window to require, at
30246least, the following operations:
922fbb7b 30247
a2c02241
NR
30248@itemize @bullet
30249@item @code{-gdb-show} @code{output-radix}
30250@item @code{-stack-list-arguments}
30251@item @code{-stack-list-locals}
30252@item @code{-stack-select-frame}
30253@end itemize
922fbb7b 30254
a1b5960f
VP
30255@end ignore
30256
c8b2f53c 30257@subheading Introduction to Variable Objects
922fbb7b 30258
a2c02241 30259@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
30260
30261Variable objects are "object-oriented" MI interface for examining and
30262changing values of expressions. Unlike some other MI interfaces that
30263work with expressions, variable objects are specifically designed for
30264simple and efficient presentation in the frontend. A variable object
30265is identified by string name. When a variable object is created, the
30266frontend specifies the expression for that variable object. The
30267expression can be a simple variable, or it can be an arbitrary complex
30268expression, and can even involve CPU registers. After creating a
30269variable object, the frontend can invoke other variable object
30270operations---for example to obtain or change the value of a variable
30271object, or to change display format.
30272
30273Variable objects have hierarchical tree structure. Any variable object
30274that corresponds to a composite type, such as structure in C, has
30275a number of child variable objects, for example corresponding to each
30276element of a structure. A child variable object can itself have
30277children, recursively. Recursion ends when we reach
25d5ea92
VP
30278leaf variable objects, which always have built-in types. Child variable
30279objects are created only by explicit request, so if a frontend
30280is not interested in the children of a particular variable object, no
30281child will be created.
c8b2f53c
VP
30282
30283For a leaf variable object it is possible to obtain its value as a
30284string, or set the value from a string. String value can be also
30285obtained for a non-leaf variable object, but it's generally a string
30286that only indicates the type of the object, and does not list its
30287contents. Assignment to a non-leaf variable object is not allowed.
30288
30289A frontend does not need to read the values of all variable objects each time
30290the program stops. Instead, MI provides an update command that lists all
30291variable objects whose values has changed since the last update
30292operation. This considerably reduces the amount of data that must
25d5ea92
VP
30293be transferred to the frontend. As noted above, children variable
30294objects are created on demand, and only leaf variable objects have a
30295real value. As result, gdb will read target memory only for leaf
30296variables that frontend has created.
30297
30298The automatic update is not always desirable. For example, a frontend
30299might want to keep a value of some expression for future reference,
30300and never update it. For another example, fetching memory is
30301relatively slow for embedded targets, so a frontend might want
30302to disable automatic update for the variables that are either not
30303visible on the screen, or ``closed''. This is possible using so
30304called ``frozen variable objects''. Such variable objects are never
30305implicitly updated.
922fbb7b 30306
c3b108f7
VP
30307Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
30308fixed variable object, the expression is parsed when the variable
30309object is created, including associating identifiers to specific
30310variables. The meaning of expression never changes. For a floating
30311variable object the values of variables whose names appear in the
30312expressions are re-evaluated every time in the context of the current
30313frame. Consider this example:
30314
30315@smallexample
30316void do_work(...)
30317@{
30318 struct work_state state;
30319
30320 if (...)
30321 do_work(...);
30322@}
30323@end smallexample
30324
30325If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 30326this function, and we enter the recursive call, the variable
c3b108f7
VP
30327object will report the value of @code{state} in the top-level
30328@code{do_work} invocation. On the other hand, a floating variable
30329object will report the value of @code{state} in the current frame.
30330
30331If an expression specified when creating a fixed variable object
30332refers to a local variable, the variable object becomes bound to the
30333thread and frame in which the variable object is created. When such
30334variable object is updated, @value{GDBN} makes sure that the
30335thread/frame combination the variable object is bound to still exists,
30336and re-evaluates the variable object in context of that thread/frame.
30337
a2c02241
NR
30338The following is the complete set of @sc{gdb/mi} operations defined to
30339access this functionality:
922fbb7b 30340
a2c02241
NR
30341@multitable @columnfractions .4 .6
30342@item @strong{Operation}
30343@tab @strong{Description}
922fbb7b 30344
0cc7d26f
TT
30345@item @code{-enable-pretty-printing}
30346@tab enable Python-based pretty-printing
a2c02241
NR
30347@item @code{-var-create}
30348@tab create a variable object
30349@item @code{-var-delete}
22d8a470 30350@tab delete the variable object and/or its children
a2c02241
NR
30351@item @code{-var-set-format}
30352@tab set the display format of this variable
30353@item @code{-var-show-format}
30354@tab show the display format of this variable
30355@item @code{-var-info-num-children}
30356@tab tells how many children this object has
30357@item @code{-var-list-children}
30358@tab return a list of the object's children
30359@item @code{-var-info-type}
30360@tab show the type of this variable object
30361@item @code{-var-info-expression}
02142340
VP
30362@tab print parent-relative expression that this variable object represents
30363@item @code{-var-info-path-expression}
30364@tab print full expression that this variable object represents
a2c02241
NR
30365@item @code{-var-show-attributes}
30366@tab is this variable editable? does it exist here?
30367@item @code{-var-evaluate-expression}
30368@tab get the value of this variable
30369@item @code{-var-assign}
30370@tab set the value of this variable
30371@item @code{-var-update}
30372@tab update the variable and its children
25d5ea92
VP
30373@item @code{-var-set-frozen}
30374@tab set frozeness attribute
0cc7d26f
TT
30375@item @code{-var-set-update-range}
30376@tab set range of children to display on update
a2c02241 30377@end multitable
922fbb7b 30378
a2c02241
NR
30379In the next subsection we describe each operation in detail and suggest
30380how it can be used.
922fbb7b 30381
a2c02241 30382@subheading Description And Use of Operations on Variable Objects
922fbb7b 30383
0cc7d26f
TT
30384@subheading The @code{-enable-pretty-printing} Command
30385@findex -enable-pretty-printing
30386
30387@smallexample
30388-enable-pretty-printing
30389@end smallexample
30390
30391@value{GDBN} allows Python-based visualizers to affect the output of the
30392MI variable object commands. However, because there was no way to
30393implement this in a fully backward-compatible way, a front end must
30394request that this functionality be enabled.
30395
30396Once enabled, this feature cannot be disabled.
30397
30398Note that if Python support has not been compiled into @value{GDBN},
30399this command will still succeed (and do nothing).
30400
f43030c4
TT
30401This feature is currently (as of @value{GDBN} 7.0) experimental, and
30402may work differently in future versions of @value{GDBN}.
30403
a2c02241
NR
30404@subheading The @code{-var-create} Command
30405@findex -var-create
ef21caaf 30406
a2c02241 30407@subsubheading Synopsis
ef21caaf 30408
a2c02241
NR
30409@smallexample
30410 -var-create @{@var{name} | "-"@}
c3b108f7 30411 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
30412@end smallexample
30413
30414This operation creates a variable object, which allows the monitoring of
30415a variable, the result of an expression, a memory cell or a CPU
30416register.
ef21caaf 30417
a2c02241
NR
30418The @var{name} parameter is the string by which the object can be
30419referenced. It must be unique. If @samp{-} is specified, the varobj
30420system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 30421unique provided that one does not specify @var{name} of that format.
a2c02241 30422The command fails if a duplicate name is found.
ef21caaf 30423
a2c02241
NR
30424The frame under which the expression should be evaluated can be
30425specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
30426frame should be used. A @samp{@@} indicates that a floating variable
30427object must be created.
922fbb7b 30428
a2c02241
NR
30429@var{expression} is any expression valid on the current language set (must not
30430begin with a @samp{*}), or one of the following:
922fbb7b 30431
a2c02241
NR
30432@itemize @bullet
30433@item
30434@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 30435
a2c02241
NR
30436@item
30437@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 30438
a2c02241
NR
30439@item
30440@samp{$@var{regname}} --- a CPU register name
30441@end itemize
922fbb7b 30442
0cc7d26f
TT
30443@cindex dynamic varobj
30444A varobj's contents may be provided by a Python-based pretty-printer. In this
30445case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
30446have slightly different semantics in some cases. If the
30447@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
30448will never create a dynamic varobj. This ensures backward
30449compatibility for existing clients.
30450
a2c02241 30451@subsubheading Result
922fbb7b 30452
0cc7d26f
TT
30453This operation returns attributes of the newly-created varobj. These
30454are:
30455
30456@table @samp
30457@item name
30458The name of the varobj.
30459
30460@item numchild
30461The number of children of the varobj. This number is not necessarily
30462reliable for a dynamic varobj. Instead, you must examine the
30463@samp{has_more} attribute.
30464
30465@item value
30466The varobj's scalar value. For a varobj whose type is some sort of
30467aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
30468will not be interesting.
30469
30470@item type
30471The varobj's type. This is a string representation of the type, as
8264ba82
AG
30472would be printed by the @value{GDBN} CLI. If @samp{print object}
30473(@pxref{Print Settings, set print object}) is set to @code{on}, the
30474@emph{actual} (derived) type of the object is shown rather than the
30475@emph{declared} one.
0cc7d26f
TT
30476
30477@item thread-id
30478If a variable object is bound to a specific thread, then this is the
30479thread's identifier.
30480
30481@item has_more
30482For a dynamic varobj, this indicates whether there appear to be any
30483children available. For a non-dynamic varobj, this will be 0.
30484
30485@item dynamic
30486This attribute will be present and have the value @samp{1} if the
30487varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30488then this attribute will not be present.
30489
30490@item displayhint
30491A dynamic varobj can supply a display hint to the front end. The
30492value comes directly from the Python pretty-printer object's
4c374409 30493@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30494@end table
30495
30496Typical output will look like this:
922fbb7b
AC
30497
30498@smallexample
0cc7d26f
TT
30499 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
30500 has_more="@var{has_more}"
dcaaae04
NR
30501@end smallexample
30502
a2c02241
NR
30503
30504@subheading The @code{-var-delete} Command
30505@findex -var-delete
922fbb7b
AC
30506
30507@subsubheading Synopsis
30508
30509@smallexample
22d8a470 30510 -var-delete [ -c ] @var{name}
922fbb7b
AC
30511@end smallexample
30512
a2c02241 30513Deletes a previously created variable object and all of its children.
22d8a470 30514With the @samp{-c} option, just deletes the children.
922fbb7b 30515
a2c02241 30516Returns an error if the object @var{name} is not found.
922fbb7b 30517
922fbb7b 30518
a2c02241
NR
30519@subheading The @code{-var-set-format} Command
30520@findex -var-set-format
922fbb7b 30521
a2c02241 30522@subsubheading Synopsis
922fbb7b
AC
30523
30524@smallexample
a2c02241 30525 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
30526@end smallexample
30527
a2c02241
NR
30528Sets the output format for the value of the object @var{name} to be
30529@var{format-spec}.
30530
de051565 30531@anchor{-var-set-format}
a2c02241
NR
30532The syntax for the @var{format-spec} is as follows:
30533
30534@smallexample
30535 @var{format-spec} @expansion{}
30536 @{binary | decimal | hexadecimal | octal | natural@}
30537@end smallexample
30538
c8b2f53c
VP
30539The natural format is the default format choosen automatically
30540based on the variable type (like decimal for an @code{int}, hex
30541for pointers, etc.).
30542
30543For a variable with children, the format is set only on the
30544variable itself, and the children are not affected.
a2c02241
NR
30545
30546@subheading The @code{-var-show-format} Command
30547@findex -var-show-format
922fbb7b
AC
30548
30549@subsubheading Synopsis
30550
30551@smallexample
a2c02241 30552 -var-show-format @var{name}
922fbb7b
AC
30553@end smallexample
30554
a2c02241 30555Returns the format used to display the value of the object @var{name}.
922fbb7b 30556
a2c02241
NR
30557@smallexample
30558 @var{format} @expansion{}
30559 @var{format-spec}
30560@end smallexample
922fbb7b 30561
922fbb7b 30562
a2c02241
NR
30563@subheading The @code{-var-info-num-children} Command
30564@findex -var-info-num-children
30565
30566@subsubheading Synopsis
30567
30568@smallexample
30569 -var-info-num-children @var{name}
30570@end smallexample
30571
30572Returns the number of children of a variable object @var{name}:
30573
30574@smallexample
30575 numchild=@var{n}
30576@end smallexample
30577
0cc7d26f
TT
30578Note that this number is not completely reliable for a dynamic varobj.
30579It will return the current number of children, but more children may
30580be available.
30581
a2c02241
NR
30582
30583@subheading The @code{-var-list-children} Command
30584@findex -var-list-children
30585
30586@subsubheading Synopsis
30587
30588@smallexample
0cc7d26f 30589 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 30590@end smallexample
b569d230 30591@anchor{-var-list-children}
a2c02241
NR
30592
30593Return a list of the children of the specified variable object and
30594create variable objects for them, if they do not already exist. With
f5011d11 30595a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
30596@code{--no-values}, print only the names of the variables; if
30597@var{print-values} is 1 or @code{--all-values}, also print their
30598values; and if it is 2 or @code{--simple-values} print the name and
30599value for simple data types and just the name for arrays, structures
30600and unions.
922fbb7b 30601
0cc7d26f
TT
30602@var{from} and @var{to}, if specified, indicate the range of children
30603to report. If @var{from} or @var{to} is less than zero, the range is
30604reset and all children will be reported. Otherwise, children starting
30605at @var{from} (zero-based) and up to and excluding @var{to} will be
30606reported.
30607
30608If a child range is requested, it will only affect the current call to
30609@code{-var-list-children}, but not future calls to @code{-var-update}.
30610For this, you must instead use @code{-var-set-update-range}. The
30611intent of this approach is to enable a front end to implement any
30612update approach it likes; for example, scrolling a view may cause the
30613front end to request more children with @code{-var-list-children}, and
30614then the front end could call @code{-var-set-update-range} with a
30615different range to ensure that future updates are restricted to just
30616the visible items.
30617
b569d230
EZ
30618For each child the following results are returned:
30619
30620@table @var
30621
30622@item name
30623Name of the variable object created for this child.
30624
30625@item exp
30626The expression to be shown to the user by the front end to designate this child.
30627For example this may be the name of a structure member.
30628
0cc7d26f
TT
30629For a dynamic varobj, this value cannot be used to form an
30630expression. There is no way to do this at all with a dynamic varobj.
30631
b569d230
EZ
30632For C/C@t{++} structures there are several pseudo children returned to
30633designate access qualifiers. For these pseudo children @var{exp} is
30634@samp{public}, @samp{private}, or @samp{protected}. In this case the
30635type and value are not present.
30636
0cc7d26f
TT
30637A dynamic varobj will not report the access qualifying
30638pseudo-children, regardless of the language. This information is not
30639available at all with a dynamic varobj.
30640
b569d230 30641@item numchild
0cc7d26f
TT
30642Number of children this child has. For a dynamic varobj, this will be
306430.
b569d230
EZ
30644
30645@item type
8264ba82
AG
30646The type of the child. If @samp{print object}
30647(@pxref{Print Settings, set print object}) is set to @code{on}, the
30648@emph{actual} (derived) type of the object is shown rather than the
30649@emph{declared} one.
b569d230
EZ
30650
30651@item value
30652If values were requested, this is the value.
30653
30654@item thread-id
30655If this variable object is associated with a thread, this is the thread id.
30656Otherwise this result is not present.
30657
30658@item frozen
30659If the variable object is frozen, this variable will be present with a value of 1.
30660@end table
30661
0cc7d26f
TT
30662The result may have its own attributes:
30663
30664@table @samp
30665@item displayhint
30666A dynamic varobj can supply a display hint to the front end. The
30667value comes directly from the Python pretty-printer object's
4c374409 30668@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
30669
30670@item has_more
30671This is an integer attribute which is nonzero if there are children
30672remaining after the end of the selected range.
30673@end table
30674
922fbb7b
AC
30675@subsubheading Example
30676
30677@smallexample
594fe323 30678(gdb)
a2c02241 30679 -var-list-children n
b569d230 30680 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30681 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 30682(gdb)
a2c02241 30683 -var-list-children --all-values n
b569d230 30684 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 30685 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
30686@end smallexample
30687
922fbb7b 30688
a2c02241
NR
30689@subheading The @code{-var-info-type} Command
30690@findex -var-info-type
922fbb7b 30691
a2c02241
NR
30692@subsubheading Synopsis
30693
30694@smallexample
30695 -var-info-type @var{name}
30696@end smallexample
30697
30698Returns the type of the specified variable @var{name}. The type is
30699returned as a string in the same format as it is output by the
30700@value{GDBN} CLI:
30701
30702@smallexample
30703 type=@var{typename}
30704@end smallexample
30705
30706
30707@subheading The @code{-var-info-expression} Command
30708@findex -var-info-expression
922fbb7b
AC
30709
30710@subsubheading Synopsis
30711
30712@smallexample
a2c02241 30713 -var-info-expression @var{name}
922fbb7b
AC
30714@end smallexample
30715
02142340
VP
30716Returns a string that is suitable for presenting this
30717variable object in user interface. The string is generally
30718not valid expression in the current language, and cannot be evaluated.
30719
30720For example, if @code{a} is an array, and variable object
30721@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 30722
a2c02241 30723@smallexample
02142340
VP
30724(gdb) -var-info-expression A.1
30725^done,lang="C",exp="1"
a2c02241 30726@end smallexample
922fbb7b 30727
a2c02241 30728@noindent
02142340
VP
30729Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
30730
30731Note that the output of the @code{-var-list-children} command also
30732includes those expressions, so the @code{-var-info-expression} command
30733is of limited use.
30734
30735@subheading The @code{-var-info-path-expression} Command
30736@findex -var-info-path-expression
30737
30738@subsubheading Synopsis
30739
30740@smallexample
30741 -var-info-path-expression @var{name}
30742@end smallexample
30743
30744Returns an expression that can be evaluated in the current
30745context and will yield the same value that a variable object has.
30746Compare this with the @code{-var-info-expression} command, which
30747result can be used only for UI presentation. Typical use of
30748the @code{-var-info-path-expression} command is creating a
30749watchpoint from a variable object.
30750
0cc7d26f
TT
30751This command is currently not valid for children of a dynamic varobj,
30752and will give an error when invoked on one.
30753
02142340
VP
30754For example, suppose @code{C} is a C@t{++} class, derived from class
30755@code{Base}, and that the @code{Base} class has a member called
30756@code{m_size}. Assume a variable @code{c} is has the type of
30757@code{C} and a variable object @code{C} was created for variable
30758@code{c}. Then, we'll get this output:
30759@smallexample
30760(gdb) -var-info-path-expression C.Base.public.m_size
30761^done,path_expr=((Base)c).m_size)
30762@end smallexample
922fbb7b 30763
a2c02241
NR
30764@subheading The @code{-var-show-attributes} Command
30765@findex -var-show-attributes
922fbb7b 30766
a2c02241 30767@subsubheading Synopsis
922fbb7b 30768
a2c02241
NR
30769@smallexample
30770 -var-show-attributes @var{name}
30771@end smallexample
922fbb7b 30772
a2c02241 30773List attributes of the specified variable object @var{name}:
922fbb7b
AC
30774
30775@smallexample
a2c02241 30776 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
30777@end smallexample
30778
a2c02241
NR
30779@noindent
30780where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
30781
30782@subheading The @code{-var-evaluate-expression} Command
30783@findex -var-evaluate-expression
30784
30785@subsubheading Synopsis
30786
30787@smallexample
de051565 30788 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
30789@end smallexample
30790
30791Evaluates the expression that is represented by the specified variable
de051565
MK
30792object and returns its value as a string. The format of the string
30793can be specified with the @samp{-f} option. The possible values of
30794this option are the same as for @code{-var-set-format}
30795(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
30796the current display format will be used. The current display format
30797can be changed using the @code{-var-set-format} command.
a2c02241
NR
30798
30799@smallexample
30800 value=@var{value}
30801@end smallexample
30802
30803Note that one must invoke @code{-var-list-children} for a variable
30804before the value of a child variable can be evaluated.
30805
30806@subheading The @code{-var-assign} Command
30807@findex -var-assign
30808
30809@subsubheading Synopsis
30810
30811@smallexample
30812 -var-assign @var{name} @var{expression}
30813@end smallexample
30814
30815Assigns the value of @var{expression} to the variable object specified
30816by @var{name}. The object must be @samp{editable}. If the variable's
30817value is altered by the assign, the variable will show up in any
30818subsequent @code{-var-update} list.
30819
30820@subsubheading Example
922fbb7b
AC
30821
30822@smallexample
594fe323 30823(gdb)
a2c02241
NR
30824-var-assign var1 3
30825^done,value="3"
594fe323 30826(gdb)
a2c02241
NR
30827-var-update *
30828^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 30829(gdb)
922fbb7b
AC
30830@end smallexample
30831
a2c02241
NR
30832@subheading The @code{-var-update} Command
30833@findex -var-update
30834
30835@subsubheading Synopsis
30836
30837@smallexample
30838 -var-update [@var{print-values}] @{@var{name} | "*"@}
30839@end smallexample
30840
c8b2f53c
VP
30841Reevaluate the expressions corresponding to the variable object
30842@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
30843list of variable objects whose values have changed; @var{name} must
30844be a root variable object. Here, ``changed'' means that the result of
30845@code{-var-evaluate-expression} before and after the
30846@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
30847object names, all existing variable objects are updated, except
30848for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 30849@var{print-values} determines whether both names and values, or just
de051565 30850names are printed. The possible values of this option are the same
36ece8b3
NR
30851as for @code{-var-list-children} (@pxref{-var-list-children}). It is
30852recommended to use the @samp{--all-values} option, to reduce the
30853number of MI commands needed on each program stop.
c8b2f53c 30854
c3b108f7
VP
30855With the @samp{*} parameter, if a variable object is bound to a
30856currently running thread, it will not be updated, without any
30857diagnostic.
a2c02241 30858
0cc7d26f
TT
30859If @code{-var-set-update-range} was previously used on a varobj, then
30860only the selected range of children will be reported.
922fbb7b 30861
0cc7d26f
TT
30862@code{-var-update} reports all the changed varobjs in a tuple named
30863@samp{changelist}.
30864
30865Each item in the change list is itself a tuple holding:
30866
30867@table @samp
30868@item name
30869The name of the varobj.
30870
30871@item value
30872If values were requested for this update, then this field will be
30873present and will hold the value of the varobj.
922fbb7b 30874
0cc7d26f 30875@item in_scope
9f708cb2 30876@anchor{-var-update}
0cc7d26f 30877This field is a string which may take one of three values:
36ece8b3
NR
30878
30879@table @code
30880@item "true"
30881The variable object's current value is valid.
30882
30883@item "false"
30884The variable object does not currently hold a valid value but it may
30885hold one in the future if its associated expression comes back into
30886scope.
30887
30888@item "invalid"
30889The variable object no longer holds a valid value.
30890This can occur when the executable file being debugged has changed,
30891either through recompilation or by using the @value{GDBN} @code{file}
30892command. The front end should normally choose to delete these variable
30893objects.
30894@end table
30895
30896In the future new values may be added to this list so the front should
30897be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
30898
0cc7d26f
TT
30899@item type_changed
30900This is only present if the varobj is still valid. If the type
30901changed, then this will be the string @samp{true}; otherwise it will
30902be @samp{false}.
30903
7191c139
JB
30904When a varobj's type changes, its children are also likely to have
30905become incorrect. Therefore, the varobj's children are automatically
30906deleted when this attribute is @samp{true}. Also, the varobj's update
30907range, when set using the @code{-var-set-update-range} command, is
30908unset.
30909
0cc7d26f
TT
30910@item new_type
30911If the varobj's type changed, then this field will be present and will
30912hold the new type.
30913
30914@item new_num_children
30915For a dynamic varobj, if the number of children changed, or if the
30916type changed, this will be the new number of children.
30917
30918The @samp{numchild} field in other varobj responses is generally not
30919valid for a dynamic varobj -- it will show the number of children that
30920@value{GDBN} knows about, but because dynamic varobjs lazily
30921instantiate their children, this will not reflect the number of
30922children which may be available.
30923
30924The @samp{new_num_children} attribute only reports changes to the
30925number of children known by @value{GDBN}. This is the only way to
30926detect whether an update has removed children (which necessarily can
30927only happen at the end of the update range).
30928
30929@item displayhint
30930The display hint, if any.
30931
30932@item has_more
30933This is an integer value, which will be 1 if there are more children
30934available outside the varobj's update range.
30935
30936@item dynamic
30937This attribute will be present and have the value @samp{1} if the
30938varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
30939then this attribute will not be present.
30940
30941@item new_children
30942If new children were added to a dynamic varobj within the selected
30943update range (as set by @code{-var-set-update-range}), then they will
30944be listed in this attribute.
30945@end table
30946
30947@subsubheading Example
30948
30949@smallexample
30950(gdb)
30951-var-assign var1 3
30952^done,value="3"
30953(gdb)
30954-var-update --all-values var1
30955^done,changelist=[@{name="var1",value="3",in_scope="true",
30956type_changed="false"@}]
30957(gdb)
30958@end smallexample
30959
25d5ea92
VP
30960@subheading The @code{-var-set-frozen} Command
30961@findex -var-set-frozen
9f708cb2 30962@anchor{-var-set-frozen}
25d5ea92
VP
30963
30964@subsubheading Synopsis
30965
30966@smallexample
9f708cb2 30967 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
30968@end smallexample
30969
9f708cb2 30970Set the frozenness flag on the variable object @var{name}. The
25d5ea92 30971@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 30972frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 30973frozen, then neither itself, nor any of its children, are
9f708cb2 30974implicitly updated by @code{-var-update} of
25d5ea92
VP
30975a parent variable or by @code{-var-update *}. Only
30976@code{-var-update} of the variable itself will update its value and
30977values of its children. After a variable object is unfrozen, it is
30978implicitly updated by all subsequent @code{-var-update} operations.
30979Unfreezing a variable does not update it, only subsequent
30980@code{-var-update} does.
30981
30982@subsubheading Example
30983
30984@smallexample
30985(gdb)
30986-var-set-frozen V 1
30987^done
30988(gdb)
30989@end smallexample
30990
0cc7d26f
TT
30991@subheading The @code{-var-set-update-range} command
30992@findex -var-set-update-range
30993@anchor{-var-set-update-range}
30994
30995@subsubheading Synopsis
30996
30997@smallexample
30998 -var-set-update-range @var{name} @var{from} @var{to}
30999@end smallexample
31000
31001Set the range of children to be returned by future invocations of
31002@code{-var-update}.
31003
31004@var{from} and @var{to} indicate the range of children to report. If
31005@var{from} or @var{to} is less than zero, the range is reset and all
31006children will be reported. Otherwise, children starting at @var{from}
31007(zero-based) and up to and excluding @var{to} will be reported.
31008
31009@subsubheading Example
31010
31011@smallexample
31012(gdb)
31013-var-set-update-range V 1 2
31014^done
31015@end smallexample
31016
b6313243
TT
31017@subheading The @code{-var-set-visualizer} command
31018@findex -var-set-visualizer
31019@anchor{-var-set-visualizer}
31020
31021@subsubheading Synopsis
31022
31023@smallexample
31024 -var-set-visualizer @var{name} @var{visualizer}
31025@end smallexample
31026
31027Set a visualizer for the variable object @var{name}.
31028
31029@var{visualizer} is the visualizer to use. The special value
31030@samp{None} means to disable any visualizer in use.
31031
31032If not @samp{None}, @var{visualizer} must be a Python expression.
31033This expression must evaluate to a callable object which accepts a
31034single argument. @value{GDBN} will call this object with the value of
31035the varobj @var{name} as an argument (this is done so that the same
31036Python pretty-printing code can be used for both the CLI and MI).
31037When called, this object must return an object which conforms to the
4c374409 31038pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
31039
31040The pre-defined function @code{gdb.default_visualizer} may be used to
31041select a visualizer by following the built-in process
31042(@pxref{Selecting Pretty-Printers}). This is done automatically when
31043a varobj is created, and so ordinarily is not needed.
31044
31045This feature is only available if Python support is enabled. The MI
31046command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
31047can be used to check this.
31048
31049@subsubheading Example
31050
31051Resetting the visualizer:
31052
31053@smallexample
31054(gdb)
31055-var-set-visualizer V None
31056^done
31057@end smallexample
31058
31059Reselecting the default (type-based) visualizer:
31060
31061@smallexample
31062(gdb)
31063-var-set-visualizer V gdb.default_visualizer
31064^done
31065@end smallexample
31066
31067Suppose @code{SomeClass} is a visualizer class. A lambda expression
31068can be used to instantiate this class for a varobj:
31069
31070@smallexample
31071(gdb)
31072-var-set-visualizer V "lambda val: SomeClass()"
31073^done
31074@end smallexample
25d5ea92 31075
a2c02241
NR
31076@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31077@node GDB/MI Data Manipulation
31078@section @sc{gdb/mi} Data Manipulation
922fbb7b 31079
a2c02241
NR
31080@cindex data manipulation, in @sc{gdb/mi}
31081@cindex @sc{gdb/mi}, data manipulation
31082This section describes the @sc{gdb/mi} commands that manipulate data:
31083examine memory and registers, evaluate expressions, etc.
31084
31085@c REMOVED FROM THE INTERFACE.
31086@c @subheading -data-assign
31087@c Change the value of a program variable. Plenty of side effects.
79a6e687 31088@c @subsubheading GDB Command
a2c02241
NR
31089@c set variable
31090@c @subsubheading Example
31091@c N.A.
31092
31093@subheading The @code{-data-disassemble} Command
31094@findex -data-disassemble
922fbb7b
AC
31095
31096@subsubheading Synopsis
31097
31098@smallexample
a2c02241
NR
31099 -data-disassemble
31100 [ -s @var{start-addr} -e @var{end-addr} ]
31101 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
31102 -- @var{mode}
922fbb7b
AC
31103@end smallexample
31104
a2c02241
NR
31105@noindent
31106Where:
31107
31108@table @samp
31109@item @var{start-addr}
31110is the beginning address (or @code{$pc})
31111@item @var{end-addr}
31112is the end address
31113@item @var{filename}
31114is the name of the file to disassemble
31115@item @var{linenum}
31116is the line number to disassemble around
31117@item @var{lines}
d3e8051b 31118is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
31119the whole function will be disassembled, in case no @var{end-addr} is
31120specified. If @var{end-addr} is specified as a non-zero value, and
31121@var{lines} is lower than the number of disassembly lines between
31122@var{start-addr} and @var{end-addr}, only @var{lines} lines are
31123displayed; if @var{lines} is higher than the number of lines between
31124@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
31125are displayed.
31126@item @var{mode}
b716877b
AB
31127is either 0 (meaning only disassembly), 1 (meaning mixed source and
31128disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
31129mixed source and disassembly with raw opcodes).
a2c02241
NR
31130@end table
31131
31132@subsubheading Result
31133
ed8a1c2d
AB
31134The result of the @code{-data-disassemble} command will be a list named
31135@samp{asm_insns}, the contents of this list depend on the @var{mode}
31136used with the @code{-data-disassemble} command.
a2c02241 31137
ed8a1c2d
AB
31138For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
31139following fields:
31140
31141@table @code
31142@item address
31143The address at which this instruction was disassembled.
31144
31145@item func-name
31146The name of the function this instruction is within.
31147
31148@item offset
31149The decimal offset in bytes from the start of @samp{func-name}.
31150
31151@item inst
31152The text disassembly for this @samp{address}.
31153
31154@item opcodes
31155This field is only present for mode 2. This contains the raw opcode
31156bytes for the @samp{inst} field.
31157
31158@end table
31159
31160For modes 1 and 3 the @samp{asm_insns} list contains tuples named
31161@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 31162
ed8a1c2d
AB
31163@table @code
31164@item line
31165The line number within @samp{file}.
31166
31167@item file
31168The file name from the compilation unit. This might be an absolute
31169file name or a relative file name depending on the compile command
31170used.
31171
31172@item fullname
f35a17b5
JK
31173Absolute file name of @samp{file}. It is converted to a canonical form
31174using the source file search path
31175(@pxref{Source Path, ,Specifying Source Directories})
31176and after resolving all the symbolic links.
31177
31178If the source file is not found this field will contain the path as
31179present in the debug information.
ed8a1c2d
AB
31180
31181@item line_asm_insn
31182This is a list of tuples containing the disassembly for @samp{line} in
31183@samp{file}. The fields of each tuple are the same as for
31184@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
31185@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
31186@samp{opcodes}.
31187
31188@end table
31189
31190Note that whatever included in the @samp{inst} field, is not
31191manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
31192adjust its format.
922fbb7b
AC
31193
31194@subsubheading @value{GDBN} Command
31195
ed8a1c2d 31196The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
31197
31198@subsubheading Example
31199
a2c02241
NR
31200Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
31201
922fbb7b 31202@smallexample
594fe323 31203(gdb)
a2c02241
NR
31204-data-disassemble -s $pc -e "$pc + 20" -- 0
31205^done,
31206asm_insns=[
31207@{address="0x000107c0",func-name="main",offset="4",
31208inst="mov 2, %o0"@},
31209@{address="0x000107c4",func-name="main",offset="8",
31210inst="sethi %hi(0x11800), %o2"@},
31211@{address="0x000107c8",func-name="main",offset="12",
31212inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
31213@{address="0x000107cc",func-name="main",offset="16",
31214inst="sethi %hi(0x11800), %o2"@},
31215@{address="0x000107d0",func-name="main",offset="20",
31216inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 31217(gdb)
a2c02241
NR
31218@end smallexample
31219
31220Disassemble the whole @code{main} function. Line 32 is part of
31221@code{main}.
31222
31223@smallexample
31224-data-disassemble -f basics.c -l 32 -- 0
31225^done,asm_insns=[
31226@{address="0x000107bc",func-name="main",offset="0",
31227inst="save %sp, -112, %sp"@},
31228@{address="0x000107c0",func-name="main",offset="4",
31229inst="mov 2, %o0"@},
31230@{address="0x000107c4",func-name="main",offset="8",
31231inst="sethi %hi(0x11800), %o2"@},
31232[@dots{}]
31233@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
31234@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 31235(gdb)
922fbb7b
AC
31236@end smallexample
31237
a2c02241 31238Disassemble 3 instructions from the start of @code{main}:
922fbb7b 31239
a2c02241 31240@smallexample
594fe323 31241(gdb)
a2c02241
NR
31242-data-disassemble -f basics.c -l 32 -n 3 -- 0
31243^done,asm_insns=[
31244@{address="0x000107bc",func-name="main",offset="0",
31245inst="save %sp, -112, %sp"@},
31246@{address="0x000107c0",func-name="main",offset="4",
31247inst="mov 2, %o0"@},
31248@{address="0x000107c4",func-name="main",offset="8",
31249inst="sethi %hi(0x11800), %o2"@}]
594fe323 31250(gdb)
a2c02241
NR
31251@end smallexample
31252
31253Disassemble 3 instructions from the start of @code{main} in mixed mode:
31254
31255@smallexample
594fe323 31256(gdb)
a2c02241
NR
31257-data-disassemble -f basics.c -l 32 -n 3 -- 1
31258^done,asm_insns=[
31259src_and_asm_line=@{line="31",
ed8a1c2d
AB
31260file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31261fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31262line_asm_insn=[@{address="0x000107bc",
31263func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 31264src_and_asm_line=@{line="32",
ed8a1c2d
AB
31265file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31266fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31267line_asm_insn=[@{address="0x000107c0",
31268func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
31269@{address="0x000107c4",func-name="main",offset="8",
31270inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 31271(gdb)
a2c02241
NR
31272@end smallexample
31273
31274
31275@subheading The @code{-data-evaluate-expression} Command
31276@findex -data-evaluate-expression
922fbb7b
AC
31277
31278@subsubheading Synopsis
31279
31280@smallexample
a2c02241 31281 -data-evaluate-expression @var{expr}
922fbb7b
AC
31282@end smallexample
31283
a2c02241
NR
31284Evaluate @var{expr} as an expression. The expression could contain an
31285inferior function call. The function call will execute synchronously.
31286If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
31287
31288@subsubheading @value{GDBN} Command
31289
a2c02241
NR
31290The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
31291@samp{call}. In @code{gdbtk} only, there's a corresponding
31292@samp{gdb_eval} command.
922fbb7b
AC
31293
31294@subsubheading Example
31295
a2c02241
NR
31296In the following example, the numbers that precede the commands are the
31297@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
31298Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
31299output.
31300
922fbb7b 31301@smallexample
a2c02241
NR
31302211-data-evaluate-expression A
31303211^done,value="1"
594fe323 31304(gdb)
a2c02241
NR
31305311-data-evaluate-expression &A
31306311^done,value="0xefffeb7c"
594fe323 31307(gdb)
a2c02241
NR
31308411-data-evaluate-expression A+3
31309411^done,value="4"
594fe323 31310(gdb)
a2c02241
NR
31311511-data-evaluate-expression "A + 3"
31312511^done,value="4"
594fe323 31313(gdb)
a2c02241 31314@end smallexample
922fbb7b
AC
31315
31316
a2c02241
NR
31317@subheading The @code{-data-list-changed-registers} Command
31318@findex -data-list-changed-registers
922fbb7b
AC
31319
31320@subsubheading Synopsis
31321
31322@smallexample
a2c02241 31323 -data-list-changed-registers
922fbb7b
AC
31324@end smallexample
31325
a2c02241 31326Display a list of the registers that have changed.
922fbb7b
AC
31327
31328@subsubheading @value{GDBN} Command
31329
a2c02241
NR
31330@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
31331has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
31332
31333@subsubheading Example
922fbb7b 31334
a2c02241 31335On a PPC MBX board:
922fbb7b
AC
31336
31337@smallexample
594fe323 31338(gdb)
a2c02241
NR
31339-exec-continue
31340^running
922fbb7b 31341
594fe323 31342(gdb)
a47ec5fe
AR
31343*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
31344func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
31345line="5"@}
594fe323 31346(gdb)
a2c02241
NR
31347-data-list-changed-registers
31348^done,changed-registers=["0","1","2","4","5","6","7","8","9",
31349"10","11","13","14","15","16","17","18","19","20","21","22","23",
31350"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 31351(gdb)
a2c02241 31352@end smallexample
922fbb7b
AC
31353
31354
a2c02241
NR
31355@subheading The @code{-data-list-register-names} Command
31356@findex -data-list-register-names
922fbb7b
AC
31357
31358@subsubheading Synopsis
31359
31360@smallexample
a2c02241 31361 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
31362@end smallexample
31363
a2c02241
NR
31364Show a list of register names for the current target. If no arguments
31365are given, it shows a list of the names of all the registers. If
31366integer numbers are given as arguments, it will print a list of the
31367names of the registers corresponding to the arguments. To ensure
31368consistency between a register name and its number, the output list may
31369include empty register names.
922fbb7b
AC
31370
31371@subsubheading @value{GDBN} Command
31372
a2c02241
NR
31373@value{GDBN} does not have a command which corresponds to
31374@samp{-data-list-register-names}. In @code{gdbtk} there is a
31375corresponding command @samp{gdb_regnames}.
922fbb7b
AC
31376
31377@subsubheading Example
922fbb7b 31378
a2c02241
NR
31379For the PPC MBX board:
31380@smallexample
594fe323 31381(gdb)
a2c02241
NR
31382-data-list-register-names
31383^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
31384"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
31385"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
31386"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
31387"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
31388"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
31389"", "pc","ps","cr","lr","ctr","xer"]
594fe323 31390(gdb)
a2c02241
NR
31391-data-list-register-names 1 2 3
31392^done,register-names=["r1","r2","r3"]
594fe323 31393(gdb)
a2c02241 31394@end smallexample
922fbb7b 31395
a2c02241
NR
31396@subheading The @code{-data-list-register-values} Command
31397@findex -data-list-register-values
922fbb7b
AC
31398
31399@subsubheading Synopsis
31400
31401@smallexample
a2c02241 31402 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
31403@end smallexample
31404
a2c02241
NR
31405Display the registers' contents. @var{fmt} is the format according to
31406which the registers' contents are to be returned, followed by an optional
31407list of numbers specifying the registers to display. A missing list of
31408numbers indicates that the contents of all the registers must be returned.
31409
31410Allowed formats for @var{fmt} are:
31411
31412@table @code
31413@item x
31414Hexadecimal
31415@item o
31416Octal
31417@item t
31418Binary
31419@item d
31420Decimal
31421@item r
31422Raw
31423@item N
31424Natural
31425@end table
922fbb7b
AC
31426
31427@subsubheading @value{GDBN} Command
31428
a2c02241
NR
31429The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
31430all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
31431
31432@subsubheading Example
922fbb7b 31433
a2c02241
NR
31434For a PPC MBX board (note: line breaks are for readability only, they
31435don't appear in the actual output):
31436
31437@smallexample
594fe323 31438(gdb)
a2c02241
NR
31439-data-list-register-values r 64 65
31440^done,register-values=[@{number="64",value="0xfe00a300"@},
31441@{number="65",value="0x00029002"@}]
594fe323 31442(gdb)
a2c02241
NR
31443-data-list-register-values x
31444^done,register-values=[@{number="0",value="0xfe0043c8"@},
31445@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
31446@{number="3",value="0x0"@},@{number="4",value="0xa"@},
31447@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
31448@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
31449@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
31450@{number="11",value="0x1"@},@{number="12",value="0x0"@},
31451@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
31452@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
31453@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
31454@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
31455@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
31456@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
31457@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
31458@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
31459@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
31460@{number="31",value="0x0"@},@{number="32",value="0x0"@},
31461@{number="33",value="0x0"@},@{number="34",value="0x0"@},
31462@{number="35",value="0x0"@},@{number="36",value="0x0"@},
31463@{number="37",value="0x0"@},@{number="38",value="0x0"@},
31464@{number="39",value="0x0"@},@{number="40",value="0x0"@},
31465@{number="41",value="0x0"@},@{number="42",value="0x0"@},
31466@{number="43",value="0x0"@},@{number="44",value="0x0"@},
31467@{number="45",value="0x0"@},@{number="46",value="0x0"@},
31468@{number="47",value="0x0"@},@{number="48",value="0x0"@},
31469@{number="49",value="0x0"@},@{number="50",value="0x0"@},
31470@{number="51",value="0x0"@},@{number="52",value="0x0"@},
31471@{number="53",value="0x0"@},@{number="54",value="0x0"@},
31472@{number="55",value="0x0"@},@{number="56",value="0x0"@},
31473@{number="57",value="0x0"@},@{number="58",value="0x0"@},
31474@{number="59",value="0x0"@},@{number="60",value="0x0"@},
31475@{number="61",value="0x0"@},@{number="62",value="0x0"@},
31476@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
31477@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
31478@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
31479@{number="69",value="0x20002b03"@}]
594fe323 31480(gdb)
a2c02241 31481@end smallexample
922fbb7b 31482
a2c02241
NR
31483
31484@subheading The @code{-data-read-memory} Command
31485@findex -data-read-memory
922fbb7b 31486
8dedea02
VP
31487This command is deprecated, use @code{-data-read-memory-bytes} instead.
31488
922fbb7b
AC
31489@subsubheading Synopsis
31490
31491@smallexample
a2c02241
NR
31492 -data-read-memory [ -o @var{byte-offset} ]
31493 @var{address} @var{word-format} @var{word-size}
31494 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
31495@end smallexample
31496
a2c02241
NR
31497@noindent
31498where:
922fbb7b 31499
a2c02241
NR
31500@table @samp
31501@item @var{address}
31502An expression specifying the address of the first memory word to be
31503read. Complex expressions containing embedded white space should be
31504quoted using the C convention.
922fbb7b 31505
a2c02241
NR
31506@item @var{word-format}
31507The format to be used to print the memory words. The notation is the
31508same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 31509,Output Formats}).
922fbb7b 31510
a2c02241
NR
31511@item @var{word-size}
31512The size of each memory word in bytes.
922fbb7b 31513
a2c02241
NR
31514@item @var{nr-rows}
31515The number of rows in the output table.
922fbb7b 31516
a2c02241
NR
31517@item @var{nr-cols}
31518The number of columns in the output table.
922fbb7b 31519
a2c02241
NR
31520@item @var{aschar}
31521If present, indicates that each row should include an @sc{ascii} dump. The
31522value of @var{aschar} is used as a padding character when a byte is not a
31523member of the printable @sc{ascii} character set (printable @sc{ascii}
31524characters are those whose code is between 32 and 126, inclusively).
922fbb7b 31525
a2c02241
NR
31526@item @var{byte-offset}
31527An offset to add to the @var{address} before fetching memory.
31528@end table
922fbb7b 31529
a2c02241
NR
31530This command displays memory contents as a table of @var{nr-rows} by
31531@var{nr-cols} words, each word being @var{word-size} bytes. In total,
31532@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
31533(returned as @samp{total-bytes}). Should less than the requested number
31534of bytes be returned by the target, the missing words are identified
31535using @samp{N/A}. The number of bytes read from the target is returned
31536in @samp{nr-bytes} and the starting address used to read memory in
31537@samp{addr}.
31538
31539The address of the next/previous row or page is available in
31540@samp{next-row} and @samp{prev-row}, @samp{next-page} and
31541@samp{prev-page}.
922fbb7b
AC
31542
31543@subsubheading @value{GDBN} Command
31544
a2c02241
NR
31545The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
31546@samp{gdb_get_mem} memory read command.
922fbb7b
AC
31547
31548@subsubheading Example
32e7087d 31549
a2c02241
NR
31550Read six bytes of memory starting at @code{bytes+6} but then offset by
31551@code{-6} bytes. Format as three rows of two columns. One byte per
31552word. Display each word in hex.
32e7087d
JB
31553
31554@smallexample
594fe323 31555(gdb)
a2c02241
NR
315569-data-read-memory -o -6 -- bytes+6 x 1 3 2
315579^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
31558next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
31559prev-page="0x0000138a",memory=[
31560@{addr="0x00001390",data=["0x00","0x01"]@},
31561@{addr="0x00001392",data=["0x02","0x03"]@},
31562@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 31563(gdb)
32e7087d
JB
31564@end smallexample
31565
a2c02241
NR
31566Read two bytes of memory starting at address @code{shorts + 64} and
31567display as a single word formatted in decimal.
32e7087d 31568
32e7087d 31569@smallexample
594fe323 31570(gdb)
a2c02241
NR
315715-data-read-memory shorts+64 d 2 1 1
315725^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
31573next-row="0x00001512",prev-row="0x0000150e",
31574next-page="0x00001512",prev-page="0x0000150e",memory=[
31575@{addr="0x00001510",data=["128"]@}]
594fe323 31576(gdb)
32e7087d
JB
31577@end smallexample
31578
a2c02241
NR
31579Read thirty two bytes of memory starting at @code{bytes+16} and format
31580as eight rows of four columns. Include a string encoding with @samp{x}
31581used as the non-printable character.
922fbb7b
AC
31582
31583@smallexample
594fe323 31584(gdb)
a2c02241
NR
315854-data-read-memory bytes+16 x 1 8 4 x
315864^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
31587next-row="0x000013c0",prev-row="0x0000139c",
31588next-page="0x000013c0",prev-page="0x00001380",memory=[
31589@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
31590@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
31591@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
31592@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
31593@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
31594@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
31595@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
31596@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 31597(gdb)
922fbb7b
AC
31598@end smallexample
31599
8dedea02
VP
31600@subheading The @code{-data-read-memory-bytes} Command
31601@findex -data-read-memory-bytes
31602
31603@subsubheading Synopsis
31604
31605@smallexample
31606 -data-read-memory-bytes [ -o @var{byte-offset} ]
31607 @var{address} @var{count}
31608@end smallexample
31609
31610@noindent
31611where:
31612
31613@table @samp
31614@item @var{address}
31615An expression specifying the address of the first memory word to be
31616read. Complex expressions containing embedded white space should be
31617quoted using the C convention.
31618
31619@item @var{count}
31620The number of bytes to read. This should be an integer literal.
31621
31622@item @var{byte-offset}
31623The offsets in bytes relative to @var{address} at which to start
31624reading. This should be an integer literal. This option is provided
31625so that a frontend is not required to first evaluate address and then
31626perform address arithmetics itself.
31627
31628@end table
31629
31630This command attempts to read all accessible memory regions in the
31631specified range. First, all regions marked as unreadable in the memory
31632map (if one is defined) will be skipped. @xref{Memory Region
31633Attributes}. Second, @value{GDBN} will attempt to read the remaining
31634regions. For each one, if reading full region results in an errors,
31635@value{GDBN} will try to read a subset of the region.
31636
31637In general, every single byte in the region may be readable or not,
31638and the only way to read every readable byte is to try a read at
31639every address, which is not practical. Therefore, @value{GDBN} will
31640attempt to read all accessible bytes at either beginning or the end
31641of the region, using a binary division scheme. This heuristic works
31642well for reading accross a memory map boundary. Note that if a region
31643has a readable range that is neither at the beginning or the end,
31644@value{GDBN} will not read it.
31645
31646The result record (@pxref{GDB/MI Result Records}) that is output of
31647the command includes a field named @samp{memory} whose content is a
31648list of tuples. Each tuple represent a successfully read memory block
31649and has the following fields:
31650
31651@table @code
31652@item begin
31653The start address of the memory block, as hexadecimal literal.
31654
31655@item end
31656The end address of the memory block, as hexadecimal literal.
31657
31658@item offset
31659The offset of the memory block, as hexadecimal literal, relative to
31660the start address passed to @code{-data-read-memory-bytes}.
31661
31662@item contents
31663The contents of the memory block, in hex.
31664
31665@end table
31666
31667
31668
31669@subsubheading @value{GDBN} Command
31670
31671The corresponding @value{GDBN} command is @samp{x}.
31672
31673@subsubheading Example
31674
31675@smallexample
31676(gdb)
31677-data-read-memory-bytes &a 10
31678^done,memory=[@{begin="0xbffff154",offset="0x00000000",
31679 end="0xbffff15e",
31680 contents="01000000020000000300"@}]
31681(gdb)
31682@end smallexample
31683
31684
31685@subheading The @code{-data-write-memory-bytes} Command
31686@findex -data-write-memory-bytes
31687
31688@subsubheading Synopsis
31689
31690@smallexample
31691 -data-write-memory-bytes @var{address} @var{contents}
62747a60 31692 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
31693@end smallexample
31694
31695@noindent
31696where:
31697
31698@table @samp
31699@item @var{address}
31700An expression specifying the address of the first memory word to be
31701read. Complex expressions containing embedded white space should be
31702quoted using the C convention.
31703
31704@item @var{contents}
31705The hex-encoded bytes to write.
31706
62747a60
TT
31707@item @var{count}
31708Optional argument indicating the number of bytes to be written. If @var{count}
31709is greater than @var{contents}' length, @value{GDBN} will repeatedly
31710write @var{contents} until it fills @var{count} bytes.
31711
8dedea02
VP
31712@end table
31713
31714@subsubheading @value{GDBN} Command
31715
31716There's no corresponding @value{GDBN} command.
31717
31718@subsubheading Example
31719
31720@smallexample
31721(gdb)
31722-data-write-memory-bytes &a "aabbccdd"
31723^done
31724(gdb)
31725@end smallexample
31726
62747a60
TT
31727@smallexample
31728(gdb)
31729-data-write-memory-bytes &a "aabbccdd" 16e
31730^done
31731(gdb)
31732@end smallexample
8dedea02 31733
a2c02241
NR
31734@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31735@node GDB/MI Tracepoint Commands
31736@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 31737
18148017
VP
31738The commands defined in this section implement MI support for
31739tracepoints. For detailed introduction, see @ref{Tracepoints}.
31740
31741@subheading The @code{-trace-find} Command
31742@findex -trace-find
31743
31744@subsubheading Synopsis
31745
31746@smallexample
31747 -trace-find @var{mode} [@var{parameters}@dots{}]
31748@end smallexample
31749
31750Find a trace frame using criteria defined by @var{mode} and
31751@var{parameters}. The following table lists permissible
31752modes and their parameters. For details of operation, see @ref{tfind}.
31753
31754@table @samp
31755
31756@item none
31757No parameters are required. Stops examining trace frames.
31758
31759@item frame-number
31760An integer is required as parameter. Selects tracepoint frame with
31761that index.
31762
31763@item tracepoint-number
31764An integer is required as parameter. Finds next
31765trace frame that corresponds to tracepoint with the specified number.
31766
31767@item pc
31768An address is required as parameter. Finds
31769next trace frame that corresponds to any tracepoint at the specified
31770address.
31771
31772@item pc-inside-range
31773Two addresses are required as parameters. Finds next trace
31774frame that corresponds to a tracepoint at an address inside the
31775specified range. Both bounds are considered to be inside the range.
31776
31777@item pc-outside-range
31778Two addresses are required as parameters. Finds
31779next trace frame that corresponds to a tracepoint at an address outside
31780the specified range. Both bounds are considered to be inside the range.
31781
31782@item line
31783Line specification is required as parameter. @xref{Specify Location}.
31784Finds next trace frame that corresponds to a tracepoint at
31785the specified location.
31786
31787@end table
31788
31789If @samp{none} was passed as @var{mode}, the response does not
31790have fields. Otherwise, the response may have the following fields:
31791
31792@table @samp
31793@item found
31794This field has either @samp{0} or @samp{1} as the value, depending
31795on whether a matching tracepoint was found.
31796
31797@item traceframe
31798The index of the found traceframe. This field is present iff
31799the @samp{found} field has value of @samp{1}.
31800
31801@item tracepoint
31802The index of the found tracepoint. This field is present iff
31803the @samp{found} field has value of @samp{1}.
31804
31805@item frame
31806The information about the frame corresponding to the found trace
31807frame. This field is present only if a trace frame was found.
cd64ee31 31808@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
31809
31810@end table
31811
7d13fe92
SS
31812@subsubheading @value{GDBN} Command
31813
31814The corresponding @value{GDBN} command is @samp{tfind}.
31815
18148017
VP
31816@subheading -trace-define-variable
31817@findex -trace-define-variable
31818
31819@subsubheading Synopsis
31820
31821@smallexample
31822 -trace-define-variable @var{name} [ @var{value} ]
31823@end smallexample
31824
31825Create trace variable @var{name} if it does not exist. If
31826@var{value} is specified, sets the initial value of the specified
31827trace variable to that value. Note that the @var{name} should start
31828with the @samp{$} character.
31829
7d13fe92
SS
31830@subsubheading @value{GDBN} Command
31831
31832The corresponding @value{GDBN} command is @samp{tvariable}.
31833
18148017
VP
31834@subheading -trace-list-variables
31835@findex -trace-list-variables
922fbb7b 31836
18148017 31837@subsubheading Synopsis
922fbb7b 31838
18148017
VP
31839@smallexample
31840 -trace-list-variables
31841@end smallexample
922fbb7b 31842
18148017
VP
31843Return a table of all defined trace variables. Each element of the
31844table has the following fields:
922fbb7b 31845
18148017
VP
31846@table @samp
31847@item name
31848The name of the trace variable. This field is always present.
922fbb7b 31849
18148017
VP
31850@item initial
31851The initial value. This is a 64-bit signed integer. This
31852field is always present.
922fbb7b 31853
18148017
VP
31854@item current
31855The value the trace variable has at the moment. This is a 64-bit
31856signed integer. This field is absent iff current value is
31857not defined, for example if the trace was never run, or is
31858presently running.
922fbb7b 31859
18148017 31860@end table
922fbb7b 31861
7d13fe92
SS
31862@subsubheading @value{GDBN} Command
31863
31864The corresponding @value{GDBN} command is @samp{tvariables}.
31865
18148017 31866@subsubheading Example
922fbb7b 31867
18148017
VP
31868@smallexample
31869(gdb)
31870-trace-list-variables
31871^done,trace-variables=@{nr_rows="1",nr_cols="3",
31872hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
31873 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
31874 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
31875body=[variable=@{name="$trace_timestamp",initial="0"@}
31876 variable=@{name="$foo",initial="10",current="15"@}]@}
31877(gdb)
31878@end smallexample
922fbb7b 31879
18148017
VP
31880@subheading -trace-save
31881@findex -trace-save
922fbb7b 31882
18148017
VP
31883@subsubheading Synopsis
31884
31885@smallexample
31886 -trace-save [-r ] @var{filename}
31887@end smallexample
31888
31889Saves the collected trace data to @var{filename}. Without the
31890@samp{-r} option, the data is downloaded from the target and saved
31891in a local file. With the @samp{-r} option the target is asked
31892to perform the save.
31893
7d13fe92
SS
31894@subsubheading @value{GDBN} Command
31895
31896The corresponding @value{GDBN} command is @samp{tsave}.
31897
18148017
VP
31898
31899@subheading -trace-start
31900@findex -trace-start
31901
31902@subsubheading Synopsis
31903
31904@smallexample
31905 -trace-start
31906@end smallexample
922fbb7b 31907
18148017
VP
31908Starts a tracing experiments. The result of this command does not
31909have any fields.
922fbb7b 31910
7d13fe92
SS
31911@subsubheading @value{GDBN} Command
31912
31913The corresponding @value{GDBN} command is @samp{tstart}.
31914
18148017
VP
31915@subheading -trace-status
31916@findex -trace-status
922fbb7b 31917
18148017
VP
31918@subsubheading Synopsis
31919
31920@smallexample
31921 -trace-status
31922@end smallexample
31923
a97153c7 31924Obtains the status of a tracing experiment. The result may include
18148017
VP
31925the following fields:
31926
31927@table @samp
31928
31929@item supported
31930May have a value of either @samp{0}, when no tracing operations are
31931supported, @samp{1}, when all tracing operations are supported, or
31932@samp{file} when examining trace file. In the latter case, examining
31933of trace frame is possible but new tracing experiement cannot be
31934started. This field is always present.
31935
31936@item running
31937May have a value of either @samp{0} or @samp{1} depending on whether
31938tracing experiement is in progress on target. This field is present
31939if @samp{supported} field is not @samp{0}.
31940
31941@item stop-reason
31942Report the reason why the tracing was stopped last time. This field
31943may be absent iff tracing was never stopped on target yet. The
31944value of @samp{request} means the tracing was stopped as result of
31945the @code{-trace-stop} command. The value of @samp{overflow} means
31946the tracing buffer is full. The value of @samp{disconnection} means
31947tracing was automatically stopped when @value{GDBN} has disconnected.
31948The value of @samp{passcount} means tracing was stopped when a
31949tracepoint was passed a maximal number of times for that tracepoint.
31950This field is present if @samp{supported} field is not @samp{0}.
31951
31952@item stopping-tracepoint
31953The number of tracepoint whose passcount as exceeded. This field is
31954present iff the @samp{stop-reason} field has the value of
31955@samp{passcount}.
31956
31957@item frames
87290684
SS
31958@itemx frames-created
31959The @samp{frames} field is a count of the total number of trace frames
31960in the trace buffer, while @samp{frames-created} is the total created
31961during the run, including ones that were discarded, such as when a
31962circular trace buffer filled up. Both fields are optional.
18148017
VP
31963
31964@item buffer-size
31965@itemx buffer-free
31966These fields tell the current size of the tracing buffer and the
87290684 31967remaining space. These fields are optional.
18148017 31968
a97153c7
PA
31969@item circular
31970The value of the circular trace buffer flag. @code{1} means that the
31971trace buffer is circular and old trace frames will be discarded if
31972necessary to make room, @code{0} means that the trace buffer is linear
31973and may fill up.
31974
31975@item disconnected
31976The value of the disconnected tracing flag. @code{1} means that
31977tracing will continue after @value{GDBN} disconnects, @code{0} means
31978that the trace run will stop.
31979
18148017
VP
31980@end table
31981
7d13fe92
SS
31982@subsubheading @value{GDBN} Command
31983
31984The corresponding @value{GDBN} command is @samp{tstatus}.
31985
18148017
VP
31986@subheading -trace-stop
31987@findex -trace-stop
31988
31989@subsubheading Synopsis
31990
31991@smallexample
31992 -trace-stop
31993@end smallexample
922fbb7b 31994
18148017
VP
31995Stops a tracing experiment. The result of this command has the same
31996fields as @code{-trace-status}, except that the @samp{supported} and
31997@samp{running} fields are not output.
922fbb7b 31998
7d13fe92
SS
31999@subsubheading @value{GDBN} Command
32000
32001The corresponding @value{GDBN} command is @samp{tstop}.
32002
922fbb7b 32003
a2c02241
NR
32004@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32005@node GDB/MI Symbol Query
32006@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
32007
32008
9901a55b 32009@ignore
a2c02241
NR
32010@subheading The @code{-symbol-info-address} Command
32011@findex -symbol-info-address
922fbb7b
AC
32012
32013@subsubheading Synopsis
32014
32015@smallexample
a2c02241 32016 -symbol-info-address @var{symbol}
922fbb7b
AC
32017@end smallexample
32018
a2c02241 32019Describe where @var{symbol} is stored.
922fbb7b
AC
32020
32021@subsubheading @value{GDBN} Command
32022
a2c02241 32023The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
32024
32025@subsubheading Example
32026N.A.
32027
32028
a2c02241
NR
32029@subheading The @code{-symbol-info-file} Command
32030@findex -symbol-info-file
922fbb7b
AC
32031
32032@subsubheading Synopsis
32033
32034@smallexample
a2c02241 32035 -symbol-info-file
922fbb7b
AC
32036@end smallexample
32037
a2c02241 32038Show the file for the symbol.
922fbb7b 32039
a2c02241 32040@subsubheading @value{GDBN} Command
922fbb7b 32041
a2c02241
NR
32042There's no equivalent @value{GDBN} command. @code{gdbtk} has
32043@samp{gdb_find_file}.
922fbb7b
AC
32044
32045@subsubheading Example
32046N.A.
32047
32048
a2c02241
NR
32049@subheading The @code{-symbol-info-function} Command
32050@findex -symbol-info-function
922fbb7b
AC
32051
32052@subsubheading Synopsis
32053
32054@smallexample
a2c02241 32055 -symbol-info-function
922fbb7b
AC
32056@end smallexample
32057
a2c02241 32058Show which function the symbol lives in.
922fbb7b
AC
32059
32060@subsubheading @value{GDBN} Command
32061
a2c02241 32062@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
32063
32064@subsubheading Example
32065N.A.
32066
32067
a2c02241
NR
32068@subheading The @code{-symbol-info-line} Command
32069@findex -symbol-info-line
922fbb7b
AC
32070
32071@subsubheading Synopsis
32072
32073@smallexample
a2c02241 32074 -symbol-info-line
922fbb7b
AC
32075@end smallexample
32076
a2c02241 32077Show the core addresses of the code for a source line.
922fbb7b 32078
a2c02241 32079@subsubheading @value{GDBN} Command
922fbb7b 32080
a2c02241
NR
32081The corresponding @value{GDBN} command is @samp{info line}.
32082@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
32083
32084@subsubheading Example
a2c02241 32085N.A.
922fbb7b
AC
32086
32087
a2c02241
NR
32088@subheading The @code{-symbol-info-symbol} Command
32089@findex -symbol-info-symbol
07f31aa6
DJ
32090
32091@subsubheading Synopsis
32092
a2c02241
NR
32093@smallexample
32094 -symbol-info-symbol @var{addr}
32095@end smallexample
07f31aa6 32096
a2c02241 32097Describe what symbol is at location @var{addr}.
07f31aa6 32098
a2c02241 32099@subsubheading @value{GDBN} Command
07f31aa6 32100
a2c02241 32101The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
32102
32103@subsubheading Example
a2c02241 32104N.A.
07f31aa6
DJ
32105
32106
a2c02241
NR
32107@subheading The @code{-symbol-list-functions} Command
32108@findex -symbol-list-functions
922fbb7b
AC
32109
32110@subsubheading Synopsis
32111
32112@smallexample
a2c02241 32113 -symbol-list-functions
922fbb7b
AC
32114@end smallexample
32115
a2c02241 32116List the functions in the executable.
922fbb7b
AC
32117
32118@subsubheading @value{GDBN} Command
32119
a2c02241
NR
32120@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
32121@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32122
32123@subsubheading Example
a2c02241 32124N.A.
9901a55b 32125@end ignore
922fbb7b
AC
32126
32127
a2c02241
NR
32128@subheading The @code{-symbol-list-lines} Command
32129@findex -symbol-list-lines
922fbb7b
AC
32130
32131@subsubheading Synopsis
32132
32133@smallexample
a2c02241 32134 -symbol-list-lines @var{filename}
922fbb7b
AC
32135@end smallexample
32136
a2c02241
NR
32137Print the list of lines that contain code and their associated program
32138addresses for the given source filename. The entries are sorted in
32139ascending PC order.
922fbb7b
AC
32140
32141@subsubheading @value{GDBN} Command
32142
a2c02241 32143There is no corresponding @value{GDBN} command.
922fbb7b
AC
32144
32145@subsubheading Example
a2c02241 32146@smallexample
594fe323 32147(gdb)
a2c02241
NR
32148-symbol-list-lines basics.c
32149^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 32150(gdb)
a2c02241 32151@end smallexample
922fbb7b
AC
32152
32153
9901a55b 32154@ignore
a2c02241
NR
32155@subheading The @code{-symbol-list-types} Command
32156@findex -symbol-list-types
922fbb7b
AC
32157
32158@subsubheading Synopsis
32159
32160@smallexample
a2c02241 32161 -symbol-list-types
922fbb7b
AC
32162@end smallexample
32163
a2c02241 32164List all the type names.
922fbb7b
AC
32165
32166@subsubheading @value{GDBN} Command
32167
a2c02241
NR
32168The corresponding commands are @samp{info types} in @value{GDBN},
32169@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32170
32171@subsubheading Example
32172N.A.
32173
32174
a2c02241
NR
32175@subheading The @code{-symbol-list-variables} Command
32176@findex -symbol-list-variables
922fbb7b
AC
32177
32178@subsubheading Synopsis
32179
32180@smallexample
a2c02241 32181 -symbol-list-variables
922fbb7b
AC
32182@end smallexample
32183
a2c02241 32184List all the global and static variable names.
922fbb7b
AC
32185
32186@subsubheading @value{GDBN} Command
32187
a2c02241 32188@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
32189
32190@subsubheading Example
32191N.A.
32192
32193
a2c02241
NR
32194@subheading The @code{-symbol-locate} Command
32195@findex -symbol-locate
922fbb7b
AC
32196
32197@subsubheading Synopsis
32198
32199@smallexample
a2c02241 32200 -symbol-locate
922fbb7b
AC
32201@end smallexample
32202
922fbb7b
AC
32203@subsubheading @value{GDBN} Command
32204
a2c02241 32205@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
32206
32207@subsubheading Example
32208N.A.
32209
32210
a2c02241
NR
32211@subheading The @code{-symbol-type} Command
32212@findex -symbol-type
922fbb7b
AC
32213
32214@subsubheading Synopsis
32215
32216@smallexample
a2c02241 32217 -symbol-type @var{variable}
922fbb7b
AC
32218@end smallexample
32219
a2c02241 32220Show type of @var{variable}.
922fbb7b 32221
a2c02241 32222@subsubheading @value{GDBN} Command
922fbb7b 32223
a2c02241
NR
32224The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
32225@samp{gdb_obj_variable}.
32226
32227@subsubheading Example
32228N.A.
9901a55b 32229@end ignore
a2c02241
NR
32230
32231
32232@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32233@node GDB/MI File Commands
32234@section @sc{gdb/mi} File Commands
32235
32236This section describes the GDB/MI commands to specify executable file names
32237and to read in and obtain symbol table information.
32238
32239@subheading The @code{-file-exec-and-symbols} Command
32240@findex -file-exec-and-symbols
32241
32242@subsubheading Synopsis
922fbb7b
AC
32243
32244@smallexample
a2c02241 32245 -file-exec-and-symbols @var{file}
922fbb7b
AC
32246@end smallexample
32247
a2c02241
NR
32248Specify the executable file to be debugged. This file is the one from
32249which the symbol table is also read. If no file is specified, the
32250command clears the executable and symbol information. If breakpoints
32251are set when using this command with no arguments, @value{GDBN} will produce
32252error messages. Otherwise, no output is produced, except a completion
32253notification.
32254
922fbb7b
AC
32255@subsubheading @value{GDBN} Command
32256
a2c02241 32257The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
32258
32259@subsubheading Example
32260
32261@smallexample
594fe323 32262(gdb)
a2c02241
NR
32263-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32264^done
594fe323 32265(gdb)
922fbb7b
AC
32266@end smallexample
32267
922fbb7b 32268
a2c02241
NR
32269@subheading The @code{-file-exec-file} Command
32270@findex -file-exec-file
922fbb7b
AC
32271
32272@subsubheading Synopsis
32273
32274@smallexample
a2c02241 32275 -file-exec-file @var{file}
922fbb7b
AC
32276@end smallexample
32277
a2c02241
NR
32278Specify the executable file to be debugged. Unlike
32279@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
32280from this file. If used without argument, @value{GDBN} clears the information
32281about the executable file. No output is produced, except a completion
32282notification.
922fbb7b 32283
a2c02241
NR
32284@subsubheading @value{GDBN} Command
32285
32286The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
32287
32288@subsubheading Example
a2c02241
NR
32289
32290@smallexample
594fe323 32291(gdb)
a2c02241
NR
32292-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32293^done
594fe323 32294(gdb)
a2c02241 32295@end smallexample
922fbb7b
AC
32296
32297
9901a55b 32298@ignore
a2c02241
NR
32299@subheading The @code{-file-list-exec-sections} Command
32300@findex -file-list-exec-sections
922fbb7b
AC
32301
32302@subsubheading Synopsis
32303
32304@smallexample
a2c02241 32305 -file-list-exec-sections
922fbb7b
AC
32306@end smallexample
32307
a2c02241
NR
32308List the sections of the current executable file.
32309
922fbb7b
AC
32310@subsubheading @value{GDBN} Command
32311
a2c02241
NR
32312The @value{GDBN} command @samp{info file} shows, among the rest, the same
32313information as this command. @code{gdbtk} has a corresponding command
32314@samp{gdb_load_info}.
922fbb7b
AC
32315
32316@subsubheading Example
32317N.A.
9901a55b 32318@end ignore
922fbb7b
AC
32319
32320
a2c02241
NR
32321@subheading The @code{-file-list-exec-source-file} Command
32322@findex -file-list-exec-source-file
922fbb7b
AC
32323
32324@subsubheading Synopsis
32325
32326@smallexample
a2c02241 32327 -file-list-exec-source-file
922fbb7b
AC
32328@end smallexample
32329
a2c02241 32330List the line number, the current source file, and the absolute path
44288b44
NR
32331to the current source file for the current executable. The macro
32332information field has a value of @samp{1} or @samp{0} depending on
32333whether or not the file includes preprocessor macro information.
922fbb7b
AC
32334
32335@subsubheading @value{GDBN} Command
32336
a2c02241 32337The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
32338
32339@subsubheading Example
32340
922fbb7b 32341@smallexample
594fe323 32342(gdb)
a2c02241 32343123-file-list-exec-source-file
44288b44 32344123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 32345(gdb)
922fbb7b
AC
32346@end smallexample
32347
32348
a2c02241
NR
32349@subheading The @code{-file-list-exec-source-files} Command
32350@findex -file-list-exec-source-files
922fbb7b
AC
32351
32352@subsubheading Synopsis
32353
32354@smallexample
a2c02241 32355 -file-list-exec-source-files
922fbb7b
AC
32356@end smallexample
32357
a2c02241
NR
32358List the source files for the current executable.
32359
f35a17b5
JK
32360It will always output both the filename and fullname (absolute file
32361name) of a source file.
922fbb7b
AC
32362
32363@subsubheading @value{GDBN} Command
32364
a2c02241
NR
32365The @value{GDBN} equivalent is @samp{info sources}.
32366@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
32367
32368@subsubheading Example
922fbb7b 32369@smallexample
594fe323 32370(gdb)
a2c02241
NR
32371-file-list-exec-source-files
32372^done,files=[
32373@{file=foo.c,fullname=/home/foo.c@},
32374@{file=/home/bar.c,fullname=/home/bar.c@},
32375@{file=gdb_could_not_find_fullpath.c@}]
594fe323 32376(gdb)
922fbb7b
AC
32377@end smallexample
32378
9901a55b 32379@ignore
a2c02241
NR
32380@subheading The @code{-file-list-shared-libraries} Command
32381@findex -file-list-shared-libraries
922fbb7b 32382
a2c02241 32383@subsubheading Synopsis
922fbb7b 32384
a2c02241
NR
32385@smallexample
32386 -file-list-shared-libraries
32387@end smallexample
922fbb7b 32388
a2c02241 32389List the shared libraries in the program.
922fbb7b 32390
a2c02241 32391@subsubheading @value{GDBN} Command
922fbb7b 32392
a2c02241 32393The corresponding @value{GDBN} command is @samp{info shared}.
922fbb7b 32394
a2c02241
NR
32395@subsubheading Example
32396N.A.
922fbb7b
AC
32397
32398
a2c02241
NR
32399@subheading The @code{-file-list-symbol-files} Command
32400@findex -file-list-symbol-files
922fbb7b 32401
a2c02241 32402@subsubheading Synopsis
922fbb7b 32403
a2c02241
NR
32404@smallexample
32405 -file-list-symbol-files
32406@end smallexample
922fbb7b 32407
a2c02241 32408List symbol files.
922fbb7b 32409
a2c02241 32410@subsubheading @value{GDBN} Command
922fbb7b 32411
a2c02241 32412The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 32413
a2c02241
NR
32414@subsubheading Example
32415N.A.
9901a55b 32416@end ignore
922fbb7b 32417
922fbb7b 32418
a2c02241
NR
32419@subheading The @code{-file-symbol-file} Command
32420@findex -file-symbol-file
922fbb7b 32421
a2c02241 32422@subsubheading Synopsis
922fbb7b 32423
a2c02241
NR
32424@smallexample
32425 -file-symbol-file @var{file}
32426@end smallexample
922fbb7b 32427
a2c02241
NR
32428Read symbol table info from the specified @var{file} argument. When
32429used without arguments, clears @value{GDBN}'s symbol table info. No output is
32430produced, except for a completion notification.
922fbb7b 32431
a2c02241 32432@subsubheading @value{GDBN} Command
922fbb7b 32433
a2c02241 32434The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 32435
a2c02241 32436@subsubheading Example
922fbb7b 32437
a2c02241 32438@smallexample
594fe323 32439(gdb)
a2c02241
NR
32440-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32441^done
594fe323 32442(gdb)
a2c02241 32443@end smallexample
922fbb7b 32444
a2c02241 32445@ignore
a2c02241
NR
32446@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32447@node GDB/MI Memory Overlay Commands
32448@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 32449
a2c02241 32450The memory overlay commands are not implemented.
922fbb7b 32451
a2c02241 32452@c @subheading -overlay-auto
922fbb7b 32453
a2c02241 32454@c @subheading -overlay-list-mapping-state
922fbb7b 32455
a2c02241 32456@c @subheading -overlay-list-overlays
922fbb7b 32457
a2c02241 32458@c @subheading -overlay-map
922fbb7b 32459
a2c02241 32460@c @subheading -overlay-off
922fbb7b 32461
a2c02241 32462@c @subheading -overlay-on
922fbb7b 32463
a2c02241 32464@c @subheading -overlay-unmap
922fbb7b 32465
a2c02241
NR
32466@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32467@node GDB/MI Signal Handling Commands
32468@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 32469
a2c02241 32470Signal handling commands are not implemented.
922fbb7b 32471
a2c02241 32472@c @subheading -signal-handle
922fbb7b 32473
a2c02241 32474@c @subheading -signal-list-handle-actions
922fbb7b 32475
a2c02241
NR
32476@c @subheading -signal-list-signal-types
32477@end ignore
922fbb7b 32478
922fbb7b 32479
a2c02241
NR
32480@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32481@node GDB/MI Target Manipulation
32482@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
32483
32484
a2c02241
NR
32485@subheading The @code{-target-attach} Command
32486@findex -target-attach
922fbb7b
AC
32487
32488@subsubheading Synopsis
32489
32490@smallexample
c3b108f7 32491 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
32492@end smallexample
32493
c3b108f7
VP
32494Attach to a process @var{pid} or a file @var{file} outside of
32495@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
32496group, the id previously returned by
32497@samp{-list-thread-groups --available} must be used.
922fbb7b 32498
79a6e687 32499@subsubheading @value{GDBN} Command
922fbb7b 32500
a2c02241 32501The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 32502
a2c02241 32503@subsubheading Example
b56e7235
VP
32504@smallexample
32505(gdb)
32506-target-attach 34
32507=thread-created,id="1"
5ae4183a 32508*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
32509^done
32510(gdb)
32511@end smallexample
a2c02241 32512
9901a55b 32513@ignore
a2c02241
NR
32514@subheading The @code{-target-compare-sections} Command
32515@findex -target-compare-sections
922fbb7b
AC
32516
32517@subsubheading Synopsis
32518
32519@smallexample
a2c02241 32520 -target-compare-sections [ @var{section} ]
922fbb7b
AC
32521@end smallexample
32522
a2c02241
NR
32523Compare data of section @var{section} on target to the exec file.
32524Without the argument, all sections are compared.
922fbb7b 32525
a2c02241 32526@subsubheading @value{GDBN} Command
922fbb7b 32527
a2c02241 32528The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 32529
a2c02241
NR
32530@subsubheading Example
32531N.A.
9901a55b 32532@end ignore
a2c02241
NR
32533
32534
32535@subheading The @code{-target-detach} Command
32536@findex -target-detach
922fbb7b
AC
32537
32538@subsubheading Synopsis
32539
32540@smallexample
c3b108f7 32541 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
32542@end smallexample
32543
a2c02241 32544Detach from the remote target which normally resumes its execution.
c3b108f7
VP
32545If either @var{pid} or @var{gid} is specified, detaches from either
32546the specified process, or specified thread group. There's no output.
a2c02241 32547
79a6e687 32548@subsubheading @value{GDBN} Command
a2c02241
NR
32549
32550The corresponding @value{GDBN} command is @samp{detach}.
32551
32552@subsubheading Example
922fbb7b
AC
32553
32554@smallexample
594fe323 32555(gdb)
a2c02241
NR
32556-target-detach
32557^done
594fe323 32558(gdb)
922fbb7b
AC
32559@end smallexample
32560
32561
a2c02241
NR
32562@subheading The @code{-target-disconnect} Command
32563@findex -target-disconnect
922fbb7b
AC
32564
32565@subsubheading Synopsis
32566
123dc839 32567@smallexample
a2c02241 32568 -target-disconnect
123dc839 32569@end smallexample
922fbb7b 32570
a2c02241
NR
32571Disconnect from the remote target. There's no output and the target is
32572generally not resumed.
32573
79a6e687 32574@subsubheading @value{GDBN} Command
a2c02241
NR
32575
32576The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
32577
32578@subsubheading Example
922fbb7b
AC
32579
32580@smallexample
594fe323 32581(gdb)
a2c02241
NR
32582-target-disconnect
32583^done
594fe323 32584(gdb)
922fbb7b
AC
32585@end smallexample
32586
32587
a2c02241
NR
32588@subheading The @code{-target-download} Command
32589@findex -target-download
922fbb7b
AC
32590
32591@subsubheading Synopsis
32592
32593@smallexample
a2c02241 32594 -target-download
922fbb7b
AC
32595@end smallexample
32596
a2c02241
NR
32597Loads the executable onto the remote target.
32598It prints out an update message every half second, which includes the fields:
32599
32600@table @samp
32601@item section
32602The name of the section.
32603@item section-sent
32604The size of what has been sent so far for that section.
32605@item section-size
32606The size of the section.
32607@item total-sent
32608The total size of what was sent so far (the current and the previous sections).
32609@item total-size
32610The size of the overall executable to download.
32611@end table
32612
32613@noindent
32614Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
32615@sc{gdb/mi} Output Syntax}).
32616
32617In addition, it prints the name and size of the sections, as they are
32618downloaded. These messages include the following fields:
32619
32620@table @samp
32621@item section
32622The name of the section.
32623@item section-size
32624The size of the section.
32625@item total-size
32626The size of the overall executable to download.
32627@end table
32628
32629@noindent
32630At the end, a summary is printed.
32631
32632@subsubheading @value{GDBN} Command
32633
32634The corresponding @value{GDBN} command is @samp{load}.
32635
32636@subsubheading Example
32637
32638Note: each status message appears on a single line. Here the messages
32639have been broken down so that they can fit onto a page.
922fbb7b
AC
32640
32641@smallexample
594fe323 32642(gdb)
a2c02241
NR
32643-target-download
32644+download,@{section=".text",section-size="6668",total-size="9880"@}
32645+download,@{section=".text",section-sent="512",section-size="6668",
32646total-sent="512",total-size="9880"@}
32647+download,@{section=".text",section-sent="1024",section-size="6668",
32648total-sent="1024",total-size="9880"@}
32649+download,@{section=".text",section-sent="1536",section-size="6668",
32650total-sent="1536",total-size="9880"@}
32651+download,@{section=".text",section-sent="2048",section-size="6668",
32652total-sent="2048",total-size="9880"@}
32653+download,@{section=".text",section-sent="2560",section-size="6668",
32654total-sent="2560",total-size="9880"@}
32655+download,@{section=".text",section-sent="3072",section-size="6668",
32656total-sent="3072",total-size="9880"@}
32657+download,@{section=".text",section-sent="3584",section-size="6668",
32658total-sent="3584",total-size="9880"@}
32659+download,@{section=".text",section-sent="4096",section-size="6668",
32660total-sent="4096",total-size="9880"@}
32661+download,@{section=".text",section-sent="4608",section-size="6668",
32662total-sent="4608",total-size="9880"@}
32663+download,@{section=".text",section-sent="5120",section-size="6668",
32664total-sent="5120",total-size="9880"@}
32665+download,@{section=".text",section-sent="5632",section-size="6668",
32666total-sent="5632",total-size="9880"@}
32667+download,@{section=".text",section-sent="6144",section-size="6668",
32668total-sent="6144",total-size="9880"@}
32669+download,@{section=".text",section-sent="6656",section-size="6668",
32670total-sent="6656",total-size="9880"@}
32671+download,@{section=".init",section-size="28",total-size="9880"@}
32672+download,@{section=".fini",section-size="28",total-size="9880"@}
32673+download,@{section=".data",section-size="3156",total-size="9880"@}
32674+download,@{section=".data",section-sent="512",section-size="3156",
32675total-sent="7236",total-size="9880"@}
32676+download,@{section=".data",section-sent="1024",section-size="3156",
32677total-sent="7748",total-size="9880"@}
32678+download,@{section=".data",section-sent="1536",section-size="3156",
32679total-sent="8260",total-size="9880"@}
32680+download,@{section=".data",section-sent="2048",section-size="3156",
32681total-sent="8772",total-size="9880"@}
32682+download,@{section=".data",section-sent="2560",section-size="3156",
32683total-sent="9284",total-size="9880"@}
32684+download,@{section=".data",section-sent="3072",section-size="3156",
32685total-sent="9796",total-size="9880"@}
32686^done,address="0x10004",load-size="9880",transfer-rate="6586",
32687write-rate="429"
594fe323 32688(gdb)
922fbb7b
AC
32689@end smallexample
32690
32691
9901a55b 32692@ignore
a2c02241
NR
32693@subheading The @code{-target-exec-status} Command
32694@findex -target-exec-status
922fbb7b
AC
32695
32696@subsubheading Synopsis
32697
32698@smallexample
a2c02241 32699 -target-exec-status
922fbb7b
AC
32700@end smallexample
32701
a2c02241
NR
32702Provide information on the state of the target (whether it is running or
32703not, for instance).
922fbb7b 32704
a2c02241 32705@subsubheading @value{GDBN} Command
922fbb7b 32706
a2c02241
NR
32707There's no equivalent @value{GDBN} command.
32708
32709@subsubheading Example
32710N.A.
922fbb7b 32711
a2c02241
NR
32712
32713@subheading The @code{-target-list-available-targets} Command
32714@findex -target-list-available-targets
922fbb7b
AC
32715
32716@subsubheading Synopsis
32717
32718@smallexample
a2c02241 32719 -target-list-available-targets
922fbb7b
AC
32720@end smallexample
32721
a2c02241 32722List the possible targets to connect to.
922fbb7b 32723
a2c02241 32724@subsubheading @value{GDBN} Command
922fbb7b 32725
a2c02241 32726The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 32727
a2c02241
NR
32728@subsubheading Example
32729N.A.
32730
32731
32732@subheading The @code{-target-list-current-targets} Command
32733@findex -target-list-current-targets
922fbb7b
AC
32734
32735@subsubheading Synopsis
32736
32737@smallexample
a2c02241 32738 -target-list-current-targets
922fbb7b
AC
32739@end smallexample
32740
a2c02241 32741Describe the current target.
922fbb7b 32742
a2c02241 32743@subsubheading @value{GDBN} Command
922fbb7b 32744
a2c02241
NR
32745The corresponding information is printed by @samp{info file} (among
32746other things).
922fbb7b 32747
a2c02241
NR
32748@subsubheading Example
32749N.A.
32750
32751
32752@subheading The @code{-target-list-parameters} Command
32753@findex -target-list-parameters
922fbb7b
AC
32754
32755@subsubheading Synopsis
32756
32757@smallexample
a2c02241 32758 -target-list-parameters
922fbb7b
AC
32759@end smallexample
32760
a2c02241 32761@c ????
9901a55b 32762@end ignore
a2c02241
NR
32763
32764@subsubheading @value{GDBN} Command
32765
32766No equivalent.
922fbb7b
AC
32767
32768@subsubheading Example
a2c02241
NR
32769N.A.
32770
32771
32772@subheading The @code{-target-select} Command
32773@findex -target-select
32774
32775@subsubheading Synopsis
922fbb7b
AC
32776
32777@smallexample
a2c02241 32778 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
32779@end smallexample
32780
a2c02241 32781Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 32782
a2c02241
NR
32783@table @samp
32784@item @var{type}
75c99385 32785The type of target, for instance @samp{remote}, etc.
a2c02241
NR
32786@item @var{parameters}
32787Device names, host names and the like. @xref{Target Commands, ,
79a6e687 32788Commands for Managing Targets}, for more details.
a2c02241
NR
32789@end table
32790
32791The output is a connection notification, followed by the address at
32792which the target program is, in the following form:
922fbb7b
AC
32793
32794@smallexample
a2c02241
NR
32795^connected,addr="@var{address}",func="@var{function name}",
32796 args=[@var{arg list}]
922fbb7b
AC
32797@end smallexample
32798
a2c02241
NR
32799@subsubheading @value{GDBN} Command
32800
32801The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
32802
32803@subsubheading Example
922fbb7b 32804
265eeb58 32805@smallexample
594fe323 32806(gdb)
75c99385 32807-target-select remote /dev/ttya
a2c02241 32808^connected,addr="0xfe00a300",func="??",args=[]
594fe323 32809(gdb)
265eeb58 32810@end smallexample
ef21caaf 32811
a6b151f1
DJ
32812@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32813@node GDB/MI File Transfer Commands
32814@section @sc{gdb/mi} File Transfer Commands
32815
32816
32817@subheading The @code{-target-file-put} Command
32818@findex -target-file-put
32819
32820@subsubheading Synopsis
32821
32822@smallexample
32823 -target-file-put @var{hostfile} @var{targetfile}
32824@end smallexample
32825
32826Copy file @var{hostfile} from the host system (the machine running
32827@value{GDBN}) to @var{targetfile} on the target system.
32828
32829@subsubheading @value{GDBN} Command
32830
32831The corresponding @value{GDBN} command is @samp{remote put}.
32832
32833@subsubheading Example
32834
32835@smallexample
32836(gdb)
32837-target-file-put localfile remotefile
32838^done
32839(gdb)
32840@end smallexample
32841
32842
1763a388 32843@subheading The @code{-target-file-get} Command
a6b151f1
DJ
32844@findex -target-file-get
32845
32846@subsubheading Synopsis
32847
32848@smallexample
32849 -target-file-get @var{targetfile} @var{hostfile}
32850@end smallexample
32851
32852Copy file @var{targetfile} from the target system to @var{hostfile}
32853on the host system.
32854
32855@subsubheading @value{GDBN} Command
32856
32857The corresponding @value{GDBN} command is @samp{remote get}.
32858
32859@subsubheading Example
32860
32861@smallexample
32862(gdb)
32863-target-file-get remotefile localfile
32864^done
32865(gdb)
32866@end smallexample
32867
32868
32869@subheading The @code{-target-file-delete} Command
32870@findex -target-file-delete
32871
32872@subsubheading Synopsis
32873
32874@smallexample
32875 -target-file-delete @var{targetfile}
32876@end smallexample
32877
32878Delete @var{targetfile} from the target system.
32879
32880@subsubheading @value{GDBN} Command
32881
32882The corresponding @value{GDBN} command is @samp{remote delete}.
32883
32884@subsubheading Example
32885
32886@smallexample
32887(gdb)
32888-target-file-delete remotefile
32889^done
32890(gdb)
32891@end smallexample
32892
32893
ef21caaf
NR
32894@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32895@node GDB/MI Miscellaneous Commands
32896@section Miscellaneous @sc{gdb/mi} Commands
32897
32898@c @subheading -gdb-complete
32899
32900@subheading The @code{-gdb-exit} Command
32901@findex -gdb-exit
32902
32903@subsubheading Synopsis
32904
32905@smallexample
32906 -gdb-exit
32907@end smallexample
32908
32909Exit @value{GDBN} immediately.
32910
32911@subsubheading @value{GDBN} Command
32912
32913Approximately corresponds to @samp{quit}.
32914
32915@subsubheading Example
32916
32917@smallexample
594fe323 32918(gdb)
ef21caaf
NR
32919-gdb-exit
32920^exit
32921@end smallexample
32922
a2c02241 32923
9901a55b 32924@ignore
a2c02241
NR
32925@subheading The @code{-exec-abort} Command
32926@findex -exec-abort
32927
32928@subsubheading Synopsis
32929
32930@smallexample
32931 -exec-abort
32932@end smallexample
32933
32934Kill the inferior running program.
32935
32936@subsubheading @value{GDBN} Command
32937
32938The corresponding @value{GDBN} command is @samp{kill}.
32939
32940@subsubheading Example
32941N.A.
9901a55b 32942@end ignore
a2c02241
NR
32943
32944
ef21caaf
NR
32945@subheading The @code{-gdb-set} Command
32946@findex -gdb-set
32947
32948@subsubheading Synopsis
32949
32950@smallexample
32951 -gdb-set
32952@end smallexample
32953
32954Set an internal @value{GDBN} variable.
32955@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
32956
32957@subsubheading @value{GDBN} Command
32958
32959The corresponding @value{GDBN} command is @samp{set}.
32960
32961@subsubheading Example
32962
32963@smallexample
594fe323 32964(gdb)
ef21caaf
NR
32965-gdb-set $foo=3
32966^done
594fe323 32967(gdb)
ef21caaf
NR
32968@end smallexample
32969
32970
32971@subheading The @code{-gdb-show} Command
32972@findex -gdb-show
32973
32974@subsubheading Synopsis
32975
32976@smallexample
32977 -gdb-show
32978@end smallexample
32979
32980Show the current value of a @value{GDBN} variable.
32981
79a6e687 32982@subsubheading @value{GDBN} Command
ef21caaf
NR
32983
32984The corresponding @value{GDBN} command is @samp{show}.
32985
32986@subsubheading Example
32987
32988@smallexample
594fe323 32989(gdb)
ef21caaf
NR
32990-gdb-show annotate
32991^done,value="0"
594fe323 32992(gdb)
ef21caaf
NR
32993@end smallexample
32994
32995@c @subheading -gdb-source
32996
32997
32998@subheading The @code{-gdb-version} Command
32999@findex -gdb-version
33000
33001@subsubheading Synopsis
33002
33003@smallexample
33004 -gdb-version
33005@end smallexample
33006
33007Show version information for @value{GDBN}. Used mostly in testing.
33008
33009@subsubheading @value{GDBN} Command
33010
33011The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
33012default shows this information when you start an interactive session.
33013
33014@subsubheading Example
33015
33016@c This example modifies the actual output from GDB to avoid overfull
33017@c box in TeX.
33018@smallexample
594fe323 33019(gdb)
ef21caaf
NR
33020-gdb-version
33021~GNU gdb 5.2.1
33022~Copyright 2000 Free Software Foundation, Inc.
33023~GDB is free software, covered by the GNU General Public License, and
33024~you are welcome to change it and/or distribute copies of it under
33025~ certain conditions.
33026~Type "show copying" to see the conditions.
33027~There is absolutely no warranty for GDB. Type "show warranty" for
33028~ details.
33029~This GDB was configured as
33030 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
33031^done
594fe323 33032(gdb)
ef21caaf
NR
33033@end smallexample
33034
084344da
VP
33035@subheading The @code{-list-features} Command
33036@findex -list-features
33037
33038Returns a list of particular features of the MI protocol that
33039this version of gdb implements. A feature can be a command,
33040or a new field in an output of some command, or even an
33041important bugfix. While a frontend can sometimes detect presence
33042of a feature at runtime, it is easier to perform detection at debugger
33043startup.
33044
33045The command returns a list of strings, with each string naming an
33046available feature. Each returned string is just a name, it does not
33047have any internal structure. The list of possible feature names
33048is given below.
33049
33050Example output:
33051
33052@smallexample
33053(gdb) -list-features
33054^done,result=["feature1","feature2"]
33055@end smallexample
33056
33057The current list of features is:
33058
30e026bb
VP
33059@table @samp
33060@item frozen-varobjs
a05336a1
JB
33061Indicates support for the @code{-var-set-frozen} command, as well
33062as possible presense of the @code{frozen} field in the output
30e026bb
VP
33063of @code{-varobj-create}.
33064@item pending-breakpoints
a05336a1
JB
33065Indicates support for the @option{-f} option to the @code{-break-insert}
33066command.
b6313243 33067@item python
a05336a1 33068Indicates Python scripting support, Python-based
b6313243
TT
33069pretty-printing commands, and possible presence of the
33070@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 33071@item thread-info
a05336a1 33072Indicates support for the @code{-thread-info} command.
8dedea02 33073@item data-read-memory-bytes
a05336a1 33074Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 33075@code{-data-write-memory-bytes} commands.
39c4d40a
TT
33076@item breakpoint-notifications
33077Indicates that changes to breakpoints and breakpoints created via the
33078CLI will be announced via async records.
5d77fe44
JB
33079@item ada-task-info
33080Indicates support for the @code{-ada-task-info} command.
30e026bb 33081@end table
084344da 33082
c6ebd6cf
VP
33083@subheading The @code{-list-target-features} Command
33084@findex -list-target-features
33085
33086Returns a list of particular features that are supported by the
33087target. Those features affect the permitted MI commands, but
33088unlike the features reported by the @code{-list-features} command, the
33089features depend on which target GDB is using at the moment. Whenever
33090a target can change, due to commands such as @code{-target-select},
33091@code{-target-attach} or @code{-exec-run}, the list of target features
33092may change, and the frontend should obtain it again.
33093Example output:
33094
33095@smallexample
33096(gdb) -list-features
33097^done,result=["async"]
33098@end smallexample
33099
33100The current list of features is:
33101
33102@table @samp
33103@item async
33104Indicates that the target is capable of asynchronous command
33105execution, which means that @value{GDBN} will accept further commands
33106while the target is running.
33107
f75d858b
MK
33108@item reverse
33109Indicates that the target is capable of reverse execution.
33110@xref{Reverse Execution}, for more information.
33111
c6ebd6cf
VP
33112@end table
33113
c3b108f7
VP
33114@subheading The @code{-list-thread-groups} Command
33115@findex -list-thread-groups
33116
33117@subheading Synopsis
33118
33119@smallexample
dc146f7c 33120-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
33121@end smallexample
33122
dc146f7c
VP
33123Lists thread groups (@pxref{Thread groups}). When a single thread
33124group is passed as the argument, lists the children of that group.
33125When several thread group are passed, lists information about those
33126thread groups. Without any parameters, lists information about all
33127top-level thread groups.
33128
33129Normally, thread groups that are being debugged are reported.
33130With the @samp{--available} option, @value{GDBN} reports thread groups
33131available on the target.
33132
33133The output of this command may have either a @samp{threads} result or
33134a @samp{groups} result. The @samp{thread} result has a list of tuples
33135as value, with each tuple describing a thread (@pxref{GDB/MI Thread
33136Information}). The @samp{groups} result has a list of tuples as value,
33137each tuple describing a thread group. If top-level groups are
33138requested (that is, no parameter is passed), or when several groups
33139are passed, the output always has a @samp{groups} result. The format
33140of the @samp{group} result is described below.
33141
33142To reduce the number of roundtrips it's possible to list thread groups
33143together with their children, by passing the @samp{--recurse} option
33144and the recursion depth. Presently, only recursion depth of 1 is
33145permitted. If this option is present, then every reported thread group
33146will also include its children, either as @samp{group} or
33147@samp{threads} field.
33148
33149In general, any combination of option and parameters is permitted, with
33150the following caveats:
33151
33152@itemize @bullet
33153@item
33154When a single thread group is passed, the output will typically
33155be the @samp{threads} result. Because threads may not contain
33156anything, the @samp{recurse} option will be ignored.
33157
33158@item
33159When the @samp{--available} option is passed, limited information may
33160be available. In particular, the list of threads of a process might
33161be inaccessible. Further, specifying specific thread groups might
33162not give any performance advantage over listing all thread groups.
33163The frontend should assume that @samp{-list-thread-groups --available}
33164is always an expensive operation and cache the results.
33165
33166@end itemize
33167
33168The @samp{groups} result is a list of tuples, where each tuple may
33169have the following fields:
33170
33171@table @code
33172@item id
33173Identifier of the thread group. This field is always present.
a79b8f6e
VP
33174The identifier is an opaque string; frontends should not try to
33175convert it to an integer, even though it might look like one.
dc146f7c
VP
33176
33177@item type
33178The type of the thread group. At present, only @samp{process} is a
33179valid type.
33180
33181@item pid
33182The target-specific process identifier. This field is only present
a79b8f6e 33183for thread groups of type @samp{process} and only if the process exists.
c3b108f7 33184
dc146f7c
VP
33185@item num_children
33186The number of children this thread group has. This field may be
33187absent for an available thread group.
33188
33189@item threads
33190This field has a list of tuples as value, each tuple describing a
33191thread. It may be present if the @samp{--recurse} option is
33192specified, and it's actually possible to obtain the threads.
33193
33194@item cores
33195This field is a list of integers, each identifying a core that one
33196thread of the group is running on. This field may be absent if
33197such information is not available.
33198
a79b8f6e
VP
33199@item executable
33200The name of the executable file that corresponds to this thread group.
33201The field is only present for thread groups of type @samp{process},
33202and only if there is a corresponding executable file.
33203
dc146f7c 33204@end table
c3b108f7
VP
33205
33206@subheading Example
33207
33208@smallexample
33209@value{GDBP}
33210-list-thread-groups
33211^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
33212-list-thread-groups 17
33213^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
33214 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
33215@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
33216 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
33217 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
dc146f7c
VP
33218-list-thread-groups --available
33219^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
33220-list-thread-groups --available --recurse 1
33221 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33222 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33223 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
33224-list-thread-groups --available --recurse 1 17 18
33225^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33226 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33227 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 33228@end smallexample
c6ebd6cf 33229
f3e0e960
SS
33230@subheading The @code{-info-os} Command
33231@findex -info-os
33232
33233@subsubheading Synopsis
33234
33235@smallexample
33236-info-os [ @var{type} ]
33237@end smallexample
33238
33239If no argument is supplied, the command returns a table of available
33240operating-system-specific information types. If one of these types is
33241supplied as an argument @var{type}, then the command returns a table
33242of data of that type.
33243
33244The types of information available depend on the target operating
33245system.
33246
33247@subsubheading @value{GDBN} Command
33248
33249The corresponding @value{GDBN} command is @samp{info os}.
33250
33251@subsubheading Example
33252
33253When run on a @sc{gnu}/Linux system, the output will look something
33254like this:
33255
33256@smallexample
33257@value{GDBP}
33258-info-os
71caed83 33259^done,OSDataTable=@{nr_rows="9",nr_cols="3",
f3e0e960 33260hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
33261 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
33262 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
33263body=[item=@{col0="processes",col1="Listing of all processes",
33264 col2="Processes"@},
33265 item=@{col0="procgroups",col1="Listing of all process groups",
33266 col2="Process groups"@},
33267 item=@{col0="threads",col1="Listing of all threads",
33268 col2="Threads"@},
33269 item=@{col0="files",col1="Listing of all file descriptors",
33270 col2="File descriptors"@},
33271 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
33272 col2="Sockets"@},
33273 item=@{col0="shm",col1="Listing of all shared-memory regions",
33274 col2="Shared-memory regions"@},
33275 item=@{col0="semaphores",col1="Listing of all semaphores",
33276 col2="Semaphores"@},
33277 item=@{col0="msg",col1="Listing of all message queues",
33278 col2="Message queues"@},
33279 item=@{col0="modules",col1="Listing of all loaded kernel modules",
33280 col2="Kernel modules"@}]@}
f3e0e960
SS
33281@value{GDBP}
33282-info-os processes
33283^done,OSDataTable=@{nr_rows="190",nr_cols="4",
33284hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
33285 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
33286 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
33287 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
33288body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
33289 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
33290 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
33291 ...
33292 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
33293 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
33294(gdb)
33295@end smallexample
a79b8f6e 33296
71caed83
SS
33297(Note that the MI output here includes a @code{"Title"} column that
33298does not appear in command-line @code{info os}; this column is useful
33299for MI clients that want to enumerate the types of data, such as in a
33300popup menu, but is needless clutter on the command line, and
33301@code{info os} omits it.)
33302
a79b8f6e
VP
33303@subheading The @code{-add-inferior} Command
33304@findex -add-inferior
33305
33306@subheading Synopsis
33307
33308@smallexample
33309-add-inferior
33310@end smallexample
33311
33312Creates a new inferior (@pxref{Inferiors and Programs}). The created
33313inferior is not associated with any executable. Such association may
33314be established with the @samp{-file-exec-and-symbols} command
33315(@pxref{GDB/MI File Commands}). The command response has a single
33316field, @samp{thread-group}, whose value is the identifier of the
33317thread group corresponding to the new inferior.
33318
33319@subheading Example
33320
33321@smallexample
33322@value{GDBP}
33323-add-inferior
33324^done,thread-group="i3"
33325@end smallexample
33326
ef21caaf
NR
33327@subheading The @code{-interpreter-exec} Command
33328@findex -interpreter-exec
33329
33330@subheading Synopsis
33331
33332@smallexample
33333-interpreter-exec @var{interpreter} @var{command}
33334@end smallexample
a2c02241 33335@anchor{-interpreter-exec}
ef21caaf
NR
33336
33337Execute the specified @var{command} in the given @var{interpreter}.
33338
33339@subheading @value{GDBN} Command
33340
33341The corresponding @value{GDBN} command is @samp{interpreter-exec}.
33342
33343@subheading Example
33344
33345@smallexample
594fe323 33346(gdb)
ef21caaf
NR
33347-interpreter-exec console "break main"
33348&"During symbol reading, couldn't parse type; debugger out of date?.\n"
33349&"During symbol reading, bad structure-type format.\n"
33350~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
33351^done
594fe323 33352(gdb)
ef21caaf
NR
33353@end smallexample
33354
33355@subheading The @code{-inferior-tty-set} Command
33356@findex -inferior-tty-set
33357
33358@subheading Synopsis
33359
33360@smallexample
33361-inferior-tty-set /dev/pts/1
33362@end smallexample
33363
33364Set terminal for future runs of the program being debugged.
33365
33366@subheading @value{GDBN} Command
33367
33368The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
33369
33370@subheading Example
33371
33372@smallexample
594fe323 33373(gdb)
ef21caaf
NR
33374-inferior-tty-set /dev/pts/1
33375^done
594fe323 33376(gdb)
ef21caaf
NR
33377@end smallexample
33378
33379@subheading The @code{-inferior-tty-show} Command
33380@findex -inferior-tty-show
33381
33382@subheading Synopsis
33383
33384@smallexample
33385-inferior-tty-show
33386@end smallexample
33387
33388Show terminal for future runs of program being debugged.
33389
33390@subheading @value{GDBN} Command
33391
33392The corresponding @value{GDBN} command is @samp{show inferior-tty}.
33393
33394@subheading Example
33395
33396@smallexample
594fe323 33397(gdb)
ef21caaf
NR
33398-inferior-tty-set /dev/pts/1
33399^done
594fe323 33400(gdb)
ef21caaf
NR
33401-inferior-tty-show
33402^done,inferior_tty_terminal="/dev/pts/1"
594fe323 33403(gdb)
ef21caaf 33404@end smallexample
922fbb7b 33405
a4eefcd8
NR
33406@subheading The @code{-enable-timings} Command
33407@findex -enable-timings
33408
33409@subheading Synopsis
33410
33411@smallexample
33412-enable-timings [yes | no]
33413@end smallexample
33414
33415Toggle the printing of the wallclock, user and system times for an MI
33416command as a field in its output. This command is to help frontend
33417developers optimize the performance of their code. No argument is
33418equivalent to @samp{yes}.
33419
33420@subheading @value{GDBN} Command
33421
33422No equivalent.
33423
33424@subheading Example
33425
33426@smallexample
33427(gdb)
33428-enable-timings
33429^done
33430(gdb)
33431-break-insert main
33432^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
33433addr="0x080484ed",func="main",file="myprog.c",
33434fullname="/home/nickrob/myprog.c",line="73",times="0"@},
33435time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
33436(gdb)
33437-enable-timings no
33438^done
33439(gdb)
33440-exec-run
33441^running
33442(gdb)
a47ec5fe 33443*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
33444frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
33445@{name="argv",value="0xbfb60364"@}],file="myprog.c",
33446fullname="/home/nickrob/myprog.c",line="73"@}
33447(gdb)
33448@end smallexample
33449
922fbb7b
AC
33450@node Annotations
33451@chapter @value{GDBN} Annotations
33452
086432e2
AC
33453This chapter describes annotations in @value{GDBN}. Annotations were
33454designed to interface @value{GDBN} to graphical user interfaces or other
33455similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
33456relatively high level.
33457
d3e8051b 33458The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
33459(@pxref{GDB/MI}).
33460
922fbb7b
AC
33461@ignore
33462This is Edition @value{EDITION}, @value{DATE}.
33463@end ignore
33464
33465@menu
33466* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 33467* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
33468* Prompting:: Annotations marking @value{GDBN}'s need for input.
33469* Errors:: Annotations for error messages.
922fbb7b
AC
33470* Invalidation:: Some annotations describe things now invalid.
33471* Annotations for Running::
33472 Whether the program is running, how it stopped, etc.
33473* Source Annotations:: Annotations describing source code.
922fbb7b
AC
33474@end menu
33475
33476@node Annotations Overview
33477@section What is an Annotation?
33478@cindex annotations
33479
922fbb7b
AC
33480Annotations start with a newline character, two @samp{control-z}
33481characters, and the name of the annotation. If there is no additional
33482information associated with this annotation, the name of the annotation
33483is followed immediately by a newline. If there is additional
33484information, the name of the annotation is followed by a space, the
33485additional information, and a newline. The additional information
33486cannot contain newline characters.
33487
33488Any output not beginning with a newline and two @samp{control-z}
33489characters denotes literal output from @value{GDBN}. Currently there is
33490no need for @value{GDBN} to output a newline followed by two
33491@samp{control-z} characters, but if there was such a need, the
33492annotations could be extended with an @samp{escape} annotation which
33493means those three characters as output.
33494
086432e2
AC
33495The annotation @var{level}, which is specified using the
33496@option{--annotate} command line option (@pxref{Mode Options}), controls
33497how much information @value{GDBN} prints together with its prompt,
33498values of expressions, source lines, and other types of output. Level 0
d3e8051b 33499is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
33500subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
33501for programs that control @value{GDBN}, and level 2 annotations have
33502been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
33503Interface, annotate, GDB's Obsolete Annotations}).
33504
33505@table @code
33506@kindex set annotate
33507@item set annotate @var{level}
e09f16f9 33508The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 33509annotations to the specified @var{level}.
9c16f35a
EZ
33510
33511@item show annotate
33512@kindex show annotate
33513Show the current annotation level.
09d4efe1
EZ
33514@end table
33515
33516This chapter describes level 3 annotations.
086432e2 33517
922fbb7b
AC
33518A simple example of starting up @value{GDBN} with annotations is:
33519
33520@smallexample
086432e2
AC
33521$ @kbd{gdb --annotate=3}
33522GNU gdb 6.0
33523Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
33524GDB is free software, covered by the GNU General Public License,
33525and you are welcome to change it and/or distribute copies of it
33526under certain conditions.
33527Type "show copying" to see the conditions.
33528There is absolutely no warranty for GDB. Type "show warranty"
33529for details.
086432e2 33530This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
33531
33532^Z^Zpre-prompt
f7dc1244 33533(@value{GDBP})
922fbb7b 33534^Z^Zprompt
086432e2 33535@kbd{quit}
922fbb7b
AC
33536
33537^Z^Zpost-prompt
b383017d 33538$
922fbb7b
AC
33539@end smallexample
33540
33541Here @samp{quit} is input to @value{GDBN}; the rest is output from
33542@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
33543denotes a @samp{control-z} character) are annotations; the rest is
33544output from @value{GDBN}.
33545
9e6c4bd5
NR
33546@node Server Prefix
33547@section The Server Prefix
33548@cindex server prefix
33549
33550If you prefix a command with @samp{server } then it will not affect
33551the command history, nor will it affect @value{GDBN}'s notion of which
33552command to repeat if @key{RET} is pressed on a line by itself. This
33553means that commands can be run behind a user's back by a front-end in
33554a transparent manner.
33555
d837706a
NR
33556The @code{server } prefix does not affect the recording of values into
33557the value history; to print a value without recording it into the
33558value history, use the @code{output} command instead of the
33559@code{print} command.
33560
33561Using this prefix also disables confirmation requests
33562(@pxref{confirmation requests}).
9e6c4bd5 33563
922fbb7b
AC
33564@node Prompting
33565@section Annotation for @value{GDBN} Input
33566
33567@cindex annotations for prompts
33568When @value{GDBN} prompts for input, it annotates this fact so it is possible
33569to know when to send output, when the output from a given command is
33570over, etc.
33571
33572Different kinds of input each have a different @dfn{input type}. Each
33573input type has three annotations: a @code{pre-} annotation, which
33574denotes the beginning of any prompt which is being output, a plain
33575annotation, which denotes the end of the prompt, and then a @code{post-}
33576annotation which denotes the end of any echo which may (or may not) be
33577associated with the input. For example, the @code{prompt} input type
33578features the following annotations:
33579
33580@smallexample
33581^Z^Zpre-prompt
33582^Z^Zprompt
33583^Z^Zpost-prompt
33584@end smallexample
33585
33586The input types are
33587
33588@table @code
e5ac9b53
EZ
33589@findex pre-prompt annotation
33590@findex prompt annotation
33591@findex post-prompt annotation
922fbb7b
AC
33592@item prompt
33593When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
33594
e5ac9b53
EZ
33595@findex pre-commands annotation
33596@findex commands annotation
33597@findex post-commands annotation
922fbb7b
AC
33598@item commands
33599When @value{GDBN} prompts for a set of commands, like in the @code{commands}
33600command. The annotations are repeated for each command which is input.
33601
e5ac9b53
EZ
33602@findex pre-overload-choice annotation
33603@findex overload-choice annotation
33604@findex post-overload-choice annotation
922fbb7b
AC
33605@item overload-choice
33606When @value{GDBN} wants the user to select between various overloaded functions.
33607
e5ac9b53
EZ
33608@findex pre-query annotation
33609@findex query annotation
33610@findex post-query annotation
922fbb7b
AC
33611@item query
33612When @value{GDBN} wants the user to confirm a potentially dangerous operation.
33613
e5ac9b53
EZ
33614@findex pre-prompt-for-continue annotation
33615@findex prompt-for-continue annotation
33616@findex post-prompt-for-continue annotation
922fbb7b
AC
33617@item prompt-for-continue
33618When @value{GDBN} is asking the user to press return to continue. Note: Don't
33619expect this to work well; instead use @code{set height 0} to disable
33620prompting. This is because the counting of lines is buggy in the
33621presence of annotations.
33622@end table
33623
33624@node Errors
33625@section Errors
33626@cindex annotations for errors, warnings and interrupts
33627
e5ac9b53 33628@findex quit annotation
922fbb7b
AC
33629@smallexample
33630^Z^Zquit
33631@end smallexample
33632
33633This annotation occurs right before @value{GDBN} responds to an interrupt.
33634
e5ac9b53 33635@findex error annotation
922fbb7b
AC
33636@smallexample
33637^Z^Zerror
33638@end smallexample
33639
33640This annotation occurs right before @value{GDBN} responds to an error.
33641
33642Quit and error annotations indicate that any annotations which @value{GDBN} was
33643in the middle of may end abruptly. For example, if a
33644@code{value-history-begin} annotation is followed by a @code{error}, one
33645cannot expect to receive the matching @code{value-history-end}. One
33646cannot expect not to receive it either, however; an error annotation
33647does not necessarily mean that @value{GDBN} is immediately returning all the way
33648to the top level.
33649
e5ac9b53 33650@findex error-begin annotation
922fbb7b
AC
33651A quit or error annotation may be preceded by
33652
33653@smallexample
33654^Z^Zerror-begin
33655@end smallexample
33656
33657Any output between that and the quit or error annotation is the error
33658message.
33659
33660Warning messages are not yet annotated.
33661@c If we want to change that, need to fix warning(), type_error(),
33662@c range_error(), and possibly other places.
33663
922fbb7b
AC
33664@node Invalidation
33665@section Invalidation Notices
33666
33667@cindex annotations for invalidation messages
33668The following annotations say that certain pieces of state may have
33669changed.
33670
33671@table @code
e5ac9b53 33672@findex frames-invalid annotation
922fbb7b
AC
33673@item ^Z^Zframes-invalid
33674
33675The frames (for example, output from the @code{backtrace} command) may
33676have changed.
33677
e5ac9b53 33678@findex breakpoints-invalid annotation
922fbb7b
AC
33679@item ^Z^Zbreakpoints-invalid
33680
33681The breakpoints may have changed. For example, the user just added or
33682deleted a breakpoint.
33683@end table
33684
33685@node Annotations for Running
33686@section Running the Program
33687@cindex annotations for running programs
33688
e5ac9b53
EZ
33689@findex starting annotation
33690@findex stopping annotation
922fbb7b 33691When the program starts executing due to a @value{GDBN} command such as
b383017d 33692@code{step} or @code{continue},
922fbb7b
AC
33693
33694@smallexample
33695^Z^Zstarting
33696@end smallexample
33697
b383017d 33698is output. When the program stops,
922fbb7b
AC
33699
33700@smallexample
33701^Z^Zstopped
33702@end smallexample
33703
33704is output. Before the @code{stopped} annotation, a variety of
33705annotations describe how the program stopped.
33706
33707@table @code
e5ac9b53 33708@findex exited annotation
922fbb7b
AC
33709@item ^Z^Zexited @var{exit-status}
33710The program exited, and @var{exit-status} is the exit status (zero for
33711successful exit, otherwise nonzero).
33712
e5ac9b53
EZ
33713@findex signalled annotation
33714@findex signal-name annotation
33715@findex signal-name-end annotation
33716@findex signal-string annotation
33717@findex signal-string-end annotation
922fbb7b
AC
33718@item ^Z^Zsignalled
33719The program exited with a signal. After the @code{^Z^Zsignalled}, the
33720annotation continues:
33721
33722@smallexample
33723@var{intro-text}
33724^Z^Zsignal-name
33725@var{name}
33726^Z^Zsignal-name-end
33727@var{middle-text}
33728^Z^Zsignal-string
33729@var{string}
33730^Z^Zsignal-string-end
33731@var{end-text}
33732@end smallexample
33733
33734@noindent
33735where @var{name} is the name of the signal, such as @code{SIGILL} or
33736@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
33737as @code{Illegal Instruction} or @code{Segmentation fault}.
33738@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
33739user's benefit and have no particular format.
33740
e5ac9b53 33741@findex signal annotation
922fbb7b
AC
33742@item ^Z^Zsignal
33743The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
33744just saying that the program received the signal, not that it was
33745terminated with it.
33746
e5ac9b53 33747@findex breakpoint annotation
922fbb7b
AC
33748@item ^Z^Zbreakpoint @var{number}
33749The program hit breakpoint number @var{number}.
33750
e5ac9b53 33751@findex watchpoint annotation
922fbb7b
AC
33752@item ^Z^Zwatchpoint @var{number}
33753The program hit watchpoint number @var{number}.
33754@end table
33755
33756@node Source Annotations
33757@section Displaying Source
33758@cindex annotations for source display
33759
e5ac9b53 33760@findex source annotation
922fbb7b
AC
33761The following annotation is used instead of displaying source code:
33762
33763@smallexample
33764^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
33765@end smallexample
33766
33767where @var{filename} is an absolute file name indicating which source
33768file, @var{line} is the line number within that file (where 1 is the
33769first line in the file), @var{character} is the character position
33770within the file (where 0 is the first character in the file) (for most
33771debug formats this will necessarily point to the beginning of a line),
33772@var{middle} is @samp{middle} if @var{addr} is in the middle of the
33773line, or @samp{beg} if @var{addr} is at the beginning of the line, and
33774@var{addr} is the address in the target program associated with the
33775source which is being displayed. @var{addr} is in the form @samp{0x}
33776followed by one or more lowercase hex digits (note that this does not
33777depend on the language).
33778
4efc6507
DE
33779@node JIT Interface
33780@chapter JIT Compilation Interface
33781@cindex just-in-time compilation
33782@cindex JIT compilation interface
33783
33784This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
33785interface. A JIT compiler is a program or library that generates native
33786executable code at runtime and executes it, usually in order to achieve good
33787performance while maintaining platform independence.
33788
33789Programs that use JIT compilation are normally difficult to debug because
33790portions of their code are generated at runtime, instead of being loaded from
33791object files, which is where @value{GDBN} normally finds the program's symbols
33792and debug information. In order to debug programs that use JIT compilation,
33793@value{GDBN} has an interface that allows the program to register in-memory
33794symbol files with @value{GDBN} at runtime.
33795
33796If you are using @value{GDBN} to debug a program that uses this interface, then
33797it should work transparently so long as you have not stripped the binary. If
33798you are developing a JIT compiler, then the interface is documented in the rest
33799of this chapter. At this time, the only known client of this interface is the
33800LLVM JIT.
33801
33802Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
33803JIT compiler communicates with @value{GDBN} by writing data into a global
33804variable and calling a fuction at a well-known symbol. When @value{GDBN}
33805attaches, it reads a linked list of symbol files from the global variable to
33806find existing code, and puts a breakpoint in the function so that it can find
33807out about additional code.
33808
33809@menu
33810* Declarations:: Relevant C struct declarations
33811* Registering Code:: Steps to register code
33812* Unregistering Code:: Steps to unregister code
f85b53f8 33813* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
33814@end menu
33815
33816@node Declarations
33817@section JIT Declarations
33818
33819These are the relevant struct declarations that a C program should include to
33820implement the interface:
33821
33822@smallexample
33823typedef enum
33824@{
33825 JIT_NOACTION = 0,
33826 JIT_REGISTER_FN,
33827 JIT_UNREGISTER_FN
33828@} jit_actions_t;
33829
33830struct jit_code_entry
33831@{
33832 struct jit_code_entry *next_entry;
33833 struct jit_code_entry *prev_entry;
33834 const char *symfile_addr;
33835 uint64_t symfile_size;
33836@};
33837
33838struct jit_descriptor
33839@{
33840 uint32_t version;
33841 /* This type should be jit_actions_t, but we use uint32_t
33842 to be explicit about the bitwidth. */
33843 uint32_t action_flag;
33844 struct jit_code_entry *relevant_entry;
33845 struct jit_code_entry *first_entry;
33846@};
33847
33848/* GDB puts a breakpoint in this function. */
33849void __attribute__((noinline)) __jit_debug_register_code() @{ @};
33850
33851/* Make sure to specify the version statically, because the
33852 debugger may check the version before we can set it. */
33853struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
33854@end smallexample
33855
33856If the JIT is multi-threaded, then it is important that the JIT synchronize any
33857modifications to this global data properly, which can easily be done by putting
33858a global mutex around modifications to these structures.
33859
33860@node Registering Code
33861@section Registering Code
33862
33863To register code with @value{GDBN}, the JIT should follow this protocol:
33864
33865@itemize @bullet
33866@item
33867Generate an object file in memory with symbols and other desired debug
33868information. The file must include the virtual addresses of the sections.
33869
33870@item
33871Create a code entry for the file, which gives the start and size of the symbol
33872file.
33873
33874@item
33875Add it to the linked list in the JIT descriptor.
33876
33877@item
33878Point the relevant_entry field of the descriptor at the entry.
33879
33880@item
33881Set @code{action_flag} to @code{JIT_REGISTER} and call
33882@code{__jit_debug_register_code}.
33883@end itemize
33884
33885When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
33886@code{relevant_entry} pointer so it doesn't have to walk the list looking for
33887new code. However, the linked list must still be maintained in order to allow
33888@value{GDBN} to attach to a running process and still find the symbol files.
33889
33890@node Unregistering Code
33891@section Unregistering Code
33892
33893If code is freed, then the JIT should use the following protocol:
33894
33895@itemize @bullet
33896@item
33897Remove the code entry corresponding to the code from the linked list.
33898
33899@item
33900Point the @code{relevant_entry} field of the descriptor at the code entry.
33901
33902@item
33903Set @code{action_flag} to @code{JIT_UNREGISTER} and call
33904@code{__jit_debug_register_code}.
33905@end itemize
33906
33907If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
33908and the JIT will leak the memory used for the associated symbol files.
33909
f85b53f8
SD
33910@node Custom Debug Info
33911@section Custom Debug Info
33912@cindex custom JIT debug info
33913@cindex JIT debug info reader
33914
33915Generating debug information in platform-native file formats (like ELF
33916or COFF) may be an overkill for JIT compilers; especially if all the
33917debug info is used for is displaying a meaningful backtrace. The
33918issue can be resolved by having the JIT writers decide on a debug info
33919format and also provide a reader that parses the debug info generated
33920by the JIT compiler. This section gives a brief overview on writing
33921such a parser. More specific details can be found in the source file
33922@file{gdb/jit-reader.in}, which is also installed as a header at
33923@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
33924
33925The reader is implemented as a shared object (so this functionality is
33926not available on platforms which don't allow loading shared objects at
33927runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
33928@code{jit-reader-unload} are provided, to be used to load and unload
33929the readers from a preconfigured directory. Once loaded, the shared
33930object is used the parse the debug information emitted by the JIT
33931compiler.
33932
33933@menu
33934* Using JIT Debug Info Readers:: How to use supplied readers correctly
33935* Writing JIT Debug Info Readers:: Creating a debug-info reader
33936@end menu
33937
33938@node Using JIT Debug Info Readers
33939@subsection Using JIT Debug Info Readers
33940@kindex jit-reader-load
33941@kindex jit-reader-unload
33942
33943Readers can be loaded and unloaded using the @code{jit-reader-load}
33944and @code{jit-reader-unload} commands.
33945
33946@table @code
33947@item jit-reader-load @var{reader-name}
33948Load the JIT reader named @var{reader-name}. On a UNIX system, this
33949will usually load @file{@var{libdir}/gdb/@var{reader-name}}, where
33950@var{libdir} is the system library directory, usually
33951@file{/usr/local/lib}. Only one reader can be active at a time;
33952trying to load a second reader when one is already loaded will result
33953in @value{GDBN} reporting an error. A new JIT reader can be loaded by
33954first unloading the current one using @code{jit-reader-load} and then
33955invoking @code{jit-reader-load}.
33956
33957@item jit-reader-unload
33958Unload the currently loaded JIT reader.
33959
33960@end table
33961
33962@node Writing JIT Debug Info Readers
33963@subsection Writing JIT Debug Info Readers
33964@cindex writing JIT debug info readers
33965
33966As mentioned, a reader is essentially a shared object conforming to a
33967certain ABI. This ABI is described in @file{jit-reader.h}.
33968
33969@file{jit-reader.h} defines the structures, macros and functions
33970required to write a reader. It is installed (along with
33971@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
33972the system include directory.
33973
33974Readers need to be released under a GPL compatible license. A reader
33975can be declared as released under such a license by placing the macro
33976@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
33977
33978The entry point for readers is the symbol @code{gdb_init_reader},
33979which is expected to be a function with the prototype
33980
33981@findex gdb_init_reader
33982@smallexample
33983extern struct gdb_reader_funcs *gdb_init_reader (void);
33984@end smallexample
33985
33986@cindex @code{struct gdb_reader_funcs}
33987
33988@code{struct gdb_reader_funcs} contains a set of pointers to callback
33989functions. These functions are executed to read the debug info
33990generated by the JIT compiler (@code{read}), to unwind stack frames
33991(@code{unwind}) and to create canonical frame IDs
33992(@code{get_Frame_id}). It also has a callback that is called when the
33993reader is being unloaded (@code{destroy}). The struct looks like this
33994
33995@smallexample
33996struct gdb_reader_funcs
33997@{
33998 /* Must be set to GDB_READER_INTERFACE_VERSION. */
33999 int reader_version;
34000
34001 /* For use by the reader. */
34002 void *priv_data;
34003
34004 gdb_read_debug_info *read;
34005 gdb_unwind_frame *unwind;
34006 gdb_get_frame_id *get_frame_id;
34007 gdb_destroy_reader *destroy;
34008@};
34009@end smallexample
34010
34011@cindex @code{struct gdb_symbol_callbacks}
34012@cindex @code{struct gdb_unwind_callbacks}
34013
34014The callbacks are provided with another set of callbacks by
34015@value{GDBN} to do their job. For @code{read}, these callbacks are
34016passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
34017and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
34018@code{struct gdb_symbol_callbacks} has callbacks to create new object
34019files and new symbol tables inside those object files. @code{struct
34020gdb_unwind_callbacks} has callbacks to read registers off the current
34021frame and to write out the values of the registers in the previous
34022frame. Both have a callback (@code{target_read}) to read bytes off the
34023target's address space.
34024
d1feda86
YQ
34025@node In-Process Agent
34026@chapter In-Process Agent
34027@cindex debugging agent
34028The traditional debugging model is conceptually low-speed, but works fine,
34029because most bugs can be reproduced in debugging-mode execution. However,
34030as multi-core or many-core processors are becoming mainstream, and
34031multi-threaded programs become more and more popular, there should be more
34032and more bugs that only manifest themselves at normal-mode execution, for
34033example, thread races, because debugger's interference with the program's
34034timing may conceal the bugs. On the other hand, in some applications,
34035it is not feasible for the debugger to interrupt the program's execution
34036long enough for the developer to learn anything helpful about its behavior.
34037If the program's correctness depends on its real-time behavior, delays
34038introduced by a debugger might cause the program to fail, even when the
34039code itself is correct. It is useful to be able to observe the program's
34040behavior without interrupting it.
34041
34042Therefore, traditional debugging model is too intrusive to reproduce
34043some bugs. In order to reduce the interference with the program, we can
34044reduce the number of operations performed by debugger. The
34045@dfn{In-Process Agent}, a shared library, is running within the same
34046process with inferior, and is able to perform some debugging operations
34047itself. As a result, debugger is only involved when necessary, and
34048performance of debugging can be improved accordingly. Note that
34049interference with program can be reduced but can't be removed completely,
34050because the in-process agent will still stop or slow down the program.
34051
34052The in-process agent can interpret and execute Agent Expressions
34053(@pxref{Agent Expressions}) during performing debugging operations. The
34054agent expressions can be used for different purposes, such as collecting
34055data in tracepoints, and condition evaluation in breakpoints.
34056
34057@anchor{Control Agent}
34058You can control whether the in-process agent is used as an aid for
34059debugging with the following commands:
34060
34061@table @code
34062@kindex set agent on
34063@item set agent on
34064Causes the in-process agent to perform some operations on behalf of the
34065debugger. Just which operations requested by the user will be done
34066by the in-process agent depends on the its capabilities. For example,
34067if you request to evaluate breakpoint conditions in the in-process agent,
34068and the in-process agent has such capability as well, then breakpoint
34069conditions will be evaluated in the in-process agent.
34070
34071@kindex set agent off
34072@item set agent off
34073Disables execution of debugging operations by the in-process agent. All
34074of the operations will be performed by @value{GDBN}.
34075
34076@kindex show agent
34077@item show agent
34078Display the current setting of execution of debugging operations by
34079the in-process agent.
34080@end table
34081
16bdd41f
YQ
34082@menu
34083* In-Process Agent Protocol::
34084@end menu
34085
34086@node In-Process Agent Protocol
34087@section In-Process Agent Protocol
34088@cindex in-process agent protocol
34089
34090The in-process agent is able to communicate with both @value{GDBN} and
34091GDBserver (@pxref{In-Process Agent}). This section documents the protocol
34092used for communications between @value{GDBN} or GDBserver and the IPA.
34093In general, @value{GDBN} or GDBserver sends commands
34094(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
34095in-process agent replies back with the return result of the command, or
34096some other information. The data sent to in-process agent is composed
34097of primitive data types, such as 4-byte or 8-byte type, and composite
34098types, which are called objects (@pxref{IPA Protocol Objects}).
34099
34100@menu
34101* IPA Protocol Objects::
34102* IPA Protocol Commands::
34103@end menu
34104
34105@node IPA Protocol Objects
34106@subsection IPA Protocol Objects
34107@cindex ipa protocol objects
34108
34109The commands sent to and results received from agent may contain some
34110complex data types called @dfn{objects}.
34111
34112The in-process agent is running on the same machine with @value{GDBN}
34113or GDBserver, so it doesn't have to handle as much differences between
34114two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
34115However, there are still some differences of two ends in two processes:
34116
34117@enumerate
34118@item
34119word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
34120compiled as a 64-bit executable, while in-process agent is a 32-bit one.
34121@item
34122ABI. Some machines may have multiple types of ABI, @value{GDBN} or
34123GDBserver is compiled with one, and in-process agent is compiled with
34124the other one.
34125@end enumerate
34126
34127Here are the IPA Protocol Objects:
34128
34129@enumerate
34130@item
34131agent expression object. It represents an agent expression
34132(@pxref{Agent Expressions}).
34133@anchor{agent expression object}
34134@item
34135tracepoint action object. It represents a tracepoint action
34136(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
34137memory, static trace data and to evaluate expression.
34138@anchor{tracepoint action object}
34139@item
34140tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
34141@anchor{tracepoint object}
34142
34143@end enumerate
34144
34145The following table describes important attributes of each IPA protocol
34146object:
34147
34148@multitable @columnfractions .30 .20 .50
34149@headitem Name @tab Size @tab Description
34150@item @emph{agent expression object} @tab @tab
34151@item length @tab 4 @tab length of bytes code
34152@item byte code @tab @var{length} @tab contents of byte code
34153@item @emph{tracepoint action for collecting memory} @tab @tab
34154@item 'M' @tab 1 @tab type of tracepoint action
34155@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
34156address of the lowest byte to collect, otherwise @var{addr} is the offset
34157of @var{basereg} for memory collecting.
34158@item len @tab 8 @tab length of memory for collecting
34159@item basereg @tab 4 @tab the register number containing the starting
34160memory address for collecting.
34161@item @emph{tracepoint action for collecting registers} @tab @tab
34162@item 'R' @tab 1 @tab type of tracepoint action
34163@item @emph{tracepoint action for collecting static trace data} @tab @tab
34164@item 'L' @tab 1 @tab type of tracepoint action
34165@item @emph{tracepoint action for expression evaluation} @tab @tab
34166@item 'X' @tab 1 @tab type of tracepoint action
34167@item agent expression @tab length of @tab @ref{agent expression object}
34168@item @emph{tracepoint object} @tab @tab
34169@item number @tab 4 @tab number of tracepoint
34170@item address @tab 8 @tab address of tracepoint inserted on
34171@item type @tab 4 @tab type of tracepoint
34172@item enabled @tab 1 @tab enable or disable of tracepoint
34173@item step_count @tab 8 @tab step
34174@item pass_count @tab 8 @tab pass
34175@item numactions @tab 4 @tab number of tracepoint actions
34176@item hit count @tab 8 @tab hit count
34177@item trace frame usage @tab 8 @tab trace frame usage
34178@item compiled_cond @tab 8 @tab compiled condition
34179@item orig_size @tab 8 @tab orig size
34180@item condition @tab 4 if condition is NULL otherwise length of
34181@ref{agent expression object}
34182@tab zero if condition is NULL, otherwise is
34183@ref{agent expression object}
34184@item actions @tab variable
34185@tab numactions number of @ref{tracepoint action object}
34186@end multitable
34187
34188@node IPA Protocol Commands
34189@subsection IPA Protocol Commands
34190@cindex ipa protocol commands
34191
34192The spaces in each command are delimiters to ease reading this commands
34193specification. They don't exist in real commands.
34194
34195@table @samp
34196
34197@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
34198Installs a new fast tracepoint described by @var{tracepoint_object}
34199(@pxref{tracepoint object}). @var{gdb_jump_pad_head}, 8-byte long, is the
34200head of @dfn{jumppad}, which is used to jump to data collection routine
34201in IPA finally.
34202
34203Replies:
34204@table @samp
34205@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
34206@var{target_address} is address of tracepoint in the inferior.
34207@var{gdb_jump_pad_head} is updated head of jumppad. Both of
34208@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
34209@var{fjump} contains a sequence of instructions jump to jumppad entry.
34210@var{fjump_size}, 4-byte long, is the size of @var{fjump}.
34211@item E @var{NN}
34212for an error
34213
34214@end table
34215
7255706c
YQ
34216@item close
34217Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
34218is about to kill inferiors.
34219
16bdd41f
YQ
34220@item qTfSTM
34221@xref{qTfSTM}.
34222@item qTsSTM
34223@xref{qTsSTM}.
34224@item qTSTMat
34225@xref{qTSTMat}.
34226@item probe_marker_at:@var{address}
34227Asks in-process agent to probe the marker at @var{address}.
34228
34229Replies:
34230@table @samp
34231@item E @var{NN}
34232for an error
34233@end table
34234@item unprobe_marker_at:@var{address}
34235Asks in-process agent to unprobe the marker at @var{address}.
34236@end table
34237
8e04817f
AC
34238@node GDB Bugs
34239@chapter Reporting Bugs in @value{GDBN}
34240@cindex bugs in @value{GDBN}
34241@cindex reporting bugs in @value{GDBN}
c906108c 34242
8e04817f 34243Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 34244
8e04817f
AC
34245Reporting a bug may help you by bringing a solution to your problem, or it
34246may not. But in any case the principal function of a bug report is to help
34247the entire community by making the next version of @value{GDBN} work better. Bug
34248reports are your contribution to the maintenance of @value{GDBN}.
c906108c 34249
8e04817f
AC
34250In order for a bug report to serve its purpose, you must include the
34251information that enables us to fix the bug.
c4555f82
SC
34252
34253@menu
8e04817f
AC
34254* Bug Criteria:: Have you found a bug?
34255* Bug Reporting:: How to report bugs
c4555f82
SC
34256@end menu
34257
8e04817f 34258@node Bug Criteria
79a6e687 34259@section Have You Found a Bug?
8e04817f 34260@cindex bug criteria
c4555f82 34261
8e04817f 34262If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
34263
34264@itemize @bullet
8e04817f
AC
34265@cindex fatal signal
34266@cindex debugger crash
34267@cindex crash of debugger
c4555f82 34268@item
8e04817f
AC
34269If the debugger gets a fatal signal, for any input whatever, that is a
34270@value{GDBN} bug. Reliable debuggers never crash.
34271
34272@cindex error on valid input
34273@item
34274If @value{GDBN} produces an error message for valid input, that is a
34275bug. (Note that if you're cross debugging, the problem may also be
34276somewhere in the connection to the target.)
c4555f82 34277
8e04817f 34278@cindex invalid input
c4555f82 34279@item
8e04817f
AC
34280If @value{GDBN} does not produce an error message for invalid input,
34281that is a bug. However, you should note that your idea of
34282``invalid input'' might be our idea of ``an extension'' or ``support
34283for traditional practice''.
34284
34285@item
34286If you are an experienced user of debugging tools, your suggestions
34287for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
34288@end itemize
34289
8e04817f 34290@node Bug Reporting
79a6e687 34291@section How to Report Bugs
8e04817f
AC
34292@cindex bug reports
34293@cindex @value{GDBN} bugs, reporting
34294
34295A number of companies and individuals offer support for @sc{gnu} products.
34296If you obtained @value{GDBN} from a support organization, we recommend you
34297contact that organization first.
34298
34299You can find contact information for many support companies and
34300individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
34301distribution.
34302@c should add a web page ref...
34303
c16158bc
JM
34304@ifset BUGURL
34305@ifset BUGURL_DEFAULT
129188f6 34306In any event, we also recommend that you submit bug reports for
d3e8051b 34307@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
34308@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
34309page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
34310be used.
8e04817f
AC
34311
34312@strong{Do not send bug reports to @samp{info-gdb}, or to
34313@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
34314not want to receive bug reports. Those that do have arranged to receive
34315@samp{bug-gdb}.
34316
34317The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
34318serves as a repeater. The mailing list and the newsgroup carry exactly
34319the same messages. Often people think of posting bug reports to the
34320newsgroup instead of mailing them. This appears to work, but it has one
34321problem which can be crucial: a newsgroup posting often lacks a mail
34322path back to the sender. Thus, if we need to ask for more information,
34323we may be unable to reach you. For this reason, it is better to send
34324bug reports to the mailing list.
c16158bc
JM
34325@end ifset
34326@ifclear BUGURL_DEFAULT
34327In any event, we also recommend that you submit bug reports for
34328@value{GDBN} to @value{BUGURL}.
34329@end ifclear
34330@end ifset
c4555f82 34331
8e04817f
AC
34332The fundamental principle of reporting bugs usefully is this:
34333@strong{report all the facts}. If you are not sure whether to state a
34334fact or leave it out, state it!
c4555f82 34335
8e04817f
AC
34336Often people omit facts because they think they know what causes the
34337problem and assume that some details do not matter. Thus, you might
34338assume that the name of the variable you use in an example does not matter.
34339Well, probably it does not, but one cannot be sure. Perhaps the bug is a
34340stray memory reference which happens to fetch from the location where that
34341name is stored in memory; perhaps, if the name were different, the contents
34342of that location would fool the debugger into doing the right thing despite
34343the bug. Play it safe and give a specific, complete example. That is the
34344easiest thing for you to do, and the most helpful.
c4555f82 34345
8e04817f
AC
34346Keep in mind that the purpose of a bug report is to enable us to fix the
34347bug. It may be that the bug has been reported previously, but neither
34348you nor we can know that unless your bug report is complete and
34349self-contained.
c4555f82 34350
8e04817f
AC
34351Sometimes people give a few sketchy facts and ask, ``Does this ring a
34352bell?'' Those bug reports are useless, and we urge everyone to
34353@emph{refuse to respond to them} except to chide the sender to report
34354bugs properly.
34355
34356To enable us to fix the bug, you should include all these things:
c4555f82
SC
34357
34358@itemize @bullet
34359@item
8e04817f
AC
34360The version of @value{GDBN}. @value{GDBN} announces it if you start
34361with no arguments; you can also print it at any time using @code{show
34362version}.
c4555f82 34363
8e04817f
AC
34364Without this, we will not know whether there is any point in looking for
34365the bug in the current version of @value{GDBN}.
c4555f82
SC
34366
34367@item
8e04817f
AC
34368The type of machine you are using, and the operating system name and
34369version number.
c4555f82
SC
34370
34371@item
c1468174 34372What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 34373``@value{GCC}--2.8.1''.
c4555f82
SC
34374
34375@item
8e04817f 34376What compiler (and its version) was used to compile the program you are
c1468174 34377debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
34378C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
34379to get this information; for other compilers, see the documentation for
34380those compilers.
c4555f82 34381
8e04817f
AC
34382@item
34383The command arguments you gave the compiler to compile your example and
34384observe the bug. For example, did you use @samp{-O}? To guarantee
34385you will not omit something important, list them all. A copy of the
34386Makefile (or the output from make) is sufficient.
c4555f82 34387
8e04817f
AC
34388If we were to try to guess the arguments, we would probably guess wrong
34389and then we might not encounter the bug.
c4555f82 34390
8e04817f
AC
34391@item
34392A complete input script, and all necessary source files, that will
34393reproduce the bug.
c4555f82 34394
8e04817f
AC
34395@item
34396A description of what behavior you observe that you believe is
34397incorrect. For example, ``It gets a fatal signal.''
c4555f82 34398
8e04817f
AC
34399Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
34400will certainly notice it. But if the bug is incorrect output, we might
34401not notice unless it is glaringly wrong. You might as well not give us
34402a chance to make a mistake.
c4555f82 34403
8e04817f
AC
34404Even if the problem you experience is a fatal signal, you should still
34405say so explicitly. Suppose something strange is going on, such as, your
34406copy of @value{GDBN} is out of synch, or you have encountered a bug in
34407the C library on your system. (This has happened!) Your copy might
34408crash and ours would not. If you told us to expect a crash, then when
34409ours fails to crash, we would know that the bug was not happening for
34410us. If you had not told us to expect a crash, then we would not be able
34411to draw any conclusion from our observations.
c4555f82 34412
e0c07bf0
MC
34413@pindex script
34414@cindex recording a session script
34415To collect all this information, you can use a session recording program
34416such as @command{script}, which is available on many Unix systems.
34417Just run your @value{GDBN} session inside @command{script} and then
34418include the @file{typescript} file with your bug report.
34419
34420Another way to record a @value{GDBN} session is to run @value{GDBN}
34421inside Emacs and then save the entire buffer to a file.
34422
8e04817f
AC
34423@item
34424If you wish to suggest changes to the @value{GDBN} source, send us context
34425diffs. If you even discuss something in the @value{GDBN} source, refer to
34426it by context, not by line number.
c4555f82 34427
8e04817f
AC
34428The line numbers in our development sources will not match those in your
34429sources. Your line numbers would convey no useful information to us.
c4555f82 34430
8e04817f 34431@end itemize
c4555f82 34432
8e04817f 34433Here are some things that are not necessary:
c4555f82 34434
8e04817f
AC
34435@itemize @bullet
34436@item
34437A description of the envelope of the bug.
c4555f82 34438
8e04817f
AC
34439Often people who encounter a bug spend a lot of time investigating
34440which changes to the input file will make the bug go away and which
34441changes will not affect it.
c4555f82 34442
8e04817f
AC
34443This is often time consuming and not very useful, because the way we
34444will find the bug is by running a single example under the debugger
34445with breakpoints, not by pure deduction from a series of examples.
34446We recommend that you save your time for something else.
c4555f82 34447
8e04817f
AC
34448Of course, if you can find a simpler example to report @emph{instead}
34449of the original one, that is a convenience for us. Errors in the
34450output will be easier to spot, running under the debugger will take
34451less time, and so on.
c4555f82 34452
8e04817f
AC
34453However, simplification is not vital; if you do not want to do this,
34454report the bug anyway and send us the entire test case you used.
c4555f82 34455
8e04817f
AC
34456@item
34457A patch for the bug.
c4555f82 34458
8e04817f
AC
34459A patch for the bug does help us if it is a good one. But do not omit
34460the necessary information, such as the test case, on the assumption that
34461a patch is all we need. We might see problems with your patch and decide
34462to fix the problem another way, or we might not understand it at all.
c4555f82 34463
8e04817f
AC
34464Sometimes with a program as complicated as @value{GDBN} it is very hard to
34465construct an example that will make the program follow a certain path
34466through the code. If you do not send us the example, we will not be able
34467to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 34468
8e04817f
AC
34469And if we cannot understand what bug you are trying to fix, or why your
34470patch should be an improvement, we will not install it. A test case will
34471help us to understand.
c4555f82 34472
8e04817f
AC
34473@item
34474A guess about what the bug is or what it depends on.
c4555f82 34475
8e04817f
AC
34476Such guesses are usually wrong. Even we cannot guess right about such
34477things without first using the debugger to find the facts.
34478@end itemize
c4555f82 34479
8e04817f
AC
34480@c The readline documentation is distributed with the readline code
34481@c and consists of the two following files:
cc88a640
JK
34482@c rluser.texi
34483@c hsuser.texi
8e04817f
AC
34484@c Use -I with makeinfo to point to the appropriate directory,
34485@c environment var TEXINPUTS with TeX.
39037522 34486@ifclear SYSTEM_READLINE
5bdf8622 34487@include rluser.texi
cc88a640 34488@include hsuser.texi
39037522 34489@end ifclear
c4555f82 34490
4ceed123
JB
34491@node In Memoriam
34492@appendix In Memoriam
34493
9ed350ad
JB
34494The @value{GDBN} project mourns the loss of the following long-time
34495contributors:
4ceed123
JB
34496
34497@table @code
34498@item Fred Fish
9ed350ad
JB
34499Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
34500to Free Software in general. Outside of @value{GDBN}, he was known in
34501the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
34502
34503@item Michael Snyder
9ed350ad
JB
34504Michael was one of the Global Maintainers of the @value{GDBN} project,
34505with contributions recorded as early as 1996, until 2011. In addition
34506to his day to day participation, he was a large driving force behind
34507adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
34508@end table
34509
34510Beyond their technical contributions to the project, they were also
34511enjoyable members of the Free Software Community. We will miss them.
c4555f82 34512
8e04817f
AC
34513@node Formatting Documentation
34514@appendix Formatting Documentation
c4555f82 34515
8e04817f
AC
34516@cindex @value{GDBN} reference card
34517@cindex reference card
34518The @value{GDBN} 4 release includes an already-formatted reference card, ready
34519for printing with PostScript or Ghostscript, in the @file{gdb}
34520subdirectory of the main source directory@footnote{In
34521@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
34522release.}. If you can use PostScript or Ghostscript with your printer,
34523you can print the reference card immediately with @file{refcard.ps}.
c4555f82 34524
8e04817f
AC
34525The release also includes the source for the reference card. You
34526can format it, using @TeX{}, by typing:
c4555f82 34527
474c8240 34528@smallexample
8e04817f 34529make refcard.dvi
474c8240 34530@end smallexample
c4555f82 34531
8e04817f
AC
34532The @value{GDBN} reference card is designed to print in @dfn{landscape}
34533mode on US ``letter'' size paper;
34534that is, on a sheet 11 inches wide by 8.5 inches
34535high. You will need to specify this form of printing as an option to
34536your @sc{dvi} output program.
c4555f82 34537
8e04817f 34538@cindex documentation
c4555f82 34539
8e04817f
AC
34540All the documentation for @value{GDBN} comes as part of the machine-readable
34541distribution. The documentation is written in Texinfo format, which is
34542a documentation system that uses a single source file to produce both
34543on-line information and a printed manual. You can use one of the Info
34544formatting commands to create the on-line version of the documentation
34545and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 34546
8e04817f
AC
34547@value{GDBN} includes an already formatted copy of the on-line Info
34548version of this manual in the @file{gdb} subdirectory. The main Info
34549file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
34550subordinate files matching @samp{gdb.info*} in the same directory. If
34551necessary, you can print out these files, or read them with any editor;
34552but they are easier to read using the @code{info} subsystem in @sc{gnu}
34553Emacs or the standalone @code{info} program, available as part of the
34554@sc{gnu} Texinfo distribution.
c4555f82 34555
8e04817f
AC
34556If you want to format these Info files yourself, you need one of the
34557Info formatting programs, such as @code{texinfo-format-buffer} or
34558@code{makeinfo}.
c4555f82 34559
8e04817f
AC
34560If you have @code{makeinfo} installed, and are in the top level
34561@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
34562version @value{GDBVN}), you can make the Info file by typing:
c4555f82 34563
474c8240 34564@smallexample
8e04817f
AC
34565cd gdb
34566make gdb.info
474c8240 34567@end smallexample
c4555f82 34568
8e04817f
AC
34569If you want to typeset and print copies of this manual, you need @TeX{},
34570a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
34571Texinfo definitions file.
c4555f82 34572
8e04817f
AC
34573@TeX{} is a typesetting program; it does not print files directly, but
34574produces output files called @sc{dvi} files. To print a typeset
34575document, you need a program to print @sc{dvi} files. If your system
34576has @TeX{} installed, chances are it has such a program. The precise
34577command to use depends on your system; @kbd{lpr -d} is common; another
34578(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
34579require a file name without any extension or a @samp{.dvi} extension.
c4555f82 34580
8e04817f
AC
34581@TeX{} also requires a macro definitions file called
34582@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
34583written in Texinfo format. On its own, @TeX{} cannot either read or
34584typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
34585and is located in the @file{gdb-@var{version-number}/texinfo}
34586directory.
c4555f82 34587
8e04817f 34588If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 34589typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
34590subdirectory of the main source directory (for example, to
34591@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 34592
474c8240 34593@smallexample
8e04817f 34594make gdb.dvi
474c8240 34595@end smallexample
c4555f82 34596
8e04817f 34597Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 34598
8e04817f
AC
34599@node Installing GDB
34600@appendix Installing @value{GDBN}
8e04817f 34601@cindex installation
c4555f82 34602
7fa2210b
DJ
34603@menu
34604* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 34605* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
34606* Separate Objdir:: Compiling @value{GDBN} in another directory
34607* Config Names:: Specifying names for hosts and targets
34608* Configure Options:: Summary of options for configure
098b41a6 34609* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
34610@end menu
34611
34612@node Requirements
79a6e687 34613@section Requirements for Building @value{GDBN}
7fa2210b
DJ
34614@cindex building @value{GDBN}, requirements for
34615
34616Building @value{GDBN} requires various tools and packages to be available.
34617Other packages will be used only if they are found.
34618
79a6e687 34619@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b
DJ
34620@table @asis
34621@item ISO C90 compiler
34622@value{GDBN} is written in ISO C90. It should be buildable with any
34623working C90 compiler, e.g.@: GCC.
34624
34625@end table
34626
79a6e687 34627@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
34628@table @asis
34629@item Expat
123dc839 34630@anchor{Expat}
7fa2210b
DJ
34631@value{GDBN} can use the Expat XML parsing library. This library may be
34632included with your operating system distribution; if it is not, you
34633can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 34634The @file{configure} script will search for this library in several
7fa2210b
DJ
34635standard locations; if it is installed in an unusual path, you can
34636use the @option{--with-libexpat-prefix} option to specify its location.
34637
9cceb671
DJ
34638Expat is used for:
34639
34640@itemize @bullet
34641@item
34642Remote protocol memory maps (@pxref{Memory Map Format})
34643@item
34644Target descriptions (@pxref{Target Descriptions})
34645@item
2268b414
JK
34646Remote shared library lists (@xref{Library List Format},
34647or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
34648@item
34649MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
34650@item
34651Traceframe info (@pxref{Traceframe Info Format})
9cceb671 34652@end itemize
7fa2210b 34653
31fffb02
CS
34654@item zlib
34655@cindex compressed debug sections
34656@value{GDBN} will use the @samp{zlib} library, if available, to read
34657compressed debug sections. Some linkers, such as GNU gold, are capable
34658of producing binaries with compressed debug sections. If @value{GDBN}
34659is compiled with @samp{zlib}, it will be able to read the debug
34660information in such binaries.
34661
34662The @samp{zlib} library is likely included with your operating system
34663distribution; if it is not, you can get the latest version from
34664@url{http://zlib.net}.
34665
6c7a06a3
TT
34666@item iconv
34667@value{GDBN}'s features related to character sets (@pxref{Character
34668Sets}) require a functioning @code{iconv} implementation. If you are
34669on a GNU system, then this is provided by the GNU C Library. Some
34670other systems also provide a working @code{iconv}.
34671
478aac75
DE
34672If @value{GDBN} is using the @code{iconv} program which is installed
34673in a non-standard place, you will need to tell @value{GDBN} where to find it.
34674This is done with @option{--with-iconv-bin} which specifies the
34675directory that contains the @code{iconv} program.
34676
34677On systems without @code{iconv}, you can install GNU Libiconv. If you
6c7a06a3
TT
34678have previously installed Libiconv, you can use the
34679@option{--with-libiconv-prefix} option to configure.
34680
34681@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
34682arrange to build Libiconv if a directory named @file{libiconv} appears
34683in the top-most source directory. If Libiconv is built this way, and
34684if the operating system does not provide a suitable @code{iconv}
34685implementation, then the just-built library will automatically be used
34686by @value{GDBN}. One easy way to set this up is to download GNU
34687Libiconv, unpack it, and then rename the directory holding the
34688Libiconv source code to @samp{libiconv}.
7fa2210b
DJ
34689@end table
34690
34691@node Running Configure
db2e3e2e 34692@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 34693@cindex configuring @value{GDBN}
db2e3e2e 34694@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
34695of preparing @value{GDBN} for installation; you can then use @code{make} to
34696build the @code{gdb} program.
34697@iftex
34698@c irrelevant in info file; it's as current as the code it lives with.
34699@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
34700look at the @file{README} file in the sources; we may have improved the
34701installation procedures since publishing this manual.}
34702@end iftex
c4555f82 34703
8e04817f
AC
34704The @value{GDBN} distribution includes all the source code you need for
34705@value{GDBN} in a single directory, whose name is usually composed by
34706appending the version number to @samp{gdb}.
c4555f82 34707
8e04817f
AC
34708For example, the @value{GDBN} version @value{GDBVN} distribution is in the
34709@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 34710
8e04817f
AC
34711@table @code
34712@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
34713script for configuring @value{GDBN} and all its supporting libraries
c4555f82 34714
8e04817f
AC
34715@item gdb-@value{GDBVN}/gdb
34716the source specific to @value{GDBN} itself
c4555f82 34717
8e04817f
AC
34718@item gdb-@value{GDBVN}/bfd
34719source for the Binary File Descriptor library
c906108c 34720
8e04817f
AC
34721@item gdb-@value{GDBVN}/include
34722@sc{gnu} include files
c906108c 34723
8e04817f
AC
34724@item gdb-@value{GDBVN}/libiberty
34725source for the @samp{-liberty} free software library
c906108c 34726
8e04817f
AC
34727@item gdb-@value{GDBVN}/opcodes
34728source for the library of opcode tables and disassemblers
c906108c 34729
8e04817f
AC
34730@item gdb-@value{GDBVN}/readline
34731source for the @sc{gnu} command-line interface
c906108c 34732
8e04817f
AC
34733@item gdb-@value{GDBVN}/glob
34734source for the @sc{gnu} filename pattern-matching subroutine
c906108c 34735
8e04817f
AC
34736@item gdb-@value{GDBVN}/mmalloc
34737source for the @sc{gnu} memory-mapped malloc package
34738@end table
c906108c 34739
db2e3e2e 34740The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
34741from the @file{gdb-@var{version-number}} source directory, which in
34742this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 34743
8e04817f 34744First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 34745if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
34746identifier for the platform on which @value{GDBN} will run as an
34747argument.
c906108c 34748
8e04817f 34749For example:
c906108c 34750
474c8240 34751@smallexample
8e04817f
AC
34752cd gdb-@value{GDBVN}
34753./configure @var{host}
34754make
474c8240 34755@end smallexample
c906108c 34756
8e04817f
AC
34757@noindent
34758where @var{host} is an identifier such as @samp{sun4} or
34759@samp{decstation}, that identifies the platform where @value{GDBN} will run.
db2e3e2e 34760(You can often leave off @var{host}; @file{configure} tries to guess the
8e04817f 34761correct value by examining your system.)
c906108c 34762
8e04817f
AC
34763Running @samp{configure @var{host}} and then running @code{make} builds the
34764@file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
34765libraries, then @code{gdb} itself. The configured source files, and the
34766binaries, are left in the corresponding source directories.
c906108c 34767
8e04817f 34768@need 750
db2e3e2e 34769@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
34770system does not recognize this automatically when you run a different
34771shell, you may need to run @code{sh} on it explicitly:
c906108c 34772
474c8240 34773@smallexample
8e04817f 34774sh configure @var{host}
474c8240 34775@end smallexample
c906108c 34776
db2e3e2e 34777If you run @file{configure} from a directory that contains source
8e04817f 34778directories for multiple libraries or programs, such as the
db2e3e2e
BW
34779@file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
34780@file{configure}
8e04817f
AC
34781creates configuration files for every directory level underneath (unless
34782you tell it not to, with the @samp{--norecursion} option).
34783
db2e3e2e 34784You should run the @file{configure} script from the top directory in the
94e91d6d 34785source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 34786@file{configure} from one of the subdirectories, you will configure only
94e91d6d 34787that subdirectory. That is usually not what you want. In particular,
db2e3e2e 34788if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
34789of the @file{gdb-@var{version-number}} directory, you will omit the
34790configuration of @file{bfd}, @file{readline}, and other sibling
34791directories of the @file{gdb} subdirectory. This leads to build errors
34792about missing include files such as @file{bfd/bfd.h}.
c906108c 34793
8e04817f
AC
34794You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
34795However, you should make sure that the shell on your path (named by
34796the @samp{SHELL} environment variable) is publicly readable. Remember
34797that @value{GDBN} uses the shell to start your program---some systems refuse to
34798let @value{GDBN} debug child processes whose programs are not readable.
c906108c 34799
8e04817f 34800@node Separate Objdir
79a6e687 34801@section Compiling @value{GDBN} in Another Directory
c906108c 34802
8e04817f
AC
34803If you want to run @value{GDBN} versions for several host or target machines,
34804you need a different @code{gdb} compiled for each combination of
db2e3e2e 34805host and target. @file{configure} is designed to make this easy by
8e04817f
AC
34806allowing you to generate each configuration in a separate subdirectory,
34807rather than in the source directory. If your @code{make} program
34808handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
34809@code{make} in each of these directories builds the @code{gdb}
34810program specified there.
c906108c 34811
db2e3e2e 34812To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 34813with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
34814(You also need to specify a path to find @file{configure}
34815itself from your working directory. If the path to @file{configure}
8e04817f
AC
34816would be the same as the argument to @samp{--srcdir}, you can leave out
34817the @samp{--srcdir} option; it is assumed.)
c906108c 34818
8e04817f
AC
34819For example, with version @value{GDBVN}, you can build @value{GDBN} in a
34820separate directory for a Sun 4 like this:
c906108c 34821
474c8240 34822@smallexample
8e04817f
AC
34823@group
34824cd gdb-@value{GDBVN}
34825mkdir ../gdb-sun4
34826cd ../gdb-sun4
34827../gdb-@value{GDBVN}/configure sun4
34828make
34829@end group
474c8240 34830@end smallexample
c906108c 34831
db2e3e2e 34832When @file{configure} builds a configuration using a remote source
8e04817f
AC
34833directory, it creates a tree for the binaries with the same structure
34834(and using the same names) as the tree under the source directory. In
34835the example, you'd find the Sun 4 library @file{libiberty.a} in the
34836directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
34837@file{gdb-sun4/gdb}.
c906108c 34838
94e91d6d
MC
34839Make sure that your path to the @file{configure} script has just one
34840instance of @file{gdb} in it. If your path to @file{configure} looks
34841like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
34842one subdirectory of @value{GDBN}, not the whole package. This leads to
34843build errors about missing include files such as @file{bfd/bfd.h}.
34844
8e04817f
AC
34845One popular reason to build several @value{GDBN} configurations in separate
34846directories is to configure @value{GDBN} for cross-compiling (where
34847@value{GDBN} runs on one machine---the @dfn{host}---while debugging
34848programs that run on another machine---the @dfn{target}).
34849You specify a cross-debugging target by
db2e3e2e 34850giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 34851
8e04817f
AC
34852When you run @code{make} to build a program or library, you must run
34853it in a configured directory---whatever directory you were in when you
db2e3e2e 34854called @file{configure} (or one of its subdirectories).
c906108c 34855
db2e3e2e 34856The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
34857directory also runs recursively. If you type @code{make} in a source
34858directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
34859directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
34860will build all the required libraries, and then build GDB.
c906108c 34861
8e04817f
AC
34862When you have multiple hosts or targets configured in separate
34863directories, you can run @code{make} on them in parallel (for example,
34864if they are NFS-mounted on each of the hosts); they will not interfere
34865with each other.
c906108c 34866
8e04817f 34867@node Config Names
79a6e687 34868@section Specifying Names for Hosts and Targets
c906108c 34869
db2e3e2e 34870The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
34871script are based on a three-part naming scheme, but some short predefined
34872aliases are also supported. The full naming scheme encodes three pieces
34873of information in the following pattern:
c906108c 34874
474c8240 34875@smallexample
8e04817f 34876@var{architecture}-@var{vendor}-@var{os}
474c8240 34877@end smallexample
c906108c 34878
8e04817f
AC
34879For example, you can use the alias @code{sun4} as a @var{host} argument,
34880or as the value for @var{target} in a @code{--target=@var{target}}
34881option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 34882
db2e3e2e 34883The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 34884any query facility to list all supported host and target names or
db2e3e2e 34885aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
34886@code{config.sub} to map abbreviations to full names; you can read the
34887script, if you wish, or you can use it to test your guesses on
34888abbreviations---for example:
c906108c 34889
8e04817f
AC
34890@smallexample
34891% sh config.sub i386-linux
34892i386-pc-linux-gnu
34893% sh config.sub alpha-linux
34894alpha-unknown-linux-gnu
34895% sh config.sub hp9k700
34896hppa1.1-hp-hpux
34897% sh config.sub sun4
34898sparc-sun-sunos4.1.1
34899% sh config.sub sun3
34900m68k-sun-sunos4.1.1
34901% sh config.sub i986v
34902Invalid configuration `i986v': machine `i986v' not recognized
34903@end smallexample
c906108c 34904
8e04817f
AC
34905@noindent
34906@code{config.sub} is also distributed in the @value{GDBN} source
34907directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 34908
8e04817f 34909@node Configure Options
db2e3e2e 34910@section @file{configure} Options
c906108c 34911
db2e3e2e
BW
34912Here is a summary of the @file{configure} options and arguments that
34913are most often useful for building @value{GDBN}. @file{configure} also has
8e04817f 34914several other options not listed here. @inforef{What Configure
db2e3e2e 34915Does,,configure.info}, for a full explanation of @file{configure}.
c906108c 34916
474c8240 34917@smallexample
8e04817f
AC
34918configure @r{[}--help@r{]}
34919 @r{[}--prefix=@var{dir}@r{]}
34920 @r{[}--exec-prefix=@var{dir}@r{]}
34921 @r{[}--srcdir=@var{dirname}@r{]}
34922 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
34923 @r{[}--target=@var{target}@r{]}
34924 @var{host}
474c8240 34925@end smallexample
c906108c 34926
8e04817f
AC
34927@noindent
34928You may introduce options with a single @samp{-} rather than
34929@samp{--} if you prefer; but you may abbreviate option names if you use
34930@samp{--}.
c906108c 34931
8e04817f
AC
34932@table @code
34933@item --help
db2e3e2e 34934Display a quick summary of how to invoke @file{configure}.
c906108c 34935
8e04817f
AC
34936@item --prefix=@var{dir}
34937Configure the source to install programs and files under directory
34938@file{@var{dir}}.
c906108c 34939
8e04817f
AC
34940@item --exec-prefix=@var{dir}
34941Configure the source to install programs under directory
34942@file{@var{dir}}.
c906108c 34943
8e04817f
AC
34944@c avoid splitting the warning from the explanation:
34945@need 2000
34946@item --srcdir=@var{dirname}
34947@strong{Warning: using this option requires @sc{gnu} @code{make}, or another
34948@code{make} that implements the @code{VPATH} feature.}@*
34949Use this option to make configurations in directories separate from the
34950@value{GDBN} source directories. Among other things, you can use this to
34951build (or maintain) several configurations simultaneously, in separate
db2e3e2e 34952directories. @file{configure} writes configuration-specific files in
8e04817f 34953the current directory, but arranges for them to use the source in the
db2e3e2e 34954directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
34955the working directory in parallel to the source directories below
34956@var{dirname}.
c906108c 34957
8e04817f 34958@item --norecursion
db2e3e2e 34959Configure only the directory level where @file{configure} is executed; do not
8e04817f 34960propagate configuration to subdirectories.
c906108c 34961
8e04817f
AC
34962@item --target=@var{target}
34963Configure @value{GDBN} for cross-debugging programs running on the specified
34964@var{target}. Without this option, @value{GDBN} is configured to debug
34965programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 34966
8e04817f 34967There is no convenient way to generate a list of all available targets.
c906108c 34968
8e04817f
AC
34969@item @var{host} @dots{}
34970Configure @value{GDBN} to run on the specified @var{host}.
c906108c 34971
8e04817f
AC
34972There is no convenient way to generate a list of all available hosts.
34973@end table
c906108c 34974
8e04817f
AC
34975There are many other options available as well, but they are generally
34976needed for special purposes only.
c906108c 34977
098b41a6
JG
34978@node System-wide configuration
34979@section System-wide configuration and settings
34980@cindex system-wide init file
34981
34982@value{GDBN} can be configured to have a system-wide init file;
34983this file will be read and executed at startup (@pxref{Startup, , What
34984@value{GDBN} does during startup}).
34985
34986Here is the corresponding configure option:
34987
34988@table @code
34989@item --with-system-gdbinit=@var{file}
34990Specify that the default location of the system-wide init file is
34991@var{file}.
34992@end table
34993
34994If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
34995it may be subject to relocation. Two possible cases:
34996
34997@itemize @bullet
34998@item
34999If the default location of this init file contains @file{$prefix},
35000it will be subject to relocation. Suppose that the configure options
35001are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
35002if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
35003init file is looked for as @file{$install/etc/gdbinit} instead of
35004@file{$prefix/etc/gdbinit}.
35005
35006@item
35007By contrast, if the default location does not contain the prefix,
35008it will not be relocated. E.g.@: if @value{GDBN} has been configured with
35009@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
35010then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
35011wherever @value{GDBN} is installed.
35012@end itemize
35013
e64e0392
DE
35014If the configured location of the system-wide init file (as given by the
35015@option{--with-system-gdbinit} option at configure time) is in the
35016data-directory (as specified by @option{--with-gdb-datadir} at configure
35017time) or in one of its subdirectories, then @value{GDBN} will look for the
35018system-wide init file in the directory specified by the
35019@option{--data-directory} command-line option.
35020Note that the system-wide init file is only read once, during @value{GDBN}
35021initialization. If the data-directory is changed after @value{GDBN} has
35022started with the @code{set data-directory} command, the file will not be
35023reread.
35024
8e04817f
AC
35025@node Maintenance Commands
35026@appendix Maintenance Commands
35027@cindex maintenance commands
35028@cindex internal commands
c906108c 35029
8e04817f 35030In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
35031includes a number of commands intended for @value{GDBN} developers,
35032that are not documented elsewhere in this manual. These commands are
da316a69
EZ
35033provided here for reference. (For commands that turn on debugging
35034messages, see @ref{Debugging Output}.)
c906108c 35035
8e04817f 35036@table @code
09d4efe1 35037@kindex maint agent
782b2b07 35038@kindex maint agent-eval
f77cc5f0
HZ
35039@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
35040@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
35041Translate the given @var{expression} into remote agent bytecodes.
35042This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
35043(@pxref{Agent Expressions}). The @samp{agent} version produces an
35044expression useful for data collection, such as by tracepoints, while
35045@samp{maint agent-eval} produces an expression that evaluates directly
35046to a result. For instance, a collection expression for @code{globa +
35047globb} will include bytecodes to record four bytes of memory at each
35048of the addresses of @code{globa} and @code{globb}, while discarding
35049the result of the addition, while an evaluation expression will do the
35050addition and return the sum.
f77cc5f0
HZ
35051If @code{-at} is given, generate remote agent bytecode for @var{location}.
35052If not, generate remote agent bytecode for current frame PC address.
09d4efe1 35053
d3ce09f5
SS
35054@kindex maint agent-printf
35055@item maint agent-printf @var{format},@var{expr},...
35056Translate the given format string and list of argument expressions
35057into remote agent bytecodes and display them as a disassembled list.
35058This command is useful for debugging the agent version of dynamic
35059printf (@pxref{Dynamic Printf}.
35060
8e04817f
AC
35061@kindex maint info breakpoints
35062@item @anchor{maint info breakpoints}maint info breakpoints
35063Using the same format as @samp{info breakpoints}, display both the
35064breakpoints you've set explicitly, and those @value{GDBN} is using for
35065internal purposes. Internal breakpoints are shown with negative
35066breakpoint numbers. The type column identifies what kind of breakpoint
35067is shown:
c906108c 35068
8e04817f
AC
35069@table @code
35070@item breakpoint
35071Normal, explicitly set breakpoint.
c906108c 35072
8e04817f
AC
35073@item watchpoint
35074Normal, explicitly set watchpoint.
c906108c 35075
8e04817f
AC
35076@item longjmp
35077Internal breakpoint, used to handle correctly stepping through
35078@code{longjmp} calls.
c906108c 35079
8e04817f
AC
35080@item longjmp resume
35081Internal breakpoint at the target of a @code{longjmp}.
c906108c 35082
8e04817f
AC
35083@item until
35084Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 35085
8e04817f
AC
35086@item finish
35087Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 35088
8e04817f
AC
35089@item shlib events
35090Shared library events.
c906108c 35091
8e04817f 35092@end table
c906108c 35093
d6b28940
TT
35094@kindex maint info bfds
35095@item maint info bfds
35096This prints information about each @code{bfd} object that is known to
35097@value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
35098
fff08868
HZ
35099@kindex set displaced-stepping
35100@kindex show displaced-stepping
237fc4c9
PA
35101@cindex displaced stepping support
35102@cindex out-of-line single-stepping
fff08868
HZ
35103@item set displaced-stepping
35104@itemx show displaced-stepping
237fc4c9 35105Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
35106if the target supports it. Displaced stepping is a way to single-step
35107over breakpoints without removing them from the inferior, by executing
35108an out-of-line copy of the instruction that was originally at the
35109breakpoint location. It is also known as out-of-line single-stepping.
35110
35111@table @code
35112@item set displaced-stepping on
35113If the target architecture supports it, @value{GDBN} will use
35114displaced stepping to step over breakpoints.
35115
35116@item set displaced-stepping off
35117@value{GDBN} will not use displaced stepping to step over breakpoints,
35118even if such is supported by the target architecture.
35119
35120@cindex non-stop mode, and @samp{set displaced-stepping}
35121@item set displaced-stepping auto
35122This is the default mode. @value{GDBN} will use displaced stepping
35123only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
35124architecture supports displaced stepping.
35125@end table
237fc4c9 35126
09d4efe1
EZ
35127@kindex maint check-symtabs
35128@item maint check-symtabs
35129Check the consistency of psymtabs and symtabs.
35130
35131@kindex maint cplus first_component
35132@item maint cplus first_component @var{name}
35133Print the first C@t{++} class/namespace component of @var{name}.
35134
35135@kindex maint cplus namespace
35136@item maint cplus namespace
35137Print the list of possible C@t{++} namespaces.
35138
35139@kindex maint demangle
35140@item maint demangle @var{name}
d3e8051b 35141Demangle a C@t{++} or Objective-C mangled @var{name}.
09d4efe1
EZ
35142
35143@kindex maint deprecate
35144@kindex maint undeprecate
35145@cindex deprecated commands
35146@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
35147@itemx maint undeprecate @var{command}
35148Deprecate or undeprecate the named @var{command}. Deprecated commands
35149cause @value{GDBN} to issue a warning when you use them. The optional
35150argument @var{replacement} says which newer command should be used in
35151favor of the deprecated one; if it is given, @value{GDBN} will mention
35152the replacement as part of the warning.
35153
35154@kindex maint dump-me
35155@item maint dump-me
721c2651 35156@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 35157Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
35158This is supported only on systems which support aborting a program
35159with the @code{SIGQUIT} signal.
09d4efe1 35160
8d30a00d
AC
35161@kindex maint internal-error
35162@kindex maint internal-warning
09d4efe1
EZ
35163@item maint internal-error @r{[}@var{message-text}@r{]}
35164@itemx maint internal-warning @r{[}@var{message-text}@r{]}
8d30a00d
AC
35165Cause @value{GDBN} to call the internal function @code{internal_error}
35166or @code{internal_warning} and hence behave as though an internal error
35167or internal warning has been detected. In addition to reporting the
35168internal problem, these functions give the user the opportunity to
35169either quit @value{GDBN} or create a core file of the current
35170@value{GDBN} session.
35171
09d4efe1
EZ
35172These commands take an optional parameter @var{message-text} that is
35173used as the text of the error or warning message.
35174
d3e8051b 35175Here's an example of using @code{internal-error}:
09d4efe1 35176
8d30a00d 35177@smallexample
f7dc1244 35178(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
35179@dots{}/maint.c:121: internal-error: testing, 1, 2
35180A problem internal to GDB has been detected. Further
35181debugging may prove unreliable.
35182Quit this debugging session? (y or n) @kbd{n}
35183Create a core file? (y or n) @kbd{n}
f7dc1244 35184(@value{GDBP})
8d30a00d
AC
35185@end smallexample
35186
3c16cced
PA
35187@cindex @value{GDBN} internal error
35188@cindex internal errors, control of @value{GDBN} behavior
35189
35190@kindex maint set internal-error
35191@kindex maint show internal-error
35192@kindex maint set internal-warning
35193@kindex maint show internal-warning
35194@item maint set internal-error @var{action} [ask|yes|no]
35195@itemx maint show internal-error @var{action}
35196@itemx maint set internal-warning @var{action} [ask|yes|no]
35197@itemx maint show internal-warning @var{action}
35198When @value{GDBN} reports an internal problem (error or warning) it
35199gives the user the opportunity to both quit @value{GDBN} and create a
35200core file of the current @value{GDBN} session. These commands let you
35201override the default behaviour for each particular @var{action},
35202described in the table below.
35203
35204@table @samp
35205@item quit
35206You can specify that @value{GDBN} should always (yes) or never (no)
35207quit. The default is to ask the user what to do.
35208
35209@item corefile
35210You can specify that @value{GDBN} should always (yes) or never (no)
35211create a core file. The default is to ask the user what to do.
35212@end table
35213
09d4efe1
EZ
35214@kindex maint packet
35215@item maint packet @var{text}
35216If @value{GDBN} is talking to an inferior via the serial protocol,
35217then this command sends the string @var{text} to the inferior, and
35218displays the response packet. @value{GDBN} supplies the initial
35219@samp{$} character, the terminating @samp{#} character, and the
35220checksum.
35221
35222@kindex maint print architecture
35223@item maint print architecture @r{[}@var{file}@r{]}
35224Print the entire architecture configuration. The optional argument
35225@var{file} names the file where the output goes.
8d30a00d 35226
81adfced
DJ
35227@kindex maint print c-tdesc
35228@item maint print c-tdesc
35229Print the current target description (@pxref{Target Descriptions}) as
35230a C source file. The created source file can be used in @value{GDBN}
35231when an XML parser is not available to parse the description.
35232
00905d52
AC
35233@kindex maint print dummy-frames
35234@item maint print dummy-frames
00905d52
AC
35235Prints the contents of @value{GDBN}'s internal dummy-frame stack.
35236
35237@smallexample
f7dc1244 35238(@value{GDBP}) @kbd{b add}
00905d52 35239@dots{}
f7dc1244 35240(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
35241Breakpoint 2, add (a=2, b=3) at @dots{}
3524258 return (a + b);
35243The program being debugged stopped while in a function called from GDB.
35244@dots{}
f7dc1244 35245(@value{GDBP}) @kbd{maint print dummy-frames}
00905d52
AC
352460x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
35247 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
35248 call_lo=0x01014000 call_hi=0x01014001
f7dc1244 35249(@value{GDBP})
00905d52
AC
35250@end smallexample
35251
35252Takes an optional file parameter.
35253
0680b120
AC
35254@kindex maint print registers
35255@kindex maint print raw-registers
35256@kindex maint print cooked-registers
617073a9 35257@kindex maint print register-groups
c21236dc 35258@kindex maint print remote-registers
09d4efe1
EZ
35259@item maint print registers @r{[}@var{file}@r{]}
35260@itemx maint print raw-registers @r{[}@var{file}@r{]}
35261@itemx maint print cooked-registers @r{[}@var{file}@r{]}
35262@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 35263@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
35264Print @value{GDBN}'s internal register data structures.
35265
617073a9 35266The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
35267the raw register cache; the command @code{maint print
35268cooked-registers} includes the (cooked) value of all registers,
35269including registers which aren't available on the target nor visible
35270to user; the command @code{maint print register-groups} includes the
35271groups that each register is a member of; and the command @code{maint
35272print remote-registers} includes the remote target's register numbers
35273and offsets in the `G' packets. @xref{Registers,, Registers, gdbint,
617073a9 35274@value{GDBN} Internals}.
0680b120 35275
09d4efe1
EZ
35276These commands take an optional parameter, a file name to which to
35277write the information.
0680b120 35278
617073a9 35279@kindex maint print reggroups
09d4efe1
EZ
35280@item maint print reggroups @r{[}@var{file}@r{]}
35281Print @value{GDBN}'s internal register group data structures. The
35282optional argument @var{file} tells to what file to write the
35283information.
617073a9 35284
09d4efe1 35285The register groups info looks like this:
617073a9
AC
35286
35287@smallexample
f7dc1244 35288(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
35289 Group Type
35290 general user
35291 float user
35292 all user
35293 vector user
35294 system user
35295 save internal
35296 restore internal
617073a9
AC
35297@end smallexample
35298
09d4efe1
EZ
35299@kindex flushregs
35300@item flushregs
35301This command forces @value{GDBN} to flush its internal register cache.
35302
35303@kindex maint print objfiles
35304@cindex info for known object files
35305@item maint print objfiles
35306Print a dump of all known object files. For each object file, this
35307command prints its name, address in memory, and all of its psymtabs
35308and symtabs.
35309
8a1ea21f
DE
35310@kindex maint print section-scripts
35311@cindex info for known .debug_gdb_scripts-loaded scripts
35312@item maint print section-scripts [@var{regexp}]
35313Print a dump of scripts specified in the @code{.debug_gdb_section} section.
35314If @var{regexp} is specified, only print scripts loaded by object files
35315matching @var{regexp}.
35316For each script, this command prints its name as specified in the objfile,
35317and the full path if known.
8e0583c8 35318@xref{dotdebug_gdb_scripts section}.
8a1ea21f 35319
09d4efe1
EZ
35320@kindex maint print statistics
35321@cindex bcache statistics
35322@item maint print statistics
35323This command prints, for each object file in the program, various data
35324about that object file followed by the byte cache (@dfn{bcache})
35325statistics for the object file. The objfile data includes the number
d3e8051b 35326of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
35327defined by the objfile, the number of as yet unexpanded psym tables,
35328the number of line tables and string tables, and the amount of memory
35329used by the various tables. The bcache statistics include the counts,
35330sizes, and counts of duplicates of all and unique objects, max,
35331average, and median entry size, total memory used and its overhead and
35332savings, and various measures of the hash table size and chain
35333lengths.
35334
c7ba131e
JB
35335@kindex maint print target-stack
35336@cindex target stack description
35337@item maint print target-stack
35338A @dfn{target} is an interface between the debugger and a particular
35339kind of file or process. Targets can be stacked in @dfn{strata},
35340so that more than one target can potentially respond to a request.
35341In particular, memory accesses will walk down the stack of targets
35342until they find a target that is interested in handling that particular
35343address.
35344
35345This command prints a short description of each layer that was pushed on
35346the @dfn{target stack}, starting from the top layer down to the bottom one.
35347
09d4efe1
EZ
35348@kindex maint print type
35349@cindex type chain of a data type
35350@item maint print type @var{expr}
35351Print the type chain for a type specified by @var{expr}. The argument
35352can be either a type name or a symbol. If it is a symbol, the type of
35353that symbol is described. The type chain produced by this command is
35354a recursive definition of the data type as stored in @value{GDBN}'s
35355data structures, including its flags and contained types.
35356
9eae7c52
TT
35357@kindex maint set dwarf2 always-disassemble
35358@kindex maint show dwarf2 always-disassemble
35359@item maint set dwarf2 always-disassemble
35360@item maint show dwarf2 always-disassemble
35361Control the behavior of @code{info address} when using DWARF debugging
35362information.
35363
35364The default is @code{off}, which means that @value{GDBN} should try to
35365describe a variable's location in an easily readable format. When
35366@code{on}, @value{GDBN} will instead display the DWARF location
35367expression in an assembly-like format. Note that some locations are
35368too complex for @value{GDBN} to describe simply; in this case you will
35369always see the disassembly form.
35370
35371Here is an example of the resulting disassembly:
35372
35373@smallexample
35374(gdb) info addr argc
35375Symbol "argc" is a complex DWARF expression:
35376 1: DW_OP_fbreg 0
35377@end smallexample
35378
35379For more information on these expressions, see
35380@uref{http://www.dwarfstd.org/, the DWARF standard}.
35381
09d4efe1
EZ
35382@kindex maint set dwarf2 max-cache-age
35383@kindex maint show dwarf2 max-cache-age
35384@item maint set dwarf2 max-cache-age
35385@itemx maint show dwarf2 max-cache-age
35386Control the DWARF 2 compilation unit cache.
35387
35388@cindex DWARF 2 compilation units cache
35389In object files with inter-compilation-unit references, such as those
35390produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
35391reader needs to frequently refer to previously read compilation units.
35392This setting controls how long a compilation unit will remain in the
35393cache if it is not referenced. A higher limit means that cached
35394compilation units will be stored in memory longer, and more total
35395memory will be used. Setting it to zero disables caching, which will
35396slow down @value{GDBN} startup, but reduce memory consumption.
35397
e7ba9c65
DJ
35398@kindex maint set profile
35399@kindex maint show profile
35400@cindex profiling GDB
35401@item maint set profile
35402@itemx maint show profile
35403Control profiling of @value{GDBN}.
35404
35405Profiling will be disabled until you use the @samp{maint set profile}
35406command to enable it. When you enable profiling, the system will begin
35407collecting timing and execution count data; when you disable profiling or
35408exit @value{GDBN}, the results will be written to a log file. Remember that
35409if you use profiling, @value{GDBN} will overwrite the profiling log file
35410(often called @file{gmon.out}). If you have a record of important profiling
35411data in a @file{gmon.out} file, be sure to move it to a safe location.
35412
35413Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 35414compiled with the @samp{-pg} compiler option.
e7ba9c65 35415
cbe54154
PA
35416@kindex maint set show-debug-regs
35417@kindex maint show show-debug-regs
eac35c4e 35418@cindex hardware debug registers
cbe54154
PA
35419@item maint set show-debug-regs
35420@itemx maint show show-debug-regs
eac35c4e 35421Control whether to show variables that mirror the hardware debug
09d4efe1 35422registers. Use @code{ON} to enable, @code{OFF} to disable. If
3f94c067 35423enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
35424removes a hardware breakpoint or watchpoint, and when the inferior
35425triggers a hardware-assisted breakpoint or watchpoint.
35426
711e434b
PM
35427@kindex maint set show-all-tib
35428@kindex maint show show-all-tib
35429@item maint set show-all-tib
35430@itemx maint show show-all-tib
35431Control whether to show all non zero areas within a 1k block starting
35432at thread local base, when using the @samp{info w32 thread-information-block}
35433command.
35434
09d4efe1
EZ
35435@kindex maint space
35436@cindex memory used by commands
35437@item maint space
35438Control whether to display memory usage for each command. If set to a
35439nonzero value, @value{GDBN} will display how much memory each command
35440took, following the command's own output. This can also be requested
35441by invoking @value{GDBN} with the @option{--statistics} command-line
35442switch (@pxref{Mode Options}).
35443
35444@kindex maint time
35445@cindex time of command execution
35446@item maint time
0a1c4d10
DE
35447Control whether to display the execution time of @value{GDBN} for each command.
35448If set to a nonzero value, @value{GDBN} will display how much time it
09d4efe1 35449took to execute each command, following the command's own output.
0a1c4d10
DE
35450Both CPU time and wallclock time are printed.
35451Printing both is useful when trying to determine whether the cost is
35452CPU or, e.g., disk/network, latency.
35453Note that the CPU time printed is for @value{GDBN} only, it does not include
35454the execution time of the inferior because there's no mechanism currently
35455to compute how much time was spent by @value{GDBN} and how much time was
35456spent by the program been debugged.
09d4efe1
EZ
35457This can also be requested by invoking @value{GDBN} with the
35458@option{--statistics} command-line switch (@pxref{Mode Options}).
35459
35460@kindex maint translate-address
35461@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
35462Find the symbol stored at the location specified by the address
35463@var{addr} and an optional section name @var{section}. If found,
35464@value{GDBN} prints the name of the closest symbol and an offset from
35465the symbol's location to the specified address. This is similar to
35466the @code{info address} command (@pxref{Symbols}), except that this
35467command also allows to find symbols in other sections.
ae038cb0 35468
c14c28ba
PP
35469If section was not specified, the section in which the symbol was found
35470is also printed. For dynamically linked executables, the name of
35471executable or shared library containing the symbol is printed as well.
35472
8e04817f 35473@end table
c906108c 35474
9c16f35a
EZ
35475The following command is useful for non-interactive invocations of
35476@value{GDBN}, such as in the test suite.
35477
35478@table @code
35479@item set watchdog @var{nsec}
35480@kindex set watchdog
35481@cindex watchdog timer
35482@cindex timeout for commands
35483Set the maximum number of seconds @value{GDBN} will wait for the
35484target operation to finish. If this time expires, @value{GDBN}
35485reports and error and the command is aborted.
35486
35487@item show watchdog
35488Show the current setting of the target wait timeout.
35489@end table
c906108c 35490
e0ce93ac 35491@node Remote Protocol
8e04817f 35492@appendix @value{GDBN} Remote Serial Protocol
c906108c 35493
ee2d5c50
AC
35494@menu
35495* Overview::
35496* Packets::
35497* Stop Reply Packets::
35498* General Query Packets::
a1dcb23a 35499* Architecture-Specific Protocol Details::
9d29849a 35500* Tracepoint Packets::
a6b151f1 35501* Host I/O Packets::
9a6253be 35502* Interrupts::
8b23ecc4
SL
35503* Notification Packets::
35504* Remote Non-Stop::
a6f3e723 35505* Packet Acknowledgment::
ee2d5c50 35506* Examples::
79a6e687 35507* File-I/O Remote Protocol Extension::
cfa9d6d9 35508* Library List Format::
2268b414 35509* Library List Format for SVR4 Targets::
79a6e687 35510* Memory Map Format::
dc146f7c 35511* Thread List Format::
b3b9301e 35512* Traceframe Info Format::
ee2d5c50
AC
35513@end menu
35514
35515@node Overview
35516@section Overview
35517
8e04817f
AC
35518There may be occasions when you need to know something about the
35519protocol---for example, if there is only one serial port to your target
35520machine, you might want your program to do something special if it
35521recognizes a packet meant for @value{GDBN}.
c906108c 35522
d2c6833e 35523In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 35524transmitted and received data, respectively.
c906108c 35525
8e04817f
AC
35526@cindex protocol, @value{GDBN} remote serial
35527@cindex serial protocol, @value{GDBN} remote
35528@cindex remote serial protocol
8b23ecc4
SL
35529All @value{GDBN} commands and responses (other than acknowledgments
35530and notifications, see @ref{Notification Packets}) are sent as a
35531@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
35532@samp{$}, the actual @var{packet-data}, and the terminating character
35533@samp{#} followed by a two-digit @var{checksum}:
c906108c 35534
474c8240 35535@smallexample
8e04817f 35536@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 35537@end smallexample
8e04817f 35538@noindent
c906108c 35539
8e04817f
AC
35540@cindex checksum, for @value{GDBN} remote
35541@noindent
35542The two-digit @var{checksum} is computed as the modulo 256 sum of all
35543characters between the leading @samp{$} and the trailing @samp{#} (an
35544eight bit unsigned checksum).
c906108c 35545
8e04817f
AC
35546Implementors should note that prior to @value{GDBN} 5.0 the protocol
35547specification also included an optional two-digit @var{sequence-id}:
c906108c 35548
474c8240 35549@smallexample
8e04817f 35550@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 35551@end smallexample
c906108c 35552
8e04817f
AC
35553@cindex sequence-id, for @value{GDBN} remote
35554@noindent
35555That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
35556has never output @var{sequence-id}s. Stubs that handle packets added
35557since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 35558
8e04817f
AC
35559When either the host or the target machine receives a packet, the first
35560response expected is an acknowledgment: either @samp{+} (to indicate
35561the package was received correctly) or @samp{-} (to request
35562retransmission):
c906108c 35563
474c8240 35564@smallexample
d2c6833e
AC
35565-> @code{$}@var{packet-data}@code{#}@var{checksum}
35566<- @code{+}
474c8240 35567@end smallexample
8e04817f 35568@noindent
53a5351d 35569
a6f3e723
SL
35570The @samp{+}/@samp{-} acknowledgments can be disabled
35571once a connection is established.
35572@xref{Packet Acknowledgment}, for details.
35573
8e04817f
AC
35574The host (@value{GDBN}) sends @var{command}s, and the target (the
35575debugging stub incorporated in your program) sends a @var{response}. In
35576the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
35577when the operation has completed, and the target has again stopped all
35578threads in all attached processes. This is the default all-stop mode
35579behavior, but the remote protocol also supports @value{GDBN}'s non-stop
35580execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 35581
8e04817f
AC
35582@var{packet-data} consists of a sequence of characters with the
35583exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
35584exceptions).
c906108c 35585
ee2d5c50 35586@cindex remote protocol, field separator
0876f84a 35587Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 35588@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 35589@sc{hex} with leading zeros suppressed.
c906108c 35590
8e04817f
AC
35591Implementors should note that prior to @value{GDBN} 5.0, the character
35592@samp{:} could not appear as the third character in a packet (as it
35593would potentially conflict with the @var{sequence-id}).
c906108c 35594
0876f84a
DJ
35595@cindex remote protocol, binary data
35596@anchor{Binary Data}
35597Binary data in most packets is encoded either as two hexadecimal
35598digits per byte of binary data. This allowed the traditional remote
35599protocol to work over connections which were only seven-bit clean.
35600Some packets designed more recently assume an eight-bit clean
35601connection, and use a more efficient encoding to send and receive
35602binary data.
35603
35604The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
35605as an escape character. Any escaped byte is transmitted as the escape
35606character followed by the original character XORed with @code{0x20}.
35607For example, the byte @code{0x7d} would be transmitted as the two
35608bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
35609@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
35610@samp{@}}) must always be escaped. Responses sent by the stub
35611must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
35612is not interpreted as the start of a run-length encoded sequence
35613(described next).
35614
1d3811f6
DJ
35615Response @var{data} can be run-length encoded to save space.
35616Run-length encoding replaces runs of identical characters with one
35617instance of the repeated character, followed by a @samp{*} and a
35618repeat count. The repeat count is itself sent encoded, to avoid
35619binary characters in @var{data}: a value of @var{n} is sent as
35620@code{@var{n}+29}. For a repeat count greater or equal to 3, this
35621produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
35622code 32) for a repeat count of 3. (This is because run-length
35623encoding starts to win for counts 3 or more.) Thus, for example,
35624@samp{0* } is a run-length encoding of ``0000'': the space character
35625after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
356263}} more times.
35627
35628The printable characters @samp{#} and @samp{$} or with a numeric value
35629greater than 126 must not be used. Runs of six repeats (@samp{#}) or
35630seven repeats (@samp{$}) can be expanded using a repeat count of only
35631five (@samp{"}). For example, @samp{00000000} can be encoded as
35632@samp{0*"00}.
c906108c 35633
8e04817f
AC
35634The error response returned for some packets includes a two character
35635error number. That number is not well defined.
c906108c 35636
f8da2bff 35637@cindex empty response, for unsupported packets
8e04817f
AC
35638For any @var{command} not supported by the stub, an empty response
35639(@samp{$#00}) should be returned. That way it is possible to extend the
35640protocol. A newer @value{GDBN} can tell if a packet is supported based
35641on that response.
c906108c 35642
393eab54
PA
35643At a minimum, a stub is required to support the @samp{g} and @samp{G}
35644commands for register access, and the @samp{m} and @samp{M} commands
35645for memory access. Stubs that only control single-threaded targets
35646can implement run control with the @samp{c} (continue), and @samp{s}
35647(step) commands. Stubs that support multi-threading targets should
35648support the @samp{vCont} command. All other commands are optional.
c906108c 35649
ee2d5c50
AC
35650@node Packets
35651@section Packets
35652
35653The following table provides a complete list of all currently defined
35654@var{command}s and their corresponding response @var{data}.
79a6e687 35655@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 35656I/O extension of the remote protocol.
ee2d5c50 35657
b8ff78ce
JB
35658Each packet's description has a template showing the packet's overall
35659syntax, followed by an explanation of the packet's meaning. We
35660include spaces in some of the templates for clarity; these are not
35661part of the packet's syntax. No @value{GDBN} packet uses spaces to
35662separate its components. For example, a template like @samp{foo
35663@var{bar} @var{baz}} describes a packet beginning with the three ASCII
35664bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 35665@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
35666@samp{foo} and the @var{bar}, or between the @var{bar} and the
35667@var{baz}.
35668
b90a069a
SL
35669@cindex @var{thread-id}, in remote protocol
35670@anchor{thread-id syntax}
35671Several packets and replies include a @var{thread-id} field to identify
35672a thread. Normally these are positive numbers with a target-specific
35673interpretation, formatted as big-endian hex strings. A @var{thread-id}
35674can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
35675pick any thread.
35676
35677In addition, the remote protocol supports a multiprocess feature in
35678which the @var{thread-id} syntax is extended to optionally include both
35679process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
35680The @var{pid} (process) and @var{tid} (thread) components each have the
35681format described above: a positive number with target-specific
35682interpretation formatted as a big-endian hex string, literal @samp{-1}
35683to indicate all processes or threads (respectively), or @samp{0} to
35684indicate an arbitrary process or thread. Specifying just a process, as
35685@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
35686error to specify all processes but a specific thread, such as
35687@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
35688for those packets and replies explicitly documented to include a process
35689ID, rather than a @var{thread-id}.
35690
35691The multiprocess @var{thread-id} syntax extensions are only used if both
35692@value{GDBN} and the stub report support for the @samp{multiprocess}
35693feature using @samp{qSupported}. @xref{multiprocess extensions}, for
35694more information.
35695
8ffe2530
JB
35696Note that all packet forms beginning with an upper- or lower-case
35697letter, other than those described here, are reserved for future use.
35698
b8ff78ce 35699Here are the packet descriptions.
ee2d5c50 35700
b8ff78ce 35701@table @samp
ee2d5c50 35702
b8ff78ce
JB
35703@item !
35704@cindex @samp{!} packet
2d717e4f 35705@anchor{extended mode}
8e04817f
AC
35706Enable extended mode. In extended mode, the remote server is made
35707persistent. The @samp{R} packet is used to restart the program being
35708debugged.
ee2d5c50
AC
35709
35710Reply:
35711@table @samp
35712@item OK
8e04817f 35713The remote target both supports and has enabled extended mode.
ee2d5c50 35714@end table
c906108c 35715
b8ff78ce
JB
35716@item ?
35717@cindex @samp{?} packet
ee2d5c50 35718Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
35719step and continue. This packet has a special interpretation when the
35720target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 35721
ee2d5c50
AC
35722Reply:
35723@xref{Stop Reply Packets}, for the reply specifications.
35724
b8ff78ce
JB
35725@item A @var{arglen},@var{argnum},@var{arg},@dots{}
35726@cindex @samp{A} packet
35727Initialized @code{argv[]} array passed into program. @var{arglen}
35728specifies the number of bytes in the hex encoded byte stream
35729@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
35730
35731Reply:
35732@table @samp
35733@item OK
b8ff78ce
JB
35734The arguments were set.
35735@item E @var{NN}
35736An error occurred.
ee2d5c50
AC
35737@end table
35738
b8ff78ce
JB
35739@item b @var{baud}
35740@cindex @samp{b} packet
35741(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
35742Change the serial line speed to @var{baud}.
35743
35744JTC: @emph{When does the transport layer state change? When it's
35745received, or after the ACK is transmitted. In either case, there are
35746problems if the command or the acknowledgment packet is dropped.}
35747
35748Stan: @emph{If people really wanted to add something like this, and get
35749it working for the first time, they ought to modify ser-unix.c to send
35750some kind of out-of-band message to a specially-setup stub and have the
35751switch happen "in between" packets, so that from remote protocol's point
35752of view, nothing actually happened.}
35753
b8ff78ce
JB
35754@item B @var{addr},@var{mode}
35755@cindex @samp{B} packet
8e04817f 35756Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
35757breakpoint at @var{addr}.
35758
b8ff78ce 35759Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 35760(@pxref{insert breakpoint or watchpoint packet}).
c906108c 35761
bacec72f 35762@cindex @samp{bc} packet
0d772ac9
MS
35763@anchor{bc}
35764@item bc
bacec72f
MS
35765Backward continue. Execute the target system in reverse. No parameter.
35766@xref{Reverse Execution}, for more information.
35767
35768Reply:
35769@xref{Stop Reply Packets}, for the reply specifications.
35770
bacec72f 35771@cindex @samp{bs} packet
0d772ac9
MS
35772@anchor{bs}
35773@item bs
bacec72f
MS
35774Backward single step. Execute one instruction in reverse. No parameter.
35775@xref{Reverse Execution}, for more information.
35776
35777Reply:
35778@xref{Stop Reply Packets}, for the reply specifications.
35779
4f553f88 35780@item c @r{[}@var{addr}@r{]}
b8ff78ce
JB
35781@cindex @samp{c} packet
35782Continue. @var{addr} is address to resume. If @var{addr} is omitted,
35783resume at current address.
c906108c 35784
393eab54
PA
35785This packet is deprecated for multi-threading support. @xref{vCont
35786packet}.
35787
ee2d5c50
AC
35788Reply:
35789@xref{Stop Reply Packets}, for the reply specifications.
35790
4f553f88 35791@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 35792@cindex @samp{C} packet
8e04817f 35793Continue with signal @var{sig} (hex signal number). If
b8ff78ce 35794@samp{;@var{addr}} is omitted, resume at same address.
c906108c 35795
393eab54
PA
35796This packet is deprecated for multi-threading support. @xref{vCont
35797packet}.
35798
ee2d5c50
AC
35799Reply:
35800@xref{Stop Reply Packets}, for the reply specifications.
c906108c 35801
b8ff78ce
JB
35802@item d
35803@cindex @samp{d} packet
ee2d5c50
AC
35804Toggle debug flag.
35805
b8ff78ce
JB
35806Don't use this packet; instead, define a general set packet
35807(@pxref{General Query Packets}).
ee2d5c50 35808
b8ff78ce 35809@item D
b90a069a 35810@itemx D;@var{pid}
b8ff78ce 35811@cindex @samp{D} packet
b90a069a
SL
35812The first form of the packet is used to detach @value{GDBN} from the
35813remote system. It is sent to the remote target
07f31aa6 35814before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 35815
b90a069a
SL
35816The second form, including a process ID, is used when multiprocess
35817protocol extensions are enabled (@pxref{multiprocess extensions}), to
35818detach only a specific process. The @var{pid} is specified as a
35819big-endian hex string.
35820
ee2d5c50
AC
35821Reply:
35822@table @samp
10fac096
NW
35823@item OK
35824for success
b8ff78ce 35825@item E @var{NN}
10fac096 35826for an error
ee2d5c50 35827@end table
c906108c 35828
b8ff78ce
JB
35829@item F @var{RC},@var{EE},@var{CF};@var{XX}
35830@cindex @samp{F} packet
35831A reply from @value{GDBN} to an @samp{F} packet sent by the target.
35832This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 35833Remote Protocol Extension}, for the specification.
ee2d5c50 35834
b8ff78ce 35835@item g
ee2d5c50 35836@anchor{read registers packet}
b8ff78ce 35837@cindex @samp{g} packet
ee2d5c50
AC
35838Read general registers.
35839
35840Reply:
35841@table @samp
35842@item @var{XX@dots{}}
8e04817f
AC
35843Each byte of register data is described by two hex digits. The bytes
35844with the register are transmitted in target byte order. The size of
b8ff78ce 35845each register and their position within the @samp{g} packet are
4a9bb1df
UW
35846determined by the @value{GDBN} internal gdbarch functions
35847@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
b8ff78ce 35848specification of several standard @samp{g} packets is specified below.
ad196637
PA
35849
35850When reading registers from a trace frame (@pxref{Analyze Collected
35851Data,,Using the Collected Data}), the stub may also return a string of
35852literal @samp{x}'s in place of the register data digits, to indicate
35853that the corresponding register has not been collected, thus its value
35854is unavailable. For example, for an architecture with 4 registers of
358554 bytes each, the following reply indicates to @value{GDBN} that
35856registers 0 and 2 have not been collected, while registers 1 and 3
35857have been collected, and both have zero value:
35858
35859@smallexample
35860-> @code{g}
35861<- @code{xxxxxxxx00000000xxxxxxxx00000000}
35862@end smallexample
35863
b8ff78ce 35864@item E @var{NN}
ee2d5c50
AC
35865for an error.
35866@end table
c906108c 35867
b8ff78ce
JB
35868@item G @var{XX@dots{}}
35869@cindex @samp{G} packet
35870Write general registers. @xref{read registers packet}, for a
35871description of the @var{XX@dots{}} data.
ee2d5c50
AC
35872
35873Reply:
35874@table @samp
35875@item OK
35876for success
b8ff78ce 35877@item E @var{NN}
ee2d5c50
AC
35878for an error
35879@end table
35880
393eab54 35881@item H @var{op} @var{thread-id}
b8ff78ce 35882@cindex @samp{H} packet
8e04817f 35883Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
393eab54
PA
35884@samp{G}, et.al.). @var{op} depends on the operation to be performed:
35885it should be @samp{c} for step and continue operations (note that this
35886is deprecated, supporting the @samp{vCont} command is a better
35887option), @samp{g} for other operations. The thread designator
35888@var{thread-id} has the format and interpretation described in
35889@ref{thread-id syntax}.
ee2d5c50
AC
35890
35891Reply:
35892@table @samp
35893@item OK
35894for success
b8ff78ce 35895@item E @var{NN}
ee2d5c50
AC
35896for an error
35897@end table
c906108c 35898
8e04817f
AC
35899@c FIXME: JTC:
35900@c 'H': How restrictive (or permissive) is the thread model. If a
35901@c thread is selected and stopped, are other threads allowed
35902@c to continue to execute? As I mentioned above, I think the
35903@c semantics of each command when a thread is selected must be
35904@c described. For example:
35905@c
35906@c 'g': If the stub supports threads and a specific thread is
35907@c selected, returns the register block from that thread;
35908@c otherwise returns current registers.
35909@c
35910@c 'G' If the stub supports threads and a specific thread is
35911@c selected, sets the registers of the register block of
35912@c that thread; otherwise sets current registers.
c906108c 35913
b8ff78ce 35914@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 35915@anchor{cycle step packet}
b8ff78ce
JB
35916@cindex @samp{i} packet
35917Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
35918present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
35919step starting at that address.
c906108c 35920
b8ff78ce
JB
35921@item I
35922@cindex @samp{I} packet
35923Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
35924step packet}.
ee2d5c50 35925
b8ff78ce
JB
35926@item k
35927@cindex @samp{k} packet
35928Kill request.
c906108c 35929
ac282366 35930FIXME: @emph{There is no description of how to operate when a specific
ee2d5c50
AC
35931thread context has been selected (i.e.@: does 'k' kill only that
35932thread?)}.
c906108c 35933
b8ff78ce
JB
35934@item m @var{addr},@var{length}
35935@cindex @samp{m} packet
8e04817f 35936Read @var{length} bytes of memory starting at address @var{addr}.
fb031cdf
JB
35937Note that @var{addr} may not be aligned to any particular boundary.
35938
35939The stub need not use any particular size or alignment when gathering
35940data from memory for the response; even if @var{addr} is word-aligned
35941and @var{length} is a multiple of the word size, the stub is free to
35942use byte accesses, or not. For this reason, this packet may not be
35943suitable for accessing memory-mapped I/O devices.
c43c5473
JB
35944@cindex alignment of remote memory accesses
35945@cindex size of remote memory accesses
35946@cindex memory, alignment and size of remote accesses
c906108c 35947
ee2d5c50
AC
35948Reply:
35949@table @samp
35950@item @var{XX@dots{}}
599b237a 35951Memory contents; each byte is transmitted as a two-digit hexadecimal
b8ff78ce
JB
35952number. The reply may contain fewer bytes than requested if the
35953server was able to read only part of the region of memory.
35954@item E @var{NN}
ee2d5c50
AC
35955@var{NN} is errno
35956@end table
35957
b8ff78ce
JB
35958@item M @var{addr},@var{length}:@var{XX@dots{}}
35959@cindex @samp{M} packet
8e04817f 35960Write @var{length} bytes of memory starting at address @var{addr}.
b8ff78ce 35961@var{XX@dots{}} is the data; each byte is transmitted as a two-digit
599b237a 35962hexadecimal number.
ee2d5c50
AC
35963
35964Reply:
35965@table @samp
35966@item OK
35967for success
b8ff78ce 35968@item E @var{NN}
8e04817f
AC
35969for an error (this includes the case where only part of the data was
35970written).
ee2d5c50 35971@end table
c906108c 35972
b8ff78ce
JB
35973@item p @var{n}
35974@cindex @samp{p} packet
35975Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
35976@xref{read registers packet}, for a description of how the returned
35977register value is encoded.
ee2d5c50
AC
35978
35979Reply:
35980@table @samp
2e868123
AC
35981@item @var{XX@dots{}}
35982the register's value
b8ff78ce 35983@item E @var{NN}
2e868123
AC
35984for an error
35985@item
35986Indicating an unrecognized @var{query}.
ee2d5c50
AC
35987@end table
35988
b8ff78ce 35989@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 35990@anchor{write register packet}
b8ff78ce
JB
35991@cindex @samp{P} packet
35992Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 35993number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 35994digits for each byte in the register (target byte order).
c906108c 35995
ee2d5c50
AC
35996Reply:
35997@table @samp
35998@item OK
35999for success
b8ff78ce 36000@item E @var{NN}
ee2d5c50
AC
36001for an error
36002@end table
36003
5f3bebba
JB
36004@item q @var{name} @var{params}@dots{}
36005@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 36006@cindex @samp{q} packet
b8ff78ce 36007@cindex @samp{Q} packet
5f3bebba
JB
36008General query (@samp{q}) and set (@samp{Q}). These packets are
36009described fully in @ref{General Query Packets}.
c906108c 36010
b8ff78ce
JB
36011@item r
36012@cindex @samp{r} packet
8e04817f 36013Reset the entire system.
c906108c 36014
b8ff78ce 36015Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 36016
b8ff78ce
JB
36017@item R @var{XX}
36018@cindex @samp{R} packet
8e04817f 36019Restart the program being debugged. @var{XX}, while needed, is ignored.
2d717e4f 36020This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 36021
8e04817f 36022The @samp{R} packet has no reply.
ee2d5c50 36023
4f553f88 36024@item s @r{[}@var{addr}@r{]}
b8ff78ce
JB
36025@cindex @samp{s} packet
36026Single step. @var{addr} is the address at which to resume. If
36027@var{addr} is omitted, resume at same address.
c906108c 36028
393eab54
PA
36029This packet is deprecated for multi-threading support. @xref{vCont
36030packet}.
36031
ee2d5c50
AC
36032Reply:
36033@xref{Stop Reply Packets}, for the reply specifications.
36034
4f553f88 36035@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 36036@anchor{step with signal packet}
b8ff78ce
JB
36037@cindex @samp{S} packet
36038Step with signal. This is analogous to the @samp{C} packet, but
36039requests a single-step, rather than a normal resumption of execution.
c906108c 36040
393eab54
PA
36041This packet is deprecated for multi-threading support. @xref{vCont
36042packet}.
36043
ee2d5c50
AC
36044Reply:
36045@xref{Stop Reply Packets}, for the reply specifications.
36046
b8ff78ce
JB
36047@item t @var{addr}:@var{PP},@var{MM}
36048@cindex @samp{t} packet
8e04817f 36049Search backwards starting at address @var{addr} for a match with pattern
ee2d5c50
AC
36050@var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
36051@var{addr} must be at least 3 digits.
c906108c 36052
b90a069a 36053@item T @var{thread-id}
b8ff78ce 36054@cindex @samp{T} packet
b90a069a 36055Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 36056
ee2d5c50
AC
36057Reply:
36058@table @samp
36059@item OK
36060thread is still alive
b8ff78ce 36061@item E @var{NN}
ee2d5c50
AC
36062thread is dead
36063@end table
36064
b8ff78ce
JB
36065@item v
36066Packets starting with @samp{v} are identified by a multi-letter name,
36067up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 36068
2d717e4f
DJ
36069@item vAttach;@var{pid}
36070@cindex @samp{vAttach} packet
8b23ecc4
SL
36071Attach to a new process with the specified process ID @var{pid}.
36072The process ID is a
36073hexadecimal integer identifying the process. In all-stop mode, all
36074threads in the attached process are stopped; in non-stop mode, it may be
36075attached without being stopped if that is supported by the target.
36076
36077@c In non-stop mode, on a successful vAttach, the stub should set the
36078@c current thread to a thread of the newly-attached process. After
36079@c attaching, GDB queries for the attached process's thread ID with qC.
36080@c Also note that, from a user perspective, whether or not the
36081@c target is stopped on attach in non-stop mode depends on whether you
36082@c use the foreground or background version of the attach command, not
36083@c on what vAttach does; GDB does the right thing with respect to either
36084@c stopping or restarting threads.
2d717e4f
DJ
36085
36086This packet is only available in extended mode (@pxref{extended mode}).
36087
36088Reply:
36089@table @samp
36090@item E @var{nn}
36091for an error
36092@item @r{Any stop packet}
8b23ecc4
SL
36093for success in all-stop mode (@pxref{Stop Reply Packets})
36094@item OK
36095for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
36096@end table
36097
b90a069a 36098@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 36099@cindex @samp{vCont} packet
393eab54 36100@anchor{vCont packet}
b8ff78ce 36101Resume the inferior, specifying different actions for each thread.
b90a069a 36102If an action is specified with no @var{thread-id}, then it is applied to any
86d30acc 36103threads that don't have a specific action specified; if no default action is
8b23ecc4
SL
36104specified then other threads should remain stopped in all-stop mode and
36105in their current state in non-stop mode.
36106Specifying multiple
86d30acc 36107default actions is an error; specifying no actions is also an error.
b90a069a
SL
36108Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
36109
36110Currently supported actions are:
86d30acc 36111
b8ff78ce 36112@table @samp
86d30acc
DJ
36113@item c
36114Continue.
b8ff78ce 36115@item C @var{sig}
8b23ecc4 36116Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
36117@item s
36118Step.
b8ff78ce 36119@item S @var{sig}
8b23ecc4
SL
36120Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
36121@item t
36122Stop.
86d30acc
DJ
36123@end table
36124
8b23ecc4
SL
36125The optional argument @var{addr} normally associated with the
36126@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 36127not supported in @samp{vCont}.
86d30acc 36128
08a0efd0
PA
36129The @samp{t} action is only relevant in non-stop mode
36130(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
36131A stop reply should be generated for any affected thread not already stopped.
36132When a thread is stopped by means of a @samp{t} action,
36133the corresponding stop reply should indicate that the thread has stopped with
36134signal @samp{0}, regardless of whether the target uses some other signal
36135as an implementation detail.
36136
4220b2f8
TS
36137The stub must support @samp{vCont} if it reports support for
36138multiprocess extensions (@pxref{multiprocess extensions}). Note that in
36139this case @samp{vCont} actions can be specified to apply to all threads
36140in a process by using the @samp{p@var{pid}.-1} form of the
36141@var{thread-id}.
36142
86d30acc
DJ
36143Reply:
36144@xref{Stop Reply Packets}, for the reply specifications.
36145
b8ff78ce
JB
36146@item vCont?
36147@cindex @samp{vCont?} packet
d3e8051b 36148Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
36149
36150Reply:
36151@table @samp
b8ff78ce
JB
36152@item vCont@r{[};@var{action}@dots{}@r{]}
36153The @samp{vCont} packet is supported. Each @var{action} is a supported
36154command in the @samp{vCont} packet.
86d30acc 36155@item
b8ff78ce 36156The @samp{vCont} packet is not supported.
86d30acc 36157@end table
ee2d5c50 36158
a6b151f1
DJ
36159@item vFile:@var{operation}:@var{parameter}@dots{}
36160@cindex @samp{vFile} packet
36161Perform a file operation on the target system. For details,
36162see @ref{Host I/O Packets}.
36163
68437a39
DJ
36164@item vFlashErase:@var{addr},@var{length}
36165@cindex @samp{vFlashErase} packet
36166Direct the stub to erase @var{length} bytes of flash starting at
36167@var{addr}. The region may enclose any number of flash blocks, but
36168its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
36169flash block size appearing in the memory map (@pxref{Memory Map
36170Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
36171together, and sends a @samp{vFlashDone} request after each group; the
36172stub is allowed to delay erase operation until the @samp{vFlashDone}
36173packet is received.
36174
36175Reply:
36176@table @samp
36177@item OK
36178for success
36179@item E @var{NN}
36180for an error
36181@end table
36182
36183@item vFlashWrite:@var{addr}:@var{XX@dots{}}
36184@cindex @samp{vFlashWrite} packet
36185Direct the stub to write data to flash address @var{addr}. The data
36186is passed in binary form using the same encoding as for the @samp{X}
36187packet (@pxref{Binary Data}). The memory ranges specified by
36188@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
36189not overlap, and must appear in order of increasing addresses
36190(although @samp{vFlashErase} packets for higher addresses may already
36191have been received; the ordering is guaranteed only between
36192@samp{vFlashWrite} packets). If a packet writes to an address that was
36193neither erased by a preceding @samp{vFlashErase} packet nor by some other
36194target-specific method, the results are unpredictable.
36195
36196
36197Reply:
36198@table @samp
36199@item OK
36200for success
36201@item E.memtype
36202for vFlashWrite addressing non-flash memory
36203@item E @var{NN}
36204for an error
36205@end table
36206
36207@item vFlashDone
36208@cindex @samp{vFlashDone} packet
36209Indicate to the stub that flash programming operation is finished.
36210The stub is permitted to delay or batch the effects of a group of
36211@samp{vFlashErase} and @samp{vFlashWrite} packets until a
36212@samp{vFlashDone} packet is received. The contents of the affected
36213regions of flash memory are unpredictable until the @samp{vFlashDone}
36214request is completed.
36215
b90a069a
SL
36216@item vKill;@var{pid}
36217@cindex @samp{vKill} packet
36218Kill the process with the specified process ID. @var{pid} is a
36219hexadecimal integer identifying the process. This packet is used in
36220preference to @samp{k} when multiprocess protocol extensions are
36221supported; see @ref{multiprocess extensions}.
36222
36223Reply:
36224@table @samp
36225@item E @var{nn}
36226for an error
36227@item OK
36228for success
36229@end table
36230
2d717e4f
DJ
36231@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
36232@cindex @samp{vRun} packet
36233Run the program @var{filename}, passing it each @var{argument} on its
36234command line. The file and arguments are hex-encoded strings. If
36235@var{filename} is an empty string, the stub may use a default program
36236(e.g.@: the last program run). The program is created in the stopped
9b562ab8 36237state.
2d717e4f 36238
8b23ecc4
SL
36239@c FIXME: What about non-stop mode?
36240
2d717e4f
DJ
36241This packet is only available in extended mode (@pxref{extended mode}).
36242
36243Reply:
36244@table @samp
36245@item E @var{nn}
36246for an error
36247@item @r{Any stop packet}
36248for success (@pxref{Stop Reply Packets})
36249@end table
36250
8b23ecc4 36251@item vStopped
8b23ecc4 36252@cindex @samp{vStopped} packet
8dbe8ece 36253@xref{Notification Packets}.
8b23ecc4 36254
b8ff78ce 36255@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 36256@anchor{X packet}
b8ff78ce
JB
36257@cindex @samp{X} packet
36258Write data to memory, where the data is transmitted in binary.
36259@var{addr} is address, @var{length} is number of bytes,
0876f84a 36260@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 36261
ee2d5c50
AC
36262Reply:
36263@table @samp
36264@item OK
36265for success
b8ff78ce 36266@item E @var{NN}
ee2d5c50
AC
36267for an error
36268@end table
36269
a1dcb23a
DJ
36270@item z @var{type},@var{addr},@var{kind}
36271@itemx Z @var{type},@var{addr},@var{kind}
2f870471 36272@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
36273@cindex @samp{z} packet
36274@cindex @samp{Z} packets
36275Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 36276watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 36277
2f870471
AC
36278Each breakpoint and watchpoint packet @var{type} is documented
36279separately.
36280
512217c7
AC
36281@emph{Implementation notes: A remote target shall return an empty string
36282for an unrecognized breakpoint or watchpoint packet @var{type}. A
36283remote target shall support either both or neither of a given
b8ff78ce 36284@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
36285avoid potential problems with duplicate packets, the operations should
36286be implemented in an idempotent way.}
36287
a1dcb23a 36288@item z0,@var{addr},@var{kind}
d3ce09f5 36289@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
36290@cindex @samp{z0} packet
36291@cindex @samp{Z0} packet
36292Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
a1dcb23a 36293@var{addr} of type @var{kind}.
2f870471
AC
36294
36295A memory breakpoint is implemented by replacing the instruction at
36296@var{addr} with a software breakpoint or trap instruction. The
a1dcb23a
DJ
36297@var{kind} is target-specific and typically indicates the size of
36298the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
36299and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
36300architectures have additional meanings for @var{kind};
83364271
LM
36301@var{cond_list} is an optional list of conditional expressions in bytecode
36302form that should be evaluated on the target's side. These are the
36303conditions that should be taken into consideration when deciding if
36304the breakpoint trigger should be reported back to @var{GDBN}.
36305
36306The @var{cond_list} parameter is comprised of a series of expressions,
36307concatenated without separators. Each expression has the following form:
36308
36309@table @samp
36310
36311@item X @var{len},@var{expr}
36312@var{len} is the length of the bytecode expression and @var{expr} is the
36313actual conditional expression in bytecode form.
36314
36315@end table
36316
d3ce09f5
SS
36317The optional @var{cmd_list} parameter introduces commands that may be
36318run on the target, rather than being reported back to @value{GDBN}.
36319The parameter starts with a numeric flag @var{persist}; if the flag is
36320nonzero, then the breakpoint may remain active and the commands
36321continue to be run even when @value{GDBN} disconnects from the target.
36322Following this flag is a series of expressions concatenated with no
36323separators. Each expression has the following form:
36324
36325@table @samp
36326
36327@item X @var{len},@var{expr}
36328@var{len} is the length of the bytecode expression and @var{expr} is the
36329actual conditional expression in bytecode form.
36330
36331@end table
36332
a1dcb23a 36333see @ref{Architecture-Specific Protocol Details}.
c906108c 36334
2f870471
AC
36335@emph{Implementation note: It is possible for a target to copy or move
36336code that contains memory breakpoints (e.g., when implementing
36337overlays). The behavior of this packet, in the presence of such a
36338target, is not defined.}
c906108c 36339
ee2d5c50
AC
36340Reply:
36341@table @samp
2f870471
AC
36342@item OK
36343success
36344@item
36345not supported
b8ff78ce 36346@item E @var{NN}
ee2d5c50 36347for an error
2f870471
AC
36348@end table
36349
a1dcb23a 36350@item z1,@var{addr},@var{kind}
83364271 36351@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
b8ff78ce
JB
36352@cindex @samp{z1} packet
36353@cindex @samp{Z1} packet
36354Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 36355address @var{addr}.
2f870471
AC
36356
36357A hardware breakpoint is implemented using a mechanism that is not
a1dcb23a 36358dependant on being able to modify the target's memory. @var{kind}
83364271 36359and @var{cond_list} have the same meaning as in @samp{Z0} packets.
2f870471
AC
36360
36361@emph{Implementation note: A hardware breakpoint is not affected by code
36362movement.}
36363
36364Reply:
36365@table @samp
ee2d5c50 36366@item OK
2f870471
AC
36367success
36368@item
36369not supported
b8ff78ce 36370@item E @var{NN}
2f870471
AC
36371for an error
36372@end table
36373
a1dcb23a
DJ
36374@item z2,@var{addr},@var{kind}
36375@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
36376@cindex @samp{z2} packet
36377@cindex @samp{Z2} packet
a1dcb23a
DJ
36378Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
36379@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36380
36381Reply:
36382@table @samp
36383@item OK
36384success
36385@item
36386not supported
b8ff78ce 36387@item E @var{NN}
2f870471
AC
36388for an error
36389@end table
36390
a1dcb23a
DJ
36391@item z3,@var{addr},@var{kind}
36392@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
36393@cindex @samp{z3} packet
36394@cindex @samp{Z3} packet
a1dcb23a
DJ
36395Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
36396@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36397
36398Reply:
36399@table @samp
36400@item OK
36401success
36402@item
36403not supported
b8ff78ce 36404@item E @var{NN}
2f870471
AC
36405for an error
36406@end table
36407
a1dcb23a
DJ
36408@item z4,@var{addr},@var{kind}
36409@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
36410@cindex @samp{z4} packet
36411@cindex @samp{Z4} packet
a1dcb23a
DJ
36412Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
36413@var{kind} is interpreted as the number of bytes to watch.
2f870471
AC
36414
36415Reply:
36416@table @samp
36417@item OK
36418success
36419@item
36420not supported
b8ff78ce 36421@item E @var{NN}
2f870471 36422for an error
ee2d5c50
AC
36423@end table
36424
36425@end table
c906108c 36426
ee2d5c50
AC
36427@node Stop Reply Packets
36428@section Stop Reply Packets
36429@cindex stop reply packets
c906108c 36430
8b23ecc4
SL
36431The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
36432@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
36433receive any of the below as a reply. Except for @samp{?}
36434and @samp{vStopped}, that reply is only returned
b8ff78ce 36435when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
36436number} is defined by the header @file{include/gdb/signals.h} in the
36437@value{GDBN} source code.
c906108c 36438
b8ff78ce
JB
36439As in the description of request packets, we include spaces in the
36440reply templates for clarity; these are not part of the reply packet's
36441syntax. No @value{GDBN} stop reply packet uses spaces to separate its
36442components.
c906108c 36443
b8ff78ce 36444@table @samp
ee2d5c50 36445
b8ff78ce 36446@item S @var{AA}
599b237a 36447The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36448number). This is equivalent to a @samp{T} response with no
36449@var{n}:@var{r} pairs.
c906108c 36450
b8ff78ce
JB
36451@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
36452@cindex @samp{T} packet reply
599b237a 36453The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
36454number). This is equivalent to an @samp{S} response, except that the
36455@samp{@var{n}:@var{r}} pairs can carry values of important registers
36456and other information directly in the stop reply packet, reducing
36457round-trip latency. Single-step and breakpoint traps are reported
36458this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
36459
36460@itemize @bullet
b8ff78ce 36461@item
599b237a 36462If @var{n} is a hexadecimal number, it is a register number, and the
b8ff78ce
JB
36463corresponding @var{r} gives that register's value. @var{r} is a
36464series of bytes in target byte order, with each byte given by a
36465two-digit hex number.
cfa9d6d9 36466
b8ff78ce 36467@item
b90a069a
SL
36468If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
36469the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 36470
dc146f7c
VP
36471@item
36472If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
36473the core on which the stop event was detected.
36474
b8ff78ce 36475@item
cfa9d6d9
DJ
36476If @var{n} is a recognized @dfn{stop reason}, it describes a more
36477specific event that stopped the target. The currently defined stop
36478reasons are listed below. @var{aa} should be @samp{05}, the trap
36479signal. At most one stop reason should be present.
36480
b8ff78ce
JB
36481@item
36482Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
36483and go on to the next; this allows us to extend the protocol in the
36484future.
cfa9d6d9
DJ
36485@end itemize
36486
36487The currently defined stop reasons are:
36488
36489@table @samp
36490@item watch
36491@itemx rwatch
36492@itemx awatch
36493The packet indicates a watchpoint hit, and @var{r} is the data address, in
36494hex.
36495
36496@cindex shared library events, remote reply
36497@item library
36498The packet indicates that the loaded libraries have changed.
36499@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
36500list of loaded libraries. @var{r} is ignored.
bacec72f
MS
36501
36502@cindex replay log events, remote reply
36503@item replaylog
36504The packet indicates that the target cannot continue replaying
36505logged execution events, because it has reached the end (or the
36506beginning when executing backward) of the log. The value of @var{r}
36507will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
36508for more information.
cfa9d6d9 36509@end table
ee2d5c50 36510
b8ff78ce 36511@item W @var{AA}
b90a069a 36512@itemx W @var{AA} ; process:@var{pid}
8e04817f 36513The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
36514applicable to certain targets.
36515
b90a069a
SL
36516The second form of the response, including the process ID of the exited
36517process, can be used only when @value{GDBN} has reported support for
36518multiprocess protocol extensions; see @ref{multiprocess extensions}.
36519The @var{pid} is formatted as a big-endian hex string.
36520
b8ff78ce 36521@item X @var{AA}
b90a069a 36522@itemx X @var{AA} ; process:@var{pid}
8e04817f 36523The process terminated with signal @var{AA}.
c906108c 36524
b90a069a
SL
36525The second form of the response, including the process ID of the
36526terminated process, can be used only when @value{GDBN} has reported
36527support for multiprocess protocol extensions; see @ref{multiprocess
36528extensions}. The @var{pid} is formatted as a big-endian hex string.
36529
b8ff78ce
JB
36530@item O @var{XX}@dots{}
36531@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
36532written as the program's console output. This can happen at any time
36533while the program is running and the debugger should continue to wait
8b23ecc4 36534for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 36535
b8ff78ce 36536@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
36537@var{call-id} is the identifier which says which host system call should
36538be called. This is just the name of the function. Translation into the
36539correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 36540@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
36541system calls.
36542
b8ff78ce
JB
36543@samp{@var{parameter}@dots{}} is a list of parameters as defined for
36544this very system call.
0ce1b118 36545
b8ff78ce
JB
36546The target replies with this packet when it expects @value{GDBN} to
36547call a host system call on behalf of the target. @value{GDBN} replies
36548with an appropriate @samp{F} packet and keeps up waiting for the next
36549reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
36550or @samp{s} action is expected to be continued. @xref{File-I/O Remote
36551Protocol Extension}, for more details.
0ce1b118 36552
ee2d5c50
AC
36553@end table
36554
36555@node General Query Packets
36556@section General Query Packets
9c16f35a 36557@cindex remote query requests
c906108c 36558
5f3bebba
JB
36559Packets starting with @samp{q} are @dfn{general query packets};
36560packets starting with @samp{Q} are @dfn{general set packets}. General
36561query and set packets are a semi-unified form for retrieving and
36562sending information to and from the stub.
36563
36564The initial letter of a query or set packet is followed by a name
36565indicating what sort of thing the packet applies to. For example,
36566@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
36567definitions with the stub. These packet names follow some
36568conventions:
36569
36570@itemize @bullet
36571@item
36572The name must not contain commas, colons or semicolons.
36573@item
36574Most @value{GDBN} query and set packets have a leading upper case
36575letter.
36576@item
36577The names of custom vendor packets should use a company prefix, in
36578lower case, followed by a period. For example, packets designed at
36579the Acme Corporation might begin with @samp{qacme.foo} (for querying
36580foos) or @samp{Qacme.bar} (for setting bars).
36581@end itemize
36582
aa56d27a
JB
36583The name of a query or set packet should be separated from any
36584parameters by a @samp{:}; the parameters themselves should be
36585separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
36586full packet name, and check for a separator or the end of the packet,
36587in case two packet names share a common prefix. New packets should not begin
36588with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
36589packets predate these conventions, and have arguments without any terminator
36590for the packet name; we suspect they are in widespread use in places that
36591are difficult to upgrade. The @samp{qC} packet has no arguments, but some
36592existing stubs (e.g.@: RedBoot) are known to not check for the end of the
36593packet.}.
c906108c 36594
b8ff78ce
JB
36595Like the descriptions of the other packets, each description here
36596has a template showing the packet's overall syntax, followed by an
36597explanation of the packet's meaning. We include spaces in some of the
36598templates for clarity; these are not part of the packet's syntax. No
36599@value{GDBN} packet uses spaces to separate its components.
36600
5f3bebba
JB
36601Here are the currently defined query and set packets:
36602
b8ff78ce 36603@table @samp
c906108c 36604
d1feda86 36605@item QAgent:1
af4238e5 36606@itemx QAgent:0
d1feda86
YQ
36607Turn on or off the agent as a helper to perform some debugging operations
36608delegated from @value{GDBN} (@pxref{Control Agent}).
36609
d914c394
SS
36610@item QAllow:@var{op}:@var{val}@dots{}
36611@cindex @samp{QAllow} packet
36612Specify which operations @value{GDBN} expects to request of the
36613target, as a semicolon-separated list of operation name and value
36614pairs. Possible values for @var{op} include @samp{WriteReg},
36615@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
36616@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
36617indicating that @value{GDBN} will not request the operation, or 1,
36618indicating that it may. (The target can then use this to set up its
36619own internals optimally, for instance if the debugger never expects to
36620insert breakpoints, it may not need to install its own trap handler.)
36621
b8ff78ce 36622@item qC
9c16f35a 36623@cindex current thread, remote request
b8ff78ce 36624@cindex @samp{qC} packet
b90a069a 36625Return the current thread ID.
ee2d5c50
AC
36626
36627Reply:
36628@table @samp
b90a069a
SL
36629@item QC @var{thread-id}
36630Where @var{thread-id} is a thread ID as documented in
36631@ref{thread-id syntax}.
b8ff78ce 36632@item @r{(anything else)}
b90a069a 36633Any other reply implies the old thread ID.
ee2d5c50
AC
36634@end table
36635
b8ff78ce 36636@item qCRC:@var{addr},@var{length}
ff2587ec 36637@cindex CRC of memory block, remote request
b8ff78ce 36638@cindex @samp{qCRC} packet
99e008fe
EZ
36639Compute the CRC checksum of a block of memory using CRC-32 defined in
36640IEEE 802.3. The CRC is computed byte at a time, taking the most
36641significant bit of each byte first. The initial pattern code
36642@code{0xffffffff} is used to ensure leading zeros affect the CRC.
36643
36644@emph{Note:} This is the same CRC used in validating separate debug
36645files (@pxref{Separate Debug Files, , Debugging Information in Separate
36646Files}). However the algorithm is slightly different. When validating
36647separate debug files, the CRC is computed taking the @emph{least}
36648significant bit of each byte first, and the final result is inverted to
36649detect trailing zeros.
36650
ff2587ec
WZ
36651Reply:
36652@table @samp
b8ff78ce 36653@item E @var{NN}
ff2587ec 36654An error (such as memory fault)
b8ff78ce
JB
36655@item C @var{crc32}
36656The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
36657@end table
36658
03583c20
UW
36659@item QDisableRandomization:@var{value}
36660@cindex disable address space randomization, remote request
36661@cindex @samp{QDisableRandomization} packet
36662Some target operating systems will randomize the virtual address space
36663of the inferior process as a security feature, but provide a feature
36664to disable such randomization, e.g.@: to allow for a more deterministic
36665debugging experience. On such systems, this packet with a @var{value}
36666of 1 directs the target to disable address space randomization for
36667processes subsequently started via @samp{vRun} packets, while a packet
36668with a @var{value} of 0 tells the target to enable address space
36669randomization.
36670
36671This packet is only available in extended mode (@pxref{extended mode}).
36672
36673Reply:
36674@table @samp
36675@item OK
36676The request succeeded.
36677
36678@item E @var{nn}
36679An error occurred. @var{nn} are hex digits.
36680
36681@item
36682An empty reply indicates that @samp{QDisableRandomization} is not supported
36683by the stub.
36684@end table
36685
36686This packet is not probed by default; the remote stub must request it,
36687by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36688This should only be done on targets that actually support disabling
36689address space randomization.
36690
b8ff78ce
JB
36691@item qfThreadInfo
36692@itemx qsThreadInfo
9c16f35a 36693@cindex list active threads, remote request
b8ff78ce
JB
36694@cindex @samp{qfThreadInfo} packet
36695@cindex @samp{qsThreadInfo} packet
b90a069a 36696Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
36697may be too many active threads to fit into one reply packet, this query
36698works iteratively: it may require more than one query/reply sequence to
36699obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
36700be the @samp{qfThreadInfo} query; subsequent queries in the
36701sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 36702
b8ff78ce 36703NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
36704
36705Reply:
36706@table @samp
b90a069a
SL
36707@item m @var{thread-id}
36708A single thread ID
36709@item m @var{thread-id},@var{thread-id}@dots{}
36710a comma-separated list of thread IDs
b8ff78ce
JB
36711@item l
36712(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
36713@end table
36714
36715In response to each query, the target will reply with a list of one or
b90a069a 36716more thread IDs, separated by commas.
e1aac25b 36717@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 36718ids (using the @samp{qs} form of the query), until the target responds
501994c0 36719with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
36720Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
36721fields.
c906108c 36722
b8ff78ce 36723@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 36724@cindex get thread-local storage address, remote request
b8ff78ce 36725@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
36726Fetch the address associated with thread local storage specified
36727by @var{thread-id}, @var{offset}, and @var{lm}.
36728
b90a069a
SL
36729@var{thread-id} is the thread ID associated with the
36730thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
36731
36732@var{offset} is the (big endian, hex encoded) offset associated with the
36733thread local variable. (This offset is obtained from the debug
36734information associated with the variable.)
36735
db2e3e2e 36736@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 36737load module associated with the thread local storage. For example,
ff2587ec
WZ
36738a @sc{gnu}/Linux system will pass the link map address of the shared
36739object associated with the thread local storage under consideration.
36740Other operating environments may choose to represent the load module
36741differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
36742
36743Reply:
b8ff78ce
JB
36744@table @samp
36745@item @var{XX}@dots{}
ff2587ec
WZ
36746Hex encoded (big endian) bytes representing the address of the thread
36747local storage requested.
36748
b8ff78ce
JB
36749@item E @var{nn}
36750An error occurred. @var{nn} are hex digits.
ff2587ec 36751
b8ff78ce
JB
36752@item
36753An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
36754@end table
36755
711e434b
PM
36756@item qGetTIBAddr:@var{thread-id}
36757@cindex get thread information block address
36758@cindex @samp{qGetTIBAddr} packet
36759Fetch address of the Windows OS specific Thread Information Block.
36760
36761@var{thread-id} is the thread ID associated with the thread.
36762
36763Reply:
36764@table @samp
36765@item @var{XX}@dots{}
36766Hex encoded (big endian) bytes representing the linear address of the
36767thread information block.
36768
36769@item E @var{nn}
36770An error occured. This means that either the thread was not found, or the
36771address could not be retrieved.
36772
36773@item
36774An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
36775@end table
36776
b8ff78ce 36777@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
36778Obtain thread information from RTOS. Where: @var{startflag} (one hex
36779digit) is one to indicate the first query and zero to indicate a
36780subsequent query; @var{threadcount} (two hex digits) is the maximum
36781number of threads the response packet can contain; and @var{nextthread}
36782(eight hex digits), for subsequent queries (@var{startflag} is zero), is
36783returned in the response as @var{argthread}.
ee2d5c50 36784
b8ff78ce 36785Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
36786
36787Reply:
36788@table @samp
b8ff78ce 36789@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
36790Where: @var{count} (two hex digits) is the number of threads being
36791returned; @var{done} (one hex digit) is zero to indicate more threads
36792and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 36793digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
ee2d5c50 36794is a sequence of thread IDs from the target. @var{threadid} (eight hex
8e04817f 36795digits). See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 36796@end table
c906108c 36797
b8ff78ce 36798@item qOffsets
9c16f35a 36799@cindex section offsets, remote request
b8ff78ce 36800@cindex @samp{qOffsets} packet
31d99776
DJ
36801Get section offsets that the target used when relocating the downloaded
36802image.
c906108c 36803
ee2d5c50
AC
36804Reply:
36805@table @samp
31d99776
DJ
36806@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
36807Relocate the @code{Text} section by @var{xxx} from its original address.
36808Relocate the @code{Data} section by @var{yyy} from its original address.
36809If the object file format provides segment information (e.g.@: @sc{elf}
36810@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
36811segments by the supplied offsets.
36812
36813@emph{Note: while a @code{Bss} offset may be included in the response,
36814@value{GDBN} ignores this and instead applies the @code{Data} offset
36815to the @code{Bss} section.}
36816
36817@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
36818Relocate the first segment of the object file, which conventionally
36819contains program code, to a starting address of @var{xxx}. If
36820@samp{DataSeg} is specified, relocate the second segment, which
36821conventionally contains modifiable data, to a starting address of
36822@var{yyy}. @value{GDBN} will report an error if the object file
36823does not contain segment information, or does not contain at least
36824as many segments as mentioned in the reply. Extra segments are
36825kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
36826@end table
36827
b90a069a 36828@item qP @var{mode} @var{thread-id}
9c16f35a 36829@cindex thread information, remote request
b8ff78ce 36830@cindex @samp{qP} packet
b90a069a
SL
36831Returns information on @var{thread-id}. Where: @var{mode} is a hex
36832encoded 32 bit mode; @var{thread-id} is a thread ID
36833(@pxref{thread-id syntax}).
ee2d5c50 36834
aa56d27a
JB
36835Don't use this packet; use the @samp{qThreadExtraInfo} query instead
36836(see below).
36837
b8ff78ce 36838Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 36839
8b23ecc4 36840@item QNonStop:1
687e43a4 36841@itemx QNonStop:0
8b23ecc4
SL
36842@cindex non-stop mode, remote request
36843@cindex @samp{QNonStop} packet
36844@anchor{QNonStop}
36845Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
36846@xref{Remote Non-Stop}, for more information.
36847
36848Reply:
36849@table @samp
36850@item OK
36851The request succeeded.
36852
36853@item E @var{nn}
36854An error occurred. @var{nn} are hex digits.
36855
36856@item
36857An empty reply indicates that @samp{QNonStop} is not supported by
36858the stub.
36859@end table
36860
36861This packet is not probed by default; the remote stub must request it,
36862by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36863Use of this packet is controlled by the @code{set non-stop} command;
36864@pxref{Non-Stop Mode}.
36865
89be2091
DJ
36866@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
36867@cindex pass signals to inferior, remote request
36868@cindex @samp{QPassSignals} packet
23181151 36869@anchor{QPassSignals}
89be2091
DJ
36870Each listed @var{signal} should be passed directly to the inferior process.
36871Signals are numbered identically to continue packets and stop replies
36872(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
36873strictly greater than the previous item. These signals do not need to stop
36874the inferior, or be reported to @value{GDBN}. All other signals should be
36875reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
36876combine; any earlier @samp{QPassSignals} list is completely replaced by the
36877new list. This packet improves performance when using @samp{handle
36878@var{signal} nostop noprint pass}.
36879
36880Reply:
36881@table @samp
36882@item OK
36883The request succeeded.
36884
36885@item E @var{nn}
36886An error occurred. @var{nn} are hex digits.
36887
36888@item
36889An empty reply indicates that @samp{QPassSignals} is not supported by
36890the stub.
36891@end table
36892
36893Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 36894command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
36895This packet is not probed by default; the remote stub must request it,
36896by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36897
9b224c5e
PA
36898@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
36899@cindex signals the inferior may see, remote request
36900@cindex @samp{QProgramSignals} packet
36901@anchor{QProgramSignals}
36902Each listed @var{signal} may be delivered to the inferior process.
36903Others should be silently discarded.
36904
36905In some cases, the remote stub may need to decide whether to deliver a
36906signal to the program or not without @value{GDBN} involvement. One
36907example of that is while detaching --- the program's threads may have
36908stopped for signals that haven't yet had a chance of being reported to
36909@value{GDBN}, and so the remote stub can use the signal list specified
36910by this packet to know whether to deliver or ignore those pending
36911signals.
36912
36913This does not influence whether to deliver a signal as requested by a
36914resumption packet (@pxref{vCont packet}).
36915
36916Signals are numbered identically to continue packets and stop replies
36917(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
36918strictly greater than the previous item. Multiple
36919@samp{QProgramSignals} packets do not combine; any earlier
36920@samp{QProgramSignals} list is completely replaced by the new list.
36921
36922Reply:
36923@table @samp
36924@item OK
36925The request succeeded.
36926
36927@item E @var{nn}
36928An error occurred. @var{nn} are hex digits.
36929
36930@item
36931An empty reply indicates that @samp{QProgramSignals} is not supported
36932by the stub.
36933@end table
36934
36935Use of this packet is controlled by the @code{set remote program-signals}
36936command (@pxref{Remote Configuration, set remote program-signals}).
36937This packet is not probed by default; the remote stub must request it,
36938by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36939
b8ff78ce 36940@item qRcmd,@var{command}
ff2587ec 36941@cindex execute remote command, remote request
b8ff78ce 36942@cindex @samp{qRcmd} packet
ff2587ec 36943@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
36944execution. Invalid commands should be reported using the output
36945string. Before the final result packet, the target may also respond
36946with a number of intermediate @samp{O@var{output}} console output
36947packets. @emph{Implementors should note that providing access to a
36948stubs's interpreter may have security implications}.
fa93a9d8 36949
ff2587ec
WZ
36950Reply:
36951@table @samp
36952@item OK
36953A command response with no output.
36954@item @var{OUTPUT}
36955A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 36956@item E @var{NN}
ff2587ec 36957Indicate a badly formed request.
b8ff78ce
JB
36958@item
36959An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 36960@end table
fa93a9d8 36961
aa56d27a
JB
36962(Note that the @code{qRcmd} packet's name is separated from the
36963command by a @samp{,}, not a @samp{:}, contrary to the naming
36964conventions above. Please don't use this packet as a model for new
36965packets.)
36966
08388c79
DE
36967@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
36968@cindex searching memory, in remote debugging
36969@cindex @samp{qSearch:memory} packet
36970@anchor{qSearch memory}
36971Search @var{length} bytes at @var{address} for @var{search-pattern}.
36972@var{address} and @var{length} are encoded in hex.
36973@var{search-pattern} is a sequence of bytes, hex encoded.
36974
36975Reply:
36976@table @samp
36977@item 0
36978The pattern was not found.
36979@item 1,address
36980The pattern was found at @var{address}.
36981@item E @var{NN}
36982A badly formed request or an error was encountered while searching memory.
36983@item
36984An empty reply indicates that @samp{qSearch:memory} is not recognized.
36985@end table
36986
a6f3e723
SL
36987@item QStartNoAckMode
36988@cindex @samp{QStartNoAckMode} packet
36989@anchor{QStartNoAckMode}
36990Request that the remote stub disable the normal @samp{+}/@samp{-}
36991protocol acknowledgments (@pxref{Packet Acknowledgment}).
36992
36993Reply:
36994@table @samp
36995@item OK
36996The stub has switched to no-acknowledgment mode.
36997@value{GDBN} acknowledges this reponse,
36998but neither the stub nor @value{GDBN} shall send or expect further
36999@samp{+}/@samp{-} acknowledgments in the current connection.
37000@item
37001An empty reply indicates that the stub does not support no-acknowledgment mode.
37002@end table
37003
be2a5f71
DJ
37004@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
37005@cindex supported packets, remote query
37006@cindex features of the remote protocol
37007@cindex @samp{qSupported} packet
0876f84a 37008@anchor{qSupported}
be2a5f71
DJ
37009Tell the remote stub about features supported by @value{GDBN}, and
37010query the stub for features it supports. This packet allows
37011@value{GDBN} and the remote stub to take advantage of each others'
37012features. @samp{qSupported} also consolidates multiple feature probes
37013at startup, to improve @value{GDBN} performance---a single larger
37014packet performs better than multiple smaller probe packets on
37015high-latency links. Some features may enable behavior which must not
37016be on by default, e.g.@: because it would confuse older clients or
37017stubs. Other features may describe packets which could be
37018automatically probed for, but are not. These features must be
37019reported before @value{GDBN} will use them. This ``default
37020unsupported'' behavior is not appropriate for all packets, but it
37021helps to keep the initial connection time under control with new
37022versions of @value{GDBN} which support increasing numbers of packets.
37023
37024Reply:
37025@table @samp
37026@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
37027The stub supports or does not support each returned @var{stubfeature},
37028depending on the form of each @var{stubfeature} (see below for the
37029possible forms).
37030@item
37031An empty reply indicates that @samp{qSupported} is not recognized,
37032or that no features needed to be reported to @value{GDBN}.
37033@end table
37034
37035The allowed forms for each feature (either a @var{gdbfeature} in the
37036@samp{qSupported} packet, or a @var{stubfeature} in the response)
37037are:
37038
37039@table @samp
37040@item @var{name}=@var{value}
37041The remote protocol feature @var{name} is supported, and associated
37042with the specified @var{value}. The format of @var{value} depends
37043on the feature, but it must not include a semicolon.
37044@item @var{name}+
37045The remote protocol feature @var{name} is supported, and does not
37046need an associated value.
37047@item @var{name}-
37048The remote protocol feature @var{name} is not supported.
37049@item @var{name}?
37050The remote protocol feature @var{name} may be supported, and
37051@value{GDBN} should auto-detect support in some other way when it is
37052needed. This form will not be used for @var{gdbfeature} notifications,
37053but may be used for @var{stubfeature} responses.
37054@end table
37055
37056Whenever the stub receives a @samp{qSupported} request, the
37057supplied set of @value{GDBN} features should override any previous
37058request. This allows @value{GDBN} to put the stub in a known
37059state, even if the stub had previously been communicating with
37060a different version of @value{GDBN}.
37061
b90a069a
SL
37062The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
37063are defined:
37064
37065@table @samp
37066@item multiprocess
37067This feature indicates whether @value{GDBN} supports multiprocess
37068extensions to the remote protocol. @value{GDBN} does not use such
37069extensions unless the stub also reports that it supports them by
37070including @samp{multiprocess+} in its @samp{qSupported} reply.
37071@xref{multiprocess extensions}, for details.
c8d5aac9
L
37072
37073@item xmlRegisters
37074This feature indicates that @value{GDBN} supports the XML target
37075description. If the stub sees @samp{xmlRegisters=} with target
37076specific strings separated by a comma, it will report register
37077description.
dde08ee1
PA
37078
37079@item qRelocInsn
37080This feature indicates whether @value{GDBN} supports the
37081@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
37082instruction reply packet}).
b90a069a
SL
37083@end table
37084
37085Stubs should ignore any unknown values for
be2a5f71
DJ
37086@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
37087packet supports receiving packets of unlimited length (earlier
b90a069a 37088versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
37089for @var{gdbfeature} may be defined in the future to let the stub take
37090advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
37091improvements in the remote protocol---the @samp{multiprocess} feature is
37092an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
37093of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
37094describes all the features it supports, and then the stub replies with
37095all the features it supports.
37096
37097Similarly, @value{GDBN} will silently ignore unrecognized stub feature
37098responses, as long as each response uses one of the standard forms.
37099
37100Some features are flags. A stub which supports a flag feature
37101should respond with a @samp{+} form response. Other features
37102require values, and the stub should respond with an @samp{=}
37103form response.
37104
37105Each feature has a default value, which @value{GDBN} will use if
37106@samp{qSupported} is not available or if the feature is not mentioned
37107in the @samp{qSupported} response. The default values are fixed; a
37108stub is free to omit any feature responses that match the defaults.
37109
37110Not all features can be probed, but for those which can, the probing
37111mechanism is useful: in some cases, a stub's internal
37112architecture may not allow the protocol layer to know some information
37113about the underlying target in advance. This is especially common in
37114stubs which may be configured for multiple targets.
37115
37116These are the currently defined stub features and their properties:
37117
cfa9d6d9 37118@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
37119@c NOTE: The first row should be @headitem, but we do not yet require
37120@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 37121@item Feature Name
be2a5f71
DJ
37122@tab Value Required
37123@tab Default
37124@tab Probe Allowed
37125
37126@item @samp{PacketSize}
37127@tab Yes
37128@tab @samp{-}
37129@tab No
37130
0876f84a
DJ
37131@item @samp{qXfer:auxv:read}
37132@tab No
37133@tab @samp{-}
37134@tab Yes
37135
23181151
DJ
37136@item @samp{qXfer:features:read}
37137@tab No
37138@tab @samp{-}
37139@tab Yes
37140
cfa9d6d9
DJ
37141@item @samp{qXfer:libraries:read}
37142@tab No
37143@tab @samp{-}
37144@tab Yes
37145
68437a39
DJ
37146@item @samp{qXfer:memory-map:read}
37147@tab No
37148@tab @samp{-}
37149@tab Yes
37150
0fb4aa4b
PA
37151@item @samp{qXfer:sdata:read}
37152@tab No
37153@tab @samp{-}
37154@tab Yes
37155
0e7f50da
UW
37156@item @samp{qXfer:spu:read}
37157@tab No
37158@tab @samp{-}
37159@tab Yes
37160
37161@item @samp{qXfer:spu:write}
37162@tab No
37163@tab @samp{-}
37164@tab Yes
37165
4aa995e1
PA
37166@item @samp{qXfer:siginfo:read}
37167@tab No
37168@tab @samp{-}
37169@tab Yes
37170
37171@item @samp{qXfer:siginfo:write}
37172@tab No
37173@tab @samp{-}
37174@tab Yes
37175
dc146f7c
VP
37176@item @samp{qXfer:threads:read}
37177@tab No
37178@tab @samp{-}
37179@tab Yes
37180
b3b9301e
PA
37181@item @samp{qXfer:traceframe-info:read}
37182@tab No
37183@tab @samp{-}
37184@tab Yes
37185
169081d0
TG
37186@item @samp{qXfer:uib:read}
37187@tab No
37188@tab @samp{-}
37189@tab Yes
37190
78d85199
YQ
37191@item @samp{qXfer:fdpic:read}
37192@tab No
37193@tab @samp{-}
37194@tab Yes
dc146f7c 37195
8b23ecc4
SL
37196@item @samp{QNonStop}
37197@tab No
37198@tab @samp{-}
37199@tab Yes
37200
89be2091
DJ
37201@item @samp{QPassSignals}
37202@tab No
37203@tab @samp{-}
37204@tab Yes
37205
a6f3e723
SL
37206@item @samp{QStartNoAckMode}
37207@tab No
37208@tab @samp{-}
37209@tab Yes
37210
b90a069a
SL
37211@item @samp{multiprocess}
37212@tab No
37213@tab @samp{-}
37214@tab No
37215
83364271
LM
37216@item @samp{ConditionalBreakpoints}
37217@tab No
37218@tab @samp{-}
37219@tab No
37220
782b2b07
SS
37221@item @samp{ConditionalTracepoints}
37222@tab No
37223@tab @samp{-}
37224@tab No
37225
0d772ac9
MS
37226@item @samp{ReverseContinue}
37227@tab No
2f8132f3 37228@tab @samp{-}
0d772ac9
MS
37229@tab No
37230
37231@item @samp{ReverseStep}
37232@tab No
2f8132f3 37233@tab @samp{-}
0d772ac9
MS
37234@tab No
37235
409873ef
SS
37236@item @samp{TracepointSource}
37237@tab No
37238@tab @samp{-}
37239@tab No
37240
d1feda86
YQ
37241@item @samp{QAgent}
37242@tab No
37243@tab @samp{-}
37244@tab No
37245
d914c394
SS
37246@item @samp{QAllow}
37247@tab No
37248@tab @samp{-}
37249@tab No
37250
03583c20
UW
37251@item @samp{QDisableRandomization}
37252@tab No
37253@tab @samp{-}
37254@tab No
37255
d248b706
KY
37256@item @samp{EnableDisableTracepoints}
37257@tab No
37258@tab @samp{-}
37259@tab No
37260
3065dfb6
SS
37261@item @samp{tracenz}
37262@tab No
37263@tab @samp{-}
37264@tab No
37265
d3ce09f5
SS
37266@item @samp{BreakpointCommands}
37267@tab No
37268@tab @samp{-}
37269@tab No
37270
be2a5f71
DJ
37271@end multitable
37272
37273These are the currently defined stub features, in more detail:
37274
37275@table @samp
37276@cindex packet size, remote protocol
37277@item PacketSize=@var{bytes}
37278The remote stub can accept packets up to at least @var{bytes} in
37279length. @value{GDBN} will send packets up to this size for bulk
37280transfers, and will never send larger packets. This is a limit on the
37281data characters in the packet, including the frame and checksum.
37282There is no trailing NUL byte in a remote protocol packet; if the stub
37283stores packets in a NUL-terminated format, it should allow an extra
37284byte in its buffer for the NUL. If this stub feature is not supported,
37285@value{GDBN} guesses based on the size of the @samp{g} packet response.
37286
0876f84a
DJ
37287@item qXfer:auxv:read
37288The remote stub understands the @samp{qXfer:auxv:read} packet
37289(@pxref{qXfer auxiliary vector read}).
37290
23181151
DJ
37291@item qXfer:features:read
37292The remote stub understands the @samp{qXfer:features:read} packet
37293(@pxref{qXfer target description read}).
37294
cfa9d6d9
DJ
37295@item qXfer:libraries:read
37296The remote stub understands the @samp{qXfer:libraries:read} packet
37297(@pxref{qXfer library list read}).
37298
2268b414
JK
37299@item qXfer:libraries-svr4:read
37300The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
37301(@pxref{qXfer svr4 library list read}).
37302
23181151
DJ
37303@item qXfer:memory-map:read
37304The remote stub understands the @samp{qXfer:memory-map:read} packet
37305(@pxref{qXfer memory map read}).
37306
0fb4aa4b
PA
37307@item qXfer:sdata:read
37308The remote stub understands the @samp{qXfer:sdata:read} packet
37309(@pxref{qXfer sdata read}).
37310
0e7f50da
UW
37311@item qXfer:spu:read
37312The remote stub understands the @samp{qXfer:spu:read} packet
37313(@pxref{qXfer spu read}).
37314
37315@item qXfer:spu:write
37316The remote stub understands the @samp{qXfer:spu:write} packet
37317(@pxref{qXfer spu write}).
37318
4aa995e1
PA
37319@item qXfer:siginfo:read
37320The remote stub understands the @samp{qXfer:siginfo:read} packet
37321(@pxref{qXfer siginfo read}).
37322
37323@item qXfer:siginfo:write
37324The remote stub understands the @samp{qXfer:siginfo:write} packet
37325(@pxref{qXfer siginfo write}).
37326
dc146f7c
VP
37327@item qXfer:threads:read
37328The remote stub understands the @samp{qXfer:threads:read} packet
37329(@pxref{qXfer threads read}).
37330
b3b9301e
PA
37331@item qXfer:traceframe-info:read
37332The remote stub understands the @samp{qXfer:traceframe-info:read}
37333packet (@pxref{qXfer traceframe info read}).
37334
169081d0
TG
37335@item qXfer:uib:read
37336The remote stub understands the @samp{qXfer:uib:read}
37337packet (@pxref{qXfer unwind info block}).
37338
78d85199
YQ
37339@item qXfer:fdpic:read
37340The remote stub understands the @samp{qXfer:fdpic:read}
37341packet (@pxref{qXfer fdpic loadmap read}).
37342
8b23ecc4
SL
37343@item QNonStop
37344The remote stub understands the @samp{QNonStop} packet
37345(@pxref{QNonStop}).
37346
23181151
DJ
37347@item QPassSignals
37348The remote stub understands the @samp{QPassSignals} packet
37349(@pxref{QPassSignals}).
37350
a6f3e723
SL
37351@item QStartNoAckMode
37352The remote stub understands the @samp{QStartNoAckMode} packet and
37353prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
37354
b90a069a
SL
37355@item multiprocess
37356@anchor{multiprocess extensions}
37357@cindex multiprocess extensions, in remote protocol
37358The remote stub understands the multiprocess extensions to the remote
37359protocol syntax. The multiprocess extensions affect the syntax of
37360thread IDs in both packets and replies (@pxref{thread-id syntax}), and
37361add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
37362replies. Note that reporting this feature indicates support for the
37363syntactic extensions only, not that the stub necessarily supports
37364debugging of more than one process at a time. The stub must not use
37365multiprocess extensions in packet replies unless @value{GDBN} has also
37366indicated it supports them in its @samp{qSupported} request.
37367
07e059b5
VP
37368@item qXfer:osdata:read
37369The remote stub understands the @samp{qXfer:osdata:read} packet
37370((@pxref{qXfer osdata read}).
37371
83364271
LM
37372@item ConditionalBreakpoints
37373The target accepts and implements evaluation of conditional expressions
37374defined for breakpoints. The target will only report breakpoint triggers
37375when such conditions are true (@pxref{Conditions, ,Break Conditions}).
37376
782b2b07
SS
37377@item ConditionalTracepoints
37378The remote stub accepts and implements conditional expressions defined
37379for tracepoints (@pxref{Tracepoint Conditions}).
37380
0d772ac9
MS
37381@item ReverseContinue
37382The remote stub accepts and implements the reverse continue packet
37383(@pxref{bc}).
37384
37385@item ReverseStep
37386The remote stub accepts and implements the reverse step packet
37387(@pxref{bs}).
37388
409873ef
SS
37389@item TracepointSource
37390The remote stub understands the @samp{QTDPsrc} packet that supplies
37391the source form of tracepoint definitions.
37392
d1feda86
YQ
37393@item QAgent
37394The remote stub understands the @samp{QAgent} packet.
37395
d914c394
SS
37396@item QAllow
37397The remote stub understands the @samp{QAllow} packet.
37398
03583c20
UW
37399@item QDisableRandomization
37400The remote stub understands the @samp{QDisableRandomization} packet.
37401
0fb4aa4b
PA
37402@item StaticTracepoint
37403@cindex static tracepoints, in remote protocol
37404The remote stub supports static tracepoints.
37405
1e4d1764
YQ
37406@item InstallInTrace
37407@anchor{install tracepoint in tracing}
37408The remote stub supports installing tracepoint in tracing.
37409
d248b706
KY
37410@item EnableDisableTracepoints
37411The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
37412@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
37413to be enabled and disabled while a trace experiment is running.
37414
3065dfb6
SS
37415@item tracenz
37416@cindex string tracing, in remote protocol
37417The remote stub supports the @samp{tracenz} bytecode for collecting strings.
37418See @ref{Bytecode Descriptions} for details about the bytecode.
37419
d3ce09f5
SS
37420@item BreakpointCommands
37421@cindex breakpoint commands, in remote protocol
37422The remote stub supports running a breakpoint's command list itself,
37423rather than reporting the hit to @value{GDBN}.
37424
be2a5f71
DJ
37425@end table
37426
b8ff78ce 37427@item qSymbol::
ff2587ec 37428@cindex symbol lookup, remote request
b8ff78ce 37429@cindex @samp{qSymbol} packet
ff2587ec
WZ
37430Notify the target that @value{GDBN} is prepared to serve symbol lookup
37431requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
37432
37433Reply:
ff2587ec 37434@table @samp
b8ff78ce 37435@item OK
ff2587ec 37436The target does not need to look up any (more) symbols.
b8ff78ce 37437@item qSymbol:@var{sym_name}
ff2587ec
WZ
37438The target requests the value of symbol @var{sym_name} (hex encoded).
37439@value{GDBN} may provide the value by using the
b8ff78ce
JB
37440@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
37441below.
ff2587ec 37442@end table
83761cbd 37443
b8ff78ce 37444@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
37445Set the value of @var{sym_name} to @var{sym_value}.
37446
37447@var{sym_name} (hex encoded) is the name of a symbol whose value the
37448target has previously requested.
37449
37450@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
37451@value{GDBN} cannot supply a value for @var{sym_name}, then this field
37452will be empty.
37453
37454Reply:
37455@table @samp
b8ff78ce 37456@item OK
ff2587ec 37457The target does not need to look up any (more) symbols.
b8ff78ce 37458@item qSymbol:@var{sym_name}
ff2587ec
WZ
37459The target requests the value of a new symbol @var{sym_name} (hex
37460encoded). @value{GDBN} will continue to supply the values of symbols
37461(if available), until the target ceases to request them.
fa93a9d8 37462@end table
0abb7bc7 37463
00bf0b85 37464@item qTBuffer
687e43a4
TT
37465@itemx QTBuffer
37466@itemx QTDisconnected
d5551862 37467@itemx QTDP
409873ef 37468@itemx QTDPsrc
d5551862 37469@itemx QTDV
00bf0b85
SS
37470@itemx qTfP
37471@itemx qTfV
9d29849a 37472@itemx QTFrame
405f8e94
SS
37473@itemx qTMinFTPILen
37474
9d29849a
JB
37475@xref{Tracepoint Packets}.
37476
b90a069a 37477@item qThreadExtraInfo,@var{thread-id}
ff2587ec 37478@cindex thread attributes info, remote request
b8ff78ce
JB
37479@cindex @samp{qThreadExtraInfo} packet
37480Obtain a printable string description of a thread's attributes from
b90a069a
SL
37481the target OS. @var{thread-id} is a thread ID;
37482see @ref{thread-id syntax}. This
b8ff78ce
JB
37483string may contain anything that the target OS thinks is interesting
37484for @value{GDBN} to tell the user about the thread. The string is
37485displayed in @value{GDBN}'s @code{info threads} display. Some
37486examples of possible thread extra info strings are @samp{Runnable}, or
37487@samp{Blocked on Mutex}.
ff2587ec
WZ
37488
37489Reply:
37490@table @samp
b8ff78ce
JB
37491@item @var{XX}@dots{}
37492Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
37493comprising the printable string containing the extra information about
37494the thread's attributes.
ff2587ec 37495@end table
814e32d7 37496
aa56d27a
JB
37497(Note that the @code{qThreadExtraInfo} packet's name is separated from
37498the command by a @samp{,}, not a @samp{:}, contrary to the naming
37499conventions above. Please don't use this packet as a model for new
37500packets.)
37501
f196051f 37502@item QTNotes
687e43a4
TT
37503@itemx qTP
37504@itemx QTSave
37505@itemx qTsP
37506@itemx qTsV
d5551862 37507@itemx QTStart
9d29849a 37508@itemx QTStop
d248b706
KY
37509@itemx QTEnable
37510@itemx QTDisable
9d29849a
JB
37511@itemx QTinit
37512@itemx QTro
37513@itemx qTStatus
d5551862 37514@itemx qTV
0fb4aa4b
PA
37515@itemx qTfSTM
37516@itemx qTsSTM
37517@itemx qTSTMat
9d29849a
JB
37518@xref{Tracepoint Packets}.
37519
0876f84a
DJ
37520@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
37521@cindex read special object, remote request
37522@cindex @samp{qXfer} packet
68437a39 37523@anchor{qXfer read}
0876f84a
DJ
37524Read uninterpreted bytes from the target's special data area
37525identified by the keyword @var{object}. Request @var{length} bytes
37526starting at @var{offset} bytes into the data. The content and
0e7f50da 37527encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
37528additional details about what data to access.
37529
37530Here are the specific requests of this form defined so far. All
37531@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
37532formats, listed below.
37533
37534@table @samp
37535@item qXfer:auxv:read::@var{offset},@var{length}
37536@anchor{qXfer auxiliary vector read}
37537Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 37538auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
37539
37540This packet is not probed by default; the remote stub must request it,
89be2091 37541by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 37542
23181151
DJ
37543@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
37544@anchor{qXfer target description read}
37545Access the @dfn{target description}. @xref{Target Descriptions}. The
37546annex specifies which XML document to access. The main description is
37547always loaded from the @samp{target.xml} annex.
37548
37549This packet is not probed by default; the remote stub must request it,
37550by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37551
cfa9d6d9
DJ
37552@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
37553@anchor{qXfer library list read}
37554Access the target's list of loaded libraries. @xref{Library List Format}.
37555The annex part of the generic @samp{qXfer} packet must be empty
37556(@pxref{qXfer read}).
37557
37558Targets which maintain a list of libraries in the program's memory do
37559not need to implement this packet; it is designed for platforms where
37560the operating system manages the list of loaded libraries.
37561
37562This packet is not probed by default; the remote stub must request it,
37563by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37564
2268b414
JK
37565@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
37566@anchor{qXfer svr4 library list read}
37567Access the target's list of loaded libraries when the target is an SVR4
37568platform. @xref{Library List Format for SVR4 Targets}. The annex part
37569of the generic @samp{qXfer} packet must be empty (@pxref{qXfer read}).
37570
37571This packet is optional for better performance on SVR4 targets.
37572@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
37573
37574This packet is not probed by default; the remote stub must request it,
37575by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37576
68437a39
DJ
37577@item qXfer:memory-map:read::@var{offset},@var{length}
37578@anchor{qXfer memory map read}
79a6e687 37579Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
37580annex part of the generic @samp{qXfer} packet must be empty
37581(@pxref{qXfer read}).
37582
0e7f50da
UW
37583This packet is not probed by default; the remote stub must request it,
37584by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37585
0fb4aa4b
PA
37586@item qXfer:sdata:read::@var{offset},@var{length}
37587@anchor{qXfer sdata read}
37588
37589Read contents of the extra collected static tracepoint marker
37590information. The annex part of the generic @samp{qXfer} packet must
37591be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
37592Action Lists}.
37593
37594This packet is not probed by default; the remote stub must request it,
37595by supplying an appropriate @samp{qSupported} response
37596(@pxref{qSupported}).
37597
4aa995e1
PA
37598@item qXfer:siginfo:read::@var{offset},@var{length}
37599@anchor{qXfer siginfo read}
37600Read contents of the extra signal information on the target
37601system. The annex part of the generic @samp{qXfer} packet must be
37602empty (@pxref{qXfer read}).
37603
37604This packet is not probed by default; the remote stub must request it,
37605by supplying an appropriate @samp{qSupported} response
37606(@pxref{qSupported}).
37607
0e7f50da
UW
37608@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
37609@anchor{qXfer spu read}
37610Read contents of an @code{spufs} file on the target system. The
37611annex specifies which file to read; it must be of the form
37612@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37613in the target process, and @var{name} identifes the @code{spufs} file
37614in that context to be accessed.
37615
68437a39 37616This packet is not probed by default; the remote stub must request it,
07e059b5
VP
37617by supplying an appropriate @samp{qSupported} response
37618(@pxref{qSupported}).
37619
dc146f7c
VP
37620@item qXfer:threads:read::@var{offset},@var{length}
37621@anchor{qXfer threads read}
37622Access the list of threads on target. @xref{Thread List Format}. The
37623annex part of the generic @samp{qXfer} packet must be empty
37624(@pxref{qXfer read}).
37625
37626This packet is not probed by default; the remote stub must request it,
37627by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37628
b3b9301e
PA
37629@item qXfer:traceframe-info:read::@var{offset},@var{length}
37630@anchor{qXfer traceframe info read}
37631
37632Return a description of the current traceframe's contents.
37633@xref{Traceframe Info Format}. The annex part of the generic
37634@samp{qXfer} packet must be empty (@pxref{qXfer read}).
37635
37636This packet is not probed by default; the remote stub must request it,
37637by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37638
169081d0
TG
37639@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
37640@anchor{qXfer unwind info block}
37641
37642Return the unwind information block for @var{pc}. This packet is used
37643on OpenVMS/ia64 to ask the kernel unwind information.
37644
37645This packet is not probed by default.
37646
78d85199
YQ
37647@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
37648@anchor{qXfer fdpic loadmap read}
37649Read contents of @code{loadmap}s on the target system. The
37650annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
37651executable @code{loadmap} or interpreter @code{loadmap} to read.
37652
37653This packet is not probed by default; the remote stub must request it,
37654by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37655
07e059b5
VP
37656@item qXfer:osdata:read::@var{offset},@var{length}
37657@anchor{qXfer osdata read}
37658Access the target's @dfn{operating system information}.
37659@xref{Operating System Information}.
37660
68437a39
DJ
37661@end table
37662
0876f84a
DJ
37663Reply:
37664@table @samp
37665@item m @var{data}
37666Data @var{data} (@pxref{Binary Data}) has been read from the
37667target. There may be more data at a higher address (although
37668it is permitted to return @samp{m} even for the last valid
37669block of data, as long as at least one byte of data was read).
37670@var{data} may have fewer bytes than the @var{length} in the
37671request.
37672
37673@item l @var{data}
37674Data @var{data} (@pxref{Binary Data}) has been read from the target.
37675There is no more data to be read. @var{data} may have fewer bytes
37676than the @var{length} in the request.
37677
37678@item l
37679The @var{offset} in the request is at the end of the data.
37680There is no more data to be read.
37681
37682@item E00
37683The request was malformed, or @var{annex} was invalid.
37684
37685@item E @var{nn}
37686The offset was invalid, or there was an error encountered reading the data.
37687@var{nn} is a hex-encoded @code{errno} value.
37688
37689@item
37690An empty reply indicates the @var{object} string was not recognized by
37691the stub, or that the object does not support reading.
37692@end table
37693
37694@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
37695@cindex write data into object, remote request
4aa995e1 37696@anchor{qXfer write}
0876f84a
DJ
37697Write uninterpreted bytes into the target's special data area
37698identified by the keyword @var{object}, starting at @var{offset} bytes
0e7f50da 37699into the data. @var{data}@dots{} is the binary-encoded data
0876f84a 37700(@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
0e7f50da 37701is specific to @var{object}; it can supply additional details about what data
0876f84a
DJ
37702to access.
37703
0e7f50da
UW
37704Here are the specific requests of this form defined so far. All
37705@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
37706formats, listed below.
37707
37708@table @samp
4aa995e1
PA
37709@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
37710@anchor{qXfer siginfo write}
37711Write @var{data} to the extra signal information on the target system.
37712The annex part of the generic @samp{qXfer} packet must be
37713empty (@pxref{qXfer write}).
37714
37715This packet is not probed by default; the remote stub must request it,
37716by supplying an appropriate @samp{qSupported} response
37717(@pxref{qSupported}).
37718
84fcdf95 37719@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
37720@anchor{qXfer spu write}
37721Write @var{data} to an @code{spufs} file on the target system. The
37722annex specifies which file to write; it must be of the form
37723@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37724in the target process, and @var{name} identifes the @code{spufs} file
37725in that context to be accessed.
37726
37727This packet is not probed by default; the remote stub must request it,
37728by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37729@end table
0876f84a
DJ
37730
37731Reply:
37732@table @samp
37733@item @var{nn}
37734@var{nn} (hex encoded) is the number of bytes written.
37735This may be fewer bytes than supplied in the request.
37736
37737@item E00
37738The request was malformed, or @var{annex} was invalid.
37739
37740@item E @var{nn}
37741The offset was invalid, or there was an error encountered writing the data.
37742@var{nn} is a hex-encoded @code{errno} value.
37743
37744@item
37745An empty reply indicates the @var{object} string was not
37746recognized by the stub, or that the object does not support writing.
37747@end table
37748
37749@item qXfer:@var{object}:@var{operation}:@dots{}
37750Requests of this form may be added in the future. When a stub does
37751not recognize the @var{object} keyword, or its support for
37752@var{object} does not recognize the @var{operation} keyword, the stub
37753must respond with an empty packet.
37754
0b16c5cf
PA
37755@item qAttached:@var{pid}
37756@cindex query attached, remote request
37757@cindex @samp{qAttached} packet
37758Return an indication of whether the remote server attached to an
37759existing process or created a new process. When the multiprocess
37760protocol extensions are supported (@pxref{multiprocess extensions}),
37761@var{pid} is an integer in hexadecimal format identifying the target
37762process. Otherwise, @value{GDBN} will omit the @var{pid} field and
37763the query packet will be simplified as @samp{qAttached}.
37764
37765This query is used, for example, to know whether the remote process
37766should be detached or killed when a @value{GDBN} session is ended with
37767the @code{quit} command.
37768
37769Reply:
37770@table @samp
37771@item 1
37772The remote server attached to an existing process.
37773@item 0
37774The remote server created a new process.
37775@item E @var{NN}
37776A badly formed request or an error was encountered.
37777@end table
37778
ee2d5c50
AC
37779@end table
37780
a1dcb23a
DJ
37781@node Architecture-Specific Protocol Details
37782@section Architecture-Specific Protocol Details
37783
37784This section describes how the remote protocol is applied to specific
37785target architectures. Also see @ref{Standard Target Features}, for
37786details of XML target descriptions for each architecture.
37787
02b67415
MR
37788@menu
37789* ARM-Specific Protocol Details::
37790* MIPS-Specific Protocol Details::
37791@end menu
37792
37793@node ARM-Specific Protocol Details
37794@subsection @acronym{ARM}-specific Protocol Details
37795
37796@menu
37797* ARM Breakpoint Kinds::
37798@end menu
a1dcb23a 37799
02b67415
MR
37800@node ARM Breakpoint Kinds
37801@subsubsection @acronym{ARM} Breakpoint Kinds
37802@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
37803
37804These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
37805
37806@table @r
37807
37808@item 2
3780916-bit Thumb mode breakpoint.
37810
37811@item 3
3781232-bit Thumb mode (Thumb-2) breakpoint.
37813
37814@item 4
02b67415 3781532-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
37816
37817@end table
37818
02b67415
MR
37819@node MIPS-Specific Protocol Details
37820@subsection @acronym{MIPS}-specific Protocol Details
37821
37822@menu
37823* MIPS Register packet Format::
4cc0665f 37824* MIPS Breakpoint Kinds::
02b67415 37825@end menu
a1dcb23a 37826
02b67415
MR
37827@node MIPS Register packet Format
37828@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 37829@cindex register packet format, @acronym{MIPS}
eb12ee30 37830
b8ff78ce 37831The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
37832In the below, some thirty-two bit registers are transferred as
37833sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
37834to fill the space allocated. Register bytes are transferred in target
37835byte order. The two nibbles within a register byte are transferred
02b67415 37836most-significant -- least-significant.
eb12ee30 37837
ee2d5c50 37838@table @r
eb12ee30 37839
8e04817f 37840@item MIPS32
599b237a 37841All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
3784232 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
37843registers; fsr; fir; fp.
eb12ee30 37844
8e04817f 37845@item MIPS64
599b237a 37846All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
37847thirty-two bit registers such as @code{sr}). The ordering is the same
37848as @code{MIPS32}.
eb12ee30 37849
ee2d5c50
AC
37850@end table
37851
4cc0665f
MR
37852@node MIPS Breakpoint Kinds
37853@subsubsection @acronym{MIPS} Breakpoint Kinds
37854@cindex breakpoint kinds, @acronym{MIPS}
37855
37856These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
37857
37858@table @r
37859
37860@item 2
3786116-bit @acronym{MIPS16} mode breakpoint.
37862
37863@item 3
3786416-bit @acronym{microMIPS} mode breakpoint.
37865
37866@item 4
3786732-bit standard @acronym{MIPS} mode breakpoint.
37868
37869@item 5
3787032-bit @acronym{microMIPS} mode breakpoint.
37871
37872@end table
37873
9d29849a
JB
37874@node Tracepoint Packets
37875@section Tracepoint Packets
37876@cindex tracepoint packets
37877@cindex packets, tracepoint
37878
37879Here we describe the packets @value{GDBN} uses to implement
37880tracepoints (@pxref{Tracepoints}).
37881
37882@table @samp
37883
7a697b8d 37884@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 37885@cindex @samp{QTDP} packet
9d29849a
JB
37886Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
37887is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
37888the tracepoint is disabled. @var{step} is the tracepoint's step
7a697b8d
SS
37889count, and @var{pass} is its pass count. If an @samp{F} is present,
37890then the tracepoint is to be a fast tracepoint, and the @var{flen} is
37891the number of bytes that the target should copy elsewhere to make room
37892for the tracepoint. If an @samp{X} is present, it introduces a
37893tracepoint condition, which consists of a hexadecimal length, followed
37894by a comma and hex-encoded bytes, in a manner similar to action
37895encodings as described below. If the trailing @samp{-} is present,
37896further @samp{QTDP} packets will follow to specify this tracepoint's
37897actions.
9d29849a
JB
37898
37899Replies:
37900@table @samp
37901@item OK
37902The packet was understood and carried out.
dde08ee1
PA
37903@item qRelocInsn
37904@xref{Tracepoint Packets,,Relocate instruction reply packet}.
9d29849a
JB
37905@item
37906The packet was not recognized.
37907@end table
37908
37909@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
37910Define actions to be taken when a tracepoint is hit. @var{n} and
37911@var{addr} must be the same as in the initial @samp{QTDP} packet for
37912this tracepoint. This packet may only be sent immediately after
37913another @samp{QTDP} packet that ended with a @samp{-}. If the
37914trailing @samp{-} is present, further @samp{QTDP} packets will follow,
37915specifying more actions for this tracepoint.
37916
37917In the series of action packets for a given tracepoint, at most one
37918can have an @samp{S} before its first @var{action}. If such a packet
37919is sent, it and the following packets define ``while-stepping''
37920actions. Any prior packets define ordinary actions --- that is, those
37921taken when the tracepoint is first hit. If no action packet has an
37922@samp{S}, then all the packets in the series specify ordinary
37923tracepoint actions.
37924
37925The @samp{@var{action}@dots{}} portion of the packet is a series of
37926actions, concatenated without separators. Each action has one of the
37927following forms:
37928
37929@table @samp
37930
37931@item R @var{mask}
37932Collect the registers whose bits are set in @var{mask}. @var{mask} is
599b237a 37933a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
37934@var{i} should be collected. (The least significant bit is numbered
37935zero.) Note that @var{mask} may be any number of digits long; it may
37936not fit in a 32-bit word.
37937
37938@item M @var{basereg},@var{offset},@var{len}
37939Collect @var{len} bytes of memory starting at the address in register
37940number @var{basereg}, plus @var{offset}. If @var{basereg} is
37941@samp{-1}, then the range has a fixed address: @var{offset} is the
37942address of the lowest byte to collect. The @var{basereg},
599b237a 37943@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
37944values (the @samp{-1} value for @var{basereg} is a special case).
37945
37946@item X @var{len},@var{expr}
37947Evaluate @var{expr}, whose length is @var{len}, and collect memory as
37948it directs. @var{expr} is an agent expression, as described in
37949@ref{Agent Expressions}. Each byte of the expression is encoded as a
37950two-digit hex number in the packet; @var{len} is the number of bytes
37951in the expression (and thus one-half the number of hex digits in the
37952packet).
37953
37954@end table
37955
37956Any number of actions may be packed together in a single @samp{QTDP}
37957packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
37958length (400 bytes, for many stubs). There may be only one @samp{R}
37959action per tracepoint, and it must precede any @samp{M} or @samp{X}
37960actions. Any registers referred to by @samp{M} and @samp{X} actions
37961must be collected by a preceding @samp{R} action. (The
37962``while-stepping'' actions are treated as if they were attached to a
37963separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
37964
37965Replies:
37966@table @samp
37967@item OK
37968The packet was understood and carried out.
dde08ee1
PA
37969@item qRelocInsn
37970@xref{Tracepoint Packets,,Relocate instruction reply packet}.
9d29849a
JB
37971@item
37972The packet was not recognized.
37973@end table
37974
409873ef
SS
37975@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
37976@cindex @samp{QTDPsrc} packet
37977Specify a source string of tracepoint @var{n} at address @var{addr}.
37978This is useful to get accurate reproduction of the tracepoints
37979originally downloaded at the beginning of the trace run. @var{type}
37980is the name of the tracepoint part, such as @samp{cond} for the
37981tracepoint's conditional expression (see below for a list of types), while
37982@var{bytes} is the string, encoded in hexadecimal.
37983
37984@var{start} is the offset of the @var{bytes} within the overall source
37985string, while @var{slen} is the total length of the source string.
37986This is intended for handling source strings that are longer than will
37987fit in a single packet.
37988@c Add detailed example when this info is moved into a dedicated
37989@c tracepoint descriptions section.
37990
37991The available string types are @samp{at} for the location,
37992@samp{cond} for the conditional, and @samp{cmd} for an action command.
37993@value{GDBN} sends a separate packet for each command in the action
37994list, in the same order in which the commands are stored in the list.
37995
37996The target does not need to do anything with source strings except
37997report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
37998query packets.
37999
38000Although this packet is optional, and @value{GDBN} will only send it
38001if the target replies with @samp{TracepointSource} @xref{General
38002Query Packets}, it makes both disconnected tracing and trace files
38003much easier to use. Otherwise the user must be careful that the
38004tracepoints in effect while looking at trace frames are identical to
38005the ones in effect during the trace run; even a small discrepancy
38006could cause @samp{tdump} not to work, or a particular trace frame not
38007be found.
38008
f61e138d
SS
38009@item QTDV:@var{n}:@var{value}
38010@cindex define trace state variable, remote request
38011@cindex @samp{QTDV} packet
38012Create a new trace state variable, number @var{n}, with an initial
38013value of @var{value}, which is a 64-bit signed integer. Both @var{n}
38014and @var{value} are encoded as hexadecimal values. @value{GDBN} has
38015the option of not using this packet for initial values of zero; the
38016target should simply create the trace state variables as they are
38017mentioned in expressions.
38018
9d29849a 38019@item QTFrame:@var{n}
c614397c 38020@cindex @samp{QTFrame} packet
9d29849a
JB
38021Select the @var{n}'th tracepoint frame from the buffer, and use the
38022register and memory contents recorded there to answer subsequent
38023request packets from @value{GDBN}.
38024
38025A successful reply from the stub indicates that the stub has found the
38026requested frame. The response is a series of parts, concatenated
38027without separators, describing the frame we selected. Each part has
38028one of the following forms:
38029
38030@table @samp
38031@item F @var{f}
38032The selected frame is number @var{n} in the trace frame buffer;
599b237a 38033@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
38034was no frame matching the criteria in the request packet.
38035
38036@item T @var{t}
38037The selected trace frame records a hit of tracepoint number @var{t};
599b237a 38038@var{t} is a hexadecimal number.
9d29849a
JB
38039
38040@end table
38041
38042@item QTFrame:pc:@var{addr}
38043Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38044currently selected frame whose PC is @var{addr};
599b237a 38045@var{addr} is a hexadecimal number.
9d29849a
JB
38046
38047@item QTFrame:tdp:@var{t}
38048Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38049currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 38050is a hexadecimal number.
9d29849a
JB
38051
38052@item QTFrame:range:@var{start}:@var{end}
38053Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
38054currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 38055and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
38056numbers.
38057
38058@item QTFrame:outside:@var{start}:@var{end}
38059Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 38060frame @emph{outside} the given range of addresses (exclusive).
9d29849a 38061
405f8e94 38062@item qTMinFTPILen
c614397c 38063@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
38064This packet requests the minimum length of instruction at which a fast
38065tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
38066the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
38067it depends on the target system being able to create trampolines in
38068the first 64K of memory, which might or might not be possible for that
38069system. So the reply to this packet will be 4 if it is able to
38070arrange for that.
38071
38072Replies:
38073
38074@table @samp
38075@item 0
38076The minimum instruction length is currently unknown.
38077@item @var{length}
38078The minimum instruction length is @var{length}, where @var{length} is greater
38079or equal to 1. @var{length} is a hexadecimal number. A reply of 1 means
38080that a fast tracepoint may be placed on any instruction regardless of size.
38081@item E
38082An error has occurred.
38083@item
38084An empty reply indicates that the request is not supported by the stub.
38085@end table
38086
9d29849a 38087@item QTStart
c614397c 38088@cindex @samp{QTStart} packet
dde08ee1
PA
38089Begin the tracepoint experiment. Begin collecting data from
38090tracepoint hits in the trace frame buffer. This packet supports the
38091@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
38092instruction reply packet}).
9d29849a
JB
38093
38094@item QTStop
c614397c 38095@cindex @samp{QTStop} packet
9d29849a
JB
38096End the tracepoint experiment. Stop collecting trace frames.
38097
d248b706
KY
38098@item QTEnable:@var{n}:@var{addr}
38099@anchor{QTEnable}
c614397c 38100@cindex @samp{QTEnable} packet
d248b706
KY
38101Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
38102experiment. If the tracepoint was previously disabled, then collection
38103of data from it will resume.
38104
38105@item QTDisable:@var{n}:@var{addr}
38106@anchor{QTDisable}
c614397c 38107@cindex @samp{QTDisable} packet
d248b706
KY
38108Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
38109experiment. No more data will be collected from the tracepoint unless
38110@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
38111
9d29849a 38112@item QTinit
c614397c 38113@cindex @samp{QTinit} packet
9d29849a
JB
38114Clear the table of tracepoints, and empty the trace frame buffer.
38115
38116@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 38117@cindex @samp{QTro} packet
9d29849a
JB
38118Establish the given ranges of memory as ``transparent''. The stub
38119will answer requests for these ranges from memory's current contents,
38120if they were not collected as part of the tracepoint hit.
38121
38122@value{GDBN} uses this to mark read-only regions of memory, like those
38123containing program code. Since these areas never change, they should
38124still have the same contents they did when the tracepoint was hit, so
38125there's no reason for the stub to refuse to provide their contents.
38126
d5551862 38127@item QTDisconnected:@var{value}
c614397c 38128@cindex @samp{QTDisconnected} packet
d5551862
SS
38129Set the choice to what to do with the tracing run when @value{GDBN}
38130disconnects from the target. A @var{value} of 1 directs the target to
38131continue the tracing run, while 0 tells the target to stop tracing if
38132@value{GDBN} is no longer in the picture.
38133
9d29849a 38134@item qTStatus
c614397c 38135@cindex @samp{qTStatus} packet
9d29849a
JB
38136Ask the stub if there is a trace experiment running right now.
38137
4daf5ac0
SS
38138The reply has the form:
38139
38140@table @samp
38141
38142@item T@var{running}@r{[};@var{field}@r{]}@dots{}
38143@var{running} is a single digit @code{1} if the trace is presently
38144running, or @code{0} if not. It is followed by semicolon-separated
38145optional fields that an agent may use to report additional status.
38146
38147@end table
38148
38149If the trace is not running, the agent may report any of several
38150explanations as one of the optional fields:
38151
38152@table @samp
38153
38154@item tnotrun:0
38155No trace has been run yet.
38156
f196051f
SS
38157@item tstop[:@var{text}]:0
38158The trace was stopped by a user-originated stop command. The optional
38159@var{text} field is a user-supplied string supplied as part of the
38160stop command (for instance, an explanation of why the trace was
38161stopped manually). It is hex-encoded.
4daf5ac0
SS
38162
38163@item tfull:0
38164The trace stopped because the trace buffer filled up.
38165
38166@item tdisconnected:0
38167The trace stopped because @value{GDBN} disconnected from the target.
38168
38169@item tpasscount:@var{tpnum}
38170The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
38171
6c28cbf2
SS
38172@item terror:@var{text}:@var{tpnum}
38173The trace stopped because tracepoint @var{tpnum} had an error. The
38174string @var{text} is available to describe the nature of the error
38175(for instance, a divide by zero in the condition expression).
99b5e152 38176@var{text} is hex encoded.
6c28cbf2 38177
4daf5ac0
SS
38178@item tunknown:0
38179The trace stopped for some other reason.
38180
38181@end table
38182
33da3f1c
SS
38183Additional optional fields supply statistical and other information.
38184Although not required, they are extremely useful for users monitoring
38185the progress of a trace run. If a trace has stopped, and these
38186numbers are reported, they must reflect the state of the just-stopped
38187trace.
4daf5ac0 38188
9d29849a 38189@table @samp
4daf5ac0
SS
38190
38191@item tframes:@var{n}
38192The number of trace frames in the buffer.
38193
38194@item tcreated:@var{n}
38195The total number of trace frames created during the run. This may
38196be larger than the trace frame count, if the buffer is circular.
38197
38198@item tsize:@var{n}
38199The total size of the trace buffer, in bytes.
38200
38201@item tfree:@var{n}
38202The number of bytes still unused in the buffer.
38203
33da3f1c
SS
38204@item circular:@var{n}
38205The value of the circular trace buffer flag. @code{1} means that the
38206trace buffer is circular and old trace frames will be discarded if
38207necessary to make room, @code{0} means that the trace buffer is linear
38208and may fill up.
38209
38210@item disconn:@var{n}
38211The value of the disconnected tracing flag. @code{1} means that
38212tracing will continue after @value{GDBN} disconnects, @code{0} means
38213that the trace run will stop.
38214
9d29849a
JB
38215@end table
38216
f196051f
SS
38217@item qTP:@var{tp}:@var{addr}
38218@cindex tracepoint status, remote request
38219@cindex @samp{qTP} packet
38220Ask the stub for the current state of tracepoint number @var{tp} at
38221address @var{addr}.
38222
38223Replies:
38224@table @samp
38225@item V@var{hits}:@var{usage}
38226The tracepoint has been hit @var{hits} times so far during the trace
38227run, and accounts for @var{usage} in the trace buffer. Note that
38228@code{while-stepping} steps are not counted as separate hits, but the
38229steps' space consumption is added into the usage number.
38230
38231@end table
38232
f61e138d
SS
38233@item qTV:@var{var}
38234@cindex trace state variable value, remote request
38235@cindex @samp{qTV} packet
38236Ask the stub for the value of the trace state variable number @var{var}.
38237
38238Replies:
38239@table @samp
38240@item V@var{value}
38241The value of the variable is @var{value}. This will be the current
38242value of the variable if the user is examining a running target, or a
38243saved value if the variable was collected in the trace frame that the
38244user is looking at. Note that multiple requests may result in
38245different reply values, such as when requesting values while the
38246program is running.
38247
38248@item U
38249The value of the variable is unknown. This would occur, for example,
38250if the user is examining a trace frame in which the requested variable
38251was not collected.
9d29849a
JB
38252@end table
38253
d5551862 38254@item qTfP
c614397c 38255@cindex @samp{qTfP} packet
d5551862 38256@itemx qTsP
c614397c 38257@cindex @samp{qTsP} packet
d5551862
SS
38258These packets request data about tracepoints that are being used by
38259the target. @value{GDBN} sends @code{qTfP} to get the first piece
38260of data, and multiple @code{qTsP} to get additional pieces. Replies
38261to these packets generally take the form of the @code{QTDP} packets
38262that define tracepoints. (FIXME add detailed syntax)
38263
00bf0b85 38264@item qTfV
c614397c 38265@cindex @samp{qTfV} packet
00bf0b85 38266@itemx qTsV
c614397c 38267@cindex @samp{qTsV} packet
00bf0b85
SS
38268These packets request data about trace state variables that are on the
38269target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
38270and multiple @code{qTsV} to get additional variables. Replies to
38271these packets follow the syntax of the @code{QTDV} packets that define
38272trace state variables.
38273
0fb4aa4b
PA
38274@item qTfSTM
38275@itemx qTsSTM
16bdd41f
YQ
38276@anchor{qTfSTM}
38277@anchor{qTsSTM}
c614397c
YQ
38278@cindex @samp{qTfSTM} packet
38279@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
38280These packets request data about static tracepoint markers that exist
38281in the target program. @value{GDBN} sends @code{qTfSTM} to get the
38282first piece of data, and multiple @code{qTsSTM} to get additional
38283pieces. Replies to these packets take the following form:
38284
38285Reply:
38286@table @samp
38287@item m @var{address}:@var{id}:@var{extra}
38288A single marker
38289@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
38290a comma-separated list of markers
38291@item l
38292(lower case letter @samp{L}) denotes end of list.
38293@item E @var{nn}
38294An error occurred. @var{nn} are hex digits.
38295@item
38296An empty reply indicates that the request is not supported by the
38297stub.
38298@end table
38299
38300@var{address} is encoded in hex.
38301@var{id} and @var{extra} are strings encoded in hex.
38302
38303In response to each query, the target will reply with a list of one or
38304more markers, separated by commas. @value{GDBN} will respond to each
38305reply with a request for more markers (using the @samp{qs} form of the
38306query), until the target responds with @samp{l} (lower-case ell, for
38307@dfn{last}).
38308
38309@item qTSTMat:@var{address}
16bdd41f 38310@anchor{qTSTMat}
c614397c 38311@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
38312This packets requests data about static tracepoint markers in the
38313target program at @var{address}. Replies to this packet follow the
38314syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
38315tracepoint markers.
38316
00bf0b85 38317@item QTSave:@var{filename}
c614397c 38318@cindex @samp{QTSave} packet
00bf0b85
SS
38319This packet directs the target to save trace data to the file name
38320@var{filename} in the target's filesystem. @var{filename} is encoded
38321as a hex string; the interpretation of the file name (relative vs
38322absolute, wild cards, etc) is up to the target.
38323
38324@item qTBuffer:@var{offset},@var{len}
c614397c 38325@cindex @samp{qTBuffer} packet
00bf0b85
SS
38326Return up to @var{len} bytes of the current contents of trace buffer,
38327starting at @var{offset}. The trace buffer is treated as if it were
38328a contiguous collection of traceframes, as per the trace file format.
38329The reply consists as many hex-encoded bytes as the target can deliver
38330in a packet; it is not an error to return fewer than were asked for.
38331A reply consisting of just @code{l} indicates that no bytes are
38332available.
38333
4daf5ac0
SS
38334@item QTBuffer:circular:@var{value}
38335This packet directs the target to use a circular trace buffer if
38336@var{value} is 1, or a linear buffer if the value is 0.
38337
f196051f 38338@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 38339@cindex @samp{QTNotes} packet
f196051f
SS
38340This packet adds optional textual notes to the trace run. Allowable
38341types include @code{user}, @code{notes}, and @code{tstop}, the
38342@var{text} fields are arbitrary strings, hex-encoded.
38343
f61e138d 38344@end table
9d29849a 38345
dde08ee1
PA
38346@subsection Relocate instruction reply packet
38347When installing fast tracepoints in memory, the target may need to
38348relocate the instruction currently at the tracepoint address to a
38349different address in memory. For most instructions, a simple copy is
38350enough, but, for example, call instructions that implicitly push the
38351return address on the stack, and relative branches or other
38352PC-relative instructions require offset adjustment, so that the effect
38353of executing the instruction at a different address is the same as if
38354it had executed in the original location.
38355
38356In response to several of the tracepoint packets, the target may also
38357respond with a number of intermediate @samp{qRelocInsn} request
38358packets before the final result packet, to have @value{GDBN} handle
38359this relocation operation. If a packet supports this mechanism, its
38360documentation will explicitly say so. See for example the above
38361descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
38362format of the request is:
38363
38364@table @samp
38365@item qRelocInsn:@var{from};@var{to}
38366
38367This requests @value{GDBN} to copy instruction at address @var{from}
38368to address @var{to}, possibly adjusted so that executing the
38369instruction at @var{to} has the same effect as executing it at
38370@var{from}. @value{GDBN} writes the adjusted instruction to target
38371memory starting at @var{to}.
38372@end table
38373
38374Replies:
38375@table @samp
38376@item qRelocInsn:@var{adjusted_size}
38377Informs the stub the relocation is complete. @var{adjusted_size} is
38378the length in bytes of resulting relocated instruction sequence.
38379@item E @var{NN}
38380A badly formed request was detected, or an error was encountered while
38381relocating the instruction.
38382@end table
38383
a6b151f1
DJ
38384@node Host I/O Packets
38385@section Host I/O Packets
38386@cindex Host I/O, remote protocol
38387@cindex file transfer, remote protocol
38388
38389The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
38390operations on the far side of a remote link. For example, Host I/O is
38391used to upload and download files to a remote target with its own
38392filesystem. Host I/O uses the same constant values and data structure
38393layout as the target-initiated File-I/O protocol. However, the
38394Host I/O packets are structured differently. The target-initiated
38395protocol relies on target memory to store parameters and buffers.
38396Host I/O requests are initiated by @value{GDBN}, and the
38397target's memory is not involved. @xref{File-I/O Remote Protocol
38398Extension}, for more details on the target-initiated protocol.
38399
38400The Host I/O request packets all encode a single operation along with
38401its arguments. They have this format:
38402
38403@table @samp
38404
38405@item vFile:@var{operation}: @var{parameter}@dots{}
38406@var{operation} is the name of the particular request; the target
38407should compare the entire packet name up to the second colon when checking
38408for a supported operation. The format of @var{parameter} depends on
38409the operation. Numbers are always passed in hexadecimal. Negative
38410numbers have an explicit minus sign (i.e.@: two's complement is not
38411used). Strings (e.g.@: filenames) are encoded as a series of
38412hexadecimal bytes. The last argument to a system call may be a
38413buffer of escaped binary data (@pxref{Binary Data}).
38414
38415@end table
38416
38417The valid responses to Host I/O packets are:
38418
38419@table @samp
38420
38421@item F @var{result} [, @var{errno}] [; @var{attachment}]
38422@var{result} is the integer value returned by this operation, usually
38423non-negative for success and -1 for errors. If an error has occured,
38424@var{errno} will be included in the result. @var{errno} will have a
38425value defined by the File-I/O protocol (@pxref{Errno Values}). For
38426operations which return data, @var{attachment} supplies the data as a
38427binary buffer. Binary buffers in response packets are escaped in the
38428normal way (@pxref{Binary Data}). See the individual packet
38429documentation for the interpretation of @var{result} and
38430@var{attachment}.
38431
38432@item
38433An empty response indicates that this operation is not recognized.
38434
38435@end table
38436
38437These are the supported Host I/O operations:
38438
38439@table @samp
38440@item vFile:open: @var{pathname}, @var{flags}, @var{mode}
38441Open a file at @var{pathname} and return a file descriptor for it, or
38442return -1 if an error occurs. @var{pathname} is a string,
38443@var{flags} is an integer indicating a mask of open flags
38444(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
38445of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 38446@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
38447
38448@item vFile:close: @var{fd}
38449Close the open file corresponding to @var{fd} and return 0, or
38450-1 if an error occurs.
38451
38452@item vFile:pread: @var{fd}, @var{count}, @var{offset}
38453Read data from the open file corresponding to @var{fd}. Up to
38454@var{count} bytes will be read from the file, starting at @var{offset}
38455relative to the start of the file. The target may read fewer bytes;
38456common reasons include packet size limits and an end-of-file
38457condition. The number of bytes read is returned. Zero should only be
38458returned for a successful read at the end of the file, or if
38459@var{count} was zero.
38460
38461The data read should be returned as a binary attachment on success.
38462If zero bytes were read, the response should include an empty binary
38463attachment (i.e.@: a trailing semicolon). The return value is the
38464number of target bytes read; the binary attachment may be longer if
38465some characters were escaped.
38466
38467@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
38468Write @var{data} (a binary buffer) to the open file corresponding
38469to @var{fd}. Start the write at @var{offset} from the start of the
38470file. Unlike many @code{write} system calls, there is no
38471separate @var{count} argument; the length of @var{data} in the
38472packet is used. @samp{vFile:write} returns the number of bytes written,
38473which may be shorter than the length of @var{data}, or -1 if an
38474error occurred.
38475
38476@item vFile:unlink: @var{pathname}
38477Delete the file at @var{pathname} on the target. Return 0,
38478or -1 if an error occurs. @var{pathname} is a string.
38479
b9e7b9c3
UW
38480@item vFile:readlink: @var{filename}
38481Read value of symbolic link @var{filename} on the target. Return
38482the number of bytes read, or -1 if an error occurs.
38483
38484The data read should be returned as a binary attachment on success.
38485If zero bytes were read, the response should include an empty binary
38486attachment (i.e.@: a trailing semicolon). The return value is the
38487number of target bytes read; the binary attachment may be longer if
38488some characters were escaped.
38489
a6b151f1
DJ
38490@end table
38491
9a6253be
KB
38492@node Interrupts
38493@section Interrupts
38494@cindex interrupts (remote protocol)
38495
38496When a program on the remote target is running, @value{GDBN} may
9a7071a8
JB
38497attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
38498a @code{BREAK} followed by @code{g},
38499control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
38500
38501The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
38502mechanism and may, in fact, be undefined. @value{GDBN} does not
38503currently define a @code{BREAK} mechanism for any of the network
38504interfaces except for TCP, in which case @value{GDBN} sends the
38505@code{telnet} BREAK sequence.
9a6253be
KB
38506
38507@samp{Ctrl-C}, on the other hand, is defined and implemented for all
38508transport mechanisms. It is represented by sending the single byte
38509@code{0x03} without any of the usual packet overhead described in
38510the Overview section (@pxref{Overview}). When a @code{0x03} byte is
38511transmitted as part of a packet, it is considered to be packet data
38512and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 38513(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
38514@code{0x03} as part of its packet.
38515
9a7071a8
JB
38516@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
38517When Linux kernel receives this sequence from serial port,
38518it stops execution and connects to gdb.
38519
9a6253be
KB
38520Stubs are not required to recognize these interrupt mechanisms and the
38521precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
38522implementation defined. If the target supports debugging of multiple
38523threads and/or processes, it should attempt to interrupt all
38524currently-executing threads and processes.
38525If the stub is successful at interrupting the
38526running program, it should send one of the stop
38527reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
38528of successfully stopping the program in all-stop mode, and a stop reply
38529for each stopped thread in non-stop mode.
38530Interrupts received while the
38531program is stopped are discarded.
38532
38533@node Notification Packets
38534@section Notification Packets
38535@cindex notification packets
38536@cindex packets, notification
38537
38538The @value{GDBN} remote serial protocol includes @dfn{notifications},
38539packets that require no acknowledgment. Both the GDB and the stub
38540may send notifications (although the only notifications defined at
38541present are sent by the stub). Notifications carry information
38542without incurring the round-trip latency of an acknowledgment, and so
38543are useful for low-impact communications where occasional packet loss
38544is not a problem.
38545
38546A notification packet has the form @samp{% @var{data} #
38547@var{checksum}}, where @var{data} is the content of the notification,
38548and @var{checksum} is a checksum of @var{data}, computed and formatted
38549as for ordinary @value{GDBN} packets. A notification's @var{data}
38550never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
38551receiving a notification, the recipient sends no @samp{+} or @samp{-}
38552to acknowledge the notification's receipt or to report its corruption.
38553
38554Every notification's @var{data} begins with a name, which contains no
38555colon characters, followed by a colon character.
38556
38557Recipients should silently ignore corrupted notifications and
38558notifications they do not understand. Recipients should restart
38559timeout periods on receipt of a well-formed notification, whether or
38560not they understand it.
38561
38562Senders should only send the notifications described here when this
38563protocol description specifies that they are permitted. In the
38564future, we may extend the protocol to permit existing notifications in
38565new contexts; this rule helps older senders avoid confusing newer
38566recipients.
38567
38568(Older versions of @value{GDBN} ignore bytes received until they see
38569the @samp{$} byte that begins an ordinary packet, so new stubs may
38570transmit notifications without fear of confusing older clients. There
38571are no notifications defined for @value{GDBN} to send at the moment, but we
38572assume that most older stubs would ignore them, as well.)
38573
8dbe8ece 38574Each notification is comprised of three parts:
8b23ecc4 38575@table @samp
8dbe8ece
YQ
38576@item @var{name}:@var{event}
38577The notification packet is sent by the side that initiates the
38578exchange (currently, only the stub does that), with @var{event}
38579carrying the specific information about the notification.
38580@var{name} is the name of the notification.
38581@item @var{ack}
38582The acknowledge sent by the other side, usually @value{GDBN}, to
38583acknowledge the exchange and request the event.
38584@end table
38585
38586The purpose of an asynchronous notification mechanism is to report to
38587@value{GDBN} that something interesting happened in the remote stub.
38588
38589The remote stub may send notification @var{name}:@var{event}
38590at any time, but @value{GDBN} acknowledges the notification when
38591appropriate. The notification event is pending before @value{GDBN}
38592acknowledges. Only one notification at a time may be pending; if
38593additional events occur before @value{GDBN} has acknowledged the
38594previous notification, they must be queued by the stub for later
38595synchronous transmission in response to @var{ack} packets from
38596@value{GDBN}. Because the notification mechanism is unreliable,
38597the stub is permitted to resend a notification if it believes
38598@value{GDBN} may not have received it.
38599
38600Specifically, notifications may appear when @value{GDBN} is not
38601otherwise reading input from the stub, or when @value{GDBN} is
38602expecting to read a normal synchronous response or a
38603@samp{+}/@samp{-} acknowledgment to a packet it has sent.
38604Notification packets are distinct from any other communication from
38605the stub so there is no ambiguity.
38606
38607After receiving a notification, @value{GDBN} shall acknowledge it by
38608sending a @var{ack} packet as a regular, synchronous request to the
38609stub. Such acknowledgment is not required to happen immediately, as
38610@value{GDBN} is permitted to send other, unrelated packets to the
38611stub first, which the stub should process normally.
38612
38613Upon receiving a @var{ack} packet, if the stub has other queued
38614events to report to @value{GDBN}, it shall respond by sending a
38615normal @var{event}. @value{GDBN} shall then send another @var{ack}
38616packet to solicit further responses; again, it is permitted to send
38617other, unrelated packets as well which the stub should process
38618normally.
38619
38620If the stub receives a @var{ack} packet and there are no additional
38621@var{event} to report, the stub shall return an @samp{OK} response.
38622At this point, @value{GDBN} has finished processing a notification
38623and the stub has completed sending any queued events. @value{GDBN}
38624won't accept any new notifications until the final @samp{OK} is
38625received . If further notification events occur, the stub shall send
38626a new notification, @value{GDBN} shall accept the notification, and
38627the process shall be repeated.
38628
38629The process of asynchronous notification can be illustrated by the
38630following example:
38631@smallexample
38632<- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
38633@code{...}
38634-> @code{vStopped}
38635<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
38636-> @code{vStopped}
38637<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
38638-> @code{vStopped}
38639<- @code{OK}
38640@end smallexample
38641
38642The following notifications are defined:
38643@multitable @columnfractions 0.12 0.12 0.38 0.38
38644
38645@item Notification
38646@tab Ack
38647@tab Event
38648@tab Description
38649
38650@item Stop
38651@tab vStopped
38652@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
38653described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
38654for information on how these notifications are acknowledged by
38655@value{GDBN}.
8dbe8ece
YQ
38656@tab Report an asynchronous stop event in non-stop mode.
38657
38658@end multitable
8b23ecc4
SL
38659
38660@node Remote Non-Stop
38661@section Remote Protocol Support for Non-Stop Mode
38662
38663@value{GDBN}'s remote protocol supports non-stop debugging of
38664multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
38665supports non-stop mode, it should report that to @value{GDBN} by including
38666@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
38667
38668@value{GDBN} typically sends a @samp{QNonStop} packet only when
38669establishing a new connection with the stub. Entering non-stop mode
38670does not alter the state of any currently-running threads, but targets
38671must stop all threads in any already-attached processes when entering
38672all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
38673probe the target state after a mode change.
38674
38675In non-stop mode, when an attached process encounters an event that
38676would otherwise be reported with a stop reply, it uses the
38677asynchronous notification mechanism (@pxref{Notification Packets}) to
38678inform @value{GDBN}. In contrast to all-stop mode, where all threads
38679in all processes are stopped when a stop reply is sent, in non-stop
38680mode only the thread reporting the stop event is stopped. That is,
38681when reporting a @samp{S} or @samp{T} response to indicate completion
38682of a step operation, hitting a breakpoint, or a fault, only the
38683affected thread is stopped; any other still-running threads continue
38684to run. When reporting a @samp{W} or @samp{X} response, all running
38685threads belonging to other attached processes continue to run.
38686
8b23ecc4
SL
38687In non-stop mode, the target shall respond to the @samp{?} packet as
38688follows. First, any incomplete stop reply notification/@samp{vStopped}
38689sequence in progress is abandoned. The target must begin a new
38690sequence reporting stop events for all stopped threads, whether or not
38691it has previously reported those events to @value{GDBN}. The first
38692stop reply is sent as a synchronous reply to the @samp{?} packet, and
38693subsequent stop replies are sent as responses to @samp{vStopped} packets
38694using the mechanism described above. The target must not send
38695asynchronous stop reply notifications until the sequence is complete.
38696If all threads are running when the target receives the @samp{?} packet,
38697or if the target is not attached to any process, it shall respond
38698@samp{OK}.
9a6253be 38699
a6f3e723
SL
38700@node Packet Acknowledgment
38701@section Packet Acknowledgment
38702
38703@cindex acknowledgment, for @value{GDBN} remote
38704@cindex packet acknowledgment, for @value{GDBN} remote
38705By default, when either the host or the target machine receives a packet,
38706the first response expected is an acknowledgment: either @samp{+} (to indicate
38707the package was received correctly) or @samp{-} (to request retransmission).
38708This mechanism allows the @value{GDBN} remote protocol to operate over
38709unreliable transport mechanisms, such as a serial line.
38710
38711In cases where the transport mechanism is itself reliable (such as a pipe or
38712TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
38713It may be desirable to disable them in that case to reduce communication
38714overhead, or for other reasons. This can be accomplished by means of the
38715@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
38716
38717When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
38718expect @samp{+}/@samp{-} protocol acknowledgments. The packet
38719and response format still includes the normal checksum, as described in
38720@ref{Overview}, but the checksum may be ignored by the receiver.
38721
38722If the stub supports @samp{QStartNoAckMode} and prefers to operate in
38723no-acknowledgment mode, it should report that to @value{GDBN}
38724by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
38725@pxref{qSupported}.
38726If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
38727disabled via the @code{set remote noack-packet off} command
38728(@pxref{Remote Configuration}),
38729@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
38730Only then may the stub actually turn off packet acknowledgments.
38731@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
38732response, which can be safely ignored by the stub.
38733
38734Note that @code{set remote noack-packet} command only affects negotiation
38735between @value{GDBN} and the stub when subsequent connections are made;
38736it does not affect the protocol acknowledgment state for any current
38737connection.
38738Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
38739new connection is established,
38740there is also no protocol request to re-enable the acknowledgments
38741for the current connection, once disabled.
38742
ee2d5c50
AC
38743@node Examples
38744@section Examples
eb12ee30 38745
8e04817f
AC
38746Example sequence of a target being re-started. Notice how the restart
38747does not get any direct output:
eb12ee30 38748
474c8240 38749@smallexample
d2c6833e
AC
38750-> @code{R00}
38751<- @code{+}
8e04817f 38752@emph{target restarts}
d2c6833e 38753-> @code{?}
8e04817f 38754<- @code{+}
d2c6833e
AC
38755<- @code{T001:1234123412341234}
38756-> @code{+}
474c8240 38757@end smallexample
eb12ee30 38758
8e04817f 38759Example sequence of a target being stepped by a single instruction:
eb12ee30 38760
474c8240 38761@smallexample
d2c6833e 38762-> @code{G1445@dots{}}
8e04817f 38763<- @code{+}
d2c6833e
AC
38764-> @code{s}
38765<- @code{+}
38766@emph{time passes}
38767<- @code{T001:1234123412341234}
8e04817f 38768-> @code{+}
d2c6833e 38769-> @code{g}
8e04817f 38770<- @code{+}
d2c6833e
AC
38771<- @code{1455@dots{}}
38772-> @code{+}
474c8240 38773@end smallexample
eb12ee30 38774
79a6e687
BW
38775@node File-I/O Remote Protocol Extension
38776@section File-I/O Remote Protocol Extension
0ce1b118
CV
38777@cindex File-I/O remote protocol extension
38778
38779@menu
38780* File-I/O Overview::
79a6e687
BW
38781* Protocol Basics::
38782* The F Request Packet::
38783* The F Reply Packet::
38784* The Ctrl-C Message::
0ce1b118 38785* Console I/O::
79a6e687 38786* List of Supported Calls::
db2e3e2e 38787* Protocol-specific Representation of Datatypes::
0ce1b118
CV
38788* Constants::
38789* File-I/O Examples::
38790@end menu
38791
38792@node File-I/O Overview
38793@subsection File-I/O Overview
38794@cindex file-i/o overview
38795
9c16f35a 38796The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 38797target to use the host's file system and console I/O to perform various
0ce1b118 38798system calls. System calls on the target system are translated into a
fc320d37
SL
38799remote protocol packet to the host system, which then performs the needed
38800actions and returns a response packet to the target system.
0ce1b118
CV
38801This simulates file system operations even on targets that lack file systems.
38802
fc320d37
SL
38803The protocol is defined to be independent of both the host and target systems.
38804It uses its own internal representation of datatypes and values. Both
0ce1b118 38805@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
38806translating the system-dependent value representations into the internal
38807protocol representations when data is transmitted.
0ce1b118 38808
fc320d37
SL
38809The communication is synchronous. A system call is possible only when
38810@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
38811or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 38812the target is stopped to allow deterministic access to the target's
fc320d37
SL
38813memory. Therefore File-I/O is not interruptible by target signals. On
38814the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 38815(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
38816
38817The target's request to perform a host system call does not finish
38818the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
38819after finishing the system call, the target returns to continuing the
38820previous activity (continue, step). No additional continue or step
38821request from @value{GDBN} is required.
38822
38823@smallexample
f7dc1244 38824(@value{GDBP}) continue
0ce1b118
CV
38825 <- target requests 'system call X'
38826 target is stopped, @value{GDBN} executes system call
3f94c067
BW
38827 -> @value{GDBN} returns result
38828 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
38829 <- target hits breakpoint and sends a Txx packet
38830@end smallexample
38831
fc320d37
SL
38832The protocol only supports I/O on the console and to regular files on
38833the host file system. Character or block special devices, pipes,
38834named pipes, sockets or any other communication method on the host
0ce1b118
CV
38835system are not supported by this protocol.
38836
8b23ecc4
SL
38837File I/O is not supported in non-stop mode.
38838
79a6e687
BW
38839@node Protocol Basics
38840@subsection Protocol Basics
0ce1b118
CV
38841@cindex protocol basics, file-i/o
38842
fc320d37
SL
38843The File-I/O protocol uses the @code{F} packet as the request as well
38844as reply packet. Since a File-I/O system call can only occur when
38845@value{GDBN} is waiting for a response from the continuing or stepping target,
38846the File-I/O request is a reply that @value{GDBN} has to expect as a result
38847of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
38848This @code{F} packet contains all information needed to allow @value{GDBN}
38849to call the appropriate host system call:
38850
38851@itemize @bullet
b383017d 38852@item
0ce1b118
CV
38853A unique identifier for the requested system call.
38854
38855@item
38856All parameters to the system call. Pointers are given as addresses
38857in the target memory address space. Pointers to strings are given as
b383017d 38858pointer/length pair. Numerical values are given as they are.
db2e3e2e 38859Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
38860
38861@end itemize
38862
fc320d37 38863At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
38864
38865@itemize @bullet
b383017d 38866@item
fc320d37
SL
38867If the parameters include pointer values to data needed as input to a
38868system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
38869standard @code{m} packet request. This additional communication has to be
38870expected by the target implementation and is handled as any other @code{m}
38871packet.
38872
38873@item
38874@value{GDBN} translates all value from protocol representation to host
38875representation as needed. Datatypes are coerced into the host types.
38876
38877@item
fc320d37 38878@value{GDBN} calls the system call.
0ce1b118
CV
38879
38880@item
38881It then coerces datatypes back to protocol representation.
38882
38883@item
fc320d37
SL
38884If the system call is expected to return data in buffer space specified
38885by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
38886target using a @code{M} or @code{X} packet. This packet has to be expected
38887by the target implementation and is handled as any other @code{M} or @code{X}
38888packet.
38889
38890@end itemize
38891
38892Eventually @value{GDBN} replies with another @code{F} packet which contains all
38893necessary information for the target to continue. This at least contains
38894
38895@itemize @bullet
38896@item
38897Return value.
38898
38899@item
38900@code{errno}, if has been changed by the system call.
38901
38902@item
38903``Ctrl-C'' flag.
38904
38905@end itemize
38906
38907After having done the needed type and value coercion, the target continues
38908the latest continue or step action.
38909
79a6e687
BW
38910@node The F Request Packet
38911@subsection The @code{F} Request Packet
0ce1b118
CV
38912@cindex file-i/o request packet
38913@cindex @code{F} request packet
38914
38915The @code{F} request packet has the following format:
38916
38917@table @samp
fc320d37 38918@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
38919
38920@var{call-id} is the identifier to indicate the host system call to be called.
38921This is just the name of the function.
38922
fc320d37
SL
38923@var{parameter@dots{}} are the parameters to the system call.
38924Parameters are hexadecimal integer values, either the actual values in case
38925of scalar datatypes, pointers to target buffer space in case of compound
38926datatypes and unspecified memory areas, or pointer/length pairs in case
38927of string parameters. These are appended to the @var{call-id} as a
38928comma-delimited list. All values are transmitted in ASCII
38929string representation, pointer/length pairs separated by a slash.
0ce1b118 38930
b383017d 38931@end table
0ce1b118 38932
fc320d37 38933
0ce1b118 38934
79a6e687
BW
38935@node The F Reply Packet
38936@subsection The @code{F} Reply Packet
0ce1b118
CV
38937@cindex file-i/o reply packet
38938@cindex @code{F} reply packet
38939
38940The @code{F} reply packet has the following format:
38941
38942@table @samp
38943
d3bdde98 38944@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
38945
38946@var{retcode} is the return code of the system call as hexadecimal value.
38947
db2e3e2e
BW
38948@var{errno} is the @code{errno} set by the call, in protocol-specific
38949representation.
0ce1b118
CV
38950This parameter can be omitted if the call was successful.
38951
fc320d37
SL
38952@var{Ctrl-C flag} is only sent if the user requested a break. In this
38953case, @var{errno} must be sent as well, even if the call was successful.
38954The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
38955
38956@smallexample
38957F0,0,C
38958@end smallexample
38959
38960@noindent
fc320d37 38961or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
38962
38963@smallexample
38964F-1,4,C
38965@end smallexample
38966
38967@noindent
db2e3e2e 38968assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
38969
38970@end table
38971
0ce1b118 38972
79a6e687
BW
38973@node The Ctrl-C Message
38974@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
38975@cindex ctrl-c message, in file-i/o protocol
38976
c8aa23ab 38977If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 38978reply packet (@pxref{The F Reply Packet}),
fc320d37 38979the target should behave as if it had
0ce1b118 38980gotten a break message. The meaning for the target is ``system call
fc320d37 38981interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 38982(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 38983packet.
fc320d37
SL
38984
38985It's important for the target to know in which
38986state the system call was interrupted. There are two possible cases:
0ce1b118
CV
38987
38988@itemize @bullet
38989@item
38990The system call hasn't been performed on the host yet.
38991
38992@item
38993The system call on the host has been finished.
38994
38995@end itemize
38996
38997These two states can be distinguished by the target by the value of the
38998returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
38999call hasn't been performed. This is equivalent to the @code{EINTR} handling
39000on POSIX systems. In any other case, the target may presume that the
fc320d37 39001system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
39002as if the break message arrived right after the system call.
39003
fc320d37 39004@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
39005yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
39006@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
39007before the user requests a break, the full action must be finished by
39008@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
39009The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
39010or the full action has been completed.
39011
39012@node Console I/O
39013@subsection Console I/O
39014@cindex console i/o as part of file-i/o
39015
d3e8051b 39016By default and if not explicitly closed by the target system, the file
0ce1b118
CV
39017descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
39018on the @value{GDBN} console is handled as any other file output operation
39019(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
39020by @value{GDBN} so that after the target read request from file descriptor
390210 all following typing is buffered until either one of the following
39022conditions is met:
39023
39024@itemize @bullet
39025@item
c8aa23ab 39026The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
39027@code{read}
39028system call is treated as finished.
39029
39030@item
7f9087cb 39031The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 39032newline.
0ce1b118
CV
39033
39034@item
c8aa23ab
EZ
39035The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
39036character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
39037
39038@end itemize
39039
fc320d37
SL
39040If the user has typed more characters than fit in the buffer given to
39041the @code{read} call, the trailing characters are buffered in @value{GDBN} until
39042either another @code{read(0, @dots{})} is requested by the target, or debugging
39043is stopped at the user's request.
0ce1b118 39044
0ce1b118 39045
79a6e687
BW
39046@node List of Supported Calls
39047@subsection List of Supported Calls
0ce1b118
CV
39048@cindex list of supported file-i/o calls
39049
39050@menu
39051* open::
39052* close::
39053* read::
39054* write::
39055* lseek::
39056* rename::
39057* unlink::
39058* stat/fstat::
39059* gettimeofday::
39060* isatty::
39061* system::
39062@end menu
39063
39064@node open
39065@unnumberedsubsubsec open
39066@cindex open, file-i/o system call
39067
fc320d37
SL
39068@table @asis
39069@item Synopsis:
0ce1b118 39070@smallexample
0ce1b118
CV
39071int open(const char *pathname, int flags);
39072int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
39073@end smallexample
39074
fc320d37
SL
39075@item Request:
39076@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
39077
0ce1b118 39078@noindent
fc320d37 39079@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
39080
39081@table @code
b383017d 39082@item O_CREAT
0ce1b118
CV
39083If the file does not exist it will be created. The host
39084rules apply as far as file ownership and time stamps
39085are concerned.
39086
b383017d 39087@item O_EXCL
fc320d37 39088When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
39089an error and open() fails.
39090
b383017d 39091@item O_TRUNC
0ce1b118 39092If the file already exists and the open mode allows
fc320d37
SL
39093writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
39094truncated to zero length.
0ce1b118 39095
b383017d 39096@item O_APPEND
0ce1b118
CV
39097The file is opened in append mode.
39098
b383017d 39099@item O_RDONLY
0ce1b118
CV
39100The file is opened for reading only.
39101
b383017d 39102@item O_WRONLY
0ce1b118
CV
39103The file is opened for writing only.
39104
b383017d 39105@item O_RDWR
0ce1b118 39106The file is opened for reading and writing.
fc320d37 39107@end table
0ce1b118
CV
39108
39109@noindent
fc320d37 39110Other bits are silently ignored.
0ce1b118 39111
0ce1b118
CV
39112
39113@noindent
fc320d37 39114@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
39115
39116@table @code
b383017d 39117@item S_IRUSR
0ce1b118
CV
39118User has read permission.
39119
b383017d 39120@item S_IWUSR
0ce1b118
CV
39121User has write permission.
39122
b383017d 39123@item S_IRGRP
0ce1b118
CV
39124Group has read permission.
39125
b383017d 39126@item S_IWGRP
0ce1b118
CV
39127Group has write permission.
39128
b383017d 39129@item S_IROTH
0ce1b118
CV
39130Others have read permission.
39131
b383017d 39132@item S_IWOTH
0ce1b118 39133Others have write permission.
fc320d37 39134@end table
0ce1b118
CV
39135
39136@noindent
fc320d37 39137Other bits are silently ignored.
0ce1b118 39138
0ce1b118 39139
fc320d37
SL
39140@item Return value:
39141@code{open} returns the new file descriptor or -1 if an error
39142occurred.
0ce1b118 39143
fc320d37 39144@item Errors:
0ce1b118
CV
39145
39146@table @code
b383017d 39147@item EEXIST
fc320d37 39148@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 39149
b383017d 39150@item EISDIR
fc320d37 39151@var{pathname} refers to a directory.
0ce1b118 39152
b383017d 39153@item EACCES
0ce1b118
CV
39154The requested access is not allowed.
39155
39156@item ENAMETOOLONG
fc320d37 39157@var{pathname} was too long.
0ce1b118 39158
b383017d 39159@item ENOENT
fc320d37 39160A directory component in @var{pathname} does not exist.
0ce1b118 39161
b383017d 39162@item ENODEV
fc320d37 39163@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 39164
b383017d 39165@item EROFS
fc320d37 39166@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
39167write access was requested.
39168
b383017d 39169@item EFAULT
fc320d37 39170@var{pathname} is an invalid pointer value.
0ce1b118 39171
b383017d 39172@item ENOSPC
0ce1b118
CV
39173No space on device to create the file.
39174
b383017d 39175@item EMFILE
0ce1b118
CV
39176The process already has the maximum number of files open.
39177
b383017d 39178@item ENFILE
0ce1b118
CV
39179The limit on the total number of files open on the system
39180has been reached.
39181
b383017d 39182@item EINTR
0ce1b118
CV
39183The call was interrupted by the user.
39184@end table
39185
fc320d37
SL
39186@end table
39187
0ce1b118
CV
39188@node close
39189@unnumberedsubsubsec close
39190@cindex close, file-i/o system call
39191
fc320d37
SL
39192@table @asis
39193@item Synopsis:
0ce1b118 39194@smallexample
0ce1b118 39195int close(int fd);
fc320d37 39196@end smallexample
0ce1b118 39197
fc320d37
SL
39198@item Request:
39199@samp{Fclose,@var{fd}}
0ce1b118 39200
fc320d37
SL
39201@item Return value:
39202@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 39203
fc320d37 39204@item Errors:
0ce1b118
CV
39205
39206@table @code
b383017d 39207@item EBADF
fc320d37 39208@var{fd} isn't a valid open file descriptor.
0ce1b118 39209
b383017d 39210@item EINTR
0ce1b118
CV
39211The call was interrupted by the user.
39212@end table
39213
fc320d37
SL
39214@end table
39215
0ce1b118
CV
39216@node read
39217@unnumberedsubsubsec read
39218@cindex read, file-i/o system call
39219
fc320d37
SL
39220@table @asis
39221@item Synopsis:
0ce1b118 39222@smallexample
0ce1b118 39223int read(int fd, void *buf, unsigned int count);
fc320d37 39224@end smallexample
0ce1b118 39225
fc320d37
SL
39226@item Request:
39227@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39228
fc320d37 39229@item Return value:
0ce1b118
CV
39230On success, the number of bytes read is returned.
39231Zero indicates end of file. If count is zero, read
b383017d 39232returns zero as well. On error, -1 is returned.
0ce1b118 39233
fc320d37 39234@item Errors:
0ce1b118
CV
39235
39236@table @code
b383017d 39237@item EBADF
fc320d37 39238@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39239reading.
39240
b383017d 39241@item EFAULT
fc320d37 39242@var{bufptr} is an invalid pointer value.
0ce1b118 39243
b383017d 39244@item EINTR
0ce1b118
CV
39245The call was interrupted by the user.
39246@end table
39247
fc320d37
SL
39248@end table
39249
0ce1b118
CV
39250@node write
39251@unnumberedsubsubsec write
39252@cindex write, file-i/o system call
39253
fc320d37
SL
39254@table @asis
39255@item Synopsis:
0ce1b118 39256@smallexample
0ce1b118 39257int write(int fd, const void *buf, unsigned int count);
fc320d37 39258@end smallexample
0ce1b118 39259
fc320d37
SL
39260@item Request:
39261@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 39262
fc320d37 39263@item Return value:
0ce1b118
CV
39264On success, the number of bytes written are returned.
39265Zero indicates nothing was written. On error, -1
39266is returned.
39267
fc320d37 39268@item Errors:
0ce1b118
CV
39269
39270@table @code
b383017d 39271@item EBADF
fc320d37 39272@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
39273writing.
39274
b383017d 39275@item EFAULT
fc320d37 39276@var{bufptr} is an invalid pointer value.
0ce1b118 39277
b383017d 39278@item EFBIG
0ce1b118 39279An attempt was made to write a file that exceeds the
db2e3e2e 39280host-specific maximum file size allowed.
0ce1b118 39281
b383017d 39282@item ENOSPC
0ce1b118
CV
39283No space on device to write the data.
39284
b383017d 39285@item EINTR
0ce1b118
CV
39286The call was interrupted by the user.
39287@end table
39288
fc320d37
SL
39289@end table
39290
0ce1b118
CV
39291@node lseek
39292@unnumberedsubsubsec lseek
39293@cindex lseek, file-i/o system call
39294
fc320d37
SL
39295@table @asis
39296@item Synopsis:
0ce1b118 39297@smallexample
0ce1b118 39298long lseek (int fd, long offset, int flag);
0ce1b118
CV
39299@end smallexample
39300
fc320d37
SL
39301@item Request:
39302@samp{Flseek,@var{fd},@var{offset},@var{flag}}
39303
39304@var{flag} is one of:
0ce1b118
CV
39305
39306@table @code
b383017d 39307@item SEEK_SET
fc320d37 39308The offset is set to @var{offset} bytes.
0ce1b118 39309
b383017d 39310@item SEEK_CUR
fc320d37 39311The offset is set to its current location plus @var{offset}
0ce1b118
CV
39312bytes.
39313
b383017d 39314@item SEEK_END
fc320d37 39315The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
39316bytes.
39317@end table
39318
fc320d37 39319@item Return value:
0ce1b118
CV
39320On success, the resulting unsigned offset in bytes from
39321the beginning of the file is returned. Otherwise, a
39322value of -1 is returned.
39323
fc320d37 39324@item Errors:
0ce1b118
CV
39325
39326@table @code
b383017d 39327@item EBADF
fc320d37 39328@var{fd} is not a valid open file descriptor.
0ce1b118 39329
b383017d 39330@item ESPIPE
fc320d37 39331@var{fd} is associated with the @value{GDBN} console.
0ce1b118 39332
b383017d 39333@item EINVAL
fc320d37 39334@var{flag} is not a proper value.
0ce1b118 39335
b383017d 39336@item EINTR
0ce1b118
CV
39337The call was interrupted by the user.
39338@end table
39339
fc320d37
SL
39340@end table
39341
0ce1b118
CV
39342@node rename
39343@unnumberedsubsubsec rename
39344@cindex rename, file-i/o system call
39345
fc320d37
SL
39346@table @asis
39347@item Synopsis:
0ce1b118 39348@smallexample
0ce1b118 39349int rename(const char *oldpath, const char *newpath);
fc320d37 39350@end smallexample
0ce1b118 39351
fc320d37
SL
39352@item Request:
39353@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 39354
fc320d37 39355@item Return value:
0ce1b118
CV
39356On success, zero is returned. On error, -1 is returned.
39357
fc320d37 39358@item Errors:
0ce1b118
CV
39359
39360@table @code
b383017d 39361@item EISDIR
fc320d37 39362@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
39363directory.
39364
b383017d 39365@item EEXIST
fc320d37 39366@var{newpath} is a non-empty directory.
0ce1b118 39367
b383017d 39368@item EBUSY
fc320d37 39369@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
39370process.
39371
b383017d 39372@item EINVAL
0ce1b118
CV
39373An attempt was made to make a directory a subdirectory
39374of itself.
39375
b383017d 39376@item ENOTDIR
fc320d37
SL
39377A component used as a directory in @var{oldpath} or new
39378path is not a directory. Or @var{oldpath} is a directory
39379and @var{newpath} exists but is not a directory.
0ce1b118 39380
b383017d 39381@item EFAULT
fc320d37 39382@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 39383
b383017d 39384@item EACCES
0ce1b118
CV
39385No access to the file or the path of the file.
39386
39387@item ENAMETOOLONG
b383017d 39388
fc320d37 39389@var{oldpath} or @var{newpath} was too long.
0ce1b118 39390
b383017d 39391@item ENOENT
fc320d37 39392A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 39393
b383017d 39394@item EROFS
0ce1b118
CV
39395The file is on a read-only filesystem.
39396
b383017d 39397@item ENOSPC
0ce1b118
CV
39398The device containing the file has no room for the new
39399directory entry.
39400
b383017d 39401@item EINTR
0ce1b118
CV
39402The call was interrupted by the user.
39403@end table
39404
fc320d37
SL
39405@end table
39406
0ce1b118
CV
39407@node unlink
39408@unnumberedsubsubsec unlink
39409@cindex unlink, file-i/o system call
39410
fc320d37
SL
39411@table @asis
39412@item Synopsis:
0ce1b118 39413@smallexample
0ce1b118 39414int unlink(const char *pathname);
fc320d37 39415@end smallexample
0ce1b118 39416
fc320d37
SL
39417@item Request:
39418@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 39419
fc320d37 39420@item Return value:
0ce1b118
CV
39421On success, zero is returned. On error, -1 is returned.
39422
fc320d37 39423@item Errors:
0ce1b118
CV
39424
39425@table @code
b383017d 39426@item EACCES
0ce1b118
CV
39427No access to the file or the path of the file.
39428
b383017d 39429@item EPERM
0ce1b118
CV
39430The system does not allow unlinking of directories.
39431
b383017d 39432@item EBUSY
fc320d37 39433The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
39434being used by another process.
39435
b383017d 39436@item EFAULT
fc320d37 39437@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
39438
39439@item ENAMETOOLONG
fc320d37 39440@var{pathname} was too long.
0ce1b118 39441
b383017d 39442@item ENOENT
fc320d37 39443A directory component in @var{pathname} does not exist.
0ce1b118 39444
b383017d 39445@item ENOTDIR
0ce1b118
CV
39446A component of the path is not a directory.
39447
b383017d 39448@item EROFS
0ce1b118
CV
39449The file is on a read-only filesystem.
39450
b383017d 39451@item EINTR
0ce1b118
CV
39452The call was interrupted by the user.
39453@end table
39454
fc320d37
SL
39455@end table
39456
0ce1b118
CV
39457@node stat/fstat
39458@unnumberedsubsubsec stat/fstat
39459@cindex fstat, file-i/o system call
39460@cindex stat, file-i/o system call
39461
fc320d37
SL
39462@table @asis
39463@item Synopsis:
0ce1b118 39464@smallexample
0ce1b118
CV
39465int stat(const char *pathname, struct stat *buf);
39466int fstat(int fd, struct stat *buf);
fc320d37 39467@end smallexample
0ce1b118 39468
fc320d37
SL
39469@item Request:
39470@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
39471@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 39472
fc320d37 39473@item Return value:
0ce1b118
CV
39474On success, zero is returned. On error, -1 is returned.
39475
fc320d37 39476@item Errors:
0ce1b118
CV
39477
39478@table @code
b383017d 39479@item EBADF
fc320d37 39480@var{fd} is not a valid open file.
0ce1b118 39481
b383017d 39482@item ENOENT
fc320d37 39483A directory component in @var{pathname} does not exist or the
0ce1b118
CV
39484path is an empty string.
39485
b383017d 39486@item ENOTDIR
0ce1b118
CV
39487A component of the path is not a directory.
39488
b383017d 39489@item EFAULT
fc320d37 39490@var{pathnameptr} is an invalid pointer value.
0ce1b118 39491
b383017d 39492@item EACCES
0ce1b118
CV
39493No access to the file or the path of the file.
39494
39495@item ENAMETOOLONG
fc320d37 39496@var{pathname} was too long.
0ce1b118 39497
b383017d 39498@item EINTR
0ce1b118
CV
39499The call was interrupted by the user.
39500@end table
39501
fc320d37
SL
39502@end table
39503
0ce1b118
CV
39504@node gettimeofday
39505@unnumberedsubsubsec gettimeofday
39506@cindex gettimeofday, file-i/o system call
39507
fc320d37
SL
39508@table @asis
39509@item Synopsis:
0ce1b118 39510@smallexample
0ce1b118 39511int gettimeofday(struct timeval *tv, void *tz);
fc320d37 39512@end smallexample
0ce1b118 39513
fc320d37
SL
39514@item Request:
39515@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 39516
fc320d37 39517@item Return value:
0ce1b118
CV
39518On success, 0 is returned, -1 otherwise.
39519
fc320d37 39520@item Errors:
0ce1b118
CV
39521
39522@table @code
b383017d 39523@item EINVAL
fc320d37 39524@var{tz} is a non-NULL pointer.
0ce1b118 39525
b383017d 39526@item EFAULT
fc320d37
SL
39527@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
39528@end table
39529
0ce1b118
CV
39530@end table
39531
39532@node isatty
39533@unnumberedsubsubsec isatty
39534@cindex isatty, file-i/o system call
39535
fc320d37
SL
39536@table @asis
39537@item Synopsis:
0ce1b118 39538@smallexample
0ce1b118 39539int isatty(int fd);
fc320d37 39540@end smallexample
0ce1b118 39541
fc320d37
SL
39542@item Request:
39543@samp{Fisatty,@var{fd}}
0ce1b118 39544
fc320d37
SL
39545@item Return value:
39546Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 39547
fc320d37 39548@item Errors:
0ce1b118
CV
39549
39550@table @code
b383017d 39551@item EINTR
0ce1b118
CV
39552The call was interrupted by the user.
39553@end table
39554
fc320d37
SL
39555@end table
39556
39557Note that the @code{isatty} call is treated as a special case: it returns
395581 to the target if the file descriptor is attached
39559to the @value{GDBN} console, 0 otherwise. Implementing through system calls
39560would require implementing @code{ioctl} and would be more complex than
39561needed.
39562
39563
0ce1b118
CV
39564@node system
39565@unnumberedsubsubsec system
39566@cindex system, file-i/o system call
39567
fc320d37
SL
39568@table @asis
39569@item Synopsis:
0ce1b118 39570@smallexample
0ce1b118 39571int system(const char *command);
fc320d37 39572@end smallexample
0ce1b118 39573
fc320d37
SL
39574@item Request:
39575@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 39576
fc320d37 39577@item Return value:
5600ea19
NS
39578If @var{len} is zero, the return value indicates whether a shell is
39579available. A zero return value indicates a shell is not available.
39580For non-zero @var{len}, the value returned is -1 on error and the
39581return status of the command otherwise. Only the exit status of the
39582command is returned, which is extracted from the host's @code{system}
39583return value by calling @code{WEXITSTATUS(retval)}. In case
39584@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 39585
fc320d37 39586@item Errors:
0ce1b118
CV
39587
39588@table @code
b383017d 39589@item EINTR
0ce1b118
CV
39590The call was interrupted by the user.
39591@end table
39592
fc320d37
SL
39593@end table
39594
39595@value{GDBN} takes over the full task of calling the necessary host calls
39596to perform the @code{system} call. The return value of @code{system} on
39597the host is simplified before it's returned
39598to the target. Any termination signal information from the child process
39599is discarded, and the return value consists
39600entirely of the exit status of the called command.
39601
39602Due to security concerns, the @code{system} call is by default refused
39603by @value{GDBN}. The user has to allow this call explicitly with the
39604@code{set remote system-call-allowed 1} command.
39605
39606@table @code
39607@item set remote system-call-allowed
39608@kindex set remote system-call-allowed
39609Control whether to allow the @code{system} calls in the File I/O
39610protocol for the remote target. The default is zero (disabled).
39611
39612@item show remote system-call-allowed
39613@kindex show remote system-call-allowed
39614Show whether the @code{system} calls are allowed in the File I/O
39615protocol.
39616@end table
39617
db2e3e2e
BW
39618@node Protocol-specific Representation of Datatypes
39619@subsection Protocol-specific Representation of Datatypes
39620@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
39621
39622@menu
79a6e687
BW
39623* Integral Datatypes::
39624* Pointer Values::
39625* Memory Transfer::
0ce1b118
CV
39626* struct stat::
39627* struct timeval::
39628@end menu
39629
79a6e687
BW
39630@node Integral Datatypes
39631@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
39632@cindex integral datatypes, in file-i/o protocol
39633
fc320d37
SL
39634The integral datatypes used in the system calls are @code{int},
39635@code{unsigned int}, @code{long}, @code{unsigned long},
39636@code{mode_t}, and @code{time_t}.
0ce1b118 39637
fc320d37 39638@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
39639implemented as 32 bit values in this protocol.
39640
fc320d37 39641@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 39642
0ce1b118
CV
39643@xref{Limits}, for corresponding MIN and MAX values (similar to those
39644in @file{limits.h}) to allow range checking on host and target.
39645
39646@code{time_t} datatypes are defined as seconds since the Epoch.
39647
39648All integral datatypes transferred as part of a memory read or write of a
39649structured datatype e.g.@: a @code{struct stat} have to be given in big endian
39650byte order.
39651
79a6e687
BW
39652@node Pointer Values
39653@unnumberedsubsubsec Pointer Values
0ce1b118
CV
39654@cindex pointer values, in file-i/o protocol
39655
39656Pointers to target data are transmitted as they are. An exception
39657is made for pointers to buffers for which the length isn't
39658transmitted as part of the function call, namely strings. Strings
39659are transmitted as a pointer/length pair, both as hex values, e.g.@:
39660
39661@smallexample
39662@code{1aaf/12}
39663@end smallexample
39664
39665@noindent
39666which is a pointer to data of length 18 bytes at position 0x1aaf.
39667The length is defined as the full string length in bytes, including
fc320d37
SL
39668the trailing null byte. For example, the string @code{"hello world"}
39669at address 0x123456 is transmitted as
0ce1b118
CV
39670
39671@smallexample
fc320d37 39672@code{123456/d}
0ce1b118
CV
39673@end smallexample
39674
79a6e687
BW
39675@node Memory Transfer
39676@unnumberedsubsubsec Memory Transfer
fc320d37
SL
39677@cindex memory transfer, in file-i/o protocol
39678
39679Structured data which is transferred using a memory read or write (for
db2e3e2e 39680example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
39681with all scalar multibyte datatypes being big endian. Translation to
39682this representation needs to be done both by the target before the @code{F}
39683packet is sent, and by @value{GDBN} before
39684it transfers memory to the target. Transferred pointers to structured
39685data should point to the already-coerced data at any time.
0ce1b118 39686
0ce1b118
CV
39687
39688@node struct stat
39689@unnumberedsubsubsec struct stat
39690@cindex struct stat, in file-i/o protocol
39691
fc320d37
SL
39692The buffer of type @code{struct stat} used by the target and @value{GDBN}
39693is defined as follows:
0ce1b118
CV
39694
39695@smallexample
39696struct stat @{
39697 unsigned int st_dev; /* device */
39698 unsigned int st_ino; /* inode */
39699 mode_t st_mode; /* protection */
39700 unsigned int st_nlink; /* number of hard links */
39701 unsigned int st_uid; /* user ID of owner */
39702 unsigned int st_gid; /* group ID of owner */
39703 unsigned int st_rdev; /* device type (if inode device) */
39704 unsigned long st_size; /* total size, in bytes */
39705 unsigned long st_blksize; /* blocksize for filesystem I/O */
39706 unsigned long st_blocks; /* number of blocks allocated */
39707 time_t st_atime; /* time of last access */
39708 time_t st_mtime; /* time of last modification */
39709 time_t st_ctime; /* time of last change */
39710@};
39711@end smallexample
39712
fc320d37 39713The integral datatypes conform to the definitions given in the
79a6e687 39714appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
39715structure is of size 64 bytes.
39716
39717The values of several fields have a restricted meaning and/or
39718range of values.
39719
fc320d37 39720@table @code
0ce1b118 39721
fc320d37
SL
39722@item st_dev
39723A value of 0 represents a file, 1 the console.
0ce1b118 39724
fc320d37
SL
39725@item st_ino
39726No valid meaning for the target. Transmitted unchanged.
0ce1b118 39727
fc320d37
SL
39728@item st_mode
39729Valid mode bits are described in @ref{Constants}. Any other
39730bits have currently no meaning for the target.
0ce1b118 39731
fc320d37
SL
39732@item st_uid
39733@itemx st_gid
39734@itemx st_rdev
39735No valid meaning for the target. Transmitted unchanged.
0ce1b118 39736
fc320d37
SL
39737@item st_atime
39738@itemx st_mtime
39739@itemx st_ctime
39740These values have a host and file system dependent
39741accuracy. Especially on Windows hosts, the file system may not
39742support exact timing values.
39743@end table
0ce1b118 39744
fc320d37
SL
39745The target gets a @code{struct stat} of the above representation and is
39746responsible for coercing it to the target representation before
0ce1b118
CV
39747continuing.
39748
fc320d37
SL
39749Note that due to size differences between the host, target, and protocol
39750representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
39751get truncated on the target.
39752
39753@node struct timeval
39754@unnumberedsubsubsec struct timeval
39755@cindex struct timeval, in file-i/o protocol
39756
fc320d37 39757The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
39758is defined as follows:
39759
39760@smallexample
b383017d 39761struct timeval @{
0ce1b118
CV
39762 time_t tv_sec; /* second */
39763 long tv_usec; /* microsecond */
39764@};
39765@end smallexample
39766
fc320d37 39767The integral datatypes conform to the definitions given in the
79a6e687 39768appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
39769structure is of size 8 bytes.
39770
39771@node Constants
39772@subsection Constants
39773@cindex constants, in file-i/o protocol
39774
39775The following values are used for the constants inside of the
fc320d37 39776protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
39777values before and after the call as needed.
39778
39779@menu
79a6e687
BW
39780* Open Flags::
39781* mode_t Values::
39782* Errno Values::
39783* Lseek Flags::
0ce1b118
CV
39784* Limits::
39785@end menu
39786
79a6e687
BW
39787@node Open Flags
39788@unnumberedsubsubsec Open Flags
0ce1b118
CV
39789@cindex open flags, in file-i/o protocol
39790
39791All values are given in hexadecimal representation.
39792
39793@smallexample
39794 O_RDONLY 0x0
39795 O_WRONLY 0x1
39796 O_RDWR 0x2
39797 O_APPEND 0x8
39798 O_CREAT 0x200
39799 O_TRUNC 0x400
39800 O_EXCL 0x800
39801@end smallexample
39802
79a6e687
BW
39803@node mode_t Values
39804@unnumberedsubsubsec mode_t Values
0ce1b118
CV
39805@cindex mode_t values, in file-i/o protocol
39806
39807All values are given in octal representation.
39808
39809@smallexample
39810 S_IFREG 0100000
39811 S_IFDIR 040000
39812 S_IRUSR 0400
39813 S_IWUSR 0200
39814 S_IXUSR 0100
39815 S_IRGRP 040
39816 S_IWGRP 020
39817 S_IXGRP 010
39818 S_IROTH 04
39819 S_IWOTH 02
39820 S_IXOTH 01
39821@end smallexample
39822
79a6e687
BW
39823@node Errno Values
39824@unnumberedsubsubsec Errno Values
0ce1b118
CV
39825@cindex errno values, in file-i/o protocol
39826
39827All values are given in decimal representation.
39828
39829@smallexample
39830 EPERM 1
39831 ENOENT 2
39832 EINTR 4
39833 EBADF 9
39834 EACCES 13
39835 EFAULT 14
39836 EBUSY 16
39837 EEXIST 17
39838 ENODEV 19
39839 ENOTDIR 20
39840 EISDIR 21
39841 EINVAL 22
39842 ENFILE 23
39843 EMFILE 24
39844 EFBIG 27
39845 ENOSPC 28
39846 ESPIPE 29
39847 EROFS 30
39848 ENAMETOOLONG 91
39849 EUNKNOWN 9999
39850@end smallexample
39851
fc320d37 39852 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
39853 any error value not in the list of supported error numbers.
39854
79a6e687
BW
39855@node Lseek Flags
39856@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
39857@cindex lseek flags, in file-i/o protocol
39858
39859@smallexample
39860 SEEK_SET 0
39861 SEEK_CUR 1
39862 SEEK_END 2
39863@end smallexample
39864
39865@node Limits
39866@unnumberedsubsubsec Limits
39867@cindex limits, in file-i/o protocol
39868
39869All values are given in decimal representation.
39870
39871@smallexample
39872 INT_MIN -2147483648
39873 INT_MAX 2147483647
39874 UINT_MAX 4294967295
39875 LONG_MIN -9223372036854775808
39876 LONG_MAX 9223372036854775807
39877 ULONG_MAX 18446744073709551615
39878@end smallexample
39879
39880@node File-I/O Examples
39881@subsection File-I/O Examples
39882@cindex file-i/o examples
39883
39884Example sequence of a write call, file descriptor 3, buffer is at target
39885address 0x1234, 6 bytes should be written:
39886
39887@smallexample
39888<- @code{Fwrite,3,1234,6}
39889@emph{request memory read from target}
39890-> @code{m1234,6}
39891<- XXXXXX
39892@emph{return "6 bytes written"}
39893-> @code{F6}
39894@end smallexample
39895
39896Example sequence of a read call, file descriptor 3, buffer is at target
39897address 0x1234, 6 bytes should be read:
39898
39899@smallexample
39900<- @code{Fread,3,1234,6}
39901@emph{request memory write to target}
39902-> @code{X1234,6:XXXXXX}
39903@emph{return "6 bytes read"}
39904-> @code{F6}
39905@end smallexample
39906
39907Example sequence of a read call, call fails on the host due to invalid
fc320d37 39908file descriptor (@code{EBADF}):
0ce1b118
CV
39909
39910@smallexample
39911<- @code{Fread,3,1234,6}
39912-> @code{F-1,9}
39913@end smallexample
39914
c8aa23ab 39915Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
39916host is called:
39917
39918@smallexample
39919<- @code{Fread,3,1234,6}
39920-> @code{F-1,4,C}
39921<- @code{T02}
39922@end smallexample
39923
c8aa23ab 39924Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
39925host is called:
39926
39927@smallexample
39928<- @code{Fread,3,1234,6}
39929-> @code{X1234,6:XXXXXX}
39930<- @code{T02}
39931@end smallexample
39932
cfa9d6d9
DJ
39933@node Library List Format
39934@section Library List Format
39935@cindex library list format, remote protocol
39936
39937On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
39938same process as your application to manage libraries. In this case,
39939@value{GDBN} can use the loader's symbol table and normal memory
39940operations to maintain a list of shared libraries. On other
39941platforms, the operating system manages loaded libraries.
39942@value{GDBN} can not retrieve the list of currently loaded libraries
39943through memory operations, so it uses the @samp{qXfer:libraries:read}
39944packet (@pxref{qXfer library list read}) instead. The remote stub
39945queries the target's operating system and reports which libraries
39946are loaded.
39947
39948The @samp{qXfer:libraries:read} packet returns an XML document which
39949lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
39950associated name and one or more segment or section base addresses,
39951which report where the library was loaded in memory.
39952
39953For the common case of libraries that are fully linked binaries, the
39954library should have a list of segments. If the target supports
39955dynamic linking of a relocatable object file, its library XML element
39956should instead include a list of allocated sections. The segment or
39957section bases are start addresses, not relocation offsets; they do not
39958depend on the library's link-time base addresses.
cfa9d6d9 39959
9cceb671
DJ
39960@value{GDBN} must be linked with the Expat library to support XML
39961library lists. @xref{Expat}.
39962
cfa9d6d9
DJ
39963A simple memory map, with one loaded library relocated by a single
39964offset, looks like this:
39965
39966@smallexample
39967<library-list>
39968 <library name="/lib/libc.so.6">
39969 <segment address="0x10000000"/>
39970 </library>
39971</library-list>
39972@end smallexample
39973
1fddbabb
PA
39974Another simple memory map, with one loaded library with three
39975allocated sections (.text, .data, .bss), looks like this:
39976
39977@smallexample
39978<library-list>
39979 <library name="sharedlib.o">
39980 <section address="0x10000000"/>
39981 <section address="0x20000000"/>
39982 <section address="0x30000000"/>
39983 </library>
39984</library-list>
39985@end smallexample
39986
cfa9d6d9
DJ
39987The format of a library list is described by this DTD:
39988
39989@smallexample
39990<!-- library-list: Root element with versioning -->
39991<!ELEMENT library-list (library)*>
39992<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 39993<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
39994<!ATTLIST library name CDATA #REQUIRED>
39995<!ELEMENT segment EMPTY>
39996<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
39997<!ELEMENT section EMPTY>
39998<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
39999@end smallexample
40000
1fddbabb
PA
40001In addition, segments and section descriptors cannot be mixed within a
40002single library element, and you must supply at least one segment or
40003section for each library.
40004
2268b414
JK
40005@node Library List Format for SVR4 Targets
40006@section Library List Format for SVR4 Targets
40007@cindex library list format, remote protocol
40008
40009On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
40010(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
40011shared libraries. Still a special library list provided by this packet is
40012more efficient for the @value{GDBN} remote protocol.
40013
40014The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
40015loaded libraries and their SVR4 linker parameters. For each library on SVR4
40016target, the following parameters are reported:
40017
40018@itemize @minus
40019@item
40020@code{name}, the absolute file name from the @code{l_name} field of
40021@code{struct link_map}.
40022@item
40023@code{lm} with address of @code{struct link_map} used for TLS
40024(Thread Local Storage) access.
40025@item
40026@code{l_addr}, the displacement as read from the field @code{l_addr} of
40027@code{struct link_map}. For prelinked libraries this is not an absolute
40028memory address. It is a displacement of absolute memory address against
40029address the file was prelinked to during the library load.
40030@item
40031@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
40032@end itemize
40033
40034Additionally the single @code{main-lm} attribute specifies address of
40035@code{struct link_map} used for the main executable. This parameter is used
40036for TLS access and its presence is optional.
40037
40038@value{GDBN} must be linked with the Expat library to support XML
40039SVR4 library lists. @xref{Expat}.
40040
40041A simple memory map, with two loaded libraries (which do not use prelink),
40042looks like this:
40043
40044@smallexample
40045<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
40046 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
40047 l_ld="0xe4eefc"/>
40048 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
40049 l_ld="0x152350"/>
40050</library-list-svr>
40051@end smallexample
40052
40053The format of an SVR4 library list is described by this DTD:
40054
40055@smallexample
40056<!-- library-list-svr4: Root element with versioning -->
40057<!ELEMENT library-list-svr4 (library)*>
40058<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
40059<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
40060<!ELEMENT library EMPTY>
40061<!ATTLIST library name CDATA #REQUIRED>
40062<!ATTLIST library lm CDATA #REQUIRED>
40063<!ATTLIST library l_addr CDATA #REQUIRED>
40064<!ATTLIST library l_ld CDATA #REQUIRED>
40065@end smallexample
40066
79a6e687
BW
40067@node Memory Map Format
40068@section Memory Map Format
68437a39
DJ
40069@cindex memory map format
40070
40071To be able to write into flash memory, @value{GDBN} needs to obtain a
40072memory map from the target. This section describes the format of the
40073memory map.
40074
40075The memory map is obtained using the @samp{qXfer:memory-map:read}
40076(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
40077lists memory regions.
40078
40079@value{GDBN} must be linked with the Expat library to support XML
40080memory maps. @xref{Expat}.
40081
40082The top-level structure of the document is shown below:
68437a39
DJ
40083
40084@smallexample
40085<?xml version="1.0"?>
40086<!DOCTYPE memory-map
40087 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40088 "http://sourceware.org/gdb/gdb-memory-map.dtd">
40089<memory-map>
40090 region...
40091</memory-map>
40092@end smallexample
40093
40094Each region can be either:
40095
40096@itemize
40097
40098@item
40099A region of RAM starting at @var{addr} and extending for @var{length}
40100bytes from there:
40101
40102@smallexample
40103<memory type="ram" start="@var{addr}" length="@var{length}"/>
40104@end smallexample
40105
40106
40107@item
40108A region of read-only memory:
40109
40110@smallexample
40111<memory type="rom" start="@var{addr}" length="@var{length}"/>
40112@end smallexample
40113
40114
40115@item
40116A region of flash memory, with erasure blocks @var{blocksize}
40117bytes in length:
40118
40119@smallexample
40120<memory type="flash" start="@var{addr}" length="@var{length}">
40121 <property name="blocksize">@var{blocksize}</property>
40122</memory>
40123@end smallexample
40124
40125@end itemize
40126
40127Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
40128by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
40129packets to write to addresses in such ranges.
40130
40131The formal DTD for memory map format is given below:
40132
40133@smallexample
40134<!-- ................................................... -->
40135<!-- Memory Map XML DTD ................................ -->
40136<!-- File: memory-map.dtd .............................. -->
40137<!-- .................................... .............. -->
40138<!-- memory-map.dtd -->
40139<!-- memory-map: Root element with versioning -->
40140<!ELEMENT memory-map (memory | property)>
40141<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
40142<!ELEMENT memory (property)>
40143<!-- memory: Specifies a memory region,
40144 and its type, or device. -->
40145<!ATTLIST memory type CDATA #REQUIRED
40146 start CDATA #REQUIRED
40147 length CDATA #REQUIRED
40148 device CDATA #IMPLIED>
40149<!-- property: Generic attribute tag -->
40150<!ELEMENT property (#PCDATA | property)*>
40151<!ATTLIST property name CDATA #REQUIRED>
40152@end smallexample
40153
dc146f7c
VP
40154@node Thread List Format
40155@section Thread List Format
40156@cindex thread list format
40157
40158To efficiently update the list of threads and their attributes,
40159@value{GDBN} issues the @samp{qXfer:threads:read} packet
40160(@pxref{qXfer threads read}) and obtains the XML document with
40161the following structure:
40162
40163@smallexample
40164<?xml version="1.0"?>
40165<threads>
40166 <thread id="id" core="0">
40167 ... description ...
40168 </thread>
40169</threads>
40170@end smallexample
40171
40172Each @samp{thread} element must have the @samp{id} attribute that
40173identifies the thread (@pxref{thread-id syntax}). The
40174@samp{core} attribute, if present, specifies which processor core
40175the thread was last executing on. The content of the of @samp{thread}
40176element is interpreted as human-readable auxilliary information.
40177
b3b9301e
PA
40178@node Traceframe Info Format
40179@section Traceframe Info Format
40180@cindex traceframe info format
40181
40182To be able to know which objects in the inferior can be examined when
40183inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
40184memory ranges, registers and trace state variables that have been
40185collected in a traceframe.
40186
40187This list is obtained using the @samp{qXfer:traceframe-info:read}
40188(@pxref{qXfer traceframe info read}) packet and is an XML document.
40189
40190@value{GDBN} must be linked with the Expat library to support XML
40191traceframe info discovery. @xref{Expat}.
40192
40193The top-level structure of the document is shown below:
40194
40195@smallexample
40196<?xml version="1.0"?>
40197<!DOCTYPE traceframe-info
40198 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40199 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
40200<traceframe-info>
40201 block...
40202</traceframe-info>
40203@end smallexample
40204
40205Each traceframe block can be either:
40206
40207@itemize
40208
40209@item
40210A region of collected memory starting at @var{addr} and extending for
40211@var{length} bytes from there:
40212
40213@smallexample
40214<memory start="@var{addr}" length="@var{length}"/>
40215@end smallexample
40216
40217@end itemize
40218
40219The formal DTD for the traceframe info format is given below:
40220
40221@smallexample
40222<!ELEMENT traceframe-info (memory)* >
40223<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
40224
40225<!ELEMENT memory EMPTY>
40226<!ATTLIST memory start CDATA #REQUIRED
40227 length CDATA #REQUIRED>
40228@end smallexample
40229
f418dd93
DJ
40230@include agentexpr.texi
40231
23181151
DJ
40232@node Target Descriptions
40233@appendix Target Descriptions
40234@cindex target descriptions
40235
23181151
DJ
40236One of the challenges of using @value{GDBN} to debug embedded systems
40237is that there are so many minor variants of each processor
40238architecture in use. It is common practice for vendors to start with
eb17f351 40239a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
40240and then make changes to adapt it to a particular market niche. Some
40241architectures have hundreds of variants, available from dozens of
40242vendors. This leads to a number of problems:
40243
40244@itemize @bullet
40245@item
40246With so many different customized processors, it is difficult for
40247the @value{GDBN} maintainers to keep up with the changes.
40248@item
40249Since individual variants may have short lifetimes or limited
40250audiences, it may not be worthwhile to carry information about every
40251variant in the @value{GDBN} source tree.
40252@item
40253When @value{GDBN} does support the architecture of the embedded system
40254at hand, the task of finding the correct architecture name to give the
40255@command{set architecture} command can be error-prone.
40256@end itemize
40257
40258To address these problems, the @value{GDBN} remote protocol allows a
40259target system to not only identify itself to @value{GDBN}, but to
40260actually describe its own features. This lets @value{GDBN} support
40261processor variants it has never seen before --- to the extent that the
40262descriptions are accurate, and that @value{GDBN} understands them.
40263
9cceb671
DJ
40264@value{GDBN} must be linked with the Expat library to support XML
40265target descriptions. @xref{Expat}.
123dc839 40266
23181151
DJ
40267@menu
40268* Retrieving Descriptions:: How descriptions are fetched from a target.
40269* Target Description Format:: The contents of a target description.
123dc839
DJ
40270* Predefined Target Types:: Standard types available for target
40271 descriptions.
40272* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
40273@end menu
40274
40275@node Retrieving Descriptions
40276@section Retrieving Descriptions
40277
40278Target descriptions can be read from the target automatically, or
40279specified by the user manually. The default behavior is to read the
40280description from the target. @value{GDBN} retrieves it via the remote
40281protocol using @samp{qXfer} requests (@pxref{General Query Packets,
40282qXfer}). The @var{annex} in the @samp{qXfer} packet will be
40283@samp{target.xml}. The contents of the @samp{target.xml} annex are an
40284XML document, of the form described in @ref{Target Description
40285Format}.
40286
40287Alternatively, you can specify a file to read for the target description.
40288If a file is set, the target will not be queried. The commands to
40289specify a file are:
40290
40291@table @code
40292@cindex set tdesc filename
40293@item set tdesc filename @var{path}
40294Read the target description from @var{path}.
40295
40296@cindex unset tdesc filename
40297@item unset tdesc filename
40298Do not read the XML target description from a file. @value{GDBN}
40299will use the description supplied by the current target.
40300
40301@cindex show tdesc filename
40302@item show tdesc filename
40303Show the filename to read for a target description, if any.
40304@end table
40305
40306
40307@node Target Description Format
40308@section Target Description Format
40309@cindex target descriptions, XML format
40310
40311A target description annex is an @uref{http://www.w3.org/XML/, XML}
40312document which complies with the Document Type Definition provided in
40313the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
40314means you can use generally available tools like @command{xmllint} to
40315check that your feature descriptions are well-formed and valid.
40316However, to help people unfamiliar with XML write descriptions for
40317their targets, we also describe the grammar here.
40318
123dc839
DJ
40319Target descriptions can identify the architecture of the remote target
40320and (for some architectures) provide information about custom register
08d16641
PA
40321sets. They can also identify the OS ABI of the remote target.
40322@value{GDBN} can use this information to autoconfigure for your
123dc839 40323target, or to warn you if you connect to an unsupported target.
23181151
DJ
40324
40325Here is a simple target description:
40326
123dc839 40327@smallexample
1780a0ed 40328<target version="1.0">
23181151
DJ
40329 <architecture>i386:x86-64</architecture>
40330</target>
123dc839 40331@end smallexample
23181151
DJ
40332
40333@noindent
40334This minimal description only says that the target uses
40335the x86-64 architecture.
40336
123dc839
DJ
40337A target description has the following overall form, with [ ] marking
40338optional elements and @dots{} marking repeatable elements. The elements
40339are explained further below.
23181151 40340
123dc839 40341@smallexample
23181151
DJ
40342<?xml version="1.0"?>
40343<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 40344<target version="1.0">
123dc839 40345 @r{[}@var{architecture}@r{]}
08d16641 40346 @r{[}@var{osabi}@r{]}
e35359c5 40347 @r{[}@var{compatible}@r{]}
123dc839 40348 @r{[}@var{feature}@dots{}@r{]}
23181151 40349</target>
123dc839 40350@end smallexample
23181151
DJ
40351
40352@noindent
40353The description is generally insensitive to whitespace and line
40354breaks, under the usual common-sense rules. The XML version
40355declaration and document type declaration can generally be omitted
40356(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
40357useful for XML validation tools. The @samp{version} attribute for
40358@samp{<target>} may also be omitted, but we recommend
40359including it; if future versions of @value{GDBN} use an incompatible
40360revision of @file{gdb-target.dtd}, they will detect and report
40361the version mismatch.
23181151 40362
108546a0
DJ
40363@subsection Inclusion
40364@cindex target descriptions, inclusion
40365@cindex XInclude
40366@ifnotinfo
40367@cindex <xi:include>
40368@end ifnotinfo
40369
40370It can sometimes be valuable to split a target description up into
40371several different annexes, either for organizational purposes, or to
40372share files between different possible target descriptions. You can
40373divide a description into multiple files by replacing any element of
40374the target description with an inclusion directive of the form:
40375
123dc839 40376@smallexample
108546a0 40377<xi:include href="@var{document}"/>
123dc839 40378@end smallexample
108546a0
DJ
40379
40380@noindent
40381When @value{GDBN} encounters an element of this form, it will retrieve
40382the named XML @var{document}, and replace the inclusion directive with
40383the contents of that document. If the current description was read
40384using @samp{qXfer}, then so will be the included document;
40385@var{document} will be interpreted as the name of an annex. If the
40386current description was read from a file, @value{GDBN} will look for
40387@var{document} as a file in the same directory where it found the
40388original description.
40389
123dc839
DJ
40390@subsection Architecture
40391@cindex <architecture>
40392
40393An @samp{<architecture>} element has this form:
40394
40395@smallexample
40396 <architecture>@var{arch}</architecture>
40397@end smallexample
40398
e35359c5
UW
40399@var{arch} is one of the architectures from the set accepted by
40400@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 40401
08d16641
PA
40402@subsection OS ABI
40403@cindex @code{<osabi>}
40404
40405This optional field was introduced in @value{GDBN} version 7.0.
40406Previous versions of @value{GDBN} ignore it.
40407
40408An @samp{<osabi>} element has this form:
40409
40410@smallexample
40411 <osabi>@var{abi-name}</osabi>
40412@end smallexample
40413
40414@var{abi-name} is an OS ABI name from the same selection accepted by
40415@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
40416
e35359c5
UW
40417@subsection Compatible Architecture
40418@cindex @code{<compatible>}
40419
40420This optional field was introduced in @value{GDBN} version 7.0.
40421Previous versions of @value{GDBN} ignore it.
40422
40423A @samp{<compatible>} element has this form:
40424
40425@smallexample
40426 <compatible>@var{arch}</compatible>
40427@end smallexample
40428
40429@var{arch} is one of the architectures from the set accepted by
40430@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
40431
40432A @samp{<compatible>} element is used to specify that the target
40433is able to run binaries in some other than the main target architecture
40434given by the @samp{<architecture>} element. For example, on the
40435Cell Broadband Engine, the main architecture is @code{powerpc:common}
40436or @code{powerpc:common64}, but the system is able to run binaries
40437in the @code{spu} architecture as well. The way to describe this
40438capability with @samp{<compatible>} is as follows:
40439
40440@smallexample
40441 <architecture>powerpc:common</architecture>
40442 <compatible>spu</compatible>
40443@end smallexample
40444
123dc839
DJ
40445@subsection Features
40446@cindex <feature>
40447
40448Each @samp{<feature>} describes some logical portion of the target
40449system. Features are currently used to describe available CPU
40450registers and the types of their contents. A @samp{<feature>} element
40451has this form:
40452
40453@smallexample
40454<feature name="@var{name}">
40455 @r{[}@var{type}@dots{}@r{]}
40456 @var{reg}@dots{}
40457</feature>
40458@end smallexample
40459
40460@noindent
40461Each feature's name should be unique within the description. The name
40462of a feature does not matter unless @value{GDBN} has some special
40463knowledge of the contents of that feature; if it does, the feature
40464should have its standard name. @xref{Standard Target Features}.
40465
40466@subsection Types
40467
40468Any register's value is a collection of bits which @value{GDBN} must
40469interpret. The default interpretation is a two's complement integer,
40470but other types can be requested by name in the register description.
40471Some predefined types are provided by @value{GDBN} (@pxref{Predefined
40472Target Types}), and the description can define additional composite types.
40473
40474Each type element must have an @samp{id} attribute, which gives
40475a unique (within the containing @samp{<feature>}) name to the type.
40476Types must be defined before they are used.
40477
40478@cindex <vector>
40479Some targets offer vector registers, which can be treated as arrays
40480of scalar elements. These types are written as @samp{<vector>} elements,
40481specifying the array element type, @var{type}, and the number of elements,
40482@var{count}:
40483
40484@smallexample
40485<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
40486@end smallexample
40487
40488@cindex <union>
40489If a register's value is usefully viewed in multiple ways, define it
40490with a union type containing the useful representations. The
40491@samp{<union>} element contains one or more @samp{<field>} elements,
40492each of which has a @var{name} and a @var{type}:
40493
40494@smallexample
40495<union id="@var{id}">
40496 <field name="@var{name}" type="@var{type}"/>
40497 @dots{}
40498</union>
40499@end smallexample
40500
f5dff777
DJ
40501@cindex <struct>
40502If a register's value is composed from several separate values, define
40503it with a structure type. There are two forms of the @samp{<struct>}
40504element; a @samp{<struct>} element must either contain only bitfields
40505or contain no bitfields. If the structure contains only bitfields,
40506its total size in bytes must be specified, each bitfield must have an
40507explicit start and end, and bitfields are automatically assigned an
40508integer type. The field's @var{start} should be less than or
40509equal to its @var{end}, and zero represents the least significant bit.
40510
40511@smallexample
40512<struct id="@var{id}" size="@var{size}">
40513 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40514 @dots{}
40515</struct>
40516@end smallexample
40517
40518If the structure contains no bitfields, then each field has an
40519explicit type, and no implicit padding is added.
40520
40521@smallexample
40522<struct id="@var{id}">
40523 <field name="@var{name}" type="@var{type}"/>
40524 @dots{}
40525</struct>
40526@end smallexample
40527
40528@cindex <flags>
40529If a register's value is a series of single-bit flags, define it with
40530a flags type. The @samp{<flags>} element has an explicit @var{size}
40531and contains one or more @samp{<field>} elements. Each field has a
40532@var{name}, a @var{start}, and an @var{end}. Only single-bit flags
40533are supported.
40534
40535@smallexample
40536<flags id="@var{id}" size="@var{size}">
40537 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40538 @dots{}
40539</flags>
40540@end smallexample
40541
123dc839
DJ
40542@subsection Registers
40543@cindex <reg>
40544
40545Each register is represented as an element with this form:
40546
40547@smallexample
40548<reg name="@var{name}"
40549 bitsize="@var{size}"
40550 @r{[}regnum="@var{num}"@r{]}
40551 @r{[}save-restore="@var{save-restore}"@r{]}
40552 @r{[}type="@var{type}"@r{]}
40553 @r{[}group="@var{group}"@r{]}/>
40554@end smallexample
40555
40556@noindent
40557The components are as follows:
40558
40559@table @var
40560
40561@item name
40562The register's name; it must be unique within the target description.
40563
40564@item bitsize
40565The register's size, in bits.
40566
40567@item regnum
40568The register's number. If omitted, a register's number is one greater
40569than that of the previous register (either in the current feature or in
177b42fe 40570a preceding feature); the first register in the target description
123dc839
DJ
40571defaults to zero. This register number is used to read or write
40572the register; e.g.@: it is used in the remote @code{p} and @code{P}
40573packets, and registers appear in the @code{g} and @code{G} packets
40574in order of increasing register number.
40575
40576@item save-restore
40577Whether the register should be preserved across inferior function
40578calls; this must be either @code{yes} or @code{no}. The default is
40579@code{yes}, which is appropriate for most registers except for
40580some system control registers; this is not related to the target's
40581ABI.
40582
40583@item type
40584The type of the register. @var{type} may be a predefined type, a type
40585defined in the current feature, or one of the special types @code{int}
40586and @code{float}. @code{int} is an integer type of the correct size
40587for @var{bitsize}, and @code{float} is a floating point type (in the
40588architecture's normal floating point format) of the correct size for
40589@var{bitsize}. The default is @code{int}.
40590
40591@item group
40592The register group to which this register belongs. @var{group} must
40593be either @code{general}, @code{float}, or @code{vector}. If no
40594@var{group} is specified, @value{GDBN} will not display the register
40595in @code{info registers}.
40596
40597@end table
40598
40599@node Predefined Target Types
40600@section Predefined Target Types
40601@cindex target descriptions, predefined types
40602
40603Type definitions in the self-description can build up composite types
40604from basic building blocks, but can not define fundamental types. Instead,
40605standard identifiers are provided by @value{GDBN} for the fundamental
40606types. The currently supported types are:
40607
40608@table @code
40609
40610@item int8
40611@itemx int16
40612@itemx int32
40613@itemx int64
7cc46491 40614@itemx int128
123dc839
DJ
40615Signed integer types holding the specified number of bits.
40616
40617@item uint8
40618@itemx uint16
40619@itemx uint32
40620@itemx uint64
7cc46491 40621@itemx uint128
123dc839
DJ
40622Unsigned integer types holding the specified number of bits.
40623
40624@item code_ptr
40625@itemx data_ptr
40626Pointers to unspecified code and data. The program counter and
40627any dedicated return address register may be marked as code
40628pointers; printing a code pointer converts it into a symbolic
40629address. The stack pointer and any dedicated address registers
40630may be marked as data pointers.
40631
6e3bbd1a
PB
40632@item ieee_single
40633Single precision IEEE floating point.
40634
40635@item ieee_double
40636Double precision IEEE floating point.
40637
123dc839
DJ
40638@item arm_fpa_ext
40639The 12-byte extended precision format used by ARM FPA registers.
40640
075b51b7
L
40641@item i387_ext
40642The 10-byte extended precision format used by x87 registers.
40643
40644@item i386_eflags
4064532bit @sc{eflags} register used by x86.
40646
40647@item i386_mxcsr
4064832bit @sc{mxcsr} register used by x86.
40649
123dc839
DJ
40650@end table
40651
40652@node Standard Target Features
40653@section Standard Target Features
40654@cindex target descriptions, standard features
40655
40656A target description must contain either no registers or all the
40657target's registers. If the description contains no registers, then
40658@value{GDBN} will assume a default register layout, selected based on
40659the architecture. If the description contains any registers, the
40660default layout will not be used; the standard registers must be
40661described in the target description, in such a way that @value{GDBN}
40662can recognize them.
40663
40664This is accomplished by giving specific names to feature elements
40665which contain standard registers. @value{GDBN} will look for features
40666with those names and verify that they contain the expected registers;
40667if any known feature is missing required registers, or if any required
40668feature is missing, @value{GDBN} will reject the target
40669description. You can add additional registers to any of the
40670standard features --- @value{GDBN} will display them just as if
40671they were added to an unrecognized feature.
40672
40673This section lists the known features and their expected contents.
40674Sample XML documents for these features are included in the
40675@value{GDBN} source tree, in the directory @file{gdb/features}.
40676
40677Names recognized by @value{GDBN} should include the name of the
40678company or organization which selected the name, and the overall
40679architecture to which the feature applies; so e.g.@: the feature
40680containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
40681
ff6f572f
DJ
40682The names of registers are not case sensitive for the purpose
40683of recognizing standard features, but @value{GDBN} will only display
40684registers using the capitalization used in the description.
40685
e9c17194
VP
40686@menu
40687* ARM Features::
3bb8d5c3 40688* i386 Features::
1e26b4f8 40689* MIPS Features::
e9c17194 40690* M68K Features::
1e26b4f8 40691* PowerPC Features::
224bbe49 40692* TIC6x Features::
e9c17194
VP
40693@end menu
40694
40695
40696@node ARM Features
123dc839
DJ
40697@subsection ARM Features
40698@cindex target descriptions, ARM features
40699
9779414d
DJ
40700The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
40701ARM targets.
123dc839
DJ
40702It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
40703@samp{lr}, @samp{pc}, and @samp{cpsr}.
40704
9779414d
DJ
40705For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
40706feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
40707registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
40708and @samp{xpsr}.
40709
123dc839
DJ
40710The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
40711should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
40712
ff6f572f
DJ
40713The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
40714it should contain at least registers @samp{wR0} through @samp{wR15} and
40715@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
40716@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 40717
58d6951d
DJ
40718The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
40719should contain at least registers @samp{d0} through @samp{d15}. If
40720they are present, @samp{d16} through @samp{d31} should also be included.
40721@value{GDBN} will synthesize the single-precision registers from
40722halves of the double-precision registers.
40723
40724The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
40725need to contain registers; it instructs @value{GDBN} to display the
40726VFP double-precision registers as vectors and to synthesize the
40727quad-precision registers from pairs of double-precision registers.
40728If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
40729be present and include 32 double-precision registers.
40730
3bb8d5c3
L
40731@node i386 Features
40732@subsection i386 Features
40733@cindex target descriptions, i386 features
40734
40735The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
40736targets. It should describe the following registers:
40737
40738@itemize @minus
40739@item
40740@samp{eax} through @samp{edi} plus @samp{eip} for i386
40741@item
40742@samp{rax} through @samp{r15} plus @samp{rip} for amd64
40743@item
40744@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
40745@samp{fs}, @samp{gs}
40746@item
40747@samp{st0} through @samp{st7}
40748@item
40749@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
40750@samp{foseg}, @samp{fooff} and @samp{fop}
40751@end itemize
40752
40753The register sets may be different, depending on the target.
40754
3a13a53b 40755The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
40756describe registers:
40757
40758@itemize @minus
40759@item
40760@samp{xmm0} through @samp{xmm7} for i386
40761@item
40762@samp{xmm0} through @samp{xmm15} for amd64
40763@item
40764@samp{mxcsr}
40765@end itemize
40766
3a13a53b
L
40767The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
40768@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
40769describe the upper 128 bits of @sc{ymm} registers:
40770
40771@itemize @minus
40772@item
40773@samp{ymm0h} through @samp{ymm7h} for i386
40774@item
40775@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
40776@end itemize
40777
3bb8d5c3
L
40778The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
40779describe a single register, @samp{orig_eax}.
40780
1e26b4f8 40781@node MIPS Features
eb17f351
EZ
40782@subsection @acronym{MIPS} Features
40783@cindex target descriptions, @acronym{MIPS} features
f8b73d13 40784
eb17f351 40785The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
40786It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
40787@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
40788on the target.
40789
40790The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
40791contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
40792registers. They may be 32-bit or 64-bit depending on the target.
40793
40794The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
40795it may be optional in a future version of @value{GDBN}. It should
40796contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
40797@samp{fir}. They may be 32-bit or 64-bit depending on the target.
40798
1faeff08
MR
40799The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
40800contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
40801@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
40802be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
40803
822b6570
DJ
40804The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
40805contain a single register, @samp{restart}, which is used by the
40806Linux kernel to control restartable syscalls.
40807
e9c17194
VP
40808@node M68K Features
40809@subsection M68K Features
40810@cindex target descriptions, M68K features
40811
40812@table @code
40813@item @samp{org.gnu.gdb.m68k.core}
40814@itemx @samp{org.gnu.gdb.coldfire.core}
40815@itemx @samp{org.gnu.gdb.fido.core}
40816One of those features must be always present.
249e1128 40817The feature that is present determines which flavor of m68k is
e9c17194
VP
40818used. The feature that is present should contain registers
40819@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
40820@samp{sp}, @samp{ps} and @samp{pc}.
40821
40822@item @samp{org.gnu.gdb.coldfire.fp}
40823This feature is optional. If present, it should contain registers
40824@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
40825@samp{fpiaddr}.
40826@end table
40827
1e26b4f8 40828@node PowerPC Features
7cc46491
DJ
40829@subsection PowerPC Features
40830@cindex target descriptions, PowerPC features
40831
40832The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
40833targets. It should contain registers @samp{r0} through @samp{r31},
40834@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
40835@samp{xer}. They may be 32-bit or 64-bit depending on the target.
40836
40837The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
40838contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
40839
40840The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
40841contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
40842and @samp{vrsave}.
40843
677c5bb1
LM
40844The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
40845contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
40846will combine these registers with the floating point registers
40847(@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
aeac0ff9 40848through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
677c5bb1
LM
40849through @samp{vs63}, the set of vector registers for POWER7.
40850
7cc46491
DJ
40851The @samp{org.gnu.gdb.power.spe} feature is optional. It should
40852contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
40853@samp{spefscr}. SPE targets should provide 32-bit registers in
40854@samp{org.gnu.gdb.power.core} and provide the upper halves in
40855@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
40856these to present registers @samp{ev0} through @samp{ev31} to the
40857user.
40858
224bbe49
YQ
40859@node TIC6x Features
40860@subsection TMS320C6x Features
40861@cindex target descriptions, TIC6x features
40862@cindex target descriptions, TMS320C6x features
40863The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
40864targets. It should contain registers @samp{A0} through @samp{A15},
40865registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
40866
40867The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
40868contain registers @samp{A16} through @samp{A31} and @samp{B16}
40869through @samp{B31}.
40870
40871The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
40872contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
40873
07e059b5
VP
40874@node Operating System Information
40875@appendix Operating System Information
40876@cindex operating system information
40877
40878@menu
40879* Process list::
40880@end menu
40881
40882Users of @value{GDBN} often wish to obtain information about the state of
40883the operating system running on the target---for example the list of
40884processes, or the list of open files. This section describes the
40885mechanism that makes it possible. This mechanism is similar to the
40886target features mechanism (@pxref{Target Descriptions}), but focuses
40887on a different aspect of target.
40888
40889Operating system information is retrived from the target via the
40890remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
40891read}). The object name in the request should be @samp{osdata}, and
40892the @var{annex} identifies the data to be fetched.
40893
40894@node Process list
40895@appendixsection Process list
40896@cindex operating system information, process list
40897
40898When requesting the process list, the @var{annex} field in the
40899@samp{qXfer} request should be @samp{processes}. The returned data is
40900an XML document. The formal syntax of this document is defined in
40901@file{gdb/features/osdata.dtd}.
40902
40903An example document is:
40904
40905@smallexample
40906<?xml version="1.0"?>
40907<!DOCTYPE target SYSTEM "osdata.dtd">
40908<osdata type="processes">
40909 <item>
40910 <column name="pid">1</column>
40911 <column name="user">root</column>
40912 <column name="command">/sbin/init</column>
dc146f7c 40913 <column name="cores">1,2,3</column>
07e059b5
VP
40914 </item>
40915</osdata>
40916@end smallexample
40917
40918Each item should include a column whose name is @samp{pid}. The value
40919of that column should identify the process on the target. The
40920@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
40921displayed by @value{GDBN}. The @samp{cores} column, if present,
40922should contain a comma-separated list of cores that this process
40923is running on. Target may provide additional columns,
07e059b5
VP
40924which @value{GDBN} currently ignores.
40925
05c8c3f5
TT
40926@node Trace File Format
40927@appendix Trace File Format
40928@cindex trace file format
40929
40930The trace file comes in three parts: a header, a textual description
40931section, and a trace frame section with binary data.
40932
40933The header has the form @code{\x7fTRACE0\n}. The first byte is
40934@code{0x7f} so as to indicate that the file contains binary data,
40935while the @code{0} is a version number that may have different values
40936in the future.
40937
40938The description section consists of multiple lines of @sc{ascii} text
40939separated by newline characters (@code{0xa}). The lines may include a
40940variety of optional descriptive or context-setting information, such
40941as tracepoint definitions or register set size. @value{GDBN} will
40942ignore any line that it does not recognize. An empty line marks the end
40943of this section.
40944
40945@c FIXME add some specific types of data
40946
40947The trace frame section consists of a number of consecutive frames.
40948Each frame begins with a two-byte tracepoint number, followed by a
40949four-byte size giving the amount of data in the frame. The data in
40950the frame consists of a number of blocks, each introduced by a
40951character indicating its type (at least register, memory, and trace
40952state variable). The data in this section is raw binary, not a
40953hexadecimal or other encoding; its endianness matches the target's
40954endianness.
40955
40956@c FIXME bi-arch may require endianness/arch info in description section
40957
40958@table @code
40959@item R @var{bytes}
40960Register block. The number and ordering of bytes matches that of a
40961@code{g} packet in the remote protocol. Note that these are the
40962actual bytes, in target order and @value{GDBN} register order, not a
40963hexadecimal encoding.
40964
40965@item M @var{address} @var{length} @var{bytes}...
40966Memory block. This is a contiguous block of memory, at the 8-byte
40967address @var{address}, with a 2-byte length @var{length}, followed by
40968@var{length} bytes.
40969
40970@item V @var{number} @var{value}
40971Trace state variable block. This records the 8-byte signed value
40972@var{value} of trace state variable numbered @var{number}.
40973
40974@end table
40975
40976Future enhancements of the trace file format may include additional types
40977of blocks.
40978
90476074
TT
40979@node Index Section Format
40980@appendix @code{.gdb_index} section format
40981@cindex .gdb_index section format
40982@cindex index section format
40983
40984This section documents the index section that is created by @code{save
40985gdb-index} (@pxref{Index Files}). The index section is
40986DWARF-specific; some knowledge of DWARF is assumed in this
40987description.
40988
40989The mapped index file format is designed to be directly
40990@code{mmap}able on any architecture. In most cases, a datum is
40991represented using a little-endian 32-bit integer value, called an
40992@code{offset_type}. Big endian machines must byte-swap the values
40993before using them. Exceptions to this rule are noted. The data is
40994laid out such that alignment is always respected.
40995
40996A mapped index consists of several areas, laid out in order.
40997
40998@enumerate
40999@item
41000The file header. This is a sequence of values, of @code{offset_type}
41001unless otherwise noted:
41002
41003@enumerate
41004@item
b6ba681c 41005The version number, currently 7. Versions 1, 2 and 3 are obsolete.
481860b3 41006Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
41007Version 6 includes symbols for inlined functions, whereas versions 4
41008and 5 do not. Version 7 adds attributes to the CU indices in the
41009symbol table. @value{GDBN} will only read version 4, 5, or 6 indices
e615022a 41010by specifying @code{set use-deprecated-index-sections on}.
90476074
TT
41011
41012@item
41013The offset, from the start of the file, of the CU list.
41014
41015@item
41016The offset, from the start of the file, of the types CU list. Note
41017that this area can be empty, in which case this offset will be equal
41018to the next offset.
41019
41020@item
41021The offset, from the start of the file, of the address area.
41022
41023@item
41024The offset, from the start of the file, of the symbol table.
41025
41026@item
41027The offset, from the start of the file, of the constant pool.
41028@end enumerate
41029
41030@item
41031The CU list. This is a sequence of pairs of 64-bit little-endian
41032values, sorted by the CU offset. The first element in each pair is
41033the offset of a CU in the @code{.debug_info} section. The second
41034element in each pair is the length of that CU. References to a CU
41035elsewhere in the map are done using a CU index, which is just the
410360-based index into this table. Note that if there are type CUs, then
41037conceptually CUs and type CUs form a single list for the purposes of
41038CU indices.
41039
41040@item
41041The types CU list. This is a sequence of triplets of 64-bit
41042little-endian values. In a triplet, the first value is the CU offset,
41043the second value is the type offset in the CU, and the third value is
41044the type signature. The types CU list is not sorted.
41045
41046@item
41047The address area. The address area consists of a sequence of address
41048entries. Each address entry has three elements:
41049
41050@enumerate
41051@item
41052The low address. This is a 64-bit little-endian value.
41053
41054@item
41055The high address. This is a 64-bit little-endian value. Like
41056@code{DW_AT_high_pc}, the value is one byte beyond the end.
41057
41058@item
41059The CU index. This is an @code{offset_type} value.
41060@end enumerate
41061
41062@item
41063The symbol table. This is an open-addressed hash table. The size of
41064the hash table is always a power of 2.
41065
41066Each slot in the hash table consists of a pair of @code{offset_type}
41067values. The first value is the offset of the symbol's name in the
41068constant pool. The second value is the offset of the CU vector in the
41069constant pool.
41070
41071If both values are 0, then this slot in the hash table is empty. This
41072is ok because while 0 is a valid constant pool index, it cannot be a
41073valid index for both a string and a CU vector.
41074
41075The hash value for a table entry is computed by applying an
41076iterative hash function to the symbol's name. Starting with an
41077initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
41078the string is incorporated into the hash using the formula depending on the
41079index version:
41080
41081@table @asis
41082@item Version 4
41083The formula is @code{r = r * 67 + c - 113}.
41084
156942c7 41085@item Versions 5 to 7
559a7a62
JK
41086The formula is @code{r = r * 67 + tolower (c) - 113}.
41087@end table
41088
41089The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
41090
41091The step size used in the hash table is computed via
41092@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
41093value, and @samp{size} is the size of the hash table. The step size
41094is used to find the next candidate slot when handling a hash
41095collision.
41096
41097The names of C@t{++} symbols in the hash table are canonicalized. We
41098don't currently have a simple description of the canonicalization
41099algorithm; if you intend to create new index sections, you must read
41100the code.
41101
41102@item
41103The constant pool. This is simply a bunch of bytes. It is organized
41104so that alignment is correct: CU vectors are stored first, followed by
41105strings.
41106
41107A CU vector in the constant pool is a sequence of @code{offset_type}
41108values. The first value is the number of CU indices in the vector.
156942c7
DE
41109Each subsequent value is the index and symbol attributes of a CU in
41110the CU list. This element in the hash table is used to indicate which
41111CUs define the symbol and how the symbol is used.
41112See below for the format of each CU index+attributes entry.
90476074
TT
41113
41114A string in the constant pool is zero-terminated.
41115@end enumerate
41116
156942c7
DE
41117Attributes were added to CU index values in @code{.gdb_index} version 7.
41118If a symbol has multiple uses within a CU then there is one
41119CU index+attributes value for each use.
41120
41121The format of each CU index+attributes entry is as follows
41122(bit 0 = LSB):
41123
41124@table @asis
41125
41126@item Bits 0-23
41127This is the index of the CU in the CU list.
41128@item Bits 24-27
41129These bits are reserved for future purposes and must be zero.
41130@item Bits 28-30
41131The kind of the symbol in the CU.
41132
41133@table @asis
41134@item 0
41135This value is reserved and should not be used.
41136By reserving zero the full @code{offset_type} value is backwards compatible
41137with previous versions of the index.
41138@item 1
41139The symbol is a type.
41140@item 2
41141The symbol is a variable or an enum value.
41142@item 3
41143The symbol is a function.
41144@item 4
41145Any other kind of symbol.
41146@item 5,6,7
41147These values are reserved.
41148@end table
41149
41150@item Bit 31
41151This bit is zero if the value is global and one if it is static.
41152
41153The determination of whether a symbol is global or static is complicated.
41154The authorative reference is the file @file{dwarf2read.c} in
41155@value{GDBN} sources.
41156
41157@end table
41158
41159This pseudo-code describes the computation of a symbol's kind and
41160global/static attributes in the index.
41161
41162@smallexample
41163is_external = get_attribute (die, DW_AT_external);
41164language = get_attribute (cu_die, DW_AT_language);
41165switch (die->tag)
41166 @{
41167 case DW_TAG_typedef:
41168 case DW_TAG_base_type:
41169 case DW_TAG_subrange_type:
41170 kind = TYPE;
41171 is_static = 1;
41172 break;
41173 case DW_TAG_enumerator:
41174 kind = VARIABLE;
41175 is_static = (language != CPLUS && language != JAVA);
41176 break;
41177 case DW_TAG_subprogram:
41178 kind = FUNCTION;
41179 is_static = ! (is_external || language == ADA);
41180 break;
41181 case DW_TAG_constant:
41182 kind = VARIABLE;
41183 is_static = ! is_external;
41184 break;
41185 case DW_TAG_variable:
41186 kind = VARIABLE;
41187 is_static = ! is_external;
41188 break;
41189 case DW_TAG_namespace:
41190 kind = TYPE;
41191 is_static = 0;
41192 break;
41193 case DW_TAG_class_type:
41194 case DW_TAG_interface_type:
41195 case DW_TAG_structure_type:
41196 case DW_TAG_union_type:
41197 case DW_TAG_enumeration_type:
41198 kind = TYPE;
41199 is_static = (language != CPLUS && language != JAVA);
41200 break;
41201 default:
41202 assert (0);
41203 @}
41204@end smallexample
41205
aab4e0ec 41206@include gpl.texi
eb12ee30 41207
e4c0cfae
SS
41208@node GNU Free Documentation License
41209@appendix GNU Free Documentation License
6826cf00
EZ
41210@include fdl.texi
41211
00595b5e
EZ
41212@node Concept Index
41213@unnumbered Concept Index
c906108c
SS
41214
41215@printindex cp
41216
00595b5e
EZ
41217@node Command and Variable Index
41218@unnumbered Command, Variable, and Function Index
41219
41220@printindex fn
41221
c906108c 41222@tex
984359d2 41223% I think something like @@colophon should be in texinfo. In the
c906108c
SS
41224% meantime:
41225\long\def\colophon{\hbox to0pt{}\vfill
41226\centerline{The body of this manual is set in}
41227\centerline{\fontname\tenrm,}
41228\centerline{with headings in {\bf\fontname\tenbf}}
41229\centerline{and examples in {\tt\fontname\tentt}.}
41230\centerline{{\it\fontname\tenit\/},}
41231\centerline{{\bf\fontname\tenbf}, and}
41232\centerline{{\sl\fontname\tensl\/}}
41233\centerline{are used for emphasis.}\vfill}
41234\page\colophon
984359d2 41235% Blame: doc@@cygnus.com, 1991.
c906108c
SS
41236@end tex
41237
c906108c 41238@bye
This page took 6.560442 seconds and 4 git commands to generate.