gdb/doc/
[external/binutils.git] / gdb / doc / gdb.texinfo
1 \input texinfo      @c -*-texinfo-*-
2 @c Copyright (C) 1988-1996, 1998-2012 Free Software Foundation, Inc.
3 @c
4 @c %**start of header
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
11 @settitle Debugging with @value{GDBN}
12 @setchapternewpage odd
13 @c %**end of header
14
15 @iftex
16 @c @smallbook
17 @c @cropmarks
18 @end iftex
19
20 @finalout
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
27
28 @c readline appendices use @vindex, @findex and @ftable,
29 @c annotate.texi and gdbmi use @findex.
30 @syncodeindex vr fn
31 @syncodeindex fn fn
32
33 @c !!set GDB manual's edition---not the same as GDB version!
34 @c This is updated by GNU Press.
35 @set EDITION Tenth
36
37 @c !!set GDB edit command default editor
38 @set EDITOR /bin/ex
39
40 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
41
42 @c This is a dir.info fragment to support semi-automated addition of
43 @c manuals to an info tree.
44 @dircategory Software development
45 @direntry
46 * Gdb: (gdb).                     The GNU debugger.
47 @end direntry
48
49 @copying
50 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
51 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
52 2011, 2012
53 Free Software Foundation, Inc.
54
55 Permission is granted to copy, distribute and/or modify this document
56 under the terms of the GNU Free Documentation License, Version 1.3 or
57 any later version published by the Free Software Foundation; with the
58 Invariant Sections being ``Free Software'' and ``Free Software Needs
59 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60 and with the Back-Cover Texts as in (a) below.
61
62 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63 this GNU Manual.  Buying copies from GNU Press supports the FSF in
64 developing GNU and promoting software freedom.''
65 @end copying
66
67 @ifnottex
68 This file documents the @sc{gnu} debugger @value{GDBN}.
69
70 This is the @value{EDITION} Edition, of @cite{Debugging with
71 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
72 @ifset VERSION_PACKAGE
73 @value{VERSION_PACKAGE}
74 @end ifset
75 Version @value{GDBVN}.
76
77 @insertcopying
78 @end ifnottex
79
80 @titlepage
81 @title Debugging with @value{GDBN}
82 @subtitle The @sc{gnu} Source-Level Debugger
83 @sp 1
84 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
85 @ifset VERSION_PACKAGE
86 @sp 1
87 @subtitle @value{VERSION_PACKAGE}
88 @end ifset
89 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
90 @page
91 @tex
92 {\parskip=0pt
93 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
94 \hfill {\it Debugging with @value{GDBN}}\par
95 \hfill \TeX{}info \texinfoversion\par
96 }
97 @end tex
98
99 @vskip 0pt plus 1filll
100 Published by the Free Software Foundation @*
101 51 Franklin Street, Fifth Floor,
102 Boston, MA 02110-1301, USA@*
103 ISBN 978-0-9831592-3-0 @*
104
105 @insertcopying
106 @end titlepage
107 @page
108
109 @ifnottex
110 @node Top, Summary, (dir), (dir)
111
112 @top Debugging with @value{GDBN}
113
114 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
115
116 This is the @value{EDITION} Edition, for @value{GDBN}
117 @ifset VERSION_PACKAGE
118 @value{VERSION_PACKAGE}
119 @end ifset
120 Version @value{GDBVN}.
121
122 Copyright (C) 1988-2012 Free Software Foundation, Inc.
123
124 This edition of the GDB manual is dedicated to the memory of Fred
125 Fish.  Fred was a long-standing contributor to GDB and to Free
126 software in general.  We will miss him.
127
128 @menu
129 * Summary::                     Summary of @value{GDBN}
130 * Sample Session::              A sample @value{GDBN} session
131
132 * Invocation::                  Getting in and out of @value{GDBN}
133 * Commands::                    @value{GDBN} commands
134 * Running::                     Running programs under @value{GDBN}
135 * Stopping::                    Stopping and continuing
136 * Reverse Execution::           Running programs backward
137 * Process Record and Replay::   Recording inferior's execution and replaying it
138 * Stack::                       Examining the stack
139 * Source::                      Examining source files
140 * Data::                        Examining data
141 * Optimized Code::              Debugging optimized code
142 * Macros::                      Preprocessor Macros
143 * Tracepoints::                 Debugging remote targets non-intrusively
144 * Overlays::                    Debugging programs that use overlays
145
146 * Languages::                   Using @value{GDBN} with different languages
147
148 * Symbols::                     Examining the symbol table
149 * Altering::                    Altering execution
150 * GDB Files::                   @value{GDBN} files
151 * Targets::                     Specifying a debugging target
152 * Remote Debugging::            Debugging remote programs
153 * Configurations::              Configuration-specific information
154 * Controlling GDB::             Controlling @value{GDBN}
155 * Extending GDB::               Extending @value{GDBN}
156 * Interpreters::                Command Interpreters
157 * TUI::                         @value{GDBN} Text User Interface
158 * Emacs::                       Using @value{GDBN} under @sc{gnu} Emacs
159 * GDB/MI::                      @value{GDBN}'s Machine Interface.
160 * Annotations::                 @value{GDBN}'s annotation interface.
161 * JIT Interface::               Using the JIT debugging interface.
162 * In-Process Agent::            In-Process Agent
163
164 * GDB Bugs::                    Reporting bugs in @value{GDBN}
165
166 @ifset SYSTEM_READLINE
167 * Command Line Editing: (rluserman).         Command Line Editing
168 * Using History Interactively: (history).    Using History Interactively
169 @end ifset
170 @ifclear SYSTEM_READLINE
171 * Command Line Editing::        Command Line Editing
172 * Using History Interactively:: Using History Interactively
173 @end ifclear
174 * In Memoriam::                 In Memoriam
175 * Formatting Documentation::    How to format and print @value{GDBN} documentation
176 * Installing GDB::              Installing GDB
177 * Maintenance Commands::        Maintenance Commands
178 * Remote Protocol::             GDB Remote Serial Protocol
179 * Agent Expressions::           The GDB Agent Expression Mechanism
180 * Target Descriptions::         How targets can describe themselves to
181                                 @value{GDBN}
182 * Operating System Information:: Getting additional information from
183                                  the operating system
184 * Trace File Format::           GDB trace file format
185 * Index Section Format::        .gdb_index section format
186 * Copying::                     GNU General Public License says
187                                 how you can copy and share GDB
188 * GNU Free Documentation License::  The license for this documentation
189 * Concept Index::               Index of @value{GDBN} concepts
190 * Command and Variable Index::  Index of @value{GDBN} commands, variables,
191                                   functions, and Python data types
192 @end menu
193
194 @end ifnottex
195
196 @contents
197
198 @node Summary
199 @unnumbered Summary of @value{GDBN}
200
201 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
202 going on ``inside'' another program while it executes---or what another
203 program was doing at the moment it crashed.
204
205 @value{GDBN} can do four main kinds of things (plus other things in support of
206 these) to help you catch bugs in the act:
207
208 @itemize @bullet
209 @item
210 Start your program, specifying anything that might affect its behavior.
211
212 @item
213 Make your program stop on specified conditions.
214
215 @item
216 Examine what has happened, when your program has stopped.
217
218 @item
219 Change things in your program, so you can experiment with correcting the
220 effects of one bug and go on to learn about another.
221 @end itemize
222
223 You can use @value{GDBN} to debug programs written in C and C@t{++}.
224 For more information, see @ref{Supported Languages,,Supported Languages}.
225 For more information, see @ref{C,,C and C++}.
226
227 Support for D is partial.  For information on D, see
228 @ref{D,,D}.
229
230 @cindex Modula-2
231 Support for Modula-2 is partial.  For information on Modula-2, see
232 @ref{Modula-2,,Modula-2}.
233
234 Support for OpenCL C is partial.  For information on OpenCL C, see
235 @ref{OpenCL C,,OpenCL C}.
236
237 @cindex Pascal
238 Debugging Pascal programs which use sets, subranges, file variables, or
239 nested functions does not currently work.  @value{GDBN} does not support
240 entering expressions, printing values, or similar features using Pascal
241 syntax.
242
243 @cindex Fortran
244 @value{GDBN} can be used to debug programs written in Fortran, although
245 it may be necessary to refer to some variables with a trailing
246 underscore.
247
248 @value{GDBN} can be used to debug programs written in Objective-C,
249 using either the Apple/NeXT or the GNU Objective-C runtime.
250
251 @menu
252 * Free Software::               Freely redistributable software
253 * Free Documentation::          Free Software Needs Free Documentation
254 * Contributors::                Contributors to GDB
255 @end menu
256
257 @node Free Software
258 @unnumberedsec Free Software
259
260 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
261 General Public License
262 (GPL).  The GPL gives you the freedom to copy or adapt a licensed
263 program---but every person getting a copy also gets with it the
264 freedom to modify that copy (which means that they must get access to
265 the source code), and the freedom to distribute further copies.
266 Typical software companies use copyrights to limit your freedoms; the
267 Free Software Foundation uses the GPL to preserve these freedoms.
268
269 Fundamentally, the General Public License is a license which says that
270 you have these freedoms and that you cannot take these freedoms away
271 from anyone else.
272
273 @node Free Documentation
274 @unnumberedsec Free Software Needs Free Documentation
275
276 The biggest deficiency in the free software community today is not in
277 the software---it is the lack of good free documentation that we can
278 include with the free software.  Many of our most important
279 programs do not come with free reference manuals and free introductory
280 texts.  Documentation is an essential part of any software package;
281 when an important free software package does not come with a free
282 manual and a free tutorial, that is a major gap.  We have many such
283 gaps today.
284
285 Consider Perl, for instance.  The tutorial manuals that people
286 normally use are non-free.  How did this come about?  Because the
287 authors of those manuals published them with restrictive terms---no
288 copying, no modification, source files not available---which exclude
289 them from the free software world.
290
291 That wasn't the first time this sort of thing happened, and it was far
292 from the last.  Many times we have heard a GNU user eagerly describe a
293 manual that he is writing, his intended contribution to the community,
294 only to learn that he had ruined everything by signing a publication
295 contract to make it non-free.
296
297 Free documentation, like free software, is a matter of freedom, not
298 price.  The problem with the non-free manual is not that publishers
299 charge a price for printed copies---that in itself is fine.  (The Free
300 Software Foundation sells printed copies of manuals, too.)  The
301 problem is the restrictions on the use of the manual.  Free manuals
302 are available in source code form, and give you permission to copy and
303 modify.  Non-free manuals do not allow this.
304
305 The criteria of freedom for a free manual are roughly the same as for
306 free software.  Redistribution (including the normal kinds of
307 commercial redistribution) must be permitted, so that the manual can
308 accompany every copy of the program, both on-line and on paper.
309
310 Permission for modification of the technical content is crucial too.
311 When people modify the software, adding or changing features, if they
312 are conscientious they will change the manual too---so they can
313 provide accurate and clear documentation for the modified program.  A
314 manual that leaves you no choice but to write a new manual to document
315 a changed version of the program is not really available to our
316 community.
317
318 Some kinds of limits on the way modification is handled are
319 acceptable.  For example, requirements to preserve the original
320 author's copyright notice, the distribution terms, or the list of
321 authors, are ok.  It is also no problem to require modified versions
322 to include notice that they were modified.  Even entire sections that
323 may not be deleted or changed are acceptable, as long as they deal
324 with nontechnical topics (like this one).  These kinds of restrictions
325 are acceptable because they don't obstruct the community's normal use
326 of the manual.
327
328 However, it must be possible to modify all the @emph{technical}
329 content of the manual, and then distribute the result in all the usual
330 media, through all the usual channels.  Otherwise, the restrictions
331 obstruct the use of the manual, it is not free, and we need another
332 manual to replace it.
333
334 Please spread the word about this issue.  Our community continues to
335 lose manuals to proprietary publishing.  If we spread the word that
336 free software needs free reference manuals and free tutorials, perhaps
337 the next person who wants to contribute by writing documentation will
338 realize, before it is too late, that only free manuals contribute to
339 the free software community.
340
341 If you are writing documentation, please insist on publishing it under
342 the GNU Free Documentation License or another free documentation
343 license.  Remember that this decision requires your approval---you
344 don't have to let the publisher decide.  Some commercial publishers
345 will use a free license if you insist, but they will not propose the
346 option; it is up to you to raise the issue and say firmly that this is
347 what you want.  If the publisher you are dealing with refuses, please
348 try other publishers.  If you're not sure whether a proposed license
349 is free, write to @email{licensing@@gnu.org}.
350
351 You can encourage commercial publishers to sell more free, copylefted
352 manuals and tutorials by buying them, and particularly by buying
353 copies from the publishers that paid for their writing or for major
354 improvements.  Meanwhile, try to avoid buying non-free documentation
355 at all.  Check the distribution terms of a manual before you buy it,
356 and insist that whoever seeks your business must respect your freedom.
357 Check the history of the book, and try to reward the publishers that
358 have paid or pay the authors to work on it.
359
360 The Free Software Foundation maintains a list of free documentation
361 published by other publishers, at
362 @url{http://www.fsf.org/doc/other-free-books.html}.
363
364 @node Contributors
365 @unnumberedsec Contributors to @value{GDBN}
366
367 Richard Stallman was the original author of @value{GDBN}, and of many
368 other @sc{gnu} programs.  Many others have contributed to its
369 development.  This section attempts to credit major contributors.  One
370 of the virtues of free software is that everyone is free to contribute
371 to it; with regret, we cannot actually acknowledge everyone here.  The
372 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
373 blow-by-blow account.
374
375 Changes much prior to version 2.0 are lost in the mists of time.
376
377 @quotation
378 @emph{Plea:} Additions to this section are particularly welcome.  If you
379 or your friends (or enemies, to be evenhanded) have been unfairly
380 omitted from this list, we would like to add your names!
381 @end quotation
382
383 So that they may not regard their many labors as thankless, we
384 particularly thank those who shepherded @value{GDBN} through major
385 releases:
386 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
387 Jim Blandy (release 4.18);
388 Jason Molenda (release 4.17);
389 Stan Shebs (release 4.14);
390 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
391 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
392 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
393 Jim Kingdon (releases 3.5, 3.4, and 3.3);
394 and Randy Smith (releases 3.2, 3.1, and 3.0).
395
396 Richard Stallman, assisted at various times by Peter TerMaat, Chris
397 Hanson, and Richard Mlynarik, handled releases through 2.8.
398
399 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
400 in @value{GDBN}, with significant additional contributions from Per
401 Bothner and Daniel Berlin.  James Clark wrote the @sc{gnu} C@t{++}
402 demangler.  Early work on C@t{++} was by Peter TerMaat (who also did
403 much general update work leading to release 3.0).
404
405 @value{GDBN} uses the BFD subroutine library to examine multiple
406 object-file formats; BFD was a joint project of David V.
407 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
408
409 David Johnson wrote the original COFF support; Pace Willison did
410 the original support for encapsulated COFF.
411
412 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
413
414 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
415 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
416 support.
417 Jean-Daniel Fekete contributed Sun 386i support.
418 Chris Hanson improved the HP9000 support.
419 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
420 David Johnson contributed Encore Umax support.
421 Jyrki Kuoppala contributed Altos 3068 support.
422 Jeff Law contributed HP PA and SOM support.
423 Keith Packard contributed NS32K support.
424 Doug Rabson contributed Acorn Risc Machine support.
425 Bob Rusk contributed Harris Nighthawk CX-UX support.
426 Chris Smith contributed Convex support (and Fortran debugging).
427 Jonathan Stone contributed Pyramid support.
428 Michael Tiemann contributed SPARC support.
429 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
430 Pace Willison contributed Intel 386 support.
431 Jay Vosburgh contributed Symmetry support.
432 Marko Mlinar contributed OpenRISC 1000 support.
433
434 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
435
436 Rich Schaefer and Peter Schauer helped with support of SunOS shared
437 libraries.
438
439 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
440 about several machine instruction sets.
441
442 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
443 remote debugging.  Intel Corporation, Wind River Systems, AMD, and ARM
444 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
445 and RDI targets, respectively.
446
447 Brian Fox is the author of the readline libraries providing
448 command-line editing and command history.
449
450 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
451 Modula-2 support, and contributed the Languages chapter of this manual.
452
453 Fred Fish wrote most of the support for Unix System Vr4.
454 He also enhanced the command-completion support to cover C@t{++} overloaded
455 symbols.
456
457 Hitachi America (now Renesas America), Ltd. sponsored the support for
458 H8/300, H8/500, and Super-H processors.
459
460 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
461
462 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
463 processors.
464
465 Toshiba sponsored the support for the TX39 Mips processor.
466
467 Matsushita sponsored the support for the MN10200 and MN10300 processors.
468
469 Fujitsu sponsored the support for SPARClite and FR30 processors.
470
471 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
472 watchpoints.
473
474 Michael Snyder added support for tracepoints.
475
476 Stu Grossman wrote gdbserver.
477
478 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
479 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
480
481 The following people at the Hewlett-Packard Company contributed
482 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
483 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
484 compiler, and the Text User Interface (nee Terminal User Interface):
485 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
486 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni.  Kim Haase
487 provided HP-specific information in this manual.
488
489 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
490 Robert Hoehne made significant contributions to the DJGPP port.
491
492 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
493 development since 1991.  Cygnus engineers who have worked on @value{GDBN}
494 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
495 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
496 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
497 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
498 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni.  In
499 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
500 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
501 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
502 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
503 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
504 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
505 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
506 Zuhn have made contributions both large and small.
507
508 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
509 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
510
511 Jim Blandy added support for preprocessor macros, while working for Red
512 Hat.
513
514 Andrew Cagney designed @value{GDBN}'s architecture vector.  Many
515 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
516 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
517 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
518 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
519 with the migration of old architectures to this new framework.
520
521 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
522 unwinder framework, this consisting of a fresh new design featuring
523 frame IDs, independent frame sniffers, and the sentinel frame.  Mark
524 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
525 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
526 trad unwinders.  The architecture-specific changes, each involving a
527 complete rewrite of the architecture's frame code, were carried out by
528 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
529 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
530 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
531 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
532 Weigand.
533
534 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
535 Tensilica, Inc.@: contributed support for Xtensa processors.  Others
536 who have worked on the Xtensa port of @value{GDBN} in the past include
537 Steve Tjiang, John Newlin, and Scott Foehner.
538
539 Michael Eager and staff of Xilinx, Inc., contributed support for the
540 Xilinx MicroBlaze architecture.
541
542 @node Sample Session
543 @chapter A Sample @value{GDBN} Session
544
545 You can use this manual at your leisure to read all about @value{GDBN}.
546 However, a handful of commands are enough to get started using the
547 debugger.  This chapter illustrates those commands.
548
549 @iftex
550 In this sample session, we emphasize user input like this: @b{input},
551 to make it easier to pick out from the surrounding output.
552 @end iftex
553
554 @c FIXME: this example may not be appropriate for some configs, where
555 @c FIXME...primary interest is in remote use.
556
557 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
558 processor) exhibits the following bug: sometimes, when we change its
559 quote strings from the default, the commands used to capture one macro
560 definition within another stop working.  In the following short @code{m4}
561 session, we define a macro @code{foo} which expands to @code{0000}; we
562 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
563 same thing.  However, when we change the open quote string to
564 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
565 procedure fails to define a new synonym @code{baz}:
566
567 @smallexample
568 $ @b{cd gnu/m4}
569 $ @b{./m4}
570 @b{define(foo,0000)}
571
572 @b{foo}
573 0000
574 @b{define(bar,defn(`foo'))}
575
576 @b{bar}
577 0000
578 @b{changequote(<QUOTE>,<UNQUOTE>)}
579
580 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
581 @b{baz}
582 @b{Ctrl-d}
583 m4: End of input: 0: fatal error: EOF in string
584 @end smallexample
585
586 @noindent
587 Let us use @value{GDBN} to try to see what is going on.
588
589 @smallexample
590 $ @b{@value{GDBP} m4}
591 @c FIXME: this falsifies the exact text played out, to permit smallbook
592 @c FIXME... format to come out better.
593 @value{GDBN} is free software and you are welcome to distribute copies
594  of it under certain conditions; type "show copying" to see
595  the conditions.
596 There is absolutely no warranty for @value{GDBN}; type "show warranty"
597  for details.
598
599 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
600 (@value{GDBP})
601 @end smallexample
602
603 @noindent
604 @value{GDBN} reads only enough symbol data to know where to find the
605 rest when needed; as a result, the first prompt comes up very quickly.
606 We now tell @value{GDBN} to use a narrower display width than usual, so
607 that examples fit in this manual.
608
609 @smallexample
610 (@value{GDBP}) @b{set width 70}
611 @end smallexample
612
613 @noindent
614 We need to see how the @code{m4} built-in @code{changequote} works.
615 Having looked at the source, we know the relevant subroutine is
616 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
617 @code{break} command.
618
619 @smallexample
620 (@value{GDBP}) @b{break m4_changequote}
621 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
622 @end smallexample
623
624 @noindent
625 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
626 control; as long as control does not reach the @code{m4_changequote}
627 subroutine, the program runs as usual:
628
629 @smallexample
630 (@value{GDBP}) @b{run}
631 Starting program: /work/Editorial/gdb/gnu/m4/m4
632 @b{define(foo,0000)}
633
634 @b{foo}
635 0000
636 @end smallexample
637
638 @noindent
639 To trigger the breakpoint, we call @code{changequote}.  @value{GDBN}
640 suspends execution of @code{m4}, displaying information about the
641 context where it stops.
642
643 @smallexample
644 @b{changequote(<QUOTE>,<UNQUOTE>)}
645
646 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
647     at builtin.c:879
648 879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
649 @end smallexample
650
651 @noindent
652 Now we use the command @code{n} (@code{next}) to advance execution to
653 the next line of the current function.
654
655 @smallexample
656 (@value{GDBP}) @b{n}
657 882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
658  : nil,
659 @end smallexample
660
661 @noindent
662 @code{set_quotes} looks like a promising subroutine.  We can go into it
663 by using the command @code{s} (@code{step}) instead of @code{next}.
664 @code{step} goes to the next line to be executed in @emph{any}
665 subroutine, so it steps into @code{set_quotes}.
666
667 @smallexample
668 (@value{GDBP}) @b{s}
669 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
670     at input.c:530
671 530         if (lquote != def_lquote)
672 @end smallexample
673
674 @noindent
675 The display that shows the subroutine where @code{m4} is now
676 suspended (and its arguments) is called a stack frame display.  It
677 shows a summary of the stack.  We can use the @code{backtrace}
678 command (which can also be spelled @code{bt}), to see where we are
679 in the stack as a whole: the @code{backtrace} command displays a
680 stack frame for each active subroutine.
681
682 @smallexample
683 (@value{GDBP}) @b{bt}
684 #0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
685     at input.c:530
686 #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
687     at builtin.c:882
688 #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
689 #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
690     at macro.c:71
691 #4  0x79dc in expand_input () at macro.c:40
692 #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
693 @end smallexample
694
695 @noindent
696 We step through a few more lines to see what happens.  The first two
697 times, we can use @samp{s}; the next two times we use @code{n} to avoid
698 falling into the @code{xstrdup} subroutine.
699
700 @smallexample
701 (@value{GDBP}) @b{s}
702 0x3b5c  532         if (rquote != def_rquote)
703 (@value{GDBP}) @b{s}
704 0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
705 def_lquote : xstrdup(lq);
706 (@value{GDBP}) @b{n}
707 536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
708  : xstrdup(rq);
709 (@value{GDBP}) @b{n}
710 538         len_lquote = strlen(rquote);
711 @end smallexample
712
713 @noindent
714 The last line displayed looks a little odd; we can examine the variables
715 @code{lquote} and @code{rquote} to see if they are in fact the new left
716 and right quotes we specified.  We use the command @code{p}
717 (@code{print}) to see their values.
718
719 @smallexample
720 (@value{GDBP}) @b{p lquote}
721 $1 = 0x35d40 "<QUOTE>"
722 (@value{GDBP}) @b{p rquote}
723 $2 = 0x35d50 "<UNQUOTE>"
724 @end smallexample
725
726 @noindent
727 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
728 To look at some context, we can display ten lines of source
729 surrounding the current line with the @code{l} (@code{list}) command.
730
731 @smallexample
732 (@value{GDBP}) @b{l}
733 533             xfree(rquote);
734 534
735 535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
736  : xstrdup (lq);
737 536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
738  : xstrdup (rq);
739 537
740 538         len_lquote = strlen(rquote);
741 539         len_rquote = strlen(lquote);
742 540     @}
743 541
744 542     void
745 @end smallexample
746
747 @noindent
748 Let us step past the two lines that set @code{len_lquote} and
749 @code{len_rquote}, and then examine the values of those variables.
750
751 @smallexample
752 (@value{GDBP}) @b{n}
753 539         len_rquote = strlen(lquote);
754 (@value{GDBP}) @b{n}
755 540     @}
756 (@value{GDBP}) @b{p len_lquote}
757 $3 = 9
758 (@value{GDBP}) @b{p len_rquote}
759 $4 = 7
760 @end smallexample
761
762 @noindent
763 That certainly looks wrong, assuming @code{len_lquote} and
764 @code{len_rquote} are meant to be the lengths of @code{lquote} and
765 @code{rquote} respectively.  We can set them to better values using
766 the @code{p} command, since it can print the value of
767 any expression---and that expression can include subroutine calls and
768 assignments.
769
770 @smallexample
771 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
772 $5 = 7
773 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
774 $6 = 9
775 @end smallexample
776
777 @noindent
778 Is that enough to fix the problem of using the new quotes with the
779 @code{m4} built-in @code{defn}?  We can allow @code{m4} to continue
780 executing with the @code{c} (@code{continue}) command, and then try the
781 example that caused trouble initially:
782
783 @smallexample
784 (@value{GDBP}) @b{c}
785 Continuing.
786
787 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
788
789 baz
790 0000
791 @end smallexample
792
793 @noindent
794 Success!  The new quotes now work just as well as the default ones.  The
795 problem seems to have been just the two typos defining the wrong
796 lengths.  We allow @code{m4} exit by giving it an EOF as input:
797
798 @smallexample
799 @b{Ctrl-d}
800 Program exited normally.
801 @end smallexample
802
803 @noindent
804 The message @samp{Program exited normally.} is from @value{GDBN}; it
805 indicates @code{m4} has finished executing.  We can end our @value{GDBN}
806 session with the @value{GDBN} @code{quit} command.
807
808 @smallexample
809 (@value{GDBP}) @b{quit}
810 @end smallexample
811
812 @node Invocation
813 @chapter Getting In and Out of @value{GDBN}
814
815 This chapter discusses how to start @value{GDBN}, and how to get out of it.
816 The essentials are:
817 @itemize @bullet
818 @item
819 type @samp{@value{GDBP}} to start @value{GDBN}.
820 @item
821 type @kbd{quit} or @kbd{Ctrl-d} to exit.
822 @end itemize
823
824 @menu
825 * Invoking GDB::                How to start @value{GDBN}
826 * Quitting GDB::                How to quit @value{GDBN}
827 * Shell Commands::              How to use shell commands inside @value{GDBN}
828 * Logging Output::              How to log @value{GDBN}'s output to a file
829 @end menu
830
831 @node Invoking GDB
832 @section Invoking @value{GDBN}
833
834 Invoke @value{GDBN} by running the program @code{@value{GDBP}}.  Once started,
835 @value{GDBN} reads commands from the terminal until you tell it to exit.
836
837 You can also run @code{@value{GDBP}} with a variety of arguments and options,
838 to specify more of your debugging environment at the outset.
839
840 The command-line options described here are designed
841 to cover a variety of situations; in some environments, some of these
842 options may effectively be unavailable.
843
844 The most usual way to start @value{GDBN} is with one argument,
845 specifying an executable program:
846
847 @smallexample
848 @value{GDBP} @var{program}
849 @end smallexample
850
851 @noindent
852 You can also start with both an executable program and a core file
853 specified:
854
855 @smallexample
856 @value{GDBP} @var{program} @var{core}
857 @end smallexample
858
859 You can, instead, specify a process ID as a second argument, if you want
860 to debug a running process:
861
862 @smallexample
863 @value{GDBP} @var{program} 1234
864 @end smallexample
865
866 @noindent
867 would attach @value{GDBN} to process @code{1234} (unless you also have a file
868 named @file{1234}; @value{GDBN} does check for a core file first).
869
870 Taking advantage of the second command-line argument requires a fairly
871 complete operating system; when you use @value{GDBN} as a remote
872 debugger attached to a bare board, there may not be any notion of
873 ``process'', and there is often no way to get a core dump.  @value{GDBN}
874 will warn you if it is unable to attach or to read core dumps.
875
876 You can optionally have @code{@value{GDBP}} pass any arguments after the
877 executable file to the inferior using @code{--args}.  This option stops
878 option processing.
879 @smallexample
880 @value{GDBP} --args gcc -O2 -c foo.c
881 @end smallexample
882 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
883 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
884
885 You can run @code{@value{GDBP}} without printing the front material, which describes
886 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
887
888 @smallexample
889 @value{GDBP} -silent
890 @end smallexample
891
892 @noindent
893 You can further control how @value{GDBN} starts up by using command-line
894 options.  @value{GDBN} itself can remind you of the options available.
895
896 @noindent
897 Type
898
899 @smallexample
900 @value{GDBP} -help
901 @end smallexample
902
903 @noindent
904 to display all available options and briefly describe their use
905 (@samp{@value{GDBP} -h} is a shorter equivalent).
906
907 All options and command line arguments you give are processed
908 in sequential order.  The order makes a difference when the
909 @samp{-x} option is used.
910
911
912 @menu
913 * File Options::                Choosing files
914 * Mode Options::                Choosing modes
915 * Startup::                     What @value{GDBN} does during startup
916 @end menu
917
918 @node File Options
919 @subsection Choosing Files
920
921 When @value{GDBN} starts, it reads any arguments other than options as
922 specifying an executable file and core file (or process ID).  This is
923 the same as if the arguments were specified by the @samp{-se} and
924 @samp{-c} (or @samp{-p}) options respectively.  (@value{GDBN} reads the
925 first argument that does not have an associated option flag as
926 equivalent to the @samp{-se} option followed by that argument; and the
927 second argument that does not have an associated option flag, if any, as
928 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
929 If the second argument begins with a decimal digit, @value{GDBN} will
930 first attempt to attach to it as a process, and if that fails, attempt
931 to open it as a corefile.  If you have a corefile whose name begins with
932 a digit, you can prevent @value{GDBN} from treating it as a pid by
933 prefixing it with @file{./}, e.g.@: @file{./12345}.
934
935 If @value{GDBN} has not been configured to included core file support,
936 such as for most embedded targets, then it will complain about a second
937 argument and ignore it.
938
939 Many options have both long and short forms; both are shown in the
940 following list.  @value{GDBN} also recognizes the long forms if you truncate
941 them, so long as enough of the option is present to be unambiguous.
942 (If you prefer, you can flag option arguments with @samp{--} rather
943 than @samp{-}, though we illustrate the more usual convention.)
944
945 @c NOTE: the @cindex entries here use double dashes ON PURPOSE.  This
946 @c way, both those who look for -foo and --foo in the index, will find
947 @c it.
948
949 @table @code
950 @item -symbols @var{file}
951 @itemx -s @var{file}
952 @cindex @code{--symbols}
953 @cindex @code{-s}
954 Read symbol table from file @var{file}.
955
956 @item -exec @var{file}
957 @itemx -e @var{file}
958 @cindex @code{--exec}
959 @cindex @code{-e}
960 Use file @var{file} as the executable file to execute when appropriate,
961 and for examining pure data in conjunction with a core dump.
962
963 @item -se @var{file}
964 @cindex @code{--se}
965 Read symbol table from file @var{file} and use it as the executable
966 file.
967
968 @item -core @var{file}
969 @itemx -c @var{file}
970 @cindex @code{--core}
971 @cindex @code{-c}
972 Use file @var{file} as a core dump to examine.
973
974 @item -pid @var{number}
975 @itemx -p @var{number}
976 @cindex @code{--pid}
977 @cindex @code{-p}
978 Connect to process ID @var{number}, as with the @code{attach} command.
979
980 @item -command @var{file}
981 @itemx -x @var{file}
982 @cindex @code{--command}
983 @cindex @code{-x}
984 Execute commands from file @var{file}.  The contents of this file is
985 evaluated exactly as the @code{source} command would.
986 @xref{Command Files,, Command files}.
987
988 @item -eval-command @var{command}
989 @itemx -ex @var{command}
990 @cindex @code{--eval-command}
991 @cindex @code{-ex}
992 Execute a single @value{GDBN} command.
993
994 This option may be used multiple times to call multiple commands.  It may
995 also be interleaved with @samp{-command} as required.
996
997 @smallexample
998 @value{GDBP} -ex 'target sim' -ex 'load' \
999    -x setbreakpoints -ex 'run' a.out
1000 @end smallexample
1001
1002 @item -init-command @var{file}
1003 @itemx -ix @var{file}
1004 @cindex @code{--init-command}
1005 @cindex @code{-ix}
1006 Execute commands from file @var{file} before loading the inferior (but
1007 after loading gdbinit files).
1008 @xref{Startup}.
1009
1010 @item -init-eval-command @var{command}
1011 @itemx -iex @var{command}
1012 @cindex @code{--init-eval-command}
1013 @cindex @code{-iex}
1014 Execute a single @value{GDBN} command before loading the inferior (but
1015 after loading gdbinit files).
1016 @xref{Startup}.
1017
1018 @item -directory @var{directory}
1019 @itemx -d @var{directory}
1020 @cindex @code{--directory}
1021 @cindex @code{-d}
1022 Add @var{directory} to the path to search for source and script files.
1023
1024 @item -r
1025 @itemx -readnow
1026 @cindex @code{--readnow}
1027 @cindex @code{-r}
1028 Read each symbol file's entire symbol table immediately, rather than
1029 the default, which is to read it incrementally as it is needed.
1030 This makes startup slower, but makes future operations faster.
1031
1032 @end table
1033
1034 @node Mode Options
1035 @subsection Choosing Modes
1036
1037 You can run @value{GDBN} in various alternative modes---for example, in
1038 batch mode or quiet mode.
1039
1040 @table @code
1041 @anchor{-nx}
1042 @item -nx
1043 @itemx -n
1044 @cindex @code{--nx}
1045 @cindex @code{-n}
1046 Do not execute commands found in any initialization file.
1047 There are three init files, loaded in the following order:
1048
1049 @table @code
1050 @item @file{system.gdbinit}
1051 This is the system-wide init file.
1052 Its location is specified with the @code{--with-system-gdbinit}
1053 configure option (@pxref{System-wide configuration}).
1054 It is loaded first when @value{GDBN} starts, before command line options
1055 have been processed.
1056 @item @file{~/.gdbinit}
1057 This is the init file in your home directory.
1058 It is loaded next, after @file{system.gdbinit}, and before
1059 command options have been processed.
1060 @item @file{./.gdbinit}
1061 This is the init file in the current directory.
1062 It is loaded last, after command line options other than @code{-x} and
1063 @code{-ex} have been processed.  Command line options @code{-x} and
1064 @code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1065 @end table
1066
1067 For further documentation on startup processing, @xref{Startup}.
1068 For documentation on how to write command files,
1069 @xref{Command Files,,Command Files}.
1070
1071 @anchor{-nh}
1072 @item -nh
1073 @cindex @code{--nh}
1074 Do not execute commands found in @file{~/.gdbinit}, the init file
1075 in your home directory.
1076 @xref{Startup}.
1077
1078 @item -quiet
1079 @itemx -silent
1080 @itemx -q
1081 @cindex @code{--quiet}
1082 @cindex @code{--silent}
1083 @cindex @code{-q}
1084 ``Quiet''.  Do not print the introductory and copyright messages.  These
1085 messages are also suppressed in batch mode.
1086
1087 @item -batch
1088 @cindex @code{--batch}
1089 Run in batch mode.  Exit with status @code{0} after processing all the
1090 command files specified with @samp{-x} (and all commands from
1091 initialization files, if not inhibited with @samp{-n}).  Exit with
1092 nonzero status if an error occurs in executing the @value{GDBN} commands
1093 in the command files.  Batch mode also disables pagination, sets unlimited
1094 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1095 off} were in effect (@pxref{Messages/Warnings}).
1096
1097 Batch mode may be useful for running @value{GDBN} as a filter, for
1098 example to download and run a program on another computer; in order to
1099 make this more useful, the message
1100
1101 @smallexample
1102 Program exited normally.
1103 @end smallexample
1104
1105 @noindent
1106 (which is ordinarily issued whenever a program running under
1107 @value{GDBN} control terminates) is not issued when running in batch
1108 mode.
1109
1110 @item -batch-silent
1111 @cindex @code{--batch-silent}
1112 Run in batch mode exactly like @samp{-batch}, but totally silently.  All
1113 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1114 unaffected).  This is much quieter than @samp{-silent} and would be useless
1115 for an interactive session.
1116
1117 This is particularly useful when using targets that give @samp{Loading section}
1118 messages, for example.
1119
1120 Note that targets that give their output via @value{GDBN}, as opposed to
1121 writing directly to @code{stdout}, will also be made silent.
1122
1123 @item -return-child-result
1124 @cindex @code{--return-child-result}
1125 The return code from @value{GDBN} will be the return code from the child
1126 process (the process being debugged), with the following exceptions:
1127
1128 @itemize @bullet
1129 @item
1130 @value{GDBN} exits abnormally.  E.g., due to an incorrect argument or an
1131 internal error.  In this case the exit code is the same as it would have been
1132 without @samp{-return-child-result}.
1133 @item
1134 The user quits with an explicit value.  E.g., @samp{quit 1}.
1135 @item
1136 The child process never runs, or is not allowed to terminate, in which case
1137 the exit code will be -1.
1138 @end itemize
1139
1140 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1141 when @value{GDBN} is being used as a remote program loader or simulator
1142 interface.
1143
1144 @item -nowindows
1145 @itemx -nw
1146 @cindex @code{--nowindows}
1147 @cindex @code{-nw}
1148 ``No windows''.  If @value{GDBN} comes with a graphical user interface
1149 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1150 interface.  If no GUI is available, this option has no effect.
1151
1152 @item -windows
1153 @itemx -w
1154 @cindex @code{--windows}
1155 @cindex @code{-w}
1156 If @value{GDBN} includes a GUI, then this option requires it to be
1157 used if possible.
1158
1159 @item -cd @var{directory}
1160 @cindex @code{--cd}
1161 Run @value{GDBN} using @var{directory} as its working directory,
1162 instead of the current directory.
1163
1164 @item -data-directory @var{directory}
1165 @cindex @code{--data-directory}
1166 Run @value{GDBN} using @var{directory} as its data directory.
1167 The data directory is where @value{GDBN} searches for its
1168 auxiliary files.  @xref{Data Files}.
1169
1170 @item -fullname
1171 @itemx -f
1172 @cindex @code{--fullname}
1173 @cindex @code{-f}
1174 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1175 subprocess.  It tells @value{GDBN} to output the full file name and line
1176 number in a standard, recognizable fashion each time a stack frame is
1177 displayed (which includes each time your program stops).  This
1178 recognizable format looks like two @samp{\032} characters, followed by
1179 the file name, line number and character position separated by colons,
1180 and a newline.  The Emacs-to-@value{GDBN} interface program uses the two
1181 @samp{\032} characters as a signal to display the source code for the
1182 frame.
1183
1184 @item -epoch
1185 @cindex @code{--epoch}
1186 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1187 @value{GDBN} as a subprocess.  It tells @value{GDBN} to modify its print
1188 routines so as to allow Epoch to display values of expressions in a
1189 separate window.
1190
1191 @item -annotate @var{level}
1192 @cindex @code{--annotate}
1193 This option sets the @dfn{annotation level} inside @value{GDBN}.  Its
1194 effect is identical to using @samp{set annotate @var{level}}
1195 (@pxref{Annotations}).  The annotation @var{level} controls how much
1196 information @value{GDBN} prints together with its prompt, values of
1197 expressions, source lines, and other types of output.  Level 0 is the
1198 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1199 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1200 that control @value{GDBN}, and level 2 has been deprecated.
1201
1202 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1203 (@pxref{GDB/MI}).
1204
1205 @item --args
1206 @cindex @code{--args}
1207 Change interpretation of command line so that arguments following the
1208 executable file are passed as command line arguments to the inferior.
1209 This option stops option processing.
1210
1211 @item -baud @var{bps}
1212 @itemx -b @var{bps}
1213 @cindex @code{--baud}
1214 @cindex @code{-b}
1215 Set the line speed (baud rate or bits per second) of any serial
1216 interface used by @value{GDBN} for remote debugging.
1217
1218 @item -l @var{timeout}
1219 @cindex @code{-l}
1220 Set the timeout (in seconds) of any communication used by @value{GDBN}
1221 for remote debugging.
1222
1223 @item -tty @var{device}
1224 @itemx -t @var{device}
1225 @cindex @code{--tty}
1226 @cindex @code{-t}
1227 Run using @var{device} for your program's standard input and output.
1228 @c FIXME: kingdon thinks there is more to -tty.  Investigate.
1229
1230 @c resolve the situation of these eventually
1231 @item -tui
1232 @cindex @code{--tui}
1233 Activate the @dfn{Text User Interface} when starting.  The Text User
1234 Interface manages several text windows on the terminal, showing
1235 source, assembly, registers and @value{GDBN} command outputs
1236 (@pxref{TUI, ,@value{GDBN} Text User Interface}).  Do not use this
1237 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1238 Using @value{GDBN} under @sc{gnu} Emacs}).
1239
1240 @c @item -xdb
1241 @c @cindex @code{--xdb}
1242 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1243 @c For information, see the file @file{xdb_trans.html}, which is usually
1244 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1245 @c systems.
1246
1247 @item -interpreter @var{interp}
1248 @cindex @code{--interpreter}
1249 Use the interpreter @var{interp} for interface with the controlling
1250 program or device.  This option is meant to be set by programs which
1251 communicate with @value{GDBN} using it as a back end.
1252 @xref{Interpreters, , Command Interpreters}.
1253
1254 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1255 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1256 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0.  The
1257 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1258 selected with @samp{--interpreter=mi1}, is deprecated.  Earlier
1259 @sc{gdb/mi} interfaces are no longer supported.
1260
1261 @item -write
1262 @cindex @code{--write}
1263 Open the executable and core files for both reading and writing.  This
1264 is equivalent to the @samp{set write on} command inside @value{GDBN}
1265 (@pxref{Patching}).
1266
1267 @item -statistics
1268 @cindex @code{--statistics}
1269 This option causes @value{GDBN} to print statistics about time and
1270 memory usage after it completes each command and returns to the prompt.
1271
1272 @item -version
1273 @cindex @code{--version}
1274 This option causes @value{GDBN} to print its version number and
1275 no-warranty blurb, and exit.
1276
1277 @end table
1278
1279 @node Startup
1280 @subsection What @value{GDBN} Does During Startup
1281 @cindex @value{GDBN} startup
1282
1283 Here's the description of what @value{GDBN} does during session startup:
1284
1285 @enumerate
1286 @item
1287 Sets up the command interpreter as specified by the command line
1288 (@pxref{Mode Options, interpreter}).
1289
1290 @item
1291 @cindex init file
1292 Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1293 used when building @value{GDBN}; @pxref{System-wide configuration,
1294  ,System-wide configuration and settings}) and executes all the commands in
1295 that file.
1296
1297 @anchor{Home Directory Init File}
1298 @item
1299 Reads the init file (if any) in your home directory@footnote{On
1300 DOS/Windows systems, the home directory is the one pointed to by the
1301 @code{HOME} environment variable.} and executes all the commands in
1302 that file.
1303
1304 @anchor{Option -init-eval-command}
1305 @item
1306 Executes commands and command files specified by the @samp{-iex} and
1307 @samp{-ix} options in their specified order.  Usually you should use the
1308 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1309 settings before @value{GDBN} init files get executed and before inferior
1310 gets loaded.
1311
1312 @item
1313 Processes command line options and operands.
1314
1315 @anchor{Init File in the Current Directory during Startup}
1316 @item
1317 Reads and executes the commands from init file (if any) in the current
1318 working directory as long as @samp{set auto-load local-gdbinit} is set to
1319 @samp{on} (@pxref{Init File in the Current Directory}).
1320 This is only done if the current directory is
1321 different from your home directory.  Thus, you can have more than one
1322 init file, one generic in your home directory, and another, specific
1323 to the program you are debugging, in the directory where you invoke
1324 @value{GDBN}.
1325
1326 @item
1327 If the command line specified a program to debug, or a process to
1328 attach to, or a core file, @value{GDBN} loads any auto-loaded
1329 scripts provided for the program or for its loaded shared libraries.
1330 @xref{Auto-loading}.
1331
1332 If you wish to disable the auto-loading during startup,
1333 you must do something like the following:
1334
1335 @smallexample
1336 $ gdb -iex "set auto-load python-scripts off" myprogram
1337 @end smallexample
1338
1339 Option @samp{-ex} does not work because the auto-loading is then turned
1340 off too late.
1341
1342 @item
1343 Executes commands and command files specified by the @samp{-ex} and
1344 @samp{-x} options in their specified order.  @xref{Command Files}, for
1345 more details about @value{GDBN} command files.
1346
1347 @item
1348 Reads the command history recorded in the @dfn{history file}.
1349 @xref{Command History}, for more details about the command history and the
1350 files where @value{GDBN} records it.
1351 @end enumerate
1352
1353 Init files use the same syntax as @dfn{command files} (@pxref{Command
1354 Files}) and are processed by @value{GDBN} in the same way.  The init
1355 file in your home directory can set options (such as @samp{set
1356 complaints}) that affect subsequent processing of command line options
1357 and operands.  Init files are not executed if you use the @samp{-nx}
1358 option (@pxref{Mode Options, ,Choosing Modes}).
1359
1360 To display the list of init files loaded by gdb at startup, you
1361 can use @kbd{gdb --help}.
1362
1363 @cindex init file name
1364 @cindex @file{.gdbinit}
1365 @cindex @file{gdb.ini}
1366 The @value{GDBN} init files are normally called @file{.gdbinit}.
1367 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1368 the limitations of file names imposed by DOS filesystems.  The Windows
1369 port of @value{GDBN} uses the standard name, but if it finds a
1370 @file{gdb.ini} file in your home directory, it warns you about that
1371 and suggests to rename the file to the standard name.
1372
1373
1374 @node Quitting GDB
1375 @section Quitting @value{GDBN}
1376 @cindex exiting @value{GDBN}
1377 @cindex leaving @value{GDBN}
1378
1379 @table @code
1380 @kindex quit @r{[}@var{expression}@r{]}
1381 @kindex q @r{(@code{quit})}
1382 @item quit @r{[}@var{expression}@r{]}
1383 @itemx q
1384 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1385 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}).  If you
1386 do not supply @var{expression}, @value{GDBN} will terminate normally;
1387 otherwise it will terminate using the result of @var{expression} as the
1388 error code.
1389 @end table
1390
1391 @cindex interrupt
1392 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1393 terminates the action of any @value{GDBN} command that is in progress and
1394 returns to @value{GDBN} command level.  It is safe to type the interrupt
1395 character at any time because @value{GDBN} does not allow it to take effect
1396 until a time when it is safe.
1397
1398 If you have been using @value{GDBN} to control an attached process or
1399 device, you can release it with the @code{detach} command
1400 (@pxref{Attach, ,Debugging an Already-running Process}).
1401
1402 @node Shell Commands
1403 @section Shell Commands
1404
1405 If you need to execute occasional shell commands during your
1406 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1407 just use the @code{shell} command.
1408
1409 @table @code
1410 @kindex shell
1411 @kindex !
1412 @cindex shell escape
1413 @item shell @var{command-string}
1414 @itemx !@var{command-string}
1415 Invoke a standard shell to execute @var{command-string}.
1416 Note that no space is needed between @code{!} and @var{command-string}.
1417 If it exists, the environment variable @code{SHELL} determines which
1418 shell to run.  Otherwise @value{GDBN} uses the default shell
1419 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1420 @end table
1421
1422 The utility @code{make} is often needed in development environments.
1423 You do not have to use the @code{shell} command for this purpose in
1424 @value{GDBN}:
1425
1426 @table @code
1427 @kindex make
1428 @cindex calling make
1429 @item make @var{make-args}
1430 Execute the @code{make} program with the specified
1431 arguments.  This is equivalent to @samp{shell make @var{make-args}}.
1432 @end table
1433
1434 @node Logging Output
1435 @section Logging Output
1436 @cindex logging @value{GDBN} output
1437 @cindex save @value{GDBN} output to a file
1438
1439 You may want to save the output of @value{GDBN} commands to a file.
1440 There are several commands to control @value{GDBN}'s logging.
1441
1442 @table @code
1443 @kindex set logging
1444 @item set logging on
1445 Enable logging.
1446 @item set logging off
1447 Disable logging.
1448 @cindex logging file name
1449 @item set logging file @var{file}
1450 Change the name of the current logfile.  The default logfile is @file{gdb.txt}.
1451 @item set logging overwrite [on|off]
1452 By default, @value{GDBN} will append to the logfile.  Set @code{overwrite} if
1453 you want @code{set logging on} to overwrite the logfile instead.
1454 @item set logging redirect [on|off]
1455 By default, @value{GDBN} output will go to both the terminal and the logfile.
1456 Set @code{redirect} if you want output to go only to the log file.
1457 @kindex show logging
1458 @item show logging
1459 Show the current values of the logging settings.
1460 @end table
1461
1462 @node Commands
1463 @chapter @value{GDBN} Commands
1464
1465 You can abbreviate a @value{GDBN} command to the first few letters of the command
1466 name, if that abbreviation is unambiguous; and you can repeat certain
1467 @value{GDBN} commands by typing just @key{RET}.  You can also use the @key{TAB}
1468 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1469 show you the alternatives available, if there is more than one possibility).
1470
1471 @menu
1472 * Command Syntax::              How to give commands to @value{GDBN}
1473 * Completion::                  Command completion
1474 * Help::                        How to ask @value{GDBN} for help
1475 @end menu
1476
1477 @node Command Syntax
1478 @section Command Syntax
1479
1480 A @value{GDBN} command is a single line of input.  There is no limit on
1481 how long it can be.  It starts with a command name, which is followed by
1482 arguments whose meaning depends on the command name.  For example, the
1483 command @code{step} accepts an argument which is the number of times to
1484 step, as in @samp{step 5}.  You can also use the @code{step} command
1485 with no arguments.  Some commands do not allow any arguments.
1486
1487 @cindex abbreviation
1488 @value{GDBN} command names may always be truncated if that abbreviation is
1489 unambiguous.  Other possible command abbreviations are listed in the
1490 documentation for individual commands.  In some cases, even ambiguous
1491 abbreviations are allowed; for example, @code{s} is specially defined as
1492 equivalent to @code{step} even though there are other commands whose
1493 names start with @code{s}.  You can test abbreviations by using them as
1494 arguments to the @code{help} command.
1495
1496 @cindex repeating commands
1497 @kindex RET @r{(repeat last command)}
1498 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1499 repeat the previous command.  Certain commands (for example, @code{run})
1500 will not repeat this way; these are commands whose unintentional
1501 repetition might cause trouble and which you are unlikely to want to
1502 repeat.  User-defined commands can disable this feature; see
1503 @ref{Define, dont-repeat}.
1504
1505 The @code{list} and @code{x} commands, when you repeat them with
1506 @key{RET}, construct new arguments rather than repeating
1507 exactly as typed.  This permits easy scanning of source or memory.
1508
1509 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1510 output, in a way similar to the common utility @code{more}
1511 (@pxref{Screen Size,,Screen Size}).  Since it is easy to press one
1512 @key{RET} too many in this situation, @value{GDBN} disables command
1513 repetition after any command that generates this sort of display.
1514
1515 @kindex # @r{(a comment)}
1516 @cindex comment
1517 Any text from a @kbd{#} to the end of the line is a comment; it does
1518 nothing.  This is useful mainly in command files (@pxref{Command
1519 Files,,Command Files}).
1520
1521 @cindex repeating command sequences
1522 @kindex Ctrl-o @r{(operate-and-get-next)}
1523 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1524 commands.  This command accepts the current line, like @key{RET}, and
1525 then fetches the next line relative to the current line from the history
1526 for editing.
1527
1528 @node Completion
1529 @section Command Completion
1530
1531 @cindex completion
1532 @cindex word completion
1533 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1534 only one possibility; it can also show you what the valid possibilities
1535 are for the next word in a command, at any time.  This works for @value{GDBN}
1536 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1537
1538 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1539 of a word.  If there is only one possibility, @value{GDBN} fills in the
1540 word, and waits for you to finish the command (or press @key{RET} to
1541 enter it).  For example, if you type
1542
1543 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1544 @c complete accuracy in these examples; space introduced for clarity.
1545 @c If texinfo enhancements make it unnecessary, it would be nice to
1546 @c replace " @key" by "@key" in the following...
1547 @smallexample
1548 (@value{GDBP}) info bre @key{TAB}
1549 @end smallexample
1550
1551 @noindent
1552 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1553 the only @code{info} subcommand beginning with @samp{bre}:
1554
1555 @smallexample
1556 (@value{GDBP}) info breakpoints
1557 @end smallexample
1558
1559 @noindent
1560 You can either press @key{RET} at this point, to run the @code{info
1561 breakpoints} command, or backspace and enter something else, if
1562 @samp{breakpoints} does not look like the command you expected.  (If you
1563 were sure you wanted @code{info breakpoints} in the first place, you
1564 might as well just type @key{RET} immediately after @samp{info bre},
1565 to exploit command abbreviations rather than command completion).
1566
1567 If there is more than one possibility for the next word when you press
1568 @key{TAB}, @value{GDBN} sounds a bell.  You can either supply more
1569 characters and try again, or just press @key{TAB} a second time;
1570 @value{GDBN} displays all the possible completions for that word.  For
1571 example, you might want to set a breakpoint on a subroutine whose name
1572 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1573 just sounds the bell.  Typing @key{TAB} again displays all the
1574 function names in your program that begin with those characters, for
1575 example:
1576
1577 @smallexample
1578 (@value{GDBP}) b make_ @key{TAB}
1579 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1580 make_a_section_from_file     make_environ
1581 make_abs_section             make_function_type
1582 make_blockvector             make_pointer_type
1583 make_cleanup                 make_reference_type
1584 make_command                 make_symbol_completion_list
1585 (@value{GDBP}) b make_
1586 @end smallexample
1587
1588 @noindent
1589 After displaying the available possibilities, @value{GDBN} copies your
1590 partial input (@samp{b make_} in the example) so you can finish the
1591 command.
1592
1593 If you just want to see the list of alternatives in the first place, you
1594 can press @kbd{M-?} rather than pressing @key{TAB} twice.  @kbd{M-?}
1595 means @kbd{@key{META} ?}.  You can type this either by holding down a
1596 key designated as the @key{META} shift on your keyboard (if there is
1597 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1598
1599 @cindex quotes in commands
1600 @cindex completion of quoted strings
1601 Sometimes the string you need, while logically a ``word'', may contain
1602 parentheses or other characters that @value{GDBN} normally excludes from
1603 its notion of a word.  To permit word completion to work in this
1604 situation, you may enclose words in @code{'} (single quote marks) in
1605 @value{GDBN} commands.
1606
1607 The most likely situation where you might need this is in typing the
1608 name of a C@t{++} function.  This is because C@t{++} allows function
1609 overloading (multiple definitions of the same function, distinguished
1610 by argument type).  For example, when you want to set a breakpoint you
1611 may need to distinguish whether you mean the version of @code{name}
1612 that takes an @code{int} parameter, @code{name(int)}, or the version
1613 that takes a @code{float} parameter, @code{name(float)}.  To use the
1614 word-completion facilities in this situation, type a single quote
1615 @code{'} at the beginning of the function name.  This alerts
1616 @value{GDBN} that it may need to consider more information than usual
1617 when you press @key{TAB} or @kbd{M-?} to request word completion:
1618
1619 @smallexample
1620 (@value{GDBP}) b 'bubble( @kbd{M-?}
1621 bubble(double,double)    bubble(int,int)
1622 (@value{GDBP}) b 'bubble(
1623 @end smallexample
1624
1625 In some cases, @value{GDBN} can tell that completing a name requires using
1626 quotes.  When this happens, @value{GDBN} inserts the quote for you (while
1627 completing as much as it can) if you do not type the quote in the first
1628 place:
1629
1630 @smallexample
1631 (@value{GDBP}) b bub @key{TAB}
1632 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1633 (@value{GDBP}) b 'bubble(
1634 @end smallexample
1635
1636 @noindent
1637 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1638 you have not yet started typing the argument list when you ask for
1639 completion on an overloaded symbol.
1640
1641 For more information about overloaded functions, see @ref{C Plus Plus
1642 Expressions, ,C@t{++} Expressions}.  You can use the command @code{set
1643 overload-resolution off} to disable overload resolution;
1644 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1645
1646 @cindex completion of structure field names
1647 @cindex structure field name completion
1648 @cindex completion of union field names
1649 @cindex union field name completion
1650 When completing in an expression which looks up a field in a
1651 structure, @value{GDBN} also tries@footnote{The completer can be
1652 confused by certain kinds of invalid expressions.  Also, it only
1653 examines the static type of the expression, not the dynamic type.} to
1654 limit completions to the field names available in the type of the
1655 left-hand-side:
1656
1657 @smallexample
1658 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1659 magic                to_fputs             to_rewind
1660 to_data              to_isatty            to_write
1661 to_delete            to_put               to_write_async_safe
1662 to_flush             to_read
1663 @end smallexample
1664
1665 @noindent
1666 This is because the @code{gdb_stdout} is a variable of the type
1667 @code{struct ui_file} that is defined in @value{GDBN} sources as
1668 follows:
1669
1670 @smallexample
1671 struct ui_file
1672 @{
1673    int *magic;
1674    ui_file_flush_ftype *to_flush;
1675    ui_file_write_ftype *to_write;
1676    ui_file_write_async_safe_ftype *to_write_async_safe;
1677    ui_file_fputs_ftype *to_fputs;
1678    ui_file_read_ftype *to_read;
1679    ui_file_delete_ftype *to_delete;
1680    ui_file_isatty_ftype *to_isatty;
1681    ui_file_rewind_ftype *to_rewind;
1682    ui_file_put_ftype *to_put;
1683    void *to_data;
1684 @}
1685 @end smallexample
1686
1687
1688 @node Help
1689 @section Getting Help
1690 @cindex online documentation
1691 @kindex help
1692
1693 You can always ask @value{GDBN} itself for information on its commands,
1694 using the command @code{help}.
1695
1696 @table @code
1697 @kindex h @r{(@code{help})}
1698 @item help
1699 @itemx h
1700 You can use @code{help} (abbreviated @code{h}) with no arguments to
1701 display a short list of named classes of commands:
1702
1703 @smallexample
1704 (@value{GDBP}) help
1705 List of classes of commands:
1706
1707 aliases -- Aliases of other commands
1708 breakpoints -- Making program stop at certain points
1709 data -- Examining data
1710 files -- Specifying and examining files
1711 internals -- Maintenance commands
1712 obscure -- Obscure features
1713 running -- Running the program
1714 stack -- Examining the stack
1715 status -- Status inquiries
1716 support -- Support facilities
1717 tracepoints -- Tracing of program execution without
1718                stopping the program
1719 user-defined -- User-defined commands
1720
1721 Type "help" followed by a class name for a list of
1722 commands in that class.
1723 Type "help" followed by command name for full
1724 documentation.
1725 Command name abbreviations are allowed if unambiguous.
1726 (@value{GDBP})
1727 @end smallexample
1728 @c the above line break eliminates huge line overfull...
1729
1730 @item help @var{class}
1731 Using one of the general help classes as an argument, you can get a
1732 list of the individual commands in that class.  For example, here is the
1733 help display for the class @code{status}:
1734
1735 @smallexample
1736 (@value{GDBP}) help status
1737 Status inquiries.
1738
1739 List of commands:
1740
1741 @c Line break in "show" line falsifies real output, but needed
1742 @c to fit in smallbook page size.
1743 info -- Generic command for showing things
1744         about the program being debugged
1745 show -- Generic command for showing things
1746         about the debugger
1747
1748 Type "help" followed by command name for full
1749 documentation.
1750 Command name abbreviations are allowed if unambiguous.
1751 (@value{GDBP})
1752 @end smallexample
1753
1754 @item help @var{command}
1755 With a command name as @code{help} argument, @value{GDBN} displays a
1756 short paragraph on how to use that command.
1757
1758 @kindex apropos
1759 @item apropos @var{args}
1760 The @code{apropos} command searches through all of the @value{GDBN}
1761 commands, and their documentation, for the regular expression specified in
1762 @var{args}.  It prints out all matches found.  For example:
1763
1764 @smallexample
1765 apropos alias
1766 @end smallexample
1767
1768 @noindent
1769 results in:
1770
1771 @smallexample
1772 @c @group
1773 alias -- Define a new command that is an alias of an existing command
1774 aliases -- Aliases of other commands
1775 d -- Delete some breakpoints or auto-display expressions
1776 del -- Delete some breakpoints or auto-display expressions
1777 delete -- Delete some breakpoints or auto-display expressions
1778 @c @end group
1779 @end smallexample
1780
1781 @kindex complete
1782 @item complete @var{args}
1783 The @code{complete @var{args}} command lists all the possible completions
1784 for the beginning of a command.  Use @var{args} to specify the beginning of the
1785 command you want completed.  For example:
1786
1787 @smallexample
1788 complete i
1789 @end smallexample
1790
1791 @noindent results in:
1792
1793 @smallexample
1794 @group
1795 if
1796 ignore
1797 info
1798 inspect
1799 @end group
1800 @end smallexample
1801
1802 @noindent This is intended for use by @sc{gnu} Emacs.
1803 @end table
1804
1805 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1806 and @code{show} to inquire about the state of your program, or the state
1807 of @value{GDBN} itself.  Each command supports many topics of inquiry; this
1808 manual introduces each of them in the appropriate context.  The listings
1809 under @code{info} and under @code{show} in the Command, Variable, and
1810 Function Index point to all the sub-commands.  @xref{Command and Variable
1811 Index}.
1812
1813 @c @group
1814 @table @code
1815 @kindex info
1816 @kindex i @r{(@code{info})}
1817 @item info
1818 This command (abbreviated @code{i}) is for describing the state of your
1819 program.  For example, you can show the arguments passed to a function
1820 with @code{info args}, list the registers currently in use with @code{info
1821 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1822 You can get a complete list of the @code{info} sub-commands with
1823 @w{@code{help info}}.
1824
1825 @kindex set
1826 @item set
1827 You can assign the result of an expression to an environment variable with
1828 @code{set}.  For example, you can set the @value{GDBN} prompt to a $-sign with
1829 @code{set prompt $}.
1830
1831 @kindex show
1832 @item show
1833 In contrast to @code{info}, @code{show} is for describing the state of
1834 @value{GDBN} itself.
1835 You can change most of the things you can @code{show}, by using the
1836 related command @code{set}; for example, you can control what number
1837 system is used for displays with @code{set radix}, or simply inquire
1838 which is currently in use with @code{show radix}.
1839
1840 @kindex info set
1841 To display all the settable parameters and their current
1842 values, you can use @code{show} with no arguments; you may also use
1843 @code{info set}.  Both commands produce the same display.
1844 @c FIXME: "info set" violates the rule that "info" is for state of
1845 @c FIXME...program.  Ck w/ GNU: "info set" to be called something else,
1846 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1847 @end table
1848 @c @end group
1849
1850 Here are three miscellaneous @code{show} subcommands, all of which are
1851 exceptional in lacking corresponding @code{set} commands:
1852
1853 @table @code
1854 @kindex show version
1855 @cindex @value{GDBN} version number
1856 @item show version
1857 Show what version of @value{GDBN} is running.  You should include this
1858 information in @value{GDBN} bug-reports.  If multiple versions of
1859 @value{GDBN} are in use at your site, you may need to determine which
1860 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1861 commands are introduced, and old ones may wither away.  Also, many
1862 system vendors ship variant versions of @value{GDBN}, and there are
1863 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1864 The version number is the same as the one announced when you start
1865 @value{GDBN}.
1866
1867 @kindex show copying
1868 @kindex info copying
1869 @cindex display @value{GDBN} copyright
1870 @item show copying
1871 @itemx info copying
1872 Display information about permission for copying @value{GDBN}.
1873
1874 @kindex show warranty
1875 @kindex info warranty
1876 @item show warranty
1877 @itemx info warranty
1878 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1879 if your version of @value{GDBN} comes with one.
1880
1881 @end table
1882
1883 @node Running
1884 @chapter Running Programs Under @value{GDBN}
1885
1886 When you run a program under @value{GDBN}, you must first generate
1887 debugging information when you compile it.
1888
1889 You may start @value{GDBN} with its arguments, if any, in an environment
1890 of your choice.  If you are doing native debugging, you may redirect
1891 your program's input and output, debug an already running process, or
1892 kill a child process.
1893
1894 @menu
1895 * Compilation::                 Compiling for debugging
1896 * Starting::                    Starting your program
1897 * Arguments::                   Your program's arguments
1898 * Environment::                 Your program's environment
1899
1900 * Working Directory::           Your program's working directory
1901 * Input/Output::                Your program's input and output
1902 * Attach::                      Debugging an already-running process
1903 * Kill Process::                Killing the child process
1904
1905 * Inferiors and Programs::      Debugging multiple inferiors and programs
1906 * Threads::                     Debugging programs with multiple threads
1907 * Forks::                       Debugging forks
1908 * Checkpoint/Restart::          Setting a @emph{bookmark} to return to later
1909 @end menu
1910
1911 @node Compilation
1912 @section Compiling for Debugging
1913
1914 In order to debug a program effectively, you need to generate
1915 debugging information when you compile it.  This debugging information
1916 is stored in the object file; it describes the data type of each
1917 variable or function and the correspondence between source line numbers
1918 and addresses in the executable code.
1919
1920 To request debugging information, specify the @samp{-g} option when you run
1921 the compiler.
1922
1923 Programs that are to be shipped to your customers are compiled with
1924 optimizations, using the @samp{-O} compiler option.  However, some
1925 compilers are unable to handle the @samp{-g} and @samp{-O} options
1926 together.  Using those compilers, you cannot generate optimized
1927 executables containing debugging information.
1928
1929 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1930 without @samp{-O}, making it possible to debug optimized code.  We
1931 recommend that you @emph{always} use @samp{-g} whenever you compile a
1932 program.  You may think your program is correct, but there is no sense
1933 in pushing your luck.  For more information, see @ref{Optimized Code}.
1934
1935 Older versions of the @sc{gnu} C compiler permitted a variant option
1936 @w{@samp{-gg}} for debugging information.  @value{GDBN} no longer supports this
1937 format; if your @sc{gnu} C compiler has this option, do not use it.
1938
1939 @value{GDBN} knows about preprocessor macros and can show you their
1940 expansion (@pxref{Macros}).  Most compilers do not include information
1941 about preprocessor macros in the debugging information if you specify
1942 the @option{-g} flag alone.  Version 3.1 and later of @value{NGCC},
1943 the @sc{gnu} C compiler, provides macro information if you are using
1944 the DWARF debugging format, and specify the option @option{-g3}.
1945
1946 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
1947 gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1948 information on @value{NGCC} options affecting debug information.
1949
1950 You will have the best debugging experience if you use the latest
1951 version of the DWARF debugging format that your compiler supports.
1952 DWARF is currently the most expressive and best supported debugging
1953 format in @value{GDBN}.
1954
1955 @need 2000
1956 @node Starting
1957 @section Starting your Program
1958 @cindex starting
1959 @cindex running
1960
1961 @table @code
1962 @kindex run
1963 @kindex r @r{(@code{run})}
1964 @item run
1965 @itemx r
1966 Use the @code{run} command to start your program under @value{GDBN}.
1967 You must first specify the program name (except on VxWorks) with an
1968 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1969 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1970 (@pxref{Files, ,Commands to Specify Files}).
1971
1972 @end table
1973
1974 If you are running your program in an execution environment that
1975 supports processes, @code{run} creates an inferior process and makes
1976 that process run your program.  In some environments without processes,
1977 @code{run} jumps to the start of your program.  Other targets,
1978 like @samp{remote}, are always running.  If you get an error
1979 message like this one:
1980
1981 @smallexample
1982 The "remote" target does not support "run".
1983 Try "help target" or "continue".
1984 @end smallexample
1985
1986 @noindent
1987 then use @code{continue} to run your program.  You may need @code{load}
1988 first (@pxref{load}).
1989
1990 The execution of a program is affected by certain information it
1991 receives from its superior.  @value{GDBN} provides ways to specify this
1992 information, which you must do @emph{before} starting your program.  (You
1993 can change it after starting your program, but such changes only affect
1994 your program the next time you start it.)  This information may be
1995 divided into four categories:
1996
1997 @table @asis
1998 @item The @emph{arguments.}
1999 Specify the arguments to give your program as the arguments of the
2000 @code{run} command.  If a shell is available on your target, the shell
2001 is used to pass the arguments, so that you may use normal conventions
2002 (such as wildcard expansion or variable substitution) in describing
2003 the arguments.
2004 In Unix systems, you can control which shell is used with the
2005 @code{SHELL} environment variable.
2006 @xref{Arguments, ,Your Program's Arguments}.
2007
2008 @item The @emph{environment.}
2009 Your program normally inherits its environment from @value{GDBN}, but you can
2010 use the @value{GDBN} commands @code{set environment} and @code{unset
2011 environment} to change parts of the environment that affect
2012 your program.  @xref{Environment, ,Your Program's Environment}.
2013
2014 @item The @emph{working directory.}
2015 Your program inherits its working directory from @value{GDBN}.  You can set
2016 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
2017 @xref{Working Directory, ,Your Program's Working Directory}.
2018
2019 @item The @emph{standard input and output.}
2020 Your program normally uses the same device for standard input and
2021 standard output as @value{GDBN} is using.  You can redirect input and output
2022 in the @code{run} command line, or you can use the @code{tty} command to
2023 set a different device for your program.
2024 @xref{Input/Output, ,Your Program's Input and Output}.
2025
2026 @cindex pipes
2027 @emph{Warning:} While input and output redirection work, you cannot use
2028 pipes to pass the output of the program you are debugging to another
2029 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2030 wrong program.
2031 @end table
2032
2033 When you issue the @code{run} command, your program begins to execute
2034 immediately.  @xref{Stopping, ,Stopping and Continuing}, for discussion
2035 of how to arrange for your program to stop.  Once your program has
2036 stopped, you may call functions in your program, using the @code{print}
2037 or @code{call} commands.  @xref{Data, ,Examining Data}.
2038
2039 If the modification time of your symbol file has changed since the last
2040 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2041 table, and reads it again.  When it does this, @value{GDBN} tries to retain
2042 your current breakpoints.
2043
2044 @table @code
2045 @kindex start
2046 @item start
2047 @cindex run to main procedure
2048 The name of the main procedure can vary from language to language.
2049 With C or C@t{++}, the main procedure name is always @code{main}, but
2050 other languages such as Ada do not require a specific name for their
2051 main procedure.  The debugger provides a convenient way to start the
2052 execution of the program and to stop at the beginning of the main
2053 procedure, depending on the language used.
2054
2055 The @samp{start} command does the equivalent of setting a temporary
2056 breakpoint at the beginning of the main procedure and then invoking
2057 the @samp{run} command.
2058
2059 @cindex elaboration phase
2060 Some programs contain an @dfn{elaboration} phase where some startup code is
2061 executed before the main procedure is called.  This depends on the
2062 languages used to write your program.  In C@t{++}, for instance,
2063 constructors for static and global objects are executed before
2064 @code{main} is called.  It is therefore possible that the debugger stops
2065 before reaching the main procedure.  However, the temporary breakpoint
2066 will remain to halt execution.
2067
2068 Specify the arguments to give to your program as arguments to the
2069 @samp{start} command.  These arguments will be given verbatim to the
2070 underlying @samp{run} command.  Note that the same arguments will be
2071 reused if no argument is provided during subsequent calls to
2072 @samp{start} or @samp{run}.
2073
2074 It is sometimes necessary to debug the program during elaboration.  In
2075 these cases, using the @code{start} command would stop the execution of
2076 your program too late, as the program would have already completed the
2077 elaboration phase.  Under these circumstances, insert breakpoints in your
2078 elaboration code before running your program.
2079
2080 @kindex set exec-wrapper
2081 @item set exec-wrapper @var{wrapper}
2082 @itemx show exec-wrapper
2083 @itemx unset exec-wrapper
2084 When @samp{exec-wrapper} is set, the specified wrapper is used to
2085 launch programs for debugging.  @value{GDBN} starts your program
2086 with a shell command of the form @kbd{exec @var{wrapper}
2087 @var{program}}.  Quoting is added to @var{program} and its
2088 arguments, but not to @var{wrapper}, so you should add quotes if
2089 appropriate for your shell.  The wrapper runs until it executes
2090 your program, and then @value{GDBN} takes control.
2091
2092 You can use any program that eventually calls @code{execve} with
2093 its arguments as a wrapper.  Several standard Unix utilities do
2094 this, e.g.@: @code{env} and @code{nohup}.  Any Unix shell script ending
2095 with @code{exec "$@@"} will also work.
2096
2097 For example, you can use @code{env} to pass an environment variable to
2098 the debugged program, without setting the variable in your shell's
2099 environment:
2100
2101 @smallexample
2102 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2103 (@value{GDBP}) run
2104 @end smallexample
2105
2106 This command is available when debugging locally on most targets, excluding
2107 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2108
2109 @kindex set disable-randomization
2110 @item set disable-randomization
2111 @itemx set disable-randomization on
2112 This option (enabled by default in @value{GDBN}) will turn off the native
2113 randomization of the virtual address space of the started program.  This option
2114 is useful for multiple debugging sessions to make the execution better
2115 reproducible and memory addresses reusable across debugging sessions.
2116
2117 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2118 On @sc{gnu}/Linux you can get the same behavior using
2119
2120 @smallexample
2121 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2122 @end smallexample
2123
2124 @item set disable-randomization off
2125 Leave the behavior of the started executable unchanged.  Some bugs rear their
2126 ugly heads only when the program is loaded at certain addresses.  If your bug
2127 disappears when you run the program under @value{GDBN}, that might be because
2128 @value{GDBN} by default disables the address randomization on platforms, such
2129 as @sc{gnu}/Linux, which do that for stand-alone programs.  Use @kbd{set
2130 disable-randomization off} to try to reproduce such elusive bugs.
2131
2132 On targets where it is available, virtual address space randomization
2133 protects the programs against certain kinds of security attacks.  In these
2134 cases the attacker needs to know the exact location of a concrete executable
2135 code.  Randomizing its location makes it impossible to inject jumps misusing
2136 a code at its expected addresses.
2137
2138 Prelinking shared libraries provides a startup performance advantage but it
2139 makes addresses in these libraries predictable for privileged processes by
2140 having just unprivileged access at the target system.  Reading the shared
2141 library binary gives enough information for assembling the malicious code
2142 misusing it.  Still even a prelinked shared library can get loaded at a new
2143 random address just requiring the regular relocation process during the
2144 startup.  Shared libraries not already prelinked are always loaded at
2145 a randomly chosen address.
2146
2147 Position independent executables (PIE) contain position independent code
2148 similar to the shared libraries and therefore such executables get loaded at
2149 a randomly chosen address upon startup.  PIE executables always load even
2150 already prelinked shared libraries at a random address.  You can build such
2151 executable using @command{gcc -fPIE -pie}.
2152
2153 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2154 (as long as the randomization is enabled).
2155
2156 @item show disable-randomization
2157 Show the current setting of the explicit disable of the native randomization of
2158 the virtual address space of the started program.
2159
2160 @end table
2161
2162 @node Arguments
2163 @section Your Program's Arguments
2164
2165 @cindex arguments (to your program)
2166 The arguments to your program can be specified by the arguments of the
2167 @code{run} command.
2168 They are passed to a shell, which expands wildcard characters and
2169 performs redirection of I/O, and thence to your program.  Your
2170 @code{SHELL} environment variable (if it exists) specifies what shell
2171 @value{GDBN} uses.  If you do not define @code{SHELL}, @value{GDBN} uses
2172 the default shell (@file{/bin/sh} on Unix).
2173
2174 On non-Unix systems, the program is usually invoked directly by
2175 @value{GDBN}, which emulates I/O redirection via the appropriate system
2176 calls, and the wildcard characters are expanded by the startup code of
2177 the program, not by the shell.
2178
2179 @code{run} with no arguments uses the same arguments used by the previous
2180 @code{run}, or those set by the @code{set args} command.
2181
2182 @table @code
2183 @kindex set args
2184 @item set args
2185 Specify the arguments to be used the next time your program is run.  If
2186 @code{set args} has no arguments, @code{run} executes your program
2187 with no arguments.  Once you have run your program with arguments,
2188 using @code{set args} before the next @code{run} is the only way to run
2189 it again without arguments.
2190
2191 @kindex show args
2192 @item show args
2193 Show the arguments to give your program when it is started.
2194 @end table
2195
2196 @node Environment
2197 @section Your Program's Environment
2198
2199 @cindex environment (of your program)
2200 The @dfn{environment} consists of a set of environment variables and
2201 their values.  Environment variables conventionally record such things as
2202 your user name, your home directory, your terminal type, and your search
2203 path for programs to run.  Usually you set up environment variables with
2204 the shell and they are inherited by all the other programs you run.  When
2205 debugging, it can be useful to try running your program with a modified
2206 environment without having to start @value{GDBN} over again.
2207
2208 @table @code
2209 @kindex path
2210 @item path @var{directory}
2211 Add @var{directory} to the front of the @code{PATH} environment variable
2212 (the search path for executables) that will be passed to your program.
2213 The value of @code{PATH} used by @value{GDBN} does not change.
2214 You may specify several directory names, separated by whitespace or by a
2215 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2216 MS-DOS and MS-Windows).  If @var{directory} is already in the path, it
2217 is moved to the front, so it is searched sooner.
2218
2219 You can use the string @samp{$cwd} to refer to whatever is the current
2220 working directory at the time @value{GDBN} searches the path.  If you
2221 use @samp{.} instead, it refers to the directory where you executed the
2222 @code{path} command.  @value{GDBN} replaces @samp{.} in the
2223 @var{directory} argument (with the current path) before adding
2224 @var{directory} to the search path.
2225 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2226 @c document that, since repeating it would be a no-op.
2227
2228 @kindex show paths
2229 @item show paths
2230 Display the list of search paths for executables (the @code{PATH}
2231 environment variable).
2232
2233 @kindex show environment
2234 @item show environment @r{[}@var{varname}@r{]}
2235 Print the value of environment variable @var{varname} to be given to
2236 your program when it starts.  If you do not supply @var{varname},
2237 print the names and values of all environment variables to be given to
2238 your program.  You can abbreviate @code{environment} as @code{env}.
2239
2240 @kindex set environment
2241 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2242 Set environment variable @var{varname} to @var{value}.  The value
2243 changes for your program only, not for @value{GDBN} itself.  @var{value} may
2244 be any string; the values of environment variables are just strings, and
2245 any interpretation is supplied by your program itself.  The @var{value}
2246 parameter is optional; if it is eliminated, the variable is set to a
2247 null value.
2248 @c "any string" here does not include leading, trailing
2249 @c blanks. Gnu asks: does anyone care?
2250
2251 For example, this command:
2252
2253 @smallexample
2254 set env USER = foo
2255 @end smallexample
2256
2257 @noindent
2258 tells the debugged program, when subsequently run, that its user is named
2259 @samp{foo}.  (The spaces around @samp{=} are used for clarity here; they
2260 are not actually required.)
2261
2262 @kindex unset environment
2263 @item unset environment @var{varname}
2264 Remove variable @var{varname} from the environment to be passed to your
2265 program.  This is different from @samp{set env @var{varname} =};
2266 @code{unset environment} removes the variable from the environment,
2267 rather than assigning it an empty value.
2268 @end table
2269
2270 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2271 the shell indicated
2272 by your @code{SHELL} environment variable if it exists (or
2273 @code{/bin/sh} if not).  If your @code{SHELL} variable names a shell
2274 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2275 @file{.bashrc} for BASH---any variables you set in that file affect
2276 your program.  You may wish to move setting of environment variables to
2277 files that are only run when you sign on, such as @file{.login} or
2278 @file{.profile}.
2279
2280 @node Working Directory
2281 @section Your Program's Working Directory
2282
2283 @cindex working directory (of your program)
2284 Each time you start your program with @code{run}, it inherits its
2285 working directory from the current working directory of @value{GDBN}.
2286 The @value{GDBN} working directory is initially whatever it inherited
2287 from its parent process (typically the shell), but you can specify a new
2288 working directory in @value{GDBN} with the @code{cd} command.
2289
2290 The @value{GDBN} working directory also serves as a default for the commands
2291 that specify files for @value{GDBN} to operate on.  @xref{Files, ,Commands to
2292 Specify Files}.
2293
2294 @table @code
2295 @kindex cd
2296 @cindex change working directory
2297 @item cd @r{[}@var{directory}@r{]}
2298 Set the @value{GDBN} working directory to @var{directory}.  If not
2299 given, @var{directory} uses @file{'~'}.
2300
2301 @kindex pwd
2302 @item pwd
2303 Print the @value{GDBN} working directory.
2304 @end table
2305
2306 It is generally impossible to find the current working directory of
2307 the process being debugged (since a program can change its directory
2308 during its run).  If you work on a system where @value{GDBN} is
2309 configured with the @file{/proc} support, you can use the @code{info
2310 proc} command (@pxref{SVR4 Process Information}) to find out the
2311 current working directory of the debuggee.
2312
2313 @node Input/Output
2314 @section Your Program's Input and Output
2315
2316 @cindex redirection
2317 @cindex i/o
2318 @cindex terminal
2319 By default, the program you run under @value{GDBN} does input and output to
2320 the same terminal that @value{GDBN} uses.  @value{GDBN} switches the terminal
2321 to its own terminal modes to interact with you, but it records the terminal
2322 modes your program was using and switches back to them when you continue
2323 running your program.
2324
2325 @table @code
2326 @kindex info terminal
2327 @item info terminal
2328 Displays information recorded by @value{GDBN} about the terminal modes your
2329 program is using.
2330 @end table
2331
2332 You can redirect your program's input and/or output using shell
2333 redirection with the @code{run} command.  For example,
2334
2335 @smallexample
2336 run > outfile
2337 @end smallexample
2338
2339 @noindent
2340 starts your program, diverting its output to the file @file{outfile}.
2341
2342 @kindex tty
2343 @cindex controlling terminal
2344 Another way to specify where your program should do input and output is
2345 with the @code{tty} command.  This command accepts a file name as
2346 argument, and causes this file to be the default for future @code{run}
2347 commands.  It also resets the controlling terminal for the child
2348 process, for future @code{run} commands.  For example,
2349
2350 @smallexample
2351 tty /dev/ttyb
2352 @end smallexample
2353
2354 @noindent
2355 directs that processes started with subsequent @code{run} commands
2356 default to do input and output on the terminal @file{/dev/ttyb} and have
2357 that as their controlling terminal.
2358
2359 An explicit redirection in @code{run} overrides the @code{tty} command's
2360 effect on the input/output device, but not its effect on the controlling
2361 terminal.
2362
2363 When you use the @code{tty} command or redirect input in the @code{run}
2364 command, only the input @emph{for your program} is affected.  The input
2365 for @value{GDBN} still comes from your terminal.  @code{tty} is an alias
2366 for @code{set inferior-tty}.
2367
2368 @cindex inferior tty
2369 @cindex set inferior controlling terminal
2370 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2371 display the name of the terminal that will be used for future runs of your
2372 program.
2373
2374 @table @code
2375 @item set inferior-tty /dev/ttyb
2376 @kindex set inferior-tty
2377 Set the tty for the program being debugged to /dev/ttyb.
2378
2379 @item show inferior-tty
2380 @kindex show inferior-tty
2381 Show the current tty for the program being debugged.
2382 @end table
2383
2384 @node Attach
2385 @section Debugging an Already-running Process
2386 @kindex attach
2387 @cindex attach
2388
2389 @table @code
2390 @item attach @var{process-id}
2391 This command attaches to a running process---one that was started
2392 outside @value{GDBN}.  (@code{info files} shows your active
2393 targets.)  The command takes as argument a process ID.  The usual way to
2394 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2395 or with the @samp{jobs -l} shell command.
2396
2397 @code{attach} does not repeat if you press @key{RET} a second time after
2398 executing the command.
2399 @end table
2400
2401 To use @code{attach}, your program must be running in an environment
2402 which supports processes; for example, @code{attach} does not work for
2403 programs on bare-board targets that lack an operating system.  You must
2404 also have permission to send the process a signal.
2405
2406 When you use @code{attach}, the debugger finds the program running in
2407 the process first by looking in the current working directory, then (if
2408 the program is not found) by using the source file search path
2409 (@pxref{Source Path, ,Specifying Source Directories}).  You can also use
2410 the @code{file} command to load the program.  @xref{Files, ,Commands to
2411 Specify Files}.
2412
2413 The first thing @value{GDBN} does after arranging to debug the specified
2414 process is to stop it.  You can examine and modify an attached process
2415 with all the @value{GDBN} commands that are ordinarily available when
2416 you start processes with @code{run}.  You can insert breakpoints; you
2417 can step and continue; you can modify storage.  If you would rather the
2418 process continue running, you may use the @code{continue} command after
2419 attaching @value{GDBN} to the process.
2420
2421 @table @code
2422 @kindex detach
2423 @item detach
2424 When you have finished debugging the attached process, you can use the
2425 @code{detach} command to release it from @value{GDBN} control.  Detaching
2426 the process continues its execution.  After the @code{detach} command,
2427 that process and @value{GDBN} become completely independent once more, and you
2428 are ready to @code{attach} another process or start one with @code{run}.
2429 @code{detach} does not repeat if you press @key{RET} again after
2430 executing the command.
2431 @end table
2432
2433 If you exit @value{GDBN} while you have an attached process, you detach
2434 that process.  If you use the @code{run} command, you kill that process.
2435 By default, @value{GDBN} asks for confirmation if you try to do either of these
2436 things; you can control whether or not you need to confirm by using the
2437 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2438 Messages}).
2439
2440 @node Kill Process
2441 @section Killing the Child Process
2442
2443 @table @code
2444 @kindex kill
2445 @item kill
2446 Kill the child process in which your program is running under @value{GDBN}.
2447 @end table
2448
2449 This command is useful if you wish to debug a core dump instead of a
2450 running process.  @value{GDBN} ignores any core dump file while your program
2451 is running.
2452
2453 On some operating systems, a program cannot be executed outside @value{GDBN}
2454 while you have breakpoints set on it inside @value{GDBN}.  You can use the
2455 @code{kill} command in this situation to permit running your program
2456 outside the debugger.
2457
2458 The @code{kill} command is also useful if you wish to recompile and
2459 relink your program, since on many systems it is impossible to modify an
2460 executable file while it is running in a process.  In this case, when you
2461 next type @code{run}, @value{GDBN} notices that the file has changed, and
2462 reads the symbol table again (while trying to preserve your current
2463 breakpoint settings).
2464
2465 @node Inferiors and Programs
2466 @section Debugging Multiple Inferiors and Programs
2467
2468 @value{GDBN} lets you run and debug multiple programs in a single
2469 session.  In addition, @value{GDBN} on some systems may let you run
2470 several programs simultaneously (otherwise you have to exit from one
2471 before starting another).  In the most general case, you can have
2472 multiple threads of execution in each of multiple processes, launched
2473 from multiple executables.
2474
2475 @cindex inferior
2476 @value{GDBN} represents the state of each program execution with an
2477 object called an @dfn{inferior}.  An inferior typically corresponds to
2478 a process, but is more general and applies also to targets that do not
2479 have processes.  Inferiors may be created before a process runs, and
2480 may be retained after a process exits.  Inferiors have unique
2481 identifiers that are different from process ids.  Usually each
2482 inferior will also have its own distinct address space, although some
2483 embedded targets may have several inferiors running in different parts
2484 of a single address space.  Each inferior may in turn have multiple
2485 threads running in it.
2486
2487 To find out what inferiors exist at any moment, use @w{@code{info
2488 inferiors}}:
2489
2490 @table @code
2491 @kindex info inferiors
2492 @item info inferiors
2493 Print a list of all inferiors currently being managed by @value{GDBN}.
2494
2495 @value{GDBN} displays for each inferior (in this order):
2496
2497 @enumerate
2498 @item
2499 the inferior number assigned by @value{GDBN}
2500
2501 @item
2502 the target system's inferior identifier
2503
2504 @item
2505 the name of the executable the inferior is running.
2506
2507 @end enumerate
2508
2509 @noindent
2510 An asterisk @samp{*} preceding the @value{GDBN} inferior number
2511 indicates the current inferior.
2512
2513 For example,
2514 @end table
2515 @c end table here to get a little more width for example
2516
2517 @smallexample
2518 (@value{GDBP}) info inferiors
2519   Num  Description       Executable
2520   2    process 2307      hello
2521 * 1    process 3401      goodbye
2522 @end smallexample
2523
2524 To switch focus between inferiors, use the @code{inferior} command:
2525
2526 @table @code
2527 @kindex inferior @var{infno}
2528 @item inferior @var{infno}
2529 Make inferior number @var{infno} the current inferior.  The argument
2530 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
2531 in the first field of the @samp{info inferiors} display.
2532 @end table
2533
2534
2535 You can get multiple executables into a debugging session via the
2536 @code{add-inferior} and @w{@code{clone-inferior}} commands.  On some
2537 systems @value{GDBN} can add inferiors to the debug session
2538 automatically by following calls to @code{fork} and @code{exec}.  To
2539 remove inferiors from the debugging session use the
2540 @w{@code{remove-inferiors}} command.
2541
2542 @table @code
2543 @kindex add-inferior
2544 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2545 Adds @var{n} inferiors to be run using @var{executable} as the
2546 executable.  @var{n} defaults to 1.  If no executable is specified,
2547 the inferiors begins empty, with no program.  You can still assign or
2548 change the program assigned to the inferior at any time by using the
2549 @code{file} command with the executable name as its argument.
2550
2551 @kindex clone-inferior
2552 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2553 Adds @var{n} inferiors ready to execute the same program as inferior
2554 @var{infno}.  @var{n} defaults to 1.  @var{infno} defaults to the
2555 number of the current inferior.  This is a convenient command when you
2556 want to run another instance of the inferior you are debugging.
2557
2558 @smallexample
2559 (@value{GDBP}) info inferiors
2560   Num  Description       Executable
2561 * 1    process 29964     helloworld
2562 (@value{GDBP}) clone-inferior
2563 Added inferior 2.
2564 1 inferiors added.
2565 (@value{GDBP}) info inferiors
2566   Num  Description       Executable
2567   2    <null>            helloworld
2568 * 1    process 29964     helloworld
2569 @end smallexample
2570
2571 You can now simply switch focus to inferior 2 and run it.
2572
2573 @kindex remove-inferiors
2574 @item remove-inferiors @var{infno}@dots{}
2575 Removes the inferior or inferiors @var{infno}@dots{}.  It is not
2576 possible to remove an inferior that is running with this command.  For
2577 those, use the @code{kill} or @code{detach} command first.
2578
2579 @end table
2580
2581 To quit debugging one of the running inferiors that is not the current
2582 inferior, you can either detach from it by using the @w{@code{detach
2583 inferior}} command (allowing it to run independently), or kill it
2584 using the @w{@code{kill inferiors}} command:
2585
2586 @table @code
2587 @kindex detach inferiors @var{infno}@dots{}
2588 @item detach inferior @var{infno}@dots{}
2589 Detach from the inferior or inferiors identified by @value{GDBN}
2590 inferior number(s) @var{infno}@dots{}.  Note that the inferior's entry
2591 still stays on the list of inferiors shown by @code{info inferiors},
2592 but its Description will show @samp{<null>}.
2593
2594 @kindex kill inferiors @var{infno}@dots{}
2595 @item kill inferiors @var{infno}@dots{}
2596 Kill the inferior or inferiors identified by @value{GDBN} inferior
2597 number(s) @var{infno}@dots{}.  Note that the inferior's entry still
2598 stays on the list of inferiors shown by @code{info inferiors}, but its
2599 Description will show @samp{<null>}.
2600 @end table
2601
2602 After the successful completion of a command such as @code{detach},
2603 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
2604 a normal process exit, the inferior is still valid and listed with
2605 @code{info inferiors}, ready to be restarted.
2606
2607
2608 To be notified when inferiors are started or exit under @value{GDBN}'s
2609 control use @w{@code{set print inferior-events}}:
2610
2611 @table @code
2612 @kindex set print inferior-events
2613 @cindex print messages on inferior start and exit
2614 @item set print inferior-events
2615 @itemx set print inferior-events on
2616 @itemx set print inferior-events off
2617 The @code{set print inferior-events} command allows you to enable or
2618 disable printing of messages when @value{GDBN} notices that new
2619 inferiors have started or that inferiors have exited or have been
2620 detached.  By default, these messages will not be printed.
2621
2622 @kindex show print inferior-events
2623 @item show print inferior-events
2624 Show whether messages will be printed when @value{GDBN} detects that
2625 inferiors have started, exited or have been detached.
2626 @end table
2627
2628 Many commands will work the same with multiple programs as with a
2629 single program: e.g., @code{print myglobal} will simply display the
2630 value of @code{myglobal} in the current inferior.
2631
2632
2633 Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2634 get more info about the relationship of inferiors, programs, address
2635 spaces in a debug session.  You can do that with the @w{@code{maint
2636 info program-spaces}} command.
2637
2638 @table @code
2639 @kindex maint info program-spaces
2640 @item maint info program-spaces
2641 Print a list of all program spaces currently being managed by
2642 @value{GDBN}.
2643
2644 @value{GDBN} displays for each program space (in this order):
2645
2646 @enumerate
2647 @item
2648 the program space number assigned by @value{GDBN}
2649
2650 @item
2651 the name of the executable loaded into the program space, with e.g.,
2652 the @code{file} command.
2653
2654 @end enumerate
2655
2656 @noindent
2657 An asterisk @samp{*} preceding the @value{GDBN} program space number
2658 indicates the current program space.
2659
2660 In addition, below each program space line, @value{GDBN} prints extra
2661 information that isn't suitable to display in tabular form.  For
2662 example, the list of inferiors bound to the program space.
2663
2664 @smallexample
2665 (@value{GDBP}) maint info program-spaces
2666   Id   Executable
2667   2    goodbye
2668         Bound inferiors: ID 1 (process 21561)
2669 * 1    hello
2670 @end smallexample
2671
2672 Here we can see that no inferior is running the program @code{hello},
2673 while @code{process 21561} is running the program @code{goodbye}.  On
2674 some targets, it is possible that multiple inferiors are bound to the
2675 same program space.  The most common example is that of debugging both
2676 the parent and child processes of a @code{vfork} call.  For example,
2677
2678 @smallexample
2679 (@value{GDBP}) maint info program-spaces
2680   Id   Executable
2681 * 1    vfork-test
2682         Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2683 @end smallexample
2684
2685 Here, both inferior 2 and inferior 1 are running in the same program
2686 space as a result of inferior 1 having executed a @code{vfork} call.
2687 @end table
2688
2689 @node Threads
2690 @section Debugging Programs with Multiple Threads
2691
2692 @cindex threads of execution
2693 @cindex multiple threads
2694 @cindex switching threads
2695 In some operating systems, such as HP-UX and Solaris, a single program
2696 may have more than one @dfn{thread} of execution.  The precise semantics
2697 of threads differ from one operating system to another, but in general
2698 the threads of a single program are akin to multiple processes---except
2699 that they share one address space (that is, they can all examine and
2700 modify the same variables).  On the other hand, each thread has its own
2701 registers and execution stack, and perhaps private memory.
2702
2703 @value{GDBN} provides these facilities for debugging multi-thread
2704 programs:
2705
2706 @itemize @bullet
2707 @item automatic notification of new threads
2708 @item @samp{thread @var{threadno}}, a command to switch among threads
2709 @item @samp{info threads}, a command to inquire about existing threads
2710 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2711 a command to apply a command to a list of threads
2712 @item thread-specific breakpoints
2713 @item @samp{set print thread-events}, which controls printing of 
2714 messages on thread start and exit.
2715 @item @samp{set libthread-db-search-path @var{path}}, which lets
2716 the user specify which @code{libthread_db} to use if the default choice
2717 isn't compatible with the program.
2718 @end itemize
2719
2720 @quotation
2721 @emph{Warning:} These facilities are not yet available on every
2722 @value{GDBN} configuration where the operating system supports threads.
2723 If your @value{GDBN} does not support threads, these commands have no
2724 effect.  For example, a system without thread support shows no output
2725 from @samp{info threads}, and always rejects the @code{thread} command,
2726 like this:
2727
2728 @smallexample
2729 (@value{GDBP}) info threads
2730 (@value{GDBP}) thread 1
2731 Thread ID 1 not known.  Use the "info threads" command to
2732 see the IDs of currently known threads.
2733 @end smallexample
2734 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2735 @c                        doesn't support threads"?
2736 @end quotation
2737
2738 @cindex focus of debugging
2739 @cindex current thread
2740 The @value{GDBN} thread debugging facility allows you to observe all
2741 threads while your program runs---but whenever @value{GDBN} takes
2742 control, one thread in particular is always the focus of debugging.
2743 This thread is called the @dfn{current thread}.  Debugging commands show
2744 program information from the perspective of the current thread.
2745
2746 @cindex @code{New} @var{systag} message
2747 @cindex thread identifier (system)
2748 @c FIXME-implementors!! It would be more helpful if the [New...] message
2749 @c included GDB's numeric thread handle, so you could just go to that
2750 @c thread without first checking `info threads'.
2751 Whenever @value{GDBN} detects a new thread in your program, it displays
2752 the target system's identification for the thread with a message in the
2753 form @samp{[New @var{systag}]}.  @var{systag} is a thread identifier
2754 whose form varies depending on the particular system.  For example, on
2755 @sc{gnu}/Linux, you might see
2756
2757 @smallexample
2758 [New Thread 0x41e02940 (LWP 25582)]
2759 @end smallexample
2760
2761 @noindent
2762 when @value{GDBN} notices a new thread.  In contrast, on an SGI system,
2763 the @var{systag} is simply something like @samp{process 368}, with no
2764 further qualifier.
2765
2766 @c FIXME!! (1) Does the [New...] message appear even for the very first
2767 @c         thread of a program, or does it only appear for the
2768 @c         second---i.e.@: when it becomes obvious we have a multithread
2769 @c         program?
2770 @c         (2) *Is* there necessarily a first thread always?  Or do some
2771 @c         multithread systems permit starting a program with multiple
2772 @c         threads ab initio?
2773
2774 @cindex thread number
2775 @cindex thread identifier (GDB)
2776 For debugging purposes, @value{GDBN} associates its own thread
2777 number---always a single integer---with each thread in your program.
2778
2779 @table @code
2780 @kindex info threads
2781 @item info threads @r{[}@var{id}@dots{}@r{]}
2782 Display a summary of all threads currently in your program.  Optional 
2783 argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2784 means to print information only about the specified thread or threads.
2785 @value{GDBN} displays for each thread (in this order):
2786
2787 @enumerate
2788 @item
2789 the thread number assigned by @value{GDBN}
2790
2791 @item
2792 the target system's thread identifier (@var{systag})
2793
2794 @item
2795 the thread's name, if one is known.  A thread can either be named by
2796 the user (see @code{thread name}, below), or, in some cases, by the
2797 program itself.
2798
2799 @item
2800 the current stack frame summary for that thread
2801 @end enumerate
2802
2803 @noindent
2804 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2805 indicates the current thread.
2806
2807 For example,
2808 @end table
2809 @c end table here to get a little more width for example
2810
2811 @smallexample
2812 (@value{GDBP}) info threads
2813   Id   Target Id         Frame
2814   3    process 35 thread 27  0x34e5 in sigpause ()
2815   2    process 35 thread 23  0x34e5 in sigpause ()
2816 * 1    process 35 thread 13  main (argc=1, argv=0x7ffffff8)
2817     at threadtest.c:68
2818 @end smallexample
2819
2820 On Solaris, you can display more information about user threads with a
2821 Solaris-specific command:
2822
2823 @table @code
2824 @item maint info sol-threads
2825 @kindex maint info sol-threads
2826 @cindex thread info (Solaris)
2827 Display info on Solaris user threads.
2828 @end table
2829
2830 @table @code
2831 @kindex thread @var{threadno}
2832 @item thread @var{threadno}
2833 Make thread number @var{threadno} the current thread.  The command
2834 argument @var{threadno} is the internal @value{GDBN} thread number, as
2835 shown in the first field of the @samp{info threads} display.
2836 @value{GDBN} responds by displaying the system identifier of the thread
2837 you selected, and its current stack frame summary:
2838
2839 @smallexample
2840 (@value{GDBP}) thread 2
2841 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2842 #0  some_function (ignore=0x0) at example.c:8
2843 8           printf ("hello\n");
2844 @end smallexample
2845
2846 @noindent
2847 As with the @samp{[New @dots{}]} message, the form of the text after
2848 @samp{Switching to} depends on your system's conventions for identifying
2849 threads.
2850
2851 @vindex $_thread@r{, convenience variable}
2852 The debugger convenience variable @samp{$_thread} contains the number
2853 of the current thread.  You may find this useful in writing breakpoint
2854 conditional expressions, command scripts, and so forth.  See
2855 @xref{Convenience Vars,, Convenience Variables}, for general
2856 information on convenience variables.
2857
2858 @kindex thread apply
2859 @cindex apply command to several threads
2860 @item thread apply [@var{threadno} | all] @var{command}
2861 The @code{thread apply} command allows you to apply the named
2862 @var{command} to one or more threads.  Specify the numbers of the
2863 threads that you want affected with the command argument
2864 @var{threadno}.  It can be a single thread number, one of the numbers
2865 shown in the first field of the @samp{info threads} display; or it
2866 could be a range of thread numbers, as in @code{2-4}.  To apply a
2867 command to all threads, type @kbd{thread apply all @var{command}}.
2868
2869 @kindex thread name
2870 @cindex name a thread
2871 @item thread name [@var{name}]
2872 This command assigns a name to the current thread.  If no argument is
2873 given, any existing user-specified name is removed.  The thread name
2874 appears in the @samp{info threads} display.
2875
2876 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2877 determine the name of the thread as given by the OS.  On these
2878 systems, a name specified with @samp{thread name} will override the
2879 system-give name, and removing the user-specified name will cause
2880 @value{GDBN} to once again display the system-specified name.
2881
2882 @kindex thread find
2883 @cindex search for a thread
2884 @item thread find [@var{regexp}]
2885 Search for and display thread ids whose name or @var{systag}
2886 matches the supplied regular expression.
2887
2888 As well as being the complement to the @samp{thread name} command, 
2889 this command also allows you to identify a thread by its target 
2890 @var{systag}.  For instance, on @sc{gnu}/Linux, the target @var{systag}
2891 is the LWP id.
2892
2893 @smallexample
2894 (@value{GDBN}) thread find 26688
2895 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2896 (@value{GDBN}) info thread 4
2897   Id   Target Id         Frame 
2898   4    Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2899 @end smallexample
2900
2901 @kindex set print thread-events
2902 @cindex print messages on thread start and exit
2903 @item set print thread-events
2904 @itemx set print thread-events on
2905 @itemx set print thread-events off
2906 The @code{set print thread-events} command allows you to enable or
2907 disable printing of messages when @value{GDBN} notices that new threads have
2908 started or that threads have exited.  By default, these messages will
2909 be printed if detection of these events is supported by the target.
2910 Note that these messages cannot be disabled on all targets.
2911
2912 @kindex show print thread-events
2913 @item show print thread-events
2914 Show whether messages will be printed when @value{GDBN} detects that threads
2915 have started and exited.
2916 @end table
2917
2918 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2919 more information about how @value{GDBN} behaves when you stop and start
2920 programs with multiple threads.
2921
2922 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
2923 watchpoints in programs with multiple threads.
2924
2925 @anchor{set libthread-db-search-path}
2926 @table @code
2927 @kindex set libthread-db-search-path
2928 @cindex search path for @code{libthread_db}
2929 @item set libthread-db-search-path @r{[}@var{path}@r{]}
2930 If this variable is set, @var{path} is a colon-separated list of
2931 directories @value{GDBN} will use to search for @code{libthread_db}.
2932 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
2933 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
2934 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
2935 macro.
2936
2937 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2938 @code{libthread_db} library to obtain information about threads in the
2939 inferior process.  @value{GDBN} will use @samp{libthread-db-search-path}
2940 to find @code{libthread_db}.  @value{GDBN} also consults first if inferior
2941 specific thread debugging library loading is enabled
2942 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
2943
2944 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
2945 refers to the default system directories that are
2946 normally searched for loading shared libraries.  The @samp{$sdir} entry
2947 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
2948 (@pxref{libthread_db.so.1 file}).
2949
2950 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
2951 refers to the directory from which @code{libpthread}
2952 was loaded in the inferior process.
2953
2954 For any @code{libthread_db} library @value{GDBN} finds in above directories,
2955 @value{GDBN} attempts to initialize it with the current inferior process.
2956 If this initialization fails (which could happen because of a version
2957 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2958 will unload @code{libthread_db}, and continue with the next directory.
2959 If none of @code{libthread_db} libraries initialize successfully,
2960 @value{GDBN} will issue a warning and thread debugging will be disabled.
2961
2962 Setting @code{libthread-db-search-path} is currently implemented
2963 only on some platforms.
2964
2965 @kindex show libthread-db-search-path 
2966 @item show libthread-db-search-path 
2967 Display current libthread_db search path.
2968
2969 @kindex set debug libthread-db
2970 @kindex show debug libthread-db
2971 @cindex debugging @code{libthread_db}
2972 @item set debug libthread-db
2973 @itemx show debug libthread-db
2974 Turns on or off display of @code{libthread_db}-related events.
2975 Use @code{1} to enable, @code{0} to disable.
2976 @end table
2977
2978 @node Forks
2979 @section Debugging Forks
2980
2981 @cindex fork, debugging programs which call
2982 @cindex multiple processes
2983 @cindex processes, multiple
2984 On most systems, @value{GDBN} has no special support for debugging
2985 programs which create additional processes using the @code{fork}
2986 function.  When a program forks, @value{GDBN} will continue to debug the
2987 parent process and the child process will run unimpeded.  If you have
2988 set a breakpoint in any code which the child then executes, the child
2989 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2990 will cause it to terminate.
2991
2992 However, if you want to debug the child process there is a workaround
2993 which isn't too painful.  Put a call to @code{sleep} in the code which
2994 the child process executes after the fork.  It may be useful to sleep
2995 only if a certain environment variable is set, or a certain file exists,
2996 so that the delay need not occur when you don't want to run @value{GDBN}
2997 on the child.  While the child is sleeping, use the @code{ps} program to
2998 get its process ID.  Then tell @value{GDBN} (a new invocation of
2999 @value{GDBN} if you are also debugging the parent process) to attach to
3000 the child process (@pxref{Attach}).  From that point on you can debug
3001 the child process just like any other process which you attached to.
3002
3003 On some systems, @value{GDBN} provides support for debugging programs that
3004 create additional processes using the @code{fork} or @code{vfork} functions.
3005 Currently, the only platforms with this feature are HP-UX (11.x and later
3006 only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
3007
3008 By default, when a program forks, @value{GDBN} will continue to debug
3009 the parent process and the child process will run unimpeded.
3010
3011 If you want to follow the child process instead of the parent process,
3012 use the command @w{@code{set follow-fork-mode}}.
3013
3014 @table @code
3015 @kindex set follow-fork-mode
3016 @item set follow-fork-mode @var{mode}
3017 Set the debugger response to a program call of @code{fork} or
3018 @code{vfork}.  A call to @code{fork} or @code{vfork} creates a new
3019 process.  The @var{mode} argument can be:
3020
3021 @table @code
3022 @item parent
3023 The original process is debugged after a fork.  The child process runs
3024 unimpeded.  This is the default.
3025
3026 @item child
3027 The new process is debugged after a fork.  The parent process runs
3028 unimpeded.
3029
3030 @end table
3031
3032 @kindex show follow-fork-mode
3033 @item show follow-fork-mode
3034 Display the current debugger response to a @code{fork} or @code{vfork} call.
3035 @end table
3036
3037 @cindex debugging multiple processes
3038 On Linux, if you want to debug both the parent and child processes, use the
3039 command @w{@code{set detach-on-fork}}.
3040
3041 @table @code
3042 @kindex set detach-on-fork
3043 @item set detach-on-fork @var{mode}
3044 Tells gdb whether to detach one of the processes after a fork, or
3045 retain debugger control over them both.
3046
3047 @table @code
3048 @item on
3049 The child process (or parent process, depending on the value of
3050 @code{follow-fork-mode}) will be detached and allowed to run 
3051 independently.  This is the default.
3052
3053 @item off
3054 Both processes will be held under the control of @value{GDBN}.
3055 One process (child or parent, depending on the value of 
3056 @code{follow-fork-mode}) is debugged as usual, while the other
3057 is held suspended.  
3058
3059 @end table
3060
3061 @kindex show detach-on-fork
3062 @item show detach-on-fork
3063 Show whether detach-on-fork mode is on/off.
3064 @end table
3065
3066 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3067 will retain control of all forked processes (including nested forks).
3068 You can list the forked processes under the control of @value{GDBN} by
3069 using the @w{@code{info inferiors}} command, and switch from one fork
3070 to another by using the @code{inferior} command (@pxref{Inferiors and
3071 Programs, ,Debugging Multiple Inferiors and Programs}).
3072
3073 To quit debugging one of the forked processes, you can either detach
3074 from it by using the @w{@code{detach inferiors}} command (allowing it
3075 to run independently), or kill it using the @w{@code{kill inferiors}}
3076 command.  @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3077 and Programs}.
3078
3079 If you ask to debug a child process and a @code{vfork} is followed by an
3080 @code{exec}, @value{GDBN} executes the new target up to the first
3081 breakpoint in the new target.  If you have a breakpoint set on
3082 @code{main} in your original program, the breakpoint will also be set on
3083 the child process's @code{main}.
3084
3085 On some systems, when a child process is spawned by @code{vfork}, you
3086 cannot debug the child or parent until an @code{exec} call completes.
3087
3088 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3089 call executes, the new target restarts.  To restart the parent
3090 process, use the @code{file} command with the parent executable name
3091 as its argument.  By default, after an @code{exec} call executes,
3092 @value{GDBN} discards the symbols of the previous executable image.
3093 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3094 command.
3095
3096 @table @code
3097 @kindex set follow-exec-mode
3098 @item set follow-exec-mode @var{mode}
3099
3100 Set debugger response to a program call of @code{exec}.  An
3101 @code{exec} call replaces the program image of a process.
3102
3103 @code{follow-exec-mode} can be:
3104
3105 @table @code
3106 @item new
3107 @value{GDBN} creates a new inferior and rebinds the process to this
3108 new inferior.  The program the process was running before the
3109 @code{exec} call can be restarted afterwards by restarting the
3110 original inferior.
3111
3112 For example:
3113
3114 @smallexample
3115 (@value{GDBP}) info inferiors
3116 (gdb) info inferior
3117   Id   Description   Executable
3118 * 1    <null>        prog1
3119 (@value{GDBP}) run
3120 process 12020 is executing new program: prog2
3121 Program exited normally.
3122 (@value{GDBP}) info inferiors
3123   Id   Description   Executable
3124 * 2    <null>        prog2
3125   1    <null>        prog1
3126 @end smallexample
3127
3128 @item same
3129 @value{GDBN} keeps the process bound to the same inferior.  The new
3130 executable image replaces the previous executable loaded in the
3131 inferior.  Restarting the inferior after the @code{exec} call, with
3132 e.g., the @code{run} command, restarts the executable the process was
3133 running after the @code{exec} call.  This is the default mode.
3134
3135 For example:
3136
3137 @smallexample
3138 (@value{GDBP}) info inferiors
3139   Id   Description   Executable
3140 * 1    <null>        prog1
3141 (@value{GDBP}) run
3142 process 12020 is executing new program: prog2
3143 Program exited normally.
3144 (@value{GDBP}) info inferiors
3145   Id   Description   Executable
3146 * 1    <null>        prog2
3147 @end smallexample
3148
3149 @end table
3150 @end table
3151
3152 You can use the @code{catch} command to make @value{GDBN} stop whenever
3153 a @code{fork}, @code{vfork}, or @code{exec} call is made.  @xref{Set
3154 Catchpoints, ,Setting Catchpoints}.
3155
3156 @node Checkpoint/Restart
3157 @section Setting a @emph{Bookmark} to Return to Later
3158
3159 @cindex checkpoint
3160 @cindex restart
3161 @cindex bookmark
3162 @cindex snapshot of a process
3163 @cindex rewind program state
3164
3165 On certain operating systems@footnote{Currently, only
3166 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3167 program's state, called a @dfn{checkpoint}, and come back to it
3168 later.
3169
3170 Returning to a checkpoint effectively undoes everything that has
3171 happened in the program since the @code{checkpoint} was saved.  This
3172 includes changes in memory, registers, and even (within some limits)
3173 system state.  Effectively, it is like going back in time to the
3174 moment when the checkpoint was saved.
3175
3176 Thus, if you're stepping thru a program and you think you're 
3177 getting close to the point where things go wrong, you can save
3178 a checkpoint.  Then, if you accidentally go too far and miss
3179 the critical statement, instead of having to restart your program
3180 from the beginning, you can just go back to the checkpoint and
3181 start again from there.
3182
3183 This can be especially useful if it takes a lot of time or 
3184 steps to reach the point where you think the bug occurs.  
3185
3186 To use the @code{checkpoint}/@code{restart} method of debugging:
3187
3188 @table @code
3189 @kindex checkpoint
3190 @item checkpoint
3191 Save a snapshot of the debugged program's current execution state.
3192 The @code{checkpoint} command takes no arguments, but each checkpoint
3193 is assigned a small integer id, similar to a breakpoint id.
3194
3195 @kindex info checkpoints
3196 @item info checkpoints
3197 List the checkpoints that have been saved in the current debugging
3198 session.  For each checkpoint, the following information will be
3199 listed:
3200
3201 @table @code
3202 @item Checkpoint ID
3203 @item Process ID
3204 @item Code Address
3205 @item Source line, or label
3206 @end table
3207
3208 @kindex restart @var{checkpoint-id}
3209 @item restart @var{checkpoint-id}
3210 Restore the program state that was saved as checkpoint number
3211 @var{checkpoint-id}.  All program variables, registers, stack frames
3212 etc.@:  will be returned to the values that they had when the checkpoint
3213 was saved.  In essence, gdb will ``wind back the clock'' to the point
3214 in time when the checkpoint was saved.
3215
3216 Note that breakpoints, @value{GDBN} variables, command history etc.
3217 are not affected by restoring a checkpoint.  In general, a checkpoint
3218 only restores things that reside in the program being debugged, not in
3219 the debugger.
3220
3221 @kindex delete checkpoint @var{checkpoint-id}
3222 @item delete checkpoint @var{checkpoint-id}
3223 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3224
3225 @end table
3226
3227 Returning to a previously saved checkpoint will restore the user state
3228 of the program being debugged, plus a significant subset of the system
3229 (OS) state, including file pointers.  It won't ``un-write'' data from
3230 a file, but it will rewind the file pointer to the previous location,
3231 so that the previously written data can be overwritten.  For files
3232 opened in read mode, the pointer will also be restored so that the
3233 previously read data can be read again.
3234
3235 Of course, characters that have been sent to a printer (or other
3236 external device) cannot be ``snatched back'', and characters received
3237 from eg.@: a serial device can be removed from internal program buffers,
3238 but they cannot be ``pushed back'' into the serial pipeline, ready to
3239 be received again.  Similarly, the actual contents of files that have
3240 been changed cannot be restored (at this time).
3241
3242 However, within those constraints, you actually can ``rewind'' your
3243 program to a previously saved point in time, and begin debugging it
3244 again --- and you can change the course of events so as to debug a
3245 different execution path this time.
3246
3247 @cindex checkpoints and process id
3248 Finally, there is one bit of internal program state that will be
3249 different when you return to a checkpoint --- the program's process
3250 id.  Each checkpoint will have a unique process id (or @var{pid}), 
3251 and each will be different from the program's original @var{pid}.
3252 If your program has saved a local copy of its process id, this could
3253 potentially pose a problem.
3254
3255 @subsection A Non-obvious Benefit of Using Checkpoints
3256
3257 On some systems such as @sc{gnu}/Linux, address space randomization
3258 is performed on new processes for security reasons.  This makes it 
3259 difficult or impossible to set a breakpoint, or watchpoint, on an
3260 absolute address if you have to restart the program, since the 
3261 absolute location of a symbol will change from one execution to the
3262 next.
3263
3264 A checkpoint, however, is an @emph{identical} copy of a process. 
3265 Therefore if you create a checkpoint at (eg.@:) the start of main, 
3266 and simply return to that checkpoint instead of restarting the 
3267 process, you can avoid the effects of address randomization and
3268 your symbols will all stay in the same place.
3269
3270 @node Stopping
3271 @chapter Stopping and Continuing
3272
3273 The principal purposes of using a debugger are so that you can stop your
3274 program before it terminates; or so that, if your program runs into
3275 trouble, you can investigate and find out why.
3276
3277 Inside @value{GDBN}, your program may stop for any of several reasons,
3278 such as a signal, a breakpoint, or reaching a new line after a
3279 @value{GDBN} command such as @code{step}.  You may then examine and
3280 change variables, set new breakpoints or remove old ones, and then
3281 continue execution.  Usually, the messages shown by @value{GDBN} provide
3282 ample explanation of the status of your program---but you can also
3283 explicitly request this information at any time.
3284
3285 @table @code
3286 @kindex info program
3287 @item info program
3288 Display information about the status of your program: whether it is
3289 running or not, what process it is, and why it stopped.
3290 @end table
3291
3292 @menu
3293 * Breakpoints::                 Breakpoints, watchpoints, and catchpoints
3294 * Continuing and Stepping::     Resuming execution
3295 * Skipping Over Functions and Files::
3296                                 Skipping over functions and files
3297 * Signals::                     Signals
3298 * Thread Stops::                Stopping and starting multi-thread programs
3299 @end menu
3300
3301 @node Breakpoints
3302 @section Breakpoints, Watchpoints, and Catchpoints
3303
3304 @cindex breakpoints
3305 A @dfn{breakpoint} makes your program stop whenever a certain point in
3306 the program is reached.  For each breakpoint, you can add conditions to
3307 control in finer detail whether your program stops.  You can set
3308 breakpoints with the @code{break} command and its variants (@pxref{Set
3309 Breaks, ,Setting Breakpoints}), to specify the place where your program
3310 should stop by line number, function name or exact address in the
3311 program.
3312
3313 On some systems, you can set breakpoints in shared libraries before
3314 the executable is run.  There is a minor limitation on HP-UX systems:
3315 you must wait until the executable is run in order to set breakpoints
3316 in shared library routines that are not called directly by the program
3317 (for example, routines that are arguments in a @code{pthread_create}
3318 call).
3319
3320 @cindex watchpoints
3321 @cindex data breakpoints
3322 @cindex memory tracing
3323 @cindex breakpoint on memory address
3324 @cindex breakpoint on variable modification
3325 A @dfn{watchpoint} is a special breakpoint that stops your program
3326 when the value of an expression changes.  The expression may be a value
3327 of a variable, or it could involve values of one or more variables
3328 combined by operators, such as @samp{a + b}.  This is sometimes called
3329 @dfn{data breakpoints}.  You must use a different command to set
3330 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
3331 from that, you can manage a watchpoint like any other breakpoint: you
3332 enable, disable, and delete both breakpoints and watchpoints using the
3333 same commands.
3334
3335 You can arrange to have values from your program displayed automatically
3336 whenever @value{GDBN} stops at a breakpoint.  @xref{Auto Display,,
3337 Automatic Display}.
3338
3339 @cindex catchpoints
3340 @cindex breakpoint on events
3341 A @dfn{catchpoint} is another special breakpoint that stops your program
3342 when a certain kind of event occurs, such as the throwing of a C@t{++}
3343 exception or the loading of a library.  As with watchpoints, you use a
3344 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
3345 Catchpoints}), but aside from that, you can manage a catchpoint like any
3346 other breakpoint.  (To stop when your program receives a signal, use the
3347 @code{handle} command; see @ref{Signals, ,Signals}.)
3348
3349 @cindex breakpoint numbers
3350 @cindex numbers for breakpoints
3351 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
3352 catchpoint when you create it; these numbers are successive integers
3353 starting with one.  In many of the commands for controlling various
3354 features of breakpoints you use the breakpoint number to say which
3355 breakpoint you want to change.  Each breakpoint may be @dfn{enabled} or
3356 @dfn{disabled}; if disabled, it has no effect on your program until you
3357 enable it again.
3358
3359 @cindex breakpoint ranges
3360 @cindex ranges of breakpoints
3361 Some @value{GDBN} commands accept a range of breakpoints on which to
3362 operate.  A breakpoint range is either a single breakpoint number, like
3363 @samp{5}, or two such numbers, in increasing order, separated by a
3364 hyphen, like @samp{5-7}.  When a breakpoint range is given to a command,
3365 all breakpoints in that range are operated on.
3366
3367 @menu
3368 * Set Breaks::                  Setting breakpoints
3369 * Set Watchpoints::             Setting watchpoints
3370 * Set Catchpoints::             Setting catchpoints
3371 * Delete Breaks::               Deleting breakpoints
3372 * Disabling::                   Disabling breakpoints
3373 * Conditions::                  Break conditions
3374 * Break Commands::              Breakpoint command lists
3375 * Dynamic Printf::              Dynamic printf
3376 * Save Breakpoints::            How to save breakpoints in a file
3377 * Static Probe Points::         Listing static probe points
3378 * Error in Breakpoints::        ``Cannot insert breakpoints''
3379 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
3380 @end menu
3381
3382 @node Set Breaks
3383 @subsection Setting Breakpoints
3384
3385 @c FIXME LMB what does GDB do if no code on line of breakpt?
3386 @c       consider in particular declaration with/without initialization.
3387 @c
3388 @c FIXME 2 is there stuff on this already? break at fun start, already init?
3389
3390 @kindex break
3391 @kindex b @r{(@code{break})}
3392 @vindex $bpnum@r{, convenience variable}
3393 @cindex latest breakpoint
3394 Breakpoints are set with the @code{break} command (abbreviated
3395 @code{b}).  The debugger convenience variable @samp{$bpnum} records the
3396 number of the breakpoint you've set most recently; see @ref{Convenience
3397 Vars,, Convenience Variables}, for a discussion of what you can do with
3398 convenience variables.
3399
3400 @table @code
3401 @item break @var{location}
3402 Set a breakpoint at the given @var{location}, which can specify a
3403 function name, a line number, or an address of an instruction.
3404 (@xref{Specify Location}, for a list of all the possible ways to
3405 specify a @var{location}.)  The breakpoint will stop your program just
3406 before it executes any of the code in the specified @var{location}.
3407
3408 When using source languages that permit overloading of symbols, such as
3409 C@t{++}, a function name may refer to more than one possible place to break.
3410 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3411 that situation.
3412
3413 It is also possible to insert a breakpoint that will stop the program
3414 only if a specific thread (@pxref{Thread-Specific Breakpoints})
3415 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
3416
3417 @item break
3418 When called without any arguments, @code{break} sets a breakpoint at
3419 the next instruction to be executed in the selected stack frame
3420 (@pxref{Stack, ,Examining the Stack}).  In any selected frame but the
3421 innermost, this makes your program stop as soon as control
3422 returns to that frame.  This is similar to the effect of a
3423 @code{finish} command in the frame inside the selected frame---except
3424 that @code{finish} does not leave an active breakpoint.  If you use
3425 @code{break} without an argument in the innermost frame, @value{GDBN} stops
3426 the next time it reaches the current location; this may be useful
3427 inside loops.
3428
3429 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
3430 least one instruction has been executed.  If it did not do this, you
3431 would be unable to proceed past a breakpoint without first disabling the
3432 breakpoint.  This rule applies whether or not the breakpoint already
3433 existed when your program stopped.
3434
3435 @item break @dots{} if @var{cond}
3436 Set a breakpoint with condition @var{cond}; evaluate the expression
3437 @var{cond} each time the breakpoint is reached, and stop only if the
3438 value is nonzero---that is, if @var{cond} evaluates as true.
3439 @samp{@dots{}} stands for one of the possible arguments described
3440 above (or no argument) specifying where to break.  @xref{Conditions,
3441 ,Break Conditions}, for more information on breakpoint conditions.
3442
3443 @kindex tbreak
3444 @item tbreak @var{args}
3445 Set a breakpoint enabled only for one stop.  @var{args} are the
3446 same as for the @code{break} command, and the breakpoint is set in the same
3447 way, but the breakpoint is automatically deleted after the first time your
3448 program stops there.  @xref{Disabling, ,Disabling Breakpoints}.
3449
3450 @kindex hbreak
3451 @cindex hardware breakpoints
3452 @item hbreak @var{args}
3453 Set a hardware-assisted breakpoint.  @var{args} are the same as for the
3454 @code{break} command and the breakpoint is set in the same way, but the
3455 breakpoint requires hardware support and some target hardware may not
3456 have this support.  The main purpose of this is EPROM/ROM code
3457 debugging, so you can set a breakpoint at an instruction without
3458 changing the instruction.  This can be used with the new trap-generation
3459 provided by SPARClite DSU and most x86-based targets.  These targets
3460 will generate traps when a program accesses some data or instruction
3461 address that is assigned to the debug registers.  However the hardware
3462 breakpoint registers can take a limited number of breakpoints.  For
3463 example, on the DSU, only two data breakpoints can be set at a time, and
3464 @value{GDBN} will reject this command if more than two are used.  Delete
3465 or disable unused hardware breakpoints before setting new ones
3466 (@pxref{Disabling, ,Disabling Breakpoints}).
3467 @xref{Conditions, ,Break Conditions}.
3468 For remote targets, you can restrict the number of hardware
3469 breakpoints @value{GDBN} will use, see @ref{set remote
3470 hardware-breakpoint-limit}.
3471
3472 @kindex thbreak
3473 @item thbreak @var{args}
3474 Set a hardware-assisted breakpoint enabled only for one stop.  @var{args}
3475 are the same as for the @code{hbreak} command and the breakpoint is set in
3476 the same way.  However, like the @code{tbreak} command,
3477 the breakpoint is automatically deleted after the
3478 first time your program stops there.  Also, like the @code{hbreak}
3479 command, the breakpoint requires hardware support and some target hardware
3480 may not have this support.  @xref{Disabling, ,Disabling Breakpoints}.
3481 See also @ref{Conditions, ,Break Conditions}.
3482
3483 @kindex rbreak
3484 @cindex regular expression
3485 @cindex breakpoints at functions matching a regexp
3486 @cindex set breakpoints in many functions
3487 @item rbreak @var{regex}
3488 Set breakpoints on all functions matching the regular expression
3489 @var{regex}.  This command sets an unconditional breakpoint on all
3490 matches, printing a list of all breakpoints it set.  Once these
3491 breakpoints are set, they are treated just like the breakpoints set with
3492 the @code{break} command.  You can delete them, disable them, or make
3493 them conditional the same way as any other breakpoint.
3494
3495 The syntax of the regular expression is the standard one used with tools
3496 like @file{grep}.  Note that this is different from the syntax used by
3497 shells, so for instance @code{foo*} matches all functions that include
3498 an @code{fo} followed by zero or more @code{o}s.  There is an implicit
3499 @code{.*} leading and trailing the regular expression you supply, so to
3500 match only functions that begin with @code{foo}, use @code{^foo}.
3501
3502 @cindex non-member C@t{++} functions, set breakpoint in
3503 When debugging C@t{++} programs, @code{rbreak} is useful for setting
3504 breakpoints on overloaded functions that are not members of any special
3505 classes.
3506
3507 @cindex set breakpoints on all functions
3508 The @code{rbreak} command can be used to set breakpoints in
3509 @strong{all} the functions in a program, like this:
3510
3511 @smallexample
3512 (@value{GDBP}) rbreak .
3513 @end smallexample
3514
3515 @item rbreak @var{file}:@var{regex}
3516 If @code{rbreak} is called with a filename qualification, it limits
3517 the search for functions matching the given regular expression to the
3518 specified @var{file}.  This can be used, for example, to set breakpoints on
3519 every function in a given file:
3520
3521 @smallexample
3522 (@value{GDBP}) rbreak file.c:.
3523 @end smallexample
3524
3525 The colon separating the filename qualifier from the regex may
3526 optionally be surrounded by spaces.
3527
3528 @kindex info breakpoints
3529 @cindex @code{$_} and @code{info breakpoints}
3530 @item info breakpoints @r{[}@var{n}@dots{}@r{]}
3531 @itemx info break @r{[}@var{n}@dots{}@r{]}
3532 Print a table of all breakpoints, watchpoints, and catchpoints set and
3533 not deleted.  Optional argument @var{n} means print information only
3534 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3535 For each breakpoint, following columns are printed:
3536
3537 @table @emph
3538 @item Breakpoint Numbers
3539 @item Type
3540 Breakpoint, watchpoint, or catchpoint.
3541 @item Disposition
3542 Whether the breakpoint is marked to be disabled or deleted when hit.
3543 @item Enabled or Disabled
3544 Enabled breakpoints are marked with @samp{y}.  @samp{n} marks breakpoints
3545 that are not enabled.
3546 @item Address
3547 Where the breakpoint is in your program, as a memory address.  For a
3548 pending breakpoint whose address is not yet known, this field will
3549 contain @samp{<PENDING>}.  Such breakpoint won't fire until a shared
3550 library that has the symbol or line referred by breakpoint is loaded.
3551 See below for details.  A breakpoint with several locations will
3552 have @samp{<MULTIPLE>} in this field---see below for details.
3553 @item What
3554 Where the breakpoint is in the source for your program, as a file and
3555 line number.  For a pending breakpoint, the original string passed to
3556 the breakpoint command will be listed as it cannot be resolved until
3557 the appropriate shared library is loaded in the future.
3558 @end table
3559
3560 @noindent
3561 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3562 ``target''.  If mode is ``host'', breakpoint condition evaluation is done by
3563 @value{GDBN} on the host's side.  If it is ``target'', then the condition
3564 is evaluated by the target.  The @code{info break} command shows
3565 the condition on the line following the affected breakpoint, together with
3566 its condition evaluation mode in between parentheses.
3567
3568 Breakpoint commands, if any, are listed after that.  A pending breakpoint is
3569 allowed to have a condition specified for it.  The condition is not parsed for
3570 validity until a shared library is loaded that allows the pending
3571 breakpoint to resolve to a valid location.
3572
3573 @noindent
3574 @code{info break} with a breakpoint
3575 number @var{n} as argument lists only that breakpoint.  The
3576 convenience variable @code{$_} and the default examining-address for
3577 the @code{x} command are set to the address of the last breakpoint
3578 listed (@pxref{Memory, ,Examining Memory}).
3579
3580 @noindent
3581 @code{info break} displays a count of the number of times the breakpoint
3582 has been hit.  This is especially useful in conjunction with the
3583 @code{ignore} command.  You can ignore a large number of breakpoint
3584 hits, look at the breakpoint info to see how many times the breakpoint
3585 was hit, and then run again, ignoring one less than that number.  This
3586 will get you quickly to the last hit of that breakpoint.
3587
3588 @noindent
3589 For a breakpoints with an enable count (xref) greater than 1,
3590 @code{info break} also displays that count.
3591
3592 @end table
3593
3594 @value{GDBN} allows you to set any number of breakpoints at the same place in
3595 your program.  There is nothing silly or meaningless about this.  When
3596 the breakpoints are conditional, this is even useful
3597 (@pxref{Conditions, ,Break Conditions}).
3598
3599 @cindex multiple locations, breakpoints
3600 @cindex breakpoints, multiple locations
3601 It is possible that a breakpoint corresponds to several locations
3602 in your program.  Examples of this situation are:
3603
3604 @itemize @bullet
3605 @item
3606 Multiple functions in the program may have the same name.
3607
3608 @item
3609 For a C@t{++} constructor, the @value{NGCC} compiler generates several
3610 instances of the function body, used in different cases.
3611
3612 @item
3613 For a C@t{++} template function, a given line in the function can
3614 correspond to any number of instantiations.
3615
3616 @item
3617 For an inlined function, a given source line can correspond to
3618 several places where that function is inlined.
3619 @end itemize
3620
3621 In all those cases, @value{GDBN} will insert a breakpoint at all
3622 the relevant locations.
3623
3624 A breakpoint with multiple locations is displayed in the breakpoint
3625 table using several rows---one header row, followed by one row for
3626 each breakpoint location.  The header row has @samp{<MULTIPLE>} in the
3627 address column.  The rows for individual locations contain the actual
3628 addresses for locations, and show the functions to which those
3629 locations belong.  The number column for a location is of the form
3630 @var{breakpoint-number}.@var{location-number}.
3631
3632 For example:
3633
3634 @smallexample
3635 Num     Type           Disp Enb  Address    What
3636 1       breakpoint     keep y    <MULTIPLE>
3637         stop only if i==1
3638         breakpoint already hit 1 time
3639 1.1                         y    0x080486a2 in void foo<int>() at t.cc:8
3640 1.2                         y    0x080486ca in void foo<double>() at t.cc:8
3641 @end smallexample
3642
3643 Each location can be individually enabled or disabled by passing
3644 @var{breakpoint-number}.@var{location-number} as argument to the
3645 @code{enable} and @code{disable} commands.  Note that you cannot
3646 delete the individual locations from the list, you can only delete the
3647 entire list of locations that belong to their parent breakpoint (with
3648 the @kbd{delete @var{num}} command, where @var{num} is the number of
3649 the parent breakpoint, 1 in the above example).  Disabling or enabling
3650 the parent breakpoint (@pxref{Disabling}) affects all of the locations
3651 that belong to that breakpoint.
3652
3653 @cindex pending breakpoints
3654 It's quite common to have a breakpoint inside a shared library.
3655 Shared libraries can be loaded and unloaded explicitly,
3656 and possibly repeatedly, as the program is executed.  To support
3657 this use case, @value{GDBN} updates breakpoint locations whenever
3658 any shared library is loaded or unloaded.  Typically, you would
3659 set a breakpoint in a shared library at the beginning of your
3660 debugging session, when the library is not loaded, and when the
3661 symbols from the library are not available.  When you try to set
3662 breakpoint, @value{GDBN} will ask you if you want to set
3663 a so called @dfn{pending breakpoint}---breakpoint whose address
3664 is not yet resolved.
3665
3666 After the program is run, whenever a new shared library is loaded,
3667 @value{GDBN} reevaluates all the breakpoints.  When a newly loaded
3668 shared library contains the symbol or line referred to by some
3669 pending breakpoint, that breakpoint is resolved and becomes an
3670 ordinary breakpoint.  When a library is unloaded, all breakpoints
3671 that refer to its symbols or source lines become pending again.
3672
3673 This logic works for breakpoints with multiple locations, too.  For
3674 example, if you have a breakpoint in a C@t{++} template function, and
3675 a newly loaded shared library has an instantiation of that template,
3676 a new location is added to the list of locations for the breakpoint.
3677
3678 Except for having unresolved address, pending breakpoints do not
3679 differ from regular breakpoints.  You can set conditions or commands,
3680 enable and disable them and perform other breakpoint operations.
3681
3682 @value{GDBN} provides some additional commands for controlling what
3683 happens when the @samp{break} command cannot resolve breakpoint
3684 address specification to an address:
3685
3686 @kindex set breakpoint pending
3687 @kindex show breakpoint pending
3688 @table @code
3689 @item set breakpoint pending auto
3690 This is the default behavior.  When @value{GDBN} cannot find the breakpoint
3691 location, it queries you whether a pending breakpoint should be created.
3692
3693 @item set breakpoint pending on
3694 This indicates that an unrecognized breakpoint location should automatically
3695 result in a pending breakpoint being created.
3696
3697 @item set breakpoint pending off
3698 This indicates that pending breakpoints are not to be created.  Any
3699 unrecognized breakpoint location results in an error.  This setting does
3700 not affect any pending breakpoints previously created.
3701
3702 @item show breakpoint pending
3703 Show the current behavior setting for creating pending breakpoints.
3704 @end table
3705
3706 The settings above only affect the @code{break} command and its
3707 variants.  Once breakpoint is set, it will be automatically updated
3708 as shared libraries are loaded and unloaded.
3709
3710 @cindex automatic hardware breakpoints
3711 For some targets, @value{GDBN} can automatically decide if hardware or
3712 software breakpoints should be used, depending on whether the
3713 breakpoint address is read-only or read-write.  This applies to
3714 breakpoints set with the @code{break} command as well as to internal
3715 breakpoints set by commands like @code{next} and @code{finish}.  For
3716 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3717 breakpoints.
3718
3719 You can control this automatic behaviour with the following commands::
3720
3721 @kindex set breakpoint auto-hw
3722 @kindex show breakpoint auto-hw
3723 @table @code
3724 @item set breakpoint auto-hw on
3725 This is the default behavior.  When @value{GDBN} sets a breakpoint, it
3726 will try to use the target memory map to decide if software or hardware
3727 breakpoint must be used.
3728
3729 @item set breakpoint auto-hw off
3730 This indicates @value{GDBN} should not automatically select breakpoint
3731 type.  If the target provides a memory map, @value{GDBN} will warn when
3732 trying to set software breakpoint at a read-only address.
3733 @end table
3734
3735 @value{GDBN} normally implements breakpoints by replacing the program code
3736 at the breakpoint address with a special instruction, which, when
3737 executed, given control to the debugger.  By default, the program
3738 code is so modified only when the program is resumed.  As soon as
3739 the program stops, @value{GDBN} restores the original instructions.  This
3740 behaviour guards against leaving breakpoints inserted in the
3741 target should gdb abrubptly disconnect.  However, with slow remote
3742 targets, inserting and removing breakpoint can reduce the performance.
3743 This behavior can be controlled with the following commands::
3744
3745 @kindex set breakpoint always-inserted
3746 @kindex show breakpoint always-inserted
3747 @table @code
3748 @item set breakpoint always-inserted off
3749 All breakpoints, including newly added by the user, are inserted in
3750 the target only when the target is resumed.  All breakpoints are
3751 removed from the target when it stops.
3752
3753 @item set breakpoint always-inserted on
3754 Causes all breakpoints to be inserted in the target at all times.  If
3755 the user adds a new breakpoint, or changes an existing breakpoint, the
3756 breakpoints in the target are updated immediately.  A breakpoint is
3757 removed from the target only when breakpoint itself is removed.
3758
3759 @cindex non-stop mode, and @code{breakpoint always-inserted}
3760 @item set breakpoint always-inserted auto
3761 This is the default mode.  If @value{GDBN} is controlling the inferior
3762 in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3763 @code{breakpoint always-inserted} mode is on.  If @value{GDBN} is
3764 controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3765 @code{breakpoint always-inserted} mode is off.
3766 @end table
3767
3768 @value{GDBN} handles conditional breakpoints by evaluating these conditions
3769 when a breakpoint breaks.  If the condition is true, then the process being
3770 debugged stops, otherwise the process is resumed.
3771
3772 If the target supports evaluating conditions on its end, @value{GDBN} may
3773 download the breakpoint, together with its conditions, to it.
3774
3775 This feature can be controlled via the following commands:
3776
3777 @kindex set breakpoint condition-evaluation
3778 @kindex show breakpoint condition-evaluation
3779 @table @code
3780 @item set breakpoint condition-evaluation host
3781 This option commands @value{GDBN} to evaluate the breakpoint
3782 conditions on the host's side.  Unconditional breakpoints are sent to
3783 the target which in turn receives the triggers and reports them back to GDB
3784 for condition evaluation.  This is the standard evaluation mode.
3785
3786 @item set breakpoint condition-evaluation target
3787 This option commands @value{GDBN} to download breakpoint conditions
3788 to the target at the moment of their insertion.  The target
3789 is responsible for evaluating the conditional expression and reporting
3790 breakpoint stop events back to @value{GDBN} whenever the condition
3791 is true.  Due to limitations of target-side evaluation, some conditions
3792 cannot be evaluated there, e.g., conditions that depend on local data
3793 that is only known to the host.  Examples include
3794 conditional expressions involving convenience variables, complex types
3795 that cannot be handled by the agent expression parser and expressions
3796 that are too long to be sent over to the target, specially when the
3797 target is a remote system.  In these cases, the conditions will be
3798 evaluated by @value{GDBN}.
3799
3800 @item set breakpoint condition-evaluation auto
3801 This is the default mode.  If the target supports evaluating breakpoint
3802 conditions on its end, @value{GDBN} will download breakpoint conditions to
3803 the target (limitations mentioned previously apply).  If the target does
3804 not support breakpoint condition evaluation, then @value{GDBN} will fallback
3805 to evaluating all these conditions on the host's side.
3806 @end table
3807
3808
3809 @cindex negative breakpoint numbers
3810 @cindex internal @value{GDBN} breakpoints
3811 @value{GDBN} itself sometimes sets breakpoints in your program for
3812 special purposes, such as proper handling of @code{longjmp} (in C
3813 programs).  These internal breakpoints are assigned negative numbers,
3814 starting with @code{-1}; @samp{info breakpoints} does not display them.
3815 You can see these breakpoints with the @value{GDBN} maintenance command
3816 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3817
3818
3819 @node Set Watchpoints
3820 @subsection Setting Watchpoints
3821
3822 @cindex setting watchpoints
3823 You can use a watchpoint to stop execution whenever the value of an
3824 expression changes, without having to predict a particular place where
3825 this may happen.  (This is sometimes called a @dfn{data breakpoint}.)
3826 The expression may be as simple as the value of a single variable, or
3827 as complex as many variables combined by operators.  Examples include:
3828
3829 @itemize @bullet
3830 @item
3831 A reference to the value of a single variable.
3832
3833 @item
3834 An address cast to an appropriate data type.  For example,
3835 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3836 address (assuming an @code{int} occupies 4 bytes).
3837
3838 @item
3839 An arbitrarily complex expression, such as @samp{a*b + c/d}.  The
3840 expression can use any operators valid in the program's native
3841 language (@pxref{Languages}).
3842 @end itemize
3843
3844 You can set a watchpoint on an expression even if the expression can
3845 not be evaluated yet.  For instance, you can set a watchpoint on
3846 @samp{*global_ptr} before @samp{global_ptr} is initialized.
3847 @value{GDBN} will stop when your program sets @samp{global_ptr} and
3848 the expression produces a valid value.  If the expression becomes
3849 valid in some other way than changing a variable (e.g.@: if the memory
3850 pointed to by @samp{*global_ptr} becomes readable as the result of a
3851 @code{malloc} call), @value{GDBN} may not stop until the next time
3852 the expression changes.
3853
3854 @cindex software watchpoints
3855 @cindex hardware watchpoints
3856 Depending on your system, watchpoints may be implemented in software or
3857 hardware.  @value{GDBN} does software watchpointing by single-stepping your
3858 program and testing the variable's value each time, which is hundreds of
3859 times slower than normal execution.  (But this may still be worth it, to
3860 catch errors where you have no clue what part of your program is the
3861 culprit.)
3862
3863 On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3864 x86-based targets, @value{GDBN} includes support for hardware
3865 watchpoints, which do not slow down the running of your program.
3866
3867 @table @code
3868 @kindex watch
3869 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3870 Set a watchpoint for an expression.  @value{GDBN} will break when the
3871 expression @var{expr} is written into by the program and its value
3872 changes.  The simplest (and the most popular) use of this command is
3873 to watch the value of a single variable:
3874
3875 @smallexample
3876 (@value{GDBP}) watch foo
3877 @end smallexample
3878
3879 If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3880 argument, @value{GDBN} breaks only when the thread identified by
3881 @var{threadnum} changes the value of @var{expr}.  If any other threads
3882 change the value of @var{expr}, @value{GDBN} will not break.  Note
3883 that watchpoints restricted to a single thread in this way only work
3884 with Hardware Watchpoints.
3885
3886 Ordinarily a watchpoint respects the scope of variables in @var{expr}
3887 (see below).  The @code{-location} argument tells @value{GDBN} to
3888 instead watch the memory referred to by @var{expr}.  In this case,
3889 @value{GDBN} will evaluate @var{expr}, take the address of the result,
3890 and watch the memory at that address.  The type of the result is used
3891 to determine the size of the watched memory.  If the expression's
3892 result does not have an address, then @value{GDBN} will print an
3893 error.
3894
3895 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3896 of masked watchpoints, if the current architecture supports this
3897 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3898 Embedded}.)  A @dfn{masked watchpoint} specifies a mask in addition
3899 to an address to watch.  The mask specifies that some bits of an address
3900 (the bits which are reset in the mask) should be ignored when matching
3901 the address accessed by the inferior against the watchpoint address.
3902 Thus, a masked watchpoint watches many addresses simultaneously---those
3903 addresses whose unmasked bits are identical to the unmasked bits in the
3904 watchpoint address.  The @code{mask} argument implies @code{-location}.
3905 Examples:
3906
3907 @smallexample
3908 (@value{GDBP}) watch foo mask 0xffff00ff
3909 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
3910 @end smallexample
3911
3912 @kindex rwatch
3913 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3914 Set a watchpoint that will break when the value of @var{expr} is read
3915 by the program.
3916
3917 @kindex awatch
3918 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3919 Set a watchpoint that will break when @var{expr} is either read from
3920 or written into by the program.
3921
3922 @kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
3923 @item info watchpoints @r{[}@var{n}@dots{}@r{]}
3924 This command prints a list of watchpoints, using the same format as
3925 @code{info break} (@pxref{Set Breaks}).
3926 @end table
3927
3928 If you watch for a change in a numerically entered address you need to
3929 dereference it, as the address itself is just a constant number which will
3930 never change.  @value{GDBN} refuses to create a watchpoint that watches
3931 a never-changing value:
3932
3933 @smallexample
3934 (@value{GDBP}) watch 0x600850
3935 Cannot watch constant value 0x600850.
3936 (@value{GDBP}) watch *(int *) 0x600850
3937 Watchpoint 1: *(int *) 6293584
3938 @end smallexample
3939
3940 @value{GDBN} sets a @dfn{hardware watchpoint} if possible.  Hardware
3941 watchpoints execute very quickly, and the debugger reports a change in
3942 value at the exact instruction where the change occurs.  If @value{GDBN}
3943 cannot set a hardware watchpoint, it sets a software watchpoint, which
3944 executes more slowly and reports the change in value at the next
3945 @emph{statement}, not the instruction, after the change occurs.
3946
3947 @cindex use only software watchpoints
3948 You can force @value{GDBN} to use only software watchpoints with the
3949 @kbd{set can-use-hw-watchpoints 0} command.  With this variable set to
3950 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3951 the underlying system supports them.  (Note that hardware-assisted
3952 watchpoints that were set @emph{before} setting
3953 @code{can-use-hw-watchpoints} to zero will still use the hardware
3954 mechanism of watching expression values.)
3955
3956 @table @code
3957 @item set can-use-hw-watchpoints
3958 @kindex set can-use-hw-watchpoints
3959 Set whether or not to use hardware watchpoints.
3960
3961 @item show can-use-hw-watchpoints
3962 @kindex show can-use-hw-watchpoints
3963 Show the current mode of using hardware watchpoints.
3964 @end table
3965
3966 For remote targets, you can restrict the number of hardware
3967 watchpoints @value{GDBN} will use, see @ref{set remote
3968 hardware-breakpoint-limit}.
3969
3970 When you issue the @code{watch} command, @value{GDBN} reports
3971
3972 @smallexample
3973 Hardware watchpoint @var{num}: @var{expr}
3974 @end smallexample
3975
3976 @noindent
3977 if it was able to set a hardware watchpoint.
3978
3979 Currently, the @code{awatch} and @code{rwatch} commands can only set
3980 hardware watchpoints, because accesses to data that don't change the
3981 value of the watched expression cannot be detected without examining
3982 every instruction as it is being executed, and @value{GDBN} does not do
3983 that currently.  If @value{GDBN} finds that it is unable to set a
3984 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3985 will print a message like this:
3986
3987 @smallexample
3988 Expression cannot be implemented with read/access watchpoint.
3989 @end smallexample
3990
3991 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3992 data type of the watched expression is wider than what a hardware
3993 watchpoint on the target machine can handle.  For example, some systems
3994 can only watch regions that are up to 4 bytes wide; on such systems you
3995 cannot set hardware watchpoints for an expression that yields a
3996 double-precision floating-point number (which is typically 8 bytes
3997 wide).  As a work-around, it might be possible to break the large region
3998 into a series of smaller ones and watch them with separate watchpoints.
3999
4000 If you set too many hardware watchpoints, @value{GDBN} might be unable
4001 to insert all of them when you resume the execution of your program.
4002 Since the precise number of active watchpoints is unknown until such
4003 time as the program is about to be resumed, @value{GDBN} might not be
4004 able to warn you about this when you set the watchpoints, and the
4005 warning will be printed only when the program is resumed:
4006
4007 @smallexample
4008 Hardware watchpoint @var{num}: Could not insert watchpoint
4009 @end smallexample
4010
4011 @noindent
4012 If this happens, delete or disable some of the watchpoints.
4013
4014 Watching complex expressions that reference many variables can also
4015 exhaust the resources available for hardware-assisted watchpoints.
4016 That's because @value{GDBN} needs to watch every variable in the
4017 expression with separately allocated resources.
4018
4019 If you call a function interactively using @code{print} or @code{call},
4020 any watchpoints you have set will be inactive until @value{GDBN} reaches another
4021 kind of breakpoint or the call completes.
4022
4023 @value{GDBN} automatically deletes watchpoints that watch local
4024 (automatic) variables, or expressions that involve such variables, when
4025 they go out of scope, that is, when the execution leaves the block in
4026 which these variables were defined.  In particular, when the program
4027 being debugged terminates, @emph{all} local variables go out of scope,
4028 and so only watchpoints that watch global variables remain set.  If you
4029 rerun the program, you will need to set all such watchpoints again.  One
4030 way of doing that would be to set a code breakpoint at the entry to the
4031 @code{main} function and when it breaks, set all the watchpoints.
4032
4033 @cindex watchpoints and threads
4034 @cindex threads and watchpoints
4035 In multi-threaded programs, watchpoints will detect changes to the
4036 watched expression from every thread.
4037
4038 @quotation
4039 @emph{Warning:} In multi-threaded programs, software watchpoints
4040 have only limited usefulness.  If @value{GDBN} creates a software
4041 watchpoint, it can only watch the value of an expression @emph{in a
4042 single thread}.  If you are confident that the expression can only
4043 change due to the current thread's activity (and if you are also
4044 confident that no other thread can become current), then you can use
4045 software watchpoints as usual.  However, @value{GDBN} may not notice
4046 when a non-current thread's activity changes the expression.  (Hardware
4047 watchpoints, in contrast, watch an expression in all threads.)
4048 @end quotation
4049
4050 @xref{set remote hardware-watchpoint-limit}.
4051
4052 @node Set Catchpoints
4053 @subsection Setting Catchpoints
4054 @cindex catchpoints, setting
4055 @cindex exception handlers
4056 @cindex event handling
4057
4058 You can use @dfn{catchpoints} to cause the debugger to stop for certain
4059 kinds of program events, such as C@t{++} exceptions or the loading of a
4060 shared library.  Use the @code{catch} command to set a catchpoint.
4061
4062 @table @code
4063 @kindex catch
4064 @item catch @var{event}
4065 Stop when @var{event} occurs.  @var{event} can be any of the following:
4066 @table @code
4067 @item throw
4068 @cindex stop on C@t{++} exceptions
4069 The throwing of a C@t{++} exception.
4070
4071 @item catch
4072 The catching of a C@t{++} exception.
4073
4074 @item exception
4075 @cindex Ada exception catching
4076 @cindex catch Ada exceptions
4077 An Ada exception being raised.  If an exception name is specified
4078 at the end of the command (eg @code{catch exception Program_Error}),
4079 the debugger will stop only when this specific exception is raised.
4080 Otherwise, the debugger stops execution when any Ada exception is raised.
4081
4082 When inserting an exception catchpoint on a user-defined exception whose
4083 name is identical to one of the exceptions defined by the language, the
4084 fully qualified name must be used as the exception name.  Otherwise,
4085 @value{GDBN} will assume that it should stop on the pre-defined exception
4086 rather than the user-defined one.  For instance, assuming an exception
4087 called @code{Constraint_Error} is defined in package @code{Pck}, then
4088 the command to use to catch such exceptions is @kbd{catch exception
4089 Pck.Constraint_Error}.
4090
4091 @item exception unhandled
4092 An exception that was raised but is not handled by the program.
4093
4094 @item assert
4095 A failed Ada assertion.
4096
4097 @item exec
4098 @cindex break on fork/exec
4099 A call to @code{exec}.  This is currently only available for HP-UX
4100 and @sc{gnu}/Linux.
4101
4102 @item syscall
4103 @itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{} 
4104 @cindex break on a system call.
4105 A call to or return from a system call, a.k.a.@: @dfn{syscall}.  A
4106 syscall is a mechanism for application programs to request a service
4107 from the operating system (OS) or one of the OS system services.
4108 @value{GDBN} can catch some or all of the syscalls issued by the
4109 debuggee, and show the related information for each syscall.  If no
4110 argument is specified, calls to and returns from all system calls
4111 will be caught.
4112
4113 @var{name} can be any system call name that is valid for the
4114 underlying OS.  Just what syscalls are valid depends on the OS.  On
4115 GNU and Unix systems, you can find the full list of valid syscall
4116 names on @file{/usr/include/asm/unistd.h}.
4117
4118 @c For MS-Windows, the syscall names and the corresponding numbers
4119 @c can be found, e.g., on this URL:
4120 @c http://www.metasploit.com/users/opcode/syscalls.html
4121 @c but we don't support Windows syscalls yet.
4122
4123 Normally, @value{GDBN} knows in advance which syscalls are valid for
4124 each OS, so you can use the @value{GDBN} command-line completion
4125 facilities (@pxref{Completion,, command completion}) to list the
4126 available choices.
4127
4128 You may also specify the system call numerically.  A syscall's
4129 number is the value passed to the OS's syscall dispatcher to
4130 identify the requested service.  When you specify the syscall by its
4131 name, @value{GDBN} uses its database of syscalls to convert the name
4132 into the corresponding numeric code, but using the number directly
4133 may be useful if @value{GDBN}'s database does not have the complete
4134 list of syscalls on your system (e.g., because @value{GDBN} lags
4135 behind the OS upgrades).
4136
4137 The example below illustrates how this command works if you don't provide
4138 arguments to it:
4139
4140 @smallexample
4141 (@value{GDBP}) catch syscall
4142 Catchpoint 1 (syscall)
4143 (@value{GDBP}) r
4144 Starting program: /tmp/catch-syscall
4145
4146 Catchpoint 1 (call to syscall 'close'), \
4147            0xffffe424 in __kernel_vsyscall ()
4148 (@value{GDBP}) c
4149 Continuing.
4150
4151 Catchpoint 1 (returned from syscall 'close'), \
4152         0xffffe424 in __kernel_vsyscall ()
4153 (@value{GDBP})
4154 @end smallexample
4155
4156 Here is an example of catching a system call by name:
4157
4158 @smallexample
4159 (@value{GDBP}) catch syscall chroot
4160 Catchpoint 1 (syscall 'chroot' [61])
4161 (@value{GDBP}) r
4162 Starting program: /tmp/catch-syscall
4163
4164 Catchpoint 1 (call to syscall 'chroot'), \
4165                    0xffffe424 in __kernel_vsyscall ()
4166 (@value{GDBP}) c
4167 Continuing.
4168
4169 Catchpoint 1 (returned from syscall 'chroot'), \
4170         0xffffe424 in __kernel_vsyscall ()
4171 (@value{GDBP})
4172 @end smallexample
4173
4174 An example of specifying a system call numerically.  In the case
4175 below, the syscall number has a corresponding entry in the XML
4176 file, so @value{GDBN} finds its name and prints it:
4177
4178 @smallexample
4179 (@value{GDBP}) catch syscall 252
4180 Catchpoint 1 (syscall(s) 'exit_group')
4181 (@value{GDBP}) r
4182 Starting program: /tmp/catch-syscall
4183
4184 Catchpoint 1 (call to syscall 'exit_group'), \
4185                    0xffffe424 in __kernel_vsyscall ()
4186 (@value{GDBP}) c
4187 Continuing.
4188
4189 Program exited normally.
4190 (@value{GDBP})
4191 @end smallexample
4192
4193 However, there can be situations when there is no corresponding name
4194 in XML file for that syscall number.  In this case, @value{GDBN} prints
4195 a warning message saying that it was not able to find the syscall name,
4196 but the catchpoint will be set anyway.  See the example below:
4197
4198 @smallexample
4199 (@value{GDBP}) catch syscall 764
4200 warning: The number '764' does not represent a known syscall.
4201 Catchpoint 2 (syscall 764)
4202 (@value{GDBP})
4203 @end smallexample
4204
4205 If you configure @value{GDBN} using the @samp{--without-expat} option,
4206 it will not be able to display syscall names.  Also, if your
4207 architecture does not have an XML file describing its system calls,
4208 you will not be able to see the syscall names.  It is important to
4209 notice that these two features are used for accessing the syscall
4210 name database.  In either case, you will see a warning like this:
4211
4212 @smallexample
4213 (@value{GDBP}) catch syscall
4214 warning: Could not open "syscalls/i386-linux.xml"
4215 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4216 GDB will not be able to display syscall names.
4217 Catchpoint 1 (syscall)
4218 (@value{GDBP})
4219 @end smallexample
4220
4221 Of course, the file name will change depending on your architecture and system.
4222
4223 Still using the example above, you can also try to catch a syscall by its
4224 number.  In this case, you would see something like:
4225
4226 @smallexample
4227 (@value{GDBP}) catch syscall 252
4228 Catchpoint 1 (syscall(s) 252)
4229 @end smallexample
4230
4231 Again, in this case @value{GDBN} would not be able to display syscall's names.
4232
4233 @item fork
4234 A call to @code{fork}.  This is currently only available for HP-UX
4235 and @sc{gnu}/Linux.
4236
4237 @item vfork
4238 A call to @code{vfork}.  This is currently only available for HP-UX
4239 and @sc{gnu}/Linux.
4240
4241 @item load @r{[}regexp@r{]}
4242 @itemx unload @r{[}regexp@r{]}
4243 The loading or unloading of a shared library.  If @var{regexp} is
4244 given, then the catchpoint will stop only if the regular expression
4245 matches one of the affected libraries.
4246
4247 @end table
4248
4249 @item tcatch @var{event}
4250 Set a catchpoint that is enabled only for one stop.  The catchpoint is
4251 automatically deleted after the first time the event is caught.
4252
4253 @end table
4254
4255 Use the @code{info break} command to list the current catchpoints.
4256
4257 There are currently some limitations to C@t{++} exception handling
4258 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4259
4260 @itemize @bullet
4261 @item
4262 If you call a function interactively, @value{GDBN} normally returns
4263 control to you when the function has finished executing.  If the call
4264 raises an exception, however, the call may bypass the mechanism that
4265 returns control to you and cause your program either to abort or to
4266 simply continue running until it hits a breakpoint, catches a signal
4267 that @value{GDBN} is listening for, or exits.  This is the case even if
4268 you set a catchpoint for the exception; catchpoints on exceptions are
4269 disabled within interactive calls.
4270
4271 @item
4272 You cannot raise an exception interactively.
4273
4274 @item
4275 You cannot install an exception handler interactively.
4276 @end itemize
4277
4278 @cindex raise exceptions
4279 Sometimes @code{catch} is not the best way to debug exception handling:
4280 if you need to know exactly where an exception is raised, it is better to
4281 stop @emph{before} the exception handler is called, since that way you
4282 can see the stack before any unwinding takes place.  If you set a
4283 breakpoint in an exception handler instead, it may not be easy to find
4284 out where the exception was raised.
4285
4286 To stop just before an exception handler is called, you need some
4287 knowledge of the implementation.  In the case of @sc{gnu} C@t{++}, exceptions are
4288 raised by calling a library function named @code{__raise_exception}
4289 which has the following ANSI C interface:
4290
4291 @smallexample
4292     /* @var{addr} is where the exception identifier is stored.
4293        @var{id} is the exception identifier.  */
4294     void __raise_exception (void **addr, void *id);
4295 @end smallexample
4296
4297 @noindent
4298 To make the debugger catch all exceptions before any stack
4299 unwinding takes place, set a breakpoint on @code{__raise_exception}
4300 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
4301
4302 With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
4303 that depends on the value of @var{id}, you can stop your program when
4304 a specific exception is raised.  You can use multiple conditional
4305 breakpoints to stop your program when any of a number of exceptions are
4306 raised.
4307
4308
4309 @node Delete Breaks
4310 @subsection Deleting Breakpoints
4311
4312 @cindex clearing breakpoints, watchpoints, catchpoints
4313 @cindex deleting breakpoints, watchpoints, catchpoints
4314 It is often necessary to eliminate a breakpoint, watchpoint, or
4315 catchpoint once it has done its job and you no longer want your program
4316 to stop there.  This is called @dfn{deleting} the breakpoint.  A
4317 breakpoint that has been deleted no longer exists; it is forgotten.
4318
4319 With the @code{clear} command you can delete breakpoints according to
4320 where they are in your program.  With the @code{delete} command you can
4321 delete individual breakpoints, watchpoints, or catchpoints by specifying
4322 their breakpoint numbers.
4323
4324 It is not necessary to delete a breakpoint to proceed past it.  @value{GDBN}
4325 automatically ignores breakpoints on the first instruction to be executed
4326 when you continue execution without changing the execution address.
4327
4328 @table @code
4329 @kindex clear
4330 @item clear
4331 Delete any breakpoints at the next instruction to be executed in the
4332 selected stack frame (@pxref{Selection, ,Selecting a Frame}).  When
4333 the innermost frame is selected, this is a good way to delete a
4334 breakpoint where your program just stopped.
4335
4336 @item clear @var{location}
4337 Delete any breakpoints set at the specified @var{location}.
4338 @xref{Specify Location}, for the various forms of @var{location}; the
4339 most useful ones are listed below:
4340
4341 @table @code
4342 @item clear @var{function}
4343 @itemx clear @var{filename}:@var{function}
4344 Delete any breakpoints set at entry to the named @var{function}.
4345
4346 @item clear @var{linenum}
4347 @itemx clear @var{filename}:@var{linenum}
4348 Delete any breakpoints set at or within the code of the specified
4349 @var{linenum} of the specified @var{filename}.
4350 @end table
4351
4352 @cindex delete breakpoints
4353 @kindex delete
4354 @kindex d @r{(@code{delete})}
4355 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4356 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4357 ranges specified as arguments.  If no argument is specified, delete all
4358 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4359 confirm off}).  You can abbreviate this command as @code{d}.
4360 @end table
4361
4362 @node Disabling
4363 @subsection Disabling Breakpoints
4364
4365 @cindex enable/disable a breakpoint
4366 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4367 prefer to @dfn{disable} it.  This makes the breakpoint inoperative as if
4368 it had been deleted, but remembers the information on the breakpoint so
4369 that you can @dfn{enable} it again later.
4370
4371 You disable and enable breakpoints, watchpoints, and catchpoints with
4372 the @code{enable} and @code{disable} commands, optionally specifying
4373 one or more breakpoint numbers as arguments.  Use @code{info break} to
4374 print a list of all breakpoints, watchpoints, and catchpoints if you
4375 do not know which numbers to use.
4376
4377 Disabling and enabling a breakpoint that has multiple locations
4378 affects all of its locations.
4379
4380 A breakpoint, watchpoint, or catchpoint can have any of several
4381 different states of enablement:
4382
4383 @itemize @bullet
4384 @item
4385 Enabled.  The breakpoint stops your program.  A breakpoint set
4386 with the @code{break} command starts out in this state.
4387 @item
4388 Disabled.  The breakpoint has no effect on your program.
4389 @item
4390 Enabled once.  The breakpoint stops your program, but then becomes
4391 disabled.
4392 @item
4393 Enabled for a count.  The breakpoint stops your program for the next
4394 N times, then becomes disabled.
4395 @item
4396 Enabled for deletion.  The breakpoint stops your program, but
4397 immediately after it does so it is deleted permanently.  A breakpoint
4398 set with the @code{tbreak} command starts out in this state.
4399 @end itemize
4400
4401 You can use the following commands to enable or disable breakpoints,
4402 watchpoints, and catchpoints:
4403
4404 @table @code
4405 @kindex disable
4406 @kindex dis @r{(@code{disable})}
4407 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4408 Disable the specified breakpoints---or all breakpoints, if none are
4409 listed.  A disabled breakpoint has no effect but is not forgotten.  All
4410 options such as ignore-counts, conditions and commands are remembered in
4411 case the breakpoint is enabled again later.  You may abbreviate
4412 @code{disable} as @code{dis}.
4413
4414 @kindex enable
4415 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4416 Enable the specified breakpoints (or all defined breakpoints).  They
4417 become effective once again in stopping your program.
4418
4419 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
4420 Enable the specified breakpoints temporarily.  @value{GDBN} disables any
4421 of these breakpoints immediately after stopping your program.
4422
4423 @item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4424 Enable the specified breakpoints temporarily.  @value{GDBN} records
4425 @var{count} with each of the specified breakpoints, and decrements a
4426 breakpoint's count when it is hit.  When any count reaches 0,
4427 @value{GDBN} disables that breakpoint.  If a breakpoint has an ignore
4428 count (@pxref{Conditions, ,Break Conditions}), that will be
4429 decremented to 0 before @var{count} is affected.
4430
4431 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
4432 Enable the specified breakpoints to work once, then die.  @value{GDBN}
4433 deletes any of these breakpoints as soon as your program stops there.
4434 Breakpoints set by the @code{tbreak} command start out in this state.
4435 @end table
4436
4437 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4438 @c confusing: tbreak is also initially enabled.
4439 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
4440 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
4441 subsequently, they become disabled or enabled only when you use one of
4442 the commands above.  (The command @code{until} can set and delete a
4443 breakpoint of its own, but it does not change the state of your other
4444 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
4445 Stepping}.)
4446
4447 @node Conditions
4448 @subsection Break Conditions
4449 @cindex conditional breakpoints
4450 @cindex breakpoint conditions
4451
4452 @c FIXME what is scope of break condition expr?  Context where wanted?
4453 @c      in particular for a watchpoint?
4454 The simplest sort of breakpoint breaks every time your program reaches a
4455 specified place.  You can also specify a @dfn{condition} for a
4456 breakpoint.  A condition is just a Boolean expression in your
4457 programming language (@pxref{Expressions, ,Expressions}).  A breakpoint with
4458 a condition evaluates the expression each time your program reaches it,
4459 and your program stops only if the condition is @emph{true}.
4460
4461 This is the converse of using assertions for program validation; in that
4462 situation, you want to stop when the assertion is violated---that is,
4463 when the condition is false.  In C, if you want to test an assertion expressed
4464 by the condition @var{assert}, you should set the condition
4465 @samp{! @var{assert}} on the appropriate breakpoint.
4466
4467 Conditions are also accepted for watchpoints; you may not need them,
4468 since a watchpoint is inspecting the value of an expression anyhow---but
4469 it might be simpler, say, to just set a watchpoint on a variable name,
4470 and specify a condition that tests whether the new value is an interesting
4471 one.
4472
4473 Break conditions can have side effects, and may even call functions in
4474 your program.  This can be useful, for example, to activate functions
4475 that log program progress, or to use your own print functions to
4476 format special data structures.  The effects are completely predictable
4477 unless there is another enabled breakpoint at the same address.  (In
4478 that case, @value{GDBN} might see the other breakpoint first and stop your
4479 program without checking the condition of this one.)  Note that
4480 breakpoint commands are usually more convenient and flexible than break
4481 conditions for the
4482 purpose of performing side effects when a breakpoint is reached
4483 (@pxref{Break Commands, ,Breakpoint Command Lists}).
4484
4485 Breakpoint conditions can also be evaluated on the target's side if
4486 the target supports it.  Instead of evaluating the conditions locally,
4487 @value{GDBN} encodes the expression into an agent expression
4488 (@pxref{Agent Expressions}) suitable for execution on the target,
4489 independently of @value{GDBN}.  Global variables become raw memory
4490 locations, locals become stack accesses, and so forth.
4491
4492 In this case, @value{GDBN} will only be notified of a breakpoint trigger
4493 when its condition evaluates to true.  This mechanism may provide faster
4494 response times depending on the performance characteristics of the target
4495 since it does not need to keep @value{GDBN} informed about
4496 every breakpoint trigger, even those with false conditions.
4497
4498 Break conditions can be specified when a breakpoint is set, by using
4499 @samp{if} in the arguments to the @code{break} command.  @xref{Set
4500 Breaks, ,Setting Breakpoints}.  They can also be changed at any time
4501 with the @code{condition} command.
4502
4503 You can also use the @code{if} keyword with the @code{watch} command.
4504 The @code{catch} command does not recognize the @code{if} keyword;
4505 @code{condition} is the only way to impose a further condition on a
4506 catchpoint.
4507
4508 @table @code
4509 @kindex condition
4510 @item condition @var{bnum} @var{expression}
4511 Specify @var{expression} as the break condition for breakpoint,
4512 watchpoint, or catchpoint number @var{bnum}.  After you set a condition,
4513 breakpoint @var{bnum} stops your program only if the value of
4514 @var{expression} is true (nonzero, in C).  When you use
4515 @code{condition}, @value{GDBN} checks @var{expression} immediately for
4516 syntactic correctness, and to determine whether symbols in it have
4517 referents in the context of your breakpoint.  If @var{expression} uses
4518 symbols not referenced in the context of the breakpoint, @value{GDBN}
4519 prints an error message:
4520
4521 @smallexample
4522 No symbol "foo" in current context.
4523 @end smallexample
4524
4525 @noindent
4526 @value{GDBN} does
4527 not actually evaluate @var{expression} at the time the @code{condition}
4528 command (or a command that sets a breakpoint with a condition, like
4529 @code{break if @dots{}}) is given, however.  @xref{Expressions, ,Expressions}.
4530
4531 @item condition @var{bnum}
4532 Remove the condition from breakpoint number @var{bnum}.  It becomes
4533 an ordinary unconditional breakpoint.
4534 @end table
4535
4536 @cindex ignore count (of breakpoint)
4537 A special case of a breakpoint condition is to stop only when the
4538 breakpoint has been reached a certain number of times.  This is so
4539 useful that there is a special way to do it, using the @dfn{ignore
4540 count} of the breakpoint.  Every breakpoint has an ignore count, which
4541 is an integer.  Most of the time, the ignore count is zero, and
4542 therefore has no effect.  But if your program reaches a breakpoint whose
4543 ignore count is positive, then instead of stopping, it just decrements
4544 the ignore count by one and continues.  As a result, if the ignore count
4545 value is @var{n}, the breakpoint does not stop the next @var{n} times
4546 your program reaches it.
4547
4548 @table @code
4549 @kindex ignore
4550 @item ignore @var{bnum} @var{count}
4551 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4552 The next @var{count} times the breakpoint is reached, your program's
4553 execution does not stop; other than to decrement the ignore count, @value{GDBN}
4554 takes no action.
4555
4556 To make the breakpoint stop the next time it is reached, specify
4557 a count of zero.
4558
4559 When you use @code{continue} to resume execution of your program from a
4560 breakpoint, you can specify an ignore count directly as an argument to
4561 @code{continue}, rather than using @code{ignore}.  @xref{Continuing and
4562 Stepping,,Continuing and Stepping}.
4563
4564 If a breakpoint has a positive ignore count and a condition, the
4565 condition is not checked.  Once the ignore count reaches zero,
4566 @value{GDBN} resumes checking the condition.
4567
4568 You could achieve the effect of the ignore count with a condition such
4569 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4570 is decremented each time.  @xref{Convenience Vars, ,Convenience
4571 Variables}.
4572 @end table
4573
4574 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4575
4576
4577 @node Break Commands
4578 @subsection Breakpoint Command Lists
4579
4580 @cindex breakpoint commands
4581 You can give any breakpoint (or watchpoint or catchpoint) a series of
4582 commands to execute when your program stops due to that breakpoint.  For
4583 example, you might want to print the values of certain expressions, or
4584 enable other breakpoints.
4585
4586 @table @code
4587 @kindex commands
4588 @kindex end@r{ (breakpoint commands)}
4589 @item commands @r{[}@var{range}@dots{}@r{]}
4590 @itemx @dots{} @var{command-list} @dots{}
4591 @itemx end
4592 Specify a list of commands for the given breakpoints.  The commands
4593 themselves appear on the following lines.  Type a line containing just
4594 @code{end} to terminate the commands.
4595
4596 To remove all commands from a breakpoint, type @code{commands} and
4597 follow it immediately with @code{end}; that is, give no commands.
4598
4599 With no argument, @code{commands} refers to the last breakpoint,
4600 watchpoint, or catchpoint set (not to the breakpoint most recently
4601 encountered).  If the most recent breakpoints were set with a single
4602 command, then the @code{commands} will apply to all the breakpoints
4603 set by that command.  This applies to breakpoints set by
4604 @code{rbreak}, and also applies when a single @code{break} command
4605 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4606 Expressions}).
4607 @end table
4608
4609 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4610 disabled within a @var{command-list}.
4611
4612 You can use breakpoint commands to start your program up again.  Simply
4613 use the @code{continue} command, or @code{step}, or any other command
4614 that resumes execution.
4615
4616 Any other commands in the command list, after a command that resumes
4617 execution, are ignored.  This is because any time you resume execution
4618 (even with a simple @code{next} or @code{step}), you may encounter
4619 another breakpoint---which could have its own command list, leading to
4620 ambiguities about which list to execute.
4621
4622 @kindex silent
4623 If the first command you specify in a command list is @code{silent}, the
4624 usual message about stopping at a breakpoint is not printed.  This may
4625 be desirable for breakpoints that are to print a specific message and
4626 then continue.  If none of the remaining commands print anything, you
4627 see no sign that the breakpoint was reached.  @code{silent} is
4628 meaningful only at the beginning of a breakpoint command list.
4629
4630 The commands @code{echo}, @code{output}, and @code{printf} allow you to
4631 print precisely controlled output, and are often useful in silent
4632 breakpoints.  @xref{Output, ,Commands for Controlled Output}.
4633
4634 For example, here is how you could use breakpoint commands to print the
4635 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4636
4637 @smallexample
4638 break foo if x>0
4639 commands
4640 silent
4641 printf "x is %d\n",x
4642 cont
4643 end
4644 @end smallexample
4645
4646 One application for breakpoint commands is to compensate for one bug so
4647 you can test for another.  Put a breakpoint just after the erroneous line
4648 of code, give it a condition to detect the case in which something
4649 erroneous has been done, and give it commands to assign correct values
4650 to any variables that need them.  End with the @code{continue} command
4651 so that your program does not stop, and start with the @code{silent}
4652 command so that no output is produced.  Here is an example:
4653
4654 @smallexample
4655 break 403
4656 commands
4657 silent
4658 set x = y + 4
4659 cont
4660 end
4661 @end smallexample
4662
4663 @node Dynamic Printf
4664 @subsection Dynamic Printf
4665
4666 @cindex dynamic printf
4667 @cindex dprintf
4668 The dynamic printf command @code{dprintf} combines a breakpoint with
4669 formatted printing of your program's data to give you the effect of
4670 inserting @code{printf} calls into your program on-the-fly, without
4671 having to recompile it.
4672
4673 In its most basic form, the output goes to the GDB console.  However,
4674 you can set the variable @code{dprintf-style} for alternate handling.
4675 For instance, you can ask to format the output by calling your
4676 program's @code{printf} function.  This has the advantage that the
4677 characters go to the program's output device, so they can recorded in
4678 redirects to files and so forth.
4679
4680 If you are doing remote debugging with a stub or agent, you can also
4681 ask to have the printf handled by the remote agent.  In addition to
4682 ensuring that the output goes to the remote program's device along
4683 with any other output the program might produce, you can also ask that
4684 the dprintf remain active even after disconnecting from the remote
4685 target.  Using the stub/agent is also more efficient, as it can do
4686 everything without needing to communicate with @value{GDBN}.
4687
4688 @table @code
4689 @kindex dprintf
4690 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4691 Whenever execution reaches @var{location}, print the values of one or
4692 more @var{expressions} under the control of the string @var{template}.
4693 To print several values, separate them with commas.
4694
4695 @item set dprintf-style @var{style}
4696 Set the dprintf output to be handled in one of several different
4697 styles enumerated below.  A change of style affects all existing
4698 dynamic printfs immediately.  (If you need individual control over the
4699 print commands, simply define normal breakpoints with
4700 explicitly-supplied command lists.)
4701
4702 @item gdb
4703 @kindex dprintf-style gdb
4704 Handle the output using the @value{GDBN} @code{printf} command.
4705
4706 @item call
4707 @kindex dprintf-style call
4708 Handle the output by calling a function in your program (normally
4709 @code{printf}).
4710
4711 @item agent
4712 @kindex dprintf-style agent
4713 Have the remote debugging agent (such as @code{gdbserver}) handle
4714 the output itself.  This style is only available for agents that
4715 support running commands on the target.
4716
4717 @item set dprintf-function @var{function}
4718 Set the function to call if the dprintf style is @code{call}.  By
4719 default its value is @code{printf}.  You may set it to any expression.
4720 that @value{GDBN} can evaluate to a function, as per the @code{call}
4721 command.
4722
4723 @item set dprintf-channel @var{channel}
4724 Set a ``channel'' for dprintf.  If set to a non-empty value,
4725 @value{GDBN} will evaluate it as an expression and pass the result as
4726 a first argument to the @code{dprintf-function}, in the manner of
4727 @code{fprintf} and similar functions.  Otherwise, the dprintf format
4728 string will be the first argument, in the manner of @code{printf}.
4729
4730 As an example, if you wanted @code{dprintf} output to go to a logfile
4731 that is a standard I/O stream assigned to the variable @code{mylog},
4732 you could do the following:
4733
4734 @example
4735 (gdb) set dprintf-style call
4736 (gdb) set dprintf-function fprintf
4737 (gdb) set dprintf-channel mylog
4738 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
4739 Dprintf 1 at 0x123456: file main.c, line 25.
4740 (gdb) info break
4741 1       dprintf        keep y   0x00123456 in main at main.c:25
4742         call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4743         continue
4744 (gdb)
4745 @end example
4746
4747 Note that the @code{info break} displays the dynamic printf commands
4748 as normal breakpoint commands; you can thus easily see the effect of
4749 the variable settings.
4750
4751 @item set disconnected-dprintf on
4752 @itemx set disconnected-dprintf off
4753 @kindex set disconnected-dprintf
4754 Choose whether @code{dprintf} commands should continue to run if
4755 @value{GDBN} has disconnected from the target.  This only applies
4756 if the @code{dprintf-style} is @code{agent}.
4757
4758 @item show disconnected-dprintf off
4759 @kindex show disconnected-dprintf
4760 Show the current choice for disconnected @code{dprintf}.
4761
4762 @end table
4763
4764 @value{GDBN} does not check the validity of function and channel,
4765 relying on you to supply values that are meaningful for the contexts
4766 in which they are being used.  For instance, the function and channel
4767 may be the values of local variables, but if that is the case, then
4768 all enabled dynamic prints must be at locations within the scope of
4769 those locals.  If evaluation fails, @value{GDBN} will report an error.
4770
4771 @node Save Breakpoints
4772 @subsection How to save breakpoints to a file
4773
4774 To save breakpoint definitions to a file use the @w{@code{save
4775 breakpoints}} command.
4776
4777 @table @code
4778 @kindex save breakpoints
4779 @cindex save breakpoints to a file for future sessions
4780 @item save breakpoints [@var{filename}]
4781 This command saves all current breakpoint definitions together with
4782 their commands and ignore counts, into a file @file{@var{filename}}
4783 suitable for use in a later debugging session.  This includes all
4784 types of breakpoints (breakpoints, watchpoints, catchpoints,
4785 tracepoints).  To read the saved breakpoint definitions, use the
4786 @code{source} command (@pxref{Command Files}).  Note that watchpoints
4787 with expressions involving local variables may fail to be recreated
4788 because it may not be possible to access the context where the
4789 watchpoint is valid anymore.  Because the saved breakpoint definitions
4790 are simply a sequence of @value{GDBN} commands that recreate the
4791 breakpoints, you can edit the file in your favorite editing program,
4792 and remove the breakpoint definitions you're not interested in, or
4793 that can no longer be recreated.
4794 @end table
4795
4796 @node Static Probe Points
4797 @subsection Static Probe Points
4798
4799 @cindex static probe point, SystemTap
4800 @value{GDBN} supports @dfn{SDT} probes in the code.  @acronym{SDT} stands
4801 for Statically Defined Tracing, and the probes are designed to have a tiny
4802 runtime code and data footprint, and no dynamic relocations.  They are
4803 usable from assembly, C and C@t{++} languages.  See
4804 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
4805 for a good reference on how the @acronym{SDT} probes are implemented.
4806
4807 Currently, @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
4808 @acronym{SDT} probes are supported on ELF-compatible systems.  See
4809 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
4810 for more information on how to add @code{SystemTap} @acronym{SDT} probes
4811 in your applications.
4812
4813 @cindex semaphores on static probe points
4814 Some probes have an associated semaphore variable; for instance, this
4815 happens automatically if you defined your probe using a DTrace-style
4816 @file{.d} file.  If your probe has a semaphore, @value{GDBN} will
4817 automatically enable it when you specify a breakpoint using the
4818 @samp{-probe-stap} notation.  But, if you put a breakpoint at a probe's
4819 location by some other method (e.g., @code{break file:line}), then
4820 @value{GDBN} will not automatically set the semaphore.
4821
4822 You can examine the available static static probes using @code{info
4823 probes}, with optional arguments:
4824
4825 @table @code
4826 @kindex info probes
4827 @item info probes stap @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
4828 If given, @var{provider} is a regular expression used to match against provider
4829 names when selecting which probes to list.  If omitted, probes by all
4830 probes from all providers are listed.
4831
4832 If given, @var{name} is a regular expression to match against probe names
4833 when selecting which probes to list.  If omitted, probe names are not
4834 considered when deciding whether to display them.
4835
4836 If given, @var{objfile} is a regular expression used to select which
4837 object files (executable or shared libraries) to examine.  If not
4838 given, all object files are considered.
4839
4840 @item info probes all
4841 List the available static probes, from all types.
4842 @end table
4843
4844 @vindex $_probe_arg@r{, convenience variable}
4845 A probe may specify up to twelve arguments.  These are available at the
4846 point at which the probe is defined---that is, when the current PC is
4847 at the probe's location.  The arguments are available using the
4848 convenience variables (@pxref{Convenience Vars})
4849 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}.  Each probe argument is
4850 an integer of the appropriate size; types are not preserved.  The
4851 convenience variable @code{$_probe_argc} holds the number of arguments
4852 at the current probe point.
4853
4854 These variables are always available, but attempts to access them at
4855 any location other than a probe point will cause @value{GDBN} to give
4856 an error message.
4857
4858
4859 @c  @ifclear BARETARGET
4860 @node Error in Breakpoints
4861 @subsection ``Cannot insert breakpoints''
4862
4863 If you request too many active hardware-assisted breakpoints and
4864 watchpoints, you will see this error message:
4865
4866 @c FIXME: the precise wording of this message may change; the relevant
4867 @c source change is not committed yet (Sep 3, 1999).
4868 @smallexample
4869 Stopped; cannot insert breakpoints.
4870 You may have requested too many hardware breakpoints and watchpoints.
4871 @end smallexample
4872
4873 @noindent
4874 This message is printed when you attempt to resume the program, since
4875 only then @value{GDBN} knows exactly how many hardware breakpoints and
4876 watchpoints it needs to insert.
4877
4878 When this message is printed, you need to disable or remove some of the
4879 hardware-assisted breakpoints and watchpoints, and then continue.
4880
4881 @node Breakpoint-related Warnings
4882 @subsection ``Breakpoint address adjusted...''
4883 @cindex breakpoint address adjusted
4884
4885 Some processor architectures place constraints on the addresses at
4886 which breakpoints may be placed.  For architectures thus constrained,
4887 @value{GDBN} will attempt to adjust the breakpoint's address to comply
4888 with the constraints dictated by the architecture.
4889
4890 One example of such an architecture is the Fujitsu FR-V.  The FR-V is
4891 a VLIW architecture in which a number of RISC-like instructions may be
4892 bundled together for parallel execution.  The FR-V architecture
4893 constrains the location of a breakpoint instruction within such a
4894 bundle to the instruction with the lowest address.  @value{GDBN}
4895 honors this constraint by adjusting a breakpoint's address to the
4896 first in the bundle.
4897
4898 It is not uncommon for optimized code to have bundles which contain
4899 instructions from different source statements, thus it may happen that
4900 a breakpoint's address will be adjusted from one source statement to
4901 another.  Since this adjustment may significantly alter @value{GDBN}'s
4902 breakpoint related behavior from what the user expects, a warning is
4903 printed when the breakpoint is first set and also when the breakpoint
4904 is hit.
4905
4906 A warning like the one below is printed when setting a breakpoint
4907 that's been subject to address adjustment:
4908
4909 @smallexample
4910 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4911 @end smallexample
4912
4913 Such warnings are printed both for user settable and @value{GDBN}'s
4914 internal breakpoints.  If you see one of these warnings, you should
4915 verify that a breakpoint set at the adjusted address will have the
4916 desired affect.  If not, the breakpoint in question may be removed and
4917 other breakpoints may be set which will have the desired behavior.
4918 E.g., it may be sufficient to place the breakpoint at a later
4919 instruction.  A conditional breakpoint may also be useful in some
4920 cases to prevent the breakpoint from triggering too often.
4921
4922 @value{GDBN} will also issue a warning when stopping at one of these
4923 adjusted breakpoints:
4924
4925 @smallexample
4926 warning: Breakpoint 1 address previously adjusted from 0x00010414
4927 to 0x00010410.
4928 @end smallexample
4929
4930 When this warning is encountered, it may be too late to take remedial
4931 action except in cases where the breakpoint is hit earlier or more
4932 frequently than expected.
4933
4934 @node Continuing and Stepping
4935 @section Continuing and Stepping
4936
4937 @cindex stepping
4938 @cindex continuing
4939 @cindex resuming execution
4940 @dfn{Continuing} means resuming program execution until your program
4941 completes normally.  In contrast, @dfn{stepping} means executing just
4942 one more ``step'' of your program, where ``step'' may mean either one
4943 line of source code, or one machine instruction (depending on what
4944 particular command you use).  Either when continuing or when stepping,
4945 your program may stop even sooner, due to a breakpoint or a signal.  (If
4946 it stops due to a signal, you may want to use @code{handle}, or use
4947 @samp{signal 0} to resume execution.  @xref{Signals, ,Signals}.)
4948
4949 @table @code
4950 @kindex continue
4951 @kindex c @r{(@code{continue})}
4952 @kindex fg @r{(resume foreground execution)}
4953 @item continue @r{[}@var{ignore-count}@r{]}
4954 @itemx c @r{[}@var{ignore-count}@r{]}
4955 @itemx fg @r{[}@var{ignore-count}@r{]}
4956 Resume program execution, at the address where your program last stopped;
4957 any breakpoints set at that address are bypassed.  The optional argument
4958 @var{ignore-count} allows you to specify a further number of times to
4959 ignore a breakpoint at this location; its effect is like that of
4960 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
4961
4962 The argument @var{ignore-count} is meaningful only when your program
4963 stopped due to a breakpoint.  At other times, the argument to
4964 @code{continue} is ignored.
4965
4966 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4967 debugged program is deemed to be the foreground program) are provided
4968 purely for convenience, and have exactly the same behavior as
4969 @code{continue}.
4970 @end table
4971
4972 To resume execution at a different place, you can use @code{return}
4973 (@pxref{Returning, ,Returning from a Function}) to go back to the
4974 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
4975 Different Address}) to go to an arbitrary location in your program.
4976
4977 A typical technique for using stepping is to set a breakpoint
4978 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
4979 beginning of the function or the section of your program where a problem
4980 is believed to lie, run your program until it stops at that breakpoint,
4981 and then step through the suspect area, examining the variables that are
4982 interesting, until you see the problem happen.
4983
4984 @table @code
4985 @kindex step
4986 @kindex s @r{(@code{step})}
4987 @item step
4988 Continue running your program until control reaches a different source
4989 line, then stop it and return control to @value{GDBN}.  This command is
4990 abbreviated @code{s}.
4991
4992 @quotation
4993 @c "without debugging information" is imprecise; actually "without line
4994 @c numbers in the debugging information".  (gcc -g1 has debugging info but
4995 @c not line numbers).  But it seems complex to try to make that
4996 @c distinction here.
4997 @emph{Warning:} If you use the @code{step} command while control is
4998 within a function that was compiled without debugging information,
4999 execution proceeds until control reaches a function that does have
5000 debugging information.  Likewise, it will not step into a function which
5001 is compiled without debugging information.  To step through functions
5002 without debugging information, use the @code{stepi} command, described
5003 below.
5004 @end quotation
5005
5006 The @code{step} command only stops at the first instruction of a source
5007 line.  This prevents the multiple stops that could otherwise occur in
5008 @code{switch} statements, @code{for} loops, etc.  @code{step} continues
5009 to stop if a function that has debugging information is called within
5010 the line.  In other words, @code{step} @emph{steps inside} any functions
5011 called within the line.
5012
5013 Also, the @code{step} command only enters a function if there is line
5014 number information for the function.  Otherwise it acts like the
5015 @code{next} command.  This avoids problems when using @code{cc -gl}
5016 on @acronym{MIPS} machines.  Previously, @code{step} entered subroutines if there
5017 was any debugging information about the routine.
5018
5019 @item step @var{count}
5020 Continue running as in @code{step}, but do so @var{count} times.  If a
5021 breakpoint is reached, or a signal not related to stepping occurs before
5022 @var{count} steps, stepping stops right away.
5023
5024 @kindex next
5025 @kindex n @r{(@code{next})}
5026 @item next @r{[}@var{count}@r{]}
5027 Continue to the next source line in the current (innermost) stack frame.
5028 This is similar to @code{step}, but function calls that appear within
5029 the line of code are executed without stopping.  Execution stops when
5030 control reaches a different line of code at the original stack level
5031 that was executing when you gave the @code{next} command.  This command
5032 is abbreviated @code{n}.
5033
5034 An argument @var{count} is a repeat count, as for @code{step}.
5035
5036
5037 @c  FIX ME!!  Do we delete this, or is there a way it fits in with
5038 @c  the following paragraph?   ---  Vctoria
5039 @c
5040 @c  @code{next} within a function that lacks debugging information acts like
5041 @c  @code{step}, but any function calls appearing within the code of the
5042 @c  function are executed without stopping.
5043
5044 The @code{next} command only stops at the first instruction of a
5045 source line.  This prevents multiple stops that could otherwise occur in
5046 @code{switch} statements, @code{for} loops, etc.
5047
5048 @kindex set step-mode
5049 @item set step-mode
5050 @cindex functions without line info, and stepping
5051 @cindex stepping into functions with no line info
5052 @itemx set step-mode on
5053 The @code{set step-mode on} command causes the @code{step} command to
5054 stop at the first instruction of a function which contains no debug line
5055 information rather than stepping over it.
5056
5057 This is useful in cases where you may be interested in inspecting the
5058 machine instructions of a function which has no symbolic info and do not
5059 want @value{GDBN} to automatically skip over this function.
5060
5061 @item set step-mode off
5062 Causes the @code{step} command to step over any functions which contains no
5063 debug information.  This is the default.
5064
5065 @item show step-mode
5066 Show whether @value{GDBN} will stop in or step over functions without
5067 source line debug information.
5068
5069 @kindex finish
5070 @kindex fin @r{(@code{finish})}
5071 @item finish
5072 Continue running until just after function in the selected stack frame
5073 returns.  Print the returned value (if any).  This command can be
5074 abbreviated as @code{fin}.
5075
5076 Contrast this with the @code{return} command (@pxref{Returning,
5077 ,Returning from a Function}).
5078
5079 @kindex until
5080 @kindex u @r{(@code{until})}
5081 @cindex run until specified location
5082 @item until
5083 @itemx u
5084 Continue running until a source line past the current line, in the
5085 current stack frame, is reached.  This command is used to avoid single
5086 stepping through a loop more than once.  It is like the @code{next}
5087 command, except that when @code{until} encounters a jump, it
5088 automatically continues execution until the program counter is greater
5089 than the address of the jump.
5090
5091 This means that when you reach the end of a loop after single stepping
5092 though it, @code{until} makes your program continue execution until it
5093 exits the loop.  In contrast, a @code{next} command at the end of a loop
5094 simply steps back to the beginning of the loop, which forces you to step
5095 through the next iteration.
5096
5097 @code{until} always stops your program if it attempts to exit the current
5098 stack frame.
5099
5100 @code{until} may produce somewhat counterintuitive results if the order
5101 of machine code does not match the order of the source lines.  For
5102 example, in the following excerpt from a debugging session, the @code{f}
5103 (@code{frame}) command shows that execution is stopped at line
5104 @code{206}; yet when we use @code{until}, we get to line @code{195}:
5105
5106 @smallexample
5107 (@value{GDBP}) f
5108 #0  main (argc=4, argv=0xf7fffae8) at m4.c:206
5109 206                 expand_input();
5110 (@value{GDBP}) until
5111 195             for ( ; argc > 0; NEXTARG) @{
5112 @end smallexample
5113
5114 This happened because, for execution efficiency, the compiler had
5115 generated code for the loop closure test at the end, rather than the
5116 start, of the loop---even though the test in a C @code{for}-loop is
5117 written before the body of the loop.  The @code{until} command appeared
5118 to step back to the beginning of the loop when it advanced to this
5119 expression; however, it has not really gone to an earlier
5120 statement---not in terms of the actual machine code.
5121
5122 @code{until} with no argument works by means of single
5123 instruction stepping, and hence is slower than @code{until} with an
5124 argument.
5125
5126 @item until @var{location}
5127 @itemx u @var{location}
5128 Continue running your program until either the specified location is
5129 reached, or the current stack frame returns.  @var{location} is any of
5130 the forms described in @ref{Specify Location}.
5131 This form of the command uses temporary breakpoints, and
5132 hence is quicker than @code{until} without an argument.  The specified
5133 location is actually reached only if it is in the current frame.  This
5134 implies that @code{until} can be used to skip over recursive function
5135 invocations.  For instance in the code below, if the current location is
5136 line @code{96}, issuing @code{until 99} will execute the program up to
5137 line @code{99} in the same invocation of factorial, i.e., after the inner
5138 invocations have returned.
5139
5140 @smallexample
5141 94      int factorial (int value)
5142 95      @{
5143 96          if (value > 1) @{
5144 97            value *= factorial (value - 1);
5145 98          @}
5146 99          return (value);
5147 100     @}
5148 @end smallexample
5149
5150
5151 @kindex advance @var{location}
5152 @item advance @var{location}
5153 Continue running the program up to the given @var{location}.  An argument is
5154 required, which should be of one of the forms described in
5155 @ref{Specify Location}.
5156 Execution will also stop upon exit from the current stack
5157 frame.  This command is similar to @code{until}, but @code{advance} will
5158 not skip over recursive function calls, and the target location doesn't
5159 have to be in the same frame as the current one.
5160
5161
5162 @kindex stepi
5163 @kindex si @r{(@code{stepi})}
5164 @item stepi
5165 @itemx stepi @var{arg}
5166 @itemx si
5167 Execute one machine instruction, then stop and return to the debugger.
5168
5169 It is often useful to do @samp{display/i $pc} when stepping by machine
5170 instructions.  This makes @value{GDBN} automatically display the next
5171 instruction to be executed, each time your program stops.  @xref{Auto
5172 Display,, Automatic Display}.
5173
5174 An argument is a repeat count, as in @code{step}.
5175
5176 @need 750
5177 @kindex nexti
5178 @kindex ni @r{(@code{nexti})}
5179 @item nexti
5180 @itemx nexti @var{arg}
5181 @itemx ni
5182 Execute one machine instruction, but if it is a function call,
5183 proceed until the function returns.
5184
5185 An argument is a repeat count, as in @code{next}.
5186 @end table
5187
5188 @node Skipping Over Functions and Files
5189 @section Skipping Over Functions and Files
5190 @cindex skipping over functions and files
5191
5192 The program you are debugging may contain some functions which are
5193 uninteresting to debug.  The @code{skip} comand lets you tell @value{GDBN} to
5194 skip a function or all functions in a file when stepping.
5195
5196 For example, consider the following C function:
5197
5198 @smallexample
5199 101     int func()
5200 102     @{
5201 103         foo(boring());
5202 104         bar(boring());
5203 105     @}
5204 @end smallexample
5205
5206 @noindent
5207 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5208 are not interested in stepping through @code{boring}.  If you run @code{step}
5209 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5210 step over both @code{foo} and @code{boring}!
5211
5212 One solution is to @code{step} into @code{boring} and use the @code{finish}
5213 command to immediately exit it.  But this can become tedious if @code{boring}
5214 is called from many places.
5215
5216 A more flexible solution is to execute @kbd{skip boring}.  This instructs
5217 @value{GDBN} never to step into @code{boring}.  Now when you execute
5218 @code{step} at line 103, you'll step over @code{boring} and directly into
5219 @code{foo}.
5220
5221 You can also instruct @value{GDBN} to skip all functions in a file, with, for
5222 example, @code{skip file boring.c}.
5223
5224 @table @code
5225 @kindex skip function
5226 @item skip @r{[}@var{linespec}@r{]}
5227 @itemx skip function @r{[}@var{linespec}@r{]}
5228 After running this command, the function named by @var{linespec} or the
5229 function containing the line named by @var{linespec} will be skipped over when
5230 stepping.  @xref{Specify Location}.
5231
5232 If you do not specify @var{linespec}, the function you're currently debugging
5233 will be skipped.
5234
5235 (If you have a function called @code{file} that you want to skip, use
5236 @kbd{skip function file}.)
5237
5238 @kindex skip file
5239 @item skip file @r{[}@var{filename}@r{]}
5240 After running this command, any function whose source lives in @var{filename}
5241 will be skipped over when stepping.
5242
5243 If you do not specify @var{filename}, functions whose source lives in the file
5244 you're currently debugging will be skipped.
5245 @end table
5246
5247 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5248 These are the commands for managing your list of skips:
5249
5250 @table @code
5251 @kindex info skip
5252 @item info skip @r{[}@var{range}@r{]}
5253 Print details about the specified skip(s).  If @var{range} is not specified,
5254 print a table with details about all functions and files marked for skipping.
5255 @code{info skip} prints the following information about each skip:
5256
5257 @table @emph
5258 @item Identifier
5259 A number identifying this skip.
5260 @item Type
5261 The type of this skip, either @samp{function} or @samp{file}.
5262 @item Enabled or Disabled
5263 Enabled skips are marked with @samp{y}.  Disabled skips are marked with @samp{n}.
5264 @item Address
5265 For function skips, this column indicates the address in memory of the function
5266 being skipped.  If you've set a function skip on a function which has not yet
5267 been loaded, this field will contain @samp{<PENDING>}.  Once a shared library
5268 which has the function is loaded, @code{info skip} will show the function's
5269 address here.
5270 @item What
5271 For file skips, this field contains the filename being skipped.  For functions
5272 skips, this field contains the function name and its line number in the file
5273 where it is defined.
5274 @end table
5275
5276 @kindex skip delete
5277 @item skip delete @r{[}@var{range}@r{]}
5278 Delete the specified skip(s).  If @var{range} is not specified, delete all
5279 skips.
5280
5281 @kindex skip enable
5282 @item skip enable @r{[}@var{range}@r{]}
5283 Enable the specified skip(s).  If @var{range} is not specified, enable all
5284 skips.
5285
5286 @kindex skip disable
5287 @item skip disable @r{[}@var{range}@r{]}
5288 Disable the specified skip(s).  If @var{range} is not specified, disable all
5289 skips.
5290
5291 @end table
5292
5293 @node Signals
5294 @section Signals
5295 @cindex signals
5296
5297 A signal is an asynchronous event that can happen in a program.  The
5298 operating system defines the possible kinds of signals, and gives each
5299 kind a name and a number.  For example, in Unix @code{SIGINT} is the
5300 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
5301 @code{SIGSEGV} is the signal a program gets from referencing a place in
5302 memory far away from all the areas in use; @code{SIGALRM} occurs when
5303 the alarm clock timer goes off (which happens only if your program has
5304 requested an alarm).
5305
5306 @cindex fatal signals
5307 Some signals, including @code{SIGALRM}, are a normal part of the
5308 functioning of your program.  Others, such as @code{SIGSEGV}, indicate
5309 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
5310 program has not specified in advance some other way to handle the signal.
5311 @code{SIGINT} does not indicate an error in your program, but it is normally
5312 fatal so it can carry out the purpose of the interrupt: to kill the program.
5313
5314 @value{GDBN} has the ability to detect any occurrence of a signal in your
5315 program.  You can tell @value{GDBN} in advance what to do for each kind of
5316 signal.
5317
5318 @cindex handling signals
5319 Normally, @value{GDBN} is set up to let the non-erroneous signals like
5320 @code{SIGALRM} be silently passed to your program
5321 (so as not to interfere with their role in the program's functioning)
5322 but to stop your program immediately whenever an error signal happens.
5323 You can change these settings with the @code{handle} command.
5324
5325 @table @code
5326 @kindex info signals
5327 @kindex info handle
5328 @item info signals
5329 @itemx info handle
5330 Print a table of all the kinds of signals and how @value{GDBN} has been told to
5331 handle each one.  You can use this to see the signal numbers of all
5332 the defined types of signals.
5333
5334 @item info signals @var{sig}
5335 Similar, but print information only about the specified signal number.
5336
5337 @code{info handle} is an alias for @code{info signals}.
5338
5339 @kindex handle
5340 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5341 Change the way @value{GDBN} handles signal @var{signal}.  @var{signal}
5342 can be the number of a signal or its name (with or without the
5343 @samp{SIG} at the beginning); a list of signal numbers of the form
5344 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
5345 known signals.  Optional arguments @var{keywords}, described below,
5346 say what change to make.
5347 @end table
5348
5349 @c @group
5350 The keywords allowed by the @code{handle} command can be abbreviated.
5351 Their full names are:
5352
5353 @table @code
5354 @item nostop
5355 @value{GDBN} should not stop your program when this signal happens.  It may
5356 still print a message telling you that the signal has come in.
5357
5358 @item stop
5359 @value{GDBN} should stop your program when this signal happens.  This implies
5360 the @code{print} keyword as well.
5361
5362 @item print
5363 @value{GDBN} should print a message when this signal happens.
5364
5365 @item noprint
5366 @value{GDBN} should not mention the occurrence of the signal at all.  This
5367 implies the @code{nostop} keyword as well.
5368
5369 @item pass
5370 @itemx noignore
5371 @value{GDBN} should allow your program to see this signal; your program
5372 can handle the signal, or else it may terminate if the signal is fatal
5373 and not handled.  @code{pass} and @code{noignore} are synonyms.
5374
5375 @item nopass
5376 @itemx ignore
5377 @value{GDBN} should not allow your program to see this signal.
5378 @code{nopass} and @code{ignore} are synonyms.
5379 @end table
5380 @c @end group
5381
5382 When a signal stops your program, the signal is not visible to the
5383 program until you
5384 continue.  Your program sees the signal then, if @code{pass} is in
5385 effect for the signal in question @emph{at that time}.  In other words,
5386 after @value{GDBN} reports a signal, you can use the @code{handle}
5387 command with @code{pass} or @code{nopass} to control whether your
5388 program sees that signal when you continue.
5389
5390 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5391 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5392 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5393 erroneous signals.
5394
5395 You can also use the @code{signal} command to prevent your program from
5396 seeing a signal, or cause it to see a signal it normally would not see,
5397 or to give it any signal at any time.  For example, if your program stopped
5398 due to some sort of memory reference error, you might store correct
5399 values into the erroneous variables and continue, hoping to see more
5400 execution; but your program would probably terminate immediately as
5401 a result of the fatal signal once it saw the signal.  To prevent this,
5402 you can continue with @samp{signal 0}.  @xref{Signaling, ,Giving your
5403 Program a Signal}.
5404
5405 @cindex extra signal information
5406 @anchor{extra signal information}
5407
5408 On some targets, @value{GDBN} can inspect extra signal information
5409 associated with the intercepted signal, before it is actually
5410 delivered to the program being debugged.  This information is exported
5411 by the convenience variable @code{$_siginfo}, and consists of data
5412 that is passed by the kernel to the signal handler at the time of the
5413 receipt of a signal.  The data type of the information itself is
5414 target dependent.  You can see the data type using the @code{ptype
5415 $_siginfo} command.  On Unix systems, it typically corresponds to the
5416 standard @code{siginfo_t} type, as defined in the @file{signal.h}
5417 system header.
5418
5419 Here's an example, on a @sc{gnu}/Linux system, printing the stray
5420 referenced address that raised a segmentation fault.
5421
5422 @smallexample
5423 @group
5424 (@value{GDBP}) continue
5425 Program received signal SIGSEGV, Segmentation fault.
5426 0x0000000000400766 in main ()
5427 69        *(int *)p = 0;
5428 (@value{GDBP}) ptype $_siginfo
5429 type = struct @{
5430     int si_signo;
5431     int si_errno;
5432     int si_code;
5433     union @{
5434         int _pad[28];
5435         struct @{...@} _kill;
5436         struct @{...@} _timer;
5437         struct @{...@} _rt;
5438         struct @{...@} _sigchld;
5439         struct @{...@} _sigfault;
5440         struct @{...@} _sigpoll;
5441     @} _sifields;
5442 @}
5443 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
5444 type = struct @{
5445     void *si_addr;
5446 @}
5447 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5448 $1 = (void *) 0x7ffff7ff7000
5449 @end group
5450 @end smallexample
5451
5452 Depending on target support, @code{$_siginfo} may also be writable.
5453
5454 @node Thread Stops
5455 @section Stopping and Starting Multi-thread Programs
5456
5457 @cindex stopped threads
5458 @cindex threads, stopped
5459
5460 @cindex continuing threads
5461 @cindex threads, continuing
5462
5463 @value{GDBN} supports debugging programs with multiple threads
5464 (@pxref{Threads,, Debugging Programs with Multiple Threads}).  There
5465 are two modes of controlling execution of your program within the
5466 debugger.  In the default mode, referred to as @dfn{all-stop mode},
5467 when any thread in your program stops (for example, at a breakpoint 
5468 or while being stepped), all other threads in the program are also stopped by 
5469 @value{GDBN}.  On some targets, @value{GDBN} also supports 
5470 @dfn{non-stop mode}, in which other threads can continue to run freely while
5471 you examine the stopped thread in the debugger.
5472
5473 @menu
5474 * All-Stop Mode::               All threads stop when GDB takes control
5475 * Non-Stop Mode::               Other threads continue to execute
5476 * Background Execution::        Running your program asynchronously
5477 * Thread-Specific Breakpoints:: Controlling breakpoints
5478 * Interrupted System Calls::    GDB may interfere with system calls
5479 * Observer Mode::               GDB does not alter program behavior
5480 @end menu
5481
5482 @node All-Stop Mode
5483 @subsection All-Stop Mode
5484
5485 @cindex all-stop mode
5486
5487 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5488 @emph{all} threads of execution stop, not just the current thread.  This
5489 allows you to examine the overall state of the program, including
5490 switching between threads, without worrying that things may change
5491 underfoot.
5492
5493 Conversely, whenever you restart the program, @emph{all} threads start
5494 executing.  @emph{This is true even when single-stepping} with commands
5495 like @code{step} or @code{next}.
5496
5497 In particular, @value{GDBN} cannot single-step all threads in lockstep.
5498 Since thread scheduling is up to your debugging target's operating
5499 system (not controlled by @value{GDBN}), other threads may
5500 execute more than one statement while the current thread completes a
5501 single step.  Moreover, in general other threads stop in the middle of a
5502 statement, rather than at a clean statement boundary, when the program
5503 stops.
5504
5505 You might even find your program stopped in another thread after
5506 continuing or even single-stepping.  This happens whenever some other
5507 thread runs into a breakpoint, a signal, or an exception before the
5508 first thread completes whatever you requested.
5509
5510 @cindex automatic thread selection
5511 @cindex switching threads automatically
5512 @cindex threads, automatic switching
5513 Whenever @value{GDBN} stops your program, due to a breakpoint or a
5514 signal, it automatically selects the thread where that breakpoint or
5515 signal happened.  @value{GDBN} alerts you to the context switch with a
5516 message such as @samp{[Switching to Thread @var{n}]} to identify the
5517 thread.  
5518
5519 On some OSes, you can modify @value{GDBN}'s default behavior by
5520 locking the OS scheduler to allow only a single thread to run.
5521
5522 @table @code
5523 @item set scheduler-locking @var{mode}
5524 @cindex scheduler locking mode
5525 @cindex lock scheduler
5526 Set the scheduler locking mode.  If it is @code{off}, then there is no
5527 locking and any thread may run at any time.  If @code{on}, then only the
5528 current thread may run when the inferior is resumed.  The @code{step}
5529 mode optimizes for single-stepping; it prevents other threads 
5530 from preempting the current thread while you are stepping, so that 
5531 the focus of debugging does not change unexpectedly.
5532 Other threads only rarely (or never) get a chance to run
5533 when you step.  They are more likely to run when you @samp{next} over a
5534 function call, and they are completely free to run when you use commands
5535 like @samp{continue}, @samp{until}, or @samp{finish}.  However, unless another
5536 thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5537 the current thread away from the thread that you are debugging.
5538
5539 @item show scheduler-locking
5540 Display the current scheduler locking mode.
5541 @end table
5542
5543 @cindex resume threads of multiple processes simultaneously
5544 By default, when you issue one of the execution commands such as
5545 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5546 threads of the current inferior to run.  For example, if @value{GDBN}
5547 is attached to two inferiors, each with two threads, the
5548 @code{continue} command resumes only the two threads of the current
5549 inferior.  This is useful, for example, when you debug a program that
5550 forks and you want to hold the parent stopped (so that, for instance,
5551 it doesn't run to exit), while you debug the child.  In other
5552 situations, you may not be interested in inspecting the current state
5553 of any of the processes @value{GDBN} is attached to, and you may want
5554 to resume them all until some breakpoint is hit.  In the latter case,
5555 you can instruct @value{GDBN} to allow all threads of all the
5556 inferiors to run with the @w{@code{set schedule-multiple}} command.
5557
5558 @table @code
5559 @kindex set schedule-multiple
5560 @item set schedule-multiple
5561 Set the mode for allowing threads of multiple processes to be resumed
5562 when an execution command is issued.  When @code{on}, all threads of
5563 all processes are allowed to run.  When @code{off}, only the threads
5564 of the current process are resumed.  The default is @code{off}.  The
5565 @code{scheduler-locking} mode takes precedence when set to @code{on},
5566 or while you are stepping and set to @code{step}.
5567
5568 @item show schedule-multiple
5569 Display the current mode for resuming the execution of threads of
5570 multiple processes.
5571 @end table
5572
5573 @node Non-Stop Mode
5574 @subsection Non-Stop Mode
5575
5576 @cindex non-stop mode
5577
5578 @c This section is really only a place-holder, and needs to be expanded
5579 @c with more details.  
5580
5581 For some multi-threaded targets, @value{GDBN} supports an optional
5582 mode of operation in which you can examine stopped program threads in
5583 the debugger while other threads continue to execute freely.  This
5584 minimizes intrusion when debugging live systems, such as programs 
5585 where some threads have real-time constraints or must continue to 
5586 respond to external events.  This is referred to as @dfn{non-stop} mode.
5587
5588 In non-stop mode, when a thread stops to report a debugging event,
5589 @emph{only} that thread is stopped; @value{GDBN} does not stop other
5590 threads as well, in contrast to the all-stop mode behavior.  Additionally,
5591 execution commands such as @code{continue} and @code{step} apply by default
5592 only to the current thread in non-stop mode, rather than all threads as
5593 in all-stop mode.  This allows you to control threads explicitly in
5594 ways that are not possible in all-stop mode --- for example, stepping 
5595 one thread while allowing others to run freely, stepping
5596 one thread while holding all others stopped, or stepping several threads 
5597 independently and simultaneously.
5598
5599 To enter non-stop mode, use this sequence of commands before you run
5600 or attach to your program:
5601
5602 @smallexample
5603 # Enable the async interface.  
5604 set target-async 1
5605
5606 # If using the CLI, pagination breaks non-stop.
5607 set pagination off
5608
5609 # Finally, turn it on!
5610 set non-stop on
5611 @end smallexample
5612
5613 You can use these commands to manipulate the non-stop mode setting:
5614
5615 @table @code
5616 @kindex set non-stop
5617 @item set non-stop on
5618 Enable selection of non-stop mode.
5619 @item set non-stop off
5620 Disable selection of non-stop mode.
5621 @kindex show non-stop
5622 @item show non-stop
5623 Show the current non-stop enablement setting.
5624 @end table
5625
5626 Note these commands only reflect whether non-stop mode is enabled,
5627 not whether the currently-executing program is being run in non-stop mode.  
5628 In particular, the @code{set non-stop} preference is only consulted when
5629 @value{GDBN} starts or connects to the target program, and it is generally 
5630 not possible to switch modes once debugging has started.  Furthermore,
5631 since not all targets support non-stop mode, even when you have enabled
5632 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5633 default.
5634
5635 In non-stop mode, all execution commands apply only to the current thread
5636 by default.  That is, @code{continue} only continues one thread.  
5637 To continue all threads, issue @code{continue -a} or @code{c -a}.
5638
5639 You can use @value{GDBN}'s background execution commands 
5640 (@pxref{Background Execution}) to run some threads in the background
5641 while you continue to examine or step others from @value{GDBN}.  
5642 The MI execution commands (@pxref{GDB/MI Program Execution}) are
5643 always executed asynchronously in non-stop mode.
5644
5645 Suspending execution is done with the @code{interrupt} command when
5646 running in the background, or @kbd{Ctrl-c} during foreground execution.  
5647 In all-stop mode, this stops the whole process; 
5648 but in non-stop mode the interrupt applies only to the current thread.  
5649 To stop the whole program, use @code{interrupt -a}.
5650
5651 Other execution commands do not currently support the @code{-a} option.
5652
5653 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5654 that thread current, as it does in all-stop mode.  This is because the
5655 thread stop notifications are asynchronous with respect to @value{GDBN}'s 
5656 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5657 changed to a different thread just as you entered a command to operate on the
5658 previously current thread.
5659
5660 @node Background Execution
5661 @subsection Background Execution
5662
5663 @cindex foreground execution
5664 @cindex background execution
5665 @cindex asynchronous execution
5666 @cindex execution, foreground, background and asynchronous
5667
5668 @value{GDBN}'s execution commands have two variants:  the normal
5669 foreground (synchronous) behavior, and a background
5670 (asynchronous) behavior.  In foreground execution, @value{GDBN} waits for 
5671 the program to report that some thread has stopped before prompting for
5672 another command.  In background execution, @value{GDBN} immediately gives
5673 a command prompt so that you can issue other commands while your program runs.
5674
5675 You need to explicitly enable asynchronous mode before you can use
5676 background execution commands.  You can use these commands to
5677 manipulate the asynchronous mode setting:
5678
5679 @table @code
5680 @kindex set target-async
5681 @item set target-async on
5682 Enable asynchronous mode.
5683 @item set target-async off
5684 Disable asynchronous mode.
5685 @kindex show target-async
5686 @item show target-async
5687 Show the current target-async setting.
5688 @end table
5689
5690 If the target doesn't support async mode, @value{GDBN} issues an error
5691 message if you attempt to use the background execution commands.
5692
5693 To specify background execution, add a @code{&} to the command.  For example,
5694 the background form of the @code{continue} command is @code{continue&}, or
5695 just @code{c&}.  The execution commands that accept background execution
5696 are:
5697
5698 @table @code
5699 @kindex run&
5700 @item run
5701 @xref{Starting, , Starting your Program}.
5702
5703 @item attach
5704 @kindex attach&
5705 @xref{Attach, , Debugging an Already-running Process}.
5706
5707 @item step
5708 @kindex step&
5709 @xref{Continuing and Stepping, step}.
5710
5711 @item stepi
5712 @kindex stepi&
5713 @xref{Continuing and Stepping, stepi}.
5714
5715 @item next
5716 @kindex next&
5717 @xref{Continuing and Stepping, next}.
5718
5719 @item nexti
5720 @kindex nexti&
5721 @xref{Continuing and Stepping, nexti}.
5722
5723 @item continue
5724 @kindex continue&
5725 @xref{Continuing and Stepping, continue}.
5726
5727 @item finish
5728 @kindex finish&
5729 @xref{Continuing and Stepping, finish}.
5730
5731 @item until
5732 @kindex until&
5733 @xref{Continuing and Stepping, until}.
5734
5735 @end table
5736
5737 Background execution is especially useful in conjunction with non-stop
5738 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5739 However, you can also use these commands in the normal all-stop mode with
5740 the restriction that you cannot issue another execution command until the
5741 previous one finishes.  Examples of commands that are valid in all-stop
5742 mode while the program is running include @code{help} and @code{info break}.
5743
5744 You can interrupt your program while it is running in the background by
5745 using the @code{interrupt} command.
5746
5747 @table @code
5748 @kindex interrupt
5749 @item interrupt
5750 @itemx interrupt -a
5751
5752 Suspend execution of the running program.  In all-stop mode, 
5753 @code{interrupt} stops the whole process, but in non-stop mode, it stops
5754 only the current thread.  To stop the whole program in non-stop mode, 
5755 use @code{interrupt -a}.
5756 @end table
5757
5758 @node Thread-Specific Breakpoints
5759 @subsection Thread-Specific Breakpoints
5760
5761 When your program has multiple threads (@pxref{Threads,, Debugging
5762 Programs with Multiple Threads}), you can choose whether to set
5763 breakpoints on all threads, or on a particular thread.
5764
5765 @table @code
5766 @cindex breakpoints and threads
5767 @cindex thread breakpoints
5768 @kindex break @dots{} thread @var{threadno}
5769 @item break @var{linespec} thread @var{threadno}
5770 @itemx break @var{linespec} thread @var{threadno} if @dots{}
5771 @var{linespec} specifies source lines; there are several ways of
5772 writing them (@pxref{Specify Location}), but the effect is always to
5773 specify some source line.
5774
5775 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5776 to specify that you only want @value{GDBN} to stop the program when a
5777 particular thread reaches this breakpoint.  @var{threadno} is one of the
5778 numeric thread identifiers assigned by @value{GDBN}, shown in the first
5779 column of the @samp{info threads} display.
5780
5781 If you do not specify @samp{thread @var{threadno}} when you set a
5782 breakpoint, the breakpoint applies to @emph{all} threads of your
5783 program.
5784
5785 You can use the @code{thread} qualifier on conditional breakpoints as
5786 well; in this case, place @samp{thread @var{threadno}} before or
5787 after the breakpoint condition, like this:
5788
5789 @smallexample
5790 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
5791 @end smallexample
5792
5793 @end table
5794
5795 @node Interrupted System Calls
5796 @subsection Interrupted System Calls 
5797
5798 @cindex thread breakpoints and system calls
5799 @cindex system calls and thread breakpoints
5800 @cindex premature return from system calls
5801 There is an unfortunate side effect when using @value{GDBN} to debug
5802 multi-threaded programs.  If one thread stops for a
5803 breakpoint, or for some other reason, and another thread is blocked in a
5804 system call, then the system call may return prematurely.  This is a
5805 consequence of the interaction between multiple threads and the signals
5806 that @value{GDBN} uses to implement breakpoints and other events that
5807 stop execution.
5808
5809 To handle this problem, your program should check the return value of
5810 each system call and react appropriately.  This is good programming
5811 style anyways.
5812
5813 For example, do not write code like this:
5814
5815 @smallexample
5816   sleep (10);
5817 @end smallexample
5818
5819 The call to @code{sleep} will return early if a different thread stops
5820 at a breakpoint or for some other reason.
5821
5822 Instead, write this:
5823
5824 @smallexample
5825   int unslept = 10;
5826   while (unslept > 0)
5827     unslept = sleep (unslept);
5828 @end smallexample
5829
5830 A system call is allowed to return early, so the system is still
5831 conforming to its specification.  But @value{GDBN} does cause your
5832 multi-threaded program to behave differently than it would without
5833 @value{GDBN}.
5834
5835 Also, @value{GDBN} uses internal breakpoints in the thread library to
5836 monitor certain events such as thread creation and thread destruction.
5837 When such an event happens, a system call in another thread may return
5838 prematurely, even though your program does not appear to stop.
5839
5840 @node Observer Mode
5841 @subsection Observer Mode
5842
5843 If you want to build on non-stop mode and observe program behavior
5844 without any chance of disruption by @value{GDBN}, you can set
5845 variables to disable all of the debugger's attempts to modify state,
5846 whether by writing memory, inserting breakpoints, etc.  These operate
5847 at a low level, intercepting operations from all commands.
5848
5849 When all of these are set to @code{off}, then @value{GDBN} is said to
5850 be @dfn{observer mode}.  As a convenience, the variable
5851 @code{observer} can be set to disable these, plus enable non-stop
5852 mode.
5853
5854 Note that @value{GDBN} will not prevent you from making nonsensical
5855 combinations of these settings. For instance, if you have enabled
5856 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
5857 then breakpoints that work by writing trap instructions into the code
5858 stream will still not be able to be placed.
5859
5860 @table @code
5861
5862 @kindex observer
5863 @item set observer on
5864 @itemx set observer off
5865 When set to @code{on}, this disables all the permission variables
5866 below (except for @code{insert-fast-tracepoints}), plus enables
5867 non-stop debugging.  Setting this to @code{off} switches back to
5868 normal debugging, though remaining in non-stop mode.
5869
5870 @item show observer
5871 Show whether observer mode is on or off.
5872
5873 @kindex may-write-registers
5874 @item set may-write-registers on
5875 @itemx set may-write-registers off
5876 This controls whether @value{GDBN} will attempt to alter the values of
5877 registers, such as with assignment expressions in @code{print}, or the
5878 @code{jump} command.  It defaults to @code{on}.
5879
5880 @item show may-write-registers
5881 Show the current permission to write registers.
5882
5883 @kindex may-write-memory
5884 @item set may-write-memory on
5885 @itemx set may-write-memory off
5886 This controls whether @value{GDBN} will attempt to alter the contents
5887 of memory, such as with assignment expressions in @code{print}.  It
5888 defaults to @code{on}.
5889
5890 @item show may-write-memory
5891 Show the current permission to write memory.
5892
5893 @kindex may-insert-breakpoints
5894 @item set may-insert-breakpoints on
5895 @itemx set may-insert-breakpoints off
5896 This controls whether @value{GDBN} will attempt to insert breakpoints.
5897 This affects all breakpoints, including internal breakpoints defined
5898 by @value{GDBN}.  It defaults to @code{on}.
5899
5900 @item show may-insert-breakpoints
5901 Show the current permission to insert breakpoints.
5902
5903 @kindex may-insert-tracepoints
5904 @item set may-insert-tracepoints on
5905 @itemx set may-insert-tracepoints off
5906 This controls whether @value{GDBN} will attempt to insert (regular)
5907 tracepoints at the beginning of a tracing experiment.  It affects only
5908 non-fast tracepoints, fast tracepoints being under the control of
5909 @code{may-insert-fast-tracepoints}.  It defaults to @code{on}.
5910
5911 @item show may-insert-tracepoints
5912 Show the current permission to insert tracepoints.
5913
5914 @kindex may-insert-fast-tracepoints
5915 @item set may-insert-fast-tracepoints on
5916 @itemx set may-insert-fast-tracepoints off
5917 This controls whether @value{GDBN} will attempt to insert fast
5918 tracepoints at the beginning of a tracing experiment.  It affects only
5919 fast tracepoints, regular (non-fast) tracepoints being under the
5920 control of @code{may-insert-tracepoints}.  It defaults to @code{on}.
5921
5922 @item show may-insert-fast-tracepoints
5923 Show the current permission to insert fast tracepoints.
5924
5925 @kindex may-interrupt
5926 @item set may-interrupt on
5927 @itemx set may-interrupt off
5928 This controls whether @value{GDBN} will attempt to interrupt or stop
5929 program execution.  When this variable is @code{off}, the
5930 @code{interrupt} command will have no effect, nor will
5931 @kbd{Ctrl-c}. It defaults to @code{on}.
5932
5933 @item show may-interrupt
5934 Show the current permission to interrupt or stop the program.
5935
5936 @end table
5937
5938 @node Reverse Execution
5939 @chapter Running programs backward
5940 @cindex reverse execution
5941 @cindex running programs backward
5942
5943 When you are debugging a program, it is not unusual to realize that
5944 you have gone too far, and some event of interest has already happened.
5945 If the target environment supports it, @value{GDBN} can allow you to
5946 ``rewind'' the program by running it backward.
5947
5948 A target environment that supports reverse execution should be able
5949 to ``undo'' the changes in machine state that have taken place as the
5950 program was executing normally.  Variables, registers etc.@: should
5951 revert to their previous values.  Obviously this requires a great
5952 deal of sophistication on the part of the target environment; not
5953 all target environments can support reverse execution.
5954
5955 When a program is executed in reverse, the instructions that
5956 have most recently been executed are ``un-executed'', in reverse
5957 order.  The program counter runs backward, following the previous
5958 thread of execution in reverse.  As each instruction is ``un-executed'',
5959 the values of memory and/or registers that were changed by that
5960 instruction are reverted to their previous states.  After executing
5961 a piece of source code in reverse, all side effects of that code
5962 should be ``undone'', and all variables should be returned to their
5963 prior values@footnote{
5964 Note that some side effects are easier to undo than others.  For instance,
5965 memory and registers are relatively easy, but device I/O is hard.  Some
5966 targets may be able undo things like device I/O, and some may not.
5967
5968 The contract between @value{GDBN} and the reverse executing target
5969 requires only that the target do something reasonable when
5970 @value{GDBN} tells it to execute backwards, and then report the 
5971 results back to @value{GDBN}.  Whatever the target reports back to
5972 @value{GDBN}, @value{GDBN} will report back to the user.  @value{GDBN}
5973 assumes that the memory and registers that the target reports are in a
5974 consistant state, but @value{GDBN} accepts whatever it is given.
5975 }.
5976
5977 If you are debugging in a target environment that supports
5978 reverse execution, @value{GDBN} provides the following commands.
5979
5980 @table @code
5981 @kindex reverse-continue
5982 @kindex rc @r{(@code{reverse-continue})}
5983 @item reverse-continue @r{[}@var{ignore-count}@r{]}
5984 @itemx rc @r{[}@var{ignore-count}@r{]}
5985 Beginning at the point where your program last stopped, start executing
5986 in reverse.  Reverse execution will stop for breakpoints and synchronous
5987 exceptions (signals), just like normal execution.  Behavior of
5988 asynchronous signals depends on the target environment.
5989
5990 @kindex reverse-step
5991 @kindex rs @r{(@code{step})}
5992 @item reverse-step @r{[}@var{count}@r{]}
5993 Run the program backward until control reaches the start of a
5994 different source line; then stop it, and return control to @value{GDBN}.
5995
5996 Like the @code{step} command, @code{reverse-step} will only stop
5997 at the beginning of a source line.  It ``un-executes'' the previously
5998 executed source line.  If the previous source line included calls to
5999 debuggable functions, @code{reverse-step} will step (backward) into
6000 the called function, stopping at the beginning of the @emph{last}
6001 statement in the called function (typically a return statement).
6002
6003 Also, as with the @code{step} command, if non-debuggable functions are
6004 called, @code{reverse-step} will run thru them backward without stopping.
6005
6006 @kindex reverse-stepi
6007 @kindex rsi @r{(@code{reverse-stepi})}
6008 @item reverse-stepi @r{[}@var{count}@r{]}
6009 Reverse-execute one machine instruction.  Note that the instruction
6010 to be reverse-executed is @emph{not} the one pointed to by the program
6011 counter, but the instruction executed prior to that one.  For instance,
6012 if the last instruction was a jump, @code{reverse-stepi} will take you
6013 back from the destination of the jump to the jump instruction itself.
6014
6015 @kindex reverse-next
6016 @kindex rn @r{(@code{reverse-next})}
6017 @item reverse-next @r{[}@var{count}@r{]}
6018 Run backward to the beginning of the previous line executed in
6019 the current (innermost) stack frame.  If the line contains function
6020 calls, they will be ``un-executed'' without stopping.  Starting from
6021 the first line of a function, @code{reverse-next} will take you back
6022 to the caller of that function, @emph{before} the function was called,
6023 just as the normal @code{next} command would take you from the last 
6024 line of a function back to its return to its caller
6025 @footnote{Unless the code is too heavily optimized.}.
6026
6027 @kindex reverse-nexti
6028 @kindex rni @r{(@code{reverse-nexti})}
6029 @item reverse-nexti @r{[}@var{count}@r{]}
6030 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6031 in reverse, except that called functions are ``un-executed'' atomically.
6032 That is, if the previously executed instruction was a return from
6033 another function, @code{reverse-nexti} will continue to execute
6034 in reverse until the call to that function (from the current stack
6035 frame) is reached.
6036
6037 @kindex reverse-finish
6038 @item reverse-finish
6039 Just as the @code{finish} command takes you to the point where the
6040 current function returns, @code{reverse-finish} takes you to the point
6041 where it was called.  Instead of ending up at the end of the current
6042 function invocation, you end up at the beginning.
6043
6044 @kindex set exec-direction
6045 @item set exec-direction
6046 Set the direction of target execution.
6047 @item set exec-direction reverse
6048 @cindex execute forward or backward in time
6049 @value{GDBN} will perform all execution commands in reverse, until the
6050 exec-direction mode is changed to ``forward''.  Affected commands include
6051 @code{step, stepi, next, nexti, continue, and finish}.  The @code{return}
6052 command cannot be used in reverse mode.
6053 @item set exec-direction forward
6054 @value{GDBN} will perform all execution commands in the normal fashion.
6055 This is the default.
6056 @end table
6057
6058
6059 @node Process Record and Replay
6060 @chapter Recording Inferior's Execution and Replaying It
6061 @cindex process record and replay
6062 @cindex recording inferior's execution and replaying it
6063
6064 On some platforms, @value{GDBN} provides a special @dfn{process record
6065 and replay} target that can record a log of the process execution, and
6066 replay it later with both forward and reverse execution commands.
6067
6068 @cindex replay mode
6069 When this target is in use, if the execution log includes the record
6070 for the next instruction, @value{GDBN} will debug in @dfn{replay
6071 mode}.  In the replay mode, the inferior does not really execute code
6072 instructions.  Instead, all the events that normally happen during
6073 code execution are taken from the execution log.  While code is not
6074 really executed in replay mode, the values of registers (including the
6075 program counter register) and the memory of the inferior are still
6076 changed as they normally would.  Their contents are taken from the
6077 execution log.
6078
6079 @cindex record mode
6080 If the record for the next instruction is not in the execution log,
6081 @value{GDBN} will debug in @dfn{record mode}.  In this mode, the
6082 inferior executes normally, and @value{GDBN} records the execution log
6083 for future replay.
6084
6085 The process record and replay target supports reverse execution
6086 (@pxref{Reverse Execution}), even if the platform on which the
6087 inferior runs does not.  However, the reverse execution is limited in
6088 this case by the range of the instructions recorded in the execution
6089 log.  In other words, reverse execution on platforms that don't
6090 support it directly can only be done in the replay mode.
6091
6092 When debugging in the reverse direction, @value{GDBN} will work in
6093 replay mode as long as the execution log includes the record for the
6094 previous instruction; otherwise, it will work in record mode, if the
6095 platform supports reverse execution, or stop if not.
6096
6097 For architecture environments that support process record and replay,
6098 @value{GDBN} provides the following commands:
6099
6100 @table @code
6101 @kindex target record
6102 @kindex record
6103 @kindex rec
6104 @item target record
6105 This command starts the process record and replay target.  The process
6106 record and replay target can only debug a process that is already
6107 running.  Therefore, you need first to start the process with the
6108 @kbd{run} or @kbd{start} commands, and then start the recording with
6109 the @kbd{target record} command.
6110
6111 Both @code{record} and @code{rec} are aliases of @code{target record}.
6112
6113 @cindex displaced stepping, and process record and replay
6114 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6115 will be automatically disabled when process record and replay target
6116 is started.  That's because the process record and replay target
6117 doesn't support displaced stepping.
6118
6119 @cindex non-stop mode, and process record and replay
6120 @cindex asynchronous execution, and process record and replay
6121 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
6122 the asynchronous execution mode (@pxref{Background Execution}), the
6123 process record and replay target cannot be started because it doesn't
6124 support these two modes.
6125
6126 @kindex record stop
6127 @kindex rec s
6128 @item record stop
6129 Stop the process record and replay target.  When process record and
6130 replay target stops, the entire execution log will be deleted and the
6131 inferior will either be terminated, or will remain in its final state.
6132
6133 When you stop the process record and replay target in record mode (at
6134 the end of the execution log), the inferior will be stopped at the
6135 next instruction that would have been recorded.  In other words, if
6136 you record for a while and then stop recording, the inferior process
6137 will be left in the same state as if the recording never happened.
6138
6139 On the other hand, if the process record and replay target is stopped
6140 while in replay mode (that is, not at the end of the execution log,
6141 but at some earlier point), the inferior process will become ``live''
6142 at that earlier state, and it will then be possible to continue the
6143 usual ``live'' debugging of the process from that state.
6144
6145 When the inferior process exits, or @value{GDBN} detaches from it,
6146 process record and replay target will automatically stop itself.
6147
6148 @kindex record save
6149 @item record save @var{filename}
6150 Save the execution log to a file @file{@var{filename}}.
6151 Default filename is @file{gdb_record.@var{process_id}}, where
6152 @var{process_id} is the process ID of the inferior.
6153
6154 @kindex record restore
6155 @item record restore @var{filename}
6156 Restore the execution log from a file @file{@var{filename}}.
6157 File must have been created with @code{record save}.
6158
6159 @kindex set record insn-number-max
6160 @item set record insn-number-max @var{limit}
6161 Set the limit of instructions to be recorded.  Default value is 200000.
6162
6163 If @var{limit} is a positive number, then @value{GDBN} will start
6164 deleting instructions from the log once the number of the record
6165 instructions becomes greater than @var{limit}.  For every new recorded
6166 instruction, @value{GDBN} will delete the earliest recorded
6167 instruction to keep the number of recorded instructions at the limit.
6168 (Since deleting recorded instructions loses information, @value{GDBN}
6169 lets you control what happens when the limit is reached, by means of
6170 the @code{stop-at-limit} option, described below.)
6171
6172 If @var{limit} is zero, @value{GDBN} will never delete recorded
6173 instructions from the execution log.  The number of recorded
6174 instructions is unlimited in this case.
6175
6176 @kindex show record insn-number-max
6177 @item show record insn-number-max
6178 Show the limit of instructions to be recorded.
6179
6180 @kindex set record stop-at-limit
6181 @item set record stop-at-limit
6182 Control the behavior when the number of recorded instructions reaches
6183 the limit.  If ON (the default), @value{GDBN} will stop when the limit
6184 is reached for the first time and ask you whether you want to stop the
6185 inferior or continue running it and recording the execution log.  If
6186 you decide to continue recording, each new recorded instruction will
6187 cause the oldest one to be deleted.
6188
6189 If this option is OFF, @value{GDBN} will automatically delete the
6190 oldest record to make room for each new one, without asking.
6191
6192 @kindex show record stop-at-limit
6193 @item show record stop-at-limit
6194 Show the current setting of @code{stop-at-limit}.
6195
6196 @kindex set record memory-query
6197 @item set record memory-query
6198 Control the behavior when @value{GDBN} is unable to record memory
6199 changes caused by an instruction.  If ON, @value{GDBN} will query
6200 whether to stop the inferior in that case.
6201
6202 If this option is OFF (the default), @value{GDBN} will automatically
6203 ignore the effect of such instructions on memory.  Later, when
6204 @value{GDBN} replays this execution log, it will mark the log of this
6205 instruction as not accessible, and it will not affect the replay
6206 results.
6207
6208 @kindex show record memory-query
6209 @item show record memory-query
6210 Show the current setting of @code{memory-query}.
6211
6212 @kindex info record
6213 @item info record
6214 Show various statistics about the state of process record and its
6215 in-memory execution log buffer, including:
6216
6217 @itemize @bullet
6218 @item
6219 Whether in record mode or replay mode.
6220 @item
6221 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6222 @item
6223 Highest recorded instruction number.
6224 @item
6225 Current instruction about to be replayed (if in replay mode).
6226 @item
6227 Number of instructions contained in the execution log.
6228 @item
6229 Maximum number of instructions that may be contained in the execution log.
6230 @end itemize
6231
6232 @kindex record delete
6233 @kindex rec del
6234 @item record delete
6235 When record target runs in replay mode (``in the past''), delete the
6236 subsequent execution log and begin to record a new execution log starting
6237 from the current address.  This means you will abandon the previously
6238 recorded ``future'' and begin recording a new ``future''.
6239 @end table
6240
6241
6242 @node Stack
6243 @chapter Examining the Stack
6244
6245 When your program has stopped, the first thing you need to know is where it
6246 stopped and how it got there.
6247
6248 @cindex call stack
6249 Each time your program performs a function call, information about the call
6250 is generated.
6251 That information includes the location of the call in your program,
6252 the arguments of the call,
6253 and the local variables of the function being called.
6254 The information is saved in a block of data called a @dfn{stack frame}.
6255 The stack frames are allocated in a region of memory called the @dfn{call
6256 stack}.
6257
6258 When your program stops, the @value{GDBN} commands for examining the
6259 stack allow you to see all of this information.
6260
6261 @cindex selected frame
6262 One of the stack frames is @dfn{selected} by @value{GDBN} and many
6263 @value{GDBN} commands refer implicitly to the selected frame.  In
6264 particular, whenever you ask @value{GDBN} for the value of a variable in
6265 your program, the value is found in the selected frame.  There are
6266 special @value{GDBN} commands to select whichever frame you are
6267 interested in.  @xref{Selection, ,Selecting a Frame}.
6268
6269 When your program stops, @value{GDBN} automatically selects the
6270 currently executing frame and describes it briefly, similar to the
6271 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
6272
6273 @menu
6274 * Frames::                      Stack frames
6275 * Backtrace::                   Backtraces
6276 * Selection::                   Selecting a frame
6277 * Frame Info::                  Information on a frame
6278
6279 @end menu
6280
6281 @node Frames
6282 @section Stack Frames
6283
6284 @cindex frame, definition
6285 @cindex stack frame
6286 The call stack is divided up into contiguous pieces called @dfn{stack
6287 frames}, or @dfn{frames} for short; each frame is the data associated
6288 with one call to one function.  The frame contains the arguments given
6289 to the function, the function's local variables, and the address at
6290 which the function is executing.
6291
6292 @cindex initial frame
6293 @cindex outermost frame
6294 @cindex innermost frame
6295 When your program is started, the stack has only one frame, that of the
6296 function @code{main}.  This is called the @dfn{initial} frame or the
6297 @dfn{outermost} frame.  Each time a function is called, a new frame is
6298 made.  Each time a function returns, the frame for that function invocation
6299 is eliminated.  If a function is recursive, there can be many frames for
6300 the same function.  The frame for the function in which execution is
6301 actually occurring is called the @dfn{innermost} frame.  This is the most
6302 recently created of all the stack frames that still exist.
6303
6304 @cindex frame pointer
6305 Inside your program, stack frames are identified by their addresses.  A
6306 stack frame consists of many bytes, each of which has its own address; each
6307 kind of computer has a convention for choosing one byte whose
6308 address serves as the address of the frame.  Usually this address is kept
6309 in a register called the @dfn{frame pointer register}
6310 (@pxref{Registers, $fp}) while execution is going on in that frame.
6311
6312 @cindex frame number
6313 @value{GDBN} assigns numbers to all existing stack frames, starting with
6314 zero for the innermost frame, one for the frame that called it,
6315 and so on upward.  These numbers do not really exist in your program;
6316 they are assigned by @value{GDBN} to give you a way of designating stack
6317 frames in @value{GDBN} commands.
6318
6319 @c The -fomit-frame-pointer below perennially causes hbox overflow
6320 @c underflow problems.
6321 @cindex frameless execution
6322 Some compilers provide a way to compile functions so that they operate
6323 without stack frames.  (For example, the @value{NGCC} option
6324 @smallexample
6325 @samp{-fomit-frame-pointer}
6326 @end smallexample
6327 generates functions without a frame.)
6328 This is occasionally done with heavily used library functions to save
6329 the frame setup time.  @value{GDBN} has limited facilities for dealing
6330 with these function invocations.  If the innermost function invocation
6331 has no stack frame, @value{GDBN} nevertheless regards it as though
6332 it had a separate frame, which is numbered zero as usual, allowing
6333 correct tracing of the function call chain.  However, @value{GDBN} has
6334 no provision for frameless functions elsewhere in the stack.
6335
6336 @table @code
6337 @kindex frame@r{, command}
6338 @cindex current stack frame
6339 @item frame @var{args}
6340 The @code{frame} command allows you to move from one stack frame to another,
6341 and to print the stack frame you select.  @var{args} may be either the
6342 address of the frame or the stack frame number.  Without an argument,
6343 @code{frame} prints the current stack frame.
6344
6345 @kindex select-frame
6346 @cindex selecting frame silently
6347 @item select-frame
6348 The @code{select-frame} command allows you to move from one stack frame
6349 to another without printing the frame.  This is the silent version of
6350 @code{frame}.
6351 @end table
6352
6353 @node Backtrace
6354 @section Backtraces
6355
6356 @cindex traceback
6357 @cindex call stack traces
6358 A backtrace is a summary of how your program got where it is.  It shows one
6359 line per frame, for many frames, starting with the currently executing
6360 frame (frame zero), followed by its caller (frame one), and on up the
6361 stack.
6362
6363 @table @code
6364 @kindex backtrace
6365 @kindex bt @r{(@code{backtrace})}
6366 @item backtrace
6367 @itemx bt
6368 Print a backtrace of the entire stack: one line per frame for all
6369 frames in the stack.
6370
6371 You can stop the backtrace at any time by typing the system interrupt
6372 character, normally @kbd{Ctrl-c}.
6373
6374 @item backtrace @var{n}
6375 @itemx bt @var{n}
6376 Similar, but print only the innermost @var{n} frames.
6377
6378 @item backtrace -@var{n}
6379 @itemx bt -@var{n}
6380 Similar, but print only the outermost @var{n} frames.
6381
6382 @item backtrace full
6383 @itemx bt full
6384 @itemx bt full @var{n}
6385 @itemx bt full -@var{n}
6386 Print the values of the local variables also.  @var{n} specifies the
6387 number of frames to print, as described above.
6388 @end table
6389
6390 @kindex where
6391 @kindex info stack
6392 The names @code{where} and @code{info stack} (abbreviated @code{info s})
6393 are additional aliases for @code{backtrace}.
6394
6395 @cindex multiple threads, backtrace
6396 In a multi-threaded program, @value{GDBN} by default shows the
6397 backtrace only for the current thread.  To display the backtrace for
6398 several or all of the threads, use the command @code{thread apply}
6399 (@pxref{Threads, thread apply}).  For example, if you type @kbd{thread
6400 apply all backtrace}, @value{GDBN} will display the backtrace for all
6401 the threads; this is handy when you debug a core dump of a
6402 multi-threaded program.
6403
6404 Each line in the backtrace shows the frame number and the function name.
6405 The program counter value is also shown---unless you use @code{set
6406 print address off}.  The backtrace also shows the source file name and
6407 line number, as well as the arguments to the function.  The program
6408 counter value is omitted if it is at the beginning of the code for that
6409 line number.
6410
6411 Here is an example of a backtrace.  It was made with the command
6412 @samp{bt 3}, so it shows the innermost three frames.
6413
6414 @smallexample
6415 @group
6416 #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6417     at builtin.c:993
6418 #1  0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
6419 #2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6420     at macro.c:71
6421 (More stack frames follow...)
6422 @end group
6423 @end smallexample
6424
6425 @noindent
6426 The display for frame zero does not begin with a program counter
6427 value, indicating that your program has stopped at the beginning of the
6428 code for line @code{993} of @code{builtin.c}.
6429
6430 @noindent
6431 The value of parameter @code{data} in frame 1 has been replaced by
6432 @code{@dots{}}.  By default, @value{GDBN} prints the value of a parameter
6433 only if it is a scalar (integer, pointer, enumeration, etc).  See command
6434 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
6435 on how to configure the way function parameter values are printed.
6436
6437 @cindex optimized out, in backtrace
6438 @cindex function call arguments, optimized out
6439 If your program was compiled with optimizations, some compilers will
6440 optimize away arguments passed to functions if those arguments are
6441 never used after the call.  Such optimizations generate code that
6442 passes arguments through registers, but doesn't store those arguments
6443 in the stack frame.  @value{GDBN} has no way of displaying such
6444 arguments in stack frames other than the innermost one.  Here's what
6445 such a backtrace might look like:
6446
6447 @smallexample
6448 @group
6449 #0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6450     at builtin.c:993
6451 #1  0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6452 #2  0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
6453     at macro.c:71
6454 (More stack frames follow...)
6455 @end group
6456 @end smallexample
6457
6458 @noindent
6459 The values of arguments that were not saved in their stack frames are
6460 shown as @samp{<optimized out>}.
6461
6462 If you need to display the values of such optimized-out arguments,
6463 either deduce that from other variables whose values depend on the one
6464 you are interested in, or recompile without optimizations.
6465
6466 @cindex backtrace beyond @code{main} function
6467 @cindex program entry point
6468 @cindex startup code, and backtrace
6469 Most programs have a standard user entry point---a place where system
6470 libraries and startup code transition into user code.  For C this is
6471 @code{main}@footnote{
6472 Note that embedded programs (the so-called ``free-standing''
6473 environment) are not required to have a @code{main} function as the
6474 entry point.  They could even have multiple entry points.}.
6475 When @value{GDBN} finds the entry function in a backtrace
6476 it will terminate the backtrace, to avoid tracing into highly
6477 system-specific (and generally uninteresting) code.
6478
6479 If you need to examine the startup code, or limit the number of levels
6480 in a backtrace, you can change this behavior:
6481
6482 @table @code
6483 @item set backtrace past-main
6484 @itemx set backtrace past-main on
6485 @kindex set backtrace
6486 Backtraces will continue past the user entry point.
6487
6488 @item set backtrace past-main off
6489 Backtraces will stop when they encounter the user entry point.  This is the
6490 default.
6491
6492 @item show backtrace past-main
6493 @kindex show backtrace
6494 Display the current user entry point backtrace policy.
6495
6496 @item set backtrace past-entry
6497 @itemx set backtrace past-entry on
6498 Backtraces will continue past the internal entry point of an application.
6499 This entry point is encoded by the linker when the application is built,
6500 and is likely before the user entry point @code{main} (or equivalent) is called.
6501
6502 @item set backtrace past-entry off
6503 Backtraces will stop when they encounter the internal entry point of an
6504 application.  This is the default.
6505
6506 @item show backtrace past-entry
6507 Display the current internal entry point backtrace policy.
6508
6509 @item set backtrace limit @var{n}
6510 @itemx set backtrace limit 0
6511 @cindex backtrace limit
6512 Limit the backtrace to @var{n} levels.  A value of zero means
6513 unlimited.
6514
6515 @item show backtrace limit
6516 Display the current limit on backtrace levels.
6517 @end table
6518
6519 @node Selection
6520 @section Selecting a Frame
6521
6522 Most commands for examining the stack and other data in your program work on
6523 whichever stack frame is selected at the moment.  Here are the commands for
6524 selecting a stack frame; all of them finish by printing a brief description
6525 of the stack frame just selected.
6526
6527 @table @code
6528 @kindex frame@r{, selecting}
6529 @kindex f @r{(@code{frame})}
6530 @item frame @var{n}
6531 @itemx f @var{n}
6532 Select frame number @var{n}.  Recall that frame zero is the innermost
6533 (currently executing) frame, frame one is the frame that called the
6534 innermost one, and so on.  The highest-numbered frame is the one for
6535 @code{main}.
6536
6537 @item frame @var{addr}
6538 @itemx f @var{addr}
6539 Select the frame at address @var{addr}.  This is useful mainly if the
6540 chaining of stack frames has been damaged by a bug, making it
6541 impossible for @value{GDBN} to assign numbers properly to all frames.  In
6542 addition, this can be useful when your program has multiple stacks and
6543 switches between them.
6544
6545 On the SPARC architecture, @code{frame} needs two addresses to
6546 select an arbitrary frame: a frame pointer and a stack pointer.
6547
6548 On the @acronym{MIPS} and Alpha architecture, it needs two addresses: a stack
6549 pointer and a program counter.
6550
6551 On the 29k architecture, it needs three addresses: a register stack
6552 pointer, a program counter, and a memory stack pointer.
6553
6554 @kindex up
6555 @item up @var{n}
6556 Move @var{n} frames up the stack.  For positive numbers @var{n}, this
6557 advances toward the outermost frame, to higher frame numbers, to frames
6558 that have existed longer.  @var{n} defaults to one.
6559
6560 @kindex down
6561 @kindex do @r{(@code{down})}
6562 @item down @var{n}
6563 Move @var{n} frames down the stack.  For positive numbers @var{n}, this
6564 advances toward the innermost frame, to lower frame numbers, to frames
6565 that were created more recently.  @var{n} defaults to one.  You may
6566 abbreviate @code{down} as @code{do}.
6567 @end table
6568
6569 All of these commands end by printing two lines of output describing the
6570 frame.  The first line shows the frame number, the function name, the
6571 arguments, and the source file and line number of execution in that
6572 frame.  The second line shows the text of that source line.
6573
6574 @need 1000
6575 For example:
6576
6577 @smallexample
6578 @group
6579 (@value{GDBP}) up
6580 #1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6581     at env.c:10
6582 10              read_input_file (argv[i]);
6583 @end group
6584 @end smallexample
6585
6586 After such a printout, the @code{list} command with no arguments
6587 prints ten lines centered on the point of execution in the frame.
6588 You can also edit the program at the point of execution with your favorite
6589 editing program by typing @code{edit}.
6590 @xref{List, ,Printing Source Lines},
6591 for details.
6592
6593 @table @code
6594 @kindex down-silently
6595 @kindex up-silently
6596 @item up-silently @var{n}
6597 @itemx down-silently @var{n}
6598 These two commands are variants of @code{up} and @code{down},
6599 respectively; they differ in that they do their work silently, without
6600 causing display of the new frame.  They are intended primarily for use
6601 in @value{GDBN} command scripts, where the output might be unnecessary and
6602 distracting.
6603 @end table
6604
6605 @node Frame Info
6606 @section Information About a Frame
6607
6608 There are several other commands to print information about the selected
6609 stack frame.
6610
6611 @table @code
6612 @item frame
6613 @itemx f
6614 When used without any argument, this command does not change which
6615 frame is selected, but prints a brief description of the currently
6616 selected stack frame.  It can be abbreviated @code{f}.  With an
6617 argument, this command is used to select a stack frame.
6618 @xref{Selection, ,Selecting a Frame}.
6619
6620 @kindex info frame
6621 @kindex info f @r{(@code{info frame})}
6622 @item info frame
6623 @itemx info f
6624 This command prints a verbose description of the selected stack frame,
6625 including:
6626
6627 @itemize @bullet
6628 @item
6629 the address of the frame
6630 @item
6631 the address of the next frame down (called by this frame)
6632 @item
6633 the address of the next frame up (caller of this frame)
6634 @item
6635 the language in which the source code corresponding to this frame is written
6636 @item
6637 the address of the frame's arguments
6638 @item
6639 the address of the frame's local variables
6640 @item
6641 the program counter saved in it (the address of execution in the caller frame)
6642 @item
6643 which registers were saved in the frame
6644 @end itemize
6645
6646 @noindent The verbose description is useful when
6647 something has gone wrong that has made the stack format fail to fit
6648 the usual conventions.
6649
6650 @item info frame @var{addr}
6651 @itemx info f @var{addr}
6652 Print a verbose description of the frame at address @var{addr}, without
6653 selecting that frame.  The selected frame remains unchanged by this
6654 command.  This requires the same kind of address (more than one for some
6655 architectures) that you specify in the @code{frame} command.
6656 @xref{Selection, ,Selecting a Frame}.
6657
6658 @kindex info args
6659 @item info args
6660 Print the arguments of the selected frame, each on a separate line.
6661
6662 @item info locals
6663 @kindex info locals
6664 Print the local variables of the selected frame, each on a separate
6665 line.  These are all variables (declared either static or automatic)
6666 accessible at the point of execution of the selected frame.
6667
6668 @end table
6669
6670
6671 @node Source
6672 @chapter Examining Source Files
6673
6674 @value{GDBN} can print parts of your program's source, since the debugging
6675 information recorded in the program tells @value{GDBN} what source files were
6676 used to build it.  When your program stops, @value{GDBN} spontaneously prints
6677 the line where it stopped.  Likewise, when you select a stack frame
6678 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
6679 execution in that frame has stopped.  You can print other portions of
6680 source files by explicit command.
6681
6682 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
6683 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
6684 @value{GDBN} under @sc{gnu} Emacs}.
6685
6686 @menu
6687 * List::                        Printing source lines
6688 * Specify Location::            How to specify code locations
6689 * Edit::                        Editing source files
6690 * Search::                      Searching source files
6691 * Source Path::                 Specifying source directories
6692 * Machine Code::                Source and machine code
6693 @end menu
6694
6695 @node List
6696 @section Printing Source Lines
6697
6698 @kindex list
6699 @kindex l @r{(@code{list})}
6700 To print lines from a source file, use the @code{list} command
6701 (abbreviated @code{l}).  By default, ten lines are printed.
6702 There are several ways to specify what part of the file you want to
6703 print; see @ref{Specify Location}, for the full list.
6704
6705 Here are the forms of the @code{list} command most commonly used:
6706
6707 @table @code
6708 @item list @var{linenum}
6709 Print lines centered around line number @var{linenum} in the
6710 current source file.
6711
6712 @item list @var{function}
6713 Print lines centered around the beginning of function
6714 @var{function}.
6715
6716 @item list
6717 Print more lines.  If the last lines printed were printed with a
6718 @code{list} command, this prints lines following the last lines
6719 printed; however, if the last line printed was a solitary line printed
6720 as part of displaying a stack frame (@pxref{Stack, ,Examining the
6721 Stack}), this prints lines centered around that line.
6722
6723 @item list -
6724 Print lines just before the lines last printed.
6725 @end table
6726
6727 @cindex @code{list}, how many lines to display
6728 By default, @value{GDBN} prints ten source lines with any of these forms of
6729 the @code{list} command.  You can change this using @code{set listsize}:
6730
6731 @table @code
6732 @kindex set listsize
6733 @item set listsize @var{count}
6734 Make the @code{list} command display @var{count} source lines (unless
6735 the @code{list} argument explicitly specifies some other number).
6736 Setting @var{count} to -1 means there's no limit and 0 means suppress
6737 display of source lines.
6738
6739 @kindex show listsize
6740 @item show listsize
6741 Display the number of lines that @code{list} prints.
6742 @end table
6743
6744 Repeating a @code{list} command with @key{RET} discards the argument,
6745 so it is equivalent to typing just @code{list}.  This is more useful
6746 than listing the same lines again.  An exception is made for an
6747 argument of @samp{-}; that argument is preserved in repetition so that
6748 each repetition moves up in the source file.
6749
6750 In general, the @code{list} command expects you to supply zero, one or two
6751 @dfn{linespecs}.  Linespecs specify source lines; there are several ways
6752 of writing them (@pxref{Specify Location}), but the effect is always
6753 to specify some source line.
6754
6755 Here is a complete description of the possible arguments for @code{list}:
6756
6757 @table @code
6758 @item list @var{linespec}
6759 Print lines centered around the line specified by @var{linespec}.
6760
6761 @item list @var{first},@var{last}
6762 Print lines from @var{first} to @var{last}.  Both arguments are
6763 linespecs.  When a @code{list} command has two linespecs, and the
6764 source file of the second linespec is omitted, this refers to
6765 the same source file as the first linespec.
6766
6767 @item list ,@var{last}
6768 Print lines ending with @var{last}.
6769
6770 @item list @var{first},
6771 Print lines starting with @var{first}.
6772
6773 @item list +
6774 Print lines just after the lines last printed.
6775
6776 @item list -
6777 Print lines just before the lines last printed.
6778
6779 @item list
6780 As described in the preceding table.
6781 @end table
6782
6783 @node Specify Location
6784 @section Specifying a Location
6785 @cindex specifying location
6786 @cindex linespec
6787
6788 Several @value{GDBN} commands accept arguments that specify a location
6789 of your program's code.  Since @value{GDBN} is a source-level
6790 debugger, a location usually specifies some line in the source code;
6791 for that reason, locations are also known as @dfn{linespecs}.
6792
6793 Here are all the different ways of specifying a code location that
6794 @value{GDBN} understands:
6795
6796 @table @code
6797 @item @var{linenum}
6798 Specifies the line number @var{linenum} of the current source file.
6799
6800 @item -@var{offset}
6801 @itemx +@var{offset}
6802 Specifies the line @var{offset} lines before or after the @dfn{current
6803 line}.  For the @code{list} command, the current line is the last one
6804 printed; for the breakpoint commands, this is the line at which
6805 execution stopped in the currently selected @dfn{stack frame}
6806 (@pxref{Frames, ,Frames}, for a description of stack frames.)  When
6807 used as the second of the two linespecs in a @code{list} command,
6808 this specifies the line @var{offset} lines up or down from the first
6809 linespec.
6810
6811 @item @var{filename}:@var{linenum}
6812 Specifies the line @var{linenum} in the source file @var{filename}.
6813 If @var{filename} is a relative file name, then it will match any
6814 source file name with the same trailing components.  For example, if
6815 @var{filename} is @samp{gcc/expr.c}, then it will match source file
6816 name of @file{/build/trunk/gcc/expr.c}, but not
6817 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
6818
6819 @item @var{function}
6820 Specifies the line that begins the body of the function @var{function}.
6821 For example, in C, this is the line with the open brace.
6822
6823 @item @var{function}:@var{label}
6824 Specifies the line where @var{label} appears in @var{function}.
6825
6826 @item @var{filename}:@var{function}
6827 Specifies the line that begins the body of the function @var{function}
6828 in the file @var{filename}.  You only need the file name with a
6829 function name to avoid ambiguity when there are identically named
6830 functions in different source files.
6831
6832 @item @var{label}
6833 Specifies the line at which the label named @var{label} appears.
6834 @value{GDBN} searches for the label in the function corresponding to
6835 the currently selected stack frame.  If there is no current selected
6836 stack frame (for instance, if the inferior is not running), then
6837 @value{GDBN} will not search for a label.
6838
6839 @item *@var{address}
6840 Specifies the program address @var{address}.  For line-oriented
6841 commands, such as @code{list} and @code{edit}, this specifies a source
6842 line that contains @var{address}.  For @code{break} and other
6843 breakpoint oriented commands, this can be used to set breakpoints in
6844 parts of your program which do not have debugging information or
6845 source files.
6846
6847 Here @var{address} may be any expression valid in the current working
6848 language (@pxref{Languages, working language}) that specifies a code
6849 address.  In addition, as a convenience, @value{GDBN} extends the
6850 semantics of expressions used in locations to cover the situations
6851 that frequently happen during debugging.  Here are the various forms
6852 of @var{address}:
6853
6854 @table @code
6855 @item @var{expression}
6856 Any expression valid in the current working language.
6857
6858 @item @var{funcaddr}
6859 An address of a function or procedure derived from its name.  In C,
6860 C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
6861 simply the function's name @var{function} (and actually a special case
6862 of a valid expression).  In Pascal and Modula-2, this is
6863 @code{&@var{function}}.  In Ada, this is @code{@var{function}'Address}
6864 (although the Pascal form also works).
6865
6866 This form specifies the address of the function's first instruction,
6867 before the stack frame and arguments have been set up.
6868
6869 @item '@var{filename}'::@var{funcaddr}
6870 Like @var{funcaddr} above, but also specifies the name of the source
6871 file explicitly.  This is useful if the name of the function does not
6872 specify the function unambiguously, e.g., if there are several
6873 functions with identical names in different source files.
6874 @end table
6875
6876 @cindex breakpoint at static probe point
6877 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
6878 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
6879 applications to embed static probes.  @xref{Static Probe Points}, for more
6880 information on finding and using static probes.  This form of linespec
6881 specifies the location of such a static probe.
6882
6883 If @var{objfile} is given, only probes coming from that shared library
6884 or executable matching @var{objfile} as a regular expression are considered.
6885 If @var{provider} is given, then only probes from that provider are considered.
6886 If several probes match the spec, @value{GDBN} will insert a breakpoint at
6887 each one of those probes.
6888
6889 @end table
6890
6891
6892 @node Edit
6893 @section Editing Source Files
6894 @cindex editing source files
6895
6896 @kindex edit
6897 @kindex e @r{(@code{edit})}
6898 To edit the lines in a source file, use the @code{edit} command.
6899 The editing program of your choice
6900 is invoked with the current line set to
6901 the active line in the program.
6902 Alternatively, there are several ways to specify what part of the file you
6903 want to print if you want to see other parts of the program:
6904
6905 @table @code
6906 @item edit @var{location}
6907 Edit the source file specified by @code{location}.  Editing starts at
6908 that @var{location}, e.g., at the specified source line of the
6909 specified file.  @xref{Specify Location}, for all the possible forms
6910 of the @var{location} argument; here are the forms of the @code{edit}
6911 command most commonly used:
6912
6913 @table @code
6914 @item edit @var{number}
6915 Edit the current source file with @var{number} as the active line number.
6916
6917 @item edit @var{function}
6918 Edit the file containing @var{function} at the beginning of its definition.
6919 @end table
6920
6921 @end table
6922
6923 @subsection Choosing your Editor
6924 You can customize @value{GDBN} to use any editor you want
6925 @footnote{
6926 The only restriction is that your editor (say @code{ex}), recognizes the
6927 following command-line syntax:
6928 @smallexample
6929 ex +@var{number} file
6930 @end smallexample
6931 The optional numeric value +@var{number} specifies the number of the line in
6932 the file where to start editing.}.
6933 By default, it is @file{@value{EDITOR}}, but you can change this
6934 by setting the environment variable @code{EDITOR} before using
6935 @value{GDBN}.  For example, to configure @value{GDBN} to use the
6936 @code{vi} editor, you could use these commands with the @code{sh} shell:
6937 @smallexample
6938 EDITOR=/usr/bin/vi
6939 export EDITOR
6940 gdb @dots{}
6941 @end smallexample
6942 or in the @code{csh} shell,
6943 @smallexample
6944 setenv EDITOR /usr/bin/vi
6945 gdb @dots{}
6946 @end smallexample
6947
6948 @node Search
6949 @section Searching Source Files
6950 @cindex searching source files
6951
6952 There are two commands for searching through the current source file for a
6953 regular expression.
6954
6955 @table @code
6956 @kindex search
6957 @kindex forward-search
6958 @kindex fo @r{(@code{forward-search})}
6959 @item forward-search @var{regexp}
6960 @itemx search @var{regexp}
6961 The command @samp{forward-search @var{regexp}} checks each line,
6962 starting with the one following the last line listed, for a match for
6963 @var{regexp}.  It lists the line that is found.  You can use the
6964 synonym @samp{search @var{regexp}} or abbreviate the command name as
6965 @code{fo}.
6966
6967 @kindex reverse-search
6968 @item reverse-search @var{regexp}
6969 The command @samp{reverse-search @var{regexp}} checks each line, starting
6970 with the one before the last line listed and going backward, for a match
6971 for @var{regexp}.  It lists the line that is found.  You can abbreviate
6972 this command as @code{rev}.
6973 @end table
6974
6975 @node Source Path
6976 @section Specifying Source Directories
6977
6978 @cindex source path
6979 @cindex directories for source files
6980 Executable programs sometimes do not record the directories of the source
6981 files from which they were compiled, just the names.  Even when they do,
6982 the directories could be moved between the compilation and your debugging
6983 session.  @value{GDBN} has a list of directories to search for source files;
6984 this is called the @dfn{source path}.  Each time @value{GDBN} wants a source file,
6985 it tries all the directories in the list, in the order they are present
6986 in the list, until it finds a file with the desired name.
6987
6988 For example, suppose an executable references the file
6989 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
6990 @file{/mnt/cross}.  The file is first looked up literally; if this
6991 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
6992 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
6993 message is printed.  @value{GDBN} does not look up the parts of the
6994 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
6995 Likewise, the subdirectories of the source path are not searched: if
6996 the source path is @file{/mnt/cross}, and the binary refers to
6997 @file{foo.c}, @value{GDBN} would not find it under
6998 @file{/mnt/cross/usr/src/foo-1.0/lib}.
6999
7000 Plain file names, relative file names with leading directories, file
7001 names containing dots, etc.@: are all treated as described above; for
7002 instance, if the source path is @file{/mnt/cross}, and the source file
7003 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
7004 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
7005 that---@file{/mnt/cross/foo.c}.
7006
7007 Note that the executable search path is @emph{not} used to locate the
7008 source files.
7009
7010 Whenever you reset or rearrange the source path, @value{GDBN} clears out
7011 any information it has cached about where source files are found and where
7012 each line is in the file.
7013
7014 @kindex directory
7015 @kindex dir
7016 When you start @value{GDBN}, its source path includes only @samp{cdir}
7017 and @samp{cwd}, in that order.
7018 To add other directories, use the @code{directory} command.
7019
7020 The search path is used to find both program source files and @value{GDBN}
7021 script files (read using the @samp{-command} option and @samp{source} command).
7022
7023 In addition to the source path, @value{GDBN} provides a set of commands
7024 that manage a list of source path substitution rules.  A @dfn{substitution
7025 rule} specifies how to rewrite source directories stored in the program's
7026 debug information in case the sources were moved to a different
7027 directory between compilation and debugging.  A rule is made of
7028 two strings, the first specifying what needs to be rewritten in
7029 the path, and the second specifying how it should be rewritten.
7030 In @ref{set substitute-path}, we name these two parts @var{from} and
7031 @var{to} respectively.  @value{GDBN} does a simple string replacement
7032 of @var{from} with @var{to} at the start of the directory part of the
7033 source file name, and uses that result instead of the original file
7034 name to look up the sources.
7035
7036 Using the previous example, suppose the @file{foo-1.0} tree has been
7037 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
7038 @value{GDBN} to replace @file{/usr/src} in all source path names with
7039 @file{/mnt/cross}.  The first lookup will then be
7040 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7041 of @file{/usr/src/foo-1.0/lib/foo.c}.  To define a source path
7042 substitution rule, use the @code{set substitute-path} command
7043 (@pxref{set substitute-path}).
7044
7045 To avoid unexpected substitution results, a rule is applied only if the
7046 @var{from} part of the directory name ends at a directory separator.
7047 For instance, a rule substituting  @file{/usr/source} into
7048 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7049 not to @file{/usr/sourceware/foo-2.0}.  And because the substitution
7050 is applied only at the beginning of the directory name, this rule will
7051 not be applied to @file{/root/usr/source/baz.c} either.
7052
7053 In many cases, you can achieve the same result using the @code{directory}
7054 command.  However, @code{set substitute-path} can be more efficient in
7055 the case where the sources are organized in a complex tree with multiple
7056 subdirectories.  With the @code{directory} command, you need to add each
7057 subdirectory of your project.  If you moved the entire tree while
7058 preserving its internal organization, then @code{set substitute-path}
7059 allows you to direct the debugger to all the sources with one single
7060 command.
7061
7062 @code{set substitute-path} is also more than just a shortcut command.
7063 The source path is only used if the file at the original location no
7064 longer exists.  On the other hand, @code{set substitute-path} modifies
7065 the debugger behavior to look at the rewritten location instead.  So, if
7066 for any reason a source file that is not relevant to your executable is
7067 located at the original location, a substitution rule is the only
7068 method available to point @value{GDBN} at the new location.
7069
7070 @cindex @samp{--with-relocated-sources}
7071 @cindex default source path substitution
7072 You can configure a default source path substitution rule by
7073 configuring @value{GDBN} with the
7074 @samp{--with-relocated-sources=@var{dir}} option.  The @var{dir}
7075 should be the name of a directory under @value{GDBN}'s configured
7076 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7077 directory names in debug information under @var{dir} will be adjusted
7078 automatically if the installed @value{GDBN} is moved to a new
7079 location.  This is useful if @value{GDBN}, libraries or executables
7080 with debug information and corresponding source code are being moved
7081 together.
7082
7083 @table @code
7084 @item directory @var{dirname} @dots{}
7085 @item dir @var{dirname} @dots{}
7086 Add directory @var{dirname} to the front of the source path.  Several
7087 directory names may be given to this command, separated by @samp{:}
7088 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7089 part of absolute file names) or
7090 whitespace.  You may specify a directory that is already in the source
7091 path; this moves it forward, so @value{GDBN} searches it sooner.
7092
7093 @kindex cdir
7094 @kindex cwd
7095 @vindex $cdir@r{, convenience variable}
7096 @vindex $cwd@r{, convenience variable}
7097 @cindex compilation directory
7098 @cindex current directory
7099 @cindex working directory
7100 @cindex directory, current
7101 @cindex directory, compilation
7102 You can use the string @samp{$cdir} to refer to the compilation
7103 directory (if one is recorded), and @samp{$cwd} to refer to the current
7104 working directory.  @samp{$cwd} is not the same as @samp{.}---the former
7105 tracks the current working directory as it changes during your @value{GDBN}
7106 session, while the latter is immediately expanded to the current
7107 directory at the time you add an entry to the source path.
7108
7109 @item directory
7110 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems).  This requires confirmation.
7111
7112 @c RET-repeat for @code{directory} is explicitly disabled, but since
7113 @c repeating it would be a no-op we do not say that.  (thanks to RMS)
7114
7115 @item set directories @var{path-list}
7116 @kindex set directories
7117 Set the source path to @var{path-list}.
7118 @samp{$cdir:$cwd} are added if missing.
7119
7120 @item show directories
7121 @kindex show directories
7122 Print the source path: show which directories it contains.
7123
7124 @anchor{set substitute-path}
7125 @item set substitute-path @var{from} @var{to}
7126 @kindex set substitute-path
7127 Define a source path substitution rule, and add it at the end of the
7128 current list of existing substitution rules.  If a rule with the same
7129 @var{from} was already defined, then the old rule is also deleted.
7130
7131 For example, if the file @file{/foo/bar/baz.c} was moved to
7132 @file{/mnt/cross/baz.c}, then the command
7133
7134 @smallexample
7135 (@value{GDBP}) set substitute-path /usr/src /mnt/cross
7136 @end smallexample
7137
7138 @noindent
7139 will tell @value{GDBN} to replace @samp{/usr/src} with
7140 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
7141 @file{baz.c} even though it was moved.
7142
7143 In the case when more than one substitution rule have been defined,
7144 the rules are evaluated one by one in the order where they have been
7145 defined.  The first one matching, if any, is selected to perform
7146 the substitution.
7147
7148 For instance, if we had entered the following commands:
7149
7150 @smallexample
7151 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
7152 (@value{GDBP}) set substitute-path /usr/src /mnt/src
7153 @end smallexample
7154
7155 @noindent
7156 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
7157 @file{/mnt/include/defs.h} by using the first rule.  However, it would
7158 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
7159 @file{/mnt/src/lib/foo.c}.
7160
7161
7162 @item unset substitute-path [path]
7163 @kindex unset substitute-path
7164 If a path is specified, search the current list of substitution rules
7165 for a rule that would rewrite that path.  Delete that rule if found.
7166 A warning is emitted by the debugger if no rule could be found.
7167
7168 If no path is specified, then all substitution rules are deleted.
7169
7170 @item show substitute-path [path]
7171 @kindex show substitute-path
7172 If a path is specified, then print the source path substitution rule
7173 which would rewrite that path, if any.
7174
7175 If no path is specified, then print all existing source path substitution
7176 rules.
7177
7178 @end table
7179
7180 If your source path is cluttered with directories that are no longer of
7181 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
7182 versions of source.  You can correct the situation as follows:
7183
7184 @enumerate
7185 @item
7186 Use @code{directory} with no argument to reset the source path to its default value.
7187
7188 @item
7189 Use @code{directory} with suitable arguments to reinstall the
7190 directories you want in the source path.  You can add all the
7191 directories in one command.
7192 @end enumerate
7193
7194 @node Machine Code
7195 @section Source and Machine Code
7196 @cindex source line and its code address
7197
7198 You can use the command @code{info line} to map source lines to program
7199 addresses (and vice versa), and the command @code{disassemble} to display
7200 a range of addresses as machine instructions.  You can use the command
7201 @code{set disassemble-next-line} to set whether to disassemble next
7202 source line when execution stops.  When run under @sc{gnu} Emacs
7203 mode, the @code{info line} command causes the arrow to point to the
7204 line specified.  Also, @code{info line} prints addresses in symbolic form as
7205 well as hex.
7206
7207 @table @code
7208 @kindex info line
7209 @item info line @var{linespec}
7210 Print the starting and ending addresses of the compiled code for
7211 source line @var{linespec}.  You can specify source lines in any of
7212 the ways documented in @ref{Specify Location}.
7213 @end table
7214
7215 For example, we can use @code{info line} to discover the location of
7216 the object code for the first line of function
7217 @code{m4_changequote}:
7218
7219 @c FIXME: I think this example should also show the addresses in
7220 @c symbolic form, as they usually would be displayed.
7221 @smallexample
7222 (@value{GDBP}) info line m4_changequote
7223 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
7224 @end smallexample
7225
7226 @noindent
7227 @cindex code address and its source line
7228 We can also inquire (using @code{*@var{addr}} as the form for
7229 @var{linespec}) what source line covers a particular address:
7230 @smallexample
7231 (@value{GDBP}) info line *0x63ff
7232 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
7233 @end smallexample
7234
7235 @cindex @code{$_} and @code{info line}
7236 @cindex @code{x} command, default address
7237 @kindex x@r{(examine), and} info line
7238 After @code{info line}, the default address for the @code{x} command
7239 is changed to the starting address of the line, so that @samp{x/i} is
7240 sufficient to begin examining the machine code (@pxref{Memory,
7241 ,Examining Memory}).  Also, this address is saved as the value of the
7242 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
7243 Variables}).
7244
7245 @table @code
7246 @kindex disassemble
7247 @cindex assembly instructions
7248 @cindex instructions, assembly
7249 @cindex machine instructions
7250 @cindex listing machine instructions
7251 @item disassemble
7252 @itemx disassemble /m
7253 @itemx disassemble /r
7254 This specialized command dumps a range of memory as machine
7255 instructions.  It can also print mixed source+disassembly by specifying
7256 the @code{/m} modifier and print the raw instructions in hex as well as
7257 in symbolic form by specifying the @code{/r}.
7258 The default memory range is the function surrounding the
7259 program counter of the selected frame.  A single argument to this
7260 command is a program counter value; @value{GDBN} dumps the function
7261 surrounding this value.  When two arguments are given, they should
7262 be separated by a comma, possibly surrounded by whitespace.  The
7263 arguments specify a range of addresses to dump, in one of two forms:
7264
7265 @table @code
7266 @item @var{start},@var{end}
7267 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7268 @item @var{start},+@var{length}
7269 the addresses from @var{start} (inclusive) to
7270 @code{@var{start}+@var{length}} (exclusive).
7271 @end table
7272
7273 @noindent
7274 When 2 arguments are specified, the name of the function is also
7275 printed (since there could be several functions in the given range).
7276
7277 The argument(s) can be any expression yielding a numeric value, such as
7278 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
7279
7280 If the range of memory being disassembled contains current program counter,
7281 the instruction at that location is shown with a @code{=>} marker.
7282 @end table
7283
7284 The following example shows the disassembly of a range of addresses of
7285 HP PA-RISC 2.0 code:
7286
7287 @smallexample
7288 (@value{GDBP}) disas 0x32c4, 0x32e4
7289 Dump of assembler code from 0x32c4 to 0x32e4:
7290    0x32c4 <main+204>:      addil 0,dp
7291    0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
7292    0x32cc <main+212>:      ldil 0x3000,r31
7293    0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
7294    0x32d4 <main+220>:      ldo 0(r31),rp
7295    0x32d8 <main+224>:      addil -0x800,dp
7296    0x32dc <main+228>:      ldo 0x588(r1),r26
7297    0x32e0 <main+232>:      ldil 0x3000,r31
7298 End of assembler dump.
7299 @end smallexample
7300
7301 Here is an example showing mixed source+assembly for Intel x86, when the
7302 program is stopped just after function prologue:
7303
7304 @smallexample
7305 (@value{GDBP}) disas /m main
7306 Dump of assembler code for function main:
7307 5       @{
7308    0x08048330 <+0>:    push   %ebp
7309    0x08048331 <+1>:    mov    %esp,%ebp
7310    0x08048333 <+3>:    sub    $0x8,%esp
7311    0x08048336 <+6>:    and    $0xfffffff0,%esp
7312    0x08048339 <+9>:    sub    $0x10,%esp
7313
7314 6         printf ("Hello.\n");
7315 => 0x0804833c <+12>:   movl   $0x8048440,(%esp)
7316    0x08048343 <+19>:   call   0x8048284 <puts@@plt>
7317
7318 7         return 0;
7319 8       @}
7320    0x08048348 <+24>:   mov    $0x0,%eax
7321    0x0804834d <+29>:   leave
7322    0x0804834e <+30>:   ret
7323
7324 End of assembler dump.
7325 @end smallexample
7326
7327 Here is another example showing raw instructions in hex for AMD x86-64,
7328
7329 @smallexample
7330 (gdb) disas /r 0x400281,+10
7331 Dump of assembler code from 0x400281 to 0x40028b:
7332    0x0000000000400281:  38 36  cmp    %dh,(%rsi)
7333    0x0000000000400283:  2d 36 34 2e 73 sub    $0x732e3436,%eax
7334    0x0000000000400288:  6f     outsl  %ds:(%rsi),(%dx)
7335    0x0000000000400289:  2e 32 00       xor    %cs:(%rax),%al
7336 End of assembler dump.
7337 @end smallexample
7338
7339 Some architectures have more than one commonly-used set of instruction
7340 mnemonics or other syntax.
7341
7342 For programs that were dynamically linked and use shared libraries,
7343 instructions that call functions or branch to locations in the shared
7344 libraries might show a seemingly bogus location---it's actually a
7345 location of the relocation table.  On some architectures, @value{GDBN}
7346 might be able to resolve these to actual function names.
7347
7348 @table @code
7349 @kindex set disassembly-flavor
7350 @cindex Intel disassembly flavor
7351 @cindex AT&T disassembly flavor
7352 @item set disassembly-flavor @var{instruction-set}
7353 Select the instruction set to use when disassembling the
7354 program via the @code{disassemble} or @code{x/i} commands.
7355
7356 Currently this command is only defined for the Intel x86 family.  You
7357 can set @var{instruction-set} to either @code{intel} or @code{att}.
7358 The default is @code{att}, the AT&T flavor used by default by Unix
7359 assemblers for x86-based targets.
7360
7361 @kindex show disassembly-flavor
7362 @item show disassembly-flavor
7363 Show the current setting of the disassembly flavor.
7364 @end table
7365
7366 @table @code
7367 @kindex set disassemble-next-line
7368 @kindex show disassemble-next-line
7369 @item set disassemble-next-line
7370 @itemx show disassemble-next-line
7371 Control whether or not @value{GDBN} will disassemble the next source
7372 line or instruction when execution stops.  If ON, @value{GDBN} will
7373 display disassembly of the next source line when execution of the
7374 program being debugged stops.  This is @emph{in addition} to
7375 displaying the source line itself, which @value{GDBN} always does if
7376 possible.  If the next source line cannot be displayed for some reason
7377 (e.g., if @value{GDBN} cannot find the source file, or there's no line
7378 info in the debug info), @value{GDBN} will display disassembly of the
7379 next @emph{instruction} instead of showing the next source line.  If
7380 AUTO, @value{GDBN} will display disassembly of next instruction only
7381 if the source line cannot be displayed.  This setting causes
7382 @value{GDBN} to display some feedback when you step through a function
7383 with no line info or whose source file is unavailable.  The default is
7384 OFF, which means never display the disassembly of the next line or
7385 instruction.
7386 @end table
7387
7388
7389 @node Data
7390 @chapter Examining Data
7391
7392 @cindex printing data
7393 @cindex examining data
7394 @kindex print
7395 @kindex inspect
7396 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
7397 @c document because it is nonstandard...  Under Epoch it displays in a
7398 @c different window or something like that.
7399 The usual way to examine data in your program is with the @code{print}
7400 command (abbreviated @code{p}), or its synonym @code{inspect}.  It
7401 evaluates and prints the value of an expression of the language your
7402 program is written in (@pxref{Languages, ,Using @value{GDBN} with
7403 Different Languages}).  It may also print the expression using a
7404 Python-based pretty-printer (@pxref{Pretty Printing}).
7405
7406 @table @code
7407 @item print @var{expr}
7408 @itemx print /@var{f} @var{expr}
7409 @var{expr} is an expression (in the source language).  By default the
7410 value of @var{expr} is printed in a format appropriate to its data type;
7411 you can choose a different format by specifying @samp{/@var{f}}, where
7412 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
7413 Formats}.
7414
7415 @item print
7416 @itemx print /@var{f}
7417 @cindex reprint the last value
7418 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
7419 @dfn{value history}; @pxref{Value History, ,Value History}).  This allows you to
7420 conveniently inspect the same value in an alternative format.
7421 @end table
7422
7423 A more low-level way of examining data is with the @code{x} command.
7424 It examines data in memory at a specified address and prints it in a
7425 specified format.  @xref{Memory, ,Examining Memory}.
7426
7427 If you are interested in information about types, or about how the
7428 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7429 command rather than @code{print}.  @xref{Symbols, ,Examining the Symbol
7430 Table}.
7431
7432 @cindex exploring hierarchical data structures
7433 @kindex explore
7434 Another way of examining values of expressions and type information is
7435 through the Python extension command @code{explore} (available only if
7436 the @value{GDBN} build is configured with @code{--with-python}).  It
7437 offers an interactive way to start at the highest level (or, the most
7438 abstract level) of the data type of an expression (or, the data type
7439 itself) and explore all the way down to leaf scalar values/fields
7440 embedded in the higher level data types.
7441
7442 @table @code
7443 @item explore @var{arg}
7444 @var{arg} is either an expression (in the source language), or a type
7445 visible in the current context of the program being debugged.
7446 @end table
7447
7448 The working of the @code{explore} command can be illustrated with an
7449 example.  If a data type @code{struct ComplexStruct} is defined in your
7450 C program as
7451
7452 @smallexample
7453 struct SimpleStruct
7454 @{
7455   int i;
7456   double d;
7457 @};
7458
7459 struct ComplexStruct
7460 @{
7461   struct SimpleStruct *ss_p;
7462   int arr[10];
7463 @};
7464 @end smallexample
7465
7466 @noindent
7467 followed by variable declarations as
7468
7469 @smallexample
7470 struct SimpleStruct ss = @{ 10, 1.11 @};
7471 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
7472 @end smallexample
7473
7474 @noindent
7475 then, the value of the variable @code{cs} can be explored using the
7476 @code{explore} command as follows.
7477
7478 @smallexample
7479 (gdb) explore cs
7480 The value of `cs' is a struct/class of type `struct ComplexStruct' with
7481 the following fields:
7482
7483   ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
7484    arr = <Enter 1 to explore this field of type `int [10]'>
7485
7486 Enter the field number of choice:
7487 @end smallexample
7488
7489 @noindent
7490 Since the fields of @code{cs} are not scalar values, you are being
7491 prompted to chose the field you want to explore.  Let's say you choose
7492 the field @code{ss_p} by entering @code{0}.  Then, since this field is a
7493 pointer, you will be asked if it is pointing to a single value.  From
7494 the declaration of @code{cs} above, it is indeed pointing to a single
7495 value, hence you enter @code{y}.  If you enter @code{n}, then you will
7496 be asked if it were pointing to an array of values, in which case this
7497 field will be explored as if it were an array.
7498
7499 @smallexample
7500 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
7501 Continue exploring it as a pointer to a single value [y/n]: y
7502 The value of `*(cs.ss_p)' is a struct/class of type `struct
7503 SimpleStruct' with the following fields:
7504
7505   i = 10 .. (Value of type `int')
7506   d = 1.1100000000000001 .. (Value of type `double')
7507
7508 Press enter to return to parent value:
7509 @end smallexample
7510
7511 @noindent
7512 If the field @code{arr} of @code{cs} was chosen for exploration by
7513 entering @code{1} earlier, then since it is as array, you will be
7514 prompted to enter the index of the element in the array that you want
7515 to explore.
7516
7517 @smallexample
7518 `cs.arr' is an array of `int'.
7519 Enter the index of the element you want to explore in `cs.arr': 5
7520
7521 `(cs.arr)[5]' is a scalar value of type `int'.
7522
7523 (cs.arr)[5] = 4
7524
7525 Press enter to return to parent value: 
7526 @end smallexample
7527
7528 In general, at any stage of exploration, you can go deeper towards the
7529 leaf values by responding to the prompts appropriately, or hit the
7530 return key to return to the enclosing data structure (the @i{higher}
7531 level data structure).
7532
7533 Similar to exploring values, you can use the @code{explore} command to
7534 explore types.  Instead of specifying a value (which is typically a
7535 variable name or an expression valid in the current context of the
7536 program being debugged), you specify a type name.  If you consider the
7537 same example as above, your can explore the type
7538 @code{struct ComplexStruct} by passing the argument
7539 @code{struct ComplexStruct} to the @code{explore} command.
7540
7541 @smallexample
7542 (gdb) explore struct ComplexStruct
7543 @end smallexample
7544
7545 @noindent
7546 By responding to the prompts appropriately in the subsequent interactive
7547 session, you can explore the type @code{struct ComplexStruct} in a
7548 manner similar to how the value @code{cs} was explored in the above
7549 example.
7550
7551 The @code{explore} command also has two sub-commands,
7552 @code{explore value} and @code{explore type}. The former sub-command is
7553 a way to explicitly specify that value exploration of the argument is
7554 being invoked, while the latter is a way to explicitly specify that type
7555 exploration of the argument is being invoked.
7556
7557 @table @code
7558 @item explore value @var{expr}
7559 @cindex explore value
7560 This sub-command of @code{explore} explores the value of the
7561 expression @var{expr} (if @var{expr} is an expression valid in the
7562 current context of the program being debugged).  The behavior of this
7563 command is identical to that of the behavior of the @code{explore}
7564 command being passed the argument @var{expr}.
7565
7566 @item explore type @var{arg}
7567 @cindex explore type
7568 This sub-command of @code{explore} explores the type of @var{arg} (if
7569 @var{arg} is a type visible in the current context of program being
7570 debugged), or the type of the value/expression @var{arg} (if @var{arg}
7571 is an expression valid in the current context of the program being
7572 debugged).  If @var{arg} is a type, then the behavior of this command is
7573 identical to that of the @code{explore} command being passed the
7574 argument @var{arg}.  If @var{arg} is an expression, then the behavior of
7575 this command will be identical to that of the @code{explore} command
7576 being passed the type of @var{arg} as the argument.
7577 @end table
7578
7579 @menu
7580 * Expressions::                 Expressions
7581 * Ambiguous Expressions::       Ambiguous Expressions
7582 * Variables::                   Program variables
7583 * Arrays::                      Artificial arrays
7584 * Output Formats::              Output formats
7585 * Memory::                      Examining memory
7586 * Auto Display::                Automatic display
7587 * Print Settings::              Print settings
7588 * Pretty Printing::             Python pretty printing
7589 * Value History::               Value history
7590 * Convenience Vars::            Convenience variables
7591 * Convenience Funs::            Convenience functions
7592 * Registers::                   Registers
7593 * Floating Point Hardware::     Floating point hardware
7594 * Vector Unit::                 Vector Unit
7595 * OS Information::              Auxiliary data provided by operating system
7596 * Memory Region Attributes::    Memory region attributes
7597 * Dump/Restore Files::          Copy between memory and a file
7598 * Core File Generation::        Cause a program dump its core
7599 * Character Sets::              Debugging programs that use a different
7600                                 character set than GDB does
7601 * Caching Remote Data::         Data caching for remote targets
7602 * Searching Memory::            Searching memory for a sequence of bytes
7603 @end menu
7604
7605 @node Expressions
7606 @section Expressions
7607
7608 @cindex expressions
7609 @code{print} and many other @value{GDBN} commands accept an expression and
7610 compute its value.  Any kind of constant, variable or operator defined
7611 by the programming language you are using is valid in an expression in
7612 @value{GDBN}.  This includes conditional expressions, function calls,
7613 casts, and string constants.  It also includes preprocessor macros, if
7614 you compiled your program to include this information; see
7615 @ref{Compilation}.
7616
7617 @cindex arrays in expressions
7618 @value{GDBN} supports array constants in expressions input by
7619 the user.  The syntax is @{@var{element}, @var{element}@dots{}@}.  For example,
7620 you can use the command @code{print @{1, 2, 3@}} to create an array
7621 of three integers.  If you pass an array to a function or assign it
7622 to a program variable, @value{GDBN} copies the array to memory that
7623 is @code{malloc}ed in the target program.
7624
7625 Because C is so widespread, most of the expressions shown in examples in
7626 this manual are in C.  @xref{Languages, , Using @value{GDBN} with Different
7627 Languages}, for information on how to use expressions in other
7628 languages.
7629
7630 In this section, we discuss operators that you can use in @value{GDBN}
7631 expressions regardless of your programming language.
7632
7633 @cindex casts, in expressions
7634 Casts are supported in all languages, not just in C, because it is so
7635 useful to cast a number into a pointer in order to examine a structure
7636 at that address in memory.
7637 @c FIXME: casts supported---Mod2 true?
7638
7639 @value{GDBN} supports these operators, in addition to those common
7640 to programming languages:
7641
7642 @table @code
7643 @item @@
7644 @samp{@@} is a binary operator for treating parts of memory as arrays.
7645 @xref{Arrays, ,Artificial Arrays}, for more information.
7646
7647 @item ::
7648 @samp{::} allows you to specify a variable in terms of the file or
7649 function where it is defined.  @xref{Variables, ,Program Variables}.
7650
7651 @cindex @{@var{type}@}
7652 @cindex type casting memory
7653 @cindex memory, viewing as typed object
7654 @cindex casts, to view memory
7655 @item @{@var{type}@} @var{addr}
7656 Refers to an object of type @var{type} stored at address @var{addr} in
7657 memory.  @var{addr} may be any expression whose value is an integer or
7658 pointer (but parentheses are required around binary operators, just as in
7659 a cast).  This construct is allowed regardless of what kind of data is
7660 normally supposed to reside at @var{addr}.
7661 @end table
7662
7663 @node Ambiguous Expressions
7664 @section Ambiguous Expressions
7665 @cindex ambiguous expressions
7666
7667 Expressions can sometimes contain some ambiguous elements.  For instance,
7668 some programming languages (notably Ada, C@t{++} and Objective-C) permit
7669 a single function name to be defined several times, for application in
7670 different contexts.  This is called @dfn{overloading}.  Another example
7671 involving Ada is generics.  A @dfn{generic package} is similar to C@t{++}
7672 templates and is typically instantiated several times, resulting in
7673 the same function name being defined in different contexts.
7674
7675 In some cases and depending on the language, it is possible to adjust
7676 the expression to remove the ambiguity.  For instance in C@t{++}, you
7677 can specify the signature of the function you want to break on, as in
7678 @kbd{break @var{function}(@var{types})}.  In Ada, using the fully
7679 qualified name of your function often makes the expression unambiguous
7680 as well.
7681
7682 When an ambiguity that needs to be resolved is detected, the debugger
7683 has the capability to display a menu of numbered choices for each
7684 possibility, and then waits for the selection with the prompt @samp{>}.
7685 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
7686 aborts the current command.  If the command in which the expression was
7687 used allows more than one choice to be selected, the next option in the
7688 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
7689 choices.
7690
7691 For example, the following session excerpt shows an attempt to set a
7692 breakpoint at the overloaded symbol @code{String::after}.
7693 We choose three particular definitions of that function name:
7694
7695 @c FIXME! This is likely to change to show arg type lists, at least
7696 @smallexample
7697 @group
7698 (@value{GDBP}) b String::after
7699 [0] cancel
7700 [1] all
7701 [2] file:String.cc; line number:867
7702 [3] file:String.cc; line number:860
7703 [4] file:String.cc; line number:875
7704 [5] file:String.cc; line number:853
7705 [6] file:String.cc; line number:846
7706 [7] file:String.cc; line number:735
7707 > 2 4 6
7708 Breakpoint 1 at 0xb26c: file String.cc, line 867.
7709 Breakpoint 2 at 0xb344: file String.cc, line 875.
7710 Breakpoint 3 at 0xafcc: file String.cc, line 846.
7711 Multiple breakpoints were set.
7712 Use the "delete" command to delete unwanted
7713  breakpoints.
7714 (@value{GDBP})
7715 @end group
7716 @end smallexample
7717
7718 @table @code
7719 @kindex set multiple-symbols
7720 @item set multiple-symbols @var{mode}
7721 @cindex multiple-symbols menu
7722
7723 This option allows you to adjust the debugger behavior when an expression
7724 is ambiguous.
7725
7726 By default, @var{mode} is set to @code{all}.  If the command with which
7727 the expression is used allows more than one choice, then @value{GDBN}
7728 automatically selects all possible choices.  For instance, inserting
7729 a breakpoint on a function using an ambiguous name results in a breakpoint
7730 inserted on each possible match.  However, if a unique choice must be made,
7731 then @value{GDBN} uses the menu to help you disambiguate the expression.
7732 For instance, printing the address of an overloaded function will result
7733 in the use of the menu.
7734
7735 When @var{mode} is set to @code{ask}, the debugger always uses the menu
7736 when an ambiguity is detected.
7737
7738 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7739 an error due to the ambiguity and the command is aborted.
7740
7741 @kindex show multiple-symbols
7742 @item show multiple-symbols
7743 Show the current value of the @code{multiple-symbols} setting.
7744 @end table
7745
7746 @node Variables
7747 @section Program Variables
7748
7749 The most common kind of expression to use is the name of a variable
7750 in your program.
7751
7752 Variables in expressions are understood in the selected stack frame
7753 (@pxref{Selection, ,Selecting a Frame}); they must be either:
7754
7755 @itemize @bullet
7756 @item
7757 global (or file-static)
7758 @end itemize
7759
7760 @noindent or
7761
7762 @itemize @bullet
7763 @item
7764 visible according to the scope rules of the
7765 programming language from the point of execution in that frame
7766 @end itemize
7767
7768 @noindent This means that in the function
7769
7770 @smallexample
7771 foo (a)
7772      int a;
7773 @{
7774   bar (a);
7775   @{
7776     int b = test ();
7777     bar (b);
7778   @}
7779 @}
7780 @end smallexample
7781
7782 @noindent
7783 you can examine and use the variable @code{a} whenever your program is
7784 executing within the function @code{foo}, but you can only use or
7785 examine the variable @code{b} while your program is executing inside
7786 the block where @code{b} is declared.
7787
7788 @cindex variable name conflict
7789 There is an exception: you can refer to a variable or function whose
7790 scope is a single source file even if the current execution point is not
7791 in this file.  But it is possible to have more than one such variable or
7792 function with the same name (in different source files).  If that
7793 happens, referring to that name has unpredictable effects.  If you wish,
7794 you can specify a static variable in a particular function or file by
7795 using the colon-colon (@code{::}) notation:
7796
7797 @cindex colon-colon, context for variables/functions
7798 @ifnotinfo
7799 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
7800 @cindex @code{::}, context for variables/functions
7801 @end ifnotinfo
7802 @smallexample
7803 @var{file}::@var{variable}
7804 @var{function}::@var{variable}
7805 @end smallexample
7806
7807 @noindent
7808 Here @var{file} or @var{function} is the name of the context for the
7809 static @var{variable}.  In the case of file names, you can use quotes to
7810 make sure @value{GDBN} parses the file name as a single word---for example,
7811 to print a global value of @code{x} defined in @file{f2.c}:
7812
7813 @smallexample
7814 (@value{GDBP}) p 'f2.c'::x
7815 @end smallexample
7816
7817 The @code{::} notation is normally used for referring to
7818 static variables, since you typically disambiguate uses of local variables
7819 in functions by selecting the appropriate frame and using the
7820 simple name of the variable.  However, you may also use this notation
7821 to refer to local variables in frames enclosing the selected frame:
7822
7823 @smallexample
7824 void
7825 foo (int a)
7826 @{
7827   if (a < 10)
7828     bar (a);
7829   else
7830     process (a);    /* Stop here */
7831 @}
7832
7833 int
7834 bar (int a)
7835 @{
7836   foo (a + 5);
7837 @}
7838 @end smallexample
7839
7840 @noindent
7841 For example, if there is a breakpoint at the commented line,
7842 here is what you might see
7843 when the program stops after executing the call @code{bar(0)}:
7844
7845 @smallexample
7846 (@value{GDBP}) p a
7847 $1 = 10
7848 (@value{GDBP}) p bar::a
7849 $2 = 5
7850 (@value{GDBP}) up 2
7851 #2  0x080483d0 in foo (a=5) at foobar.c:12
7852 (@value{GDBP}) p a
7853 $3 = 5
7854 (@value{GDBP}) p bar::a
7855 $4 = 0
7856 @end smallexample
7857
7858 @cindex C@t{++} scope resolution
7859 These uses of @samp{::} are very rarely in conflict with the very similar
7860 use of the same notation in C@t{++}.  @value{GDBN} also supports use of the C@t{++}
7861 scope resolution operator in @value{GDBN} expressions.
7862 @c FIXME: Um, so what happens in one of those rare cases where it's in
7863 @c conflict??  --mew
7864
7865 @cindex wrong values
7866 @cindex variable values, wrong
7867 @cindex function entry/exit, wrong values of variables
7868 @cindex optimized code, wrong values of variables
7869 @quotation
7870 @emph{Warning:} Occasionally, a local variable may appear to have the
7871 wrong value at certain points in a function---just after entry to a new
7872 scope, and just before exit.
7873 @end quotation
7874 You may see this problem when you are stepping by machine instructions.
7875 This is because, on most machines, it takes more than one instruction to
7876 set up a stack frame (including local variable definitions); if you are
7877 stepping by machine instructions, variables may appear to have the wrong
7878 values until the stack frame is completely built.  On exit, it usually
7879 also takes more than one machine instruction to destroy a stack frame;
7880 after you begin stepping through that group of instructions, local
7881 variable definitions may be gone.
7882
7883 This may also happen when the compiler does significant optimizations.
7884 To be sure of always seeing accurate values, turn off all optimization
7885 when compiling.
7886
7887 @cindex ``No symbol "foo" in current context''
7888 Another possible effect of compiler optimizations is to optimize
7889 unused variables out of existence, or assign variables to registers (as
7890 opposed to memory addresses).  Depending on the support for such cases
7891 offered by the debug info format used by the compiler, @value{GDBN}
7892 might not be able to display values for such local variables.  If that
7893 happens, @value{GDBN} will print a message like this:
7894
7895 @smallexample
7896 No symbol "foo" in current context.
7897 @end smallexample
7898
7899 To solve such problems, either recompile without optimizations, or use a
7900 different debug info format, if the compiler supports several such
7901 formats.  @xref{Compilation}, for more information on choosing compiler
7902 options.  @xref{C, ,C and C@t{++}}, for more information about debug
7903 info formats that are best suited to C@t{++} programs.
7904
7905 If you ask to print an object whose contents are unknown to
7906 @value{GDBN}, e.g., because its data type is not completely specified
7907 by the debug information, @value{GDBN} will say @samp{<incomplete
7908 type>}.  @xref{Symbols, incomplete type}, for more about this.
7909
7910 If you append @kbd{@@entry} string to a function parameter name you get its
7911 value at the time the function got called.  If the value is not available an
7912 error message is printed.  Entry values are available only with some compilers.
7913 Entry values are normally also printed at the function parameter list according
7914 to @ref{set print entry-values}.
7915
7916 @smallexample
7917 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
7918 29        i++;
7919 (gdb) next
7920 30        e (i);
7921 (gdb) print i
7922 $1 = 31
7923 (gdb) print i@@entry
7924 $2 = 30
7925 @end smallexample
7926
7927 Strings are identified as arrays of @code{char} values without specified
7928 signedness.  Arrays of either @code{signed char} or @code{unsigned char} get
7929 printed as arrays of 1 byte sized integers.  @code{-fsigned-char} or
7930 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
7931 defines literal string type @code{"char"} as @code{char} without a sign.
7932 For program code
7933
7934 @smallexample
7935 char var0[] = "A";
7936 signed char var1[] = "A";
7937 @end smallexample
7938
7939 You get during debugging
7940 @smallexample
7941 (gdb) print var0
7942 $1 = "A"
7943 (gdb) print var1
7944 $2 = @{65 'A', 0 '\0'@}
7945 @end smallexample
7946
7947 @node Arrays
7948 @section Artificial Arrays
7949
7950 @cindex artificial array
7951 @cindex arrays
7952 @kindex @@@r{, referencing memory as an array}
7953 It is often useful to print out several successive objects of the
7954 same type in memory; a section of an array, or an array of
7955 dynamically determined size for which only a pointer exists in the
7956 program.
7957
7958 You can do this by referring to a contiguous span of memory as an
7959 @dfn{artificial array}, using the binary operator @samp{@@}.  The left
7960 operand of @samp{@@} should be the first element of the desired array
7961 and be an individual object.  The right operand should be the desired length
7962 of the array.  The result is an array value whose elements are all of
7963 the type of the left argument.  The first element is actually the left
7964 argument; the second element comes from bytes of memory immediately
7965 following those that hold the first element, and so on.  Here is an
7966 example.  If a program says
7967
7968 @smallexample
7969 int *array = (int *) malloc (len * sizeof (int));
7970 @end smallexample
7971
7972 @noindent
7973 you can print the contents of @code{array} with
7974
7975 @smallexample
7976 p *array@@len
7977 @end smallexample
7978
7979 The left operand of @samp{@@} must reside in memory.  Array values made
7980 with @samp{@@} in this way behave just like other arrays in terms of
7981 subscripting, and are coerced to pointers when used in expressions.
7982 Artificial arrays most often appear in expressions via the value history
7983 (@pxref{Value History, ,Value History}), after printing one out.
7984
7985 Another way to create an artificial array is to use a cast.
7986 This re-interprets a value as if it were an array.
7987 The value need not be in memory:
7988 @smallexample
7989 (@value{GDBP}) p/x (short[2])0x12345678
7990 $1 = @{0x1234, 0x5678@}
7991 @end smallexample
7992
7993 As a convenience, if you leave the array length out (as in
7994 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
7995 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
7996 @smallexample
7997 (@value{GDBP}) p/x (short[])0x12345678
7998 $2 = @{0x1234, 0x5678@}
7999 @end smallexample
8000
8001 Sometimes the artificial array mechanism is not quite enough; in
8002 moderately complex data structures, the elements of interest may not
8003 actually be adjacent---for example, if you are interested in the values
8004 of pointers in an array.  One useful work-around in this situation is
8005 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
8006 Variables}) as a counter in an expression that prints the first
8007 interesting value, and then repeat that expression via @key{RET}.  For
8008 instance, suppose you have an array @code{dtab} of pointers to
8009 structures, and you are interested in the values of a field @code{fv}
8010 in each structure.  Here is an example of what you might type:
8011
8012 @smallexample
8013 set $i = 0
8014 p dtab[$i++]->fv
8015 @key{RET}
8016 @key{RET}
8017 @dots{}
8018 @end smallexample
8019
8020 @node Output Formats
8021 @section Output Formats
8022
8023 @cindex formatted output
8024 @cindex output formats
8025 By default, @value{GDBN} prints a value according to its data type.  Sometimes
8026 this is not what you want.  For example, you might want to print a number
8027 in hex, or a pointer in decimal.  Or you might want to view data in memory
8028 at a certain address as a character string or as an instruction.  To do
8029 these things, specify an @dfn{output format} when you print a value.
8030
8031 The simplest use of output formats is to say how to print a value
8032 already computed.  This is done by starting the arguments of the
8033 @code{print} command with a slash and a format letter.  The format
8034 letters supported are:
8035
8036 @table @code
8037 @item x
8038 Regard the bits of the value as an integer, and print the integer in
8039 hexadecimal.
8040
8041 @item d
8042 Print as integer in signed decimal.
8043
8044 @item u
8045 Print as integer in unsigned decimal.
8046
8047 @item o
8048 Print as integer in octal.
8049
8050 @item t
8051 Print as integer in binary.  The letter @samp{t} stands for ``two''.
8052 @footnote{@samp{b} cannot be used because these format letters are also
8053 used with the @code{x} command, where @samp{b} stands for ``byte'';
8054 see @ref{Memory,,Examining Memory}.}
8055
8056 @item a
8057 @cindex unknown address, locating
8058 @cindex locate address
8059 Print as an address, both absolute in hexadecimal and as an offset from
8060 the nearest preceding symbol.  You can use this format used to discover
8061 where (in what function) an unknown address is located:
8062
8063 @smallexample
8064 (@value{GDBP}) p/a 0x54320
8065 $3 = 0x54320 <_initialize_vx+396>
8066 @end smallexample
8067
8068 @noindent
8069 The command @code{info symbol 0x54320} yields similar results.
8070 @xref{Symbols, info symbol}.
8071
8072 @item c
8073 Regard as an integer and print it as a character constant.  This
8074 prints both the numerical value and its character representation.  The
8075 character representation is replaced with the octal escape @samp{\nnn}
8076 for characters outside the 7-bit @sc{ascii} range.
8077
8078 Without this format, @value{GDBN} displays @code{char},
8079 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
8080 constants.  Single-byte members of vectors are displayed as integer
8081 data.
8082
8083 @item f
8084 Regard the bits of the value as a floating point number and print
8085 using typical floating point syntax.
8086
8087 @item s
8088 @cindex printing strings
8089 @cindex printing byte arrays
8090 Regard as a string, if possible.  With this format, pointers to single-byte
8091 data are displayed as null-terminated strings and arrays of single-byte data
8092 are displayed as fixed-length strings.  Other values are displayed in their
8093 natural types.
8094
8095 Without this format, @value{GDBN} displays pointers to and arrays of
8096 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
8097 strings.  Single-byte members of a vector are displayed as an integer
8098 array.
8099
8100 @item r
8101 @cindex raw printing
8102 Print using the @samp{raw} formatting.  By default, @value{GDBN} will
8103 use a Python-based pretty-printer, if one is available (@pxref{Pretty
8104 Printing}).  This typically results in a higher-level display of the
8105 value's contents.  The @samp{r} format bypasses any Python
8106 pretty-printer which might exist.
8107 @end table
8108
8109 For example, to print the program counter in hex (@pxref{Registers}), type
8110
8111 @smallexample
8112 p/x $pc
8113 @end smallexample
8114
8115 @noindent
8116 Note that no space is required before the slash; this is because command
8117 names in @value{GDBN} cannot contain a slash.
8118
8119 To reprint the last value in the value history with a different format,
8120 you can use the @code{print} command with just a format and no
8121 expression.  For example, @samp{p/x} reprints the last value in hex.
8122
8123 @node Memory
8124 @section Examining Memory
8125
8126 You can use the command @code{x} (for ``examine'') to examine memory in
8127 any of several formats, independently of your program's data types.
8128
8129 @cindex examining memory
8130 @table @code
8131 @kindex x @r{(examine memory)}
8132 @item x/@var{nfu} @var{addr}
8133 @itemx x @var{addr}
8134 @itemx x
8135 Use the @code{x} command to examine memory.
8136 @end table
8137
8138 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
8139 much memory to display and how to format it; @var{addr} is an
8140 expression giving the address where you want to start displaying memory.
8141 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
8142 Several commands set convenient defaults for @var{addr}.
8143
8144 @table @r
8145 @item @var{n}, the repeat count
8146 The repeat count is a decimal integer; the default is 1.  It specifies
8147 how much memory (counting by units @var{u}) to display.
8148 @c This really is **decimal**; unaffected by 'set radix' as of GDB
8149 @c 4.1.2.
8150
8151 @item @var{f}, the display format
8152 The display format is one of the formats used by @code{print}
8153 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
8154 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
8155 The default is @samp{x} (hexadecimal) initially.  The default changes
8156 each time you use either @code{x} or @code{print}.
8157
8158 @item @var{u}, the unit size
8159 The unit size is any of
8160
8161 @table @code
8162 @item b
8163 Bytes.
8164 @item h
8165 Halfwords (two bytes).
8166 @item w
8167 Words (four bytes).  This is the initial default.
8168 @item g
8169 Giant words (eight bytes).
8170 @end table
8171
8172 Each time you specify a unit size with @code{x}, that size becomes the
8173 default unit the next time you use @code{x}.  For the @samp{i} format,
8174 the unit size is ignored and is normally not written.  For the @samp{s} format,
8175 the unit size defaults to @samp{b}, unless it is explicitly given.
8176 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
8177 32-bit strings.  The next use of @kbd{x /s} will again display 8-bit strings.
8178 Note that the results depend on the programming language of the
8179 current compilation unit.  If the language is C, the @samp{s}
8180 modifier will use the UTF-16 encoding while @samp{w} will use
8181 UTF-32.  The encoding is set by the programming language and cannot
8182 be altered.
8183
8184 @item @var{addr}, starting display address
8185 @var{addr} is the address where you want @value{GDBN} to begin displaying
8186 memory.  The expression need not have a pointer value (though it may);
8187 it is always interpreted as an integer address of a byte of memory.
8188 @xref{Expressions, ,Expressions}, for more information on expressions.  The default for
8189 @var{addr} is usually just after the last address examined---but several
8190 other commands also set the default address: @code{info breakpoints} (to
8191 the address of the last breakpoint listed), @code{info line} (to the
8192 starting address of a line), and @code{print} (if you use it to display
8193 a value from memory).
8194 @end table
8195
8196 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
8197 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
8198 starting at address @code{0x54320}.  @samp{x/4xw $sp} prints the four
8199 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
8200 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
8201
8202 Since the letters indicating unit sizes are all distinct from the
8203 letters specifying output formats, you do not have to remember whether
8204 unit size or format comes first; either order works.  The output
8205 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
8206 (However, the count @var{n} must come first; @samp{wx4} does not work.)
8207
8208 Even though the unit size @var{u} is ignored for the formats @samp{s}
8209 and @samp{i}, you might still want to use a count @var{n}; for example,
8210 @samp{3i} specifies that you want to see three machine instructions,
8211 including any operands.  For convenience, especially when used with
8212 the @code{display} command, the @samp{i} format also prints branch delay
8213 slot instructions, if any, beyond the count specified, which immediately
8214 follow the last instruction that is within the count.  The command
8215 @code{disassemble} gives an alternative way of inspecting machine
8216 instructions; see @ref{Machine Code,,Source and Machine Code}.
8217
8218 All the defaults for the arguments to @code{x} are designed to make it
8219 easy to continue scanning memory with minimal specifications each time
8220 you use @code{x}.  For example, after you have inspected three machine
8221 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
8222 with just @samp{x/7}.  If you use @key{RET} to repeat the @code{x} command,
8223 the repeat count @var{n} is used again; the other arguments default as
8224 for successive uses of @code{x}.
8225
8226 When examining machine instructions, the instruction at current program
8227 counter is shown with a @code{=>} marker. For example:
8228
8229 @smallexample
8230 (@value{GDBP}) x/5i $pc-6
8231    0x804837f <main+11>: mov    %esp,%ebp
8232    0x8048381 <main+13>: push   %ecx
8233    0x8048382 <main+14>: sub    $0x4,%esp
8234 => 0x8048385 <main+17>: movl   $0x8048460,(%esp)
8235    0x804838c <main+24>: call   0x80482d4 <puts@@plt>
8236 @end smallexample
8237
8238 @cindex @code{$_}, @code{$__}, and value history
8239 The addresses and contents printed by the @code{x} command are not saved
8240 in the value history because there is often too much of them and they
8241 would get in the way.  Instead, @value{GDBN} makes these values available for
8242 subsequent use in expressions as values of the convenience variables
8243 @code{$_} and @code{$__}.  After an @code{x} command, the last address
8244 examined is available for use in expressions in the convenience variable
8245 @code{$_}.  The contents of that address, as examined, are available in
8246 the convenience variable @code{$__}.
8247
8248 If the @code{x} command has a repeat count, the address and contents saved
8249 are from the last memory unit printed; this is not the same as the last
8250 address printed if several units were printed on the last line of output.
8251
8252 @cindex remote memory comparison
8253 @cindex verify remote memory image
8254 When you are debugging a program running on a remote target machine
8255 (@pxref{Remote Debugging}), you may wish to verify the program's image in the
8256 remote machine's memory against the executable file you downloaded to
8257 the target.  The @code{compare-sections} command is provided for such
8258 situations.
8259
8260 @table @code
8261 @kindex compare-sections
8262 @item compare-sections @r{[}@var{section-name}@r{]}
8263 Compare the data of a loadable section @var{section-name} in the
8264 executable file of the program being debugged with the same section in
8265 the remote machine's memory, and report any mismatches.  With no
8266 arguments, compares all loadable sections.  This command's
8267 availability depends on the target's support for the @code{"qCRC"}
8268 remote request.
8269 @end table
8270
8271 @node Auto Display
8272 @section Automatic Display
8273 @cindex automatic display
8274 @cindex display of expressions
8275
8276 If you find that you want to print the value of an expression frequently
8277 (to see how it changes), you might want to add it to the @dfn{automatic
8278 display list} so that @value{GDBN} prints its value each time your program stops.
8279 Each expression added to the list is given a number to identify it;
8280 to remove an expression from the list, you specify that number.
8281 The automatic display looks like this:
8282
8283 @smallexample
8284 2: foo = 38
8285 3: bar[5] = (struct hack *) 0x3804
8286 @end smallexample
8287
8288 @noindent
8289 This display shows item numbers, expressions and their current values.  As with
8290 displays you request manually using @code{x} or @code{print}, you can
8291 specify the output format you prefer; in fact, @code{display} decides
8292 whether to use @code{print} or @code{x} depending your format
8293 specification---it uses @code{x} if you specify either the @samp{i}
8294 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
8295
8296 @table @code
8297 @kindex display
8298 @item display @var{expr}
8299 Add the expression @var{expr} to the list of expressions to display
8300 each time your program stops.  @xref{Expressions, ,Expressions}.
8301
8302 @code{display} does not repeat if you press @key{RET} again after using it.
8303
8304 @item display/@var{fmt} @var{expr}
8305 For @var{fmt} specifying only a display format and not a size or
8306 count, add the expression @var{expr} to the auto-display list but
8307 arrange to display it each time in the specified format @var{fmt}.
8308 @xref{Output Formats,,Output Formats}.
8309
8310 @item display/@var{fmt} @var{addr}
8311 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
8312 number of units, add the expression @var{addr} as a memory address to
8313 be examined each time your program stops.  Examining means in effect
8314 doing @samp{x/@var{fmt} @var{addr}}.  @xref{Memory, ,Examining Memory}.
8315 @end table
8316
8317 For example, @samp{display/i $pc} can be helpful, to see the machine
8318 instruction about to be executed each time execution stops (@samp{$pc}
8319 is a common name for the program counter; @pxref{Registers, ,Registers}).
8320
8321 @table @code
8322 @kindex delete display
8323 @kindex undisplay
8324 @item undisplay @var{dnums}@dots{}
8325 @itemx delete display @var{dnums}@dots{}
8326 Remove items from the list of expressions to display.  Specify the
8327 numbers of the displays that you want affected with the command
8328 argument @var{dnums}.  It can be a single display number, one of the
8329 numbers shown in the first field of the @samp{info display} display;
8330 or it could be a range of display numbers, as in @code{2-4}.
8331
8332 @code{undisplay} does not repeat if you press @key{RET} after using it.
8333 (Otherwise you would just get the error @samp{No display number @dots{}}.)
8334
8335 @kindex disable display
8336 @item disable display @var{dnums}@dots{}
8337 Disable the display of item numbers @var{dnums}.  A disabled display
8338 item is not printed automatically, but is not forgotten.  It may be
8339 enabled again later.  Specify the numbers of the displays that you
8340 want affected with the command argument @var{dnums}.  It can be a
8341 single display number, one of the numbers shown in the first field of
8342 the @samp{info display} display; or it could be a range of display
8343 numbers, as in @code{2-4}.
8344
8345 @kindex enable display
8346 @item enable display @var{dnums}@dots{}
8347 Enable display of item numbers @var{dnums}.  It becomes effective once
8348 again in auto display of its expression, until you specify otherwise.
8349 Specify the numbers of the displays that you want affected with the
8350 command argument @var{dnums}.  It can be a single display number, one
8351 of the numbers shown in the first field of the @samp{info display}
8352 display; or it could be a range of display numbers, as in @code{2-4}.
8353
8354 @item display
8355 Display the current values of the expressions on the list, just as is
8356 done when your program stops.
8357
8358 @kindex info display
8359 @item info display
8360 Print the list of expressions previously set up to display
8361 automatically, each one with its item number, but without showing the
8362 values.  This includes disabled expressions, which are marked as such.
8363 It also includes expressions which would not be displayed right now
8364 because they refer to automatic variables not currently available.
8365 @end table
8366
8367 @cindex display disabled out of scope
8368 If a display expression refers to local variables, then it does not make
8369 sense outside the lexical context for which it was set up.  Such an
8370 expression is disabled when execution enters a context where one of its
8371 variables is not defined.  For example, if you give the command
8372 @code{display last_char} while inside a function with an argument
8373 @code{last_char}, @value{GDBN} displays this argument while your program
8374 continues to stop inside that function.  When it stops elsewhere---where
8375 there is no variable @code{last_char}---the display is disabled
8376 automatically.  The next time your program stops where @code{last_char}
8377 is meaningful, you can enable the display expression once again.
8378
8379 @node Print Settings
8380 @section Print Settings
8381
8382 @cindex format options
8383 @cindex print settings
8384 @value{GDBN} provides the following ways to control how arrays, structures,
8385 and symbols are printed.
8386
8387 @noindent
8388 These settings are useful for debugging programs in any language:
8389
8390 @table @code
8391 @kindex set print
8392 @item set print address
8393 @itemx set print address on
8394 @cindex print/don't print memory addresses
8395 @value{GDBN} prints memory addresses showing the location of stack
8396 traces, structure values, pointer values, breakpoints, and so forth,
8397 even when it also displays the contents of those addresses.  The default
8398 is @code{on}.  For example, this is what a stack frame display looks like with
8399 @code{set print address on}:
8400
8401 @smallexample
8402 @group
8403 (@value{GDBP}) f
8404 #0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8405     at input.c:530
8406 530         if (lquote != def_lquote)
8407 @end group
8408 @end smallexample
8409
8410 @item set print address off
8411 Do not print addresses when displaying their contents.  For example,
8412 this is the same stack frame displayed with @code{set print address off}:
8413
8414 @smallexample
8415 @group
8416 (@value{GDBP}) set print addr off
8417 (@value{GDBP}) f
8418 #0  set_quotes (lq="<<", rq=">>") at input.c:530
8419 530         if (lquote != def_lquote)
8420 @end group
8421 @end smallexample
8422
8423 You can use @samp{set print address off} to eliminate all machine
8424 dependent displays from the @value{GDBN} interface.  For example, with
8425 @code{print address off}, you should get the same text for backtraces on
8426 all machines---whether or not they involve pointer arguments.
8427
8428 @kindex show print
8429 @item show print address
8430 Show whether or not addresses are to be printed.
8431 @end table
8432
8433 When @value{GDBN} prints a symbolic address, it normally prints the
8434 closest earlier symbol plus an offset.  If that symbol does not uniquely
8435 identify the address (for example, it is a name whose scope is a single
8436 source file), you may need to clarify.  One way to do this is with
8437 @code{info line}, for example @samp{info line *0x4537}.  Alternately,
8438 you can set @value{GDBN} to print the source file and line number when
8439 it prints a symbolic address:
8440
8441 @table @code
8442 @item set print symbol-filename on
8443 @cindex source file and line of a symbol
8444 @cindex symbol, source file and line
8445 Tell @value{GDBN} to print the source file name and line number of a
8446 symbol in the symbolic form of an address.
8447
8448 @item set print symbol-filename off
8449 Do not print source file name and line number of a symbol.  This is the
8450 default.
8451
8452 @item show print symbol-filename
8453 Show whether or not @value{GDBN} will print the source file name and
8454 line number of a symbol in the symbolic form of an address.
8455 @end table
8456
8457 Another situation where it is helpful to show symbol filenames and line
8458 numbers is when disassembling code; @value{GDBN} shows you the line
8459 number and source file that corresponds to each instruction.
8460
8461 Also, you may wish to see the symbolic form only if the address being
8462 printed is reasonably close to the closest earlier symbol:
8463
8464 @table @code
8465 @item set print max-symbolic-offset @var{max-offset}
8466 @cindex maximum value for offset of closest symbol
8467 Tell @value{GDBN} to only display the symbolic form of an address if the
8468 offset between the closest earlier symbol and the address is less than
8469 @var{max-offset}.  The default is 0, which tells @value{GDBN}
8470 to always print the symbolic form of an address if any symbol precedes it.
8471
8472 @item show print max-symbolic-offset
8473 Ask how large the maximum offset is that @value{GDBN} prints in a
8474 symbolic address.
8475 @end table
8476
8477 @cindex wild pointer, interpreting
8478 @cindex pointer, finding referent
8479 If you have a pointer and you are not sure where it points, try
8480 @samp{set print symbol-filename on}.  Then you can determine the name
8481 and source file location of the variable where it points, using
8482 @samp{p/a @var{pointer}}.  This interprets the address in symbolic form.
8483 For example, here @value{GDBN} shows that a variable @code{ptt} points
8484 at another variable @code{t}, defined in @file{hi2.c}:
8485
8486 @smallexample
8487 (@value{GDBP}) set print symbol-filename on
8488 (@value{GDBP}) p/a ptt
8489 $4 = 0xe008 <t in hi2.c>
8490 @end smallexample
8491
8492 @quotation
8493 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
8494 does not show the symbol name and filename of the referent, even with
8495 the appropriate @code{set print} options turned on.
8496 @end quotation
8497
8498 You can also enable @samp{/a}-like formatting all the time using
8499 @samp{set print symbol on}:
8500
8501 @table @code
8502 @item set print symbol on
8503 Tell @value{GDBN} to print the symbol corresponding to an address, if
8504 one exists.
8505
8506 @item set print symbol off
8507 Tell @value{GDBN} not to print the symbol corresponding to an
8508 address.  In this mode, @value{GDBN} will still print the symbol
8509 corresponding to pointers to functions.  This is the default.
8510
8511 @item show print symbol
8512 Show whether @value{GDBN} will display the symbol corresponding to an
8513 address.
8514 @end table
8515
8516 Other settings control how different kinds of objects are printed:
8517
8518 @table @code
8519 @item set print array
8520 @itemx set print array on
8521 @cindex pretty print arrays
8522 Pretty print arrays.  This format is more convenient to read,
8523 but uses more space.  The default is off.
8524
8525 @item set print array off
8526 Return to compressed format for arrays.
8527
8528 @item show print array
8529 Show whether compressed or pretty format is selected for displaying
8530 arrays.
8531
8532 @cindex print array indexes
8533 @item set print array-indexes
8534 @itemx set print array-indexes on
8535 Print the index of each element when displaying arrays.  May be more
8536 convenient to locate a given element in the array or quickly find the
8537 index of a given element in that printed array.  The default is off.
8538
8539 @item set print array-indexes off
8540 Stop printing element indexes when displaying arrays.
8541
8542 @item show print array-indexes
8543 Show whether the index of each element is printed when displaying
8544 arrays.
8545
8546 @item set print elements @var{number-of-elements}
8547 @cindex number of array elements to print
8548 @cindex limit on number of printed array elements
8549 Set a limit on how many elements of an array @value{GDBN} will print.
8550 If @value{GDBN} is printing a large array, it stops printing after it has
8551 printed the number of elements set by the @code{set print elements} command.
8552 This limit also applies to the display of strings.
8553 When @value{GDBN} starts, this limit is set to 200.
8554 Setting  @var{number-of-elements} to zero means that the printing is unlimited.
8555
8556 @item show print elements
8557 Display the number of elements of a large array that @value{GDBN} will print.
8558 If the number is 0, then the printing is unlimited.
8559
8560 @item set print frame-arguments @var{value}
8561 @kindex set print frame-arguments
8562 @cindex printing frame argument values
8563 @cindex print all frame argument values
8564 @cindex print frame argument values for scalars only
8565 @cindex do not print frame argument values
8566 This command allows to control how the values of arguments are printed
8567 when the debugger prints a frame (@pxref{Frames}).  The possible
8568 values are:
8569
8570 @table @code
8571 @item all
8572 The values of all arguments are printed.
8573
8574 @item scalars
8575 Print the value of an argument only if it is a scalar.  The value of more
8576 complex arguments such as arrays, structures, unions, etc, is replaced
8577 by @code{@dots{}}.  This is the default.  Here is an example where
8578 only scalar arguments are shown:
8579
8580 @smallexample
8581 #1  0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
8582   at frame-args.c:23
8583 @end smallexample
8584
8585 @item none
8586 None of the argument values are printed.  Instead, the value of each argument
8587 is replaced by @code{@dots{}}.  In this case, the example above now becomes:
8588
8589 @smallexample
8590 #1  0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
8591   at frame-args.c:23
8592 @end smallexample
8593 @end table
8594
8595 By default, only scalar arguments are printed.  This command can be used
8596 to configure the debugger to print the value of all arguments, regardless
8597 of their type.  However, it is often advantageous to not print the value
8598 of more complex parameters.  For instance, it reduces the amount of
8599 information printed in each frame, making the backtrace more readable.
8600 Also, it improves performance when displaying Ada frames, because
8601 the computation of large arguments can sometimes be CPU-intensive,
8602 especially in large applications.  Setting @code{print frame-arguments}
8603 to @code{scalars} (the default) or @code{none} avoids this computation,
8604 thus speeding up the display of each Ada frame.
8605
8606 @item show print frame-arguments
8607 Show how the value of arguments should be displayed when printing a frame.
8608
8609 @anchor{set print entry-values}
8610 @item set print entry-values @var{value}
8611 @kindex set print entry-values
8612 Set printing of frame argument values at function entry.  In some cases
8613 @value{GDBN} can determine the value of function argument which was passed by
8614 the function caller, even if the value was modified inside the called function
8615 and therefore is different.  With optimized code, the current value could be
8616 unavailable, but the entry value may still be known.
8617
8618 The default value is @code{default} (see below for its description).  Older
8619 @value{GDBN} behaved as with the setting @code{no}.  Compilers not supporting
8620 this feature will behave in the @code{default} setting the same way as with the
8621 @code{no} setting.
8622
8623 This functionality is currently supported only by DWARF 2 debugging format and
8624 the compiler has to produce @samp{DW_TAG_GNU_call_site} tags.  With
8625 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
8626 this information.
8627
8628 The @var{value} parameter can be one of the following:
8629
8630 @table @code
8631 @item no
8632 Print only actual parameter values, never print values from function entry
8633 point.
8634 @smallexample
8635 #0  equal (val=5)
8636 #0  different (val=6)
8637 #0  lost (val=<optimized out>)
8638 #0  born (val=10)
8639 #0  invalid (val=<optimized out>)
8640 @end smallexample
8641
8642 @item only
8643 Print only parameter values from function entry point.  The actual parameter
8644 values are never printed.
8645 @smallexample
8646 #0  equal (val@@entry=5)
8647 #0  different (val@@entry=5)
8648 #0  lost (val@@entry=5)
8649 #0  born (val@@entry=<optimized out>)
8650 #0  invalid (val@@entry=<optimized out>)
8651 @end smallexample
8652
8653 @item preferred
8654 Print only parameter values from function entry point.  If value from function
8655 entry point is not known while the actual value is known, print the actual
8656 value for such parameter.
8657 @smallexample
8658 #0  equal (val@@entry=5)
8659 #0  different (val@@entry=5)
8660 #0  lost (val@@entry=5)
8661 #0  born (val=10)
8662 #0  invalid (val@@entry=<optimized out>)
8663 @end smallexample
8664
8665 @item if-needed
8666 Print actual parameter values.  If actual parameter value is not known while
8667 value from function entry point is known, print the entry point value for such
8668 parameter.
8669 @smallexample
8670 #0  equal (val=5)
8671 #0  different (val=6)
8672 #0  lost (val@@entry=5)
8673 #0  born (val=10)
8674 #0  invalid (val=<optimized out>)
8675 @end smallexample
8676
8677 @item both
8678 Always print both the actual parameter value and its value from function entry
8679 point, even if values of one or both are not available due to compiler
8680 optimizations.
8681 @smallexample
8682 #0  equal (val=5, val@@entry=5)
8683 #0  different (val=6, val@@entry=5)
8684 #0  lost (val=<optimized out>, val@@entry=5)
8685 #0  born (val=10, val@@entry=<optimized out>)
8686 #0  invalid (val=<optimized out>, val@@entry=<optimized out>)
8687 @end smallexample
8688
8689 @item compact
8690 Print the actual parameter value if it is known and also its value from
8691 function entry point if it is known.  If neither is known, print for the actual
8692 value @code{<optimized out>}.  If not in MI mode (@pxref{GDB/MI}) and if both
8693 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@@entry=5)
8699 #0  born (val=10)
8700 #0  invalid (val=<optimized out>)
8701 @end smallexample
8702
8703 @item default
8704 Always print the actual parameter value.  Print also its value from function
8705 entry point, but only if it is known.  If not in MI mode (@pxref{GDB/MI}) and
8706 if both values are known and identical, print the shortened
8707 @code{param=param@@entry=VALUE} notation.
8708 @smallexample
8709 #0  equal (val=val@@entry=5)
8710 #0  different (val=6, val@@entry=5)
8711 #0  lost (val=<optimized out>, val@@entry=5)
8712 #0  born (val=10)
8713 #0  invalid (val=<optimized out>)
8714 @end smallexample
8715 @end table
8716
8717 For analysis messages on possible failures of frame argument values at function
8718 entry resolution see @ref{set debug entry-values}.
8719
8720 @item show print entry-values
8721 Show the method being used for printing of frame argument values at function
8722 entry.
8723
8724 @item set print repeats
8725 @cindex repeated array elements
8726 Set the threshold for suppressing display of repeated array
8727 elements.  When the number of consecutive identical elements of an
8728 array exceeds the threshold, @value{GDBN} prints the string
8729 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
8730 identical repetitions, instead of displaying the identical elements
8731 themselves.  Setting the threshold to zero will cause all elements to
8732 be individually printed.  The default threshold is 10.
8733
8734 @item show print repeats
8735 Display the current threshold for printing repeated identical
8736 elements.
8737
8738 @item set print null-stop
8739 @cindex @sc{null} elements in arrays
8740 Cause @value{GDBN} to stop printing the characters of an array when the first
8741 @sc{null} is encountered.  This is useful when large arrays actually
8742 contain only short strings.
8743 The default is off.
8744
8745 @item show print null-stop
8746 Show whether @value{GDBN} stops printing an array on the first
8747 @sc{null} character.
8748
8749 @item set print pretty on
8750 @cindex print structures in indented form
8751 @cindex indentation in structure display
8752 Cause @value{GDBN} to print structures in an indented format with one member
8753 per line, like this:
8754
8755 @smallexample
8756 @group
8757 $1 = @{
8758   next = 0x0,
8759   flags = @{
8760     sweet = 1,
8761     sour = 1
8762   @},
8763   meat = 0x54 "Pork"
8764 @}
8765 @end group
8766 @end smallexample
8767
8768 @item set print pretty off
8769 Cause @value{GDBN} to print structures in a compact format, like this:
8770
8771 @smallexample
8772 @group
8773 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
8774 meat = 0x54 "Pork"@}
8775 @end group
8776 @end smallexample
8777
8778 @noindent
8779 This is the default format.
8780
8781 @item show print pretty
8782 Show which format @value{GDBN} is using to print structures.
8783
8784 @item set print sevenbit-strings on
8785 @cindex eight-bit characters in strings
8786 @cindex octal escapes in strings
8787 Print using only seven-bit characters; if this option is set,
8788 @value{GDBN} displays any eight-bit characters (in strings or
8789 character values) using the notation @code{\}@var{nnn}.  This setting is
8790 best if you are working in English (@sc{ascii}) and you use the
8791 high-order bit of characters as a marker or ``meta'' bit.
8792
8793 @item set print sevenbit-strings off
8794 Print full eight-bit characters.  This allows the use of more
8795 international character sets, and is the default.
8796
8797 @item show print sevenbit-strings
8798 Show whether or not @value{GDBN} is printing only seven-bit characters.
8799
8800 @item set print union on
8801 @cindex unions in structures, printing
8802 Tell @value{GDBN} to print unions which are contained in structures
8803 and other unions.  This is the default setting.
8804
8805 @item set print union off
8806 Tell @value{GDBN} not to print unions which are contained in
8807 structures and other unions.  @value{GDBN} will print @code{"@{...@}"}
8808 instead.
8809
8810 @item show print union
8811 Ask @value{GDBN} whether or not it will print unions which are contained in
8812 structures and other unions.
8813
8814 For example, given the declarations
8815
8816 @smallexample
8817 typedef enum @{Tree, Bug@} Species;
8818 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
8819 typedef enum @{Caterpillar, Cocoon, Butterfly@}
8820               Bug_forms;
8821
8822 struct thing @{
8823   Species it;
8824   union @{
8825     Tree_forms tree;
8826     Bug_forms bug;
8827   @} form;
8828 @};
8829
8830 struct thing foo = @{Tree, @{Acorn@}@};
8831 @end smallexample
8832
8833 @noindent
8834 with @code{set print union on} in effect @samp{p foo} would print
8835
8836 @smallexample
8837 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
8838 @end smallexample
8839
8840 @noindent
8841 and with @code{set print union off} in effect it would print
8842
8843 @smallexample
8844 $1 = @{it = Tree, form = @{...@}@}
8845 @end smallexample
8846
8847 @noindent
8848 @code{set print union} affects programs written in C-like languages
8849 and in Pascal.
8850 @end table
8851
8852 @need 1000
8853 @noindent
8854 These settings are of interest when debugging C@t{++} programs:
8855
8856 @table @code
8857 @cindex demangling C@t{++} names
8858 @item set print demangle
8859 @itemx set print demangle on
8860 Print C@t{++} names in their source form rather than in the encoded
8861 (``mangled'') form passed to the assembler and linker for type-safe
8862 linkage.  The default is on.
8863
8864 @item show print demangle
8865 Show whether C@t{++} names are printed in mangled or demangled form.
8866
8867 @item set print asm-demangle
8868 @itemx set print asm-demangle on
8869 Print C@t{++} names in their source form rather than their mangled form, even
8870 in assembler code printouts such as instruction disassemblies.
8871 The default is off.
8872
8873 @item show print asm-demangle
8874 Show whether C@t{++} names in assembly listings are printed in mangled
8875 or demangled form.
8876
8877 @cindex C@t{++} symbol decoding style
8878 @cindex symbol decoding style, C@t{++}
8879 @kindex set demangle-style
8880 @item set demangle-style @var{style}
8881 Choose among several encoding schemes used by different compilers to
8882 represent C@t{++} names.  The choices for @var{style} are currently:
8883
8884 @table @code
8885 @item auto
8886 Allow @value{GDBN} to choose a decoding style by inspecting your program.
8887 This is the default.
8888
8889 @item gnu
8890 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
8891
8892 @item hp
8893 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
8894
8895 @item lucid
8896 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
8897
8898 @item arm
8899 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
8900 @strong{Warning:} this setting alone is not sufficient to allow
8901 debugging @code{cfront}-generated executables.  @value{GDBN} would
8902 require further enhancement to permit that.
8903
8904 @end table
8905 If you omit @var{style}, you will see a list of possible formats.
8906
8907 @item show demangle-style
8908 Display the encoding style currently in use for decoding C@t{++} symbols.
8909
8910 @item set print object
8911 @itemx set print object on
8912 @cindex derived type of an object, printing
8913 @cindex display derived types
8914 When displaying a pointer to an object, identify the @emph{actual}
8915 (derived) type of the object rather than the @emph{declared} type, using
8916 the virtual function table.  Note that the virtual function table is
8917 required---this feature can only work for objects that have run-time
8918 type identification; a single virtual method in the object's declared
8919 type is sufficient.  Note that this setting is also taken into account when
8920 working with variable objects via MI (@pxref{GDB/MI}).
8921
8922 @item set print object off
8923 Display only the declared type of objects, without reference to the
8924 virtual function table.  This is the default setting.
8925
8926 @item show print object
8927 Show whether actual, or declared, object types are displayed.
8928
8929 @item set print static-members
8930 @itemx set print static-members on
8931 @cindex static members of C@t{++} objects
8932 Print static members when displaying a C@t{++} object.  The default is on.
8933
8934 @item set print static-members off
8935 Do not print static members when displaying a C@t{++} object.
8936
8937 @item show print static-members
8938 Show whether C@t{++} static members are printed or not.
8939
8940 @item set print pascal_static-members
8941 @itemx set print pascal_static-members on
8942 @cindex static members of Pascal objects
8943 @cindex Pascal objects, static members display
8944 Print static members when displaying a Pascal object.  The default is on.
8945
8946 @item set print pascal_static-members off
8947 Do not print static members when displaying a Pascal object.
8948
8949 @item show print pascal_static-members
8950 Show whether Pascal static members are printed or not.
8951
8952 @c These don't work with HP ANSI C++ yet.
8953 @item set print vtbl
8954 @itemx set print vtbl on
8955 @cindex pretty print C@t{++} virtual function tables
8956 @cindex virtual functions (C@t{++}) display
8957 @cindex VTBL display
8958 Pretty print C@t{++} virtual function tables.  The default is off.
8959 (The @code{vtbl} commands do not work on programs compiled with the HP
8960 ANSI C@t{++} compiler (@code{aCC}).)
8961
8962 @item set print vtbl off
8963 Do not pretty print C@t{++} virtual function tables.
8964
8965 @item show print vtbl
8966 Show whether C@t{++} virtual function tables are pretty printed, or not.
8967 @end table
8968
8969 @node Pretty Printing
8970 @section Pretty Printing
8971
8972 @value{GDBN} provides a mechanism to allow pretty-printing of values using
8973 Python code.  It greatly simplifies the display of complex objects.  This
8974 mechanism works for both MI and the CLI.
8975
8976 @menu
8977 * Pretty-Printer Introduction::  Introduction to pretty-printers
8978 * Pretty-Printer Example::       An example pretty-printer
8979 * Pretty-Printer Commands::      Pretty-printer commands
8980 @end menu
8981
8982 @node Pretty-Printer Introduction
8983 @subsection Pretty-Printer Introduction
8984
8985 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
8986 registered for the value.  If there is then @value{GDBN} invokes the
8987 pretty-printer to print the value.  Otherwise the value is printed normally.
8988
8989 Pretty-printers are normally named.  This makes them easy to manage.
8990 The @samp{info pretty-printer} command will list all the installed
8991 pretty-printers with their names.
8992 If a pretty-printer can handle multiple data types, then its
8993 @dfn{subprinters} are the printers for the individual data types.
8994 Each such subprinter has its own name.
8995 The format of the name is @var{printer-name};@var{subprinter-name}.
8996
8997 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
8998 Typically they are automatically loaded and registered when the corresponding
8999 debug information is loaded, thus making them available without having to
9000 do anything special.
9001
9002 There are three places where a pretty-printer can be registered.
9003
9004 @itemize @bullet
9005 @item
9006 Pretty-printers registered globally are available when debugging
9007 all inferiors.
9008
9009 @item
9010 Pretty-printers registered with a program space are available only
9011 when debugging that program.
9012 @xref{Progspaces In Python}, for more details on program spaces in Python.
9013
9014 @item
9015 Pretty-printers registered with an objfile are loaded and unloaded
9016 with the corresponding objfile (e.g., shared library).
9017 @xref{Objfiles In Python}, for more details on objfiles in Python.
9018 @end itemize
9019
9020 @xref{Selecting Pretty-Printers}, for further information on how 
9021 pretty-printers are selected,
9022
9023 @xref{Writing a Pretty-Printer}, for implementing pretty printers
9024 for new types.
9025
9026 @node Pretty-Printer Example
9027 @subsection Pretty-Printer Example
9028
9029 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
9030
9031 @smallexample
9032 (@value{GDBP}) print s
9033 $1 = @{
9034   static npos = 4294967295, 
9035   _M_dataplus = @{
9036     <std::allocator<char>> = @{
9037       <__gnu_cxx::new_allocator<char>> = @{
9038         <No data fields>@}, <No data fields>
9039       @},
9040     members of std::basic_string<char, std::char_traits<char>,
9041       std::allocator<char> >::_Alloc_hider:
9042     _M_p = 0x804a014 "abcd"
9043   @}
9044 @}
9045 @end smallexample
9046
9047 With a pretty-printer for @code{std::string} only the contents are printed:
9048
9049 @smallexample
9050 (@value{GDBP}) print s
9051 $2 = "abcd"
9052 @end smallexample
9053
9054 @node Pretty-Printer Commands
9055 @subsection Pretty-Printer Commands
9056 @cindex pretty-printer commands
9057
9058 @table @code
9059 @kindex info pretty-printer
9060 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9061 Print the list of installed pretty-printers.
9062 This includes disabled pretty-printers, which are marked as such.
9063
9064 @var{object-regexp} is a regular expression matching the objects
9065 whose pretty-printers to list.
9066 Objects can be @code{global}, the program space's file
9067 (@pxref{Progspaces In Python}),
9068 and the object files within that program space (@pxref{Objfiles In Python}).
9069 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
9070 looks up a printer from these three objects.
9071
9072 @var{name-regexp} is a regular expression matching the name of the printers
9073 to list.
9074
9075 @kindex disable pretty-printer
9076 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9077 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9078 A disabled pretty-printer is not forgotten, it may be enabled again later.
9079
9080 @kindex enable pretty-printer
9081 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9082 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9083 @end table
9084
9085 Example:
9086
9087 Suppose we have three pretty-printers installed: one from library1.so
9088 named @code{foo} that prints objects of type @code{foo}, and
9089 another from library2.so named @code{bar} that prints two types of objects,
9090 @code{bar1} and @code{bar2}.
9091
9092 @smallexample
9093 (gdb) info pretty-printer
9094 library1.so:
9095   foo
9096 library2.so:
9097   bar
9098     bar1
9099     bar2
9100 (gdb) info pretty-printer library2
9101 library2.so:
9102   bar
9103     bar1
9104     bar2
9105 (gdb) disable pretty-printer library1
9106 1 printer disabled
9107 2 of 3 printers enabled
9108 (gdb) info pretty-printer
9109 library1.so:
9110   foo [disabled]
9111 library2.so:
9112   bar
9113     bar1
9114     bar2
9115 (gdb) disable pretty-printer library2 bar:bar1
9116 1 printer disabled
9117 1 of 3 printers enabled
9118 (gdb) info pretty-printer library2
9119 library1.so:
9120   foo [disabled]
9121 library2.so:
9122   bar
9123     bar1 [disabled]
9124     bar2
9125 (gdb) disable pretty-printer library2 bar
9126 1 printer disabled
9127 0 of 3 printers enabled
9128 (gdb) info pretty-printer library2
9129 library1.so:
9130   foo [disabled]
9131 library2.so:
9132   bar [disabled]
9133     bar1 [disabled]
9134     bar2
9135 @end smallexample
9136
9137 Note that for @code{bar} the entire printer can be disabled,
9138 as can each individual subprinter.
9139
9140 @node Value History
9141 @section Value History
9142
9143 @cindex value history
9144 @cindex history of values printed by @value{GDBN}
9145 Values printed by the @code{print} command are saved in the @value{GDBN}
9146 @dfn{value history}.  This allows you to refer to them in other expressions.
9147 Values are kept until the symbol table is re-read or discarded
9148 (for example with the @code{file} or @code{symbol-file} commands).
9149 When the symbol table changes, the value history is discarded,
9150 since the values may contain pointers back to the types defined in the
9151 symbol table.
9152
9153 @cindex @code{$}
9154 @cindex @code{$$}
9155 @cindex history number
9156 The values printed are given @dfn{history numbers} by which you can
9157 refer to them.  These are successive integers starting with one.
9158 @code{print} shows you the history number assigned to a value by
9159 printing @samp{$@var{num} = } before the value; here @var{num} is the
9160 history number.
9161
9162 To refer to any previous value, use @samp{$} followed by the value's
9163 history number.  The way @code{print} labels its output is designed to
9164 remind you of this.  Just @code{$} refers to the most recent value in
9165 the history, and @code{$$} refers to the value before that.
9166 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
9167 is the value just prior to @code{$$}, @code{$$1} is equivalent to
9168 @code{$$}, and @code{$$0} is equivalent to @code{$}.
9169
9170 For example, suppose you have just printed a pointer to a structure and
9171 want to see the contents of the structure.  It suffices to type
9172
9173 @smallexample
9174 p *$
9175 @end smallexample
9176
9177 If you have a chain of structures where the component @code{next} points
9178 to the next one, you can print the contents of the next one with this:
9179
9180 @smallexample
9181 p *$.next
9182 @end smallexample
9183
9184 @noindent
9185 You can print successive links in the chain by repeating this
9186 command---which you can do by just typing @key{RET}.
9187
9188 Note that the history records values, not expressions.  If the value of
9189 @code{x} is 4 and you type these commands:
9190
9191 @smallexample
9192 print x
9193 set x=5
9194 @end smallexample
9195
9196 @noindent
9197 then the value recorded in the value history by the @code{print} command
9198 remains 4 even though the value of @code{x} has changed.
9199
9200 @table @code
9201 @kindex show values
9202 @item show values
9203 Print the last ten values in the value history, with their item numbers.
9204 This is like @samp{p@ $$9} repeated ten times, except that @code{show
9205 values} does not change the history.
9206
9207 @item show values @var{n}
9208 Print ten history values centered on history item number @var{n}.
9209
9210 @item show values +
9211 Print ten history values just after the values last printed.  If no more
9212 values are available, @code{show values +} produces no display.
9213 @end table
9214
9215 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
9216 same effect as @samp{show values +}.
9217
9218 @node Convenience Vars
9219 @section Convenience Variables
9220
9221 @cindex convenience variables
9222 @cindex user-defined variables
9223 @value{GDBN} provides @dfn{convenience variables} that you can use within
9224 @value{GDBN} to hold on to a value and refer to it later.  These variables
9225 exist entirely within @value{GDBN}; they are not part of your program, and
9226 setting a convenience variable has no direct effect on further execution
9227 of your program.  That is why you can use them freely.
9228
9229 Convenience variables are prefixed with @samp{$}.  Any name preceded by
9230 @samp{$} can be used for a convenience variable, unless it is one of
9231 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
9232 (Value history references, in contrast, are @emph{numbers} preceded
9233 by @samp{$}.  @xref{Value History, ,Value History}.)
9234
9235 You can save a value in a convenience variable with an assignment
9236 expression, just as you would set a variable in your program.
9237 For example:
9238
9239 @smallexample
9240 set $foo = *object_ptr
9241 @end smallexample
9242
9243 @noindent
9244 would save in @code{$foo} the value contained in the object pointed to by
9245 @code{object_ptr}.
9246
9247 Using a convenience variable for the first time creates it, but its
9248 value is @code{void} until you assign a new value.  You can alter the
9249 value with another assignment at any time.
9250
9251 Convenience variables have no fixed types.  You can assign a convenience
9252 variable any type of value, including structures and arrays, even if
9253 that variable already has a value of a different type.  The convenience
9254 variable, when used as an expression, has the type of its current value.
9255
9256 @table @code
9257 @kindex show convenience
9258 @cindex show all user variables and functions
9259 @item show convenience
9260 Print a list of convenience variables used so far, and their values,
9261 as well as a list of the convenience functions.
9262 Abbreviated @code{show conv}.
9263
9264 @kindex init-if-undefined
9265 @cindex convenience variables, initializing
9266 @item init-if-undefined $@var{variable} = @var{expression}
9267 Set a convenience variable if it has not already been set.  This is useful
9268 for user-defined commands that keep some state.  It is similar, in concept,
9269 to using local static variables with initializers in C (except that
9270 convenience variables are global).  It can also be used to allow users to
9271 override default values used in a command script.
9272
9273 If the variable is already defined then the expression is not evaluated so
9274 any side-effects do not occur.
9275 @end table
9276
9277 One of the ways to use a convenience variable is as a counter to be
9278 incremented or a pointer to be advanced.  For example, to print
9279 a field from successive elements of an array of structures:
9280
9281 @smallexample
9282 set $i = 0
9283 print bar[$i++]->contents
9284 @end smallexample
9285
9286 @noindent
9287 Repeat that command by typing @key{RET}.
9288
9289 Some convenience variables are created automatically by @value{GDBN} and given
9290 values likely to be useful.
9291
9292 @table @code
9293 @vindex $_@r{, convenience variable}
9294 @item $_
9295 The variable @code{$_} is automatically set by the @code{x} command to
9296 the last address examined (@pxref{Memory, ,Examining Memory}).  Other
9297 commands which provide a default address for @code{x} to examine also
9298 set @code{$_} to that address; these commands include @code{info line}
9299 and @code{info breakpoint}.  The type of @code{$_} is @code{void *}
9300 except when set by the @code{x} command, in which case it is a pointer
9301 to the type of @code{$__}.
9302
9303 @vindex $__@r{, convenience variable}
9304 @item $__
9305 The variable @code{$__} is automatically set by the @code{x} command
9306 to the value found in the last address examined.  Its type is chosen
9307 to match the format in which the data was printed.
9308
9309 @item $_exitcode
9310 @vindex $_exitcode@r{, convenience variable}
9311 The variable @code{$_exitcode} is automatically set to the exit code when
9312 the program being debugged terminates.
9313
9314 @item $_probe_argc
9315 @itemx $_probe_arg0@dots{}$_probe_arg11
9316 Arguments to a static probe.  @xref{Static Probe Points}.
9317
9318 @item $_sdata
9319 @vindex $_sdata@r{, inspect, convenience variable}
9320 The variable @code{$_sdata} contains extra collected static tracepoint
9321 data.  @xref{Tracepoint Actions,,Tracepoint Action Lists}.  Note that
9322 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
9323 if extra static tracepoint data has not been collected.
9324
9325 @item $_siginfo
9326 @vindex $_siginfo@r{, convenience variable}
9327 The variable @code{$_siginfo} contains extra signal information
9328 (@pxref{extra signal information}).  Note that @code{$_siginfo}
9329 could be empty, if the application has not yet received any signals.
9330 For example, it will be empty before you execute the @code{run} command.
9331
9332 @item $_tlb
9333 @vindex $_tlb@r{, convenience variable}
9334 The variable @code{$_tlb} is automatically set when debugging
9335 applications running on MS-Windows in native mode or connected to
9336 gdbserver that supports the @code{qGetTIBAddr} request. 
9337 @xref{General Query Packets}.
9338 This variable contains the address of the thread information block.
9339
9340 @end table
9341
9342 On HP-UX systems, if you refer to a function or variable name that
9343 begins with a dollar sign, @value{GDBN} searches for a user or system
9344 name first, before it searches for a convenience variable.
9345
9346 @node Convenience Funs
9347 @section Convenience Functions
9348
9349 @cindex convenience functions
9350 @value{GDBN} also supplies some @dfn{convenience functions}.  These
9351 have a syntax similar to convenience variables.  A convenience
9352 function can be used in an expression just like an ordinary function;
9353 however, a convenience function is implemented internally to
9354 @value{GDBN}.
9355
9356 These functions require @value{GDBN} to be configured with
9357 @code{Python} support.
9358
9359 @table @code
9360
9361 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
9362 @findex $_memeq@r{, convenience function}
9363 Returns one if the @var{length} bytes at the addresses given by
9364 @var{buf1} and @var{buf2} are equal.
9365 Otherwise it returns zero.
9366
9367 @item $_regex(@var{str}, @var{regex})
9368 @findex $_regex@r{, convenience function}
9369 Returns one if the string @var{str} matches the regular expression
9370 @var{regex}.  Otherwise it returns zero.
9371 The syntax of the regular expression is that specified by @code{Python}'s
9372 regular expression support.
9373
9374 @item $_streq(@var{str1}, @var{str2})
9375 @findex $_streq@r{, convenience function}
9376 Returns one if the strings @var{str1} and @var{str2} are equal.
9377 Otherwise it returns zero.
9378
9379 @item $_strlen(@var{str})
9380 @findex $_strlen@r{, convenience function}
9381 Returns the length of string @var{str}.
9382
9383 @end table
9384
9385 @value{GDBN} provides the ability to list and get help on
9386 convenience functions.
9387
9388 @table @code
9389 @item help function
9390 @kindex help function
9391 @cindex show all convenience functions
9392 Print a list of all convenience functions.
9393 @end table
9394
9395 @node Registers
9396 @section Registers
9397
9398 @cindex registers
9399 You can refer to machine register contents, in expressions, as variables
9400 with names starting with @samp{$}.  The names of registers are different
9401 for each machine; use @code{info registers} to see the names used on
9402 your machine.
9403
9404 @table @code
9405 @kindex info registers
9406 @item info registers
9407 Print the names and values of all registers except floating-point
9408 and vector registers (in the selected stack frame).
9409
9410 @kindex info all-registers
9411 @cindex floating point registers
9412 @item info all-registers
9413 Print the names and values of all registers, including floating-point
9414 and vector registers (in the selected stack frame).
9415
9416 @item info registers @var{regname} @dots{}
9417 Print the @dfn{relativized} value of each specified register @var{regname}.
9418 As discussed in detail below, register values are normally relative to
9419 the selected stack frame.  @var{regname} may be any register name valid on
9420 the machine you are using, with or without the initial @samp{$}.
9421 @end table
9422
9423 @cindex stack pointer register
9424 @cindex program counter register
9425 @cindex process status register
9426 @cindex frame pointer register
9427 @cindex standard registers
9428 @value{GDBN} has four ``standard'' register names that are available (in
9429 expressions) on most machines---whenever they do not conflict with an
9430 architecture's canonical mnemonics for registers.  The register names
9431 @code{$pc} and @code{$sp} are used for the program counter register and
9432 the stack pointer.  @code{$fp} is used for a register that contains a
9433 pointer to the current stack frame, and @code{$ps} is used for a
9434 register that contains the processor status.  For example,
9435 you could print the program counter in hex with
9436
9437 @smallexample
9438 p/x $pc
9439 @end smallexample
9440
9441 @noindent
9442 or print the instruction to be executed next with
9443
9444 @smallexample
9445 x/i $pc
9446 @end smallexample
9447
9448 @noindent
9449 or add four to the stack pointer@footnote{This is a way of removing
9450 one word from the stack, on machines where stacks grow downward in
9451 memory (most machines, nowadays).  This assumes that the innermost
9452 stack frame is selected; setting @code{$sp} is not allowed when other
9453 stack frames are selected.  To pop entire frames off the stack,
9454 regardless of machine architecture, use @code{return};
9455 see @ref{Returning, ,Returning from a Function}.} with
9456
9457 @smallexample
9458 set $sp += 4
9459 @end smallexample
9460
9461 Whenever possible, these four standard register names are available on
9462 your machine even though the machine has different canonical mnemonics,
9463 so long as there is no conflict.  The @code{info registers} command
9464 shows the canonical names.  For example, on the SPARC, @code{info
9465 registers} displays the processor status register as @code{$psr} but you
9466 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
9467 is an alias for the @sc{eflags} register.
9468
9469 @value{GDBN} always considers the contents of an ordinary register as an
9470 integer when the register is examined in this way.  Some machines have
9471 special registers which can hold nothing but floating point; these
9472 registers are considered to have floating point values.  There is no way
9473 to refer to the contents of an ordinary register as floating point value
9474 (although you can @emph{print} it as a floating point value with
9475 @samp{print/f $@var{regname}}).
9476
9477 Some registers have distinct ``raw'' and ``virtual'' data formats.  This
9478 means that the data format in which the register contents are saved by
9479 the operating system is not the same one that your program normally
9480 sees.  For example, the registers of the 68881 floating point
9481 coprocessor are always saved in ``extended'' (raw) format, but all C
9482 programs expect to work with ``double'' (virtual) format.  In such
9483 cases, @value{GDBN} normally works with the virtual format only (the format
9484 that makes sense for your program), but the @code{info registers} command
9485 prints the data in both formats.
9486
9487 @cindex SSE registers (x86)
9488 @cindex MMX registers (x86)
9489 Some machines have special registers whose contents can be interpreted
9490 in several different ways.  For example, modern x86-based machines
9491 have SSE and MMX registers that can hold several values packed
9492 together in several different formats.  @value{GDBN} refers to such
9493 registers in @code{struct} notation:
9494
9495 @smallexample
9496 (@value{GDBP}) print $xmm1
9497 $1 = @{
9498   v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
9499   v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
9500   v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
9501   v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
9502   v4_int32 = @{0, 20657912, 11, 13@},
9503   v2_int64 = @{88725056443645952, 55834574859@},
9504   uint128 = 0x0000000d0000000b013b36f800000000
9505 @}
9506 @end smallexample
9507
9508 @noindent
9509 To set values of such registers, you need to tell @value{GDBN} which
9510 view of the register you wish to change, as if you were assigning
9511 value to a @code{struct} member:
9512
9513 @smallexample
9514  (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
9515 @end smallexample
9516
9517 Normally, register values are relative to the selected stack frame
9518 (@pxref{Selection, ,Selecting a Frame}).  This means that you get the
9519 value that the register would contain if all stack frames farther in
9520 were exited and their saved registers restored.  In order to see the
9521 true contents of hardware registers, you must select the innermost
9522 frame (with @samp{frame 0}).
9523
9524 However, @value{GDBN} must deduce where registers are saved, from the machine
9525 code generated by your compiler.  If some registers are not saved, or if
9526 @value{GDBN} is unable to locate the saved registers, the selected stack
9527 frame makes no difference.
9528
9529 @node Floating Point Hardware
9530 @section Floating Point Hardware
9531 @cindex floating point
9532
9533 Depending on the configuration, @value{GDBN} may be able to give
9534 you more information about the status of the floating point hardware.
9535
9536 @table @code
9537 @kindex info float
9538 @item info float
9539 Display hardware-dependent information about the floating
9540 point unit.  The exact contents and layout vary depending on the
9541 floating point chip.  Currently, @samp{info float} is supported on
9542 the ARM and x86 machines.
9543 @end table
9544
9545 @node Vector Unit
9546 @section Vector Unit
9547 @cindex vector unit
9548
9549 Depending on the configuration, @value{GDBN} may be able to give you
9550 more information about the status of the vector unit.
9551
9552 @table @code
9553 @kindex info vector
9554 @item info vector
9555 Display information about the vector unit.  The exact contents and
9556 layout vary depending on the hardware.
9557 @end table
9558
9559 @node OS Information
9560 @section Operating System Auxiliary Information
9561 @cindex OS information
9562
9563 @value{GDBN} provides interfaces to useful OS facilities that can help
9564 you debug your program.
9565
9566 @cindex auxiliary vector
9567 @cindex vector, auxiliary
9568 Some operating systems supply an @dfn{auxiliary vector} to programs at
9569 startup.  This is akin to the arguments and environment that you
9570 specify for a program, but contains a system-dependent variety of
9571 binary values that tell system libraries important details about the
9572 hardware, operating system, and process.  Each value's purpose is
9573 identified by an integer tag; the meanings are well-known but system-specific.
9574 Depending on the configuration and operating system facilities,
9575 @value{GDBN} may be able to show you this information.  For remote
9576 targets, this functionality may further depend on the remote stub's
9577 support of the @samp{qXfer:auxv:read} packet, see
9578 @ref{qXfer auxiliary vector read}.
9579
9580 @table @code
9581 @kindex info auxv
9582 @item info auxv
9583 Display the auxiliary vector of the inferior, which can be either a
9584 live process or a core dump file.  @value{GDBN} prints each tag value
9585 numerically, and also shows names and text descriptions for recognized
9586 tags.  Some values in the vector are numbers, some bit masks, and some
9587 pointers to strings or other data.  @value{GDBN} displays each value in the
9588 most appropriate form for a recognized tag, and in hexadecimal for
9589 an unrecognized tag.
9590 @end table
9591
9592 On some targets, @value{GDBN} can access operating system-specific
9593 information and show it to you.  The types of information available
9594 will differ depending on the type of operating system running on the
9595 target.  The mechanism used to fetch the data is described in
9596 @ref{Operating System Information}.  For remote targets, this
9597 functionality depends on the remote stub's support of the
9598 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
9599
9600 @table @code
9601 @kindex info os
9602 @item info os @var{infotype}
9603
9604 Display OS information of the requested type.
9605
9606 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
9607
9608 @anchor{linux info os infotypes}
9609 @table @code
9610 @kindex info os processes
9611 @item processes
9612 Display the list of processes on the target.  For each process,
9613 @value{GDBN} prints the process identifier, the name of the user, the
9614 command corresponding to the process, and the list of processor cores
9615 that the process is currently running on.  (To understand what these
9616 properties mean, for this and the following info types, please consult
9617 the general @sc{gnu}/Linux documentation.)
9618
9619 @kindex info os procgroups
9620 @item procgroups
9621 Display the list of process groups on the target.  For each process,
9622 @value{GDBN} prints the identifier of the process group that it belongs
9623 to, the command corresponding to the process group leader, the process
9624 identifier, and the command line of the process.  The list is sorted
9625 first by the process group identifier, then by the process identifier,
9626 so that processes belonging to the same process group are grouped together
9627 and the process group leader is listed first.
9628
9629 @kindex info os threads
9630 @item threads
9631 Display the list of threads running on the target.  For each thread,
9632 @value{GDBN} prints the identifier of the process that the thread
9633 belongs to, the command of the process, the thread identifier, and the
9634 processor core that it is currently running on.  The main thread of a
9635 process is not listed.
9636
9637 @kindex info os files
9638 @item files
9639 Display the list of open file descriptors on the target.  For each
9640 file descriptor, @value{GDBN} prints the identifier of the process
9641 owning the descriptor, the command of the owning process, the value
9642 of the descriptor, and the target of the descriptor.
9643
9644 @kindex info os sockets
9645 @item sockets
9646 Display the list of Internet-domain sockets on the target.  For each
9647 socket, @value{GDBN} prints the address and port of the local and
9648 remote endpoints, the current state of the connection, the creator of
9649 the socket, the IP address family of the socket, and the type of the
9650 connection.
9651
9652 @kindex info os shm
9653 @item shm
9654 Display the list of all System V shared-memory regions on the target.
9655 For each shared-memory region, @value{GDBN} prints the region key,
9656 the shared-memory identifier, the access permissions, the size of the
9657 region, the process that created the region, the process that last
9658 attached to or detached from the region, the current number of live
9659 attaches to the region, and the times at which the region was last
9660 attached to, detach from, and changed.
9661
9662 @kindex info os semaphores
9663 @item semaphores
9664 Display the list of all System V semaphore sets on the target.  For each
9665 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
9666 set identifier, the access permissions, the number of semaphores in the
9667 set, the user and group of the owner and creator of the semaphore set,
9668 and the times at which the semaphore set was operated upon and changed.
9669
9670 @kindex info os msg
9671 @item msg
9672 Display the list of all System V message queues on the target.  For each
9673 message queue, @value{GDBN} prints the message queue key, the message
9674 queue identifier, the access permissions, the current number of bytes
9675 on the queue, the current number of messages on the queue, the processes
9676 that last sent and received a message on the queue, the user and group
9677 of the owner and creator of the message queue, the times at which a
9678 message was last sent and received on the queue, and the time at which
9679 the message queue was last changed.
9680
9681 @kindex info os modules
9682 @item modules
9683 Display the list of all loaded kernel modules on the target.  For each
9684 module, @value{GDBN} prints the module name, the size of the module in
9685 bytes, the number of times the module is used, the dependencies of the
9686 module, the status of the module, and the address of the loaded module
9687 in memory.
9688 @end table
9689
9690 @item info os
9691 If @var{infotype} is omitted, then list the possible values for
9692 @var{infotype} and the kind of OS information available for each
9693 @var{infotype}.  If the target does not return a list of possible
9694 types, this command will report an error.
9695 @end table
9696
9697 @node Memory Region Attributes
9698 @section Memory Region Attributes
9699 @cindex memory region attributes
9700
9701 @dfn{Memory region attributes} allow you to describe special handling
9702 required by regions of your target's memory.  @value{GDBN} uses
9703 attributes to determine whether to allow certain types of memory
9704 accesses; whether to use specific width accesses; and whether to cache
9705 target memory.  By default the description of memory regions is
9706 fetched from the target (if the current target supports this), but the
9707 user can override the fetched regions.
9708
9709 Defined memory regions can be individually enabled and disabled.  When a
9710 memory region is disabled, @value{GDBN} uses the default attributes when
9711 accessing memory in that region.  Similarly, if no memory regions have
9712 been defined, @value{GDBN} uses the default attributes when accessing
9713 all memory.
9714
9715 When a memory region is defined, it is given a number to identify it;
9716 to enable, disable, or remove a memory region, you specify that number.
9717
9718 @table @code
9719 @kindex mem
9720 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
9721 Define a memory region bounded by @var{lower} and @var{upper} with
9722 attributes @var{attributes}@dots{}, and add it to the list of regions
9723 monitored by @value{GDBN}.  Note that @var{upper} == 0 is a special
9724 case: it is treated as the target's maximum memory address.
9725 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
9726
9727 @item mem auto
9728 Discard any user changes to the memory regions and use target-supplied
9729 regions, if available, or no regions if the target does not support.
9730
9731 @kindex delete mem
9732 @item delete mem @var{nums}@dots{}
9733 Remove memory regions @var{nums}@dots{} from the list of regions
9734 monitored by @value{GDBN}.
9735
9736 @kindex disable mem
9737 @item disable mem @var{nums}@dots{}
9738 Disable monitoring of memory regions @var{nums}@dots{}.
9739 A disabled memory region is not forgotten.
9740 It may be enabled again later.
9741
9742 @kindex enable mem
9743 @item enable mem @var{nums}@dots{}
9744 Enable monitoring of memory regions @var{nums}@dots{}.
9745
9746 @kindex info mem
9747 @item info mem
9748 Print a table of all defined memory regions, with the following columns
9749 for each region:
9750
9751 @table @emph
9752 @item Memory Region Number
9753 @item Enabled or Disabled.
9754 Enabled memory regions are marked with @samp{y}.
9755 Disabled memory regions are marked with @samp{n}.
9756
9757 @item Lo Address
9758 The address defining the inclusive lower bound of the memory region.
9759
9760 @item Hi Address
9761 The address defining the exclusive upper bound of the memory region.
9762
9763 @item Attributes
9764 The list of attributes set for this memory region.
9765 @end table
9766 @end table
9767
9768
9769 @subsection Attributes
9770
9771 @subsubsection Memory Access Mode
9772 The access mode attributes set whether @value{GDBN} may make read or
9773 write accesses to a memory region.
9774
9775 While these attributes prevent @value{GDBN} from performing invalid
9776 memory accesses, they do nothing to prevent the target system, I/O DMA,
9777 etc.@: from accessing memory.
9778
9779 @table @code
9780 @item ro
9781 Memory is read only.
9782 @item wo
9783 Memory is write only.
9784 @item rw
9785 Memory is read/write.  This is the default.
9786 @end table
9787
9788 @subsubsection Memory Access Size
9789 The access size attribute tells @value{GDBN} to use specific sized
9790 accesses in the memory region.  Often memory mapped device registers
9791 require specific sized accesses.  If no access size attribute is
9792 specified, @value{GDBN} may use accesses of any size.
9793
9794 @table @code
9795 @item 8
9796 Use 8 bit memory accesses.
9797 @item 16
9798 Use 16 bit memory accesses.
9799 @item 32
9800 Use 32 bit memory accesses.
9801 @item 64
9802 Use 64 bit memory accesses.
9803 @end table
9804
9805 @c @subsubsection Hardware/Software Breakpoints
9806 @c The hardware/software breakpoint attributes set whether @value{GDBN}
9807 @c will use hardware or software breakpoints for the internal breakpoints
9808 @c used by the step, next, finish, until, etc. commands.
9809 @c
9810 @c @table @code
9811 @c @item hwbreak
9812 @c Always use hardware breakpoints
9813 @c @item swbreak (default)
9814 @c @end table
9815
9816 @subsubsection Data Cache
9817 The data cache attributes set whether @value{GDBN} will cache target
9818 memory.  While this generally improves performance by reducing debug
9819 protocol overhead, it can lead to incorrect results because @value{GDBN}
9820 does not know about volatile variables or memory mapped device
9821 registers.
9822
9823 @table @code
9824 @item cache
9825 Enable @value{GDBN} to cache target memory.
9826 @item nocache
9827 Disable @value{GDBN} from caching target memory.  This is the default.
9828 @end table
9829
9830 @subsection Memory Access Checking
9831 @value{GDBN} can be instructed to refuse accesses to memory that is
9832 not explicitly described.  This can be useful if accessing such
9833 regions has undesired effects for a specific target, or to provide
9834 better error checking.  The following commands control this behaviour.
9835
9836 @table @code
9837 @kindex set mem inaccessible-by-default
9838 @item set mem inaccessible-by-default [on|off]
9839 If @code{on} is specified, make  @value{GDBN} treat memory not
9840 explicitly described by the memory ranges as non-existent and refuse accesses
9841 to such memory.  The checks are only performed if there's at least one
9842 memory range defined.  If @code{off} is specified, make @value{GDBN}
9843 treat the memory not explicitly described by the memory ranges as RAM.
9844 The default value is @code{on}.
9845 @kindex show mem inaccessible-by-default
9846 @item show mem inaccessible-by-default
9847 Show the current handling of accesses to unknown memory.
9848 @end table
9849
9850
9851 @c @subsubsection Memory Write Verification
9852 @c The memory write verification attributes set whether @value{GDBN}
9853 @c will re-reads data after each write to verify the write was successful.
9854 @c
9855 @c @table @code
9856 @c @item verify
9857 @c @item noverify (default)
9858 @c @end table
9859
9860 @node Dump/Restore Files
9861 @section Copy Between Memory and a File
9862 @cindex dump/restore files
9863 @cindex append data to a file
9864 @cindex dump data to a file
9865 @cindex restore data from a file
9866
9867 You can use the commands @code{dump}, @code{append}, and
9868 @code{restore} to copy data between target memory and a file.  The
9869 @code{dump} and @code{append} commands write data to a file, and the
9870 @code{restore} command reads data from a file back into the inferior's
9871 memory.  Files may be in binary, Motorola S-record, Intel hex, or
9872 Tektronix Hex format; however, @value{GDBN} can only append to binary
9873 files.
9874
9875 @table @code
9876
9877 @kindex dump
9878 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
9879 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
9880 Dump the contents of memory from @var{start_addr} to @var{end_addr},
9881 or the value of @var{expr}, to @var{filename} in the given format.
9882
9883 The @var{format} parameter may be any one of:
9884 @table @code
9885 @item binary
9886 Raw binary form.
9887 @item ihex
9888 Intel hex format.
9889 @item srec
9890 Motorola S-record format.
9891 @item tekhex
9892 Tektronix Hex format.
9893 @end table
9894
9895 @value{GDBN} uses the same definitions of these formats as the
9896 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}.  If
9897 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
9898 form.
9899
9900 @kindex append
9901 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
9902 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
9903 Append the contents of memory from @var{start_addr} to @var{end_addr},
9904 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
9905 (@value{GDBN} can only append data to files in raw binary form.)
9906
9907 @kindex restore
9908 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
9909 Restore the contents of file @var{filename} into memory.  The
9910 @code{restore} command can automatically recognize any known @sc{bfd}
9911 file format, except for raw binary.  To restore a raw binary file you
9912 must specify the optional keyword @code{binary} after the filename.
9913
9914 If @var{bias} is non-zero, its value will be added to the addresses
9915 contained in the file.  Binary files always start at address zero, so
9916 they will be restored at address @var{bias}.  Other bfd files have
9917 a built-in location; they will be restored at offset @var{bias}
9918 from that location.
9919
9920 If @var{start} and/or @var{end} are non-zero, then only data between
9921 file offset @var{start} and file offset @var{end} will be restored.
9922 These offsets are relative to the addresses in the file, before
9923 the @var{bias} argument is applied.
9924
9925 @end table
9926
9927 @node Core File Generation
9928 @section How to Produce a Core File from Your Program
9929 @cindex dump core from inferior
9930
9931 A @dfn{core file} or @dfn{core dump} is a file that records the memory
9932 image of a running process and its process status (register values
9933 etc.).  Its primary use is post-mortem debugging of a program that
9934 crashed while it ran outside a debugger.  A program that crashes
9935 automatically produces a core file, unless this feature is disabled by
9936 the user.  @xref{Files}, for information on invoking @value{GDBN} in
9937 the post-mortem debugging mode.
9938
9939 Occasionally, you may wish to produce a core file of the program you
9940 are debugging in order to preserve a snapshot of its state.
9941 @value{GDBN} has a special command for that.
9942
9943 @table @code
9944 @kindex gcore
9945 @kindex generate-core-file
9946 @item generate-core-file [@var{file}]
9947 @itemx gcore [@var{file}]
9948 Produce a core dump of the inferior process.  The optional argument
9949 @var{file} specifies the file name where to put the core dump.  If not
9950 specified, the file name defaults to @file{core.@var{pid}}, where
9951 @var{pid} is the inferior process ID.
9952
9953 Note that this command is implemented only for some systems (as of
9954 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
9955 @end table
9956
9957 @node Character Sets
9958 @section Character Sets
9959 @cindex character sets
9960 @cindex charset
9961 @cindex translating between character sets
9962 @cindex host character set
9963 @cindex target character set
9964
9965 If the program you are debugging uses a different character set to
9966 represent characters and strings than the one @value{GDBN} uses itself,
9967 @value{GDBN} can automatically translate between the character sets for
9968 you.  The character set @value{GDBN} uses we call the @dfn{host
9969 character set}; the one the inferior program uses we call the
9970 @dfn{target character set}.
9971
9972 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
9973 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
9974 remote protocol (@pxref{Remote Debugging}) to debug a program
9975 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
9976 then the host character set is Latin-1, and the target character set is
9977 @sc{ebcdic}.  If you give @value{GDBN} the command @code{set
9978 target-charset EBCDIC-US}, then @value{GDBN} translates between
9979 @sc{ebcdic} and Latin 1 as you print character or string values, or use
9980 character and string literals in expressions.
9981
9982 @value{GDBN} has no way to automatically recognize which character set
9983 the inferior program uses; you must tell it, using the @code{set
9984 target-charset} command, described below.
9985
9986 Here are the commands for controlling @value{GDBN}'s character set
9987 support:
9988
9989 @table @code
9990 @item set target-charset @var{charset}
9991 @kindex set target-charset
9992 Set the current target character set to @var{charset}.  To display the
9993 list of supported target character sets, type
9994 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
9995
9996 @item set host-charset @var{charset}
9997 @kindex set host-charset
9998 Set the current host character set to @var{charset}.
9999
10000 By default, @value{GDBN} uses a host character set appropriate to the
10001 system it is running on; you can override that default using the
10002 @code{set host-charset} command.  On some systems, @value{GDBN} cannot
10003 automatically determine the appropriate host character set.  In this
10004 case, @value{GDBN} uses @samp{UTF-8}.
10005
10006 @value{GDBN} can only use certain character sets as its host character
10007 set.  If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10008 @value{GDBN} will list the host character sets it supports.
10009
10010 @item set charset @var{charset}
10011 @kindex set charset
10012 Set the current host and target character sets to @var{charset}.  As
10013 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
10014 @value{GDBN} will list the names of the character sets that can be used
10015 for both host and target.
10016
10017 @item show charset
10018 @kindex show charset
10019 Show the names of the current host and target character sets.
10020
10021 @item show host-charset
10022 @kindex show host-charset
10023 Show the name of the current host character set.
10024
10025 @item show target-charset
10026 @kindex show target-charset
10027 Show the name of the current target character set.
10028
10029 @item set target-wide-charset @var{charset}
10030 @kindex set target-wide-charset
10031 Set the current target's wide character set to @var{charset}.  This is
10032 the character set used by the target's @code{wchar_t} type.  To
10033 display the list of supported wide character sets, type
10034 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
10035
10036 @item show target-wide-charset
10037 @kindex show target-wide-charset
10038 Show the name of the current target's wide character set.
10039 @end table
10040
10041 Here is an example of @value{GDBN}'s character set support in action.
10042 Assume that the following source code has been placed in the file
10043 @file{charset-test.c}:
10044
10045 @smallexample
10046 #include <stdio.h>
10047
10048 char ascii_hello[]
10049   = @{72, 101, 108, 108, 111, 44, 32, 119,
10050      111, 114, 108, 100, 33, 10, 0@};
10051 char ibm1047_hello[]
10052   = @{200, 133, 147, 147, 150, 107, 64, 166,
10053      150, 153, 147, 132, 90, 37, 0@};
10054
10055 main ()
10056 @{
10057   printf ("Hello, world!\n");
10058 @}
10059 @end smallexample
10060
10061 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
10062 containing the string @samp{Hello, world!} followed by a newline,
10063 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
10064
10065 We compile the program, and invoke the debugger on it:
10066
10067 @smallexample
10068 $ gcc -g charset-test.c -o charset-test
10069 $ gdb -nw charset-test
10070 GNU gdb 2001-12-19-cvs
10071 Copyright 2001 Free Software Foundation, Inc.
10072 @dots{}
10073 (@value{GDBP})
10074 @end smallexample
10075
10076 We can use the @code{show charset} command to see what character sets
10077 @value{GDBN} is currently using to interpret and display characters and
10078 strings:
10079
10080 @smallexample
10081 (@value{GDBP}) show charset
10082 The current host and target character set is `ISO-8859-1'.
10083 (@value{GDBP})
10084 @end smallexample
10085
10086 For the sake of printing this manual, let's use @sc{ascii} as our
10087 initial character set:
10088 @smallexample
10089 (@value{GDBP}) set charset ASCII
10090 (@value{GDBP}) show charset
10091 The current host and target character set is `ASCII'.
10092 (@value{GDBP})
10093 @end smallexample
10094
10095 Let's assume that @sc{ascii} is indeed the correct character set for our
10096 host system --- in other words, let's assume that if @value{GDBN} prints
10097 characters using the @sc{ascii} character set, our terminal will display
10098 them properly.  Since our current target character set is also
10099 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
10100
10101 @smallexample
10102 (@value{GDBP}) print ascii_hello
10103 $1 = 0x401698 "Hello, world!\n"
10104 (@value{GDBP}) print ascii_hello[0]
10105 $2 = 72 'H'
10106 (@value{GDBP})
10107 @end smallexample
10108
10109 @value{GDBN} uses the target character set for character and string
10110 literals you use in expressions:
10111
10112 @smallexample
10113 (@value{GDBP}) print '+'
10114 $3 = 43 '+'
10115 (@value{GDBP})
10116 @end smallexample
10117
10118 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
10119 character.
10120
10121 @value{GDBN} relies on the user to tell it which character set the
10122 target program uses.  If we print @code{ibm1047_hello} while our target
10123 character set is still @sc{ascii}, we get jibberish:
10124
10125 @smallexample
10126 (@value{GDBP}) print ibm1047_hello
10127 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
10128 (@value{GDBP}) print ibm1047_hello[0]
10129 $5 = 200 '\310'
10130 (@value{GDBP})
10131 @end smallexample
10132
10133 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
10134 @value{GDBN} tells us the character sets it supports:
10135
10136 @smallexample
10137 (@value{GDBP}) set target-charset
10138 ASCII       EBCDIC-US   IBM1047     ISO-8859-1
10139 (@value{GDBP}) set target-charset
10140 @end smallexample
10141
10142 We can select @sc{ibm1047} as our target character set, and examine the
10143 program's strings again.  Now the @sc{ascii} string is wrong, but
10144 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
10145 target character set, @sc{ibm1047}, to the host character set,
10146 @sc{ascii}, and they display correctly:
10147
10148 @smallexample
10149 (@value{GDBP}) set target-charset IBM1047
10150 (@value{GDBP}) show charset
10151 The current host character set is `ASCII'.
10152 The current target character set is `IBM1047'.
10153 (@value{GDBP}) print ascii_hello
10154 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
10155 (@value{GDBP}) print ascii_hello[0]
10156 $7 = 72 '\110'
10157 (@value{GDBP}) print ibm1047_hello
10158 $8 = 0x4016a8 "Hello, world!\n"
10159 (@value{GDBP}) print ibm1047_hello[0]
10160 $9 = 200 'H'
10161 (@value{GDBP})
10162 @end smallexample
10163
10164 As above, @value{GDBN} uses the target character set for character and
10165 string literals you use in expressions:
10166
10167 @smallexample
10168 (@value{GDBP}) print '+'
10169 $10 = 78 '+'
10170 (@value{GDBP})
10171 @end smallexample
10172
10173 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
10174 character.
10175
10176 @node Caching Remote Data
10177 @section Caching Data of Remote Targets
10178 @cindex caching data of remote targets
10179
10180 @value{GDBN} caches data exchanged between the debugger and a
10181 remote target (@pxref{Remote Debugging}).  Such caching generally improves
10182 performance, because it reduces the overhead of the remote protocol by
10183 bundling memory reads and writes into large chunks.  Unfortunately, simply
10184 caching everything would lead to incorrect results, since @value{GDBN} 
10185 does not necessarily know anything about volatile values, memory-mapped I/O
10186 addresses, etc.  Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
10187 memory can be changed @emph{while} a gdb command is executing.
10188 Therefore, by default, @value{GDBN} only caches data
10189 known to be on the stack@footnote{In non-stop mode, it is moderately
10190 rare for a running thread to modify the stack of a stopped thread
10191 in a way that would interfere with a backtrace, and caching of
10192 stack reads provides a significant speed up of remote backtraces.}.
10193 Other regions of memory can be explicitly marked as
10194 cacheable; see @pxref{Memory Region Attributes}.
10195
10196 @table @code
10197 @kindex set remotecache
10198 @item set remotecache on
10199 @itemx set remotecache off
10200 This option no longer does anything; it exists for compatibility
10201 with old scripts.
10202
10203 @kindex show remotecache
10204 @item show remotecache
10205 Show the current state of the obsolete remotecache flag.
10206
10207 @kindex set stack-cache
10208 @item set stack-cache on
10209 @itemx set stack-cache off
10210 Enable or disable caching of stack accesses.  When @code{ON}, use
10211 caching.  By default, this option is @code{ON}.
10212
10213 @kindex show stack-cache
10214 @item show stack-cache
10215 Show the current state of data caching for memory accesses.
10216
10217 @kindex info dcache
10218 @item info dcache @r{[}line@r{]}
10219 Print the information about the data cache performance.  The
10220 information displayed includes the dcache width and depth, and for
10221 each cache line, its number, address, and how many times it was
10222 referenced.  This command is useful for debugging the data cache
10223 operation.
10224
10225 If a line number is specified, the contents of that line will be
10226 printed in hex.
10227
10228 @item set dcache size @var{size}
10229 @cindex dcache size
10230 @kindex set dcache size
10231 Set maximum number of entries in dcache (dcache depth above).
10232
10233 @item set dcache line-size @var{line-size}
10234 @cindex dcache line-size
10235 @kindex set dcache line-size
10236 Set number of bytes each dcache entry caches (dcache width above).
10237 Must be a power of 2.
10238
10239 @item show dcache size
10240 @kindex show dcache size
10241 Show maximum number of dcache entries.  See also @ref{Caching Remote Data, info dcache}.
10242
10243 @item show dcache line-size
10244 @kindex show dcache line-size
10245 Show default size of dcache lines.  See also @ref{Caching Remote Data, info dcache}.
10246
10247 @end table
10248
10249 @node Searching Memory
10250 @section Search Memory
10251 @cindex searching memory
10252
10253 Memory can be searched for a particular sequence of bytes with the
10254 @code{find} command.
10255
10256 @table @code
10257 @kindex find
10258 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10259 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10260 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
10261 etc.  The search begins at address @var{start_addr} and continues for either
10262 @var{len} bytes or through to @var{end_addr} inclusive.
10263 @end table
10264
10265 @var{s} and @var{n} are optional parameters.
10266 They may be specified in either order, apart or together.
10267
10268 @table @r
10269 @item @var{s}, search query size
10270 The size of each search query value.
10271
10272 @table @code
10273 @item b
10274 bytes
10275 @item h
10276 halfwords (two bytes)
10277 @item w
10278 words (four bytes)
10279 @item g
10280 giant words (eight bytes)
10281 @end table
10282
10283 All values are interpreted in the current language.
10284 This means, for example, that if the current source language is C/C@t{++}
10285 then searching for the string ``hello'' includes the trailing '\0'.
10286
10287 If the value size is not specified, it is taken from the
10288 value's type in the current language.
10289 This is useful when one wants to specify the search
10290 pattern as a mixture of types.
10291 Note that this means, for example, that in the case of C-like languages
10292 a search for an untyped 0x42 will search for @samp{(int) 0x42}
10293 which is typically four bytes.
10294
10295 @item @var{n}, maximum number of finds
10296 The maximum number of matches to print.  The default is to print all finds.
10297 @end table
10298
10299 You can use strings as search values.  Quote them with double-quotes
10300  (@code{"}).
10301 The string value is copied into the search pattern byte by byte,
10302 regardless of the endianness of the target and the size specification.
10303
10304 The address of each match found is printed as well as a count of the
10305 number of matches found.
10306
10307 The address of the last value found is stored in convenience variable
10308 @samp{$_}.
10309 A count of the number of matches is stored in @samp{$numfound}.
10310
10311 For example, if stopped at the @code{printf} in this function:
10312
10313 @smallexample
10314 void
10315 hello ()
10316 @{
10317   static char hello[] = "hello-hello";
10318   static struct @{ char c; short s; int i; @}
10319     __attribute__ ((packed)) mixed
10320     = @{ 'c', 0x1234, 0x87654321 @};
10321   printf ("%s\n", hello);
10322 @}
10323 @end smallexample
10324
10325 @noindent
10326 you get during debugging:
10327
10328 @smallexample
10329 (gdb) find &hello[0], +sizeof(hello), "hello"
10330 0x804956d <hello.1620+6>
10331 1 pattern found
10332 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
10333 0x8049567 <hello.1620>
10334 0x804956d <hello.1620+6>
10335 2 patterns found
10336 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
10337 0x8049567 <hello.1620>
10338 1 pattern found
10339 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
10340 0x8049560 <mixed.1625>
10341 1 pattern found
10342 (gdb) print $numfound
10343 $1 = 1
10344 (gdb) print $_
10345 $2 = (void *) 0x8049560
10346 @end smallexample
10347
10348 @node Optimized Code
10349 @chapter Debugging Optimized Code
10350 @cindex optimized code, debugging
10351 @cindex debugging optimized code
10352
10353 Almost all compilers support optimization.  With optimization
10354 disabled, the compiler generates assembly code that corresponds
10355 directly to your source code, in a simplistic way.  As the compiler
10356 applies more powerful optimizations, the generated assembly code
10357 diverges from your original source code.  With help from debugging
10358 information generated by the compiler, @value{GDBN} can map from
10359 the running program back to constructs from your original source.
10360
10361 @value{GDBN} is more accurate with optimization disabled.  If you
10362 can recompile without optimization, it is easier to follow the
10363 progress of your program during debugging.  But, there are many cases
10364 where you may need to debug an optimized version.
10365
10366 When you debug a program compiled with @samp{-g -O}, remember that the
10367 optimizer has rearranged your code; the debugger shows you what is
10368 really there.  Do not be too surprised when the execution path does not
10369 exactly match your source file!  An extreme example: if you define a
10370 variable, but never use it, @value{GDBN} never sees that
10371 variable---because the compiler optimizes it out of existence.
10372
10373 Some things do not work as well with @samp{-g -O} as with just
10374 @samp{-g}, particularly on machines with instruction scheduling.  If in
10375 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
10376 please report it to us as a bug (including a test case!).
10377 @xref{Variables}, for more information about debugging optimized code.
10378
10379 @menu
10380 * Inline Functions::            How @value{GDBN} presents inlining
10381 * Tail Call Frames::            @value{GDBN} analysis of jumps to functions
10382 @end menu
10383
10384 @node Inline Functions
10385 @section Inline Functions
10386 @cindex inline functions, debugging
10387
10388 @dfn{Inlining} is an optimization that inserts a copy of the function
10389 body directly at each call site, instead of jumping to a shared
10390 routine.  @value{GDBN} displays inlined functions just like
10391 non-inlined functions.  They appear in backtraces.  You can view their
10392 arguments and local variables, step into them with @code{step}, skip
10393 them with @code{next}, and escape from them with @code{finish}.
10394 You can check whether a function was inlined by using the
10395 @code{info frame} command.
10396
10397 For @value{GDBN} to support inlined functions, the compiler must
10398 record information about inlining in the debug information ---
10399 @value{NGCC} using the @sc{dwarf 2} format does this, and several
10400 other compilers do also.  @value{GDBN} only supports inlined functions
10401 when using @sc{dwarf 2}.  Versions of @value{NGCC} before 4.1
10402 do not emit two required attributes (@samp{DW_AT_call_file} and
10403 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
10404 function calls with earlier versions of @value{NGCC}.  It instead
10405 displays the arguments and local variables of inlined functions as
10406 local variables in the caller.
10407
10408 The body of an inlined function is directly included at its call site;
10409 unlike a non-inlined function, there are no instructions devoted to
10410 the call.  @value{GDBN} still pretends that the call site and the
10411 start of the inlined function are different instructions.  Stepping to
10412 the call site shows the call site, and then stepping again shows
10413 the first line of the inlined function, even though no additional
10414 instructions are executed.
10415
10416 This makes source-level debugging much clearer; you can see both the
10417 context of the call and then the effect of the call.  Only stepping by
10418 a single instruction using @code{stepi} or @code{nexti} does not do
10419 this; single instruction steps always show the inlined body.
10420
10421 There are some ways that @value{GDBN} does not pretend that inlined
10422 function calls are the same as normal calls:
10423
10424 @itemize @bullet
10425 @item
10426 Setting breakpoints at the call site of an inlined function may not
10427 work, because the call site does not contain any code.  @value{GDBN}
10428 may incorrectly move the breakpoint to the next line of the enclosing
10429 function, after the call.  This limitation will be removed in a future
10430 version of @value{GDBN}; until then, set a breakpoint on an earlier line
10431 or inside the inlined function instead.
10432
10433 @item
10434 @value{GDBN} cannot locate the return value of inlined calls after
10435 using the @code{finish} command.  This is a limitation of compiler-generated
10436 debugging information; after @code{finish}, you can step to the next line
10437 and print a variable where your program stored the return value.
10438
10439 @end itemize
10440
10441 @node Tail Call Frames
10442 @section Tail Call Frames
10443 @cindex tail call frames, debugging
10444
10445 Function @code{B} can call function @code{C} in its very last statement.  In
10446 unoptimized compilation the call of @code{C} is immediately followed by return
10447 instruction at the end of @code{B} code.  Optimizing compiler may replace the
10448 call and return in function @code{B} into one jump to function @code{C}
10449 instead.  Such use of a jump instruction is called @dfn{tail call}.
10450
10451 During execution of function @code{C}, there will be no indication in the
10452 function call stack frames that it was tail-called from @code{B}.  If function
10453 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
10454 then @value{GDBN} will see @code{A} as the caller of @code{C}.  However, in
10455 some cases @value{GDBN} can determine that @code{C} was tail-called from
10456 @code{B}, and it will then create fictitious call frame for that, with the
10457 return address set up as if @code{B} called @code{C} normally.
10458
10459 This functionality is currently supported only by DWARF 2 debugging format and
10460 the compiler has to produce @samp{DW_TAG_GNU_call_site} tags.  With
10461 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10462 this information.
10463
10464 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
10465 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
10466
10467 @smallexample
10468 (gdb) x/i $pc - 2
10469    0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
10470 (gdb) info frame
10471 Stack level 1, frame at 0x7fffffffda30:
10472  rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
10473  tail call frame, caller of frame at 0x7fffffffda30
10474  source language c++.
10475  Arglist at unknown address.
10476  Locals at unknown address, Previous frame's sp is 0x7fffffffda30
10477 @end smallexample
10478
10479 The detection of all the possible code path executions can find them ambiguous.
10480 There is no execution history stored (possible @ref{Reverse Execution} is never
10481 used for this purpose) and the last known caller could have reached the known
10482 callee by multiple different jump sequences.  In such case @value{GDBN} still
10483 tries to show at least all the unambiguous top tail callers and all the
10484 unambiguous bottom tail calees, if any.
10485
10486 @table @code
10487 @anchor{set debug entry-values}
10488 @item set debug entry-values
10489 @kindex set debug entry-values
10490 When set to on, enables printing of analysis messages for both frame argument
10491 values at function entry and tail calls.  It will show all the possible valid
10492 tail calls code paths it has considered.  It will also print the intersection
10493 of them with the final unambiguous (possibly partial or even empty) code path
10494 result.
10495
10496 @item show debug entry-values
10497 @kindex show debug entry-values
10498 Show the current state of analysis messages printing for both frame argument
10499 values at function entry and tail calls.
10500 @end table
10501
10502 The analysis messages for tail calls can for example show why the virtual tail
10503 call frame for function @code{c} has not been recognized (due to the indirect
10504 reference by variable @code{x}):
10505
10506 @smallexample
10507 static void __attribute__((noinline, noclone)) c (void);
10508 void (*x) (void) = c;
10509 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10510 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
10511 int main (void) @{ x (); return 0; @}
10512
10513 Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
10514 DW_TAG_GNU_call_site 0x40039a in main
10515 a () at t.c:3
10516 3       static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
10517 (gdb) bt
10518 #0  a () at t.c:3
10519 #1  0x000000000040039a in main () at t.c:5
10520 @end smallexample
10521
10522 Another possibility is an ambiguous virtual tail call frames resolution:
10523
10524 @smallexample
10525 int i;
10526 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
10527 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
10528 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
10529 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
10530 static void __attribute__((noinline, noclone)) b (void)
10531 @{ if (i) c (); else e (); @}
10532 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
10533 int main (void) @{ a (); return 0; @}
10534
10535 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
10536 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
10537 tailcall: reduced: 0x4004d2(a) |
10538 (gdb) bt
10539 #0  f () at t.c:2
10540 #1  0x00000000004004d2 in a () at t.c:8
10541 #2  0x0000000000400395 in main () at t.c:9
10542 @end smallexample
10543
10544 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
10545 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
10546
10547 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
10548 @ifset HAVE_MAKEINFO_CLICK
10549 @set ARROW @click{}
10550 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
10551 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
10552 @end ifset
10553 @ifclear HAVE_MAKEINFO_CLICK
10554 @set ARROW ->
10555 @set CALLSEQ1B @value{CALLSEQ1A}
10556 @set CALLSEQ2B @value{CALLSEQ2A}
10557 @end ifclear
10558
10559 Frames #0 and #2 are real, #1 is a virtual tail call frame.
10560 The code can have possible execution paths @value{CALLSEQ1B} or
10561 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
10562
10563 @code{initial:} state shows some random possible calling sequence @value{GDBN}
10564 has found.  It then finds another possible calling sequcen - that one is
10565 prefixed by @code{compare:}.  The non-ambiguous intersection of these two is
10566 printed as the @code{reduced:} calling sequence.  That one could have many
10567 futher @code{compare:} and @code{reduced:} statements as long as there remain
10568 any non-ambiguous sequence entries.
10569
10570 For the frame of function @code{b} in both cases there are different possible
10571 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
10572 also ambigous.  The only non-ambiguous frame is the one for function @code{a},
10573 therefore this one is displayed to the user while the ambiguous frames are
10574 omitted.
10575
10576 There can be also reasons why printing of frame argument values at function
10577 entry may fail:
10578
10579 @smallexample
10580 int v;
10581 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
10582 static void __attribute__((noinline, noclone)) a (int i);
10583 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
10584 static void __attribute__((noinline, noclone)) a (int i)
10585 @{ if (i) b (i - 1); else c (0); @}
10586 int main (void) @{ a (5); return 0; @}
10587
10588 (gdb) bt
10589 #0  c (i=i@@entry=0) at t.c:2
10590 #1  0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
10591 function "a" at 0x400420 can call itself via tail calls
10592 i=<optimized out>) at t.c:6
10593 #2  0x000000000040036e in main () at t.c:7
10594 @end smallexample
10595
10596 @value{GDBN} cannot find out from the inferior state if and how many times did
10597 function @code{a} call itself (via function @code{b}) as these calls would be
10598 tail calls.  Such tail calls would modify thue @code{i} variable, therefore
10599 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
10600 prints @code{<optimized out>} instead.
10601
10602 @node Macros
10603 @chapter C Preprocessor Macros
10604
10605 Some languages, such as C and C@t{++}, provide a way to define and invoke
10606 ``preprocessor macros'' which expand into strings of tokens.
10607 @value{GDBN} can evaluate expressions containing macro invocations, show
10608 the result of macro expansion, and show a macro's definition, including
10609 where it was defined.
10610
10611 You may need to compile your program specially to provide @value{GDBN}
10612 with information about preprocessor macros.  Most compilers do not
10613 include macros in their debugging information, even when you compile
10614 with the @option{-g} flag.  @xref{Compilation}.
10615
10616 A program may define a macro at one point, remove that definition later,
10617 and then provide a different definition after that.  Thus, at different
10618 points in the program, a macro may have different definitions, or have
10619 no definition at all.  If there is a current stack frame, @value{GDBN}
10620 uses the macros in scope at that frame's source code line.  Otherwise,
10621 @value{GDBN} uses the macros in scope at the current listing location;
10622 see @ref{List}.
10623
10624 Whenever @value{GDBN} evaluates an expression, it always expands any
10625 macro invocations present in the expression.  @value{GDBN} also provides
10626 the following commands for working with macros explicitly.
10627
10628 @table @code
10629
10630 @kindex macro expand
10631 @cindex macro expansion, showing the results of preprocessor
10632 @cindex preprocessor macro expansion, showing the results of
10633 @cindex expanding preprocessor macros
10634 @item macro expand @var{expression}
10635 @itemx macro exp @var{expression}
10636 Show the results of expanding all preprocessor macro invocations in
10637 @var{expression}.  Since @value{GDBN} simply expands macros, but does
10638 not parse the result, @var{expression} need not be a valid expression;
10639 it can be any string of tokens.
10640
10641 @kindex macro exp1
10642 @item macro expand-once @var{expression}
10643 @itemx macro exp1 @var{expression}
10644 @cindex expand macro once
10645 @i{(This command is not yet implemented.)}  Show the results of
10646 expanding those preprocessor macro invocations that appear explicitly in
10647 @var{expression}.  Macro invocations appearing in that expansion are
10648 left unchanged.  This command allows you to see the effect of a
10649 particular macro more clearly, without being confused by further
10650 expansions.  Since @value{GDBN} simply expands macros, but does not
10651 parse the result, @var{expression} need not be a valid expression; it
10652 can be any string of tokens.
10653
10654 @kindex info macro
10655 @cindex macro definition, showing
10656 @cindex definition of a macro, showing
10657 @cindex macros, from debug info
10658 @item info macro [-a|-all] [--] @var{macro}
10659 Show the current definition or all definitions of the named @var{macro},
10660 and describe the source location or compiler command-line where that
10661 definition was established.  The optional double dash is to signify the end of
10662 argument processing and the beginning of @var{macro} for non C-like macros where
10663 the macro may begin with a hyphen.
10664
10665 @kindex info macros
10666 @item info macros @var{linespec}
10667 Show all macro definitions that are in effect at the location specified
10668 by @var{linespec},  and describe the source location or compiler
10669 command-line where those definitions were established.
10670
10671 @kindex macro define
10672 @cindex user-defined macros
10673 @cindex defining macros interactively
10674 @cindex macros, user-defined
10675 @item macro define @var{macro} @var{replacement-list}
10676 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
10677 Introduce a definition for a preprocessor macro named @var{macro},
10678 invocations of which are replaced by the tokens given in
10679 @var{replacement-list}.  The first form of this command defines an
10680 ``object-like'' macro, which takes no arguments; the second form
10681 defines a ``function-like'' macro, which takes the arguments given in
10682 @var{arglist}.
10683
10684 A definition introduced by this command is in scope in every
10685 expression evaluated in @value{GDBN}, until it is removed with the
10686 @code{macro undef} command, described below.  The definition overrides
10687 all definitions for @var{macro} present in the program being debugged,
10688 as well as any previous user-supplied definition.
10689
10690 @kindex macro undef
10691 @item macro undef @var{macro}
10692 Remove any user-supplied definition for the macro named @var{macro}.
10693 This command only affects definitions provided with the @code{macro
10694 define} command, described above; it cannot remove definitions present
10695 in the program being debugged.
10696
10697 @kindex macro list
10698 @item macro list
10699 List all the macros defined using the @code{macro define} command.
10700 @end table
10701
10702 @cindex macros, example of debugging with
10703 Here is a transcript showing the above commands in action.  First, we
10704 show our source files:
10705
10706 @smallexample
10707 $ cat sample.c
10708 #include <stdio.h>
10709 #include "sample.h"
10710
10711 #define M 42
10712 #define ADD(x) (M + x)
10713
10714 main ()
10715 @{
10716 #define N 28
10717   printf ("Hello, world!\n");
10718 #undef N
10719   printf ("We're so creative.\n");
10720 #define N 1729
10721   printf ("Goodbye, world!\n");
10722 @}
10723 $ cat sample.h
10724 #define Q <
10725 $
10726 @end smallexample
10727
10728 Now, we compile the program using the @sc{gnu} C compiler,
10729 @value{NGCC}.  We pass the @option{-gdwarf-2}@footnote{This is the
10730 minimum.  Recent versions of @value{NGCC} support @option{-gdwarf-3}
10731 and @option{-gdwarf-4}; we recommend always choosing the most recent
10732 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
10733 includes information about preprocessor macros in the debugging
10734 information.
10735
10736 @smallexample
10737 $ gcc -gdwarf-2 -g3 sample.c -o sample
10738 $
10739 @end smallexample
10740
10741 Now, we start @value{GDBN} on our sample program:
10742
10743 @smallexample
10744 $ gdb -nw sample
10745 GNU gdb 2002-05-06-cvs
10746 Copyright 2002 Free Software Foundation, Inc.
10747 GDB is free software, @dots{}
10748 (@value{GDBP})
10749 @end smallexample
10750
10751 We can expand macros and examine their definitions, even when the
10752 program is not running.  @value{GDBN} uses the current listing position
10753 to decide which macro definitions are in scope:
10754
10755 @smallexample
10756 (@value{GDBP}) list main
10757 3
10758 4       #define M 42
10759 5       #define ADD(x) (M + x)
10760 6
10761 7       main ()
10762 8       @{
10763 9       #define N 28
10764 10        printf ("Hello, world!\n");
10765 11      #undef N
10766 12        printf ("We're so creative.\n");
10767 (@value{GDBP}) info macro ADD
10768 Defined at /home/jimb/gdb/macros/play/sample.c:5
10769 #define ADD(x) (M + x)
10770 (@value{GDBP}) info macro Q
10771 Defined at /home/jimb/gdb/macros/play/sample.h:1
10772   included at /home/jimb/gdb/macros/play/sample.c:2
10773 #define Q <
10774 (@value{GDBP}) macro expand ADD(1)
10775 expands to: (42 + 1)
10776 (@value{GDBP}) macro expand-once ADD(1)
10777 expands to: once (M + 1)
10778 (@value{GDBP})
10779 @end smallexample
10780
10781 In the example above, note that @code{macro expand-once} expands only
10782 the macro invocation explicit in the original text --- the invocation of
10783 @code{ADD} --- but does not expand the invocation of the macro @code{M},
10784 which was introduced by @code{ADD}.
10785
10786 Once the program is running, @value{GDBN} uses the macro definitions in
10787 force at the source line of the current stack frame:
10788
10789 @smallexample
10790 (@value{GDBP}) break main
10791 Breakpoint 1 at 0x8048370: file sample.c, line 10.
10792 (@value{GDBP}) run
10793 Starting program: /home/jimb/gdb/macros/play/sample
10794
10795 Breakpoint 1, main () at sample.c:10
10796 10        printf ("Hello, world!\n");
10797 (@value{GDBP})
10798 @end smallexample
10799
10800 At line 10, the definition of the macro @code{N} at line 9 is in force:
10801
10802 @smallexample
10803 (@value{GDBP}) info macro N
10804 Defined at /home/jimb/gdb/macros/play/sample.c:9
10805 #define N 28
10806 (@value{GDBP}) macro expand N Q M
10807 expands to: 28 < 42
10808 (@value{GDBP}) print N Q M
10809 $1 = 1
10810 (@value{GDBP})
10811 @end smallexample
10812
10813 As we step over directives that remove @code{N}'s definition, and then
10814 give it a new definition, @value{GDBN} finds the definition (or lack
10815 thereof) in force at each point:
10816
10817 @smallexample
10818 (@value{GDBP}) next
10819 Hello, world!
10820 12        printf ("We're so creative.\n");
10821 (@value{GDBP}) info macro N
10822 The symbol `N' has no definition as a C/C++ preprocessor macro
10823 at /home/jimb/gdb/macros/play/sample.c:12
10824 (@value{GDBP}) next
10825 We're so creative.
10826 14        printf ("Goodbye, world!\n");
10827 (@value{GDBP}) info macro N
10828 Defined at /home/jimb/gdb/macros/play/sample.c:13
10829 #define N 1729
10830 (@value{GDBP}) macro expand N Q M
10831 expands to: 1729 < 42
10832 (@value{GDBP}) print N Q M
10833 $2 = 0
10834 (@value{GDBP})
10835 @end smallexample
10836
10837 In addition to source files, macros can be defined on the compilation command
10838 line using the @option{-D@var{name}=@var{value}} syntax.  For macros defined in
10839 such a way, @value{GDBN} displays the location of their definition as line zero
10840 of the source file submitted to the compiler.
10841
10842 @smallexample
10843 (@value{GDBP}) info macro __STDC__
10844 Defined at /home/jimb/gdb/macros/play/sample.c:0
10845 -D__STDC__=1
10846 (@value{GDBP})
10847 @end smallexample
10848
10849
10850 @node Tracepoints
10851 @chapter Tracepoints
10852 @c This chapter is based on the documentation written by Michael
10853 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
10854
10855 @cindex tracepoints
10856 In some applications, it is not feasible for the debugger to interrupt
10857 the program's execution long enough for the developer to learn
10858 anything helpful about its behavior.  If the program's correctness
10859 depends on its real-time behavior, delays introduced by a debugger
10860 might cause the program to change its behavior drastically, or perhaps
10861 fail, even when the code itself is correct.  It is useful to be able
10862 to observe the program's behavior without interrupting it.
10863
10864 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
10865 specify locations in the program, called @dfn{tracepoints}, and
10866 arbitrary expressions to evaluate when those tracepoints are reached.
10867 Later, using the @code{tfind} command, you can examine the values
10868 those expressions had when the program hit the tracepoints.  The
10869 expressions may also denote objects in memory---structures or arrays,
10870 for example---whose values @value{GDBN} should record; while visiting
10871 a particular tracepoint, you may inspect those objects as if they were
10872 in memory at that moment.  However, because @value{GDBN} records these
10873 values without interacting with you, it can do so quickly and
10874 unobtrusively, hopefully not disturbing the program's behavior.
10875
10876 The tracepoint facility is currently available only for remote
10877 targets.  @xref{Targets}.  In addition, your remote target must know
10878 how to collect trace data.  This functionality is implemented in the
10879 remote stub; however, none of the stubs distributed with @value{GDBN}
10880 support tracepoints as of this writing.  The format of the remote
10881 packets used to implement tracepoints are described in @ref{Tracepoint
10882 Packets}.
10883
10884 It is also possible to get trace data from a file, in a manner reminiscent
10885 of corefiles; you specify the filename, and use @code{tfind} to search
10886 through the file.  @xref{Trace Files}, for more details.
10887
10888 This chapter describes the tracepoint commands and features.
10889
10890 @menu
10891 * Set Tracepoints::
10892 * Analyze Collected Data::
10893 * Tracepoint Variables::
10894 * Trace Files::
10895 @end menu
10896
10897 @node Set Tracepoints
10898 @section Commands to Set Tracepoints
10899
10900 Before running such a @dfn{trace experiment}, an arbitrary number of
10901 tracepoints can be set.  A tracepoint is actually a special type of
10902 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
10903 standard breakpoint commands.  For instance, as with breakpoints,
10904 tracepoint numbers are successive integers starting from one, and many
10905 of the commands associated with tracepoints take the tracepoint number
10906 as their argument, to identify which tracepoint to work on.
10907
10908 For each tracepoint, you can specify, in advance, some arbitrary set
10909 of data that you want the target to collect in the trace buffer when
10910 it hits that tracepoint.  The collected data can include registers,
10911 local variables, or global data.  Later, you can use @value{GDBN}
10912 commands to examine the values these data had at the time the
10913 tracepoint was hit.
10914
10915 Tracepoints do not support every breakpoint feature.  Ignore counts on
10916 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
10917 commands when they are hit.  Tracepoints may not be thread-specific
10918 either.
10919
10920 @cindex fast tracepoints
10921 Some targets may support @dfn{fast tracepoints}, which are inserted in
10922 a different way (such as with a jump instead of a trap), that is
10923 faster but possibly restricted in where they may be installed.
10924
10925 @cindex static tracepoints
10926 @cindex markers, static tracepoints
10927 @cindex probing markers, static tracepoints
10928 Regular and fast tracepoints are dynamic tracing facilities, meaning
10929 that they can be used to insert tracepoints at (almost) any location
10930 in the target.  Some targets may also support controlling @dfn{static
10931 tracepoints} from @value{GDBN}.  With static tracing, a set of
10932 instrumentation points, also known as @dfn{markers}, are embedded in
10933 the target program, and can be activated or deactivated by name or
10934 address.  These are usually placed at locations which facilitate
10935 investigating what the target is actually doing.  @value{GDBN}'s
10936 support for static tracing includes being able to list instrumentation
10937 points, and attach them with @value{GDBN} defined high level
10938 tracepoints that expose the whole range of convenience of
10939 @value{GDBN}'s tracepoints support.  Namely, support for collecting
10940 registers values and values of global or local (to the instrumentation
10941 point) variables; tracepoint conditions and trace state variables.
10942 The act of installing a @value{GDBN} static tracepoint on an
10943 instrumentation point, or marker, is referred to as @dfn{probing} a
10944 static tracepoint marker.
10945
10946 @code{gdbserver} supports tracepoints on some target systems.
10947 @xref{Server,,Tracepoints support in @code{gdbserver}}.
10948
10949 This section describes commands to set tracepoints and associated
10950 conditions and actions.
10951
10952 @menu
10953 * Create and Delete Tracepoints::
10954 * Enable and Disable Tracepoints::
10955 * Tracepoint Passcounts::
10956 * Tracepoint Conditions::
10957 * Trace State Variables::
10958 * Tracepoint Actions::
10959 * Listing Tracepoints::
10960 * Listing Static Tracepoint Markers::
10961 * Starting and Stopping Trace Experiments::
10962 * Tracepoint Restrictions::
10963 @end menu
10964
10965 @node Create and Delete Tracepoints
10966 @subsection Create and Delete Tracepoints
10967
10968 @table @code
10969 @cindex set tracepoint
10970 @kindex trace
10971 @item trace @var{location}
10972 The @code{trace} command is very similar to the @code{break} command.
10973 Its argument @var{location} can be a source line, a function name, or
10974 an address in the target program.  @xref{Specify Location}.  The
10975 @code{trace} command defines a tracepoint, which is a point in the
10976 target program where the debugger will briefly stop, collect some
10977 data, and then allow the program to continue.  Setting a tracepoint or
10978 changing its actions takes effect immediately if the remote stub
10979 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
10980 in tracing}).
10981 If remote stub doesn't support the @samp{InstallInTrace} feature, all
10982 these changes don't take effect until the next @code{tstart}
10983 command, and once a trace experiment is running, further changes will
10984 not have any effect until the next trace experiment starts.  In addition,
10985 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
10986 address is not yet resolved.  (This is similar to pending breakpoints.)
10987 Pending tracepoints are not downloaded to the target and not installed
10988 until they are resolved.  The resolution of pending tracepoints requires
10989 @value{GDBN} support---when debugging with the remote target, and
10990 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
10991 tracing}), pending tracepoints can not be resolved (and downloaded to
10992 the remote stub) while @value{GDBN} is disconnected.
10993
10994 Here are some examples of using the @code{trace} command:
10995
10996 @smallexample
10997 (@value{GDBP}) @b{trace foo.c:121}    // a source file and line number
10998
10999 (@value{GDBP}) @b{trace +2}           // 2 lines forward
11000
11001 (@value{GDBP}) @b{trace my_function}  // first source line of function
11002
11003 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
11004
11005 (@value{GDBP}) @b{trace *0x2117c4}    // an address
11006 @end smallexample
11007
11008 @noindent
11009 You can abbreviate @code{trace} as @code{tr}.
11010
11011 @item trace @var{location} if @var{cond}
11012 Set a tracepoint with condition @var{cond}; evaluate the expression
11013 @var{cond} each time the tracepoint is reached, and collect data only
11014 if the value is nonzero---that is, if @var{cond} evaluates as true.
11015 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
11016 information on tracepoint conditions.
11017
11018 @item ftrace @var{location} [ if @var{cond} ]
11019 @cindex set fast tracepoint
11020 @cindex fast tracepoints, setting
11021 @kindex ftrace
11022 The @code{ftrace} command sets a fast tracepoint.  For targets that
11023 support them, fast tracepoints will use a more efficient but possibly
11024 less general technique to trigger data collection, such as a jump
11025 instruction instead of a trap, or some sort of hardware support.  It
11026 may not be possible to create a fast tracepoint at the desired
11027 location, in which case the command will exit with an explanatory
11028 message.
11029
11030 @value{GDBN} handles arguments to @code{ftrace} exactly as for
11031 @code{trace}.
11032
11033 On 32-bit x86-architecture systems, fast tracepoints normally need to
11034 be placed at an instruction that is 5 bytes or longer, but can be
11035 placed at 4-byte instructions if the low 64K of memory of the target
11036 program is available to install trampolines.  Some Unix-type systems,
11037 such as @sc{gnu}/Linux, exclude low addresses from the program's
11038 address space; but for instance with the Linux kernel it is possible
11039 to let @value{GDBN} use this area by doing a @command{sysctl} command
11040 to set the @code{mmap_min_addr} kernel parameter, as in
11041
11042 @example
11043 sudo sysctl -w vm.mmap_min_addr=32768
11044 @end example
11045
11046 @noindent
11047 which sets the low address to 32K, which leaves plenty of room for
11048 trampolines.  The minimum address should be set to a page boundary.
11049
11050 @item strace @var{location} [ if @var{cond} ]
11051 @cindex set static tracepoint
11052 @cindex static tracepoints, setting
11053 @cindex probe static tracepoint marker
11054 @kindex strace
11055 The @code{strace} command sets a static tracepoint.  For targets that
11056 support it, setting a static tracepoint probes a static
11057 instrumentation point, or marker, found at @var{location}.  It may not
11058 be possible to set a static tracepoint at the desired location, in
11059 which case the command will exit with an explanatory message.
11060
11061 @value{GDBN} handles arguments to @code{strace} exactly as for
11062 @code{trace}, with the addition that the user can also specify
11063 @code{-m @var{marker}} as @var{location}.  This probes the marker
11064 identified by the @var{marker} string identifier.  This identifier
11065 depends on the static tracepoint backend library your program is
11066 using.  You can find all the marker identifiers in the @samp{ID} field
11067 of the @code{info static-tracepoint-markers} command output.
11068 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
11069 Markers}.  For example, in the following small program using the UST
11070 tracing engine:
11071
11072 @smallexample
11073 main ()
11074 @{
11075   trace_mark(ust, bar33, "str %s", "FOOBAZ");
11076 @}
11077 @end smallexample
11078
11079 @noindent
11080 the marker id is composed of joining the first two arguments to the
11081 @code{trace_mark} call with a slash, which translates to:
11082
11083 @smallexample
11084 (@value{GDBP}) info static-tracepoint-markers
11085 Cnt Enb ID         Address            What
11086 1   n   ust/bar33  0x0000000000400ddc in main at stexample.c:22
11087          Data: "str %s"
11088 [etc...]
11089 @end smallexample
11090
11091 @noindent
11092 so you may probe the marker above with:
11093
11094 @smallexample
11095 (@value{GDBP}) strace -m ust/bar33
11096 @end smallexample
11097
11098 Static tracepoints accept an extra collect action --- @code{collect
11099 $_sdata}.  This collects arbitrary user data passed in the probe point
11100 call to the tracing library.  In the UST example above, you'll see
11101 that the third argument to @code{trace_mark} is a printf-like format
11102 string.  The user data is then the result of running that formating
11103 string against the following arguments.  Note that @code{info
11104 static-tracepoint-markers} command output lists that format string in
11105 the @samp{Data:} field.
11106
11107 You can inspect this data when analyzing the trace buffer, by printing
11108 the $_sdata variable like any other variable available to
11109 @value{GDBN}.  @xref{Tracepoint Actions,,Tracepoint Action Lists}.
11110
11111 @vindex $tpnum
11112 @cindex last tracepoint number
11113 @cindex recent tracepoint number
11114 @cindex tracepoint number
11115 The convenience variable @code{$tpnum} records the tracepoint number
11116 of the most recently set tracepoint.
11117
11118 @kindex delete tracepoint
11119 @cindex tracepoint deletion
11120 @item delete tracepoint @r{[}@var{num}@r{]}
11121 Permanently delete one or more tracepoints.  With no argument, the
11122 default is to delete all tracepoints.  Note that the regular
11123 @code{delete} command can remove tracepoints also.
11124
11125 Examples:
11126
11127 @smallexample
11128 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
11129
11130 (@value{GDBP}) @b{delete trace}       // remove all tracepoints
11131 @end smallexample
11132
11133 @noindent
11134 You can abbreviate this command as @code{del tr}.
11135 @end table
11136
11137 @node Enable and Disable Tracepoints
11138 @subsection Enable and Disable Tracepoints
11139
11140 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
11141
11142 @table @code
11143 @kindex disable tracepoint
11144 @item disable tracepoint @r{[}@var{num}@r{]}
11145 Disable tracepoint @var{num}, or all tracepoints if no argument
11146 @var{num} is given.  A disabled tracepoint will have no effect during
11147 a trace experiment, but it is not forgotten.  You can re-enable
11148 a disabled tracepoint using the @code{enable tracepoint} command.
11149 If the command is issued during a trace experiment and the debug target
11150 has support for disabling tracepoints during a trace experiment, then the
11151 change will be effective immediately.  Otherwise, it will be applied to the
11152 next trace experiment.
11153
11154 @kindex enable tracepoint
11155 @item enable tracepoint @r{[}@var{num}@r{]}
11156 Enable tracepoint @var{num}, or all tracepoints.  If this command is
11157 issued during a trace experiment and the debug target supports enabling
11158 tracepoints during a trace experiment, then the enabled tracepoints will
11159 become effective immediately.  Otherwise, they will become effective the
11160 next time a trace experiment is run.
11161 @end table
11162
11163 @node Tracepoint Passcounts
11164 @subsection Tracepoint Passcounts
11165
11166 @table @code
11167 @kindex passcount
11168 @cindex tracepoint pass count
11169 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
11170 Set the @dfn{passcount} of a tracepoint.  The passcount is a way to
11171 automatically stop a trace experiment.  If a tracepoint's passcount is
11172 @var{n}, then the trace experiment will be automatically stopped on
11173 the @var{n}'th time that tracepoint is hit.  If the tracepoint number
11174 @var{num} is not specified, the @code{passcount} command sets the
11175 passcount of the most recently defined tracepoint.  If no passcount is
11176 given, the trace experiment will run until stopped explicitly by the
11177 user.
11178
11179 Examples:
11180
11181 @smallexample
11182 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
11183 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
11184
11185 (@value{GDBP}) @b{passcount 12}  // Stop on the 12th execution of the
11186 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
11187 (@value{GDBP}) @b{trace foo}
11188 (@value{GDBP}) @b{pass 3}
11189 (@value{GDBP}) @b{trace bar}
11190 (@value{GDBP}) @b{pass 2}
11191 (@value{GDBP}) @b{trace baz}
11192 (@value{GDBP}) @b{pass 1}        // Stop tracing when foo has been
11193 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
11194 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
11195 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
11196 @end smallexample
11197 @end table
11198
11199 @node Tracepoint Conditions
11200 @subsection Tracepoint Conditions
11201 @cindex conditional tracepoints
11202 @cindex tracepoint conditions
11203
11204 The simplest sort of tracepoint collects data every time your program
11205 reaches a specified place.  You can also specify a @dfn{condition} for
11206 a tracepoint.  A condition is just a Boolean expression in your
11207 programming language (@pxref{Expressions, ,Expressions}).  A
11208 tracepoint with a condition evaluates the expression each time your
11209 program reaches it, and data collection happens only if the condition
11210 is true.
11211
11212 Tracepoint conditions can be specified when a tracepoint is set, by
11213 using @samp{if} in the arguments to the @code{trace} command.
11214 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}.  They can
11215 also be set or changed at any time with the @code{condition} command,
11216 just as with breakpoints.
11217
11218 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
11219 the conditional expression itself.  Instead, @value{GDBN} encodes the
11220 expression into an agent expression (@pxref{Agent Expressions})
11221 suitable for execution on the target, independently of @value{GDBN}.
11222 Global variables become raw memory locations, locals become stack
11223 accesses, and so forth.
11224
11225 For instance, suppose you have a function that is usually called
11226 frequently, but should not be called after an error has occurred.  You
11227 could use the following tracepoint command to collect data about calls
11228 of that function that happen while the error code is propagating
11229 through the program; an unconditional tracepoint could end up
11230 collecting thousands of useless trace frames that you would have to
11231 search through.
11232
11233 @smallexample
11234 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
11235 @end smallexample
11236
11237 @node Trace State Variables
11238 @subsection Trace State Variables
11239 @cindex trace state variables
11240
11241 A @dfn{trace state variable} is a special type of variable that is
11242 created and managed by target-side code.  The syntax is the same as
11243 that for GDB's convenience variables (a string prefixed with ``$''),
11244 but they are stored on the target.  They must be created explicitly,
11245 using a @code{tvariable} command.  They are always 64-bit signed
11246 integers.
11247
11248 Trace state variables are remembered by @value{GDBN}, and downloaded
11249 to the target along with tracepoint information when the trace
11250 experiment starts.  There are no intrinsic limits on the number of
11251 trace state variables, beyond memory limitations of the target.
11252
11253 @cindex convenience variables, and trace state variables
11254 Although trace state variables are managed by the target, you can use
11255 them in print commands and expressions as if they were convenience
11256 variables; @value{GDBN} will get the current value from the target
11257 while the trace experiment is running.  Trace state variables share
11258 the same namespace as other ``$'' variables, which means that you
11259 cannot have trace state variables with names like @code{$23} or
11260 @code{$pc}, nor can you have a trace state variable and a convenience
11261 variable with the same name.
11262
11263 @table @code
11264
11265 @item tvariable $@var{name} [ = @var{expression} ]
11266 @kindex tvariable
11267 The @code{tvariable} command creates a new trace state variable named
11268 @code{$@var{name}}, and optionally gives it an initial value of
11269 @var{expression}.  @var{expression} is evaluated when this command is
11270 entered; the result will be converted to an integer if possible,
11271 otherwise @value{GDBN} will report an error. A subsequent
11272 @code{tvariable} command specifying the same name does not create a
11273 variable, but instead assigns the supplied initial value to the
11274 existing variable of that name, overwriting any previous initial
11275 value. The default initial value is 0.
11276
11277 @item info tvariables
11278 @kindex info tvariables
11279 List all the trace state variables along with their initial values.
11280 Their current values may also be displayed, if the trace experiment is
11281 currently running.
11282
11283 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
11284 @kindex delete tvariable
11285 Delete the given trace state variables, or all of them if no arguments
11286 are specified.
11287
11288 @end table
11289
11290 @node Tracepoint Actions
11291 @subsection Tracepoint Action Lists
11292
11293 @table @code
11294 @kindex actions
11295 @cindex tracepoint actions
11296 @item actions @r{[}@var{num}@r{]}
11297 This command will prompt for a list of actions to be taken when the
11298 tracepoint is hit.  If the tracepoint number @var{num} is not
11299 specified, this command sets the actions for the one that was most
11300 recently defined (so that you can define a tracepoint and then say
11301 @code{actions} without bothering about its number).  You specify the
11302 actions themselves on the following lines, one action at a time, and
11303 terminate the actions list with a line containing just @code{end}.  So
11304 far, the only defined actions are @code{collect}, @code{teval}, and
11305 @code{while-stepping}.
11306
11307 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
11308 Commands, ,Breakpoint Command Lists}), except that only the defined
11309 actions are allowed; any other @value{GDBN} command is rejected.
11310
11311 @cindex remove actions from a tracepoint
11312 To remove all actions from a tracepoint, type @samp{actions @var{num}}
11313 and follow it immediately with @samp{end}.
11314
11315 @smallexample
11316 (@value{GDBP}) @b{collect @var{data}} // collect some data
11317
11318 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
11319
11320 (@value{GDBP}) @b{end}              // signals the end of actions.
11321 @end smallexample
11322
11323 In the following example, the action list begins with @code{collect}
11324 commands indicating the things to be collected when the tracepoint is
11325 hit.  Then, in order to single-step and collect additional data
11326 following the tracepoint, a @code{while-stepping} command is used,
11327 followed by the list of things to be collected after each step in a
11328 sequence of single steps.  The @code{while-stepping} command is
11329 terminated by its own separate @code{end} command.  Lastly, the action
11330 list is terminated by an @code{end} command.
11331
11332 @smallexample
11333 (@value{GDBP}) @b{trace foo}
11334 (@value{GDBP}) @b{actions}
11335 Enter actions for tracepoint 1, one per line:
11336 > collect bar,baz
11337 > collect $regs
11338 > while-stepping 12
11339   > collect $pc, arr[i]
11340   > end
11341 end
11342 @end smallexample
11343
11344 @kindex collect @r{(tracepoints)}
11345 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
11346 Collect values of the given expressions when the tracepoint is hit.
11347 This command accepts a comma-separated list of any valid expressions.
11348 In addition to global, static, or local variables, the following
11349 special arguments are supported:
11350
11351 @table @code
11352 @item $regs
11353 Collect all registers.
11354
11355 @item $args
11356 Collect all function arguments.
11357
11358 @item $locals
11359 Collect all local variables.
11360
11361 @item $_ret
11362 Collect the return address.  This is helpful if you want to see more
11363 of a backtrace.
11364
11365 @item $_probe_argc
11366 Collects the number of arguments from the static probe at which the
11367 tracepoint is located.
11368 @xref{Static Probe Points}.
11369
11370 @item $_probe_arg@var{n}
11371 @var{n} is an integer between 0 and 11.  Collects the @var{n}th argument
11372 from the static probe at which the tracepoint is located.
11373 @xref{Static Probe Points}.
11374
11375 @item $_sdata
11376 @vindex $_sdata@r{, collect}
11377 Collect static tracepoint marker specific data.  Only available for
11378 static tracepoints.  @xref{Tracepoint Actions,,Tracepoint Action
11379 Lists}.  On the UST static tracepoints library backend, an
11380 instrumentation point resembles a @code{printf} function call.  The
11381 tracing library is able to collect user specified data formatted to a
11382 character string using the format provided by the programmer that
11383 instrumented the program.  Other backends have similar mechanisms.
11384 Here's an example of a UST marker call:
11385
11386 @smallexample
11387  const char master_name[] = "$your_name";
11388  trace_mark(channel1, marker1, "hello %s", master_name)
11389 @end smallexample
11390
11391 In this case, collecting @code{$_sdata} collects the string
11392 @samp{hello $yourname}.  When analyzing the trace buffer, you can
11393 inspect @samp{$_sdata} like any other variable available to
11394 @value{GDBN}.
11395 @end table
11396
11397 You can give several consecutive @code{collect} commands, each one
11398 with a single argument, or one @code{collect} command with several
11399 arguments separated by commas; the effect is the same.
11400
11401 The optional @var{mods} changes the usual handling of the arguments.
11402 @code{s} requests that pointers to chars be handled as strings, in
11403 particular collecting the contents of the memory being pointed at, up
11404 to the first zero.  The upper bound is by default the value of the
11405 @code{print elements} variable; if @code{s} is followed by a decimal
11406 number, that is the upper bound instead.  So for instance
11407 @samp{collect/s25 mystr} collects as many as 25 characters at
11408 @samp{mystr}.
11409
11410 The command @code{info scope} (@pxref{Symbols, info scope}) is
11411 particularly useful for figuring out what data to collect.
11412
11413 @kindex teval @r{(tracepoints)}
11414 @item teval @var{expr1}, @var{expr2}, @dots{}
11415 Evaluate the given expressions when the tracepoint is hit.  This
11416 command accepts a comma-separated list of expressions.  The results
11417 are discarded, so this is mainly useful for assigning values to trace
11418 state variables (@pxref{Trace State Variables}) without adding those
11419 values to the trace buffer, as would be the case if the @code{collect}
11420 action were used.
11421
11422 @kindex while-stepping @r{(tracepoints)}
11423 @item while-stepping @var{n}
11424 Perform @var{n} single-step instruction traces after the tracepoint,
11425 collecting new data after each step.  The @code{while-stepping}
11426 command is followed by the list of what to collect while stepping
11427 (followed by its own @code{end} command):
11428
11429 @smallexample
11430 > while-stepping 12
11431   > collect $regs, myglobal
11432   > end
11433 >
11434 @end smallexample
11435
11436 @noindent
11437 Note that @code{$pc} is not automatically collected by
11438 @code{while-stepping}; you need to explicitly collect that register if
11439 you need it.  You may abbreviate @code{while-stepping} as @code{ws} or
11440 @code{stepping}.
11441
11442 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
11443 @kindex set default-collect
11444 @cindex default collection action
11445 This variable is a list of expressions to collect at each tracepoint
11446 hit.  It is effectively an additional @code{collect} action prepended
11447 to every tracepoint action list.  The expressions are parsed
11448 individually for each tracepoint, so for instance a variable named
11449 @code{xyz} may be interpreted as a global for one tracepoint, and a
11450 local for another, as appropriate to the tracepoint's location.
11451
11452 @item show default-collect
11453 @kindex show default-collect
11454 Show the list of expressions that are collected by default at each
11455 tracepoint hit.
11456
11457 @end table
11458
11459 @node Listing Tracepoints
11460 @subsection Listing Tracepoints
11461
11462 @table @code
11463 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
11464 @kindex info tp @r{[}@var{n}@dots{}@r{]}
11465 @cindex information about tracepoints
11466 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
11467 Display information about the tracepoint @var{num}.  If you don't
11468 specify a tracepoint number, displays information about all the
11469 tracepoints defined so far.  The format is similar to that used for
11470 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
11471 command, simply restricting itself to tracepoints.
11472
11473 A tracepoint's listing may include additional information specific to
11474 tracing:
11475
11476 @itemize @bullet
11477 @item
11478 its passcount as given by the @code{passcount @var{n}} command
11479
11480 @item
11481 the state about installed on target of each location
11482 @end itemize
11483
11484 @smallexample
11485 (@value{GDBP}) @b{info trace}
11486 Num     Type           Disp Enb Address    What
11487 1       tracepoint     keep y   0x0804ab57 in foo() at main.cxx:7
11488         while-stepping 20
11489           collect globfoo, $regs
11490         end
11491         collect globfoo2
11492         end
11493         pass count 1200 
11494 2       tracepoint     keep y   <MULTIPLE>
11495         collect $eip
11496 2.1                         y     0x0804859c in func4 at change-loc.h:35
11497         installed on target
11498 2.2                         y     0xb7ffc480 in func4 at change-loc.h:35
11499         installed on target
11500 2.3                         y     <PENDING>  set_tracepoint
11501 3       tracepoint     keep y   0x080485b1 in foo at change-loc.c:29
11502         not installed on target
11503 (@value{GDBP})
11504 @end smallexample
11505
11506 @noindent
11507 This command can be abbreviated @code{info tp}.
11508 @end table
11509
11510 @node Listing Static Tracepoint Markers
11511 @subsection Listing Static Tracepoint Markers
11512
11513 @table @code
11514 @kindex info static-tracepoint-markers
11515 @cindex information about static tracepoint markers
11516 @item info static-tracepoint-markers
11517 Display information about all static tracepoint markers defined in the
11518 program.
11519
11520 For each marker, the following columns are printed:
11521
11522 @table @emph
11523 @item Count
11524 An incrementing counter, output to help readability.  This is not a
11525 stable identifier.
11526 @item ID
11527 The marker ID, as reported by the target.
11528 @item Enabled or Disabled
11529 Probed markers are tagged with @samp{y}.  @samp{n} identifies marks
11530 that are not enabled.
11531 @item Address
11532 Where the marker is in your program, as a memory address.
11533 @item What
11534 Where the marker is in the source for your program, as a file and line
11535 number.  If the debug information included in the program does not
11536 allow @value{GDBN} to locate the source of the marker, this column
11537 will be left blank.
11538 @end table
11539
11540 @noindent
11541 In addition, the following information may be printed for each marker:
11542
11543 @table @emph
11544 @item Data
11545 User data passed to the tracing library by the marker call.  In the
11546 UST backend, this is the format string passed as argument to the
11547 marker call.
11548 @item Static tracepoints probing the marker
11549 The list of static tracepoints attached to the marker.
11550 @end table
11551
11552 @smallexample
11553 (@value{GDBP}) info static-tracepoint-markers
11554 Cnt ID         Enb Address            What
11555 1   ust/bar2   y   0x0000000000400e1a in main at stexample.c:25
11556      Data: number1 %d number2 %d
11557      Probed by static tracepoints: #2
11558 2   ust/bar33  n   0x0000000000400c87 in main at stexample.c:24
11559      Data: str %s
11560 (@value{GDBP})
11561 @end smallexample
11562 @end table
11563
11564 @node Starting and Stopping Trace Experiments
11565 @subsection Starting and Stopping Trace Experiments
11566
11567 @table @code
11568 @kindex tstart [ @var{notes} ]
11569 @cindex start a new trace experiment
11570 @cindex collected data discarded
11571 @item tstart
11572 This command starts the trace experiment, and begins collecting data.
11573 It has the side effect of discarding all the data collected in the
11574 trace buffer during the previous trace experiment.  If any arguments
11575 are supplied, they are taken as a note and stored with the trace
11576 experiment's state.  The notes may be arbitrary text, and are
11577 especially useful with disconnected tracing in a multi-user context;
11578 the notes can explain what the trace is doing, supply user contact
11579 information, and so forth.
11580
11581 @kindex tstop [ @var{notes} ]
11582 @cindex stop a running trace experiment
11583 @item tstop
11584 This command stops the trace experiment.  If any arguments are
11585 supplied, they are recorded with the experiment as a note.  This is
11586 useful if you are stopping a trace started by someone else, for
11587 instance if the trace is interfering with the system's behavior and
11588 needs to be stopped quickly.
11589
11590 @strong{Note}: a trace experiment and data collection may stop
11591 automatically if any tracepoint's passcount is reached
11592 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
11593
11594 @kindex tstatus
11595 @cindex status of trace data collection
11596 @cindex trace experiment, status of
11597 @item tstatus
11598 This command displays the status of the current trace data
11599 collection.
11600 @end table
11601
11602 Here is an example of the commands we described so far:
11603
11604 @smallexample
11605 (@value{GDBP}) @b{trace gdb_c_test}
11606 (@value{GDBP}) @b{actions}
11607 Enter actions for tracepoint #1, one per line.
11608 > collect $regs,$locals,$args
11609 > while-stepping 11
11610   > collect $regs
11611   > end
11612 > end
11613 (@value{GDBP}) @b{tstart}
11614         [time passes @dots{}]
11615 (@value{GDBP}) @b{tstop}
11616 @end smallexample
11617
11618 @anchor{disconnected tracing}
11619 @cindex disconnected tracing
11620 You can choose to continue running the trace experiment even if
11621 @value{GDBN} disconnects from the target, voluntarily or
11622 involuntarily.  For commands such as @code{detach}, the debugger will
11623 ask what you want to do with the trace.  But for unexpected
11624 terminations (@value{GDBN} crash, network outage), it would be
11625 unfortunate to lose hard-won trace data, so the variable
11626 @code{disconnected-tracing} lets you decide whether the trace should
11627 continue running without @value{GDBN}.
11628
11629 @table @code
11630 @item set disconnected-tracing on
11631 @itemx set disconnected-tracing off
11632 @kindex set disconnected-tracing
11633 Choose whether a tracing run should continue to run if @value{GDBN}
11634 has disconnected from the target.  Note that @code{detach} or
11635 @code{quit} will ask you directly what to do about a running trace no
11636 matter what this variable's setting, so the variable is mainly useful
11637 for handling unexpected situations, such as loss of the network.
11638
11639 @item show disconnected-tracing
11640 @kindex show disconnected-tracing
11641 Show the current choice for disconnected tracing.
11642
11643 @end table
11644
11645 When you reconnect to the target, the trace experiment may or may not
11646 still be running; it might have filled the trace buffer in the
11647 meantime, or stopped for one of the other reasons.  If it is running,
11648 it will continue after reconnection.
11649
11650 Upon reconnection, the target will upload information about the
11651 tracepoints in effect.  @value{GDBN} will then compare that
11652 information to the set of tracepoints currently defined, and attempt
11653 to match them up, allowing for the possibility that the numbers may
11654 have changed due to creation and deletion in the meantime.  If one of
11655 the target's tracepoints does not match any in @value{GDBN}, the
11656 debugger will create a new tracepoint, so that you have a number with
11657 which to specify that tracepoint.  This matching-up process is
11658 necessarily heuristic, and it may result in useless tracepoints being
11659 created; you may simply delete them if they are of no use.
11660
11661 @cindex circular trace buffer
11662 If your target agent supports a @dfn{circular trace buffer}, then you
11663 can run a trace experiment indefinitely without filling the trace
11664 buffer; when space runs out, the agent deletes already-collected trace
11665 frames, oldest first, until there is enough room to continue
11666 collecting.  This is especially useful if your tracepoints are being
11667 hit too often, and your trace gets terminated prematurely because the
11668 buffer is full.  To ask for a circular trace buffer, simply set
11669 @samp{circular-trace-buffer} to on.  You can set this at any time,
11670 including during tracing; if the agent can do it, it will change
11671 buffer handling on the fly, otherwise it will not take effect until
11672 the next run.
11673
11674 @table @code
11675 @item set circular-trace-buffer on
11676 @itemx set circular-trace-buffer off
11677 @kindex set circular-trace-buffer
11678 Choose whether a tracing run should use a linear or circular buffer
11679 for trace data.  A linear buffer will not lose any trace data, but may
11680 fill up prematurely, while a circular buffer will discard old trace
11681 data, but it will have always room for the latest tracepoint hits.
11682
11683 @item show circular-trace-buffer
11684 @kindex show circular-trace-buffer
11685 Show the current choice for the trace buffer.  Note that this may not
11686 match the agent's current buffer handling, nor is it guaranteed to
11687 match the setting that might have been in effect during a past run,
11688 for instance if you are looking at frames from a trace file.
11689
11690 @end table
11691
11692 @table @code
11693 @item set trace-user @var{text}
11694 @kindex set trace-user
11695
11696 @item show trace-user
11697 @kindex show trace-user
11698
11699 @item set trace-notes @var{text}
11700 @kindex set trace-notes
11701 Set the trace run's notes.
11702
11703 @item show trace-notes
11704 @kindex show trace-notes
11705 Show the trace run's notes.
11706
11707 @item set trace-stop-notes @var{text}
11708 @kindex set trace-stop-notes
11709 Set the trace run's stop notes.  The handling of the note is as for
11710 @code{tstop} arguments; the set command is convenient way to fix a
11711 stop note that is mistaken or incomplete.
11712
11713 @item show trace-stop-notes
11714 @kindex show trace-stop-notes
11715 Show the trace run's stop notes.
11716
11717 @end table
11718
11719 @node Tracepoint Restrictions
11720 @subsection Tracepoint Restrictions
11721
11722 @cindex tracepoint restrictions
11723 There are a number of restrictions on the use of tracepoints.  As
11724 described above, tracepoint data gathering occurs on the target
11725 without interaction from @value{GDBN}.  Thus the full capabilities of
11726 the debugger are not available during data gathering, and then at data
11727 examination time, you will be limited by only having what was
11728 collected.  The following items describe some common problems, but it
11729 is not exhaustive, and you may run into additional difficulties not
11730 mentioned here.
11731
11732 @itemize @bullet
11733
11734 @item
11735 Tracepoint expressions are intended to gather objects (lvalues).  Thus
11736 the full flexibility of GDB's expression evaluator is not available.
11737 You cannot call functions, cast objects to aggregate types, access
11738 convenience variables or modify values (except by assignment to trace
11739 state variables).  Some language features may implicitly call
11740 functions (for instance Objective-C fields with accessors), and therefore
11741 cannot be collected either.
11742
11743 @item
11744 Collection of local variables, either individually or in bulk with
11745 @code{$locals} or @code{$args}, during @code{while-stepping} may
11746 behave erratically.  The stepping action may enter a new scope (for
11747 instance by stepping into a function), or the location of the variable
11748 may change (for instance it is loaded into a register).  The
11749 tracepoint data recorded uses the location information for the
11750 variables that is correct for the tracepoint location.  When the
11751 tracepoint is created, it is not possible, in general, to determine
11752 where the steps of a @code{while-stepping} sequence will advance the
11753 program---particularly if a conditional branch is stepped.
11754
11755 @item
11756 Collection of an incompletely-initialized or partially-destroyed object
11757 may result in something that @value{GDBN} cannot display, or displays
11758 in a misleading way.
11759
11760 @item
11761 When @value{GDBN} displays a pointer to character it automatically
11762 dereferences the pointer to also display characters of the string
11763 being pointed to.  However, collecting the pointer during tracing does
11764 not automatically collect the string.  You need to explicitly
11765 dereference the pointer and provide size information if you want to
11766 collect not only the pointer, but the memory pointed to.  For example,
11767 @code{*ptr@@50} can be used to collect the 50 element array pointed to
11768 by @code{ptr}.
11769
11770 @item
11771 It is not possible to collect a complete stack backtrace at a
11772 tracepoint.  Instead, you may collect the registers and a few hundred
11773 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
11774 (adjust to use the name of the actual stack pointer register on your
11775 target architecture, and the amount of stack you wish to capture).
11776 Then the @code{backtrace} command will show a partial backtrace when
11777 using a trace frame.  The number of stack frames that can be examined
11778 depends on the sizes of the frames in the collected stack.  Note that
11779 if you ask for a block so large that it goes past the bottom of the
11780 stack, the target agent may report an error trying to read from an
11781 invalid address.
11782
11783 @item
11784 If you do not collect registers at a tracepoint, @value{GDBN} can
11785 infer that the value of @code{$pc} must be the same as the address of
11786 the tracepoint and use that when you are looking at a trace frame
11787 for that tracepoint.  However, this cannot work if the tracepoint has
11788 multiple locations (for instance if it was set in a function that was
11789 inlined), or if it has a @code{while-stepping} loop.  In those cases
11790 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
11791 it to zero.
11792
11793 @end itemize
11794
11795 @node Analyze Collected Data
11796 @section Using the Collected Data
11797
11798 After the tracepoint experiment ends, you use @value{GDBN} commands
11799 for examining the trace data.  The basic idea is that each tracepoint
11800 collects a trace @dfn{snapshot} every time it is hit and another
11801 snapshot every time it single-steps.  All these snapshots are
11802 consecutively numbered from zero and go into a buffer, and you can
11803 examine them later.  The way you examine them is to @dfn{focus} on a
11804 specific trace snapshot.  When the remote stub is focused on a trace
11805 snapshot, it will respond to all @value{GDBN} requests for memory and
11806 registers by reading from the buffer which belongs to that snapshot,
11807 rather than from @emph{real} memory or registers of the program being
11808 debugged.  This means that @strong{all} @value{GDBN} commands
11809 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
11810 behave as if we were currently debugging the program state as it was
11811 when the tracepoint occurred.  Any requests for data that are not in
11812 the buffer will fail.
11813
11814 @menu
11815 * tfind::                       How to select a trace snapshot
11816 * tdump::                       How to display all data for a snapshot
11817 * save tracepoints::            How to save tracepoints for a future run
11818 @end menu
11819
11820 @node tfind
11821 @subsection @code{tfind @var{n}}
11822
11823 @kindex tfind
11824 @cindex select trace snapshot
11825 @cindex find trace snapshot
11826 The basic command for selecting a trace snapshot from the buffer is
11827 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
11828 counting from zero.  If no argument @var{n} is given, the next
11829 snapshot is selected.
11830
11831 Here are the various forms of using the @code{tfind} command.
11832
11833 @table @code
11834 @item tfind start
11835 Find the first snapshot in the buffer.  This is a synonym for
11836 @code{tfind 0} (since 0 is the number of the first snapshot).
11837
11838 @item tfind none
11839 Stop debugging trace snapshots, resume @emph{live} debugging.
11840
11841 @item tfind end
11842 Same as @samp{tfind none}.
11843
11844 @item tfind
11845 No argument means find the next trace snapshot.
11846
11847 @item tfind -
11848 Find the previous trace snapshot before the current one.  This permits
11849 retracing earlier steps.
11850
11851 @item tfind tracepoint @var{num}
11852 Find the next snapshot associated with tracepoint @var{num}.  Search
11853 proceeds forward from the last examined trace snapshot.  If no
11854 argument @var{num} is given, it means find the next snapshot collected
11855 for the same tracepoint as the current snapshot.
11856
11857 @item tfind pc @var{addr}
11858 Find the next snapshot associated with the value @var{addr} of the
11859 program counter.  Search proceeds forward from the last examined trace
11860 snapshot.  If no argument @var{addr} is given, it means find the next
11861 snapshot with the same value of PC as the current snapshot.
11862
11863 @item tfind outside @var{addr1}, @var{addr2}
11864 Find the next snapshot whose PC is outside the given range of
11865 addresses (exclusive).
11866
11867 @item tfind range @var{addr1}, @var{addr2}
11868 Find the next snapshot whose PC is between @var{addr1} and
11869 @var{addr2} (inclusive).
11870
11871 @item tfind line @r{[}@var{file}:@r{]}@var{n}
11872 Find the next snapshot associated with the source line @var{n}.  If
11873 the optional argument @var{file} is given, refer to line @var{n} in
11874 that source file.  Search proceeds forward from the last examined
11875 trace snapshot.  If no argument @var{n} is given, it means find the
11876 next line other than the one currently being examined; thus saying
11877 @code{tfind line} repeatedly can appear to have the same effect as
11878 stepping from line to line in a @emph{live} debugging session.
11879 @end table
11880
11881 The default arguments for the @code{tfind} commands are specifically
11882 designed to make it easy to scan through the trace buffer.  For
11883 instance, @code{tfind} with no argument selects the next trace
11884 snapshot, and @code{tfind -} with no argument selects the previous
11885 trace snapshot.  So, by giving one @code{tfind} command, and then
11886 simply hitting @key{RET} repeatedly you can examine all the trace
11887 snapshots in order.  Or, by saying @code{tfind -} and then hitting
11888 @key{RET} repeatedly you can examine the snapshots in reverse order.
11889 The @code{tfind line} command with no argument selects the snapshot
11890 for the next source line executed.  The @code{tfind pc} command with
11891 no argument selects the next snapshot with the same program counter
11892 (PC) as the current frame.  The @code{tfind tracepoint} command with
11893 no argument selects the next trace snapshot collected by the same
11894 tracepoint as the current one.
11895
11896 In addition to letting you scan through the trace buffer manually,
11897 these commands make it easy to construct @value{GDBN} scripts that
11898 scan through the trace buffer and print out whatever collected data
11899 you are interested in.  Thus, if we want to examine the PC, FP, and SP
11900 registers from each trace frame in the buffer, we can say this:
11901
11902 @smallexample
11903 (@value{GDBP}) @b{tfind start}
11904 (@value{GDBP}) @b{while ($trace_frame != -1)}
11905 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
11906           $trace_frame, $pc, $sp, $fp
11907 > tfind
11908 > end
11909
11910 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
11911 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
11912 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
11913 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
11914 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
11915 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
11916 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
11917 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
11918 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
11919 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
11920 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
11921 @end smallexample
11922
11923 Or, if we want to examine the variable @code{X} at each source line in
11924 the buffer:
11925
11926 @smallexample
11927 (@value{GDBP}) @b{tfind start}
11928 (@value{GDBP}) @b{while ($trace_frame != -1)}
11929 > printf "Frame %d, X == %d\n", $trace_frame, X
11930 > tfind line
11931 > end
11932
11933 Frame 0, X = 1
11934 Frame 7, X = 2
11935 Frame 13, X = 255
11936 @end smallexample
11937
11938 @node tdump
11939 @subsection @code{tdump}
11940 @kindex tdump
11941 @cindex dump all data collected at tracepoint
11942 @cindex tracepoint data, display
11943
11944 This command takes no arguments.  It prints all the data collected at
11945 the current trace snapshot.
11946
11947 @smallexample
11948 (@value{GDBP}) @b{trace 444}
11949 (@value{GDBP}) @b{actions}
11950 Enter actions for tracepoint #2, one per line:
11951 > collect $regs, $locals, $args, gdb_long_test
11952 > end
11953
11954 (@value{GDBP}) @b{tstart}
11955
11956 (@value{GDBP}) @b{tfind line 444}
11957 #0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
11958 at gdb_test.c:444
11959 444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
11960
11961 (@value{GDBP}) @b{tdump}
11962 Data collected at tracepoint 2, trace frame 1:
11963 d0             0xc4aa0085       -995491707
11964 d1             0x18     24
11965 d2             0x80     128
11966 d3             0x33     51
11967 d4             0x71aea3d        119204413
11968 d5             0x22     34
11969 d6             0xe0     224
11970 d7             0x380035 3670069
11971 a0             0x19e24a 1696330
11972 a1             0x3000668        50333288
11973 a2             0x100    256
11974 a3             0x322000 3284992
11975 a4             0x3000698        50333336
11976 a5             0x1ad3cc 1758156
11977 fp             0x30bf3c 0x30bf3c
11978 sp             0x30bf34 0x30bf34
11979 ps             0x0      0
11980 pc             0x20b2c8 0x20b2c8
11981 fpcontrol      0x0      0
11982 fpstatus       0x0      0
11983 fpiaddr        0x0      0
11984 p = 0x20e5b4 "gdb-test"
11985 p1 = (void *) 0x11
11986 p2 = (void *) 0x22
11987 p3 = (void *) 0x33
11988 p4 = (void *) 0x44
11989 p5 = (void *) 0x55
11990 p6 = (void *) 0x66
11991 gdb_long_test = 17 '\021'
11992
11993 (@value{GDBP})
11994 @end smallexample
11995
11996 @code{tdump} works by scanning the tracepoint's current collection
11997 actions and printing the value of each expression listed.  So
11998 @code{tdump} can fail, if after a run, you change the tracepoint's
11999 actions to mention variables that were not collected during the run.
12000
12001 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
12002 uses the collected value of @code{$pc} to distinguish between trace
12003 frames that were collected at the tracepoint hit, and frames that were
12004 collected while stepping.  This allows it to correctly choose whether
12005 to display the basic list of collections, or the collections from the
12006 body of the while-stepping loop.  However, if @code{$pc} was not collected,
12007 then @code{tdump} will always attempt to dump using the basic collection
12008 list, and may fail if a while-stepping frame does not include all the
12009 same data that is collected at the tracepoint hit.
12010 @c This is getting pretty arcane, example would be good.
12011
12012 @node save tracepoints
12013 @subsection @code{save tracepoints @var{filename}}
12014 @kindex save tracepoints
12015 @kindex save-tracepoints
12016 @cindex save tracepoints for future sessions
12017
12018 This command saves all current tracepoint definitions together with
12019 their actions and passcounts, into a file @file{@var{filename}}
12020 suitable for use in a later debugging session.  To read the saved
12021 tracepoint definitions, use the @code{source} command (@pxref{Command
12022 Files}).  The @w{@code{save-tracepoints}} command is a deprecated
12023 alias for @w{@code{save tracepoints}}
12024
12025 @node Tracepoint Variables
12026 @section Convenience Variables for Tracepoints
12027 @cindex tracepoint variables
12028 @cindex convenience variables for tracepoints
12029
12030 @table @code
12031 @vindex $trace_frame
12032 @item (int) $trace_frame
12033 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
12034 snapshot is selected.
12035
12036 @vindex $tracepoint
12037 @item (int) $tracepoint
12038 The tracepoint for the current trace snapshot.
12039
12040 @vindex $trace_line
12041 @item (int) $trace_line
12042 The line number for the current trace snapshot.
12043
12044 @vindex $trace_file
12045 @item (char []) $trace_file
12046 The source file for the current trace snapshot.
12047
12048 @vindex $trace_func
12049 @item (char []) $trace_func
12050 The name of the function containing @code{$tracepoint}.
12051 @end table
12052
12053 Note: @code{$trace_file} is not suitable for use in @code{printf},
12054 use @code{output} instead.
12055
12056 Here's a simple example of using these convenience variables for
12057 stepping through all the trace snapshots and printing some of their
12058 data.  Note that these are not the same as trace state variables,
12059 which are managed by the target.
12060
12061 @smallexample
12062 (@value{GDBP}) @b{tfind start}
12063
12064 (@value{GDBP}) @b{while $trace_frame != -1}
12065 > output $trace_file
12066 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
12067 > tfind
12068 > end
12069 @end smallexample
12070
12071 @node Trace Files
12072 @section Using Trace Files
12073 @cindex trace files
12074
12075 In some situations, the target running a trace experiment may no
12076 longer be available; perhaps it crashed, or the hardware was needed
12077 for a different activity.  To handle these cases, you can arrange to
12078 dump the trace data into a file, and later use that file as a source
12079 of trace data, via the @code{target tfile} command.
12080
12081 @table @code
12082
12083 @kindex tsave
12084 @item tsave [ -r ] @var{filename}
12085 Save the trace data to @var{filename}.  By default, this command
12086 assumes that @var{filename} refers to the host filesystem, so if
12087 necessary @value{GDBN} will copy raw trace data up from the target and
12088 then save it.  If the target supports it, you can also supply the
12089 optional argument @code{-r} (``remote'') to direct the target to save
12090 the data directly into @var{filename} in its own filesystem, which may be
12091 more efficient if the trace buffer is very large.  (Note, however, that
12092 @code{target tfile} can only read from files accessible to the host.)
12093
12094 @kindex target tfile
12095 @kindex tfile
12096 @item target tfile @var{filename}
12097 Use the file named @var{filename} as a source of trace data.  Commands
12098 that examine data work as they do with a live target, but it is not
12099 possible to run any new trace experiments.  @code{tstatus} will report
12100 the state of the trace run at the moment the data was saved, as well
12101 as the current trace frame you are examining.  @var{filename} must be
12102 on a filesystem accessible to the host.
12103
12104 @end table
12105
12106 @node Overlays
12107 @chapter Debugging Programs That Use Overlays
12108 @cindex overlays
12109
12110 If your program is too large to fit completely in your target system's
12111 memory, you can sometimes use @dfn{overlays} to work around this
12112 problem.  @value{GDBN} provides some support for debugging programs that
12113 use overlays.
12114
12115 @menu
12116 * How Overlays Work::              A general explanation of overlays.
12117 * Overlay Commands::               Managing overlays in @value{GDBN}.
12118 * Automatic Overlay Debugging::    @value{GDBN} can find out which overlays are
12119                                    mapped by asking the inferior.
12120 * Overlay Sample Program::         A sample program using overlays.
12121 @end menu
12122
12123 @node How Overlays Work
12124 @section How Overlays Work
12125 @cindex mapped overlays
12126 @cindex unmapped overlays
12127 @cindex load address, overlay's
12128 @cindex mapped address
12129 @cindex overlay area
12130
12131 Suppose you have a computer whose instruction address space is only 64
12132 kilobytes long, but which has much more memory which can be accessed by
12133 other means: special instructions, segment registers, or memory
12134 management hardware, for example.  Suppose further that you want to
12135 adapt a program which is larger than 64 kilobytes to run on this system.
12136
12137 One solution is to identify modules of your program which are relatively
12138 independent, and need not call each other directly; call these modules
12139 @dfn{overlays}.  Separate the overlays from the main program, and place
12140 their machine code in the larger memory.  Place your main program in
12141 instruction memory, but leave at least enough space there to hold the
12142 largest overlay as well.
12143
12144 Now, to call a function located in an overlay, you must first copy that
12145 overlay's machine code from the large memory into the space set aside
12146 for it in the instruction memory, and then jump to its entry point
12147 there.
12148
12149 @c NB:  In the below the mapped area's size is greater or equal to the
12150 @c size of all overlays.  This is intentional to remind the developer
12151 @c that overlays don't necessarily need to be the same size.
12152
12153 @smallexample
12154 @group
12155     Data             Instruction            Larger
12156 Address Space       Address Space        Address Space
12157 +-----------+       +-----------+        +-----------+
12158 |           |       |           |        |           |
12159 +-----------+       +-----------+        +-----------+<-- overlay 1
12160 | program   |       |   main    |   .----| overlay 1 | load address
12161 | variables |       |  program  |   |    +-----------+
12162 | and heap  |       |           |   |    |           |
12163 +-----------+       |           |   |    +-----------+<-- overlay 2
12164 |           |       +-----------+   |    |           | load address
12165 +-----------+       |           |   |  .-| overlay 2 |
12166                     |           |   |  | |           |
12167          mapped --->+-----------+   |  | +-----------+
12168          address    |           |   |  | |           |
12169                     |  overlay  | <-'  | |           |
12170                     |   area    |  <---' +-----------+<-- overlay 3
12171                     |           | <---.  |           | load address
12172                     +-----------+     `--| overlay 3 |
12173                     |           |        |           |
12174                     +-----------+        |           |
12175                                          +-----------+
12176                                          |           |
12177                                          +-----------+
12178
12179                     @anchor{A code overlay}A code overlay
12180 @end group
12181 @end smallexample
12182
12183 The diagram (@pxref{A code overlay}) shows a system with separate data
12184 and instruction address spaces.  To map an overlay, the program copies
12185 its code from the larger address space to the instruction address space.
12186 Since the overlays shown here all use the same mapped address, only one
12187 may be mapped at a time.  For a system with a single address space for
12188 data and instructions, the diagram would be similar, except that the
12189 program variables and heap would share an address space with the main
12190 program and the overlay area.
12191
12192 An overlay loaded into instruction memory and ready for use is called a
12193 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
12194 instruction memory.  An overlay not present (or only partially present)
12195 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
12196 is its address in the larger memory.  The mapped address is also called
12197 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
12198 called the @dfn{load memory address}, or @dfn{LMA}.
12199
12200 Unfortunately, overlays are not a completely transparent way to adapt a
12201 program to limited instruction memory.  They introduce a new set of
12202 global constraints you must keep in mind as you design your program:
12203
12204 @itemize @bullet
12205
12206 @item
12207 Before calling or returning to a function in an overlay, your program
12208 must make sure that overlay is actually mapped.  Otherwise, the call or
12209 return will transfer control to the right address, but in the wrong
12210 overlay, and your program will probably crash.
12211
12212 @item
12213 If the process of mapping an overlay is expensive on your system, you
12214 will need to choose your overlays carefully to minimize their effect on
12215 your program's performance.
12216
12217 @item
12218 The executable file you load onto your system must contain each
12219 overlay's instructions, appearing at the overlay's load address, not its
12220 mapped address.  However, each overlay's instructions must be relocated
12221 and its symbols defined as if the overlay were at its mapped address.
12222 You can use GNU linker scripts to specify different load and relocation
12223 addresses for pieces of your program; see @ref{Overlay Description,,,
12224 ld.info, Using ld: the GNU linker}.
12225
12226 @item
12227 The procedure for loading executable files onto your system must be able
12228 to load their contents into the larger address space as well as the
12229 instruction and data spaces.
12230
12231 @end itemize
12232
12233 The overlay system described above is rather simple, and could be
12234 improved in many ways:
12235
12236 @itemize @bullet
12237
12238 @item
12239 If your system has suitable bank switch registers or memory management
12240 hardware, you could use those facilities to make an overlay's load area
12241 contents simply appear at their mapped address in instruction space.
12242 This would probably be faster than copying the overlay to its mapped
12243 area in the usual way.
12244
12245 @item
12246 If your overlays are small enough, you could set aside more than one
12247 overlay area, and have more than one overlay mapped at a time.
12248
12249 @item
12250 You can use overlays to manage data, as well as instructions.  In
12251 general, data overlays are even less transparent to your design than
12252 code overlays: whereas code overlays only require care when you call or
12253 return to functions, data overlays require care every time you access
12254 the data.  Also, if you change the contents of a data overlay, you
12255 must copy its contents back out to its load address before you can copy a
12256 different data overlay into the same mapped area.
12257
12258 @end itemize
12259
12260
12261 @node Overlay Commands
12262 @section Overlay Commands
12263
12264 To use @value{GDBN}'s overlay support, each overlay in your program must
12265 correspond to a separate section of the executable file.  The section's
12266 virtual memory address and load memory address must be the overlay's
12267 mapped and load addresses.  Identifying overlays with sections allows
12268 @value{GDBN} to determine the appropriate address of a function or
12269 variable, depending on whether the overlay is mapped or not.
12270
12271 @value{GDBN}'s overlay commands all start with the word @code{overlay};
12272 you can abbreviate this as @code{ov} or @code{ovly}.  The commands are:
12273
12274 @table @code
12275 @item overlay off
12276 @kindex overlay
12277 Disable @value{GDBN}'s overlay support.  When overlay support is
12278 disabled, @value{GDBN} assumes that all functions and variables are
12279 always present at their mapped addresses.  By default, @value{GDBN}'s
12280 overlay support is disabled.
12281
12282 @item overlay manual
12283 @cindex manual overlay debugging
12284 Enable @dfn{manual} overlay debugging.  In this mode, @value{GDBN}
12285 relies on you to tell it which overlays are mapped, and which are not,
12286 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
12287 commands described below.
12288
12289 @item overlay map-overlay @var{overlay}
12290 @itemx overlay map @var{overlay}
12291 @cindex map an overlay
12292 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
12293 be the name of the object file section containing the overlay.  When an
12294 overlay is mapped, @value{GDBN} assumes it can find the overlay's
12295 functions and variables at their mapped addresses.  @value{GDBN} assumes
12296 that any other overlays whose mapped ranges overlap that of
12297 @var{overlay} are now unmapped.
12298
12299 @item overlay unmap-overlay @var{overlay}
12300 @itemx overlay unmap @var{overlay}
12301 @cindex unmap an overlay
12302 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
12303 must be the name of the object file section containing the overlay.
12304 When an overlay is unmapped, @value{GDBN} assumes it can find the
12305 overlay's functions and variables at their load addresses.
12306
12307 @item overlay auto
12308 Enable @dfn{automatic} overlay debugging.  In this mode, @value{GDBN}
12309 consults a data structure the overlay manager maintains in the inferior
12310 to see which overlays are mapped.  For details, see @ref{Automatic
12311 Overlay Debugging}.
12312
12313 @item overlay load-target
12314 @itemx overlay load
12315 @cindex reloading the overlay table
12316 Re-read the overlay table from the inferior.  Normally, @value{GDBN}
12317 re-reads the table @value{GDBN} automatically each time the inferior
12318 stops, so this command should only be necessary if you have changed the
12319 overlay mapping yourself using @value{GDBN}.  This command is only
12320 useful when using automatic overlay debugging.
12321
12322 @item overlay list-overlays
12323 @itemx overlay list
12324 @cindex listing mapped overlays
12325 Display a list of the overlays currently mapped, along with their mapped
12326 addresses, load addresses, and sizes.
12327
12328 @end table
12329
12330 Normally, when @value{GDBN} prints a code address, it includes the name
12331 of the function the address falls in:
12332
12333 @smallexample
12334 (@value{GDBP}) print main
12335 $3 = @{int ()@} 0x11a0 <main>
12336 @end smallexample
12337 @noindent
12338 When overlay debugging is enabled, @value{GDBN} recognizes code in
12339 unmapped overlays, and prints the names of unmapped functions with
12340 asterisks around them.  For example, if @code{foo} is a function in an
12341 unmapped overlay, @value{GDBN} prints it this way:
12342
12343 @smallexample
12344 (@value{GDBP}) overlay list
12345 No sections are mapped.
12346 (@value{GDBP}) print foo
12347 $5 = @{int (int)@} 0x100000 <*foo*>
12348 @end smallexample
12349 @noindent
12350 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
12351 name normally:
12352
12353 @smallexample
12354 (@value{GDBP}) overlay list
12355 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
12356         mapped at 0x1016 - 0x104a
12357 (@value{GDBP}) print foo
12358 $6 = @{int (int)@} 0x1016 <foo>
12359 @end smallexample
12360
12361 When overlay debugging is enabled, @value{GDBN} can find the correct
12362 address for functions and variables in an overlay, whether or not the
12363 overlay is mapped.  This allows most @value{GDBN} commands, like
12364 @code{break} and @code{disassemble}, to work normally, even on unmapped
12365 code.  However, @value{GDBN}'s breakpoint support has some limitations:
12366
12367 @itemize @bullet
12368 @item
12369 @cindex breakpoints in overlays
12370 @cindex overlays, setting breakpoints in
12371 You can set breakpoints in functions in unmapped overlays, as long as
12372 @value{GDBN} can write to the overlay at its load address.
12373 @item
12374 @value{GDBN} can not set hardware or simulator-based breakpoints in
12375 unmapped overlays.  However, if you set a breakpoint at the end of your
12376 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
12377 you are using manual overlay management), @value{GDBN} will re-set its
12378 breakpoints properly.
12379 @end itemize
12380
12381
12382 @node Automatic Overlay Debugging
12383 @section Automatic Overlay Debugging
12384 @cindex automatic overlay debugging
12385
12386 @value{GDBN} can automatically track which overlays are mapped and which
12387 are not, given some simple co-operation from the overlay manager in the
12388 inferior.  If you enable automatic overlay debugging with the
12389 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
12390 looks in the inferior's memory for certain variables describing the
12391 current state of the overlays.
12392
12393 Here are the variables your overlay manager must define to support
12394 @value{GDBN}'s automatic overlay debugging:
12395
12396 @table @asis
12397
12398 @item @code{_ovly_table}:
12399 This variable must be an array of the following structures:
12400
12401 @smallexample
12402 struct
12403 @{
12404   /* The overlay's mapped address.  */
12405   unsigned long vma;
12406
12407   /* The size of the overlay, in bytes.  */
12408   unsigned long size;
12409
12410   /* The overlay's load address.  */
12411   unsigned long lma;
12412
12413   /* Non-zero if the overlay is currently mapped;
12414      zero otherwise.  */
12415   unsigned long mapped;
12416 @}
12417 @end smallexample
12418
12419 @item @code{_novlys}:
12420 This variable must be a four-byte signed integer, holding the total
12421 number of elements in @code{_ovly_table}.
12422
12423 @end table
12424
12425 To decide whether a particular overlay is mapped or not, @value{GDBN}
12426 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
12427 @code{lma} members equal the VMA and LMA of the overlay's section in the
12428 executable file.  When @value{GDBN} finds a matching entry, it consults
12429 the entry's @code{mapped} member to determine whether the overlay is
12430 currently mapped.
12431
12432 In addition, your overlay manager may define a function called
12433 @code{_ovly_debug_event}.  If this function is defined, @value{GDBN}
12434 will silently set a breakpoint there.  If the overlay manager then
12435 calls this function whenever it has changed the overlay table, this
12436 will enable @value{GDBN} to accurately keep track of which overlays
12437 are in program memory, and update any breakpoints that may be set
12438 in overlays.  This will allow breakpoints to work even if the
12439 overlays are kept in ROM or other non-writable memory while they
12440 are not being executed.
12441
12442 @node Overlay Sample Program
12443 @section Overlay Sample Program
12444 @cindex overlay example program
12445
12446 When linking a program which uses overlays, you must place the overlays
12447 at their load addresses, while relocating them to run at their mapped
12448 addresses.  To do this, you must write a linker script (@pxref{Overlay
12449 Description,,, ld.info, Using ld: the GNU linker}).  Unfortunately,
12450 since linker scripts are specific to a particular host system, target
12451 architecture, and target memory layout, this manual cannot provide
12452 portable sample code demonstrating @value{GDBN}'s overlay support.
12453
12454 However, the @value{GDBN} source distribution does contain an overlaid
12455 program, with linker scripts for a few systems, as part of its test
12456 suite.  The program consists of the following files from
12457 @file{gdb/testsuite/gdb.base}:
12458
12459 @table @file
12460 @item overlays.c
12461 The main program file.
12462 @item ovlymgr.c
12463 A simple overlay manager, used by @file{overlays.c}.
12464 @item foo.c
12465 @itemx bar.c
12466 @itemx baz.c
12467 @itemx grbx.c
12468 Overlay modules, loaded and used by @file{overlays.c}.
12469 @item d10v.ld
12470 @itemx m32r.ld
12471 Linker scripts for linking the test program on the @code{d10v-elf}
12472 and @code{m32r-elf} targets.
12473 @end table
12474
12475 You can build the test program using the @code{d10v-elf} GCC
12476 cross-compiler like this:
12477
12478 @smallexample
12479 $ d10v-elf-gcc -g -c overlays.c
12480 $ d10v-elf-gcc -g -c ovlymgr.c
12481 $ d10v-elf-gcc -g -c foo.c
12482 $ d10v-elf-gcc -g -c bar.c
12483 $ d10v-elf-gcc -g -c baz.c
12484 $ d10v-elf-gcc -g -c grbx.c
12485 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
12486                   baz.o grbx.o -Wl,-Td10v.ld -o overlays
12487 @end smallexample
12488
12489 The build process is identical for any other architecture, except that
12490 you must substitute the appropriate compiler and linker script for the
12491 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
12492
12493
12494 @node Languages
12495 @chapter Using @value{GDBN} with Different Languages
12496 @cindex languages
12497
12498 Although programming languages generally have common aspects, they are
12499 rarely expressed in the same manner.  For instance, in ANSI C,
12500 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
12501 Modula-2, it is accomplished by @code{p^}.  Values can also be
12502 represented (and displayed) differently.  Hex numbers in C appear as
12503 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
12504
12505 @cindex working language
12506 Language-specific information is built into @value{GDBN} for some languages,
12507 allowing you to express operations like the above in your program's
12508 native language, and allowing @value{GDBN} to output values in a manner
12509 consistent with the syntax of your program's native language.  The
12510 language you use to build expressions is called the @dfn{working
12511 language}.
12512
12513 @menu
12514 * Setting::                     Switching between source languages
12515 * Show::                        Displaying the language
12516 * Checks::                      Type and range checks
12517 * Supported Languages::         Supported languages
12518 * Unsupported Languages::       Unsupported languages
12519 @end menu
12520
12521 @node Setting
12522 @section Switching Between Source Languages
12523
12524 There are two ways to control the working language---either have @value{GDBN}
12525 set it automatically, or select it manually yourself.  You can use the
12526 @code{set language} command for either purpose.  On startup, @value{GDBN}
12527 defaults to setting the language automatically.  The working language is
12528 used to determine how expressions you type are interpreted, how values
12529 are printed, etc.
12530
12531 In addition to the working language, every source file that
12532 @value{GDBN} knows about has its own working language.  For some object
12533 file formats, the compiler might indicate which language a particular
12534 source file is in.  However, most of the time @value{GDBN} infers the
12535 language from the name of the file.  The language of a source file
12536 controls whether C@t{++} names are demangled---this way @code{backtrace} can
12537 show each frame appropriately for its own language.  There is no way to
12538 set the language of a source file from within @value{GDBN}, but you can
12539 set the language associated with a filename extension.  @xref{Show, ,
12540 Displaying the Language}.
12541
12542 This is most commonly a problem when you use a program, such
12543 as @code{cfront} or @code{f2c}, that generates C but is written in
12544 another language.  In that case, make the
12545 program use @code{#line} directives in its C output; that way
12546 @value{GDBN} will know the correct language of the source code of the original
12547 program, and will display that source code, not the generated C code.
12548
12549 @menu
12550 * Filenames::                   Filename extensions and languages.
12551 * Manually::                    Setting the working language manually
12552 * Automatically::               Having @value{GDBN} infer the source language
12553 @end menu
12554
12555 @node Filenames
12556 @subsection List of Filename Extensions and Languages
12557
12558 If a source file name ends in one of the following extensions, then
12559 @value{GDBN} infers that its language is the one indicated.
12560
12561 @table @file
12562 @item .ada
12563 @itemx .ads
12564 @itemx .adb
12565 @itemx .a
12566 Ada source file.
12567
12568 @item .c
12569 C source file
12570
12571 @item .C
12572 @itemx .cc
12573 @itemx .cp
12574 @itemx .cpp
12575 @itemx .cxx
12576 @itemx .c++
12577 C@t{++} source file
12578
12579 @item .d
12580 D source file
12581
12582 @item .m
12583 Objective-C source file
12584
12585 @item .f
12586 @itemx .F
12587 Fortran source file
12588
12589 @item .mod
12590 Modula-2 source file
12591
12592 @item .s
12593 @itemx .S
12594 Assembler source file.  This actually behaves almost like C, but
12595 @value{GDBN} does not skip over function prologues when stepping.
12596 @end table
12597
12598 In addition, you may set the language associated with a filename
12599 extension.  @xref{Show, , Displaying the Language}.
12600
12601 @node Manually
12602 @subsection Setting the Working Language
12603
12604 If you allow @value{GDBN} to set the language automatically,
12605 expressions are interpreted the same way in your debugging session and
12606 your program.
12607
12608 @kindex set language
12609 If you wish, you may set the language manually.  To do this, issue the
12610 command @samp{set language @var{lang}}, where @var{lang} is the name of
12611 a language, such as
12612 @code{c} or @code{modula-2}.
12613 For a list of the supported languages, type @samp{set language}.
12614
12615 Setting the language manually prevents @value{GDBN} from updating the working
12616 language automatically.  This can lead to confusion if you try
12617 to debug a program when the working language is not the same as the
12618 source language, when an expression is acceptable to both
12619 languages---but means different things.  For instance, if the current
12620 source file were written in C, and @value{GDBN} was parsing Modula-2, a
12621 command such as:
12622
12623 @smallexample
12624 print a = b + c
12625 @end smallexample
12626
12627 @noindent
12628 might not have the effect you intended.  In C, this means to add
12629 @code{b} and @code{c} and place the result in @code{a}.  The result
12630 printed would be the value of @code{a}.  In Modula-2, this means to compare
12631 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
12632
12633 @node Automatically
12634 @subsection Having @value{GDBN} Infer the Source Language
12635
12636 To have @value{GDBN} set the working language automatically, use
12637 @samp{set language local} or @samp{set language auto}.  @value{GDBN}
12638 then infers the working language.  That is, when your program stops in a
12639 frame (usually by encountering a breakpoint), @value{GDBN} sets the
12640 working language to the language recorded for the function in that
12641 frame.  If the language for a frame is unknown (that is, if the function
12642 or block corresponding to the frame was defined in a source file that
12643 does not have a recognized extension), the current working language is
12644 not changed, and @value{GDBN} issues a warning.
12645
12646 This may not seem necessary for most programs, which are written
12647 entirely in one source language.  However, program modules and libraries
12648 written in one source language can be used by a main program written in
12649 a different source language.  Using @samp{set language auto} in this
12650 case frees you from having to set the working language manually.
12651
12652 @node Show
12653 @section Displaying the Language
12654
12655 The following commands help you find out which language is the
12656 working language, and also what language source files were written in.
12657
12658 @table @code
12659 @item show language
12660 @kindex show language
12661 Display the current working language.  This is the
12662 language you can use with commands such as @code{print} to
12663 build and compute expressions that may involve variables in your program.
12664
12665 @item info frame
12666 @kindex info frame@r{, show the source language}
12667 Display the source language for this frame.  This language becomes the
12668 working language if you use an identifier from this frame.
12669 @xref{Frame Info, ,Information about a Frame}, to identify the other
12670 information listed here.
12671
12672 @item info source
12673 @kindex info source@r{, show the source language}
12674 Display the source language of this source file.
12675 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
12676 information listed here.
12677 @end table
12678
12679 In unusual circumstances, you may have source files with extensions
12680 not in the standard list.  You can then set the extension associated
12681 with a language explicitly:
12682
12683 @table @code
12684 @item set extension-language @var{ext} @var{language}
12685 @kindex set extension-language
12686 Tell @value{GDBN} that source files with extension @var{ext} are to be
12687 assumed as written in the source language @var{language}.
12688
12689 @item info extensions
12690 @kindex info extensions
12691 List all the filename extensions and the associated languages.
12692 @end table
12693
12694 @node Checks
12695 @section Type and Range Checking
12696
12697 Some languages are designed to guard you against making seemingly common
12698 errors through a series of compile- and run-time checks.  These include
12699 checking the type of arguments to functions and operators and making
12700 sure mathematical overflows are caught at run time.  Checks such as
12701 these help to ensure a program's correctness once it has been compiled
12702 by eliminating type mismatches and providing active checks for range
12703 errors when your program is running.
12704
12705 By default @value{GDBN} checks for these errors according to the
12706 rules of the current source language.  Although @value{GDBN} does not check
12707 the statements in your program, it can check expressions entered directly
12708 into @value{GDBN} for evaluation via the @code{print} command, for example.
12709
12710 @menu
12711 * Type Checking::               An overview of type checking
12712 * Range Checking::              An overview of range checking
12713 @end menu
12714
12715 @cindex type checking
12716 @cindex checks, type
12717 @node Type Checking
12718 @subsection An Overview of Type Checking
12719
12720 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
12721 arguments to operators and functions have to be of the correct type,
12722 otherwise an error occurs.  These checks prevent type mismatch
12723 errors from ever causing any run-time problems.  For example,
12724
12725 @smallexample
12726 int klass::my_method(char *b) @{ return  b ? 1 : 2; @}
12727
12728 (@value{GDBP}) print obj.my_method (0)
12729 $1 = 2
12730 @exdent but
12731 (@value{GDBP}) print obj.my_method (0x1234)
12732 Cannot resolve method klass::my_method to any overloaded instance
12733 @end smallexample
12734
12735 The second example fails because in C@t{++} the integer constant
12736 @samp{0x1234} is not type-compatible with the pointer parameter type.
12737
12738 For the expressions you use in @value{GDBN} commands, you can tell
12739 @value{GDBN} to not enforce strict type checking or
12740 to treat any mismatches as errors and abandon the expression;
12741 When type checking is disabled, @value{GDBN} successfully evaluates
12742 expressions like the second example above.
12743
12744 Even if type checking is off, there may be other reasons
12745 related to type that prevent @value{GDBN} from evaluating an expression.
12746 For instance, @value{GDBN} does not know how to add an @code{int} and
12747 a @code{struct foo}.  These particular type errors have nothing to do
12748 with the language in use and usually arise from expressions which make
12749 little sense to evaluate anyway.
12750
12751 @value{GDBN} provides some additional commands for controlling type checking:
12752
12753 @kindex set check type
12754 @kindex show check type
12755 @table @code
12756 @item set check type on
12757 @itemx set check type off
12758 Set strict type checking on or off.  If any type mismatches occur in
12759 evaluating an expression while type checking is on, @value{GDBN} prints a
12760 message and aborts evaluation of the expression.
12761
12762 @item show check type
12763 Show the current setting of type checking and whether @value{GDBN}
12764 is enforcing strict type checking rules.
12765 @end table
12766
12767 @cindex range checking
12768 @cindex checks, range
12769 @node Range Checking
12770 @subsection An Overview of Range Checking
12771
12772 In some languages (such as Modula-2), it is an error to exceed the
12773 bounds of a type; this is enforced with run-time checks.  Such range
12774 checking is meant to ensure program correctness by making sure
12775 computations do not overflow, or indices on an array element access do
12776 not exceed the bounds of the array.
12777
12778 For expressions you use in @value{GDBN} commands, you can tell
12779 @value{GDBN} to treat range errors in one of three ways: ignore them,
12780 always treat them as errors and abandon the expression, or issue
12781 warnings but evaluate the expression anyway.
12782
12783 A range error can result from numerical overflow, from exceeding an
12784 array index bound, or when you type a constant that is not a member
12785 of any type.  Some languages, however, do not treat overflows as an
12786 error.  In many implementations of C, mathematical overflow causes the
12787 result to ``wrap around'' to lower values---for example, if @var{m} is
12788 the largest integer value, and @var{s} is the smallest, then
12789
12790 @smallexample
12791 @var{m} + 1 @result{} @var{s}
12792 @end smallexample
12793
12794 This, too, is specific to individual languages, and in some cases
12795 specific to individual compilers or machines.  @xref{Supported Languages, ,
12796 Supported Languages}, for further details on specific languages.
12797
12798 @value{GDBN} provides some additional commands for controlling the range checker:
12799
12800 @kindex set check range
12801 @kindex show check range
12802 @table @code
12803 @item set check range auto
12804 Set range checking on or off based on the current working language.
12805 @xref{Supported Languages, ,Supported Languages}, for the default settings for
12806 each language.
12807
12808 @item set check range on
12809 @itemx set check range off
12810 Set range checking on or off, overriding the default setting for the
12811 current working language.  A warning is issued if the setting does not
12812 match the language default.  If a range error occurs and range checking is on,
12813 then a message is printed and evaluation of the expression is aborted.
12814
12815 @item set check range warn
12816 Output messages when the @value{GDBN} range checker detects a range error,
12817 but attempt to evaluate the expression anyway.  Evaluating the
12818 expression may still be impossible for other reasons, such as accessing
12819 memory that the process does not own (a typical example from many Unix
12820 systems).
12821
12822 @item show range
12823 Show the current setting of the range checker, and whether or not it is
12824 being set automatically by @value{GDBN}.
12825 @end table
12826
12827 @node Supported Languages
12828 @section Supported Languages
12829
12830 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
12831 OpenCL C, Pascal, assembly, Modula-2, and Ada.
12832 @c This is false ...
12833 Some @value{GDBN} features may be used in expressions regardless of the
12834 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
12835 and the @samp{@{type@}addr} construct (@pxref{Expressions,
12836 ,Expressions}) can be used with the constructs of any supported
12837 language.
12838
12839 The following sections detail to what degree each source language is
12840 supported by @value{GDBN}.  These sections are not meant to be language
12841 tutorials or references, but serve only as a reference guide to what the
12842 @value{GDBN} expression parser accepts, and what input and output
12843 formats should look like for different languages.  There are many good
12844 books written on each of these languages; please look to these for a
12845 language reference or tutorial.
12846
12847 @menu
12848 * C::                           C and C@t{++}
12849 * D::                           D
12850 * Go::                          Go
12851 * Objective-C::                 Objective-C
12852 * OpenCL C::                    OpenCL C
12853 * Fortran::                     Fortran
12854 * Pascal::                      Pascal
12855 * Modula-2::                    Modula-2
12856 * Ada::                         Ada
12857 @end menu
12858
12859 @node C
12860 @subsection C and C@t{++}
12861
12862 @cindex C and C@t{++}
12863 @cindex expressions in C or C@t{++}
12864
12865 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
12866 to both languages.  Whenever this is the case, we discuss those languages
12867 together.
12868
12869 @cindex C@t{++}
12870 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
12871 @cindex @sc{gnu} C@t{++}
12872 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
12873 compiler and @value{GDBN}.  Therefore, to debug your C@t{++} code
12874 effectively, you must compile your C@t{++} programs with a supported
12875 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
12876 compiler (@code{aCC}).
12877
12878 @menu
12879 * C Operators::                 C and C@t{++} operators
12880 * C Constants::                 C and C@t{++} constants
12881 * C Plus Plus Expressions::     C@t{++} expressions
12882 * C Defaults::                  Default settings for C and C@t{++}
12883 * C Checks::                    C and C@t{++} type and range checks
12884 * Debugging C::                 @value{GDBN} and C
12885 * Debugging C Plus Plus::       @value{GDBN} features for C@t{++}
12886 * Decimal Floating Point::      Numbers in Decimal Floating Point format
12887 @end menu
12888
12889 @node C Operators
12890 @subsubsection C and C@t{++} Operators
12891
12892 @cindex C and C@t{++} operators
12893
12894 Operators must be defined on values of specific types.  For instance,
12895 @code{+} is defined on numbers, but not on structures.  Operators are
12896 often defined on groups of types.
12897
12898 For the purposes of C and C@t{++}, the following definitions hold:
12899
12900 @itemize @bullet
12901
12902 @item
12903 @emph{Integral types} include @code{int} with any of its storage-class
12904 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
12905
12906 @item
12907 @emph{Floating-point types} include @code{float}, @code{double}, and
12908 @code{long double} (if supported by the target platform).
12909
12910 @item
12911 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
12912
12913 @item
12914 @emph{Scalar types} include all of the above.
12915
12916 @end itemize
12917
12918 @noindent
12919 The following operators are supported.  They are listed here
12920 in order of increasing precedence:
12921
12922 @table @code
12923 @item ,
12924 The comma or sequencing operator.  Expressions in a comma-separated list
12925 are evaluated from left to right, with the result of the entire
12926 expression being the last expression evaluated.
12927
12928 @item =
12929 Assignment.  The value of an assignment expression is the value
12930 assigned.  Defined on scalar types.
12931
12932 @item @var{op}=
12933 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
12934 and translated to @w{@code{@var{a} = @var{a op b}}}.
12935 @w{@code{@var{op}=}} and @code{=} have the same precedence.
12936 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
12937 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
12938
12939 @item ?:
12940 The ternary operator.  @code{@var{a} ? @var{b} : @var{c}} can be thought
12941 of as:  if @var{a} then @var{b} else @var{c}.  @var{a} should be of an
12942 integral type.
12943
12944 @item ||
12945 Logical @sc{or}.  Defined on integral types.
12946
12947 @item &&
12948 Logical @sc{and}.  Defined on integral types.
12949
12950 @item |
12951 Bitwise @sc{or}.  Defined on integral types.
12952
12953 @item ^
12954 Bitwise exclusive-@sc{or}.  Defined on integral types.
12955
12956 @item &
12957 Bitwise @sc{and}.  Defined on integral types.
12958
12959 @item ==@r{, }!=
12960 Equality and inequality.  Defined on scalar types.  The value of these
12961 expressions is 0 for false and non-zero for true.
12962
12963 @item <@r{, }>@r{, }<=@r{, }>=
12964 Less than, greater than, less than or equal, greater than or equal.
12965 Defined on scalar types.  The value of these expressions is 0 for false
12966 and non-zero for true.
12967
12968 @item <<@r{, }>>
12969 left shift, and right shift.  Defined on integral types.
12970
12971 @item @@
12972 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
12973
12974 @item +@r{, }-
12975 Addition and subtraction.  Defined on integral types, floating-point types and
12976 pointer types.
12977
12978 @item *@r{, }/@r{, }%
12979 Multiplication, division, and modulus.  Multiplication and division are
12980 defined on integral and floating-point types.  Modulus is defined on
12981 integral types.
12982
12983 @item ++@r{, }--
12984 Increment and decrement.  When appearing before a variable, the
12985 operation is performed before the variable is used in an expression;
12986 when appearing after it, the variable's value is used before the
12987 operation takes place.
12988
12989 @item *
12990 Pointer dereferencing.  Defined on pointer types.  Same precedence as
12991 @code{++}.
12992
12993 @item &
12994 Address operator.  Defined on variables.  Same precedence as @code{++}.
12995
12996 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
12997 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
12998 to examine the address
12999 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
13000 stored.
13001
13002 @item -
13003 Negative.  Defined on integral and floating-point types.  Same
13004 precedence as @code{++}.
13005
13006 @item !
13007 Logical negation.  Defined on integral types.  Same precedence as
13008 @code{++}.
13009
13010 @item ~
13011 Bitwise complement operator.  Defined on integral types.  Same precedence as
13012 @code{++}.
13013
13014
13015 @item .@r{, }->
13016 Structure member, and pointer-to-structure member.  For convenience,
13017 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
13018 pointer based on the stored type information.
13019 Defined on @code{struct} and @code{union} data.
13020
13021 @item .*@r{, }->*
13022 Dereferences of pointers to members.
13023
13024 @item []
13025 Array indexing.  @code{@var{a}[@var{i}]} is defined as
13026 @code{*(@var{a}+@var{i})}.  Same precedence as @code{->}.
13027
13028 @item ()
13029 Function parameter list.  Same precedence as @code{->}.
13030
13031 @item ::
13032 C@t{++} scope resolution operator.  Defined on @code{struct}, @code{union},
13033 and @code{class} types.
13034
13035 @item ::
13036 Doubled colons also represent the @value{GDBN} scope operator
13037 (@pxref{Expressions, ,Expressions}).  Same precedence as @code{::},
13038 above.
13039 @end table
13040
13041 If an operator is redefined in the user code, @value{GDBN} usually
13042 attempts to invoke the redefined version instead of using the operator's
13043 predefined meaning.
13044
13045 @node C Constants
13046 @subsubsection C and C@t{++} Constants
13047
13048 @cindex C and C@t{++} constants
13049
13050 @value{GDBN} allows you to express the constants of C and C@t{++} in the
13051 following ways:
13052
13053 @itemize @bullet
13054 @item
13055 Integer constants are a sequence of digits.  Octal constants are
13056 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
13057 by a leading @samp{0x} or @samp{0X}.  Constants may also end with a letter
13058 @samp{l}, specifying that the constant should be treated as a
13059 @code{long} value.
13060
13061 @item
13062 Floating point constants are a sequence of digits, followed by a decimal
13063 point, followed by a sequence of digits, and optionally followed by an
13064 exponent.  An exponent is of the form:
13065 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
13066 sequence of digits.  The @samp{+} is optional for positive exponents.
13067 A floating-point constant may also end with a letter @samp{f} or
13068 @samp{F}, specifying that the constant should be treated as being of
13069 the @code{float} (as opposed to the default @code{double}) type; or with
13070 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
13071 constant.
13072
13073 @item
13074 Enumerated constants consist of enumerated identifiers, or their
13075 integral equivalents.
13076
13077 @item
13078 Character constants are a single character surrounded by single quotes
13079 (@code{'}), or a number---the ordinal value of the corresponding character
13080 (usually its @sc{ascii} value).  Within quotes, the single character may
13081 be represented by a letter or by @dfn{escape sequences}, which are of
13082 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
13083 of the character's ordinal value; or of the form @samp{\@var{x}}, where
13084 @samp{@var{x}} is a predefined special character---for example,
13085 @samp{\n} for newline.
13086
13087 Wide character constants can be written by prefixing a character
13088 constant with @samp{L}, as in C.  For example, @samp{L'x'} is the wide
13089 form of @samp{x}.  The target wide character set is used when
13090 computing the value of this constant (@pxref{Character Sets}).
13091
13092 @item
13093 String constants are a sequence of character constants surrounded by
13094 double quotes (@code{"}).  Any valid character constant (as described
13095 above) may appear.  Double quotes within the string must be preceded by
13096 a backslash, so for instance @samp{"a\"b'c"} is a string of five
13097 characters.
13098
13099 Wide string constants can be written by prefixing a string constant
13100 with @samp{L}, as in C.  The target wide character set is used when
13101 computing the value of this constant (@pxref{Character Sets}).
13102
13103 @item
13104 Pointer constants are an integral value.  You can also write pointers
13105 to constants using the C operator @samp{&}.
13106
13107 @item
13108 Array constants are comma-separated lists surrounded by braces @samp{@{}
13109 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
13110 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
13111 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
13112 @end itemize
13113
13114 @node C Plus Plus Expressions
13115 @subsubsection C@t{++} Expressions
13116
13117 @cindex expressions in C@t{++}
13118 @value{GDBN} expression handling can interpret most C@t{++} expressions.
13119
13120 @cindex debugging C@t{++} programs
13121 @cindex C@t{++} compilers
13122 @cindex debug formats and C@t{++}
13123 @cindex @value{NGCC} and C@t{++}
13124 @quotation
13125 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
13126 the proper compiler and the proper debug format.  Currently,
13127 @value{GDBN} works best when debugging C@t{++} code that is compiled
13128 with the most recent version of @value{NGCC} possible.  The DWARF
13129 debugging format is preferred; @value{NGCC} defaults to this on most
13130 popular platforms.  Other compilers and/or debug formats are likely to
13131 work badly or not at all when using @value{GDBN} to debug C@t{++}
13132 code.  @xref{Compilation}.
13133 @end quotation
13134
13135 @enumerate
13136
13137 @cindex member functions
13138 @item
13139 Member function calls are allowed; you can use expressions like
13140
13141 @smallexample
13142 count = aml->GetOriginal(x, y)
13143 @end smallexample
13144
13145 @vindex this@r{, inside C@t{++} member functions}
13146 @cindex namespace in C@t{++}
13147 @item
13148 While a member function is active (in the selected stack frame), your
13149 expressions have the same namespace available as the member function;
13150 that is, @value{GDBN} allows implicit references to the class instance
13151 pointer @code{this} following the same rules as C@t{++}.  @code{using}
13152 declarations in the current scope are also respected by @value{GDBN}.
13153
13154 @cindex call overloaded functions
13155 @cindex overloaded functions, calling
13156 @cindex type conversions in C@t{++}
13157 @item
13158 You can call overloaded functions; @value{GDBN} resolves the function
13159 call to the right definition, with some restrictions.  @value{GDBN} does not
13160 perform overload resolution involving user-defined type conversions,
13161 calls to constructors, or instantiations of templates that do not exist
13162 in the program.  It also cannot handle ellipsis argument lists or
13163 default arguments.
13164
13165 It does perform integral conversions and promotions, floating-point
13166 promotions, arithmetic conversions, pointer conversions, conversions of
13167 class objects to base classes, and standard conversions such as those of
13168 functions or arrays to pointers; it requires an exact match on the
13169 number of function arguments.
13170
13171 Overload resolution is always performed, unless you have specified
13172 @code{set overload-resolution off}.  @xref{Debugging C Plus Plus,
13173 ,@value{GDBN} Features for C@t{++}}.
13174
13175 You must specify @code{set overload-resolution off} in order to use an
13176 explicit function signature to call an overloaded function, as in
13177 @smallexample
13178 p 'foo(char,int)'('x', 13)
13179 @end smallexample
13180
13181 The @value{GDBN} command-completion facility can simplify this;
13182 see @ref{Completion, ,Command Completion}.
13183
13184 @cindex reference declarations
13185 @item
13186 @value{GDBN} understands variables declared as C@t{++} references; you can use
13187 them in expressions just as you do in C@t{++} source---they are automatically
13188 dereferenced.
13189
13190 In the parameter list shown when @value{GDBN} displays a frame, the values of
13191 reference variables are not displayed (unlike other variables); this
13192 avoids clutter, since references are often used for large structures.
13193 The @emph{address} of a reference variable is always shown, unless
13194 you have specified @samp{set print address off}.
13195
13196 @item
13197 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
13198 expressions can use it just as expressions in your program do.  Since
13199 one scope may be defined in another, you can use @code{::} repeatedly if
13200 necessary, for example in an expression like
13201 @samp{@var{scope1}::@var{scope2}::@var{name}}.  @value{GDBN} also allows
13202 resolving name scope by reference to source files, in both C and C@t{++}
13203 debugging (@pxref{Variables, ,Program Variables}).
13204
13205 @item
13206 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
13207 specification.
13208 @end enumerate
13209
13210 @node C Defaults
13211 @subsubsection C and C@t{++} Defaults
13212
13213 @cindex C and C@t{++} defaults
13214
13215 If you allow @value{GDBN} to set range checking automatically, it
13216 defaults to @code{off} whenever the working language changes to
13217 C or C@t{++}.  This happens regardless of whether you or @value{GDBN}
13218 selects the working language.
13219
13220 If you allow @value{GDBN} to set the language automatically, it
13221 recognizes source files whose names end with @file{.c}, @file{.C}, or
13222 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
13223 these files, it sets the working language to C or C@t{++}.
13224 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
13225 for further details.
13226
13227 @node C Checks
13228 @subsubsection C and C@t{++} Type and Range Checks
13229
13230 @cindex C and C@t{++} checks
13231
13232 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
13233 checking is used.  However, if you turn type checking off, @value{GDBN}
13234 will allow certain non-standard conversions, such as promoting integer
13235 constants to pointers.
13236
13237 Range checking, if turned on, is done on mathematical operations.  Array
13238 indices are not checked, since they are often used to index a pointer
13239 that is not itself an array.
13240
13241 @node Debugging C
13242 @subsubsection @value{GDBN} and C
13243
13244 The @code{set print union} and @code{show print union} commands apply to
13245 the @code{union} type.  When set to @samp{on}, any @code{union} that is
13246 inside a @code{struct} or @code{class} is also printed.  Otherwise, it
13247 appears as @samp{@{...@}}.
13248
13249 The @code{@@} operator aids in the debugging of dynamic arrays, formed
13250 with pointers and a memory allocation function.  @xref{Expressions,
13251 ,Expressions}.
13252
13253 @node Debugging C Plus Plus
13254 @subsubsection @value{GDBN} Features for C@t{++}
13255
13256 @cindex commands for C@t{++}
13257
13258 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
13259 designed specifically for use with C@t{++}.  Here is a summary:
13260
13261 @table @code
13262 @cindex break in overloaded functions
13263 @item @r{breakpoint menus}
13264 When you want a breakpoint in a function whose name is overloaded,
13265 @value{GDBN} has the capability to display a menu of possible breakpoint
13266 locations to help you specify which function definition you want.
13267 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
13268
13269 @cindex overloading in C@t{++}
13270 @item rbreak @var{regex}
13271 Setting breakpoints using regular expressions is helpful for setting
13272 breakpoints on overloaded functions that are not members of any special
13273 classes.
13274 @xref{Set Breaks, ,Setting Breakpoints}.
13275
13276 @cindex C@t{++} exception handling
13277 @item catch throw
13278 @itemx catch catch
13279 Debug C@t{++} exception handling using these commands.  @xref{Set
13280 Catchpoints, , Setting Catchpoints}.
13281
13282 @cindex inheritance
13283 @item ptype @var{typename}
13284 Print inheritance relationships as well as other information for type
13285 @var{typename}.
13286 @xref{Symbols, ,Examining the Symbol Table}.
13287
13288 @item info vtbl @var{expression}.
13289 The @code{info vtbl} command can be used to display the virtual
13290 method tables of the object computed by @var{expression}.  This shows
13291 one entry per virtual table; there may be multiple virtual tables when
13292 multiple inheritance is in use.
13293
13294 @cindex C@t{++} symbol display
13295 @item set print demangle
13296 @itemx show print demangle
13297 @itemx set print asm-demangle
13298 @itemx show print asm-demangle
13299 Control whether C@t{++} symbols display in their source form, both when
13300 displaying code as C@t{++} source and when displaying disassemblies.
13301 @xref{Print Settings, ,Print Settings}.
13302
13303 @item set print object
13304 @itemx show print object
13305 Choose whether to print derived (actual) or declared types of objects.
13306 @xref{Print Settings, ,Print Settings}.
13307
13308 @item set print vtbl
13309 @itemx show print vtbl
13310 Control the format for printing virtual function tables.
13311 @xref{Print Settings, ,Print Settings}.
13312 (The @code{vtbl} commands do not work on programs compiled with the HP
13313 ANSI C@t{++} compiler (@code{aCC}).)
13314
13315 @kindex set overload-resolution
13316 @cindex overloaded functions, overload resolution
13317 @item set overload-resolution on
13318 Enable overload resolution for C@t{++} expression evaluation.  The default
13319 is on.  For overloaded functions, @value{GDBN} evaluates the arguments
13320 and searches for a function whose signature matches the argument types,
13321 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
13322 Expressions, ,C@t{++} Expressions}, for details).
13323 If it cannot find a match, it emits a message.
13324
13325 @item set overload-resolution off
13326 Disable overload resolution for C@t{++} expression evaluation.  For
13327 overloaded functions that are not class member functions, @value{GDBN}
13328 chooses the first function of the specified name that it finds in the
13329 symbol table, whether or not its arguments are of the correct type.  For
13330 overloaded functions that are class member functions, @value{GDBN}
13331 searches for a function whose signature @emph{exactly} matches the
13332 argument types.
13333
13334 @kindex show overload-resolution
13335 @item show overload-resolution
13336 Show the current setting of overload resolution.
13337
13338 @item @r{Overloaded symbol names}
13339 You can specify a particular definition of an overloaded symbol, using
13340 the same notation that is used to declare such symbols in C@t{++}: type
13341 @code{@var{symbol}(@var{types})} rather than just @var{symbol}.  You can
13342 also use the @value{GDBN} command-line word completion facilities to list the
13343 available choices, or to finish the type list for you.
13344 @xref{Completion,, Command Completion}, for details on how to do this.
13345 @end table
13346
13347 @node Decimal Floating Point
13348 @subsubsection Decimal Floating Point format
13349 @cindex decimal floating point format
13350
13351 @value{GDBN} can examine, set and perform computations with numbers in
13352 decimal floating point format, which in the C language correspond to the
13353 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
13354 specified by the extension to support decimal floating-point arithmetic.
13355
13356 There are two encodings in use, depending on the architecture: BID (Binary
13357 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
13358 PowerPC.  @value{GDBN} will use the appropriate encoding for the configured
13359 target.
13360
13361 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
13362 to manipulate decimal floating point numbers, it is not possible to convert
13363 (using a cast, for example) integers wider than 32-bit to decimal float.
13364
13365 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
13366 point computations, error checking in decimal float operations ignores
13367 underflow, overflow and divide by zero exceptions.
13368
13369 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
13370 to inspect @code{_Decimal128} values stored in floating point registers.
13371 See @ref{PowerPC,,PowerPC} for more details.
13372
13373 @node D
13374 @subsection D
13375
13376 @cindex D
13377 @value{GDBN} can be used to debug programs written in D and compiled with
13378 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
13379 specific feature --- dynamic arrays.
13380
13381 @node Go
13382 @subsection Go
13383
13384 @cindex Go (programming language)
13385 @value{GDBN} can be used to debug programs written in Go and compiled with
13386 @file{gccgo} or @file{6g} compilers.
13387
13388 Here is a summary of the Go-specific features and restrictions:
13389
13390 @table @code
13391 @cindex current Go package
13392 @item The current Go package
13393 The name of the current package does not need to be specified when
13394 specifying global variables and functions.
13395
13396 For example, given the program:
13397
13398 @example
13399 package main
13400 var myglob = "Shall we?"
13401 func main () @{
13402   // ...
13403 @}
13404 @end example
13405
13406 When stopped inside @code{main} either of these work:
13407
13408 @example
13409 (gdb) p myglob
13410 (gdb) p main.myglob
13411 @end example
13412
13413 @cindex builtin Go types
13414 @item Builtin Go types
13415 The @code{string} type is recognized by @value{GDBN} and is printed
13416 as a string.
13417
13418 @cindex builtin Go functions
13419 @item Builtin Go functions
13420 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
13421 function and handles it internally.
13422
13423 @cindex restrictions on Go expressions
13424 @item Restrictions on Go expressions
13425 All Go operators are supported except @code{&^}.
13426 The Go @code{_} ``blank identifier'' is not supported.
13427 Automatic dereferencing of pointers is not supported.
13428 @end table
13429
13430 @node Objective-C
13431 @subsection Objective-C
13432
13433 @cindex Objective-C
13434 This section provides information about some commands and command
13435 options that are useful for debugging Objective-C code.  See also
13436 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
13437 few more commands specific to Objective-C support.
13438
13439 @menu
13440 * Method Names in Commands::
13441 * The Print Command with Objective-C::
13442 @end menu
13443
13444 @node Method Names in Commands
13445 @subsubsection Method Names in Commands
13446
13447 The following commands have been extended to accept Objective-C method
13448 names as line specifications:
13449
13450 @kindex clear@r{, and Objective-C}
13451 @kindex break@r{, and Objective-C}
13452 @kindex info line@r{, and Objective-C}
13453 @kindex jump@r{, and Objective-C}
13454 @kindex list@r{, and Objective-C}
13455 @itemize
13456 @item @code{clear}
13457 @item @code{break}
13458 @item @code{info line}
13459 @item @code{jump}
13460 @item @code{list}
13461 @end itemize
13462
13463 A fully qualified Objective-C method name is specified as
13464
13465 @smallexample
13466 -[@var{Class} @var{methodName}]
13467 @end smallexample
13468
13469 where the minus sign is used to indicate an instance method and a
13470 plus sign (not shown) is used to indicate a class method.  The class
13471 name @var{Class} and method name @var{methodName} are enclosed in
13472 brackets, similar to the way messages are specified in Objective-C
13473 source code.  For example, to set a breakpoint at the @code{create}
13474 instance method of class @code{Fruit} in the program currently being
13475 debugged, enter:
13476
13477 @smallexample
13478 break -[Fruit create]
13479 @end smallexample
13480
13481 To list ten program lines around the @code{initialize} class method,
13482 enter:
13483
13484 @smallexample
13485 list +[NSText initialize]
13486 @end smallexample
13487
13488 In the current version of @value{GDBN}, the plus or minus sign is
13489 required.  In future versions of @value{GDBN}, the plus or minus
13490 sign will be optional, but you can use it to narrow the search.  It
13491 is also possible to specify just a method name:
13492
13493 @smallexample
13494 break create
13495 @end smallexample
13496
13497 You must specify the complete method name, including any colons.  If
13498 your program's source files contain more than one @code{create} method,
13499 you'll be presented with a numbered list of classes that implement that
13500 method.  Indicate your choice by number, or type @samp{0} to exit if
13501 none apply.
13502
13503 As another example, to clear a breakpoint established at the
13504 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
13505
13506 @smallexample
13507 clear -[NSWindow makeKeyAndOrderFront:]
13508 @end smallexample
13509
13510 @node The Print Command with Objective-C
13511 @subsubsection The Print Command With Objective-C
13512 @cindex Objective-C, print objects
13513 @kindex print-object
13514 @kindex po @r{(@code{print-object})}
13515
13516 The print command has also been extended to accept methods.  For example:
13517
13518 @smallexample
13519 print -[@var{object} hash]
13520 @end smallexample
13521
13522 @cindex print an Objective-C object description
13523 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
13524 @noindent
13525 will tell @value{GDBN} to send the @code{hash} message to @var{object}
13526 and print the result.  Also, an additional command has been added,
13527 @code{print-object} or @code{po} for short, which is meant to print
13528 the description of an object.  However, this command may only work
13529 with certain Objective-C libraries that have a particular hook
13530 function, @code{_NSPrintForDebugger}, defined.
13531
13532 @node OpenCL C
13533 @subsection OpenCL C
13534
13535 @cindex OpenCL C
13536 This section provides information about @value{GDBN}s OpenCL C support.
13537
13538 @menu
13539 * OpenCL C Datatypes::
13540 * OpenCL C Expressions::
13541 * OpenCL C Operators::
13542 @end menu
13543
13544 @node OpenCL C Datatypes
13545 @subsubsection OpenCL C Datatypes
13546
13547 @cindex OpenCL C Datatypes
13548 @value{GDBN} supports the builtin scalar and vector datatypes specified
13549 by OpenCL 1.1.  In addition the half- and double-precision floating point
13550 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
13551 extensions are also known to @value{GDBN}.
13552
13553 @node OpenCL C Expressions
13554 @subsubsection OpenCL C Expressions
13555
13556 @cindex OpenCL C Expressions
13557 @value{GDBN} supports accesses to vector components including the access as
13558 lvalue where possible.  Since OpenCL C is based on C99 most C expressions
13559 supported by @value{GDBN} can be used as well.
13560
13561 @node OpenCL C Operators
13562 @subsubsection OpenCL C Operators
13563
13564 @cindex OpenCL C Operators
13565 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
13566 vector data types.
13567
13568 @node Fortran
13569 @subsection Fortran
13570 @cindex Fortran-specific support in @value{GDBN}
13571
13572 @value{GDBN} can be used to debug programs written in Fortran, but it
13573 currently supports only the features of Fortran 77 language.
13574
13575 @cindex trailing underscore, in Fortran symbols
13576 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
13577 among them) append an underscore to the names of variables and
13578 functions.  When you debug programs compiled by those compilers, you
13579 will need to refer to variables and functions with a trailing
13580 underscore.
13581
13582 @menu
13583 * Fortran Operators::           Fortran operators and expressions
13584 * Fortran Defaults::            Default settings for Fortran
13585 * Special Fortran Commands::    Special @value{GDBN} commands for Fortran
13586 @end menu
13587
13588 @node Fortran Operators
13589 @subsubsection Fortran Operators and Expressions
13590
13591 @cindex Fortran operators and expressions
13592
13593 Operators must be defined on values of specific types.  For instance,
13594 @code{+} is defined on numbers, but not on characters or other non-
13595 arithmetic types.  Operators are often defined on groups of types.
13596
13597 @table @code
13598 @item **
13599 The exponentiation operator.  It raises the first operand to the power
13600 of the second one.
13601
13602 @item :
13603 The range operator.  Normally used in the form of array(low:high) to
13604 represent a section of array.
13605
13606 @item %
13607 The access component operator.  Normally used to access elements in derived
13608 types.  Also suitable for unions.  As unions aren't part of regular Fortran,
13609 this can only happen when accessing a register that uses a gdbarch-defined
13610 union type.
13611 @end table
13612
13613 @node Fortran Defaults
13614 @subsubsection Fortran Defaults
13615
13616 @cindex Fortran Defaults
13617
13618 Fortran symbols are usually case-insensitive, so @value{GDBN} by
13619 default uses case-insensitive matches for Fortran symbols.  You can
13620 change that with the @samp{set case-insensitive} command, see
13621 @ref{Symbols}, for the details.
13622
13623 @node Special Fortran Commands
13624 @subsubsection Special Fortran Commands
13625
13626 @cindex Special Fortran commands
13627
13628 @value{GDBN} has some commands to support Fortran-specific features,
13629 such as displaying common blocks.
13630
13631 @table @code
13632 @cindex @code{COMMON} blocks, Fortran
13633 @kindex info common
13634 @item info common @r{[}@var{common-name}@r{]}
13635 This command prints the values contained in the Fortran @code{COMMON}
13636 block whose name is @var{common-name}.  With no argument, the names of
13637 all @code{COMMON} blocks visible at the current program location are
13638 printed.
13639 @end table
13640
13641 @node Pascal
13642 @subsection Pascal
13643
13644 @cindex Pascal support in @value{GDBN}, limitations
13645 Debugging Pascal programs which use sets, subranges, file variables, or
13646 nested functions does not currently work.  @value{GDBN} does not support
13647 entering expressions, printing values, or similar features using Pascal
13648 syntax.
13649
13650 The Pascal-specific command @code{set print pascal_static-members}
13651 controls whether static members of Pascal objects are displayed.
13652 @xref{Print Settings, pascal_static-members}.
13653
13654 @node Modula-2
13655 @subsection Modula-2
13656
13657 @cindex Modula-2, @value{GDBN} support
13658
13659 The extensions made to @value{GDBN} to support Modula-2 only support
13660 output from the @sc{gnu} Modula-2 compiler (which is currently being
13661 developed).  Other Modula-2 compilers are not currently supported, and
13662 attempting to debug executables produced by them is most likely
13663 to give an error as @value{GDBN} reads in the executable's symbol
13664 table.
13665
13666 @cindex expressions in Modula-2
13667 @menu
13668 * M2 Operators::                Built-in operators
13669 * Built-In Func/Proc::          Built-in functions and procedures
13670 * M2 Constants::                Modula-2 constants
13671 * M2 Types::                    Modula-2 types
13672 * M2 Defaults::                 Default settings for Modula-2
13673 * Deviations::                  Deviations from standard Modula-2
13674 * M2 Checks::                   Modula-2 type and range checks
13675 * M2 Scope::                    The scope operators @code{::} and @code{.}
13676 * GDB/M2::                      @value{GDBN} and Modula-2
13677 @end menu
13678
13679 @node M2 Operators
13680 @subsubsection Operators
13681 @cindex Modula-2 operators
13682
13683 Operators must be defined on values of specific types.  For instance,
13684 @code{+} is defined on numbers, but not on structures.  Operators are
13685 often defined on groups of types.  For the purposes of Modula-2, the
13686 following definitions hold:
13687
13688 @itemize @bullet
13689
13690 @item
13691 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
13692 their subranges.
13693
13694 @item
13695 @emph{Character types} consist of @code{CHAR} and its subranges.
13696
13697 @item
13698 @emph{Floating-point types} consist of @code{REAL}.
13699
13700 @item
13701 @emph{Pointer types} consist of anything declared as @code{POINTER TO
13702 @var{type}}.
13703
13704 @item
13705 @emph{Scalar types} consist of all of the above.
13706
13707 @item
13708 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
13709
13710 @item
13711 @emph{Boolean types} consist of @code{BOOLEAN}.
13712 @end itemize
13713
13714 @noindent
13715 The following operators are supported, and appear in order of
13716 increasing precedence:
13717
13718 @table @code
13719 @item ,
13720 Function argument or array index separator.
13721
13722 @item :=
13723 Assignment.  The value of @var{var} @code{:=} @var{value} is
13724 @var{value}.
13725
13726 @item <@r{, }>
13727 Less than, greater than on integral, floating-point, or enumerated
13728 types.
13729
13730 @item <=@r{, }>=
13731 Less than or equal to, greater than or equal to
13732 on integral, floating-point and enumerated types, or set inclusion on
13733 set types.  Same precedence as @code{<}.
13734
13735 @item =@r{, }<>@r{, }#
13736 Equality and two ways of expressing inequality, valid on scalar types.
13737 Same precedence as @code{<}.  In @value{GDBN} scripts, only @code{<>} is
13738 available for inequality, since @code{#} conflicts with the script
13739 comment character.
13740
13741 @item IN
13742 Set membership.  Defined on set types and the types of their members.
13743 Same precedence as @code{<}.
13744
13745 @item OR
13746 Boolean disjunction.  Defined on boolean types.
13747
13748 @item AND@r{, }&
13749 Boolean conjunction.  Defined on boolean types.
13750
13751 @item @@
13752 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13753
13754 @item +@r{, }-
13755 Addition and subtraction on integral and floating-point types, or union
13756 and difference on set types.
13757
13758 @item *
13759 Multiplication on integral and floating-point types, or set intersection
13760 on set types.
13761
13762 @item /
13763 Division on floating-point types, or symmetric set difference on set
13764 types.  Same precedence as @code{*}.
13765
13766 @item DIV@r{, }MOD
13767 Integer division and remainder.  Defined on integral types.  Same
13768 precedence as @code{*}.
13769
13770 @item -
13771 Negative.  Defined on @code{INTEGER} and @code{REAL} data.
13772
13773 @item ^
13774 Pointer dereferencing.  Defined on pointer types.
13775
13776 @item NOT
13777 Boolean negation.  Defined on boolean types.  Same precedence as
13778 @code{^}.
13779
13780 @item .
13781 @code{RECORD} field selector.  Defined on @code{RECORD} data.  Same
13782 precedence as @code{^}.
13783
13784 @item []
13785 Array indexing.  Defined on @code{ARRAY} data.  Same precedence as @code{^}.
13786
13787 @item ()
13788 Procedure argument list.  Defined on @code{PROCEDURE} objects.  Same precedence
13789 as @code{^}.
13790
13791 @item ::@r{, }.
13792 @value{GDBN} and Modula-2 scope operators.
13793 @end table
13794
13795 @quotation
13796 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
13797 treats the use of the operator @code{IN}, or the use of operators
13798 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
13799 @code{<=}, and @code{>=} on sets as an error.
13800 @end quotation
13801
13802
13803 @node Built-In Func/Proc
13804 @subsubsection Built-in Functions and Procedures
13805 @cindex Modula-2 built-ins
13806
13807 Modula-2 also makes available several built-in procedures and functions.
13808 In describing these, the following metavariables are used:
13809
13810 @table @var
13811
13812 @item a
13813 represents an @code{ARRAY} variable.
13814
13815 @item c
13816 represents a @code{CHAR} constant or variable.
13817
13818 @item i
13819 represents a variable or constant of integral type.
13820
13821 @item m
13822 represents an identifier that belongs to a set.  Generally used in the
13823 same function with the metavariable @var{s}.  The type of @var{s} should
13824 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
13825
13826 @item n
13827 represents a variable or constant of integral or floating-point type.
13828
13829 @item r
13830 represents a variable or constant of floating-point type.
13831
13832 @item t
13833 represents a type.
13834
13835 @item v
13836 represents a variable.
13837
13838 @item x
13839 represents a variable or constant of one of many types.  See the
13840 explanation of the function for details.
13841 @end table
13842
13843 All Modula-2 built-in procedures also return a result, described below.
13844
13845 @table @code
13846 @item ABS(@var{n})
13847 Returns the absolute value of @var{n}.
13848
13849 @item CAP(@var{c})
13850 If @var{c} is a lower case letter, it returns its upper case
13851 equivalent, otherwise it returns its argument.
13852
13853 @item CHR(@var{i})
13854 Returns the character whose ordinal value is @var{i}.
13855
13856 @item DEC(@var{v})
13857 Decrements the value in the variable @var{v} by one.  Returns the new value.
13858
13859 @item DEC(@var{v},@var{i})
13860 Decrements the value in the variable @var{v} by @var{i}.  Returns the
13861 new value.
13862
13863 @item EXCL(@var{m},@var{s})
13864 Removes the element @var{m} from the set @var{s}.  Returns the new
13865 set.
13866
13867 @item FLOAT(@var{i})
13868 Returns the floating point equivalent of the integer @var{i}.
13869
13870 @item HIGH(@var{a})
13871 Returns the index of the last member of @var{a}.
13872
13873 @item INC(@var{v})
13874 Increments the value in the variable @var{v} by one.  Returns the new value.
13875
13876 @item INC(@var{v},@var{i})
13877 Increments the value in the variable @var{v} by @var{i}.  Returns the
13878 new value.
13879
13880 @item INCL(@var{m},@var{s})
13881 Adds the element @var{m} to the set @var{s} if it is not already
13882 there.  Returns the new set.
13883
13884 @item MAX(@var{t})
13885 Returns the maximum value of the type @var{t}.
13886
13887 @item MIN(@var{t})
13888 Returns the minimum value of the type @var{t}.
13889
13890 @item ODD(@var{i})
13891 Returns boolean TRUE if @var{i} is an odd number.
13892
13893 @item ORD(@var{x})
13894 Returns the ordinal value of its argument.  For example, the ordinal
13895 value of a character is its @sc{ascii} value (on machines supporting the
13896 @sc{ascii} character set).  @var{x} must be of an ordered type, which include
13897 integral, character and enumerated types.
13898
13899 @item SIZE(@var{x})
13900 Returns the size of its argument.  @var{x} can be a variable or a type.
13901
13902 @item TRUNC(@var{r})
13903 Returns the integral part of @var{r}.
13904
13905 @item TSIZE(@var{x})
13906 Returns the size of its argument.  @var{x} can be a variable or a type.
13907
13908 @item VAL(@var{t},@var{i})
13909 Returns the member of the type @var{t} whose ordinal value is @var{i}.
13910 @end table
13911
13912 @quotation
13913 @emph{Warning:}  Sets and their operations are not yet supported, so
13914 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
13915 an error.
13916 @end quotation
13917
13918 @cindex Modula-2 constants
13919 @node M2 Constants
13920 @subsubsection Constants
13921
13922 @value{GDBN} allows you to express the constants of Modula-2 in the following
13923 ways:
13924
13925 @itemize @bullet
13926
13927 @item
13928 Integer constants are simply a sequence of digits.  When used in an
13929 expression, a constant is interpreted to be type-compatible with the
13930 rest of the expression.  Hexadecimal integers are specified by a
13931 trailing @samp{H}, and octal integers by a trailing @samp{B}.
13932
13933 @item
13934 Floating point constants appear as a sequence of digits, followed by a
13935 decimal point and another sequence of digits.  An optional exponent can
13936 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
13937 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent.  All of the
13938 digits of the floating point constant must be valid decimal (base 10)
13939 digits.
13940
13941 @item
13942 Character constants consist of a single character enclosed by a pair of
13943 like quotes, either single (@code{'}) or double (@code{"}).  They may
13944 also be expressed by their ordinal value (their @sc{ascii} value, usually)
13945 followed by a @samp{C}.
13946
13947 @item
13948 String constants consist of a sequence of characters enclosed by a
13949 pair of like quotes, either single (@code{'}) or double (@code{"}).
13950 Escape sequences in the style of C are also allowed.  @xref{C
13951 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
13952 sequences.
13953
13954 @item
13955 Enumerated constants consist of an enumerated identifier.
13956
13957 @item
13958 Boolean constants consist of the identifiers @code{TRUE} and
13959 @code{FALSE}.
13960
13961 @item
13962 Pointer constants consist of integral values only.
13963
13964 @item
13965 Set constants are not yet supported.
13966 @end itemize
13967
13968 @node M2 Types
13969 @subsubsection Modula-2 Types
13970 @cindex Modula-2 types
13971
13972 Currently @value{GDBN} can print the following data types in Modula-2
13973 syntax: array types, record types, set types, pointer types, procedure
13974 types, enumerated types, subrange types and base types.  You can also
13975 print the contents of variables declared using these type.
13976 This section gives a number of simple source code examples together with
13977 sample @value{GDBN} sessions.
13978
13979 The first example contains the following section of code:
13980
13981 @smallexample
13982 VAR
13983    s: SET OF CHAR ;
13984    r: [20..40] ;
13985 @end smallexample
13986
13987 @noindent
13988 and you can request @value{GDBN} to interrogate the type and value of
13989 @code{r} and @code{s}.
13990
13991 @smallexample
13992 (@value{GDBP}) print s
13993 @{'A'..'C', 'Z'@}
13994 (@value{GDBP}) ptype s
13995 SET OF CHAR
13996 (@value{GDBP}) print r
13997 21
13998 (@value{GDBP}) ptype r
13999 [20..40]
14000 @end smallexample
14001
14002 @noindent
14003 Likewise if your source code declares @code{s} as:
14004
14005 @smallexample
14006 VAR
14007    s: SET ['A'..'Z'] ;
14008 @end smallexample
14009
14010 @noindent
14011 then you may query the type of @code{s} by:
14012
14013 @smallexample
14014 (@value{GDBP}) ptype s
14015 type = SET ['A'..'Z']
14016 @end smallexample
14017
14018 @noindent
14019 Note that at present you cannot interactively manipulate set
14020 expressions using the debugger.
14021
14022 The following example shows how you might declare an array in Modula-2
14023 and how you can interact with @value{GDBN} to print its type and contents:
14024
14025 @smallexample
14026 VAR
14027    s: ARRAY [-10..10] OF CHAR ;
14028 @end smallexample
14029
14030 @smallexample
14031 (@value{GDBP}) ptype s
14032 ARRAY [-10..10] OF CHAR
14033 @end smallexample
14034
14035 Note that the array handling is not yet complete and although the type
14036 is printed correctly, expression handling still assumes that all
14037 arrays have a lower bound of zero and not @code{-10} as in the example
14038 above.
14039
14040 Here are some more type related Modula-2 examples:
14041
14042 @smallexample
14043 TYPE
14044    colour = (blue, red, yellow, green) ;
14045    t = [blue..yellow] ;
14046 VAR
14047    s: t ;
14048 BEGIN
14049    s := blue ;
14050 @end smallexample
14051
14052 @noindent
14053 The @value{GDBN} interaction shows how you can query the data type
14054 and value of a variable.
14055
14056 @smallexample
14057 (@value{GDBP}) print s
14058 $1 = blue
14059 (@value{GDBP}) ptype t
14060 type = [blue..yellow]
14061 @end smallexample
14062
14063 @noindent
14064 In this example a Modula-2 array is declared and its contents
14065 displayed.  Observe that the contents are written in the same way as
14066 their @code{C} counterparts.
14067
14068 @smallexample
14069 VAR
14070    s: ARRAY [1..5] OF CARDINAL ;
14071 BEGIN
14072    s[1] := 1 ;
14073 @end smallexample
14074
14075 @smallexample
14076 (@value{GDBP}) print s
14077 $1 = @{1, 0, 0, 0, 0@}
14078 (@value{GDBP}) ptype s
14079 type = ARRAY [1..5] OF CARDINAL
14080 @end smallexample
14081
14082 The Modula-2 language interface to @value{GDBN} also understands
14083 pointer types as shown in this example:
14084
14085 @smallexample
14086 VAR
14087    s: POINTER TO ARRAY [1..5] OF CARDINAL ;
14088 BEGIN
14089    NEW(s) ;
14090    s^[1] := 1 ;
14091 @end smallexample
14092
14093 @noindent
14094 and you can request that @value{GDBN} describes the type of @code{s}.
14095
14096 @smallexample
14097 (@value{GDBP}) ptype s
14098 type = POINTER TO ARRAY [1..5] OF CARDINAL
14099 @end smallexample
14100
14101 @value{GDBN} handles compound types as we can see in this example.
14102 Here we combine array types, record types, pointer types and subrange
14103 types:
14104
14105 @smallexample
14106 TYPE
14107    foo = RECORD
14108             f1: CARDINAL ;
14109             f2: CHAR ;
14110             f3: myarray ;
14111          END ;
14112
14113    myarray = ARRAY myrange OF CARDINAL ;
14114    myrange = [-2..2] ;
14115 VAR
14116    s: POINTER TO ARRAY myrange OF foo ;
14117 @end smallexample
14118
14119 @noindent
14120 and you can ask @value{GDBN} to describe the type of @code{s} as shown
14121 below.
14122
14123 @smallexample
14124 (@value{GDBP}) ptype s
14125 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
14126     f1 : CARDINAL;
14127     f2 : CHAR;
14128     f3 : ARRAY [-2..2] OF CARDINAL;
14129 END 
14130 @end smallexample
14131
14132 @node M2 Defaults
14133 @subsubsection Modula-2 Defaults
14134 @cindex Modula-2 defaults
14135
14136 If type and range checking are set automatically by @value{GDBN}, they
14137 both default to @code{on} whenever the working language changes to
14138 Modula-2.  This happens regardless of whether you or @value{GDBN}
14139 selected the working language.
14140
14141 If you allow @value{GDBN} to set the language automatically, then entering
14142 code compiled from a file whose name ends with @file{.mod} sets the
14143 working language to Modula-2.  @xref{Automatically, ,Having @value{GDBN}
14144 Infer the Source Language}, for further details.
14145
14146 @node Deviations
14147 @subsubsection Deviations from Standard Modula-2
14148 @cindex Modula-2, deviations from
14149
14150 A few changes have been made to make Modula-2 programs easier to debug.
14151 This is done primarily via loosening its type strictness:
14152
14153 @itemize @bullet
14154 @item
14155 Unlike in standard Modula-2, pointer constants can be formed by
14156 integers.  This allows you to modify pointer variables during
14157 debugging.  (In standard Modula-2, the actual address contained in a
14158 pointer variable is hidden from you; it can only be modified
14159 through direct assignment to another pointer variable or expression that
14160 returned a pointer.)
14161
14162 @item
14163 C escape sequences can be used in strings and characters to represent
14164 non-printable characters.  @value{GDBN} prints out strings with these
14165 escape sequences embedded.  Single non-printable characters are
14166 printed using the @samp{CHR(@var{nnn})} format.
14167
14168 @item
14169 The assignment operator (@code{:=}) returns the value of its right-hand
14170 argument.
14171
14172 @item
14173 All built-in procedures both modify @emph{and} return their argument.
14174 @end itemize
14175
14176 @node M2 Checks
14177 @subsubsection Modula-2 Type and Range Checks
14178 @cindex Modula-2 checks
14179
14180 @quotation
14181 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
14182 range checking.
14183 @end quotation
14184 @c FIXME remove warning when type/range checks added
14185
14186 @value{GDBN} considers two Modula-2 variables type equivalent if:
14187
14188 @itemize @bullet
14189 @item
14190 They are of types that have been declared equivalent via a @code{TYPE
14191 @var{t1} = @var{t2}} statement
14192
14193 @item
14194 They have been declared on the same line.  (Note:  This is true of the
14195 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
14196 @end itemize
14197
14198 As long as type checking is enabled, any attempt to combine variables
14199 whose types are not equivalent is an error.
14200
14201 Range checking is done on all mathematical operations, assignment, array
14202 index bounds, and all built-in functions and procedures.
14203
14204 @node M2 Scope
14205 @subsubsection The Scope Operators @code{::} and @code{.}
14206 @cindex scope
14207 @cindex @code{.}, Modula-2 scope operator
14208 @cindex colon, doubled as scope operator
14209 @ifinfo
14210 @vindex colon-colon@r{, in Modula-2}
14211 @c Info cannot handle :: but TeX can.
14212 @end ifinfo
14213 @ifnotinfo
14214 @vindex ::@r{, in Modula-2}
14215 @end ifnotinfo
14216
14217 There are a few subtle differences between the Modula-2 scope operator
14218 (@code{.}) and the @value{GDBN} scope operator (@code{::}).  The two have
14219 similar syntax:
14220
14221 @smallexample
14222
14223 @var{module} . @var{id}
14224 @var{scope} :: @var{id}
14225 @end smallexample
14226
14227 @noindent
14228 where @var{scope} is the name of a module or a procedure,
14229 @var{module} the name of a module, and @var{id} is any declared
14230 identifier within your program, except another module.
14231
14232 Using the @code{::} operator makes @value{GDBN} search the scope
14233 specified by @var{scope} for the identifier @var{id}.  If it is not
14234 found in the specified scope, then @value{GDBN} searches all scopes
14235 enclosing the one specified by @var{scope}.
14236
14237 Using the @code{.} operator makes @value{GDBN} search the current scope for
14238 the identifier specified by @var{id} that was imported from the
14239 definition module specified by @var{module}.  With this operator, it is
14240 an error if the identifier @var{id} was not imported from definition
14241 module @var{module}, or if @var{id} is not an identifier in
14242 @var{module}.
14243
14244 @node GDB/M2
14245 @subsubsection @value{GDBN} and Modula-2
14246
14247 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
14248 Five subcommands of @code{set print} and @code{show print} apply
14249 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
14250 @samp{asm-demangle}, @samp{object}, and @samp{union}.  The first four
14251 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
14252 analogue in Modula-2.
14253
14254 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
14255 with any language, is not useful with Modula-2.  Its
14256 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
14257 created in Modula-2 as they can in C or C@t{++}.  However, because an
14258 address can be specified by an integral constant, the construct
14259 @samp{@{@var{type}@}@var{adrexp}} is still useful.
14260
14261 @cindex @code{#} in Modula-2
14262 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
14263 interpreted as the beginning of a comment.  Use @code{<>} instead.
14264
14265 @node Ada
14266 @subsection Ada
14267 @cindex Ada
14268
14269 The extensions made to @value{GDBN} for Ada only support
14270 output from the @sc{gnu} Ada (GNAT) compiler.
14271 Other Ada compilers are not currently supported, and
14272 attempting to debug executables produced by them is most likely
14273 to be difficult.
14274
14275
14276 @cindex expressions in Ada
14277 @menu
14278 * Ada Mode Intro::              General remarks on the Ada syntax 
14279                                    and semantics supported by Ada mode 
14280                                    in @value{GDBN}.
14281 * Omissions from Ada::          Restrictions on the Ada expression syntax.
14282 * Additions to Ada::            Extensions of the Ada expression syntax.
14283 * Stopping Before Main Program:: Debugging the program during elaboration.
14284 * Ada Tasks::                   Listing and setting breakpoints in tasks.
14285 * Ada Tasks and Core Files::    Tasking Support when Debugging Core Files
14286 * Ravenscar Profile::           Tasking Support when using the Ravenscar
14287                                    Profile
14288 * Ada Glitches::                Known peculiarities of Ada mode.
14289 @end menu
14290
14291 @node Ada Mode Intro
14292 @subsubsection Introduction
14293 @cindex Ada mode, general
14294
14295 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression 
14296 syntax, with some extensions.
14297 The philosophy behind the design of this subset is 
14298
14299 @itemize @bullet
14300 @item
14301 That @value{GDBN} should provide basic literals and access to operations for 
14302 arithmetic, dereferencing, field selection, indexing, and subprogram calls, 
14303 leaving more sophisticated computations to subprograms written into the
14304 program (which therefore may be called from @value{GDBN}).
14305
14306 @item 
14307 That type safety and strict adherence to Ada language restrictions
14308 are not particularly important to the @value{GDBN} user.
14309
14310 @item 
14311 That brevity is important to the @value{GDBN} user.
14312 @end itemize
14313
14314 Thus, for brevity, the debugger acts as if all names declared in
14315 user-written packages are directly visible, even if they are not visible
14316 according to Ada rules, thus making it unnecessary to fully qualify most
14317 names with their packages, regardless of context.  Where this causes
14318 ambiguity, @value{GDBN} asks the user's intent.
14319
14320 The debugger will start in Ada mode if it detects an Ada main program. 
14321 As for other languages, it will enter Ada mode when stopped in a program that
14322 was translated from an Ada source file.
14323
14324 While in Ada mode, you may use `@t{--}' for comments.  This is useful 
14325 mostly for documenting command files.  The standard @value{GDBN} comment 
14326 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the 
14327 middle (to allow based literals).
14328
14329 The debugger supports limited overloading.  Given a subprogram call in which
14330 the function symbol has multiple definitions, it will use the number of 
14331 actual parameters and some information about their types to attempt to narrow
14332 the set of definitions.  It also makes very limited use of context, preferring
14333 procedures to functions in the context of the @code{call} command, and
14334 functions to procedures elsewhere. 
14335
14336 @node Omissions from Ada
14337 @subsubsection Omissions from Ada
14338 @cindex Ada, omissions from
14339
14340 Here are the notable omissions from the subset:
14341
14342 @itemize @bullet
14343 @item
14344 Only a subset of the attributes are supported:
14345
14346 @itemize @minus
14347 @item
14348 @t{'First}, @t{'Last}, and @t{'Length}
14349  on array objects (not on types and subtypes).
14350
14351 @item
14352 @t{'Min} and @t{'Max}.  
14353
14354 @item 
14355 @t{'Pos} and @t{'Val}. 
14356
14357 @item
14358 @t{'Tag}.
14359
14360 @item
14361 @t{'Range} on array objects (not subtypes), but only as the right
14362 operand of the membership (@code{in}) operator.
14363
14364 @item 
14365 @t{'Access}, @t{'Unchecked_Access}, and 
14366 @t{'Unrestricted_Access} (a GNAT extension).
14367
14368 @item
14369 @t{'Address}.
14370 @end itemize
14371
14372 @item
14373 The names in
14374 @code{Characters.Latin_1} are not available and
14375 concatenation is not implemented.  Thus, escape characters in strings are 
14376 not currently available.
14377
14378 @item
14379 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
14380 equality of representations.  They will generally work correctly
14381 for strings and arrays whose elements have integer or enumeration types.
14382 They may not work correctly for arrays whose element
14383 types have user-defined equality, for arrays of real values 
14384 (in particular, IEEE-conformant floating point, because of negative
14385 zeroes and NaNs), and for arrays whose elements contain unused bits with
14386 indeterminate values.  
14387
14388 @item
14389 The other component-by-component array operations (@code{and}, @code{or}, 
14390 @code{xor}, @code{not}, and relational tests other than equality)
14391 are not implemented. 
14392
14393 @item 
14394 @cindex array aggregates (Ada)
14395 @cindex record aggregates (Ada)
14396 @cindex aggregates (Ada) 
14397 There is limited support for array and record aggregates.  They are
14398 permitted only on the right sides of assignments, as in these examples:
14399
14400 @smallexample
14401 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
14402 (@value{GDBP}) set An_Array := (1, others => 0)
14403 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
14404 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
14405 (@value{GDBP}) set A_Record := (1, "Peter", True);
14406 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
14407 @end smallexample
14408
14409 Changing a
14410 discriminant's value by assigning an aggregate has an
14411 undefined effect if that discriminant is used within the record.
14412 However, you can first modify discriminants by directly assigning to
14413 them (which normally would not be allowed in Ada), and then performing an
14414 aggregate assignment.  For example, given a variable @code{A_Rec} 
14415 declared to have a type such as:
14416
14417 @smallexample
14418 type Rec (Len : Small_Integer := 0) is record
14419     Id : Integer;
14420     Vals : IntArray (1 .. Len);
14421 end record;
14422 @end smallexample
14423
14424 you can assign a value with a different size of @code{Vals} with two
14425 assignments:
14426
14427 @smallexample
14428 (@value{GDBP}) set A_Rec.Len := 4
14429 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
14430 @end smallexample
14431
14432 As this example also illustrates, @value{GDBN} is very loose about the usual
14433 rules concerning aggregates.  You may leave out some of the
14434 components of an array or record aggregate (such as the @code{Len} 
14435 component in the assignment to @code{A_Rec} above); they will retain their
14436 original values upon assignment.  You may freely use dynamic values as
14437 indices in component associations.  You may even use overlapping or
14438 redundant component associations, although which component values are
14439 assigned in such cases is not defined.
14440
14441 @item
14442 Calls to dispatching subprograms are not implemented.
14443
14444 @item
14445 The overloading algorithm is much more limited (i.e., less selective)
14446 than that of real Ada.  It makes only limited use of the context in
14447 which a subexpression appears to resolve its meaning, and it is much
14448 looser in its rules for allowing type matches.  As a result, some
14449 function calls will be ambiguous, and the user will be asked to choose
14450 the proper resolution.
14451
14452 @item
14453 The @code{new} operator is not implemented.
14454
14455 @item
14456 Entry calls are not implemented.
14457
14458 @item 
14459 Aside from printing, arithmetic operations on the native VAX floating-point 
14460 formats are not supported.
14461
14462 @item
14463 It is not possible to slice a packed array.
14464
14465 @item
14466 The names @code{True} and @code{False}, when not part of a qualified name, 
14467 are interpreted as if implicitly prefixed by @code{Standard}, regardless of 
14468 context.
14469 Should your program
14470 redefine these names in a package or procedure (at best a dubious practice),
14471 you will have to use fully qualified names to access their new definitions.
14472 @end itemize
14473
14474 @node Additions to Ada
14475 @subsubsection Additions to Ada
14476 @cindex Ada, deviations from 
14477
14478 As it does for other languages, @value{GDBN} makes certain generic
14479 extensions to Ada (@pxref{Expressions}):
14480
14481 @itemize @bullet
14482 @item
14483 If the expression @var{E} is a variable residing in memory (typically
14484 a local variable or array element) and @var{N} is a positive integer,
14485 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
14486 @var{N}-1 adjacent variables following it in memory as an array.  In
14487 Ada, this operator is generally not necessary, since its prime use is
14488 in displaying parts of an array, and slicing will usually do this in
14489 Ada.  However, there are occasional uses when debugging programs in
14490 which certain debugging information has been optimized away.
14491
14492 @item
14493 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
14494 appears in function or file @var{B}.''  When @var{B} is a file name,
14495 you must typically surround it in single quotes.
14496
14497 @item 
14498 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
14499 @var{type} that appears at address @var{addr}.''
14500
14501 @item
14502 A name starting with @samp{$} is a convenience variable 
14503 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
14504 @end itemize
14505
14506 In addition, @value{GDBN} provides a few other shortcuts and outright
14507 additions specific to Ada:
14508
14509 @itemize @bullet
14510 @item 
14511 The assignment statement is allowed as an expression, returning
14512 its right-hand operand as its value.  Thus, you may enter
14513
14514 @smallexample
14515 (@value{GDBP}) set x := y + 3
14516 (@value{GDBP}) print A(tmp := y + 1)
14517 @end smallexample
14518
14519 @item 
14520 The semicolon is allowed as an ``operator,''  returning as its value 
14521 the value of its right-hand operand.
14522 This allows, for example,
14523 complex conditional breaks:
14524
14525 @smallexample
14526 (@value{GDBP}) break f
14527 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
14528 @end smallexample
14529
14530 @item 
14531 Rather than use catenation and symbolic character names to introduce special 
14532 characters into strings, one may instead use a special bracket notation, 
14533 which is also used to print strings.  A sequence of characters of the form 
14534 @samp{["@var{XX}"]} within a string or character literal denotes the 
14535 (single) character whose numeric encoding is @var{XX} in hexadecimal.  The
14536 sequence of characters @samp{["""]} also denotes a single quotation mark 
14537 in strings.   For example,
14538 @smallexample
14539    "One line.["0a"]Next line.["0a"]"
14540 @end smallexample
14541 @noindent
14542 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
14543 after each period.
14544
14545 @item
14546 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
14547 @t{'Max} is optional (and is ignored in any case).  For example, it is valid
14548 to write
14549
14550 @smallexample
14551 (@value{GDBP}) print 'max(x, y)
14552 @end smallexample
14553
14554 @item
14555 When printing arrays, @value{GDBN} uses positional notation when the 
14556 array has a lower bound of 1, and uses a modified named notation otherwise.
14557 For example, a one-dimensional array of three integers with a lower bound
14558 of 3 might print as
14559
14560 @smallexample
14561 (3 => 10, 17, 1)
14562 @end smallexample
14563
14564 @noindent
14565 That is, in contrast to valid Ada, only the first component has a @code{=>} 
14566 clause.
14567
14568 @item
14569 You may abbreviate attributes in expressions with any unique,
14570 multi-character subsequence of 
14571 their names (an exact match gets preference).
14572 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
14573 in place of  @t{a'length}.
14574
14575 @item
14576 @cindex quoting Ada internal identifiers
14577 Since Ada is case-insensitive, the debugger normally maps identifiers you type 
14578 to lower case.  The GNAT compiler uses upper-case characters for 
14579 some of its internal identifiers, which are normally of no interest to users.
14580 For the rare occasions when you actually have to look at them,
14581 enclose them in angle brackets to avoid the lower-case mapping. 
14582 For example,
14583 @smallexample
14584 (@value{GDBP}) print <JMPBUF_SAVE>[0]
14585 @end smallexample
14586
14587 @item
14588 Printing an object of class-wide type or dereferencing an 
14589 access-to-class-wide value will display all the components of the object's
14590 specific type (as indicated by its run-time tag).  Likewise, component
14591 selection on such a value will operate on the specific type of the
14592 object.
14593
14594 @end itemize
14595
14596 @node Stopping Before Main Program
14597 @subsubsection Stopping at the Very Beginning
14598
14599 @cindex breakpointing Ada elaboration code
14600 It is sometimes necessary to debug the program during elaboration, and
14601 before reaching the main procedure.
14602 As defined in the Ada Reference
14603 Manual, the elaboration code is invoked from a procedure called
14604 @code{adainit}.  To run your program up to the beginning of
14605 elaboration, simply use the following two commands:
14606 @code{tbreak adainit} and @code{run}.
14607
14608 @node Ada Tasks
14609 @subsubsection Extensions for Ada Tasks
14610 @cindex Ada, tasking
14611
14612 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
14613 @value{GDBN} provides the following task-related commands:
14614
14615 @table @code
14616 @kindex info tasks
14617 @item info tasks
14618 This command shows a list of current Ada tasks, as in the following example:
14619
14620
14621 @smallexample
14622 @iftex
14623 @leftskip=0.5cm
14624 @end iftex
14625 (@value{GDBP}) info tasks
14626   ID       TID P-ID Pri State                 Name
14627    1   8088000   0   15 Child Activation Wait main_task
14628    2   80a4000   1   15 Accept Statement      b
14629    3   809a800   1   15 Child Activation Wait a
14630 *  4   80ae800   3   15 Runnable              c
14631
14632 @end smallexample
14633
14634 @noindent
14635 In this listing, the asterisk before the last task indicates it to be the
14636 task currently being inspected.
14637
14638 @table @asis
14639 @item ID
14640 Represents @value{GDBN}'s internal task number.
14641
14642 @item TID
14643 The Ada task ID.
14644
14645 @item P-ID
14646 The parent's task ID (@value{GDBN}'s internal task number).
14647
14648 @item Pri
14649 The base priority of the task.
14650
14651 @item State
14652 Current state of the task.
14653
14654 @table @code
14655 @item Unactivated
14656 The task has been created but has not been activated.  It cannot be
14657 executing.
14658
14659 @item Runnable
14660 The task is not blocked for any reason known to Ada.  (It may be waiting
14661 for a mutex, though.) It is conceptually "executing" in normal mode.
14662
14663 @item Terminated
14664 The task is terminated, in the sense of ARM 9.3 (5).  Any dependents
14665 that were waiting on terminate alternatives have been awakened and have
14666 terminated themselves.
14667
14668 @item Child Activation Wait
14669 The task is waiting for created tasks to complete activation.
14670
14671 @item Accept Statement
14672 The task is waiting on an accept or selective wait statement.
14673
14674 @item Waiting on entry call
14675 The task is waiting on an entry call.
14676
14677 @item Async Select Wait
14678 The task is waiting to start the abortable part of an asynchronous
14679 select statement.
14680
14681 @item Delay Sleep
14682 The task is waiting on a select statement with only a delay
14683 alternative open.
14684
14685 @item Child Termination Wait
14686 The task is sleeping having completed a master within itself, and is
14687 waiting for the tasks dependent on that master to become terminated or
14688 waiting on a terminate Phase.
14689
14690 @item Wait Child in Term Alt
14691 The task is sleeping waiting for tasks on terminate alternatives to
14692 finish terminating.
14693
14694 @item Accepting RV with @var{taskno}
14695 The task is accepting a rendez-vous with the task @var{taskno}.
14696 @end table
14697
14698 @item Name
14699 Name of the task in the program.
14700
14701 @end table
14702
14703 @kindex info task @var{taskno}
14704 @item info task @var{taskno}
14705 This command shows detailled informations on the specified task, as in
14706 the following example:
14707 @smallexample
14708 @iftex
14709 @leftskip=0.5cm
14710 @end iftex
14711 (@value{GDBP}) info tasks
14712   ID       TID P-ID Pri State                  Name
14713    1   8077880    0  15 Child Activation Wait  main_task
14714 *  2   807c468    1  15 Runnable               task_1
14715 (@value{GDBP}) info task 2
14716 Ada Task: 0x807c468
14717 Name: task_1
14718 Thread: 0x807f378
14719 Parent: 1 (main_task)
14720 Base Priority: 15
14721 State: Runnable
14722 @end smallexample
14723
14724 @item task
14725 @kindex task@r{ (Ada)}
14726 @cindex current Ada task ID
14727 This command prints the ID of the current task.
14728
14729 @smallexample
14730 @iftex
14731 @leftskip=0.5cm
14732 @end iftex
14733 (@value{GDBP}) info tasks
14734   ID       TID P-ID Pri State                  Name
14735    1   8077870    0  15 Child Activation Wait  main_task
14736 *  2   807c458    1  15 Runnable               t
14737 (@value{GDBP}) task
14738 [Current task is 2]
14739 @end smallexample
14740
14741 @item task @var{taskno}
14742 @cindex Ada task switching
14743 This command is like the @code{thread @var{threadno}}
14744 command (@pxref{Threads}).  It switches the context of debugging
14745 from the current task to the given task.
14746
14747 @smallexample
14748 @iftex
14749 @leftskip=0.5cm
14750 @end iftex
14751 (@value{GDBP}) info tasks
14752   ID       TID P-ID Pri State                  Name
14753    1   8077870    0  15 Child Activation Wait  main_task
14754 *  2   807c458    1  15 Runnable               t
14755 (@value{GDBP}) task 1
14756 [Switching to task 1]
14757 #0  0x8067726 in pthread_cond_wait ()
14758 (@value{GDBP}) bt
14759 #0  0x8067726 in pthread_cond_wait ()
14760 #1  0x8056714 in system.os_interface.pthread_cond_wait ()
14761 #2  0x805cb63 in system.task_primitives.operations.sleep ()
14762 #3  0x806153e in system.tasking.stages.activate_tasks ()
14763 #4  0x804aacc in un () at un.adb:5
14764 @end smallexample
14765
14766 @item break @var{linespec} task @var{taskno}
14767 @itemx break @var{linespec} task @var{taskno} if @dots{}
14768 @cindex breakpoints and tasks, in Ada
14769 @cindex task breakpoints, in Ada
14770 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
14771 These commands are like the @code{break @dots{} thread @dots{}}
14772 command (@pxref{Thread Stops}).
14773 @var{linespec} specifies source lines, as described
14774 in @ref{Specify Location}.
14775
14776 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
14777 to specify that you only want @value{GDBN} to stop the program when a
14778 particular Ada task reaches this breakpoint.  @var{taskno} is one of the
14779 numeric task identifiers assigned by @value{GDBN}, shown in the first
14780 column of the @samp{info tasks} display.
14781
14782 If you do not specify @samp{task @var{taskno}} when you set a
14783 breakpoint, the breakpoint applies to @emph{all} tasks of your
14784 program.
14785
14786 You can use the @code{task} qualifier on conditional breakpoints as
14787 well; in this case, place @samp{task @var{taskno}} before the
14788 breakpoint condition (before the @code{if}).
14789
14790 For example,
14791
14792 @smallexample
14793 @iftex
14794 @leftskip=0.5cm
14795 @end iftex
14796 (@value{GDBP}) info tasks
14797   ID       TID P-ID Pri State                 Name
14798    1 140022020   0   15 Child Activation Wait main_task
14799    2 140045060   1   15 Accept/Select Wait    t2
14800    3 140044840   1   15 Runnable              t1
14801 *  4 140056040   1   15 Runnable              t3
14802 (@value{GDBP}) b 15 task 2
14803 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
14804 (@value{GDBP}) cont
14805 Continuing.
14806 task # 1 running
14807 task # 2 running
14808
14809 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
14810 15               flush;
14811 (@value{GDBP}) info tasks
14812   ID       TID P-ID Pri State                 Name
14813    1 140022020   0   15 Child Activation Wait main_task
14814 *  2 140045060   1   15 Runnable              t2
14815    3 140044840   1   15 Runnable              t1
14816    4 140056040   1   15 Delay Sleep           t3
14817 @end smallexample
14818 @end table
14819
14820 @node Ada Tasks and Core Files
14821 @subsubsection Tasking Support when Debugging Core Files
14822 @cindex Ada tasking and core file debugging
14823
14824 When inspecting a core file, as opposed to debugging a live program,
14825 tasking support may be limited or even unavailable, depending on
14826 the platform being used.
14827 For instance, on x86-linux, the list of tasks is available, but task
14828 switching is not supported.  On Tru64, however, task switching will work
14829 as usual.
14830
14831 On certain platforms, including Tru64, the debugger needs to perform some
14832 memory writes in order to provide Ada tasking support.  When inspecting
14833 a core file, this means that the core file must be opened with read-write
14834 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
14835 Under these circumstances, you should make a backup copy of the core
14836 file before inspecting it with @value{GDBN}.
14837
14838 @node Ravenscar Profile
14839 @subsubsection Tasking Support when using the Ravenscar Profile
14840 @cindex Ravenscar Profile
14841
14842 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
14843 specifically designed for systems with safety-critical real-time
14844 requirements.
14845
14846 @table @code
14847 @kindex set ravenscar task-switching on
14848 @cindex task switching with program using Ravenscar Profile
14849 @item set ravenscar task-switching on
14850 Allows task switching when debugging a program that uses the Ravenscar
14851 Profile.  This is the default.
14852
14853 @kindex set ravenscar task-switching off
14854 @item set ravenscar task-switching off
14855 Turn off task switching when debugging a program that uses the Ravenscar
14856 Profile.  This is mostly intended to disable the code that adds support
14857 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
14858 the Ravenscar runtime is preventing @value{GDBN} from working properly.
14859 To be effective, this command should be run before the program is started.
14860
14861 @kindex show ravenscar task-switching
14862 @item show ravenscar task-switching
14863 Show whether it is possible to switch from task to task in a program
14864 using the Ravenscar Profile.
14865
14866 @end table
14867
14868 @node Ada Glitches
14869 @subsubsection Known Peculiarities of Ada Mode
14870 @cindex Ada, problems
14871
14872 Besides the omissions listed previously (@pxref{Omissions from Ada}),
14873 we know of several problems with and limitations of Ada mode in
14874 @value{GDBN},
14875 some of which will be fixed with planned future releases of the debugger 
14876 and the GNU Ada compiler.
14877
14878 @itemize @bullet
14879 @item 
14880 Static constants that the compiler chooses not to materialize as objects in 
14881 storage are invisible to the debugger.
14882
14883 @item
14884 Named parameter associations in function argument lists are ignored (the
14885 argument lists are treated as positional).
14886
14887 @item
14888 Many useful library packages are currently invisible to the debugger.
14889
14890 @item
14891 Fixed-point arithmetic, conversions, input, and output is carried out using 
14892 floating-point arithmetic, and may give results that only approximate those on 
14893 the host machine.
14894
14895 @item
14896 The GNAT compiler never generates the prefix @code{Standard} for any of 
14897 the standard symbols defined by the Ada language.  @value{GDBN} knows about 
14898 this: it will strip the prefix from names when you use it, and will never
14899 look for a name you have so qualified among local symbols, nor match against
14900 symbols in other packages or subprograms.  If you have 
14901 defined entities anywhere in your program other than parameters and 
14902 local variables whose simple names match names in @code{Standard}, 
14903 GNAT's lack of qualification here can cause confusion.  When this happens,
14904 you can usually resolve the confusion 
14905 by qualifying the problematic names with package
14906 @code{Standard} explicitly.  
14907 @end itemize
14908
14909 Older versions of the compiler sometimes generate erroneous debugging
14910 information, resulting in the debugger incorrectly printing the value
14911 of affected entities.  In some cases, the debugger is able to work
14912 around an issue automatically. In other cases, the debugger is able
14913 to work around the issue, but the work-around has to be specifically
14914 enabled.
14915
14916 @kindex set ada trust-PAD-over-XVS
14917 @kindex show ada trust-PAD-over-XVS
14918 @table @code
14919
14920 @item set ada trust-PAD-over-XVS on
14921 Configure GDB to strictly follow the GNAT encoding when computing the
14922 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
14923 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
14924 a complete description of the encoding used by the GNAT compiler).
14925 This is the default.
14926
14927 @item set ada trust-PAD-over-XVS off
14928 This is related to the encoding using by the GNAT compiler.  If @value{GDBN}
14929 sometimes prints the wrong value for certain entities, changing @code{ada
14930 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
14931 the issue.  It is always safe to set @code{ada trust-PAD-over-XVS} to
14932 @code{off}, but this incurs a slight performance penalty, so it is
14933 recommended to leave this setting to @code{on} unless necessary.
14934
14935 @end table
14936
14937 @node Unsupported Languages
14938 @section Unsupported Languages
14939
14940 @cindex unsupported languages
14941 @cindex minimal language
14942 In addition to the other fully-supported programming languages,
14943 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
14944 It does not represent a real programming language, but provides a set
14945 of capabilities close to what the C or assembly languages provide.
14946 This should allow most simple operations to be performed while debugging
14947 an application that uses a language currently not supported by @value{GDBN}.
14948
14949 If the language is set to @code{auto}, @value{GDBN} will automatically
14950 select this language if the current frame corresponds to an unsupported
14951 language.
14952
14953 @node Symbols
14954 @chapter Examining the Symbol Table
14955
14956 The commands described in this chapter allow you to inquire about the
14957 symbols (names of variables, functions and types) defined in your
14958 program.  This information is inherent in the text of your program and
14959 does not change as your program executes.  @value{GDBN} finds it in your
14960 program's symbol table, in the file indicated when you started @value{GDBN}
14961 (@pxref{File Options, ,Choosing Files}), or by one of the
14962 file-management commands (@pxref{Files, ,Commands to Specify Files}).
14963
14964 @cindex symbol names
14965 @cindex names of symbols
14966 @cindex quoting names
14967 Occasionally, you may need to refer to symbols that contain unusual
14968 characters, which @value{GDBN} ordinarily treats as word delimiters.  The
14969 most frequent case is in referring to static variables in other
14970 source files (@pxref{Variables,,Program Variables}).  File names
14971 are recorded in object files as debugging symbols, but @value{GDBN} would
14972 ordinarily parse a typical file name, like @file{foo.c}, as the three words
14973 @samp{foo} @samp{.} @samp{c}.  To allow @value{GDBN} to recognize
14974 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
14975
14976 @smallexample
14977 p 'foo.c'::x
14978 @end smallexample
14979
14980 @noindent
14981 looks up the value of @code{x} in the scope of the file @file{foo.c}.
14982
14983 @table @code
14984 @cindex case-insensitive symbol names
14985 @cindex case sensitivity in symbol names
14986 @kindex set case-sensitive
14987 @item set case-sensitive on
14988 @itemx set case-sensitive off
14989 @itemx set case-sensitive auto
14990 Normally, when @value{GDBN} looks up symbols, it matches their names
14991 with case sensitivity determined by the current source language.
14992 Occasionally, you may wish to control that.  The command @code{set
14993 case-sensitive} lets you do that by specifying @code{on} for
14994 case-sensitive matches or @code{off} for case-insensitive ones.  If
14995 you specify @code{auto}, case sensitivity is reset to the default
14996 suitable for the source language.  The default is case-sensitive
14997 matches for all languages except for Fortran, for which the default is
14998 case-insensitive matches.
14999
15000 @kindex show case-sensitive
15001 @item show case-sensitive
15002 This command shows the current setting of case sensitivity for symbols
15003 lookups.
15004
15005 @kindex set print type methods
15006 @item set print type methods
15007 @itemx set print type methods on
15008 @itemx set print type methods off
15009 Normally, when @value{GDBN} prints a class, it displays any methods
15010 declared in that class.  You can control this behavior either by
15011 passing the appropriate flag to @code{ptype}, or using @command{set
15012 print type methods}.  Specifying @code{on} will cause @value{GDBN} to
15013 display the methods; this is the default.  Specifying @code{off} will
15014 cause @value{GDBN} to omit the methods.
15015
15016 @kindex show print type methods
15017 @item show print type methods
15018 This command shows the current setting of method display when printing
15019 classes.
15020
15021 @kindex set print type typedefs
15022 @item set print type typedefs
15023 @itemx set print type typedefs on
15024 @itemx set print type typedefs off
15025
15026 Normally, when @value{GDBN} prints a class, it displays any typedefs
15027 defined in that class.  You can control this behavior either by
15028 passing the appropriate flag to @code{ptype}, or using @command{set
15029 print type typedefs}.  Specifying @code{on} will cause @value{GDBN} to
15030 display the typedef definitions; this is the default.  Specifying
15031 @code{off} will cause @value{GDBN} to omit the typedef definitions.
15032 Note that this controls whether the typedef definition itself is
15033 printed, not whether typedef names are substituted when printing other
15034 types.
15035
15036 @kindex show print type typedefs
15037 @item show print type typedefs
15038 This command shows the current setting of typedef display when
15039 printing classes.
15040
15041 @kindex info address
15042 @cindex address of a symbol
15043 @item info address @var{symbol}
15044 Describe where the data for @var{symbol} is stored.  For a register
15045 variable, this says which register it is kept in.  For a non-register
15046 local variable, this prints the stack-frame offset at which the variable
15047 is always stored.
15048
15049 Note the contrast with @samp{print &@var{symbol}}, which does not work
15050 at all for a register variable, and for a stack local variable prints
15051 the exact address of the current instantiation of the variable.
15052
15053 @kindex info symbol
15054 @cindex symbol from address
15055 @cindex closest symbol and offset for an address
15056 @item info symbol @var{addr}
15057 Print the name of a symbol which is stored at the address @var{addr}.
15058 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
15059 nearest symbol and an offset from it:
15060
15061 @smallexample
15062 (@value{GDBP}) info symbol 0x54320
15063 _initialize_vx + 396 in section .text
15064 @end smallexample
15065
15066 @noindent
15067 This is the opposite of the @code{info address} command.  You can use
15068 it to find out the name of a variable or a function given its address.
15069
15070 For dynamically linked executables, the name of executable or shared
15071 library containing the symbol is also printed:
15072
15073 @smallexample
15074 (@value{GDBP}) info symbol 0x400225
15075 _start + 5 in section .text of /tmp/a.out
15076 (@value{GDBP}) info symbol 0x2aaaac2811cf
15077 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
15078 @end smallexample
15079
15080 @kindex whatis
15081 @item whatis[/@var{flags}] [@var{arg}]
15082 Print the data type of @var{arg}, which can be either an expression
15083 or a name of a data type.  With no argument, print the data type of
15084 @code{$}, the last value in the value history.
15085
15086 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
15087 is not actually evaluated, and any side-effecting operations (such as
15088 assignments or function calls) inside it do not take place.
15089
15090 If @var{arg} is a variable or an expression, @code{whatis} prints its
15091 literal type as it is used in the source code.  If the type was
15092 defined using a @code{typedef}, @code{whatis} will @emph{not} print
15093 the data type underlying the @code{typedef}.  If the type of the
15094 variable or the expression is a compound data type, such as
15095 @code{struct} or  @code{class}, @code{whatis} never prints their
15096 fields or methods.  It just prints the @code{struct}/@code{class}
15097 name (a.k.a.@: its @dfn{tag}).  If you want to see the members of
15098 such a compound data type, use @code{ptype}.
15099
15100 If @var{arg} is a type name that was defined using @code{typedef},
15101 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
15102 Unrolling means that @code{whatis} will show the underlying type used
15103 in the @code{typedef} declaration of @var{arg}.  However, if that
15104 underlying type is also a @code{typedef}, @code{whatis} will not
15105 unroll it.
15106
15107 For C code, the type names may also have the form @samp{class
15108 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
15109 @var{union-tag}} or @samp{enum @var{enum-tag}}.
15110
15111 @var{flags} can be used to modify how the type is displayed.
15112 Available flags are:
15113
15114 @table @code
15115 @item r
15116 Display in ``raw'' form.  Normally, @value{GDBN} substitutes template
15117 parameters and typedefs defined in a class when printing the class'
15118 members.  The @code{/r} flag disables this.
15119
15120 @item m
15121 Do not print methods defined in the class.
15122
15123 @item M
15124 Print methods defined in the class.  This is the default, but the flag
15125 exists in case you change the default with @command{set print type methods}.
15126
15127 @item t
15128 Do not print typedefs defined in the class.  Note that this controls
15129 whether the typedef definition itself is printed, not whether typedef
15130 names are substituted when printing other types.
15131
15132 @item T
15133 Print typedefs defined in the class.  This is the default, but the flag
15134 exists in case you change the default with @command{set print type typedefs}.
15135 @end table
15136
15137 @kindex ptype
15138 @item ptype[/@var{flags}] [@var{arg}]
15139 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
15140 detailed description of the type, instead of just the name of the type.
15141 @xref{Expressions, ,Expressions}.
15142
15143 Contrary to @code{whatis}, @code{ptype} always unrolls any
15144 @code{typedef}s in its argument declaration, whether the argument is
15145 a variable, expression, or a data type.  This means that @code{ptype}
15146 of a variable or an expression will not print literally its type as
15147 present in the source code---use @code{whatis} for that.  @code{typedef}s at
15148 the pointer or reference targets are also unrolled.  Only @code{typedef}s of
15149 fields, methods and inner @code{class typedef}s of @code{struct}s,
15150 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
15151
15152 For example, for this variable declaration:
15153
15154 @smallexample
15155 typedef double real_t;
15156 struct complex @{ real_t real; double imag; @};
15157 typedef struct complex complex_t;
15158 complex_t var;
15159 real_t *real_pointer_var;
15160 @end smallexample
15161
15162 @noindent
15163 the two commands give this output:
15164
15165 @smallexample
15166 @group
15167 (@value{GDBP}) whatis var
15168 type = complex_t
15169 (@value{GDBP}) ptype var
15170 type = struct complex @{
15171     real_t real;
15172     double imag;
15173 @}
15174 (@value{GDBP}) whatis complex_t
15175 type = struct complex
15176 (@value{GDBP}) whatis struct complex
15177 type = struct complex
15178 (@value{GDBP}) ptype struct complex
15179 type = struct complex @{
15180     real_t real;
15181     double imag;
15182 @}
15183 (@value{GDBP}) whatis real_pointer_var
15184 type = real_t *
15185 (@value{GDBP}) ptype real_pointer_var
15186 type = double *
15187 @end group
15188 @end smallexample
15189
15190 @noindent
15191 As with @code{whatis}, using @code{ptype} without an argument refers to
15192 the type of @code{$}, the last value in the value history.
15193
15194 @cindex incomplete type
15195 Sometimes, programs use opaque data types or incomplete specifications
15196 of complex data structure.  If the debug information included in the
15197 program does not allow @value{GDBN} to display a full declaration of
15198 the data type, it will say @samp{<incomplete type>}.  For example,
15199 given these declarations:
15200
15201 @smallexample
15202     struct foo;
15203     struct foo *fooptr;
15204 @end smallexample
15205
15206 @noindent
15207 but no definition for @code{struct foo} itself, @value{GDBN} will say:
15208
15209 @smallexample
15210   (@value{GDBP}) ptype foo
15211   $1 = <incomplete type>
15212 @end smallexample
15213
15214 @noindent
15215 ``Incomplete type'' is C terminology for data types that are not
15216 completely specified.
15217
15218 @kindex info types
15219 @item info types @var{regexp}
15220 @itemx info types
15221 Print a brief description of all types whose names match the regular
15222 expression @var{regexp} (or all types in your program, if you supply
15223 no argument).  Each complete typename is matched as though it were a
15224 complete line; thus, @samp{i type value} gives information on all
15225 types in your program whose names include the string @code{value}, but
15226 @samp{i type ^value$} gives information only on types whose complete
15227 name is @code{value}.
15228
15229 This command differs from @code{ptype} in two ways: first, like
15230 @code{whatis}, it does not print a detailed description; second, it
15231 lists all source files where a type is defined.
15232
15233 @kindex info type-printers
15234 @item info type-printers
15235 Versions of @value{GDBN} that ship with Python scripting enabled may
15236 have ``type printers'' available.  When using @command{ptype} or
15237 @command{whatis}, these printers are consulted when the name of a type
15238 is needed.  @xref{Type Printing API}, for more information on writing
15239 type printers.
15240
15241 @code{info type-printers} displays all the available type printers.
15242
15243 @kindex enable type-printer
15244 @kindex disable type-printer
15245 @item enable type-printer @var{name}@dots{}
15246 @item disable type-printer @var{name}@dots{}
15247 These commands can be used to enable or disable type printers.
15248
15249 @kindex info scope
15250 @cindex local variables
15251 @item info scope @var{location}
15252 List all the variables local to a particular scope.  This command
15253 accepts a @var{location} argument---a function name, a source line, or
15254 an address preceded by a @samp{*}, and prints all the variables local
15255 to the scope defined by that location.  (@xref{Specify Location}, for
15256 details about supported forms of @var{location}.)  For example:
15257
15258 @smallexample
15259 (@value{GDBP}) @b{info scope command_line_handler}
15260 Scope for command_line_handler:
15261 Symbol rl is an argument at stack/frame offset 8, length 4.
15262 Symbol linebuffer is in static storage at address 0x150a18, length 4.
15263 Symbol linelength is in static storage at address 0x150a1c, length 4.
15264 Symbol p is a local variable in register $esi, length 4.
15265 Symbol p1 is a local variable in register $ebx, length 4.
15266 Symbol nline is a local variable in register $edx, length 4.
15267 Symbol repeat is a local variable at frame offset -8, length 4.
15268 @end smallexample
15269
15270 @noindent
15271 This command is especially useful for determining what data to collect
15272 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
15273 collect}.
15274
15275 @kindex info source
15276 @item info source
15277 Show information about the current source file---that is, the source file for
15278 the function containing the current point of execution:
15279 @itemize @bullet
15280 @item
15281 the name of the source file, and the directory containing it,
15282 @item
15283 the directory it was compiled in,
15284 @item
15285 its length, in lines,
15286 @item
15287 which programming language it is written in,
15288 @item
15289 whether the executable includes debugging information for that file, and
15290 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
15291 @item
15292 whether the debugging information includes information about
15293 preprocessor macros.
15294 @end itemize
15295
15296
15297 @kindex info sources
15298 @item info sources
15299 Print the names of all source files in your program for which there is
15300 debugging information, organized into two lists: files whose symbols
15301 have already been read, and files whose symbols will be read when needed.
15302
15303 @kindex info functions
15304 @item info functions
15305 Print the names and data types of all defined functions.
15306
15307 @item info functions @var{regexp}
15308 Print the names and data types of all defined functions
15309 whose names contain a match for regular expression @var{regexp}.
15310 Thus, @samp{info fun step} finds all functions whose names
15311 include @code{step}; @samp{info fun ^step} finds those whose names
15312 start with @code{step}.  If a function name contains characters
15313 that conflict with the regular expression language (e.g.@:
15314 @samp{operator*()}), they may be quoted with a backslash.
15315
15316 @kindex info variables
15317 @item info variables
15318 Print the names and data types of all variables that are defined
15319 outside of functions (i.e.@: excluding local variables).
15320
15321 @item info variables @var{regexp}
15322 Print the names and data types of all variables (except for local
15323 variables) whose names contain a match for regular expression
15324 @var{regexp}.
15325
15326 @kindex info classes
15327 @cindex Objective-C, classes and selectors
15328 @item info classes
15329 @itemx info classes @var{regexp}
15330 Display all Objective-C classes in your program, or
15331 (with the @var{regexp} argument) all those matching a particular regular
15332 expression.
15333
15334 @kindex info selectors
15335 @item info selectors
15336 @itemx info selectors @var{regexp}
15337 Display all Objective-C selectors in your program, or
15338 (with the @var{regexp} argument) all those matching a particular regular
15339 expression.
15340
15341 @ignore
15342 This was never implemented.
15343 @kindex info methods
15344 @item info methods
15345 @itemx info methods @var{regexp}
15346 The @code{info methods} command permits the user to examine all defined
15347 methods within C@t{++} program, or (with the @var{regexp} argument) a
15348 specific set of methods found in the various C@t{++} classes.  Many
15349 C@t{++} classes provide a large number of methods.  Thus, the output
15350 from the @code{ptype} command can be overwhelming and hard to use.  The
15351 @code{info-methods} command filters the methods, printing only those
15352 which match the regular-expression @var{regexp}.
15353 @end ignore
15354
15355 @cindex opaque data types
15356 @kindex set opaque-type-resolution
15357 @item set opaque-type-resolution on
15358 Tell @value{GDBN} to resolve opaque types.  An opaque type is a type
15359 declared as a pointer to a @code{struct}, @code{class}, or
15360 @code{union}---for example, @code{struct MyType *}---that is used in one
15361 source file although the full declaration of @code{struct MyType} is in
15362 another source file.  The default is on.
15363
15364 A change in the setting of this subcommand will not take effect until
15365 the next time symbols for a file are loaded.
15366
15367 @item set opaque-type-resolution off
15368 Tell @value{GDBN} not to resolve opaque types.  In this case, the type
15369 is printed as follows:
15370 @smallexample
15371 @{<no data fields>@}
15372 @end smallexample
15373
15374 @kindex show opaque-type-resolution
15375 @item show opaque-type-resolution
15376 Show whether opaque types are resolved or not.
15377
15378 @kindex maint print symbols
15379 @cindex symbol dump
15380 @kindex maint print psymbols
15381 @cindex partial symbol dump
15382 @item maint print symbols @var{filename}
15383 @itemx maint print psymbols @var{filename}
15384 @itemx maint print msymbols @var{filename}
15385 Write a dump of debugging symbol data into the file @var{filename}.
15386 These commands are used to debug the @value{GDBN} symbol-reading code.  Only
15387 symbols with debugging data are included.  If you use @samp{maint print
15388 symbols}, @value{GDBN} includes all the symbols for which it has already
15389 collected full details: that is, @var{filename} reflects symbols for
15390 only those files whose symbols @value{GDBN} has read.  You can use the
15391 command @code{info sources} to find out which files these are.  If you
15392 use @samp{maint print psymbols} instead, the dump shows information about
15393 symbols that @value{GDBN} only knows partially---that is, symbols defined in
15394 files that @value{GDBN} has skimmed, but not yet read completely.  Finally,
15395 @samp{maint print msymbols} dumps just the minimal symbol information
15396 required for each object file from which @value{GDBN} has read some symbols.
15397 @xref{Files, ,Commands to Specify Files}, for a discussion of how
15398 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
15399
15400 @kindex maint info symtabs
15401 @kindex maint info psymtabs
15402 @cindex listing @value{GDBN}'s internal symbol tables
15403 @cindex symbol tables, listing @value{GDBN}'s internal
15404 @cindex full symbol tables, listing @value{GDBN}'s internal
15405 @cindex partial symbol tables, listing @value{GDBN}'s internal
15406 @item maint info symtabs @r{[} @var{regexp} @r{]}
15407 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
15408
15409 List the @code{struct symtab} or @code{struct partial_symtab}
15410 structures whose names match @var{regexp}.  If @var{regexp} is not
15411 given, list them all.  The output includes expressions which you can
15412 copy into a @value{GDBN} debugging this one to examine a particular
15413 structure in more detail.  For example:
15414
15415 @smallexample
15416 (@value{GDBP}) maint info psymtabs dwarf2read
15417 @{ objfile /home/gnu/build/gdb/gdb
15418   ((struct objfile *) 0x82e69d0)
15419   @{ psymtab /home/gnu/src/gdb/dwarf2read.c
15420     ((struct partial_symtab *) 0x8474b10)
15421     readin no
15422     fullname (null)
15423     text addresses 0x814d3c8 -- 0x8158074
15424     globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
15425     statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
15426     dependencies (none)
15427   @}
15428 @}
15429 (@value{GDBP}) maint info symtabs
15430 (@value{GDBP})
15431 @end smallexample
15432 @noindent
15433 We see that there is one partial symbol table whose filename contains
15434 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
15435 and we see that @value{GDBN} has not read in any symtabs yet at all.
15436 If we set a breakpoint on a function, that will cause @value{GDBN} to
15437 read the symtab for the compilation unit containing that function:
15438
15439 @smallexample
15440 (@value{GDBP}) break dwarf2_psymtab_to_symtab
15441 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
15442 line 1574.
15443 (@value{GDBP}) maint info symtabs
15444 @{ objfile /home/gnu/build/gdb/gdb
15445   ((struct objfile *) 0x82e69d0)
15446   @{ symtab /home/gnu/src/gdb/dwarf2read.c
15447     ((struct symtab *) 0x86c1f38)
15448     dirname (null)
15449     fullname (null)
15450     blockvector ((struct blockvector *) 0x86c1bd0) (primary)
15451     linetable ((struct linetable *) 0x8370fa0)
15452     debugformat DWARF 2
15453   @}
15454 @}
15455 (@value{GDBP})
15456 @end smallexample
15457 @end table
15458
15459
15460 @node Altering
15461 @chapter Altering Execution
15462
15463 Once you think you have found an error in your program, you might want to
15464 find out for certain whether correcting the apparent error would lead to
15465 correct results in the rest of the run.  You can find the answer by
15466 experiment, using the @value{GDBN} features for altering execution of the
15467 program.
15468
15469 For example, you can store new values into variables or memory
15470 locations, give your program a signal, restart it at a different
15471 address, or even return prematurely from a function.
15472
15473 @menu
15474 * Assignment::                  Assignment to variables
15475 * Jumping::                     Continuing at a different address
15476 * Signaling::                   Giving your program a signal
15477 * Returning::                   Returning from a function
15478 * Calling::                     Calling your program's functions
15479 * Patching::                    Patching your program
15480 @end menu
15481
15482 @node Assignment
15483 @section Assignment to Variables
15484
15485 @cindex assignment
15486 @cindex setting variables
15487 To alter the value of a variable, evaluate an assignment expression.
15488 @xref{Expressions, ,Expressions}.  For example,
15489
15490 @smallexample
15491 print x=4
15492 @end smallexample
15493
15494 @noindent
15495 stores the value 4 into the variable @code{x}, and then prints the
15496 value of the assignment expression (which is 4).
15497 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
15498 information on operators in supported languages.
15499
15500 @kindex set variable
15501 @cindex variables, setting
15502 If you are not interested in seeing the value of the assignment, use the
15503 @code{set} command instead of the @code{print} command.  @code{set} is
15504 really the same as @code{print} except that the expression's value is
15505 not printed and is not put in the value history (@pxref{Value History,
15506 ,Value History}).  The expression is evaluated only for its effects.
15507
15508 If the beginning of the argument string of the @code{set} command
15509 appears identical to a @code{set} subcommand, use the @code{set
15510 variable} command instead of just @code{set}.  This command is identical
15511 to @code{set} except for its lack of subcommands.  For example, if your
15512 program has a variable @code{width}, you get an error if you try to set
15513 a new value with just @samp{set width=13}, because @value{GDBN} has the
15514 command @code{set width}:
15515
15516 @smallexample
15517 (@value{GDBP}) whatis width
15518 type = double
15519 (@value{GDBP}) p width
15520 $4 = 13
15521 (@value{GDBP}) set width=47
15522 Invalid syntax in expression.
15523 @end smallexample
15524
15525 @noindent
15526 The invalid expression, of course, is @samp{=47}.  In
15527 order to actually set the program's variable @code{width}, use
15528
15529 @smallexample
15530 (@value{GDBP}) set var width=47
15531 @end smallexample
15532
15533 Because the @code{set} command has many subcommands that can conflict
15534 with the names of program variables, it is a good idea to use the
15535 @code{set variable} command instead of just @code{set}.  For example, if
15536 your program has a variable @code{g}, you run into problems if you try
15537 to set a new value with just @samp{set g=4}, because @value{GDBN} has
15538 the command @code{set gnutarget}, abbreviated @code{set g}:
15539
15540 @smallexample
15541 @group
15542 (@value{GDBP}) whatis g
15543 type = double
15544 (@value{GDBP}) p g
15545 $1 = 1
15546 (@value{GDBP}) set g=4
15547 (@value{GDBP}) p g
15548 $2 = 1
15549 (@value{GDBP}) r
15550 The program being debugged has been started already.
15551 Start it from the beginning? (y or n) y
15552 Starting program: /home/smith/cc_progs/a.out
15553 "/home/smith/cc_progs/a.out": can't open to read symbols:
15554                                  Invalid bfd target.
15555 (@value{GDBP}) show g
15556 The current BFD target is "=4".
15557 @end group
15558 @end smallexample
15559
15560 @noindent
15561 The program variable @code{g} did not change, and you silently set the
15562 @code{gnutarget} to an invalid value.  In order to set the variable
15563 @code{g}, use
15564
15565 @smallexample
15566 (@value{GDBP}) set var g=4
15567 @end smallexample
15568
15569 @value{GDBN} allows more implicit conversions in assignments than C; you can
15570 freely store an integer value into a pointer variable or vice versa,
15571 and you can convert any structure to any other structure that is the
15572 same length or shorter.
15573 @comment FIXME: how do structs align/pad in these conversions?
15574 @comment        /doc@cygnus.com 18dec1990
15575
15576 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
15577 construct to generate a value of specified type at a specified address
15578 (@pxref{Expressions, ,Expressions}).  For example, @code{@{int@}0x83040} refers
15579 to memory location @code{0x83040} as an integer (which implies a certain size
15580 and representation in memory), and
15581
15582 @smallexample
15583 set @{int@}0x83040 = 4
15584 @end smallexample
15585
15586 @noindent
15587 stores the value 4 into that memory location.
15588
15589 @node Jumping
15590 @section Continuing at a Different Address
15591
15592 Ordinarily, when you continue your program, you do so at the place where
15593 it stopped, with the @code{continue} command.  You can instead continue at
15594 an address of your own choosing, with the following commands:
15595
15596 @table @code
15597 @kindex jump
15598 @kindex j @r{(@code{jump})}
15599 @item jump @var{linespec}
15600 @itemx j @var{linespec}
15601 @itemx jump @var{location}
15602 @itemx j @var{location}
15603 Resume execution at line @var{linespec} or at address given by
15604 @var{location}.  Execution stops again immediately if there is a
15605 breakpoint there.  @xref{Specify Location}, for a description of the
15606 different forms of @var{linespec} and @var{location}.  It is common
15607 practice to use the @code{tbreak} command in conjunction with
15608 @code{jump}.  @xref{Set Breaks, ,Setting Breakpoints}.
15609
15610 The @code{jump} command does not change the current stack frame, or
15611 the stack pointer, or the contents of any memory location or any
15612 register other than the program counter.  If line @var{linespec} is in
15613 a different function from the one currently executing, the results may
15614 be bizarre if the two functions expect different patterns of arguments or
15615 of local variables.  For this reason, the @code{jump} command requests
15616 confirmation if the specified line is not in the function currently
15617 executing.  However, even bizarre results are predictable if you are
15618 well acquainted with the machine-language code of your program.
15619 @end table
15620
15621 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
15622 On many systems, you can get much the same effect as the @code{jump}
15623 command by storing a new value into the register @code{$pc}.  The
15624 difference is that this does not start your program running; it only
15625 changes the address of where it @emph{will} run when you continue.  For
15626 example,
15627
15628 @smallexample
15629 set $pc = 0x485
15630 @end smallexample
15631
15632 @noindent
15633 makes the next @code{continue} command or stepping command execute at
15634 address @code{0x485}, rather than at the address where your program stopped.
15635 @xref{Continuing and Stepping, ,Continuing and Stepping}.
15636
15637 The most common occasion to use the @code{jump} command is to back
15638 up---perhaps with more breakpoints set---over a portion of a program
15639 that has already executed, in order to examine its execution in more
15640 detail.
15641
15642 @c @group
15643 @node Signaling
15644 @section Giving your Program a Signal
15645 @cindex deliver a signal to a program
15646
15647 @table @code
15648 @kindex signal
15649 @item signal @var{signal}
15650 Resume execution where your program stopped, but immediately give it the
15651 signal @var{signal}.  @var{signal} can be the name or the number of a
15652 signal.  For example, on many systems @code{signal 2} and @code{signal
15653 SIGINT} are both ways of sending an interrupt signal.
15654
15655 Alternatively, if @var{signal} is zero, continue execution without
15656 giving a signal.  This is useful when your program stopped on account of
15657 a signal and would ordinarily see the signal when resumed with the
15658 @code{continue} command; @samp{signal 0} causes it to resume without a
15659 signal.
15660
15661 @code{signal} does not repeat when you press @key{RET} a second time
15662 after executing the command.
15663 @end table
15664 @c @end group
15665
15666 Invoking the @code{signal} command is not the same as invoking the
15667 @code{kill} utility from the shell.  Sending a signal with @code{kill}
15668 causes @value{GDBN} to decide what to do with the signal depending on
15669 the signal handling tables (@pxref{Signals}).  The @code{signal} command
15670 passes the signal directly to your program.
15671
15672
15673 @node Returning
15674 @section Returning from a Function
15675
15676 @table @code
15677 @cindex returning from a function
15678 @kindex return
15679 @item return
15680 @itemx return @var{expression}
15681 You can cancel execution of a function call with the @code{return}
15682 command.  If you give an
15683 @var{expression} argument, its value is used as the function's return
15684 value.
15685 @end table
15686
15687 When you use @code{return}, @value{GDBN} discards the selected stack frame
15688 (and all frames within it).  You can think of this as making the
15689 discarded frame return prematurely.  If you wish to specify a value to
15690 be returned, give that value as the argument to @code{return}.
15691
15692 This pops the selected stack frame (@pxref{Selection, ,Selecting a
15693 Frame}), and any other frames inside of it, leaving its caller as the
15694 innermost remaining frame.  That frame becomes selected.  The
15695 specified value is stored in the registers used for returning values
15696 of functions.
15697
15698 The @code{return} command does not resume execution; it leaves the
15699 program stopped in the state that would exist if the function had just
15700 returned.  In contrast, the @code{finish} command (@pxref{Continuing
15701 and Stepping, ,Continuing and Stepping}) resumes execution until the
15702 selected stack frame returns naturally.
15703
15704 @value{GDBN} needs to know how the @var{expression} argument should be set for
15705 the inferior.  The concrete registers assignment depends on the OS ABI and the
15706 type being returned by the selected stack frame.  For example it is common for
15707 OS ABI to return floating point values in FPU registers while integer values in
15708 CPU registers.  Still some ABIs return even floating point values in CPU
15709 registers.  Larger integer widths (such as @code{long long int}) also have
15710 specific placement rules.  @value{GDBN} already knows the OS ABI from its
15711 current target so it needs to find out also the type being returned to make the
15712 assignment into the right register(s).
15713
15714 Normally, the selected stack frame has debug info.  @value{GDBN} will always
15715 use the debug info instead of the implicit type of @var{expression} when the
15716 debug info is available.  For example, if you type @kbd{return -1}, and the
15717 function in the current stack frame is declared to return a @code{long long
15718 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
15719 into a @code{long long int}:
15720
15721 @smallexample
15722 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
15723 29        return 31;
15724 (@value{GDBP}) return -1
15725 Make func return now? (y or n) y
15726 #0  0x004004f6 in main () at gdb.base/return-nodebug.c:43
15727 43        printf ("result=%lld\n", func ());
15728 (@value{GDBP})
15729 @end smallexample
15730
15731 However, if the selected stack frame does not have a debug info, e.g., if the
15732 function was compiled without debug info, @value{GDBN} has to find out the type
15733 to return from user.  Specifying a different type by mistake may set the value
15734 in different inferior registers than the caller code expects.  For example,
15735 typing @kbd{return -1} with its implicit type @code{int} would set only a part
15736 of a @code{long long int} result for a debug info less function (on 32-bit
15737 architectures).  Therefore the user is required to specify the return type by
15738 an appropriate cast explicitly:
15739
15740 @smallexample
15741 Breakpoint 2, 0x0040050b in func ()
15742 (@value{GDBP}) return -1
15743 Return value type not available for selected stack frame.
15744 Please use an explicit cast of the value to return.
15745 (@value{GDBP}) return (long long int) -1
15746 Make selected stack frame return now? (y or n) y
15747 #0  0x00400526 in main ()
15748 (@value{GDBP})
15749 @end smallexample
15750
15751 @node Calling
15752 @section Calling Program Functions
15753
15754 @table @code
15755 @cindex calling functions
15756 @cindex inferior functions, calling
15757 @item print @var{expr}
15758 Evaluate the expression @var{expr} and display the resulting value.
15759 @var{expr} may include calls to functions in the program being
15760 debugged.
15761
15762 @kindex call
15763 @item call @var{expr}
15764 Evaluate the expression @var{expr} without displaying @code{void}
15765 returned values.
15766
15767 You can use this variant of the @code{print} command if you want to
15768 execute a function from your program that does not return anything
15769 (a.k.a.@: @dfn{a void function}), but without cluttering the output
15770 with @code{void} returned values that @value{GDBN} will otherwise
15771 print.  If the result is not void, it is printed and saved in the
15772 value history.
15773 @end table
15774
15775 It is possible for the function you call via the @code{print} or
15776 @code{call} command to generate a signal (e.g., if there's a bug in
15777 the function, or if you passed it incorrect arguments).  What happens
15778 in that case is controlled by the @code{set unwindonsignal} command.
15779
15780 Similarly, with a C@t{++} program it is possible for the function you
15781 call via the @code{print} or @code{call} command to generate an
15782 exception that is not handled due to the constraints of the dummy
15783 frame.  In this case, any exception that is raised in the frame, but has
15784 an out-of-frame exception handler will not be found.  GDB builds a
15785 dummy-frame for the inferior function call, and the unwinder cannot
15786 seek for exception handlers outside of this dummy-frame.  What happens
15787 in that case is controlled by the
15788 @code{set unwind-on-terminating-exception} command.
15789
15790 @table @code
15791 @item set unwindonsignal
15792 @kindex set unwindonsignal
15793 @cindex unwind stack in called functions
15794 @cindex call dummy stack unwinding
15795 Set unwinding of the stack if a signal is received while in a function
15796 that @value{GDBN} called in the program being debugged.  If set to on,
15797 @value{GDBN} unwinds the stack it created for the call and restores
15798 the context to what it was before the call.  If set to off (the
15799 default), @value{GDBN} stops in the frame where the signal was
15800 received.
15801
15802 @item show unwindonsignal
15803 @kindex show unwindonsignal
15804 Show the current setting of stack unwinding in the functions called by
15805 @value{GDBN}.
15806
15807 @item set unwind-on-terminating-exception
15808 @kindex set unwind-on-terminating-exception
15809 @cindex unwind stack in called functions with unhandled exceptions
15810 @cindex call dummy stack unwinding on unhandled exception.
15811 Set unwinding of the stack if a C@t{++} exception is raised, but left
15812 unhandled while in a function that @value{GDBN} called in the program being
15813 debugged.  If set to on (the default), @value{GDBN} unwinds the stack
15814 it created for the call and restores the context to what it was before
15815 the call.  If set to off, @value{GDBN} the exception is delivered to
15816 the default C@t{++} exception handler and the inferior terminated.
15817
15818 @item show unwind-on-terminating-exception
15819 @kindex show unwind-on-terminating-exception
15820 Show the current setting of stack unwinding in the functions called by
15821 @value{GDBN}.
15822
15823 @end table
15824
15825 @cindex weak alias functions
15826 Sometimes, a function you wish to call is actually a @dfn{weak alias}
15827 for another function.  In such case, @value{GDBN} might not pick up
15828 the type information, including the types of the function arguments,
15829 which causes @value{GDBN} to call the inferior function incorrectly.
15830 As a result, the called function will function erroneously and may
15831 even crash.  A solution to that is to use the name of the aliased
15832 function instead.
15833
15834 @node Patching
15835 @section Patching Programs
15836
15837 @cindex patching binaries
15838 @cindex writing into executables
15839 @cindex writing into corefiles
15840
15841 By default, @value{GDBN} opens the file containing your program's
15842 executable code (or the corefile) read-only.  This prevents accidental
15843 alterations to machine code; but it also prevents you from intentionally
15844 patching your program's binary.
15845
15846 If you'd like to be able to patch the binary, you can specify that
15847 explicitly with the @code{set write} command.  For example, you might
15848 want to turn on internal debugging flags, or even to make emergency
15849 repairs.
15850
15851 @table @code
15852 @kindex set write
15853 @item set write on
15854 @itemx set write off
15855 If you specify @samp{set write on}, @value{GDBN} opens executable and
15856 core files for both reading and writing; if you specify @kbd{set write
15857 off} (the default), @value{GDBN} opens them read-only.
15858
15859 If you have already loaded a file, you must load it again (using the
15860 @code{exec-file} or @code{core-file} command) after changing @code{set
15861 write}, for your new setting to take effect.
15862
15863 @item show write
15864 @kindex show write
15865 Display whether executable files and core files are opened for writing
15866 as well as reading.
15867 @end table
15868
15869 @node GDB Files
15870 @chapter @value{GDBN} Files
15871
15872 @value{GDBN} needs to know the file name of the program to be debugged,
15873 both in order to read its symbol table and in order to start your
15874 program.  To debug a core dump of a previous run, you must also tell
15875 @value{GDBN} the name of the core dump file.
15876
15877 @menu
15878 * Files::                       Commands to specify files
15879 * Separate Debug Files::        Debugging information in separate files
15880 * MiniDebugInfo::               Debugging information in a special section
15881 * Index Files::                 Index files speed up GDB
15882 * Symbol Errors::               Errors reading symbol files
15883 * Data Files::                  GDB data files
15884 @end menu
15885
15886 @node Files
15887 @section Commands to Specify Files
15888
15889 @cindex symbol table
15890 @cindex core dump file
15891
15892 You may want to specify executable and core dump file names.  The usual
15893 way to do this is at start-up time, using the arguments to
15894 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
15895 Out of @value{GDBN}}).
15896
15897 Occasionally it is necessary to change to a different file during a
15898 @value{GDBN} session.  Or you may run @value{GDBN} and forget to
15899 specify a file you want to use.  Or you are debugging a remote target
15900 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
15901 Program}).  In these situations the @value{GDBN} commands to specify
15902 new files are useful.
15903
15904 @table @code
15905 @cindex executable file
15906 @kindex file
15907 @item file @var{filename}
15908 Use @var{filename} as the program to be debugged.  It is read for its
15909 symbols and for the contents of pure memory.  It is also the program
15910 executed when you use the @code{run} command.  If you do not specify a
15911 directory and the file is not found in the @value{GDBN} working directory,
15912 @value{GDBN} uses the environment variable @code{PATH} as a list of
15913 directories to search, just as the shell does when looking for a program
15914 to run.  You can change the value of this variable, for both @value{GDBN}
15915 and your program, using the @code{path} command.
15916
15917 @cindex unlinked object files
15918 @cindex patching object files
15919 You can load unlinked object @file{.o} files into @value{GDBN} using
15920 the @code{file} command.  You will not be able to ``run'' an object
15921 file, but you can disassemble functions and inspect variables.  Also,
15922 if the underlying BFD functionality supports it, you could use
15923 @kbd{gdb -write} to patch object files using this technique.  Note
15924 that @value{GDBN} can neither interpret nor modify relocations in this
15925 case, so branches and some initialized variables will appear to go to
15926 the wrong place.  But this feature is still handy from time to time.
15927
15928 @item file
15929 @code{file} with no argument makes @value{GDBN} discard any information it
15930 has on both executable file and the symbol table.
15931
15932 @kindex exec-file
15933 @item exec-file @r{[} @var{filename} @r{]}
15934 Specify that the program to be run (but not the symbol table) is found
15935 in @var{filename}.  @value{GDBN} searches the environment variable @code{PATH}
15936 if necessary to locate your program.  Omitting @var{filename} means to
15937 discard information on the executable file.
15938
15939 @kindex symbol-file
15940 @item symbol-file @r{[} @var{filename} @r{]}
15941 Read symbol table information from file @var{filename}.  @code{PATH} is
15942 searched when necessary.  Use the @code{file} command to get both symbol
15943 table and program to run from the same file.
15944
15945 @code{symbol-file} with no argument clears out @value{GDBN} information on your
15946 program's symbol table.
15947
15948 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
15949 some breakpoints and auto-display expressions.  This is because they may
15950 contain pointers to the internal data recording symbols and data types,
15951 which are part of the old symbol table data being discarded inside
15952 @value{GDBN}.
15953
15954 @code{symbol-file} does not repeat if you press @key{RET} again after
15955 executing it once.
15956
15957 When @value{GDBN} is configured for a particular environment, it
15958 understands debugging information in whatever format is the standard
15959 generated for that environment; you may use either a @sc{gnu} compiler, or
15960 other compilers that adhere to the local conventions.
15961 Best results are usually obtained from @sc{gnu} compilers; for example,
15962 using @code{@value{NGCC}} you can generate debugging information for
15963 optimized code.
15964
15965 For most kinds of object files, with the exception of old SVR3 systems
15966 using COFF, the @code{symbol-file} command does not normally read the
15967 symbol table in full right away.  Instead, it scans the symbol table
15968 quickly to find which source files and which symbols are present.  The
15969 details are read later, one source file at a time, as they are needed.
15970
15971 The purpose of this two-stage reading strategy is to make @value{GDBN}
15972 start up faster.  For the most part, it is invisible except for
15973 occasional pauses while the symbol table details for a particular source
15974 file are being read.  (The @code{set verbose} command can turn these
15975 pauses into messages if desired.  @xref{Messages/Warnings, ,Optional
15976 Warnings and Messages}.)
15977
15978 We have not implemented the two-stage strategy for COFF yet.  When the
15979 symbol table is stored in COFF format, @code{symbol-file} reads the
15980 symbol table data in full right away.  Note that ``stabs-in-COFF''
15981 still does the two-stage strategy, since the debug info is actually
15982 in stabs format.
15983
15984 @kindex readnow
15985 @cindex reading symbols immediately
15986 @cindex symbols, reading immediately
15987 @item symbol-file @r{[} -readnow @r{]} @var{filename}
15988 @itemx file @r{[} -readnow @r{]} @var{filename}
15989 You can override the @value{GDBN} two-stage strategy for reading symbol
15990 tables by using the @samp{-readnow} option with any of the commands that
15991 load symbol table information, if you want to be sure @value{GDBN} has the
15992 entire symbol table available.
15993
15994 @c FIXME: for now no mention of directories, since this seems to be in
15995 @c flux.  13mar1992 status is that in theory GDB would look either in
15996 @c current dir or in same dir as myprog; but issues like competing
15997 @c GDB's, or clutter in system dirs, mean that in practice right now
15998 @c only current dir is used.  FFish says maybe a special GDB hierarchy
15999 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
16000 @c files.
16001
16002 @kindex core-file
16003 @item core-file @r{[}@var{filename}@r{]}
16004 @itemx core
16005 Specify the whereabouts of a core dump file to be used as the ``contents
16006 of memory''.  Traditionally, core files contain only some parts of the
16007 address space of the process that generated them; @value{GDBN} can access the
16008 executable file itself for other parts.
16009
16010 @code{core-file} with no argument specifies that no core file is
16011 to be used.
16012
16013 Note that the core file is ignored when your program is actually running
16014 under @value{GDBN}.  So, if you have been running your program and you
16015 wish to debug a core file instead, you must kill the subprocess in which
16016 the program is running.  To do this, use the @code{kill} command
16017 (@pxref{Kill Process, ,Killing the Child Process}).
16018
16019 @kindex add-symbol-file
16020 @cindex dynamic linking
16021 @item add-symbol-file @var{filename} @var{address}
16022 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
16023 @itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
16024 The @code{add-symbol-file} command reads additional symbol table
16025 information from the file @var{filename}.  You would use this command
16026 when @var{filename} has been dynamically loaded (by some other means)
16027 into the program that is running.  @var{address} should be the memory
16028 address at which the file has been loaded; @value{GDBN} cannot figure
16029 this out for itself.  You can additionally specify an arbitrary number
16030 of @samp{-s @var{section} @var{address}} pairs, to give an explicit
16031 section name and base address for that section.  You can specify any
16032 @var{address} as an expression.
16033
16034 The symbol table of the file @var{filename} is added to the symbol table
16035 originally read with the @code{symbol-file} command.  You can use the
16036 @code{add-symbol-file} command any number of times; the new symbol data
16037 thus read keeps adding to the old.  To discard all old symbol data
16038 instead, use the @code{symbol-file} command without any arguments.
16039
16040 @cindex relocatable object files, reading symbols from
16041 @cindex object files, relocatable, reading symbols from
16042 @cindex reading symbols from relocatable object files
16043 @cindex symbols, reading from relocatable object files
16044 @cindex @file{.o} files, reading symbols from
16045 Although @var{filename} is typically a shared library file, an
16046 executable file, or some other object file which has been fully
16047 relocated for loading into a process, you can also load symbolic
16048 information from relocatable @file{.o} files, as long as:
16049
16050 @itemize @bullet
16051 @item
16052 the file's symbolic information refers only to linker symbols defined in
16053 that file, not to symbols defined by other object files,
16054 @item
16055 every section the file's symbolic information refers to has actually
16056 been loaded into the inferior, as it appears in the file, and
16057 @item
16058 you can determine the address at which every section was loaded, and
16059 provide these to the @code{add-symbol-file} command.
16060 @end itemize
16061
16062 @noindent
16063 Some embedded operating systems, like Sun Chorus and VxWorks, can load
16064 relocatable files into an already running program; such systems
16065 typically make the requirements above easy to meet.  However, it's
16066 important to recognize that many native systems use complex link
16067 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
16068 assembly, for example) that make the requirements difficult to meet.  In
16069 general, one cannot assume that using @code{add-symbol-file} to read a
16070 relocatable object file's symbolic information will have the same effect
16071 as linking the relocatable object file into the program in the normal
16072 way.
16073
16074 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
16075
16076 @kindex add-symbol-file-from-memory
16077 @cindex @code{syscall DSO}
16078 @cindex load symbols from memory
16079 @item add-symbol-file-from-memory @var{address}
16080 Load symbols from the given @var{address} in a dynamically loaded
16081 object file whose image is mapped directly into the inferior's memory.
16082 For example, the Linux kernel maps a @code{syscall DSO} into each
16083 process's address space; this DSO provides kernel-specific code for
16084 some system calls.  The argument can be any expression whose
16085 evaluation yields the address of the file's shared object file header.
16086 For this command to work, you must have used @code{symbol-file} or
16087 @code{exec-file} commands in advance.
16088
16089 @kindex add-shared-symbol-files
16090 @kindex assf
16091 @item add-shared-symbol-files @var{library-file}
16092 @itemx assf @var{library-file}
16093 The @code{add-shared-symbol-files} command can currently be used only
16094 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
16095 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
16096 @value{GDBN} automatically looks for shared libraries, however if
16097 @value{GDBN} does not find yours, you can invoke
16098 @code{add-shared-symbol-files}.  It takes one argument: the shared
16099 library's file name.  @code{assf} is a shorthand alias for
16100 @code{add-shared-symbol-files}.
16101
16102 @kindex section
16103 @item section @var{section} @var{addr}
16104 The @code{section} command changes the base address of the named
16105 @var{section} of the exec file to @var{addr}.  This can be used if the
16106 exec file does not contain section addresses, (such as in the
16107 @code{a.out} format), or when the addresses specified in the file
16108 itself are wrong.  Each section must be changed separately.  The
16109 @code{info files} command, described below, lists all the sections and
16110 their addresses.
16111
16112 @kindex info files
16113 @kindex info target
16114 @item info files
16115 @itemx info target
16116 @code{info files} and @code{info target} are synonymous; both print the
16117 current target (@pxref{Targets, ,Specifying a Debugging Target}),
16118 including the names of the executable and core dump files currently in
16119 use by @value{GDBN}, and the files from which symbols were loaded.  The
16120 command @code{help target} lists all possible targets rather than
16121 current ones.
16122
16123 @kindex maint info sections
16124 @item maint info sections
16125 Another command that can give you extra information about program sections
16126 is @code{maint info sections}.  In addition to the section information
16127 displayed by @code{info files}, this command displays the flags and file
16128 offset of each section in the executable and core dump files.  In addition,
16129 @code{maint info sections} provides the following command options (which
16130 may be arbitrarily combined):
16131
16132 @table @code
16133 @item ALLOBJ
16134 Display sections for all loaded object files, including shared libraries.
16135 @item @var{sections}
16136 Display info only for named @var{sections}.
16137 @item @var{section-flags}
16138 Display info only for sections for which @var{section-flags} are true.
16139 The section flags that @value{GDBN} currently knows about are:
16140 @table @code
16141 @item ALLOC
16142 Section will have space allocated in the process when loaded.
16143 Set for all sections except those containing debug information.
16144 @item LOAD
16145 Section will be loaded from the file into the child process memory.
16146 Set for pre-initialized code and data, clear for @code{.bss} sections.
16147 @item RELOC
16148 Section needs to be relocated before loading.
16149 @item READONLY
16150 Section cannot be modified by the child process.
16151 @item CODE
16152 Section contains executable code only.
16153 @item DATA
16154 Section contains data only (no executable code).
16155 @item ROM
16156 Section will reside in ROM.
16157 @item CONSTRUCTOR
16158 Section contains data for constructor/destructor lists.
16159 @item HAS_CONTENTS
16160 Section is not empty.
16161 @item NEVER_LOAD
16162 An instruction to the linker to not output the section.
16163 @item COFF_SHARED_LIBRARY
16164 A notification to the linker that the section contains
16165 COFF shared library information.
16166 @item IS_COMMON
16167 Section contains common symbols.
16168 @end table
16169 @end table
16170 @kindex set trust-readonly-sections
16171 @cindex read-only sections
16172 @item set trust-readonly-sections on
16173 Tell @value{GDBN} that readonly sections in your object file
16174 really are read-only (i.e.@: that their contents will not change).
16175 In that case, @value{GDBN} can fetch values from these sections
16176 out of the object file, rather than from the target program.
16177 For some targets (notably embedded ones), this can be a significant
16178 enhancement to debugging performance.
16179
16180 The default is off.
16181
16182 @item set trust-readonly-sections off
16183 Tell @value{GDBN} not to trust readonly sections.  This means that
16184 the contents of the section might change while the program is running,
16185 and must therefore be fetched from the target when needed.
16186
16187 @item show trust-readonly-sections
16188 Show the current setting of trusting readonly sections.
16189 @end table
16190
16191 All file-specifying commands allow both absolute and relative file names
16192 as arguments.  @value{GDBN} always converts the file name to an absolute file
16193 name and remembers it that way.
16194
16195 @cindex shared libraries
16196 @anchor{Shared Libraries}
16197 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
16198 and IBM RS/6000 AIX shared libraries.
16199
16200 On MS-Windows @value{GDBN} must be linked with the Expat library to support
16201 shared libraries.  @xref{Expat}.
16202
16203 @value{GDBN} automatically loads symbol definitions from shared libraries
16204 when you use the @code{run} command, or when you examine a core file.
16205 (Before you issue the @code{run} command, @value{GDBN} does not understand
16206 references to a function in a shared library, however---unless you are
16207 debugging a core file).
16208
16209 On HP-UX, if the program loads a library explicitly, @value{GDBN}
16210 automatically loads the symbols at the time of the @code{shl_load} call.
16211
16212 @c FIXME: some @value{GDBN} release may permit some refs to undef
16213 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
16214 @c FIXME...lib; check this from time to time when updating manual
16215
16216 There are times, however, when you may wish to not automatically load
16217 symbol definitions from shared libraries, such as when they are
16218 particularly large or there are many of them.
16219
16220 To control the automatic loading of shared library symbols, use the
16221 commands:
16222
16223 @table @code
16224 @kindex set auto-solib-add
16225 @item set auto-solib-add @var{mode}
16226 If @var{mode} is @code{on}, symbols from all shared object libraries
16227 will be loaded automatically when the inferior begins execution, you
16228 attach to an independently started inferior, or when the dynamic linker
16229 informs @value{GDBN} that a new library has been loaded.  If @var{mode}
16230 is @code{off}, symbols must be loaded manually, using the
16231 @code{sharedlibrary} command.  The default value is @code{on}.
16232
16233 @cindex memory used for symbol tables
16234 If your program uses lots of shared libraries with debug info that
16235 takes large amounts of memory, you can decrease the @value{GDBN}
16236 memory footprint by preventing it from automatically loading the
16237 symbols from shared libraries.  To that end, type @kbd{set
16238 auto-solib-add off} before running the inferior, then load each
16239 library whose debug symbols you do need with @kbd{sharedlibrary
16240 @var{regexp}}, where @var{regexp} is a regular expression that matches
16241 the libraries whose symbols you want to be loaded.
16242
16243 @kindex show auto-solib-add
16244 @item show auto-solib-add
16245 Display the current autoloading mode.
16246 @end table
16247
16248 @cindex load shared library
16249 To explicitly load shared library symbols, use the @code{sharedlibrary}
16250 command:
16251
16252 @table @code
16253 @kindex info sharedlibrary
16254 @kindex info share
16255 @item info share @var{regex}
16256 @itemx info sharedlibrary @var{regex}
16257 Print the names of the shared libraries which are currently loaded
16258 that match @var{regex}.  If @var{regex} is omitted then print
16259 all shared libraries that are loaded.
16260
16261 @kindex sharedlibrary
16262 @kindex share
16263 @item sharedlibrary @var{regex}
16264 @itemx share @var{regex}
16265 Load shared object library symbols for files matching a
16266 Unix regular expression.
16267 As with files loaded automatically, it only loads shared libraries
16268 required by your program for a core file or after typing @code{run}.  If
16269 @var{regex} is omitted all shared libraries required by your program are
16270 loaded.
16271
16272 @item nosharedlibrary
16273 @kindex nosharedlibrary
16274 @cindex unload symbols from shared libraries
16275 Unload all shared object library symbols.  This discards all symbols
16276 that have been loaded from all shared libraries.  Symbols from shared
16277 libraries that were loaded by explicit user requests are not
16278 discarded.
16279 @end table
16280
16281 Sometimes you may wish that @value{GDBN} stops and gives you control
16282 when any of shared library events happen.  The best way to do this is
16283 to use @code{catch load} and @code{catch unload} (@pxref{Set
16284 Catchpoints}).
16285
16286 @value{GDBN} also supports the the @code{set stop-on-solib-events}
16287 command for this.  This command exists for historical reasons.  It is
16288 less useful than setting a catchpoint, because it does not allow for
16289 conditions or commands as a catchpoint does.
16290
16291 @table @code
16292 @item set stop-on-solib-events
16293 @kindex set stop-on-solib-events
16294 This command controls whether @value{GDBN} should give you control
16295 when the dynamic linker notifies it about some shared library event.
16296 The most common event of interest is loading or unloading of a new
16297 shared library.
16298
16299 @item show stop-on-solib-events
16300 @kindex show stop-on-solib-events
16301 Show whether @value{GDBN} stops and gives you control when shared
16302 library events happen.
16303 @end table
16304
16305 Shared libraries are also supported in many cross or remote debugging
16306 configurations.  @value{GDBN} needs to have access to the target's libraries;
16307 this can be accomplished either by providing copies of the libraries
16308 on the host system, or by asking @value{GDBN} to automatically retrieve the
16309 libraries from the target.  If copies of the target libraries are
16310 provided, they need to be the same as the target libraries, although the
16311 copies on the target can be stripped as long as the copies on the host are
16312 not.
16313
16314 @cindex where to look for shared libraries
16315 For remote debugging, you need to tell @value{GDBN} where the target
16316 libraries are, so that it can load the correct copies---otherwise, it
16317 may try to load the host's libraries.  @value{GDBN} has two variables
16318 to specify the search directories for target libraries.
16319
16320 @table @code
16321 @cindex prefix for shared library file names
16322 @cindex system root, alternate
16323 @kindex set solib-absolute-prefix
16324 @kindex set sysroot
16325 @item set sysroot @var{path}
16326 Use @var{path} as the system root for the program being debugged.  Any
16327 absolute shared library paths will be prefixed with @var{path}; many
16328 runtime loaders store the absolute paths to the shared library in the
16329 target program's memory.  If you use @code{set sysroot} to find shared
16330 libraries, they need to be laid out in the same way that they are on
16331 the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
16332 under @var{path}.
16333
16334 If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will 
16335 retrieve the target libraries from the remote system.  This is only
16336 supported when using a remote target that supports the @code{remote get}
16337 command (@pxref{File Transfer,,Sending files to a remote system}).
16338 The part of @var{path} following the initial @file{remote:}
16339 (if present) is used as system root prefix on the remote file system.
16340 @footnote{If you want to specify a local system root using a directory
16341 that happens to be named @file{remote:}, you need to use some equivalent
16342 variant of the name like @file{./remote:}.}
16343
16344 For targets with an MS-DOS based filesystem, such as MS-Windows and
16345 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
16346 absolute file name with @var{path}.  But first, on Unix hosts,
16347 @value{GDBN} converts all backslash directory separators into forward
16348 slashes, because the backslash is not a directory separator on Unix:
16349
16350 @smallexample
16351   c:\foo\bar.dll @result{} c:/foo/bar.dll
16352 @end smallexample
16353
16354 Then, @value{GDBN} attempts prefixing the target file name with
16355 @var{path}, and looks for the resulting file name in the host file
16356 system:
16357
16358 @smallexample
16359   c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
16360 @end smallexample
16361
16362 If that does not find the shared library, @value{GDBN} tries removing
16363 the @samp{:} character from the drive spec, both for convenience, and,
16364 for the case of the host file system not supporting file names with
16365 colons:
16366
16367 @smallexample
16368   c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
16369 @end smallexample
16370
16371 This makes it possible to have a system root that mirrors a target
16372 with more than one drive.  E.g., you may want to setup your local
16373 copies of the target system shared libraries like so (note @samp{c} vs
16374 @samp{z}):
16375
16376 @smallexample
16377  @file{/path/to/sysroot/c/sys/bin/foo.dll}
16378  @file{/path/to/sysroot/c/sys/bin/bar.dll}
16379  @file{/path/to/sysroot/z/sys/bin/bar.dll}
16380 @end smallexample
16381
16382 @noindent
16383 and point the system root at @file{/path/to/sysroot}, so that
16384 @value{GDBN} can find the correct copies of both
16385 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
16386
16387 If that still does not find the shared library, @value{GDBN} tries
16388 removing the whole drive spec from the target file name:
16389
16390 @smallexample
16391   c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
16392 @end smallexample
16393
16394 This last lookup makes it possible to not care about the drive name,
16395 if you don't want or need to.
16396
16397 The @code{set solib-absolute-prefix} command is an alias for @code{set
16398 sysroot}.
16399
16400 @cindex default system root
16401 @cindex @samp{--with-sysroot}
16402 You can set the default system root by using the configure-time
16403 @samp{--with-sysroot} option.  If the system root is inside
16404 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
16405 @samp{--exec-prefix}), then the default system root will be updated
16406 automatically if the installed @value{GDBN} is moved to a new
16407 location.
16408
16409 @kindex show sysroot
16410 @item show sysroot
16411 Display the current shared library prefix.
16412
16413 @kindex set solib-search-path
16414 @item set solib-search-path @var{path}
16415 If this variable is set, @var{path} is a colon-separated list of
16416 directories to search for shared libraries.  @samp{solib-search-path}
16417 is used after @samp{sysroot} fails to locate the library, or if the
16418 path to the library is relative instead of absolute.  If you want to
16419 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
16420 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
16421 finding your host's libraries.  @samp{sysroot} is preferred; setting
16422 it to a nonexistent directory may interfere with automatic loading
16423 of shared library symbols.
16424
16425 @kindex show solib-search-path
16426 @item show solib-search-path
16427 Display the current shared library search path.
16428
16429 @cindex DOS file-name semantics of file names.
16430 @kindex set target-file-system-kind (unix|dos-based|auto)
16431 @kindex show target-file-system-kind
16432 @item set target-file-system-kind @var{kind}
16433 Set assumed file system kind for target reported file names.
16434
16435 Shared library file names as reported by the target system may not
16436 make sense as is on the system @value{GDBN} is running on.  For
16437 example, when remote debugging a target that has MS-DOS based file
16438 system semantics, from a Unix host, the target may be reporting to
16439 @value{GDBN} a list of loaded shared libraries with file names such as
16440 @file{c:\Windows\kernel32.dll}.  On Unix hosts, there's no concept of
16441 drive letters, so the @samp{c:\} prefix is not normally understood as
16442 indicating an absolute file name, and neither is the backslash
16443 normally considered a directory separator character.  In that case,
16444 the native file system would interpret this whole absolute file name
16445 as a relative file name with no directory components.  This would make
16446 it impossible to point @value{GDBN} at a copy of the remote target's
16447 shared libraries on the host using @code{set sysroot}, and impractical
16448 with @code{set solib-search-path}.  Setting
16449 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
16450 to interpret such file names similarly to how the target would, and to
16451 map them to file names valid on @value{GDBN}'s native file system
16452 semantics.  The value of @var{kind} can be @code{"auto"}, in addition
16453 to one of the supported file system kinds.  In that case, @value{GDBN}
16454 tries to determine the appropriate file system variant based on the
16455 current target's operating system (@pxref{ABI, ,Configuring the
16456 Current ABI}).  The supported file system settings are:
16457
16458 @table @code
16459 @item unix
16460 Instruct @value{GDBN} to assume the target file system is of Unix
16461 kind.  Only file names starting the forward slash (@samp{/}) character
16462 are considered absolute, and the directory separator character is also
16463 the forward slash.
16464
16465 @item dos-based
16466 Instruct @value{GDBN} to assume the target file system is DOS based.
16467 File names starting with either a forward slash, or a drive letter
16468 followed by a colon (e.g., @samp{c:}), are considered absolute, and
16469 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
16470 considered directory separators.
16471
16472 @item auto
16473 Instruct @value{GDBN} to use the file system kind associated with the
16474 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
16475 This is the default.
16476 @end table
16477 @end table
16478
16479 @cindex file name canonicalization
16480 @cindex base name differences
16481 When processing file names provided by the user, @value{GDBN}
16482 frequently needs to compare them to the file names recorded in the
16483 program's debug info.  Normally, @value{GDBN} compares just the
16484 @dfn{base names} of the files as strings, which is reasonably fast
16485 even for very large programs.  (The base name of a file is the last
16486 portion of its name, after stripping all the leading directories.)
16487 This shortcut in comparison is based upon the assumption that files
16488 cannot have more than one base name.  This is usually true, but
16489 references to files that use symlinks or similar filesystem
16490 facilities violate that assumption.  If your program records files
16491 using such facilities, or if you provide file names to @value{GDBN}
16492 using symlinks etc., you can set @code{basenames-may-differ} to
16493 @code{true} to instruct @value{GDBN} to completely canonicalize each
16494 pair of file names it needs to compare.  This will make file-name
16495 comparisons accurate, but at a price of a significant slowdown.
16496
16497 @table @code
16498 @item set basenames-may-differ
16499 @kindex set basenames-may-differ
16500 Set whether a source file may have multiple base names.
16501
16502 @item show basenames-may-differ
16503 @kindex show basenames-may-differ
16504 Show whether a source file may have multiple base names.
16505 @end table
16506
16507 @node Separate Debug Files
16508 @section Debugging Information in Separate Files
16509 @cindex separate debugging information files
16510 @cindex debugging information in separate files
16511 @cindex @file{.debug} subdirectories
16512 @cindex debugging information directory, global
16513 @cindex global debugging information directories
16514 @cindex build ID, and separate debugging files
16515 @cindex @file{.build-id} directory
16516
16517 @value{GDBN} allows you to put a program's debugging information in a
16518 file separate from the executable itself, in a way that allows
16519 @value{GDBN} to find and load the debugging information automatically.
16520 Since debugging information can be very large---sometimes larger
16521 than the executable code itself---some systems distribute debugging
16522 information for their executables in separate files, which users can
16523 install only when they need to debug a problem.
16524
16525 @value{GDBN} supports two ways of specifying the separate debug info
16526 file:
16527
16528 @itemize @bullet
16529 @item
16530 The executable contains a @dfn{debug link} that specifies the name of
16531 the separate debug info file.  The separate debug file's name is
16532 usually @file{@var{executable}.debug}, where @var{executable} is the
16533 name of the corresponding executable file without leading directories
16534 (e.g., @file{ls.debug} for @file{/usr/bin/ls}).  In addition, the
16535 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
16536 checksum for the debug file, which @value{GDBN} uses to validate that
16537 the executable and the debug file came from the same build.
16538
16539 @item
16540 The executable contains a @dfn{build ID}, a unique bit string that is
16541 also present in the corresponding debug info file.  (This is supported
16542 only on some operating systems, notably those which use the ELF format
16543 for binary files and the @sc{gnu} Binutils.)  For more details about
16544 this feature, see the description of the @option{--build-id}
16545 command-line option in @ref{Options, , Command Line Options, ld.info,
16546 The GNU Linker}.  The debug info file's name is not specified
16547 explicitly by the build ID, but can be computed from the build ID, see
16548 below.
16549 @end itemize
16550
16551 Depending on the way the debug info file is specified, @value{GDBN}
16552 uses two different methods of looking for the debug file:
16553
16554 @itemize @bullet
16555 @item
16556 For the ``debug link'' method, @value{GDBN} looks up the named file in
16557 the directory of the executable file, then in a subdirectory of that
16558 directory named @file{.debug}, and finally under each one of the global debug
16559 directories, in a subdirectory whose name is identical to the leading
16560 directories of the executable's absolute file name.
16561
16562 @item
16563 For the ``build ID'' method, @value{GDBN} looks in the
16564 @file{.build-id} subdirectory of each one of the global debug directories for
16565 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
16566 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
16567 are the rest of the bit string.  (Real build ID strings are 32 or more
16568 hex characters, not 10.)
16569 @end itemize
16570
16571 So, for example, suppose you ask @value{GDBN} to debug
16572 @file{/usr/bin/ls}, which has a debug link that specifies the
16573 file @file{ls.debug}, and a build ID whose value in hex is
16574 @code{abcdef1234}.  If the list of the global debug directories includes
16575 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
16576 debug information files, in the indicated order:
16577
16578 @itemize @minus
16579 @item
16580 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
16581 @item
16582 @file{/usr/bin/ls.debug}
16583 @item
16584 @file{/usr/bin/.debug/ls.debug}
16585 @item
16586 @file{/usr/lib/debug/usr/bin/ls.debug}.
16587 @end itemize
16588
16589 @anchor{debug-file-directory}
16590 Global debugging info directories default to what is set by @value{GDBN}
16591 configure option @option{--with-separate-debug-dir}.  During @value{GDBN} run
16592 you can also set the global debugging info directories, and view the list
16593 @value{GDBN} is currently using.
16594
16595 @table @code
16596
16597 @kindex set debug-file-directory
16598 @item set debug-file-directory @var{directories}
16599 Set the directories which @value{GDBN} searches for separate debugging
16600 information files to @var{directory}.  Multiple path components can be set
16601 concatenating them by a path separator.
16602
16603 @kindex show debug-file-directory
16604 @item show debug-file-directory
16605 Show the directories @value{GDBN} searches for separate debugging
16606 information files.
16607
16608 @end table
16609
16610 @cindex @code{.gnu_debuglink} sections
16611 @cindex debug link sections
16612 A debug link is a special section of the executable file named
16613 @code{.gnu_debuglink}.  The section must contain:
16614
16615 @itemize
16616 @item
16617 A filename, with any leading directory components removed, followed by
16618 a zero byte,
16619 @item
16620 zero to three bytes of padding, as needed to reach the next four-byte
16621 boundary within the section, and
16622 @item
16623 a four-byte CRC checksum, stored in the same endianness used for the
16624 executable file itself.  The checksum is computed on the debugging
16625 information file's full contents by the function given below, passing
16626 zero as the @var{crc} argument.
16627 @end itemize
16628
16629 Any executable file format can carry a debug link, as long as it can
16630 contain a section named @code{.gnu_debuglink} with the contents
16631 described above.
16632
16633 @cindex @code{.note.gnu.build-id} sections
16634 @cindex build ID sections
16635 The build ID is a special section in the executable file (and in other
16636 ELF binary files that @value{GDBN} may consider).  This section is
16637 often named @code{.note.gnu.build-id}, but that name is not mandatory.
16638 It contains unique identification for the built files---the ID remains
16639 the same across multiple builds of the same build tree.  The default
16640 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
16641 content for the build ID string.  The same section with an identical
16642 value is present in the original built binary with symbols, in its
16643 stripped variant, and in the separate debugging information file.
16644
16645 The debugging information file itself should be an ordinary
16646 executable, containing a full set of linker symbols, sections, and
16647 debugging information.  The sections of the debugging information file
16648 should have the same names, addresses, and sizes as the original file,
16649 but they need not contain any data---much like a @code{.bss} section
16650 in an ordinary executable.
16651
16652 The @sc{gnu} binary utilities (Binutils) package includes the
16653 @samp{objcopy} utility that can produce
16654 the separated executable / debugging information file pairs using the
16655 following commands:
16656
16657 @smallexample
16658 @kbd{objcopy --only-keep-debug foo foo.debug}
16659 @kbd{strip -g foo}
16660 @end smallexample
16661
16662 @noindent
16663 These commands remove the debugging
16664 information from the executable file @file{foo} and place it in the file
16665 @file{foo.debug}.  You can use the first, second or both methods to link the
16666 two files:
16667
16668 @itemize @bullet
16669 @item
16670 The debug link method needs the following additional command to also leave
16671 behind a debug link in @file{foo}:
16672
16673 @smallexample
16674 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
16675 @end smallexample
16676
16677 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
16678 a version of the @code{strip} command such that the command @kbd{strip foo -f
16679 foo.debug} has the same functionality as the two @code{objcopy} commands and
16680 the @code{ln -s} command above, together.
16681
16682 @item
16683 Build ID gets embedded into the main executable using @code{ld --build-id} or
16684 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}.  Build ID support plus
16685 compatibility fixes for debug files separation are present in @sc{gnu} binary
16686 utilities (Binutils) package since version 2.18.
16687 @end itemize
16688
16689 @noindent
16690
16691 @cindex CRC algorithm definition
16692 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
16693 IEEE 802.3 using the polynomial:
16694
16695 @c TexInfo requires naked braces for multi-digit exponents for Tex
16696 @c output, but this causes HTML output to barf. HTML has to be set using
16697 @c raw commands. So we end up having to specify this equation in 2
16698 @c different ways!
16699 @ifhtml
16700 @display
16701 @html
16702  <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>
16703  + <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
16704 @end html
16705 @end display
16706 @end ifhtml
16707 @ifnothtml
16708 @display
16709  @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
16710  @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
16711 @end display
16712 @end ifnothtml
16713
16714 The function is computed byte at a time, taking the least
16715 significant bit of each byte first.  The initial pattern
16716 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
16717 the final result is inverted to ensure trailing zeros also affect the
16718 CRC.
16719
16720 @emph{Note:} This is the same CRC polynomial as used in handling the
16721 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
16722 , @value{GDBN} Remote Serial Protocol}).  However in the
16723 case of the Remote Serial Protocol, the CRC is computed @emph{most}
16724 significant bit first, and the result is not inverted, so trailing
16725 zeros have no effect on the CRC value.
16726
16727 To complete the description, we show below the code of the function
16728 which produces the CRC used in @code{.gnu_debuglink}.  Inverting the
16729 initially supplied @code{crc} argument means that an initial call to
16730 this function passing in zero will start computing the CRC using
16731 @code{0xffffffff}.
16732
16733 @kindex gnu_debuglink_crc32
16734 @smallexample
16735 unsigned long
16736 gnu_debuglink_crc32 (unsigned long crc,
16737                      unsigned char *buf, size_t len)
16738 @{
16739   static const unsigned long crc32_table[256] =
16740     @{
16741       0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
16742       0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
16743       0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
16744       0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
16745       0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
16746       0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
16747       0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
16748       0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
16749       0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
16750       0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
16751       0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
16752       0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
16753       0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
16754       0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
16755       0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
16756       0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
16757       0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
16758       0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
16759       0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
16760       0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
16761       0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
16762       0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
16763       0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
16764       0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
16765       0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
16766       0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
16767       0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
16768       0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
16769       0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
16770       0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
16771       0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
16772       0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
16773       0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
16774       0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
16775       0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
16776       0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
16777       0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
16778       0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
16779       0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
16780       0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
16781       0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
16782       0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
16783       0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
16784       0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
16785       0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
16786       0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
16787       0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
16788       0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
16789       0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
16790       0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
16791       0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
16792       0x2d02ef8d
16793     @};
16794   unsigned char *end;
16795
16796   crc = ~crc & 0xffffffff;
16797   for (end = buf + len; buf < end; ++buf)
16798     crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
16799   return ~crc & 0xffffffff;
16800 @}
16801 @end smallexample
16802
16803 @noindent
16804 This computation does not apply to the ``build ID'' method.
16805
16806 @node MiniDebugInfo
16807 @section Debugging information in a special section
16808 @cindex separate debug sections
16809 @cindex @samp{.gnu_debugdata} section
16810
16811 Some systems ship pre-built executables and libraries that have a
16812 special @samp{.gnu_debugdata} section.  This feature is called
16813 @dfn{MiniDebugInfo}.  This section holds an LZMA-compressed object and
16814 is used to supply extra symbols for backtraces.
16815
16816 The intent of this section is to provide extra minimal debugging
16817 information for use in simple backtraces.  It is not intended to be a
16818 replacement for full separate debugging information (@pxref{Separate
16819 Debug Files}).  The example below shows the intended use; however,
16820 @value{GDBN} does not currently put restrictions on what sort of
16821 debugging information might be included in the section.
16822
16823 @value{GDBN} has support for this extension.  If the section exists,
16824 then it is used provided that no other source of debugging information
16825 can be found, and that @value{GDBN} was configured with LZMA support.
16826
16827 This section can be easily created using @command{objcopy} and other
16828 standard utilities:
16829
16830 @smallexample
16831 # Extract the dynamic symbols from the main binary, there is no need
16832 # to also have these in the normal symbol table
16833 nm -D @var{binary} --format=posix --defined-only \
16834   | awk '@{ print $1 @}' | sort > dynsyms
16835
16836 # Extract all the text (i.e. function) symbols from the debuginfo .
16837 nm @var{binary} --format=posix --defined-only \
16838   | awk '@{ if ($2 == "T" || $2 == "t") print $1 @}' \
16839   | sort > funcsyms
16840
16841 # Keep all the function symbols not already in the dynamic symbol
16842 # table.
16843 comm -13 dynsyms funcsyms > keep_symbols
16844
16845 # Copy the full debuginfo, keeping only a minimal set of symbols and
16846 # removing some unnecessary sections.
16847 objcopy -S --remove-section .gdb_index --remove-section .comment \
16848   --keep-symbols=keep_symbols @var{binary} mini_debuginfo
16849
16850 # Inject the compressed data into the .gnu_debugdata section of the
16851 # original binary.
16852 xz mini_debuginfo
16853 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
16854 @end smallexample
16855
16856 @node Index Files
16857 @section Index Files Speed Up @value{GDBN}
16858 @cindex index files
16859 @cindex @samp{.gdb_index} section
16860
16861 When @value{GDBN} finds a symbol file, it scans the symbols in the
16862 file in order to construct an internal symbol table.  This lets most
16863 @value{GDBN} operations work quickly---at the cost of a delay early
16864 on.  For large programs, this delay can be quite lengthy, so
16865 @value{GDBN} provides a way to build an index, which speeds up
16866 startup.
16867
16868 The index is stored as a section in the symbol file.  @value{GDBN} can
16869 write the index to a file, then you can put it into the symbol file
16870 using @command{objcopy}.
16871
16872 To create an index file, use the @code{save gdb-index} command:
16873
16874 @table @code
16875 @item save gdb-index @var{directory}
16876 @kindex save gdb-index
16877 Create an index file for each symbol file currently known by
16878 @value{GDBN}.  Each file is named after its corresponding symbol file,
16879 with @samp{.gdb-index} appended, and is written into the given
16880 @var{directory}.
16881 @end table
16882
16883 Once you have created an index file you can merge it into your symbol
16884 file, here named @file{symfile}, using @command{objcopy}:
16885
16886 @smallexample
16887 $ objcopy --add-section .gdb_index=symfile.gdb-index \
16888     --set-section-flags .gdb_index=readonly symfile symfile
16889 @end smallexample
16890
16891 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
16892 sections that have been deprecated.  Usually they are deprecated because
16893 they are missing a new feature or have performance issues.
16894 To tell @value{GDBN} to use a deprecated index section anyway
16895 specify @code{set use-deprecated-index-sections on}.
16896 The default is @code{off}.
16897 This can speed up startup, but may result in some functionality being lost.
16898 @xref{Index Section Format}.
16899
16900 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
16901 must be done before gdb reads the file.  The following will not work:
16902
16903 @smallexample
16904 $ gdb -ex "set use-deprecated-index-sections on" <program>
16905 @end smallexample
16906
16907 Instead you must do, for example,
16908
16909 @smallexample
16910 $ gdb -iex "set use-deprecated-index-sections on" <program>
16911 @end smallexample
16912
16913 There are currently some limitation on indices.  They only work when
16914 for DWARF debugging information, not stabs.  And, they do not
16915 currently work for programs using Ada.
16916
16917 @node Symbol Errors
16918 @section Errors Reading Symbol Files
16919
16920 While reading a symbol file, @value{GDBN} occasionally encounters problems,
16921 such as symbol types it does not recognize, or known bugs in compiler
16922 output.  By default, @value{GDBN} does not notify you of such problems, since
16923 they are relatively common and primarily of interest to people
16924 debugging compilers.  If you are interested in seeing information
16925 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
16926 only one message about each such type of problem, no matter how many
16927 times the problem occurs; or you can ask @value{GDBN} to print more messages,
16928 to see how many times the problems occur, with the @code{set
16929 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
16930 Messages}).
16931
16932 The messages currently printed, and their meanings, include:
16933
16934 @table @code
16935 @item inner block not inside outer block in @var{symbol}
16936
16937 The symbol information shows where symbol scopes begin and end
16938 (such as at the start of a function or a block of statements).  This
16939 error indicates that an inner scope block is not fully contained
16940 in its outer scope blocks.
16941
16942 @value{GDBN} circumvents the problem by treating the inner block as if it had
16943 the same scope as the outer block.  In the error message, @var{symbol}
16944 may be shown as ``@code{(don't know)}'' if the outer block is not a
16945 function.
16946
16947 @item block at @var{address} out of order
16948
16949 The symbol information for symbol scope blocks should occur in
16950 order of increasing addresses.  This error indicates that it does not
16951 do so.
16952
16953 @value{GDBN} does not circumvent this problem, and has trouble
16954 locating symbols in the source file whose symbols it is reading.  (You
16955 can often determine what source file is affected by specifying
16956 @code{set verbose on}.  @xref{Messages/Warnings, ,Optional Warnings and
16957 Messages}.)
16958
16959 @item bad block start address patched
16960
16961 The symbol information for a symbol scope block has a start address
16962 smaller than the address of the preceding source line.  This is known
16963 to occur in the SunOS 4.1.1 (and earlier) C compiler.
16964
16965 @value{GDBN} circumvents the problem by treating the symbol scope block as
16966 starting on the previous source line.
16967
16968 @item bad string table offset in symbol @var{n}
16969
16970 @cindex foo
16971 Symbol number @var{n} contains a pointer into the string table which is
16972 larger than the size of the string table.
16973
16974 @value{GDBN} circumvents the problem by considering the symbol to have the
16975 name @code{foo}, which may cause other problems if many symbols end up
16976 with this name.
16977
16978 @item unknown symbol type @code{0x@var{nn}}
16979
16980 The symbol information contains new data types that @value{GDBN} does
16981 not yet know how to read.  @code{0x@var{nn}} is the symbol type of the
16982 uncomprehended information, in hexadecimal.
16983
16984 @value{GDBN} circumvents the error by ignoring this symbol information.
16985 This usually allows you to debug your program, though certain symbols
16986 are not accessible.  If you encounter such a problem and feel like
16987 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
16988 on @code{complain}, then go up to the function @code{read_dbx_symtab}
16989 and examine @code{*bufp} to see the symbol.
16990
16991 @item stub type has NULL name
16992
16993 @value{GDBN} could not find the full definition for a struct or class.
16994
16995 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
16996 The symbol information for a C@t{++} member function is missing some
16997 information that recent versions of the compiler should have output for
16998 it.
16999
17000 @item info mismatch between compiler and debugger
17001
17002 @value{GDBN} could not parse a type specification output by the compiler.
17003
17004 @end table
17005
17006 @node Data Files
17007 @section GDB Data Files
17008
17009 @cindex prefix for data files
17010 @value{GDBN} will sometimes read an auxiliary data file.  These files
17011 are kept in a directory known as the @dfn{data directory}.
17012
17013 You can set the data directory's name, and view the name @value{GDBN}
17014 is currently using.
17015
17016 @table @code
17017 @kindex set data-directory
17018 @item set data-directory @var{directory}
17019 Set the directory which @value{GDBN} searches for auxiliary data files
17020 to @var{directory}.
17021
17022 @kindex show data-directory
17023 @item show data-directory
17024 Show the directory @value{GDBN} searches for auxiliary data files.
17025 @end table
17026
17027 @cindex default data directory
17028 @cindex @samp{--with-gdb-datadir}
17029 You can set the default data directory by using the configure-time
17030 @samp{--with-gdb-datadir} option.  If the data directory is inside
17031 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17032 @samp{--exec-prefix}), then the default data directory will be updated
17033 automatically if the installed @value{GDBN} is moved to a new
17034 location.
17035
17036 The data directory may also be specified with the
17037 @code{--data-directory} command line option.
17038 @xref{Mode Options}.
17039
17040 @node Targets
17041 @chapter Specifying a Debugging Target
17042
17043 @cindex debugging target
17044 A @dfn{target} is the execution environment occupied by your program.
17045
17046 Often, @value{GDBN} runs in the same host environment as your program;
17047 in that case, the debugging target is specified as a side effect when
17048 you use the @code{file} or @code{core} commands.  When you need more
17049 flexibility---for example, running @value{GDBN} on a physically separate
17050 host, or controlling a standalone system over a serial port or a
17051 realtime system over a TCP/IP connection---you can use the @code{target}
17052 command to specify one of the target types configured for @value{GDBN}
17053 (@pxref{Target Commands, ,Commands for Managing Targets}).
17054
17055 @cindex target architecture
17056 It is possible to build @value{GDBN} for several different @dfn{target
17057 architectures}.  When @value{GDBN} is built like that, you can choose
17058 one of the available architectures with the @kbd{set architecture}
17059 command.
17060
17061 @table @code
17062 @kindex set architecture
17063 @kindex show architecture
17064 @item set architecture @var{arch}
17065 This command sets the current target architecture to @var{arch}.  The
17066 value of @var{arch} can be @code{"auto"}, in addition to one of the
17067 supported architectures.
17068
17069 @item show architecture
17070 Show the current target architecture.
17071
17072 @item set processor
17073 @itemx processor
17074 @kindex set processor
17075 @kindex show processor
17076 These are alias commands for, respectively, @code{set architecture}
17077 and @code{show architecture}.
17078 @end table
17079
17080 @menu
17081 * Active Targets::              Active targets
17082 * Target Commands::             Commands for managing targets
17083 * Byte Order::                  Choosing target byte order
17084 @end menu
17085
17086 @node Active Targets
17087 @section Active Targets
17088
17089 @cindex stacking targets
17090 @cindex active targets
17091 @cindex multiple targets
17092
17093 There are multiple classes of targets such as: processes, executable files or
17094 recording sessions.  Core files belong to the process class, making core file
17095 and process mutually exclusive.  Otherwise, @value{GDBN} can work concurrently
17096 on multiple active targets, one in each class.  This allows you to (for
17097 example) start a process and inspect its activity, while still having access to
17098 the executable file after the process finishes.  Or if you start process
17099 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
17100 presented a virtual layer of the recording target, while the process target
17101 remains stopped at the chronologically last point of the process execution.
17102
17103 Use the @code{core-file} and @code{exec-file} commands to select a new core
17104 file or executable target (@pxref{Files, ,Commands to Specify Files}).  To
17105 specify as a target a process that is already running, use the @code{attach}
17106 command (@pxref{Attach, ,Debugging an Already-running Process}).
17107
17108 @node Target Commands
17109 @section Commands for Managing Targets
17110
17111 @table @code
17112 @item target @var{type} @var{parameters}
17113 Connects the @value{GDBN} host environment to a target machine or
17114 process.  A target is typically a protocol for talking to debugging
17115 facilities.  You use the argument @var{type} to specify the type or
17116 protocol of the target machine.
17117
17118 Further @var{parameters} are interpreted by the target protocol, but
17119 typically include things like device names or host names to connect
17120 with, process numbers, and baud rates.
17121
17122 The @code{target} command does not repeat if you press @key{RET} again
17123 after executing the command.
17124
17125 @kindex help target
17126 @item help target
17127 Displays the names of all targets available.  To display targets
17128 currently selected, use either @code{info target} or @code{info files}
17129 (@pxref{Files, ,Commands to Specify Files}).
17130
17131 @item help target @var{name}
17132 Describe a particular target, including any parameters necessary to
17133 select it.
17134
17135 @kindex set gnutarget
17136 @item set gnutarget @var{args}
17137 @value{GDBN} uses its own library BFD to read your files.  @value{GDBN}
17138 knows whether it is reading an @dfn{executable},
17139 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
17140 with the @code{set gnutarget} command.  Unlike most @code{target} commands,
17141 with @code{gnutarget} the @code{target} refers to a program, not a machine.
17142
17143 @quotation
17144 @emph{Warning:} To specify a file format with @code{set gnutarget},
17145 you must know the actual BFD name.
17146 @end quotation
17147
17148 @noindent
17149 @xref{Files, , Commands to Specify Files}.
17150
17151 @kindex show gnutarget
17152 @item show gnutarget
17153 Use the @code{show gnutarget} command to display what file format
17154 @code{gnutarget} is set to read.  If you have not set @code{gnutarget},
17155 @value{GDBN} will determine the file format for each file automatically,
17156 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
17157 @end table
17158
17159 @cindex common targets
17160 Here are some common targets (available, or not, depending on the GDB
17161 configuration):
17162
17163 @table @code
17164 @kindex target
17165 @item target exec @var{program}
17166 @cindex executable file target
17167 An executable file.  @samp{target exec @var{program}} is the same as
17168 @samp{exec-file @var{program}}.
17169
17170 @item target core @var{filename}
17171 @cindex core dump file target
17172 A core dump file.  @samp{target core @var{filename}} is the same as
17173 @samp{core-file @var{filename}}.
17174
17175 @item target remote @var{medium}
17176 @cindex remote target
17177 A remote system connected to @value{GDBN} via a serial line or network
17178 connection.  This command tells @value{GDBN} to use its own remote
17179 protocol over @var{medium} for debugging.  @xref{Remote Debugging}.
17180
17181 For example, if you have a board connected to @file{/dev/ttya} on the
17182 machine running @value{GDBN}, you could say:
17183
17184 @smallexample
17185 target remote /dev/ttya
17186 @end smallexample
17187
17188 @code{target remote} supports the @code{load} command.  This is only
17189 useful if you have some other way of getting the stub to the target
17190 system, and you can put it somewhere in memory where it won't get
17191 clobbered by the download.
17192
17193 @item target sim @r{[}@var{simargs}@r{]} @dots{}
17194 @cindex built-in simulator target
17195 Builtin CPU simulator.  @value{GDBN} includes simulators for most architectures.
17196 In general,
17197 @smallexample
17198         target sim
17199         load
17200         run
17201 @end smallexample
17202 @noindent
17203 works; however, you cannot assume that a specific memory map, device
17204 drivers, or even basic I/O is available, although some simulators do
17205 provide these.  For info about any processor-specific simulator details,
17206 see the appropriate section in @ref{Embedded Processors, ,Embedded
17207 Processors}.
17208
17209 @end table
17210
17211 Some configurations may include these targets as well:
17212
17213 @table @code
17214
17215 @item target nrom @var{dev}
17216 @cindex NetROM ROM emulator target
17217 NetROM ROM emulator.  This target only supports downloading.
17218
17219 @end table
17220
17221 Different targets are available on different configurations of @value{GDBN};
17222 your configuration may have more or fewer targets.
17223
17224 Many remote targets require you to download the executable's code once
17225 you've successfully established a connection.  You may wish to control
17226 various aspects of this process.
17227
17228 @table @code
17229
17230 @item set hash
17231 @kindex set hash@r{, for remote monitors}
17232 @cindex hash mark while downloading
17233 This command controls whether a hash mark @samp{#} is displayed while
17234 downloading a file to the remote monitor.  If on, a hash mark is
17235 displayed after each S-record is successfully downloaded to the
17236 monitor.
17237
17238 @item show hash
17239 @kindex show hash@r{, for remote monitors}
17240 Show the current status of displaying the hash mark.
17241
17242 @item set debug monitor
17243 @kindex set debug monitor
17244 @cindex display remote monitor communications
17245 Enable or disable display of communications messages between
17246 @value{GDBN} and the remote monitor.
17247
17248 @item show debug monitor
17249 @kindex show debug monitor
17250 Show the current status of displaying communications between
17251 @value{GDBN} and the remote monitor.
17252 @end table
17253
17254 @table @code
17255
17256 @kindex load @var{filename}
17257 @item load @var{filename}
17258 @anchor{load}
17259 Depending on what remote debugging facilities are configured into
17260 @value{GDBN}, the @code{load} command may be available.  Where it exists, it
17261 is meant to make @var{filename} (an executable) available for debugging
17262 on the remote system---by downloading, or dynamic linking, for example.
17263 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
17264 the @code{add-symbol-file} command.
17265
17266 If your @value{GDBN} does not have a @code{load} command, attempting to
17267 execute it gets the error message ``@code{You can't do that when your
17268 target is @dots{}}''
17269
17270 The file is loaded at whatever address is specified in the executable.
17271 For some object file formats, you can specify the load address when you
17272 link the program; for other formats, like a.out, the object file format
17273 specifies a fixed address.
17274 @c FIXME! This would be a good place for an xref to the GNU linker doc.
17275
17276 Depending on the remote side capabilities, @value{GDBN} may be able to
17277 load programs into flash memory.
17278
17279 @code{load} does not repeat if you press @key{RET} again after using it.
17280 @end table
17281
17282 @node Byte Order
17283 @section Choosing Target Byte Order
17284
17285 @cindex choosing target byte order
17286 @cindex target byte order
17287
17288 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
17289 offer the ability to run either big-endian or little-endian byte
17290 orders.  Usually the executable or symbol will include a bit to
17291 designate the endian-ness, and you will not need to worry about
17292 which to use.  However, you may still find it useful to adjust
17293 @value{GDBN}'s idea of processor endian-ness manually.
17294
17295 @table @code
17296 @kindex set endian
17297 @item set endian big
17298 Instruct @value{GDBN} to assume the target is big-endian.
17299
17300 @item set endian little
17301 Instruct @value{GDBN} to assume the target is little-endian.
17302
17303 @item set endian auto
17304 Instruct @value{GDBN} to use the byte order associated with the
17305 executable.
17306
17307 @item show endian
17308 Display @value{GDBN}'s current idea of the target byte order.
17309
17310 @end table
17311
17312 Note that these commands merely adjust interpretation of symbolic
17313 data on the host, and that they have absolutely no effect on the
17314 target system.
17315
17316
17317 @node Remote Debugging
17318 @chapter Debugging Remote Programs
17319 @cindex remote debugging
17320
17321 If you are trying to debug a program running on a machine that cannot run
17322 @value{GDBN} in the usual way, it is often useful to use remote debugging.
17323 For example, you might use remote debugging on an operating system kernel,
17324 or on a small system which does not have a general purpose operating system
17325 powerful enough to run a full-featured debugger.
17326
17327 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
17328 to make this work with particular debugging targets.  In addition,
17329 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
17330 but not specific to any particular target system) which you can use if you
17331 write the remote stubs---the code that runs on the remote system to
17332 communicate with @value{GDBN}.
17333
17334 Other remote targets may be available in your
17335 configuration of @value{GDBN}; use @code{help target} to list them.
17336
17337 @menu
17338 * Connecting::                  Connecting to a remote target
17339 * File Transfer::               Sending files to a remote system
17340 * Server::                      Using the gdbserver program
17341 * Remote Configuration::        Remote configuration
17342 * Remote Stub::                 Implementing a remote stub
17343 @end menu
17344
17345 @node Connecting
17346 @section Connecting to a Remote Target
17347
17348 On the @value{GDBN} host machine, you will need an unstripped copy of
17349 your program, since @value{GDBN} needs symbol and debugging information.
17350 Start up @value{GDBN} as usual, using the name of the local copy of your
17351 program as the first argument.
17352
17353 @cindex @code{target remote}
17354 @value{GDBN} can communicate with the target over a serial line, or
17355 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}.  In
17356 each case, @value{GDBN} uses the same protocol for debugging your
17357 program; only the medium carrying the debugging packets varies.  The
17358 @code{target remote} command establishes a connection to the target.
17359 Its arguments indicate which medium to use:
17360
17361 @table @code
17362
17363 @item target remote @var{serial-device}
17364 @cindex serial line, @code{target remote}
17365 Use @var{serial-device} to communicate with the target.  For example,
17366 to use a serial line connected to the device named @file{/dev/ttyb}:
17367
17368 @smallexample
17369 target remote /dev/ttyb
17370 @end smallexample
17371
17372 If you're using a serial line, you may want to give @value{GDBN} the
17373 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
17374 (@pxref{Remote Configuration, set remotebaud}) before the
17375 @code{target} command.
17376
17377 @item target remote @code{@var{host}:@var{port}}
17378 @itemx target remote @code{tcp:@var{host}:@var{port}}
17379 @cindex @acronym{TCP} port, @code{target remote}
17380 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
17381 The @var{host} may be either a host name or a numeric @acronym{IP}
17382 address; @var{port} must be a decimal number.  The @var{host} could be
17383 the target machine itself, if it is directly connected to the net, or
17384 it might be a terminal server which in turn has a serial line to the
17385 target.
17386
17387 For example, to connect to port 2828 on a terminal server named
17388 @code{manyfarms}:
17389
17390 @smallexample
17391 target remote manyfarms:2828
17392 @end smallexample
17393
17394 If your remote target is actually running on the same machine as your
17395 debugger session (e.g.@: a simulator for your target running on the
17396 same host), you can omit the hostname.  For example, to connect to
17397 port 1234 on your local machine:
17398
17399 @smallexample
17400 target remote :1234
17401 @end smallexample
17402 @noindent
17403
17404 Note that the colon is still required here.
17405
17406 @item target remote @code{udp:@var{host}:@var{port}}
17407 @cindex @acronym{UDP} port, @code{target remote}
17408 Debug using @acronym{UDP} packets to @var{port} on @var{host}.  For example, to
17409 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
17410
17411 @smallexample
17412 target remote udp:manyfarms:2828
17413 @end smallexample
17414
17415 When using a @acronym{UDP} connection for remote debugging, you should
17416 keep in mind that the `U' stands for ``Unreliable''.  @acronym{UDP}
17417 can silently drop packets on busy or unreliable networks, which will
17418 cause havoc with your debugging session.
17419
17420 @item target remote | @var{command}
17421 @cindex pipe, @code{target remote} to
17422 Run @var{command} in the background and communicate with it using a
17423 pipe.  The @var{command} is a shell command, to be parsed and expanded
17424 by the system's command shell, @code{/bin/sh}; it should expect remote
17425 protocol packets on its standard input, and send replies on its
17426 standard output.  You could use this to run a stand-alone simulator
17427 that speaks the remote debugging protocol, to make net connections
17428 using programs like @code{ssh}, or for other similar tricks.
17429
17430 If @var{command} closes its standard output (perhaps by exiting),
17431 @value{GDBN} will try to send it a @code{SIGTERM} signal.  (If the
17432 program has already exited, this will have no effect.)
17433
17434 @end table
17435
17436 Once the connection has been established, you can use all the usual
17437 commands to examine and change data.  The remote program is already
17438 running; you can use @kbd{step} and @kbd{continue}, and you do not
17439 need to use @kbd{run}.
17440
17441 @cindex interrupting remote programs
17442 @cindex remote programs, interrupting
17443 Whenever @value{GDBN} is waiting for the remote program, if you type the
17444 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
17445 program.  This may or may not succeed, depending in part on the hardware
17446 and the serial drivers the remote system uses.  If you type the
17447 interrupt character once again, @value{GDBN} displays this prompt:
17448
17449 @smallexample
17450 Interrupted while waiting for the program.
17451 Give up (and stop debugging it)?  (y or n)
17452 @end smallexample
17453
17454 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
17455 (If you decide you want to try again later, you can use @samp{target
17456 remote} again to connect once more.)  If you type @kbd{n}, @value{GDBN}
17457 goes back to waiting.
17458
17459 @table @code
17460 @kindex detach (remote)
17461 @item detach
17462 When you have finished debugging the remote program, you can use the
17463 @code{detach} command to release it from @value{GDBN} control.
17464 Detaching from the target normally resumes its execution, but the results
17465 will depend on your particular remote stub.  After the @code{detach}
17466 command, @value{GDBN} is free to connect to another target.
17467
17468 @kindex disconnect
17469 @item disconnect
17470 The @code{disconnect} command behaves like @code{detach}, except that
17471 the target is generally not resumed.  It will wait for @value{GDBN}
17472 (this instance or another one) to connect and continue debugging.  After
17473 the @code{disconnect} command, @value{GDBN} is again free to connect to
17474 another target.
17475
17476 @cindex send command to remote monitor
17477 @cindex extend @value{GDBN} for remote targets
17478 @cindex add new commands for external monitor
17479 @kindex monitor
17480 @item monitor @var{cmd}
17481 This command allows you to send arbitrary commands directly to the
17482 remote monitor.  Since @value{GDBN} doesn't care about the commands it
17483 sends like this, this command is the way to extend @value{GDBN}---you
17484 can add new commands that only the external monitor will understand
17485 and implement.
17486 @end table
17487
17488 @node File Transfer
17489 @section Sending files to a remote system
17490 @cindex remote target, file transfer
17491 @cindex file transfer
17492 @cindex sending files to remote systems
17493
17494 Some remote targets offer the ability to transfer files over the same
17495 connection used to communicate with @value{GDBN}.  This is convenient
17496 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
17497 running @code{gdbserver} over a network interface.  For other targets,
17498 e.g.@: embedded devices with only a single serial port, this may be
17499 the only way to upload or download files.
17500
17501 Not all remote targets support these commands.
17502
17503 @table @code
17504 @kindex remote put
17505 @item remote put @var{hostfile} @var{targetfile}
17506 Copy file @var{hostfile} from the host system (the machine running
17507 @value{GDBN}) to @var{targetfile} on the target system.
17508
17509 @kindex remote get
17510 @item remote get @var{targetfile} @var{hostfile}
17511 Copy file @var{targetfile} from the target system to @var{hostfile}
17512 on the host system.
17513
17514 @kindex remote delete
17515 @item remote delete @var{targetfile}
17516 Delete @var{targetfile} from the target system.
17517
17518 @end table
17519
17520 @node Server
17521 @section Using the @code{gdbserver} Program
17522
17523 @kindex gdbserver
17524 @cindex remote connection without stubs
17525 @code{gdbserver} is a control program for Unix-like systems, which
17526 allows you to connect your program with a remote @value{GDBN} via
17527 @code{target remote}---but without linking in the usual debugging stub.
17528
17529 @code{gdbserver} is not a complete replacement for the debugging stubs,
17530 because it requires essentially the same operating-system facilities
17531 that @value{GDBN} itself does.  In fact, a system that can run
17532 @code{gdbserver} to connect to a remote @value{GDBN} could also run
17533 @value{GDBN} locally!  @code{gdbserver} is sometimes useful nevertheless,
17534 because it is a much smaller program than @value{GDBN} itself.  It is
17535 also easier to port than all of @value{GDBN}, so you may be able to get
17536 started more quickly on a new system by using @code{gdbserver}.
17537 Finally, if you develop code for real-time systems, you may find that
17538 the tradeoffs involved in real-time operation make it more convenient to
17539 do as much development work as possible on another system, for example
17540 by cross-compiling.  You can use @code{gdbserver} to make a similar
17541 choice for debugging.
17542
17543 @value{GDBN} and @code{gdbserver} communicate via either a serial line
17544 or a TCP connection, using the standard @value{GDBN} remote serial
17545 protocol.
17546
17547 @quotation
17548 @emph{Warning:} @code{gdbserver} does not have any built-in security.
17549 Do not run @code{gdbserver} connected to any public network; a
17550 @value{GDBN} connection to @code{gdbserver} provides access to the
17551 target system with the same privileges as the user running
17552 @code{gdbserver}.
17553 @end quotation
17554
17555 @subsection Running @code{gdbserver}
17556 @cindex arguments, to @code{gdbserver}
17557 @cindex @code{gdbserver}, command-line arguments
17558
17559 Run @code{gdbserver} on the target system.  You need a copy of the
17560 program you want to debug, including any libraries it requires.
17561 @code{gdbserver} does not need your program's symbol table, so you can
17562 strip the program if necessary to save space.  @value{GDBN} on the host
17563 system does all the symbol handling.
17564
17565 To use the server, you must tell it how to communicate with @value{GDBN};
17566 the name of your program; and the arguments for your program.  The usual
17567 syntax is:
17568
17569 @smallexample
17570 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
17571 @end smallexample
17572
17573 @var{comm} is either a device name (to use a serial line), or a TCP
17574 hostname and portnumber, or @code{-} or @code{stdio} to use
17575 stdin/stdout of @code{gdbserver}.
17576 For example, to debug Emacs with the argument
17577 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
17578 @file{/dev/com1}:
17579
17580 @smallexample
17581 target> gdbserver /dev/com1 emacs foo.txt
17582 @end smallexample
17583
17584 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
17585 with it.
17586
17587 To use a TCP connection instead of a serial line:
17588
17589 @smallexample
17590 target> gdbserver host:2345 emacs foo.txt
17591 @end smallexample
17592
17593 The only difference from the previous example is the first argument,
17594 specifying that you are communicating with the host @value{GDBN} via
17595 TCP.  The @samp{host:2345} argument means that @code{gdbserver} is to
17596 expect a TCP connection from machine @samp{host} to local TCP port 2345.
17597 (Currently, the @samp{host} part is ignored.)  You can choose any number
17598 you want for the port number as long as it does not conflict with any
17599 TCP ports already in use on the target system (for example, @code{23} is
17600 reserved for @code{telnet}).@footnote{If you choose a port number that
17601 conflicts with another service, @code{gdbserver} prints an error message
17602 and exits.}  You must use the same port number with the host @value{GDBN}
17603 @code{target remote} command.
17604
17605 The @code{stdio} connection is useful when starting @code{gdbserver}
17606 with ssh:
17607
17608 @smallexample
17609 (gdb) target remote | ssh -T hostname gdbserver - hello
17610 @end smallexample
17611
17612 The @samp{-T} option to ssh is provided because we don't need a remote pty,
17613 and we don't want escape-character handling.  Ssh does this by default when
17614 a command is provided, the flag is provided to make it explicit.
17615 You could elide it if you want to.
17616
17617 Programs started with stdio-connected gdbserver have @file{/dev/null} for
17618 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
17619 display through a pipe connected to gdbserver.
17620 Both @code{stdout} and @code{stderr} use the same pipe.
17621
17622 @subsubsection Attaching to a Running Program
17623 @cindex attach to a program, @code{gdbserver}
17624 @cindex @option{--attach}, @code{gdbserver} option
17625
17626 On some targets, @code{gdbserver} can also attach to running programs.
17627 This is accomplished via the @code{--attach} argument.  The syntax is:
17628
17629 @smallexample
17630 target> gdbserver --attach @var{comm} @var{pid}
17631 @end smallexample
17632
17633 @var{pid} is the process ID of a currently running process.  It isn't necessary
17634 to point @code{gdbserver} at a binary for the running process.
17635
17636 @pindex pidof
17637 You can debug processes by name instead of process ID if your target has the
17638 @code{pidof} utility:
17639
17640 @smallexample
17641 target> gdbserver --attach @var{comm} `pidof @var{program}`
17642 @end smallexample
17643
17644 In case more than one copy of @var{program} is running, or @var{program}
17645 has multiple threads, most versions of @code{pidof} support the
17646 @code{-s} option to only return the first process ID.
17647
17648 @subsubsection Multi-Process Mode for @code{gdbserver}
17649 @cindex @code{gdbserver}, multiple processes
17650 @cindex multiple processes with @code{gdbserver}
17651
17652 When you connect to @code{gdbserver} using @code{target remote},
17653 @code{gdbserver} debugs the specified program only once.  When the
17654 program exits, or you detach from it, @value{GDBN} closes the connection
17655 and @code{gdbserver} exits.
17656
17657 If you connect using @kbd{target extended-remote}, @code{gdbserver}
17658 enters multi-process mode.  When the debugged program exits, or you
17659 detach from it, @value{GDBN} stays connected to @code{gdbserver} even
17660 though no program is running.  The @code{run} and @code{attach}
17661 commands instruct @code{gdbserver} to run or attach to a new program.
17662 The @code{run} command uses @code{set remote exec-file} (@pxref{set
17663 remote exec-file}) to select the program to run.  Command line
17664 arguments are supported, except for wildcard expansion and I/O
17665 redirection (@pxref{Arguments}).
17666
17667 @cindex @option{--multi}, @code{gdbserver} option
17668 To start @code{gdbserver} without supplying an initial command to run
17669 or process ID to attach, use the @option{--multi} command line option.
17670 Then you can connect using @kbd{target extended-remote} and start
17671 the program you want to debug.
17672
17673 In multi-process mode @code{gdbserver} does not automatically exit unless you
17674 use the option @option{--once}.  You can terminate it by using
17675 @code{monitor exit} (@pxref{Monitor Commands for gdbserver}).  Note that the
17676 conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
17677 connects to it (@kbd{target remote} or @kbd{target extended-remote}).  The
17678 @option{--multi} option to @code{gdbserver} has no influence on that.
17679
17680 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
17681
17682 This section applies only when @code{gdbserver} is run to listen on a TCP port.
17683
17684 @code{gdbserver} normally terminates after all of its debugged processes have
17685 terminated in @kbd{target remote} mode.  On the other hand, for @kbd{target
17686 extended-remote}, @code{gdbserver} stays running even with no processes left.
17687 @value{GDBN} normally terminates the spawned debugged process on its exit,
17688 which normally also terminates @code{gdbserver} in the @kbd{target remote}
17689 mode.  Therefore, when the connection drops unexpectedly, and @value{GDBN}
17690 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
17691 stays running even in the @kbd{target remote} mode.
17692
17693 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
17694 Such reconnecting is useful for features like @ref{disconnected tracing}.  For
17695 completeness, at most one @value{GDBN} can be connected at a time.
17696
17697 @cindex @option{--once}, @code{gdbserver} option
17698 By default, @code{gdbserver} keeps the listening TCP port open, so that
17699 additional connections are possible.  However, if you start @code{gdbserver}
17700 with the @option{--once} option, it will stop listening for any further
17701 connection attempts after connecting to the first @value{GDBN} session.  This
17702 means no further connections to @code{gdbserver} will be possible after the
17703 first one.  It also means @code{gdbserver} will terminate after the first
17704 connection with remote @value{GDBN} has closed, even for unexpectedly closed
17705 connections and even in the @kbd{target extended-remote} mode.  The
17706 @option{--once} option allows reusing the same port number for connecting to
17707 multiple instances of @code{gdbserver} running on the same host, since each
17708 instance closes its port after the first connection.
17709
17710 @subsubsection Other Command-Line Arguments for @code{gdbserver}
17711
17712 @cindex @option{--debug}, @code{gdbserver} option
17713 The @option{--debug} option tells @code{gdbserver} to display extra
17714 status information about the debugging process.
17715 @cindex @option{--remote-debug}, @code{gdbserver} option
17716 The @option{--remote-debug} option tells @code{gdbserver} to display
17717 remote protocol debug output.  These options are intended for
17718 @code{gdbserver} development and for bug reports to the developers.
17719
17720 @cindex @option{--wrapper}, @code{gdbserver} option
17721 The @option{--wrapper} option specifies a wrapper to launch programs
17722 for debugging.  The option should be followed by the name of the
17723 wrapper, then any command-line arguments to pass to the wrapper, then
17724 @kbd{--} indicating the end of the wrapper arguments.
17725
17726 @code{gdbserver} runs the specified wrapper program with a combined
17727 command line including the wrapper arguments, then the name of the
17728 program to debug, then any arguments to the program.  The wrapper
17729 runs until it executes your program, and then @value{GDBN} gains control.
17730
17731 You can use any program that eventually calls @code{execve} with
17732 its arguments as a wrapper.  Several standard Unix utilities do
17733 this, e.g.@: @code{env} and @code{nohup}.  Any Unix shell script ending
17734 with @code{exec "$@@"} will also work.
17735
17736 For example, you can use @code{env} to pass an environment variable to
17737 the debugged program, without setting the variable in @code{gdbserver}'s
17738 environment:
17739
17740 @smallexample
17741 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
17742 @end smallexample
17743
17744 @subsection Connecting to @code{gdbserver}
17745
17746 Run @value{GDBN} on the host system.
17747
17748 First make sure you have the necessary symbol files.  Load symbols for
17749 your application using the @code{file} command before you connect.  Use
17750 @code{set sysroot} to locate target libraries (unless your @value{GDBN}
17751 was compiled with the correct sysroot using @code{--with-sysroot}).
17752
17753 The symbol file and target libraries must exactly match the executable
17754 and libraries on the target, with one exception: the files on the host
17755 system should not be stripped, even if the files on the target system
17756 are.  Mismatched or missing files will lead to confusing results
17757 during debugging.  On @sc{gnu}/Linux targets, mismatched or missing
17758 files may also prevent @code{gdbserver} from debugging multi-threaded
17759 programs.
17760
17761 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
17762 For TCP connections, you must start up @code{gdbserver} prior to using
17763 the @code{target remote} command.  Otherwise you may get an error whose
17764 text depends on the host system, but which usually looks something like
17765 @samp{Connection refused}.  Don't use the @code{load}
17766 command in @value{GDBN} when using @code{gdbserver}, since the program is
17767 already on the target.
17768
17769 @subsection Monitor Commands for @code{gdbserver}
17770 @cindex monitor commands, for @code{gdbserver}
17771 @anchor{Monitor Commands for gdbserver}
17772
17773 During a @value{GDBN} session using @code{gdbserver}, you can use the
17774 @code{monitor} command to send special requests to @code{gdbserver}.
17775 Here are the available commands.
17776
17777 @table @code
17778 @item monitor help
17779 List the available monitor commands.
17780
17781 @item monitor set debug 0
17782 @itemx monitor set debug 1
17783 Disable or enable general debugging messages.
17784
17785 @item monitor set remote-debug 0
17786 @itemx monitor set remote-debug 1
17787 Disable or enable specific debugging messages associated with the remote
17788 protocol (@pxref{Remote Protocol}).
17789
17790 @item monitor set libthread-db-search-path [PATH]
17791 @cindex gdbserver, search path for @code{libthread_db}
17792 When this command is issued, @var{path} is a colon-separated list of
17793 directories to search for @code{libthread_db} (@pxref{Threads,,set
17794 libthread-db-search-path}).  If you omit @var{path},
17795 @samp{libthread-db-search-path} will be reset to its default value.
17796
17797 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
17798 not supported in @code{gdbserver}.
17799
17800 @item monitor exit
17801 Tell gdbserver to exit immediately.  This command should be followed by
17802 @code{disconnect} to close the debugging session.  @code{gdbserver} will
17803 detach from any attached processes and kill any processes it created.
17804 Use @code{monitor exit} to terminate @code{gdbserver} at the end
17805 of a multi-process mode debug session.
17806
17807 @end table
17808
17809 @subsection Tracepoints support in @code{gdbserver}
17810 @cindex tracepoints support in @code{gdbserver}
17811
17812 On some targets, @code{gdbserver} supports tracepoints, fast
17813 tracepoints and static tracepoints.
17814
17815 For fast or static tracepoints to work, a special library called the
17816 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
17817 This library is built and distributed as an integral part of
17818 @code{gdbserver}.  In addition, support for static tracepoints
17819 requires building the in-process agent library with static tracepoints
17820 support.  At present, the UST (LTTng Userspace Tracer,
17821 @url{http://lttng.org/ust}) tracing engine is supported.  This support
17822 is automatically available if UST development headers are found in the
17823 standard include path when @code{gdbserver} is built, or if
17824 @code{gdbserver} was explicitly configured using @option{--with-ust}
17825 to point at such headers.  You can explicitly disable the support
17826 using @option{--with-ust=no}.
17827
17828 There are several ways to load the in-process agent in your program:
17829
17830 @table @code
17831 @item Specifying it as dependency at link time
17832
17833 You can link your program dynamically with the in-process agent
17834 library.  On most systems, this is accomplished by adding
17835 @code{-linproctrace} to the link command.
17836
17837 @item Using the system's preloading mechanisms
17838
17839 You can force loading the in-process agent at startup time by using
17840 your system's support for preloading shared libraries.  Many Unixes
17841 support the concept of preloading user defined libraries.  In most
17842 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
17843 in the environment.  See also the description of @code{gdbserver}'s
17844 @option{--wrapper} command line option.
17845
17846 @item Using @value{GDBN} to force loading the agent at run time
17847
17848 On some systems, you can force the inferior to load a shared library,
17849 by calling a dynamic loader function in the inferior that takes care
17850 of dynamically looking up and loading a shared library.  On most Unix
17851 systems, the function is @code{dlopen}.  You'll use the @code{call}
17852 command for that.  For example:
17853
17854 @smallexample
17855 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
17856 @end smallexample
17857
17858 Note that on most Unix systems, for the @code{dlopen} function to be
17859 available, the program needs to be linked with @code{-ldl}.
17860 @end table
17861
17862 On systems that have a userspace dynamic loader, like most Unix
17863 systems, when you connect to @code{gdbserver} using @code{target
17864 remote}, you'll find that the program is stopped at the dynamic
17865 loader's entry point, and no shared library has been loaded in the
17866 program's address space yet, including the in-process agent.  In that
17867 case, before being able to use any of the fast or static tracepoints
17868 features, you need to let the loader run and load the shared
17869 libraries.  The simplest way to do that is to run the program to the
17870 main procedure.  E.g., if debugging a C or C@t{++} program, start
17871 @code{gdbserver} like so:
17872
17873 @smallexample
17874 $ gdbserver :9999 myprogram
17875 @end smallexample
17876
17877 Start GDB and connect to @code{gdbserver} like so, and run to main:
17878
17879 @smallexample
17880 $ gdb myprogram
17881 (@value{GDBP}) target remote myhost:9999
17882 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
17883 (@value{GDBP}) b main
17884 (@value{GDBP}) continue
17885 @end smallexample
17886
17887 The in-process tracing agent library should now be loaded into the
17888 process; you can confirm it with the @code{info sharedlibrary}
17889 command, which will list @file{libinproctrace.so} as loaded in the
17890 process.  You are now ready to install fast tracepoints, list static
17891 tracepoint markers, probe static tracepoints markers, and start
17892 tracing.
17893
17894 @node Remote Configuration
17895 @section Remote Configuration
17896
17897 @kindex set remote
17898 @kindex show remote
17899 This section documents the configuration options available when
17900 debugging remote programs.  For the options related to the File I/O
17901 extensions of the remote protocol, see @ref{system,
17902 system-call-allowed}.
17903
17904 @table @code
17905 @item set remoteaddresssize @var{bits}
17906 @cindex address size for remote targets
17907 @cindex bits in remote address
17908 Set the maximum size of address in a memory packet to the specified
17909 number of bits.  @value{GDBN} will mask off the address bits above
17910 that number, when it passes addresses to the remote target.  The
17911 default value is the number of bits in the target's address.
17912
17913 @item show remoteaddresssize
17914 Show the current value of remote address size in bits.
17915
17916 @item set remotebaud @var{n}
17917 @cindex baud rate for remote targets
17918 Set the baud rate for the remote serial I/O to @var{n} baud.  The
17919 value is used to set the speed of the serial port used for debugging
17920 remote targets.
17921
17922 @item show remotebaud
17923 Show the current speed of the remote connection.
17924
17925 @item set remotebreak
17926 @cindex interrupt remote programs
17927 @cindex BREAK signal instead of Ctrl-C
17928 @anchor{set remotebreak}
17929 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
17930 when you type @kbd{Ctrl-c} to interrupt the program running
17931 on the remote.  If set to off, @value{GDBN} sends the @samp{Ctrl-C}
17932 character instead.  The default is off, since most remote systems
17933 expect to see @samp{Ctrl-C} as the interrupt signal.
17934
17935 @item show remotebreak
17936 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
17937 interrupt the remote program.
17938
17939 @item set remoteflow on
17940 @itemx set remoteflow off
17941 @kindex set remoteflow
17942 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
17943 on the serial port used to communicate to the remote target.
17944
17945 @item show remoteflow
17946 @kindex show remoteflow
17947 Show the current setting of hardware flow control.
17948
17949 @item set remotelogbase @var{base}
17950 Set the base (a.k.a.@: radix) of logging serial protocol
17951 communications to @var{base}.  Supported values of @var{base} are:
17952 @code{ascii}, @code{octal}, and @code{hex}.  The default is
17953 @code{ascii}.
17954
17955 @item show remotelogbase
17956 Show the current setting of the radix for logging remote serial
17957 protocol.
17958
17959 @item set remotelogfile @var{file}
17960 @cindex record serial communications on file
17961 Record remote serial communications on the named @var{file}.  The
17962 default is not to record at all.
17963
17964 @item show remotelogfile.
17965 Show the current setting  of the file name on which to record the
17966 serial communications.
17967
17968 @item set remotetimeout @var{num}
17969 @cindex timeout for serial communications
17970 @cindex remote timeout
17971 Set the timeout limit to wait for the remote target to respond to
17972 @var{num} seconds.  The default is 2 seconds.
17973
17974 @item show remotetimeout
17975 Show the current number of seconds to wait for the remote target
17976 responses.
17977
17978 @cindex limit hardware breakpoints and watchpoints
17979 @cindex remote target, limit break- and watchpoints
17980 @anchor{set remote hardware-watchpoint-limit}
17981 @anchor{set remote hardware-breakpoint-limit}
17982 @item set remote hardware-watchpoint-limit @var{limit}
17983 @itemx set remote hardware-breakpoint-limit @var{limit}
17984 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
17985 watchpoints.  A limit of -1, the default, is treated as unlimited.
17986
17987 @cindex limit hardware watchpoints length
17988 @cindex remote target, limit watchpoints length
17989 @anchor{set remote hardware-watchpoint-length-limit}
17990 @item set remote hardware-watchpoint-length-limit @var{limit}
17991 Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
17992 a remote hardware watchpoint.  A limit of -1, the default, is treated
17993 as unlimited.
17994
17995 @item show remote hardware-watchpoint-length-limit
17996 Show the current limit (in bytes) of the maximum length of
17997 a remote hardware watchpoint.
17998
17999 @item set remote exec-file @var{filename}
18000 @itemx show remote exec-file
18001 @anchor{set remote exec-file}
18002 @cindex executable file, for remote target
18003 Select the file used for @code{run} with @code{target
18004 extended-remote}.  This should be set to a filename valid on the
18005 target system.  If it is not set, the target will use a default
18006 filename (e.g.@: the last program run).
18007
18008 @item set remote interrupt-sequence
18009 @cindex interrupt remote programs
18010 @cindex select Ctrl-C, BREAK or BREAK-g
18011 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
18012 @samp{BREAK-g} as the
18013 sequence to the remote target in order to interrupt the execution.
18014 @samp{Ctrl-C} is a default.  Some system prefers @code{BREAK} which
18015 is high level of serial line for some certain time.
18016 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
18017 It is @code{BREAK} signal followed by character @code{g}.
18018
18019 @item show interrupt-sequence
18020 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
18021 is sent by @value{GDBN} to interrupt the remote program.
18022 @code{BREAK-g} is BREAK signal followed by @code{g} and
18023 also known as Magic SysRq g.
18024
18025 @item set remote interrupt-on-connect
18026 @cindex send interrupt-sequence on start
18027 Specify whether interrupt-sequence is sent to remote target when
18028 @value{GDBN} connects to it.  This is mostly needed when you debug
18029 Linux kernel.  Linux kernel expects @code{BREAK} followed by @code{g}
18030 which is known as Magic SysRq g in order to connect @value{GDBN}.
18031
18032 @item show interrupt-on-connect
18033 Show whether interrupt-sequence is sent
18034 to remote target when @value{GDBN} connects to it.
18035
18036 @kindex set tcp
18037 @kindex show tcp
18038 @item set tcp auto-retry on
18039 @cindex auto-retry, for remote TCP target
18040 Enable auto-retry for remote TCP connections.  This is useful if the remote
18041 debugging agent is launched in parallel with @value{GDBN}; there is a race
18042 condition because the agent may not become ready to accept the connection
18043 before @value{GDBN} attempts to connect.  When auto-retry is
18044 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
18045 to establish the connection using the timeout specified by 
18046 @code{set tcp connect-timeout}.
18047
18048 @item set tcp auto-retry off
18049 Do not auto-retry failed TCP connections.
18050
18051 @item show tcp auto-retry
18052 Show the current auto-retry setting.
18053
18054 @item set tcp connect-timeout @var{seconds}
18055 @cindex connection timeout, for remote TCP target
18056 @cindex timeout, for remote target connection
18057 Set the timeout for establishing a TCP connection to the remote target to
18058 @var{seconds}.  The timeout affects both polling to retry failed connections 
18059 (enabled by @code{set tcp auto-retry on}) and waiting for connections
18060 that are merely slow to complete, and represents an approximate cumulative
18061 value.
18062
18063 @item show tcp connect-timeout
18064 Show the current connection timeout setting.
18065 @end table
18066
18067 @cindex remote packets, enabling and disabling
18068 The @value{GDBN} remote protocol autodetects the packets supported by
18069 your debugging stub.  If you need to override the autodetection, you
18070 can use these commands to enable or disable individual packets.  Each
18071 packet can be set to @samp{on} (the remote target supports this
18072 packet), @samp{off} (the remote target does not support this packet),
18073 or @samp{auto} (detect remote target support for this packet).  They
18074 all default to @samp{auto}.  For more information about each packet,
18075 see @ref{Remote Protocol}.
18076
18077 During normal use, you should not have to use any of these commands.
18078 If you do, that may be a bug in your remote debugging stub, or a bug
18079 in @value{GDBN}.  You may want to report the problem to the
18080 @value{GDBN} developers.
18081
18082 For each packet @var{name}, the command to enable or disable the
18083 packet is @code{set remote @var{name}-packet}.  The available settings
18084 are:
18085
18086 @multitable @columnfractions 0.28 0.32 0.25
18087 @item Command Name
18088 @tab Remote Packet
18089 @tab Related Features
18090
18091 @item @code{fetch-register}
18092 @tab @code{p}
18093 @tab @code{info registers}
18094
18095 @item @code{set-register}
18096 @tab @code{P}
18097 @tab @code{set}
18098
18099 @item @code{binary-download}
18100 @tab @code{X}
18101 @tab @code{load}, @code{set}
18102
18103 @item @code{read-aux-vector}
18104 @tab @code{qXfer:auxv:read}
18105 @tab @code{info auxv}
18106
18107 @item @code{symbol-lookup}
18108 @tab @code{qSymbol}
18109 @tab Detecting multiple threads
18110
18111 @item @code{attach}
18112 @tab @code{vAttach}
18113 @tab @code{attach}
18114
18115 @item @code{verbose-resume}
18116 @tab @code{vCont}
18117 @tab Stepping or resuming multiple threads
18118
18119 @item @code{run}
18120 @tab @code{vRun}
18121 @tab @code{run}
18122
18123 @item @code{software-breakpoint}
18124 @tab @code{Z0}
18125 @tab @code{break}
18126
18127 @item @code{hardware-breakpoint}
18128 @tab @code{Z1}
18129 @tab @code{hbreak}
18130
18131 @item @code{write-watchpoint}
18132 @tab @code{Z2}
18133 @tab @code{watch}
18134
18135 @item @code{read-watchpoint}
18136 @tab @code{Z3}
18137 @tab @code{rwatch}
18138
18139 @item @code{access-watchpoint}
18140 @tab @code{Z4}
18141 @tab @code{awatch}
18142
18143 @item @code{target-features}
18144 @tab @code{qXfer:features:read}
18145 @tab @code{set architecture}
18146
18147 @item @code{library-info}
18148 @tab @code{qXfer:libraries:read}
18149 @tab @code{info sharedlibrary}
18150
18151 @item @code{memory-map}
18152 @tab @code{qXfer:memory-map:read}
18153 @tab @code{info mem}
18154
18155 @item @code{read-sdata-object}
18156 @tab @code{qXfer:sdata:read}
18157 @tab @code{print $_sdata}
18158
18159 @item @code{read-spu-object}
18160 @tab @code{qXfer:spu:read}
18161 @tab @code{info spu}
18162
18163 @item @code{write-spu-object}
18164 @tab @code{qXfer:spu:write}
18165 @tab @code{info spu}
18166
18167 @item @code{read-siginfo-object}
18168 @tab @code{qXfer:siginfo:read}
18169 @tab @code{print $_siginfo}
18170
18171 @item @code{write-siginfo-object}
18172 @tab @code{qXfer:siginfo:write}
18173 @tab @code{set $_siginfo}
18174
18175 @item @code{threads}
18176 @tab @code{qXfer:threads:read}
18177 @tab @code{info threads}
18178
18179 @item @code{get-thread-local-@*storage-address}
18180 @tab @code{qGetTLSAddr}
18181 @tab Displaying @code{__thread} variables
18182
18183 @item @code{get-thread-information-block-address}
18184 @tab @code{qGetTIBAddr}
18185 @tab Display MS-Windows Thread Information Block.
18186
18187 @item @code{search-memory}
18188 @tab @code{qSearch:memory}
18189 @tab @code{find}
18190
18191 @item @code{supported-packets}
18192 @tab @code{qSupported}
18193 @tab Remote communications parameters
18194
18195 @item @code{pass-signals}
18196 @tab @code{QPassSignals}
18197 @tab @code{handle @var{signal}}
18198
18199 @item @code{program-signals}
18200 @tab @code{QProgramSignals}
18201 @tab @code{handle @var{signal}}
18202
18203 @item @code{hostio-close-packet}
18204 @tab @code{vFile:close}
18205 @tab @code{remote get}, @code{remote put}
18206
18207 @item @code{hostio-open-packet}
18208 @tab @code{vFile:open}
18209 @tab @code{remote get}, @code{remote put}
18210
18211 @item @code{hostio-pread-packet}
18212 @tab @code{vFile:pread}
18213 @tab @code{remote get}, @code{remote put}
18214
18215 @item @code{hostio-pwrite-packet}
18216 @tab @code{vFile:pwrite}
18217 @tab @code{remote get}, @code{remote put}
18218
18219 @item @code{hostio-unlink-packet}
18220 @tab @code{vFile:unlink}
18221 @tab @code{remote delete}
18222
18223 @item @code{hostio-readlink-packet}
18224 @tab @code{vFile:readlink}
18225 @tab Host I/O
18226
18227 @item @code{noack-packet}
18228 @tab @code{QStartNoAckMode}
18229 @tab Packet acknowledgment
18230
18231 @item @code{osdata}
18232 @tab @code{qXfer:osdata:read}
18233 @tab @code{info os}
18234
18235 @item @code{query-attached}
18236 @tab @code{qAttached}
18237 @tab Querying remote process attach state.
18238
18239 @item @code{traceframe-info}
18240 @tab @code{qXfer:traceframe-info:read}
18241 @tab Traceframe info
18242
18243 @item @code{install-in-trace}
18244 @tab @code{InstallInTrace}
18245 @tab Install tracepoint in tracing
18246
18247 @item @code{disable-randomization}
18248 @tab @code{QDisableRandomization}
18249 @tab @code{set disable-randomization}
18250
18251 @item @code{conditional-breakpoints-packet}
18252 @tab @code{Z0 and Z1}
18253 @tab @code{Support for target-side breakpoint condition evaluation}
18254 @end multitable
18255
18256 @node Remote Stub
18257 @section Implementing a Remote Stub
18258
18259 @cindex debugging stub, example
18260 @cindex remote stub, example
18261 @cindex stub example, remote debugging
18262 The stub files provided with @value{GDBN} implement the target side of the
18263 communication protocol, and the @value{GDBN} side is implemented in the
18264 @value{GDBN} source file @file{remote.c}.  Normally, you can simply allow
18265 these subroutines to communicate, and ignore the details.  (If you're
18266 implementing your own stub file, you can still ignore the details: start
18267 with one of the existing stub files.  @file{sparc-stub.c} is the best
18268 organized, and therefore the easiest to read.)
18269
18270 @cindex remote serial debugging, overview
18271 To debug a program running on another machine (the debugging
18272 @dfn{target} machine), you must first arrange for all the usual
18273 prerequisites for the program to run by itself.  For example, for a C
18274 program, you need:
18275
18276 @enumerate
18277 @item
18278 A startup routine to set up the C runtime environment; these usually
18279 have a name like @file{crt0}.  The startup routine may be supplied by
18280 your hardware supplier, or you may have to write your own.
18281
18282 @item
18283 A C subroutine library to support your program's
18284 subroutine calls, notably managing input and output.
18285
18286 @item
18287 A way of getting your program to the other machine---for example, a
18288 download program.  These are often supplied by the hardware
18289 manufacturer, but you may have to write your own from hardware
18290 documentation.
18291 @end enumerate
18292
18293 The next step is to arrange for your program to use a serial port to
18294 communicate with the machine where @value{GDBN} is running (the @dfn{host}
18295 machine).  In general terms, the scheme looks like this:
18296
18297 @table @emph
18298 @item On the host,
18299 @value{GDBN} already understands how to use this protocol; when everything
18300 else is set up, you can simply use the @samp{target remote} command
18301 (@pxref{Targets,,Specifying a Debugging Target}).
18302
18303 @item On the target,
18304 you must link with your program a few special-purpose subroutines that
18305 implement the @value{GDBN} remote serial protocol.  The file containing these
18306 subroutines is called  a @dfn{debugging stub}.
18307
18308 On certain remote targets, you can use an auxiliary program
18309 @code{gdbserver} instead of linking a stub into your program.
18310 @xref{Server,,Using the @code{gdbserver} Program}, for details.
18311 @end table
18312
18313 The debugging stub is specific to the architecture of the remote
18314 machine; for example, use @file{sparc-stub.c} to debug programs on
18315 @sc{sparc} boards.
18316
18317 @cindex remote serial stub list
18318 These working remote stubs are distributed with @value{GDBN}:
18319
18320 @table @code
18321
18322 @item i386-stub.c
18323 @cindex @file{i386-stub.c}
18324 @cindex Intel
18325 @cindex i386
18326 For Intel 386 and compatible architectures.
18327
18328 @item m68k-stub.c
18329 @cindex @file{m68k-stub.c}
18330 @cindex Motorola 680x0
18331 @cindex m680x0
18332 For Motorola 680x0 architectures.
18333
18334 @item sh-stub.c
18335 @cindex @file{sh-stub.c}
18336 @cindex Renesas
18337 @cindex SH
18338 For Renesas SH architectures.
18339
18340 @item sparc-stub.c
18341 @cindex @file{sparc-stub.c}
18342 @cindex Sparc
18343 For @sc{sparc} architectures.
18344
18345 @item sparcl-stub.c
18346 @cindex @file{sparcl-stub.c}
18347 @cindex Fujitsu
18348 @cindex SparcLite
18349 For Fujitsu @sc{sparclite} architectures.
18350
18351 @end table
18352
18353 The @file{README} file in the @value{GDBN} distribution may list other
18354 recently added stubs.
18355
18356 @menu
18357 * Stub Contents::       What the stub can do for you
18358 * Bootstrapping::       What you must do for the stub
18359 * Debug Session::       Putting it all together
18360 @end menu
18361
18362 @node Stub Contents
18363 @subsection What the Stub Can Do for You
18364
18365 @cindex remote serial stub
18366 The debugging stub for your architecture supplies these three
18367 subroutines:
18368
18369 @table @code
18370 @item set_debug_traps
18371 @findex set_debug_traps
18372 @cindex remote serial stub, initialization
18373 This routine arranges for @code{handle_exception} to run when your
18374 program stops.  You must call this subroutine explicitly in your
18375 program's startup code.
18376
18377 @item handle_exception
18378 @findex handle_exception
18379 @cindex remote serial stub, main routine
18380 This is the central workhorse, but your program never calls it
18381 explicitly---the setup code arranges for @code{handle_exception} to
18382 run when a trap is triggered.
18383
18384 @code{handle_exception} takes control when your program stops during
18385 execution (for example, on a breakpoint), and mediates communications
18386 with @value{GDBN} on the host machine.  This is where the communications
18387 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
18388 representative on the target machine.  It begins by sending summary
18389 information on the state of your program, then continues to execute,
18390 retrieving and transmitting any information @value{GDBN} needs, until you
18391 execute a @value{GDBN} command that makes your program resume; at that point,
18392 @code{handle_exception} returns control to your own code on the target
18393 machine.
18394
18395 @item breakpoint
18396 @cindex @code{breakpoint} subroutine, remote
18397 Use this auxiliary subroutine to make your program contain a
18398 breakpoint.  Depending on the particular situation, this may be the only
18399 way for @value{GDBN} to get control.  For instance, if your target
18400 machine has some sort of interrupt button, you won't need to call this;
18401 pressing the interrupt button transfers control to
18402 @code{handle_exception}---in effect, to @value{GDBN}.  On some machines,
18403 simply receiving characters on the serial port may also trigger a trap;
18404 again, in that situation, you don't need to call @code{breakpoint} from
18405 your own program---simply running @samp{target remote} from the host
18406 @value{GDBN} session gets control.
18407
18408 Call @code{breakpoint} if none of these is true, or if you simply want
18409 to make certain your program stops at a predetermined point for the
18410 start of your debugging session.
18411 @end table
18412
18413 @node Bootstrapping
18414 @subsection What You Must Do for the Stub
18415
18416 @cindex remote stub, support routines
18417 The debugging stubs that come with @value{GDBN} are set up for a particular
18418 chip architecture, but they have no information about the rest of your
18419 debugging target machine.
18420
18421 First of all you need to tell the stub how to communicate with the
18422 serial port.
18423
18424 @table @code
18425 @item int getDebugChar()
18426 @findex getDebugChar
18427 Write this subroutine to read a single character from the serial port.
18428 It may be identical to @code{getchar} for your target system; a
18429 different name is used to allow you to distinguish the two if you wish.
18430
18431 @item void putDebugChar(int)
18432 @findex putDebugChar
18433 Write this subroutine to write a single character to the serial port.
18434 It may be identical to @code{putchar} for your target system; a
18435 different name is used to allow you to distinguish the two if you wish.
18436 @end table
18437
18438 @cindex control C, and remote debugging
18439 @cindex interrupting remote targets
18440 If you want @value{GDBN} to be able to stop your program while it is
18441 running, you need to use an interrupt-driven serial driver, and arrange
18442 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
18443 character).  That is the character which @value{GDBN} uses to tell the
18444 remote system to stop.
18445
18446 Getting the debugging target to return the proper status to @value{GDBN}
18447 probably requires changes to the standard stub; one quick and dirty way
18448 is to just execute a breakpoint instruction (the ``dirty'' part is that
18449 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
18450
18451 Other routines you need to supply are:
18452
18453 @table @code
18454 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
18455 @findex exceptionHandler
18456 Write this function to install @var{exception_address} in the exception
18457 handling tables.  You need to do this because the stub does not have any
18458 way of knowing what the exception handling tables on your target system
18459 are like (for example, the processor's table might be in @sc{rom},
18460 containing entries which point to a table in @sc{ram}).
18461 @var{exception_number} is the exception number which should be changed;
18462 its meaning is architecture-dependent (for example, different numbers
18463 might represent divide by zero, misaligned access, etc).  When this
18464 exception occurs, control should be transferred directly to
18465 @var{exception_address}, and the processor state (stack, registers,
18466 and so on) should be just as it is when a processor exception occurs.  So if
18467 you want to use a jump instruction to reach @var{exception_address}, it
18468 should be a simple jump, not a jump to subroutine.
18469
18470 For the 386, @var{exception_address} should be installed as an interrupt
18471 gate so that interrupts are masked while the handler runs.  The gate
18472 should be at privilege level 0 (the most privileged level).  The
18473 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
18474 help from @code{exceptionHandler}.
18475
18476 @item void flush_i_cache()
18477 @findex flush_i_cache
18478 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
18479 instruction cache, if any, on your target machine.  If there is no
18480 instruction cache, this subroutine may be a no-op.
18481
18482 On target machines that have instruction caches, @value{GDBN} requires this
18483 function to make certain that the state of your program is stable.
18484 @end table
18485
18486 @noindent
18487 You must also make sure this library routine is available:
18488
18489 @table @code
18490 @item void *memset(void *, int, int)
18491 @findex memset
18492 This is the standard library function @code{memset} that sets an area of
18493 memory to a known value.  If you have one of the free versions of
18494 @code{libc.a}, @code{memset} can be found there; otherwise, you must
18495 either obtain it from your hardware manufacturer, or write your own.
18496 @end table
18497
18498 If you do not use the GNU C compiler, you may need other standard
18499 library subroutines as well; this varies from one stub to another,
18500 but in general the stubs are likely to use any of the common library
18501 subroutines which @code{@value{NGCC}} generates as inline code.
18502
18503
18504 @node Debug Session
18505 @subsection Putting it All Together
18506
18507 @cindex remote serial debugging summary
18508 In summary, when your program is ready to debug, you must follow these
18509 steps.
18510
18511 @enumerate
18512 @item
18513 Make sure you have defined the supporting low-level routines
18514 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
18515 @display
18516 @code{getDebugChar}, @code{putDebugChar},
18517 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
18518 @end display
18519
18520 @item
18521 Insert these lines in your program's startup code, before the main
18522 procedure is called:
18523
18524 @smallexample
18525 set_debug_traps();
18526 breakpoint();
18527 @end smallexample
18528
18529 On some machines, when a breakpoint trap is raised, the hardware
18530 automatically makes the PC point to the instruction after the
18531 breakpoint.  If your machine doesn't do that, you may need to adjust
18532 @code{handle_exception} to arrange for it to return to the instruction
18533 after the breakpoint on this first invocation, so that your program
18534 doesn't keep hitting the initial breakpoint instead of making
18535 progress.
18536
18537 @item
18538 For the 680x0 stub only, you need to provide a variable called
18539 @code{exceptionHook}.  Normally you just use:
18540
18541 @smallexample
18542 void (*exceptionHook)() = 0;
18543 @end smallexample
18544
18545 @noindent
18546 but if before calling @code{set_debug_traps}, you set it to point to a
18547 function in your program, that function is called when
18548 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
18549 error).  The function indicated by @code{exceptionHook} is called with
18550 one parameter: an @code{int} which is the exception number.
18551
18552 @item
18553 Compile and link together: your program, the @value{GDBN} debugging stub for
18554 your target architecture, and the supporting subroutines.
18555
18556 @item
18557 Make sure you have a serial connection between your target machine and
18558 the @value{GDBN} host, and identify the serial port on the host.
18559
18560 @item
18561 @c The "remote" target now provides a `load' command, so we should
18562 @c document that.  FIXME.
18563 Download your program to your target machine (or get it there by
18564 whatever means the manufacturer provides), and start it.
18565
18566 @item
18567 Start @value{GDBN} on the host, and connect to the target
18568 (@pxref{Connecting,,Connecting to a Remote Target}).
18569
18570 @end enumerate
18571
18572 @node Configurations
18573 @chapter Configuration-Specific Information
18574
18575 While nearly all @value{GDBN} commands are available for all native and
18576 cross versions of the debugger, there are some exceptions.  This chapter
18577 describes things that are only available in certain configurations.
18578
18579 There are three major categories of configurations: native
18580 configurations, where the host and target are the same, embedded
18581 operating system configurations, which are usually the same for several
18582 different processor architectures, and bare embedded processors, which
18583 are quite different from each other.
18584
18585 @menu
18586 * Native::
18587 * Embedded OS::
18588 * Embedded Processors::
18589 * Architectures::
18590 @end menu
18591
18592 @node Native
18593 @section Native
18594
18595 This section describes details specific to particular native
18596 configurations.
18597
18598 @menu
18599 * HP-UX::                       HP-UX
18600 * BSD libkvm Interface::        Debugging BSD kernel memory images
18601 * SVR4 Process Information::    SVR4 process information
18602 * DJGPP Native::                Features specific to the DJGPP port
18603 * Cygwin Native::               Features specific to the Cygwin port
18604 * Hurd Native::                 Features specific to @sc{gnu} Hurd
18605 * Darwin::                      Features specific to Darwin
18606 @end menu
18607
18608 @node HP-UX
18609 @subsection HP-UX
18610
18611 On HP-UX systems, if you refer to a function or variable name that
18612 begins with a dollar sign, @value{GDBN} searches for a user or system
18613 name first, before it searches for a convenience variable.
18614
18615
18616 @node BSD libkvm Interface
18617 @subsection BSD libkvm Interface
18618
18619 @cindex libkvm
18620 @cindex kernel memory image
18621 @cindex kernel crash dump
18622
18623 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
18624 interface that provides a uniform interface for accessing kernel virtual
18625 memory images, including live systems and crash dumps.  @value{GDBN}
18626 uses this interface to allow you to debug live kernels and kernel crash
18627 dumps on many native BSD configurations.  This is implemented as a
18628 special @code{kvm} debugging target.  For debugging a live system, load
18629 the currently running kernel into @value{GDBN} and connect to the
18630 @code{kvm} target:
18631
18632 @smallexample
18633 (@value{GDBP}) @b{target kvm}
18634 @end smallexample
18635
18636 For debugging crash dumps, provide the file name of the crash dump as an
18637 argument:
18638
18639 @smallexample
18640 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
18641 @end smallexample
18642
18643 Once connected to the @code{kvm} target, the following commands are
18644 available:
18645
18646 @table @code
18647 @kindex kvm
18648 @item kvm pcb
18649 Set current context from the @dfn{Process Control Block} (PCB) address.
18650
18651 @item kvm proc
18652 Set current context from proc address.  This command isn't available on
18653 modern FreeBSD systems.
18654 @end table
18655
18656 @node SVR4 Process Information
18657 @subsection SVR4 Process Information
18658 @cindex /proc
18659 @cindex examine process image
18660 @cindex process info via @file{/proc}
18661
18662 Many versions of SVR4 and compatible systems provide a facility called
18663 @samp{/proc} that can be used to examine the image of a running
18664 process using file-system subroutines.
18665
18666 If @value{GDBN} is configured for an operating system with this
18667 facility, the command @code{info proc} is available to report
18668 information about the process running your program, or about any
18669 process running on your system.  This includes, as of this writing,
18670 @sc{gnu}/Linux, OSF/1 (Digital Unix), Solaris, and Irix, but
18671 not HP-UX, for example.
18672
18673 This command may also work on core files that were created on a system
18674 that has the @samp{/proc} facility.
18675
18676 @table @code
18677 @kindex info proc
18678 @cindex process ID
18679 @item info proc
18680 @itemx info proc @var{process-id}
18681 Summarize available information about any running process.  If a
18682 process ID is specified by @var{process-id}, display information about
18683 that process; otherwise display information about the program being
18684 debugged.  The summary includes the debugged process ID, the command
18685 line used to invoke it, its current working directory, and its
18686 executable file's absolute file name.
18687
18688 On some systems, @var{process-id} can be of the form
18689 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
18690 within a process.  If the optional @var{pid} part is missing, it means
18691 a thread from the process being debugged (the leading @samp{/} still
18692 needs to be present, or else @value{GDBN} will interpret the number as
18693 a process ID rather than a thread ID).
18694
18695 @item info proc cmdline
18696 @cindex info proc cmdline
18697 Show the original command line of the process.  This command is
18698 specific to @sc{gnu}/Linux.
18699
18700 @item info proc cwd
18701 @cindex info proc cwd
18702 Show the current working directory of the process.  This command is
18703 specific to @sc{gnu}/Linux.
18704
18705 @item info proc exe
18706 @cindex info proc exe
18707 Show the name of executable of the process.  This command is specific
18708 to @sc{gnu}/Linux.
18709
18710 @item info proc mappings
18711 @cindex memory address space mappings
18712 Report the memory address space ranges accessible in the program, with
18713 information on whether the process has read, write, or execute access
18714 rights to each range.  On @sc{gnu}/Linux systems, each memory range
18715 includes the object file which is mapped to that range, instead of the
18716 memory access rights to that range.
18717
18718 @item info proc stat
18719 @itemx info proc status
18720 @cindex process detailed status information
18721 These subcommands are specific to @sc{gnu}/Linux systems.  They show
18722 the process-related information, including the user ID and group ID;
18723 how many threads are there in the process; its virtual memory usage;
18724 the signals that are pending, blocked, and ignored; its TTY; its
18725 consumption of system and user time; its stack size; its @samp{nice}
18726 value; etc.  For more information, see the @samp{proc} man page
18727 (type @kbd{man 5 proc} from your shell prompt).
18728
18729 @item info proc all
18730 Show all the information about the process described under all of the
18731 above @code{info proc} subcommands.
18732
18733 @ignore
18734 @comment These sub-options of 'info proc' were not included when
18735 @comment procfs.c was re-written.  Keep their descriptions around
18736 @comment against the day when someone finds the time to put them back in.
18737 @kindex info proc times
18738 @item info proc times
18739 Starting time, user CPU time, and system CPU time for your program and
18740 its children.
18741
18742 @kindex info proc id
18743 @item info proc id
18744 Report on the process IDs related to your program: its own process ID,
18745 the ID of its parent, the process group ID, and the session ID.
18746 @end ignore
18747
18748 @item set procfs-trace
18749 @kindex set procfs-trace
18750 @cindex @code{procfs} API calls
18751 This command enables and disables tracing of @code{procfs} API calls.
18752
18753 @item show procfs-trace
18754 @kindex show procfs-trace
18755 Show the current state of @code{procfs} API call tracing.
18756
18757 @item set procfs-file @var{file}
18758 @kindex set procfs-file
18759 Tell @value{GDBN} to write @code{procfs} API trace to the named
18760 @var{file}.  @value{GDBN} appends the trace info to the previous
18761 contents of the file.  The default is to display the trace on the
18762 standard output.
18763
18764 @item show procfs-file
18765 @kindex show procfs-file
18766 Show the file to which @code{procfs} API trace is written.
18767
18768 @item proc-trace-entry
18769 @itemx proc-trace-exit
18770 @itemx proc-untrace-entry
18771 @itemx proc-untrace-exit
18772 @kindex proc-trace-entry
18773 @kindex proc-trace-exit
18774 @kindex proc-untrace-entry
18775 @kindex proc-untrace-exit
18776 These commands enable and disable tracing of entries into and exits
18777 from the @code{syscall} interface.
18778
18779 @item info pidlist
18780 @kindex info pidlist
18781 @cindex process list, QNX Neutrino
18782 For QNX Neutrino only, this command displays the list of all the
18783 processes and all the threads within each process.
18784
18785 @item info meminfo
18786 @kindex info meminfo
18787 @cindex mapinfo list, QNX Neutrino
18788 For QNX Neutrino only, this command displays the list of all mapinfos.
18789 @end table
18790
18791 @node DJGPP Native
18792 @subsection Features for Debugging @sc{djgpp} Programs
18793 @cindex @sc{djgpp} debugging
18794 @cindex native @sc{djgpp} debugging
18795 @cindex MS-DOS-specific commands
18796
18797 @cindex DPMI
18798 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
18799 MS-Windows.  @sc{djgpp} programs are 32-bit protected-mode programs
18800 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
18801 top of real-mode DOS systems and their emulations.
18802
18803 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
18804 defines a few commands specific to the @sc{djgpp} port.  This
18805 subsection describes those commands.
18806
18807 @table @code
18808 @kindex info dos
18809 @item info dos
18810 This is a prefix of @sc{djgpp}-specific commands which print
18811 information about the target system and important OS structures.
18812
18813 @kindex sysinfo
18814 @cindex MS-DOS system info
18815 @cindex free memory information (MS-DOS)
18816 @item info dos sysinfo
18817 This command displays assorted information about the underlying
18818 platform: the CPU type and features, the OS version and flavor, the
18819 DPMI version, and the available conventional and DPMI memory.
18820
18821 @cindex GDT
18822 @cindex LDT
18823 @cindex IDT
18824 @cindex segment descriptor tables
18825 @cindex descriptor tables display
18826 @item info dos gdt
18827 @itemx info dos ldt
18828 @itemx info dos idt
18829 These 3 commands display entries from, respectively, Global, Local,
18830 and Interrupt Descriptor Tables (GDT, LDT, and IDT).  The descriptor
18831 tables are data structures which store a descriptor for each segment
18832 that is currently in use.  The segment's selector is an index into a
18833 descriptor table; the table entry for that index holds the
18834 descriptor's base address and limit, and its attributes and access
18835 rights.
18836
18837 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
18838 segment (used for both data and the stack), and a DOS segment (which
18839 allows access to DOS/BIOS data structures and absolute addresses in
18840 conventional memory).  However, the DPMI host will usually define
18841 additional segments in order to support the DPMI environment.
18842
18843 @cindex garbled pointers
18844 These commands allow to display entries from the descriptor tables.
18845 Without an argument, all entries from the specified table are
18846 displayed.  An argument, which should be an integer expression, means
18847 display a single entry whose index is given by the argument.  For
18848 example, here's a convenient way to display information about the
18849 debugged program's data segment:
18850
18851 @smallexample
18852 @exdent @code{(@value{GDBP}) info dos ldt $ds}
18853 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
18854 @end smallexample
18855
18856 @noindent
18857 This comes in handy when you want to see whether a pointer is outside
18858 the data segment's limit (i.e.@: @dfn{garbled}).
18859
18860 @cindex page tables display (MS-DOS)
18861 @item info dos pde
18862 @itemx info dos pte
18863 These two commands display entries from, respectively, the Page
18864 Directory and the Page Tables.  Page Directories and Page Tables are
18865 data structures which control how virtual memory addresses are mapped
18866 into physical addresses.  A Page Table includes an entry for every
18867 page of memory that is mapped into the program's address space; there
18868 may be several Page Tables, each one holding up to 4096 entries.  A
18869 Page Directory has up to 4096 entries, one each for every Page Table
18870 that is currently in use.
18871
18872 Without an argument, @kbd{info dos pde} displays the entire Page
18873 Directory, and @kbd{info dos pte} displays all the entries in all of
18874 the Page Tables.  An argument, an integer expression, given to the
18875 @kbd{info dos pde} command means display only that entry from the Page
18876 Directory table.  An argument given to the @kbd{info dos pte} command
18877 means display entries from a single Page Table, the one pointed to by
18878 the specified entry in the Page Directory.
18879
18880 @cindex direct memory access (DMA) on MS-DOS
18881 These commands are useful when your program uses @dfn{DMA} (Direct
18882 Memory Access), which needs physical addresses to program the DMA
18883 controller.
18884
18885 These commands are supported only with some DPMI servers.
18886
18887 @cindex physical address from linear address
18888 @item info dos address-pte @var{addr}
18889 This command displays the Page Table entry for a specified linear
18890 address.  The argument @var{addr} is a linear address which should
18891 already have the appropriate segment's base address added to it,
18892 because this command accepts addresses which may belong to @emph{any}
18893 segment.  For example, here's how to display the Page Table entry for
18894 the page where a variable @code{i} is stored:
18895
18896 @smallexample
18897 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
18898 @exdent @code{Page Table entry for address 0x11a00d30:}
18899 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
18900 @end smallexample
18901
18902 @noindent
18903 This says that @code{i} is stored at offset @code{0xd30} from the page
18904 whose physical base address is @code{0x02698000}, and shows all the
18905 attributes of that page.
18906
18907 Note that you must cast the addresses of variables to a @code{char *},
18908 since otherwise the value of @code{__djgpp_base_address}, the base
18909 address of all variables and functions in a @sc{djgpp} program, will
18910 be added using the rules of C pointer arithmetics: if @code{i} is
18911 declared an @code{int}, @value{GDBN} will add 4 times the value of
18912 @code{__djgpp_base_address} to the address of @code{i}.
18913
18914 Here's another example, it displays the Page Table entry for the
18915 transfer buffer:
18916
18917 @smallexample
18918 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
18919 @exdent @code{Page Table entry for address 0x29110:}
18920 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
18921 @end smallexample
18922
18923 @noindent
18924 (The @code{+ 3} offset is because the transfer buffer's address is the
18925 3rd member of the @code{_go32_info_block} structure.)  The output
18926 clearly shows that this DPMI server maps the addresses in conventional
18927 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
18928 linear (@code{0x29110}) addresses are identical.
18929
18930 This command is supported only with some DPMI servers.
18931 @end table
18932
18933 @cindex DOS serial data link, remote debugging
18934 In addition to native debugging, the DJGPP port supports remote
18935 debugging via a serial data link.  The following commands are specific
18936 to remote serial debugging in the DJGPP port of @value{GDBN}.
18937
18938 @table @code
18939 @kindex set com1base
18940 @kindex set com1irq
18941 @kindex set com2base
18942 @kindex set com2irq
18943 @kindex set com3base
18944 @kindex set com3irq
18945 @kindex set com4base
18946 @kindex set com4irq
18947 @item set com1base @var{addr}
18948 This command sets the base I/O port address of the @file{COM1} serial
18949 port.
18950
18951 @item set com1irq @var{irq}
18952 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
18953 for the @file{COM1} serial port.
18954
18955 There are similar commands @samp{set com2base}, @samp{set com3irq},
18956 etc.@: for setting the port address and the @code{IRQ} lines for the
18957 other 3 COM ports.
18958
18959 @kindex show com1base
18960 @kindex show com1irq
18961 @kindex show com2base
18962 @kindex show com2irq
18963 @kindex show com3base
18964 @kindex show com3irq
18965 @kindex show com4base
18966 @kindex show com4irq
18967 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
18968 display the current settings of the base address and the @code{IRQ}
18969 lines used by the COM ports.
18970
18971 @item info serial
18972 @kindex info serial
18973 @cindex DOS serial port status
18974 This command prints the status of the 4 DOS serial ports.  For each
18975 port, it prints whether it's active or not, its I/O base address and
18976 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
18977 counts of various errors encountered so far.
18978 @end table
18979
18980
18981 @node Cygwin Native
18982 @subsection Features for Debugging MS Windows PE Executables
18983 @cindex MS Windows debugging
18984 @cindex native Cygwin debugging
18985 @cindex Cygwin-specific commands
18986
18987 @value{GDBN} supports native debugging of MS Windows programs, including
18988 DLLs with and without symbolic debugging information.
18989
18990 @cindex Ctrl-BREAK, MS-Windows
18991 @cindex interrupt debuggee on MS-Windows
18992 MS-Windows programs that call @code{SetConsoleMode} to switch off the
18993 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
18994 by typing @kbd{C-c}.  For this reason, @value{GDBN} on MS-Windows
18995 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
18996 sequence, which can be used to interrupt the debuggee even if it
18997 ignores @kbd{C-c}.
18998
18999 There are various additional Cygwin-specific commands, described in
19000 this section.  Working with DLLs that have no debugging symbols is
19001 described in @ref{Non-debug DLL Symbols}.
19002
19003 @table @code
19004 @kindex info w32
19005 @item info w32
19006 This is a prefix of MS Windows-specific commands which print
19007 information about the target system and important OS structures.
19008
19009 @item info w32 selector
19010 This command displays information returned by
19011 the Win32 API @code{GetThreadSelectorEntry} function.
19012 It takes an optional argument that is evaluated to
19013 a long value to give the information about this given selector.
19014 Without argument, this command displays information
19015 about the six segment registers.
19016
19017 @item info w32 thread-information-block
19018 This command displays thread specific information stored in the
19019 Thread Information Block (readable on the X86 CPU family using @code{$fs}
19020 selector for 32-bit programs and @code{$gs} for 64-bit programs).
19021
19022 @kindex info dll
19023 @item info dll
19024 This is a Cygwin-specific alias of @code{info shared}.
19025
19026 @kindex dll-symbols
19027 @item dll-symbols
19028 This command loads symbols from a dll similarly to
19029 add-sym command but without the need to specify a base address.
19030
19031 @kindex set cygwin-exceptions
19032 @cindex debugging the Cygwin DLL
19033 @cindex Cygwin DLL, debugging
19034 @item set cygwin-exceptions @var{mode}
19035 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
19036 happen inside the Cygwin DLL.  If @var{mode} is @code{off},
19037 @value{GDBN} will delay recognition of exceptions, and may ignore some
19038 exceptions which seem to be caused by internal Cygwin DLL
19039 ``bookkeeping''.  This option is meant primarily for debugging the
19040 Cygwin DLL itself; the default value is @code{off} to avoid annoying
19041 @value{GDBN} users with false @code{SIGSEGV} signals.
19042
19043 @kindex show cygwin-exceptions
19044 @item show cygwin-exceptions
19045 Displays whether @value{GDBN} will break on exceptions that happen
19046 inside the Cygwin DLL itself.
19047
19048 @kindex set new-console
19049 @item set new-console @var{mode}
19050 If @var{mode} is @code{on} the debuggee will
19051 be started in a new console on next start.
19052 If @var{mode} is @code{off}, the debuggee will
19053 be started in the same console as the debugger.
19054
19055 @kindex show new-console
19056 @item show new-console
19057 Displays whether a new console is used
19058 when the debuggee is started.
19059
19060 @kindex set new-group
19061 @item set new-group @var{mode}
19062 This boolean value controls whether the debuggee should
19063 start a new group or stay in the same group as the debugger.
19064 This affects the way the Windows OS handles
19065 @samp{Ctrl-C}.
19066
19067 @kindex show new-group
19068 @item show new-group
19069 Displays current value of new-group boolean.
19070
19071 @kindex set debugevents
19072 @item set debugevents
19073 This boolean value adds debug output concerning kernel events related
19074 to the debuggee seen by the debugger.  This includes events that
19075 signal thread and process creation and exit, DLL loading and
19076 unloading, console interrupts, and debugging messages produced by the
19077 Windows @code{OutputDebugString} API call.
19078
19079 @kindex set debugexec
19080 @item set debugexec
19081 This boolean value adds debug output concerning execute events
19082 (such as resume thread) seen by the debugger.
19083
19084 @kindex set debugexceptions
19085 @item set debugexceptions
19086 This boolean value adds debug output concerning exceptions in the
19087 debuggee seen by the debugger.
19088
19089 @kindex set debugmemory
19090 @item set debugmemory
19091 This boolean value adds debug output concerning debuggee memory reads
19092 and writes by the debugger.
19093
19094 @kindex set shell
19095 @item set shell
19096 This boolean values specifies whether the debuggee is called
19097 via a shell or directly (default value is on).
19098
19099 @kindex show shell
19100 @item show shell
19101 Displays if the debuggee will be started with a shell.
19102
19103 @end table
19104
19105 @menu
19106 * Non-debug DLL Symbols::  Support for DLLs without debugging symbols
19107 @end menu
19108
19109 @node Non-debug DLL Symbols
19110 @subsubsection Support for DLLs without Debugging Symbols
19111 @cindex DLLs with no debugging symbols
19112 @cindex Minimal symbols and DLLs
19113
19114 Very often on windows, some of the DLLs that your program relies on do
19115 not include symbolic debugging information (for example,
19116 @file{kernel32.dll}).  When @value{GDBN} doesn't recognize any debugging
19117 symbols in a DLL, it relies on the minimal amount of symbolic
19118 information contained in the DLL's export table.  This section
19119 describes working with such symbols, known internally to @value{GDBN} as
19120 ``minimal symbols''.
19121
19122 Note that before the debugged program has started execution, no DLLs
19123 will have been loaded.  The easiest way around this problem is simply to
19124 start the program --- either by setting a breakpoint or letting the
19125 program run once to completion.  It is also possible to force
19126 @value{GDBN} to load a particular DLL before starting the executable ---
19127 see the shared library information in @ref{Files}, or the
19128 @code{dll-symbols} command in @ref{Cygwin Native}.  Currently,
19129 explicitly loading symbols from a DLL with no debugging information will
19130 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
19131 which may adversely affect symbol lookup performance.
19132
19133 @subsubsection DLL Name Prefixes
19134
19135 In keeping with the naming conventions used by the Microsoft debugging
19136 tools, DLL export symbols are made available with a prefix based on the
19137 DLL name, for instance @code{KERNEL32!CreateFileA}.  The plain name is
19138 also entered into the symbol table, so @code{CreateFileA} is often
19139 sufficient.  In some cases there will be name clashes within a program
19140 (particularly if the executable itself includes full debugging symbols)
19141 necessitating the use of the fully qualified name when referring to the
19142 contents of the DLL.  Use single-quotes around the name to avoid the
19143 exclamation mark (``!'')  being interpreted as a language operator.
19144
19145 Note that the internal name of the DLL may be all upper-case, even
19146 though the file name of the DLL is lower-case, or vice-versa.  Since
19147 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
19148 some confusion. If in doubt, try the @code{info functions} and
19149 @code{info variables} commands or even @code{maint print msymbols}
19150 (@pxref{Symbols}). Here's an example:
19151
19152 @smallexample
19153 (@value{GDBP}) info function CreateFileA
19154 All functions matching regular expression "CreateFileA":
19155
19156 Non-debugging symbols:
19157 0x77e885f4  CreateFileA
19158 0x77e885f4  KERNEL32!CreateFileA
19159 @end smallexample
19160
19161 @smallexample
19162 (@value{GDBP}) info function !
19163 All functions matching regular expression "!":
19164
19165 Non-debugging symbols:
19166 0x6100114c  cygwin1!__assert
19167 0x61004034  cygwin1!_dll_crt0@@0
19168 0x61004240  cygwin1!dll_crt0(per_process *)
19169 [etc...]
19170 @end smallexample
19171
19172 @subsubsection Working with Minimal Symbols
19173
19174 Symbols extracted from a DLL's export table do not contain very much
19175 type information. All that @value{GDBN} can do is guess whether a symbol
19176 refers to a function or variable depending on the linker section that
19177 contains the symbol. Also note that the actual contents of the memory
19178 contained in a DLL are not available unless the program is running. This
19179 means that you cannot examine the contents of a variable or disassemble
19180 a function within a DLL without a running program.
19181
19182 Variables are generally treated as pointers and dereferenced
19183 automatically. For this reason, it is often necessary to prefix a
19184 variable name with the address-of operator (``&'') and provide explicit
19185 type information in the command. Here's an example of the type of
19186 problem:
19187
19188 @smallexample
19189 (@value{GDBP}) print 'cygwin1!__argv'
19190 $1 = 268572168
19191 @end smallexample
19192
19193 @smallexample
19194 (@value{GDBP}) x 'cygwin1!__argv'
19195 0x10021610:      "\230y\""
19196 @end smallexample
19197
19198 And two possible solutions:
19199
19200 @smallexample
19201 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
19202 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
19203 @end smallexample
19204
19205 @smallexample
19206 (@value{GDBP}) x/2x &'cygwin1!__argv'
19207 0x610c0aa8 <cygwin1!__argv>:    0x10021608      0x00000000
19208 (@value{GDBP}) x/x 0x10021608
19209 0x10021608:     0x0022fd98
19210 (@value{GDBP}) x/s 0x0022fd98
19211 0x22fd98:        "/cygdrive/c/mydirectory/myprogram"
19212 @end smallexample
19213
19214 Setting a break point within a DLL is possible even before the program
19215 starts execution. However, under these circumstances, @value{GDBN} can't
19216 examine the initial instructions of the function in order to skip the
19217 function's frame set-up code. You can work around this by using ``*&''
19218 to set the breakpoint at a raw memory address:
19219
19220 @smallexample
19221 (@value{GDBP}) break *&'python22!PyOS_Readline'
19222 Breakpoint 1 at 0x1e04eff0
19223 @end smallexample
19224
19225 The author of these extensions is not entirely convinced that setting a
19226 break point within a shared DLL like @file{kernel32.dll} is completely
19227 safe.
19228
19229 @node Hurd Native
19230 @subsection Commands Specific to @sc{gnu} Hurd Systems
19231 @cindex @sc{gnu} Hurd debugging
19232
19233 This subsection describes @value{GDBN} commands specific to the
19234 @sc{gnu} Hurd native debugging.
19235
19236 @table @code
19237 @item set signals
19238 @itemx set sigs
19239 @kindex set signals@r{, Hurd command}
19240 @kindex set sigs@r{, Hurd command}
19241 This command toggles the state of inferior signal interception by
19242 @value{GDBN}.  Mach exceptions, such as breakpoint traps, are not
19243 affected by this command.  @code{sigs} is a shorthand alias for
19244 @code{signals}.
19245
19246 @item show signals
19247 @itemx show sigs
19248 @kindex show signals@r{, Hurd command}
19249 @kindex show sigs@r{, Hurd command}
19250 Show the current state of intercepting inferior's signals.
19251
19252 @item set signal-thread
19253 @itemx set sigthread
19254 @kindex set signal-thread
19255 @kindex set sigthread
19256 This command tells @value{GDBN} which thread is the @code{libc} signal
19257 thread.  That thread is run when a signal is delivered to a running
19258 process.  @code{set sigthread} is the shorthand alias of @code{set
19259 signal-thread}.
19260
19261 @item show signal-thread
19262 @itemx show sigthread
19263 @kindex show signal-thread
19264 @kindex show sigthread
19265 These two commands show which thread will run when the inferior is
19266 delivered a signal.
19267
19268 @item set stopped
19269 @kindex set stopped@r{, Hurd command}
19270 This commands tells @value{GDBN} that the inferior process is stopped,
19271 as with the @code{SIGSTOP} signal.  The stopped process can be
19272 continued by delivering a signal to it.
19273
19274 @item show stopped
19275 @kindex show stopped@r{, Hurd command}
19276 This command shows whether @value{GDBN} thinks the debuggee is
19277 stopped.
19278
19279 @item set exceptions
19280 @kindex set exceptions@r{, Hurd command}
19281 Use this command to turn off trapping of exceptions in the inferior.
19282 When exception trapping is off, neither breakpoints nor
19283 single-stepping will work.  To restore the default, set exception
19284 trapping on.
19285
19286 @item show exceptions
19287 @kindex show exceptions@r{, Hurd command}
19288 Show the current state of trapping exceptions in the inferior.
19289
19290 @item set task pause
19291 @kindex set task@r{, Hurd commands}
19292 @cindex task attributes (@sc{gnu} Hurd)
19293 @cindex pause current task (@sc{gnu} Hurd)
19294 This command toggles task suspension when @value{GDBN} has control.
19295 Setting it to on takes effect immediately, and the task is suspended
19296 whenever @value{GDBN} gets control.  Setting it to off will take
19297 effect the next time the inferior is continued.  If this option is set
19298 to off, you can use @code{set thread default pause on} or @code{set
19299 thread pause on} (see below) to pause individual threads.
19300
19301 @item show task pause
19302 @kindex show task@r{, Hurd commands}
19303 Show the current state of task suspension.
19304
19305 @item set task detach-suspend-count
19306 @cindex task suspend count
19307 @cindex detach from task, @sc{gnu} Hurd
19308 This command sets the suspend count the task will be left with when
19309 @value{GDBN} detaches from it.
19310
19311 @item show task detach-suspend-count
19312 Show the suspend count the task will be left with when detaching.
19313
19314 @item set task exception-port
19315 @itemx set task excp
19316 @cindex task exception port, @sc{gnu} Hurd
19317 This command sets the task exception port to which @value{GDBN} will
19318 forward exceptions.  The argument should be the value of the @dfn{send
19319 rights} of the task.  @code{set task excp} is a shorthand alias.
19320
19321 @item set noninvasive
19322 @cindex noninvasive task options
19323 This command switches @value{GDBN} to a mode that is the least
19324 invasive as far as interfering with the inferior is concerned.  This
19325 is the same as using @code{set task pause}, @code{set exceptions}, and
19326 @code{set signals} to values opposite to the defaults.
19327
19328 @item info send-rights
19329 @itemx info receive-rights
19330 @itemx info port-rights
19331 @itemx info port-sets
19332 @itemx info dead-names
19333 @itemx info ports
19334 @itemx info psets
19335 @cindex send rights, @sc{gnu} Hurd
19336 @cindex receive rights, @sc{gnu} Hurd
19337 @cindex port rights, @sc{gnu} Hurd
19338 @cindex port sets, @sc{gnu} Hurd
19339 @cindex dead names, @sc{gnu} Hurd
19340 These commands display information about, respectively, send rights,
19341 receive rights, port rights, port sets, and dead names of a task.
19342 There are also shorthand aliases: @code{info ports} for @code{info
19343 port-rights} and @code{info psets} for @code{info port-sets}.
19344
19345 @item set thread pause
19346 @kindex set thread@r{, Hurd command}
19347 @cindex thread properties, @sc{gnu} Hurd
19348 @cindex pause current thread (@sc{gnu} Hurd)
19349 This command toggles current thread suspension when @value{GDBN} has
19350 control.  Setting it to on takes effect immediately, and the current
19351 thread is suspended whenever @value{GDBN} gets control.  Setting it to
19352 off will take effect the next time the inferior is continued.
19353 Normally, this command has no effect, since when @value{GDBN} has
19354 control, the whole task is suspended.  However, if you used @code{set
19355 task pause off} (see above), this command comes in handy to suspend
19356 only the current thread.
19357
19358 @item show thread pause
19359 @kindex show thread@r{, Hurd command}
19360 This command shows the state of current thread suspension.
19361
19362 @item set thread run
19363 This command sets whether the current thread is allowed to run.
19364
19365 @item show thread run
19366 Show whether the current thread is allowed to run.
19367
19368 @item set thread detach-suspend-count
19369 @cindex thread suspend count, @sc{gnu} Hurd
19370 @cindex detach from thread, @sc{gnu} Hurd
19371 This command sets the suspend count @value{GDBN} will leave on a
19372 thread when detaching.  This number is relative to the suspend count
19373 found by @value{GDBN} when it notices the thread; use @code{set thread
19374 takeover-suspend-count} to force it to an absolute value.
19375
19376 @item show thread detach-suspend-count
19377 Show the suspend count @value{GDBN} will leave on the thread when
19378 detaching.
19379
19380 @item set thread exception-port
19381 @itemx set thread excp
19382 Set the thread exception port to which to forward exceptions.  This
19383 overrides the port set by @code{set task exception-port} (see above).
19384 @code{set thread excp} is the shorthand alias.
19385
19386 @item set thread takeover-suspend-count
19387 Normally, @value{GDBN}'s thread suspend counts are relative to the
19388 value @value{GDBN} finds when it notices each thread.  This command
19389 changes the suspend counts to be absolute instead.
19390
19391 @item set thread default
19392 @itemx show thread default
19393 @cindex thread default settings, @sc{gnu} Hurd
19394 Each of the above @code{set thread} commands has a @code{set thread
19395 default} counterpart (e.g., @code{set thread default pause}, @code{set
19396 thread default exception-port}, etc.).  The @code{thread default}
19397 variety of commands sets the default thread properties for all
19398 threads; you can then change the properties of individual threads with
19399 the non-default commands.
19400 @end table
19401
19402 @node Darwin
19403 @subsection Darwin
19404 @cindex Darwin
19405
19406 @value{GDBN} provides the following commands specific to the Darwin target:
19407
19408 @table @code
19409 @item set debug darwin @var{num}
19410 @kindex set debug darwin
19411 When set to a non zero value, enables debugging messages specific to
19412 the Darwin support.  Higher values produce more verbose output.
19413
19414 @item show debug darwin
19415 @kindex show debug darwin
19416 Show the current state of Darwin messages.
19417
19418 @item set debug mach-o @var{num}
19419 @kindex set debug mach-o
19420 When set to a non zero value, enables debugging messages while
19421 @value{GDBN} is reading Darwin object files.  (@dfn{Mach-O} is the
19422 file format used on Darwin for object and executable files.)  Higher
19423 values produce more verbose output.  This is a command to diagnose
19424 problems internal to @value{GDBN} and should not be needed in normal
19425 usage.
19426
19427 @item show debug mach-o
19428 @kindex show debug mach-o
19429 Show the current state of Mach-O file messages.
19430
19431 @item set mach-exceptions on
19432 @itemx set mach-exceptions off
19433 @kindex set mach-exceptions
19434 On Darwin, faults are first reported as a Mach exception and are then
19435 mapped to a Posix signal.  Use this command to turn on trapping of
19436 Mach exceptions in the inferior.  This might be sometimes useful to
19437 better understand the cause of a fault.  The default is off.
19438
19439 @item show mach-exceptions
19440 @kindex show mach-exceptions
19441 Show the current state of exceptions trapping.
19442 @end table
19443
19444
19445 @node Embedded OS
19446 @section Embedded Operating Systems
19447
19448 This section describes configurations involving the debugging of
19449 embedded operating systems that are available for several different
19450 architectures.
19451
19452 @menu
19453 * VxWorks::                     Using @value{GDBN} with VxWorks
19454 @end menu
19455
19456 @value{GDBN} includes the ability to debug programs running on
19457 various real-time operating systems.
19458
19459 @node VxWorks
19460 @subsection Using @value{GDBN} with VxWorks
19461
19462 @cindex VxWorks
19463
19464 @table @code
19465
19466 @kindex target vxworks
19467 @item target vxworks @var{machinename}
19468 A VxWorks system, attached via TCP/IP.  The argument @var{machinename}
19469 is the target system's machine name or IP address.
19470
19471 @end table
19472
19473 On VxWorks, @code{load} links @var{filename} dynamically on the
19474 current target system as well as adding its symbols in @value{GDBN}.
19475
19476 @value{GDBN} enables developers to spawn and debug tasks running on networked
19477 VxWorks targets from a Unix host.  Already-running tasks spawned from
19478 the VxWorks shell can also be debugged.  @value{GDBN} uses code that runs on
19479 both the Unix host and on the VxWorks target.  The program
19480 @code{@value{GDBP}} is installed and executed on the Unix host.  (It may be
19481 installed with the name @code{vxgdb}, to distinguish it from a
19482 @value{GDBN} for debugging programs on the host itself.)
19483
19484 @table @code
19485 @item VxWorks-timeout @var{args}
19486 @kindex vxworks-timeout
19487 All VxWorks-based targets now support the option @code{vxworks-timeout}.
19488 This option is set by the user, and  @var{args} represents the number of
19489 seconds @value{GDBN} waits for responses to rpc's.  You might use this if
19490 your VxWorks target is a slow software simulator or is on the far side
19491 of a thin network line.
19492 @end table
19493
19494 The following information on connecting to VxWorks was current when
19495 this manual was produced; newer releases of VxWorks may use revised
19496 procedures.
19497
19498 @findex INCLUDE_RDB
19499 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
19500 to include the remote debugging interface routines in the VxWorks
19501 library @file{rdb.a}.  To do this, define @code{INCLUDE_RDB} in the
19502 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
19503 kernel.  The resulting kernel contains @file{rdb.a}, and spawns the
19504 source debugging task @code{tRdbTask} when VxWorks is booted.  For more
19505 information on configuring and remaking VxWorks, see the manufacturer's
19506 manual.
19507 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
19508
19509 Once you have included @file{rdb.a} in your VxWorks system image and set
19510 your Unix execution search path to find @value{GDBN}, you are ready to
19511 run @value{GDBN}.  From your Unix host, run @code{@value{GDBP}} (or
19512 @code{vxgdb}, depending on your installation).
19513
19514 @value{GDBN} comes up showing the prompt:
19515
19516 @smallexample
19517 (vxgdb)
19518 @end smallexample
19519
19520 @menu
19521 * VxWorks Connection::          Connecting to VxWorks
19522 * VxWorks Download::            VxWorks download
19523 * VxWorks Attach::              Running tasks
19524 @end menu
19525
19526 @node VxWorks Connection
19527 @subsubsection Connecting to VxWorks
19528
19529 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
19530 network.  To connect to a target whose host name is ``@code{tt}'', type:
19531
19532 @smallexample
19533 (vxgdb) target vxworks tt
19534 @end smallexample
19535
19536 @need 750
19537 @value{GDBN} displays messages like these:
19538
19539 @smallexample
19540 Attaching remote machine across net...
19541 Connected to tt.
19542 @end smallexample
19543
19544 @need 1000
19545 @value{GDBN} then attempts to read the symbol tables of any object modules
19546 loaded into the VxWorks target since it was last booted.  @value{GDBN} locates
19547 these files by searching the directories listed in the command search
19548 path (@pxref{Environment, ,Your Program's Environment}); if it fails
19549 to find an object file, it displays a message such as:
19550
19551 @smallexample
19552 prog.o: No such file or directory.
19553 @end smallexample
19554
19555 When this happens, add the appropriate directory to the search path with
19556 the @value{GDBN} command @code{path}, and execute the @code{target}
19557 command again.
19558
19559 @node VxWorks Download
19560 @subsubsection VxWorks Download
19561
19562 @cindex download to VxWorks
19563 If you have connected to the VxWorks target and you want to debug an
19564 object that has not yet been loaded, you can use the @value{GDBN}
19565 @code{load} command to download a file from Unix to VxWorks
19566 incrementally.  The object file given as an argument to the @code{load}
19567 command is actually opened twice: first by the VxWorks target in order
19568 to download the code, then by @value{GDBN} in order to read the symbol
19569 table.  This can lead to problems if the current working directories on
19570 the two systems differ.  If both systems have NFS mounted the same
19571 filesystems, you can avoid these problems by using absolute paths.
19572 Otherwise, it is simplest to set the working directory on both systems
19573 to the directory in which the object file resides, and then to reference
19574 the file by its name, without any path.  For instance, a program
19575 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
19576 and in @file{@var{hostpath}/vw/demo/rdb} on the host.  To load this
19577 program, type this on VxWorks:
19578
19579 @smallexample
19580 -> cd "@var{vxpath}/vw/demo/rdb"
19581 @end smallexample
19582
19583 @noindent
19584 Then, in @value{GDBN}, type:
19585
19586 @smallexample
19587 (vxgdb) cd @var{hostpath}/vw/demo/rdb
19588 (vxgdb) load prog.o
19589 @end smallexample
19590
19591 @value{GDBN} displays a response similar to this:
19592
19593 @smallexample
19594 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
19595 @end smallexample
19596
19597 You can also use the @code{load} command to reload an object module
19598 after editing and recompiling the corresponding source file.  Note that
19599 this makes @value{GDBN} delete all currently-defined breakpoints,
19600 auto-displays, and convenience variables, and to clear the value
19601 history.  (This is necessary in order to preserve the integrity of
19602 debugger's data structures that reference the target system's symbol
19603 table.)
19604
19605 @node VxWorks Attach
19606 @subsubsection Running Tasks
19607
19608 @cindex running VxWorks tasks
19609 You can also attach to an existing task using the @code{attach} command as
19610 follows:
19611
19612 @smallexample
19613 (vxgdb) attach @var{task}
19614 @end smallexample
19615
19616 @noindent
19617 where @var{task} is the VxWorks hexadecimal task ID.  The task can be running
19618 or suspended when you attach to it.  Running tasks are suspended at
19619 the time of attachment.
19620
19621 @node Embedded Processors
19622 @section Embedded Processors
19623
19624 This section goes into details specific to particular embedded
19625 configurations.
19626
19627 @cindex send command to simulator
19628 Whenever a specific embedded processor has a simulator, @value{GDBN}
19629 allows to send an arbitrary command to the simulator.
19630
19631 @table @code
19632 @item sim @var{command}
19633 @kindex sim@r{, a command}
19634 Send an arbitrary @var{command} string to the simulator.  Consult the
19635 documentation for the specific simulator in use for information about
19636 acceptable commands.
19637 @end table
19638
19639
19640 @menu
19641 * ARM::                         ARM RDI
19642 * M32R/D::                      Renesas M32R/D
19643 * M68K::                        Motorola M68K
19644 * MicroBlaze::                  Xilinx MicroBlaze
19645 * MIPS Embedded::               MIPS Embedded
19646 * OpenRISC 1000::               OpenRisc 1000
19647 * PowerPC Embedded::            PowerPC Embedded
19648 * PA::                          HP PA Embedded
19649 * Sparclet::                    Tsqware Sparclet
19650 * Sparclite::                   Fujitsu Sparclite
19651 * Z8000::                       Zilog Z8000
19652 * AVR::                         Atmel AVR
19653 * CRIS::                        CRIS
19654 * Super-H::                     Renesas Super-H
19655 @end menu
19656
19657 @node ARM
19658 @subsection ARM
19659 @cindex ARM RDI
19660
19661 @table @code
19662 @kindex target rdi
19663 @item target rdi @var{dev}
19664 ARM Angel monitor, via RDI library interface to ADP protocol.  You may
19665 use this target to communicate with both boards running the Angel
19666 monitor, or with the EmbeddedICE JTAG debug device.
19667
19668 @kindex target rdp
19669 @item target rdp @var{dev}
19670 ARM Demon monitor.
19671
19672 @end table
19673
19674 @value{GDBN} provides the following ARM-specific commands:
19675
19676 @table @code
19677 @item set arm disassembler
19678 @kindex set arm
19679 This commands selects from a list of disassembly styles.  The
19680 @code{"std"} style is the standard style.
19681
19682 @item show arm disassembler
19683 @kindex show arm
19684 Show the current disassembly style.
19685
19686 @item set arm apcs32
19687 @cindex ARM 32-bit mode
19688 This command toggles ARM operation mode between 32-bit and 26-bit.
19689
19690 @item show arm apcs32
19691 Display the current usage of the ARM 32-bit mode.
19692
19693 @item set arm fpu @var{fputype}
19694 This command sets the ARM floating-point unit (FPU) type.  The
19695 argument @var{fputype} can be one of these:
19696
19697 @table @code
19698 @item auto
19699 Determine the FPU type by querying the OS ABI.
19700 @item softfpa
19701 Software FPU, with mixed-endian doubles on little-endian ARM
19702 processors.
19703 @item fpa
19704 GCC-compiled FPA co-processor.
19705 @item softvfp
19706 Software FPU with pure-endian doubles.
19707 @item vfp
19708 VFP co-processor.
19709 @end table
19710
19711 @item show arm fpu
19712 Show the current type of the FPU.
19713
19714 @item set arm abi
19715 This command forces @value{GDBN} to use the specified ABI.
19716
19717 @item show arm abi
19718 Show the currently used ABI.
19719
19720 @item set arm fallback-mode (arm|thumb|auto)
19721 @value{GDBN} uses the symbol table, when available, to determine
19722 whether instructions are ARM or Thumb.  This command controls
19723 @value{GDBN}'s default behavior when the symbol table is not
19724 available.  The default is @samp{auto}, which causes @value{GDBN} to
19725 use the current execution mode (from the @code{T} bit in the @code{CPSR}
19726 register).
19727
19728 @item show arm fallback-mode
19729 Show the current fallback instruction mode.
19730
19731 @item set arm force-mode (arm|thumb|auto)
19732 This command overrides use of the symbol table to determine whether
19733 instructions are ARM or Thumb.  The default is @samp{auto}, which
19734 causes @value{GDBN} to use the symbol table and then the setting
19735 of @samp{set arm fallback-mode}.
19736
19737 @item show arm force-mode
19738 Show the current forced instruction mode.
19739
19740 @item set debug arm
19741 Toggle whether to display ARM-specific debugging messages from the ARM
19742 target support subsystem.
19743
19744 @item show debug arm
19745 Show whether ARM-specific debugging messages are enabled.
19746 @end table
19747
19748 The following commands are available when an ARM target is debugged
19749 using the RDI interface:
19750
19751 @table @code
19752 @item rdilogfile @r{[}@var{file}@r{]}
19753 @kindex rdilogfile
19754 @cindex ADP (Angel Debugger Protocol) logging
19755 Set the filename for the ADP (Angel Debugger Protocol) packet log.
19756 With an argument, sets the log file to the specified @var{file}.  With
19757 no argument, show the current log file name.  The default log file is
19758 @file{rdi.log}.
19759
19760 @item rdilogenable @r{[}@var{arg}@r{]}
19761 @kindex rdilogenable
19762 Control logging of ADP packets.  With an argument of 1 or @code{"yes"}
19763 enables logging, with an argument 0 or @code{"no"} disables it.  With
19764 no arguments displays the current setting.  When logging is enabled,
19765 ADP packets exchanged between @value{GDBN} and the RDI target device
19766 are logged to a file.
19767
19768 @item set rdiromatzero
19769 @kindex set rdiromatzero
19770 @cindex ROM at zero address, RDI
19771 Tell @value{GDBN} whether the target has ROM at address 0.  If on,
19772 vector catching is disabled, so that zero address can be used.  If off
19773 (the default), vector catching is enabled.  For this command to take
19774 effect, it needs to be invoked prior to the @code{target rdi} command.
19775
19776 @item show rdiromatzero
19777 @kindex show rdiromatzero
19778 Show the current setting of ROM at zero address.
19779
19780 @item set rdiheartbeat
19781 @kindex set rdiheartbeat
19782 @cindex RDI heartbeat
19783 Enable or disable RDI heartbeat packets.  It is not recommended to
19784 turn on this option, since it confuses ARM and EPI JTAG interface, as
19785 well as the Angel monitor.
19786
19787 @item show rdiheartbeat
19788 @kindex show rdiheartbeat
19789 Show the setting of RDI heartbeat packets.
19790 @end table
19791
19792 @table @code
19793 @item target sim @r{[}@var{simargs}@r{]} @dots{} 
19794 The @value{GDBN} ARM simulator accepts the following optional arguments.
19795
19796 @table @code
19797 @item --swi-support=@var{type}
19798 Tell the simulator which SWI interfaces to support.
19799 @var{type} may be a comma separated list of the following values.
19800 The default value is @code{all}.
19801
19802 @table @code
19803 @item none
19804 @item demon
19805 @item angel
19806 @item redboot
19807 @item all
19808 @end table
19809 @end table
19810 @end table
19811
19812 @node M32R/D
19813 @subsection Renesas M32R/D and M32R/SDI
19814
19815 @table @code
19816 @kindex target m32r
19817 @item target m32r @var{dev}
19818 Renesas M32R/D ROM monitor.
19819
19820 @kindex target m32rsdi
19821 @item target m32rsdi @var{dev}
19822 Renesas M32R SDI server, connected via parallel port to the board.
19823 @end table
19824
19825 The following @value{GDBN} commands are specific to the M32R monitor:
19826
19827 @table @code
19828 @item set download-path @var{path}
19829 @kindex set download-path
19830 @cindex find downloadable @sc{srec} files (M32R)
19831 Set the default path for finding downloadable @sc{srec} files.
19832
19833 @item show download-path
19834 @kindex show download-path
19835 Show the default path for downloadable @sc{srec} files.
19836
19837 @item set board-address @var{addr}
19838 @kindex set board-address
19839 @cindex M32-EVA target board address
19840 Set the IP address for the M32R-EVA target board.
19841
19842 @item show board-address
19843 @kindex show board-address
19844 Show the current IP address of the target board.
19845
19846 @item set server-address @var{addr}
19847 @kindex set server-address
19848 @cindex download server address (M32R)
19849 Set the IP address for the download server, which is the @value{GDBN}'s
19850 host machine.
19851
19852 @item show server-address
19853 @kindex show server-address
19854 Display the IP address of the download server.
19855
19856 @item upload @r{[}@var{file}@r{]}
19857 @kindex upload@r{, M32R}
19858 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
19859 upload capability.  If no @var{file} argument is given, the current
19860 executable file is uploaded.
19861
19862 @item tload @r{[}@var{file}@r{]}
19863 @kindex tload@r{, M32R}
19864 Test the @code{upload} command.
19865 @end table
19866
19867 The following commands are available for M32R/SDI:
19868
19869 @table @code
19870 @item sdireset
19871 @kindex sdireset
19872 @cindex reset SDI connection, M32R
19873 This command resets the SDI connection.
19874
19875 @item sdistatus
19876 @kindex sdistatus
19877 This command shows the SDI connection status.
19878
19879 @item debug_chaos
19880 @kindex debug_chaos
19881 @cindex M32R/Chaos debugging
19882 Instructs the remote that M32R/Chaos debugging is to be used.
19883
19884 @item use_debug_dma
19885 @kindex use_debug_dma
19886 Instructs the remote to use the DEBUG_DMA method of accessing memory.
19887
19888 @item use_mon_code
19889 @kindex use_mon_code
19890 Instructs the remote to use the MON_CODE method of accessing memory.
19891
19892 @item use_ib_break
19893 @kindex use_ib_break
19894 Instructs the remote to set breakpoints by IB break.
19895
19896 @item use_dbt_break
19897 @kindex use_dbt_break
19898 Instructs the remote to set breakpoints by DBT.
19899 @end table
19900
19901 @node M68K
19902 @subsection M68k
19903
19904 The Motorola m68k configuration includes ColdFire support, and a
19905 target command for the following ROM monitor.
19906
19907 @table @code
19908
19909 @kindex target dbug
19910 @item target dbug @var{dev}
19911 dBUG ROM monitor for Motorola ColdFire.
19912
19913 @end table
19914
19915 @node MicroBlaze
19916 @subsection MicroBlaze
19917 @cindex Xilinx MicroBlaze
19918 @cindex XMD, Xilinx Microprocessor Debugger
19919
19920 The MicroBlaze is a soft-core processor supported on various Xilinx
19921 FPGAs, such as Spartan or Virtex series.  Boards with these processors
19922 usually have JTAG ports which connect to a host system running the Xilinx
19923 Embedded Development Kit (EDK) or Software Development Kit (SDK).
19924 This host system is used to download the configuration bitstream to
19925 the target FPGA.  The Xilinx Microprocessor Debugger (XMD) program
19926 communicates with the target board using the JTAG interface and
19927 presents a @code{gdbserver} interface to the board.  By default
19928 @code{xmd} uses port @code{1234}.  (While it is possible to change 
19929 this default port, it requires the use of undocumented @code{xmd} 
19930 commands.  Contact Xilinx support if you need to do this.)
19931
19932 Use these GDB commands to connect to the MicroBlaze target processor.
19933
19934 @table @code
19935 @item target remote :1234
19936 Use this command to connect to the target if you are running @value{GDBN}
19937 on the same system as @code{xmd}.
19938
19939 @item target remote @var{xmd-host}:1234
19940 Use this command to connect to the target if it is connected to @code{xmd}
19941 running on a different system named @var{xmd-host}.
19942
19943 @item load
19944 Use this command to download a program to the MicroBlaze target.
19945
19946 @item set debug microblaze @var{n}
19947 Enable MicroBlaze-specific debugging messages if non-zero.
19948
19949 @item show debug microblaze @var{n}
19950 Show MicroBlaze-specific debugging level.
19951 @end table
19952
19953 @node MIPS Embedded
19954 @subsection @acronym{MIPS} Embedded
19955
19956 @cindex @acronym{MIPS} boards
19957 @value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
19958 @acronym{MIPS} board attached to a serial line.  This is available when
19959 you configure @value{GDBN} with @samp{--target=mips-elf}.
19960
19961 @need 1000
19962 Use these @value{GDBN} commands to specify the connection to your target board:
19963
19964 @table @code
19965 @item target mips @var{port}
19966 @kindex target mips @var{port}
19967 To run a program on the board, start up @code{@value{GDBP}} with the
19968 name of your program as the argument.  To connect to the board, use the
19969 command @samp{target mips @var{port}}, where @var{port} is the name of
19970 the serial port connected to the board.  If the program has not already
19971 been downloaded to the board, you may use the @code{load} command to
19972 download it.  You can then use all the usual @value{GDBN} commands.
19973
19974 For example, this sequence connects to the target board through a serial
19975 port, and loads and runs a program called @var{prog} through the
19976 debugger:
19977
19978 @smallexample
19979 host$ @value{GDBP} @var{prog}
19980 @value{GDBN} is free software and @dots{}
19981 (@value{GDBP}) target mips /dev/ttyb
19982 (@value{GDBP}) load @var{prog}
19983 (@value{GDBP}) run
19984 @end smallexample
19985
19986 @item target mips @var{hostname}:@var{portnumber}
19987 On some @value{GDBN} host configurations, you can specify a TCP
19988 connection (for instance, to a serial line managed by a terminal
19989 concentrator) instead of a serial port, using the syntax
19990 @samp{@var{hostname}:@var{portnumber}}.
19991
19992 @item target pmon @var{port}
19993 @kindex target pmon @var{port}
19994 PMON ROM monitor.
19995
19996 @item target ddb @var{port}
19997 @kindex target ddb @var{port}
19998 NEC's DDB variant of PMON for Vr4300.
19999
20000 @item target lsi @var{port}
20001 @kindex target lsi @var{port}
20002 LSI variant of PMON.
20003
20004 @kindex target r3900
20005 @item target r3900 @var{dev}
20006 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
20007
20008 @kindex target array
20009 @item target array @var{dev}
20010 Array Tech LSI33K RAID controller board.
20011
20012 @end table
20013
20014
20015 @noindent
20016 @value{GDBN} also supports these special commands for @acronym{MIPS} targets:
20017
20018 @table @code
20019 @item set mipsfpu double
20020 @itemx set mipsfpu single
20021 @itemx set mipsfpu none
20022 @itemx set mipsfpu auto
20023 @itemx show mipsfpu
20024 @kindex set mipsfpu
20025 @kindex show mipsfpu
20026 @cindex @acronym{MIPS} remote floating point
20027 @cindex floating point, @acronym{MIPS} remote
20028 If your target board does not support the @acronym{MIPS} floating point
20029 coprocessor, you should use the command @samp{set mipsfpu none} (if you
20030 need this, you may wish to put the command in your @value{GDBN} init
20031 file).  This tells @value{GDBN} how to find the return value of
20032 functions which return floating point values.  It also allows
20033 @value{GDBN} to avoid saving the floating point registers when calling
20034 functions on the board.  If you are using a floating point coprocessor
20035 with only single precision floating point support, as on the @sc{r4650}
20036 processor, use the command @samp{set mipsfpu single}.  The default
20037 double precision floating point coprocessor may be selected using
20038 @samp{set mipsfpu double}.
20039
20040 In previous versions the only choices were double precision or no
20041 floating point, so @samp{set mipsfpu on} will select double precision
20042 and @samp{set mipsfpu off} will select no floating point.
20043
20044 As usual, you can inquire about the @code{mipsfpu} variable with
20045 @samp{show mipsfpu}.
20046
20047 @item set timeout @var{seconds}
20048 @itemx set retransmit-timeout @var{seconds}
20049 @itemx show timeout
20050 @itemx show retransmit-timeout
20051 @cindex @code{timeout}, @acronym{MIPS} protocol
20052 @cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
20053 @kindex set timeout
20054 @kindex show timeout
20055 @kindex set retransmit-timeout
20056 @kindex show retransmit-timeout
20057 You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
20058 remote protocol, with the @code{set timeout @var{seconds}} command.  The
20059 default is 5 seconds.  Similarly, you can control the timeout used while
20060 waiting for an acknowledgment of a packet with the @code{set
20061 retransmit-timeout @var{seconds}} command.  The default is 3 seconds.
20062 You can inspect both values with @code{show timeout} and @code{show
20063 retransmit-timeout}.  (These commands are @emph{only} available when
20064 @value{GDBN} is configured for @samp{--target=mips-elf}.)
20065
20066 The timeout set by @code{set timeout} does not apply when @value{GDBN}
20067 is waiting for your program to stop.  In that case, @value{GDBN} waits
20068 forever because it has no way of knowing how long the program is going
20069 to run before stopping.
20070
20071 @item set syn-garbage-limit @var{num}
20072 @kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
20073 @cindex synchronize with remote @acronym{MIPS} target
20074 Limit the maximum number of characters @value{GDBN} should ignore when
20075 it tries to synchronize with the remote target.  The default is 10
20076 characters.  Setting the limit to -1 means there's no limit.
20077
20078 @item show syn-garbage-limit
20079 @kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
20080 Show the current limit on the number of characters to ignore when
20081 trying to synchronize with the remote system.
20082
20083 @item set monitor-prompt @var{prompt}
20084 @kindex set monitor-prompt@r{, @acronym{MIPS} remote}
20085 @cindex remote monitor prompt
20086 Tell @value{GDBN} to expect the specified @var{prompt} string from the
20087 remote monitor.  The default depends on the target:
20088 @table @asis
20089 @item pmon target
20090 @samp{PMON}
20091 @item ddb target
20092 @samp{NEC010}
20093 @item lsi target
20094 @samp{PMON>}
20095 @end table
20096
20097 @item show monitor-prompt
20098 @kindex show monitor-prompt@r{, @acronym{MIPS} remote}
20099 Show the current strings @value{GDBN} expects as the prompt from the
20100 remote monitor.
20101
20102 @item set monitor-warnings
20103 @kindex set monitor-warnings@r{, @acronym{MIPS} remote}
20104 Enable or disable monitor warnings about hardware breakpoints.  This
20105 has effect only for the @code{lsi} target.  When on, @value{GDBN} will
20106 display warning messages whose codes are returned by the @code{lsi}
20107 PMON monitor for breakpoint commands.
20108
20109 @item show monitor-warnings
20110 @kindex show monitor-warnings@r{, @acronym{MIPS} remote}
20111 Show the current setting of printing monitor warnings.
20112
20113 @item pmon @var{command}
20114 @kindex pmon@r{, @acronym{MIPS} remote}
20115 @cindex send PMON command
20116 This command allows sending an arbitrary @var{command} string to the
20117 monitor.  The monitor must be in debug mode for this to work.
20118 @end table
20119
20120 @node OpenRISC 1000
20121 @subsection OpenRISC 1000
20122 @cindex OpenRISC 1000
20123
20124 @cindex or1k boards
20125 See OR1k Architecture document (@uref{www.opencores.org}) for more information
20126 about platform and commands.
20127
20128 @table @code
20129
20130 @kindex target jtag
20131 @item target jtag jtag://@var{host}:@var{port}
20132
20133 Connects to remote JTAG server.
20134 JTAG remote server can be either an or1ksim or JTAG server,
20135 connected via parallel port to the board.
20136
20137 Example: @code{target jtag jtag://localhost:9999}
20138
20139 @kindex or1ksim
20140 @item or1ksim @var{command}
20141 If connected to @code{or1ksim} OpenRISC 1000 Architectural
20142 Simulator, proprietary commands can be executed.
20143
20144 @kindex info or1k spr
20145 @item info or1k spr
20146 Displays spr groups.
20147
20148 @item info or1k spr @var{group}
20149 @itemx info or1k spr @var{groupno}
20150 Displays register names in selected group.
20151
20152 @item info or1k spr @var{group} @var{register}
20153 @itemx info or1k spr @var{register}
20154 @itemx info or1k spr @var{groupno} @var{registerno}
20155 @itemx info or1k spr @var{registerno}
20156 Shows information about specified spr register.
20157
20158 @kindex spr
20159 @item spr @var{group} @var{register} @var{value}
20160 @itemx spr @var{register @var{value}}
20161 @itemx spr @var{groupno} @var{registerno @var{value}}
20162 @itemx spr @var{registerno @var{value}}
20163 Writes @var{value} to specified spr register.
20164 @end table
20165
20166 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
20167 It is very similar to @value{GDBN} trace, except it does not interfere with normal
20168 program execution and is thus much faster.  Hardware breakpoints/watchpoint
20169 triggers can be set using:
20170 @table @code
20171 @item $LEA/$LDATA
20172 Load effective address/data
20173 @item $SEA/$SDATA
20174 Store effective address/data
20175 @item $AEA/$ADATA
20176 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
20177 @item $FETCH
20178 Fetch data
20179 @end table
20180
20181 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
20182 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
20183
20184 @code{htrace} commands:
20185 @cindex OpenRISC 1000 htrace
20186 @table @code
20187 @kindex hwatch
20188 @item hwatch @var{conditional}
20189 Set hardware watchpoint on combination of Load/Store Effective Address(es)
20190 or Data.  For example:
20191
20192 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
20193
20194 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
20195
20196 @kindex htrace
20197 @item htrace info
20198 Display information about current HW trace configuration.
20199
20200 @item htrace trigger @var{conditional}
20201 Set starting criteria for HW trace.
20202
20203 @item htrace qualifier @var{conditional}
20204 Set acquisition qualifier for HW trace.
20205
20206 @item htrace stop @var{conditional}
20207 Set HW trace stopping criteria.
20208
20209 @item htrace record [@var{data}]*
20210 Selects the data to be recorded, when qualifier is met and HW trace was
20211 triggered.
20212
20213 @item htrace enable
20214 @itemx htrace disable
20215 Enables/disables the HW trace.
20216
20217 @item htrace rewind [@var{filename}]
20218 Clears currently recorded trace data.
20219
20220 If filename is specified, new trace file is made and any newly collected data
20221 will be written there.
20222
20223 @item htrace print [@var{start} [@var{len}]]
20224 Prints trace buffer, using current record configuration.
20225
20226 @item htrace mode continuous
20227 Set continuous trace mode.
20228
20229 @item htrace mode suspend
20230 Set suspend trace mode.
20231
20232 @end table
20233
20234 @node PowerPC Embedded
20235 @subsection PowerPC Embedded
20236
20237 @cindex DVC register
20238 @value{GDBN} supports using the DVC (Data Value Compare) register to
20239 implement in hardware simple hardware watchpoint conditions of the form:
20240
20241 @smallexample
20242 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
20243   if  @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
20244 @end smallexample
20245
20246 The DVC register will be automatically used when @value{GDBN} detects
20247 such pattern in a condition expression, and the created watchpoint uses one
20248 debug register (either the @code{exact-watchpoints} option is on and the
20249 variable is scalar, or the variable has a length of one byte).  This feature
20250 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
20251 or newer.
20252
20253 When running on PowerPC embedded processors, @value{GDBN} automatically uses
20254 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
20255 in which case watchpoints using only one debug register are created when
20256 watching variables of scalar types.
20257
20258 You can create an artificial array to watch an arbitrary memory
20259 region using one of the following commands (@pxref{Expressions}):
20260
20261 @smallexample
20262 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
20263 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
20264 @end smallexample
20265
20266 PowerPC embedded processors support masked watchpoints.  See the discussion
20267 about the @code{mask} argument in @ref{Set Watchpoints}.
20268
20269 @cindex ranged breakpoint
20270 PowerPC embedded processors support hardware accelerated
20271 @dfn{ranged breakpoints}.  A ranged breakpoint stops execution of
20272 the inferior whenever it executes an instruction at any address within
20273 the range it specifies.  To set a ranged breakpoint in @value{GDBN},
20274 use the @code{break-range} command.
20275
20276 @value{GDBN} provides the following PowerPC-specific commands:
20277
20278 @table @code
20279 @kindex break-range
20280 @item break-range @var{start-location}, @var{end-location}
20281 Set a breakpoint for an address range.
20282 @var{start-location} and @var{end-location} can specify a function name,
20283 a line number, an offset of lines from the current line or from the start
20284 location, or an address of an instruction (see @ref{Specify Location},
20285 for a list of all the possible ways to specify a @var{location}.)
20286 The breakpoint will stop execution of the inferior whenever it
20287 executes an instruction at any address within the specified range,
20288 (including @var{start-location} and @var{end-location}.)
20289
20290 @kindex set powerpc
20291 @item set powerpc soft-float
20292 @itemx show powerpc soft-float
20293 Force @value{GDBN} to use (or not use) a software floating point calling
20294 convention.  By default, @value{GDBN} selects the calling convention based
20295 on the selected architecture and the provided executable file.
20296
20297 @item set powerpc vector-abi
20298 @itemx show powerpc vector-abi
20299 Force @value{GDBN} to use the specified calling convention for vector
20300 arguments and return values.  The valid options are @samp{auto};
20301 @samp{generic}, to avoid vector registers even if they are present;
20302 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
20303 registers.  By default, @value{GDBN} selects the calling convention
20304 based on the selected architecture and the provided executable file.
20305
20306 @item set powerpc exact-watchpoints
20307 @itemx show powerpc exact-watchpoints
20308 Allow @value{GDBN} to use only one debug register when watching a variable
20309 of scalar type, thus assuming that the variable is accessed through the
20310 address of its first byte.
20311
20312 @kindex target dink32
20313 @item target dink32 @var{dev}
20314 DINK32 ROM monitor.
20315
20316 @kindex target ppcbug
20317 @item target ppcbug @var{dev}
20318 @kindex target ppcbug1
20319 @item target ppcbug1 @var{dev}
20320 PPCBUG ROM monitor for PowerPC.
20321
20322 @kindex target sds
20323 @item target sds @var{dev}
20324 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
20325 @end table
20326
20327 @cindex SDS protocol
20328 The following commands specific to the SDS protocol are supported
20329 by @value{GDBN}:
20330
20331 @table @code
20332 @item set sdstimeout @var{nsec}
20333 @kindex set sdstimeout
20334 Set the timeout for SDS protocol reads to be @var{nsec} seconds.  The
20335 default is 2 seconds.
20336
20337 @item show sdstimeout
20338 @kindex show sdstimeout
20339 Show the current value of the SDS timeout.
20340
20341 @item sds @var{command}
20342 @kindex sds@r{, a command}
20343 Send the specified @var{command} string to the SDS monitor.
20344 @end table
20345
20346
20347 @node PA
20348 @subsection HP PA Embedded
20349
20350 @table @code
20351
20352 @kindex target op50n
20353 @item target op50n @var{dev}
20354 OP50N monitor, running on an OKI HPPA board.
20355
20356 @kindex target w89k
20357 @item target w89k @var{dev}
20358 W89K monitor, running on a Winbond HPPA board.
20359
20360 @end table
20361
20362 @node Sparclet
20363 @subsection Tsqware Sparclet
20364
20365 @cindex Sparclet
20366
20367 @value{GDBN} enables developers to debug tasks running on
20368 Sparclet targets from a Unix host.
20369 @value{GDBN} uses code that runs on
20370 both the Unix host and on the Sparclet target.  The program
20371 @code{@value{GDBP}} is installed and executed on the Unix host.
20372
20373 @table @code
20374 @item remotetimeout @var{args}
20375 @kindex remotetimeout
20376 @value{GDBN} supports the option @code{remotetimeout}.
20377 This option is set by the user, and  @var{args} represents the number of
20378 seconds @value{GDBN} waits for responses.
20379 @end table
20380
20381 @cindex compiling, on Sparclet
20382 When compiling for debugging, include the options @samp{-g} to get debug
20383 information and @samp{-Ttext} to relocate the program to where you wish to
20384 load it on the target.  You may also want to add the options @samp{-n} or
20385 @samp{-N} in order to reduce the size of the sections.  Example:
20386
20387 @smallexample
20388 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
20389 @end smallexample
20390
20391 You can use @code{objdump} to verify that the addresses are what you intended:
20392
20393 @smallexample
20394 sparclet-aout-objdump --headers --syms prog
20395 @end smallexample
20396
20397 @cindex running, on Sparclet
20398 Once you have set
20399 your Unix execution search path to find @value{GDBN}, you are ready to
20400 run @value{GDBN}.  From your Unix host, run @code{@value{GDBP}}
20401 (or @code{sparclet-aout-gdb}, depending on your installation).
20402
20403 @value{GDBN} comes up showing the prompt:
20404
20405 @smallexample
20406 (gdbslet)
20407 @end smallexample
20408
20409 @menu
20410 * Sparclet File::                Setting the file to debug
20411 * Sparclet Connection::          Connecting to Sparclet
20412 * Sparclet Download::            Sparclet download
20413 * Sparclet Execution::           Running and debugging
20414 @end menu
20415
20416 @node Sparclet File
20417 @subsubsection Setting File to Debug
20418
20419 The @value{GDBN} command @code{file} lets you choose with program to debug.
20420
20421 @smallexample
20422 (gdbslet) file prog
20423 @end smallexample
20424
20425 @need 1000
20426 @value{GDBN} then attempts to read the symbol table of @file{prog}.
20427 @value{GDBN} locates
20428 the file by searching the directories listed in the command search
20429 path.
20430 If the file was compiled with debug information (option @samp{-g}), source
20431 files will be searched as well.
20432 @value{GDBN} locates
20433 the source files by searching the directories listed in the directory search
20434 path (@pxref{Environment, ,Your Program's Environment}).
20435 If it fails
20436 to find a file, it displays a message such as:
20437
20438 @smallexample
20439 prog: No such file or directory.
20440 @end smallexample
20441
20442 When this happens, add the appropriate directories to the search paths with
20443 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
20444 @code{target} command again.
20445
20446 @node Sparclet Connection
20447 @subsubsection Connecting to Sparclet
20448
20449 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
20450 To connect to a target on serial port ``@code{ttya}'', type:
20451
20452 @smallexample
20453 (gdbslet) target sparclet /dev/ttya
20454 Remote target sparclet connected to /dev/ttya
20455 main () at ../prog.c:3
20456 @end smallexample
20457
20458 @need 750
20459 @value{GDBN} displays messages like these:
20460
20461 @smallexample
20462 Connected to ttya.
20463 @end smallexample
20464
20465 @node Sparclet Download
20466 @subsubsection Sparclet Download
20467
20468 @cindex download to Sparclet
20469 Once connected to the Sparclet target,
20470 you can use the @value{GDBN}
20471 @code{load} command to download the file from the host to the target.
20472 The file name and load offset should be given as arguments to the @code{load}
20473 command.
20474 Since the file format is aout, the program must be loaded to the starting
20475 address.  You can use @code{objdump} to find out what this value is.  The load
20476 offset is an offset which is added to the VMA (virtual memory address)
20477 of each of the file's sections.
20478 For instance, if the program
20479 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
20480 and bss at 0x12010170, in @value{GDBN}, type:
20481
20482 @smallexample
20483 (gdbslet) load prog 0x12010000
20484 Loading section .text, size 0xdb0 vma 0x12010000
20485 @end smallexample
20486
20487 If the code is loaded at a different address then what the program was linked
20488 to, you may need to use the @code{section} and @code{add-symbol-file} commands
20489 to tell @value{GDBN} where to map the symbol table.
20490
20491 @node Sparclet Execution
20492 @subsubsection Running and Debugging
20493
20494 @cindex running and debugging Sparclet programs
20495 You can now begin debugging the task using @value{GDBN}'s execution control
20496 commands, @code{b}, @code{step}, @code{run}, etc.  See the @value{GDBN}
20497 manual for the list of commands.
20498
20499 @smallexample
20500 (gdbslet) b main
20501 Breakpoint 1 at 0x12010000: file prog.c, line 3.
20502 (gdbslet) run
20503 Starting program: prog
20504 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
20505 3        char *symarg = 0;
20506 (gdbslet) step
20507 4        char *execarg = "hello!";
20508 (gdbslet)
20509 @end smallexample
20510
20511 @node Sparclite
20512 @subsection Fujitsu Sparclite
20513
20514 @table @code
20515
20516 @kindex target sparclite
20517 @item target sparclite @var{dev}
20518 Fujitsu sparclite boards, used only for the purpose of loading.
20519 You must use an additional command to debug the program.
20520 For example: target remote @var{dev} using @value{GDBN} standard
20521 remote protocol.
20522
20523 @end table
20524
20525 @node Z8000
20526 @subsection Zilog Z8000
20527
20528 @cindex Z8000
20529 @cindex simulator, Z8000
20530 @cindex Zilog Z8000 simulator
20531
20532 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
20533 a Z8000 simulator.
20534
20535 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
20536 unsegmented variant of the Z8000 architecture) or the Z8001 (the
20537 segmented variant).  The simulator recognizes which architecture is
20538 appropriate by inspecting the object code.
20539
20540 @table @code
20541 @item target sim @var{args}
20542 @kindex sim
20543 @kindex target sim@r{, with Z8000}
20544 Debug programs on a simulated CPU.  If the simulator supports setup
20545 options, specify them via @var{args}.
20546 @end table
20547
20548 @noindent
20549 After specifying this target, you can debug programs for the simulated
20550 CPU in the same style as programs for your host computer; use the
20551 @code{file} command to load a new program image, the @code{run} command
20552 to run your program, and so on.
20553
20554 As well as making available all the usual machine registers
20555 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
20556 additional items of information as specially named registers:
20557
20558 @table @code
20559
20560 @item cycles
20561 Counts clock-ticks in the simulator.
20562
20563 @item insts
20564 Counts instructions run in the simulator.
20565
20566 @item time
20567 Execution time in 60ths of a second.
20568
20569 @end table
20570
20571 You can refer to these values in @value{GDBN} expressions with the usual
20572 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
20573 conditional breakpoint that suspends only after at least 5000
20574 simulated clock ticks.
20575
20576 @node AVR
20577 @subsection Atmel AVR
20578 @cindex AVR
20579
20580 When configured for debugging the Atmel AVR, @value{GDBN} supports the
20581 following AVR-specific commands:
20582
20583 @table @code
20584 @item info io_registers
20585 @kindex info io_registers@r{, AVR}
20586 @cindex I/O registers (Atmel AVR)
20587 This command displays information about the AVR I/O registers.  For
20588 each register, @value{GDBN} prints its number and value.
20589 @end table
20590
20591 @node CRIS
20592 @subsection CRIS
20593 @cindex CRIS
20594
20595 When configured for debugging CRIS, @value{GDBN} provides the
20596 following CRIS-specific commands:
20597
20598 @table @code
20599 @item set cris-version @var{ver}
20600 @cindex CRIS version
20601 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
20602 The CRIS version affects register names and sizes.  This command is useful in
20603 case autodetection of the CRIS version fails.
20604
20605 @item show cris-version
20606 Show the current CRIS version.
20607
20608 @item set cris-dwarf2-cfi
20609 @cindex DWARF-2 CFI and CRIS
20610 Set the usage of DWARF-2 CFI for CRIS debugging.  The default is @samp{on}.
20611 Change to @samp{off} when using @code{gcc-cris} whose version is below 
20612 @code{R59}.
20613
20614 @item show cris-dwarf2-cfi
20615 Show the current state of using DWARF-2 CFI.
20616
20617 @item set cris-mode @var{mode}
20618 @cindex CRIS mode
20619 Set the current CRIS mode to @var{mode}.  It should only be changed when
20620 debugging in guru mode, in which case it should be set to 
20621 @samp{guru} (the default is @samp{normal}).
20622
20623 @item show cris-mode
20624 Show the current CRIS mode.
20625 @end table
20626
20627 @node Super-H
20628 @subsection Renesas Super-H
20629 @cindex Super-H
20630
20631 For the Renesas Super-H processor, @value{GDBN} provides these
20632 commands:
20633
20634 @table @code
20635 @item set sh calling-convention @var{convention}
20636 @kindex set sh calling-convention
20637 Set the calling-convention used when calling functions from @value{GDBN}.
20638 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
20639 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
20640 convention.  If the DWARF-2 information of the called function specifies
20641 that the function follows the Renesas calling convention, the function
20642 is called using the Renesas calling convention.  If the calling convention
20643 is set to @samp{renesas}, the Renesas calling convention is always used,
20644 regardless of the DWARF-2 information.  This can be used to override the
20645 default of @samp{gcc} if debug information is missing, or the compiler
20646 does not emit the DWARF-2 calling convention entry for a function.
20647
20648 @item show sh calling-convention
20649 @kindex show sh calling-convention
20650 Show the current calling convention setting.
20651
20652 @end table
20653
20654
20655 @node Architectures
20656 @section Architectures
20657
20658 This section describes characteristics of architectures that affect
20659 all uses of @value{GDBN} with the architecture, both native and cross.
20660
20661 @menu
20662 * i386::
20663 * Alpha::
20664 * MIPS::
20665 * HPPA::               HP PA architecture
20666 * SPU::                Cell Broadband Engine SPU architecture
20667 * PowerPC::
20668 @end menu
20669
20670 @node i386
20671 @subsection x86 Architecture-specific Issues
20672
20673 @table @code
20674 @item set struct-convention @var{mode}
20675 @kindex set struct-convention
20676 @cindex struct return convention
20677 @cindex struct/union returned in registers
20678 Set the convention used by the inferior to return @code{struct}s and
20679 @code{union}s from functions to @var{mode}.  Possible values of
20680 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
20681 default).  @code{"default"} or @code{"pcc"} means that @code{struct}s
20682 are returned on the stack, while @code{"reg"} means that a
20683 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
20684 be returned in a register.
20685
20686 @item show struct-convention
20687 @kindex show struct-convention
20688 Show the current setting of the convention to return @code{struct}s
20689 from functions.
20690 @end table
20691
20692 @node Alpha
20693 @subsection Alpha
20694
20695 See the following section.
20696
20697 @node MIPS
20698 @subsection @acronym{MIPS}
20699
20700 @cindex stack on Alpha
20701 @cindex stack on @acronym{MIPS}
20702 @cindex Alpha stack
20703 @cindex @acronym{MIPS} stack
20704 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
20705 sometimes requires @value{GDBN} to search backward in the object code to
20706 find the beginning of a function.
20707
20708 @cindex response time, @acronym{MIPS} debugging
20709 To improve response time (especially for embedded applications, where
20710 @value{GDBN} may be restricted to a slow serial line for this search)
20711 you may want to limit the size of this search, using one of these
20712 commands:
20713
20714 @table @code
20715 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
20716 @item set heuristic-fence-post @var{limit}
20717 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
20718 search for the beginning of a function.  A value of @var{0} (the
20719 default) means there is no limit.  However, except for @var{0}, the
20720 larger the limit the more bytes @code{heuristic-fence-post} must search
20721 and therefore the longer it takes to run.  You should only need to use
20722 this command when debugging a stripped executable.
20723
20724 @item show heuristic-fence-post
20725 Display the current limit.
20726 @end table
20727
20728 @noindent
20729 These commands are available @emph{only} when @value{GDBN} is configured
20730 for debugging programs on Alpha or @acronym{MIPS} processors.
20731
20732 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
20733 programs:
20734
20735 @table @code
20736 @item set mips abi @var{arg}
20737 @kindex set mips abi
20738 @cindex set ABI for @acronym{MIPS}
20739 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior.  Possible
20740 values of @var{arg} are:
20741
20742 @table @samp
20743 @item auto
20744 The default ABI associated with the current binary (this is the
20745 default).
20746 @item o32
20747 @item o64
20748 @item n32
20749 @item n64
20750 @item eabi32
20751 @item eabi64
20752 @end table
20753
20754 @item show mips abi
20755 @kindex show mips abi
20756 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
20757
20758 @item set mips compression @var{arg}
20759 @kindex set mips compression
20760 @cindex code compression, @acronym{MIPS}
20761 Tell @value{GDBN} which @acronym{MIPS} compressed
20762 @acronym{ISA, Instruction Set Architecture} encoding is used by the
20763 inferior.  @value{GDBN} uses this for code disassembly and other
20764 internal interpretation purposes.  This setting is only referred to
20765 when no executable has been associated with the debugging session or
20766 the executable does not provide information about the encoding it uses.
20767 Otherwise this setting is automatically updated from information
20768 provided by the executable.
20769
20770 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
20771 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
20772 executables containing @acronym{MIPS16} code frequently are not
20773 identified as such.
20774
20775 This setting is ``sticky''; that is, it retains its value across
20776 debugging sessions until reset either explicitly with this command or
20777 implicitly from an executable.
20778
20779 The compiler and/or assembler typically add symbol table annotations to
20780 identify functions compiled for the @acronym{MIPS16} or
20781 @acronym{microMIPS} @acronym{ISA}s.  If these function-scope annotations
20782 are present, @value{GDBN} uses them in preference to the global
20783 compressed @acronym{ISA} encoding setting.
20784
20785 @item show mips compression
20786 @kindex show mips compression
20787 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
20788 @value{GDBN} to debug the inferior.
20789
20790 @item set mipsfpu
20791 @itemx show mipsfpu
20792 @xref{MIPS Embedded, set mipsfpu}.
20793
20794 @item set mips mask-address @var{arg}
20795 @kindex set mips mask-address
20796 @cindex @acronym{MIPS} addresses, masking
20797 This command determines whether the most-significant 32 bits of 64-bit
20798 @acronym{MIPS} addresses are masked off.  The argument @var{arg} can be
20799 @samp{on}, @samp{off}, or @samp{auto}.  The latter is the default
20800 setting, which lets @value{GDBN} determine the correct value.
20801
20802 @item show mips mask-address
20803 @kindex show mips mask-address
20804 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
20805 not.
20806
20807 @item set remote-mips64-transfers-32bit-regs
20808 @kindex set remote-mips64-transfers-32bit-regs
20809 This command controls compatibility with 64-bit @acronym{MIPS} targets that
20810 transfer data in 32-bit quantities.  If you have an old @acronym{MIPS} 64 target
20811 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
20812 and 64 bits for other registers, set this option to @samp{on}.
20813
20814 @item show remote-mips64-transfers-32bit-regs
20815 @kindex show remote-mips64-transfers-32bit-regs
20816 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
20817
20818 @item set debug mips
20819 @kindex set debug mips
20820 This command turns on and off debugging messages for the @acronym{MIPS}-specific
20821 target code in @value{GDBN}.
20822
20823 @item show debug mips
20824 @kindex show debug mips
20825 Show the current setting of @acronym{MIPS} debugging messages.
20826 @end table
20827
20828
20829 @node HPPA
20830 @subsection HPPA
20831 @cindex HPPA support
20832
20833 When @value{GDBN} is debugging the HP PA architecture, it provides the
20834 following special commands:
20835
20836 @table @code
20837 @item set debug hppa
20838 @kindex set debug hppa
20839 This command determines whether HPPA architecture-specific debugging
20840 messages are to be displayed.
20841
20842 @item show debug hppa
20843 Show whether HPPA debugging messages are displayed.
20844
20845 @item maint print unwind @var{address}
20846 @kindex maint print unwind@r{, HPPA}
20847 This command displays the contents of the unwind table entry at the
20848 given @var{address}.
20849
20850 @end table
20851
20852
20853 @node SPU
20854 @subsection Cell Broadband Engine SPU architecture
20855 @cindex Cell Broadband Engine
20856 @cindex SPU
20857
20858 When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
20859 it provides the following special commands:
20860
20861 @table @code
20862 @item info spu event
20863 @kindex info spu
20864 Display SPU event facility status.  Shows current event mask
20865 and pending event status.
20866
20867 @item info spu signal
20868 Display SPU signal notification facility status.  Shows pending
20869 signal-control word and signal notification mode of both signal
20870 notification channels.
20871
20872 @item info spu mailbox
20873 Display SPU mailbox facility status.  Shows all pending entries,
20874 in order of processing, in each of the SPU Write Outbound,
20875 SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
20876
20877 @item info spu dma
20878 Display MFC DMA status.  Shows all pending commands in the MFC
20879 DMA queue.  For each entry, opcode, tag, class IDs, effective
20880 and local store addresses and transfer size are shown.
20881
20882 @item info spu proxydma
20883 Display MFC Proxy-DMA status.  Shows all pending commands in the MFC
20884 Proxy-DMA queue.  For each entry, opcode, tag, class IDs, effective
20885 and local store addresses and transfer size are shown.
20886
20887 @end table
20888  
20889 When @value{GDBN} is debugging a combined PowerPC/SPU application
20890 on the Cell Broadband Engine, it provides in addition the following
20891 special commands:
20892
20893 @table @code
20894 @item set spu stop-on-load @var{arg}
20895 @kindex set spu
20896 Set whether to stop for new SPE threads.  When set to @code{on}, @value{GDBN}
20897 will give control to the user when a new SPE thread enters its @code{main}
20898 function.  The default is @code{off}.
20899
20900 @item show spu stop-on-load
20901 @kindex show spu
20902 Show whether to stop for new SPE threads.
20903
20904 @item set spu auto-flush-cache @var{arg}
20905 Set whether to automatically flush the software-managed cache.  When set to
20906 @code{on}, @value{GDBN} will automatically cause the SPE software-managed
20907 cache to be flushed whenever SPE execution stops.  This provides a consistent
20908 view of PowerPC memory that is accessed via the cache.  If an application
20909 does not use the software-managed cache, this option has no effect.
20910
20911 @item show spu auto-flush-cache
20912 Show whether to automatically flush the software-managed cache.
20913
20914 @end table
20915
20916 @node PowerPC
20917 @subsection PowerPC
20918 @cindex PowerPC architecture
20919
20920 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of 
20921 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
20922 numbers stored in the floating point registers. These values must be stored
20923 in two consecutive registers, always starting at an even register like
20924 @code{f0} or @code{f2}.
20925
20926 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
20927 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
20928 @code{f2} and @code{f3} for @code{$dl1} and so on.
20929
20930 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
20931 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
20932
20933
20934 @node Controlling GDB
20935 @chapter Controlling @value{GDBN}
20936
20937 You can alter the way @value{GDBN} interacts with you by using the
20938 @code{set} command.  For commands controlling how @value{GDBN} displays
20939 data, see @ref{Print Settings, ,Print Settings}.  Other settings are
20940 described here.
20941
20942 @menu
20943 * Prompt::                      Prompt
20944 * Editing::                     Command editing
20945 * Command History::             Command history
20946 * Screen Size::                 Screen size
20947 * Numbers::                     Numbers
20948 * ABI::                         Configuring the current ABI
20949 * Auto-loading::                Automatically loading associated files
20950 * Messages/Warnings::           Optional warnings and messages
20951 * Debugging Output::            Optional messages about internal happenings
20952 * Other Misc Settings::         Other Miscellaneous Settings
20953 @end menu
20954
20955 @node Prompt
20956 @section Prompt
20957
20958 @cindex prompt
20959
20960 @value{GDBN} indicates its readiness to read a command by printing a string
20961 called the @dfn{prompt}.  This string is normally @samp{(@value{GDBP})}.  You
20962 can change the prompt string with the @code{set prompt} command.  For
20963 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
20964 the prompt in one of the @value{GDBN} sessions so that you can always tell
20965 which one you are talking to.
20966
20967 @emph{Note:}  @code{set prompt} does not add a space for you after the
20968 prompt you set.  This allows you to set a prompt which ends in a space
20969 or a prompt that does not.
20970
20971 @table @code
20972 @kindex set prompt
20973 @item set prompt @var{newprompt}
20974 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
20975
20976 @kindex show prompt
20977 @item show prompt
20978 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
20979 @end table
20980
20981 Versions of @value{GDBN} that ship with Python scripting enabled have
20982 prompt extensions.  The commands for interacting with these extensions
20983 are:
20984
20985 @table @code
20986 @kindex set extended-prompt
20987 @item set extended-prompt @var{prompt}
20988 Set an extended prompt that allows for substitutions.
20989 @xref{gdb.prompt}, for a list of escape sequences that can be used for
20990 substitution.  Any escape sequences specified as part of the prompt
20991 string are replaced with the corresponding strings each time the prompt
20992 is displayed.
20993
20994 For example:
20995
20996 @smallexample
20997 set extended-prompt Current working directory: \w (gdb)
20998 @end smallexample
20999
21000 Note that when an extended-prompt is set, it takes control of the
21001 @var{prompt_hook} hook.  @xref{prompt_hook}, for further information.
21002
21003 @kindex show extended-prompt
21004 @item show extended-prompt
21005 Prints the extended prompt.  Any escape sequences specified as part of
21006 the prompt string with @code{set extended-prompt}, are replaced with the
21007 corresponding strings each time the prompt is displayed.
21008 @end table
21009
21010 @node Editing
21011 @section Command Editing
21012 @cindex readline
21013 @cindex command line editing
21014
21015 @value{GDBN} reads its input commands via the @dfn{Readline} interface.  This
21016 @sc{gnu} library provides consistent behavior for programs which provide a
21017 command line interface to the user.  Advantages are @sc{gnu} Emacs-style
21018 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
21019 substitution, and a storage and recall of command history across
21020 debugging sessions.
21021
21022 You may control the behavior of command line editing in @value{GDBN} with the
21023 command @code{set}.
21024
21025 @table @code
21026 @kindex set editing
21027 @cindex editing
21028 @item set editing
21029 @itemx set editing on
21030 Enable command line editing (enabled by default).
21031
21032 @item set editing off
21033 Disable command line editing.
21034
21035 @kindex show editing
21036 @item show editing
21037 Show whether command line editing is enabled.
21038 @end table
21039
21040 @ifset SYSTEM_READLINE
21041 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
21042 @end ifset
21043 @ifclear SYSTEM_READLINE
21044 @xref{Command Line Editing},
21045 @end ifclear
21046 for more details about the Readline
21047 interface.  Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
21048 encouraged to read that chapter.
21049
21050 @node Command History
21051 @section Command History
21052 @cindex command history
21053
21054 @value{GDBN} can keep track of the commands you type during your
21055 debugging sessions, so that you can be certain of precisely what
21056 happened.  Use these commands to manage the @value{GDBN} command
21057 history facility.
21058
21059 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
21060 package, to provide the history facility.
21061 @ifset SYSTEM_READLINE
21062 @xref{Using History Interactively, , , history, GNU History Library},
21063 @end ifset
21064 @ifclear SYSTEM_READLINE
21065 @xref{Using History Interactively},
21066 @end ifclear
21067 for the detailed description of the History library.
21068
21069 To issue a command to @value{GDBN} without affecting certain aspects of
21070 the state which is seen by users, prefix it with @samp{server }
21071 (@pxref{Server Prefix}).  This
21072 means that this command will not affect the command history, nor will it
21073 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
21074 pressed on a line by itself.
21075
21076 @cindex @code{server}, command prefix
21077 The server prefix does not affect the recording of values into the value
21078 history; to print a value without recording it into the value history,
21079 use the @code{output} command instead of the @code{print} command.
21080
21081 Here is the description of @value{GDBN} commands related to command
21082 history.
21083
21084 @table @code
21085 @cindex history substitution
21086 @cindex history file
21087 @kindex set history filename
21088 @cindex @env{GDBHISTFILE}, environment variable
21089 @item set history filename @var{fname}
21090 Set the name of the @value{GDBN} command history file to @var{fname}.
21091 This is the file where @value{GDBN} reads an initial command history
21092 list, and where it writes the command history from this session when it
21093 exits.  You can access this list through history expansion or through
21094 the history command editing characters listed below.  This file defaults
21095 to the value of the environment variable @code{GDBHISTFILE}, or to
21096 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
21097 is not set.
21098
21099 @cindex save command history
21100 @kindex set history save
21101 @item set history save
21102 @itemx set history save on
21103 Record command history in a file, whose name may be specified with the
21104 @code{set history filename} command.  By default, this option is disabled.
21105
21106 @item set history save off
21107 Stop recording command history in a file.
21108
21109 @cindex history size
21110 @kindex set history size
21111 @cindex @env{HISTSIZE}, environment variable
21112 @item set history size @var{size}
21113 Set the number of commands which @value{GDBN} keeps in its history list.
21114 This defaults to the value of the environment variable
21115 @code{HISTSIZE}, or to 256 if this variable is not set.
21116 @end table
21117
21118 History expansion assigns special meaning to the character @kbd{!}.
21119 @ifset SYSTEM_READLINE
21120 @xref{Event Designators, , , history, GNU History Library},
21121 @end ifset
21122 @ifclear SYSTEM_READLINE
21123 @xref{Event Designators},
21124 @end ifclear
21125 for more details.
21126
21127 @cindex history expansion, turn on/off
21128 Since @kbd{!} is also the logical not operator in C, history expansion
21129 is off by default. If you decide to enable history expansion with the
21130 @code{set history expansion on} command, you may sometimes need to
21131 follow @kbd{!} (when it is used as logical not, in an expression) with
21132 a space or a tab to prevent it from being expanded.  The readline
21133 history facilities do not attempt substitution on the strings
21134 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
21135
21136 The commands to control history expansion are:
21137
21138 @table @code
21139 @item set history expansion on
21140 @itemx set history expansion
21141 @kindex set history expansion
21142 Enable history expansion.  History expansion is off by default.
21143
21144 @item set history expansion off
21145 Disable history expansion.
21146
21147 @c @group
21148 @kindex show history
21149 @item show history
21150 @itemx show history filename
21151 @itemx show history save
21152 @itemx show history size
21153 @itemx show history expansion
21154 These commands display the state of the @value{GDBN} history parameters.
21155 @code{show history} by itself displays all four states.
21156 @c @end group
21157 @end table
21158
21159 @table @code
21160 @kindex show commands
21161 @cindex show last commands
21162 @cindex display command history
21163 @item show commands
21164 Display the last ten commands in the command history.
21165
21166 @item show commands @var{n}
21167 Print ten commands centered on command number @var{n}.
21168
21169 @item show commands +
21170 Print ten commands just after the commands last printed.
21171 @end table
21172
21173 @node Screen Size
21174 @section Screen Size
21175 @cindex size of screen
21176 @cindex pauses in output
21177
21178 Certain commands to @value{GDBN} may produce large amounts of
21179 information output to the screen.  To help you read all of it,
21180 @value{GDBN} pauses and asks you for input at the end of each page of
21181 output.  Type @key{RET} when you want to continue the output, or @kbd{q}
21182 to discard the remaining output.  Also, the screen width setting
21183 determines when to wrap lines of output.  Depending on what is being
21184 printed, @value{GDBN} tries to break the line at a readable place,
21185 rather than simply letting it overflow onto the following line.
21186
21187 Normally @value{GDBN} knows the size of the screen from the terminal
21188 driver software.  For example, on Unix @value{GDBN} uses the termcap data base
21189 together with the value of the @code{TERM} environment variable and the
21190 @code{stty rows} and @code{stty cols} settings.  If this is not correct,
21191 you can override it with the @code{set height} and @code{set
21192 width} commands:
21193
21194 @table @code
21195 @kindex set height
21196 @kindex set width
21197 @kindex show width
21198 @kindex show height
21199 @item set height @var{lpp}
21200 @itemx show height
21201 @itemx set width @var{cpl}
21202 @itemx show width
21203 These @code{set} commands specify a screen height of @var{lpp} lines and
21204 a screen width of @var{cpl} characters.  The associated @code{show}
21205 commands display the current settings.
21206
21207 If you specify a height of zero lines, @value{GDBN} does not pause during
21208 output no matter how long the output is.  This is useful if output is to a
21209 file or to an editor buffer.
21210
21211 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
21212 from wrapping its output.
21213
21214 @item set pagination on
21215 @itemx set pagination off
21216 @kindex set pagination
21217 Turn the output pagination on or off; the default is on.  Turning
21218 pagination off is the alternative to @code{set height 0}.  Note that
21219 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
21220 Options, -batch}) also automatically disables pagination.
21221
21222 @item show pagination
21223 @kindex show pagination
21224 Show the current pagination mode.
21225 @end table
21226
21227 @node Numbers
21228 @section Numbers
21229 @cindex number representation
21230 @cindex entering numbers
21231
21232 You can always enter numbers in octal, decimal, or hexadecimal in
21233 @value{GDBN} by the usual conventions: octal numbers begin with
21234 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
21235 begin with @samp{0x}.  Numbers that neither begin with @samp{0} or
21236 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
21237 10; likewise, the default display for numbers---when no particular
21238 format is specified---is base 10.  You can change the default base for
21239 both input and output with the commands described below.
21240
21241 @table @code
21242 @kindex set input-radix
21243 @item set input-radix @var{base}
21244 Set the default base for numeric input.  Supported choices
21245 for @var{base} are decimal 8, 10, or 16.  @var{base} must itself be
21246 specified either unambiguously or using the current input radix; for
21247 example, any of
21248
21249 @smallexample
21250 set input-radix 012
21251 set input-radix 10.
21252 set input-radix 0xa
21253 @end smallexample
21254
21255 @noindent
21256 sets the input base to decimal.  On the other hand, @samp{set input-radix 10}
21257 leaves the input radix unchanged, no matter what it was, since
21258 @samp{10}, being without any leading or trailing signs of its base, is
21259 interpreted in the current radix.  Thus, if the current radix is 16,
21260 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
21261 change the radix.
21262
21263 @kindex set output-radix
21264 @item set output-radix @var{base}
21265 Set the default base for numeric display.  Supported choices
21266 for @var{base} are decimal 8, 10, or 16.  @var{base} must itself be
21267 specified either unambiguously or using the current input radix.
21268
21269 @kindex show input-radix
21270 @item show input-radix
21271 Display the current default base for numeric input.
21272
21273 @kindex show output-radix
21274 @item show output-radix
21275 Display the current default base for numeric display.
21276
21277 @item set radix @r{[}@var{base}@r{]}
21278 @itemx show radix
21279 @kindex set radix
21280 @kindex show radix
21281 These commands set and show the default base for both input and output
21282 of numbers.  @code{set radix} sets the radix of input and output to
21283 the same base; without an argument, it resets the radix back to its
21284 default value of 10.
21285
21286 @end table
21287
21288 @node ABI
21289 @section Configuring the Current ABI
21290
21291 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
21292 application automatically.  However, sometimes you need to override its
21293 conclusions.  Use these commands to manage @value{GDBN}'s view of the
21294 current ABI.
21295
21296 @cindex OS ABI
21297 @kindex set osabi
21298 @kindex show osabi
21299
21300 One @value{GDBN} configuration can debug binaries for multiple operating
21301 system targets, either via remote debugging or native emulation.
21302 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
21303 but you can override its conclusion using the @code{set osabi} command.
21304 One example where this is useful is in debugging of binaries which use
21305 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
21306 not have the same identifying marks that the standard C library for your
21307 platform provides.
21308
21309 @table @code
21310 @item show osabi
21311 Show the OS ABI currently in use.
21312
21313 @item set osabi
21314 With no argument, show the list of registered available OS ABI's.
21315
21316 @item set osabi @var{abi}
21317 Set the current OS ABI to @var{abi}.
21318 @end table
21319
21320 @cindex float promotion
21321
21322 Generally, the way that an argument of type @code{float} is passed to a
21323 function depends on whether the function is prototyped.  For a prototyped
21324 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
21325 according to the architecture's convention for @code{float}.  For unprototyped
21326 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
21327 @code{double} and then passed.
21328
21329 Unfortunately, some forms of debug information do not reliably indicate whether
21330 a function is prototyped.  If @value{GDBN} calls a function that is not marked
21331 as prototyped, it consults @kbd{set coerce-float-to-double}.
21332
21333 @table @code
21334 @kindex set coerce-float-to-double
21335 @item set coerce-float-to-double
21336 @itemx set coerce-float-to-double on
21337 Arguments of type @code{float} will be promoted to @code{double} when passed
21338 to an unprototyped function.  This is the default setting.
21339
21340 @item set coerce-float-to-double off
21341 Arguments of type @code{float} will be passed directly to unprototyped
21342 functions.
21343
21344 @kindex show coerce-float-to-double
21345 @item show coerce-float-to-double
21346 Show the current setting of promoting @code{float} to @code{double}.
21347 @end table
21348
21349 @kindex set cp-abi
21350 @kindex show cp-abi
21351 @value{GDBN} needs to know the ABI used for your program's C@t{++}
21352 objects.  The correct C@t{++} ABI depends on which C@t{++} compiler was
21353 used to build your application.  @value{GDBN} only fully supports
21354 programs with a single C@t{++} ABI; if your program contains code using
21355 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
21356 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
21357 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
21358 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
21359 ``hpaCC'' for the HP ANSI C@t{++} compiler.  Other C@t{++} compilers may
21360 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well.  The default setting is
21361 ``auto''.
21362
21363 @table @code
21364 @item show cp-abi
21365 Show the C@t{++} ABI currently in use.
21366
21367 @item set cp-abi
21368 With no argument, show the list of supported C@t{++} ABI's.
21369
21370 @item set cp-abi @var{abi}
21371 @itemx set cp-abi auto
21372 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
21373 @end table
21374
21375 @node Auto-loading
21376 @section Automatically loading associated files
21377 @cindex auto-loading
21378
21379 @value{GDBN} sometimes reads files with commands and settings automatically,
21380 without being explicitly told so by the user.  We call this feature
21381 @dfn{auto-loading}.  While auto-loading is useful for automatically adapting
21382 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
21383 results or introduce security risks (e.g., if the file comes from untrusted
21384 sources).
21385
21386 Note that loading of these associated files (including the local @file{.gdbinit}
21387 file) requires accordingly configured @code{auto-load safe-path}
21388 (@pxref{Auto-loading safe path}).
21389
21390 For these reasons, @value{GDBN} includes commands and options to let you
21391 control when to auto-load files and which files should be auto-loaded.
21392
21393 @table @code
21394 @anchor{set auto-load off}
21395 @kindex set auto-load off
21396 @item set auto-load off
21397 Globally disable loading of all auto-loaded files.
21398 You may want to use this command with the @samp{-iex} option
21399 (@pxref{Option -init-eval-command}) such as:
21400 @smallexample
21401 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
21402 @end smallexample
21403
21404 Be aware that system init file (@pxref{System-wide configuration})
21405 and init files from your home directory (@pxref{Home Directory Init File})
21406 still get read (as they come from generally trusted directories).
21407 To prevent @value{GDBN} from auto-loading even those init files, use the
21408 @option{-nx} option (@pxref{Mode Options}), in addition to
21409 @code{set auto-load no}.
21410
21411 @anchor{show auto-load}
21412 @kindex show auto-load
21413 @item show auto-load
21414 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
21415 or disabled.
21416
21417 @smallexample
21418 (gdb) show auto-load
21419 gdb-scripts:  Auto-loading of canned sequences of commands scripts is on.
21420 libthread-db:  Auto-loading of inferior specific libthread_db is on.
21421 local-gdbinit:  Auto-loading of .gdbinit script from current directory
21422                 is on.
21423 python-scripts:  Auto-loading of Python scripts is on.
21424 safe-path:  List of directories from which it is safe to auto-load files
21425             is $debugdir:$datadir/auto-load.
21426 scripts-directory:  List of directories from which to load auto-loaded scripts
21427                     is $debugdir:$datadir/auto-load.
21428 @end smallexample
21429
21430 @anchor{info auto-load}
21431 @kindex info auto-load
21432 @item info auto-load
21433 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
21434 not.
21435
21436 @smallexample
21437 (gdb) info auto-load
21438 gdb-scripts:
21439 Loaded  Script
21440 Yes     /home/user/gdb/gdb-gdb.gdb
21441 libthread-db:  No auto-loaded libthread-db.
21442 local-gdbinit:  Local .gdbinit file "/home/user/gdb/.gdbinit" has been
21443                 loaded.
21444 python-scripts:
21445 Loaded  Script
21446 Yes     /home/user/gdb/gdb-gdb.py
21447 @end smallexample
21448 @end table
21449
21450 These are various kinds of files @value{GDBN} can automatically load:
21451
21452 @itemize @bullet
21453 @item
21454 @xref{objfile-gdb.py file}, controlled by @ref{set auto-load python-scripts}.
21455 @item
21456 @xref{objfile-gdb.gdb file}, controlled by @ref{set auto-load gdb-scripts}.
21457 @item
21458 @xref{dotdebug_gdb_scripts section},
21459 controlled by @ref{set auto-load python-scripts}.
21460 @item
21461 @xref{Init File in the Current Directory},
21462 controlled by @ref{set auto-load local-gdbinit}.
21463 @item
21464 @xref{libthread_db.so.1 file}, controlled by @ref{set auto-load libthread-db}.
21465 @end itemize
21466
21467 These are @value{GDBN} control commands for the auto-loading:
21468
21469 @multitable @columnfractions .5 .5
21470 @item @xref{set auto-load off}.
21471 @tab Disable auto-loading globally.
21472 @item @xref{show auto-load}.
21473 @tab Show setting of all kinds of files.
21474 @item @xref{info auto-load}.
21475 @tab Show state of all kinds of files.
21476 @item @xref{set auto-load gdb-scripts}.
21477 @tab Control for @value{GDBN} command scripts.
21478 @item @xref{show auto-load gdb-scripts}.
21479 @tab Show setting of @value{GDBN} command scripts.
21480 @item @xref{info auto-load gdb-scripts}.
21481 @tab Show state of @value{GDBN} command scripts.
21482 @item @xref{set auto-load python-scripts}.
21483 @tab Control for @value{GDBN} Python scripts.
21484 @item @xref{show auto-load python-scripts}.
21485 @tab Show setting of @value{GDBN} Python scripts.
21486 @item @xref{info auto-load python-scripts}.
21487 @tab Show state of @value{GDBN} Python scripts.
21488 @item @xref{set auto-load scripts-directory}.
21489 @tab Control for @value{GDBN} auto-loaded scripts location.
21490 @item @xref{show auto-load scripts-directory}.
21491 @tab Show @value{GDBN} auto-loaded scripts location.
21492 @item @xref{set auto-load local-gdbinit}.
21493 @tab Control for init file in the current directory.
21494 @item @xref{show auto-load local-gdbinit}.
21495 @tab Show setting of init file in the current directory.
21496 @item @xref{info auto-load local-gdbinit}.
21497 @tab Show state of init file in the current directory.
21498 @item @xref{set auto-load libthread-db}.
21499 @tab Control for thread debugging library.
21500 @item @xref{show auto-load libthread-db}.
21501 @tab Show setting of thread debugging library.
21502 @item @xref{info auto-load libthread-db}.
21503 @tab Show state of thread debugging library.
21504 @item @xref{set auto-load safe-path}.
21505 @tab Control directories trusted for automatic loading.
21506 @item @xref{show auto-load safe-path}.
21507 @tab Show directories trusted for automatic loading.
21508 @item @xref{add-auto-load-safe-path}.
21509 @tab Add directory trusted for automatic loading.
21510 @end multitable
21511
21512 @menu
21513 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
21514 * libthread_db.so.1 file::             @samp{set/show/info auto-load libthread-db}
21515 * objfile-gdb.gdb file::               @samp{set/show/info auto-load gdb-script}
21516 * Auto-loading safe path::             @samp{set/show/info auto-load safe-path}
21517 * Auto-loading verbose mode::          @samp{set/show debug auto-load}
21518 @xref{Python Auto-loading}.
21519 @end menu
21520
21521 @node Init File in the Current Directory
21522 @subsection Automatically loading init file in the current directory
21523 @cindex auto-loading init file in the current directory
21524
21525 By default, @value{GDBN} reads and executes the canned sequences of commands
21526 from init file (if any) in the current working directory,
21527 see @ref{Init File in the Current Directory during Startup}.
21528
21529 Note that loading of this local @file{.gdbinit} file also requires accordingly
21530 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21531
21532 @table @code
21533 @anchor{set auto-load local-gdbinit}
21534 @kindex set auto-load local-gdbinit
21535 @item set auto-load local-gdbinit [on|off]
21536 Enable or disable the auto-loading of canned sequences of commands
21537 (@pxref{Sequences}) found in init file in the current directory.
21538
21539 @anchor{show auto-load local-gdbinit}
21540 @kindex show auto-load local-gdbinit
21541 @item show auto-load local-gdbinit
21542 Show whether auto-loading of canned sequences of commands from init file in the
21543 current directory is enabled or disabled.
21544
21545 @anchor{info auto-load local-gdbinit}
21546 @kindex info auto-load local-gdbinit
21547 @item info auto-load local-gdbinit
21548 Print whether canned sequences of commands from init file in the
21549 current directory have been auto-loaded.
21550 @end table
21551
21552 @node libthread_db.so.1 file
21553 @subsection Automatically loading thread debugging library
21554 @cindex auto-loading libthread_db.so.1
21555
21556 This feature is currently present only on @sc{gnu}/Linux native hosts.
21557
21558 @value{GDBN} reads in some cases thread debugging library from places specific
21559 to the inferior (@pxref{set libthread-db-search-path}).
21560
21561 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
21562 without checking this @samp{set auto-load libthread-db} switch as system
21563 libraries have to be trusted in general.  In all other cases of
21564 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
21565 auto-load libthread-db} is enabled before trying to open such thread debugging
21566 library.
21567
21568 Note that loading of this debugging library also requires accordingly configured
21569 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21570
21571 @table @code
21572 @anchor{set auto-load libthread-db}
21573 @kindex set auto-load libthread-db
21574 @item set auto-load libthread-db [on|off]
21575 Enable or disable the auto-loading of inferior specific thread debugging library.
21576
21577 @anchor{show auto-load libthread-db}
21578 @kindex show auto-load libthread-db
21579 @item show auto-load libthread-db
21580 Show whether auto-loading of inferior specific thread debugging library is
21581 enabled or disabled.
21582
21583 @anchor{info auto-load libthread-db}
21584 @kindex info auto-load libthread-db
21585 @item info auto-load libthread-db
21586 Print the list of all loaded inferior specific thread debugging libraries and
21587 for each such library print list of inferior @var{pid}s using it.
21588 @end table
21589
21590 @node objfile-gdb.gdb file
21591 @subsection The @file{@var{objfile}-gdb.gdb} file
21592 @cindex auto-loading @file{@var{objfile}-gdb.gdb}
21593
21594 @value{GDBN} tries to load an @file{@var{objfile}-gdb.gdb} file containing
21595 canned sequences of commands (@pxref{Sequences}), as long as @samp{set
21596 auto-load gdb-scripts} is set to @samp{on}.
21597
21598 Note that loading of this script file also requires accordingly configured
21599 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
21600
21601 For more background refer to the similar Python scripts auto-loading
21602 description (@pxref{objfile-gdb.py file}).
21603
21604 @table @code
21605 @anchor{set auto-load gdb-scripts}
21606 @kindex set auto-load gdb-scripts
21607 @item set auto-load gdb-scripts [on|off]
21608 Enable or disable the auto-loading of canned sequences of commands scripts.
21609
21610 @anchor{show auto-load gdb-scripts}
21611 @kindex show auto-load gdb-scripts
21612 @item show auto-load gdb-scripts
21613 Show whether auto-loading of canned sequences of commands scripts is enabled or
21614 disabled.
21615
21616 @anchor{info auto-load gdb-scripts}
21617 @kindex info auto-load gdb-scripts
21618 @cindex print list of auto-loaded canned sequences of commands scripts
21619 @item info auto-load gdb-scripts [@var{regexp}]
21620 Print the list of all canned sequences of commands scripts that @value{GDBN}
21621 auto-loaded.
21622 @end table
21623
21624 If @var{regexp} is supplied only canned sequences of commands scripts with
21625 matching names are printed.
21626
21627 @node Auto-loading safe path
21628 @subsection Security restriction for auto-loading
21629 @cindex auto-loading safe-path
21630
21631 As the files of inferior can come from untrusted source (such as submitted by
21632 an application user) @value{GDBN} does not always load any files automatically.
21633 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
21634 directories trusted for loading files not explicitly requested by user.
21635 Each directory can also be a shell wildcard pattern.
21636
21637 If the path is not set properly you will see a warning and the file will not
21638 get loaded:
21639
21640 @smallexample
21641 $ ./gdb -q ./gdb
21642 Reading symbols from /home/user/gdb/gdb...done.
21643 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
21644          declined by your `auto-load safe-path' set
21645          to "$debugdir:$datadir/auto-load".
21646 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
21647          declined by your `auto-load safe-path' set
21648          to "$debugdir:$datadir/auto-load".
21649 @end smallexample
21650
21651 The list of trusted directories is controlled by the following commands:
21652
21653 @table @code
21654 @anchor{set auto-load safe-path}
21655 @kindex set auto-load safe-path
21656 @item set auto-load safe-path @r{[}@var{directories}@r{]}
21657 Set the list of directories (and their subdirectories) trusted for automatic
21658 loading and execution of scripts.  You can also enter a specific trusted file.
21659 Each directory can also be a shell wildcard pattern; wildcards do not match
21660 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
21661 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
21662 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
21663 its default value as specified during @value{GDBN} compilation.
21664
21665 The list of directories uses path separator (@samp{:} on GNU and Unix
21666 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
21667 to the @env{PATH} environment variable.
21668
21669 @anchor{show auto-load safe-path}
21670 @kindex show auto-load safe-path
21671 @item show auto-load safe-path
21672 Show the list of directories trusted for automatic loading and execution of
21673 scripts.
21674
21675 @anchor{add-auto-load-safe-path}
21676 @kindex add-auto-load-safe-path
21677 @item add-auto-load-safe-path
21678 Add an entry (or list of entries) the list of directories trusted for automatic
21679 loading and execution of scripts.  Multiple entries may be delimited by the
21680 host platform path separator in use.
21681 @end table
21682
21683 This variable defaults to what @code{--with-auto-load-dir} has been configured
21684 to (@pxref{with-auto-load-dir}).  @file{$debugdir} and @file{$datadir}
21685 substitution applies the same as for @ref{set auto-load scripts-directory}.
21686 The default @code{set auto-load safe-path} value can be also overriden by
21687 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
21688
21689 Setting this variable to @file{/} disables this security protection,
21690 corresponding @value{GDBN} configuration option is
21691 @option{--without-auto-load-safe-path}.
21692 This variable is supposed to be set to the system directories writable by the
21693 system superuser only.  Users can add their source directories in init files in
21694 their home directories (@pxref{Home Directory Init File}).  See also deprecated
21695 init file in the current directory
21696 (@pxref{Init File in the Current Directory during Startup}).
21697
21698 To force @value{GDBN} to load the files it declined to load in the previous
21699 example, you could use one of the following ways:
21700
21701 @table @asis
21702 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
21703 Specify this trusted directory (or a file) as additional component of the list.
21704 You have to specify also any existing directories displayed by
21705 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
21706
21707 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
21708 Specify this directory as in the previous case but just for a single
21709 @value{GDBN} session.
21710
21711 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
21712 Disable auto-loading safety for a single @value{GDBN} session.
21713 This assumes all the files you debug during this @value{GDBN} session will come
21714 from trusted sources.
21715
21716 @item @kbd{./configure --without-auto-load-safe-path}
21717 During compilation of @value{GDBN} you may disable any auto-loading safety.
21718 This assumes all the files you will ever debug with this @value{GDBN} come from
21719 trusted sources.
21720 @end table
21721
21722 On the other hand you can also explicitly forbid automatic files loading which
21723 also suppresses any such warning messages:
21724
21725 @table @asis
21726 @item @kbd{gdb -iex "set auto-load no" @dots{}}
21727 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
21728
21729 @item @file{~/.gdbinit}: @samp{set auto-load no}
21730 Disable auto-loading globally for the user
21731 (@pxref{Home Directory Init File}).  While it is improbable, you could also
21732 use system init file instead (@pxref{System-wide configuration}).
21733 @end table
21734
21735 This setting applies to the file names as entered by user.  If no entry matches
21736 @value{GDBN} tries as a last resort to also resolve all the file names into
21737 their canonical form (typically resolving symbolic links) and compare the
21738 entries again.  @value{GDBN} already canonicalizes most of the filenames on its
21739 own before starting the comparison so a canonical form of directories is
21740 recommended to be entered.
21741
21742 @node Auto-loading verbose mode
21743 @subsection Displaying files tried for auto-load
21744 @cindex auto-loading verbose mode
21745
21746 For better visibility of all the file locations where you can place scripts to
21747 be auto-loaded with inferior --- or to protect yourself against accidental
21748 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
21749 all the files attempted to be loaded.  Both existing and non-existing files may
21750 be printed.
21751
21752 For example the list of directories from which it is safe to auto-load files
21753 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
21754 may not be too obvious while setting it up.
21755
21756 @smallexample
21757 (gdb) set debug auto-load on
21758 (gdb) file ~/src/t/true
21759 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
21760            for objfile "/tmp/true".
21761 auto-load: Updating directories of "/usr:/opt".
21762 auto-load: Using directory "/usr".
21763 auto-load: Using directory "/opt".
21764 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
21765          by your `auto-load safe-path' set to "/usr:/opt".
21766 @end smallexample
21767
21768 @table @code
21769 @anchor{set debug auto-load}
21770 @kindex set debug auto-load
21771 @item set debug auto-load [on|off]
21772 Set whether to print the filenames attempted to be auto-loaded.
21773
21774 @anchor{show debug auto-load}
21775 @kindex show debug auto-load
21776 @item show debug auto-load
21777 Show whether printing of the filenames attempted to be auto-loaded is turned
21778 on or off.
21779 @end table
21780
21781 @node Messages/Warnings
21782 @section Optional Warnings and Messages
21783
21784 @cindex verbose operation
21785 @cindex optional warnings
21786 By default, @value{GDBN} is silent about its inner workings.  If you are
21787 running on a slow machine, you may want to use the @code{set verbose}
21788 command.  This makes @value{GDBN} tell you when it does a lengthy
21789 internal operation, so you will not think it has crashed.
21790
21791 Currently, the messages controlled by @code{set verbose} are those
21792 which announce that the symbol table for a source file is being read;
21793 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
21794
21795 @table @code
21796 @kindex set verbose
21797 @item set verbose on
21798 Enables @value{GDBN} output of certain informational messages.
21799
21800 @item set verbose off
21801 Disables @value{GDBN} output of certain informational messages.
21802
21803 @kindex show verbose
21804 @item show verbose
21805 Displays whether @code{set verbose} is on or off.
21806 @end table
21807
21808 By default, if @value{GDBN} encounters bugs in the symbol table of an
21809 object file, it is silent; but if you are debugging a compiler, you may
21810 find this information useful (@pxref{Symbol Errors, ,Errors Reading
21811 Symbol Files}).
21812
21813 @table @code
21814
21815 @kindex set complaints
21816 @item set complaints @var{limit}
21817 Permits @value{GDBN} to output @var{limit} complaints about each type of
21818 unusual symbols before becoming silent about the problem.  Set
21819 @var{limit} to zero to suppress all complaints; set it to a large number
21820 to prevent complaints from being suppressed.
21821
21822 @kindex show complaints
21823 @item show complaints
21824 Displays how many symbol complaints @value{GDBN} is permitted to produce.
21825
21826 @end table
21827
21828 @anchor{confirmation requests}
21829 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
21830 lot of stupid questions to confirm certain commands.  For example, if
21831 you try to run a program which is already running:
21832
21833 @smallexample
21834 (@value{GDBP}) run
21835 The program being debugged has been started already.
21836 Start it from the beginning? (y or n)
21837 @end smallexample
21838
21839 If you are willing to unflinchingly face the consequences of your own
21840 commands, you can disable this ``feature'':
21841
21842 @table @code
21843
21844 @kindex set confirm
21845 @cindex flinching
21846 @cindex confirmation
21847 @cindex stupid questions
21848 @item set confirm off
21849 Disables confirmation requests.  Note that running @value{GDBN} with
21850 the @option{--batch} option (@pxref{Mode Options, -batch}) also
21851 automatically disables confirmation requests.
21852
21853 @item set confirm on
21854 Enables confirmation requests (the default).
21855
21856 @kindex show confirm
21857 @item show confirm
21858 Displays state of confirmation requests.
21859
21860 @end table
21861
21862 @cindex command tracing
21863 If you need to debug user-defined commands or sourced files you may find it
21864 useful to enable @dfn{command tracing}.  In this mode each command will be
21865 printed as it is executed, prefixed with one or more @samp{+} symbols, the
21866 quantity denoting the call depth of each command.
21867
21868 @table @code
21869 @kindex set trace-commands
21870 @cindex command scripts, debugging
21871 @item set trace-commands on
21872 Enable command tracing.
21873 @item set trace-commands off
21874 Disable command tracing.
21875 @item show trace-commands
21876 Display the current state of command tracing.
21877 @end table
21878
21879 @node Debugging Output
21880 @section Optional Messages about Internal Happenings
21881 @cindex optional debugging messages
21882
21883 @value{GDBN} has commands that enable optional debugging messages from
21884 various @value{GDBN} subsystems; normally these commands are of
21885 interest to @value{GDBN} maintainers, or when reporting a bug.  This
21886 section documents those commands.
21887
21888 @table @code
21889 @kindex set exec-done-display
21890 @item set exec-done-display
21891 Turns on or off the notification of asynchronous commands'
21892 completion.  When on, @value{GDBN} will print a message when an
21893 asynchronous command finishes its execution.  The default is off.
21894 @kindex show exec-done-display
21895 @item show exec-done-display
21896 Displays the current setting of asynchronous command completion
21897 notification.
21898 @kindex set debug
21899 @cindex gdbarch debugging info
21900 @cindex architecture debugging info
21901 @item set debug arch
21902 Turns on or off display of gdbarch debugging info.  The default is off
21903 @kindex show debug
21904 @item show debug arch
21905 Displays the current state of displaying gdbarch debugging info.
21906 @item set debug aix-thread
21907 @cindex AIX threads
21908 Display debugging messages about inner workings of the AIX thread
21909 module.
21910 @item show debug aix-thread
21911 Show the current state of AIX thread debugging info display.
21912 @item set debug check-physname
21913 @cindex physname
21914 Check the results of the ``physname'' computation.  When reading DWARF
21915 debugging information for C@t{++}, @value{GDBN} attempts to compute
21916 each entity's name.  @value{GDBN} can do this computation in two
21917 different ways, depending on exactly what information is present.
21918 When enabled, this setting causes @value{GDBN} to compute the names
21919 both ways and display any discrepancies.
21920 @item show debug check-physname
21921 Show the current state of ``physname'' checking.
21922 @item set debug dwarf2-die
21923 @cindex DWARF2 DIEs
21924 Dump DWARF2 DIEs after they are read in.
21925 The value is the number of nesting levels to print.
21926 A value of zero turns off the display.
21927 @item show debug dwarf2-die
21928 Show the current state of DWARF2 DIE debugging.
21929 @item set debug dwarf2-read
21930 @cindex DWARF2 Reading
21931 Turns on or off display of debugging messages related to reading
21932 DWARF debug info.  The default is off.
21933 @item show debug dwarf2-read
21934 Show the current state of DWARF2 reader debugging.
21935 @item set debug displaced
21936 @cindex displaced stepping debugging info
21937 Turns on or off display of @value{GDBN} debugging info for the
21938 displaced stepping support.  The default is off.
21939 @item show debug displaced
21940 Displays the current state of displaying @value{GDBN} debugging info
21941 related to displaced stepping.
21942 @item set debug event
21943 @cindex event debugging info
21944 Turns on or off display of @value{GDBN} event debugging info.  The
21945 default is off.
21946 @item show debug event
21947 Displays the current state of displaying @value{GDBN} event debugging
21948 info.
21949 @item set debug expression
21950 @cindex expression debugging info
21951 Turns on or off display of debugging info about @value{GDBN}
21952 expression parsing.  The default is off.
21953 @item show debug expression
21954 Displays the current state of displaying debugging info about
21955 @value{GDBN} expression parsing.
21956 @item set debug frame
21957 @cindex frame debugging info
21958 Turns on or off display of @value{GDBN} frame debugging info.  The
21959 default is off.
21960 @item show debug frame
21961 Displays the current state of displaying @value{GDBN} frame debugging
21962 info.
21963 @item set debug gnu-nat
21964 @cindex @sc{gnu}/Hurd debug messages
21965 Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
21966 @item show debug gnu-nat
21967 Show the current state of @sc{gnu}/Hurd debugging messages.
21968 @item set debug infrun
21969 @cindex inferior debugging info
21970 Turns on or off display of @value{GDBN} debugging info for running the inferior.
21971 The default is off.  @file{infrun.c} contains GDB's runtime state machine used 
21972 for implementing operations such as single-stepping the inferior.
21973 @item show debug infrun
21974 Displays the current state of @value{GDBN} inferior debugging.
21975 @item set debug jit
21976 @cindex just-in-time compilation, debugging messages
21977 Turns on or off debugging messages from JIT debug support.
21978 @item show debug jit
21979 Displays the current state of @value{GDBN} JIT debugging.
21980 @item set debug lin-lwp
21981 @cindex @sc{gnu}/Linux LWP debug messages
21982 @cindex Linux lightweight processes
21983 Turns on or off debugging messages from the Linux LWP debug support.
21984 @item show debug lin-lwp
21985 Show the current state of Linux LWP debugging messages.
21986 @item set debug notification
21987 @cindex remote async notification debugging info
21988 Turns on or off debugging messages about remote async notification.
21989 The default is off.
21990 @item show debug notification
21991 Displays the current state of remote async notification debugging messages.
21992 @item set debug observer
21993 @cindex observer debugging info
21994 Turns on or off display of @value{GDBN} observer debugging.  This
21995 includes info such as the notification of observable events.
21996 @item show debug observer
21997 Displays the current state of observer debugging.
21998 @item set debug overload
21999 @cindex C@t{++} overload debugging info
22000 Turns on or off display of @value{GDBN} C@t{++} overload debugging
22001 info. This includes info such as ranking of functions, etc.  The default
22002 is off.
22003 @item show debug overload
22004 Displays the current state of displaying @value{GDBN} C@t{++} overload
22005 debugging info.
22006 @cindex expression parser, debugging info
22007 @cindex debug expression parser
22008 @item set debug parser
22009 Turns on or off the display of expression parser debugging output.
22010 Internally, this sets the @code{yydebug} variable in the expression
22011 parser.  @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
22012 details.  The default is off.
22013 @item show debug parser
22014 Show the current state of expression parser debugging.
22015 @cindex packets, reporting on stdout
22016 @cindex serial connections, debugging
22017 @cindex debug remote protocol
22018 @cindex remote protocol debugging
22019 @cindex display remote packets
22020 @item set debug remote
22021 Turns on or off display of reports on all packets sent back and forth across
22022 the serial line to the remote machine.  The info is printed on the
22023 @value{GDBN} standard output stream. The default is off.
22024 @item show debug remote
22025 Displays the state of display of remote packets.
22026 @item set debug serial
22027 Turns on or off display of @value{GDBN} serial debugging info. The
22028 default is off.
22029 @item show debug serial
22030 Displays the current state of displaying @value{GDBN} serial debugging
22031 info.
22032 @item set debug solib-frv
22033 @cindex FR-V shared-library debugging
22034 Turns on or off debugging messages for FR-V shared-library code.
22035 @item show debug solib-frv
22036 Display the current state of FR-V shared-library code debugging
22037 messages.
22038 @item set debug symtab-create
22039 @cindex symbol table creation
22040 Turns on or off display of debugging messages related to symbol table creation.
22041 The default is off.
22042 @item show debug symtab-create
22043 Show the current state of symbol table creation debugging.
22044 @item set debug target
22045 @cindex target debugging info
22046 Turns on or off display of @value{GDBN} target debugging info. This info
22047 includes what is going on at the target level of GDB, as it happens. The
22048 default is 0.  Set it to 1 to track events, and to 2 to also track the
22049 value of large memory transfers.  Changes to this flag do not take effect
22050 until the next time you connect to a target or use the @code{run} command.
22051 @item show debug target
22052 Displays the current state of displaying @value{GDBN} target debugging
22053 info.
22054 @item set debug timestamp
22055 @cindex timestampping debugging info
22056 Turns on or off display of timestamps with @value{GDBN} debugging info.
22057 When enabled, seconds and microseconds are displayed before each debugging
22058 message.
22059 @item show debug timestamp
22060 Displays the current state of displaying timestamps with @value{GDBN}
22061 debugging info.
22062 @item set debugvarobj
22063 @cindex variable object debugging info
22064 Turns on or off display of @value{GDBN} variable object debugging
22065 info. The default is off.
22066 @item show debugvarobj
22067 Displays the current state of displaying @value{GDBN} variable object
22068 debugging info.
22069 @item set debug xml
22070 @cindex XML parser debugging
22071 Turns on or off debugging messages for built-in XML parsers.
22072 @item show debug xml
22073 Displays the current state of XML debugging messages.
22074 @end table
22075
22076 @node Other Misc Settings
22077 @section Other Miscellaneous Settings
22078 @cindex miscellaneous settings
22079
22080 @table @code
22081 @kindex set interactive-mode
22082 @item set interactive-mode
22083 If @code{on}, forces @value{GDBN} to assume that GDB was started
22084 in a terminal.  In practice, this means that @value{GDBN} should wait
22085 for the user to answer queries generated by commands entered at
22086 the command prompt.  If @code{off}, forces @value{GDBN} to operate
22087 in the opposite mode, and it uses the default answers to all queries.
22088 If @code{auto} (the default), @value{GDBN} tries to determine whether
22089 its standard input is a terminal, and works in interactive-mode if it
22090 is, non-interactively otherwise.
22091
22092 In the vast majority of cases, the debugger should be able to guess
22093 correctly which mode should be used.  But this setting can be useful
22094 in certain specific cases, such as running a MinGW @value{GDBN}
22095 inside a cygwin window.
22096
22097 @kindex show interactive-mode
22098 @item show interactive-mode
22099 Displays whether the debugger is operating in interactive mode or not.
22100 @end table
22101
22102 @node Extending GDB
22103 @chapter Extending @value{GDBN}
22104 @cindex extending GDB
22105
22106 @value{GDBN} provides three mechanisms for extension.  The first is based
22107 on composition of @value{GDBN} commands, the second is based on the
22108 Python scripting language, and the third is for defining new aliases of
22109 existing commands.
22110
22111 To facilitate the use of the first two extensions, @value{GDBN} is capable
22112 of evaluating the contents of a file.  When doing so, @value{GDBN}
22113 can recognize which scripting language is being used by looking at
22114 the filename extension.  Files with an unrecognized filename extension
22115 are always treated as a @value{GDBN} Command Files.
22116 @xref{Command Files,, Command files}.
22117
22118 You can control how @value{GDBN} evaluates these files with the following
22119 setting:
22120
22121 @table @code
22122 @kindex set script-extension
22123 @kindex show script-extension
22124 @item set script-extension off
22125 All scripts are always evaluated as @value{GDBN} Command Files.
22126
22127 @item set script-extension soft
22128 The debugger determines the scripting language based on filename
22129 extension.  If this scripting language is supported, @value{GDBN}
22130 evaluates the script using that language.  Otherwise, it evaluates
22131 the file as a @value{GDBN} Command File.
22132
22133 @item set script-extension strict
22134 The debugger determines the scripting language based on filename
22135 extension, and evaluates the script using that language.  If the
22136 language is not supported, then the evaluation fails.
22137
22138 @item show script-extension
22139 Display the current value of the @code{script-extension} option.
22140
22141 @end table
22142
22143 @menu
22144 * Sequences::          Canned Sequences of Commands
22145 * Python::             Scripting @value{GDBN} using Python
22146 * Aliases::            Creating new spellings of existing commands
22147 @end menu
22148
22149 @node Sequences
22150 @section Canned Sequences of Commands
22151
22152 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
22153 Command Lists}), @value{GDBN} provides two ways to store sequences of
22154 commands for execution as a unit: user-defined commands and command
22155 files.
22156
22157 @menu
22158 * Define::             How to define your own commands
22159 * Hooks::              Hooks for user-defined commands
22160 * Command Files::      How to write scripts of commands to be stored in a file
22161 * Output::             Commands for controlled output
22162 @end menu
22163
22164 @node Define
22165 @subsection User-defined Commands
22166
22167 @cindex user-defined command
22168 @cindex arguments, to user-defined commands
22169 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
22170 which you assign a new name as a command.  This is done with the
22171 @code{define} command.  User commands may accept up to 10 arguments
22172 separated by whitespace.  Arguments are accessed within the user command
22173 via @code{$arg0@dots{}$arg9}.  A trivial example:
22174
22175 @smallexample
22176 define adder
22177   print $arg0 + $arg1 + $arg2
22178 end
22179 @end smallexample
22180
22181 @noindent
22182 To execute the command use:
22183
22184 @smallexample
22185 adder 1 2 3
22186 @end smallexample
22187
22188 @noindent
22189 This defines the command @code{adder}, which prints the sum of
22190 its three arguments.  Note the arguments are text substitutions, so they may
22191 reference variables, use complex expressions, or even perform inferior
22192 functions calls.
22193
22194 @cindex argument count in user-defined commands
22195 @cindex how many arguments (user-defined commands)
22196 In addition, @code{$argc} may be used to find out how many arguments have
22197 been passed.  This expands to a number in the range 0@dots{}10.
22198
22199 @smallexample
22200 define adder
22201   if $argc == 2
22202     print $arg0 + $arg1
22203   end
22204   if $argc == 3
22205     print $arg0 + $arg1 + $arg2
22206   end
22207 end
22208 @end smallexample
22209
22210 @table @code
22211
22212 @kindex define
22213 @item define @var{commandname}
22214 Define a command named @var{commandname}.  If there is already a command
22215 by that name, you are asked to confirm that you want to redefine it.
22216 @var{commandname} may be a bare command name consisting of letters,
22217 numbers, dashes, and underscores.  It may also start with any predefined
22218 prefix command.  For example, @samp{define target my-target} creates
22219 a user-defined @samp{target my-target} command.
22220
22221 The definition of the command is made up of other @value{GDBN} command lines,
22222 which are given following the @code{define} command.  The end of these
22223 commands is marked by a line containing @code{end}.
22224
22225 @kindex document
22226 @kindex end@r{ (user-defined commands)}
22227 @item document @var{commandname}
22228 Document the user-defined command @var{commandname}, so that it can be
22229 accessed by @code{help}.  The command @var{commandname} must already be
22230 defined.  This command reads lines of documentation just as @code{define}
22231 reads the lines of the command definition, ending with @code{end}.
22232 After the @code{document} command is finished, @code{help} on command
22233 @var{commandname} displays the documentation you have written.
22234
22235 You may use the @code{document} command again to change the
22236 documentation of a command.  Redefining the command with @code{define}
22237 does not change the documentation.
22238
22239 @kindex dont-repeat
22240 @cindex don't repeat command
22241 @item dont-repeat
22242 Used inside a user-defined command, this tells @value{GDBN} that this
22243 command should not be repeated when the user hits @key{RET}
22244 (@pxref{Command Syntax, repeat last command}).
22245
22246 @kindex help user-defined
22247 @item help user-defined
22248 List all user-defined commands and all python commands defined in class
22249 COMAND_USER.  The first line of the documentation or docstring is
22250 included (if any).
22251
22252 @kindex show user
22253 @item show user
22254 @itemx show user @var{commandname}
22255 Display the @value{GDBN} commands used to define @var{commandname} (but
22256 not its documentation).  If no @var{commandname} is given, display the
22257 definitions for all user-defined commands.
22258 This does not work for user-defined python commands.
22259
22260 @cindex infinite recursion in user-defined commands
22261 @kindex show max-user-call-depth
22262 @kindex set max-user-call-depth
22263 @item show max-user-call-depth
22264 @itemx set max-user-call-depth
22265 The value of @code{max-user-call-depth} controls how many recursion
22266 levels are allowed in user-defined commands before @value{GDBN} suspects an
22267 infinite recursion and aborts the command.
22268 This does not apply to user-defined python commands.
22269 @end table
22270
22271 In addition to the above commands, user-defined commands frequently
22272 use control flow commands, described in @ref{Command Files}.
22273
22274 When user-defined commands are executed, the
22275 commands of the definition are not printed.  An error in any command
22276 stops execution of the user-defined command.
22277
22278 If used interactively, commands that would ask for confirmation proceed
22279 without asking when used inside a user-defined command.  Many @value{GDBN}
22280 commands that normally print messages to say what they are doing omit the
22281 messages when used in a user-defined command.
22282
22283 @node Hooks
22284 @subsection User-defined Command Hooks
22285 @cindex command hooks
22286 @cindex hooks, for commands
22287 @cindex hooks, pre-command
22288
22289 @kindex hook
22290 You may define @dfn{hooks}, which are a special kind of user-defined
22291 command.  Whenever you run the command @samp{foo}, if the user-defined
22292 command @samp{hook-foo} exists, it is executed (with no arguments)
22293 before that command.
22294
22295 @cindex hooks, post-command
22296 @kindex hookpost
22297 A hook may also be defined which is run after the command you executed.
22298 Whenever you run the command @samp{foo}, if the user-defined command
22299 @samp{hookpost-foo} exists, it is executed (with no arguments) after
22300 that command.  Post-execution hooks may exist simultaneously with
22301 pre-execution hooks, for the same command.
22302
22303 It is valid for a hook to call the command which it hooks.  If this
22304 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
22305
22306 @c It would be nice if hookpost could be passed a parameter indicating
22307 @c if the command it hooks executed properly or not.  FIXME!
22308
22309 @kindex stop@r{, a pseudo-command}
22310 In addition, a pseudo-command, @samp{stop} exists.  Defining
22311 (@samp{hook-stop}) makes the associated commands execute every time
22312 execution stops in your program: before breakpoint commands are run,
22313 displays are printed, or the stack frame is printed.
22314
22315 For example, to ignore @code{SIGALRM} signals while
22316 single-stepping, but treat them normally during normal execution,
22317 you could define:
22318
22319 @smallexample
22320 define hook-stop
22321 handle SIGALRM nopass
22322 end
22323
22324 define hook-run
22325 handle SIGALRM pass
22326 end
22327
22328 define hook-continue
22329 handle SIGALRM pass
22330 end
22331 @end smallexample
22332
22333 As a further example, to hook at the beginning and end of the @code{echo}
22334 command, and to add extra text to the beginning and end of the message,
22335 you could define:
22336
22337 @smallexample
22338 define hook-echo
22339 echo <<<---
22340 end
22341
22342 define hookpost-echo
22343 echo --->>>\n
22344 end
22345
22346 (@value{GDBP}) echo Hello World
22347 <<<---Hello World--->>>
22348 (@value{GDBP})
22349
22350 @end smallexample
22351
22352 You can define a hook for any single-word command in @value{GDBN}, but
22353 not for command aliases; you should define a hook for the basic command
22354 name, e.g.@:  @code{backtrace} rather than @code{bt}.
22355 @c FIXME!  So how does Joe User discover whether a command is an alias
22356 @c or not?
22357 You can hook a multi-word command by adding @code{hook-} or
22358 @code{hookpost-} to the last word of the command, e.g.@:
22359 @samp{define target hook-remote} to add a hook to @samp{target remote}.
22360
22361 If an error occurs during the execution of your hook, execution of
22362 @value{GDBN} commands stops and @value{GDBN} issues a prompt
22363 (before the command that you actually typed had a chance to run).
22364
22365 If you try to define a hook which does not match any known command, you
22366 get a warning from the @code{define} command.
22367
22368 @node Command Files
22369 @subsection Command Files
22370
22371 @cindex command files
22372 @cindex scripting commands
22373 A command file for @value{GDBN} is a text file made of lines that are
22374 @value{GDBN} commands.  Comments (lines starting with @kbd{#}) may
22375 also be included.  An empty line in a command file does nothing; it
22376 does not mean to repeat the last command, as it would from the
22377 terminal.
22378
22379 You can request the execution of a command file with the @code{source}
22380 command.  Note that the @code{source} command is also used to evaluate
22381 scripts that are not Command Files.  The exact behavior can be configured
22382 using the @code{script-extension} setting.
22383 @xref{Extending GDB,, Extending GDB}.
22384
22385 @table @code
22386 @kindex source
22387 @cindex execute commands from a file
22388 @item source [-s] [-v] @var{filename}
22389 Execute the command file @var{filename}.
22390 @end table
22391
22392 The lines in a command file are generally executed sequentially,
22393 unless the order of execution is changed by one of the
22394 @emph{flow-control commands} described below.  The commands are not
22395 printed as they are executed.  An error in any command terminates
22396 execution of the command file and control is returned to the console.
22397
22398 @value{GDBN} first searches for @var{filename} in the current directory.
22399 If the file is not found there, and @var{filename} does not specify a
22400 directory, then @value{GDBN} also looks for the file on the source search path
22401 (specified with the @samp{directory} command);
22402 except that @file{$cdir} is not searched because the compilation directory
22403 is not relevant to scripts.
22404
22405 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
22406 on the search path even if @var{filename} specifies a directory.
22407 The search is done by appending @var{filename} to each element of the
22408 search path.  So, for example, if @var{filename} is @file{mylib/myscript}
22409 and the search path contains @file{/home/user} then @value{GDBN} will
22410 look for the script @file{/home/user/mylib/myscript}.
22411 The search is also done if @var{filename} is an absolute path.
22412 For example, if @var{filename} is @file{/tmp/myscript} and
22413 the search path contains @file{/home/user} then @value{GDBN} will
22414 look for the script @file{/home/user/tmp/myscript}.
22415 For DOS-like systems, if @var{filename} contains a drive specification,
22416 it is stripped before concatenation.  For example, if @var{filename} is
22417 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
22418 will look for the script @file{c:/tmp/myscript}.
22419
22420 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
22421 each command as it is executed.  The option must be given before
22422 @var{filename}, and is interpreted as part of the filename anywhere else.
22423
22424 Commands that would ask for confirmation if used interactively proceed
22425 without asking when used in a command file.  Many @value{GDBN} commands that
22426 normally print messages to say what they are doing omit the messages
22427 when called from command files.
22428
22429 @value{GDBN} also accepts command input from standard input.  In this
22430 mode, normal output goes to standard output and error output goes to
22431 standard error.  Errors in a command file supplied on standard input do
22432 not terminate execution of the command file---execution continues with
22433 the next command.
22434
22435 @smallexample
22436 gdb < cmds > log 2>&1
22437 @end smallexample
22438
22439 (The syntax above will vary depending on the shell used.) This example
22440 will execute commands from the file @file{cmds}. All output and errors
22441 would be directed to @file{log}.
22442
22443 Since commands stored on command files tend to be more general than
22444 commands typed interactively, they frequently need to deal with
22445 complicated situations, such as different or unexpected values of
22446 variables and symbols, changes in how the program being debugged is
22447 built, etc.  @value{GDBN} provides a set of flow-control commands to
22448 deal with these complexities.  Using these commands, you can write
22449 complex scripts that loop over data structures, execute commands
22450 conditionally, etc.
22451
22452 @table @code
22453 @kindex if
22454 @kindex else
22455 @item if
22456 @itemx else
22457 This command allows to include in your script conditionally executed
22458 commands. The @code{if} command takes a single argument, which is an
22459 expression to evaluate.  It is followed by a series of commands that
22460 are executed only if the expression is true (its value is nonzero).
22461 There can then optionally be an @code{else} line, followed by a series
22462 of commands that are only executed if the expression was false.  The
22463 end of the list is marked by a line containing @code{end}.
22464
22465 @kindex while
22466 @item while
22467 This command allows to write loops.  Its syntax is similar to
22468 @code{if}: the command takes a single argument, which is an expression
22469 to evaluate, and must be followed by the commands to execute, one per
22470 line, terminated by an @code{end}.  These commands are called the
22471 @dfn{body} of the loop.  The commands in the body of @code{while} are
22472 executed repeatedly as long as the expression evaluates to true.
22473
22474 @kindex loop_break
22475 @item loop_break
22476 This command exits the @code{while} loop in whose body it is included.
22477 Execution of the script continues after that @code{while}s @code{end}
22478 line.
22479
22480 @kindex loop_continue
22481 @item loop_continue
22482 This command skips the execution of the rest of the body of commands
22483 in the @code{while} loop in whose body it is included.  Execution
22484 branches to the beginning of the @code{while} loop, where it evaluates
22485 the controlling expression.
22486
22487 @kindex end@r{ (if/else/while commands)}
22488 @item end
22489 Terminate the block of commands that are the body of @code{if},
22490 @code{else}, or @code{while} flow-control commands.
22491 @end table
22492
22493
22494 @node Output
22495 @subsection Commands for Controlled Output
22496
22497 During the execution of a command file or a user-defined command, normal
22498 @value{GDBN} output is suppressed; the only output that appears is what is
22499 explicitly printed by the commands in the definition.  This section
22500 describes three commands useful for generating exactly the output you
22501 want.
22502
22503 @table @code
22504 @kindex echo
22505 @item echo @var{text}
22506 @c I do not consider backslash-space a standard C escape sequence
22507 @c because it is not in ANSI.
22508 Print @var{text}.  Nonprinting characters can be included in
22509 @var{text} using C escape sequences, such as @samp{\n} to print a
22510 newline.  @strong{No newline is printed unless you specify one.}
22511 In addition to the standard C escape sequences, a backslash followed
22512 by a space stands for a space.  This is useful for displaying a
22513 string with spaces at the beginning or the end, since leading and
22514 trailing spaces are otherwise trimmed from all arguments.
22515 To print @samp{@w{ }and foo =@w{ }}, use the command
22516 @samp{echo \@w{ }and foo = \@w{ }}.
22517
22518 A backslash at the end of @var{text} can be used, as in C, to continue
22519 the command onto subsequent lines.  For example,
22520
22521 @smallexample
22522 echo This is some text\n\
22523 which is continued\n\
22524 onto several lines.\n
22525 @end smallexample
22526
22527 produces the same output as
22528
22529 @smallexample
22530 echo This is some text\n
22531 echo which is continued\n
22532 echo onto several lines.\n
22533 @end smallexample
22534
22535 @kindex output
22536 @item output @var{expression}
22537 Print the value of @var{expression} and nothing but that value: no
22538 newlines, no @samp{$@var{nn} = }.  The value is not entered in the
22539 value history either.  @xref{Expressions, ,Expressions}, for more information
22540 on expressions.
22541
22542 @item output/@var{fmt} @var{expression}
22543 Print the value of @var{expression} in format @var{fmt}.  You can use
22544 the same formats as for @code{print}.  @xref{Output Formats,,Output
22545 Formats}, for more information.
22546
22547 @kindex printf
22548 @item printf @var{template}, @var{expressions}@dots{}
22549 Print the values of one or more @var{expressions} under the control of
22550 the string @var{template}.  To print several values, make
22551 @var{expressions} be a comma-separated list of individual expressions,
22552 which may be either numbers or pointers.  Their values are printed as
22553 specified by @var{template}, exactly as a C program would do by
22554 executing the code below:
22555
22556 @smallexample
22557 printf (@var{template}, @var{expressions}@dots{});
22558 @end smallexample
22559
22560 As in @code{C} @code{printf}, ordinary characters in @var{template}
22561 are printed verbatim, while @dfn{conversion specification} introduced
22562 by the @samp{%} character cause subsequent @var{expressions} to be
22563 evaluated, their values converted and formatted according to type and
22564 style information encoded in the conversion specifications, and then
22565 printed.
22566
22567 For example, you can print two values in hex like this:
22568
22569 @smallexample
22570 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
22571 @end smallexample
22572
22573 @code{printf} supports all the standard @code{C} conversion
22574 specifications, including the flags and modifiers between the @samp{%}
22575 character and the conversion letter, with the following exceptions:
22576
22577 @itemize @bullet
22578 @item
22579 The argument-ordering modifiers, such as @samp{2$}, are not supported.
22580
22581 @item
22582 The modifier @samp{*} is not supported for specifying precision or
22583 width.
22584
22585 @item
22586 The @samp{'} flag (for separation of digits into groups according to
22587 @code{LC_NUMERIC'}) is not supported.
22588
22589 @item
22590 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
22591 supported.
22592
22593 @item
22594 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
22595
22596 @item
22597 The conversion letters @samp{a} and @samp{A} are not supported.
22598 @end itemize
22599
22600 @noindent
22601 Note that the @samp{ll} type modifier is supported only if the
22602 underlying @code{C} implementation used to build @value{GDBN} supports
22603 the @code{long long int} type, and the @samp{L} type modifier is
22604 supported only if @code{long double} type is available.
22605
22606 As in @code{C}, @code{printf} supports simple backslash-escape
22607 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
22608 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
22609 single character.  Octal and hexadecimal escape sequences are not
22610 supported.
22611
22612 Additionally, @code{printf} supports conversion specifications for DFP
22613 (@dfn{Decimal Floating Point}) types using the following length modifiers
22614 together with a floating point specifier.
22615 letters:
22616
22617 @itemize @bullet
22618 @item
22619 @samp{H} for printing @code{Decimal32} types.
22620
22621 @item
22622 @samp{D} for printing @code{Decimal64} types.
22623
22624 @item
22625 @samp{DD} for printing @code{Decimal128} types.
22626 @end itemize
22627
22628 If the underlying @code{C} implementation used to build @value{GDBN} has
22629 support for the three length modifiers for DFP types, other modifiers
22630 such as width and precision will also be available for @value{GDBN} to use.
22631
22632 In case there is no such @code{C} support, no additional modifiers will be
22633 available and the value will be printed in the standard way.
22634
22635 Here's an example of printing DFP types using the above conversion letters:
22636 @smallexample
22637 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
22638 @end smallexample
22639
22640 @kindex eval
22641 @item eval @var{template}, @var{expressions}@dots{}
22642 Convert the values of one or more @var{expressions} under the control of
22643 the string @var{template} to a command line, and call it.
22644
22645 @end table
22646
22647 @node Python
22648 @section Scripting @value{GDBN} using Python
22649 @cindex python scripting
22650 @cindex scripting with python
22651
22652 You can script @value{GDBN} using the @uref{http://www.python.org/,
22653 Python programming language}.  This feature is available only if
22654 @value{GDBN} was configured using @option{--with-python}.
22655
22656 @cindex python directory
22657 Python scripts used by @value{GDBN} should be installed in
22658 @file{@var{data-directory}/python}, where @var{data-directory} is
22659 the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
22660 This directory, known as the @dfn{python directory},
22661 is automatically added to the Python Search Path in order to allow
22662 the Python interpreter to locate all scripts installed at this location.
22663
22664 Additionally, @value{GDBN} commands and convenience functions which
22665 are written in Python and are located in the
22666 @file{@var{data-directory}/python/gdb/command} or
22667 @file{@var{data-directory}/python/gdb/function} directories are
22668 automatically imported when @value{GDBN} starts.
22669
22670 @menu
22671 * Python Commands::             Accessing Python from @value{GDBN}.
22672 * Python API::                  Accessing @value{GDBN} from Python.
22673 * Python Auto-loading::         Automatically loading Python code.
22674 * Python modules::              Python modules provided by @value{GDBN}.
22675 @end menu
22676
22677 @node Python Commands
22678 @subsection Python Commands
22679 @cindex python commands
22680 @cindex commands to access python
22681
22682 @value{GDBN} provides two commands for accessing the Python interpreter,
22683 and one related setting:
22684
22685 @table @code
22686 @kindex python-interactive
22687 @kindex pi
22688 @item python-interactive @r{[}@var{command}@r{]}
22689 @itemx pi @r{[}@var{command}@r{]}
22690 Without an argument, the @code{python-interactive} command can be used
22691 to start an interactive Python prompt.  To return to @value{GDBN},
22692 type the @code{EOF} character (e.g., @kbd{Ctrl-D} on an empty prompt).
22693
22694 Alternatively, a single-line Python command can be given as an
22695 argument and evaluated.  If the command is an expression, the result
22696 will be printed; otherwise, nothing will be printed.  For example:
22697
22698 @smallexample
22699 (@value{GDBP}) python-interactive 2 + 3
22700 5
22701 @end smallexample
22702
22703 @kindex python
22704 @kindex py
22705 @item python @r{[}@var{command}@r{]}
22706 @itemx py @r{[}@var{command}@r{]}
22707 The @code{python} command can be used to evaluate Python code.
22708
22709 If given an argument, the @code{python} command will evaluate the
22710 argument as a Python command.  For example:
22711
22712 @smallexample
22713 (@value{GDBP}) python print 23
22714 23
22715 @end smallexample
22716
22717 If you do not provide an argument to @code{python}, it will act as a
22718 multi-line command, like @code{define}.  In this case, the Python
22719 script is made up of subsequent command lines, given after the
22720 @code{python} command.  This command list is terminated using a line
22721 containing @code{end}.  For example:
22722
22723 @smallexample
22724 (@value{GDBP}) python
22725 Type python script
22726 End with a line saying just "end".
22727 >print 23
22728 >end
22729 23
22730 @end smallexample
22731
22732 @kindex set python print-stack
22733 @item set python print-stack
22734 By default, @value{GDBN} will print only the message component of a
22735 Python exception when an error occurs in a Python script.  This can be
22736 controlled using @code{set python print-stack}: if @code{full}, then
22737 full Python stack printing is enabled; if @code{none}, then Python stack
22738 and message printing is disabled; if @code{message}, the default, only
22739 the message component of the error is printed.
22740 @end table
22741
22742 It is also possible to execute a Python script from the @value{GDBN}
22743 interpreter:
22744
22745 @table @code
22746 @item source @file{script-name}
22747 The script name must end with @samp{.py} and @value{GDBN} must be configured
22748 to recognize the script language based on filename extension using
22749 the @code{script-extension} setting.  @xref{Extending GDB, ,Extending GDB}.
22750
22751 @item python execfile ("script-name")
22752 This method is based on the @code{execfile} Python built-in function,
22753 and thus is always available.
22754 @end table
22755
22756 @node Python API
22757 @subsection Python API
22758 @cindex python api
22759 @cindex programming in python
22760
22761 @cindex python stdout
22762 @cindex python pagination
22763 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
22764 @code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
22765 A Python program which outputs to one of these streams may have its
22766 output interrupted by the user (@pxref{Screen Size}).  In this
22767 situation, a Python @code{KeyboardInterrupt} exception is thrown.
22768
22769 @menu
22770 * Basic Python::                Basic Python Functions.
22771 * Exception Handling::          How Python exceptions are translated.
22772 * Values From Inferior::        Python representation of values.
22773 * Types In Python::             Python representation of types.
22774 * Pretty Printing API::         Pretty-printing values.
22775 * Selecting Pretty-Printers::   How GDB chooses a pretty-printer.
22776 * Writing a Pretty-Printer::    Writing a Pretty-Printer.
22777 * Type Printing API::           Pretty-printing types.
22778 * Inferiors In Python::         Python representation of inferiors (processes)
22779 * Events In Python::            Listening for events from @value{GDBN}.
22780 * Threads In Python::           Accessing inferior threads from Python.
22781 * Commands In Python::          Implementing new commands in Python.
22782 * Parameters In Python::        Adding new @value{GDBN} parameters.
22783 * Functions In Python::         Writing new convenience functions.
22784 * Progspaces In Python::        Program spaces.
22785 * Objfiles In Python::          Object files.
22786 * Frames In Python::            Accessing inferior stack frames from Python.
22787 * Blocks In Python::            Accessing frame blocks from Python.
22788 * Symbols In Python::           Python representation of symbols.
22789 * Symbol Tables In Python::     Python representation of symbol tables.
22790 * Breakpoints In Python::       Manipulating breakpoints using Python.
22791 * Finish Breakpoints in Python:: Setting Breakpoints on function return
22792                                 using Python.
22793 * Lazy Strings In Python::      Python representation of lazy strings.
22794 @end menu
22795
22796 @node Basic Python
22797 @subsubsection Basic Python
22798
22799 @cindex python functions
22800 @cindex python module
22801 @cindex gdb module
22802 @value{GDBN} introduces a new Python module, named @code{gdb}.  All
22803 methods and classes added by @value{GDBN} are placed in this module.
22804 @value{GDBN} automatically @code{import}s the @code{gdb} module for
22805 use in all scripts evaluated by the @code{python} command.
22806
22807 @findex gdb.PYTHONDIR
22808 @defvar gdb.PYTHONDIR
22809 A string containing the python directory (@pxref{Python}).
22810 @end defvar
22811
22812 @findex gdb.execute
22813 @defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]})
22814 Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
22815 If a GDB exception happens while @var{command} runs, it is
22816 translated as described in @ref{Exception Handling,,Exception Handling}.
22817
22818 @var{from_tty} specifies whether @value{GDBN} ought to consider this
22819 command as having originated from the user invoking it interactively.
22820 It must be a boolean value.  If omitted, it defaults to @code{False}.
22821
22822 By default, any output produced by @var{command} is sent to
22823 @value{GDBN}'s standard output.  If the @var{to_string} parameter is
22824 @code{True}, then output will be collected by @code{gdb.execute} and
22825 returned as a string.  The default is @code{False}, in which case the
22826 return value is @code{None}.  If @var{to_string} is @code{True}, the
22827 @value{GDBN} virtual terminal will be temporarily set to unlimited width
22828 and height, and its pagination will be disabled; @pxref{Screen Size}.
22829 @end defun
22830
22831 @findex gdb.breakpoints
22832 @defun gdb.breakpoints ()
22833 Return a sequence holding all of @value{GDBN}'s breakpoints.
22834 @xref{Breakpoints In Python}, for more information.
22835 @end defun
22836
22837 @findex gdb.parameter
22838 @defun gdb.parameter (parameter)
22839 Return the value of a @value{GDBN} parameter.  @var{parameter} is a
22840 string naming the parameter to look up; @var{parameter} may contain
22841 spaces if the parameter has a multi-part name.  For example,
22842 @samp{print object} is a valid parameter name.
22843
22844 If the named parameter does not exist, this function throws a
22845 @code{gdb.error} (@pxref{Exception Handling}).  Otherwise, the
22846 parameter's value is converted to a Python value of the appropriate
22847 type, and returned.
22848 @end defun
22849
22850 @findex gdb.history
22851 @defun gdb.history (number)
22852 Return a value from @value{GDBN}'s value history (@pxref{Value
22853 History}).  @var{number} indicates which history element to return.
22854 If @var{number} is negative, then @value{GDBN} will take its absolute value
22855 and count backward from the last element (i.e., the most recent element) to
22856 find the value to return.  If @var{number} is zero, then @value{GDBN} will
22857 return the most recent element.  If the element specified by @var{number}
22858 doesn't exist in the value history, a @code{gdb.error} exception will be
22859 raised.
22860
22861 If no exception is raised, the return value is always an instance of
22862 @code{gdb.Value} (@pxref{Values From Inferior}).
22863 @end defun
22864
22865 @findex gdb.parse_and_eval
22866 @defun gdb.parse_and_eval (expression)
22867 Parse @var{expression} as an expression in the current language,
22868 evaluate it, and return the result as a @code{gdb.Value}.
22869 @var{expression} must be a string.
22870
22871 This function can be useful when implementing a new command
22872 (@pxref{Commands In Python}), as it provides a way to parse the
22873 command's argument as an expression.  It is also useful simply to
22874 compute values, for example, it is the only way to get the value of a
22875 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
22876 @end defun
22877
22878 @findex gdb.find_pc_line
22879 @defun gdb.find_pc_line (pc)
22880 Return the @code{gdb.Symtab_and_line} object corresponding to the
22881 @var{pc} value.  @xref{Symbol Tables In Python}.  If an invalid
22882 value of @var{pc} is passed as an argument, then the @code{symtab} and
22883 @code{line} attributes of the returned @code{gdb.Symtab_and_line} object
22884 will be @code{None} and 0 respectively.
22885 @end defun
22886
22887 @findex gdb.post_event
22888 @defun gdb.post_event (event)
22889 Put @var{event}, a callable object taking no arguments, into
22890 @value{GDBN}'s internal event queue.  This callable will be invoked at
22891 some later point, during @value{GDBN}'s event processing.  Events
22892 posted using @code{post_event} will be run in the order in which they
22893 were posted; however, there is no way to know when they will be
22894 processed relative to other events inside @value{GDBN}.
22895
22896 @value{GDBN} is not thread-safe.  If your Python program uses multiple
22897 threads, you must be careful to only call @value{GDBN}-specific
22898 functions in the main @value{GDBN} thread.  @code{post_event} ensures
22899 this.  For example:
22900
22901 @smallexample
22902 (@value{GDBP}) python
22903 >import threading
22904 >
22905 >class Writer():
22906 > def __init__(self, message):
22907 >        self.message = message;
22908 > def __call__(self):
22909 >        gdb.write(self.message)
22910 >
22911 >class MyThread1 (threading.Thread):
22912 > def run (self):
22913 >        gdb.post_event(Writer("Hello "))
22914 >
22915 >class MyThread2 (threading.Thread):
22916 > def run (self):
22917 >        gdb.post_event(Writer("World\n"))
22918 >
22919 >MyThread1().start()
22920 >MyThread2().start()
22921 >end
22922 (@value{GDBP}) Hello World
22923 @end smallexample
22924 @end defun
22925
22926 @findex gdb.write 
22927 @defun gdb.write (string @r{[}, stream{]})
22928 Print a string to @value{GDBN}'s paginated output stream.  The
22929 optional @var{stream} determines the stream to print to.  The default
22930 stream is @value{GDBN}'s standard output stream.  Possible stream
22931 values are:
22932
22933 @table @code
22934 @findex STDOUT
22935 @findex gdb.STDOUT
22936 @item gdb.STDOUT
22937 @value{GDBN}'s standard output stream.
22938
22939 @findex STDERR
22940 @findex gdb.STDERR
22941 @item gdb.STDERR
22942 @value{GDBN}'s standard error stream.
22943
22944 @findex STDLOG
22945 @findex gdb.STDLOG
22946 @item gdb.STDLOG
22947 @value{GDBN}'s log stream (@pxref{Logging Output}).
22948 @end table
22949
22950 Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
22951 call this function and will automatically direct the output to the
22952 relevant stream.
22953 @end defun
22954
22955 @findex gdb.flush
22956 @defun gdb.flush ()
22957 Flush the buffer of a @value{GDBN} paginated stream so that the
22958 contents are displayed immediately.  @value{GDBN} will flush the
22959 contents of a stream automatically when it encounters a newline in the
22960 buffer.  The optional @var{stream} determines the stream to flush.  The
22961 default stream is @value{GDBN}'s standard output stream.  Possible
22962 stream values are: 
22963
22964 @table @code
22965 @findex STDOUT
22966 @findex gdb.STDOUT
22967 @item gdb.STDOUT
22968 @value{GDBN}'s standard output stream.
22969
22970 @findex STDERR
22971 @findex gdb.STDERR
22972 @item gdb.STDERR
22973 @value{GDBN}'s standard error stream.
22974
22975 @findex STDLOG
22976 @findex gdb.STDLOG
22977 @item gdb.STDLOG
22978 @value{GDBN}'s log stream (@pxref{Logging Output}).
22979
22980 @end table
22981
22982 Flushing @code{sys.stdout} or @code{sys.stderr} will automatically
22983 call this function for the relevant stream.
22984 @end defun
22985
22986 @findex gdb.target_charset
22987 @defun gdb.target_charset ()
22988 Return the name of the current target character set (@pxref{Character
22989 Sets}).  This differs from @code{gdb.parameter('target-charset')} in
22990 that @samp{auto} is never returned.
22991 @end defun
22992
22993 @findex gdb.target_wide_charset
22994 @defun gdb.target_wide_charset ()
22995 Return the name of the current target wide character set
22996 (@pxref{Character Sets}).  This differs from
22997 @code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
22998 never returned.
22999 @end defun
23000
23001 @findex gdb.solib_name
23002 @defun gdb.solib_name (address)
23003 Return the name of the shared library holding the given @var{address}
23004 as a string, or @code{None}.
23005 @end defun
23006
23007 @findex gdb.decode_line 
23008 @defun gdb.decode_line @r{[}expression@r{]}
23009 Return locations of the line specified by @var{expression}, or of the
23010 current line if no argument was given.  This function returns a Python
23011 tuple containing two elements.  The first element contains a string
23012 holding any unparsed section of @var{expression} (or @code{None} if
23013 the expression has been fully parsed).  The second element contains
23014 either @code{None} or another tuple that contains all the locations
23015 that match the expression represented as @code{gdb.Symtab_and_line}
23016 objects (@pxref{Symbol Tables In Python}).  If @var{expression} is
23017 provided, it is decoded the way that @value{GDBN}'s inbuilt
23018 @code{break} or @code{edit} commands do (@pxref{Specify Location}).
23019 @end defun
23020
23021 @defun gdb.prompt_hook (current_prompt)
23022 @anchor{prompt_hook}
23023
23024 If @var{prompt_hook} is callable, @value{GDBN} will call the method
23025 assigned to this operation before a prompt is displayed by
23026 @value{GDBN}.
23027
23028 The parameter @code{current_prompt} contains the current @value{GDBN} 
23029 prompt.  This method must return a Python string, or @code{None}.  If
23030 a string is returned, the @value{GDBN} prompt will be set to that
23031 string.  If @code{None} is returned, @value{GDBN} will continue to use
23032 the current prompt.
23033
23034 Some prompts cannot be substituted in @value{GDBN}.  Secondary prompts
23035 such as those used by readline for command input, and annotation
23036 related prompts are prohibited from being changed.
23037 @end defun
23038
23039 @node Exception Handling
23040 @subsubsection Exception Handling
23041 @cindex python exceptions
23042 @cindex exceptions, python
23043
23044 When executing the @code{python} command, Python exceptions
23045 uncaught within the Python code are translated to calls to
23046 @value{GDBN} error-reporting mechanism.  If the command that called
23047 @code{python} does not handle the error, @value{GDBN} will
23048 terminate it and print an error message containing the Python
23049 exception name, the associated value, and the Python call stack
23050 backtrace at the point where the exception was raised.  Example:
23051
23052 @smallexample
23053 (@value{GDBP}) python print foo
23054 Traceback (most recent call last):
23055   File "<string>", line 1, in <module>
23056 NameError: name 'foo' is not defined
23057 @end smallexample
23058
23059 @value{GDBN} errors that happen in @value{GDBN} commands invoked by
23060 Python code are converted to Python exceptions.  The type of the
23061 Python exception depends on the error.
23062
23063 @ftable @code
23064 @item gdb.error
23065 This is the base class for most exceptions generated by @value{GDBN}.
23066 It is derived from @code{RuntimeError}, for compatibility with earlier
23067 versions of @value{GDBN}.
23068
23069 If an error occurring in @value{GDBN} does not fit into some more
23070 specific category, then the generated exception will have this type.
23071
23072 @item gdb.MemoryError
23073 This is a subclass of @code{gdb.error} which is thrown when an
23074 operation tried to access invalid memory in the inferior.
23075
23076 @item KeyboardInterrupt
23077 User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
23078 prompt) is translated to a Python @code{KeyboardInterrupt} exception.
23079 @end ftable
23080
23081 In all cases, your exception handler will see the @value{GDBN} error
23082 message as its value and the Python call stack backtrace at the Python
23083 statement closest to where the @value{GDBN} error occured as the
23084 traceback.
23085
23086 @findex gdb.GdbError
23087 When implementing @value{GDBN} commands in Python via @code{gdb.Command},
23088 it is useful to be able to throw an exception that doesn't cause a
23089 traceback to be printed.  For example, the user may have invoked the
23090 command incorrectly.  Use the @code{gdb.GdbError} exception
23091 to handle this case.  Example:
23092
23093 @smallexample
23094 (gdb) python
23095 >class HelloWorld (gdb.Command):
23096 >  """Greet the whole world."""
23097 >  def __init__ (self):
23098 >    super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
23099 >  def invoke (self, args, from_tty):
23100 >    argv = gdb.string_to_argv (args)
23101 >    if len (argv) != 0:
23102 >      raise gdb.GdbError ("hello-world takes no arguments")
23103 >    print "Hello, World!"
23104 >HelloWorld ()
23105 >end
23106 (gdb) hello-world 42
23107 hello-world takes no arguments
23108 @end smallexample
23109
23110 @node Values From Inferior
23111 @subsubsection Values From Inferior
23112 @cindex values from inferior, with Python
23113 @cindex python, working with values from inferior
23114
23115 @cindex @code{gdb.Value}
23116 @value{GDBN} provides values it obtains from the inferior program in
23117 an object of type @code{gdb.Value}.  @value{GDBN} uses this object
23118 for its internal bookkeeping of the inferior's values, and for
23119 fetching values when necessary.
23120
23121 Inferior values that are simple scalars can be used directly in
23122 Python expressions that are valid for the value's data type.  Here's
23123 an example for an integer or floating-point value @code{some_val}:
23124
23125 @smallexample
23126 bar = some_val + 2
23127 @end smallexample
23128
23129 @noindent
23130 As result of this, @code{bar} will also be a @code{gdb.Value} object
23131 whose values are of the same type as those of @code{some_val}.
23132
23133 Inferior values that are structures or instances of some class can
23134 be accessed using the Python @dfn{dictionary syntax}.  For example, if
23135 @code{some_val} is a @code{gdb.Value} instance holding a structure, you
23136 can access its @code{foo} element with:
23137
23138 @smallexample
23139 bar = some_val['foo']
23140 @end smallexample
23141
23142 Again, @code{bar} will also be a @code{gdb.Value} object.
23143
23144 A @code{gdb.Value} that represents a function can be executed via
23145 inferior function call.  Any arguments provided to the call must match
23146 the function's prototype, and must be provided in the order specified
23147 by that prototype.
23148
23149 For example, @code{some_val} is a @code{gdb.Value} instance
23150 representing a function that takes two integers as arguments.  To
23151 execute this function, call it like so:
23152
23153 @smallexample
23154 result = some_val (10,20)
23155 @end smallexample
23156
23157 Any values returned from a function call will be stored as a
23158 @code{gdb.Value}.
23159
23160 The following attributes are provided:
23161
23162 @table @code
23163 @defvar Value.address
23164 If this object is addressable, this read-only attribute holds a
23165 @code{gdb.Value} object representing the address.  Otherwise,
23166 this attribute holds @code{None}.
23167 @end defvar
23168
23169 @cindex optimized out value in Python
23170 @defvar Value.is_optimized_out
23171 This read-only boolean attribute is true if the compiler optimized out
23172 this value, thus it is not available for fetching from the inferior.
23173 @end defvar
23174
23175 @defvar Value.type
23176 The type of this @code{gdb.Value}.  The value of this attribute is a
23177 @code{gdb.Type} object (@pxref{Types In Python}).
23178 @end defvar
23179
23180 @defvar Value.dynamic_type
23181 The dynamic type of this @code{gdb.Value}.  This uses C@t{++} run-time
23182 type information (@acronym{RTTI}) to determine the dynamic type of the
23183 value.  If this value is of class type, it will return the class in
23184 which the value is embedded, if any.  If this value is of pointer or
23185 reference to a class type, it will compute the dynamic type of the
23186 referenced object, and return a pointer or reference to that type,
23187 respectively.  In all other cases, it will return the value's static
23188 type.
23189
23190 Note that this feature will only work when debugging a C@t{++} program
23191 that includes @acronym{RTTI} for the object in question.  Otherwise,
23192 it will just return the static type of the value as in @kbd{ptype foo}
23193 (@pxref{Symbols, ptype}).
23194 @end defvar
23195
23196 @defvar Value.is_lazy
23197 The value of this read-only boolean attribute is @code{True} if this
23198 @code{gdb.Value} has not yet been fetched from the inferior.  
23199 @value{GDBN} does not fetch values until necessary, for efficiency.  
23200 For example:
23201
23202 @smallexample
23203 myval = gdb.parse_and_eval ('somevar')
23204 @end smallexample
23205
23206 The value of @code{somevar} is not fetched at this time.  It will be 
23207 fetched when the value is needed, or when the @code{fetch_lazy}
23208 method is invoked.  
23209 @end defvar
23210 @end table
23211
23212 The following methods are provided:
23213
23214 @table @code
23215 @defun Value.__init__ (@var{val})
23216 Many Python values can be converted directly to a @code{gdb.Value} via
23217 this object initializer.  Specifically:
23218
23219 @table @asis
23220 @item Python boolean
23221 A Python boolean is converted to the boolean type from the current
23222 language.
23223
23224 @item Python integer
23225 A Python integer is converted to the C @code{long} type for the
23226 current architecture.
23227
23228 @item Python long
23229 A Python long is converted to the C @code{long long} type for the
23230 current architecture.
23231
23232 @item Python float
23233 A Python float is converted to the C @code{double} type for the
23234 current architecture.
23235
23236 @item Python string
23237 A Python string is converted to a target string, using the current
23238 target encoding.
23239
23240 @item @code{gdb.Value}
23241 If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
23242
23243 @item @code{gdb.LazyString}
23244 If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
23245 Python}), then the lazy string's @code{value} method is called, and
23246 its result is used.
23247 @end table
23248 @end defun
23249
23250 @defun Value.cast (type)
23251 Return a new instance of @code{gdb.Value} that is the result of
23252 casting this instance to the type described by @var{type}, which must
23253 be a @code{gdb.Type} object.  If the cast cannot be performed for some
23254 reason, this method throws an exception.
23255 @end defun
23256
23257 @defun Value.dereference ()
23258 For pointer data types, this method returns a new @code{gdb.Value} object
23259 whose contents is the object pointed to by the pointer.  For example, if
23260 @code{foo} is a C pointer to an @code{int}, declared in your C program as
23261
23262 @smallexample
23263 int *foo;
23264 @end smallexample
23265
23266 @noindent
23267 then you can use the corresponding @code{gdb.Value} to access what
23268 @code{foo} points to like this:
23269
23270 @smallexample
23271 bar = foo.dereference ()
23272 @end smallexample
23273
23274 The result @code{bar} will be a @code{gdb.Value} object holding the
23275 value pointed to by @code{foo}.
23276
23277 A similar function @code{Value.referenced_value} exists which also
23278 returns @code{gdb.Value} objects corresonding to the values pointed to
23279 by pointer values (and additionally, values referenced by reference
23280 values).  However, the behavior of @code{Value.dereference}
23281 differs from @code{Value.referenced_value} by the fact that the
23282 behavior of @code{Value.dereference} is identical to applying the C
23283 unary operator @code{*} on a given value.  For example, consider a
23284 reference to a pointer @code{ptrref}, declared in your C@t{++} program
23285 as
23286
23287 @smallexample
23288 typedef int *intptr;
23289 ...
23290 int val = 10;
23291 intptr ptr = &val;
23292 intptr &ptrref = ptr;
23293 @end smallexample
23294
23295 Though @code{ptrref} is a reference value, one can apply the method
23296 @code{Value.dereference} to the @code{gdb.Value} object corresponding
23297 to it and obtain a @code{gdb.Value} which is identical to that
23298 corresponding to @code{val}.  However, if you apply the method
23299 @code{Value.referenced_value}, the result would be a @code{gdb.Value}
23300 object identical to that corresponding to @code{ptr}.
23301
23302 @smallexample
23303 py_ptrref = gdb.parse_and_eval ("ptrref")
23304 py_val = py_ptrref.dereference ()
23305 py_ptr = py_ptrref.referenced_value ()
23306 @end smallexample
23307
23308 The @code{gdb.Value} object @code{py_val} is identical to that
23309 corresponding to @code{val}, and @code{py_ptr} is identical to that
23310 corresponding to @code{ptr}.  In general, @code{Value.dereference} can
23311 be applied whenever the C unary operator @code{*} can be applied
23312 to the corresponding C value.  For those cases where applying both
23313 @code{Value.dereference} and @code{Value.referenced_value} is allowed,
23314 the results obtained need not be identical (as we have seen in the above
23315 example).  The results are however identical when applied on
23316 @code{gdb.Value} objects corresponding to pointers (@code{gdb.Value}
23317 objects with type code @code{TYPE_CODE_PTR}) in a C/C@t{++} program.
23318 @end defun
23319
23320 @defun Value.referenced_value ()
23321 For pointer or reference data types, this method returns a new
23322 @code{gdb.Value} object corresponding to the value referenced by the
23323 pointer/reference value.  For pointer data types,
23324 @code{Value.dereference} and @code{Value.referenced_value} produce
23325 identical results.  The difference between these methods is that
23326 @code{Value.dereference} cannot get the values referenced by reference
23327 values.  For example, consider a reference to an @code{int}, declared
23328 in your C@t{++} program as
23329
23330 @smallexample
23331 int val = 10;
23332 int &ref = val;
23333 @end smallexample
23334
23335 @noindent
23336 then applying @code{Value.dereference} to the @code{gdb.Value} object
23337 corresponding to @code{ref} will result in an error, while applying
23338 @code{Value.referenced_value} will result in a @code{gdb.Value} object
23339 identical to that corresponding to @code{val}.
23340
23341 @smallexample
23342 py_ref = gdb.parse_and_eval ("ref")
23343 er_ref = py_ref.dereference ()       # Results in error
23344 py_val = py_ref.referenced_value ()  # Returns the referenced value
23345 @end smallexample
23346
23347 The @code{gdb.Value} object @code{py_val} is identical to that
23348 corresponding to @code{val}.
23349 @end defun
23350
23351 @defun Value.dynamic_cast (type)
23352 Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
23353 operator were used.  Consult a C@t{++} reference for details.
23354 @end defun
23355
23356 @defun Value.reinterpret_cast (type)
23357 Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
23358 operator were used.  Consult a C@t{++} reference for details.
23359 @end defun
23360
23361 @defun Value.string (@r{[}encoding@r{[}, errors@r{[}, length@r{]]]})
23362 If this @code{gdb.Value} represents a string, then this method
23363 converts the contents to a Python string.  Otherwise, this method will
23364 throw an exception.
23365
23366 Strings are recognized in a language-specific way; whether a given
23367 @code{gdb.Value} represents a string is determined by the current
23368 language.
23369
23370 For C-like languages, a value is a string if it is a pointer to or an
23371 array of characters or ints.  The string is assumed to be terminated
23372 by a zero of the appropriate width.  However if the optional length
23373 argument is given, the string will be converted to that given length,
23374 ignoring any embedded zeros that the string may contain.
23375
23376 If the optional @var{encoding} argument is given, it must be a string
23377 naming the encoding of the string in the @code{gdb.Value}, such as
23378 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}.  It accepts
23379 the same encodings as the corresponding argument to Python's
23380 @code{string.decode} method, and the Python codec machinery will be used
23381 to convert the string.  If @var{encoding} is not given, or if
23382 @var{encoding} is the empty string, then either the @code{target-charset}
23383 (@pxref{Character Sets}) will be used, or a language-specific encoding
23384 will be used, if the current language is able to supply one.
23385
23386 The optional @var{errors} argument is the same as the corresponding
23387 argument to Python's @code{string.decode} method.
23388
23389 If the optional @var{length} argument is given, the string will be
23390 fetched and converted to the given length.
23391 @end defun
23392
23393 @defun Value.lazy_string (@r{[}encoding @r{[}, length@r{]]})
23394 If this @code{gdb.Value} represents a string, then this method
23395 converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
23396 In Python}).  Otherwise, this method will throw an exception.
23397
23398 If the optional @var{encoding} argument is given, it must be a string
23399 naming the encoding of the @code{gdb.LazyString}.  Some examples are:
23400 @samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}.  If the
23401 @var{encoding} argument is an encoding that @value{GDBN} does
23402 recognize, @value{GDBN} will raise an error.
23403
23404 When a lazy string is printed, the @value{GDBN} encoding machinery is
23405 used to convert the string during printing.  If the optional
23406 @var{encoding} argument is not provided, or is an empty string,
23407 @value{GDBN} will automatically select the encoding most suitable for
23408 the string type.  For further information on encoding in @value{GDBN}
23409 please see @ref{Character Sets}.
23410
23411 If the optional @var{length} argument is given, the string will be
23412 fetched and encoded to the length of characters specified.  If
23413 the @var{length} argument is not provided, the string will be fetched
23414 and encoded until a null of appropriate width is found.
23415 @end defun
23416
23417 @defun Value.fetch_lazy ()
23418 If the @code{gdb.Value} object is currently a lazy value 
23419 (@code{gdb.Value.is_lazy} is @code{True}), then the value is
23420 fetched from the inferior.  Any errors that occur in the process
23421 will produce a Python exception.
23422
23423 If the @code{gdb.Value} object is not a lazy value, this method
23424 has no effect.
23425
23426 This method does not return a value.
23427 @end defun
23428
23429 @end table
23430
23431 @node Types In Python
23432 @subsubsection Types In Python
23433 @cindex types in Python
23434 @cindex Python, working with types
23435
23436 @tindex gdb.Type
23437 @value{GDBN} represents types from the inferior using the class
23438 @code{gdb.Type}.
23439
23440 The following type-related functions are available in the @code{gdb}
23441 module:
23442
23443 @findex gdb.lookup_type
23444 @defun gdb.lookup_type (name @r{[}, block@r{]})
23445 This function looks up a type by name.  @var{name} is the name of the
23446 type to look up.  It must be a string.
23447
23448 If @var{block} is given, then @var{name} is looked up in that scope.
23449 Otherwise, it is searched for globally.
23450
23451 Ordinarily, this function will return an instance of @code{gdb.Type}.
23452 If the named type cannot be found, it will throw an exception.
23453 @end defun
23454
23455 If the type is a structure or class type, or an enum type, the fields
23456 of that type can be accessed using the Python @dfn{dictionary syntax}.
23457 For example, if @code{some_type} is a @code{gdb.Type} instance holding
23458 a structure type, you can access its @code{foo} field with:
23459
23460 @smallexample
23461 bar = some_type['foo']
23462 @end smallexample
23463
23464 @code{bar} will be a @code{gdb.Field} object; see below under the
23465 description of the @code{Type.fields} method for a description of the
23466 @code{gdb.Field} class.
23467
23468 An instance of @code{Type} has the following attributes:
23469
23470 @table @code
23471 @defvar Type.code
23472 The type code for this type.  The type code will be one of the
23473 @code{TYPE_CODE_} constants defined below.
23474 @end defvar
23475
23476 @defvar Type.sizeof
23477 The size of this type, in target @code{char} units.  Usually, a
23478 target's @code{char} type will be an 8-bit byte.  However, on some
23479 unusual platforms, this type may have a different size.
23480 @end defvar
23481
23482 @defvar Type.tag
23483 The tag name for this type.  The tag name is the name after
23484 @code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
23485 languages have this concept.  If this type has no tag name, then
23486 @code{None} is returned.
23487 @end defvar
23488 @end table
23489
23490 The following methods are provided:
23491
23492 @table @code
23493 @defun Type.fields ()
23494 For structure and union types, this method returns the fields.  Range
23495 types have two fields, the minimum and maximum values.  Enum types
23496 have one field per enum constant.  Function and method types have one
23497 field per parameter.  The base types of C@t{++} classes are also
23498 represented as fields.  If the type has no fields, or does not fit
23499 into one of these categories, an empty sequence will be returned.
23500
23501 Each field is a @code{gdb.Field} object, with some pre-defined attributes:
23502 @table @code
23503 @item bitpos
23504 This attribute is not available for @code{static} fields (as in
23505 C@t{++} or Java).  For non-@code{static} fields, the value is the bit
23506 position of the field.  For @code{enum} fields, the value is the
23507 enumeration member's integer representation.
23508
23509 @item name
23510 The name of the field, or @code{None} for anonymous fields.
23511
23512 @item artificial
23513 This is @code{True} if the field is artificial, usually meaning that
23514 it was provided by the compiler and not the user.  This attribute is
23515 always provided, and is @code{False} if the field is not artificial.
23516
23517 @item is_base_class
23518 This is @code{True} if the field represents a base class of a C@t{++}
23519 structure.  This attribute is always provided, and is @code{False}
23520 if the field is not a base class of the type that is the argument of
23521 @code{fields}, or if that type was not a C@t{++} class.
23522
23523 @item bitsize
23524 If the field is packed, or is a bitfield, then this will have a
23525 non-zero value, which is the size of the field in bits.  Otherwise,
23526 this will be zero; in this case the field's size is given by its type.
23527
23528 @item type
23529 The type of the field.  This is usually an instance of @code{Type},
23530 but it can be @code{None} in some situations.
23531 @end table
23532 @end defun
23533
23534 @defun Type.array (@var{n1} @r{[}, @var{n2}@r{]})
23535 Return a new @code{gdb.Type} object which represents an array of this
23536 type.  If one argument is given, it is the inclusive upper bound of
23537 the array; in this case the lower bound is zero.  If two arguments are
23538 given, the first argument is the lower bound of the array, and the
23539 second argument is the upper bound of the array.  An array's length
23540 must not be negative, but the bounds can be.
23541 @end defun
23542
23543 @defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
23544 Return a new @code{gdb.Type} object which represents a vector of this
23545 type.  If one argument is given, it is the inclusive upper bound of
23546 the vector; in this case the lower bound is zero.  If two arguments are
23547 given, the first argument is the lower bound of the vector, and the
23548 second argument is the upper bound of the vector.  A vector's length
23549 must not be negative, but the bounds can be.
23550
23551 The difference between an @code{array} and a @code{vector} is that
23552 arrays behave like in C: when used in expressions they decay to a pointer
23553 to the first element whereas vectors are treated as first class values.
23554 @end defun
23555
23556 @defun Type.const ()
23557 Return a new @code{gdb.Type} object which represents a
23558 @code{const}-qualified variant of this type.
23559 @end defun
23560
23561 @defun Type.volatile ()
23562 Return a new @code{gdb.Type} object which represents a
23563 @code{volatile}-qualified variant of this type.
23564 @end defun
23565
23566 @defun Type.unqualified ()
23567 Return a new @code{gdb.Type} object which represents an unqualified
23568 variant of this type.  That is, the result is neither @code{const} nor
23569 @code{volatile}.
23570 @end defun
23571
23572 @defun Type.range ()
23573 Return a Python @code{Tuple} object that contains two elements: the
23574 low bound of the argument type and the high bound of that type.  If
23575 the type does not have a range, @value{GDBN} will raise a
23576 @code{gdb.error} exception (@pxref{Exception Handling}).
23577 @end defun
23578
23579 @defun Type.reference ()
23580 Return a new @code{gdb.Type} object which represents a reference to this
23581 type.
23582 @end defun
23583
23584 @defun Type.pointer ()
23585 Return a new @code{gdb.Type} object which represents a pointer to this
23586 type.
23587 @end defun
23588
23589 @defun Type.strip_typedefs ()
23590 Return a new @code{gdb.Type} that represents the real type,
23591 after removing all layers of typedefs.
23592 @end defun
23593
23594 @defun Type.target ()
23595 Return a new @code{gdb.Type} object which represents the target type
23596 of this type.
23597
23598 For a pointer type, the target type is the type of the pointed-to
23599 object.  For an array type (meaning C-like arrays), the target type is
23600 the type of the elements of the array.  For a function or method type,
23601 the target type is the type of the return value.  For a complex type,
23602 the target type is the type of the elements.  For a typedef, the
23603 target type is the aliased type.
23604
23605 If the type does not have a target, this method will throw an
23606 exception.
23607 @end defun
23608
23609 @defun Type.template_argument (n @r{[}, block@r{]})
23610 If this @code{gdb.Type} is an instantiation of a template, this will
23611 return a new @code{gdb.Type} which represents the type of the
23612 @var{n}th template argument.
23613
23614 If this @code{gdb.Type} is not a template type, this will throw an
23615 exception.  Ordinarily, only C@t{++} code will have template types.
23616
23617 If @var{block} is given, then @var{name} is looked up in that scope.
23618 Otherwise, it is searched for globally.
23619 @end defun
23620 @end table
23621
23622
23623 Each type has a code, which indicates what category this type falls
23624 into.  The available type categories are represented by constants
23625 defined in the @code{gdb} module:
23626
23627 @table @code
23628 @findex TYPE_CODE_PTR
23629 @findex gdb.TYPE_CODE_PTR
23630 @item gdb.TYPE_CODE_PTR
23631 The type is a pointer.
23632
23633 @findex TYPE_CODE_ARRAY
23634 @findex gdb.TYPE_CODE_ARRAY
23635 @item gdb.TYPE_CODE_ARRAY
23636 The type is an array.
23637
23638 @findex TYPE_CODE_STRUCT
23639 @findex gdb.TYPE_CODE_STRUCT
23640 @item gdb.TYPE_CODE_STRUCT
23641 The type is a structure.
23642
23643 @findex TYPE_CODE_UNION
23644 @findex gdb.TYPE_CODE_UNION
23645 @item gdb.TYPE_CODE_UNION
23646 The type is a union.
23647
23648 @findex TYPE_CODE_ENUM
23649 @findex gdb.TYPE_CODE_ENUM
23650 @item gdb.TYPE_CODE_ENUM
23651 The type is an enum.
23652
23653 @findex TYPE_CODE_FLAGS
23654 @findex gdb.TYPE_CODE_FLAGS
23655 @item gdb.TYPE_CODE_FLAGS
23656 A bit flags type, used for things such as status registers.
23657
23658 @findex TYPE_CODE_FUNC
23659 @findex gdb.TYPE_CODE_FUNC
23660 @item gdb.TYPE_CODE_FUNC
23661 The type is a function.
23662
23663 @findex TYPE_CODE_INT
23664 @findex gdb.TYPE_CODE_INT
23665 @item gdb.TYPE_CODE_INT
23666 The type is an integer type.
23667
23668 @findex TYPE_CODE_FLT
23669 @findex gdb.TYPE_CODE_FLT
23670 @item gdb.TYPE_CODE_FLT
23671 A floating point type.
23672
23673 @findex TYPE_CODE_VOID
23674 @findex gdb.TYPE_CODE_VOID
23675 @item gdb.TYPE_CODE_VOID
23676 The special type @code{void}.
23677
23678 @findex TYPE_CODE_SET
23679 @findex gdb.TYPE_CODE_SET
23680 @item gdb.TYPE_CODE_SET
23681 A Pascal set type.
23682
23683 @findex TYPE_CODE_RANGE
23684 @findex gdb.TYPE_CODE_RANGE
23685 @item gdb.TYPE_CODE_RANGE
23686 A range type, that is, an integer type with bounds.
23687
23688 @findex TYPE_CODE_STRING
23689 @findex gdb.TYPE_CODE_STRING
23690 @item gdb.TYPE_CODE_STRING
23691 A string type.  Note that this is only used for certain languages with
23692 language-defined string types; C strings are not represented this way.
23693
23694 @findex TYPE_CODE_BITSTRING
23695 @findex gdb.TYPE_CODE_BITSTRING
23696 @item gdb.TYPE_CODE_BITSTRING
23697 A string of bits.  It is deprecated.
23698
23699 @findex TYPE_CODE_ERROR
23700 @findex gdb.TYPE_CODE_ERROR
23701 @item gdb.TYPE_CODE_ERROR
23702 An unknown or erroneous type.
23703
23704 @findex TYPE_CODE_METHOD
23705 @findex gdb.TYPE_CODE_METHOD
23706 @item gdb.TYPE_CODE_METHOD
23707 A method type, as found in C@t{++} or Java.
23708
23709 @findex TYPE_CODE_METHODPTR
23710 @findex gdb.TYPE_CODE_METHODPTR
23711 @item gdb.TYPE_CODE_METHODPTR
23712 A pointer-to-member-function.
23713
23714 @findex TYPE_CODE_MEMBERPTR
23715 @findex gdb.TYPE_CODE_MEMBERPTR
23716 @item gdb.TYPE_CODE_MEMBERPTR
23717 A pointer-to-member.
23718
23719 @findex TYPE_CODE_REF
23720 @findex gdb.TYPE_CODE_REF
23721 @item gdb.TYPE_CODE_REF
23722 A reference type.
23723
23724 @findex TYPE_CODE_CHAR
23725 @findex gdb.TYPE_CODE_CHAR
23726 @item gdb.TYPE_CODE_CHAR
23727 A character type.
23728
23729 @findex TYPE_CODE_BOOL
23730 @findex gdb.TYPE_CODE_BOOL
23731 @item gdb.TYPE_CODE_BOOL
23732 A boolean type.
23733
23734 @findex TYPE_CODE_COMPLEX
23735 @findex gdb.TYPE_CODE_COMPLEX
23736 @item gdb.TYPE_CODE_COMPLEX
23737 A complex float type.
23738
23739 @findex TYPE_CODE_TYPEDEF
23740 @findex gdb.TYPE_CODE_TYPEDEF
23741 @item gdb.TYPE_CODE_TYPEDEF
23742 A typedef to some other type.
23743
23744 @findex TYPE_CODE_NAMESPACE
23745 @findex gdb.TYPE_CODE_NAMESPACE
23746 @item gdb.TYPE_CODE_NAMESPACE
23747 A C@t{++} namespace.
23748
23749 @findex TYPE_CODE_DECFLOAT
23750 @findex gdb.TYPE_CODE_DECFLOAT
23751 @item gdb.TYPE_CODE_DECFLOAT
23752 A decimal floating point type.
23753
23754 @findex TYPE_CODE_INTERNAL_FUNCTION
23755 @findex gdb.TYPE_CODE_INTERNAL_FUNCTION
23756 @item gdb.TYPE_CODE_INTERNAL_FUNCTION
23757 A function internal to @value{GDBN}.  This is the type used to represent
23758 convenience functions.
23759 @end table
23760
23761 Further support for types is provided in the @code{gdb.types}
23762 Python module (@pxref{gdb.types}).
23763
23764 @node Pretty Printing API
23765 @subsubsection Pretty Printing API
23766
23767 An example output is provided (@pxref{Pretty Printing}).
23768
23769 A pretty-printer is just an object that holds a value and implements a
23770 specific interface, defined here.
23771
23772 @defun pretty_printer.children (self)
23773 @value{GDBN} will call this method on a pretty-printer to compute the
23774 children of the pretty-printer's value.
23775
23776 This method must return an object conforming to the Python iterator
23777 protocol.  Each item returned by the iterator must be a tuple holding
23778 two elements.  The first element is the ``name'' of the child; the
23779 second element is the child's value.  The value can be any Python
23780 object which is convertible to a @value{GDBN} value.
23781
23782 This method is optional.  If it does not exist, @value{GDBN} will act
23783 as though the value has no children.
23784 @end defun
23785
23786 @defun pretty_printer.display_hint (self)
23787 The CLI may call this method and use its result to change the
23788 formatting of a value.  The result will also be supplied to an MI
23789 consumer as a @samp{displayhint} attribute of the variable being
23790 printed.
23791
23792 This method is optional.  If it does exist, this method must return a
23793 string.
23794
23795 Some display hints are predefined by @value{GDBN}:
23796
23797 @table @samp
23798 @item array
23799 Indicate that the object being printed is ``array-like''.  The CLI
23800 uses this to respect parameters such as @code{set print elements} and
23801 @code{set print array}.
23802
23803 @item map
23804 Indicate that the object being printed is ``map-like'', and that the
23805 children of this value can be assumed to alternate between keys and
23806 values.
23807
23808 @item string
23809 Indicate that the object being printed is ``string-like''.  If the
23810 printer's @code{to_string} method returns a Python string of some
23811 kind, then @value{GDBN} will call its internal language-specific
23812 string-printing function to format the string.  For the CLI this means
23813 adding quotation marks, possibly escaping some characters, respecting
23814 @code{set print elements}, and the like.
23815 @end table
23816 @end defun
23817
23818 @defun pretty_printer.to_string (self)
23819 @value{GDBN} will call this method to display the string
23820 representation of the value passed to the object's constructor.
23821
23822 When printing from the CLI, if the @code{to_string} method exists,
23823 then @value{GDBN} will prepend its result to the values returned by
23824 @code{children}.  Exactly how this formatting is done is dependent on
23825 the display hint, and may change as more hints are added.  Also,
23826 depending on the print settings (@pxref{Print Settings}), the CLI may
23827 print just the result of @code{to_string} in a stack trace, omitting
23828 the result of @code{children}.
23829
23830 If this method returns a string, it is printed verbatim.
23831
23832 Otherwise, if this method returns an instance of @code{gdb.Value},
23833 then @value{GDBN} prints this value.  This may result in a call to
23834 another pretty-printer.
23835
23836 If instead the method returns a Python value which is convertible to a
23837 @code{gdb.Value}, then @value{GDBN} performs the conversion and prints
23838 the resulting value.  Again, this may result in a call to another
23839 pretty-printer.  Python scalars (integers, floats, and booleans) and
23840 strings are convertible to @code{gdb.Value}; other types are not.
23841
23842 Finally, if this method returns @code{None} then no further operations
23843 are peformed in this method and nothing is printed.
23844
23845 If the result is not one of these types, an exception is raised.
23846 @end defun
23847
23848 @value{GDBN} provides a function which can be used to look up the
23849 default pretty-printer for a @code{gdb.Value}:
23850
23851 @findex gdb.default_visualizer
23852 @defun gdb.default_visualizer (value)
23853 This function takes a @code{gdb.Value} object as an argument.  If a
23854 pretty-printer for this value exists, then it is returned.  If no such
23855 printer exists, then this returns @code{None}.
23856 @end defun
23857
23858 @node Selecting Pretty-Printers
23859 @subsubsection Selecting Pretty-Printers
23860
23861 The Python list @code{gdb.pretty_printers} contains an array of
23862 functions or callable objects that have been registered via addition
23863 as a pretty-printer.  Printers in this list are called @code{global}
23864 printers, they're available when debugging all inferiors.
23865 Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
23866 Each @code{gdb.Objfile} also contains a @code{pretty_printers}
23867 attribute.
23868
23869 Each function on these lists is passed a single @code{gdb.Value}
23870 argument and should return a pretty-printer object conforming to the
23871 interface definition above (@pxref{Pretty Printing API}).  If a function
23872 cannot create a pretty-printer for the value, it should return
23873 @code{None}.
23874
23875 @value{GDBN} first checks the @code{pretty_printers} attribute of each
23876 @code{gdb.Objfile} in the current program space and iteratively calls
23877 each enabled lookup routine in the list for that @code{gdb.Objfile}
23878 until it receives a pretty-printer object.
23879 If no pretty-printer is found in the objfile lists, @value{GDBN} then
23880 searches the pretty-printer list of the current program space,
23881 calling each enabled function until an object is returned.
23882 After these lists have been exhausted, it tries the global
23883 @code{gdb.pretty_printers} list, again calling each enabled function until an
23884 object is returned.
23885
23886 The order in which the objfiles are searched is not specified.  For a
23887 given list, functions are always invoked from the head of the list,
23888 and iterated over sequentially until the end of the list, or a printer
23889 object is returned.
23890
23891 For various reasons a pretty-printer may not work.
23892 For example, the underlying data structure may have changed and
23893 the pretty-printer is out of date.
23894
23895 The consequences of a broken pretty-printer are severe enough that
23896 @value{GDBN} provides support for enabling and disabling individual
23897 printers.  For example, if @code{print frame-arguments} is on,
23898 a backtrace can become highly illegible if any argument is printed
23899 with a broken printer.
23900
23901 Pretty-printers are enabled and disabled by attaching an @code{enabled}
23902 attribute to the registered function or callable object.  If this attribute
23903 is present and its value is @code{False}, the printer is disabled, otherwise
23904 the printer is enabled.
23905
23906 @node Writing a Pretty-Printer
23907 @subsubsection Writing a Pretty-Printer
23908 @cindex writing a pretty-printer
23909
23910 A pretty-printer consists of two parts: a lookup function to detect
23911 if the type is supported, and the printer itself.
23912
23913 Here is an example showing how a @code{std::string} printer might be
23914 written.  @xref{Pretty Printing API}, for details on the API this class
23915 must provide.
23916
23917 @smallexample
23918 class StdStringPrinter(object):
23919     "Print a std::string"
23920
23921     def __init__(self, val):
23922         self.val = val
23923
23924     def to_string(self):
23925         return self.val['_M_dataplus']['_M_p']
23926
23927     def display_hint(self):
23928         return 'string'
23929 @end smallexample
23930
23931 And here is an example showing how a lookup function for the printer
23932 example above might be written.
23933
23934 @smallexample
23935 def str_lookup_function(val):
23936     lookup_tag = val.type.tag
23937     if lookup_tag == None:
23938         return None
23939     regex = re.compile("^std::basic_string<char,.*>$")
23940     if regex.match(lookup_tag):
23941         return StdStringPrinter(val)
23942     return None
23943 @end smallexample
23944
23945 The example lookup function extracts the value's type, and attempts to
23946 match it to a type that it can pretty-print.  If it is a type the
23947 printer can pretty-print, it will return a printer object.  If not, it
23948 returns @code{None}.
23949
23950 We recommend that you put your core pretty-printers into a Python
23951 package.  If your pretty-printers are for use with a library, we
23952 further recommend embedding a version number into the package name.
23953 This practice will enable @value{GDBN} to load multiple versions of
23954 your pretty-printers at the same time, because they will have
23955 different names.
23956
23957 You should write auto-loaded code (@pxref{Python Auto-loading}) such that it
23958 can be evaluated multiple times without changing its meaning.  An
23959 ideal auto-load file will consist solely of @code{import}s of your
23960 printer modules, followed by a call to a register pretty-printers with
23961 the current objfile.
23962
23963 Taken as a whole, this approach will scale nicely to multiple
23964 inferiors, each potentially using a different library version.
23965 Embedding a version number in the Python package name will ensure that
23966 @value{GDBN} is able to load both sets of printers simultaneously.
23967 Then, because the search for pretty-printers is done by objfile, and
23968 because your auto-loaded code took care to register your library's
23969 printers with a specific objfile, @value{GDBN} will find the correct
23970 printers for the specific version of the library used by each
23971 inferior.
23972
23973 To continue the @code{std::string} example (@pxref{Pretty Printing API}),
23974 this code might appear in @code{gdb.libstdcxx.v6}:
23975
23976 @smallexample
23977 def register_printers(objfile):
23978     objfile.pretty_printers.append(str_lookup_function)
23979 @end smallexample
23980
23981 @noindent
23982 And then the corresponding contents of the auto-load file would be:
23983
23984 @smallexample
23985 import gdb.libstdcxx.v6
23986 gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
23987 @end smallexample
23988
23989 The previous example illustrates a basic pretty-printer.
23990 There are a few things that can be improved on.
23991 The printer doesn't have a name, making it hard to identify in a
23992 list of installed printers.  The lookup function has a name, but
23993 lookup functions can have arbitrary, even identical, names.
23994
23995 Second, the printer only handles one type, whereas a library typically has
23996 several types.  One could install a lookup function for each desired type
23997 in the library, but one could also have a single lookup function recognize
23998 several types.  The latter is the conventional way this is handled.
23999 If a pretty-printer can handle multiple data types, then its
24000 @dfn{subprinters} are the printers for the individual data types.
24001
24002 The @code{gdb.printing} module provides a formal way of solving these
24003 problems (@pxref{gdb.printing}).
24004 Here is another example that handles multiple types.
24005
24006 These are the types we are going to pretty-print:
24007
24008 @smallexample
24009 struct foo @{ int a, b; @};
24010 struct bar @{ struct foo x, y; @};
24011 @end smallexample
24012
24013 Here are the printers:
24014
24015 @smallexample
24016 class fooPrinter:
24017     """Print a foo object."""
24018
24019     def __init__(self, val):
24020         self.val = val
24021
24022     def to_string(self):
24023         return ("a=<" + str(self.val["a"]) +
24024                 "> b=<" + str(self.val["b"]) + ">")
24025
24026 class barPrinter:
24027     """Print a bar object."""
24028
24029     def __init__(self, val):
24030         self.val = val
24031
24032     def to_string(self):
24033         return ("x=<" + str(self.val["x"]) +
24034                 "> y=<" + str(self.val["y"]) + ">")
24035 @end smallexample
24036
24037 This example doesn't need a lookup function, that is handled by the
24038 @code{gdb.printing} module.  Instead a function is provided to build up
24039 the object that handles the lookup.
24040
24041 @smallexample
24042 import gdb.printing
24043
24044 def build_pretty_printer():
24045     pp = gdb.printing.RegexpCollectionPrettyPrinter(
24046         "my_library")
24047     pp.add_printer('foo', '^foo$', fooPrinter)
24048     pp.add_printer('bar', '^bar$', barPrinter)
24049     return pp
24050 @end smallexample
24051
24052 And here is the autoload support:
24053
24054 @smallexample
24055 import gdb.printing
24056 import my_library
24057 gdb.printing.register_pretty_printer(
24058     gdb.current_objfile(),
24059     my_library.build_pretty_printer())
24060 @end smallexample
24061
24062 Finally, when this printer is loaded into @value{GDBN}, here is the
24063 corresponding output of @samp{info pretty-printer}:
24064
24065 @smallexample
24066 (gdb) info pretty-printer
24067 my_library.so:
24068   my_library
24069     foo
24070     bar
24071 @end smallexample
24072
24073 @node Type Printing API
24074 @subsubsection Type Printing API
24075 @cindex type printing API for Python
24076
24077 @value{GDBN} provides a way for Python code to customize type display.
24078 This is mainly useful for substituting canonical typedef names for
24079 types.
24080
24081 @cindex type printer
24082 A @dfn{type printer} is just a Python object conforming to a certain
24083 protocol.  A simple base class implementing the protocol is provided;
24084 see @ref{gdb.types}.  A type printer must supply at least:
24085
24086 @defivar type_printer enabled
24087 A boolean which is True if the printer is enabled, and False
24088 otherwise.  This is manipulated by the @code{enable type-printer}
24089 and @code{disable type-printer} commands.
24090 @end defivar
24091
24092 @defivar type_printer name
24093 The name of the type printer.  This must be a string.  This is used by
24094 the @code{enable type-printer} and @code{disable type-printer}
24095 commands.
24096 @end defivar
24097
24098 @defmethod type_printer instantiate (self)
24099 This is called by @value{GDBN} at the start of type-printing.  It is
24100 only called if the type printer is enabled.  This method must return a
24101 new object that supplies a @code{recognize} method, as described below.
24102 @end defmethod
24103
24104
24105 When displaying a type, say via the @code{ptype} command, @value{GDBN}
24106 will compute a list of type recognizers.  This is done by iterating
24107 first over the per-objfile type printers (@pxref{Objfiles In Python}),
24108 followed by the per-progspace type printers (@pxref{Progspaces In
24109 Python}), and finally the global type printers.
24110
24111 @value{GDBN} will call the @code{instantiate} method of each enabled
24112 type printer.  If this method returns @code{None}, then the result is
24113 ignored; otherwise, it is appended to the list of recognizers.
24114
24115 Then, when @value{GDBN} is going to display a type name, it iterates
24116 over the list of recognizers.  For each one, it calls the recognition
24117 function, stopping if the function returns a non-@code{None} value.
24118 The recognition function is defined as:
24119
24120 @defmethod type_recognizer recognize (self, type)
24121 If @var{type} is not recognized, return @code{None}.  Otherwise,
24122 return a string which is to be printed as the name of @var{type}.
24123 @var{type} will be an instance of @code{gdb.Type} (@pxref{Types In
24124 Python}).
24125 @end defmethod
24126
24127 @value{GDBN} uses this two-pass approach so that type printers can
24128 efficiently cache information without holding on to it too long.  For
24129 example, it can be convenient to look up type information in a type
24130 printer and hold it for a recognizer's lifetime; if a single pass were
24131 done then type printers would have to make use of the event system in
24132 order to avoid holding information that could become stale as the
24133 inferior changed.
24134
24135 @node Inferiors In Python
24136 @subsubsection Inferiors In Python
24137 @cindex inferiors in Python
24138
24139 @findex gdb.Inferior
24140 Programs which are being run under @value{GDBN} are called inferiors
24141 (@pxref{Inferiors and Programs}).  Python scripts can access
24142 information about and manipulate inferiors controlled by @value{GDBN}
24143 via objects of the @code{gdb.Inferior} class.
24144
24145 The following inferior-related functions are available in the @code{gdb}
24146 module:
24147
24148 @defun gdb.inferiors ()
24149 Return a tuple containing all inferior objects.
24150 @end defun
24151
24152 @defun gdb.selected_inferior ()
24153 Return an object representing the current inferior.
24154 @end defun
24155
24156 A @code{gdb.Inferior} object has the following attributes:
24157
24158 @table @code
24159 @defvar Inferior.num
24160 ID of inferior, as assigned by GDB.
24161 @end defvar
24162
24163 @defvar Inferior.pid
24164 Process ID of the inferior, as assigned by the underlying operating
24165 system.
24166 @end defvar
24167
24168 @defvar Inferior.was_attached
24169 Boolean signaling whether the inferior was created using `attach', or
24170 started by @value{GDBN} itself.
24171 @end defvar
24172 @end table
24173
24174 A @code{gdb.Inferior} object has the following methods:
24175
24176 @table @code
24177 @defun Inferior.is_valid ()
24178 Returns @code{True} if the @code{gdb.Inferior} object is valid,
24179 @code{False} if not.  A @code{gdb.Inferior} object will become invalid
24180 if the inferior no longer exists within @value{GDBN}.  All other
24181 @code{gdb.Inferior} methods will throw an exception if it is invalid
24182 at the time the method is called.
24183 @end defun
24184
24185 @defun Inferior.threads ()
24186 This method returns a tuple holding all the threads which are valid
24187 when it is called.  If there are no valid threads, the method will
24188 return an empty tuple.
24189 @end defun
24190
24191 @findex Inferior.read_memory
24192 @defun Inferior.read_memory (address, length)
24193 Read @var{length} bytes of memory from the inferior, starting at
24194 @var{address}.  Returns a buffer object, which behaves much like an array
24195 or a string.  It can be modified and given to the
24196 @code{Inferior.write_memory} function.  In @code{Python} 3, the return
24197 value is a @code{memoryview} object.
24198 @end defun
24199
24200 @findex Inferior.write_memory
24201 @defun Inferior.write_memory (address, buffer @r{[}, length@r{]})
24202 Write the contents of @var{buffer} to the inferior, starting at
24203 @var{address}.  The @var{buffer} parameter must be a Python object
24204 which supports the buffer protocol, i.e., a string, an array or the
24205 object returned from @code{Inferior.read_memory}.  If given, @var{length}
24206 determines the number of bytes from @var{buffer} to be written.
24207 @end defun
24208
24209 @findex gdb.search_memory
24210 @defun Inferior.search_memory (address, length, pattern)
24211 Search a region of the inferior memory starting at @var{address} with
24212 the given @var{length} using the search pattern supplied in
24213 @var{pattern}.  The @var{pattern} parameter must be a Python object
24214 which supports the buffer protocol, i.e., a string, an array or the
24215 object returned from @code{gdb.read_memory}.  Returns a Python @code{Long}
24216 containing the address where the pattern was found, or @code{None} if
24217 the pattern could not be found.
24218 @end defun
24219 @end table
24220
24221 @node Events In Python
24222 @subsubsection Events In Python
24223 @cindex inferior events in Python
24224
24225 @value{GDBN} provides a general event facility so that Python code can be
24226 notified of various state changes, particularly changes that occur in
24227 the inferior.
24228
24229 An @dfn{event} is just an object that describes some state change.  The
24230 type of the object and its attributes will vary depending on the details
24231 of the change.  All the existing events are described below.
24232
24233 In order to be notified of an event, you must register an event handler
24234 with an @dfn{event registry}.  An event registry is an object in the
24235 @code{gdb.events} module which dispatches particular events.  A registry
24236 provides methods to register and unregister event handlers:
24237
24238 @table @code
24239 @defun EventRegistry.connect (object)
24240 Add the given callable @var{object} to the registry.  This object will be
24241 called when an event corresponding to this registry occurs.
24242 @end defun
24243
24244 @defun EventRegistry.disconnect (object)
24245 Remove the given @var{object} from the registry.  Once removed, the object
24246 will no longer receive notifications of events.
24247 @end defun
24248 @end table
24249
24250 Here is an example:
24251
24252 @smallexample
24253 def exit_handler (event):
24254     print "event type: exit"
24255     print "exit code: %d" % (event.exit_code)
24256
24257 gdb.events.exited.connect (exit_handler)
24258 @end smallexample
24259
24260 In the above example we connect our handler @code{exit_handler} to the
24261 registry @code{events.exited}.  Once connected, @code{exit_handler} gets
24262 called when the inferior exits.  The argument @dfn{event} in this example is
24263 of type @code{gdb.ExitedEvent}.  As you can see in the example the
24264 @code{ExitedEvent} object has an attribute which indicates the exit code of
24265 the inferior.
24266
24267 The following is a listing of the event registries that are available and
24268 details of the events they emit:
24269
24270 @table @code
24271
24272 @item events.cont
24273 Emits @code{gdb.ThreadEvent}.
24274
24275 Some events can be thread specific when @value{GDBN} is running in non-stop
24276 mode.  When represented in Python, these events all extend
24277 @code{gdb.ThreadEvent}.  Note, this event is not emitted directly; instead,
24278 events which are emitted by this or other modules might extend this event.
24279 Examples of these events are @code{gdb.BreakpointEvent} and
24280 @code{gdb.ContinueEvent}.
24281
24282 @table @code
24283 @defvar ThreadEvent.inferior_thread
24284 In non-stop mode this attribute will be set to the specific thread which was
24285 involved in the emitted event. Otherwise, it will be set to @code{None}.
24286 @end defvar
24287 @end table
24288
24289 Emits @code{gdb.ContinueEvent} which extends @code{gdb.ThreadEvent}.
24290
24291 This event indicates that the inferior has been continued after a stop. For
24292 inherited attribute refer to @code{gdb.ThreadEvent} above.
24293
24294 @item events.exited
24295 Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
24296 @code{events.ExitedEvent} has two attributes:
24297 @table @code
24298 @defvar ExitedEvent.exit_code
24299 An integer representing the exit code, if available, which the inferior 
24300 has returned.  (The exit code could be unavailable if, for example,
24301 @value{GDBN} detaches from the inferior.) If the exit code is unavailable,
24302 the attribute does not exist.
24303 @end defvar
24304 @defvar ExitedEvent inferior
24305 A reference to the inferior which triggered the @code{exited} event.
24306 @end defvar
24307 @end table
24308
24309 @item events.stop
24310 Emits @code{gdb.StopEvent} which extends @code{gdb.ThreadEvent}.
24311
24312 Indicates that the inferior has stopped.  All events emitted by this registry
24313 extend StopEvent.  As a child of @code{gdb.ThreadEvent}, @code{gdb.StopEvent}
24314 will indicate the stopped thread when @value{GDBN} is running in non-stop
24315 mode.  Refer to @code{gdb.ThreadEvent} above for more details.
24316
24317 Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}.
24318
24319 This event indicates that the inferior or one of its threads has received as
24320 signal.  @code{gdb.SignalEvent} has the following attributes:
24321
24322 @table @code
24323 @defvar SignalEvent.stop_signal
24324 A string representing the signal received by the inferior.  A list of possible
24325 signal values can be obtained by running the command @code{info signals} in
24326 the @value{GDBN} command prompt.
24327 @end defvar
24328 @end table
24329
24330 Also emits  @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
24331
24332 @code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
24333 been hit, and has the following attributes:
24334
24335 @table @code
24336 @defvar BreakpointEvent.breakpoints
24337 A sequence containing references to all the breakpoints (type 
24338 @code{gdb.Breakpoint}) that were hit.
24339 @xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
24340 @end defvar
24341 @defvar BreakpointEvent.breakpoint
24342 A reference to the first breakpoint that was hit.
24343 This function is maintained for backward compatibility and is now deprecated 
24344 in favor of the @code{gdb.BreakpointEvent.breakpoints} attribute.
24345 @end defvar
24346 @end table
24347
24348 @item events.new_objfile
24349 Emits @code{gdb.NewObjFileEvent} which indicates that a new object file has
24350 been loaded by @value{GDBN}.  @code{gdb.NewObjFileEvent} has one attribute:
24351
24352 @table @code
24353 @defvar NewObjFileEvent.new_objfile
24354 A reference to the object file (@code{gdb.Objfile}) which has been loaded.
24355 @xref{Objfiles In Python}, for details of the @code{gdb.Objfile} object.
24356 @end defvar
24357 @end table
24358
24359 @end table
24360
24361 @node Threads In Python
24362 @subsubsection Threads In Python
24363 @cindex threads in python
24364
24365 @findex gdb.InferiorThread
24366 Python scripts can access information about, and manipulate inferior threads
24367 controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
24368
24369 The following thread-related functions are available in the @code{gdb}
24370 module:
24371
24372 @findex gdb.selected_thread
24373 @defun gdb.selected_thread ()
24374 This function returns the thread object for the selected thread.  If there
24375 is no selected thread, this will return @code{None}.
24376 @end defun
24377
24378 A @code{gdb.InferiorThread} object has the following attributes:
24379
24380 @table @code
24381 @defvar InferiorThread.name
24382 The name of the thread.  If the user specified a name using
24383 @code{thread name}, then this returns that name.  Otherwise, if an
24384 OS-supplied name is available, then it is returned.  Otherwise, this
24385 returns @code{None}.
24386
24387 This attribute can be assigned to.  The new value must be a string
24388 object, which sets the new name, or @code{None}, which removes any
24389 user-specified thread name.
24390 @end defvar
24391
24392 @defvar InferiorThread.num
24393 ID of the thread, as assigned by GDB.
24394 @end defvar
24395
24396 @defvar InferiorThread.ptid
24397 ID of the thread, as assigned by the operating system.  This attribute is a
24398 tuple containing three integers.  The first is the Process ID (PID); the second
24399 is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
24400 Either the LWPID or TID may be 0, which indicates that the operating system
24401 does not  use that identifier.
24402 @end defvar
24403 @end table
24404
24405 A @code{gdb.InferiorThread} object has the following methods:
24406
24407 @table @code
24408 @defun InferiorThread.is_valid ()
24409 Returns @code{True} if the @code{gdb.InferiorThread} object is valid,
24410 @code{False} if not.  A @code{gdb.InferiorThread} object will become
24411 invalid if the thread exits, or the inferior that the thread belongs
24412 is deleted.  All other @code{gdb.InferiorThread} methods will throw an
24413 exception if it is invalid at the time the method is called.
24414 @end defun
24415
24416 @defun InferiorThread.switch ()
24417 This changes @value{GDBN}'s currently selected thread to the one represented
24418 by this object.
24419 @end defun
24420
24421 @defun InferiorThread.is_stopped ()
24422 Return a Boolean indicating whether the thread is stopped.
24423 @end defun
24424
24425 @defun InferiorThread.is_running ()
24426 Return a Boolean indicating whether the thread is running.
24427 @end defun
24428
24429 @defun InferiorThread.is_exited ()
24430 Return a Boolean indicating whether the thread is exited.
24431 @end defun
24432 @end table
24433
24434 @node Commands In Python
24435 @subsubsection Commands In Python
24436
24437 @cindex commands in python
24438 @cindex python commands
24439 You can implement new @value{GDBN} CLI commands in Python.  A CLI
24440 command is implemented using an instance of the @code{gdb.Command}
24441 class, most commonly using a subclass.
24442
24443 @defun Command.__init__ (name, @var{command_class} @r{[}, @var{completer_class} @r{[}, @var{prefix}@r{]]})
24444 The object initializer for @code{Command} registers the new command
24445 with @value{GDBN}.  This initializer is normally invoked from the
24446 subclass' own @code{__init__} method.
24447
24448 @var{name} is the name of the command.  If @var{name} consists of
24449 multiple words, then the initial words are looked for as prefix
24450 commands.  In this case, if one of the prefix commands does not exist,
24451 an exception is raised.
24452
24453 There is no support for multi-line commands.
24454
24455 @var{command_class} should be one of the @samp{COMMAND_} constants
24456 defined below.  This argument tells @value{GDBN} how to categorize the
24457 new command in the help system.
24458
24459 @var{completer_class} is an optional argument.  If given, it should be
24460 one of the @samp{COMPLETE_} constants defined below.  This argument
24461 tells @value{GDBN} how to perform completion for this command.  If not
24462 given, @value{GDBN} will attempt to complete using the object's
24463 @code{complete} method (see below); if no such method is found, an
24464 error will occur when completion is attempted.
24465
24466 @var{prefix} is an optional argument.  If @code{True}, then the new
24467 command is a prefix command; sub-commands of this command may be
24468 registered.
24469
24470 The help text for the new command is taken from the Python
24471 documentation string for the command's class, if there is one.  If no
24472 documentation string is provided, the default value ``This command is
24473 not documented.'' is used.
24474 @end defun
24475
24476 @cindex don't repeat Python command
24477 @defun Command.dont_repeat ()
24478 By default, a @value{GDBN} command is repeated when the user enters a
24479 blank line at the command prompt.  A command can suppress this
24480 behavior by invoking the @code{dont_repeat} method.  This is similar
24481 to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
24482 @end defun
24483
24484 @defun Command.invoke (argument, from_tty)
24485 This method is called by @value{GDBN} when this command is invoked.
24486
24487 @var{argument} is a string.  It is the argument to the command, after
24488 leading and trailing whitespace has been stripped.
24489
24490 @var{from_tty} is a boolean argument.  When true, this means that the
24491 command was entered by the user at the terminal; when false it means
24492 that the command came from elsewhere.
24493
24494 If this method throws an exception, it is turned into a @value{GDBN}
24495 @code{error} call.  Otherwise, the return value is ignored.
24496
24497 @findex gdb.string_to_argv
24498 To break @var{argument} up into an argv-like string use
24499 @code{gdb.string_to_argv}.  This function behaves identically to
24500 @value{GDBN}'s internal argument lexer @code{buildargv}.
24501 It is recommended to use this for consistency.
24502 Arguments are separated by spaces and may be quoted.
24503 Example:
24504
24505 @smallexample
24506 print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
24507 ['1', '2 "3', '4 "5', "6 '7"]
24508 @end smallexample
24509
24510 @end defun
24511
24512 @cindex completion of Python commands
24513 @defun Command.complete (text, word)
24514 This method is called by @value{GDBN} when the user attempts
24515 completion on this command.  All forms of completion are handled by
24516 this method, that is, the @key{TAB} and @key{M-?} key bindings
24517 (@pxref{Completion}), and the @code{complete} command (@pxref{Help,
24518 complete}).
24519
24520 The arguments @var{text} and @var{word} are both strings.  @var{text}
24521 holds the complete command line up to the cursor's location.
24522 @var{word} holds the last word of the command line; this is computed
24523 using a word-breaking heuristic.
24524
24525 The @code{complete} method can return several values:
24526 @itemize @bullet
24527 @item
24528 If the return value is a sequence, the contents of the sequence are
24529 used as the completions.  It is up to @code{complete} to ensure that the
24530 contents actually do complete the word.  A zero-length sequence is
24531 allowed, it means that there were no completions available.  Only
24532 string elements of the sequence are used; other elements in the
24533 sequence are ignored.
24534
24535 @item
24536 If the return value is one of the @samp{COMPLETE_} constants defined
24537 below, then the corresponding @value{GDBN}-internal completion
24538 function is invoked, and its result is used.
24539
24540 @item
24541 All other results are treated as though there were no available
24542 completions.
24543 @end itemize
24544 @end defun
24545
24546 When a new command is registered, it must be declared as a member of
24547 some general class of commands.  This is used to classify top-level
24548 commands in the on-line help system; note that prefix commands are not
24549 listed under their own category but rather that of their top-level
24550 command.  The available classifications are represented by constants
24551 defined in the @code{gdb} module:
24552
24553 @table @code
24554 @findex COMMAND_NONE
24555 @findex gdb.COMMAND_NONE
24556 @item gdb.COMMAND_NONE
24557 The command does not belong to any particular class.  A command in
24558 this category will not be displayed in any of the help categories.
24559
24560 @findex COMMAND_RUNNING
24561 @findex gdb.COMMAND_RUNNING
24562 @item gdb.COMMAND_RUNNING
24563 The command is related to running the inferior.  For example,
24564 @code{start}, @code{step}, and @code{continue} are in this category.
24565 Type @kbd{help running} at the @value{GDBN} prompt to see a list of
24566 commands in this category.
24567
24568 @findex COMMAND_DATA
24569 @findex gdb.COMMAND_DATA
24570 @item gdb.COMMAND_DATA
24571 The command is related to data or variables.  For example,
24572 @code{call}, @code{find}, and @code{print} are in this category.  Type
24573 @kbd{help data} at the @value{GDBN} prompt to see a list of commands
24574 in this category.
24575
24576 @findex COMMAND_STACK
24577 @findex gdb.COMMAND_STACK
24578 @item gdb.COMMAND_STACK
24579 The command has to do with manipulation of the stack.  For example,
24580 @code{backtrace}, @code{frame}, and @code{return} are in this
24581 category.  Type @kbd{help stack} at the @value{GDBN} prompt to see a
24582 list of commands in this category.
24583
24584 @findex COMMAND_FILES
24585 @findex gdb.COMMAND_FILES
24586 @item gdb.COMMAND_FILES
24587 This class is used for file-related commands.  For example,
24588 @code{file}, @code{list} and @code{section} are in this category.
24589 Type @kbd{help files} at the @value{GDBN} prompt to see a list of
24590 commands in this category.
24591
24592 @findex COMMAND_SUPPORT
24593 @findex gdb.COMMAND_SUPPORT
24594 @item gdb.COMMAND_SUPPORT
24595 This should be used for ``support facilities'', generally meaning
24596 things that are useful to the user when interacting with @value{GDBN},
24597 but not related to the state of the inferior.  For example,
24598 @code{help}, @code{make}, and @code{shell} are in this category.  Type
24599 @kbd{help support} at the @value{GDBN} prompt to see a list of
24600 commands in this category.
24601
24602 @findex COMMAND_STATUS
24603 @findex gdb.COMMAND_STATUS
24604 @item gdb.COMMAND_STATUS
24605 The command is an @samp{info}-related command, that is, related to the
24606 state of @value{GDBN} itself.  For example, @code{info}, @code{macro},
24607 and @code{show} are in this category.  Type @kbd{help status} at the
24608 @value{GDBN} prompt to see a list of commands in this category.
24609
24610 @findex COMMAND_BREAKPOINTS
24611 @findex gdb.COMMAND_BREAKPOINTS
24612 @item gdb.COMMAND_BREAKPOINTS
24613 The command has to do with breakpoints.  For example, @code{break},
24614 @code{clear}, and @code{delete} are in this category.  Type @kbd{help
24615 breakpoints} at the @value{GDBN} prompt to see a list of commands in
24616 this category.
24617
24618 @findex COMMAND_TRACEPOINTS
24619 @findex gdb.COMMAND_TRACEPOINTS
24620 @item gdb.COMMAND_TRACEPOINTS
24621 The command has to do with tracepoints.  For example, @code{trace},
24622 @code{actions}, and @code{tfind} are in this category.  Type
24623 @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
24624 commands in this category.
24625
24626 @findex COMMAND_USER
24627 @findex gdb.COMMAND_USER
24628 @item gdb.COMMAND_USER
24629 The command is a general purpose command for the user, and typically
24630 does not fit in one of the other categories.
24631 Type @kbd{help user-defined} at the @value{GDBN} prompt to see
24632 a list of commands in this category, as well as the list of gdb macros
24633 (@pxref{Sequences}).
24634
24635 @findex COMMAND_OBSCURE
24636 @findex gdb.COMMAND_OBSCURE
24637 @item gdb.COMMAND_OBSCURE
24638 The command is only used in unusual circumstances, or is not of
24639 general interest to users.  For example, @code{checkpoint},
24640 @code{fork}, and @code{stop} are in this category.  Type @kbd{help
24641 obscure} at the @value{GDBN} prompt to see a list of commands in this
24642 category.
24643
24644 @findex COMMAND_MAINTENANCE
24645 @findex gdb.COMMAND_MAINTENANCE
24646 @item gdb.COMMAND_MAINTENANCE
24647 The command is only useful to @value{GDBN} maintainers.  The
24648 @code{maintenance} and @code{flushregs} commands are in this category.
24649 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
24650 commands in this category.
24651 @end table
24652
24653 A new command can use a predefined completion function, either by
24654 specifying it via an argument at initialization, or by returning it
24655 from the @code{complete} method.  These predefined completion
24656 constants are all defined in the @code{gdb} module:
24657
24658 @table @code
24659 @findex COMPLETE_NONE
24660 @findex gdb.COMPLETE_NONE
24661 @item gdb.COMPLETE_NONE
24662 This constant means that no completion should be done.
24663
24664 @findex COMPLETE_FILENAME
24665 @findex gdb.COMPLETE_FILENAME
24666 @item gdb.COMPLETE_FILENAME
24667 This constant means that filename completion should be performed.
24668
24669 @findex COMPLETE_LOCATION
24670 @findex gdb.COMPLETE_LOCATION
24671 @item gdb.COMPLETE_LOCATION
24672 This constant means that location completion should be done.
24673 @xref{Specify Location}.
24674
24675 @findex COMPLETE_COMMAND
24676 @findex gdb.COMPLETE_COMMAND
24677 @item gdb.COMPLETE_COMMAND
24678 This constant means that completion should examine @value{GDBN}
24679 command names.
24680
24681 @findex COMPLETE_SYMBOL
24682 @findex gdb.COMPLETE_SYMBOL
24683 @item gdb.COMPLETE_SYMBOL
24684 This constant means that completion should be done using symbol names
24685 as the source.
24686 @end table
24687
24688 The following code snippet shows how a trivial CLI command can be
24689 implemented in Python:
24690
24691 @smallexample
24692 class HelloWorld (gdb.Command):
24693   """Greet the whole world."""
24694
24695   def __init__ (self):
24696     super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
24697
24698   def invoke (self, arg, from_tty):
24699     print "Hello, World!"
24700
24701 HelloWorld ()
24702 @end smallexample
24703
24704 The last line instantiates the class, and is necessary to trigger the
24705 registration of the command with @value{GDBN}.  Depending on how the
24706 Python code is read into @value{GDBN}, you may need to import the
24707 @code{gdb} module explicitly.
24708
24709 @node Parameters In Python
24710 @subsubsection Parameters In Python
24711
24712 @cindex parameters in python
24713 @cindex python parameters
24714 @tindex gdb.Parameter
24715 @tindex Parameter
24716 You can implement new @value{GDBN} parameters using Python.  A new
24717 parameter is implemented as an instance of the @code{gdb.Parameter}
24718 class.
24719
24720 Parameters are exposed to the user via the @code{set} and
24721 @code{show} commands.  @xref{Help}.
24722
24723 There are many parameters that already exist and can be set in
24724 @value{GDBN}.  Two examples are: @code{set follow fork} and
24725 @code{set charset}.  Setting these parameters influences certain
24726 behavior in @value{GDBN}.  Similarly, you can define parameters that
24727 can be used to influence behavior in custom Python scripts and commands.
24728
24729 @defun Parameter.__init__ (name, @var{command-class}, @var{parameter-class} @r{[}, @var{enum-sequence}@r{]})
24730 The object initializer for @code{Parameter} registers the new
24731 parameter with @value{GDBN}.  This initializer is normally invoked
24732 from the subclass' own @code{__init__} method.
24733
24734 @var{name} is the name of the new parameter.  If @var{name} consists
24735 of multiple words, then the initial words are looked for as prefix
24736 parameters.  An example of this can be illustrated with the
24737 @code{set print} set of parameters.  If @var{name} is
24738 @code{print foo}, then @code{print} will be searched as the prefix
24739 parameter.  In this case the parameter can subsequently be accessed in
24740 @value{GDBN} as @code{set print foo}.
24741
24742 If @var{name} consists of multiple words, and no prefix parameter group
24743 can be found, an exception is raised.
24744
24745 @var{command-class} should be one of the @samp{COMMAND_} constants
24746 (@pxref{Commands In Python}).  This argument tells @value{GDBN} how to
24747 categorize the new parameter in the help system.
24748
24749 @var{parameter-class} should be one of the @samp{PARAM_} constants
24750 defined below.  This argument tells @value{GDBN} the type of the new
24751 parameter; this information is used for input validation and
24752 completion.
24753
24754 If @var{parameter-class} is @code{PARAM_ENUM}, then
24755 @var{enum-sequence} must be a sequence of strings.  These strings
24756 represent the possible values for the parameter.
24757
24758 If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
24759 of a fourth argument will cause an exception to be thrown.
24760
24761 The help text for the new parameter is taken from the Python
24762 documentation string for the parameter's class, if there is one.  If
24763 there is no documentation string, a default value is used.
24764 @end defun
24765
24766 @defvar Parameter.set_doc
24767 If this attribute exists, and is a string, then its value is used as
24768 the help text for this parameter's @code{set} command.  The value is
24769 examined when @code{Parameter.__init__} is invoked; subsequent changes
24770 have no effect.
24771 @end defvar
24772
24773 @defvar Parameter.show_doc
24774 If this attribute exists, and is a string, then its value is used as
24775 the help text for this parameter's @code{show} command.  The value is
24776 examined when @code{Parameter.__init__} is invoked; subsequent changes
24777 have no effect.
24778 @end defvar
24779
24780 @defvar Parameter.value
24781 The @code{value} attribute holds the underlying value of the
24782 parameter.  It can be read and assigned to just as any other
24783 attribute.  @value{GDBN} does validation when assignments are made.
24784 @end defvar
24785
24786 There are two methods that should be implemented in any
24787 @code{Parameter} class.  These are:
24788
24789 @defun Parameter.get_set_string (self)
24790 @value{GDBN} will call this method when a @var{parameter}'s value has
24791 been changed via the @code{set} API (for example, @kbd{set foo off}).
24792 The @code{value} attribute has already been populated with the new
24793 value and may be used in output.  This method must return a string.
24794 @end defun
24795
24796 @defun Parameter.get_show_string (self, svalue)
24797 @value{GDBN} will call this method when a @var{parameter}'s
24798 @code{show} API has been invoked (for example, @kbd{show foo}).  The
24799 argument @code{svalue} receives the string representation of the
24800 current value.  This method must return a string.
24801 @end defun
24802
24803 When a new parameter is defined, its type must be specified.  The
24804 available types are represented by constants defined in the @code{gdb}
24805 module:
24806
24807 @table @code
24808 @findex PARAM_BOOLEAN
24809 @findex gdb.PARAM_BOOLEAN
24810 @item gdb.PARAM_BOOLEAN
24811 The value is a plain boolean.  The Python boolean values, @code{True}
24812 and @code{False} are the only valid values.
24813
24814 @findex PARAM_AUTO_BOOLEAN
24815 @findex gdb.PARAM_AUTO_BOOLEAN
24816 @item gdb.PARAM_AUTO_BOOLEAN
24817 The value has three possible states: true, false, and @samp{auto}.  In
24818 Python, true and false are represented using boolean constants, and
24819 @samp{auto} is represented using @code{None}.
24820
24821 @findex PARAM_UINTEGER
24822 @findex gdb.PARAM_UINTEGER
24823 @item gdb.PARAM_UINTEGER
24824 The value is an unsigned integer.  The value of 0 should be
24825 interpreted to mean ``unlimited''.
24826
24827 @findex PARAM_INTEGER
24828 @findex gdb.PARAM_INTEGER
24829 @item gdb.PARAM_INTEGER
24830 The value is a signed integer.  The value of 0 should be interpreted
24831 to mean ``unlimited''.
24832
24833 @findex PARAM_STRING
24834 @findex gdb.PARAM_STRING
24835 @item gdb.PARAM_STRING
24836 The value is a string.  When the user modifies the string, any escape
24837 sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
24838 translated into corresponding characters and encoded into the current
24839 host charset.
24840
24841 @findex PARAM_STRING_NOESCAPE
24842 @findex gdb.PARAM_STRING_NOESCAPE
24843 @item gdb.PARAM_STRING_NOESCAPE
24844 The value is a string.  When the user modifies the string, escapes are
24845 passed through untranslated.
24846
24847 @findex PARAM_OPTIONAL_FILENAME
24848 @findex gdb.PARAM_OPTIONAL_FILENAME
24849 @item gdb.PARAM_OPTIONAL_FILENAME
24850 The value is a either a filename (a string), or @code{None}.
24851
24852 @findex PARAM_FILENAME
24853 @findex gdb.PARAM_FILENAME
24854 @item gdb.PARAM_FILENAME
24855 The value is a filename.  This is just like
24856 @code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
24857
24858 @findex PARAM_ZINTEGER
24859 @findex gdb.PARAM_ZINTEGER
24860 @item gdb.PARAM_ZINTEGER
24861 The value is an integer.  This is like @code{PARAM_INTEGER}, except 0
24862 is interpreted as itself.
24863
24864 @findex PARAM_ENUM
24865 @findex gdb.PARAM_ENUM
24866 @item gdb.PARAM_ENUM
24867 The value is a string, which must be one of a collection string
24868 constants provided when the parameter is created.
24869 @end table
24870
24871 @node Functions In Python
24872 @subsubsection Writing new convenience functions
24873
24874 @cindex writing convenience functions
24875 @cindex convenience functions in python
24876 @cindex python convenience functions
24877 @tindex gdb.Function
24878 @tindex Function
24879 You can implement new convenience functions (@pxref{Convenience Vars})
24880 in Python.  A convenience function is an instance of a subclass of the
24881 class @code{gdb.Function}.
24882
24883 @defun Function.__init__ (name)
24884 The initializer for @code{Function} registers the new function with
24885 @value{GDBN}.  The argument @var{name} is the name of the function,
24886 a string.  The function will be visible to the user as a convenience
24887 variable of type @code{internal function}, whose name is the same as
24888 the given @var{name}.
24889
24890 The documentation for the new function is taken from the documentation
24891 string for the new class.
24892 @end defun
24893
24894 @defun Function.invoke (@var{*args})
24895 When a convenience function is evaluated, its arguments are converted
24896 to instances of @code{gdb.Value}, and then the function's
24897 @code{invoke} method is called.  Note that @value{GDBN} does not
24898 predetermine the arity of convenience functions.  Instead, all
24899 available arguments are passed to @code{invoke}, following the
24900 standard Python calling convention.  In particular, a convenience
24901 function can have default values for parameters without ill effect.
24902
24903 The return value of this method is used as its value in the enclosing
24904 expression.  If an ordinary Python value is returned, it is converted
24905 to a @code{gdb.Value} following the usual rules.
24906 @end defun
24907
24908 The following code snippet shows how a trivial convenience function can
24909 be implemented in Python:
24910
24911 @smallexample
24912 class Greet (gdb.Function):
24913   """Return string to greet someone.
24914 Takes a name as argument."""
24915
24916   def __init__ (self):
24917     super (Greet, self).__init__ ("greet")
24918
24919   def invoke (self, name):
24920     return "Hello, %s!" % name.string ()
24921
24922 Greet ()
24923 @end smallexample
24924
24925 The last line instantiates the class, and is necessary to trigger the
24926 registration of the function with @value{GDBN}.  Depending on how the
24927 Python code is read into @value{GDBN}, you may need to import the
24928 @code{gdb} module explicitly.
24929
24930 Now you can use the function in an expression:
24931
24932 @smallexample
24933 (gdb) print $greet("Bob")
24934 $1 = "Hello, Bob!"
24935 @end smallexample
24936
24937 @node Progspaces In Python
24938 @subsubsection Program Spaces In Python
24939
24940 @cindex progspaces in python
24941 @tindex gdb.Progspace
24942 @tindex Progspace
24943 A program space, or @dfn{progspace}, represents a symbolic view
24944 of an address space.
24945 It consists of all of the objfiles of the program.
24946 @xref{Objfiles In Python}.
24947 @xref{Inferiors and Programs, program spaces}, for more details
24948 about program spaces.
24949
24950 The following progspace-related functions are available in the
24951 @code{gdb} module:
24952
24953 @findex gdb.current_progspace
24954 @defun gdb.current_progspace ()
24955 This function returns the program space of the currently selected inferior.
24956 @xref{Inferiors and Programs}.
24957 @end defun
24958
24959 @findex gdb.progspaces
24960 @defun gdb.progspaces ()
24961 Return a sequence of all the progspaces currently known to @value{GDBN}.
24962 @end defun
24963
24964 Each progspace is represented by an instance of the @code{gdb.Progspace}
24965 class.
24966
24967 @defvar Progspace.filename
24968 The file name of the progspace as a string.
24969 @end defvar
24970
24971 @defvar Progspace.pretty_printers
24972 The @code{pretty_printers} attribute is a list of functions.  It is
24973 used to look up pretty-printers.  A @code{Value} is passed to each
24974 function in order; if the function returns @code{None}, then the
24975 search continues.  Otherwise, the return value should be an object
24976 which is used to format the value.  @xref{Pretty Printing API}, for more
24977 information.
24978 @end defvar
24979
24980 @defvar Progspace.type_printers
24981 The @code{type_printers} attribute is a list of type printer objects.
24982 @xref{Type Printing API}, for more information.
24983 @end defvar
24984
24985 @node Objfiles In Python
24986 @subsubsection Objfiles In Python
24987
24988 @cindex objfiles in python
24989 @tindex gdb.Objfile
24990 @tindex Objfile
24991 @value{GDBN} loads symbols for an inferior from various
24992 symbol-containing files (@pxref{Files}).  These include the primary
24993 executable file, any shared libraries used by the inferior, and any
24994 separate debug info files (@pxref{Separate Debug Files}).
24995 @value{GDBN} calls these symbol-containing files @dfn{objfiles}.
24996
24997 The following objfile-related functions are available in the
24998 @code{gdb} module:
24999
25000 @findex gdb.current_objfile
25001 @defun gdb.current_objfile ()
25002 When auto-loading a Python script (@pxref{Python Auto-loading}), @value{GDBN}
25003 sets the ``current objfile'' to the corresponding objfile.  This
25004 function returns the current objfile.  If there is no current objfile,
25005 this function returns @code{None}.
25006 @end defun
25007
25008 @findex gdb.objfiles
25009 @defun gdb.objfiles ()
25010 Return a sequence of all the objfiles current known to @value{GDBN}.
25011 @xref{Objfiles In Python}.
25012 @end defun
25013
25014 Each objfile is represented by an instance of the @code{gdb.Objfile}
25015 class.
25016
25017 @defvar Objfile.filename
25018 The file name of the objfile as a string.
25019 @end defvar
25020
25021 @defvar Objfile.pretty_printers
25022 The @code{pretty_printers} attribute is a list of functions.  It is
25023 used to look up pretty-printers.  A @code{Value} is passed to each
25024 function in order; if the function returns @code{None}, then the
25025 search continues.  Otherwise, the return value should be an object
25026 which is used to format the value.  @xref{Pretty Printing API}, for more
25027 information.
25028 @end defvar
25029
25030 @defvar Objfile.type_printers
25031 The @code{type_printers} attribute is a list of type printer objects.
25032 @xref{Type Printing API}, for more information.
25033 @end defvar
25034
25035 A @code{gdb.Objfile} object has the following methods:
25036
25037 @defun Objfile.is_valid ()
25038 Returns @code{True} if the @code{gdb.Objfile} object is valid,
25039 @code{False} if not.  A @code{gdb.Objfile} object can become invalid
25040 if the object file it refers to is not loaded in @value{GDBN} any
25041 longer.  All other @code{gdb.Objfile} methods will throw an exception
25042 if it is invalid at the time the method is called.
25043 @end defun
25044
25045 @node Frames In Python
25046 @subsubsection Accessing inferior stack frames from Python.
25047
25048 @cindex frames in python
25049 When the debugged program stops, @value{GDBN} is able to analyze its call
25050 stack (@pxref{Frames,,Stack frames}).  The @code{gdb.Frame} class
25051 represents a frame in the stack.  A @code{gdb.Frame} object is only valid
25052 while its corresponding frame exists in the inferior's stack.  If you try
25053 to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
25054 exception (@pxref{Exception Handling}).
25055
25056 Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
25057 operator, like:
25058
25059 @smallexample
25060 (@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
25061 True
25062 @end smallexample
25063
25064 The following frame-related functions are available in the @code{gdb} module:
25065
25066 @findex gdb.selected_frame
25067 @defun gdb.selected_frame ()
25068 Return the selected frame object.  (@pxref{Selection,,Selecting a Frame}).
25069 @end defun
25070
25071 @findex gdb.newest_frame
25072 @defun gdb.newest_frame ()
25073 Return the newest frame object for the selected thread.
25074 @end defun
25075
25076 @defun gdb.frame_stop_reason_string (reason)
25077 Return a string explaining the reason why @value{GDBN} stopped unwinding
25078 frames, as expressed by the given @var{reason} code (an integer, see the
25079 @code{unwind_stop_reason} method further down in this section).
25080 @end defun
25081
25082 A @code{gdb.Frame} object has the following methods:
25083
25084 @table @code
25085 @defun Frame.is_valid ()
25086 Returns true if the @code{gdb.Frame} object is valid, false if not.
25087 A frame object can become invalid if the frame it refers to doesn't
25088 exist anymore in the inferior.  All @code{gdb.Frame} methods will throw
25089 an exception if it is invalid at the time the method is called.
25090 @end defun
25091
25092 @defun Frame.name ()
25093 Returns the function name of the frame, or @code{None} if it can't be
25094 obtained.
25095 @end defun
25096
25097 @defun Frame.type ()
25098 Returns the type of the frame.  The value can be one of:
25099 @table @code
25100 @item gdb.NORMAL_FRAME
25101 An ordinary stack frame.
25102
25103 @item gdb.DUMMY_FRAME
25104 A fake stack frame that was created by @value{GDBN} when performing an
25105 inferior function call.
25106
25107 @item gdb.INLINE_FRAME
25108 A frame representing an inlined function.  The function was inlined
25109 into a @code{gdb.NORMAL_FRAME} that is older than this one.
25110
25111 @item gdb.TAILCALL_FRAME
25112 A frame representing a tail call.  @xref{Tail Call Frames}.
25113
25114 @item gdb.SIGTRAMP_FRAME
25115 A signal trampoline frame.  This is the frame created by the OS when
25116 it calls into a signal handler.
25117
25118 @item gdb.ARCH_FRAME
25119 A fake stack frame representing a cross-architecture call.
25120
25121 @item gdb.SENTINEL_FRAME
25122 This is like @code{gdb.NORMAL_FRAME}, but it is only used for the
25123 newest frame.
25124 @end table
25125 @end defun
25126
25127 @defun Frame.unwind_stop_reason ()
25128 Return an integer representing the reason why it's not possible to find
25129 more frames toward the outermost frame.  Use
25130 @code{gdb.frame_stop_reason_string} to convert the value returned by this
25131 function to a string. The value can be one of:
25132
25133 @table @code
25134 @item gdb.FRAME_UNWIND_NO_REASON
25135 No particular reason (older frames should be available).
25136
25137 @item gdb.FRAME_UNWIND_NULL_ID
25138 The previous frame's analyzer returns an invalid result.
25139
25140 @item gdb.FRAME_UNWIND_OUTERMOST
25141 This frame is the outermost.
25142
25143 @item gdb.FRAME_UNWIND_UNAVAILABLE
25144 Cannot unwind further, because that would require knowing the 
25145 values of registers or memory that have not been collected.
25146
25147 @item gdb.FRAME_UNWIND_INNER_ID
25148 This frame ID looks like it ought to belong to a NEXT frame,
25149 but we got it for a PREV frame.  Normally, this is a sign of
25150 unwinder failure.  It could also indicate stack corruption.
25151
25152 @item gdb.FRAME_UNWIND_SAME_ID
25153 This frame has the same ID as the previous one.  That means
25154 that unwinding further would almost certainly give us another
25155 frame with exactly the same ID, so break the chain.  Normally,
25156 this is a sign of unwinder failure.  It could also indicate
25157 stack corruption.
25158
25159 @item gdb.FRAME_UNWIND_NO_SAVED_PC
25160 The frame unwinder did not find any saved PC, but we needed
25161 one to unwind further.
25162
25163 @item gdb.FRAME_UNWIND_FIRST_ERROR
25164 Any stop reason greater or equal to this value indicates some kind
25165 of error.  This special value facilitates writing code that tests
25166 for errors in unwinding in a way that will work correctly even if
25167 the list of the other values is modified in future @value{GDBN}
25168 versions.  Using it, you could write:
25169 @smallexample
25170 reason = gdb.selected_frame().unwind_stop_reason ()
25171 reason_str =  gdb.frame_stop_reason_string (reason)
25172 if reason >=  gdb.FRAME_UNWIND_FIRST_ERROR:
25173     print "An error occured: %s" % reason_str
25174 @end smallexample
25175 @end table
25176
25177 @end defun
25178
25179 @defun Frame.pc ()
25180 Returns the frame's resume address.
25181 @end defun
25182
25183 @defun Frame.block ()
25184 Return the frame's code block.  @xref{Blocks In Python}.
25185 @end defun
25186
25187 @defun Frame.function ()
25188 Return the symbol for the function corresponding to this frame.
25189 @xref{Symbols In Python}.
25190 @end defun
25191
25192 @defun Frame.older ()
25193 Return the frame that called this frame.
25194 @end defun
25195
25196 @defun Frame.newer ()
25197 Return the frame called by this frame.
25198 @end defun
25199
25200 @defun Frame.find_sal ()
25201 Return the frame's symtab and line object.
25202 @xref{Symbol Tables In Python}.
25203 @end defun
25204
25205 @defun Frame.read_var (variable @r{[}, block@r{]})
25206 Return the value of @var{variable} in this frame.  If the optional
25207 argument @var{block} is provided, search for the variable from that
25208 block; otherwise start at the frame's current block (which is
25209 determined by the frame's current program counter).  @var{variable}
25210 must be a string or a @code{gdb.Symbol} object.  @var{block} must be a
25211 @code{gdb.Block} object.
25212 @end defun
25213
25214 @defun Frame.select ()
25215 Set this frame to be the selected frame.  @xref{Stack, ,Examining the
25216 Stack}.
25217 @end defun
25218 @end table
25219
25220 @node Blocks In Python
25221 @subsubsection Accessing frame blocks from Python.
25222
25223 @cindex blocks in python
25224 @tindex gdb.Block
25225
25226 Within each frame, @value{GDBN} maintains information on each block
25227 stored in that frame.  These blocks are organized hierarchically, and
25228 are represented individually in Python as a @code{gdb.Block}.
25229 Please see @ref{Frames In Python}, for a more in-depth discussion on
25230 frames.  Furthermore, see @ref{Stack, ,Examining the Stack}, for more
25231 detailed technical information on @value{GDBN}'s book-keeping of the
25232 stack.
25233
25234 A @code{gdb.Block} is iterable.  The iterator returns the symbols
25235 (@pxref{Symbols In Python}) local to the block.  Python programs
25236 should not assume that a specific block object will always contain a
25237 given symbol, since changes in @value{GDBN} features and
25238 infrastructure may cause symbols move across blocks in a symbol
25239 table.
25240
25241 The following block-related functions are available in the @code{gdb}
25242 module:
25243
25244 @findex gdb.block_for_pc
25245 @defun gdb.block_for_pc (pc)
25246 Return the @code{gdb.Block} containing the given @var{pc} value.  If the
25247 block cannot be found for the @var{pc} value specified, the function
25248 will return @code{None}.
25249 @end defun
25250
25251 A @code{gdb.Block} object has the following methods:
25252
25253 @table @code
25254 @defun Block.is_valid ()
25255 Returns @code{True} if the @code{gdb.Block} object is valid,
25256 @code{False} if not.  A block object can become invalid if the block it
25257 refers to doesn't exist anymore in the inferior.  All other
25258 @code{gdb.Block} methods will throw an exception if it is invalid at
25259 the time the method is called.  The block's validity is also checked
25260 during iteration over symbols of the block.
25261 @end defun
25262 @end table
25263
25264 A @code{gdb.Block} object has the following attributes:
25265
25266 @table @code
25267 @defvar Block.start
25268 The start address of the block.  This attribute is not writable.
25269 @end defvar
25270
25271 @defvar Block.end
25272 The end address of the block.  This attribute is not writable.
25273 @end defvar
25274
25275 @defvar Block.function
25276 The name of the block represented as a @code{gdb.Symbol}.  If the
25277 block is not named, then this attribute holds @code{None}.  This
25278 attribute is not writable.
25279 @end defvar
25280
25281 @defvar Block.superblock
25282 The block containing this block.  If this parent block does not exist,
25283 this attribute holds @code{None}.  This attribute is not writable.
25284 @end defvar
25285
25286 @defvar Block.global_block
25287 The global block associated with this block.  This attribute is not
25288 writable.
25289 @end defvar
25290
25291 @defvar Block.static_block
25292 The static block associated with this block.  This attribute is not
25293 writable.
25294 @end defvar
25295
25296 @defvar Block.is_global
25297 @code{True} if the @code{gdb.Block} object is a global block,
25298 @code{False} if not.  This attribute is not
25299 writable.
25300 @end defvar
25301
25302 @defvar Block.is_static
25303 @code{True} if the @code{gdb.Block} object is a static block,
25304 @code{False} if not.  This attribute is not writable.
25305 @end defvar
25306 @end table
25307
25308 @node Symbols In Python
25309 @subsubsection Python representation of Symbols.
25310
25311 @cindex symbols in python
25312 @tindex gdb.Symbol
25313
25314 @value{GDBN} represents every variable, function and type as an
25315 entry in a symbol table.  @xref{Symbols, ,Examining the Symbol Table}.
25316 Similarly, Python represents these symbols in @value{GDBN} with the
25317 @code{gdb.Symbol} object.
25318
25319 The following symbol-related functions are available in the @code{gdb}
25320 module:
25321
25322 @findex gdb.lookup_symbol
25323 @defun gdb.lookup_symbol (name @r{[}, block @r{[}, domain@r{]]})
25324 This function searches for a symbol by name.  The search scope can be
25325 restricted to the parameters defined in the optional domain and block
25326 arguments.
25327
25328 @var{name} is the name of the symbol.  It must be a string.  The
25329 optional @var{block} argument restricts the search to symbols visible
25330 in that @var{block}.  The @var{block} argument must be a
25331 @code{gdb.Block} object.  If omitted, the block for the current frame
25332 is used.  The optional @var{domain} argument restricts
25333 the search to the domain type.  The @var{domain} argument must be a
25334 domain constant defined in the @code{gdb} module and described later
25335 in this chapter.
25336
25337 The result is a tuple of two elements.
25338 The first element is a @code{gdb.Symbol} object or @code{None} if the symbol
25339 is not found.
25340 If the symbol is found, the second element is @code{True} if the symbol
25341 is a field of a method's object (e.g., @code{this} in C@t{++}),
25342 otherwise it is @code{False}.
25343 If the symbol is not found, the second element is @code{False}.
25344 @end defun
25345
25346 @findex gdb.lookup_global_symbol
25347 @defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
25348 This function searches for a global symbol by name.
25349 The search scope can be restricted to by the domain argument.
25350
25351 @var{name} is the name of the symbol.  It must be a string.
25352 The optional @var{domain} argument restricts the search to the domain type.
25353 The @var{domain} argument must be a domain constant defined in the @code{gdb}
25354 module and described later in this chapter.
25355
25356 The result is a @code{gdb.Symbol} object or @code{None} if the symbol
25357 is not found.
25358 @end defun
25359
25360 A @code{gdb.Symbol} object has the following attributes:
25361
25362 @table @code
25363 @defvar Symbol.type
25364 The type of the symbol or @code{None} if no type is recorded.
25365 This attribute is represented as a @code{gdb.Type} object.
25366 @xref{Types In Python}.  This attribute is not writable.
25367 @end defvar
25368
25369 @defvar Symbol.symtab
25370 The symbol table in which the symbol appears.  This attribute is
25371 represented as a @code{gdb.Symtab} object.  @xref{Symbol Tables In
25372 Python}.  This attribute is not writable.
25373 @end defvar
25374
25375 @defvar Symbol.line
25376 The line number in the source code at which the symbol was defined.
25377 This is an integer.
25378 @end defvar
25379
25380 @defvar Symbol.name
25381 The name of the symbol as a string.  This attribute is not writable.
25382 @end defvar
25383
25384 @defvar Symbol.linkage_name
25385 The name of the symbol, as used by the linker (i.e., may be mangled).
25386 This attribute is not writable.
25387 @end defvar
25388
25389 @defvar Symbol.print_name
25390 The name of the symbol in a form suitable for output.  This is either
25391 @code{name} or @code{linkage_name}, depending on whether the user
25392 asked @value{GDBN} to display demangled or mangled names.
25393 @end defvar
25394
25395 @defvar Symbol.addr_class
25396 The address class of the symbol.  This classifies how to find the value
25397 of a symbol.  Each address class is a constant defined in the
25398 @code{gdb} module and described later in this chapter.
25399 @end defvar
25400
25401 @defvar Symbol.needs_frame
25402 This is @code{True} if evaluating this symbol's value requires a frame
25403 (@pxref{Frames In Python}) and @code{False} otherwise.  Typically,
25404 local variables will require a frame, but other symbols will not.
25405 @end defvar
25406
25407 @defvar Symbol.is_argument
25408 @code{True} if the symbol is an argument of a function.
25409 @end defvar
25410
25411 @defvar Symbol.is_constant
25412 @code{True} if the symbol is a constant.
25413 @end defvar
25414
25415 @defvar Symbol.is_function
25416 @code{True} if the symbol is a function or a method.
25417 @end defvar
25418
25419 @defvar Symbol.is_variable
25420 @code{True} if the symbol is a variable.
25421 @end defvar
25422 @end table
25423
25424 A @code{gdb.Symbol} object has the following methods:
25425
25426 @table @code
25427 @defun Symbol.is_valid ()
25428 Returns @code{True} if the @code{gdb.Symbol} object is valid,
25429 @code{False} if not.  A @code{gdb.Symbol} object can become invalid if
25430 the symbol it refers to does not exist in @value{GDBN} any longer.
25431 All other @code{gdb.Symbol} methods will throw an exception if it is
25432 invalid at the time the method is called.
25433 @end defun
25434
25435 @defun Symbol.value (@r{[}frame@r{]})
25436 Compute the value of the symbol, as a @code{gdb.Value}.  For
25437 functions, this computes the address of the function, cast to the
25438 appropriate type.  If the symbol requires a frame in order to compute
25439 its value, then @var{frame} must be given.  If @var{frame} is not
25440 given, or if @var{frame} is invalid, then this method will throw an
25441 exception.
25442 @end defun
25443 @end table
25444
25445 The available domain categories in @code{gdb.Symbol} are represented
25446 as constants in the @code{gdb} module:
25447
25448 @table @code
25449 @findex SYMBOL_UNDEF_DOMAIN
25450 @findex gdb.SYMBOL_UNDEF_DOMAIN
25451 @item gdb.SYMBOL_UNDEF_DOMAIN
25452 This is used when a domain has not been discovered or none of the
25453 following domains apply.  This usually indicates an error either
25454 in the symbol information or in @value{GDBN}'s handling of symbols.
25455 @findex SYMBOL_VAR_DOMAIN
25456 @findex gdb.SYMBOL_VAR_DOMAIN
25457 @item gdb.SYMBOL_VAR_DOMAIN
25458 This domain contains variables, function names, typedef names and enum
25459 type values.
25460 @findex SYMBOL_STRUCT_DOMAIN
25461 @findex gdb.SYMBOL_STRUCT_DOMAIN
25462 @item gdb.SYMBOL_STRUCT_DOMAIN
25463 This domain holds struct, union and enum type names.
25464 @findex SYMBOL_LABEL_DOMAIN
25465 @findex gdb.SYMBOL_LABEL_DOMAIN
25466 @item gdb.SYMBOL_LABEL_DOMAIN
25467 This domain contains names of labels (for gotos).
25468 @findex SYMBOL_VARIABLES_DOMAIN
25469 @findex gdb.SYMBOL_VARIABLES_DOMAIN
25470 @item gdb.SYMBOL_VARIABLES_DOMAIN
25471 This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
25472 contains everything minus functions and types.
25473 @findex SYMBOL_FUNCTIONS_DOMAIN
25474 @findex gdb.SYMBOL_FUNCTIONS_DOMAIN
25475 @item gdb.SYMBOL_FUNCTION_DOMAIN
25476 This domain contains all functions.
25477 @findex SYMBOL_TYPES_DOMAIN
25478 @findex gdb.SYMBOL_TYPES_DOMAIN
25479 @item gdb.SYMBOL_TYPES_DOMAIN
25480 This domain contains all types.
25481 @end table
25482
25483 The available address class categories in @code{gdb.Symbol} are represented
25484 as constants in the @code{gdb} module:
25485
25486 @table @code
25487 @findex SYMBOL_LOC_UNDEF
25488 @findex gdb.SYMBOL_LOC_UNDEF
25489 @item gdb.SYMBOL_LOC_UNDEF
25490 If this is returned by address class, it indicates an error either in
25491 the symbol information or in @value{GDBN}'s handling of symbols.
25492 @findex SYMBOL_LOC_CONST
25493 @findex gdb.SYMBOL_LOC_CONST
25494 @item gdb.SYMBOL_LOC_CONST
25495 Value is constant int.
25496 @findex SYMBOL_LOC_STATIC
25497 @findex gdb.SYMBOL_LOC_STATIC
25498 @item gdb.SYMBOL_LOC_STATIC
25499 Value is at a fixed address.
25500 @findex SYMBOL_LOC_REGISTER
25501 @findex gdb.SYMBOL_LOC_REGISTER
25502 @item gdb.SYMBOL_LOC_REGISTER
25503 Value is in a register.
25504 @findex SYMBOL_LOC_ARG
25505 @findex gdb.SYMBOL_LOC_ARG
25506 @item gdb.SYMBOL_LOC_ARG
25507 Value is an argument.  This value is at the offset stored within the
25508 symbol inside the frame's argument list.
25509 @findex SYMBOL_LOC_REF_ARG
25510 @findex gdb.SYMBOL_LOC_REF_ARG
25511 @item gdb.SYMBOL_LOC_REF_ARG
25512 Value address is stored in the frame's argument list.  Just like
25513 @code{LOC_ARG} except that the value's address is stored at the
25514 offset, not the value itself.
25515 @findex SYMBOL_LOC_REGPARM_ADDR
25516 @findex gdb.SYMBOL_LOC_REGPARM_ADDR
25517 @item gdb.SYMBOL_LOC_REGPARM_ADDR
25518 Value is a specified register.  Just like @code{LOC_REGISTER} except
25519 the register holds the address of the argument instead of the argument
25520 itself.
25521 @findex SYMBOL_LOC_LOCAL
25522 @findex gdb.SYMBOL_LOC_LOCAL
25523 @item gdb.SYMBOL_LOC_LOCAL
25524 Value is a local variable.
25525 @findex SYMBOL_LOC_TYPEDEF
25526 @findex gdb.SYMBOL_LOC_TYPEDEF
25527 @item gdb.SYMBOL_LOC_TYPEDEF
25528 Value not used.  Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
25529 have this class.
25530 @findex SYMBOL_LOC_BLOCK
25531 @findex gdb.SYMBOL_LOC_BLOCK
25532 @item gdb.SYMBOL_LOC_BLOCK
25533 Value is a block.
25534 @findex SYMBOL_LOC_CONST_BYTES
25535 @findex gdb.SYMBOL_LOC_CONST_BYTES
25536 @item gdb.SYMBOL_LOC_CONST_BYTES
25537 Value is a byte-sequence.
25538 @findex SYMBOL_LOC_UNRESOLVED
25539 @findex gdb.SYMBOL_LOC_UNRESOLVED
25540 @item gdb.SYMBOL_LOC_UNRESOLVED
25541 Value is at a fixed address, but the address of the variable has to be
25542 determined from the minimal symbol table whenever the variable is
25543 referenced.
25544 @findex SYMBOL_LOC_OPTIMIZED_OUT
25545 @findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
25546 @item gdb.SYMBOL_LOC_OPTIMIZED_OUT
25547 The value does not actually exist in the program.
25548 @findex SYMBOL_LOC_COMPUTED
25549 @findex gdb.SYMBOL_LOC_COMPUTED
25550 @item gdb.SYMBOL_LOC_COMPUTED
25551 The value's address is a computed location.
25552 @end table
25553
25554 @node Symbol Tables In Python
25555 @subsubsection Symbol table representation in Python.
25556
25557 @cindex symbol tables in python
25558 @tindex gdb.Symtab
25559 @tindex gdb.Symtab_and_line
25560
25561 Access to symbol table data maintained by @value{GDBN} on the inferior
25562 is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
25563 @code{gdb.Symtab}.  Symbol table and line data for a frame is returned
25564 from the @code{find_sal} method in @code{gdb.Frame} object.
25565 @xref{Frames In Python}.
25566
25567 For more information on @value{GDBN}'s symbol table management, see
25568 @ref{Symbols, ,Examining the Symbol Table}, for more information.
25569
25570 A @code{gdb.Symtab_and_line} object has the following attributes:
25571
25572 @table @code
25573 @defvar Symtab_and_line.symtab
25574 The symbol table object (@code{gdb.Symtab}) for this frame.
25575 This attribute is not writable.
25576 @end defvar
25577
25578 @defvar Symtab_and_line.pc
25579 Indicates the start of the address range occupied by code for the
25580 current source line.  This attribute is not writable.
25581 @end defvar
25582
25583 @defvar Symtab_and_line.last
25584 Indicates the end of the address range occupied by code for the current
25585 source line.  This attribute is not writable.
25586 @end defvar
25587
25588 @defvar Symtab_and_line.line
25589 Indicates the current line number for this object.  This
25590 attribute is not writable.
25591 @end defvar
25592 @end table
25593
25594 A @code{gdb.Symtab_and_line} object has the following methods:
25595
25596 @table @code
25597 @defun Symtab_and_line.is_valid ()
25598 Returns @code{True} if the @code{gdb.Symtab_and_line} object is valid,
25599 @code{False} if not.  A @code{gdb.Symtab_and_line} object can become
25600 invalid if the Symbol table and line object it refers to does not
25601 exist in @value{GDBN} any longer.  All other
25602 @code{gdb.Symtab_and_line} methods will throw an exception if it is
25603 invalid at the time the method is called.
25604 @end defun
25605 @end table
25606
25607 A @code{gdb.Symtab} object has the following attributes:
25608
25609 @table @code
25610 @defvar Symtab.filename
25611 The symbol table's source filename.  This attribute is not writable.
25612 @end defvar
25613
25614 @defvar Symtab.objfile
25615 The symbol table's backing object file.  @xref{Objfiles In Python}.
25616 This attribute is not writable.
25617 @end defvar
25618 @end table
25619
25620 A @code{gdb.Symtab} object has the following methods:
25621
25622 @table @code
25623 @defun Symtab.is_valid ()
25624 Returns @code{True} if the @code{gdb.Symtab} object is valid,
25625 @code{False} if not.  A @code{gdb.Symtab} object can become invalid if
25626 the symbol table it refers to does not exist in @value{GDBN} any
25627 longer.  All other @code{gdb.Symtab} methods will throw an exception
25628 if it is invalid at the time the method is called.
25629 @end defun
25630
25631 @defun Symtab.fullname ()
25632 Return the symbol table's source absolute file name.
25633 @end defun
25634
25635 @defun Symtab.global_block ()
25636 Return the global block of the underlying symbol table.
25637 @xref{Blocks In Python}.
25638 @end defun
25639
25640 @defun Symtab.static_block ()
25641 Return the static block of the underlying symbol table.
25642 @xref{Blocks In Python}.
25643 @end defun
25644 @end table
25645
25646 @node Breakpoints In Python
25647 @subsubsection Manipulating breakpoints using Python
25648
25649 @cindex breakpoints in python
25650 @tindex gdb.Breakpoint
25651
25652 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
25653 class.
25654
25655 @defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
25656 Create a new breakpoint.  @var{spec} is a string naming the
25657 location of the breakpoint, or an expression that defines a
25658 watchpoint.  The contents can be any location recognized by the
25659 @code{break} command, or in the case of a watchpoint, by the @code{watch}
25660 command.  The optional @var{type} denotes the breakpoint to create
25661 from the types defined later in this chapter.  This argument can be
25662 either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}.  @var{type}
25663 defaults to @code{gdb.BP_BREAKPOINT}.  The optional @var{internal} argument
25664 allows the breakpoint to become invisible to the user.  The breakpoint
25665 will neither be reported when created, nor will it be listed in the
25666 output from @code{info breakpoints} (but will be listed with the
25667 @code{maint info breakpoints} command).  The optional @var{wp_class}
25668 argument defines the class of watchpoint to create, if @var{type} is
25669 @code{gdb.BP_WATCHPOINT}.  If a watchpoint class is not provided, it is
25670 assumed to be a @code{gdb.WP_WRITE} class.
25671 @end defun
25672
25673 @defun Breakpoint.stop (self)
25674 The @code{gdb.Breakpoint} class can be sub-classed and, in
25675 particular, you may choose to implement the @code{stop} method.
25676 If this method is defined as a sub-class of @code{gdb.Breakpoint},
25677 it will be called when the inferior reaches any location of a
25678 breakpoint which instantiates that sub-class.  If the method returns
25679 @code{True}, the inferior will be stopped at the location of the
25680 breakpoint, otherwise the inferior will continue.
25681
25682 If there are multiple breakpoints at the same location with a
25683 @code{stop} method, each one will be called regardless of the
25684 return status of the previous.  This ensures that all @code{stop}
25685 methods have a chance to execute at that location.  In this scenario
25686 if one of the methods returns @code{True} but the others return
25687 @code{False}, the inferior will still be stopped.
25688
25689 You should not alter the execution state of the inferior (i.e.@:, step,
25690 next, etc.), alter the current frame context (i.e.@:, change the current
25691 active frame), or alter, add or delete any breakpoint.  As a general
25692 rule, you should not alter any data within @value{GDBN} or the inferior
25693 at this time.
25694
25695 Example @code{stop} implementation:
25696
25697 @smallexample
25698 class MyBreakpoint (gdb.Breakpoint):
25699       def stop (self):
25700         inf_val = gdb.parse_and_eval("foo")
25701         if inf_val == 3:
25702           return True
25703         return False
25704 @end smallexample
25705 @end defun
25706
25707 The available watchpoint types represented by constants are defined in the
25708 @code{gdb} module:
25709
25710 @table @code
25711 @findex WP_READ
25712 @findex gdb.WP_READ
25713 @item gdb.WP_READ
25714 Read only watchpoint.
25715
25716 @findex WP_WRITE
25717 @findex gdb.WP_WRITE
25718 @item gdb.WP_WRITE
25719 Write only watchpoint.
25720
25721 @findex WP_ACCESS
25722 @findex gdb.WP_ACCESS
25723 @item gdb.WP_ACCESS
25724 Read/Write watchpoint.
25725 @end table
25726
25727 @defun Breakpoint.is_valid ()
25728 Return @code{True} if this @code{Breakpoint} object is valid,
25729 @code{False} otherwise.  A @code{Breakpoint} object can become invalid
25730 if the user deletes the breakpoint.  In this case, the object still
25731 exists, but the underlying breakpoint does not.  In the cases of
25732 watchpoint scope, the watchpoint remains valid even if execution of the
25733 inferior leaves the scope of that watchpoint.
25734 @end defun
25735
25736 @defun Breakpoint.delete
25737 Permanently deletes the @value{GDBN} breakpoint.  This also
25738 invalidates the Python @code{Breakpoint} object.  Any further access
25739 to this object's attributes or methods will raise an error.
25740 @end defun
25741
25742 @defvar Breakpoint.enabled
25743 This attribute is @code{True} if the breakpoint is enabled, and
25744 @code{False} otherwise.  This attribute is writable.
25745 @end defvar
25746
25747 @defvar Breakpoint.silent
25748 This attribute is @code{True} if the breakpoint is silent, and
25749 @code{False} otherwise.  This attribute is writable.
25750
25751 Note that a breakpoint can also be silent if it has commands and the
25752 first command is @code{silent}.  This is not reported by the
25753 @code{silent} attribute.
25754 @end defvar
25755
25756 @defvar Breakpoint.thread
25757 If the breakpoint is thread-specific, this attribute holds the thread
25758 id.  If the breakpoint is not thread-specific, this attribute is
25759 @code{None}.  This attribute is writable.
25760 @end defvar
25761
25762 @defvar Breakpoint.task
25763 If the breakpoint is Ada task-specific, this attribute holds the Ada task
25764 id.  If the breakpoint is not task-specific (or the underlying
25765 language is not Ada), this attribute is @code{None}.  This attribute
25766 is writable.
25767 @end defvar
25768
25769 @defvar Breakpoint.ignore_count
25770 This attribute holds the ignore count for the breakpoint, an integer.
25771 This attribute is writable.
25772 @end defvar
25773
25774 @defvar Breakpoint.number
25775 This attribute holds the breakpoint's number --- the identifier used by
25776 the user to manipulate the breakpoint.  This attribute is not writable.
25777 @end defvar
25778
25779 @defvar Breakpoint.type
25780 This attribute holds the breakpoint's type --- the identifier used to
25781 determine the actual breakpoint type or use-case.  This attribute is not
25782 writable.
25783 @end defvar
25784
25785 @defvar Breakpoint.visible
25786 This attribute tells whether the breakpoint is visible to the user
25787 when set, or when the @samp{info breakpoints} command is run.  This
25788 attribute is not writable.
25789 @end defvar
25790
25791 The available types are represented by constants defined in the @code{gdb}
25792 module:
25793
25794 @table @code
25795 @findex BP_BREAKPOINT
25796 @findex gdb.BP_BREAKPOINT
25797 @item gdb.BP_BREAKPOINT
25798 Normal code breakpoint.
25799
25800 @findex BP_WATCHPOINT
25801 @findex gdb.BP_WATCHPOINT
25802 @item gdb.BP_WATCHPOINT
25803 Watchpoint breakpoint.
25804
25805 @findex BP_HARDWARE_WATCHPOINT
25806 @findex gdb.BP_HARDWARE_WATCHPOINT
25807 @item gdb.BP_HARDWARE_WATCHPOINT
25808 Hardware assisted watchpoint.
25809
25810 @findex BP_READ_WATCHPOINT
25811 @findex gdb.BP_READ_WATCHPOINT
25812 @item gdb.BP_READ_WATCHPOINT
25813 Hardware assisted read watchpoint.
25814
25815 @findex BP_ACCESS_WATCHPOINT
25816 @findex gdb.BP_ACCESS_WATCHPOINT
25817 @item gdb.BP_ACCESS_WATCHPOINT
25818 Hardware assisted access watchpoint.
25819 @end table
25820
25821 @defvar Breakpoint.hit_count
25822 This attribute holds the hit count for the breakpoint, an integer.
25823 This attribute is writable, but currently it can only be set to zero.
25824 @end defvar
25825
25826 @defvar Breakpoint.location
25827 This attribute holds the location of the breakpoint, as specified by
25828 the user.  It is a string.  If the breakpoint does not have a location
25829 (that is, it is a watchpoint) the attribute's value is @code{None}.  This
25830 attribute is not writable.
25831 @end defvar
25832
25833 @defvar Breakpoint.expression
25834 This attribute holds a breakpoint expression, as specified by
25835 the user.  It is a string.  If the breakpoint does not have an
25836 expression (the breakpoint is not a watchpoint) the attribute's value
25837 is @code{None}.  This attribute is not writable.
25838 @end defvar
25839
25840 @defvar Breakpoint.condition
25841 This attribute holds the condition of the breakpoint, as specified by
25842 the user.  It is a string.  If there is no condition, this attribute's
25843 value is @code{None}.  This attribute is writable.
25844 @end defvar
25845
25846 @defvar Breakpoint.commands
25847 This attribute holds the commands attached to the breakpoint.  If
25848 there are commands, this attribute's value is a string holding all the
25849 commands, separated by newlines.  If there are no commands, this
25850 attribute is @code{None}.  This attribute is not writable.
25851 @end defvar
25852
25853 @node Finish Breakpoints in Python
25854 @subsubsection Finish Breakpoints
25855
25856 @cindex python finish breakpoints
25857 @tindex gdb.FinishBreakpoint
25858
25859 A finish breakpoint is a temporary breakpoint set at the return address of
25860 a frame, based on the @code{finish} command.  @code{gdb.FinishBreakpoint}
25861 extends @code{gdb.Breakpoint}.  The underlying breakpoint will be disabled 
25862 and deleted when the execution will run out of the breakpoint scope (i.e.@: 
25863 @code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
25864 Finish breakpoints are thread specific and must be create with the right 
25865 thread selected.  
25866  
25867 @defun FinishBreakpoint.__init__ (@r{[}frame@r{]} @r{[}, internal@r{]})
25868 Create a finish breakpoint at the return address of the @code{gdb.Frame}
25869 object @var{frame}.  If @var{frame} is not provided, this defaults to the
25870 newest frame.  The optional @var{internal} argument allows the breakpoint to
25871 become invisible to the user.  @xref{Breakpoints In Python}, for further 
25872 details about this argument.
25873 @end defun
25874
25875 @defun FinishBreakpoint.out_of_scope (self)
25876 In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN} 
25877 @code{return} command, @dots{}), a function may not properly terminate, and
25878 thus never hit the finish breakpoint.  When @value{GDBN} notices such a
25879 situation, the @code{out_of_scope} callback will be triggered.
25880
25881 You may want to sub-class @code{gdb.FinishBreakpoint} and override this
25882 method:
25883
25884 @smallexample
25885 class MyFinishBreakpoint (gdb.FinishBreakpoint)
25886     def stop (self):
25887         print "normal finish"
25888         return True
25889     
25890     def out_of_scope ():
25891         print "abnormal finish"
25892 @end smallexample 
25893 @end defun
25894
25895 @defvar FinishBreakpoint.return_value
25896 When @value{GDBN} is stopped at a finish breakpoint and the frame 
25897 used to build the @code{gdb.FinishBreakpoint} object had debug symbols, this
25898 attribute will contain a @code{gdb.Value} object corresponding to the return
25899 value of the function.  The value will be @code{None} if the function return 
25900 type is @code{void} or if the return value was not computable.  This attribute
25901 is not writable.
25902 @end defvar
25903
25904 @node Lazy Strings In Python
25905 @subsubsection Python representation of lazy strings.
25906
25907 @cindex lazy strings in python
25908 @tindex gdb.LazyString
25909
25910 A @dfn{lazy string} is a string whose contents is not retrieved or
25911 encoded until it is needed.
25912
25913 A @code{gdb.LazyString} is represented in @value{GDBN} as an
25914 @code{address} that points to a region of memory, an @code{encoding}
25915 that will be used to encode that region of memory, and a @code{length}
25916 to delimit the region of memory that represents the string.  The
25917 difference between a @code{gdb.LazyString} and a string wrapped within
25918 a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
25919 differently by @value{GDBN} when printing.  A @code{gdb.LazyString} is
25920 retrieved and encoded during printing, while a @code{gdb.Value}
25921 wrapping a string is immediately retrieved and encoded on creation.
25922
25923 A @code{gdb.LazyString} object has the following functions:
25924
25925 @defun LazyString.value ()
25926 Convert the @code{gdb.LazyString} to a @code{gdb.Value}.  This value
25927 will point to the string in memory, but will lose all the delayed
25928 retrieval, encoding and handling that @value{GDBN} applies to a
25929 @code{gdb.LazyString}.
25930 @end defun
25931
25932 @defvar LazyString.address
25933 This attribute holds the address of the string.  This attribute is not
25934 writable.
25935 @end defvar
25936
25937 @defvar LazyString.length
25938 This attribute holds the length of the string in characters.  If the
25939 length is -1, then the string will be fetched and encoded up to the
25940 first null of appropriate width.  This attribute is not writable.
25941 @end defvar
25942
25943 @defvar LazyString.encoding
25944 This attribute holds the encoding that will be applied to the string
25945 when the string is printed by @value{GDBN}.  If the encoding is not
25946 set, or contains an empty string,  then @value{GDBN} will select the
25947 most appropriate encoding when the string is printed.  This attribute
25948 is not writable.
25949 @end defvar
25950
25951 @defvar LazyString.type
25952 This attribute holds the type that is represented by the lazy string's
25953 type.  For a lazy string this will always be a pointer type.  To
25954 resolve this to the lazy string's character type, use the type's
25955 @code{target} method.  @xref{Types In Python}.  This attribute is not
25956 writable.
25957 @end defvar
25958
25959 @node Python Auto-loading
25960 @subsection Python Auto-loading
25961 @cindex Python auto-loading
25962
25963 When a new object file is read (for example, due to the @code{file}
25964 command, or because the inferior has loaded a shared library),
25965 @value{GDBN} will look for Python support scripts in several ways:
25966 @file{@var{objfile}-gdb.py} (@pxref{objfile-gdb.py file})
25967 and @code{.debug_gdb_scripts} section
25968 (@pxref{dotdebug_gdb_scripts section}).
25969
25970 The auto-loading feature is useful for supplying application-specific
25971 debugging commands and scripts.
25972
25973 Auto-loading can be enabled or disabled,
25974 and the list of auto-loaded scripts can be printed.
25975
25976 @table @code
25977 @anchor{set auto-load python-scripts}
25978 @kindex set auto-load python-scripts
25979 @item set auto-load python-scripts [on|off]
25980 Enable or disable the auto-loading of Python scripts.
25981
25982 @anchor{show auto-load python-scripts}
25983 @kindex show auto-load python-scripts
25984 @item show auto-load python-scripts
25985 Show whether auto-loading of Python scripts is enabled or disabled.
25986
25987 @anchor{info auto-load python-scripts}
25988 @kindex info auto-load python-scripts
25989 @cindex print list of auto-loaded Python scripts
25990 @item info auto-load python-scripts [@var{regexp}]
25991 Print the list of all Python scripts that @value{GDBN} auto-loaded.
25992
25993 Also printed is the list of Python scripts that were mentioned in
25994 the @code{.debug_gdb_scripts} section and were not found
25995 (@pxref{dotdebug_gdb_scripts section}).
25996 This is useful because their names are not printed when @value{GDBN}
25997 tries to load them and fails.  There may be many of them, and printing
25998 an error message for each one is problematic.
25999
26000 If @var{regexp} is supplied only Python scripts with matching names are printed.
26001
26002 Example:
26003
26004 @smallexample
26005 (gdb) info auto-load python-scripts
26006 Loaded Script
26007 Yes    py-section-script.py
26008        full name: /tmp/py-section-script.py
26009 No     my-foo-pretty-printers.py
26010 @end smallexample
26011 @end table
26012
26013 When reading an auto-loaded file, @value{GDBN} sets the
26014 @dfn{current objfile}.  This is available via the @code{gdb.current_objfile}
26015 function (@pxref{Objfiles In Python}).  This can be useful for
26016 registering objfile-specific pretty-printers.
26017
26018 @menu
26019 * objfile-gdb.py file::          The @file{@var{objfile}-gdb.py} file
26020 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
26021 * Which flavor to choose?::
26022 @end menu
26023
26024 @node objfile-gdb.py file
26025 @subsubsection The @file{@var{objfile}-gdb.py} file
26026 @cindex @file{@var{objfile}-gdb.py}
26027
26028 When a new object file is read, @value{GDBN} looks for
26029 a file named @file{@var{objfile}-gdb.py} (we call it @var{script-name} below),
26030 where @var{objfile} is the object file's real name, formed by ensuring
26031 that the file name is absolute, following all symlinks, and resolving
26032 @code{.} and @code{..} components.  If this file exists and is
26033 readable, @value{GDBN} will evaluate it as a Python script.
26034
26035 If this file does not exist, then @value{GDBN} will look for
26036 @var{script-name} file in all of the directories as specified below.
26037
26038 Note that loading of this script file also requires accordingly configured
26039 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26040
26041 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
26042 scripts normally according to its @file{.exe} filename.  But if no scripts are
26043 found @value{GDBN} also tries script filenames matching the object file without
26044 its @file{.exe} suffix.  This @file{.exe} stripping is case insensitive and it
26045 is attempted on any platform.  This makes the script filenames compatible
26046 between Unix and MS-Windows hosts.
26047
26048 @table @code
26049 @anchor{set auto-load scripts-directory}
26050 @kindex set auto-load scripts-directory
26051 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
26052 Control @value{GDBN} auto-loaded scripts location.  Multiple directory entries
26053 may be delimited by the host platform path separator in use
26054 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
26055
26056 Each entry here needs to be covered also by the security setting
26057 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
26058
26059 @anchor{with-auto-load-dir}
26060 This variable defaults to @file{$debugdir:$datadir/auto-load}.  The default
26061 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
26062 configuration option @option{--with-auto-load-dir}.
26063
26064 Any reference to @file{$debugdir} will get replaced by
26065 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
26066 reference to @file{$datadir} will get replaced by @var{data-directory} which is
26067 determined at @value{GDBN} startup (@pxref{Data Files}).  @file{$debugdir} and
26068 @file{$datadir} must be placed as a directory component --- either alone or
26069 delimited by @file{/} or @file{\} directory separators, depending on the host
26070 platform.
26071
26072 The list of directories uses path separator (@samp{:} on GNU and Unix
26073 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26074 to the @env{PATH} environment variable.
26075
26076 @anchor{show auto-load scripts-directory}
26077 @kindex show auto-load scripts-directory
26078 @item show auto-load scripts-directory
26079 Show @value{GDBN} auto-loaded scripts location.
26080 @end table
26081
26082 @value{GDBN} does not track which files it has already auto-loaded this way.
26083 @value{GDBN} will load the associated script every time the corresponding
26084 @var{objfile} is opened.
26085 So your @file{-gdb.py} file should be careful to avoid errors if it
26086 is evaluated more than once.
26087
26088 @node dotdebug_gdb_scripts section
26089 @subsubsection The @code{.debug_gdb_scripts} section
26090 @cindex @code{.debug_gdb_scripts} section
26091
26092 For systems using file formats like ELF and COFF,
26093 when @value{GDBN} loads a new object file
26094 it will look for a special section named @samp{.debug_gdb_scripts}.
26095 If this section exists, its contents is a list of names of scripts to load.
26096
26097 @value{GDBN} will look for each specified script file first in the
26098 current directory and then along the source search path
26099 (@pxref{Source Path, ,Specifying Source Directories}),
26100 except that @file{$cdir} is not searched, since the compilation
26101 directory is not relevant to scripts.
26102
26103 Entries can be placed in section @code{.debug_gdb_scripts} with,
26104 for example, this GCC macro:
26105
26106 @example
26107 /* Note: The "MS" section flags are to remove duplicates.  */
26108 #define DEFINE_GDB_SCRIPT(script_name) \
26109   asm("\
26110 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
26111 .byte 1\n\
26112 .asciz \"" script_name "\"\n\
26113 .popsection \n\
26114 ");
26115 @end example
26116
26117 @noindent
26118 Then one can reference the macro in a header or source file like this:
26119
26120 @example
26121 DEFINE_GDB_SCRIPT ("my-app-scripts.py")
26122 @end example
26123
26124 The script name may include directories if desired.
26125
26126 Note that loading of this script file also requires accordingly configured
26127 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26128
26129 If the macro is put in a header, any application or library
26130 using this header will get a reference to the specified script.
26131
26132 @node Which flavor to choose?
26133 @subsubsection Which flavor to choose?
26134
26135 Given the multiple ways of auto-loading Python scripts, it might not always
26136 be clear which one to choose.  This section provides some guidance.
26137
26138 Benefits of the @file{-gdb.py} way:
26139
26140 @itemize @bullet
26141 @item
26142 Can be used with file formats that don't support multiple sections.
26143
26144 @item
26145 Ease of finding scripts for public libraries.
26146
26147 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
26148 in the source search path.
26149 For publicly installed libraries, e.g., @file{libstdc++}, there typically
26150 isn't a source directory in which to find the script.
26151
26152 @item
26153 Doesn't require source code additions.
26154 @end itemize
26155
26156 Benefits of the @code{.debug_gdb_scripts} way:
26157
26158 @itemize @bullet
26159 @item
26160 Works with static linking.
26161
26162 Scripts for libraries done the @file{-gdb.py} way require an objfile to
26163 trigger their loading.  When an application is statically linked the only
26164 objfile available is the executable, and it is cumbersome to attach all the
26165 scripts from all the input libraries to the executable's @file{-gdb.py} script.
26166
26167 @item
26168 Works with classes that are entirely inlined.
26169
26170 Some classes can be entirely inlined, and thus there may not be an associated
26171 shared library to attach a @file{-gdb.py} script to.
26172
26173 @item
26174 Scripts needn't be copied out of the source tree.
26175
26176 In some circumstances, apps can be built out of large collections of internal
26177 libraries, and the build infrastructure necessary to install the
26178 @file{-gdb.py} scripts in a place where @value{GDBN} can find them is
26179 cumbersome.  It may be easier to specify the scripts in the
26180 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
26181 top of the source tree to the source search path.
26182 @end itemize
26183
26184 @node Python modules
26185 @subsection Python modules
26186 @cindex python modules
26187
26188 @value{GDBN} comes with several modules to assist writing Python code.
26189
26190 @menu
26191 * gdb.printing::       Building and registering pretty-printers.
26192 * gdb.types::          Utilities for working with types.
26193 * gdb.prompt::         Utilities for prompt value substitution.
26194 @end menu
26195
26196 @node gdb.printing
26197 @subsubsection gdb.printing
26198 @cindex gdb.printing
26199
26200 This module provides a collection of utilities for working with
26201 pretty-printers.
26202
26203 @table @code
26204 @item PrettyPrinter (@var{name}, @var{subprinters}=None)
26205 This class specifies the API that makes @samp{info pretty-printer},
26206 @samp{enable pretty-printer} and @samp{disable pretty-printer} work.
26207 Pretty-printers should generally inherit from this class.
26208
26209 @item SubPrettyPrinter (@var{name})
26210 For printers that handle multiple types, this class specifies the
26211 corresponding API for the subprinters.
26212
26213 @item RegexpCollectionPrettyPrinter (@var{name})
26214 Utility class for handling multiple printers, all recognized via
26215 regular expressions.
26216 @xref{Writing a Pretty-Printer}, for an example.
26217
26218 @item FlagEnumerationPrinter (@var{name})
26219 A pretty-printer which handles printing of @code{enum} values.  Unlike
26220 @value{GDBN}'s built-in @code{enum} printing, this printer attempts to
26221 work properly when there is some overlap between the enumeration
26222 constants.  @var{name} is the name of the printer and also the name of
26223 the @code{enum} type to look up.
26224
26225 @item register_pretty_printer (@var{obj}, @var{printer}, @var{replace}=False)
26226 Register @var{printer} with the pretty-printer list of @var{obj}.
26227 If @var{replace} is @code{True} then any existing copy of the printer
26228 is replaced.  Otherwise a @code{RuntimeError} exception is raised
26229 if a printer with the same name already exists.
26230 @end table
26231
26232 @node gdb.types
26233 @subsubsection gdb.types
26234 @cindex gdb.types
26235
26236 This module provides a collection of utilities for working with
26237 @code{gdb.Type} objects.
26238
26239 @table @code
26240 @item get_basic_type (@var{type})
26241 Return @var{type} with const and volatile qualifiers stripped,
26242 and with typedefs and C@t{++} references converted to the underlying type.
26243
26244 C@t{++} example:
26245
26246 @smallexample
26247 typedef const int const_int;
26248 const_int foo (3);
26249 const_int& foo_ref (foo);
26250 int main () @{ return 0; @}
26251 @end smallexample
26252
26253 Then in gdb:
26254
26255 @smallexample
26256 (gdb) start
26257 (gdb) python import gdb.types
26258 (gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
26259 (gdb) python print gdb.types.get_basic_type(foo_ref.type)
26260 int
26261 @end smallexample
26262
26263 @item has_field (@var{type}, @var{field})
26264 Return @code{True} if @var{type}, assumed to be a type with fields
26265 (e.g., a structure or union), has field @var{field}.
26266
26267 @item make_enum_dict (@var{enum_type})
26268 Return a Python @code{dictionary} type produced from @var{enum_type}.
26269
26270 @item deep_items (@var{type})
26271 Returns a Python iterator similar to the standard
26272 @code{gdb.Type.iteritems} method, except that the iterator returned
26273 by @code{deep_items} will recursively traverse anonymous struct or
26274 union fields.  For example:
26275
26276 @smallexample
26277 struct A
26278 @{
26279     int a;
26280     union @{
26281         int b0;
26282         int b1;
26283     @};
26284 @};
26285 @end smallexample
26286
26287 @noindent
26288 Then in @value{GDBN}:
26289 @smallexample
26290 (@value{GDBP}) python import gdb.types
26291 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
26292 (@value{GDBP}) python print struct_a.keys ()
26293 @{['a', '']@}
26294 (@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
26295 @{['a', 'b0', 'b1']@}
26296 @end smallexample
26297
26298 @item get_type_recognizers ()
26299 Return a list of the enabled type recognizers for the current context.
26300 This is called by @value{GDBN} during the type-printing process
26301 (@pxref{Type Printing API}).
26302
26303 @item apply_type_recognizers (recognizers, type_obj)
26304 Apply the type recognizers, @var{recognizers}, to the type object
26305 @var{type_obj}.  If any recognizer returns a string, return that
26306 string.  Otherwise, return @code{None}.  This is called by
26307 @value{GDBN} during the type-printing process (@pxref{Type Printing
26308 API}).
26309
26310 @item register_type_printer (locus, printer)
26311 This is a convenience function to register a type printer.
26312 @var{printer} is the type printer to register.  It must implement the
26313 type printer protocol.  @var{locus} is either a @code{gdb.Objfile}, in
26314 which case the printer is registered with that objfile; a
26315 @code{gdb.Progspace}, in which case the printer is registered with
26316 that progspace; or @code{None}, in which case the printer is
26317 registered globally.
26318
26319 @item TypePrinter
26320 This is a base class that implements the type printer protocol.  Type
26321 printers are encouraged, but not required, to derive from this class.
26322 It defines a constructor:
26323
26324 @defmethod TypePrinter __init__ (self, name)
26325 Initialize the type printer with the given name.  The new printer
26326 starts in the enabled state.
26327 @end defmethod
26328
26329 @end table
26330
26331 @node gdb.prompt
26332 @subsubsection gdb.prompt
26333 @cindex gdb.prompt
26334
26335 This module provides a method for prompt value-substitution.
26336
26337 @table @code
26338 @item substitute_prompt (@var{string})
26339 Return @var{string} with escape sequences substituted by values.  Some
26340 escape sequences take arguments.  You can specify arguments inside
26341 ``@{@}'' immediately following the escape sequence.
26342
26343 The escape sequences you can pass to this function are:
26344
26345 @table @code
26346 @item \\
26347 Substitute a backslash.
26348 @item \e
26349 Substitute an ESC character.
26350 @item \f
26351 Substitute the selected frame; an argument names a frame parameter.
26352 @item \n
26353 Substitute a newline.
26354 @item \p
26355 Substitute a parameter's value; the argument names the parameter.
26356 @item \r
26357 Substitute a carriage return.
26358 @item \t
26359 Substitute the selected thread; an argument names a thread parameter.
26360 @item \v
26361 Substitute the version of GDB.
26362 @item \w
26363 Substitute the current working directory.
26364 @item \[
26365 Begin a sequence of non-printing characters.  These sequences are
26366 typically used with the ESC character, and are not counted in the string
26367 length.  Example: ``\[\e[0;34m\](gdb)\[\e[0m\]'' will return a
26368 blue-colored ``(gdb)'' prompt where the length is five.
26369 @item \]
26370 End a sequence of non-printing characters.
26371 @end table
26372
26373 For example:
26374
26375 @smallexample
26376 substitute_prompt (``frame: \f,
26377                    print arguments: \p@{print frame-arguments@}'')
26378 @end smallexample
26379
26380 @exdent will return the string:
26381
26382 @smallexample
26383 "frame: main, print arguments: scalars"
26384 @end smallexample
26385 @end table
26386
26387 @node Aliases
26388 @section Creating new spellings of existing commands
26389 @cindex aliases for commands
26390
26391 It is often useful to define alternate spellings of existing commands.
26392 For example, if a new @value{GDBN} command defined in Python has
26393 a long name to type, it is handy to have an abbreviated version of it
26394 that involves less typing.
26395
26396 @value{GDBN} itself uses aliases.  For example @samp{s} is an alias
26397 of the @samp{step} command even though it is otherwise an ambiguous
26398 abbreviation of other commands like @samp{set} and @samp{show}.
26399
26400 Aliases are also used to provide shortened or more common versions
26401 of multi-word commands.  For example, @value{GDBN} provides the
26402 @samp{tty} alias of the @samp{set inferior-tty} command.
26403
26404 You can define a new alias with the @samp{alias} command.
26405
26406 @table @code
26407
26408 @kindex alias
26409 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
26410
26411 @end table
26412
26413 @var{ALIAS} specifies the name of the new alias.
26414 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
26415 underscores.
26416
26417 @var{COMMAND} specifies the name of an existing command
26418 that is being aliased.
26419
26420 The @samp{-a} option specifies that the new alias is an abbreviation
26421 of the command.  Abbreviations are not shown in command
26422 lists displayed by the @samp{help} command.
26423
26424 The @samp{--} option specifies the end of options,
26425 and is useful when @var{ALIAS} begins with a dash.
26426
26427 Here is a simple example showing how to make an abbreviation
26428 of a command so that there is less to type.
26429 Suppose you were tired of typing @samp{disas}, the current
26430 shortest unambiguous abbreviation of the @samp{disassemble} command
26431 and you wanted an even shorter version named @samp{di}.
26432 The following will accomplish this.
26433
26434 @smallexample
26435 (gdb) alias -a di = disas
26436 @end smallexample
26437
26438 Note that aliases are different from user-defined commands.
26439 With a user-defined command, you also need to write documentation
26440 for it with the @samp{document} command.
26441 An alias automatically picks up the documentation of the existing command.
26442
26443 Here is an example where we make @samp{elms} an abbreviation of
26444 @samp{elements} in the @samp{set print elements} command.
26445 This is to show that you can make an abbreviation of any part
26446 of a command.
26447
26448 @smallexample
26449 (gdb) alias -a set print elms = set print elements
26450 (gdb) alias -a show print elms = show print elements
26451 (gdb) set p elms 20
26452 (gdb) show p elms
26453 Limit on string chars or array elements to print is 200.
26454 @end smallexample
26455
26456 Note that if you are defining an alias of a @samp{set} command,
26457 and you want to have an alias for the corresponding @samp{show}
26458 command, then you need to define the latter separately.
26459
26460 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
26461 @var{ALIAS}, just as they are normally.
26462
26463 @smallexample
26464 (gdb) alias -a set pr elms = set p ele
26465 @end smallexample
26466
26467 Finally, here is an example showing the creation of a one word
26468 alias for a more complex command.
26469 This creates alias @samp{spe} of the command @samp{set print elements}.
26470
26471 @smallexample
26472 (gdb) alias spe = set print elements
26473 (gdb) spe 20
26474 @end smallexample
26475
26476 @node Interpreters
26477 @chapter Command Interpreters
26478 @cindex command interpreters
26479
26480 @value{GDBN} supports multiple command interpreters, and some command
26481 infrastructure to allow users or user interface writers to switch
26482 between interpreters or run commands in other interpreters.
26483
26484 @value{GDBN} currently supports two command interpreters, the console
26485 interpreter (sometimes called the command-line interpreter or @sc{cli})
26486 and the machine interface interpreter (or @sc{gdb/mi}).  This manual
26487 describes both of these interfaces in great detail.
26488
26489 By default, @value{GDBN} will start with the console interpreter.
26490 However, the user may choose to start @value{GDBN} with another
26491 interpreter by specifying the @option{-i} or @option{--interpreter}
26492 startup options.  Defined interpreters include:
26493
26494 @table @code
26495 @item console
26496 @cindex console interpreter
26497 The traditional console or command-line interpreter.  This is the most often
26498 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
26499 @value{GDBN} will use this interpreter.
26500
26501 @item mi
26502 @cindex mi interpreter
26503 The newest @sc{gdb/mi} interface (currently @code{mi2}).  Used primarily
26504 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
26505 or an IDE.  For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
26506 Interface}.
26507
26508 @item mi2
26509 @cindex mi2 interpreter
26510 The current @sc{gdb/mi} interface.
26511
26512 @item mi1
26513 @cindex mi1 interpreter
26514 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
26515
26516 @end table
26517
26518 @cindex invoke another interpreter
26519 The interpreter being used by @value{GDBN} may not be dynamically
26520 switched at runtime.  Although possible, this could lead to a very
26521 precarious situation.  Consider an IDE using @sc{gdb/mi}.  If a user
26522 enters the command "interpreter-set console" in a console view,
26523 @value{GDBN} would switch to using the console interpreter, rendering
26524 the IDE inoperable!
26525
26526 @kindex interpreter-exec
26527 Although you may only choose a single interpreter at startup, you may execute
26528 commands in any interpreter from the current interpreter using the appropriate
26529 command.  If you are running the console interpreter, simply use the
26530 @code{interpreter-exec} command:
26531
26532 @smallexample
26533 interpreter-exec mi "-data-list-register-names"
26534 @end smallexample
26535
26536 @sc{gdb/mi} has a similar command, although it is only available in versions of
26537 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
26538
26539 @node TUI
26540 @chapter @value{GDBN} Text User Interface
26541 @cindex TUI
26542 @cindex Text User Interface
26543
26544 @menu
26545 * TUI Overview::                TUI overview
26546 * TUI Keys::                    TUI key bindings
26547 * TUI Single Key Mode::         TUI single key mode
26548 * TUI Commands::                TUI-specific commands
26549 * TUI Configuration::           TUI configuration variables
26550 @end menu
26551
26552 The @value{GDBN} Text User Interface (TUI) is a terminal
26553 interface which uses the @code{curses} library to show the source
26554 file, the assembly output, the program registers and @value{GDBN}
26555 commands in separate text windows.  The TUI mode is supported only
26556 on platforms where a suitable version of the @code{curses} library
26557 is available.
26558
26559 The TUI mode is enabled by default when you invoke @value{GDBN} as
26560 @samp{@value{GDBP} -tui}.
26561 You can also switch in and out of TUI mode while @value{GDBN} runs by
26562 using various TUI commands and key bindings, such as @kbd{C-x C-a}. 
26563 @xref{TUI Keys, ,TUI Key Bindings}.
26564
26565 @node TUI Overview
26566 @section TUI Overview
26567
26568 In TUI mode, @value{GDBN} can display several text windows:
26569
26570 @table @emph
26571 @item command
26572 This window is the @value{GDBN} command window with the @value{GDBN}
26573 prompt and the @value{GDBN} output.  The @value{GDBN} input is still
26574 managed using readline.
26575
26576 @item source
26577 The source window shows the source file of the program.  The current
26578 line and active breakpoints are displayed in this window.
26579
26580 @item assembly
26581 The assembly window shows the disassembly output of the program.
26582
26583 @item register
26584 This window shows the processor registers.  Registers are highlighted
26585 when their values change.
26586 @end table
26587
26588 The source and assembly windows show the current program position
26589 by highlighting the current line and marking it with a @samp{>} marker.
26590 Breakpoints are indicated with two markers.  The first marker
26591 indicates the breakpoint type:
26592
26593 @table @code
26594 @item B
26595 Breakpoint which was hit at least once.
26596
26597 @item b
26598 Breakpoint which was never hit.
26599
26600 @item H
26601 Hardware breakpoint which was hit at least once.
26602
26603 @item h
26604 Hardware breakpoint which was never hit.
26605 @end table
26606
26607 The second marker indicates whether the breakpoint is enabled or not:
26608
26609 @table @code
26610 @item +
26611 Breakpoint is enabled.
26612
26613 @item -
26614 Breakpoint is disabled.
26615 @end table
26616
26617 The source, assembly and register windows are updated when the current
26618 thread changes, when the frame changes, or when the program counter
26619 changes.
26620
26621 These windows are not all visible at the same time.  The command
26622 window is always visible.  The others can be arranged in several
26623 layouts:
26624
26625 @itemize @bullet
26626 @item
26627 source only,
26628
26629 @item
26630 assembly only,
26631
26632 @item
26633 source and assembly,
26634
26635 @item
26636 source and registers, or
26637
26638 @item
26639 assembly and registers.
26640 @end itemize
26641
26642 A status line above the command window shows the following information:
26643
26644 @table @emph
26645 @item target
26646 Indicates the current @value{GDBN} target.
26647 (@pxref{Targets, ,Specifying a Debugging Target}).
26648
26649 @item process
26650 Gives the current process or thread number.
26651 When no process is being debugged, this field is set to @code{No process}.
26652
26653 @item function
26654 Gives the current function name for the selected frame.
26655 The name is demangled if demangling is turned on (@pxref{Print Settings}).
26656 When there is no symbol corresponding to the current program counter,
26657 the string @code{??} is displayed.
26658
26659 @item line
26660 Indicates the current line number for the selected frame.
26661 When the current line number is not known, the string @code{??} is displayed.
26662
26663 @item pc
26664 Indicates the current program counter address.
26665 @end table
26666
26667 @node TUI Keys
26668 @section TUI Key Bindings
26669 @cindex TUI key bindings
26670
26671 The TUI installs several key bindings in the readline keymaps
26672 @ifset SYSTEM_READLINE
26673 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
26674 @end ifset
26675 @ifclear SYSTEM_READLINE
26676 (@pxref{Command Line Editing}).
26677 @end ifclear
26678 The following key bindings are installed for both TUI mode and the
26679 @value{GDBN} standard mode.
26680
26681 @table @kbd
26682 @kindex C-x C-a
26683 @item C-x C-a
26684 @kindex C-x a
26685 @itemx C-x a
26686 @kindex C-x A
26687 @itemx C-x A
26688 Enter or leave the TUI mode.  When leaving the TUI mode,
26689 the curses window management stops and @value{GDBN} operates using
26690 its standard mode, writing on the terminal directly.  When reentering
26691 the TUI mode, control is given back to the curses windows.
26692 The screen is then refreshed.
26693
26694 @kindex C-x 1
26695 @item C-x 1
26696 Use a TUI layout with only one window.  The layout will
26697 either be @samp{source} or @samp{assembly}.  When the TUI mode
26698 is not active, it will switch to the TUI mode.
26699
26700 Think of this key binding as the Emacs @kbd{C-x 1} binding.
26701
26702 @kindex C-x 2
26703 @item C-x 2
26704 Use a TUI layout with at least two windows.  When the current
26705 layout already has two windows, the next layout with two windows is used.
26706 When a new layout is chosen, one window will always be common to the
26707 previous layout and the new one.
26708
26709 Think of it as the Emacs @kbd{C-x 2} binding.
26710
26711 @kindex C-x o
26712 @item C-x o
26713 Change the active window.  The TUI associates several key bindings
26714 (like scrolling and arrow keys) with the active window.  This command
26715 gives the focus to the next TUI window.
26716
26717 Think of it as the Emacs @kbd{C-x o} binding.
26718
26719 @kindex C-x s
26720 @item C-x s
26721 Switch in and out of the TUI SingleKey mode that binds single
26722 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
26723 @end table
26724
26725 The following key bindings only work in the TUI mode:
26726
26727 @table @asis
26728 @kindex PgUp
26729 @item @key{PgUp}
26730 Scroll the active window one page up.
26731
26732 @kindex PgDn
26733 @item @key{PgDn}
26734 Scroll the active window one page down.
26735
26736 @kindex Up
26737 @item @key{Up}
26738 Scroll the active window one line up.
26739
26740 @kindex Down
26741 @item @key{Down}
26742 Scroll the active window one line down.
26743
26744 @kindex Left
26745 @item @key{Left}
26746 Scroll the active window one column left.
26747
26748 @kindex Right
26749 @item @key{Right}
26750 Scroll the active window one column right.
26751
26752 @kindex C-L
26753 @item @kbd{C-L}
26754 Refresh the screen.
26755 @end table
26756
26757 Because the arrow keys scroll the active window in the TUI mode, they
26758 are not available for their normal use by readline unless the command
26759 window has the focus.  When another window is active, you must use
26760 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
26761 and @kbd{C-f} to control the command window.
26762
26763 @node TUI Single Key Mode
26764 @section TUI Single Key Mode
26765 @cindex TUI single key mode
26766
26767 The TUI also provides a @dfn{SingleKey} mode, which binds several
26768 frequently used @value{GDBN} commands to single keys.  Type @kbd{C-x s} to
26769 switch into this mode, where the following key bindings are used:
26770
26771 @table @kbd
26772 @kindex c @r{(SingleKey TUI key)}
26773 @item c
26774 continue
26775
26776 @kindex d @r{(SingleKey TUI key)}
26777 @item d
26778 down
26779
26780 @kindex f @r{(SingleKey TUI key)}
26781 @item f
26782 finish
26783
26784 @kindex n @r{(SingleKey TUI key)}
26785 @item n
26786 next
26787
26788 @kindex q @r{(SingleKey TUI key)}
26789 @item q
26790 exit the SingleKey mode.
26791
26792 @kindex r @r{(SingleKey TUI key)}
26793 @item r
26794 run
26795
26796 @kindex s @r{(SingleKey TUI key)}
26797 @item s
26798 step
26799
26800 @kindex u @r{(SingleKey TUI key)}
26801 @item u
26802 up
26803
26804 @kindex v @r{(SingleKey TUI key)}
26805 @item v
26806 info locals
26807
26808 @kindex w @r{(SingleKey TUI key)}
26809 @item w
26810 where
26811 @end table
26812
26813 Other keys temporarily switch to the @value{GDBN} command prompt.
26814 The key that was pressed is inserted in the editing buffer so that
26815 it is possible to type most @value{GDBN} commands without interaction
26816 with the TUI SingleKey mode.  Once the command is entered the TUI
26817 SingleKey mode is restored.  The only way to permanently leave
26818 this mode is by typing @kbd{q} or @kbd{C-x s}.
26819
26820
26821 @node TUI Commands
26822 @section TUI-specific Commands
26823 @cindex TUI commands
26824
26825 The TUI has specific commands to control the text windows.
26826 These commands are always available, even when @value{GDBN} is not in
26827 the TUI mode.  When @value{GDBN} is in the standard mode, most
26828 of these commands will automatically switch to the TUI mode.
26829
26830 Note that if @value{GDBN}'s @code{stdout} is not connected to a
26831 terminal, or @value{GDBN} has been started with the machine interface
26832 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
26833 these commands will fail with an error, because it would not be
26834 possible or desirable to enable curses window management.
26835
26836 @table @code
26837 @item info win
26838 @kindex info win
26839 List and give the size of all displayed windows.
26840
26841 @item layout next
26842 @kindex layout
26843 Display the next layout.
26844
26845 @item layout prev
26846 Display the previous layout.
26847
26848 @item layout src
26849 Display the source window only.
26850
26851 @item layout asm
26852 Display the assembly window only.
26853
26854 @item layout split
26855 Display the source and assembly window.
26856
26857 @item layout regs
26858 Display the register window together with the source or assembly window.
26859
26860 @item focus next
26861 @kindex focus
26862 Make the next window active for scrolling.
26863
26864 @item focus prev
26865 Make the previous window active for scrolling.
26866
26867 @item focus src
26868 Make the source window active for scrolling.
26869
26870 @item focus asm
26871 Make the assembly window active for scrolling.
26872
26873 @item focus regs
26874 Make the register window active for scrolling.
26875
26876 @item focus cmd
26877 Make the command window active for scrolling.
26878
26879 @item refresh
26880 @kindex refresh
26881 Refresh the screen.  This is similar to typing @kbd{C-L}.
26882
26883 @item tui reg float
26884 @kindex tui reg
26885 Show the floating point registers in the register window.
26886
26887 @item tui reg general
26888 Show the general registers in the register window.
26889
26890 @item tui reg next
26891 Show the next register group.  The list of register groups as well as
26892 their order is target specific.  The predefined register groups are the
26893 following: @code{general}, @code{float}, @code{system}, @code{vector},
26894 @code{all}, @code{save}, @code{restore}.
26895
26896 @item tui reg system
26897 Show the system registers in the register window.
26898
26899 @item update
26900 @kindex update
26901 Update the source window and the current execution point.
26902
26903 @item winheight @var{name} +@var{count}
26904 @itemx winheight @var{name} -@var{count}
26905 @kindex winheight
26906 Change the height of the window @var{name} by @var{count}
26907 lines.  Positive counts increase the height, while negative counts
26908 decrease it.
26909
26910 @item tabset @var{nchars}
26911 @kindex tabset
26912 Set the width of tab stops to be @var{nchars} characters.
26913 @end table
26914
26915 @node TUI Configuration
26916 @section TUI Configuration Variables
26917 @cindex TUI configuration variables
26918
26919 Several configuration variables control the appearance of TUI windows.
26920
26921 @table @code
26922 @item set tui border-kind @var{kind}
26923 @kindex set tui border-kind
26924 Select the border appearance for the source, assembly and register windows.
26925 The possible values are the following:
26926 @table @code
26927 @item space
26928 Use a space character to draw the border.
26929
26930 @item ascii
26931 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
26932
26933 @item acs
26934 Use the Alternate Character Set to draw the border.  The border is
26935 drawn using character line graphics if the terminal supports them.
26936 @end table
26937
26938 @item set tui border-mode @var{mode}
26939 @kindex set tui border-mode
26940 @itemx set tui active-border-mode @var{mode}
26941 @kindex set tui active-border-mode
26942 Select the display attributes for the borders of the inactive windows
26943 or the active window.  The @var{mode} can be one of the following:
26944 @table @code
26945 @item normal
26946 Use normal attributes to display the border.
26947
26948 @item standout
26949 Use standout mode.
26950
26951 @item reverse
26952 Use reverse video mode.
26953
26954 @item half
26955 Use half bright mode.
26956
26957 @item half-standout
26958 Use half bright and standout mode.
26959
26960 @item bold
26961 Use extra bright or bold mode.
26962
26963 @item bold-standout
26964 Use extra bright or bold and standout mode.
26965 @end table
26966 @end table
26967
26968 @node Emacs
26969 @chapter Using @value{GDBN} under @sc{gnu} Emacs
26970
26971 @cindex Emacs
26972 @cindex @sc{gnu} Emacs
26973 A special interface allows you to use @sc{gnu} Emacs to view (and
26974 edit) the source files for the program you are debugging with
26975 @value{GDBN}.
26976
26977 To use this interface, use the command @kbd{M-x gdb} in Emacs.  Give the
26978 executable file you want to debug as an argument.  This command starts
26979 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
26980 created Emacs buffer.
26981 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
26982
26983 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
26984 things:
26985
26986 @itemize @bullet
26987 @item
26988 All ``terminal'' input and output goes through an Emacs buffer, called
26989 the GUD buffer.
26990
26991 This applies both to @value{GDBN} commands and their output, and to the input
26992 and output done by the program you are debugging.
26993
26994 This is useful because it means that you can copy the text of previous
26995 commands and input them again; you can even use parts of the output
26996 in this way.
26997
26998 All the facilities of Emacs' Shell mode are available for interacting
26999 with your program.  In particular, you can send signals the usual
27000 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
27001 stop.
27002
27003 @item
27004 @value{GDBN} displays source code through Emacs.
27005
27006 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
27007 source file for that frame and puts an arrow (@samp{=>}) at the
27008 left margin of the current line.  Emacs uses a separate buffer for
27009 source display, and splits the screen to show both your @value{GDBN} session
27010 and the source.
27011
27012 Explicit @value{GDBN} @code{list} or search commands still produce output as
27013 usual, but you probably have no reason to use them from Emacs.
27014 @end itemize
27015
27016 We call this @dfn{text command mode}.  Emacs 22.1, and later, also uses
27017 a graphical mode, enabled by default, which provides further buffers
27018 that can control the execution and describe the state of your program.
27019 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
27020
27021 If you specify an absolute file name when prompted for the @kbd{M-x
27022 gdb} argument, then Emacs sets your current working directory to where
27023 your program resides.  If you only specify the file name, then Emacs
27024 sets your current working directory to the directory associated
27025 with the previous buffer.  In this case, @value{GDBN} may find your
27026 program by searching your environment's @code{PATH} variable, but on
27027 some operating systems it might not find the source.  So, although the
27028 @value{GDBN} input and output session proceeds normally, the auxiliary
27029 buffer does not display the current source and line of execution.
27030
27031 The initial working directory of @value{GDBN} is printed on the top
27032 line of the GUD buffer and this serves as a default for the commands
27033 that specify files for @value{GDBN} to operate on.  @xref{Files,
27034 ,Commands to Specify Files}.
27035
27036 By default, @kbd{M-x gdb} calls the program called @file{gdb}.  If you
27037 need to call @value{GDBN} by a different name (for example, if you
27038 keep several configurations around, with different names) you can
27039 customize the Emacs variable @code{gud-gdb-command-name} to run the
27040 one you want.
27041
27042 In the GUD buffer, you can use these special Emacs commands in
27043 addition to the standard Shell mode commands:
27044
27045 @table @kbd
27046 @item C-h m
27047 Describe the features of Emacs' GUD Mode.
27048
27049 @item C-c C-s
27050 Execute to another source line, like the @value{GDBN} @code{step} command; also
27051 update the display window to show the current file and location.
27052
27053 @item C-c C-n
27054 Execute to next source line in this function, skipping all function
27055 calls, like the @value{GDBN} @code{next} command.  Then update the display window
27056 to show the current file and location.
27057
27058 @item C-c C-i
27059 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
27060 display window accordingly.
27061
27062 @item C-c C-f
27063 Execute until exit from the selected stack frame, like the @value{GDBN}
27064 @code{finish} command.
27065
27066 @item C-c C-r
27067 Continue execution of your program, like the @value{GDBN} @code{continue}
27068 command.
27069
27070 @item C-c <
27071 Go up the number of frames indicated by the numeric argument
27072 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
27073 like the @value{GDBN} @code{up} command.
27074
27075 @item C-c >
27076 Go down the number of frames indicated by the numeric argument, like the
27077 @value{GDBN} @code{down} command.
27078 @end table
27079
27080 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
27081 tells @value{GDBN} to set a breakpoint on the source line point is on.
27082
27083 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
27084 separate frame which shows a backtrace when the GUD buffer is current.
27085 Move point to any frame in the stack and type @key{RET} to make it
27086 become the current frame and display the associated source in the
27087 source buffer.  Alternatively, click @kbd{Mouse-2} to make the
27088 selected frame become the current one.  In graphical mode, the
27089 speedbar displays watch expressions.
27090
27091 If you accidentally delete the source-display buffer, an easy way to get
27092 it back is to type the command @code{f} in the @value{GDBN} buffer, to
27093 request a frame display; when you run under Emacs, this recreates
27094 the source buffer if necessary to show you the context of the current
27095 frame.
27096
27097 The source files displayed in Emacs are in ordinary Emacs buffers
27098 which are visiting the source files in the usual way.  You can edit
27099 the files with these buffers if you wish; but keep in mind that @value{GDBN}
27100 communicates with Emacs in terms of line numbers.  If you add or
27101 delete lines from the text, the line numbers that @value{GDBN} knows cease
27102 to correspond properly with the code.
27103
27104 A more detailed description of Emacs' interaction with @value{GDBN} is
27105 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
27106 Emacs Manual}).
27107
27108 @c The following dropped because Epoch is nonstandard.  Reactivate
27109 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
27110 @ignore
27111 @kindex Emacs Epoch environment
27112 @kindex Epoch
27113 @kindex inspect
27114
27115 Version 18 of @sc{gnu} Emacs has a built-in window system
27116 called the @code{epoch}
27117 environment.  Users of this environment can use a new command,
27118 @code{inspect} which performs identically to @code{print} except that
27119 each value is printed in its own window.
27120 @end ignore
27121
27122
27123 @node GDB/MI
27124 @chapter The @sc{gdb/mi} Interface
27125
27126 @unnumberedsec Function and Purpose
27127
27128 @cindex @sc{gdb/mi}, its purpose
27129 @sc{gdb/mi} is a line based machine oriented text interface to
27130 @value{GDBN} and is activated by specifying using the
27131 @option{--interpreter} command line option (@pxref{Mode Options}).  It
27132 is specifically intended to support the development of systems which
27133 use the debugger as just one small component of a larger system.
27134
27135 This chapter is a specification of the @sc{gdb/mi} interface.  It is written
27136 in the form of a reference manual.
27137
27138 Note that @sc{gdb/mi} is still under construction, so some of the
27139 features described below are incomplete and subject to change
27140 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).  
27141
27142 @unnumberedsec Notation and Terminology
27143
27144 @cindex notational conventions, for @sc{gdb/mi}
27145 This chapter uses the following notation:
27146
27147 @itemize @bullet
27148 @item
27149 @code{|} separates two alternatives.
27150
27151 @item
27152 @code{[ @var{something} ]} indicates that @var{something} is optional:
27153 it may or may not be given.
27154
27155 @item
27156 @code{( @var{group} )*} means that @var{group} inside the parentheses
27157 may repeat zero or more times.
27158
27159 @item
27160 @code{( @var{group} )+} means that @var{group} inside the parentheses
27161 may repeat one or more times.
27162
27163 @item
27164 @code{"@var{string}"} means a literal @var{string}.
27165 @end itemize
27166
27167 @ignore
27168 @heading Dependencies
27169 @end ignore
27170
27171 @menu
27172 * GDB/MI General Design::
27173 * GDB/MI Command Syntax::
27174 * GDB/MI Compatibility with CLI::
27175 * GDB/MI Development and Front Ends::
27176 * GDB/MI Output Records::
27177 * GDB/MI Simple Examples::
27178 * GDB/MI Command Description Format::
27179 * GDB/MI Breakpoint Commands::
27180 * GDB/MI Catchpoint Commands::
27181 * GDB/MI Program Context::
27182 * GDB/MI Thread Commands::
27183 * GDB/MI Ada Tasking Commands::
27184 * GDB/MI Program Execution::
27185 * GDB/MI Stack Manipulation::
27186 * GDB/MI Variable Objects::
27187 * GDB/MI Data Manipulation::
27188 * GDB/MI Tracepoint Commands::
27189 * GDB/MI Symbol Query::
27190 * GDB/MI File Commands::
27191 @ignore
27192 * GDB/MI Kod Commands::
27193 * GDB/MI Memory Overlay Commands::
27194 * GDB/MI Signal Handling Commands::
27195 @end ignore
27196 * GDB/MI Target Manipulation::
27197 * GDB/MI File Transfer Commands::
27198 * GDB/MI Miscellaneous Commands::
27199 @end menu
27200
27201 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27202 @node GDB/MI General Design
27203 @section @sc{gdb/mi} General Design
27204 @cindex GDB/MI General Design
27205
27206 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
27207 parts---commands sent to @value{GDBN}, responses to those commands
27208 and notifications.  Each command results in exactly one response,
27209 indicating either successful completion of the command, or an error.
27210 For the commands that do not resume the target, the response contains the
27211 requested information.  For the commands that resume the target, the
27212 response only indicates whether the target was successfully resumed.
27213 Notifications is the mechanism for reporting changes in the state of the
27214 target, or in @value{GDBN} state, that cannot conveniently be associated with
27215 a command and reported as part of that command response.
27216
27217 The important examples of notifications are:
27218 @itemize @bullet
27219
27220 @item 
27221 Exec notifications.  These are used to report changes in
27222 target state---when a target is resumed, or stopped.  It would not
27223 be feasible to include this information in response of resuming
27224 commands, because one resume commands can result in multiple events in
27225 different threads.  Also, quite some time may pass before any event
27226 happens in the target, while a frontend needs to know whether the resuming
27227 command itself was successfully executed.
27228
27229 @item 
27230 Console output, and status notifications.  Console output
27231 notifications are used to report output of CLI commands, as well as
27232 diagnostics for other commands.  Status notifications are used to
27233 report the progress of a long-running operation.  Naturally, including
27234 this information in command response would mean no output is produced
27235 until the command is finished, which is undesirable.
27236
27237 @item
27238 General notifications.  Commands may have various side effects on
27239 the @value{GDBN} or target state beyond their official purpose.  For example,
27240 a command may change the selected thread.  Although such changes can
27241 be included in command response, using notification allows for more
27242 orthogonal frontend design.
27243
27244 @end itemize
27245
27246 There's no guarantee that whenever an MI command reports an error,
27247 @value{GDBN} or the target are in any specific state, and especially,
27248 the state is not reverted to the state before the MI command was
27249 processed.  Therefore, whenever an MI command results in an error, 
27250 we recommend that the frontend refreshes all the information shown in 
27251 the user interface.
27252
27253
27254 @menu
27255 * Context management::
27256 * Asynchronous and non-stop modes::
27257 * Thread groups::
27258 @end menu
27259
27260 @node Context management
27261 @subsection Context management
27262
27263 In most cases when @value{GDBN} accesses the target, this access is
27264 done in context of a specific thread and frame (@pxref{Frames}).
27265 Often, even when accessing global data, the target requires that a thread
27266 be specified.  The CLI interface maintains the selected thread and frame,
27267 and supplies them to target on each command.  This is convenient,
27268 because a command line user would not want to specify that information
27269 explicitly on each command, and because user interacts with
27270 @value{GDBN} via a single terminal, so no confusion is possible as 
27271 to what thread and frame are the current ones.
27272
27273 In the case of MI, the concept of selected thread and frame is less
27274 useful.  First, a frontend can easily remember this information
27275 itself.  Second, a graphical frontend can have more than one window,
27276 each one used for debugging a different thread, and the frontend might
27277 want to access additional threads for internal purposes.  This
27278 increases the risk that by relying on implicitly selected thread, the
27279 frontend may be operating on a wrong one.  Therefore, each MI command
27280 should explicitly specify which thread and frame to operate on.  To
27281 make it possible, each MI command accepts the @samp{--thread} and
27282 @samp{--frame} options, the value to each is @value{GDBN} identifier
27283 for thread and frame to operate on.
27284
27285 Usually, each top-level window in a frontend allows the user to select
27286 a thread and a frame, and remembers the user selection for further
27287 operations.  However, in some cases @value{GDBN} may suggest that the
27288 current thread be changed.  For example, when stopping on a breakpoint
27289 it is reasonable to switch to the thread where breakpoint is hit.  For
27290 another example, if the user issues the CLI @samp{thread} command via
27291 the frontend, it is desirable to change the frontend's selected thread to the
27292 one specified by user.  @value{GDBN} communicates the suggestion to
27293 change current thread using the @samp{=thread-selected} notification.
27294 No such notification is available for the selected frame at the moment.
27295
27296 Note that historically, MI shares the selected thread with CLI, so 
27297 frontends used the @code{-thread-select} to execute commands in the
27298 right context.  However, getting this to work right is cumbersome.  The
27299 simplest way is for frontend to emit @code{-thread-select} command
27300 before every command.  This doubles the number of commands that need
27301 to be sent.  The alternative approach is to suppress @code{-thread-select}
27302 if the selected thread in @value{GDBN} is supposed to be identical to the
27303 thread the frontend wants to operate on.  However, getting this
27304 optimization right can be tricky.  In particular, if the frontend
27305 sends several commands to @value{GDBN}, and one of the commands changes the
27306 selected thread, then the behaviour of subsequent commands will
27307 change.  So, a frontend should either wait for response from such
27308 problematic commands, or explicitly add @code{-thread-select} for
27309 all subsequent commands.  No frontend is known to do this exactly
27310 right, so it is suggested to just always pass the @samp{--thread} and
27311 @samp{--frame} options.
27312
27313 @node Asynchronous and non-stop modes
27314 @subsection Asynchronous command execution and non-stop mode
27315
27316 On some targets, @value{GDBN} is capable of processing MI commands
27317 even while the target is running.  This is called @dfn{asynchronous
27318 command execution} (@pxref{Background Execution}).  The frontend may
27319 specify a preferrence for asynchronous execution using the
27320 @code{-gdb-set target-async 1} command, which should be emitted before
27321 either running the executable or attaching to the target.  After the
27322 frontend has started the executable or attached to the target, it can
27323 find if asynchronous execution is enabled using the
27324 @code{-list-target-features} command.
27325
27326 Even if @value{GDBN} can accept a command while target is running,
27327 many commands that access the target do not work when the target is
27328 running.  Therefore, asynchronous command execution is most useful
27329 when combined with non-stop mode (@pxref{Non-Stop Mode}).  Then,
27330 it is possible to examine the state of one thread, while other threads
27331 are running.
27332
27333 When a given thread is running, MI commands that try to access the
27334 target in the context of that thread may not work, or may work only on
27335 some targets.  In particular, commands that try to operate on thread's
27336 stack will not work, on any target.  Commands that read memory, or
27337 modify breakpoints, may work or not work, depending on the target.  Note
27338 that even commands that operate on global state, such as @code{print},
27339 @code{set}, and breakpoint commands, still access the target in the
27340 context of a specific thread,  so frontend should try to find a
27341 stopped thread and perform the operation on that thread (using the
27342 @samp{--thread} option).
27343
27344 Which commands will work in the context of a running thread is
27345 highly target dependent.  However, the two commands
27346 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
27347 to find the state of a thread, will always work.
27348
27349 @node Thread groups
27350 @subsection Thread groups
27351 @value{GDBN} may be used to debug several processes at the same time.
27352 On some platfroms, @value{GDBN} may support debugging of several
27353 hardware systems, each one having several cores with several different
27354 processes running on each core.  This section describes the MI
27355 mechanism to support such debugging scenarios.
27356
27357 The key observation is that regardless of the structure of the 
27358 target, MI can have a global list of threads, because most commands that 
27359 accept the @samp{--thread} option do not need to know what process that
27360 thread belongs to.  Therefore, it is not necessary to introduce
27361 neither additional @samp{--process} option, nor an notion of the
27362 current process in the MI interface.  The only strictly new feature
27363 that is required is the ability to find how the threads are grouped
27364 into processes.
27365
27366 To allow the user to discover such grouping, and to support arbitrary
27367 hierarchy of machines/cores/processes, MI introduces the concept of a
27368 @dfn{thread group}.  Thread group is a collection of threads and other
27369 thread groups.  A thread group always has a string identifier, a type,
27370 and may have additional attributes specific to the type.  A new
27371 command, @code{-list-thread-groups}, returns the list of top-level
27372 thread groups, which correspond to processes that @value{GDBN} is
27373 debugging at the moment.  By passing an identifier of a thread group
27374 to the @code{-list-thread-groups} command, it is possible to obtain
27375 the members of specific thread group.
27376
27377 To allow the user to easily discover processes, and other objects, he
27378 wishes to debug, a concept of @dfn{available thread group} is
27379 introduced.  Available thread group is an thread group that
27380 @value{GDBN} is not debugging, but that can be attached to, using the
27381 @code{-target-attach} command.  The list of available top-level thread
27382 groups can be obtained using @samp{-list-thread-groups --available}.
27383 In general, the content of a thread group may be only retrieved only
27384 after attaching to that thread group.
27385
27386 Thread groups are related to inferiors (@pxref{Inferiors and
27387 Programs}).  Each inferior corresponds to a thread group of a special
27388 type @samp{process}, and some additional operations are permitted on
27389 such thread groups.
27390
27391 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27392 @node GDB/MI Command Syntax
27393 @section @sc{gdb/mi} Command Syntax
27394
27395 @menu
27396 * GDB/MI Input Syntax::
27397 * GDB/MI Output Syntax::
27398 @end menu
27399
27400 @node GDB/MI Input Syntax
27401 @subsection @sc{gdb/mi} Input Syntax
27402
27403 @cindex input syntax for @sc{gdb/mi}
27404 @cindex @sc{gdb/mi}, input syntax
27405 @table @code
27406 @item @var{command} @expansion{}
27407 @code{@var{cli-command} | @var{mi-command}}
27408
27409 @item @var{cli-command} @expansion{}
27410 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
27411 @var{cli-command} is any existing @value{GDBN} CLI command.
27412
27413 @item @var{mi-command} @expansion{}
27414 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
27415 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
27416
27417 @item @var{token} @expansion{}
27418 "any sequence of digits"
27419
27420 @item @var{option} @expansion{}
27421 @code{"-" @var{parameter} [ " " @var{parameter} ]}
27422
27423 @item @var{parameter} @expansion{}
27424 @code{@var{non-blank-sequence} | @var{c-string}}
27425
27426 @item @var{operation} @expansion{}
27427 @emph{any of the operations described in this chapter}
27428
27429 @item @var{non-blank-sequence} @expansion{}
27430 @emph{anything, provided it doesn't contain special characters such as
27431 "-", @var{nl}, """ and of course " "}
27432
27433 @item @var{c-string} @expansion{}
27434 @code{""" @var{seven-bit-iso-c-string-content} """}
27435
27436 @item @var{nl} @expansion{}
27437 @code{CR | CR-LF}
27438 @end table
27439
27440 @noindent
27441 Notes:
27442
27443 @itemize @bullet
27444 @item
27445 The CLI commands are still handled by the @sc{mi} interpreter; their
27446 output is described below.
27447
27448 @item
27449 The @code{@var{token}}, when present, is passed back when the command
27450 finishes.
27451
27452 @item
27453 Some @sc{mi} commands accept optional arguments as part of the parameter
27454 list.  Each option is identified by a leading @samp{-} (dash) and may be
27455 followed by an optional argument parameter.  Options occur first in the
27456 parameter list and can be delimited from normal parameters using
27457 @samp{--} (this is useful when some parameters begin with a dash).
27458 @end itemize
27459
27460 Pragmatics:
27461
27462 @itemize @bullet
27463 @item
27464 We want easy access to the existing CLI syntax (for debugging).
27465
27466 @item
27467 We want it to be easy to spot a @sc{mi} operation.
27468 @end itemize
27469
27470 @node GDB/MI Output Syntax
27471 @subsection @sc{gdb/mi} Output Syntax
27472
27473 @cindex output syntax of @sc{gdb/mi}
27474 @cindex @sc{gdb/mi}, output syntax
27475 The output from @sc{gdb/mi} consists of zero or more out-of-band records
27476 followed, optionally, by a single result record.  This result record
27477 is for the most recent command.  The sequence of output records is
27478 terminated by @samp{(gdb)}.
27479
27480 If an input command was prefixed with a @code{@var{token}} then the
27481 corresponding output for that command will also be prefixed by that same
27482 @var{token}.
27483
27484 @table @code
27485 @item @var{output} @expansion{}
27486 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
27487
27488 @item @var{result-record} @expansion{}
27489 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
27490
27491 @item @var{out-of-band-record} @expansion{}
27492 @code{@var{async-record} | @var{stream-record}}
27493
27494 @item @var{async-record} @expansion{}
27495 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
27496
27497 @item @var{exec-async-output} @expansion{}
27498 @code{[ @var{token} ] "*" @var{async-output}}
27499
27500 @item @var{status-async-output} @expansion{}
27501 @code{[ @var{token} ] "+" @var{async-output}}
27502
27503 @item @var{notify-async-output} @expansion{}
27504 @code{[ @var{token} ] "=" @var{async-output}}
27505
27506 @item @var{async-output} @expansion{}
27507 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
27508
27509 @item @var{result-class} @expansion{}
27510 @code{"done" | "running" | "connected" | "error" | "exit"}
27511
27512 @item @var{async-class} @expansion{}
27513 @code{"stopped" | @var{others}} (where @var{others} will be added
27514 depending on the needs---this is still in development).
27515
27516 @item @var{result} @expansion{}
27517 @code{ @var{variable} "=" @var{value}}
27518
27519 @item @var{variable} @expansion{}
27520 @code{ @var{string} }
27521
27522 @item @var{value} @expansion{}
27523 @code{ @var{const} | @var{tuple} | @var{list} }
27524
27525 @item @var{const} @expansion{}
27526 @code{@var{c-string}}
27527
27528 @item @var{tuple} @expansion{}
27529 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
27530
27531 @item @var{list} @expansion{}
27532 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
27533 @var{result} ( "," @var{result} )* "]" }
27534
27535 @item @var{stream-record} @expansion{}
27536 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
27537
27538 @item @var{console-stream-output} @expansion{}
27539 @code{"~" @var{c-string}}
27540
27541 @item @var{target-stream-output} @expansion{}
27542 @code{"@@" @var{c-string}}
27543
27544 @item @var{log-stream-output} @expansion{}
27545 @code{"&" @var{c-string}}
27546
27547 @item @var{nl} @expansion{}
27548 @code{CR | CR-LF}
27549
27550 @item @var{token} @expansion{}
27551 @emph{any sequence of digits}.
27552 @end table
27553
27554 @noindent
27555 Notes:
27556
27557 @itemize @bullet
27558 @item
27559 All output sequences end in a single line containing a period.
27560
27561 @item
27562 The @code{@var{token}} is from the corresponding request.  Note that
27563 for all async output, while the token is allowed by the grammar and
27564 may be output by future versions of @value{GDBN} for select async
27565 output messages, it is generally omitted.  Frontends should treat
27566 all async output as reporting general changes in the state of the
27567 target and there should be no need to associate async output to any
27568 prior command.
27569
27570 @item
27571 @cindex status output in @sc{gdb/mi}
27572 @var{status-async-output} contains on-going status information about the
27573 progress of a slow operation.  It can be discarded.  All status output is
27574 prefixed by @samp{+}.
27575
27576 @item
27577 @cindex async output in @sc{gdb/mi}
27578 @var{exec-async-output} contains asynchronous state change on the target
27579 (stopped, started, disappeared).  All async output is prefixed by
27580 @samp{*}.
27581
27582 @item
27583 @cindex notify output in @sc{gdb/mi}
27584 @var{notify-async-output} contains supplementary information that the
27585 client should handle (e.g., a new breakpoint information).  All notify
27586 output is prefixed by @samp{=}.
27587
27588 @item
27589 @cindex console output in @sc{gdb/mi}
27590 @var{console-stream-output} is output that should be displayed as is in the
27591 console.  It is the textual response to a CLI command.  All the console
27592 output is prefixed by @samp{~}.
27593
27594 @item
27595 @cindex target output in @sc{gdb/mi}
27596 @var{target-stream-output} is the output produced by the target program.
27597 All the target output is prefixed by @samp{@@}.
27598
27599 @item
27600 @cindex log output in @sc{gdb/mi}
27601 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
27602 instance messages that should be displayed as part of an error log.  All
27603 the log output is prefixed by @samp{&}.
27604
27605 @item
27606 @cindex list output in @sc{gdb/mi}
27607 New @sc{gdb/mi} commands should only output @var{lists} containing
27608 @var{values}.
27609
27610
27611 @end itemize
27612
27613 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
27614 details about the various output records.
27615
27616 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27617 @node GDB/MI Compatibility with CLI
27618 @section @sc{gdb/mi} Compatibility with CLI
27619
27620 @cindex compatibility, @sc{gdb/mi} and CLI
27621 @cindex @sc{gdb/mi}, compatibility with CLI
27622
27623 For the developers convenience CLI commands can be entered directly,
27624 but there may be some unexpected behaviour.  For example, commands
27625 that query the user will behave as if the user replied yes, breakpoint
27626 command lists are not executed and some CLI commands, such as
27627 @code{if}, @code{when} and @code{define}, prompt for further input with
27628 @samp{>}, which is not valid MI output.
27629
27630 This feature may be removed at some stage in the future and it is
27631 recommended that front ends use the @code{-interpreter-exec} command
27632 (@pxref{-interpreter-exec}).
27633
27634 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27635 @node GDB/MI Development and Front Ends
27636 @section @sc{gdb/mi} Development and Front Ends
27637 @cindex @sc{gdb/mi} development
27638
27639 The application which takes the MI output and presents the state of the
27640 program being debugged to the user is called a @dfn{front end}.
27641
27642 Although @sc{gdb/mi} is still incomplete, it is currently being used
27643 by a variety of front ends to @value{GDBN}.  This makes it difficult
27644 to introduce new functionality without breaking existing usage.  This
27645 section tries to minimize the problems by describing how the protocol
27646 might change.
27647
27648 Some changes in MI need not break a carefully designed front end, and
27649 for these the MI version will remain unchanged.  The following is a
27650 list of changes that may occur within one level, so front ends should
27651 parse MI output in a way that can handle them:
27652
27653 @itemize @bullet
27654 @item
27655 New MI commands may be added.
27656
27657 @item
27658 New fields may be added to the output of any MI command.
27659
27660 @item
27661 The range of values for fields with specified values, e.g.,
27662 @code{in_scope} (@pxref{-var-update}) may be extended.
27663
27664 @c The format of field's content e.g type prefix, may change so parse it
27665 @c   at your own risk.  Yes, in general?
27666
27667 @c The order of fields may change?  Shouldn't really matter but it might
27668 @c resolve inconsistencies.
27669 @end itemize
27670
27671 If the changes are likely to break front ends, the MI version level
27672 will be increased by one.  This will allow the front end to parse the
27673 output according to the MI version.  Apart from mi0, new versions of
27674 @value{GDBN} will not support old versions of MI and it will be the
27675 responsibility of the front end to work with the new one.
27676
27677 @c Starting with mi3, add a new command -mi-version that prints the MI
27678 @c version?
27679
27680 The best way to avoid unexpected changes in MI that might break your front
27681 end is to make your project known to @value{GDBN} developers and
27682 follow development on @email{gdb@@sourceware.org} and
27683 @email{gdb-patches@@sourceware.org}.
27684 @cindex mailing lists
27685
27686 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27687 @node GDB/MI Output Records
27688 @section @sc{gdb/mi} Output Records
27689
27690 @menu
27691 * GDB/MI Result Records::
27692 * GDB/MI Stream Records::
27693 * GDB/MI Async Records::
27694 * GDB/MI Frame Information::
27695 * GDB/MI Thread Information::
27696 * GDB/MI Ada Exception Information::
27697 @end menu
27698
27699 @node GDB/MI Result Records
27700 @subsection @sc{gdb/mi} Result Records
27701
27702 @cindex result records in @sc{gdb/mi}
27703 @cindex @sc{gdb/mi}, result records
27704 In addition to a number of out-of-band notifications, the response to a
27705 @sc{gdb/mi} command includes one of the following result indications:
27706
27707 @table @code
27708 @findex ^done
27709 @item "^done" [ "," @var{results} ]
27710 The synchronous operation was successful, @code{@var{results}} are the return
27711 values.
27712
27713 @item "^running"
27714 @findex ^running
27715 This result record is equivalent to @samp{^done}.  Historically, it
27716 was output instead of @samp{^done} if the command has resumed the
27717 target.  This behaviour is maintained for backward compatibility, but
27718 all frontends should treat @samp{^done} and @samp{^running}
27719 identically and rely on the @samp{*running} output record to determine
27720 which threads are resumed.
27721
27722 @item "^connected"
27723 @findex ^connected
27724 @value{GDBN} has connected to a remote target.
27725
27726 @item "^error" "," @var{c-string}
27727 @findex ^error
27728 The operation failed.  The @code{@var{c-string}} contains the corresponding
27729 error message.
27730
27731 @item "^exit"
27732 @findex ^exit
27733 @value{GDBN} has terminated.
27734
27735 @end table
27736
27737 @node GDB/MI Stream Records
27738 @subsection @sc{gdb/mi} Stream Records
27739
27740 @cindex @sc{gdb/mi}, stream records
27741 @cindex stream records in @sc{gdb/mi}
27742 @value{GDBN} internally maintains a number of output streams: the console, the
27743 target, and the log.  The output intended for each of these streams is
27744 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
27745
27746 Each stream record begins with a unique @dfn{prefix character} which
27747 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
27748 Syntax}).  In addition to the prefix, each stream record contains a
27749 @code{@var{string-output}}.  This is either raw text (with an implicit new
27750 line) or a quoted C string (which does not contain an implicit newline).
27751
27752 @table @code
27753 @item "~" @var{string-output}
27754 The console output stream contains text that should be displayed in the
27755 CLI console window.  It contains the textual responses to CLI commands.
27756
27757 @item "@@" @var{string-output}
27758 The target output stream contains any textual output from the running
27759 target.  This is only present when GDB's event loop is truly
27760 asynchronous, which is currently only the case for remote targets.
27761
27762 @item "&" @var{string-output}
27763 The log stream contains debugging messages being produced by @value{GDBN}'s
27764 internals.
27765 @end table
27766
27767 @node GDB/MI Async Records
27768 @subsection @sc{gdb/mi} Async Records
27769
27770 @cindex async records in @sc{gdb/mi}
27771 @cindex @sc{gdb/mi}, async records
27772 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
27773 additional changes that have occurred.  Those changes can either be a
27774 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
27775 target activity (e.g., target stopped).
27776
27777 The following is the list of possible async records:
27778
27779 @table @code
27780
27781 @item *running,thread-id="@var{thread}"
27782 The target is now running.  The @var{thread} field tells which
27783 specific thread is now running, and can be @samp{all} if all threads
27784 are running.  The frontend should assume that no interaction with a 
27785 running thread is possible after this notification is produced.
27786 The frontend should not assume that this notification is output
27787 only once for any command.  @value{GDBN} may emit this notification 
27788 several times, either for different threads, because it cannot resume
27789 all threads together, or even for a single thread, if the thread must
27790 be stepped though some code before letting it run freely.
27791
27792 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
27793 The target has stopped.  The @var{reason} field can have one of the
27794 following values:
27795
27796 @table @code
27797 @item breakpoint-hit
27798 A breakpoint was reached.
27799 @item watchpoint-trigger
27800 A watchpoint was triggered.
27801 @item read-watchpoint-trigger
27802 A read watchpoint was triggered.
27803 @item access-watchpoint-trigger 
27804 An access watchpoint was triggered.
27805 @item function-finished
27806 An -exec-finish or similar CLI command was accomplished.
27807 @item location-reached
27808 An -exec-until or similar CLI command was accomplished.
27809 @item watchpoint-scope
27810 A watchpoint has gone out of scope.
27811 @item end-stepping-range
27812 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or 
27813 similar CLI command was accomplished.
27814 @item exited-signalled 
27815 The inferior exited because of a signal.
27816 @item exited 
27817 The inferior exited.
27818 @item exited-normally 
27819 The inferior exited normally.
27820 @item signal-received 
27821 A signal was received by the inferior.
27822 @item solib-event
27823 The inferior has stopped due to a library being loaded or unloaded.
27824 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
27825 set or when a @code{catch load} or @code{catch unload} catchpoint is
27826 in use (@pxref{Set Catchpoints}).
27827 @item fork
27828 The inferior has forked.  This is reported when @code{catch fork}
27829 (@pxref{Set Catchpoints}) has been used.
27830 @item vfork
27831 The inferior has vforked.  This is reported in when @code{catch vfork}
27832 (@pxref{Set Catchpoints}) has been used.
27833 @item syscall-entry
27834 The inferior entered a system call.  This is reported when @code{catch
27835 syscall} (@pxref{Set Catchpoints}) has been used.
27836 @item syscall-entry
27837 The inferior returned from a system call.  This is reported when
27838 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
27839 @item exec
27840 The inferior called @code{exec}.  This is reported when @code{catch exec}
27841 (@pxref{Set Catchpoints}) has been used.
27842 @end table
27843
27844 The @var{id} field identifies the thread that directly caused the stop
27845 -- for example by hitting a breakpoint.  Depending on whether all-stop
27846 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
27847 stop all threads, or only the thread that directly triggered the stop.
27848 If all threads are stopped, the @var{stopped} field will have the
27849 value of @code{"all"}.  Otherwise, the value of the @var{stopped}
27850 field will be a list of thread identifiers.  Presently, this list will
27851 always include a single thread, but frontend should be prepared to see
27852 several threads in the list.  The @var{core} field reports the
27853 processor core on which the stop event has happened.  This field may be absent
27854 if such information is not available.
27855
27856 @item =thread-group-added,id="@var{id}"
27857 @itemx =thread-group-removed,id="@var{id}"
27858 A thread group was either added or removed.  The @var{id} field
27859 contains the @value{GDBN} identifier of the thread group.  When a thread
27860 group is added, it generally might not be associated with a running
27861 process.  When a thread group is removed, its id becomes invalid and
27862 cannot be used in any way.
27863
27864 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
27865 A thread group became associated with a running program,
27866 either because the program was just started or the thread group
27867 was attached to a program.  The @var{id} field contains the
27868 @value{GDBN} identifier of the thread group.  The @var{pid} field
27869 contains process identifier, specific to the operating system.
27870
27871 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
27872 A thread group is no longer associated with a running program,
27873 either because the program has exited, or because it was detached
27874 from.  The @var{id} field contains the @value{GDBN} identifier of the
27875 thread group.  @var{code} is the exit code of the inferior; it exists
27876 only when the inferior exited with some code.
27877
27878 @item =thread-created,id="@var{id}",group-id="@var{gid}"
27879 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
27880 A thread either was created, or has exited.  The @var{id} field
27881 contains the @value{GDBN} identifier of the thread.  The @var{gid}
27882 field identifies the thread group this thread belongs to.
27883
27884 @item =thread-selected,id="@var{id}"
27885 Informs that the selected thread was changed as result of the last
27886 command.  This notification is not emitted as result of @code{-thread-select}
27887 command but is emitted whenever an MI command that is not documented
27888 to change the selected thread actually changes it.  In particular,
27889 invoking, directly or indirectly (via user-defined command), the CLI
27890 @code{thread} command, will generate this notification.
27891
27892 We suggest that in response to this notification, front ends
27893 highlight the selected thread and cause subsequent commands to apply to
27894 that thread.
27895
27896 @item =library-loaded,...
27897 Reports that a new library file was loaded by the program.  This
27898 notification has 4 fields---@var{id}, @var{target-name},
27899 @var{host-name}, and @var{symbols-loaded}.  The @var{id} field is an
27900 opaque identifier of the library.  For remote debugging case,
27901 @var{target-name} and @var{host-name} fields give the name of the
27902 library file on the target, and on the host respectively.  For native
27903 debugging, both those fields have the same value.  The
27904 @var{symbols-loaded} field is emitted only for backward compatibility
27905 and should not be relied on to convey any useful information.  The
27906 @var{thread-group} field, if present, specifies the id of the thread
27907 group in whose context the library was loaded.  If the field is
27908 absent, it means the library was loaded in the context of all present
27909 thread groups.
27910
27911 @item =library-unloaded,...
27912 Reports that a library was unloaded by the program.  This notification
27913 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
27914 the same meaning as for the @code{=library-loaded} notification.
27915 The @var{thread-group} field, if present, specifies the id of the
27916 thread group in whose context the library was unloaded.  If the field is
27917 absent, it means the library was unloaded in the context of all present
27918 thread groups.
27919
27920 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
27921 @itemx =traceframe-changed,end
27922 Reports that the trace frame was changed and its new number is
27923 @var{tfnum}.  The number of the tracepoint associated with this trace
27924 frame is @var{tpnum}.
27925
27926 @item =tsv-created,name=@var{name},value=@var{value}
27927 Reports that the new trace state variable @var{name} is created with
27928 value @var{value}.
27929
27930 @item =tsv-deleted,name=@var{name}
27931 @itemx =tsv-deleted
27932 Reports that the trace state variable @var{name} is deleted or all
27933 trace state variables are deleted.
27934
27935 @item =breakpoint-created,bkpt=@{...@}
27936 @itemx =breakpoint-modified,bkpt=@{...@}
27937 @itemx =breakpoint-deleted,id=@var{number}
27938 Reports that a breakpoint was created, modified, or deleted,
27939 respectively.  Only user-visible breakpoints are reported to the MI
27940 user.
27941
27942 The @var{bkpt} argument is of the same form as returned by the various
27943 breakpoint commands; @xref{GDB/MI Breakpoint Commands}.  The
27944 @var{number} is the ordinal number of the breakpoint.
27945
27946 Note that if a breakpoint is emitted in the result record of a
27947 command, then it will not also be emitted in an async record.
27948
27949 @item =record-started,thread-group="@var{id}"
27950 @itemx =record-stopped,thread-group="@var{id}"
27951 Execution log recording was either started or stopped on an
27952 inferior.  The @var{id} is the @value{GDBN} identifier of the thread
27953 group corresponding to the affected inferior.
27954
27955 @item =cmd-param-changed,param=@var{param},value=@var{value}
27956 Reports that a parameter of the command @code{set @var{param}} is
27957 changed to @var{value}.  In the multi-word @code{set} command,
27958 the @var{param} is the whole parameter list to @code{set} command.
27959 For example, In command @code{set check type on}, @var{param}
27960 is @code{check type} and @var{value} is @code{on}.
27961
27962 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
27963 Reports that bytes from @var{addr} to @var{data} + @var{len} were
27964 written in an inferior.  The @var{id} is the identifier of the
27965 thread group corresponding to the affected inferior.  The optional
27966 @code{type="code"} part is reported if the memory written to holds
27967 executable code.
27968 @end table
27969
27970 @node GDB/MI Frame Information
27971 @subsection @sc{gdb/mi} Frame Information
27972
27973 Response from many MI commands includes an information about stack
27974 frame.  This information is a tuple that may have the following
27975 fields:
27976
27977 @table @code
27978 @item level
27979 The level of the stack frame.  The innermost frame has the level of
27980 zero.  This field is always present.
27981
27982 @item func
27983 The name of the function corresponding to the frame.  This field may
27984 be absent if @value{GDBN} is unable to determine the function name.
27985
27986 @item addr
27987 The code address for the frame.  This field is always present.
27988
27989 @item file
27990 The name of the source files that correspond to the frame's code
27991 address.  This field may be absent.
27992
27993 @item line
27994 The source line corresponding to the frames' code address.  This field
27995 may be absent.
27996
27997 @item from
27998 The name of the binary file (either executable or shared library) the
27999 corresponds to the frame's code address.  This field may be absent.
28000
28001 @end table
28002
28003 @node GDB/MI Thread Information
28004 @subsection @sc{gdb/mi} Thread Information
28005
28006 Whenever @value{GDBN} has to report an information about a thread, it
28007 uses a tuple with the following fields:
28008
28009 @table @code
28010 @item id
28011 The numeric id assigned to the thread by @value{GDBN}.  This field is
28012 always present.
28013
28014 @item target-id
28015 Target-specific string identifying the thread.  This field is always present.
28016
28017 @item details
28018 Additional information about the thread provided by the target.
28019 It is supposed to be human-readable and not interpreted by the
28020 frontend.  This field is optional.
28021
28022 @item state
28023 Either @samp{stopped} or @samp{running}, depending on whether the
28024 thread is presently running.  This field is always present.
28025
28026 @item core
28027 The value of this field is an integer number of the processor core the
28028 thread was last seen on.  This field is optional.
28029 @end table
28030
28031 @node GDB/MI Ada Exception Information
28032 @subsection @sc{gdb/mi} Ada Exception Information
28033
28034 Whenever a @code{*stopped} record is emitted because the program
28035 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
28036 @value{GDBN} provides the name of the exception that was raised via
28037 the @code{exception-name} field.
28038
28039 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28040 @node GDB/MI Simple Examples
28041 @section Simple Examples of @sc{gdb/mi} Interaction
28042 @cindex @sc{gdb/mi}, simple examples
28043
28044 This subsection presents several simple examples of interaction using
28045 the @sc{gdb/mi} interface.  In these examples, @samp{->} means that the
28046 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
28047 the output received from @sc{gdb/mi}.
28048
28049 Note the line breaks shown in the examples are here only for
28050 readability, they don't appear in the real output.
28051
28052 @subheading Setting a Breakpoint
28053
28054 Setting a breakpoint generates synchronous output which contains detailed
28055 information of the breakpoint.
28056
28057 @smallexample
28058 -> -break-insert main
28059 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28060     enabled="y",addr="0x08048564",func="main",file="myprog.c",
28061     fullname="/home/nickrob/myprog.c",line="68",times="0"@}
28062 <- (gdb)
28063 @end smallexample
28064
28065 @subheading Program Execution
28066
28067 Program execution generates asynchronous records and MI gives the
28068 reason that execution stopped.
28069
28070 @smallexample
28071 -> -exec-run
28072 <- ^running
28073 <- (gdb)
28074 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
28075    frame=@{addr="0x08048564",func="main",
28076    args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
28077    file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
28078 <- (gdb)
28079 -> -exec-continue
28080 <- ^running
28081 <- (gdb)
28082 <- *stopped,reason="exited-normally"
28083 <- (gdb)
28084 @end smallexample
28085
28086 @subheading Quitting @value{GDBN}
28087
28088 Quitting @value{GDBN} just prints the result class @samp{^exit}.
28089
28090 @smallexample
28091 -> (gdb)
28092 <- -gdb-exit
28093 <- ^exit
28094 @end smallexample
28095
28096 Please note that @samp{^exit} is printed immediately, but it might
28097 take some time for @value{GDBN} to actually exit.  During that time, @value{GDBN}
28098 performs necessary cleanups, including killing programs being debugged
28099 or disconnecting from debug hardware, so the frontend should wait till
28100 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
28101 fails to exit in reasonable time.
28102
28103 @subheading A Bad Command
28104
28105 Here's what happens if you pass a non-existent command:
28106
28107 @smallexample
28108 -> -rubbish
28109 <- ^error,msg="Undefined MI command: rubbish"
28110 <- (gdb)
28111 @end smallexample
28112
28113
28114 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28115 @node GDB/MI Command Description Format
28116 @section @sc{gdb/mi} Command Description Format
28117
28118 The remaining sections describe blocks of commands.  Each block of
28119 commands is laid out in a fashion similar to this section.
28120
28121 @subheading Motivation
28122
28123 The motivation for this collection of commands.
28124
28125 @subheading Introduction
28126
28127 A brief introduction to this collection of commands as a whole.
28128
28129 @subheading Commands
28130
28131 For each command in the block, the following is described:
28132
28133 @subsubheading Synopsis
28134
28135 @smallexample
28136  -command @var{args}@dots{}
28137 @end smallexample
28138
28139 @subsubheading Result
28140
28141 @subsubheading @value{GDBN} Command
28142
28143 The corresponding @value{GDBN} CLI command(s), if any.
28144
28145 @subsubheading Example
28146
28147 Example(s) formatted for readability.  Some of the described commands  have
28148 not been implemented yet and these are labeled N.A.@: (not available).
28149
28150
28151 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28152 @node GDB/MI Breakpoint Commands
28153 @section @sc{gdb/mi} Breakpoint Commands
28154
28155 @cindex breakpoint commands for @sc{gdb/mi}
28156 @cindex @sc{gdb/mi}, breakpoint commands
28157 This section documents @sc{gdb/mi} commands for manipulating
28158 breakpoints.
28159
28160 @subheading The @code{-break-after} Command
28161 @findex -break-after
28162
28163 @subsubheading Synopsis
28164
28165 @smallexample
28166  -break-after @var{number} @var{count}
28167 @end smallexample
28168
28169 The breakpoint number @var{number} is not in effect until it has been
28170 hit @var{count} times.  To see how this is reflected in the output of
28171 the @samp{-break-list} command, see the description of the
28172 @samp{-break-list} command below.
28173
28174 @subsubheading @value{GDBN} Command
28175
28176 The corresponding @value{GDBN} command is @samp{ignore}.
28177
28178 @subsubheading Example
28179
28180 @smallexample
28181 (gdb)
28182 -break-insert main
28183 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28184 enabled="y",addr="0x000100d0",func="main",file="hello.c",
28185 fullname="/home/foo/hello.c",line="5",times="0"@}
28186 (gdb)
28187 -break-after 1 3
28188 ~
28189 ^done
28190 (gdb)
28191 -break-list
28192 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28193 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28194 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28195 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28196 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28197 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28198 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28199 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28200 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28201 line="5",times="0",ignore="3"@}]@}
28202 (gdb)
28203 @end smallexample
28204
28205 @ignore
28206 @subheading The @code{-break-catch} Command
28207 @findex -break-catch
28208 @end ignore
28209
28210 @subheading The @code{-break-commands} Command
28211 @findex -break-commands
28212
28213 @subsubheading Synopsis
28214
28215 @smallexample
28216  -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
28217 @end smallexample
28218
28219 Specifies the CLI commands that should be executed when breakpoint
28220 @var{number} is hit.  The parameters @var{command1} to @var{commandN}
28221 are the commands.  If no command is specified, any previously-set
28222 commands are cleared.  @xref{Break Commands}.  Typical use of this
28223 functionality is tracing a program, that is, printing of values of
28224 some variables whenever breakpoint is hit and then continuing.
28225
28226 @subsubheading @value{GDBN} Command
28227
28228 The corresponding @value{GDBN} command is @samp{commands}.
28229
28230 @subsubheading Example
28231
28232 @smallexample
28233 (gdb)
28234 -break-insert main
28235 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28236 enabled="y",addr="0x000100d0",func="main",file="hello.c",
28237 fullname="/home/foo/hello.c",line="5",times="0"@}
28238 (gdb)
28239 -break-commands 1 "print v" "continue"
28240 ^done
28241 (gdb)
28242 @end smallexample
28243
28244 @subheading The @code{-break-condition} Command
28245 @findex -break-condition
28246
28247 @subsubheading Synopsis
28248
28249 @smallexample
28250  -break-condition @var{number} @var{expr}
28251 @end smallexample
28252
28253 Breakpoint @var{number} will stop the program only if the condition in
28254 @var{expr} is true.  The condition becomes part of the
28255 @samp{-break-list} output (see the description of the @samp{-break-list}
28256 command below).
28257
28258 @subsubheading @value{GDBN} Command
28259
28260 The corresponding @value{GDBN} command is @samp{condition}.
28261
28262 @subsubheading Example
28263
28264 @smallexample
28265 (gdb)
28266 -break-condition 1 1
28267 ^done
28268 (gdb)
28269 -break-list
28270 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28271 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28272 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28273 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28274 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28275 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28276 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28277 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28278 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28279 line="5",cond="1",times="0",ignore="3"@}]@}
28280 (gdb)
28281 @end smallexample
28282
28283 @subheading The @code{-break-delete} Command
28284 @findex -break-delete
28285
28286 @subsubheading Synopsis
28287
28288 @smallexample
28289  -break-delete ( @var{breakpoint} )+
28290 @end smallexample
28291
28292 Delete the breakpoint(s) whose number(s) are specified in the argument
28293 list.  This is obviously reflected in the breakpoint list.
28294
28295 @subsubheading @value{GDBN} Command
28296
28297 The corresponding @value{GDBN} command is @samp{delete}.
28298
28299 @subsubheading Example
28300
28301 @smallexample
28302 (gdb)
28303 -break-delete 1
28304 ^done
28305 (gdb)
28306 -break-list
28307 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28308 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28309 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28310 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28311 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28312 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28313 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28314 body=[]@}
28315 (gdb)
28316 @end smallexample
28317
28318 @subheading The @code{-break-disable} Command
28319 @findex -break-disable
28320
28321 @subsubheading Synopsis
28322
28323 @smallexample
28324  -break-disable ( @var{breakpoint} )+
28325 @end smallexample
28326
28327 Disable the named @var{breakpoint}(s).  The field @samp{enabled} in the
28328 break list is now set to @samp{n} for the named @var{breakpoint}(s).
28329
28330 @subsubheading @value{GDBN} Command
28331
28332 The corresponding @value{GDBN} command is @samp{disable}.
28333
28334 @subsubheading Example
28335
28336 @smallexample
28337 (gdb)
28338 -break-disable 2
28339 ^done
28340 (gdb)
28341 -break-list
28342 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28343 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28344 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28345 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28346 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28347 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28348 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28349 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
28350 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28351 line="5",times="0"@}]@}
28352 (gdb)
28353 @end smallexample
28354
28355 @subheading The @code{-break-enable} Command
28356 @findex -break-enable
28357
28358 @subsubheading Synopsis
28359
28360 @smallexample
28361  -break-enable ( @var{breakpoint} )+
28362 @end smallexample
28363
28364 Enable (previously disabled) @var{breakpoint}(s).
28365
28366 @subsubheading @value{GDBN} Command
28367
28368 The corresponding @value{GDBN} command is @samp{enable}.
28369
28370 @subsubheading Example
28371
28372 @smallexample
28373 (gdb)
28374 -break-enable 2
28375 ^done
28376 (gdb)
28377 -break-list
28378 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28379 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28380 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28381 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28382 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28383 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28384 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28385 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
28386 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
28387 line="5",times="0"@}]@}
28388 (gdb)
28389 @end smallexample
28390
28391 @subheading The @code{-break-info} Command
28392 @findex -break-info
28393
28394 @subsubheading Synopsis
28395
28396 @smallexample
28397  -break-info @var{breakpoint}
28398 @end smallexample
28399
28400 @c REDUNDANT???
28401 Get information about a single breakpoint.
28402
28403 @subsubheading @value{GDBN} Command
28404
28405 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
28406
28407 @subsubheading Example
28408 N.A.
28409
28410 @subheading The @code{-break-insert} Command
28411 @findex -break-insert
28412
28413 @subsubheading Synopsis
28414
28415 @smallexample
28416  -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
28417     [ -c @var{condition} ] [ -i @var{ignore-count} ]
28418     [ -p @var{thread-id} ] [ @var{location} ]
28419 @end smallexample
28420
28421 @noindent
28422 If specified, @var{location}, can be one of:
28423
28424 @itemize @bullet
28425 @item function
28426 @c @item +offset
28427 @c @item -offset
28428 @c @item linenum
28429 @item filename:linenum
28430 @item filename:function
28431 @item *address
28432 @end itemize
28433
28434 The possible optional parameters of this command are:
28435
28436 @table @samp
28437 @item -t
28438 Insert a temporary breakpoint.
28439 @item -h
28440 Insert a hardware breakpoint.
28441 @item -f
28442 If @var{location} cannot be parsed (for example if it
28443 refers to unknown files or functions), create a pending
28444 breakpoint. Without this flag, @value{GDBN} will report
28445 an error, and won't create a breakpoint, if @var{location}
28446 cannot be parsed.
28447 @item -d
28448 Create a disabled breakpoint.
28449 @item -a
28450 Create a tracepoint.  @xref{Tracepoints}.  When this parameter
28451 is used together with @samp{-h}, a fast tracepoint is created.
28452 @item -c @var{condition}
28453 Make the breakpoint conditional on @var{condition}.
28454 @item -i @var{ignore-count}
28455 Initialize the @var{ignore-count}.
28456 @item -p @var{thread-id}
28457 Restrict the breakpoint to the specified @var{thread-id}.
28458 @end table
28459
28460 @subsubheading Result
28461
28462 The result is in the form:
28463
28464 @smallexample
28465 ^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
28466 enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
28467 fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
28468 times="@var{times}"[,installed="@var{installed}"]@}
28469 @end smallexample
28470
28471 @noindent
28472 where @var{number} is the @value{GDBN} number for this breakpoint,
28473 @var{funcname} is the name of the function where the breakpoint was
28474 inserted, @var{filename} is the name of the source file which contains
28475 this function, @var{lineno} is the source line number within that file,
28476 @var{times} the number of times that the breakpoint has been hit
28477 (always 0 for -break-insert but may be greater for -break-info or -break-list
28478 which use the same output), and @var{installed}, which is an optional
28479 boolean, is about the state of each non-pending tracepoint location
28480 installed on target or not.
28481
28482 Note: this format is open to change.
28483 @c An out-of-band breakpoint instead of part of the result?
28484
28485 @subsubheading @value{GDBN} Command
28486
28487 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
28488 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
28489
28490 @subsubheading Example
28491
28492 @smallexample
28493 (gdb)
28494 -break-insert main
28495 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
28496 fullname="/home/foo/recursive2.c,line="4",times="0"@}
28497 (gdb)
28498 -break-insert -t foo
28499 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
28500 fullname="/home/foo/recursive2.c,line="11",times="0"@}
28501 (gdb)
28502 -break-list
28503 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28504 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28505 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28506 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28507 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28508 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28509 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28510 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28511 addr="0x0001072c", func="main",file="recursive2.c",
28512 fullname="/home/foo/recursive2.c,"line="4",times="0"@},
28513 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
28514 addr="0x00010774",func="foo",file="recursive2.c",
28515 fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
28516 (gdb)
28517 @c -break-insert -r foo.*
28518 @c ~int foo(int, int);
28519 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
28520 @c "fullname="/home/foo/recursive2.c",line="11",times="0"@}
28521 @c (gdb)
28522 @end smallexample
28523
28524 @subheading The @code{-break-list} Command
28525 @findex -break-list
28526
28527 @subsubheading Synopsis
28528
28529 @smallexample
28530  -break-list
28531 @end smallexample
28532
28533 Displays the list of inserted breakpoints, showing the following fields:
28534
28535 @table @samp
28536 @item Number
28537 number of the breakpoint
28538 @item Type
28539 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
28540 @item Disposition
28541 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
28542 or @samp{nokeep}
28543 @item Enabled
28544 is the breakpoint enabled or no: @samp{y} or @samp{n}
28545 @item Address
28546 memory location at which the breakpoint is set
28547 @item What
28548 logical location of the breakpoint, expressed by function name, file
28549 name, line number
28550 @item Times
28551 number of times the breakpoint has been hit
28552 @end table
28553
28554 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
28555 @code{body} field is an empty list.
28556
28557 @subsubheading @value{GDBN} Command
28558
28559 The corresponding @value{GDBN} command is @samp{info break}.
28560
28561 @subsubheading Example
28562
28563 @smallexample
28564 (gdb)
28565 -break-list
28566 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28567 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28568 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28569 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28570 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28571 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28572 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28573 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28574 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
28575 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
28576 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
28577 line="13",times="0"@}]@}
28578 (gdb)
28579 @end smallexample
28580
28581 Here's an example of the result when there are no breakpoints:
28582
28583 @smallexample
28584 (gdb)
28585 -break-list
28586 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
28587 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28588 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28589 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28590 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28591 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28592 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28593 body=[]@}
28594 (gdb)
28595 @end smallexample
28596
28597 @subheading The @code{-break-passcount} Command
28598 @findex -break-passcount
28599
28600 @subsubheading Synopsis
28601
28602 @smallexample
28603  -break-passcount @var{tracepoint-number} @var{passcount}
28604 @end smallexample
28605
28606 Set the passcount for tracepoint @var{tracepoint-number} to
28607 @var{passcount}.  If the breakpoint referred to by @var{tracepoint-number}
28608 is not a tracepoint, error is emitted.  This corresponds to CLI
28609 command @samp{passcount}.
28610
28611 @subheading The @code{-break-watch} Command
28612 @findex -break-watch
28613
28614 @subsubheading Synopsis
28615
28616 @smallexample
28617  -break-watch [ -a | -r ]
28618 @end smallexample
28619
28620 Create a watchpoint.  With the @samp{-a} option it will create an
28621 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
28622 read from or on a write to the memory location.  With the @samp{-r}
28623 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
28624 trigger only when the memory location is accessed for reading.  Without
28625 either of the options, the watchpoint created is a regular watchpoint,
28626 i.e., it will trigger when the memory location is accessed for writing.
28627 @xref{Set Watchpoints, , Setting Watchpoints}.
28628
28629 Note that @samp{-break-list} will report a single list of watchpoints and
28630 breakpoints inserted.
28631
28632 @subsubheading @value{GDBN} Command
28633
28634 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
28635 @samp{rwatch}.
28636
28637 @subsubheading Example
28638
28639 Setting a watchpoint on a variable in the @code{main} function:
28640
28641 @smallexample
28642 (gdb)
28643 -break-watch x
28644 ^done,wpt=@{number="2",exp="x"@}
28645 (gdb)
28646 -exec-continue
28647 ^running
28648 (gdb)
28649 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
28650 value=@{old="-268439212",new="55"@},
28651 frame=@{func="main",args=[],file="recursive2.c",
28652 fullname="/home/foo/bar/recursive2.c",line="5"@}
28653 (gdb)
28654 @end smallexample
28655
28656 Setting a watchpoint on a variable local to a function.  @value{GDBN} will stop
28657 the program execution twice: first for the variable changing value, then
28658 for the watchpoint going out of scope.
28659
28660 @smallexample
28661 (gdb)
28662 -break-watch C
28663 ^done,wpt=@{number="5",exp="C"@}
28664 (gdb)
28665 -exec-continue
28666 ^running
28667 (gdb)
28668 *stopped,reason="watchpoint-trigger",
28669 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
28670 frame=@{func="callee4",args=[],
28671 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28672 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
28673 (gdb)
28674 -exec-continue
28675 ^running
28676 (gdb)
28677 *stopped,reason="watchpoint-scope",wpnum="5",
28678 frame=@{func="callee3",args=[@{name="strarg",
28679 value="0x11940 \"A string argument.\""@}],
28680 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28681 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
28682 (gdb)
28683 @end smallexample
28684
28685 Listing breakpoints and watchpoints, at different points in the program
28686 execution.  Note that once the watchpoint goes out of scope, it is
28687 deleted.
28688
28689 @smallexample
28690 (gdb)
28691 -break-watch C
28692 ^done,wpt=@{number="2",exp="C"@}
28693 (gdb)
28694 -break-list
28695 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28696 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28697 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28698 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28699 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28700 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28701 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28702 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28703 addr="0x00010734",func="callee4",
28704 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28705 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
28706 bkpt=@{number="2",type="watchpoint",disp="keep",
28707 enabled="y",addr="",what="C",times="0"@}]@}
28708 (gdb)
28709 -exec-continue
28710 ^running
28711 (gdb)
28712 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
28713 value=@{old="-276895068",new="3"@},
28714 frame=@{func="callee4",args=[],
28715 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28716 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
28717 (gdb)
28718 -break-list
28719 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
28720 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28721 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28722 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28723 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28724 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28725 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28726 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28727 addr="0x00010734",func="callee4",
28728 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28729 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
28730 bkpt=@{number="2",type="watchpoint",disp="keep",
28731 enabled="y",addr="",what="C",times="-5"@}]@}
28732 (gdb)
28733 -exec-continue
28734 ^running
28735 ^done,reason="watchpoint-scope",wpnum="2",
28736 frame=@{func="callee3",args=[@{name="strarg",
28737 value="0x11940 \"A string argument.\""@}],
28738 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28739 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
28740 (gdb)
28741 -break-list
28742 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28743 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28744 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28745 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28746 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28747 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28748 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
28749 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28750 addr="0x00010734",func="callee4",
28751 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28752 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
28753 times="1"@}]@}
28754 (gdb)
28755 @end smallexample
28756
28757
28758 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28759 @node GDB/MI Catchpoint Commands
28760 @section @sc{gdb/mi} Catchpoint Commands
28761
28762 This section documents @sc{gdb/mi} commands for manipulating
28763 catchpoints.
28764
28765 @subheading The @code{-catch-load} Command
28766 @findex -catch-load
28767
28768 @subsubheading Synopsis
28769
28770 @smallexample
28771  -catch-load [ -t ] [ -d ] @var{regexp}
28772 @end smallexample
28773
28774 Add a catchpoint for library load events.  If the @samp{-t} option is used,
28775 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
28776 Breakpoints}).  If the @samp{-d} option is used, the catchpoint is created
28777 in a disabled state.  The @samp{regexp} argument is a regular
28778 expression used to match the name of the loaded library.
28779
28780
28781 @subsubheading @value{GDBN} Command
28782
28783 The corresponding @value{GDBN} command is @samp{catch load}.
28784
28785 @subsubheading Example
28786
28787 @smallexample
28788 -catch-load -t foo.so
28789 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
28790 what="load of library matching foo.so",times="0"@}
28791 (gdb)
28792 @end smallexample
28793
28794
28795 @subheading The @code{-catch-unload} Command
28796 @findex -catch-unload
28797
28798 @subsubheading Synopsis
28799
28800 @smallexample
28801  -catch-unload [ -t ] [ -d ] @var{regexp}
28802 @end smallexample
28803
28804 Add a catchpoint for library unload events.  If the @samp{-t} option is
28805 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
28806 Breakpoints}).  If the @samp{-d} option is used, the catchpoint is
28807 created in a disabled state.  The @samp{regexp} argument is a regular
28808 expression used to match the name of the unloaded library.
28809
28810 @subsubheading @value{GDBN} Command
28811
28812 The corresponding @value{GDBN} command is @samp{catch unload}.
28813
28814 @subsubheading Example
28815
28816 @smallexample
28817 -catch-unload -d bar.so
28818 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
28819 what="load of library matching bar.so",times="0"@}
28820 (gdb)
28821 @end smallexample
28822
28823
28824 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28825 @node GDB/MI Program Context
28826 @section @sc{gdb/mi}  Program Context
28827
28828 @subheading The @code{-exec-arguments} Command
28829 @findex -exec-arguments
28830
28831
28832 @subsubheading Synopsis
28833
28834 @smallexample
28835  -exec-arguments @var{args}
28836 @end smallexample
28837
28838 Set the inferior program arguments, to be used in the next
28839 @samp{-exec-run}.
28840
28841 @subsubheading @value{GDBN} Command
28842
28843 The corresponding @value{GDBN} command is @samp{set args}.
28844
28845 @subsubheading Example
28846
28847 @smallexample
28848 (gdb)
28849 -exec-arguments -v word
28850 ^done
28851 (gdb)
28852 @end smallexample
28853
28854
28855 @ignore
28856 @subheading The @code{-exec-show-arguments} Command
28857 @findex -exec-show-arguments
28858
28859 @subsubheading Synopsis
28860
28861 @smallexample
28862  -exec-show-arguments
28863 @end smallexample
28864
28865 Print the arguments of the program.
28866
28867 @subsubheading @value{GDBN} Command
28868
28869 The corresponding @value{GDBN} command is @samp{show args}.
28870
28871 @subsubheading Example
28872 N.A.
28873 @end ignore
28874
28875
28876 @subheading The @code{-environment-cd} Command
28877 @findex -environment-cd
28878
28879 @subsubheading Synopsis
28880
28881 @smallexample
28882  -environment-cd @var{pathdir}
28883 @end smallexample
28884
28885 Set @value{GDBN}'s working directory.
28886
28887 @subsubheading @value{GDBN} Command
28888
28889 The corresponding @value{GDBN} command is @samp{cd}.
28890
28891 @subsubheading Example
28892
28893 @smallexample
28894 (gdb)
28895 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
28896 ^done
28897 (gdb)
28898 @end smallexample
28899
28900
28901 @subheading The @code{-environment-directory} Command
28902 @findex -environment-directory
28903
28904 @subsubheading Synopsis
28905
28906 @smallexample
28907  -environment-directory [ -r ] [ @var{pathdir} ]+
28908 @end smallexample
28909
28910 Add directories @var{pathdir} to beginning of search path for source files.
28911 If the @samp{-r} option is used, the search path is reset to the default
28912 search path.  If directories @var{pathdir} are supplied in addition to the
28913 @samp{-r} option, the search path is first reset and then addition
28914 occurs as normal.
28915 Multiple directories may be specified, separated by blanks.  Specifying
28916 multiple directories in a single command
28917 results in the directories added to the beginning of the
28918 search path in the same order they were presented in the command.
28919 If blanks are needed as
28920 part of a directory name, double-quotes should be used around
28921 the name.  In the command output, the path will show up separated
28922 by the system directory-separator character.  The directory-separator
28923 character must not be used
28924 in any directory name.
28925 If no directories are specified, the current search path is displayed.
28926
28927 @subsubheading @value{GDBN} Command
28928
28929 The corresponding @value{GDBN} command is @samp{dir}.
28930
28931 @subsubheading Example
28932
28933 @smallexample
28934 (gdb)
28935 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
28936 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
28937 (gdb)
28938 -environment-directory ""
28939 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
28940 (gdb)
28941 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
28942 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
28943 (gdb)
28944 -environment-directory -r
28945 ^done,source-path="$cdir:$cwd"
28946 (gdb)
28947 @end smallexample
28948
28949
28950 @subheading The @code{-environment-path} Command
28951 @findex -environment-path
28952
28953 @subsubheading Synopsis
28954
28955 @smallexample
28956  -environment-path [ -r ] [ @var{pathdir} ]+
28957 @end smallexample
28958
28959 Add directories @var{pathdir} to beginning of search path for object files.
28960 If the @samp{-r} option is used, the search path is reset to the original
28961 search path that existed at gdb start-up.  If directories @var{pathdir} are
28962 supplied in addition to the
28963 @samp{-r} option, the search path is first reset and then addition
28964 occurs as normal.
28965 Multiple directories may be specified, separated by blanks.  Specifying
28966 multiple directories in a single command
28967 results in the directories added to the beginning of the
28968 search path in the same order they were presented in the command.
28969 If blanks are needed as
28970 part of a directory name, double-quotes should be used around
28971 the name.  In the command output, the path will show up separated
28972 by the system directory-separator character.  The directory-separator
28973 character must not be used
28974 in any directory name.
28975 If no directories are specified, the current path is displayed.
28976
28977
28978 @subsubheading @value{GDBN} Command
28979
28980 The corresponding @value{GDBN} command is @samp{path}.
28981
28982 @subsubheading Example
28983
28984 @smallexample
28985 (gdb)
28986 -environment-path
28987 ^done,path="/usr/bin"
28988 (gdb)
28989 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
28990 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
28991 (gdb)
28992 -environment-path -r /usr/local/bin
28993 ^done,path="/usr/local/bin:/usr/bin"
28994 (gdb)
28995 @end smallexample
28996
28997
28998 @subheading The @code{-environment-pwd} Command
28999 @findex -environment-pwd
29000
29001 @subsubheading Synopsis
29002
29003 @smallexample
29004  -environment-pwd
29005 @end smallexample
29006
29007 Show the current working directory.
29008
29009 @subsubheading @value{GDBN} Command
29010
29011 The corresponding @value{GDBN} command is @samp{pwd}.
29012
29013 @subsubheading Example
29014
29015 @smallexample
29016 (gdb)
29017 -environment-pwd
29018 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
29019 (gdb)
29020 @end smallexample
29021
29022 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29023 @node GDB/MI Thread Commands
29024 @section @sc{gdb/mi} Thread Commands
29025
29026
29027 @subheading The @code{-thread-info} Command
29028 @findex -thread-info
29029
29030 @subsubheading Synopsis
29031
29032 @smallexample
29033  -thread-info [ @var{thread-id} ]
29034 @end smallexample
29035
29036 Reports information about either a specific thread, if 
29037 the @var{thread-id} parameter is present, or about all
29038 threads.  When printing information about all threads,
29039 also reports the current thread.
29040
29041 @subsubheading @value{GDBN} Command
29042
29043 The @samp{info thread} command prints the same information
29044 about all threads.
29045
29046 @subsubheading Result
29047
29048 The result is a list of threads.  The following attributes are
29049 defined for a given thread:
29050
29051 @table @samp
29052 @item current
29053 This field exists only for the current thread.  It has the value @samp{*}.
29054
29055 @item id
29056 The identifier that @value{GDBN} uses to refer to the thread.
29057
29058 @item target-id
29059 The identifier that the target uses to refer to the thread.
29060
29061 @item details
29062 Extra information about the thread, in a target-specific format.  This
29063 field is optional.
29064
29065 @item name
29066 The name of the thread.  If the user specified a name using the
29067 @code{thread name} command, then this name is given.  Otherwise, if
29068 @value{GDBN} can extract the thread name from the target, then that
29069 name is given.  If @value{GDBN} cannot find the thread name, then this
29070 field is omitted.
29071
29072 @item frame
29073 The stack frame currently executing in the thread.
29074
29075 @item state
29076 The thread's state.  The @samp{state} field may have the following
29077 values:
29078
29079 @table @code
29080 @item stopped
29081 The thread is stopped.  Frame information is available for stopped
29082 threads.
29083
29084 @item running
29085 The thread is running.  There's no frame information for running
29086 threads.
29087
29088 @end table
29089
29090 @item core
29091 If @value{GDBN} can find the CPU core on which this thread is running,
29092 then this field is the core identifier.  This field is optional.
29093
29094 @end table
29095
29096 @subsubheading Example
29097
29098 @smallexample
29099 -thread-info
29100 ^done,threads=[
29101 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
29102    frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
29103            args=[]@},state="running"@},
29104 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
29105    frame=@{level="0",addr="0x0804891f",func="foo",
29106            args=[@{name="i",value="10"@}],
29107            file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
29108            state="running"@}],
29109 current-thread-id="1"
29110 (gdb)
29111 @end smallexample
29112
29113 @subheading The @code{-thread-list-ids} Command
29114 @findex -thread-list-ids
29115
29116 @subsubheading Synopsis
29117
29118 @smallexample
29119  -thread-list-ids
29120 @end smallexample
29121
29122 Produces a list of the currently known @value{GDBN} thread ids.  At the
29123 end of the list it also prints the total number of such threads.
29124
29125 This command is retained for historical reasons, the
29126 @code{-thread-info} command should be used instead.
29127
29128 @subsubheading @value{GDBN} Command
29129
29130 Part of @samp{info threads} supplies the same information.
29131
29132 @subsubheading Example
29133
29134 @smallexample
29135 (gdb)
29136 -thread-list-ids
29137 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
29138 current-thread-id="1",number-of-threads="3"
29139 (gdb)
29140 @end smallexample
29141
29142
29143 @subheading The @code{-thread-select} Command
29144 @findex -thread-select
29145
29146 @subsubheading Synopsis
29147
29148 @smallexample
29149  -thread-select @var{threadnum}
29150 @end smallexample
29151
29152 Make @var{threadnum} the current thread.  It prints the number of the new
29153 current thread, and the topmost frame for that thread.
29154
29155 This command is deprecated in favor of explicitly using the
29156 @samp{--thread} option to each command.
29157
29158 @subsubheading @value{GDBN} Command
29159
29160 The corresponding @value{GDBN} command is @samp{thread}.
29161
29162 @subsubheading Example
29163
29164 @smallexample
29165 (gdb)
29166 -exec-next
29167 ^running
29168 (gdb)
29169 *stopped,reason="end-stepping-range",thread-id="2",line="187",
29170 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
29171 (gdb)
29172 -thread-list-ids
29173 ^done,
29174 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
29175 number-of-threads="3"
29176 (gdb)
29177 -thread-select 3
29178 ^done,new-thread-id="3",
29179 frame=@{level="0",func="vprintf",
29180 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
29181 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
29182 (gdb)
29183 @end smallexample
29184
29185 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29186 @node GDB/MI Ada Tasking Commands
29187 @section @sc{gdb/mi} Ada Tasking Commands
29188
29189 @subheading The @code{-ada-task-info} Command
29190 @findex -ada-task-info
29191
29192 @subsubheading Synopsis
29193
29194 @smallexample
29195  -ada-task-info [ @var{task-id} ]
29196 @end smallexample
29197
29198 Reports information about either a specific Ada task, if the
29199 @var{task-id} parameter is present, or about all Ada tasks.
29200
29201 @subsubheading @value{GDBN} Command
29202
29203 The @samp{info tasks} command prints the same information
29204 about all Ada tasks (@pxref{Ada Tasks}).
29205
29206 @subsubheading Result
29207
29208 The result is a table of Ada tasks.  The following columns are
29209 defined for each Ada task:
29210
29211 @table @samp
29212 @item current
29213 This field exists only for the current thread.  It has the value @samp{*}.
29214
29215 @item id
29216 The identifier that @value{GDBN} uses to refer to the Ada task.
29217
29218 @item task-id
29219 The identifier that the target uses to refer to the Ada task.
29220
29221 @item thread-id
29222 The identifier of the thread corresponding to the Ada task.
29223
29224 This field should always exist, as Ada tasks are always implemented
29225 on top of a thread.  But if @value{GDBN} cannot find this corresponding
29226 thread for any reason, the field is omitted.
29227
29228 @item parent-id
29229 This field exists only when the task was created by another task.
29230 In this case, it provides the ID of the parent task.
29231
29232 @item priority
29233 The base priority of the task.
29234
29235 @item state
29236 The current state of the task.  For a detailed description of the
29237 possible states, see @ref{Ada Tasks}.
29238
29239 @item name
29240 The name of the task.
29241
29242 @end table
29243
29244 @subsubheading Example
29245
29246 @smallexample
29247 -ada-task-info
29248 ^done,tasks=@{nr_rows="3",nr_cols="8",
29249 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
29250 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
29251 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
29252 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
29253 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
29254 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
29255 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
29256 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
29257 body=[@{current="*",id="1",task-id="   644010",thread-id="1",priority="48",
29258 state="Child Termination Wait",name="main_task"@}]@}
29259 (gdb)
29260 @end smallexample
29261
29262 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29263 @node GDB/MI Program Execution
29264 @section @sc{gdb/mi} Program Execution
29265
29266 These are the asynchronous commands which generate the out-of-band
29267 record @samp{*stopped}.  Currently @value{GDBN} only really executes
29268 asynchronously with remote targets and this interaction is mimicked in
29269 other cases.
29270
29271 @subheading The @code{-exec-continue} Command
29272 @findex -exec-continue
29273
29274 @subsubheading Synopsis
29275
29276 @smallexample
29277  -exec-continue [--reverse] [--all|--thread-group N]
29278 @end smallexample
29279
29280 Resumes the execution of the inferior program, which will continue
29281 to execute until it reaches a debugger stop event.  If the 
29282 @samp{--reverse} option is specified, execution resumes in reverse until 
29283 it reaches a stop event.  Stop events may include
29284 @itemize @bullet
29285 @item
29286 breakpoints or watchpoints
29287 @item
29288 signals or exceptions
29289 @item
29290 the end of the process (or its beginning under @samp{--reverse})
29291 @item
29292 the end or beginning of a replay log if one is being used.
29293 @end itemize
29294 In all-stop mode (@pxref{All-Stop
29295 Mode}), may resume only one thread, or all threads, depending on the
29296 value of the @samp{scheduler-locking} variable.  If @samp{--all} is
29297 specified, all threads (in all inferiors) will be resumed.  The @samp{--all} option is
29298 ignored in all-stop mode.  If the @samp{--thread-group} options is
29299 specified, then all threads in that thread group are resumed.
29300
29301 @subsubheading @value{GDBN} Command
29302
29303 The corresponding @value{GDBN} corresponding is @samp{continue}.
29304
29305 @subsubheading Example
29306
29307 @smallexample
29308 -exec-continue
29309 ^running
29310 (gdb)
29311 @@Hello world
29312 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
29313 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
29314 line="13"@}
29315 (gdb)
29316 @end smallexample
29317
29318
29319 @subheading The @code{-exec-finish} Command
29320 @findex -exec-finish
29321
29322 @subsubheading Synopsis
29323
29324 @smallexample
29325  -exec-finish [--reverse]
29326 @end smallexample
29327
29328 Resumes the execution of the inferior program until the current
29329 function is exited.  Displays the results returned by the function.
29330 If the @samp{--reverse} option is specified, resumes the reverse
29331 execution of the inferior program until the point where current
29332 function was called.
29333
29334 @subsubheading @value{GDBN} Command
29335
29336 The corresponding @value{GDBN} command is @samp{finish}.
29337
29338 @subsubheading Example
29339
29340 Function returning @code{void}.
29341
29342 @smallexample
29343 -exec-finish
29344 ^running
29345 (gdb)
29346 @@hello from foo
29347 *stopped,reason="function-finished",frame=@{func="main",args=[],
29348 file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
29349 (gdb)
29350 @end smallexample
29351
29352 Function returning other than @code{void}.  The name of the internal
29353 @value{GDBN} variable storing the result is printed, together with the
29354 value itself.
29355
29356 @smallexample
29357 -exec-finish
29358 ^running
29359 (gdb)
29360 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
29361 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
29362 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29363 gdb-result-var="$1",return-value="0"
29364 (gdb)
29365 @end smallexample
29366
29367
29368 @subheading The @code{-exec-interrupt} Command
29369 @findex -exec-interrupt
29370
29371 @subsubheading Synopsis
29372
29373 @smallexample
29374  -exec-interrupt [--all|--thread-group N]
29375 @end smallexample
29376
29377 Interrupts the background execution of the target.  Note how the token
29378 associated with the stop message is the one for the execution command
29379 that has been interrupted.  The token for the interrupt itself only
29380 appears in the @samp{^done} output.  If the user is trying to
29381 interrupt a non-running program, an error message will be printed.
29382
29383 Note that when asynchronous execution is enabled, this command is
29384 asynchronous just like other execution commands.  That is, first the
29385 @samp{^done} response will be printed, and the target stop will be
29386 reported after that using the @samp{*stopped} notification.
29387
29388 In non-stop mode, only the context thread is interrupted by default.
29389 All threads (in all inferiors) will be interrupted if the
29390 @samp{--all}  option is specified.  If the @samp{--thread-group}
29391 option is specified, all threads in that group will be interrupted.
29392
29393 @subsubheading @value{GDBN} Command
29394
29395 The corresponding @value{GDBN} command is @samp{interrupt}.
29396
29397 @subsubheading Example
29398
29399 @smallexample
29400 (gdb)
29401 111-exec-continue
29402 111^running
29403
29404 (gdb)
29405 222-exec-interrupt
29406 222^done
29407 (gdb)
29408 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
29409 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
29410 fullname="/home/foo/bar/try.c",line="13"@}
29411 (gdb)
29412
29413 (gdb)
29414 -exec-interrupt
29415 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
29416 (gdb)
29417 @end smallexample
29418
29419 @subheading The @code{-exec-jump} Command
29420 @findex -exec-jump
29421
29422 @subsubheading Synopsis
29423
29424 @smallexample
29425  -exec-jump @var{location}
29426 @end smallexample
29427
29428 Resumes execution of the inferior program at the location specified by
29429 parameter.  @xref{Specify Location}, for a description of the
29430 different forms of @var{location}.
29431
29432 @subsubheading @value{GDBN} Command
29433
29434 The corresponding @value{GDBN} command is @samp{jump}.
29435
29436 @subsubheading Example
29437
29438 @smallexample
29439 -exec-jump foo.c:10
29440 *running,thread-id="all"
29441 ^running
29442 @end smallexample
29443
29444
29445 @subheading The @code{-exec-next} Command
29446 @findex -exec-next
29447
29448 @subsubheading Synopsis
29449
29450 @smallexample
29451  -exec-next [--reverse]
29452 @end smallexample
29453
29454 Resumes execution of the inferior program, stopping when the beginning
29455 of the next source line is reached.
29456
29457 If the @samp{--reverse} option is specified, resumes reverse execution
29458 of the inferior program, stopping at the beginning of the previous
29459 source line.  If you issue this command on the first line of a
29460 function, it will take you back to the caller of that function, to the
29461 source line where the function was called.
29462
29463
29464 @subsubheading @value{GDBN} Command
29465
29466 The corresponding @value{GDBN} command is @samp{next}.
29467
29468 @subsubheading Example
29469
29470 @smallexample
29471 -exec-next
29472 ^running
29473 (gdb)
29474 *stopped,reason="end-stepping-range",line="8",file="hello.c"
29475 (gdb)
29476 @end smallexample
29477
29478
29479 @subheading The @code{-exec-next-instruction} Command
29480 @findex -exec-next-instruction
29481
29482 @subsubheading Synopsis
29483
29484 @smallexample
29485  -exec-next-instruction [--reverse]
29486 @end smallexample
29487
29488 Executes one machine instruction.  If the instruction is a function
29489 call, continues until the function returns.  If the program stops at an
29490 instruction in the middle of a source line, the address will be
29491 printed as well.
29492
29493 If the @samp{--reverse} option is specified, resumes reverse execution
29494 of the inferior program, stopping at the previous instruction.  If the
29495 previously executed instruction was a return from another function,
29496 it will continue to execute in reverse until the call to that function
29497 (from the current stack frame) is reached.
29498
29499 @subsubheading @value{GDBN} Command
29500
29501 The corresponding @value{GDBN} command is @samp{nexti}.
29502
29503 @subsubheading Example
29504
29505 @smallexample
29506 (gdb)
29507 -exec-next-instruction
29508 ^running
29509
29510 (gdb)
29511 *stopped,reason="end-stepping-range",
29512 addr="0x000100d4",line="5",file="hello.c"
29513 (gdb)
29514 @end smallexample
29515
29516
29517 @subheading The @code{-exec-return} Command
29518 @findex -exec-return
29519
29520 @subsubheading Synopsis
29521
29522 @smallexample
29523  -exec-return
29524 @end smallexample
29525
29526 Makes current function return immediately.  Doesn't execute the inferior.
29527 Displays the new current frame.
29528
29529 @subsubheading @value{GDBN} Command
29530
29531 The corresponding @value{GDBN} command is @samp{return}.
29532
29533 @subsubheading Example
29534
29535 @smallexample
29536 (gdb)
29537 200-break-insert callee4
29538 200^done,bkpt=@{number="1",addr="0x00010734",
29539 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
29540 (gdb)
29541 000-exec-run
29542 000^running
29543 (gdb)
29544 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
29545 frame=@{func="callee4",args=[],
29546 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29547 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
29548 (gdb)
29549 205-break-delete
29550 205^done
29551 (gdb)
29552 111-exec-return
29553 111^done,frame=@{level="0",func="callee3",
29554 args=[@{name="strarg",
29555 value="0x11940 \"A string argument.\""@}],
29556 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29557 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
29558 (gdb)
29559 @end smallexample
29560
29561
29562 @subheading The @code{-exec-run} Command
29563 @findex -exec-run
29564
29565 @subsubheading Synopsis
29566
29567 @smallexample
29568  -exec-run [--all | --thread-group N]
29569 @end smallexample
29570
29571 Starts execution of the inferior from the beginning.  The inferior
29572 executes until either a breakpoint is encountered or the program
29573 exits.  In the latter case the output will include an exit code, if
29574 the program has exited exceptionally.
29575
29576 When no option is specified, the current inferior is started.  If the
29577 @samp{--thread-group} option is specified, it should refer to a thread
29578 group of type @samp{process}, and that thread group will be started.
29579 If the @samp{--all} option is specified, then all inferiors will be started.
29580
29581 @subsubheading @value{GDBN} Command
29582
29583 The corresponding @value{GDBN} command is @samp{run}.
29584
29585 @subsubheading Examples
29586
29587 @smallexample
29588 (gdb)
29589 -break-insert main
29590 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
29591 (gdb)
29592 -exec-run
29593 ^running
29594 (gdb)
29595 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
29596 frame=@{func="main",args=[],file="recursive2.c",
29597 fullname="/home/foo/bar/recursive2.c",line="4"@}
29598 (gdb)
29599 @end smallexample
29600
29601 @noindent
29602 Program exited normally:
29603
29604 @smallexample
29605 (gdb)
29606 -exec-run
29607 ^running
29608 (gdb)
29609 x = 55
29610 *stopped,reason="exited-normally"
29611 (gdb)
29612 @end smallexample
29613
29614 @noindent
29615 Program exited exceptionally:
29616
29617 @smallexample
29618 (gdb)
29619 -exec-run
29620 ^running
29621 (gdb)
29622 x = 55
29623 *stopped,reason="exited",exit-code="01"
29624 (gdb)
29625 @end smallexample
29626
29627 Another way the program can terminate is if it receives a signal such as
29628 @code{SIGINT}.  In this case, @sc{gdb/mi} displays this:
29629
29630 @smallexample
29631 (gdb)
29632 *stopped,reason="exited-signalled",signal-name="SIGINT",
29633 signal-meaning="Interrupt"
29634 @end smallexample
29635
29636
29637 @c @subheading -exec-signal
29638
29639
29640 @subheading The @code{-exec-step} Command
29641 @findex -exec-step
29642
29643 @subsubheading Synopsis
29644
29645 @smallexample
29646  -exec-step [--reverse]
29647 @end smallexample
29648
29649 Resumes execution of the inferior program, stopping when the beginning
29650 of the next source line is reached, if the next source line is not a
29651 function call.  If it is, stop at the first instruction of the called
29652 function.  If the @samp{--reverse} option is specified, resumes reverse
29653 execution of the inferior program, stopping at the beginning of the
29654 previously executed source line.
29655
29656 @subsubheading @value{GDBN} Command
29657
29658 The corresponding @value{GDBN} command is @samp{step}.
29659
29660 @subsubheading Example
29661
29662 Stepping into a function:
29663
29664 @smallexample
29665 -exec-step
29666 ^running
29667 (gdb)
29668 *stopped,reason="end-stepping-range",
29669 frame=@{func="foo",args=[@{name="a",value="10"@},
29670 @{name="b",value="0"@}],file="recursive2.c",
29671 fullname="/home/foo/bar/recursive2.c",line="11"@}
29672 (gdb)
29673 @end smallexample
29674
29675 Regular stepping:
29676
29677 @smallexample
29678 -exec-step
29679 ^running
29680 (gdb)
29681 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
29682 (gdb)
29683 @end smallexample
29684
29685
29686 @subheading The @code{-exec-step-instruction} Command
29687 @findex -exec-step-instruction
29688
29689 @subsubheading Synopsis
29690
29691 @smallexample
29692  -exec-step-instruction [--reverse]
29693 @end smallexample
29694
29695 Resumes the inferior which executes one machine instruction.  If the
29696 @samp{--reverse} option is specified, resumes reverse execution of the
29697 inferior program, stopping at the previously executed instruction.
29698 The output, once @value{GDBN} has stopped, will vary depending on
29699 whether we have stopped in the middle of a source line or not.  In the
29700 former case, the address at which the program stopped will be printed
29701 as well.
29702
29703 @subsubheading @value{GDBN} Command
29704
29705 The corresponding @value{GDBN} command is @samp{stepi}.
29706
29707 @subsubheading Example
29708
29709 @smallexample
29710 (gdb)
29711 -exec-step-instruction
29712 ^running
29713
29714 (gdb)
29715 *stopped,reason="end-stepping-range",
29716 frame=@{func="foo",args=[],file="try.c",
29717 fullname="/home/foo/bar/try.c",line="10"@}
29718 (gdb)
29719 -exec-step-instruction
29720 ^running
29721
29722 (gdb)
29723 *stopped,reason="end-stepping-range",
29724 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
29725 fullname="/home/foo/bar/try.c",line="10"@}
29726 (gdb)
29727 @end smallexample
29728
29729
29730 @subheading The @code{-exec-until} Command
29731 @findex -exec-until
29732
29733 @subsubheading Synopsis
29734
29735 @smallexample
29736  -exec-until [ @var{location} ]
29737 @end smallexample
29738
29739 Executes the inferior until the @var{location} specified in the
29740 argument is reached.  If there is no argument, the inferior executes
29741 until a source line greater than the current one is reached.  The
29742 reason for stopping in this case will be @samp{location-reached}.
29743
29744 @subsubheading @value{GDBN} Command
29745
29746 The corresponding @value{GDBN} command is @samp{until}.
29747
29748 @subsubheading Example
29749
29750 @smallexample
29751 (gdb)
29752 -exec-until recursive2.c:6
29753 ^running
29754 (gdb)
29755 x = 55
29756 *stopped,reason="location-reached",frame=@{func="main",args=[],
29757 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
29758 (gdb)
29759 @end smallexample
29760
29761 @ignore
29762 @subheading -file-clear
29763 Is this going away????
29764 @end ignore
29765
29766 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29767 @node GDB/MI Stack Manipulation
29768 @section @sc{gdb/mi} Stack Manipulation Commands
29769
29770
29771 @subheading The @code{-stack-info-frame} Command
29772 @findex -stack-info-frame
29773
29774 @subsubheading Synopsis
29775
29776 @smallexample
29777  -stack-info-frame
29778 @end smallexample
29779
29780 Get info on the selected frame.
29781
29782 @subsubheading @value{GDBN} Command
29783
29784 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
29785 (without arguments).
29786
29787 @subsubheading Example
29788
29789 @smallexample
29790 (gdb)
29791 -stack-info-frame
29792 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
29793 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29794 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
29795 (gdb)
29796 @end smallexample
29797
29798 @subheading The @code{-stack-info-depth} Command
29799 @findex -stack-info-depth
29800
29801 @subsubheading Synopsis
29802
29803 @smallexample
29804  -stack-info-depth [ @var{max-depth} ]
29805 @end smallexample
29806
29807 Return the depth of the stack.  If the integer argument @var{max-depth}
29808 is specified, do not count beyond @var{max-depth} frames.
29809
29810 @subsubheading @value{GDBN} Command
29811
29812 There's no equivalent @value{GDBN} command.
29813
29814 @subsubheading Example
29815
29816 For a stack with frame levels 0 through 11:
29817
29818 @smallexample
29819 (gdb)
29820 -stack-info-depth
29821 ^done,depth="12"
29822 (gdb)
29823 -stack-info-depth 4
29824 ^done,depth="4"
29825 (gdb)
29826 -stack-info-depth 12
29827 ^done,depth="12"
29828 (gdb)
29829 -stack-info-depth 11
29830 ^done,depth="11"
29831 (gdb)
29832 -stack-info-depth 13
29833 ^done,depth="12"
29834 (gdb)
29835 @end smallexample
29836
29837 @subheading The @code{-stack-list-arguments} Command
29838 @findex -stack-list-arguments
29839
29840 @subsubheading Synopsis
29841
29842 @smallexample
29843  -stack-list-arguments @var{print-values}
29844     [ @var{low-frame} @var{high-frame} ]
29845 @end smallexample
29846
29847 Display a list of the arguments for the frames between @var{low-frame}
29848 and @var{high-frame} (inclusive).  If @var{low-frame} and
29849 @var{high-frame} are not provided, list the arguments for the whole
29850 call stack.  If the two arguments are equal, show the single frame
29851 at the corresponding level.  It is an error if @var{low-frame} is
29852 larger than the actual number of frames.  On the other hand,
29853 @var{high-frame} may be larger than the actual number of frames, in
29854 which case only existing frames will be returned.
29855
29856 If @var{print-values} is 0 or @code{--no-values}, print only the names of
29857 the variables; if it is 1 or @code{--all-values}, print also their
29858 values; and if it is 2 or @code{--simple-values}, print the name,
29859 type and value for simple data types, and the name and type for arrays,
29860 structures and unions.
29861
29862 Use of this command to obtain arguments in a single frame is
29863 deprecated in favor of the @samp{-stack-list-variables} command.
29864
29865 @subsubheading @value{GDBN} Command
29866
29867 @value{GDBN} does not have an equivalent command.  @code{gdbtk} has a
29868 @samp{gdb_get_args} command which partially overlaps with the
29869 functionality of @samp{-stack-list-arguments}.
29870
29871 @subsubheading Example
29872
29873 @smallexample
29874 (gdb)
29875 -stack-list-frames
29876 ^done,
29877 stack=[
29878 frame=@{level="0",addr="0x00010734",func="callee4",
29879 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29880 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
29881 frame=@{level="1",addr="0x0001076c",func="callee3",
29882 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29883 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
29884 frame=@{level="2",addr="0x0001078c",func="callee2",
29885 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29886 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
29887 frame=@{level="3",addr="0x000107b4",func="callee1",
29888 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29889 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
29890 frame=@{level="4",addr="0x000107e0",func="main",
29891 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29892 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
29893 (gdb)
29894 -stack-list-arguments 0
29895 ^done,
29896 stack-args=[
29897 frame=@{level="0",args=[]@},
29898 frame=@{level="1",args=[name="strarg"]@},
29899 frame=@{level="2",args=[name="intarg",name="strarg"]@},
29900 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
29901 frame=@{level="4",args=[]@}]
29902 (gdb)
29903 -stack-list-arguments 1
29904 ^done,
29905 stack-args=[
29906 frame=@{level="0",args=[]@},
29907 frame=@{level="1",
29908  args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
29909 frame=@{level="2",args=[
29910 @{name="intarg",value="2"@},
29911 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
29912 @{frame=@{level="3",args=[
29913 @{name="intarg",value="2"@},
29914 @{name="strarg",value="0x11940 \"A string argument.\""@},
29915 @{name="fltarg",value="3.5"@}]@},
29916 frame=@{level="4",args=[]@}]
29917 (gdb)
29918 -stack-list-arguments 0 2 2
29919 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
29920 (gdb)
29921 -stack-list-arguments 1 2 2
29922 ^done,stack-args=[frame=@{level="2",
29923 args=[@{name="intarg",value="2"@},
29924 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
29925 (gdb)
29926 @end smallexample
29927
29928 @c @subheading -stack-list-exception-handlers
29929
29930
29931 @subheading The @code{-stack-list-frames} Command
29932 @findex -stack-list-frames
29933
29934 @subsubheading Synopsis
29935
29936 @smallexample
29937  -stack-list-frames [ @var{low-frame} @var{high-frame} ]
29938 @end smallexample
29939
29940 List the frames currently on the stack.  For each frame it displays the
29941 following info:
29942
29943 @table @samp
29944 @item @var{level}
29945 The frame number, 0 being the topmost frame, i.e., the innermost function.
29946 @item @var{addr}
29947 The @code{$pc} value for that frame.
29948 @item @var{func}
29949 Function name.
29950 @item @var{file}
29951 File name of the source file where the function lives.
29952 @item @var{fullname}
29953 The full file name of the source file where the function lives.
29954 @item @var{line}
29955 Line number corresponding to the @code{$pc}.
29956 @item @var{from}
29957 The shared library where this function is defined.  This is only given
29958 if the frame's function is not known.
29959 @end table
29960
29961 If invoked without arguments, this command prints a backtrace for the
29962 whole stack.  If given two integer arguments, it shows the frames whose
29963 levels are between the two arguments (inclusive).  If the two arguments
29964 are equal, it shows the single frame at the corresponding level.  It is
29965 an error if @var{low-frame} is larger than the actual number of
29966 frames.  On the other hand, @var{high-frame} may be larger than the
29967 actual number of frames, in which case only existing frames will be returned.
29968
29969 @subsubheading @value{GDBN} Command
29970
29971 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
29972
29973 @subsubheading Example
29974
29975 Full stack backtrace:
29976
29977 @smallexample
29978 (gdb)
29979 -stack-list-frames
29980 ^done,stack=
29981 [frame=@{level="0",addr="0x0001076c",func="foo",
29982   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
29983 frame=@{level="1",addr="0x000107a4",func="foo",
29984   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29985 frame=@{level="2",addr="0x000107a4",func="foo",
29986   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29987 frame=@{level="3",addr="0x000107a4",func="foo",
29988   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29989 frame=@{level="4",addr="0x000107a4",func="foo",
29990   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29991 frame=@{level="5",addr="0x000107a4",func="foo",
29992   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29993 frame=@{level="6",addr="0x000107a4",func="foo",
29994   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29995 frame=@{level="7",addr="0x000107a4",func="foo",
29996   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29997 frame=@{level="8",addr="0x000107a4",func="foo",
29998   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
29999 frame=@{level="9",addr="0x000107a4",func="foo",
30000   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30001 frame=@{level="10",addr="0x000107a4",func="foo",
30002   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30003 frame=@{level="11",addr="0x00010738",func="main",
30004   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
30005 (gdb)
30006 @end smallexample
30007
30008 Show frames between @var{low_frame} and @var{high_frame}:
30009
30010 @smallexample
30011 (gdb)
30012 -stack-list-frames 3 5
30013 ^done,stack=
30014 [frame=@{level="3",addr="0x000107a4",func="foo",
30015   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30016 frame=@{level="4",addr="0x000107a4",func="foo",
30017   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30018 frame=@{level="5",addr="0x000107a4",func="foo",
30019   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
30020 (gdb)
30021 @end smallexample
30022
30023 Show a single frame:
30024
30025 @smallexample
30026 (gdb)
30027 -stack-list-frames 3 3
30028 ^done,stack=
30029 [frame=@{level="3",addr="0x000107a4",func="foo",
30030   file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
30031 (gdb)
30032 @end smallexample
30033
30034
30035 @subheading The @code{-stack-list-locals} Command
30036 @findex -stack-list-locals
30037
30038 @subsubheading Synopsis
30039
30040 @smallexample
30041  -stack-list-locals @var{print-values}
30042 @end smallexample
30043
30044 Display the local variable names for the selected frame.  If
30045 @var{print-values} is 0 or @code{--no-values}, print only the names of
30046 the variables; if it is 1 or @code{--all-values}, print also their
30047 values; and if it is 2 or @code{--simple-values}, print the name,
30048 type and value for simple data types, and the name and type for arrays,
30049 structures and unions.  In this last case, a frontend can immediately
30050 display the value of simple data types and create variable objects for
30051 other data types when the user wishes to explore their values in
30052 more detail.
30053
30054 This command is deprecated in favor of the
30055 @samp{-stack-list-variables} command.
30056
30057 @subsubheading @value{GDBN} Command
30058
30059 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
30060
30061 @subsubheading Example
30062
30063 @smallexample
30064 (gdb)
30065 -stack-list-locals 0
30066 ^done,locals=[name="A",name="B",name="C"]
30067 (gdb)
30068 -stack-list-locals --all-values
30069 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
30070   @{name="C",value="@{1, 2, 3@}"@}]
30071 -stack-list-locals --simple-values
30072 ^done,locals=[@{name="A",type="int",value="1"@},
30073   @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
30074 (gdb)
30075 @end smallexample
30076
30077 @subheading The @code{-stack-list-variables} Command
30078 @findex -stack-list-variables
30079
30080 @subsubheading Synopsis
30081
30082 @smallexample
30083  -stack-list-variables @var{print-values}
30084 @end smallexample
30085
30086 Display the names of local variables and function arguments for the selected frame.  If
30087 @var{print-values} is 0 or @code{--no-values}, print only the names of
30088 the variables; if it is 1 or @code{--all-values}, print also their
30089 values; and if it is 2 or @code{--simple-values}, print the name,
30090 type and value for simple data types, and the name and type for arrays,
30091 structures and unions.  
30092
30093 @subsubheading Example
30094
30095 @smallexample
30096 (gdb)
30097 -stack-list-variables --thread 1 --frame 0 --all-values
30098 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
30099 (gdb)
30100 @end smallexample
30101
30102
30103 @subheading The @code{-stack-select-frame} Command
30104 @findex -stack-select-frame
30105
30106 @subsubheading Synopsis
30107
30108 @smallexample
30109  -stack-select-frame @var{framenum}
30110 @end smallexample
30111
30112 Change the selected frame.  Select a different frame @var{framenum} on
30113 the stack.
30114
30115 This command in deprecated in favor of passing the @samp{--frame}
30116 option to every command.
30117
30118 @subsubheading @value{GDBN} Command
30119
30120 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
30121 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
30122
30123 @subsubheading Example
30124
30125 @smallexample
30126 (gdb)
30127 -stack-select-frame 2
30128 ^done
30129 (gdb)
30130 @end smallexample
30131
30132 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30133 @node GDB/MI Variable Objects
30134 @section @sc{gdb/mi} Variable Objects
30135
30136 @ignore
30137
30138 @subheading Motivation for Variable Objects in @sc{gdb/mi}
30139
30140 For the implementation of a variable debugger window (locals, watched
30141 expressions, etc.), we are proposing the adaptation of the existing code
30142 used by @code{Insight}.
30143
30144 The two main reasons for that are:
30145
30146 @enumerate 1
30147 @item
30148 It has been proven in practice (it is already on its second generation).
30149
30150 @item
30151 It will shorten development time (needless to say how important it is
30152 now).
30153 @end enumerate
30154
30155 The original interface was designed to be used by Tcl code, so it was
30156 slightly changed so it could be used through @sc{gdb/mi}.  This section
30157 describes the @sc{gdb/mi} operations that will be available and gives some
30158 hints about their use.
30159
30160 @emph{Note}: In addition to the set of operations described here, we
30161 expect the @sc{gui} implementation of a variable window to require, at
30162 least, the following operations:
30163
30164 @itemize @bullet
30165 @item @code{-gdb-show} @code{output-radix}
30166 @item @code{-stack-list-arguments}
30167 @item @code{-stack-list-locals}
30168 @item @code{-stack-select-frame}
30169 @end itemize
30170
30171 @end ignore
30172
30173 @subheading Introduction to Variable Objects
30174
30175 @cindex variable objects in @sc{gdb/mi}
30176
30177 Variable objects are "object-oriented" MI interface for examining and
30178 changing values of expressions.  Unlike some other MI interfaces that
30179 work with expressions, variable objects are specifically designed for
30180 simple and efficient presentation in the frontend.  A variable object
30181 is identified by string name.  When a variable object is created, the
30182 frontend specifies the expression for that variable object.  The
30183 expression can be a simple variable, or it can be an arbitrary complex
30184 expression, and can even involve CPU registers.  After creating a
30185 variable object, the frontend can invoke other variable object
30186 operations---for example to obtain or change the value of a variable
30187 object, or to change display format.
30188
30189 Variable objects have hierarchical tree structure.  Any variable object
30190 that corresponds to a composite type, such as structure in C, has
30191 a number of child variable objects, for example corresponding to each
30192 element of a structure.  A child variable object can itself have 
30193 children, recursively.  Recursion ends when we reach 
30194 leaf variable objects, which always have built-in types.  Child variable
30195 objects are created only by explicit request, so if a frontend 
30196 is not interested in the children of a particular variable object, no
30197 child will be created.
30198
30199 For a leaf variable object it is possible to obtain its value as a
30200 string, or set the value from a string.  String value can be also
30201 obtained for a non-leaf variable object, but it's generally a string
30202 that only indicates the type of the object, and does not list its
30203 contents.  Assignment to a non-leaf variable object is not allowed.
30204  
30205 A frontend does not need to read the values of all variable objects each time
30206 the program stops.  Instead, MI provides an update command that lists all
30207 variable objects whose values has changed since the last update
30208 operation.  This considerably reduces the amount of data that must
30209 be transferred to the frontend.  As noted above, children variable
30210 objects are created on demand, and only leaf variable objects have a
30211 real value.  As result, gdb will read target memory only for leaf
30212 variables that frontend has created.
30213
30214 The automatic update is not always desirable.  For example, a frontend
30215 might want to keep a value of some expression for future reference,
30216 and never update it.  For another example,  fetching memory is
30217 relatively slow for embedded targets, so a frontend might want
30218 to disable automatic update for the variables that are either not
30219 visible on the screen, or ``closed''.  This is possible using so
30220 called ``frozen variable objects''.  Such variable objects are never
30221 implicitly updated.  
30222
30223 Variable objects can be either @dfn{fixed} or @dfn{floating}.  For the
30224 fixed variable object, the expression is parsed when the variable
30225 object is created, including associating identifiers to specific
30226 variables.  The meaning of expression never changes.  For a floating
30227 variable object the values of variables whose names appear in the
30228 expressions are re-evaluated every time in the context of the current
30229 frame.  Consider this example:
30230
30231 @smallexample
30232 void do_work(...)
30233 @{
30234         struct work_state state;
30235
30236         if (...)
30237            do_work(...);
30238 @}
30239 @end smallexample
30240
30241 If a fixed variable object for the @code{state} variable is created in
30242 this function, and we enter the recursive call, the variable
30243 object will report the value of @code{state} in the top-level
30244 @code{do_work} invocation.  On the other hand, a floating variable
30245 object will report the value of @code{state} in the current frame.
30246
30247 If an expression specified when creating a fixed variable object
30248 refers to a local variable, the variable object becomes bound to the
30249 thread and frame in which the variable object is created.  When such
30250 variable object is updated, @value{GDBN} makes sure that the
30251 thread/frame combination the variable object is bound to still exists,
30252 and re-evaluates the variable object in context of that thread/frame.
30253
30254 The following is the complete set of @sc{gdb/mi} operations defined to
30255 access this functionality:
30256
30257 @multitable @columnfractions .4 .6
30258 @item @strong{Operation}
30259 @tab @strong{Description}
30260
30261 @item @code{-enable-pretty-printing}
30262 @tab enable Python-based pretty-printing
30263 @item @code{-var-create}
30264 @tab create a variable object
30265 @item @code{-var-delete}
30266 @tab delete the variable object and/or its children
30267 @item @code{-var-set-format}
30268 @tab set the display format of this variable
30269 @item @code{-var-show-format}
30270 @tab show the display format of this variable
30271 @item @code{-var-info-num-children}
30272 @tab tells how many children this object has
30273 @item @code{-var-list-children}
30274 @tab return a list of the object's children
30275 @item @code{-var-info-type}
30276 @tab show the type of this variable object
30277 @item @code{-var-info-expression}
30278 @tab print parent-relative expression that this variable object represents
30279 @item @code{-var-info-path-expression}
30280 @tab print full expression that this variable object represents
30281 @item @code{-var-show-attributes}
30282 @tab is this variable editable? does it exist here?
30283 @item @code{-var-evaluate-expression}
30284 @tab get the value of this variable
30285 @item @code{-var-assign}
30286 @tab set the value of this variable
30287 @item @code{-var-update}
30288 @tab update the variable and its children
30289 @item @code{-var-set-frozen}
30290 @tab set frozeness attribute
30291 @item @code{-var-set-update-range}
30292 @tab set range of children to display on update
30293 @end multitable
30294
30295 In the next subsection we describe each operation in detail and suggest
30296 how it can be used.
30297
30298 @subheading Description And Use of Operations on Variable Objects
30299
30300 @subheading The @code{-enable-pretty-printing} Command
30301 @findex -enable-pretty-printing
30302
30303 @smallexample
30304 -enable-pretty-printing
30305 @end smallexample
30306
30307 @value{GDBN} allows Python-based visualizers to affect the output of the
30308 MI variable object commands.  However, because there was no way to
30309 implement this in a fully backward-compatible way, a front end must
30310 request that this functionality be enabled.
30311
30312 Once enabled, this feature cannot be disabled.
30313
30314 Note that if Python support has not been compiled into @value{GDBN},
30315 this command will still succeed (and do nothing).
30316
30317 This feature is currently (as of @value{GDBN} 7.0) experimental, and
30318 may work differently in future versions of @value{GDBN}.
30319
30320 @subheading The @code{-var-create} Command
30321 @findex -var-create
30322
30323 @subsubheading Synopsis
30324
30325 @smallexample
30326  -var-create @{@var{name} | "-"@}
30327     @{@var{frame-addr} | "*" | "@@"@} @var{expression}
30328 @end smallexample
30329
30330 This operation creates a variable object, which allows the monitoring of
30331 a variable, the result of an expression, a memory cell or a CPU
30332 register.
30333
30334 The @var{name} parameter is the string by which the object can be
30335 referenced.  It must be unique.  If @samp{-} is specified, the varobj
30336 system will generate a string ``varNNNNNN'' automatically.  It will be
30337 unique provided that one does not specify @var{name} of that format.
30338 The command fails if a duplicate name is found.
30339
30340 The frame under which the expression should be evaluated can be
30341 specified by @var{frame-addr}.  A @samp{*} indicates that the current
30342 frame should be used.  A @samp{@@} indicates that a floating variable
30343 object must be created.
30344
30345 @var{expression} is any expression valid on the current language set (must not
30346 begin with a @samp{*}), or one of the following:
30347
30348 @itemize @bullet
30349 @item
30350 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
30351
30352 @item
30353 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
30354
30355 @item
30356 @samp{$@var{regname}} --- a CPU register name
30357 @end itemize
30358
30359 @cindex dynamic varobj
30360 A varobj's contents may be provided by a Python-based pretty-printer.  In this
30361 case the varobj is known as a @dfn{dynamic varobj}.  Dynamic varobjs
30362 have slightly different semantics in some cases.  If the
30363 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
30364 will never create a dynamic varobj.  This ensures backward
30365 compatibility for existing clients.
30366
30367 @subsubheading Result
30368
30369 This operation returns attributes of the newly-created varobj.  These
30370 are:
30371
30372 @table @samp
30373 @item name
30374 The name of the varobj.
30375
30376 @item numchild
30377 The number of children of the varobj.  This number is not necessarily
30378 reliable for a dynamic varobj.  Instead, you must examine the
30379 @samp{has_more} attribute.
30380
30381 @item value
30382 The varobj's scalar value.  For a varobj whose type is some sort of
30383 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
30384 will not be interesting.
30385
30386 @item type
30387 The varobj's type.  This is a string representation of the type, as
30388 would be printed by the @value{GDBN} CLI.  If @samp{print object}
30389 (@pxref{Print Settings, set print object}) is set to @code{on}, the
30390 @emph{actual} (derived) type of the object is shown rather than the
30391 @emph{declared} one.
30392
30393 @item thread-id
30394 If a variable object is bound to a specific thread, then this is the
30395 thread's identifier.
30396
30397 @item has_more
30398 For a dynamic varobj, this indicates whether there appear to be any
30399 children available.  For a non-dynamic varobj, this will be 0.
30400
30401 @item dynamic
30402 This attribute will be present and have the value @samp{1} if the
30403 varobj is a dynamic varobj.  If the varobj is not a dynamic varobj,
30404 then this attribute will not be present.
30405
30406 @item displayhint
30407 A dynamic varobj can supply a display hint to the front end.  The
30408 value comes directly from the Python pretty-printer object's
30409 @code{display_hint} method.  @xref{Pretty Printing API}.
30410 @end table
30411
30412 Typical output will look like this:
30413
30414 @smallexample
30415  name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
30416   has_more="@var{has_more}"
30417 @end smallexample
30418
30419
30420 @subheading The @code{-var-delete} Command
30421 @findex -var-delete
30422
30423 @subsubheading Synopsis
30424
30425 @smallexample
30426  -var-delete [ -c ] @var{name}
30427 @end smallexample
30428
30429 Deletes a previously created variable object and all of its children.
30430 With the @samp{-c} option, just deletes the children.
30431
30432 Returns an error if the object @var{name} is not found.
30433
30434
30435 @subheading The @code{-var-set-format} Command
30436 @findex -var-set-format
30437
30438 @subsubheading Synopsis
30439
30440 @smallexample
30441  -var-set-format @var{name} @var{format-spec}
30442 @end smallexample
30443
30444 Sets the output format for the value of the object @var{name} to be
30445 @var{format-spec}.
30446
30447 @anchor{-var-set-format}
30448 The syntax for the @var{format-spec} is as follows:
30449
30450 @smallexample
30451  @var{format-spec} @expansion{}
30452  @{binary | decimal | hexadecimal | octal | natural@}
30453 @end smallexample
30454
30455 The natural format is the default format choosen automatically
30456 based on the variable type (like decimal for an @code{int}, hex
30457 for pointers, etc.).
30458
30459 For a variable with children, the format is set only on the 
30460 variable itself, and the children are not affected.  
30461
30462 @subheading The @code{-var-show-format} Command
30463 @findex -var-show-format
30464
30465 @subsubheading Synopsis
30466
30467 @smallexample
30468  -var-show-format @var{name}
30469 @end smallexample
30470
30471 Returns the format used to display the value of the object @var{name}.
30472
30473 @smallexample
30474  @var{format} @expansion{}
30475  @var{format-spec}
30476 @end smallexample
30477
30478
30479 @subheading The @code{-var-info-num-children} Command
30480 @findex -var-info-num-children
30481
30482 @subsubheading Synopsis
30483
30484 @smallexample
30485  -var-info-num-children @var{name}
30486 @end smallexample
30487
30488 Returns the number of children of a variable object @var{name}:
30489
30490 @smallexample
30491  numchild=@var{n}
30492 @end smallexample
30493
30494 Note that this number is not completely reliable for a dynamic varobj.
30495 It will return the current number of children, but more children may
30496 be available.
30497
30498
30499 @subheading The @code{-var-list-children} Command
30500 @findex -var-list-children
30501
30502 @subsubheading Synopsis
30503
30504 @smallexample
30505  -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
30506 @end smallexample
30507 @anchor{-var-list-children}
30508
30509 Return a list of the children of the specified variable object and
30510 create variable objects for them, if they do not already exist.  With
30511 a single argument or if @var{print-values} has a value of 0 or
30512 @code{--no-values}, print only the names of the variables; if
30513 @var{print-values} is 1 or @code{--all-values}, also print their
30514 values; and if it is 2 or @code{--simple-values} print the name and
30515 value for simple data types and just the name for arrays, structures
30516 and unions.
30517
30518 @var{from} and @var{to}, if specified, indicate the range of children
30519 to report.  If @var{from} or @var{to} is less than zero, the range is
30520 reset and all children will be reported.  Otherwise, children starting
30521 at @var{from} (zero-based) and up to and excluding @var{to} will be
30522 reported.
30523
30524 If a child range is requested, it will only affect the current call to
30525 @code{-var-list-children}, but not future calls to @code{-var-update}.
30526 For this, you must instead use @code{-var-set-update-range}.  The
30527 intent of this approach is to enable a front end to implement any
30528 update approach it likes; for example, scrolling a view may cause the
30529 front end to request more children with @code{-var-list-children}, and
30530 then the front end could call @code{-var-set-update-range} with a
30531 different range to ensure that future updates are restricted to just
30532 the visible items.
30533
30534 For each child the following results are returned:
30535
30536 @table @var
30537
30538 @item name
30539 Name of the variable object created for this child.
30540
30541 @item exp
30542 The expression to be shown to the user by the front end to designate this child.
30543 For example this may be the name of a structure member.
30544
30545 For a dynamic varobj, this value cannot be used to form an
30546 expression.  There is no way to do this at all with a dynamic varobj.
30547
30548 For C/C@t{++} structures there are several pseudo children returned to
30549 designate access qualifiers.  For these pseudo children @var{exp} is
30550 @samp{public}, @samp{private}, or @samp{protected}.  In this case the
30551 type and value are not present.
30552
30553 A dynamic varobj will not report the access qualifying
30554 pseudo-children, regardless of the language.  This information is not
30555 available at all with a dynamic varobj.
30556
30557 @item numchild
30558 Number of children this child has.  For a dynamic varobj, this will be
30559 0.
30560
30561 @item type
30562 The type of the child.  If @samp{print object}
30563 (@pxref{Print Settings, set print object}) is set to @code{on}, the
30564 @emph{actual} (derived) type of the object is shown rather than the
30565 @emph{declared} one.
30566
30567 @item value
30568 If values were requested, this is the value.
30569
30570 @item thread-id
30571 If this variable object is associated with a thread, this is the thread id.  
30572 Otherwise this result is not present.
30573
30574 @item frozen
30575 If the variable object is frozen, this variable will be present with a value of 1.
30576 @end table
30577
30578 The result may have its own attributes:
30579
30580 @table @samp
30581 @item displayhint
30582 A dynamic varobj can supply a display hint to the front end.  The
30583 value comes directly from the Python pretty-printer object's
30584 @code{display_hint} method.  @xref{Pretty Printing API}.
30585
30586 @item has_more
30587 This is an integer attribute which is nonzero if there are children
30588 remaining after the end of the selected range.
30589 @end table
30590
30591 @subsubheading Example
30592
30593 @smallexample
30594 (gdb)
30595  -var-list-children n
30596  ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
30597  numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
30598 (gdb)
30599  -var-list-children --all-values n
30600  ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
30601  numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
30602 @end smallexample
30603
30604
30605 @subheading The @code{-var-info-type} Command
30606 @findex -var-info-type
30607
30608 @subsubheading Synopsis
30609
30610 @smallexample
30611  -var-info-type @var{name}
30612 @end smallexample
30613
30614 Returns the type of the specified variable @var{name}.  The type is
30615 returned as a string in the same format as it is output by the
30616 @value{GDBN} CLI:
30617
30618 @smallexample
30619  type=@var{typename}
30620 @end smallexample
30621
30622
30623 @subheading The @code{-var-info-expression} Command
30624 @findex -var-info-expression
30625
30626 @subsubheading Synopsis
30627
30628 @smallexample
30629  -var-info-expression @var{name}
30630 @end smallexample
30631
30632 Returns a string that is suitable for presenting this
30633 variable object in user interface.  The string is generally
30634 not valid expression in the current language, and cannot be evaluated.
30635
30636 For example, if @code{a} is an array, and variable object
30637 @code{A} was created for @code{a}, then we'll get this output:
30638
30639 @smallexample
30640 (gdb) -var-info-expression A.1
30641 ^done,lang="C",exp="1"
30642 @end smallexample
30643
30644 @noindent
30645 Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
30646
30647 Note that the output of the @code{-var-list-children} command also
30648 includes those expressions, so the @code{-var-info-expression} command
30649 is of limited use.
30650
30651 @subheading The @code{-var-info-path-expression} Command
30652 @findex -var-info-path-expression
30653
30654 @subsubheading Synopsis
30655
30656 @smallexample
30657  -var-info-path-expression @var{name}
30658 @end smallexample
30659
30660 Returns an expression that can be evaluated in the current
30661 context and will yield the same value that a variable object has.
30662 Compare this with the @code{-var-info-expression} command, which
30663 result can be used only for UI presentation.  Typical use of
30664 the @code{-var-info-path-expression} command is creating a 
30665 watchpoint from a variable object.
30666
30667 This command is currently not valid for children of a dynamic varobj,
30668 and will give an error when invoked on one.
30669
30670 For example, suppose @code{C} is a C@t{++} class, derived from class
30671 @code{Base}, and that the @code{Base} class has a member called
30672 @code{m_size}.  Assume a variable @code{c} is has the type of
30673 @code{C} and a variable object @code{C} was created for variable
30674 @code{c}.  Then, we'll get this output:
30675 @smallexample
30676 (gdb) -var-info-path-expression C.Base.public.m_size
30677 ^done,path_expr=((Base)c).m_size)
30678 @end smallexample
30679
30680 @subheading The @code{-var-show-attributes} Command
30681 @findex -var-show-attributes
30682
30683 @subsubheading Synopsis
30684
30685 @smallexample
30686  -var-show-attributes @var{name}
30687 @end smallexample
30688
30689 List attributes of the specified variable object @var{name}:
30690
30691 @smallexample
30692  status=@var{attr} [ ( ,@var{attr} )* ]
30693 @end smallexample
30694
30695 @noindent
30696 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
30697
30698 @subheading The @code{-var-evaluate-expression} Command
30699 @findex -var-evaluate-expression
30700
30701 @subsubheading Synopsis
30702
30703 @smallexample
30704  -var-evaluate-expression [-f @var{format-spec}] @var{name}
30705 @end smallexample
30706
30707 Evaluates the expression that is represented by the specified variable
30708 object and returns its value as a string.  The format of the string
30709 can be specified with the @samp{-f} option.  The possible values of 
30710 this option are the same as for @code{-var-set-format} 
30711 (@pxref{-var-set-format}).  If the @samp{-f} option is not specified,
30712 the current display format will be used.  The current display format 
30713 can be changed using the @code{-var-set-format} command.
30714
30715 @smallexample
30716  value=@var{value}
30717 @end smallexample
30718
30719 Note that one must invoke @code{-var-list-children} for a variable
30720 before the value of a child variable can be evaluated.
30721
30722 @subheading The @code{-var-assign} Command
30723 @findex -var-assign
30724
30725 @subsubheading Synopsis
30726
30727 @smallexample
30728  -var-assign @var{name} @var{expression}
30729 @end smallexample
30730
30731 Assigns the value of @var{expression} to the variable object specified
30732 by @var{name}.  The object must be @samp{editable}.  If the variable's
30733 value is altered by the assign, the variable will show up in any
30734 subsequent @code{-var-update} list.
30735
30736 @subsubheading Example
30737
30738 @smallexample
30739 (gdb)
30740 -var-assign var1 3
30741 ^done,value="3"
30742 (gdb)
30743 -var-update *
30744 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
30745 (gdb)
30746 @end smallexample
30747
30748 @subheading The @code{-var-update} Command
30749 @findex -var-update
30750
30751 @subsubheading Synopsis
30752
30753 @smallexample
30754  -var-update [@var{print-values}] @{@var{name} | "*"@}
30755 @end smallexample
30756
30757 Reevaluate the expressions corresponding to the variable object
30758 @var{name} and all its direct and indirect children, and return the
30759 list of variable objects whose values have changed; @var{name} must
30760 be a root variable object.  Here, ``changed'' means that the result of
30761 @code{-var-evaluate-expression} before and after the
30762 @code{-var-update} is different.  If @samp{*} is used as the variable
30763 object names, all existing variable objects are updated, except
30764 for frozen ones (@pxref{-var-set-frozen}).  The option
30765 @var{print-values} determines whether both names and values, or just
30766 names are printed.  The possible values of this option are the same
30767 as for @code{-var-list-children} (@pxref{-var-list-children}).  It is
30768 recommended to use the @samp{--all-values} option, to reduce the
30769 number of MI commands needed on each program stop.
30770
30771 With the @samp{*} parameter, if a variable object is bound to a
30772 currently running thread, it will not be updated, without any
30773 diagnostic.
30774
30775 If @code{-var-set-update-range} was previously used on a varobj, then
30776 only the selected range of children will be reported.
30777
30778 @code{-var-update} reports all the changed varobjs in a tuple named
30779 @samp{changelist}.
30780
30781 Each item in the change list is itself a tuple holding:
30782
30783 @table @samp
30784 @item name
30785 The name of the varobj.
30786
30787 @item value
30788 If values were requested for this update, then this field will be
30789 present and will hold the value of the varobj.
30790
30791 @item in_scope
30792 @anchor{-var-update}
30793 This field is a string which may take one of three values:
30794
30795 @table @code
30796 @item "true"
30797 The variable object's current value is valid.
30798
30799 @item "false"
30800 The variable object does not currently hold a valid value but it may
30801 hold one in the future if its associated expression comes back into
30802 scope.
30803
30804 @item "invalid"
30805 The variable object no longer holds a valid value.
30806 This can occur when the executable file being debugged has changed,
30807 either through recompilation or by using the @value{GDBN} @code{file}
30808 command.  The front end should normally choose to delete these variable
30809 objects.
30810 @end table
30811
30812 In the future new values may be added to this list so the front should
30813 be prepared for this possibility.  @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
30814
30815 @item type_changed
30816 This is only present if the varobj is still valid.  If the type
30817 changed, then this will be the string @samp{true}; otherwise it will
30818 be @samp{false}.
30819
30820 When a varobj's type changes, its children are also likely to have
30821 become incorrect.  Therefore, the varobj's children are automatically
30822 deleted when this attribute is @samp{true}.  Also, the varobj's update
30823 range, when set using the @code{-var-set-update-range} command, is
30824 unset.
30825
30826 @item new_type
30827 If the varobj's type changed, then this field will be present and will
30828 hold the new type.
30829
30830 @item new_num_children
30831 For a dynamic varobj, if the number of children changed, or if the
30832 type changed, this will be the new number of children.
30833
30834 The @samp{numchild} field in other varobj responses is generally not
30835 valid for a dynamic varobj -- it will show the number of children that
30836 @value{GDBN} knows about, but because dynamic varobjs lazily
30837 instantiate their children, this will not reflect the number of
30838 children which may be available.
30839
30840 The @samp{new_num_children} attribute only reports changes to the
30841 number of children known by @value{GDBN}.  This is the only way to
30842 detect whether an update has removed children (which necessarily can
30843 only happen at the end of the update range).
30844
30845 @item displayhint
30846 The display hint, if any.
30847
30848 @item has_more
30849 This is an integer value, which will be 1 if there are more children
30850 available outside the varobj's update range.
30851
30852 @item dynamic
30853 This attribute will be present and have the value @samp{1} if the
30854 varobj is a dynamic varobj.  If the varobj is not a dynamic varobj,
30855 then this attribute will not be present.
30856
30857 @item new_children
30858 If new children were added to a dynamic varobj within the selected
30859 update range (as set by @code{-var-set-update-range}), then they will
30860 be listed in this attribute.
30861 @end table
30862
30863 @subsubheading Example
30864
30865 @smallexample
30866 (gdb)
30867 -var-assign var1 3
30868 ^done,value="3"
30869 (gdb)
30870 -var-update --all-values var1
30871 ^done,changelist=[@{name="var1",value="3",in_scope="true",
30872 type_changed="false"@}]
30873 (gdb)
30874 @end smallexample
30875
30876 @subheading The @code{-var-set-frozen} Command
30877 @findex -var-set-frozen
30878 @anchor{-var-set-frozen}
30879
30880 @subsubheading Synopsis
30881
30882 @smallexample
30883  -var-set-frozen @var{name} @var{flag}
30884 @end smallexample
30885
30886 Set the frozenness flag on the variable object @var{name}.  The
30887 @var{flag} parameter should be either @samp{1} to make the variable
30888 frozen or @samp{0} to make it unfrozen.  If a variable object is
30889 frozen, then neither itself, nor any of its children, are 
30890 implicitly updated by @code{-var-update} of 
30891 a parent variable or by @code{-var-update *}.  Only
30892 @code{-var-update} of the variable itself will update its value and
30893 values of its children.  After a variable object is unfrozen, it is
30894 implicitly updated by all subsequent @code{-var-update} operations.  
30895 Unfreezing a variable does not update it, only subsequent
30896 @code{-var-update} does.
30897
30898 @subsubheading Example
30899
30900 @smallexample
30901 (gdb)
30902 -var-set-frozen V 1
30903 ^done
30904 (gdb)
30905 @end smallexample
30906
30907 @subheading The @code{-var-set-update-range} command
30908 @findex -var-set-update-range
30909 @anchor{-var-set-update-range}
30910
30911 @subsubheading Synopsis
30912
30913 @smallexample
30914  -var-set-update-range @var{name} @var{from} @var{to}
30915 @end smallexample
30916
30917 Set the range of children to be returned by future invocations of
30918 @code{-var-update}.
30919
30920 @var{from} and @var{to} indicate the range of children to report.  If
30921 @var{from} or @var{to} is less than zero, the range is reset and all
30922 children will be reported.  Otherwise, children starting at @var{from}
30923 (zero-based) and up to and excluding @var{to} will be reported.
30924
30925 @subsubheading Example
30926
30927 @smallexample
30928 (gdb)
30929 -var-set-update-range V 1 2
30930 ^done
30931 @end smallexample
30932
30933 @subheading The @code{-var-set-visualizer} command
30934 @findex -var-set-visualizer
30935 @anchor{-var-set-visualizer}
30936
30937 @subsubheading Synopsis
30938
30939 @smallexample
30940  -var-set-visualizer @var{name} @var{visualizer}
30941 @end smallexample
30942
30943 Set a visualizer for the variable object @var{name}.
30944
30945 @var{visualizer} is the visualizer to use.  The special value
30946 @samp{None} means to disable any visualizer in use.
30947
30948 If not @samp{None}, @var{visualizer} must be a Python expression.
30949 This expression must evaluate to a callable object which accepts a
30950 single argument.  @value{GDBN} will call this object with the value of
30951 the varobj @var{name} as an argument (this is done so that the same
30952 Python pretty-printing code can be used for both the CLI and MI).
30953 When called, this object must return an object which conforms to the
30954 pretty-printing interface (@pxref{Pretty Printing API}).
30955
30956 The pre-defined function @code{gdb.default_visualizer} may be used to
30957 select a visualizer by following the built-in process
30958 (@pxref{Selecting Pretty-Printers}).  This is done automatically when
30959 a varobj is created, and so ordinarily is not needed.
30960
30961 This feature is only available if Python support is enabled.  The MI
30962 command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
30963 can be used to check this.
30964
30965 @subsubheading Example
30966
30967 Resetting the visualizer:
30968
30969 @smallexample
30970 (gdb)
30971 -var-set-visualizer V None
30972 ^done
30973 @end smallexample
30974
30975 Reselecting the default (type-based) visualizer:
30976
30977 @smallexample
30978 (gdb)
30979 -var-set-visualizer V gdb.default_visualizer
30980 ^done
30981 @end smallexample
30982
30983 Suppose @code{SomeClass} is a visualizer class.  A lambda expression
30984 can be used to instantiate this class for a varobj:
30985
30986 @smallexample
30987 (gdb)
30988 -var-set-visualizer V "lambda val: SomeClass()"
30989 ^done
30990 @end smallexample
30991
30992 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30993 @node GDB/MI Data Manipulation
30994 @section @sc{gdb/mi} Data Manipulation
30995
30996 @cindex data manipulation, in @sc{gdb/mi}
30997 @cindex @sc{gdb/mi}, data manipulation
30998 This section describes the @sc{gdb/mi} commands that manipulate data:
30999 examine memory and registers, evaluate expressions, etc.
31000
31001 @c REMOVED FROM THE INTERFACE.
31002 @c @subheading -data-assign
31003 @c Change the value of a program variable. Plenty of side effects.
31004 @c @subsubheading GDB Command
31005 @c set variable
31006 @c @subsubheading Example
31007 @c N.A.
31008
31009 @subheading The @code{-data-disassemble} Command
31010 @findex -data-disassemble
31011
31012 @subsubheading Synopsis
31013
31014 @smallexample
31015  -data-disassemble
31016     [ -s @var{start-addr} -e @var{end-addr} ]
31017   | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
31018   -- @var{mode}
31019 @end smallexample
31020
31021 @noindent
31022 Where:
31023
31024 @table @samp
31025 @item @var{start-addr}
31026 is the beginning address (or @code{$pc})
31027 @item @var{end-addr}
31028 is the end address
31029 @item @var{filename}
31030 is the name of the file to disassemble
31031 @item @var{linenum}
31032 is the line number to disassemble around
31033 @item @var{lines}
31034 is the number of disassembly lines to be produced.  If it is -1,
31035 the whole function will be disassembled, in case no @var{end-addr} is
31036 specified.  If @var{end-addr} is specified as a non-zero value, and
31037 @var{lines} is lower than the number of disassembly lines between
31038 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
31039 displayed; if @var{lines} is higher than the number of lines between
31040 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
31041 are displayed.
31042 @item @var{mode}
31043 is either 0 (meaning only disassembly), 1 (meaning mixed source and
31044 disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
31045 mixed source and disassembly with raw opcodes).
31046 @end table
31047
31048 @subsubheading Result
31049
31050 The result of the @code{-data-disassemble} command will be a list named
31051 @samp{asm_insns}, the contents of this list depend on the @var{mode}
31052 used with the @code{-data-disassemble} command.
31053
31054 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
31055 following fields:
31056
31057 @table @code
31058 @item address
31059 The address at which this instruction was disassembled.
31060
31061 @item func-name
31062 The name of the function this instruction is within.
31063
31064 @item offset
31065 The decimal offset in bytes from the start of @samp{func-name}.
31066
31067 @item inst
31068 The text disassembly for this @samp{address}.
31069
31070 @item opcodes
31071 This field is only present for mode 2.  This contains the raw opcode
31072 bytes for the @samp{inst} field.
31073
31074 @end table
31075
31076 For modes 1 and 3 the @samp{asm_insns} list contains tuples named
31077 @samp{src_and_asm_line}, each of which has the following fields:
31078
31079 @table @code
31080 @item line
31081 The line number within @samp{file}.
31082
31083 @item file
31084 The file name from the compilation unit.  This might be an absolute
31085 file name or a relative file name depending on the compile command
31086 used.
31087
31088 @item fullname
31089 Absolute file name of @samp{file}.  It is converted to a canonical form
31090 using the source file search path
31091 (@pxref{Source Path, ,Specifying Source Directories})
31092 and after resolving all the symbolic links.
31093
31094 If the source file is not found this field will contain the path as
31095 present in the debug information.
31096
31097 @item line_asm_insn
31098 This is a list of tuples containing the disassembly for @samp{line} in
31099 @samp{file}.  The fields of each tuple are the same as for
31100 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
31101 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
31102 @samp{opcodes}.
31103
31104 @end table
31105
31106 Note that whatever included in the @samp{inst} field, is not
31107 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
31108 adjust its format.
31109
31110 @subsubheading @value{GDBN} Command
31111
31112 The corresponding @value{GDBN} command is @samp{disassemble}.
31113
31114 @subsubheading Example
31115
31116 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
31117
31118 @smallexample
31119 (gdb)
31120 -data-disassemble -s $pc -e "$pc + 20" -- 0
31121 ^done,
31122 asm_insns=[
31123 @{address="0x000107c0",func-name="main",offset="4",
31124 inst="mov  2, %o0"@},
31125 @{address="0x000107c4",func-name="main",offset="8",
31126 inst="sethi  %hi(0x11800), %o2"@},
31127 @{address="0x000107c8",func-name="main",offset="12",
31128 inst="or  %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
31129 @{address="0x000107cc",func-name="main",offset="16",
31130 inst="sethi  %hi(0x11800), %o2"@},
31131 @{address="0x000107d0",func-name="main",offset="20",
31132 inst="or  %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
31133 (gdb)
31134 @end smallexample
31135
31136 Disassemble the whole @code{main} function.  Line 32 is part of
31137 @code{main}.
31138
31139 @smallexample
31140 -data-disassemble -f basics.c -l 32 -- 0
31141 ^done,asm_insns=[
31142 @{address="0x000107bc",func-name="main",offset="0",
31143 inst="save  %sp, -112, %sp"@},
31144 @{address="0x000107c0",func-name="main",offset="4",
31145 inst="mov   2, %o0"@},
31146 @{address="0x000107c4",func-name="main",offset="8",
31147 inst="sethi %hi(0x11800), %o2"@},
31148 [@dots{}]
31149 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
31150 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
31151 (gdb)
31152 @end smallexample
31153
31154 Disassemble 3 instructions from the start of @code{main}:
31155
31156 @smallexample
31157 (gdb)
31158 -data-disassemble -f basics.c -l 32 -n 3 -- 0
31159 ^done,asm_insns=[
31160 @{address="0x000107bc",func-name="main",offset="0",
31161 inst="save  %sp, -112, %sp"@},
31162 @{address="0x000107c0",func-name="main",offset="4",
31163 inst="mov  2, %o0"@},
31164 @{address="0x000107c4",func-name="main",offset="8",
31165 inst="sethi  %hi(0x11800), %o2"@}]
31166 (gdb)
31167 @end smallexample
31168
31169 Disassemble 3 instructions from the start of @code{main} in mixed mode:
31170
31171 @smallexample
31172 (gdb)
31173 -data-disassemble -f basics.c -l 32 -n 3 -- 1
31174 ^done,asm_insns=[
31175 src_and_asm_line=@{line="31",
31176 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31177 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31178 line_asm_insn=[@{address="0x000107bc",
31179 func-name="main",offset="0",inst="save  %sp, -112, %sp"@}]@},
31180 src_and_asm_line=@{line="32",
31181 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
31182 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
31183 line_asm_insn=[@{address="0x000107c0",
31184 func-name="main",offset="4",inst="mov  2, %o0"@},
31185 @{address="0x000107c4",func-name="main",offset="8",
31186 inst="sethi  %hi(0x11800), %o2"@}]@}]
31187 (gdb)
31188 @end smallexample
31189
31190
31191 @subheading The @code{-data-evaluate-expression} Command
31192 @findex -data-evaluate-expression
31193
31194 @subsubheading Synopsis
31195
31196 @smallexample
31197  -data-evaluate-expression @var{expr}
31198 @end smallexample
31199
31200 Evaluate @var{expr} as an expression.  The expression could contain an
31201 inferior function call.  The function call will execute synchronously.
31202 If the expression contains spaces, it must be enclosed in double quotes.
31203
31204 @subsubheading @value{GDBN} Command
31205
31206 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
31207 @samp{call}.  In @code{gdbtk} only, there's a corresponding
31208 @samp{gdb_eval} command.
31209
31210 @subsubheading Example
31211
31212 In the following example, the numbers that precede the commands are the
31213 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
31214 Command Syntax}.  Notice how @sc{gdb/mi} returns the same tokens in its
31215 output.
31216
31217 @smallexample
31218 211-data-evaluate-expression A
31219 211^done,value="1"
31220 (gdb)
31221 311-data-evaluate-expression &A
31222 311^done,value="0xefffeb7c"
31223 (gdb)
31224 411-data-evaluate-expression A+3
31225 411^done,value="4"
31226 (gdb)
31227 511-data-evaluate-expression "A + 3"
31228 511^done,value="4"
31229 (gdb)
31230 @end smallexample
31231
31232
31233 @subheading The @code{-data-list-changed-registers} Command
31234 @findex -data-list-changed-registers
31235
31236 @subsubheading Synopsis
31237
31238 @smallexample
31239  -data-list-changed-registers
31240 @end smallexample
31241
31242 Display a list of the registers that have changed.
31243
31244 @subsubheading @value{GDBN} Command
31245
31246 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
31247 has the corresponding command @samp{gdb_changed_register_list}.
31248
31249 @subsubheading Example
31250
31251 On a PPC MBX board:
31252
31253 @smallexample
31254 (gdb)
31255 -exec-continue
31256 ^running
31257
31258 (gdb)
31259 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
31260 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
31261 line="5"@}
31262 (gdb)
31263 -data-list-changed-registers
31264 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
31265 "10","11","13","14","15","16","17","18","19","20","21","22","23",
31266 "24","25","26","27","28","30","31","64","65","66","67","69"]
31267 (gdb)
31268 @end smallexample
31269
31270
31271 @subheading The @code{-data-list-register-names} Command
31272 @findex -data-list-register-names
31273
31274 @subsubheading Synopsis
31275
31276 @smallexample
31277  -data-list-register-names [ ( @var{regno} )+ ]
31278 @end smallexample
31279
31280 Show a list of register names for the current target.  If no arguments
31281 are given, it shows a list of the names of all the registers.  If
31282 integer numbers are given as arguments, it will print a list of the
31283 names of the registers corresponding to the arguments.  To ensure
31284 consistency between a register name and its number, the output list may
31285 include empty register names.
31286
31287 @subsubheading @value{GDBN} Command
31288
31289 @value{GDBN} does not have a command which corresponds to
31290 @samp{-data-list-register-names}.  In @code{gdbtk} there is a
31291 corresponding command @samp{gdb_regnames}.
31292
31293 @subsubheading Example
31294
31295 For the PPC MBX board:
31296 @smallexample
31297 (gdb)
31298 -data-list-register-names
31299 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
31300 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
31301 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
31302 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
31303 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
31304 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
31305 "", "pc","ps","cr","lr","ctr","xer"]
31306 (gdb)
31307 -data-list-register-names 1 2 3
31308 ^done,register-names=["r1","r2","r3"]
31309 (gdb)
31310 @end smallexample
31311
31312 @subheading The @code{-data-list-register-values} Command
31313 @findex -data-list-register-values
31314
31315 @subsubheading Synopsis
31316
31317 @smallexample
31318  -data-list-register-values @var{fmt} [ ( @var{regno} )*]
31319 @end smallexample
31320
31321 Display the registers' contents.  @var{fmt} is the format according to
31322 which the registers' contents are to be returned, followed by an optional
31323 list of numbers specifying the registers to display.  A missing list of
31324 numbers indicates that the contents of all the registers must be returned.
31325
31326 Allowed formats for @var{fmt} are:
31327
31328 @table @code
31329 @item x
31330 Hexadecimal
31331 @item o
31332 Octal
31333 @item t
31334 Binary
31335 @item d
31336 Decimal
31337 @item r
31338 Raw
31339 @item N
31340 Natural
31341 @end table
31342
31343 @subsubheading @value{GDBN} Command
31344
31345 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
31346 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
31347
31348 @subsubheading Example
31349
31350 For a PPC MBX board (note: line breaks are for readability only, they
31351 don't appear in the actual output):
31352
31353 @smallexample
31354 (gdb)
31355 -data-list-register-values r 64 65
31356 ^done,register-values=[@{number="64",value="0xfe00a300"@},
31357 @{number="65",value="0x00029002"@}]
31358 (gdb)
31359 -data-list-register-values x
31360 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
31361 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
31362 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
31363 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
31364 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
31365 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
31366 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
31367 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
31368 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
31369 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
31370 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
31371 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
31372 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
31373 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
31374 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
31375 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
31376 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
31377 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
31378 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
31379 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
31380 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
31381 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
31382 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
31383 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
31384 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
31385 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
31386 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
31387 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
31388 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
31389 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
31390 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
31391 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
31392 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
31393 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
31394 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
31395 @{number="69",value="0x20002b03"@}]
31396 (gdb)
31397 @end smallexample
31398
31399
31400 @subheading The @code{-data-read-memory} Command
31401 @findex -data-read-memory
31402
31403 This command is deprecated, use @code{-data-read-memory-bytes} instead.
31404
31405 @subsubheading Synopsis
31406
31407 @smallexample
31408  -data-read-memory [ -o @var{byte-offset} ]
31409    @var{address} @var{word-format} @var{word-size}
31410    @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
31411 @end smallexample
31412
31413 @noindent
31414 where:
31415
31416 @table @samp
31417 @item @var{address}
31418 An expression specifying the address of the first memory word to be
31419 read.  Complex expressions containing embedded white space should be
31420 quoted using the C convention.
31421
31422 @item @var{word-format}
31423 The format to be used to print the memory words.  The notation is the
31424 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
31425 ,Output Formats}).
31426
31427 @item @var{word-size}
31428 The size of each memory word in bytes.
31429
31430 @item @var{nr-rows}
31431 The number of rows in the output table.
31432
31433 @item @var{nr-cols}
31434 The number of columns in the output table.
31435
31436 @item @var{aschar}
31437 If present, indicates that each row should include an @sc{ascii} dump.  The
31438 value of @var{aschar} is used as a padding character when a byte is not a
31439 member of the printable @sc{ascii} character set (printable @sc{ascii}
31440 characters are those whose code is between 32 and 126, inclusively).
31441
31442 @item @var{byte-offset}
31443 An offset to add to the @var{address} before fetching memory.
31444 @end table
31445
31446 This command displays memory contents as a table of @var{nr-rows} by
31447 @var{nr-cols} words, each word being @var{word-size} bytes.  In total,
31448 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
31449 (returned as @samp{total-bytes}).  Should less than the requested number
31450 of bytes be returned by the target, the missing words are identified
31451 using @samp{N/A}.  The number of bytes read from the target is returned
31452 in @samp{nr-bytes} and the starting address used to read memory in
31453 @samp{addr}.
31454
31455 The address of the next/previous row or page is available in
31456 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
31457 @samp{prev-page}.
31458
31459 @subsubheading @value{GDBN} Command
31460
31461 The corresponding @value{GDBN} command is @samp{x}.  @code{gdbtk} has
31462 @samp{gdb_get_mem} memory read command.
31463
31464 @subsubheading Example
31465
31466 Read six bytes of memory starting at @code{bytes+6} but then offset by
31467 @code{-6} bytes.  Format as three rows of two columns.  One byte per
31468 word.  Display each word in hex.
31469
31470 @smallexample
31471 (gdb)
31472 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
31473 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
31474 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
31475 prev-page="0x0000138a",memory=[
31476 @{addr="0x00001390",data=["0x00","0x01"]@},
31477 @{addr="0x00001392",data=["0x02","0x03"]@},
31478 @{addr="0x00001394",data=["0x04","0x05"]@}]
31479 (gdb)
31480 @end smallexample
31481
31482 Read two bytes of memory starting at address @code{shorts + 64} and
31483 display as a single word formatted in decimal.
31484
31485 @smallexample
31486 (gdb)
31487 5-data-read-memory shorts+64 d 2 1 1
31488 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
31489 next-row="0x00001512",prev-row="0x0000150e",
31490 next-page="0x00001512",prev-page="0x0000150e",memory=[
31491 @{addr="0x00001510",data=["128"]@}]
31492 (gdb)
31493 @end smallexample
31494
31495 Read thirty two bytes of memory starting at @code{bytes+16} and format
31496 as eight rows of four columns.  Include a string encoding with @samp{x}
31497 used as the non-printable character.
31498
31499 @smallexample
31500 (gdb)
31501 4-data-read-memory bytes+16 x 1 8 4 x
31502 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
31503 next-row="0x000013c0",prev-row="0x0000139c",
31504 next-page="0x000013c0",prev-page="0x00001380",memory=[
31505 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
31506 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
31507 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
31508 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
31509 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
31510 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
31511 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
31512 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
31513 (gdb)
31514 @end smallexample
31515
31516 @subheading The @code{-data-read-memory-bytes} Command
31517 @findex -data-read-memory-bytes
31518
31519 @subsubheading Synopsis
31520
31521 @smallexample
31522  -data-read-memory-bytes [ -o @var{byte-offset} ]
31523    @var{address} @var{count}
31524 @end smallexample
31525
31526 @noindent
31527 where:
31528
31529 @table @samp
31530 @item @var{address}
31531 An expression specifying the address of the first memory word to be
31532 read.  Complex expressions containing embedded white space should be
31533 quoted using the C convention.
31534
31535 @item @var{count}
31536 The number of bytes to read.  This should be an integer literal.
31537
31538 @item @var{byte-offset}
31539 The offsets in bytes relative to @var{address} at which to start
31540 reading.  This should be an integer literal.  This option is provided
31541 so that a frontend is not required to first evaluate address and then
31542 perform address arithmetics itself.
31543
31544 @end table
31545
31546 This command attempts to read all accessible memory regions in the
31547 specified range.  First, all regions marked as unreadable in the memory
31548 map (if one is defined) will be skipped.  @xref{Memory Region
31549 Attributes}.  Second, @value{GDBN} will attempt to read the remaining
31550 regions.  For each one, if reading full region results in an errors,
31551 @value{GDBN} will try to read a subset of the region.
31552
31553 In general, every single byte in the region may be readable or not,
31554 and the only way to read every readable byte is to try a read at
31555 every address, which is not practical.   Therefore, @value{GDBN} will
31556 attempt to read all accessible bytes at either beginning or the end
31557 of the region, using a binary division scheme.  This heuristic works
31558 well for reading accross a memory map boundary.  Note that if a region
31559 has a readable range that is neither at the beginning or the end,
31560 @value{GDBN} will not read it.
31561
31562 The result record (@pxref{GDB/MI Result Records}) that is output of
31563 the command includes a field named @samp{memory} whose content is a
31564 list of tuples.  Each tuple represent a successfully read memory block
31565 and has the following fields:
31566
31567 @table @code
31568 @item begin
31569 The start address of the memory block, as hexadecimal literal.
31570
31571 @item end
31572 The end address of the memory block, as hexadecimal literal.
31573
31574 @item offset
31575 The offset of the memory block, as hexadecimal literal, relative to
31576 the start address passed to @code{-data-read-memory-bytes}.
31577
31578 @item contents
31579 The contents of the memory block, in hex.
31580
31581 @end table
31582
31583
31584
31585 @subsubheading @value{GDBN} Command
31586
31587 The corresponding @value{GDBN} command is @samp{x}.
31588
31589 @subsubheading Example
31590
31591 @smallexample
31592 (gdb)
31593 -data-read-memory-bytes &a 10
31594 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
31595               end="0xbffff15e",
31596               contents="01000000020000000300"@}]
31597 (gdb)
31598 @end smallexample
31599
31600
31601 @subheading The @code{-data-write-memory-bytes} Command
31602 @findex -data-write-memory-bytes
31603
31604 @subsubheading Synopsis
31605
31606 @smallexample
31607  -data-write-memory-bytes @var{address} @var{contents}
31608  -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
31609 @end smallexample
31610
31611 @noindent
31612 where:
31613
31614 @table @samp
31615 @item @var{address}
31616 An expression specifying the address of the first memory word to be
31617 read.  Complex expressions containing embedded white space should be
31618 quoted using the C convention.
31619
31620 @item @var{contents}
31621 The hex-encoded bytes to write.
31622
31623 @item @var{count}
31624 Optional argument indicating the number of bytes to be written.  If @var{count} 
31625 is greater than @var{contents}' length, @value{GDBN} will repeatedly 
31626 write @var{contents} until it fills @var{count} bytes.
31627
31628 @end table
31629
31630 @subsubheading @value{GDBN} Command
31631
31632 There's no corresponding @value{GDBN} command.
31633
31634 @subsubheading Example
31635
31636 @smallexample
31637 (gdb)
31638 -data-write-memory-bytes &a "aabbccdd"
31639 ^done
31640 (gdb)
31641 @end smallexample
31642
31643 @smallexample
31644 (gdb)
31645 -data-write-memory-bytes &a "aabbccdd" 16e
31646 ^done
31647 (gdb)
31648 @end smallexample
31649
31650 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31651 @node GDB/MI Tracepoint Commands
31652 @section @sc{gdb/mi} Tracepoint Commands
31653
31654 The commands defined in this section implement MI support for
31655 tracepoints.  For detailed introduction, see @ref{Tracepoints}.
31656
31657 @subheading The @code{-trace-find} Command
31658 @findex -trace-find
31659
31660 @subsubheading Synopsis
31661
31662 @smallexample
31663  -trace-find @var{mode} [@var{parameters}@dots{}]
31664 @end smallexample
31665
31666 Find a trace frame using criteria defined by @var{mode} and
31667 @var{parameters}.  The following table lists permissible
31668 modes and their parameters.  For details of operation, see @ref{tfind}.
31669
31670 @table @samp
31671
31672 @item none
31673 No parameters are required.  Stops examining trace frames.
31674
31675 @item frame-number
31676 An integer is required as parameter.  Selects tracepoint frame with
31677 that index.
31678
31679 @item tracepoint-number
31680 An integer is required as parameter.  Finds next
31681 trace frame that corresponds to tracepoint with the specified number.
31682
31683 @item pc
31684 An address is required as parameter.  Finds
31685 next trace frame that corresponds to any tracepoint at the specified
31686 address.
31687
31688 @item pc-inside-range
31689 Two addresses are required as parameters.  Finds next trace
31690 frame that corresponds to a tracepoint at an address inside the
31691 specified range.  Both bounds are considered to be inside the range.
31692
31693 @item pc-outside-range
31694 Two addresses are required as parameters.  Finds
31695 next trace frame that corresponds to a tracepoint at an address outside
31696 the specified range.  Both bounds are considered to be inside the range.
31697
31698 @item line
31699 Line specification is required as parameter.  @xref{Specify Location}.
31700 Finds next trace frame that corresponds to a tracepoint at
31701 the specified location.
31702
31703 @end table
31704
31705 If @samp{none} was passed as @var{mode}, the response does not
31706 have fields.  Otherwise, the response may have the following fields:
31707
31708 @table @samp
31709 @item found
31710 This field has either @samp{0} or @samp{1} as the value, depending
31711 on whether a matching tracepoint was found.
31712
31713 @item traceframe
31714 The index of the found traceframe.  This field is present iff
31715 the @samp{found} field has value of @samp{1}.
31716
31717 @item tracepoint
31718 The index of the found tracepoint.  This field is present iff
31719 the @samp{found} field has value of @samp{1}.
31720
31721 @item frame
31722 The information about the frame corresponding to the found trace
31723 frame.  This field is present only if a trace frame was found.
31724 @xref{GDB/MI Frame Information}, for description of this field.
31725
31726 @end table
31727
31728 @subsubheading @value{GDBN} Command
31729
31730 The corresponding @value{GDBN} command is @samp{tfind}.
31731
31732 @subheading -trace-define-variable
31733 @findex -trace-define-variable
31734
31735 @subsubheading Synopsis
31736
31737 @smallexample
31738  -trace-define-variable @var{name} [ @var{value} ]
31739 @end smallexample
31740
31741 Create trace variable @var{name} if it does not exist.  If
31742 @var{value} is specified, sets the initial value of the specified
31743 trace variable to that value.  Note that the @var{name} should start
31744 with the @samp{$} character.
31745
31746 @subsubheading @value{GDBN} Command
31747
31748 The corresponding @value{GDBN} command is @samp{tvariable}.
31749
31750 @subheading -trace-list-variables
31751 @findex -trace-list-variables
31752
31753 @subsubheading Synopsis
31754
31755 @smallexample
31756  -trace-list-variables
31757 @end smallexample
31758
31759 Return a table of all defined trace variables.  Each element of the
31760 table has the following fields:
31761
31762 @table @samp
31763 @item name
31764 The name of the trace variable.  This field is always present.
31765
31766 @item initial
31767 The initial value.  This is a 64-bit signed integer.  This
31768 field is always present.
31769
31770 @item current
31771 The value the trace variable has at the moment.  This is a 64-bit
31772 signed integer.  This field is absent iff current value is
31773 not defined, for example if the trace was never run, or is
31774 presently running.
31775
31776 @end table
31777
31778 @subsubheading @value{GDBN} Command
31779
31780 The corresponding @value{GDBN} command is @samp{tvariables}.
31781
31782 @subsubheading Example
31783
31784 @smallexample
31785 (gdb)
31786 -trace-list-variables
31787 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
31788 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
31789      @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
31790      @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
31791 body=[variable=@{name="$trace_timestamp",initial="0"@}
31792       variable=@{name="$foo",initial="10",current="15"@}]@}
31793 (gdb)
31794 @end smallexample
31795
31796 @subheading -trace-save
31797 @findex -trace-save
31798
31799 @subsubheading Synopsis
31800
31801 @smallexample
31802  -trace-save [-r ] @var{filename}
31803 @end smallexample
31804
31805 Saves the collected trace data to @var{filename}.  Without the
31806 @samp{-r} option, the data is downloaded from the target and saved
31807 in a local file.  With the @samp{-r} option the target is asked
31808 to perform the save.
31809
31810 @subsubheading @value{GDBN} Command
31811
31812 The corresponding @value{GDBN} command is @samp{tsave}.
31813
31814
31815 @subheading -trace-start
31816 @findex -trace-start
31817
31818 @subsubheading Synopsis
31819
31820 @smallexample
31821  -trace-start
31822 @end smallexample
31823
31824 Starts a tracing experiments.  The result of this command does not
31825 have any fields.
31826
31827 @subsubheading @value{GDBN} Command
31828
31829 The corresponding @value{GDBN} command is @samp{tstart}.
31830
31831 @subheading -trace-status
31832 @findex -trace-status
31833
31834 @subsubheading Synopsis
31835
31836 @smallexample
31837  -trace-status
31838 @end smallexample
31839
31840 Obtains the status of a tracing experiment.  The result may include
31841 the following fields:
31842
31843 @table @samp
31844
31845 @item supported
31846 May have a value of either @samp{0}, when no tracing operations are
31847 supported, @samp{1}, when all tracing operations are supported, or
31848 @samp{file} when examining trace file.  In the latter case, examining
31849 of trace frame is possible but new tracing experiement cannot be
31850 started.  This field is always present.
31851
31852 @item running
31853 May have a value of either @samp{0} or @samp{1} depending on whether
31854 tracing experiement is in progress on target.  This field is present
31855 if @samp{supported} field is not @samp{0}.
31856
31857 @item stop-reason
31858 Report the reason why the tracing was stopped last time.  This field
31859 may be absent iff tracing was never stopped on target yet.  The
31860 value of @samp{request} means the tracing was stopped as result of
31861 the @code{-trace-stop} command.  The value of @samp{overflow} means
31862 the tracing buffer is full.  The value of @samp{disconnection} means
31863 tracing was automatically stopped when @value{GDBN} has disconnected.
31864 The value of @samp{passcount} means tracing was stopped when a
31865 tracepoint was passed a maximal number of times for that tracepoint.
31866 This field is present if @samp{supported} field is not @samp{0}.
31867
31868 @item stopping-tracepoint
31869 The number of tracepoint whose passcount as exceeded.  This field is
31870 present iff the @samp{stop-reason} field has the value of
31871 @samp{passcount}.
31872
31873 @item frames
31874 @itemx frames-created
31875 The @samp{frames} field is a count of the total number of trace frames
31876 in the trace buffer, while @samp{frames-created} is the total created
31877 during the run, including ones that were discarded, such as when a
31878 circular trace buffer filled up.  Both fields are optional.
31879
31880 @item buffer-size
31881 @itemx buffer-free
31882 These fields tell the current size of the tracing buffer and the
31883 remaining space.  These fields are optional.
31884
31885 @item circular
31886 The value of the circular trace buffer flag.  @code{1} means that the
31887 trace buffer is circular and old trace frames will be discarded if
31888 necessary to make room, @code{0} means that the trace buffer is linear
31889 and may fill up.
31890
31891 @item disconnected
31892 The value of the disconnected tracing flag.  @code{1} means that
31893 tracing will continue after @value{GDBN} disconnects, @code{0} means
31894 that the trace run will stop.
31895
31896 @end table
31897
31898 @subsubheading @value{GDBN} Command
31899
31900 The corresponding @value{GDBN} command is @samp{tstatus}.
31901
31902 @subheading -trace-stop
31903 @findex -trace-stop
31904
31905 @subsubheading Synopsis
31906
31907 @smallexample
31908  -trace-stop
31909 @end smallexample
31910
31911 Stops a tracing experiment.  The result of this command has the same
31912 fields as @code{-trace-status}, except that the @samp{supported} and
31913 @samp{running} fields are not output.
31914
31915 @subsubheading @value{GDBN} Command
31916
31917 The corresponding @value{GDBN} command is @samp{tstop}.
31918
31919
31920 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31921 @node GDB/MI Symbol Query
31922 @section @sc{gdb/mi} Symbol Query Commands
31923
31924
31925 @ignore
31926 @subheading The @code{-symbol-info-address} Command
31927 @findex -symbol-info-address
31928
31929 @subsubheading Synopsis
31930
31931 @smallexample
31932  -symbol-info-address @var{symbol}
31933 @end smallexample
31934
31935 Describe where @var{symbol} is stored.
31936
31937 @subsubheading @value{GDBN} Command
31938
31939 The corresponding @value{GDBN} command is @samp{info address}.
31940
31941 @subsubheading Example
31942 N.A.
31943
31944
31945 @subheading The @code{-symbol-info-file} Command
31946 @findex -symbol-info-file
31947
31948 @subsubheading Synopsis
31949
31950 @smallexample
31951  -symbol-info-file
31952 @end smallexample
31953
31954 Show the file for the symbol.
31955
31956 @subsubheading @value{GDBN} Command
31957
31958 There's no equivalent @value{GDBN} command.  @code{gdbtk} has
31959 @samp{gdb_find_file}.
31960
31961 @subsubheading Example
31962 N.A.
31963
31964
31965 @subheading The @code{-symbol-info-function} Command
31966 @findex -symbol-info-function
31967
31968 @subsubheading Synopsis
31969
31970 @smallexample
31971  -symbol-info-function
31972 @end smallexample
31973
31974 Show which function the symbol lives in.
31975
31976 @subsubheading @value{GDBN} Command
31977
31978 @samp{gdb_get_function} in @code{gdbtk}.
31979
31980 @subsubheading Example
31981 N.A.
31982
31983
31984 @subheading The @code{-symbol-info-line} Command
31985 @findex -symbol-info-line
31986
31987 @subsubheading Synopsis
31988
31989 @smallexample
31990  -symbol-info-line
31991 @end smallexample
31992
31993 Show the core addresses of the code for a source line.
31994
31995 @subsubheading @value{GDBN} Command
31996
31997 The corresponding @value{GDBN} command is @samp{info line}.
31998 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
31999
32000 @subsubheading Example
32001 N.A.
32002
32003
32004 @subheading The @code{-symbol-info-symbol} Command
32005 @findex -symbol-info-symbol
32006
32007 @subsubheading Synopsis
32008
32009 @smallexample
32010  -symbol-info-symbol @var{addr}
32011 @end smallexample
32012
32013 Describe what symbol is at location @var{addr}.
32014
32015 @subsubheading @value{GDBN} Command
32016
32017 The corresponding @value{GDBN} command is @samp{info symbol}.
32018
32019 @subsubheading Example
32020 N.A.
32021
32022
32023 @subheading The @code{-symbol-list-functions} Command
32024 @findex -symbol-list-functions
32025
32026 @subsubheading Synopsis
32027
32028 @smallexample
32029  -symbol-list-functions
32030 @end smallexample
32031
32032 List the functions in the executable.
32033
32034 @subsubheading @value{GDBN} Command
32035
32036 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
32037 @samp{gdb_search} in @code{gdbtk}.
32038
32039 @subsubheading Example
32040 N.A.
32041 @end ignore
32042
32043
32044 @subheading The @code{-symbol-list-lines} Command
32045 @findex -symbol-list-lines
32046
32047 @subsubheading Synopsis
32048
32049 @smallexample
32050  -symbol-list-lines @var{filename}
32051 @end smallexample
32052
32053 Print the list of lines that contain code and their associated program
32054 addresses for the given source filename.  The entries are sorted in
32055 ascending PC order.
32056
32057 @subsubheading @value{GDBN} Command
32058
32059 There is no corresponding @value{GDBN} command.
32060
32061 @subsubheading Example
32062 @smallexample
32063 (gdb)
32064 -symbol-list-lines basics.c
32065 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
32066 (gdb)
32067 @end smallexample
32068
32069
32070 @ignore
32071 @subheading The @code{-symbol-list-types} Command
32072 @findex -symbol-list-types
32073
32074 @subsubheading Synopsis
32075
32076 @smallexample
32077  -symbol-list-types
32078 @end smallexample
32079
32080 List all the type names.
32081
32082 @subsubheading @value{GDBN} Command
32083
32084 The corresponding commands are @samp{info types} in @value{GDBN},
32085 @samp{gdb_search} in @code{gdbtk}.
32086
32087 @subsubheading Example
32088 N.A.
32089
32090
32091 @subheading The @code{-symbol-list-variables} Command
32092 @findex -symbol-list-variables
32093
32094 @subsubheading Synopsis
32095
32096 @smallexample
32097  -symbol-list-variables
32098 @end smallexample
32099
32100 List all the global and static variable names.
32101
32102 @subsubheading @value{GDBN} Command
32103
32104 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
32105
32106 @subsubheading Example
32107 N.A.
32108
32109
32110 @subheading The @code{-symbol-locate} Command
32111 @findex -symbol-locate
32112
32113 @subsubheading Synopsis
32114
32115 @smallexample
32116  -symbol-locate
32117 @end smallexample
32118
32119 @subsubheading @value{GDBN} Command
32120
32121 @samp{gdb_loc} in @code{gdbtk}.
32122
32123 @subsubheading Example
32124 N.A.
32125
32126
32127 @subheading The @code{-symbol-type} Command
32128 @findex -symbol-type
32129
32130 @subsubheading Synopsis
32131
32132 @smallexample
32133  -symbol-type @var{variable}
32134 @end smallexample
32135
32136 Show type of @var{variable}.
32137
32138 @subsubheading @value{GDBN} Command
32139
32140 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
32141 @samp{gdb_obj_variable}.
32142
32143 @subsubheading Example
32144 N.A.
32145 @end ignore
32146
32147
32148 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32149 @node GDB/MI File Commands
32150 @section @sc{gdb/mi} File Commands
32151
32152 This section describes the GDB/MI commands to specify executable file names
32153 and to read in and obtain symbol table information.
32154
32155 @subheading The @code{-file-exec-and-symbols} Command
32156 @findex -file-exec-and-symbols
32157
32158 @subsubheading Synopsis
32159
32160 @smallexample
32161  -file-exec-and-symbols @var{file}
32162 @end smallexample
32163
32164 Specify the executable file to be debugged.  This file is the one from
32165 which the symbol table is also read.  If no file is specified, the
32166 command clears the executable and symbol information.  If breakpoints
32167 are set when using this command with no arguments, @value{GDBN} will produce
32168 error messages.  Otherwise, no output is produced, except a completion
32169 notification.
32170
32171 @subsubheading @value{GDBN} Command
32172
32173 The corresponding @value{GDBN} command is @samp{file}.
32174
32175 @subsubheading Example
32176
32177 @smallexample
32178 (gdb)
32179 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32180 ^done
32181 (gdb)
32182 @end smallexample
32183
32184
32185 @subheading The @code{-file-exec-file} Command
32186 @findex -file-exec-file
32187
32188 @subsubheading Synopsis
32189
32190 @smallexample
32191  -file-exec-file @var{file}
32192 @end smallexample
32193
32194 Specify the executable file to be debugged.  Unlike
32195 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
32196 from this file.  If used without argument, @value{GDBN} clears the information
32197 about the executable file.  No output is produced, except a completion
32198 notification.
32199
32200 @subsubheading @value{GDBN} Command
32201
32202 The corresponding @value{GDBN} command is @samp{exec-file}.
32203
32204 @subsubheading Example
32205
32206 @smallexample
32207 (gdb)
32208 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32209 ^done
32210 (gdb)
32211 @end smallexample
32212
32213
32214 @ignore
32215 @subheading The @code{-file-list-exec-sections} Command
32216 @findex -file-list-exec-sections
32217
32218 @subsubheading Synopsis
32219
32220 @smallexample
32221  -file-list-exec-sections
32222 @end smallexample
32223
32224 List the sections of the current executable file.
32225
32226 @subsubheading @value{GDBN} Command
32227
32228 The @value{GDBN} command @samp{info file} shows, among the rest, the same
32229 information as this command.  @code{gdbtk} has a corresponding command
32230 @samp{gdb_load_info}.
32231
32232 @subsubheading Example
32233 N.A.
32234 @end ignore
32235
32236
32237 @subheading The @code{-file-list-exec-source-file} Command
32238 @findex -file-list-exec-source-file
32239
32240 @subsubheading Synopsis
32241
32242 @smallexample
32243  -file-list-exec-source-file
32244 @end smallexample
32245
32246 List the line number, the current source file, and the absolute path
32247 to the current source file for the current executable.  The macro
32248 information field has a value of @samp{1} or @samp{0} depending on
32249 whether or not the file includes preprocessor macro information.
32250
32251 @subsubheading @value{GDBN} Command
32252
32253 The @value{GDBN} equivalent is @samp{info source}
32254
32255 @subsubheading Example
32256
32257 @smallexample
32258 (gdb)
32259 123-file-list-exec-source-file
32260 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
32261 (gdb)
32262 @end smallexample
32263
32264
32265 @subheading The @code{-file-list-exec-source-files} Command
32266 @findex -file-list-exec-source-files
32267
32268 @subsubheading Synopsis
32269
32270 @smallexample
32271  -file-list-exec-source-files
32272 @end smallexample
32273
32274 List the source files for the current executable.
32275
32276 It will always output both the filename and fullname (absolute file
32277 name) of a source file.
32278
32279 @subsubheading @value{GDBN} Command
32280
32281 The @value{GDBN} equivalent is @samp{info sources}.
32282 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
32283
32284 @subsubheading Example
32285 @smallexample
32286 (gdb)
32287 -file-list-exec-source-files
32288 ^done,files=[
32289 @{file=foo.c,fullname=/home/foo.c@},
32290 @{file=/home/bar.c,fullname=/home/bar.c@},
32291 @{file=gdb_could_not_find_fullpath.c@}]
32292 (gdb)
32293 @end smallexample
32294
32295 @ignore
32296 @subheading The @code{-file-list-shared-libraries} Command
32297 @findex -file-list-shared-libraries
32298
32299 @subsubheading Synopsis
32300
32301 @smallexample
32302  -file-list-shared-libraries
32303 @end smallexample
32304
32305 List the shared libraries in the program.
32306
32307 @subsubheading @value{GDBN} Command
32308
32309 The corresponding @value{GDBN} command is @samp{info shared}.
32310
32311 @subsubheading Example
32312 N.A.
32313
32314
32315 @subheading The @code{-file-list-symbol-files} Command
32316 @findex -file-list-symbol-files
32317
32318 @subsubheading Synopsis
32319
32320 @smallexample
32321  -file-list-symbol-files
32322 @end smallexample
32323
32324 List symbol files.
32325
32326 @subsubheading @value{GDBN} Command
32327
32328 The corresponding @value{GDBN} command is @samp{info file} (part of it).
32329
32330 @subsubheading Example
32331 N.A.
32332 @end ignore
32333
32334
32335 @subheading The @code{-file-symbol-file} Command
32336 @findex -file-symbol-file
32337
32338 @subsubheading Synopsis
32339
32340 @smallexample
32341  -file-symbol-file @var{file}
32342 @end smallexample
32343
32344 Read symbol table info from the specified @var{file} argument.  When
32345 used without arguments, clears @value{GDBN}'s symbol table info.  No output is
32346 produced, except for a completion notification.
32347
32348 @subsubheading @value{GDBN} Command
32349
32350 The corresponding @value{GDBN} command is @samp{symbol-file}.
32351
32352 @subsubheading Example
32353
32354 @smallexample
32355 (gdb)
32356 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
32357 ^done
32358 (gdb)
32359 @end smallexample
32360
32361 @ignore
32362 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32363 @node GDB/MI Memory Overlay Commands
32364 @section @sc{gdb/mi} Memory Overlay Commands
32365
32366 The memory overlay commands are not implemented.
32367
32368 @c @subheading -overlay-auto
32369
32370 @c @subheading -overlay-list-mapping-state
32371
32372 @c @subheading -overlay-list-overlays
32373
32374 @c @subheading -overlay-map
32375
32376 @c @subheading -overlay-off
32377
32378 @c @subheading -overlay-on
32379
32380 @c @subheading -overlay-unmap
32381
32382 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32383 @node GDB/MI Signal Handling Commands
32384 @section @sc{gdb/mi} Signal Handling Commands
32385
32386 Signal handling commands are not implemented.
32387
32388 @c @subheading -signal-handle
32389
32390 @c @subheading -signal-list-handle-actions
32391
32392 @c @subheading -signal-list-signal-types
32393 @end ignore
32394
32395
32396 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32397 @node GDB/MI Target Manipulation
32398 @section @sc{gdb/mi} Target Manipulation Commands
32399
32400
32401 @subheading The @code{-target-attach} Command
32402 @findex -target-attach
32403
32404 @subsubheading Synopsis
32405
32406 @smallexample
32407  -target-attach @var{pid} | @var{gid} | @var{file}
32408 @end smallexample
32409
32410 Attach to a process @var{pid} or a file @var{file} outside of
32411 @value{GDBN}, or a thread group @var{gid}.  If attaching to a thread
32412 group, the id previously returned by 
32413 @samp{-list-thread-groups --available} must be used.
32414
32415 @subsubheading @value{GDBN} Command
32416
32417 The corresponding @value{GDBN} command is @samp{attach}.
32418
32419 @subsubheading Example
32420 @smallexample
32421 (gdb)
32422 -target-attach 34
32423 =thread-created,id="1"
32424 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
32425 ^done
32426 (gdb)
32427 @end smallexample
32428
32429 @ignore
32430 @subheading The @code{-target-compare-sections} Command
32431 @findex -target-compare-sections
32432
32433 @subsubheading Synopsis
32434
32435 @smallexample
32436  -target-compare-sections [ @var{section} ]
32437 @end smallexample
32438
32439 Compare data of section @var{section} on target to the exec file.
32440 Without the argument, all sections are compared.
32441
32442 @subsubheading @value{GDBN} Command
32443
32444 The @value{GDBN} equivalent is @samp{compare-sections}.
32445
32446 @subsubheading Example
32447 N.A.
32448 @end ignore
32449
32450
32451 @subheading The @code{-target-detach} Command
32452 @findex -target-detach
32453
32454 @subsubheading Synopsis
32455
32456 @smallexample
32457  -target-detach [ @var{pid} | @var{gid} ]
32458 @end smallexample
32459
32460 Detach from the remote target which normally resumes its execution.
32461 If either @var{pid} or @var{gid} is specified, detaches from either
32462 the specified process, or specified thread group.  There's no output.
32463
32464 @subsubheading @value{GDBN} Command
32465
32466 The corresponding @value{GDBN} command is @samp{detach}.
32467
32468 @subsubheading Example
32469
32470 @smallexample
32471 (gdb)
32472 -target-detach
32473 ^done
32474 (gdb)
32475 @end smallexample
32476
32477
32478 @subheading The @code{-target-disconnect} Command
32479 @findex -target-disconnect
32480
32481 @subsubheading Synopsis
32482
32483 @smallexample
32484  -target-disconnect
32485 @end smallexample
32486
32487 Disconnect from the remote target.  There's no output and the target is
32488 generally not resumed.
32489
32490 @subsubheading @value{GDBN} Command
32491
32492 The corresponding @value{GDBN} command is @samp{disconnect}.
32493
32494 @subsubheading Example
32495
32496 @smallexample
32497 (gdb)
32498 -target-disconnect
32499 ^done
32500 (gdb)
32501 @end smallexample
32502
32503
32504 @subheading The @code{-target-download} Command
32505 @findex -target-download
32506
32507 @subsubheading Synopsis
32508
32509 @smallexample
32510  -target-download
32511 @end smallexample
32512
32513 Loads the executable onto the remote target.
32514 It prints out an update message every half second, which includes the fields:
32515
32516 @table @samp
32517 @item section
32518 The name of the section.
32519 @item section-sent
32520 The size of what has been sent so far for that section.
32521 @item section-size
32522 The size of the section.
32523 @item total-sent
32524 The total size of what was sent so far (the current and the previous sections).
32525 @item total-size
32526 The size of the overall executable to download.
32527 @end table
32528
32529 @noindent
32530 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
32531 @sc{gdb/mi} Output Syntax}).
32532
32533 In addition, it prints the name and size of the sections, as they are
32534 downloaded.  These messages include the following fields:
32535
32536 @table @samp
32537 @item section
32538 The name of the section.
32539 @item section-size
32540 The size of the section.
32541 @item total-size
32542 The size of the overall executable to download.
32543 @end table
32544
32545 @noindent
32546 At the end, a summary is printed.
32547
32548 @subsubheading @value{GDBN} Command
32549
32550 The corresponding @value{GDBN} command is @samp{load}.
32551
32552 @subsubheading Example
32553
32554 Note: each status message appears on a single line.  Here the messages
32555 have been broken down so that they can fit onto a page.
32556
32557 @smallexample
32558 (gdb)
32559 -target-download
32560 +download,@{section=".text",section-size="6668",total-size="9880"@}
32561 +download,@{section=".text",section-sent="512",section-size="6668",
32562 total-sent="512",total-size="9880"@}
32563 +download,@{section=".text",section-sent="1024",section-size="6668",
32564 total-sent="1024",total-size="9880"@}
32565 +download,@{section=".text",section-sent="1536",section-size="6668",
32566 total-sent="1536",total-size="9880"@}
32567 +download,@{section=".text",section-sent="2048",section-size="6668",
32568 total-sent="2048",total-size="9880"@}
32569 +download,@{section=".text",section-sent="2560",section-size="6668",
32570 total-sent="2560",total-size="9880"@}
32571 +download,@{section=".text",section-sent="3072",section-size="6668",
32572 total-sent="3072",total-size="9880"@}
32573 +download,@{section=".text",section-sent="3584",section-size="6668",
32574 total-sent="3584",total-size="9880"@}
32575 +download,@{section=".text",section-sent="4096",section-size="6668",
32576 total-sent="4096",total-size="9880"@}
32577 +download,@{section=".text",section-sent="4608",section-size="6668",
32578 total-sent="4608",total-size="9880"@}
32579 +download,@{section=".text",section-sent="5120",section-size="6668",
32580 total-sent="5120",total-size="9880"@}
32581 +download,@{section=".text",section-sent="5632",section-size="6668",
32582 total-sent="5632",total-size="9880"@}
32583 +download,@{section=".text",section-sent="6144",section-size="6668",
32584 total-sent="6144",total-size="9880"@}
32585 +download,@{section=".text",section-sent="6656",section-size="6668",
32586 total-sent="6656",total-size="9880"@}
32587 +download,@{section=".init",section-size="28",total-size="9880"@}
32588 +download,@{section=".fini",section-size="28",total-size="9880"@}
32589 +download,@{section=".data",section-size="3156",total-size="9880"@}
32590 +download,@{section=".data",section-sent="512",section-size="3156",
32591 total-sent="7236",total-size="9880"@}
32592 +download,@{section=".data",section-sent="1024",section-size="3156",
32593 total-sent="7748",total-size="9880"@}
32594 +download,@{section=".data",section-sent="1536",section-size="3156",
32595 total-sent="8260",total-size="9880"@}
32596 +download,@{section=".data",section-sent="2048",section-size="3156",
32597 total-sent="8772",total-size="9880"@}
32598 +download,@{section=".data",section-sent="2560",section-size="3156",
32599 total-sent="9284",total-size="9880"@}
32600 +download,@{section=".data",section-sent="3072",section-size="3156",
32601 total-sent="9796",total-size="9880"@}
32602 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
32603 write-rate="429"
32604 (gdb)
32605 @end smallexample
32606
32607
32608 @ignore
32609 @subheading The @code{-target-exec-status} Command
32610 @findex -target-exec-status
32611
32612 @subsubheading Synopsis
32613
32614 @smallexample
32615  -target-exec-status
32616 @end smallexample
32617
32618 Provide information on the state of the target (whether it is running or
32619 not, for instance).
32620
32621 @subsubheading @value{GDBN} Command
32622
32623 There's no equivalent @value{GDBN} command.
32624
32625 @subsubheading Example
32626 N.A.
32627
32628
32629 @subheading The @code{-target-list-available-targets} Command
32630 @findex -target-list-available-targets
32631
32632 @subsubheading Synopsis
32633
32634 @smallexample
32635  -target-list-available-targets
32636 @end smallexample
32637
32638 List the possible targets to connect to.
32639
32640 @subsubheading @value{GDBN} Command
32641
32642 The corresponding @value{GDBN} command is @samp{help target}.
32643
32644 @subsubheading Example
32645 N.A.
32646
32647
32648 @subheading The @code{-target-list-current-targets} Command
32649 @findex -target-list-current-targets
32650
32651 @subsubheading Synopsis
32652
32653 @smallexample
32654  -target-list-current-targets
32655 @end smallexample
32656
32657 Describe the current target.
32658
32659 @subsubheading @value{GDBN} Command
32660
32661 The corresponding information is printed by @samp{info file} (among
32662 other things).
32663
32664 @subsubheading Example
32665 N.A.
32666
32667
32668 @subheading The @code{-target-list-parameters} Command
32669 @findex -target-list-parameters
32670
32671 @subsubheading Synopsis
32672
32673 @smallexample
32674  -target-list-parameters
32675 @end smallexample
32676
32677 @c ????
32678 @end ignore
32679
32680 @subsubheading @value{GDBN} Command
32681
32682 No equivalent.
32683
32684 @subsubheading Example
32685 N.A.
32686
32687
32688 @subheading The @code{-target-select} Command
32689 @findex -target-select
32690
32691 @subsubheading Synopsis
32692
32693 @smallexample
32694  -target-select @var{type} @var{parameters @dots{}}
32695 @end smallexample
32696
32697 Connect @value{GDBN} to the remote target.  This command takes two args:
32698
32699 @table @samp
32700 @item @var{type}
32701 The type of target, for instance @samp{remote}, etc.
32702 @item @var{parameters}
32703 Device names, host names and the like.  @xref{Target Commands, ,
32704 Commands for Managing Targets}, for more details.
32705 @end table
32706
32707 The output is a connection notification, followed by the address at
32708 which the target program is, in the following form:
32709
32710 @smallexample
32711 ^connected,addr="@var{address}",func="@var{function name}",
32712   args=[@var{arg list}]
32713 @end smallexample
32714
32715 @subsubheading @value{GDBN} Command
32716
32717 The corresponding @value{GDBN} command is @samp{target}.
32718
32719 @subsubheading Example
32720
32721 @smallexample
32722 (gdb)
32723 -target-select remote /dev/ttya
32724 ^connected,addr="0xfe00a300",func="??",args=[]
32725 (gdb)
32726 @end smallexample
32727
32728 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32729 @node GDB/MI File Transfer Commands
32730 @section @sc{gdb/mi} File Transfer Commands
32731
32732
32733 @subheading The @code{-target-file-put} Command
32734 @findex -target-file-put
32735
32736 @subsubheading Synopsis
32737
32738 @smallexample
32739  -target-file-put @var{hostfile} @var{targetfile}
32740 @end smallexample
32741
32742 Copy file @var{hostfile} from the host system (the machine running
32743 @value{GDBN}) to @var{targetfile} on the target system.
32744
32745 @subsubheading @value{GDBN} Command
32746
32747 The corresponding @value{GDBN} command is @samp{remote put}.
32748
32749 @subsubheading Example
32750
32751 @smallexample
32752 (gdb)
32753 -target-file-put localfile remotefile
32754 ^done
32755 (gdb)
32756 @end smallexample
32757
32758
32759 @subheading The @code{-target-file-get} Command
32760 @findex -target-file-get
32761
32762 @subsubheading Synopsis
32763
32764 @smallexample
32765  -target-file-get @var{targetfile} @var{hostfile}
32766 @end smallexample
32767
32768 Copy file @var{targetfile} from the target system to @var{hostfile}
32769 on the host system.
32770
32771 @subsubheading @value{GDBN} Command
32772
32773 The corresponding @value{GDBN} command is @samp{remote get}.
32774
32775 @subsubheading Example
32776
32777 @smallexample
32778 (gdb)
32779 -target-file-get remotefile localfile
32780 ^done
32781 (gdb)
32782 @end smallexample
32783
32784
32785 @subheading The @code{-target-file-delete} Command
32786 @findex -target-file-delete
32787
32788 @subsubheading Synopsis
32789
32790 @smallexample
32791  -target-file-delete @var{targetfile}
32792 @end smallexample
32793
32794 Delete @var{targetfile} from the target system.
32795
32796 @subsubheading @value{GDBN} Command
32797
32798 The corresponding @value{GDBN} command is @samp{remote delete}.
32799
32800 @subsubheading Example
32801
32802 @smallexample
32803 (gdb)
32804 -target-file-delete remotefile
32805 ^done
32806 (gdb)
32807 @end smallexample
32808
32809
32810 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32811 @node GDB/MI Miscellaneous Commands
32812 @section Miscellaneous @sc{gdb/mi} Commands
32813
32814 @c @subheading -gdb-complete
32815
32816 @subheading The @code{-gdb-exit} Command
32817 @findex -gdb-exit
32818
32819 @subsubheading Synopsis
32820
32821 @smallexample
32822  -gdb-exit
32823 @end smallexample
32824
32825 Exit @value{GDBN} immediately.
32826
32827 @subsubheading @value{GDBN} Command
32828
32829 Approximately corresponds to @samp{quit}.
32830
32831 @subsubheading Example
32832
32833 @smallexample
32834 (gdb)
32835 -gdb-exit
32836 ^exit
32837 @end smallexample
32838
32839
32840 @ignore
32841 @subheading The @code{-exec-abort} Command
32842 @findex -exec-abort
32843
32844 @subsubheading Synopsis
32845
32846 @smallexample
32847  -exec-abort
32848 @end smallexample
32849
32850 Kill the inferior running program.
32851
32852 @subsubheading @value{GDBN} Command
32853
32854 The corresponding @value{GDBN} command is @samp{kill}.
32855
32856 @subsubheading Example
32857 N.A.
32858 @end ignore
32859
32860
32861 @subheading The @code{-gdb-set} Command
32862 @findex -gdb-set
32863
32864 @subsubheading Synopsis
32865
32866 @smallexample
32867  -gdb-set
32868 @end smallexample
32869
32870 Set an internal @value{GDBN} variable.
32871 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
32872
32873 @subsubheading @value{GDBN} Command
32874
32875 The corresponding @value{GDBN} command is @samp{set}.
32876
32877 @subsubheading Example
32878
32879 @smallexample
32880 (gdb)
32881 -gdb-set $foo=3
32882 ^done
32883 (gdb)
32884 @end smallexample
32885
32886
32887 @subheading The @code{-gdb-show} Command
32888 @findex -gdb-show
32889
32890 @subsubheading Synopsis
32891
32892 @smallexample
32893  -gdb-show
32894 @end smallexample
32895
32896 Show the current value of a @value{GDBN} variable.
32897
32898 @subsubheading @value{GDBN} Command
32899
32900 The corresponding @value{GDBN} command is @samp{show}.
32901
32902 @subsubheading Example
32903
32904 @smallexample
32905 (gdb)
32906 -gdb-show annotate
32907 ^done,value="0"
32908 (gdb)
32909 @end smallexample
32910
32911 @c @subheading -gdb-source
32912
32913
32914 @subheading The @code{-gdb-version} Command
32915 @findex -gdb-version
32916
32917 @subsubheading Synopsis
32918
32919 @smallexample
32920  -gdb-version
32921 @end smallexample
32922
32923 Show version information for @value{GDBN}.  Used mostly in testing.
32924
32925 @subsubheading @value{GDBN} Command
32926
32927 The @value{GDBN} equivalent is @samp{show version}.  @value{GDBN} by
32928 default shows this information when you start an interactive session.
32929
32930 @subsubheading Example
32931
32932 @c This example modifies the actual output from GDB to avoid overfull
32933 @c box in TeX.
32934 @smallexample
32935 (gdb)
32936 -gdb-version
32937 ~GNU gdb 5.2.1
32938 ~Copyright 2000 Free Software Foundation, Inc.
32939 ~GDB is free software, covered by the GNU General Public License, and
32940 ~you are welcome to change it and/or distribute copies of it under
32941 ~ certain conditions.
32942 ~Type "show copying" to see the conditions.
32943 ~There is absolutely no warranty for GDB.  Type "show warranty" for
32944 ~ details.
32945 ~This GDB was configured as
32946  "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
32947 ^done
32948 (gdb)
32949 @end smallexample
32950
32951 @subheading The @code{-list-features} Command
32952 @findex -list-features
32953
32954 Returns a list of particular features of the MI protocol that
32955 this version of gdb implements.  A feature can be a command,
32956 or a new field in an output of some command, or even an
32957 important bugfix.  While a frontend can sometimes detect presence
32958 of a feature at runtime, it is easier to perform detection at debugger
32959 startup. 
32960
32961 The command returns a list of strings, with each string naming an
32962 available feature.  Each returned string is just a name, it does not
32963 have any internal structure.  The list of possible feature names 
32964 is given below.
32965
32966 Example output:
32967
32968 @smallexample
32969 (gdb) -list-features
32970 ^done,result=["feature1","feature2"]
32971 @end smallexample
32972
32973 The current list of features is:
32974
32975 @table @samp
32976 @item frozen-varobjs
32977 Indicates support for the @code{-var-set-frozen} command, as well
32978 as possible presense of the @code{frozen} field in the output
32979 of @code{-varobj-create}.
32980 @item pending-breakpoints
32981 Indicates support for the @option{-f} option to the @code{-break-insert}
32982 command.
32983 @item python
32984 Indicates Python scripting support, Python-based
32985 pretty-printing commands, and possible presence of the
32986 @samp{display_hint} field in the output of @code{-var-list-children}
32987 @item thread-info
32988 Indicates support for the @code{-thread-info} command.
32989 @item data-read-memory-bytes
32990 Indicates support for the @code{-data-read-memory-bytes} and the
32991 @code{-data-write-memory-bytes} commands.
32992 @item breakpoint-notifications
32993 Indicates that changes to breakpoints and breakpoints created via the
32994 CLI will be announced via async records.
32995 @item ada-task-info
32996 Indicates support for the @code{-ada-task-info} command.
32997 @end table
32998
32999 @subheading The @code{-list-target-features} Command
33000 @findex -list-target-features
33001
33002 Returns a list of particular features that are supported by the
33003 target.  Those features affect the permitted MI commands, but 
33004 unlike the features reported by the @code{-list-features} command, the
33005 features depend on which target GDB is using at the moment.  Whenever
33006 a target can change, due to commands such as @code{-target-select},
33007 @code{-target-attach} or @code{-exec-run}, the list of target features
33008 may change, and the frontend should obtain it again.
33009 Example output:
33010
33011 @smallexample
33012 (gdb) -list-features
33013 ^done,result=["async"]
33014 @end smallexample
33015
33016 The current list of features is:
33017
33018 @table @samp
33019 @item async
33020 Indicates that the target is capable of asynchronous command
33021 execution, which means that @value{GDBN} will accept further commands
33022 while the target is running.
33023
33024 @item reverse
33025 Indicates that the target is capable of reverse execution.
33026 @xref{Reverse Execution}, for more information.
33027
33028 @end table
33029
33030 @subheading The @code{-list-thread-groups} Command
33031 @findex -list-thread-groups
33032
33033 @subheading Synopsis
33034
33035 @smallexample
33036 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
33037 @end smallexample
33038
33039 Lists thread groups (@pxref{Thread groups}).  When a single thread
33040 group is passed as the argument, lists the children of that group.
33041 When several thread group are passed, lists information about those
33042 thread groups.  Without any parameters, lists information about all
33043 top-level thread groups.
33044
33045 Normally, thread groups that are being debugged are reported.
33046 With the @samp{--available} option, @value{GDBN} reports thread groups
33047 available on the target.
33048
33049 The output of this command may have either a @samp{threads} result or
33050 a @samp{groups} result.  The @samp{thread} result has a list of tuples
33051 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
33052 Information}).  The @samp{groups} result has a list of tuples as value,
33053 each tuple describing a thread group.  If top-level groups are
33054 requested (that is, no parameter is passed), or when several groups
33055 are passed, the output always has a @samp{groups} result.  The format
33056 of the @samp{group} result is described below.
33057
33058 To reduce the number of roundtrips it's possible to list thread groups
33059 together with their children, by passing the @samp{--recurse} option
33060 and the recursion depth.  Presently, only recursion depth of 1 is
33061 permitted.  If this option is present, then every reported thread group
33062 will also include its children, either as @samp{group} or
33063 @samp{threads} field.
33064
33065 In general, any combination of option and parameters is permitted, with
33066 the following caveats:
33067
33068 @itemize @bullet
33069 @item
33070 When a single thread group is passed, the output will typically
33071 be the @samp{threads} result.  Because threads may not contain
33072 anything, the @samp{recurse} option will be ignored.
33073
33074 @item
33075 When the @samp{--available} option is passed, limited information may
33076 be available.  In particular, the list of threads of a process might
33077 be inaccessible.  Further, specifying specific thread groups might
33078 not give any performance advantage over listing all thread groups.
33079 The frontend should assume that @samp{-list-thread-groups --available}
33080 is always an expensive operation and cache the results.
33081
33082 @end itemize
33083
33084 The @samp{groups} result is a list of tuples, where each tuple may
33085 have the following fields:
33086
33087 @table @code
33088 @item id
33089 Identifier of the thread group.  This field is always present.
33090 The identifier is an opaque string; frontends should not try to
33091 convert it to an integer, even though it might look like one.
33092
33093 @item type
33094 The type of the thread group.  At present, only @samp{process} is a
33095 valid type.
33096
33097 @item pid
33098 The target-specific process identifier.  This field is only present
33099 for thread groups of type @samp{process} and only if the process exists.
33100
33101 @item num_children
33102 The number of children this thread group has.  This field may be
33103 absent for an available thread group.
33104
33105 @item threads
33106 This field has a list of tuples as value, each tuple describing a
33107 thread.  It may be present if the @samp{--recurse} option is
33108 specified, and it's actually possible to obtain the threads.
33109
33110 @item cores
33111 This field is a list of integers, each identifying a core that one
33112 thread of the group is running on.  This field may be absent if
33113 such information is not available.
33114
33115 @item executable
33116 The name of the executable file that corresponds to this thread group.
33117 The field is only present for thread groups of type @samp{process},
33118 and only if there is a corresponding executable file.
33119
33120 @end table
33121
33122 @subheading Example
33123
33124 @smallexample
33125 @value{GDBP}
33126 -list-thread-groups
33127 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
33128 -list-thread-groups 17
33129 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
33130    frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
33131 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
33132    frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
33133            file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
33134 -list-thread-groups --available
33135 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
33136 -list-thread-groups --available --recurse 1
33137  ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33138                 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33139                          @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
33140 -list-thread-groups --available --recurse 1 17 18
33141 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
33142                threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
33143                         @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
33144 @end smallexample
33145
33146 @subheading The @code{-info-os} Command
33147 @findex -info-os
33148
33149 @subsubheading Synopsis
33150
33151 @smallexample
33152 -info-os [ @var{type} ]
33153 @end smallexample
33154
33155 If no argument is supplied, the command returns a table of available
33156 operating-system-specific information types.  If one of these types is
33157 supplied as an argument @var{type}, then the command returns a table
33158 of data of that type.
33159
33160 The types of information available depend on the target operating
33161 system.
33162
33163 @subsubheading @value{GDBN} Command
33164
33165 The corresponding @value{GDBN} command is @samp{info os}.
33166
33167 @subsubheading Example
33168
33169 When run on a @sc{gnu}/Linux system, the output will look something
33170 like this:
33171
33172 @smallexample
33173 @value{GDBP}
33174 -info-os
33175 ^done,OSDataTable=@{nr_rows="9",nr_cols="3",
33176 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
33177      @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
33178      @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
33179 body=[item=@{col0="processes",col1="Listing of all processes",
33180             col2="Processes"@},
33181       item=@{col0="procgroups",col1="Listing of all process groups",
33182             col2="Process groups"@},
33183       item=@{col0="threads",col1="Listing of all threads",
33184             col2="Threads"@},
33185       item=@{col0="files",col1="Listing of all file descriptors",
33186             col2="File descriptors"@},
33187       item=@{col0="sockets",col1="Listing of all internet-domain sockets",
33188             col2="Sockets"@},
33189       item=@{col0="shm",col1="Listing of all shared-memory regions",
33190             col2="Shared-memory regions"@},
33191       item=@{col0="semaphores",col1="Listing of all semaphores",
33192             col2="Semaphores"@},
33193       item=@{col0="msg",col1="Listing of all message queues",
33194             col2="Message queues"@},
33195       item=@{col0="modules",col1="Listing of all loaded kernel modules",
33196             col2="Kernel modules"@}]@}
33197 @value{GDBP}
33198 -info-os processes
33199 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
33200 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
33201      @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
33202      @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
33203      @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
33204 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
33205       item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
33206       item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
33207       ...
33208       item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
33209       item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
33210 (gdb)
33211 @end smallexample
33212
33213 (Note that the MI output here includes a @code{"Title"} column that
33214 does not appear in command-line @code{info os}; this column is useful
33215 for MI clients that want to enumerate the types of data, such as in a
33216 popup menu, but is needless clutter on the command line, and
33217 @code{info os} omits it.)
33218
33219 @subheading The @code{-add-inferior} Command
33220 @findex -add-inferior
33221
33222 @subheading Synopsis
33223
33224 @smallexample
33225 -add-inferior
33226 @end smallexample
33227
33228 Creates a new inferior (@pxref{Inferiors and Programs}).  The created
33229 inferior is not associated with any executable.  Such association may
33230 be established with the @samp{-file-exec-and-symbols} command
33231 (@pxref{GDB/MI File Commands}).  The command response has a single
33232 field, @samp{thread-group}, whose value is the identifier of the
33233 thread group corresponding to the new inferior.
33234
33235 @subheading Example
33236
33237 @smallexample
33238 @value{GDBP}
33239 -add-inferior
33240 ^done,thread-group="i3"
33241 @end smallexample
33242
33243 @subheading The @code{-interpreter-exec} Command
33244 @findex -interpreter-exec
33245
33246 @subheading Synopsis
33247
33248 @smallexample
33249 -interpreter-exec @var{interpreter} @var{command}
33250 @end smallexample
33251 @anchor{-interpreter-exec} 
33252
33253 Execute the specified @var{command} in the given @var{interpreter}.
33254
33255 @subheading @value{GDBN} Command
33256
33257 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
33258
33259 @subheading Example
33260
33261 @smallexample
33262 (gdb)
33263 -interpreter-exec console "break main"
33264 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
33265 &"During symbol reading, bad structure-type format.\n"
33266 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
33267 ^done
33268 (gdb)
33269 @end smallexample
33270
33271 @subheading The @code{-inferior-tty-set} Command
33272 @findex -inferior-tty-set
33273
33274 @subheading Synopsis
33275
33276 @smallexample
33277 -inferior-tty-set /dev/pts/1
33278 @end smallexample
33279
33280 Set terminal for future runs of the program being debugged.
33281
33282 @subheading @value{GDBN} Command
33283
33284 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
33285
33286 @subheading Example
33287
33288 @smallexample
33289 (gdb)
33290 -inferior-tty-set /dev/pts/1
33291 ^done
33292 (gdb)
33293 @end smallexample
33294
33295 @subheading The @code{-inferior-tty-show} Command
33296 @findex -inferior-tty-show
33297
33298 @subheading Synopsis
33299
33300 @smallexample
33301 -inferior-tty-show
33302 @end smallexample
33303
33304 Show terminal for future runs of program being debugged.
33305
33306 @subheading @value{GDBN} Command
33307
33308 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
33309
33310 @subheading Example
33311
33312 @smallexample
33313 (gdb)
33314 -inferior-tty-set /dev/pts/1
33315 ^done
33316 (gdb)
33317 -inferior-tty-show
33318 ^done,inferior_tty_terminal="/dev/pts/1"
33319 (gdb)
33320 @end smallexample
33321
33322 @subheading The @code{-enable-timings} Command
33323 @findex -enable-timings
33324
33325 @subheading Synopsis
33326
33327 @smallexample
33328 -enable-timings [yes | no]
33329 @end smallexample
33330
33331 Toggle the printing of the wallclock, user and system times for an MI
33332 command as a field in its output.  This command is to help frontend
33333 developers optimize the performance of their code.  No argument is
33334 equivalent to @samp{yes}.
33335
33336 @subheading @value{GDBN} Command
33337
33338 No equivalent.
33339
33340 @subheading Example
33341
33342 @smallexample
33343 (gdb)
33344 -enable-timings
33345 ^done
33346 (gdb)
33347 -break-insert main
33348 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
33349 addr="0x080484ed",func="main",file="myprog.c",
33350 fullname="/home/nickrob/myprog.c",line="73",times="0"@},
33351 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
33352 (gdb)
33353 -enable-timings no
33354 ^done
33355 (gdb)
33356 -exec-run
33357 ^running
33358 (gdb)
33359 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
33360 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
33361 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
33362 fullname="/home/nickrob/myprog.c",line="73"@}
33363 (gdb)
33364 @end smallexample
33365
33366 @node Annotations
33367 @chapter @value{GDBN} Annotations
33368
33369 This chapter describes annotations in @value{GDBN}.  Annotations were
33370 designed to interface @value{GDBN} to graphical user interfaces or other
33371 similar programs which want to interact with @value{GDBN} at a
33372 relatively high level.
33373
33374 The annotation mechanism has largely been superseded by @sc{gdb/mi}
33375 (@pxref{GDB/MI}).
33376
33377 @ignore
33378 This is Edition @value{EDITION}, @value{DATE}.
33379 @end ignore
33380
33381 @menu
33382 * Annotations Overview::  What annotations are; the general syntax.
33383 * Server Prefix::       Issuing a command without affecting user state.
33384 * Prompting::           Annotations marking @value{GDBN}'s need for input.
33385 * Errors::              Annotations for error messages.
33386 * Invalidation::        Some annotations describe things now invalid.
33387 * Annotations for Running::
33388                         Whether the program is running, how it stopped, etc.
33389 * Source Annotations::  Annotations describing source code.
33390 @end menu
33391
33392 @node Annotations Overview
33393 @section What is an Annotation?
33394 @cindex annotations
33395
33396 Annotations start with a newline character, two @samp{control-z}
33397 characters, and the name of the annotation.  If there is no additional
33398 information associated with this annotation, the name of the annotation
33399 is followed immediately by a newline.  If there is additional
33400 information, the name of the annotation is followed by a space, the
33401 additional information, and a newline.  The additional information
33402 cannot contain newline characters.
33403
33404 Any output not beginning with a newline and two @samp{control-z}
33405 characters denotes literal output from @value{GDBN}.  Currently there is
33406 no need for @value{GDBN} to output a newline followed by two
33407 @samp{control-z} characters, but if there was such a need, the
33408 annotations could be extended with an @samp{escape} annotation which
33409 means those three characters as output.
33410
33411 The annotation @var{level}, which is specified using the
33412 @option{--annotate} command line option (@pxref{Mode Options}), controls
33413 how much information @value{GDBN} prints together with its prompt,
33414 values of expressions, source lines, and other types of output.  Level 0
33415 is for no annotations, level 1 is for use when @value{GDBN} is run as a
33416 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
33417 for programs that control @value{GDBN}, and level 2 annotations have
33418 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
33419 Interface, annotate, GDB's Obsolete Annotations}).
33420
33421 @table @code
33422 @kindex set annotate
33423 @item set annotate @var{level}
33424 The @value{GDBN} command @code{set annotate} sets the level of
33425 annotations to the specified @var{level}.
33426
33427 @item show annotate
33428 @kindex show annotate
33429 Show the current annotation level.
33430 @end table
33431
33432 This chapter describes level 3 annotations.
33433
33434 A simple example of starting up @value{GDBN} with annotations is:
33435
33436 @smallexample
33437 $ @kbd{gdb --annotate=3}
33438 GNU gdb 6.0
33439 Copyright 2003 Free Software Foundation, Inc.
33440 GDB is free software, covered by the GNU General Public License,
33441 and you are welcome to change it and/or distribute copies of it
33442 under certain conditions.
33443 Type "show copying" to see the conditions.
33444 There is absolutely no warranty for GDB.  Type "show warranty"
33445 for details.
33446 This GDB was configured as "i386-pc-linux-gnu"
33447
33448 ^Z^Zpre-prompt
33449 (@value{GDBP})
33450 ^Z^Zprompt
33451 @kbd{quit}
33452
33453 ^Z^Zpost-prompt
33454 $
33455 @end smallexample
33456
33457 Here @samp{quit} is input to @value{GDBN}; the rest is output from
33458 @value{GDBN}.  The three lines beginning @samp{^Z^Z} (where @samp{^Z}
33459 denotes a @samp{control-z} character) are annotations; the rest is
33460 output from @value{GDBN}.
33461
33462 @node Server Prefix
33463 @section The Server Prefix
33464 @cindex server prefix
33465
33466 If you prefix a command with @samp{server } then it will not affect
33467 the command history, nor will it affect @value{GDBN}'s notion of which
33468 command to repeat if @key{RET} is pressed on a line by itself.  This
33469 means that commands can be run behind a user's back by a front-end in
33470 a transparent manner.
33471
33472 The @code{server } prefix does not affect the recording of values into
33473 the value history; to print a value without recording it into the
33474 value history, use the @code{output} command instead of the
33475 @code{print} command.
33476
33477 Using this prefix also disables confirmation requests
33478 (@pxref{confirmation requests}).
33479
33480 @node Prompting
33481 @section Annotation for @value{GDBN} Input
33482
33483 @cindex annotations for prompts
33484 When @value{GDBN} prompts for input, it annotates this fact so it is possible
33485 to know when to send output, when the output from a given command is
33486 over, etc.
33487
33488 Different kinds of input each have a different @dfn{input type}.  Each
33489 input type has three annotations: a @code{pre-} annotation, which
33490 denotes the beginning of any prompt which is being output, a plain
33491 annotation, which denotes the end of the prompt, and then a @code{post-}
33492 annotation which denotes the end of any echo which may (or may not) be
33493 associated with the input.  For example, the @code{prompt} input type
33494 features the following annotations:
33495
33496 @smallexample
33497 ^Z^Zpre-prompt
33498 ^Z^Zprompt
33499 ^Z^Zpost-prompt
33500 @end smallexample
33501
33502 The input types are
33503
33504 @table @code
33505 @findex pre-prompt annotation
33506 @findex prompt annotation
33507 @findex post-prompt annotation
33508 @item prompt
33509 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
33510
33511 @findex pre-commands annotation
33512 @findex commands annotation
33513 @findex post-commands annotation
33514 @item commands
33515 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
33516 command.  The annotations are repeated for each command which is input.
33517
33518 @findex pre-overload-choice annotation
33519 @findex overload-choice annotation
33520 @findex post-overload-choice annotation
33521 @item overload-choice
33522 When @value{GDBN} wants the user to select between various overloaded functions.
33523
33524 @findex pre-query annotation
33525 @findex query annotation
33526 @findex post-query annotation
33527 @item query
33528 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
33529
33530 @findex pre-prompt-for-continue annotation
33531 @findex prompt-for-continue annotation
33532 @findex post-prompt-for-continue annotation
33533 @item prompt-for-continue
33534 When @value{GDBN} is asking the user to press return to continue.  Note: Don't
33535 expect this to work well; instead use @code{set height 0} to disable
33536 prompting.  This is because the counting of lines is buggy in the
33537 presence of annotations.
33538 @end table
33539
33540 @node Errors
33541 @section Errors
33542 @cindex annotations for errors, warnings and interrupts
33543
33544 @findex quit annotation
33545 @smallexample
33546 ^Z^Zquit
33547 @end smallexample
33548
33549 This annotation occurs right before @value{GDBN} responds to an interrupt.
33550
33551 @findex error annotation
33552 @smallexample
33553 ^Z^Zerror
33554 @end smallexample
33555
33556 This annotation occurs right before @value{GDBN} responds to an error.
33557
33558 Quit and error annotations indicate that any annotations which @value{GDBN} was
33559 in the middle of may end abruptly.  For example, if a
33560 @code{value-history-begin} annotation is followed by a @code{error}, one
33561 cannot expect to receive the matching @code{value-history-end}.  One
33562 cannot expect not to receive it either, however; an error annotation
33563 does not necessarily mean that @value{GDBN} is immediately returning all the way
33564 to the top level.
33565
33566 @findex error-begin annotation
33567 A quit or error annotation may be preceded by
33568
33569 @smallexample
33570 ^Z^Zerror-begin
33571 @end smallexample
33572
33573 Any output between that and the quit or error annotation is the error
33574 message.
33575
33576 Warning messages are not yet annotated.
33577 @c If we want to change that, need to fix warning(), type_error(),
33578 @c range_error(), and possibly other places.
33579
33580 @node Invalidation
33581 @section Invalidation Notices
33582
33583 @cindex annotations for invalidation messages
33584 The following annotations say that certain pieces of state may have
33585 changed.
33586
33587 @table @code
33588 @findex frames-invalid annotation
33589 @item ^Z^Zframes-invalid
33590
33591 The frames (for example, output from the @code{backtrace} command) may
33592 have changed.
33593
33594 @findex breakpoints-invalid annotation
33595 @item ^Z^Zbreakpoints-invalid
33596
33597 The breakpoints may have changed.  For example, the user just added or
33598 deleted a breakpoint.
33599 @end table
33600
33601 @node Annotations for Running
33602 @section Running the Program
33603 @cindex annotations for running programs
33604
33605 @findex starting annotation
33606 @findex stopping annotation
33607 When the program starts executing due to a @value{GDBN} command such as
33608 @code{step} or @code{continue},
33609
33610 @smallexample
33611 ^Z^Zstarting
33612 @end smallexample
33613
33614 is output.  When the program stops,
33615
33616 @smallexample
33617 ^Z^Zstopped
33618 @end smallexample
33619
33620 is output.  Before the @code{stopped} annotation, a variety of
33621 annotations describe how the program stopped.
33622
33623 @table @code
33624 @findex exited annotation
33625 @item ^Z^Zexited @var{exit-status}
33626 The program exited, and @var{exit-status} is the exit status (zero for
33627 successful exit, otherwise nonzero).
33628
33629 @findex signalled annotation
33630 @findex signal-name annotation
33631 @findex signal-name-end annotation
33632 @findex signal-string annotation
33633 @findex signal-string-end annotation
33634 @item ^Z^Zsignalled
33635 The program exited with a signal.  After the @code{^Z^Zsignalled}, the
33636 annotation continues:
33637
33638 @smallexample
33639 @var{intro-text}
33640 ^Z^Zsignal-name
33641 @var{name}
33642 ^Z^Zsignal-name-end
33643 @var{middle-text}
33644 ^Z^Zsignal-string
33645 @var{string}
33646 ^Z^Zsignal-string-end
33647 @var{end-text}
33648 @end smallexample
33649
33650 @noindent
33651 where @var{name} is the name of the signal, such as @code{SIGILL} or
33652 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
33653 as @code{Illegal Instruction} or @code{Segmentation fault}.
33654 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
33655 user's benefit and have no particular format.
33656
33657 @findex signal annotation
33658 @item ^Z^Zsignal
33659 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
33660 just saying that the program received the signal, not that it was
33661 terminated with it.
33662
33663 @findex breakpoint annotation
33664 @item ^Z^Zbreakpoint @var{number}
33665 The program hit breakpoint number @var{number}.
33666
33667 @findex watchpoint annotation
33668 @item ^Z^Zwatchpoint @var{number}
33669 The program hit watchpoint number @var{number}.
33670 @end table
33671
33672 @node Source Annotations
33673 @section Displaying Source
33674 @cindex annotations for source display
33675
33676 @findex source annotation
33677 The following annotation is used instead of displaying source code:
33678
33679 @smallexample
33680 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
33681 @end smallexample
33682
33683 where @var{filename} is an absolute file name indicating which source
33684 file, @var{line} is the line number within that file (where 1 is the
33685 first line in the file), @var{character} is the character position
33686 within the file (where 0 is the first character in the file) (for most
33687 debug formats this will necessarily point to the beginning of a line),
33688 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
33689 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
33690 @var{addr} is the address in the target program associated with the
33691 source which is being displayed.  @var{addr} is in the form @samp{0x}
33692 followed by one or more lowercase hex digits (note that this does not
33693 depend on the language).
33694
33695 @node JIT Interface
33696 @chapter JIT Compilation Interface
33697 @cindex just-in-time compilation
33698 @cindex JIT compilation interface
33699
33700 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
33701 interface.  A JIT compiler is a program or library that generates native
33702 executable code at runtime and executes it, usually in order to achieve good
33703 performance while maintaining platform independence. 
33704
33705 Programs that use JIT compilation are normally difficult to debug because
33706 portions of their code are generated at runtime, instead of being loaded from
33707 object files, which is where @value{GDBN} normally finds the program's symbols
33708 and debug information.  In order to debug programs that use JIT compilation,
33709 @value{GDBN} has an interface that allows the program to register in-memory
33710 symbol files with @value{GDBN} at runtime.
33711
33712 If you are using @value{GDBN} to debug a program that uses this interface, then
33713 it should work transparently so long as you have not stripped the binary.  If
33714 you are developing a JIT compiler, then the interface is documented in the rest
33715 of this chapter.  At this time, the only known client of this interface is the
33716 LLVM JIT.
33717
33718 Broadly speaking, the JIT interface mirrors the dynamic loader interface.  The
33719 JIT compiler communicates with @value{GDBN} by writing data into a global
33720 variable and calling a fuction at a well-known symbol.  When @value{GDBN}
33721 attaches, it reads a linked list of symbol files from the global variable to
33722 find existing code, and puts a breakpoint in the function so that it can find
33723 out about additional code.
33724
33725 @menu
33726 * Declarations::                Relevant C struct declarations
33727 * Registering Code::            Steps to register code
33728 * Unregistering Code::          Steps to unregister code
33729 * Custom Debug Info::           Emit debug information in a custom format
33730 @end menu
33731
33732 @node Declarations
33733 @section JIT Declarations
33734
33735 These are the relevant struct declarations that a C program should include to
33736 implement the interface:
33737
33738 @smallexample
33739 typedef enum
33740 @{
33741   JIT_NOACTION = 0,
33742   JIT_REGISTER_FN,
33743   JIT_UNREGISTER_FN
33744 @} jit_actions_t;
33745
33746 struct jit_code_entry
33747 @{
33748   struct jit_code_entry *next_entry;
33749   struct jit_code_entry *prev_entry;
33750   const char *symfile_addr;
33751   uint64_t symfile_size;
33752 @};
33753
33754 struct jit_descriptor
33755 @{
33756   uint32_t version;
33757   /* This type should be jit_actions_t, but we use uint32_t
33758      to be explicit about the bitwidth.  */
33759   uint32_t action_flag;
33760   struct jit_code_entry *relevant_entry;
33761   struct jit_code_entry *first_entry;
33762 @};
33763
33764 /* GDB puts a breakpoint in this function.  */
33765 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
33766
33767 /* Make sure to specify the version statically, because the
33768    debugger may check the version before we can set it.  */
33769 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
33770 @end smallexample
33771
33772 If the JIT is multi-threaded, then it is important that the JIT synchronize any
33773 modifications to this global data properly, which can easily be done by putting
33774 a global mutex around modifications to these structures.
33775
33776 @node Registering Code
33777 @section Registering Code
33778
33779 To register code with @value{GDBN}, the JIT should follow this protocol:
33780
33781 @itemize @bullet
33782 @item
33783 Generate an object file in memory with symbols and other desired debug
33784 information.  The file must include the virtual addresses of the sections.
33785
33786 @item
33787 Create a code entry for the file, which gives the start and size of the symbol
33788 file.
33789
33790 @item
33791 Add it to the linked list in the JIT descriptor.
33792
33793 @item
33794 Point the relevant_entry field of the descriptor at the entry.
33795
33796 @item
33797 Set @code{action_flag} to @code{JIT_REGISTER} and call
33798 @code{__jit_debug_register_code}.
33799 @end itemize
33800
33801 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
33802 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
33803 new code.  However, the linked list must still be maintained in order to allow
33804 @value{GDBN} to attach to a running process and still find the symbol files.
33805
33806 @node Unregistering Code
33807 @section Unregistering Code
33808
33809 If code is freed, then the JIT should use the following protocol:
33810
33811 @itemize @bullet
33812 @item
33813 Remove the code entry corresponding to the code from the linked list.
33814
33815 @item
33816 Point the @code{relevant_entry} field of the descriptor at the code entry.
33817
33818 @item
33819 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
33820 @code{__jit_debug_register_code}.
33821 @end itemize
33822
33823 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
33824 and the JIT will leak the memory used for the associated symbol files.
33825
33826 @node Custom Debug Info
33827 @section Custom Debug Info
33828 @cindex custom JIT debug info
33829 @cindex JIT debug info reader
33830
33831 Generating debug information in platform-native file formats (like ELF
33832 or COFF) may be an overkill for JIT compilers; especially if all the
33833 debug info is used for is displaying a meaningful backtrace.  The
33834 issue can be resolved by having the JIT writers decide on a debug info
33835 format and also provide a reader that parses the debug info generated
33836 by the JIT compiler.  This section gives a brief overview on writing
33837 such a parser.  More specific details can be found in the source file
33838 @file{gdb/jit-reader.in}, which is also installed as a header at
33839 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
33840
33841 The reader is implemented as a shared object (so this functionality is
33842 not available on platforms which don't allow loading shared objects at
33843 runtime).  Two @value{GDBN} commands, @code{jit-reader-load} and
33844 @code{jit-reader-unload} are provided, to be used to load and unload
33845 the readers from a preconfigured directory.  Once loaded, the shared
33846 object is used the parse the debug information emitted by the JIT
33847 compiler.
33848
33849 @menu
33850 * Using JIT Debug Info Readers::       How to use supplied readers correctly
33851 * Writing JIT Debug Info Readers::     Creating a debug-info reader
33852 @end menu
33853
33854 @node Using JIT Debug Info Readers
33855 @subsection Using JIT Debug Info Readers
33856 @kindex jit-reader-load
33857 @kindex jit-reader-unload
33858
33859 Readers can be loaded and unloaded using the @code{jit-reader-load}
33860 and @code{jit-reader-unload} commands.
33861
33862 @table @code
33863 @item jit-reader-load @var{reader-name}
33864 Load the JIT reader named @var{reader-name}.  On a UNIX system, this
33865 will usually load @file{@var{libdir}/gdb/@var{reader-name}}, where
33866 @var{libdir} is the system library directory, usually
33867 @file{/usr/local/lib}.  Only one reader can be active at a time;
33868 trying to load a second reader when one is already loaded will result
33869 in @value{GDBN} reporting an error.  A new JIT reader can be loaded by
33870 first unloading the current one using @code{jit-reader-load} and then
33871 invoking @code{jit-reader-load}.
33872
33873 @item jit-reader-unload
33874 Unload the currently loaded JIT reader.
33875
33876 @end table
33877
33878 @node Writing JIT Debug Info Readers
33879 @subsection Writing JIT Debug Info Readers
33880 @cindex writing JIT debug info readers
33881
33882 As mentioned, a reader is essentially a shared object conforming to a
33883 certain ABI.  This ABI is described in @file{jit-reader.h}.
33884
33885 @file{jit-reader.h} defines the structures, macros and functions
33886 required to write a reader.  It is installed (along with
33887 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
33888 the system include directory.
33889
33890 Readers need to be released under a GPL compatible license.  A reader
33891 can be declared as released under such a license by placing the macro
33892 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
33893
33894 The entry point for readers is the symbol @code{gdb_init_reader},
33895 which is expected to be a function with the prototype
33896
33897 @findex gdb_init_reader
33898 @smallexample
33899 extern struct gdb_reader_funcs *gdb_init_reader (void);
33900 @end smallexample
33901
33902 @cindex @code{struct gdb_reader_funcs}
33903
33904 @code{struct gdb_reader_funcs} contains a set of pointers to callback
33905 functions.  These functions are executed to read the debug info
33906 generated by the JIT compiler (@code{read}), to unwind stack frames
33907 (@code{unwind}) and to create canonical frame IDs
33908 (@code{get_Frame_id}).  It also has a callback that is called when the
33909 reader is being unloaded (@code{destroy}).  The struct looks like this
33910
33911 @smallexample
33912 struct gdb_reader_funcs
33913 @{
33914   /* Must be set to GDB_READER_INTERFACE_VERSION.  */
33915   int reader_version;
33916
33917   /* For use by the reader.  */
33918   void *priv_data;
33919
33920   gdb_read_debug_info *read;
33921   gdb_unwind_frame *unwind;
33922   gdb_get_frame_id *get_frame_id;
33923   gdb_destroy_reader *destroy;
33924 @};
33925 @end smallexample
33926
33927 @cindex @code{struct gdb_symbol_callbacks}
33928 @cindex @code{struct gdb_unwind_callbacks}
33929
33930 The callbacks are provided with another set of callbacks by
33931 @value{GDBN} to do their job.  For @code{read}, these callbacks are
33932 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
33933 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
33934 @code{struct gdb_symbol_callbacks} has callbacks to create new object
33935 files and new symbol tables inside those object files.  @code{struct
33936 gdb_unwind_callbacks} has callbacks to read registers off the current
33937 frame and to write out the values of the registers in the previous
33938 frame.  Both have a callback (@code{target_read}) to read bytes off the
33939 target's address space.
33940
33941 @node In-Process Agent
33942 @chapter In-Process Agent
33943 @cindex debugging agent
33944 The traditional debugging model is conceptually low-speed, but works fine,
33945 because most bugs can be reproduced in debugging-mode execution.  However,
33946 as multi-core or many-core processors are becoming mainstream, and
33947 multi-threaded programs become more and more popular, there should be more
33948 and more bugs that only manifest themselves at normal-mode execution, for
33949 example, thread races, because debugger's interference with the program's
33950 timing may conceal the bugs.  On the other hand, in some applications,
33951 it is not feasible for the debugger to interrupt the program's execution
33952 long enough for the developer to learn anything helpful about its behavior.
33953 If the program's correctness depends on its real-time behavior, delays
33954 introduced by a debugger might cause the program to fail, even when the
33955 code itself is correct.  It is useful to be able to observe the program's
33956 behavior without interrupting it.
33957
33958 Therefore, traditional debugging model is too intrusive to reproduce
33959 some bugs.  In order to reduce the interference with the program, we can
33960 reduce the number of operations performed by debugger.  The
33961 @dfn{In-Process Agent}, a shared library, is running within the same
33962 process with inferior, and is able to perform some debugging operations
33963 itself.  As a result, debugger is only involved when necessary, and
33964 performance of debugging can be improved accordingly.  Note that
33965 interference with program can be reduced but can't be removed completely,
33966 because the in-process agent will still stop or slow down the program.
33967
33968 The in-process agent can interpret and execute Agent Expressions
33969 (@pxref{Agent Expressions}) during performing debugging operations.  The
33970 agent expressions can be used for different purposes, such as collecting
33971 data in tracepoints, and condition evaluation in breakpoints.
33972
33973 @anchor{Control Agent}
33974 You can control whether the in-process agent is used as an aid for
33975 debugging with the following commands:
33976
33977 @table @code
33978 @kindex set agent on
33979 @item set agent on
33980 Causes the in-process agent to perform some operations on behalf of the
33981 debugger.  Just which operations requested by the user will be done
33982 by the in-process agent depends on the its capabilities.  For example,
33983 if you request to evaluate breakpoint conditions in the in-process agent,
33984 and the in-process agent has such capability as well, then breakpoint
33985 conditions will be evaluated in the in-process agent.
33986
33987 @kindex set agent off
33988 @item set agent off
33989 Disables execution of debugging operations by the in-process agent.  All
33990 of the operations will be performed by @value{GDBN}.
33991
33992 @kindex show agent
33993 @item show agent
33994 Display the current setting of execution of debugging operations by
33995 the in-process agent.
33996 @end table
33997
33998 @menu
33999 * In-Process Agent Protocol::
34000 @end menu
34001
34002 @node In-Process Agent Protocol
34003 @section In-Process Agent Protocol
34004 @cindex in-process agent protocol
34005
34006 The in-process agent is able to communicate with both @value{GDBN} and
34007 GDBserver (@pxref{In-Process Agent}).  This section documents the protocol
34008 used for communications between @value{GDBN} or GDBserver and the IPA.
34009 In general, @value{GDBN} or GDBserver sends commands
34010 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
34011 in-process agent replies back with the return result of the command, or
34012 some other information.  The data sent to in-process agent is composed
34013 of primitive data types, such as 4-byte or 8-byte type, and composite
34014 types, which are called objects (@pxref{IPA Protocol Objects}).
34015
34016 @menu
34017 * IPA Protocol Objects::
34018 * IPA Protocol Commands::
34019 @end menu
34020
34021 @node IPA Protocol Objects
34022 @subsection IPA Protocol Objects
34023 @cindex ipa protocol objects
34024
34025 The commands sent to and results received from agent may contain some
34026 complex data types called @dfn{objects}.
34027
34028 The in-process agent is running on the same machine with @value{GDBN}
34029 or GDBserver, so it doesn't have to handle as much differences between
34030 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
34031 However, there are still some differences of two ends in two processes:
34032
34033 @enumerate
34034 @item
34035 word size.  On some 64-bit machines, @value{GDBN} or GDBserver can be
34036 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
34037 @item
34038 ABI.  Some machines may have multiple types of ABI, @value{GDBN} or
34039 GDBserver is compiled with one, and in-process agent is compiled with
34040 the other one.
34041 @end enumerate
34042
34043 Here are the IPA Protocol Objects:
34044
34045 @enumerate
34046 @item
34047 agent expression object.  It represents an agent expression
34048 (@pxref{Agent Expressions}).
34049 @anchor{agent expression object}
34050 @item
34051 tracepoint action object.  It represents a tracepoint action
34052 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
34053 memory, static trace data and to evaluate expression.
34054 @anchor{tracepoint action object}
34055 @item
34056 tracepoint object.  It represents a tracepoint (@pxref{Tracepoints}).
34057 @anchor{tracepoint object}
34058
34059 @end enumerate
34060
34061 The following table describes important attributes of each IPA protocol
34062 object:
34063
34064 @multitable @columnfractions .30 .20 .50
34065 @headitem Name @tab Size @tab Description
34066 @item @emph{agent expression object} @tab @tab
34067 @item length @tab 4 @tab length of bytes code
34068 @item byte code @tab @var{length} @tab contents of byte code
34069 @item @emph{tracepoint action for collecting memory} @tab @tab
34070 @item 'M' @tab 1 @tab type of tracepoint action
34071 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
34072 address of the lowest byte to collect, otherwise @var{addr} is the offset
34073 of @var{basereg} for memory collecting.
34074 @item len @tab 8 @tab length of memory for collecting
34075 @item basereg @tab 4 @tab the register number containing the starting
34076 memory address for collecting.
34077 @item @emph{tracepoint action for collecting registers} @tab @tab
34078 @item 'R' @tab 1 @tab type of tracepoint action
34079 @item @emph{tracepoint action for collecting static trace data} @tab @tab
34080 @item 'L' @tab 1 @tab type of tracepoint action
34081 @item @emph{tracepoint action for expression evaluation} @tab @tab
34082 @item 'X' @tab 1 @tab type of tracepoint action
34083 @item agent expression @tab length of @tab @ref{agent expression object}
34084 @item @emph{tracepoint object} @tab @tab
34085 @item number @tab 4 @tab number of tracepoint
34086 @item address @tab 8 @tab address of tracepoint inserted on
34087 @item type @tab 4 @tab type of tracepoint
34088 @item enabled @tab 1 @tab enable or disable of tracepoint
34089 @item step_count @tab 8 @tab step
34090 @item pass_count @tab 8 @tab pass
34091 @item numactions @tab 4 @tab number of tracepoint actions
34092 @item hit count @tab 8 @tab hit count
34093 @item trace frame usage @tab 8 @tab trace frame usage
34094 @item compiled_cond @tab 8 @tab compiled condition
34095 @item orig_size @tab 8 @tab orig size
34096 @item condition @tab 4 if condition is NULL otherwise length of
34097 @ref{agent expression object}
34098 @tab zero if condition is NULL, otherwise is
34099 @ref{agent expression object}
34100 @item actions @tab variable
34101 @tab numactions number of @ref{tracepoint action object}
34102 @end multitable
34103
34104 @node IPA Protocol Commands
34105 @subsection IPA Protocol Commands
34106 @cindex ipa protocol commands
34107
34108 The spaces in each command are delimiters to ease reading this commands
34109 specification.  They don't exist in real commands.
34110
34111 @table @samp
34112
34113 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
34114 Installs a new fast tracepoint described by @var{tracepoint_object}
34115 (@pxref{tracepoint object}).  @var{gdb_jump_pad_head}, 8-byte long, is the
34116 head of @dfn{jumppad}, which is used to jump to data collection routine
34117 in IPA finally.
34118
34119 Replies:
34120 @table @samp
34121 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
34122 @var{target_address} is address of tracepoint in the inferior.
34123 @var{gdb_jump_pad_head} is updated head of jumppad.  Both of
34124 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
34125 @var{fjump} contains a sequence of instructions jump to jumppad entry.
34126 @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
34127 @item E @var{NN}
34128 for an error
34129
34130 @end table
34131
34132 @item close
34133 Closes the in-process agent.  This command is sent when @value{GDBN} or GDBserver
34134 is about to kill inferiors.
34135
34136 @item qTfSTM
34137 @xref{qTfSTM}.
34138 @item qTsSTM
34139 @xref{qTsSTM}.
34140 @item qTSTMat
34141 @xref{qTSTMat}.
34142 @item probe_marker_at:@var{address}
34143 Asks in-process agent to probe the marker at @var{address}.
34144
34145 Replies:
34146 @table @samp
34147 @item E @var{NN}
34148 for an error
34149 @end table
34150 @item unprobe_marker_at:@var{address}
34151 Asks in-process agent to unprobe the marker at @var{address}.
34152 @end table
34153
34154 @node GDB Bugs
34155 @chapter Reporting Bugs in @value{GDBN}
34156 @cindex bugs in @value{GDBN}
34157 @cindex reporting bugs in @value{GDBN}
34158
34159 Your bug reports play an essential role in making @value{GDBN} reliable.
34160
34161 Reporting a bug may help you by bringing a solution to your problem, or it
34162 may not.  But in any case the principal function of a bug report is to help
34163 the entire community by making the next version of @value{GDBN} work better.  Bug
34164 reports are your contribution to the maintenance of @value{GDBN}.
34165
34166 In order for a bug report to serve its purpose, you must include the
34167 information that enables us to fix the bug.
34168
34169 @menu
34170 * Bug Criteria::                Have you found a bug?
34171 * Bug Reporting::               How to report bugs
34172 @end menu
34173
34174 @node Bug Criteria
34175 @section Have You Found a Bug?
34176 @cindex bug criteria
34177
34178 If you are not sure whether you have found a bug, here are some guidelines:
34179
34180 @itemize @bullet
34181 @cindex fatal signal
34182 @cindex debugger crash
34183 @cindex crash of debugger
34184 @item
34185 If the debugger gets a fatal signal, for any input whatever, that is a
34186 @value{GDBN} bug.  Reliable debuggers never crash.
34187
34188 @cindex error on valid input
34189 @item
34190 If @value{GDBN} produces an error message for valid input, that is a
34191 bug.  (Note that if you're cross debugging, the problem may also be
34192 somewhere in the connection to the target.)
34193
34194 @cindex invalid input
34195 @item
34196 If @value{GDBN} does not produce an error message for invalid input,
34197 that is a bug.  However, you should note that your idea of
34198 ``invalid input'' might be our idea of ``an extension'' or ``support
34199 for traditional practice''.
34200
34201 @item
34202 If you are an experienced user of debugging tools, your suggestions
34203 for improvement of @value{GDBN} are welcome in any case.
34204 @end itemize
34205
34206 @node Bug Reporting
34207 @section How to Report Bugs
34208 @cindex bug reports
34209 @cindex @value{GDBN} bugs, reporting
34210
34211 A number of companies and individuals offer support for @sc{gnu} products.
34212 If you obtained @value{GDBN} from a support organization, we recommend you
34213 contact that organization first.
34214
34215 You can find contact information for many support companies and
34216 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
34217 distribution.
34218 @c should add a web page ref...
34219
34220 @ifset BUGURL
34221 @ifset BUGURL_DEFAULT
34222 In any event, we also recommend that you submit bug reports for
34223 @value{GDBN}.  The preferred method is to submit them directly using
34224 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
34225 page}.  Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
34226 be used.
34227
34228 @strong{Do not send bug reports to @samp{info-gdb}, or to
34229 @samp{help-gdb}, or to any newsgroups.}  Most users of @value{GDBN} do
34230 not want to receive bug reports.  Those that do have arranged to receive
34231 @samp{bug-gdb}.
34232
34233 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
34234 serves as a repeater.  The mailing list and the newsgroup carry exactly
34235 the same messages.  Often people think of posting bug reports to the
34236 newsgroup instead of mailing them.  This appears to work, but it has one
34237 problem which can be crucial: a newsgroup posting often lacks a mail
34238 path back to the sender.  Thus, if we need to ask for more information,
34239 we may be unable to reach you.  For this reason, it is better to send
34240 bug reports to the mailing list.
34241 @end ifset
34242 @ifclear BUGURL_DEFAULT
34243 In any event, we also recommend that you submit bug reports for
34244 @value{GDBN} to @value{BUGURL}.
34245 @end ifclear
34246 @end ifset
34247
34248 The fundamental principle of reporting bugs usefully is this:
34249 @strong{report all the facts}.  If you are not sure whether to state a
34250 fact or leave it out, state it!
34251
34252 Often people omit facts because they think they know what causes the
34253 problem and assume that some details do not matter.  Thus, you might
34254 assume that the name of the variable you use in an example does not matter.
34255 Well, probably it does not, but one cannot be sure.  Perhaps the bug is a
34256 stray memory reference which happens to fetch from the location where that
34257 name is stored in memory; perhaps, if the name were different, the contents
34258 of that location would fool the debugger into doing the right thing despite
34259 the bug.  Play it safe and give a specific, complete example.  That is the
34260 easiest thing for you to do, and the most helpful.
34261
34262 Keep in mind that the purpose of a bug report is to enable us to fix the
34263 bug.  It may be that the bug has been reported previously, but neither
34264 you nor we can know that unless your bug report is complete and
34265 self-contained.
34266
34267 Sometimes people give a few sketchy facts and ask, ``Does this ring a
34268 bell?''  Those bug reports are useless, and we urge everyone to
34269 @emph{refuse to respond to them} except to chide the sender to report
34270 bugs properly.
34271
34272 To enable us to fix the bug, you should include all these things:
34273
34274 @itemize @bullet
34275 @item
34276 The version of @value{GDBN}.  @value{GDBN} announces it if you start
34277 with no arguments; you can also print it at any time using @code{show
34278 version}.
34279
34280 Without this, we will not know whether there is any point in looking for
34281 the bug in the current version of @value{GDBN}.
34282
34283 @item
34284 The type of machine you are using, and the operating system name and
34285 version number.
34286
34287 @item
34288 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
34289 ``@value{GCC}--2.8.1''.
34290
34291 @item
34292 What compiler (and its version) was used to compile the program you are
34293 debugging---e.g.@:  ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
34294 C Compiler''.  For @value{NGCC}, you can say @kbd{@value{GCC} --version}
34295 to get this information; for other compilers, see the documentation for
34296 those compilers.
34297
34298 @item
34299 The command arguments you gave the compiler to compile your example and
34300 observe the bug.  For example, did you use @samp{-O}?  To guarantee
34301 you will not omit something important, list them all.  A copy of the
34302 Makefile (or the output from make) is sufficient.
34303
34304 If we were to try to guess the arguments, we would probably guess wrong
34305 and then we might not encounter the bug.
34306
34307 @item
34308 A complete input script, and all necessary source files, that will
34309 reproduce the bug.
34310
34311 @item
34312 A description of what behavior you observe that you believe is
34313 incorrect.  For example, ``It gets a fatal signal.''
34314
34315 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
34316 will certainly notice it.  But if the bug is incorrect output, we might
34317 not notice unless it is glaringly wrong.  You might as well not give us
34318 a chance to make a mistake.
34319
34320 Even if the problem you experience is a fatal signal, you should still
34321 say so explicitly.  Suppose something strange is going on, such as, your
34322 copy of @value{GDBN} is out of synch, or you have encountered a bug in
34323 the C library on your system.  (This has happened!)  Your copy might
34324 crash and ours would not.  If you told us to expect a crash, then when
34325 ours fails to crash, we would know that the bug was not happening for
34326 us.  If you had not told us to expect a crash, then we would not be able
34327 to draw any conclusion from our observations.
34328
34329 @pindex script
34330 @cindex recording a session script
34331 To collect all this information, you can use a session recording program
34332 such as @command{script}, which is available on many Unix systems.
34333 Just run your @value{GDBN} session inside @command{script} and then
34334 include the @file{typescript} file with your bug report.
34335
34336 Another way to record a @value{GDBN} session is to run @value{GDBN}
34337 inside Emacs and then save the entire buffer to a file.
34338
34339 @item
34340 If you wish to suggest changes to the @value{GDBN} source, send us context
34341 diffs.  If you even discuss something in the @value{GDBN} source, refer to
34342 it by context, not by line number.
34343
34344 The line numbers in our development sources will not match those in your
34345 sources.  Your line numbers would convey no useful information to us.
34346
34347 @end itemize
34348
34349 Here are some things that are not necessary:
34350
34351 @itemize @bullet
34352 @item
34353 A description of the envelope of the bug.
34354
34355 Often people who encounter a bug spend a lot of time investigating
34356 which changes to the input file will make the bug go away and which
34357 changes will not affect it.
34358
34359 This is often time consuming and not very useful, because the way we
34360 will find the bug is by running a single example under the debugger
34361 with breakpoints, not by pure deduction from a series of examples.
34362 We recommend that you save your time for something else.
34363
34364 Of course, if you can find a simpler example to report @emph{instead}
34365 of the original one, that is a convenience for us.  Errors in the
34366 output will be easier to spot, running under the debugger will take
34367 less time, and so on.
34368
34369 However, simplification is not vital; if you do not want to do this,
34370 report the bug anyway and send us the entire test case you used.
34371
34372 @item
34373 A patch for the bug.
34374
34375 A patch for the bug does help us if it is a good one.  But do not omit
34376 the necessary information, such as the test case, on the assumption that
34377 a patch is all we need.  We might see problems with your patch and decide
34378 to fix the problem another way, or we might not understand it at all.
34379
34380 Sometimes with a program as complicated as @value{GDBN} it is very hard to
34381 construct an example that will make the program follow a certain path
34382 through the code.  If you do not send us the example, we will not be able
34383 to construct one, so we will not be able to verify that the bug is fixed.
34384
34385 And if we cannot understand what bug you are trying to fix, or why your
34386 patch should be an improvement, we will not install it.  A test case will
34387 help us to understand.
34388
34389 @item
34390 A guess about what the bug is or what it depends on.
34391
34392 Such guesses are usually wrong.  Even we cannot guess right about such
34393 things without first using the debugger to find the facts.
34394 @end itemize
34395
34396 @c The readline documentation is distributed with the readline code
34397 @c and consists of the two following files:
34398 @c     rluser.texi
34399 @c     hsuser.texi
34400 @c Use -I with makeinfo to point to the appropriate directory,
34401 @c environment var TEXINPUTS with TeX.
34402 @ifclear SYSTEM_READLINE
34403 @include rluser.texi
34404 @include hsuser.texi
34405 @end ifclear
34406
34407 @node In Memoriam
34408 @appendix In Memoriam
34409
34410 The @value{GDBN} project mourns the loss of the following long-time
34411 contributors:
34412
34413 @table @code
34414 @item Fred Fish
34415 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
34416 to Free Software in general.  Outside of @value{GDBN}, he was known in
34417 the Amiga world for his series of Fish Disks, and the GeekGadget project.
34418
34419 @item Michael Snyder
34420 Michael was one of the Global Maintainers of the @value{GDBN} project,
34421 with contributions recorded as early as 1996, until 2011.  In addition
34422 to his day to day participation, he was a large driving force behind
34423 adding Reverse Debugging to @value{GDBN}.
34424 @end table
34425
34426 Beyond their technical contributions to the project, they were also
34427 enjoyable members of the Free Software Community.  We will miss them.
34428
34429 @node Formatting Documentation
34430 @appendix Formatting Documentation
34431
34432 @cindex @value{GDBN} reference card
34433 @cindex reference card
34434 The @value{GDBN} 4 release includes an already-formatted reference card, ready
34435 for printing with PostScript or Ghostscript, in the @file{gdb}
34436 subdirectory of the main source directory@footnote{In
34437 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
34438 release.}.  If you can use PostScript or Ghostscript with your printer,
34439 you can print the reference card immediately with @file{refcard.ps}.
34440
34441 The release also includes the source for the reference card.  You
34442 can format it, using @TeX{}, by typing:
34443
34444 @smallexample
34445 make refcard.dvi
34446 @end smallexample
34447
34448 The @value{GDBN} reference card is designed to print in @dfn{landscape}
34449 mode on US ``letter'' size paper;
34450 that is, on a sheet 11 inches wide by 8.5 inches
34451 high.  You will need to specify this form of printing as an option to
34452 your @sc{dvi} output program.
34453
34454 @cindex documentation
34455
34456 All the documentation for @value{GDBN} comes as part of the machine-readable
34457 distribution.  The documentation is written in Texinfo format, which is
34458 a documentation system that uses a single source file to produce both
34459 on-line information and a printed manual.  You can use one of the Info
34460 formatting commands to create the on-line version of the documentation
34461 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
34462
34463 @value{GDBN} includes an already formatted copy of the on-line Info
34464 version of this manual in the @file{gdb} subdirectory.  The main Info
34465 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
34466 subordinate files matching @samp{gdb.info*} in the same directory.  If
34467 necessary, you can print out these files, or read them with any editor;
34468 but they are easier to read using the @code{info} subsystem in @sc{gnu}
34469 Emacs or the standalone @code{info} program, available as part of the
34470 @sc{gnu} Texinfo distribution.
34471
34472 If you want to format these Info files yourself, you need one of the
34473 Info formatting programs, such as @code{texinfo-format-buffer} or
34474 @code{makeinfo}.
34475
34476 If you have @code{makeinfo} installed, and are in the top level
34477 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
34478 version @value{GDBVN}), you can make the Info file by typing:
34479
34480 @smallexample
34481 cd gdb
34482 make gdb.info
34483 @end smallexample
34484
34485 If you want to typeset and print copies of this manual, you need @TeX{},
34486 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
34487 Texinfo definitions file.
34488
34489 @TeX{} is a typesetting program; it does not print files directly, but
34490 produces output files called @sc{dvi} files.  To print a typeset
34491 document, you need a program to print @sc{dvi} files.  If your system
34492 has @TeX{} installed, chances are it has such a program.  The precise
34493 command to use depends on your system; @kbd{lpr -d} is common; another
34494 (for PostScript devices) is @kbd{dvips}.  The @sc{dvi} print command may
34495 require a file name without any extension or a @samp{.dvi} extension.
34496
34497 @TeX{} also requires a macro definitions file called
34498 @file{texinfo.tex}.  This file tells @TeX{} how to typeset a document
34499 written in Texinfo format.  On its own, @TeX{} cannot either read or
34500 typeset a Texinfo file.  @file{texinfo.tex} is distributed with GDB
34501 and is located in the @file{gdb-@var{version-number}/texinfo}
34502 directory.
34503
34504 If you have @TeX{} and a @sc{dvi} printer program installed, you can
34505 typeset and print this manual.  First switch to the @file{gdb}
34506 subdirectory of the main source directory (for example, to
34507 @file{gdb-@value{GDBVN}/gdb}) and type:
34508
34509 @smallexample
34510 make gdb.dvi
34511 @end smallexample
34512
34513 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
34514
34515 @node Installing GDB
34516 @appendix Installing @value{GDBN}
34517 @cindex installation
34518
34519 @menu
34520 * Requirements::                Requirements for building @value{GDBN}
34521 * Running Configure::           Invoking the @value{GDBN} @file{configure} script
34522 * Separate Objdir::             Compiling @value{GDBN} in another directory
34523 * Config Names::                Specifying names for hosts and targets
34524 * Configure Options::           Summary of options for configure
34525 * System-wide configuration::   Having a system-wide init file
34526 @end menu
34527
34528 @node Requirements
34529 @section Requirements for Building @value{GDBN}
34530 @cindex building @value{GDBN}, requirements for
34531
34532 Building @value{GDBN} requires various tools and packages to be available.
34533 Other packages will be used only if they are found.
34534
34535 @heading Tools/Packages Necessary for Building @value{GDBN}
34536 @table @asis
34537 @item ISO C90 compiler
34538 @value{GDBN} is written in ISO C90.  It should be buildable with any
34539 working C90 compiler, e.g.@: GCC.
34540
34541 @end table
34542
34543 @heading Tools/Packages Optional for Building @value{GDBN}
34544 @table @asis
34545 @item Expat
34546 @anchor{Expat}
34547 @value{GDBN} can use the Expat XML parsing library.  This library may be
34548 included with your operating system distribution; if it is not, you
34549 can get the latest version from @url{http://expat.sourceforge.net}.
34550 The @file{configure} script will search for this library in several
34551 standard locations; if it is installed in an unusual path, you can
34552 use the @option{--with-libexpat-prefix} option to specify its location.
34553
34554 Expat is used for:
34555
34556 @itemize @bullet
34557 @item
34558 Remote protocol memory maps (@pxref{Memory Map Format})
34559 @item
34560 Target descriptions (@pxref{Target Descriptions})
34561 @item
34562 Remote shared library lists (@xref{Library List Format},
34563 or alternatively @pxref{Library List Format for SVR4 Targets})
34564 @item
34565 MS-Windows shared libraries (@pxref{Shared Libraries})
34566 @item
34567 Traceframe info (@pxref{Traceframe Info Format})
34568 @end itemize
34569
34570 @item zlib
34571 @cindex compressed debug sections 
34572 @value{GDBN} will use the @samp{zlib} library, if available, to read
34573 compressed debug sections.  Some linkers, such as GNU gold, are capable
34574 of producing binaries with compressed debug sections.  If @value{GDBN}
34575 is compiled with @samp{zlib}, it will be able to read the debug
34576 information in such binaries.
34577
34578 The @samp{zlib} library is likely included with your operating system
34579 distribution; if it is not, you can get the latest version from
34580 @url{http://zlib.net}.
34581
34582 @item iconv
34583 @value{GDBN}'s features related to character sets (@pxref{Character
34584 Sets}) require a functioning @code{iconv} implementation.  If you are
34585 on a GNU system, then this is provided by the GNU C Library.  Some
34586 other systems also provide a working @code{iconv}.
34587
34588 If @value{GDBN} is using the @code{iconv} program which is installed
34589 in a non-standard place, you will need to tell @value{GDBN} where to find it.
34590 This is done with @option{--with-iconv-bin} which specifies the
34591 directory that contains the @code{iconv} program.
34592
34593 On systems without @code{iconv}, you can install GNU Libiconv.  If you
34594 have previously installed Libiconv, you can use the
34595 @option{--with-libiconv-prefix} option to configure.
34596
34597 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
34598 arrange to build Libiconv if a directory named @file{libiconv} appears
34599 in the top-most source directory.  If Libiconv is built this way, and
34600 if the operating system does not provide a suitable @code{iconv}
34601 implementation, then the just-built library will automatically be used
34602 by @value{GDBN}.  One easy way to set this up is to download GNU
34603 Libiconv, unpack it, and then rename the directory holding the
34604 Libiconv source code to @samp{libiconv}.
34605 @end table
34606
34607 @node Running Configure
34608 @section Invoking the @value{GDBN} @file{configure} Script
34609 @cindex configuring @value{GDBN}
34610 @value{GDBN} comes with a @file{configure} script that automates the process
34611 of preparing @value{GDBN} for installation; you can then use @code{make} to
34612 build the @code{gdb} program.
34613 @iftex
34614 @c irrelevant in info file; it's as current as the code it lives with.
34615 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
34616 look at the @file{README} file in the sources; we may have improved the
34617 installation procedures since publishing this manual.}
34618 @end iftex
34619
34620 The @value{GDBN} distribution includes all the source code you need for
34621 @value{GDBN} in a single directory, whose name is usually composed by
34622 appending the version number to @samp{gdb}.
34623
34624 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
34625 @file{gdb-@value{GDBVN}} directory.  That directory contains:
34626
34627 @table @code
34628 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
34629 script for configuring @value{GDBN} and all its supporting libraries
34630
34631 @item gdb-@value{GDBVN}/gdb
34632 the source specific to @value{GDBN} itself
34633
34634 @item gdb-@value{GDBVN}/bfd
34635 source for the Binary File Descriptor library
34636
34637 @item gdb-@value{GDBVN}/include
34638 @sc{gnu} include files
34639
34640 @item gdb-@value{GDBVN}/libiberty
34641 source for the @samp{-liberty} free software library
34642
34643 @item gdb-@value{GDBVN}/opcodes
34644 source for the library of opcode tables and disassemblers
34645
34646 @item gdb-@value{GDBVN}/readline
34647 source for the @sc{gnu} command-line interface
34648
34649 @item gdb-@value{GDBVN}/glob
34650 source for the @sc{gnu} filename pattern-matching subroutine
34651
34652 @item gdb-@value{GDBVN}/mmalloc
34653 source for the @sc{gnu} memory-mapped malloc package
34654 @end table
34655
34656 The simplest way to configure and build @value{GDBN} is to run @file{configure}
34657 from the @file{gdb-@var{version-number}} source directory, which in
34658 this example is the @file{gdb-@value{GDBVN}} directory.
34659
34660 First switch to the @file{gdb-@var{version-number}} source directory
34661 if you are not already in it; then run @file{configure}.  Pass the
34662 identifier for the platform on which @value{GDBN} will run as an
34663 argument.
34664
34665 For example:
34666
34667 @smallexample
34668 cd gdb-@value{GDBVN}
34669 ./configure @var{host}
34670 make
34671 @end smallexample
34672
34673 @noindent
34674 where @var{host} is an identifier such as @samp{sun4} or
34675 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
34676 (You can often leave off @var{host}; @file{configure} tries to guess the
34677 correct value by examining your system.)
34678
34679 Running @samp{configure @var{host}} and then running @code{make} builds the
34680 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
34681 libraries, then @code{gdb} itself.  The configured source files, and the
34682 binaries, are left in the corresponding source directories.
34683
34684 @need 750
34685 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
34686 system does not recognize this automatically when you run a different
34687 shell, you may need to run @code{sh} on it explicitly:
34688
34689 @smallexample
34690 sh configure @var{host}
34691 @end smallexample
34692
34693 If you run @file{configure} from a directory that contains source
34694 directories for multiple libraries or programs, such as the
34695 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
34696 @file{configure}
34697 creates configuration files for every directory level underneath (unless
34698 you tell it not to, with the @samp{--norecursion} option).
34699
34700 You should run the @file{configure} script from the top directory in the
34701 source tree, the @file{gdb-@var{version-number}} directory.  If you run
34702 @file{configure} from one of the subdirectories, you will configure only
34703 that subdirectory.  That is usually not what you want.  In particular,
34704 if you run the first @file{configure} from the @file{gdb} subdirectory
34705 of the @file{gdb-@var{version-number}} directory, you will omit the
34706 configuration of @file{bfd}, @file{readline}, and other sibling
34707 directories of the @file{gdb} subdirectory.  This leads to build errors
34708 about missing include files such as @file{bfd/bfd.h}.
34709
34710 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
34711 However, you should make sure that the shell on your path (named by
34712 the @samp{SHELL} environment variable) is publicly readable.  Remember
34713 that @value{GDBN} uses the shell to start your program---some systems refuse to
34714 let @value{GDBN} debug child processes whose programs are not readable.
34715
34716 @node Separate Objdir
34717 @section Compiling @value{GDBN} in Another Directory
34718
34719 If you want to run @value{GDBN} versions for several host or target machines,
34720 you need a different @code{gdb} compiled for each combination of
34721 host and target.  @file{configure} is designed to make this easy by
34722 allowing you to generate each configuration in a separate subdirectory,
34723 rather than in the source directory.  If your @code{make} program
34724 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
34725 @code{make} in each of these directories builds the @code{gdb}
34726 program specified there.
34727
34728 To build @code{gdb} in a separate directory, run @file{configure}
34729 with the @samp{--srcdir} option to specify where to find the source.
34730 (You also need to specify a path to find @file{configure}
34731 itself from your working directory.  If the path to @file{configure}
34732 would be the same as the argument to @samp{--srcdir}, you can leave out
34733 the @samp{--srcdir} option; it is assumed.)
34734
34735 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
34736 separate directory for a Sun 4 like this:
34737
34738 @smallexample
34739 @group
34740 cd gdb-@value{GDBVN}
34741 mkdir ../gdb-sun4
34742 cd ../gdb-sun4
34743 ../gdb-@value{GDBVN}/configure sun4
34744 make
34745 @end group
34746 @end smallexample
34747
34748 When @file{configure} builds a configuration using a remote source
34749 directory, it creates a tree for the binaries with the same structure
34750 (and using the same names) as the tree under the source directory.  In
34751 the example, you'd find the Sun 4 library @file{libiberty.a} in the
34752 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
34753 @file{gdb-sun4/gdb}.
34754
34755 Make sure that your path to the @file{configure} script has just one
34756 instance of @file{gdb} in it.  If your path to @file{configure} looks
34757 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
34758 one subdirectory of @value{GDBN}, not the whole package.  This leads to
34759 build errors about missing include files such as @file{bfd/bfd.h}.
34760
34761 One popular reason to build several @value{GDBN} configurations in separate
34762 directories is to configure @value{GDBN} for cross-compiling (where
34763 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
34764 programs that run on another machine---the @dfn{target}).
34765 You specify a cross-debugging target by
34766 giving the @samp{--target=@var{target}} option to @file{configure}.
34767
34768 When you run @code{make} to build a program or library, you must run
34769 it in a configured directory---whatever directory you were in when you
34770 called @file{configure} (or one of its subdirectories).
34771
34772 The @code{Makefile} that @file{configure} generates in each source
34773 directory also runs recursively.  If you type @code{make} in a source
34774 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
34775 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
34776 will build all the required libraries, and then build GDB.
34777
34778 When you have multiple hosts or targets configured in separate
34779 directories, you can run @code{make} on them in parallel (for example,
34780 if they are NFS-mounted on each of the hosts); they will not interfere
34781 with each other.
34782
34783 @node Config Names
34784 @section Specifying Names for Hosts and Targets
34785
34786 The specifications used for hosts and targets in the @file{configure}
34787 script are based on a three-part naming scheme, but some short predefined
34788 aliases are also supported.  The full naming scheme encodes three pieces
34789 of information in the following pattern:
34790
34791 @smallexample
34792 @var{architecture}-@var{vendor}-@var{os}
34793 @end smallexample
34794
34795 For example, you can use the alias @code{sun4} as a @var{host} argument,
34796 or as the value for @var{target} in a @code{--target=@var{target}}
34797 option.  The equivalent full name is @samp{sparc-sun-sunos4}.
34798
34799 The @file{configure} script accompanying @value{GDBN} does not provide
34800 any query facility to list all supported host and target names or
34801 aliases.  @file{configure} calls the Bourne shell script
34802 @code{config.sub} to map abbreviations to full names; you can read the
34803 script, if you wish, or you can use it to test your guesses on
34804 abbreviations---for example:
34805
34806 @smallexample
34807 % sh config.sub i386-linux
34808 i386-pc-linux-gnu
34809 % sh config.sub alpha-linux
34810 alpha-unknown-linux-gnu
34811 % sh config.sub hp9k700
34812 hppa1.1-hp-hpux
34813 % sh config.sub sun4
34814 sparc-sun-sunos4.1.1
34815 % sh config.sub sun3
34816 m68k-sun-sunos4.1.1
34817 % sh config.sub i986v
34818 Invalid configuration `i986v': machine `i986v' not recognized
34819 @end smallexample
34820
34821 @noindent
34822 @code{config.sub} is also distributed in the @value{GDBN} source
34823 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
34824
34825 @node Configure Options
34826 @section @file{configure} Options
34827
34828 Here is a summary of the @file{configure} options and arguments that
34829 are most often useful for building @value{GDBN}.  @file{configure} also has
34830 several other options not listed here.  @inforef{What Configure
34831 Does,,configure.info}, for a full explanation of @file{configure}.
34832
34833 @smallexample
34834 configure @r{[}--help@r{]}
34835           @r{[}--prefix=@var{dir}@r{]}
34836           @r{[}--exec-prefix=@var{dir}@r{]}
34837           @r{[}--srcdir=@var{dirname}@r{]}
34838           @r{[}--norecursion@r{]} @r{[}--rm@r{]}
34839           @r{[}--target=@var{target}@r{]}
34840           @var{host}
34841 @end smallexample
34842
34843 @noindent
34844 You may introduce options with a single @samp{-} rather than
34845 @samp{--} if you prefer; but you may abbreviate option names if you use
34846 @samp{--}.
34847
34848 @table @code
34849 @item --help
34850 Display a quick summary of how to invoke @file{configure}.
34851
34852 @item --prefix=@var{dir}
34853 Configure the source to install programs and files under directory
34854 @file{@var{dir}}.
34855
34856 @item --exec-prefix=@var{dir}
34857 Configure the source to install programs under directory
34858 @file{@var{dir}}.
34859
34860 @c avoid splitting the warning from the explanation:
34861 @need 2000
34862 @item --srcdir=@var{dirname}
34863 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
34864 @code{make} that implements the @code{VPATH} feature.}@*
34865 Use this option to make configurations in directories separate from the
34866 @value{GDBN} source directories.  Among other things, you can use this to
34867 build (or maintain) several configurations simultaneously, in separate
34868 directories.  @file{configure} writes configuration-specific files in
34869 the current directory, but arranges for them to use the source in the
34870 directory @var{dirname}.  @file{configure} creates directories under
34871 the working directory in parallel to the source directories below
34872 @var{dirname}.
34873
34874 @item --norecursion
34875 Configure only the directory level where @file{configure} is executed; do not
34876 propagate configuration to subdirectories.
34877
34878 @item --target=@var{target}
34879 Configure @value{GDBN} for cross-debugging programs running on the specified
34880 @var{target}.  Without this option, @value{GDBN} is configured to debug
34881 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
34882
34883 There is no convenient way to generate a list of all available targets.
34884
34885 @item @var{host} @dots{}
34886 Configure @value{GDBN} to run on the specified @var{host}.
34887
34888 There is no convenient way to generate a list of all available hosts.
34889 @end table
34890
34891 There are many other options available as well, but they are generally
34892 needed for special purposes only.
34893
34894 @node System-wide configuration
34895 @section System-wide configuration and settings
34896 @cindex system-wide init file
34897
34898 @value{GDBN} can be configured to have a system-wide init file;
34899 this file will be read and executed at startup (@pxref{Startup, , What
34900 @value{GDBN} does during startup}).
34901
34902 Here is the corresponding configure option:
34903
34904 @table @code
34905 @item --with-system-gdbinit=@var{file}
34906 Specify that the default location of the system-wide init file is
34907 @var{file}.
34908 @end table
34909
34910 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
34911 it may be subject to relocation.  Two possible cases:
34912
34913 @itemize @bullet
34914 @item 
34915 If the default location of this init file contains @file{$prefix},
34916 it will be subject to relocation.  Suppose that the configure options
34917 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
34918 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
34919 init file is looked for as @file{$install/etc/gdbinit} instead of
34920 @file{$prefix/etc/gdbinit}.
34921
34922 @item
34923 By contrast, if the default location does not contain the prefix,
34924 it will not be relocated.  E.g.@: if @value{GDBN} has been configured with
34925 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
34926 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
34927 wherever @value{GDBN} is installed.
34928 @end itemize
34929
34930 If the configured location of the system-wide init file (as given by the
34931 @option{--with-system-gdbinit} option at configure time) is in the
34932 data-directory (as specified by @option{--with-gdb-datadir} at configure
34933 time) or in one of its subdirectories, then @value{GDBN} will look for the
34934 system-wide init file in the directory specified by the
34935 @option{--data-directory} command-line option.
34936 Note that the system-wide init file is only read once, during @value{GDBN}
34937 initialization.  If the data-directory is changed after @value{GDBN} has
34938 started with the @code{set data-directory} command, the file will not be
34939 reread.
34940
34941 @node Maintenance Commands
34942 @appendix Maintenance Commands
34943 @cindex maintenance commands
34944 @cindex internal commands
34945
34946 In addition to commands intended for @value{GDBN} users, @value{GDBN}
34947 includes a number of commands intended for @value{GDBN} developers,
34948 that are not documented elsewhere in this manual.  These commands are
34949 provided here for reference.  (For commands that turn on debugging
34950 messages, see @ref{Debugging Output}.)
34951
34952 @table @code
34953 @kindex maint agent
34954 @kindex maint agent-eval
34955 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
34956 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
34957 Translate the given @var{expression} into remote agent bytecodes.
34958 This command is useful for debugging the Agent Expression mechanism
34959 (@pxref{Agent Expressions}).  The @samp{agent} version produces an
34960 expression useful for data collection, such as by tracepoints, while
34961 @samp{maint agent-eval} produces an expression that evaluates directly
34962 to a result.  For instance, a collection expression for @code{globa +
34963 globb} will include bytecodes to record four bytes of memory at each
34964 of the addresses of @code{globa} and @code{globb}, while discarding
34965 the result of the addition, while an evaluation expression will do the
34966 addition and return the sum.
34967 If @code{-at} is given, generate remote agent bytecode for @var{location}.
34968 If not, generate remote agent bytecode for current frame PC address.
34969
34970 @kindex maint agent-printf
34971 @item maint agent-printf @var{format},@var{expr},...
34972 Translate the given format string and list of argument expressions
34973 into remote agent bytecodes and display them as a disassembled list.
34974 This command is useful for debugging the agent version of dynamic
34975 printf (@pxref{Dynamic Printf}.
34976
34977 @kindex maint info breakpoints
34978 @item @anchor{maint info breakpoints}maint info breakpoints
34979 Using the same format as @samp{info breakpoints}, display both the
34980 breakpoints you've set explicitly, and those @value{GDBN} is using for
34981 internal purposes.  Internal breakpoints are shown with negative
34982 breakpoint numbers.  The type column identifies what kind of breakpoint
34983 is shown:
34984
34985 @table @code
34986 @item breakpoint
34987 Normal, explicitly set breakpoint.
34988
34989 @item watchpoint
34990 Normal, explicitly set watchpoint.
34991
34992 @item longjmp
34993 Internal breakpoint, used to handle correctly stepping through
34994 @code{longjmp} calls.
34995
34996 @item longjmp resume
34997 Internal breakpoint at the target of a @code{longjmp}.
34998
34999 @item until
35000 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
35001
35002 @item finish
35003 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
35004
35005 @item shlib events
35006 Shared library events.
35007
35008 @end table
35009
35010 @kindex maint info bfds
35011 @item maint info bfds
35012 This prints information about each @code{bfd} object that is known to
35013 @value{GDBN}.  @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
35014
35015 @kindex set displaced-stepping
35016 @kindex show displaced-stepping
35017 @cindex displaced stepping support
35018 @cindex out-of-line single-stepping
35019 @item set displaced-stepping
35020 @itemx show displaced-stepping
35021 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
35022 if the target supports it.  Displaced stepping is a way to single-step
35023 over breakpoints without removing them from the inferior, by executing
35024 an out-of-line copy of the instruction that was originally at the
35025 breakpoint location.  It is also known as out-of-line single-stepping.
35026
35027 @table @code
35028 @item set displaced-stepping on
35029 If the target architecture supports it, @value{GDBN} will use
35030 displaced stepping to step over breakpoints.
35031
35032 @item set displaced-stepping off
35033 @value{GDBN} will not use displaced stepping to step over breakpoints,
35034 even if such is supported by the target architecture.
35035
35036 @cindex non-stop mode, and @samp{set displaced-stepping}
35037 @item set displaced-stepping auto
35038 This is the default mode.  @value{GDBN} will use displaced stepping
35039 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
35040 architecture supports displaced stepping.
35041 @end table
35042
35043 @kindex maint check-symtabs
35044 @item maint check-symtabs
35045 Check the consistency of psymtabs and symtabs.
35046
35047 @kindex maint cplus first_component
35048 @item maint cplus first_component @var{name}
35049 Print the first C@t{++} class/namespace component of @var{name}.
35050
35051 @kindex maint cplus namespace
35052 @item maint cplus namespace
35053 Print the list of possible C@t{++} namespaces.
35054
35055 @kindex maint demangle
35056 @item maint demangle @var{name}
35057 Demangle a C@t{++} or Objective-C mangled @var{name}.
35058
35059 @kindex maint deprecate
35060 @kindex maint undeprecate
35061 @cindex deprecated commands
35062 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
35063 @itemx maint undeprecate @var{command}
35064 Deprecate or undeprecate the named @var{command}.  Deprecated commands
35065 cause @value{GDBN} to issue a warning when you use them.  The optional
35066 argument @var{replacement} says which newer command should be used in
35067 favor of the deprecated one; if it is given, @value{GDBN} will mention
35068 the replacement as part of the warning.
35069
35070 @kindex maint dump-me
35071 @item maint dump-me
35072 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
35073 Cause a fatal signal in the debugger and force it to dump its core.
35074 This is supported only on systems which support aborting a program
35075 with the @code{SIGQUIT} signal.
35076
35077 @kindex maint internal-error
35078 @kindex maint internal-warning
35079 @item maint internal-error @r{[}@var{message-text}@r{]}
35080 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
35081 Cause @value{GDBN} to call the internal function @code{internal_error}
35082 or @code{internal_warning} and hence behave as though an internal error
35083 or internal warning has been detected.  In addition to reporting the
35084 internal problem, these functions give the user the opportunity to
35085 either quit @value{GDBN} or create a core file of the current
35086 @value{GDBN} session.
35087
35088 These commands take an optional parameter @var{message-text} that is
35089 used as the text of the error or warning message.
35090
35091 Here's an example of using @code{internal-error}:
35092
35093 @smallexample
35094 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
35095 @dots{}/maint.c:121: internal-error: testing, 1, 2
35096 A problem internal to GDB has been detected.  Further
35097 debugging may prove unreliable.
35098 Quit this debugging session? (y or n) @kbd{n}
35099 Create a core file? (y or n) @kbd{n}
35100 (@value{GDBP})
35101 @end smallexample
35102
35103 @cindex @value{GDBN} internal error
35104 @cindex internal errors, control of @value{GDBN} behavior
35105
35106 @kindex maint set internal-error
35107 @kindex maint show internal-error
35108 @kindex maint set internal-warning
35109 @kindex maint show internal-warning
35110 @item maint set internal-error @var{action} [ask|yes|no]
35111 @itemx maint show internal-error @var{action}
35112 @itemx maint set internal-warning @var{action} [ask|yes|no]
35113 @itemx maint show internal-warning @var{action}
35114 When @value{GDBN} reports an internal problem (error or warning) it
35115 gives the user the opportunity to both quit @value{GDBN} and create a
35116 core file of the current @value{GDBN} session.  These commands let you
35117 override the default behaviour for each particular @var{action},
35118 described in the table below.
35119
35120 @table @samp
35121 @item quit
35122 You can specify that @value{GDBN} should always (yes) or never (no)
35123 quit.  The default is to ask the user what to do.
35124
35125 @item corefile
35126 You can specify that @value{GDBN} should always (yes) or never (no)
35127 create a core file.  The default is to ask the user what to do.
35128 @end table
35129
35130 @kindex maint packet
35131 @item maint packet @var{text}
35132 If @value{GDBN} is talking to an inferior via the serial protocol,
35133 then this command sends the string @var{text} to the inferior, and
35134 displays the response packet.  @value{GDBN} supplies the initial
35135 @samp{$} character, the terminating @samp{#} character, and the
35136 checksum.
35137
35138 @kindex maint print architecture
35139 @item maint print architecture @r{[}@var{file}@r{]}
35140 Print the entire architecture configuration.  The optional argument
35141 @var{file} names the file where the output goes.
35142
35143 @kindex maint print c-tdesc
35144 @item maint print c-tdesc
35145 Print the current target description (@pxref{Target Descriptions}) as
35146 a C source file.  The created source file can be used in @value{GDBN}
35147 when an XML parser is not available to parse the description.
35148
35149 @kindex maint print dummy-frames
35150 @item maint print dummy-frames
35151 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
35152
35153 @smallexample
35154 (@value{GDBP}) @kbd{b add}
35155 @dots{}
35156 (@value{GDBP}) @kbd{print add(2,3)}
35157 Breakpoint 2, add (a=2, b=3) at @dots{}
35158 58        return (a + b);
35159 The program being debugged stopped while in a function called from GDB.
35160 @dots{}
35161 (@value{GDBP}) @kbd{maint print dummy-frames}
35162 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
35163  top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
35164  call_lo=0x01014000 call_hi=0x01014001
35165 (@value{GDBP})
35166 @end smallexample
35167
35168 Takes an optional file parameter.
35169
35170 @kindex maint print registers
35171 @kindex maint print raw-registers
35172 @kindex maint print cooked-registers
35173 @kindex maint print register-groups
35174 @kindex maint print remote-registers
35175 @item maint print registers @r{[}@var{file}@r{]}
35176 @itemx maint print raw-registers @r{[}@var{file}@r{]}
35177 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
35178 @itemx maint print register-groups @r{[}@var{file}@r{]}
35179 @itemx maint print remote-registers @r{[}@var{file}@r{]}
35180 Print @value{GDBN}'s internal register data structures.
35181
35182 The command @code{maint print raw-registers} includes the contents of
35183 the raw register cache; the command @code{maint print
35184 cooked-registers} includes the (cooked) value of all registers,
35185 including registers which aren't available on the target nor visible
35186 to user; the command @code{maint print register-groups} includes the
35187 groups that each register is a member of; and the command @code{maint
35188 print remote-registers} includes the remote target's register numbers
35189 and offsets in the `G' packets.  @xref{Registers,, Registers, gdbint,
35190 @value{GDBN} Internals}.
35191
35192 These commands take an optional parameter, a file name to which to
35193 write the information.
35194
35195 @kindex maint print reggroups
35196 @item maint print reggroups @r{[}@var{file}@r{]}
35197 Print @value{GDBN}'s internal register group data structures.  The
35198 optional argument @var{file} tells to what file to write the
35199 information.
35200
35201 The register groups info looks like this:
35202
35203 @smallexample
35204 (@value{GDBP}) @kbd{maint print reggroups}
35205  Group      Type
35206  general    user
35207  float      user
35208  all        user
35209  vector     user
35210  system     user
35211  save       internal
35212  restore    internal
35213 @end smallexample
35214
35215 @kindex flushregs
35216 @item flushregs
35217 This command forces @value{GDBN} to flush its internal register cache.
35218
35219 @kindex maint print objfiles
35220 @cindex info for known object files
35221 @item maint print objfiles
35222 Print a dump of all known object files.  For each object file, this
35223 command prints its name, address in memory, and all of its psymtabs
35224 and symtabs.
35225
35226 @kindex maint print section-scripts
35227 @cindex info for known .debug_gdb_scripts-loaded scripts
35228 @item maint print section-scripts [@var{regexp}]
35229 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
35230 If @var{regexp} is specified, only print scripts loaded by object files
35231 matching @var{regexp}.
35232 For each script, this command prints its name as specified in the objfile,
35233 and the full path if known.
35234 @xref{dotdebug_gdb_scripts section}.
35235
35236 @kindex maint print statistics
35237 @cindex bcache statistics
35238 @item maint print statistics
35239 This command prints, for each object file in the program, various data
35240 about that object file followed by the byte cache (@dfn{bcache})
35241 statistics for the object file.  The objfile data includes the number
35242 of minimal, partial, full, and stabs symbols, the number of types
35243 defined by the objfile, the number of as yet unexpanded psym tables,
35244 the number of line tables and string tables, and the amount of memory
35245 used by the various tables.  The bcache statistics include the counts,
35246 sizes, and counts of duplicates of all and unique objects, max,
35247 average, and median entry size, total memory used and its overhead and
35248 savings, and various measures of the hash table size and chain
35249 lengths.
35250
35251 @kindex maint print target-stack
35252 @cindex target stack description
35253 @item maint print target-stack
35254 A @dfn{target} is an interface between the debugger and a particular
35255 kind of file or process.  Targets can be stacked in @dfn{strata},
35256 so that more than one target can potentially respond to a request.
35257 In particular, memory accesses will walk down the stack of targets
35258 until they find a target that is interested in handling that particular
35259 address.
35260
35261 This command prints a short description of each layer that was pushed on
35262 the @dfn{target stack}, starting from the top layer down to the bottom one.
35263
35264 @kindex maint print type
35265 @cindex type chain of a data type
35266 @item maint print type @var{expr}
35267 Print the type chain for a type specified by @var{expr}.  The argument
35268 can be either a type name or a symbol.  If it is a symbol, the type of
35269 that symbol is described.  The type chain produced by this command is
35270 a recursive definition of the data type as stored in @value{GDBN}'s
35271 data structures, including its flags and contained types.
35272
35273 @kindex maint set dwarf2 always-disassemble
35274 @kindex maint show dwarf2 always-disassemble
35275 @item maint set dwarf2 always-disassemble
35276 @item maint show dwarf2 always-disassemble
35277 Control the behavior of @code{info address} when using DWARF debugging
35278 information.
35279
35280 The default is @code{off}, which means that @value{GDBN} should try to
35281 describe a variable's location in an easily readable format.  When
35282 @code{on}, @value{GDBN} will instead display the DWARF location
35283 expression in an assembly-like format.  Note that some locations are
35284 too complex for @value{GDBN} to describe simply; in this case you will
35285 always see the disassembly form.
35286
35287 Here is an example of the resulting disassembly:
35288
35289 @smallexample
35290 (gdb) info addr argc
35291 Symbol "argc" is a complex DWARF expression:
35292      1: DW_OP_fbreg 0
35293 @end smallexample
35294
35295 For more information on these expressions, see
35296 @uref{http://www.dwarfstd.org/, the DWARF standard}.
35297
35298 @kindex maint set dwarf2 max-cache-age
35299 @kindex maint show dwarf2 max-cache-age
35300 @item maint set dwarf2 max-cache-age
35301 @itemx maint show dwarf2 max-cache-age
35302 Control the DWARF 2 compilation unit cache.
35303
35304 @cindex DWARF 2 compilation units cache
35305 In object files with inter-compilation-unit references, such as those
35306 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
35307 reader needs to frequently refer to previously read compilation units.
35308 This setting controls how long a compilation unit will remain in the
35309 cache if it is not referenced.  A higher limit means that cached
35310 compilation units will be stored in memory longer, and more total
35311 memory will be used.  Setting it to zero disables caching, which will
35312 slow down @value{GDBN} startup, but reduce memory consumption.
35313
35314 @kindex maint set profile
35315 @kindex maint show profile
35316 @cindex profiling GDB
35317 @item maint set profile
35318 @itemx maint show profile
35319 Control profiling of @value{GDBN}.
35320
35321 Profiling will be disabled until you use the @samp{maint set profile}
35322 command to enable it.  When you enable profiling, the system will begin
35323 collecting timing and execution count data; when you disable profiling or
35324 exit @value{GDBN}, the results will be written to a log file.  Remember that
35325 if you use profiling, @value{GDBN} will overwrite the profiling log file
35326 (often called @file{gmon.out}).  If you have a record of important profiling
35327 data in a @file{gmon.out} file, be sure to move it to a safe location.
35328
35329 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
35330 compiled with the @samp{-pg} compiler option.
35331
35332 @kindex maint set show-debug-regs
35333 @kindex maint show show-debug-regs
35334 @cindex hardware debug registers
35335 @item maint set show-debug-regs
35336 @itemx maint show show-debug-regs
35337 Control whether to show variables that mirror the hardware debug
35338 registers.  Use @code{ON} to enable, @code{OFF} to disable.  If
35339 enabled, the debug registers values are shown when @value{GDBN} inserts or
35340 removes a hardware breakpoint or watchpoint, and when the inferior
35341 triggers a hardware-assisted breakpoint or watchpoint.
35342
35343 @kindex maint set show-all-tib
35344 @kindex maint show show-all-tib
35345 @item maint set show-all-tib
35346 @itemx maint show show-all-tib
35347 Control whether to show all non zero areas within a 1k block starting
35348 at thread local base, when using the @samp{info w32 thread-information-block}
35349 command.
35350
35351 @kindex maint space
35352 @cindex memory used by commands
35353 @item maint space
35354 Control whether to display memory usage for each command.  If set to a
35355 nonzero value, @value{GDBN} will display how much memory each command
35356 took, following the command's own output.  This can also be requested
35357 by invoking @value{GDBN} with the @option{--statistics} command-line
35358 switch (@pxref{Mode Options}).
35359
35360 @kindex maint time
35361 @cindex time of command execution
35362 @item maint time
35363 Control whether to display the execution time of @value{GDBN} for each command.
35364 If set to a nonzero value, @value{GDBN} will display how much time it
35365 took to execute each command, following the command's own output.
35366 Both CPU time and wallclock time are printed.
35367 Printing both is useful when trying to determine whether the cost is
35368 CPU or, e.g., disk/network, latency.
35369 Note that the CPU time printed is for @value{GDBN} only, it does not include
35370 the execution time of the inferior because there's no mechanism currently
35371 to compute how much time was spent by @value{GDBN} and how much time was
35372 spent by the program been debugged.
35373 This can also be requested by invoking @value{GDBN} with the
35374 @option{--statistics} command-line switch (@pxref{Mode Options}).
35375
35376 @kindex maint translate-address
35377 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
35378 Find the symbol stored at the location specified by the address
35379 @var{addr} and an optional section name @var{section}.  If found,
35380 @value{GDBN} prints the name of the closest symbol and an offset from
35381 the symbol's location to the specified address.  This is similar to
35382 the @code{info address} command (@pxref{Symbols}), except that this
35383 command also allows to find symbols in other sections.
35384
35385 If section was not specified, the section in which the symbol was found
35386 is also printed.  For dynamically linked executables, the name of
35387 executable or shared library containing the symbol is printed as well.
35388
35389 @end table
35390
35391 The following command is useful for non-interactive invocations of
35392 @value{GDBN}, such as in the test suite.
35393
35394 @table @code
35395 @item set watchdog @var{nsec}
35396 @kindex set watchdog
35397 @cindex watchdog timer
35398 @cindex timeout for commands
35399 Set the maximum number of seconds @value{GDBN} will wait for the
35400 target operation to finish.  If this time expires, @value{GDBN}
35401 reports and error and the command is aborted.
35402
35403 @item show watchdog
35404 Show the current setting of the target wait timeout.
35405 @end table
35406
35407 @node Remote Protocol
35408 @appendix @value{GDBN} Remote Serial Protocol
35409
35410 @menu
35411 * Overview::
35412 * Packets::
35413 * Stop Reply Packets::
35414 * General Query Packets::
35415 * Architecture-Specific Protocol Details::
35416 * Tracepoint Packets::
35417 * Host I/O Packets::
35418 * Interrupts::
35419 * Notification Packets::
35420 * Remote Non-Stop::
35421 * Packet Acknowledgment::
35422 * Examples::
35423 * File-I/O Remote Protocol Extension::
35424 * Library List Format::
35425 * Library List Format for SVR4 Targets::
35426 * Memory Map Format::
35427 * Thread List Format::
35428 * Traceframe Info Format::
35429 @end menu
35430
35431 @node Overview
35432 @section Overview
35433
35434 There may be occasions when you need to know something about the
35435 protocol---for example, if there is only one serial port to your target
35436 machine, you might want your program to do something special if it
35437 recognizes a packet meant for @value{GDBN}.
35438
35439 In the examples below, @samp{->} and @samp{<-} are used to indicate
35440 transmitted and received data, respectively.
35441
35442 @cindex protocol, @value{GDBN} remote serial
35443 @cindex serial protocol, @value{GDBN} remote
35444 @cindex remote serial protocol
35445 All @value{GDBN} commands and responses (other than acknowledgments
35446 and notifications, see @ref{Notification Packets}) are sent as a
35447 @var{packet}.  A @var{packet} is introduced with the character
35448 @samp{$}, the actual @var{packet-data}, and the terminating character
35449 @samp{#} followed by a two-digit @var{checksum}:
35450
35451 @smallexample
35452 @code{$}@var{packet-data}@code{#}@var{checksum}
35453 @end smallexample
35454 @noindent
35455
35456 @cindex checksum, for @value{GDBN} remote
35457 @noindent
35458 The two-digit @var{checksum} is computed as the modulo 256 sum of all
35459 characters between the leading @samp{$} and the trailing @samp{#} (an
35460 eight bit unsigned checksum).
35461
35462 Implementors should note that prior to @value{GDBN} 5.0 the protocol
35463 specification also included an optional two-digit @var{sequence-id}:
35464
35465 @smallexample
35466 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
35467 @end smallexample
35468
35469 @cindex sequence-id, for @value{GDBN} remote
35470 @noindent
35471 That @var{sequence-id} was appended to the acknowledgment.  @value{GDBN}
35472 has never output @var{sequence-id}s.  Stubs that handle packets added
35473 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
35474
35475 When either the host or the target machine receives a packet, the first
35476 response expected is an acknowledgment: either @samp{+} (to indicate
35477 the package was received correctly) or @samp{-} (to request
35478 retransmission):
35479
35480 @smallexample
35481 -> @code{$}@var{packet-data}@code{#}@var{checksum}
35482 <- @code{+}
35483 @end smallexample
35484 @noindent
35485
35486 The @samp{+}/@samp{-} acknowledgments can be disabled
35487 once a connection is established.
35488 @xref{Packet Acknowledgment}, for details.
35489
35490 The host (@value{GDBN}) sends @var{command}s, and the target (the
35491 debugging stub incorporated in your program) sends a @var{response}.  In
35492 the case of step and continue @var{command}s, the response is only sent
35493 when the operation has completed, and the target has again stopped all
35494 threads in all attached processes.  This is the default all-stop mode
35495 behavior, but the remote protocol also supports @value{GDBN}'s non-stop 
35496 execution mode; see @ref{Remote Non-Stop}, for details.
35497
35498 @var{packet-data} consists of a sequence of characters with the
35499 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
35500 exceptions).
35501
35502 @cindex remote protocol, field separator
35503 Fields within the packet should be separated using @samp{,} @samp{;} or
35504 @samp{:}.  Except where otherwise noted all numbers are represented in
35505 @sc{hex} with leading zeros suppressed.
35506
35507 Implementors should note that prior to @value{GDBN} 5.0, the character
35508 @samp{:} could not appear as the third character in a packet (as it
35509 would potentially conflict with the @var{sequence-id}).
35510
35511 @cindex remote protocol, binary data
35512 @anchor{Binary Data}
35513 Binary data in most packets is encoded either as two hexadecimal
35514 digits per byte of binary data.  This allowed the traditional remote
35515 protocol to work over connections which were only seven-bit clean.
35516 Some packets designed more recently assume an eight-bit clean
35517 connection, and use a more efficient encoding to send and receive
35518 binary data.
35519
35520 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
35521 as an escape character.  Any escaped byte is transmitted as the escape
35522 character followed by the original character XORed with @code{0x20}.
35523 For example, the byte @code{0x7d} would be transmitted as the two
35524 bytes @code{0x7d 0x5d}.  The bytes @code{0x23} (@sc{ascii} @samp{#}),
35525 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
35526 @samp{@}}) must always be escaped.  Responses sent by the stub
35527 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
35528 is not interpreted as the start of a run-length encoded sequence
35529 (described next).
35530
35531 Response @var{data} can be run-length encoded to save space.
35532 Run-length encoding replaces runs of identical characters with one
35533 instance of the repeated character, followed by a @samp{*} and a
35534 repeat count.  The repeat count is itself sent encoded, to avoid
35535 binary characters in @var{data}: a value of @var{n} is sent as
35536 @code{@var{n}+29}.  For a repeat count greater or equal to 3, this
35537 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
35538 code 32) for a repeat count of 3.  (This is because run-length
35539 encoding starts to win for counts 3 or more.)  Thus, for example,
35540 @samp{0* } is a run-length encoding of ``0000'': the space character
35541 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
35542 3}} more times.
35543
35544 The printable characters @samp{#} and @samp{$} or with a numeric value
35545 greater than 126 must not be used.  Runs of six repeats (@samp{#}) or
35546 seven repeats (@samp{$}) can be expanded using a repeat count of only
35547 five (@samp{"}).  For example, @samp{00000000} can be encoded as
35548 @samp{0*"00}.
35549
35550 The error response returned for some packets includes a two character
35551 error number.  That number is not well defined.
35552
35553 @cindex empty response, for unsupported packets
35554 For any @var{command} not supported by the stub, an empty response
35555 (@samp{$#00}) should be returned.  That way it is possible to extend the
35556 protocol.  A newer @value{GDBN} can tell if a packet is supported based
35557 on that response.
35558
35559 At a minimum, a stub is required to support the @samp{g} and @samp{G}
35560 commands for register access, and the @samp{m} and @samp{M} commands
35561 for memory access.  Stubs that only control single-threaded targets
35562 can implement run control with the @samp{c} (continue), and @samp{s}
35563 (step) commands.  Stubs that support multi-threading targets should
35564 support the @samp{vCont} command.  All other commands are optional.
35565
35566 @node Packets
35567 @section Packets
35568
35569 The following table provides a complete list of all currently defined
35570 @var{command}s and their corresponding response @var{data}.
35571 @xref{File-I/O Remote Protocol Extension}, for details about the File
35572 I/O extension of the remote protocol.
35573
35574 Each packet's description has a template showing the packet's overall
35575 syntax, followed by an explanation of the packet's meaning.  We
35576 include spaces in some of the templates for clarity; these are not
35577 part of the packet's syntax.  No @value{GDBN} packet uses spaces to
35578 separate its components.  For example, a template like @samp{foo
35579 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
35580 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
35581 @var{baz}.  @value{GDBN} does not transmit a space character between the
35582 @samp{foo} and the @var{bar}, or between the @var{bar} and the
35583 @var{baz}.
35584
35585 @cindex @var{thread-id}, in remote protocol
35586 @anchor{thread-id syntax} 
35587 Several packets and replies include a @var{thread-id} field to identify
35588 a thread.  Normally these are positive numbers with a target-specific
35589 interpretation, formatted as big-endian hex strings.  A @var{thread-id}
35590 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
35591 pick any thread.
35592
35593 In addition, the remote protocol supports a multiprocess feature in
35594 which the @var{thread-id} syntax is extended to optionally include both
35595 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
35596 The @var{pid} (process) and @var{tid} (thread) components each have the
35597 format described above: a positive number with target-specific
35598 interpretation formatted as a big-endian hex string, literal @samp{-1}
35599 to indicate all processes or threads (respectively), or @samp{0} to
35600 indicate an arbitrary process or thread.  Specifying just a process, as
35601 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}.  It is an
35602 error to specify all processes but a specific thread, such as
35603 @samp{p-1.@var{tid}}.  Note that the @samp{p} prefix is @emph{not} used
35604 for those packets and replies explicitly documented to include a process
35605 ID, rather than a @var{thread-id}.
35606
35607 The multiprocess @var{thread-id} syntax extensions are only used if both
35608 @value{GDBN} and the stub report support for the @samp{multiprocess}
35609 feature using @samp{qSupported}.  @xref{multiprocess extensions}, for
35610 more information.
35611
35612 Note that all packet forms beginning with an upper- or lower-case
35613 letter, other than those described here, are reserved for future use.
35614
35615 Here are the packet descriptions.
35616
35617 @table @samp
35618
35619 @item !
35620 @cindex @samp{!} packet
35621 @anchor{extended mode}
35622 Enable extended mode.  In extended mode, the remote server is made
35623 persistent.  The @samp{R} packet is used to restart the program being
35624 debugged.
35625
35626 Reply:
35627 @table @samp
35628 @item OK
35629 The remote target both supports and has enabled extended mode.
35630 @end table
35631
35632 @item ?
35633 @cindex @samp{?} packet
35634 Indicate the reason the target halted.  The reply is the same as for
35635 step and continue.  This packet has a special interpretation when the
35636 target is in non-stop mode; see @ref{Remote Non-Stop}.
35637
35638 Reply:
35639 @xref{Stop Reply Packets}, for the reply specifications.
35640
35641 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
35642 @cindex @samp{A} packet
35643 Initialized @code{argv[]} array passed into program. @var{arglen}
35644 specifies the number of bytes in the hex encoded byte stream
35645 @var{arg}.  See @code{gdbserver} for more details.
35646
35647 Reply:
35648 @table @samp
35649 @item OK
35650 The arguments were set.
35651 @item E @var{NN}
35652 An error occurred.
35653 @end table
35654
35655 @item b @var{baud}
35656 @cindex @samp{b} packet
35657 (Don't use this packet; its behavior is not well-defined.)
35658 Change the serial line speed to @var{baud}.
35659
35660 JTC: @emph{When does the transport layer state change?  When it's
35661 received, or after the ACK is transmitted.  In either case, there are
35662 problems if the command or the acknowledgment packet is dropped.}
35663
35664 Stan: @emph{If people really wanted to add something like this, and get
35665 it working for the first time, they ought to modify ser-unix.c to send
35666 some kind of out-of-band message to a specially-setup stub and have the
35667 switch happen "in between" packets, so that from remote protocol's point
35668 of view, nothing actually happened.}
35669
35670 @item B @var{addr},@var{mode}
35671 @cindex @samp{B} packet
35672 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
35673 breakpoint at @var{addr}.
35674
35675 Don't use this packet.  Use the @samp{Z} and @samp{z} packets instead
35676 (@pxref{insert breakpoint or watchpoint packet}).
35677
35678 @cindex @samp{bc} packet
35679 @anchor{bc}
35680 @item bc
35681 Backward continue.  Execute the target system in reverse.  No parameter.
35682 @xref{Reverse Execution}, for more information.
35683
35684 Reply:
35685 @xref{Stop Reply Packets}, for the reply specifications.
35686
35687 @cindex @samp{bs} packet
35688 @anchor{bs}
35689 @item bs
35690 Backward single step.  Execute one instruction in reverse.  No parameter.
35691 @xref{Reverse Execution}, for more information.
35692
35693 Reply:
35694 @xref{Stop Reply Packets}, for the reply specifications.
35695
35696 @item c @r{[}@var{addr}@r{]}
35697 @cindex @samp{c} packet
35698 Continue.  @var{addr} is address to resume.  If @var{addr} is omitted,
35699 resume at current address.
35700
35701 This packet is deprecated for multi-threading support.  @xref{vCont
35702 packet}.
35703
35704 Reply:
35705 @xref{Stop Reply Packets}, for the reply specifications.
35706
35707 @item C @var{sig}@r{[};@var{addr}@r{]}
35708 @cindex @samp{C} packet
35709 Continue with signal @var{sig} (hex signal number).  If
35710 @samp{;@var{addr}} is omitted, resume at same address.
35711
35712 This packet is deprecated for multi-threading support.  @xref{vCont
35713 packet}.
35714
35715 Reply:
35716 @xref{Stop Reply Packets}, for the reply specifications.
35717
35718 @item d
35719 @cindex @samp{d} packet
35720 Toggle debug flag.
35721
35722 Don't use this packet; instead, define a general set packet
35723 (@pxref{General Query Packets}).
35724
35725 @item D
35726 @itemx D;@var{pid}
35727 @cindex @samp{D} packet
35728 The first form of the packet is used to detach @value{GDBN} from the 
35729 remote system.  It is sent to the remote target
35730 before @value{GDBN} disconnects via the @code{detach} command.
35731
35732 The second form, including a process ID, is used when multiprocess
35733 protocol extensions are enabled (@pxref{multiprocess extensions}), to
35734 detach only a specific process.  The @var{pid} is specified as a
35735 big-endian hex string.
35736
35737 Reply:
35738 @table @samp
35739 @item OK
35740 for success
35741 @item E @var{NN}
35742 for an error
35743 @end table
35744
35745 @item F @var{RC},@var{EE},@var{CF};@var{XX}
35746 @cindex @samp{F} packet
35747 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
35748 This is part of the File-I/O protocol extension.  @xref{File-I/O
35749 Remote Protocol Extension}, for the specification.
35750
35751 @item g
35752 @anchor{read registers packet}
35753 @cindex @samp{g} packet
35754 Read general registers.
35755
35756 Reply:
35757 @table @samp
35758 @item @var{XX@dots{}}
35759 Each byte of register data is described by two hex digits.  The bytes
35760 with the register are transmitted in target byte order.  The size of
35761 each register and their position within the @samp{g} packet are
35762 determined by the @value{GDBN} internal gdbarch functions
35763 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.  The
35764 specification of several standard @samp{g} packets is specified below.
35765
35766 When reading registers from a trace frame (@pxref{Analyze Collected
35767 Data,,Using the Collected Data}), the stub may also return a string of
35768 literal @samp{x}'s in place of the register data digits, to indicate
35769 that the corresponding register has not been collected, thus its value
35770 is unavailable.  For example, for an architecture with 4 registers of
35771 4 bytes each, the following reply indicates to @value{GDBN} that
35772 registers 0 and 2 have not been collected, while registers 1 and 3
35773 have been collected, and both have zero value:
35774
35775 @smallexample
35776 -> @code{g}
35777 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
35778 @end smallexample
35779
35780 @item E @var{NN}
35781 for an error.
35782 @end table
35783
35784 @item G @var{XX@dots{}}
35785 @cindex @samp{G} packet
35786 Write general registers.  @xref{read registers packet}, for a
35787 description of the @var{XX@dots{}} data.
35788
35789 Reply:
35790 @table @samp
35791 @item OK
35792 for success
35793 @item E @var{NN}
35794 for an error
35795 @end table
35796
35797 @item H @var{op} @var{thread-id}
35798 @cindex @samp{H} packet
35799 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
35800 @samp{G}, et.al.).  @var{op} depends on the operation to be performed:
35801 it should be @samp{c} for step and continue operations (note that this
35802 is deprecated, supporting the @samp{vCont} command is a better
35803 option), @samp{g} for other operations.  The thread designator
35804 @var{thread-id} has the format and interpretation described in
35805 @ref{thread-id syntax}.
35806
35807 Reply:
35808 @table @samp
35809 @item OK
35810 for success
35811 @item E @var{NN}
35812 for an error
35813 @end table
35814
35815 @c FIXME: JTC:
35816 @c   'H': How restrictive (or permissive) is the thread model.  If a
35817 @c        thread is selected and stopped, are other threads allowed
35818 @c        to continue to execute?  As I mentioned above, I think the
35819 @c        semantics of each command when a thread is selected must be
35820 @c        described.  For example:
35821 @c
35822 @c        'g':    If the stub supports threads and a specific thread is
35823 @c                selected, returns the register block from that thread;
35824 @c                otherwise returns current registers.
35825 @c
35826 @c        'G'     If the stub supports threads and a specific thread is
35827 @c                selected, sets the registers of the register block of
35828 @c                that thread; otherwise sets current registers.
35829
35830 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
35831 @anchor{cycle step packet}
35832 @cindex @samp{i} packet
35833 Step the remote target by a single clock cycle.  If @samp{,@var{nnn}} is
35834 present, cycle step @var{nnn} cycles.  If @var{addr} is present, cycle
35835 step starting at that address.
35836
35837 @item I
35838 @cindex @samp{I} packet
35839 Signal, then cycle step.  @xref{step with signal packet}.  @xref{cycle
35840 step packet}.
35841
35842 @item k
35843 @cindex @samp{k} packet
35844 Kill request.
35845
35846 FIXME: @emph{There is no description of how to operate when a specific
35847 thread context has been selected (i.e.@: does 'k' kill only that
35848 thread?)}.
35849
35850 @item m @var{addr},@var{length}
35851 @cindex @samp{m} packet
35852 Read @var{length} bytes of memory starting at address @var{addr}.
35853 Note that @var{addr} may not be aligned to any particular boundary.
35854
35855 The stub need not use any particular size or alignment when gathering
35856 data from memory for the response; even if @var{addr} is word-aligned
35857 and @var{length} is a multiple of the word size, the stub is free to
35858 use byte accesses, or not.  For this reason, this packet may not be
35859 suitable for accessing memory-mapped I/O devices.
35860 @cindex alignment of remote memory accesses
35861 @cindex size of remote memory accesses
35862 @cindex memory, alignment and size of remote accesses
35863
35864 Reply:
35865 @table @samp
35866 @item @var{XX@dots{}}
35867 Memory contents; each byte is transmitted as a two-digit hexadecimal
35868 number.  The reply may contain fewer bytes than requested if the
35869 server was able to read only part of the region of memory.
35870 @item E @var{NN}
35871 @var{NN} is errno
35872 @end table
35873
35874 @item M @var{addr},@var{length}:@var{XX@dots{}}
35875 @cindex @samp{M} packet
35876 Write @var{length} bytes of memory starting at address @var{addr}.
35877 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
35878 hexadecimal number.
35879
35880 Reply:
35881 @table @samp
35882 @item OK
35883 for success
35884 @item E @var{NN}
35885 for an error (this includes the case where only part of the data was
35886 written).
35887 @end table
35888
35889 @item p @var{n}
35890 @cindex @samp{p} packet
35891 Read the value of register @var{n}; @var{n} is in hex.
35892 @xref{read registers packet}, for a description of how the returned
35893 register value is encoded.
35894
35895 Reply:
35896 @table @samp
35897 @item @var{XX@dots{}}
35898 the register's value
35899 @item E @var{NN}
35900 for an error
35901 @item
35902 Indicating an unrecognized @var{query}.
35903 @end table
35904
35905 @item P @var{n@dots{}}=@var{r@dots{}}
35906 @anchor{write register packet}
35907 @cindex @samp{P} packet
35908 Write register @var{n@dots{}} with value @var{r@dots{}}.  The register
35909 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
35910 digits for each byte in the register (target byte order).
35911
35912 Reply:
35913 @table @samp
35914 @item OK
35915 for success
35916 @item E @var{NN}
35917 for an error
35918 @end table
35919
35920 @item q @var{name} @var{params}@dots{}
35921 @itemx Q @var{name} @var{params}@dots{}
35922 @cindex @samp{q} packet
35923 @cindex @samp{Q} packet
35924 General query (@samp{q}) and set (@samp{Q}).  These packets are
35925 described fully in @ref{General Query Packets}.
35926
35927 @item r
35928 @cindex @samp{r} packet
35929 Reset the entire system.
35930
35931 Don't use this packet; use the @samp{R} packet instead.
35932
35933 @item R @var{XX}
35934 @cindex @samp{R} packet
35935 Restart the program being debugged.  @var{XX}, while needed, is ignored.
35936 This packet is only available in extended mode (@pxref{extended mode}).
35937
35938 The @samp{R} packet has no reply.
35939
35940 @item s @r{[}@var{addr}@r{]}
35941 @cindex @samp{s} packet
35942 Single step.  @var{addr} is the address at which to resume.  If
35943 @var{addr} is omitted, resume at same address.
35944
35945 This packet is deprecated for multi-threading support.  @xref{vCont
35946 packet}.
35947
35948 Reply:
35949 @xref{Stop Reply Packets}, for the reply specifications.
35950
35951 @item S @var{sig}@r{[};@var{addr}@r{]}
35952 @anchor{step with signal packet}
35953 @cindex @samp{S} packet
35954 Step with signal.  This is analogous to the @samp{C} packet, but
35955 requests a single-step, rather than a normal resumption of execution.
35956
35957 This packet is deprecated for multi-threading support.  @xref{vCont
35958 packet}.
35959
35960 Reply:
35961 @xref{Stop Reply Packets}, for the reply specifications.
35962
35963 @item t @var{addr}:@var{PP},@var{MM}
35964 @cindex @samp{t} packet
35965 Search backwards starting at address @var{addr} for a match with pattern
35966 @var{PP} and mask @var{MM}.  @var{PP} and @var{MM} are 4 bytes.
35967 @var{addr} must be at least 3 digits.
35968
35969 @item T @var{thread-id}
35970 @cindex @samp{T} packet
35971 Find out if the thread @var{thread-id} is alive.  @xref{thread-id syntax}.
35972
35973 Reply:
35974 @table @samp
35975 @item OK
35976 thread is still alive
35977 @item E @var{NN}
35978 thread is dead
35979 @end table
35980
35981 @item v
35982 Packets starting with @samp{v} are identified by a multi-letter name,
35983 up to the first @samp{;} or @samp{?} (or the end of the packet).
35984
35985 @item vAttach;@var{pid}
35986 @cindex @samp{vAttach} packet
35987 Attach to a new process with the specified process ID @var{pid}.
35988 The process ID is a
35989 hexadecimal integer identifying the process.  In all-stop mode, all
35990 threads in the attached process are stopped; in non-stop mode, it may be
35991 attached without being stopped if that is supported by the target.
35992
35993 @c In non-stop mode, on a successful vAttach, the stub should set the
35994 @c current thread to a thread of the newly-attached process.  After
35995 @c attaching, GDB queries for the attached process's thread ID with qC.
35996 @c Also note that, from a user perspective, whether or not the 
35997 @c target is stopped on attach in non-stop mode depends on whether you 
35998 @c use the foreground or background version of the attach command, not 
35999 @c on what vAttach does; GDB does the right thing with respect to either 
36000 @c stopping or restarting threads.
36001
36002 This packet is only available in extended mode (@pxref{extended mode}).
36003
36004 Reply:
36005 @table @samp
36006 @item E @var{nn}
36007 for an error
36008 @item @r{Any stop packet}
36009 for success in all-stop mode (@pxref{Stop Reply Packets})
36010 @item OK
36011 for success in non-stop mode (@pxref{Remote Non-Stop})
36012 @end table
36013
36014 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
36015 @cindex @samp{vCont} packet
36016 @anchor{vCont packet}
36017 Resume the inferior, specifying different actions for each thread.
36018 If an action is specified with no @var{thread-id}, then it is applied to any
36019 threads that don't have a specific action specified; if no default action is
36020 specified then other threads should remain stopped in all-stop mode and
36021 in their current state in non-stop mode.
36022 Specifying multiple
36023 default actions is an error; specifying no actions is also an error.
36024 Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
36025
36026 Currently supported actions are:
36027
36028 @table @samp
36029 @item c
36030 Continue.
36031 @item C @var{sig}
36032 Continue with signal @var{sig}.  The signal @var{sig} should be two hex digits.
36033 @item s
36034 Step.
36035 @item S @var{sig}
36036 Step with signal @var{sig}.  The signal @var{sig} should be two hex digits.
36037 @item t
36038 Stop.
36039 @end table
36040
36041 The optional argument @var{addr} normally associated with the 
36042 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
36043 not supported in @samp{vCont}.
36044
36045 The @samp{t} action is only relevant in non-stop mode
36046 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
36047 A stop reply should be generated for any affected thread not already stopped.
36048 When a thread is stopped by means of a @samp{t} action,
36049 the corresponding stop reply should indicate that the thread has stopped with
36050 signal @samp{0}, regardless of whether the target uses some other signal
36051 as an implementation detail.
36052
36053 The stub must support @samp{vCont} if it reports support for
36054 multiprocess extensions (@pxref{multiprocess extensions}).  Note that in
36055 this case @samp{vCont} actions can be specified to apply to all threads
36056 in a process by using the @samp{p@var{pid}.-1} form of the
36057 @var{thread-id}.
36058
36059 Reply:
36060 @xref{Stop Reply Packets}, for the reply specifications.
36061
36062 @item vCont?
36063 @cindex @samp{vCont?} packet
36064 Request a list of actions supported by the @samp{vCont} packet.
36065
36066 Reply:
36067 @table @samp
36068 @item vCont@r{[};@var{action}@dots{}@r{]}
36069 The @samp{vCont} packet is supported.  Each @var{action} is a supported
36070 command in the @samp{vCont} packet.
36071 @item
36072 The @samp{vCont} packet is not supported.
36073 @end table
36074
36075 @item vFile:@var{operation}:@var{parameter}@dots{}
36076 @cindex @samp{vFile} packet
36077 Perform a file operation on the target system.  For details,
36078 see @ref{Host I/O Packets}.
36079
36080 @item vFlashErase:@var{addr},@var{length}
36081 @cindex @samp{vFlashErase} packet
36082 Direct the stub to erase @var{length} bytes of flash starting at
36083 @var{addr}.  The region may enclose any number of flash blocks, but
36084 its start and end must fall on block boundaries, as indicated by the
36085 flash block size appearing in the memory map (@pxref{Memory Map
36086 Format}).  @value{GDBN} groups flash memory programming operations
36087 together, and sends a @samp{vFlashDone} request after each group; the
36088 stub is allowed to delay erase operation until the @samp{vFlashDone}
36089 packet is received.
36090
36091 Reply:
36092 @table @samp
36093 @item OK
36094 for success
36095 @item E @var{NN}
36096 for an error
36097 @end table
36098
36099 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
36100 @cindex @samp{vFlashWrite} packet
36101 Direct the stub to write data to flash address @var{addr}.  The data
36102 is passed in binary form using the same encoding as for the @samp{X}
36103 packet (@pxref{Binary Data}).  The memory ranges specified by
36104 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
36105 not overlap, and must appear in order of increasing addresses
36106 (although @samp{vFlashErase} packets for higher addresses may already
36107 have been received; the ordering is guaranteed only between
36108 @samp{vFlashWrite} packets).  If a packet writes to an address that was
36109 neither erased by a preceding @samp{vFlashErase} packet nor by some other
36110 target-specific method, the results are unpredictable.
36111
36112
36113 Reply:
36114 @table @samp
36115 @item OK
36116 for success
36117 @item E.memtype
36118 for vFlashWrite addressing non-flash memory
36119 @item E @var{NN}
36120 for an error
36121 @end table
36122
36123 @item vFlashDone
36124 @cindex @samp{vFlashDone} packet
36125 Indicate to the stub that flash programming operation is finished.
36126 The stub is permitted to delay or batch the effects of a group of
36127 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
36128 @samp{vFlashDone} packet is received.  The contents of the affected
36129 regions of flash memory are unpredictable until the @samp{vFlashDone}
36130 request is completed.
36131
36132 @item vKill;@var{pid}
36133 @cindex @samp{vKill} packet
36134 Kill the process with the specified process ID.  @var{pid} is a
36135 hexadecimal integer identifying the process.  This packet is used in
36136 preference to @samp{k} when multiprocess protocol extensions are
36137 supported; see @ref{multiprocess extensions}.
36138
36139 Reply:
36140 @table @samp
36141 @item E @var{nn}
36142 for an error
36143 @item OK
36144 for success
36145 @end table
36146
36147 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
36148 @cindex @samp{vRun} packet
36149 Run the program @var{filename}, passing it each @var{argument} on its
36150 command line.  The file and arguments are hex-encoded strings.  If
36151 @var{filename} is an empty string, the stub may use a default program
36152 (e.g.@: the last program run).  The program is created in the stopped
36153 state.
36154
36155 @c FIXME:  What about non-stop mode?
36156
36157 This packet is only available in extended mode (@pxref{extended mode}).
36158
36159 Reply:
36160 @table @samp
36161 @item E @var{nn}
36162 for an error
36163 @item @r{Any stop packet}
36164 for success (@pxref{Stop Reply Packets})
36165 @end table
36166
36167 @item vStopped
36168 @cindex @samp{vStopped} packet
36169 @xref{Notification Packets}.
36170
36171 @item X @var{addr},@var{length}:@var{XX@dots{}}
36172 @anchor{X packet}
36173 @cindex @samp{X} packet
36174 Write data to memory, where the data is transmitted in binary.
36175 @var{addr} is address, @var{length} is number of bytes,
36176 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
36177
36178 Reply:
36179 @table @samp
36180 @item OK
36181 for success
36182 @item E @var{NN}
36183 for an error
36184 @end table
36185
36186 @item z @var{type},@var{addr},@var{kind}
36187 @itemx Z @var{type},@var{addr},@var{kind}
36188 @anchor{insert breakpoint or watchpoint packet}
36189 @cindex @samp{z} packet
36190 @cindex @samp{Z} packets
36191 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
36192 watchpoint starting at address @var{address} of kind @var{kind}.
36193
36194 Each breakpoint and watchpoint packet @var{type} is documented
36195 separately.
36196
36197 @emph{Implementation notes: A remote target shall return an empty string
36198 for an unrecognized breakpoint or watchpoint packet @var{type}.  A
36199 remote target shall support either both or neither of a given
36200 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair.  To
36201 avoid potential problems with duplicate packets, the operations should
36202 be implemented in an idempotent way.}
36203
36204 @item z0,@var{addr},@var{kind}
36205 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
36206 @cindex @samp{z0} packet
36207 @cindex @samp{Z0} packet
36208 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
36209 @var{addr} of type @var{kind}.
36210
36211 A memory breakpoint is implemented by replacing the instruction at
36212 @var{addr} with a software breakpoint or trap instruction.  The
36213 @var{kind} is target-specific and typically indicates the size of
36214 the breakpoint in bytes that should be inserted.  E.g., the @sc{arm}
36215 and @sc{mips} can insert either a 2 or 4 byte breakpoint.  Some
36216 architectures have additional meanings for @var{kind};
36217 @var{cond_list} is an optional list of conditional expressions in bytecode
36218 form that should be evaluated on the target's side.  These are the
36219 conditions that should be taken into consideration when deciding if
36220 the breakpoint trigger should be reported back to @var{GDBN}.
36221
36222 The @var{cond_list} parameter is comprised of a series of expressions,
36223 concatenated without separators. Each expression has the following form:
36224
36225 @table @samp
36226
36227 @item X @var{len},@var{expr}
36228 @var{len} is the length of the bytecode expression and @var{expr} is the
36229 actual conditional expression in bytecode form.
36230
36231 @end table
36232
36233 The optional @var{cmd_list} parameter introduces commands that may be
36234 run on the target, rather than being reported back to @value{GDBN}.
36235 The parameter starts with a numeric flag @var{persist}; if the flag is
36236 nonzero, then the breakpoint may remain active and the commands
36237 continue to be run even when @value{GDBN} disconnects from the target.
36238 Following this flag is a series of expressions concatenated with no
36239 separators.  Each expression has the following form:
36240
36241 @table @samp
36242
36243 @item X @var{len},@var{expr}
36244 @var{len} is the length of the bytecode expression and @var{expr} is the
36245 actual conditional expression in bytecode form.
36246
36247 @end table
36248
36249 see @ref{Architecture-Specific Protocol Details}.
36250
36251 @emph{Implementation note: It is possible for a target to copy or move
36252 code that contains memory breakpoints (e.g., when implementing
36253 overlays).  The behavior of this packet, in the presence of such a
36254 target, is not defined.}
36255
36256 Reply:
36257 @table @samp
36258 @item OK
36259 success
36260 @item
36261 not supported
36262 @item E @var{NN}
36263 for an error
36264 @end table
36265
36266 @item z1,@var{addr},@var{kind}
36267 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
36268 @cindex @samp{z1} packet
36269 @cindex @samp{Z1} packet
36270 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
36271 address @var{addr}.
36272
36273 A hardware breakpoint is implemented using a mechanism that is not
36274 dependant on being able to modify the target's memory.  @var{kind}
36275 and @var{cond_list} have the same meaning as in @samp{Z0} packets.
36276
36277 @emph{Implementation note: A hardware breakpoint is not affected by code
36278 movement.}
36279
36280 Reply:
36281 @table @samp
36282 @item OK
36283 success
36284 @item
36285 not supported
36286 @item E @var{NN}
36287 for an error
36288 @end table
36289
36290 @item z2,@var{addr},@var{kind}
36291 @itemx Z2,@var{addr},@var{kind}
36292 @cindex @samp{z2} packet
36293 @cindex @samp{Z2} packet
36294 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
36295 @var{kind} is interpreted as the number of bytes to watch.
36296
36297 Reply:
36298 @table @samp
36299 @item OK
36300 success
36301 @item
36302 not supported
36303 @item E @var{NN}
36304 for an error
36305 @end table
36306
36307 @item z3,@var{addr},@var{kind}
36308 @itemx Z3,@var{addr},@var{kind}
36309 @cindex @samp{z3} packet
36310 @cindex @samp{Z3} packet
36311 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
36312 @var{kind} is interpreted as the number of bytes to watch.
36313
36314 Reply:
36315 @table @samp
36316 @item OK
36317 success
36318 @item
36319 not supported
36320 @item E @var{NN}
36321 for an error
36322 @end table
36323
36324 @item z4,@var{addr},@var{kind}
36325 @itemx Z4,@var{addr},@var{kind}
36326 @cindex @samp{z4} packet
36327 @cindex @samp{Z4} packet
36328 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
36329 @var{kind} is interpreted as the number of bytes to watch.
36330
36331 Reply:
36332 @table @samp
36333 @item OK
36334 success
36335 @item
36336 not supported
36337 @item E @var{NN}
36338 for an error
36339 @end table
36340
36341 @end table
36342
36343 @node Stop Reply Packets
36344 @section Stop Reply Packets
36345 @cindex stop reply packets
36346
36347 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
36348 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
36349 receive any of the below as a reply.  Except for @samp{?}
36350 and @samp{vStopped}, that reply is only returned
36351 when the target halts.  In the below the exact meaning of @dfn{signal
36352 number} is defined by the header @file{include/gdb/signals.h} in the
36353 @value{GDBN} source code.
36354
36355 As in the description of request packets, we include spaces in the
36356 reply templates for clarity; these are not part of the reply packet's
36357 syntax.  No @value{GDBN} stop reply packet uses spaces to separate its
36358 components.
36359
36360 @table @samp
36361
36362 @item S @var{AA}
36363 The program received signal number @var{AA} (a two-digit hexadecimal
36364 number).  This is equivalent to a @samp{T} response with no
36365 @var{n}:@var{r} pairs.
36366
36367 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
36368 @cindex @samp{T} packet reply
36369 The program received signal number @var{AA} (a two-digit hexadecimal
36370 number).  This is equivalent to an @samp{S} response, except that the
36371 @samp{@var{n}:@var{r}} pairs can carry values of important registers
36372 and other information directly in the stop reply packet, reducing
36373 round-trip latency.  Single-step and breakpoint traps are reported
36374 this way.  Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
36375
36376 @itemize @bullet
36377 @item
36378 If @var{n} is a hexadecimal number, it is a register number, and the
36379 corresponding @var{r} gives that register's value.  @var{r} is a
36380 series of bytes in target byte order, with each byte given by a
36381 two-digit hex number.
36382
36383 @item
36384 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
36385 the stopped thread, as specified in @ref{thread-id syntax}.
36386
36387 @item
36388 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
36389 the core on which the stop event was detected.
36390
36391 @item
36392 If @var{n} is a recognized @dfn{stop reason}, it describes a more
36393 specific event that stopped the target.  The currently defined stop
36394 reasons are listed below.  @var{aa} should be @samp{05}, the trap
36395 signal.  At most one stop reason should be present.
36396
36397 @item
36398 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
36399 and go on to the next; this allows us to extend the protocol in the
36400 future.
36401 @end itemize
36402
36403 The currently defined stop reasons are:
36404
36405 @table @samp
36406 @item watch
36407 @itemx rwatch
36408 @itemx awatch
36409 The packet indicates a watchpoint hit, and @var{r} is the data address, in
36410 hex.
36411
36412 @cindex shared library events, remote reply
36413 @item library
36414 The packet indicates that the loaded libraries have changed.
36415 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
36416 list of loaded libraries.  @var{r} is ignored.
36417
36418 @cindex replay log events, remote reply
36419 @item replaylog
36420 The packet indicates that the target cannot continue replaying 
36421 logged execution events, because it has reached the end (or the
36422 beginning when executing backward) of the log.  The value of @var{r}
36423 will be either @samp{begin} or @samp{end}.  @xref{Reverse Execution}, 
36424 for more information.
36425 @end table
36426
36427 @item W @var{AA}
36428 @itemx W @var{AA} ; process:@var{pid}
36429 The process exited, and @var{AA} is the exit status.  This is only
36430 applicable to certain targets.
36431
36432 The second form of the response, including the process ID of the exited
36433 process, can be used only when @value{GDBN} has reported support for
36434 multiprocess protocol extensions; see @ref{multiprocess extensions}.
36435 The @var{pid} is formatted as a big-endian hex string.
36436
36437 @item X @var{AA}
36438 @itemx X @var{AA} ; process:@var{pid}
36439 The process terminated with signal @var{AA}.
36440
36441 The second form of the response, including the process ID of the
36442 terminated process, can be used only when @value{GDBN} has reported
36443 support for multiprocess protocol extensions; see @ref{multiprocess
36444 extensions}.  The @var{pid} is formatted as a big-endian hex string.
36445
36446 @item O @var{XX}@dots{}
36447 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
36448 written as the program's console output.  This can happen at any time
36449 while the program is running and the debugger should continue to wait
36450 for @samp{W}, @samp{T}, etc.  This reply is not permitted in non-stop mode.
36451
36452 @item F @var{call-id},@var{parameter}@dots{}
36453 @var{call-id} is the identifier which says which host system call should
36454 be called.  This is just the name of the function.  Translation into the
36455 correct system call is only applicable as it's defined in @value{GDBN}.
36456 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
36457 system calls.
36458
36459 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
36460 this very system call.
36461
36462 The target replies with this packet when it expects @value{GDBN} to
36463 call a host system call on behalf of the target.  @value{GDBN} replies
36464 with an appropriate @samp{F} packet and keeps up waiting for the next
36465 reply packet from the target.  The latest @samp{C}, @samp{c}, @samp{S}
36466 or @samp{s} action is expected to be continued.  @xref{File-I/O Remote
36467 Protocol Extension}, for more details.
36468
36469 @end table
36470
36471 @node General Query Packets
36472 @section General Query Packets
36473 @cindex remote query requests
36474
36475 Packets starting with @samp{q} are @dfn{general query packets};
36476 packets starting with @samp{Q} are @dfn{general set packets}.  General
36477 query and set packets are a semi-unified form for retrieving and
36478 sending information to and from the stub.
36479
36480 The initial letter of a query or set packet is followed by a name
36481 indicating what sort of thing the packet applies to.  For example,
36482 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
36483 definitions with the stub.  These packet names follow some
36484 conventions:
36485
36486 @itemize @bullet
36487 @item
36488 The name must not contain commas, colons or semicolons.
36489 @item
36490 Most @value{GDBN} query and set packets have a leading upper case
36491 letter.
36492 @item
36493 The names of custom vendor packets should use a company prefix, in
36494 lower case, followed by a period.  For example, packets designed at
36495 the Acme Corporation might begin with @samp{qacme.foo} (for querying
36496 foos) or @samp{Qacme.bar} (for setting bars).
36497 @end itemize
36498
36499 The name of a query or set packet should be separated from any
36500 parameters by a @samp{:}; the parameters themselves should be
36501 separated by @samp{,} or @samp{;}.  Stubs must be careful to match the
36502 full packet name, and check for a separator or the end of the packet,
36503 in case two packet names share a common prefix.  New packets should not begin
36504 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
36505 packets predate these conventions, and have arguments without any terminator
36506 for the packet name; we suspect they are in widespread use in places that
36507 are difficult to upgrade.  The @samp{qC} packet has no arguments, but some
36508 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
36509 packet.}.
36510
36511 Like the descriptions of the other packets, each description here
36512 has a template showing the packet's overall syntax, followed by an
36513 explanation of the packet's meaning.  We include spaces in some of the
36514 templates for clarity; these are not part of the packet's syntax.  No
36515 @value{GDBN} packet uses spaces to separate its components.
36516
36517 Here are the currently defined query and set packets:
36518
36519 @table @samp
36520
36521 @item QAgent:1
36522 @itemx QAgent:0
36523 Turn on or off the agent as a helper to perform some debugging operations
36524 delegated from @value{GDBN} (@pxref{Control Agent}).
36525
36526 @item QAllow:@var{op}:@var{val}@dots{}
36527 @cindex @samp{QAllow} packet
36528 Specify which operations @value{GDBN} expects to request of the
36529 target, as a semicolon-separated list of operation name and value
36530 pairs.  Possible values for @var{op} include @samp{WriteReg},
36531 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
36532 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
36533 indicating that @value{GDBN} will not request the operation, or 1,
36534 indicating that it may.  (The target can then use this to set up its
36535 own internals optimally, for instance if the debugger never expects to
36536 insert breakpoints, it may not need to install its own trap handler.)
36537
36538 @item qC
36539 @cindex current thread, remote request
36540 @cindex @samp{qC} packet
36541 Return the current thread ID.
36542
36543 Reply:
36544 @table @samp
36545 @item QC @var{thread-id}
36546 Where @var{thread-id} is a thread ID as documented in 
36547 @ref{thread-id syntax}.
36548 @item @r{(anything else)}
36549 Any other reply implies the old thread ID.
36550 @end table
36551
36552 @item qCRC:@var{addr},@var{length}
36553 @cindex CRC of memory block, remote request
36554 @cindex @samp{qCRC} packet
36555 Compute the CRC checksum of a block of memory using CRC-32 defined in
36556 IEEE 802.3.  The CRC is computed byte at a time, taking the most
36557 significant bit of each byte first.  The initial pattern code
36558 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
36559
36560 @emph{Note:} This is the same CRC used in validating separate debug
36561 files (@pxref{Separate Debug Files, , Debugging Information in Separate
36562 Files}).  However the algorithm is slightly different.  When validating
36563 separate debug files, the CRC is computed taking the @emph{least}
36564 significant bit of each byte first, and the final result is inverted to
36565 detect trailing zeros.
36566
36567 Reply:
36568 @table @samp
36569 @item E @var{NN}
36570 An error (such as memory fault)
36571 @item C @var{crc32}
36572 The specified memory region's checksum is @var{crc32}.
36573 @end table
36574
36575 @item QDisableRandomization:@var{value}
36576 @cindex disable address space randomization, remote request
36577 @cindex @samp{QDisableRandomization} packet
36578 Some target operating systems will randomize the virtual address space
36579 of the inferior process as a security feature, but provide a feature
36580 to disable such randomization, e.g.@: to allow for a more deterministic
36581 debugging experience.  On such systems, this packet with a @var{value}
36582 of 1 directs the target to disable address space randomization for
36583 processes subsequently started via @samp{vRun} packets, while a packet
36584 with a @var{value} of 0 tells the target to enable address space
36585 randomization.
36586
36587 This packet is only available in extended mode (@pxref{extended mode}).
36588
36589 Reply:
36590 @table @samp
36591 @item OK
36592 The request succeeded.
36593
36594 @item E @var{nn}
36595 An error occurred.  @var{nn} are hex digits.
36596
36597 @item
36598 An empty reply indicates that @samp{QDisableRandomization} is not supported
36599 by the stub.
36600 @end table
36601
36602 This packet is not probed by default; the remote stub must request it,
36603 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36604 This should only be done on targets that actually support disabling
36605 address space randomization.
36606
36607 @item qfThreadInfo
36608 @itemx qsThreadInfo
36609 @cindex list active threads, remote request
36610 @cindex @samp{qfThreadInfo} packet
36611 @cindex @samp{qsThreadInfo} packet
36612 Obtain a list of all active thread IDs from the target (OS).  Since there
36613 may be too many active threads to fit into one reply packet, this query
36614 works iteratively: it may require more than one query/reply sequence to
36615 obtain the entire list of threads.  The first query of the sequence will
36616 be the @samp{qfThreadInfo} query; subsequent queries in the
36617 sequence will be the @samp{qsThreadInfo} query.
36618
36619 NOTE: This packet replaces the @samp{qL} query (see below).
36620
36621 Reply:
36622 @table @samp
36623 @item m @var{thread-id}
36624 A single thread ID
36625 @item m @var{thread-id},@var{thread-id}@dots{}
36626 a comma-separated list of thread IDs
36627 @item l
36628 (lower case letter @samp{L}) denotes end of list.
36629 @end table
36630
36631 In response to each query, the target will reply with a list of one or
36632 more thread IDs, separated by commas.
36633 @value{GDBN} will respond to each reply with a request for more thread
36634 ids (using the @samp{qs} form of the query), until the target responds
36635 with @samp{l} (lower-case ell, for @dfn{last}).
36636 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
36637 fields.
36638
36639 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
36640 @cindex get thread-local storage address, remote request
36641 @cindex @samp{qGetTLSAddr} packet
36642 Fetch the address associated with thread local storage specified
36643 by @var{thread-id}, @var{offset}, and @var{lm}.
36644
36645 @var{thread-id} is the thread ID associated with the
36646 thread for which to fetch the TLS address.  @xref{thread-id syntax}.
36647
36648 @var{offset} is the (big endian, hex encoded) offset associated with the
36649 thread local variable.  (This offset is obtained from the debug
36650 information associated with the variable.)
36651
36652 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
36653 load module associated with the thread local storage.  For example,
36654 a @sc{gnu}/Linux system will pass the link map address of the shared
36655 object associated with the thread local storage under consideration. 
36656 Other operating environments may choose to represent the load module
36657 differently, so the precise meaning of this parameter will vary.
36658
36659 Reply:
36660 @table @samp
36661 @item @var{XX}@dots{}
36662 Hex encoded (big endian) bytes representing the address of the thread
36663 local storage requested.
36664
36665 @item E @var{nn}
36666 An error occurred.  @var{nn} are hex digits.
36667
36668 @item
36669 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
36670 @end table
36671
36672 @item qGetTIBAddr:@var{thread-id}
36673 @cindex get thread information block address
36674 @cindex @samp{qGetTIBAddr} packet
36675 Fetch address of the Windows OS specific Thread Information Block.
36676
36677 @var{thread-id} is the thread ID associated with the thread.
36678
36679 Reply:
36680 @table @samp
36681 @item @var{XX}@dots{}
36682 Hex encoded (big endian) bytes representing the linear address of the
36683 thread information block.
36684
36685 @item E @var{nn}
36686 An error occured.  This means that either the thread was not found, or the
36687 address could not be retrieved.
36688
36689 @item
36690 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
36691 @end table
36692
36693 @item qL @var{startflag} @var{threadcount} @var{nextthread}
36694 Obtain thread information from RTOS.  Where: @var{startflag} (one hex
36695 digit) is one to indicate the first query and zero to indicate a
36696 subsequent query; @var{threadcount} (two hex digits) is the maximum
36697 number of threads the response packet can contain; and @var{nextthread}
36698 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
36699 returned in the response as @var{argthread}.
36700
36701 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
36702
36703 Reply:
36704 @table @samp
36705 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
36706 Where: @var{count} (two hex digits) is the number of threads being
36707 returned; @var{done} (one hex digit) is zero to indicate more threads
36708 and one indicates no further threads; @var{argthreadid} (eight hex
36709 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
36710 is a sequence of thread IDs from the target.  @var{threadid} (eight hex
36711 digits).  See @code{remote.c:parse_threadlist_response()}.
36712 @end table
36713
36714 @item qOffsets
36715 @cindex section offsets, remote request
36716 @cindex @samp{qOffsets} packet
36717 Get section offsets that the target used when relocating the downloaded
36718 image.
36719
36720 Reply:
36721 @table @samp
36722 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
36723 Relocate the @code{Text} section by @var{xxx} from its original address.
36724 Relocate the @code{Data} section by @var{yyy} from its original address.
36725 If the object file format provides segment information (e.g.@: @sc{elf}
36726 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
36727 segments by the supplied offsets.
36728
36729 @emph{Note: while a @code{Bss} offset may be included in the response,
36730 @value{GDBN} ignores this and instead applies the @code{Data} offset
36731 to the @code{Bss} section.}
36732
36733 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
36734 Relocate the first segment of the object file, which conventionally
36735 contains program code, to a starting address of @var{xxx}.  If
36736 @samp{DataSeg} is specified, relocate the second segment, which
36737 conventionally contains modifiable data, to a starting address of
36738 @var{yyy}.  @value{GDBN} will report an error if the object file
36739 does not contain segment information, or does not contain at least
36740 as many segments as mentioned in the reply.  Extra segments are
36741 kept at fixed offsets relative to the last relocated segment.
36742 @end table
36743
36744 @item qP @var{mode} @var{thread-id}
36745 @cindex thread information, remote request
36746 @cindex @samp{qP} packet
36747 Returns information on @var{thread-id}.  Where: @var{mode} is a hex
36748 encoded 32 bit mode; @var{thread-id} is a thread ID 
36749 (@pxref{thread-id syntax}).
36750
36751 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
36752 (see below).
36753
36754 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
36755
36756 @item QNonStop:1
36757 @itemx QNonStop:0
36758 @cindex non-stop mode, remote request
36759 @cindex @samp{QNonStop} packet
36760 @anchor{QNonStop}
36761 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
36762 @xref{Remote Non-Stop}, for more information.
36763
36764 Reply:
36765 @table @samp
36766 @item OK
36767 The request succeeded.
36768
36769 @item E @var{nn}
36770 An error occurred.  @var{nn} are hex digits.
36771
36772 @item
36773 An empty reply indicates that @samp{QNonStop} is not supported by
36774 the stub.
36775 @end table
36776
36777 This packet is not probed by default; the remote stub must request it,
36778 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36779 Use of this packet is controlled by the @code{set non-stop} command; 
36780 @pxref{Non-Stop Mode}.
36781
36782 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
36783 @cindex pass signals to inferior, remote request
36784 @cindex @samp{QPassSignals} packet
36785 @anchor{QPassSignals}
36786 Each listed @var{signal} should be passed directly to the inferior process. 
36787 Signals are numbered identically to continue packets and stop replies
36788 (@pxref{Stop Reply Packets}).  Each @var{signal} list item should be
36789 strictly greater than the previous item.  These signals do not need to stop
36790 the inferior, or be reported to @value{GDBN}.  All other signals should be
36791 reported to @value{GDBN}.  Multiple @samp{QPassSignals} packets do not
36792 combine; any earlier @samp{QPassSignals} list is completely replaced by the
36793 new list.  This packet improves performance when using @samp{handle
36794 @var{signal} nostop noprint pass}.
36795
36796 Reply:
36797 @table @samp
36798 @item OK
36799 The request succeeded.
36800
36801 @item E @var{nn}
36802 An error occurred.  @var{nn} are hex digits.
36803
36804 @item
36805 An empty reply indicates that @samp{QPassSignals} is not supported by
36806 the stub.
36807 @end table
36808
36809 Use of this packet is controlled by the @code{set remote pass-signals}
36810 command (@pxref{Remote Configuration, set remote pass-signals}).
36811 This packet is not probed by default; the remote stub must request it,
36812 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36813
36814 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
36815 @cindex signals the inferior may see, remote request
36816 @cindex @samp{QProgramSignals} packet
36817 @anchor{QProgramSignals}
36818 Each listed @var{signal} may be delivered to the inferior process.
36819 Others should be silently discarded.
36820
36821 In some cases, the remote stub may need to decide whether to deliver a
36822 signal to the program or not without @value{GDBN} involvement.  One
36823 example of that is while detaching --- the program's threads may have
36824 stopped for signals that haven't yet had a chance of being reported to
36825 @value{GDBN}, and so the remote stub can use the signal list specified
36826 by this packet to know whether to deliver or ignore those pending
36827 signals.
36828
36829 This does not influence whether to deliver a signal as requested by a
36830 resumption packet (@pxref{vCont packet}).
36831
36832 Signals are numbered identically to continue packets and stop replies
36833 (@pxref{Stop Reply Packets}).  Each @var{signal} list item should be
36834 strictly greater than the previous item.  Multiple
36835 @samp{QProgramSignals} packets do not combine; any earlier
36836 @samp{QProgramSignals} list is completely replaced by the new list.
36837
36838 Reply:
36839 @table @samp
36840 @item OK
36841 The request succeeded.
36842
36843 @item E @var{nn}
36844 An error occurred.  @var{nn} are hex digits.
36845
36846 @item
36847 An empty reply indicates that @samp{QProgramSignals} is not supported
36848 by the stub.
36849 @end table
36850
36851 Use of this packet is controlled by the @code{set remote program-signals}
36852 command (@pxref{Remote Configuration, set remote program-signals}).
36853 This packet is not probed by default; the remote stub must request it,
36854 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
36855
36856 @item qRcmd,@var{command}
36857 @cindex execute remote command, remote request
36858 @cindex @samp{qRcmd} packet
36859 @var{command} (hex encoded) is passed to the local interpreter for
36860 execution.  Invalid commands should be reported using the output
36861 string.  Before the final result packet, the target may also respond
36862 with a number of intermediate @samp{O@var{output}} console output
36863 packets.  @emph{Implementors should note that providing access to a
36864 stubs's interpreter may have security implications}.
36865
36866 Reply:
36867 @table @samp
36868 @item OK
36869 A command response with no output.
36870 @item @var{OUTPUT}
36871 A command response with the hex encoded output string @var{OUTPUT}.
36872 @item E @var{NN}
36873 Indicate a badly formed request.
36874 @item
36875 An empty reply indicates that @samp{qRcmd} is not recognized.
36876 @end table
36877
36878 (Note that the @code{qRcmd} packet's name is separated from the
36879 command by a @samp{,}, not a @samp{:}, contrary to the naming
36880 conventions above.  Please don't use this packet as a model for new
36881 packets.)
36882
36883 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
36884 @cindex searching memory, in remote debugging
36885 @cindex @samp{qSearch:memory} packet
36886 @anchor{qSearch memory}
36887 Search @var{length} bytes at @var{address} for @var{search-pattern}.
36888 @var{address} and @var{length} are encoded in hex.
36889 @var{search-pattern} is a sequence of bytes, hex encoded.
36890
36891 Reply:
36892 @table @samp
36893 @item 0
36894 The pattern was not found.
36895 @item 1,address
36896 The pattern was found at @var{address}.
36897 @item E @var{NN}
36898 A badly formed request or an error was encountered while searching memory.
36899 @item
36900 An empty reply indicates that @samp{qSearch:memory} is not recognized.
36901 @end table
36902
36903 @item QStartNoAckMode
36904 @cindex @samp{QStartNoAckMode} packet
36905 @anchor{QStartNoAckMode}
36906 Request that the remote stub disable the normal @samp{+}/@samp{-}
36907 protocol acknowledgments (@pxref{Packet Acknowledgment}).
36908
36909 Reply:
36910 @table @samp
36911 @item OK
36912 The stub has switched to no-acknowledgment mode.
36913 @value{GDBN} acknowledges this reponse,
36914 but neither the stub nor @value{GDBN} shall send or expect further
36915 @samp{+}/@samp{-} acknowledgments in the current connection.
36916 @item
36917 An empty reply indicates that the stub does not support no-acknowledgment mode.
36918 @end table
36919
36920 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
36921 @cindex supported packets, remote query
36922 @cindex features of the remote protocol
36923 @cindex @samp{qSupported} packet
36924 @anchor{qSupported}
36925 Tell the remote stub about features supported by @value{GDBN}, and
36926 query the stub for features it supports.  This packet allows
36927 @value{GDBN} and the remote stub to take advantage of each others'
36928 features.  @samp{qSupported} also consolidates multiple feature probes
36929 at startup, to improve @value{GDBN} performance---a single larger
36930 packet performs better than multiple smaller probe packets on
36931 high-latency links.  Some features may enable behavior which must not
36932 be on by default, e.g.@: because it would confuse older clients or
36933 stubs.  Other features may describe packets which could be
36934 automatically probed for, but are not.  These features must be
36935 reported before @value{GDBN} will use them.  This ``default
36936 unsupported'' behavior is not appropriate for all packets, but it
36937 helps to keep the initial connection time under control with new
36938 versions of @value{GDBN} which support increasing numbers of packets.
36939
36940 Reply:
36941 @table @samp
36942 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
36943 The stub supports or does not support each returned @var{stubfeature},
36944 depending on the form of each @var{stubfeature} (see below for the
36945 possible forms).
36946 @item
36947 An empty reply indicates that @samp{qSupported} is not recognized,
36948 or that no features needed to be reported to @value{GDBN}.
36949 @end table
36950
36951 The allowed forms for each feature (either a @var{gdbfeature} in the
36952 @samp{qSupported} packet, or a @var{stubfeature} in the response)
36953 are:
36954
36955 @table @samp
36956 @item @var{name}=@var{value}
36957 The remote protocol feature @var{name} is supported, and associated
36958 with the specified @var{value}.  The format of @var{value} depends
36959 on the feature, but it must not include a semicolon.
36960 @item @var{name}+
36961 The remote protocol feature @var{name} is supported, and does not
36962 need an associated value.
36963 @item @var{name}-
36964 The remote protocol feature @var{name} is not supported.
36965 @item @var{name}?
36966 The remote protocol feature @var{name} may be supported, and
36967 @value{GDBN} should auto-detect support in some other way when it is
36968 needed.  This form will not be used for @var{gdbfeature} notifications,
36969 but may be used for @var{stubfeature} responses.
36970 @end table
36971
36972 Whenever the stub receives a @samp{qSupported} request, the
36973 supplied set of @value{GDBN} features should override any previous
36974 request.  This allows @value{GDBN} to put the stub in a known
36975 state, even if the stub had previously been communicating with
36976 a different version of @value{GDBN}.
36977
36978 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
36979 are defined:  
36980
36981 @table @samp
36982 @item multiprocess
36983 This feature indicates whether @value{GDBN} supports multiprocess 
36984 extensions to the remote protocol.  @value{GDBN} does not use such
36985 extensions unless the stub also reports that it supports them by
36986 including @samp{multiprocess+} in its @samp{qSupported} reply.
36987 @xref{multiprocess extensions}, for details.
36988
36989 @item xmlRegisters
36990 This feature indicates that @value{GDBN} supports the XML target
36991 description.  If the stub sees @samp{xmlRegisters=} with target
36992 specific strings separated by a comma, it will report register
36993 description.
36994
36995 @item qRelocInsn
36996 This feature indicates whether @value{GDBN} supports the
36997 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
36998 instruction reply packet}).
36999 @end table
37000
37001 Stubs should ignore any unknown values for
37002 @var{gdbfeature}.  Any @value{GDBN} which sends a @samp{qSupported}
37003 packet supports receiving packets of unlimited length (earlier
37004 versions of @value{GDBN} may reject overly long responses).  Additional values
37005 for @var{gdbfeature} may be defined in the future to let the stub take
37006 advantage of new features in @value{GDBN}, e.g.@: incompatible
37007 improvements in the remote protocol---the @samp{multiprocess} feature is
37008 an example of such a feature.  The stub's reply should be independent
37009 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
37010 describes all the features it supports, and then the stub replies with
37011 all the features it supports.
37012
37013 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
37014 responses, as long as each response uses one of the standard forms.
37015
37016 Some features are flags.  A stub which supports a flag feature
37017 should respond with a @samp{+} form response.  Other features
37018 require values, and the stub should respond with an @samp{=}
37019 form response.
37020
37021 Each feature has a default value, which @value{GDBN} will use if
37022 @samp{qSupported} is not available or if the feature is not mentioned
37023 in the @samp{qSupported} response.  The default values are fixed; a
37024 stub is free to omit any feature responses that match the defaults.
37025
37026 Not all features can be probed, but for those which can, the probing
37027 mechanism is useful: in some cases, a stub's internal
37028 architecture may not allow the protocol layer to know some information
37029 about the underlying target in advance.  This is especially common in
37030 stubs which may be configured for multiple targets.
37031
37032 These are the currently defined stub features and their properties:
37033
37034 @multitable @columnfractions 0.35 0.2 0.12 0.2
37035 @c NOTE: The first row should be @headitem, but we do not yet require
37036 @c a new enough version of Texinfo (4.7) to use @headitem.
37037 @item Feature Name
37038 @tab Value Required
37039 @tab Default
37040 @tab Probe Allowed
37041
37042 @item @samp{PacketSize}
37043 @tab Yes
37044 @tab @samp{-}
37045 @tab No
37046
37047 @item @samp{qXfer:auxv:read}
37048 @tab No
37049 @tab @samp{-}
37050 @tab Yes
37051
37052 @item @samp{qXfer:features:read}
37053 @tab No
37054 @tab @samp{-}
37055 @tab Yes
37056
37057 @item @samp{qXfer:libraries:read}
37058 @tab No
37059 @tab @samp{-}
37060 @tab Yes
37061
37062 @item @samp{qXfer:memory-map:read}
37063 @tab No
37064 @tab @samp{-}
37065 @tab Yes
37066
37067 @item @samp{qXfer:sdata:read}
37068 @tab No
37069 @tab @samp{-}
37070 @tab Yes
37071
37072 @item @samp{qXfer:spu:read}
37073 @tab No
37074 @tab @samp{-}
37075 @tab Yes
37076
37077 @item @samp{qXfer:spu:write}
37078 @tab No
37079 @tab @samp{-}
37080 @tab Yes
37081
37082 @item @samp{qXfer:siginfo:read}
37083 @tab No
37084 @tab @samp{-}
37085 @tab Yes
37086
37087 @item @samp{qXfer:siginfo:write}
37088 @tab No
37089 @tab @samp{-}
37090 @tab Yes
37091
37092 @item @samp{qXfer:threads:read}
37093 @tab No
37094 @tab @samp{-}
37095 @tab Yes
37096
37097 @item @samp{qXfer:traceframe-info:read}
37098 @tab No
37099 @tab @samp{-}
37100 @tab Yes
37101
37102 @item @samp{qXfer:uib:read}
37103 @tab No
37104 @tab @samp{-}
37105 @tab Yes
37106
37107 @item @samp{qXfer:fdpic:read}
37108 @tab No
37109 @tab @samp{-}
37110 @tab Yes
37111
37112 @item @samp{QNonStop}
37113 @tab No
37114 @tab @samp{-}
37115 @tab Yes
37116
37117 @item @samp{QPassSignals}
37118 @tab No
37119 @tab @samp{-}
37120 @tab Yes
37121
37122 @item @samp{QStartNoAckMode}
37123 @tab No
37124 @tab @samp{-}
37125 @tab Yes
37126
37127 @item @samp{multiprocess}
37128 @tab No
37129 @tab @samp{-}
37130 @tab No
37131
37132 @item @samp{ConditionalBreakpoints}
37133 @tab No
37134 @tab @samp{-}
37135 @tab No
37136
37137 @item @samp{ConditionalTracepoints}
37138 @tab No
37139 @tab @samp{-}
37140 @tab No
37141
37142 @item @samp{ReverseContinue}
37143 @tab No
37144 @tab @samp{-}
37145 @tab No
37146
37147 @item @samp{ReverseStep}
37148 @tab No
37149 @tab @samp{-}
37150 @tab No
37151
37152 @item @samp{TracepointSource}
37153 @tab No
37154 @tab @samp{-}
37155 @tab No
37156
37157 @item @samp{QAgent}
37158 @tab No
37159 @tab @samp{-}
37160 @tab No
37161
37162 @item @samp{QAllow}
37163 @tab No
37164 @tab @samp{-}
37165 @tab No
37166
37167 @item @samp{QDisableRandomization}
37168 @tab No
37169 @tab @samp{-}
37170 @tab No
37171
37172 @item @samp{EnableDisableTracepoints}
37173 @tab No
37174 @tab @samp{-}
37175 @tab No
37176
37177 @item @samp{tracenz}
37178 @tab No
37179 @tab @samp{-}
37180 @tab No
37181
37182 @item @samp{BreakpointCommands}
37183 @tab No
37184 @tab @samp{-}
37185 @tab No
37186
37187 @end multitable
37188
37189 These are the currently defined stub features, in more detail:
37190
37191 @table @samp
37192 @cindex packet size, remote protocol
37193 @item PacketSize=@var{bytes}
37194 The remote stub can accept packets up to at least @var{bytes} in
37195 length.  @value{GDBN} will send packets up to this size for bulk
37196 transfers, and will never send larger packets.  This is a limit on the
37197 data characters in the packet, including the frame and checksum.
37198 There is no trailing NUL byte in a remote protocol packet; if the stub
37199 stores packets in a NUL-terminated format, it should allow an extra
37200 byte in its buffer for the NUL.  If this stub feature is not supported,
37201 @value{GDBN} guesses based on the size of the @samp{g} packet response.
37202
37203 @item qXfer:auxv:read
37204 The remote stub understands the @samp{qXfer:auxv:read} packet
37205 (@pxref{qXfer auxiliary vector read}).
37206
37207 @item qXfer:features:read
37208 The remote stub understands the @samp{qXfer:features:read} packet
37209 (@pxref{qXfer target description read}).
37210
37211 @item qXfer:libraries:read
37212 The remote stub understands the @samp{qXfer:libraries:read} packet
37213 (@pxref{qXfer library list read}).
37214
37215 @item qXfer:libraries-svr4:read
37216 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
37217 (@pxref{qXfer svr4 library list read}).
37218
37219 @item qXfer:memory-map:read
37220 The remote stub understands the @samp{qXfer:memory-map:read} packet
37221 (@pxref{qXfer memory map read}).
37222
37223 @item qXfer:sdata:read
37224 The remote stub understands the @samp{qXfer:sdata:read} packet
37225 (@pxref{qXfer sdata read}).
37226
37227 @item qXfer:spu:read
37228 The remote stub understands the @samp{qXfer:spu:read} packet
37229 (@pxref{qXfer spu read}).
37230
37231 @item qXfer:spu:write
37232 The remote stub understands the @samp{qXfer:spu:write} packet
37233 (@pxref{qXfer spu write}).
37234
37235 @item qXfer:siginfo:read
37236 The remote stub understands the @samp{qXfer:siginfo:read} packet
37237 (@pxref{qXfer siginfo read}).
37238
37239 @item qXfer:siginfo:write
37240 The remote stub understands the @samp{qXfer:siginfo:write} packet
37241 (@pxref{qXfer siginfo write}).
37242
37243 @item qXfer:threads:read
37244 The remote stub understands the @samp{qXfer:threads:read} packet
37245 (@pxref{qXfer threads read}).
37246
37247 @item qXfer:traceframe-info:read
37248 The remote stub understands the @samp{qXfer:traceframe-info:read}
37249 packet (@pxref{qXfer traceframe info read}).
37250
37251 @item qXfer:uib:read
37252 The remote stub understands the @samp{qXfer:uib:read}
37253 packet (@pxref{qXfer unwind info block}).
37254
37255 @item qXfer:fdpic:read
37256 The remote stub understands the @samp{qXfer:fdpic:read}
37257 packet (@pxref{qXfer fdpic loadmap read}).
37258
37259 @item QNonStop
37260 The remote stub understands the @samp{QNonStop} packet
37261 (@pxref{QNonStop}).
37262
37263 @item QPassSignals
37264 The remote stub understands the @samp{QPassSignals} packet
37265 (@pxref{QPassSignals}).
37266
37267 @item QStartNoAckMode
37268 The remote stub understands the @samp{QStartNoAckMode} packet and
37269 prefers to operate in no-acknowledgment mode.  @xref{Packet Acknowledgment}.
37270
37271 @item multiprocess
37272 @anchor{multiprocess extensions}
37273 @cindex multiprocess extensions, in remote protocol
37274 The remote stub understands the multiprocess extensions to the remote
37275 protocol syntax.  The multiprocess extensions affect the syntax of
37276 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
37277 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
37278 replies.  Note that reporting this feature indicates support for the
37279 syntactic extensions only, not that the stub necessarily supports
37280 debugging of more than one process at a time.  The stub must not use
37281 multiprocess extensions in packet replies unless @value{GDBN} has also
37282 indicated it supports them in its @samp{qSupported} request.
37283
37284 @item qXfer:osdata:read
37285 The remote stub understands the @samp{qXfer:osdata:read} packet
37286 ((@pxref{qXfer osdata read}).
37287
37288 @item ConditionalBreakpoints
37289 The target accepts and implements evaluation of conditional expressions
37290 defined for breakpoints.  The target will only report breakpoint triggers
37291 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
37292
37293 @item ConditionalTracepoints
37294 The remote stub accepts and implements conditional expressions defined
37295 for tracepoints (@pxref{Tracepoint Conditions}).
37296
37297 @item ReverseContinue
37298 The remote stub accepts and implements the reverse continue packet
37299 (@pxref{bc}).
37300
37301 @item ReverseStep
37302 The remote stub accepts and implements the reverse step packet
37303 (@pxref{bs}).
37304
37305 @item TracepointSource
37306 The remote stub understands the @samp{QTDPsrc} packet that supplies
37307 the source form of tracepoint definitions.
37308
37309 @item QAgent
37310 The remote stub understands the @samp{QAgent} packet.
37311
37312 @item QAllow
37313 The remote stub understands the @samp{QAllow} packet.
37314
37315 @item QDisableRandomization
37316 The remote stub understands the @samp{QDisableRandomization} packet.
37317
37318 @item StaticTracepoint
37319 @cindex static tracepoints, in remote protocol
37320 The remote stub supports static tracepoints.
37321
37322 @item InstallInTrace
37323 @anchor{install tracepoint in tracing}
37324 The remote stub supports installing tracepoint in tracing.
37325
37326 @item EnableDisableTracepoints
37327 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
37328 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
37329 to be enabled and disabled while a trace experiment is running.
37330
37331 @item tracenz
37332 @cindex string tracing, in remote protocol
37333 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
37334 See @ref{Bytecode Descriptions} for details about the bytecode.
37335
37336 @item BreakpointCommands
37337 @cindex breakpoint commands, in remote protocol
37338 The remote stub supports running a breakpoint's command list itself,
37339 rather than reporting the hit to @value{GDBN}.
37340
37341 @end table
37342
37343 @item qSymbol::
37344 @cindex symbol lookup, remote request
37345 @cindex @samp{qSymbol} packet
37346 Notify the target that @value{GDBN} is prepared to serve symbol lookup
37347 requests.  Accept requests from the target for the values of symbols.
37348
37349 Reply:
37350 @table @samp
37351 @item OK
37352 The target does not need to look up any (more) symbols.
37353 @item qSymbol:@var{sym_name}
37354 The target requests the value of symbol @var{sym_name} (hex encoded).
37355 @value{GDBN} may provide the value by using the
37356 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
37357 below.
37358 @end table
37359
37360 @item qSymbol:@var{sym_value}:@var{sym_name}
37361 Set the value of @var{sym_name} to @var{sym_value}.
37362
37363 @var{sym_name} (hex encoded) is the name of a symbol whose value the
37364 target has previously requested.
37365
37366 @var{sym_value} (hex) is the value for symbol @var{sym_name}.  If
37367 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
37368 will be empty.
37369
37370 Reply:
37371 @table @samp
37372 @item OK
37373 The target does not need to look up any (more) symbols.
37374 @item qSymbol:@var{sym_name}
37375 The target requests the value of a new symbol @var{sym_name} (hex
37376 encoded).  @value{GDBN} will continue to supply the values of symbols
37377 (if available), until the target ceases to request them.
37378 @end table
37379
37380 @item qTBuffer
37381 @itemx QTBuffer
37382 @itemx QTDisconnected
37383 @itemx QTDP
37384 @itemx QTDPsrc
37385 @itemx QTDV
37386 @itemx qTfP
37387 @itemx qTfV
37388 @itemx QTFrame
37389 @itemx qTMinFTPILen
37390
37391 @xref{Tracepoint Packets}.
37392
37393 @item qThreadExtraInfo,@var{thread-id}
37394 @cindex thread attributes info, remote request
37395 @cindex @samp{qThreadExtraInfo} packet
37396 Obtain a printable string description of a thread's attributes from
37397 the target OS.  @var{thread-id} is a thread ID; 
37398 see @ref{thread-id syntax}.  This
37399 string may contain anything that the target OS thinks is interesting
37400 for @value{GDBN} to tell the user about the thread.  The string is
37401 displayed in @value{GDBN}'s @code{info threads} display.  Some
37402 examples of possible thread extra info strings are @samp{Runnable}, or
37403 @samp{Blocked on Mutex}.
37404
37405 Reply:
37406 @table @samp
37407 @item @var{XX}@dots{}
37408 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
37409 comprising the printable string containing the extra information about
37410 the thread's attributes.
37411 @end table
37412
37413 (Note that the @code{qThreadExtraInfo} packet's name is separated from
37414 the command by a @samp{,}, not a @samp{:}, contrary to the naming
37415 conventions above.  Please don't use this packet as a model for new
37416 packets.)
37417
37418 @item QTNotes
37419 @itemx qTP
37420 @itemx QTSave
37421 @itemx qTsP
37422 @itemx qTsV
37423 @itemx QTStart    
37424 @itemx QTStop     
37425 @itemx QTEnable
37426 @itemx QTDisable
37427 @itemx QTinit     
37428 @itemx QTro       
37429 @itemx qTStatus   
37430 @itemx qTV
37431 @itemx qTfSTM
37432 @itemx qTsSTM
37433 @itemx qTSTMat
37434 @xref{Tracepoint Packets}.
37435
37436 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
37437 @cindex read special object, remote request
37438 @cindex @samp{qXfer} packet
37439 @anchor{qXfer read}
37440 Read uninterpreted bytes from the target's special data area
37441 identified by the keyword @var{object}.  Request @var{length} bytes
37442 starting at @var{offset} bytes into the data.  The content and
37443 encoding of @var{annex} is specific to @var{object}; it can supply
37444 additional details about what data to access.
37445
37446 Here are the specific requests of this form defined so far.  All
37447 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
37448 formats, listed below.
37449
37450 @table @samp
37451 @item qXfer:auxv:read::@var{offset},@var{length}
37452 @anchor{qXfer auxiliary vector read}
37453 Access the target's @dfn{auxiliary vector}.  @xref{OS Information,
37454 auxiliary vector}.  Note @var{annex} must be empty.
37455
37456 This packet is not probed by default; the remote stub must request it,
37457 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37458
37459 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
37460 @anchor{qXfer target description read}
37461 Access the @dfn{target description}.  @xref{Target Descriptions}.  The
37462 annex specifies which XML document to access.  The main description is
37463 always loaded from the @samp{target.xml} annex.
37464
37465 This packet is not probed by default; the remote stub must request it,
37466 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37467
37468 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
37469 @anchor{qXfer library list read}
37470 Access the target's list of loaded libraries.  @xref{Library List Format}.
37471 The annex part of the generic @samp{qXfer} packet must be empty
37472 (@pxref{qXfer read}).
37473
37474 Targets which maintain a list of libraries in the program's memory do
37475 not need to implement this packet; it is designed for platforms where
37476 the operating system manages the list of loaded libraries.
37477
37478 This packet is not probed by default; the remote stub must request it,
37479 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37480
37481 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
37482 @anchor{qXfer svr4 library list read}
37483 Access the target's list of loaded libraries when the target is an SVR4
37484 platform.  @xref{Library List Format for SVR4 Targets}.  The annex part
37485 of the generic @samp{qXfer} packet must be empty (@pxref{qXfer read}).
37486
37487 This packet is optional for better performance on SVR4 targets.  
37488 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
37489
37490 This packet is not probed by default; the remote stub must request it,
37491 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37492
37493 @item qXfer:memory-map:read::@var{offset},@var{length}
37494 @anchor{qXfer memory map read}
37495 Access the target's @dfn{memory-map}.  @xref{Memory Map Format}.  The
37496 annex part of the generic @samp{qXfer} packet must be empty
37497 (@pxref{qXfer read}).
37498
37499 This packet is not probed by default; the remote stub must request it,
37500 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37501
37502 @item qXfer:sdata:read::@var{offset},@var{length}
37503 @anchor{qXfer sdata read}
37504
37505 Read contents of the extra collected static tracepoint marker
37506 information.  The annex part of the generic @samp{qXfer} packet must
37507 be empty (@pxref{qXfer read}).  @xref{Tracepoint Actions,,Tracepoint
37508 Action Lists}.
37509
37510 This packet is not probed by default; the remote stub must request it,
37511 by supplying an appropriate @samp{qSupported} response
37512 (@pxref{qSupported}).
37513
37514 @item qXfer:siginfo:read::@var{offset},@var{length}
37515 @anchor{qXfer siginfo read}
37516 Read contents of the extra signal information on the target
37517 system.  The annex part of the generic @samp{qXfer} packet must be
37518 empty (@pxref{qXfer read}).
37519
37520 This packet is not probed by default; the remote stub must request it,
37521 by supplying an appropriate @samp{qSupported} response
37522 (@pxref{qSupported}).
37523
37524 @item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
37525 @anchor{qXfer spu read}
37526 Read contents of an @code{spufs} file on the target system.  The
37527 annex specifies which file to read; it must be of the form 
37528 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37529 in the target process, and @var{name} identifes the @code{spufs} file
37530 in that context to be accessed.
37531
37532 This packet is not probed by default; the remote stub must request it,
37533 by supplying an appropriate @samp{qSupported} response
37534 (@pxref{qSupported}).
37535
37536 @item qXfer:threads:read::@var{offset},@var{length}
37537 @anchor{qXfer threads read}
37538 Access the list of threads on target.  @xref{Thread List Format}.  The
37539 annex part of the generic @samp{qXfer} packet must be empty
37540 (@pxref{qXfer read}).
37541
37542 This packet is not probed by default; the remote stub must request it,
37543 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37544
37545 @item qXfer:traceframe-info:read::@var{offset},@var{length}
37546 @anchor{qXfer traceframe info read}
37547
37548 Return a description of the current traceframe's contents.
37549 @xref{Traceframe Info Format}.  The annex part of the generic
37550 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
37551
37552 This packet is not probed by default; the remote stub must request it,
37553 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37554
37555 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
37556 @anchor{qXfer unwind info block}
37557
37558 Return the unwind information block for @var{pc}.  This packet is used
37559 on OpenVMS/ia64 to ask the kernel unwind information.
37560
37561 This packet is not probed by default.
37562
37563 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
37564 @anchor{qXfer fdpic loadmap read}
37565 Read contents of @code{loadmap}s on the target system.  The
37566 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
37567 executable @code{loadmap} or interpreter @code{loadmap} to read.
37568
37569 This packet is not probed by default; the remote stub must request it,
37570 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37571
37572 @item qXfer:osdata:read::@var{offset},@var{length}
37573 @anchor{qXfer osdata read}
37574 Access the target's @dfn{operating system information}.  
37575 @xref{Operating System Information}.
37576
37577 @end table
37578
37579 Reply:
37580 @table @samp
37581 @item m @var{data}
37582 Data @var{data} (@pxref{Binary Data}) has been read from the
37583 target.  There may be more data at a higher address (although
37584 it is permitted to return @samp{m} even for the last valid
37585 block of data, as long as at least one byte of data was read).
37586 @var{data} may have fewer bytes than the @var{length} in the
37587 request.
37588
37589 @item l @var{data}
37590 Data @var{data} (@pxref{Binary Data}) has been read from the target.
37591 There is no more data to be read.  @var{data} may have fewer bytes
37592 than the @var{length} in the request.
37593
37594 @item l
37595 The @var{offset} in the request is at the end of the data.
37596 There is no more data to be read.
37597
37598 @item E00
37599 The request was malformed, or @var{annex} was invalid.
37600
37601 @item E @var{nn}
37602 The offset was invalid, or there was an error encountered reading the data.
37603 @var{nn} is a hex-encoded @code{errno} value.
37604
37605 @item
37606 An empty reply indicates the @var{object} string was not recognized by
37607 the stub, or that the object does not support reading.
37608 @end table
37609
37610 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
37611 @cindex write data into object, remote request
37612 @anchor{qXfer write}
37613 Write uninterpreted bytes into the target's special data area
37614 identified by the keyword @var{object}, starting at @var{offset} bytes
37615 into the data.  @var{data}@dots{} is the binary-encoded data
37616 (@pxref{Binary Data}) to be written.  The content and encoding of @var{annex}
37617 is specific to @var{object}; it can supply additional details about what data
37618 to access.
37619
37620 Here are the specific requests of this form defined so far.  All
37621 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
37622 formats, listed below.
37623
37624 @table @samp
37625 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
37626 @anchor{qXfer siginfo write}
37627 Write @var{data} to the extra signal information on the target system.
37628 The annex part of the generic @samp{qXfer} packet must be
37629 empty (@pxref{qXfer write}).
37630
37631 This packet is not probed by default; the remote stub must request it,
37632 by supplying an appropriate @samp{qSupported} response
37633 (@pxref{qSupported}).
37634
37635 @item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
37636 @anchor{qXfer spu write}
37637 Write @var{data} to an @code{spufs} file on the target system.  The
37638 annex specifies which file to write; it must be of the form
37639 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
37640 in the target process, and @var{name} identifes the @code{spufs} file
37641 in that context to be accessed.
37642
37643 This packet is not probed by default; the remote stub must request it,
37644 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
37645 @end table
37646
37647 Reply:
37648 @table @samp
37649 @item @var{nn}
37650 @var{nn} (hex encoded) is the number of bytes written.
37651 This may be fewer bytes than supplied in the request.
37652
37653 @item E00
37654 The request was malformed, or @var{annex} was invalid.
37655
37656 @item E @var{nn}
37657 The offset was invalid, or there was an error encountered writing the data.
37658 @var{nn} is a hex-encoded @code{errno} value.
37659
37660 @item
37661 An empty reply indicates the @var{object} string was not
37662 recognized by the stub, or that the object does not support writing.
37663 @end table
37664
37665 @item qXfer:@var{object}:@var{operation}:@dots{}
37666 Requests of this form may be added in the future.  When a stub does
37667 not recognize the @var{object} keyword, or its support for
37668 @var{object} does not recognize the @var{operation} keyword, the stub
37669 must respond with an empty packet.
37670
37671 @item qAttached:@var{pid}
37672 @cindex query attached, remote request
37673 @cindex @samp{qAttached} packet
37674 Return an indication of whether the remote server attached to an
37675 existing process or created a new process.  When the multiprocess
37676 protocol extensions are supported (@pxref{multiprocess extensions}),
37677 @var{pid} is an integer in hexadecimal format identifying the target
37678 process.  Otherwise, @value{GDBN} will omit the @var{pid} field and
37679 the query packet will be simplified as @samp{qAttached}.
37680
37681 This query is used, for example, to know whether the remote process
37682 should be detached or killed when a @value{GDBN} session is ended with
37683 the @code{quit} command.
37684
37685 Reply:
37686 @table @samp
37687 @item 1
37688 The remote server attached to an existing process.
37689 @item 0
37690 The remote server created a new process.
37691 @item E @var{NN}
37692 A badly formed request or an error was encountered.
37693 @end table
37694
37695 @end table
37696
37697 @node Architecture-Specific Protocol Details
37698 @section Architecture-Specific Protocol Details
37699
37700 This section describes how the remote protocol is applied to specific
37701 target architectures.  Also see @ref{Standard Target Features}, for
37702 details of XML target descriptions for each architecture.
37703
37704 @menu
37705 * ARM-Specific Protocol Details::
37706 * MIPS-Specific Protocol Details::
37707 @end menu
37708
37709 @node ARM-Specific Protocol Details
37710 @subsection @acronym{ARM}-specific Protocol Details
37711
37712 @menu
37713 * ARM Breakpoint Kinds::
37714 @end menu
37715
37716 @node ARM Breakpoint Kinds
37717 @subsubsection @acronym{ARM} Breakpoint Kinds
37718 @cindex breakpoint kinds, @acronym{ARM}
37719
37720 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
37721
37722 @table @r
37723
37724 @item 2
37725 16-bit Thumb mode breakpoint.
37726
37727 @item 3
37728 32-bit Thumb mode (Thumb-2) breakpoint.
37729
37730 @item 4
37731 32-bit @acronym{ARM} mode breakpoint.
37732
37733 @end table
37734
37735 @node MIPS-Specific Protocol Details
37736 @subsection @acronym{MIPS}-specific Protocol Details
37737
37738 @menu
37739 * MIPS Register packet Format::
37740 * MIPS Breakpoint Kinds::
37741 @end menu
37742
37743 @node MIPS Register packet Format
37744 @subsubsection @acronym{MIPS} Register Packet Format
37745 @cindex register packet format, @acronym{MIPS}
37746
37747 The following @code{g}/@code{G} packets have previously been defined.
37748 In the below, some thirty-two bit registers are transferred as
37749 sixty-four bits.  Those registers should be zero/sign extended (which?)
37750 to fill the space allocated.  Register bytes are transferred in target
37751 byte order.  The two nibbles within a register byte are transferred
37752 most-significant -- least-significant.
37753
37754 @table @r
37755
37756 @item MIPS32
37757 All registers are transferred as thirty-two bit quantities in the order:
37758 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
37759 registers; fsr; fir; fp.
37760
37761 @item MIPS64
37762 All registers are transferred as sixty-four bit quantities (including
37763 thirty-two bit registers such as @code{sr}).  The ordering is the same
37764 as @code{MIPS32}.
37765
37766 @end table
37767
37768 @node MIPS Breakpoint Kinds
37769 @subsubsection @acronym{MIPS} Breakpoint Kinds
37770 @cindex breakpoint kinds, @acronym{MIPS}
37771
37772 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
37773
37774 @table @r
37775
37776 @item 2
37777 16-bit @acronym{MIPS16} mode breakpoint.
37778
37779 @item 3
37780 16-bit @acronym{microMIPS} mode breakpoint.
37781
37782 @item 4
37783 32-bit standard @acronym{MIPS} mode breakpoint.
37784
37785 @item 5
37786 32-bit @acronym{microMIPS} mode breakpoint.
37787
37788 @end table
37789
37790 @node Tracepoint Packets
37791 @section Tracepoint Packets
37792 @cindex tracepoint packets
37793 @cindex packets, tracepoint
37794
37795 Here we describe the packets @value{GDBN} uses to implement
37796 tracepoints (@pxref{Tracepoints}).
37797
37798 @table @samp
37799
37800 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
37801 @cindex @samp{QTDP} packet
37802 Create a new tracepoint, number @var{n}, at @var{addr}.  If @var{ena}
37803 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
37804 the tracepoint is disabled.  @var{step} is the tracepoint's step
37805 count, and @var{pass} is its pass count.  If an @samp{F} is present,
37806 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
37807 the number of bytes that the target should copy elsewhere to make room
37808 for the tracepoint.  If an @samp{X} is present, it introduces a
37809 tracepoint condition, which consists of a hexadecimal length, followed
37810 by a comma and hex-encoded bytes, in a manner similar to action
37811 encodings as described below.  If the trailing @samp{-} is present,
37812 further @samp{QTDP} packets will follow to specify this tracepoint's
37813 actions.
37814
37815 Replies:
37816 @table @samp
37817 @item OK
37818 The packet was understood and carried out.
37819 @item qRelocInsn
37820 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
37821 @item 
37822 The packet was not recognized.
37823 @end table
37824
37825 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
37826 Define actions to be taken when a tracepoint is hit.  @var{n} and
37827 @var{addr} must be the same as in the initial @samp{QTDP} packet for
37828 this tracepoint.  This packet may only be sent immediately after
37829 another @samp{QTDP} packet that ended with a @samp{-}.  If the
37830 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
37831 specifying more actions for this tracepoint.
37832
37833 In the series of action packets for a given tracepoint, at most one
37834 can have an @samp{S} before its first @var{action}.  If such a packet
37835 is sent, it and the following packets define ``while-stepping''
37836 actions.  Any prior packets define ordinary actions --- that is, those
37837 taken when the tracepoint is first hit.  If no action packet has an
37838 @samp{S}, then all the packets in the series specify ordinary
37839 tracepoint actions.
37840
37841 The @samp{@var{action}@dots{}} portion of the packet is a series of
37842 actions, concatenated without separators.  Each action has one of the
37843 following forms:
37844
37845 @table @samp
37846
37847 @item R @var{mask}
37848 Collect the registers whose bits are set in @var{mask}.  @var{mask} is
37849 a hexadecimal number whose @var{i}'th bit is set if register number
37850 @var{i} should be collected.  (The least significant bit is numbered
37851 zero.)  Note that @var{mask} may be any number of digits long; it may
37852 not fit in a 32-bit word.
37853
37854 @item M @var{basereg},@var{offset},@var{len}
37855 Collect @var{len} bytes of memory starting at the address in register
37856 number @var{basereg}, plus @var{offset}.  If @var{basereg} is
37857 @samp{-1}, then the range has a fixed address: @var{offset} is the
37858 address of the lowest byte to collect.  The @var{basereg},
37859 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
37860 values (the @samp{-1} value for @var{basereg} is a special case).
37861
37862 @item X @var{len},@var{expr}
37863 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
37864 it directs.  @var{expr} is an agent expression, as described in
37865 @ref{Agent Expressions}.  Each byte of the expression is encoded as a
37866 two-digit hex number in the packet; @var{len} is the number of bytes
37867 in the expression (and thus one-half the number of hex digits in the
37868 packet).
37869
37870 @end table
37871
37872 Any number of actions may be packed together in a single @samp{QTDP}
37873 packet, as long as the packet does not exceed the maximum packet
37874 length (400 bytes, for many stubs).  There may be only one @samp{R}
37875 action per tracepoint, and it must precede any @samp{M} or @samp{X}
37876 actions.  Any registers referred to by @samp{M} and @samp{X} actions
37877 must be collected by a preceding @samp{R} action.  (The
37878 ``while-stepping'' actions are treated as if they were attached to a
37879 separate tracepoint, as far as these restrictions are concerned.)
37880
37881 Replies:
37882 @table @samp
37883 @item OK
37884 The packet was understood and carried out.
37885 @item qRelocInsn
37886 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
37887 @item 
37888 The packet was not recognized.
37889 @end table
37890
37891 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
37892 @cindex @samp{QTDPsrc} packet
37893 Specify a source string of tracepoint @var{n} at address @var{addr}.
37894 This is useful to get accurate reproduction of the tracepoints
37895 originally downloaded at the beginning of the trace run.  @var{type}
37896 is the name of the tracepoint part, such as @samp{cond} for the
37897 tracepoint's conditional expression (see below for a list of types), while
37898 @var{bytes} is the string, encoded in hexadecimal.
37899
37900 @var{start} is the offset of the @var{bytes} within the overall source
37901 string, while @var{slen} is the total length of the source string.
37902 This is intended for handling source strings that are longer than will
37903 fit in a single packet.
37904 @c Add detailed example when this info is moved into a dedicated
37905 @c tracepoint descriptions section.
37906
37907 The available string types are @samp{at} for the location,
37908 @samp{cond} for the conditional, and @samp{cmd} for an action command.
37909 @value{GDBN} sends a separate packet for each command in the action
37910 list, in the same order in which the commands are stored in the list.
37911
37912 The target does not need to do anything with source strings except
37913 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
37914 query packets.
37915
37916 Although this packet is optional, and @value{GDBN} will only send it
37917 if the target replies with @samp{TracepointSource} @xref{General
37918 Query Packets}, it makes both disconnected tracing and trace files
37919 much easier to use.  Otherwise the user must be careful that the
37920 tracepoints in effect while looking at trace frames are identical to
37921 the ones in effect during the trace run; even a small discrepancy
37922 could cause @samp{tdump} not to work, or a particular trace frame not
37923 be found.
37924
37925 @item QTDV:@var{n}:@var{value}
37926 @cindex define trace state variable, remote request
37927 @cindex @samp{QTDV} packet
37928 Create a new trace state variable, number @var{n}, with an initial
37929 value of @var{value}, which is a 64-bit signed integer.  Both @var{n}
37930 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
37931 the option of not using this packet for initial values of zero; the
37932 target should simply create the trace state variables as they are
37933 mentioned in expressions.
37934
37935 @item QTFrame:@var{n}
37936 @cindex @samp{QTFrame} packet
37937 Select the @var{n}'th tracepoint frame from the buffer, and use the
37938 register and memory contents recorded there to answer subsequent
37939 request packets from @value{GDBN}.
37940
37941 A successful reply from the stub indicates that the stub has found the
37942 requested frame.  The response is a series of parts, concatenated
37943 without separators, describing the frame we selected.  Each part has
37944 one of the following forms:
37945
37946 @table @samp
37947 @item F @var{f}
37948 The selected frame is number @var{n} in the trace frame buffer;
37949 @var{f} is a hexadecimal number.  If @var{f} is @samp{-1}, then there
37950 was no frame matching the criteria in the request packet.
37951
37952 @item T @var{t}
37953 The selected trace frame records a hit of tracepoint number @var{t};
37954 @var{t} is a hexadecimal number.
37955
37956 @end table
37957
37958 @item QTFrame:pc:@var{addr}
37959 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
37960 currently selected frame whose PC is @var{addr};
37961 @var{addr} is a hexadecimal number.
37962
37963 @item QTFrame:tdp:@var{t}
37964 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
37965 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
37966 is a hexadecimal number.
37967
37968 @item QTFrame:range:@var{start}:@var{end}
37969 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
37970 currently selected frame whose PC is between @var{start} (inclusive)
37971 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
37972 numbers.
37973
37974 @item QTFrame:outside:@var{start}:@var{end}
37975 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
37976 frame @emph{outside} the given range of addresses (exclusive).
37977
37978 @item qTMinFTPILen
37979 @cindex @samp{qTMinFTPILen} packet
37980 This packet requests the minimum length of instruction at which a fast
37981 tracepoint (@pxref{Set Tracepoints}) may be placed.  For instance, on
37982 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
37983 it depends on the target system being able to create trampolines in
37984 the first 64K of memory, which might or might not be possible for that
37985 system.  So the reply to this packet will be 4 if it is able to
37986 arrange for that.
37987
37988 Replies:
37989
37990 @table @samp
37991 @item 0
37992 The minimum instruction length is currently unknown.
37993 @item @var{length}
37994 The minimum instruction length is @var{length}, where @var{length} is greater
37995 or equal to 1.  @var{length} is a hexadecimal number.  A reply of 1 means
37996 that a fast tracepoint may be placed on any instruction regardless of size.
37997 @item E
37998 An error has occurred.
37999 @item
38000 An empty reply indicates that the request is not supported by the stub.
38001 @end table
38002
38003 @item QTStart
38004 @cindex @samp{QTStart} packet
38005 Begin the tracepoint experiment.  Begin collecting data from
38006 tracepoint hits in the trace frame buffer.  This packet supports the
38007 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
38008 instruction reply packet}).
38009
38010 @item QTStop
38011 @cindex @samp{QTStop} packet
38012 End the tracepoint experiment.  Stop collecting trace frames.
38013
38014 @item QTEnable:@var{n}:@var{addr}
38015 @anchor{QTEnable}
38016 @cindex @samp{QTEnable} packet
38017 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
38018 experiment.  If the tracepoint was previously disabled, then collection
38019 of data from it will resume.
38020
38021 @item QTDisable:@var{n}:@var{addr}
38022 @anchor{QTDisable}
38023 @cindex @samp{QTDisable} packet
38024 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
38025 experiment.  No more data will be collected from the tracepoint unless
38026 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
38027
38028 @item QTinit
38029 @cindex @samp{QTinit} packet
38030 Clear the table of tracepoints, and empty the trace frame buffer.
38031
38032 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
38033 @cindex @samp{QTro} packet
38034 Establish the given ranges of memory as ``transparent''.  The stub
38035 will answer requests for these ranges from memory's current contents,
38036 if they were not collected as part of the tracepoint hit.
38037
38038 @value{GDBN} uses this to mark read-only regions of memory, like those
38039 containing program code.  Since these areas never change, they should
38040 still have the same contents they did when the tracepoint was hit, so
38041 there's no reason for the stub to refuse to provide their contents.
38042
38043 @item QTDisconnected:@var{value}
38044 @cindex @samp{QTDisconnected} packet
38045 Set the choice to what to do with the tracing run when @value{GDBN}
38046 disconnects from the target.  A @var{value} of 1 directs the target to
38047 continue the tracing run, while 0 tells the target to stop tracing if
38048 @value{GDBN} is no longer in the picture.
38049
38050 @item qTStatus
38051 @cindex @samp{qTStatus} packet
38052 Ask the stub if there is a trace experiment running right now.
38053
38054 The reply has the form:
38055
38056 @table @samp
38057
38058 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
38059 @var{running} is a single digit @code{1} if the trace is presently
38060 running, or @code{0} if not.  It is followed by semicolon-separated
38061 optional fields that an agent may use to report additional status.
38062
38063 @end table
38064
38065 If the trace is not running, the agent may report any of several
38066 explanations as one of the optional fields:
38067
38068 @table @samp
38069
38070 @item tnotrun:0
38071 No trace has been run yet.
38072
38073 @item tstop[:@var{text}]:0
38074 The trace was stopped by a user-originated stop command.  The optional
38075 @var{text} field is a user-supplied string supplied as part of the
38076 stop command (for instance, an explanation of why the trace was
38077 stopped manually).  It is hex-encoded.
38078
38079 @item tfull:0
38080 The trace stopped because the trace buffer filled up.
38081
38082 @item tdisconnected:0
38083 The trace stopped because @value{GDBN} disconnected from the target.
38084
38085 @item tpasscount:@var{tpnum}
38086 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
38087
38088 @item terror:@var{text}:@var{tpnum}
38089 The trace stopped because tracepoint @var{tpnum} had an error.  The
38090 string @var{text} is available to describe the nature of the error
38091 (for instance, a divide by zero in the condition expression).
38092 @var{text} is hex encoded.
38093
38094 @item tunknown:0
38095 The trace stopped for some other reason.
38096
38097 @end table
38098
38099 Additional optional fields supply statistical and other information.
38100 Although not required, they are extremely useful for users monitoring
38101 the progress of a trace run.  If a trace has stopped, and these
38102 numbers are reported, they must reflect the state of the just-stopped
38103 trace.
38104
38105 @table @samp
38106
38107 @item tframes:@var{n}
38108 The number of trace frames in the buffer.
38109
38110 @item tcreated:@var{n}
38111 The total number of trace frames created during the run. This may
38112 be larger than the trace frame count, if the buffer is circular.
38113
38114 @item tsize:@var{n}
38115 The total size of the trace buffer, in bytes.
38116
38117 @item tfree:@var{n}
38118 The number of bytes still unused in the buffer.
38119
38120 @item circular:@var{n}
38121 The value of the circular trace buffer flag.  @code{1} means that the
38122 trace buffer is circular and old trace frames will be discarded if
38123 necessary to make room, @code{0} means that the trace buffer is linear
38124 and may fill up.
38125
38126 @item disconn:@var{n}
38127 The value of the disconnected tracing flag.  @code{1} means that
38128 tracing will continue after @value{GDBN} disconnects, @code{0} means
38129 that the trace run will stop.
38130
38131 @end table
38132
38133 @item qTP:@var{tp}:@var{addr}
38134 @cindex tracepoint status, remote request
38135 @cindex @samp{qTP} packet
38136 Ask the stub for the current state of tracepoint number @var{tp} at
38137 address @var{addr}.
38138
38139 Replies:
38140 @table @samp
38141 @item V@var{hits}:@var{usage}
38142 The tracepoint has been hit @var{hits} times so far during the trace
38143 run, and accounts for @var{usage} in the trace buffer.  Note that
38144 @code{while-stepping} steps are not counted as separate hits, but the
38145 steps' space consumption is added into the usage number.
38146
38147 @end table
38148
38149 @item qTV:@var{var}
38150 @cindex trace state variable value, remote request
38151 @cindex @samp{qTV} packet
38152 Ask the stub for the value of the trace state variable number @var{var}.
38153
38154 Replies:
38155 @table @samp
38156 @item V@var{value}
38157 The value of the variable is @var{value}.  This will be the current
38158 value of the variable if the user is examining a running target, or a
38159 saved value if the variable was collected in the trace frame that the
38160 user is looking at.  Note that multiple requests may result in
38161 different reply values, such as when requesting values while the
38162 program is running.
38163
38164 @item U
38165 The value of the variable is unknown.  This would occur, for example,
38166 if the user is examining a trace frame in which the requested variable
38167 was not collected.
38168 @end table
38169
38170 @item qTfP
38171 @cindex @samp{qTfP} packet
38172 @itemx qTsP
38173 @cindex @samp{qTsP} packet
38174 These packets request data about tracepoints that are being used by
38175 the target.  @value{GDBN} sends @code{qTfP} to get the first piece
38176 of data, and multiple @code{qTsP} to get additional pieces.  Replies
38177 to these packets generally take the form of the @code{QTDP} packets
38178 that define tracepoints. (FIXME add detailed syntax)
38179
38180 @item qTfV
38181 @cindex @samp{qTfV} packet
38182 @itemx qTsV
38183 @cindex @samp{qTsV} packet
38184 These packets request data about trace state variables that are on the
38185 target.  @value{GDBN} sends @code{qTfV} to get the first vari of data,
38186 and multiple @code{qTsV} to get additional variables.  Replies to
38187 these packets follow the syntax of the @code{QTDV} packets that define
38188 trace state variables.
38189
38190 @item qTfSTM
38191 @itemx qTsSTM
38192 @anchor{qTfSTM}
38193 @anchor{qTsSTM}
38194 @cindex @samp{qTfSTM} packet
38195 @cindex @samp{qTsSTM} packet
38196 These packets request data about static tracepoint markers that exist
38197 in the target program.  @value{GDBN} sends @code{qTfSTM} to get the
38198 first piece of data, and multiple @code{qTsSTM} to get additional
38199 pieces.  Replies to these packets take the following form:
38200
38201 Reply:
38202 @table @samp
38203 @item m @var{address}:@var{id}:@var{extra}
38204 A single marker
38205 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
38206 a comma-separated list of markers
38207 @item l
38208 (lower case letter @samp{L}) denotes end of list.
38209 @item E @var{nn}
38210 An error occurred.  @var{nn} are hex digits.
38211 @item
38212 An empty reply indicates that the request is not supported by the
38213 stub.
38214 @end table
38215
38216 @var{address} is encoded in hex.
38217 @var{id} and @var{extra} are strings encoded in hex.
38218
38219 In response to each query, the target will reply with a list of one or
38220 more markers, separated by commas.  @value{GDBN} will respond to each
38221 reply with a request for more markers (using the @samp{qs} form of the
38222 query), until the target responds with @samp{l} (lower-case ell, for
38223 @dfn{last}).
38224
38225 @item qTSTMat:@var{address}
38226 @anchor{qTSTMat}
38227 @cindex @samp{qTSTMat} packet
38228 This packets requests data about static tracepoint markers in the
38229 target program at @var{address}.  Replies to this packet follow the
38230 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
38231 tracepoint markers.
38232
38233 @item QTSave:@var{filename}
38234 @cindex @samp{QTSave} packet
38235 This packet directs the target to save trace data to the file name
38236 @var{filename} in the target's filesystem.  @var{filename} is encoded
38237 as a hex string; the interpretation of the file name (relative vs
38238 absolute, wild cards, etc) is up to the target.
38239
38240 @item qTBuffer:@var{offset},@var{len}
38241 @cindex @samp{qTBuffer} packet
38242 Return up to @var{len} bytes of the current contents of trace buffer,
38243 starting at @var{offset}.  The trace buffer is treated as if it were
38244 a contiguous collection of traceframes, as per the trace file format.
38245 The reply consists as many hex-encoded bytes as the target can deliver
38246 in a packet; it is not an error to return fewer than were asked for.
38247 A reply consisting of just @code{l} indicates that no bytes are
38248 available.
38249
38250 @item QTBuffer:circular:@var{value}
38251 This packet directs the target to use a circular trace buffer if
38252 @var{value} is 1, or a linear buffer if the value is 0.
38253
38254 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
38255 @cindex @samp{QTNotes} packet
38256 This packet adds optional textual notes to the trace run.  Allowable
38257 types include @code{user}, @code{notes}, and @code{tstop}, the
38258 @var{text} fields are arbitrary strings, hex-encoded.
38259
38260 @end table
38261
38262 @subsection Relocate instruction reply packet
38263 When installing fast tracepoints in memory, the target may need to
38264 relocate the instruction currently at the tracepoint address to a
38265 different address in memory.  For most instructions, a simple copy is
38266 enough, but, for example, call instructions that implicitly push the
38267 return address on the stack, and relative branches or other
38268 PC-relative instructions require offset adjustment, so that the effect
38269 of executing the instruction at a different address is the same as if
38270 it had executed in the original location.
38271
38272 In response to several of the tracepoint packets, the target may also
38273 respond with a number of intermediate @samp{qRelocInsn} request
38274 packets before the final result packet, to have @value{GDBN} handle
38275 this relocation operation.  If a packet supports this mechanism, its
38276 documentation will explicitly say so.  See for example the above
38277 descriptions for the @samp{QTStart} and @samp{QTDP} packets.  The
38278 format of the request is:
38279
38280 @table @samp
38281 @item qRelocInsn:@var{from};@var{to}
38282
38283 This requests @value{GDBN} to copy instruction at address @var{from}
38284 to address @var{to}, possibly adjusted so that executing the
38285 instruction at @var{to} has the same effect as executing it at
38286 @var{from}.  @value{GDBN} writes the adjusted instruction to target
38287 memory starting at @var{to}.
38288 @end table
38289
38290 Replies:
38291 @table @samp
38292 @item qRelocInsn:@var{adjusted_size}
38293 Informs the stub the relocation is complete.  @var{adjusted_size} is
38294 the length in bytes of resulting relocated instruction sequence.
38295 @item E @var{NN}
38296 A badly formed request was detected, or an error was encountered while
38297 relocating the instruction.
38298 @end table
38299
38300 @node Host I/O Packets
38301 @section Host I/O Packets
38302 @cindex Host I/O, remote protocol
38303 @cindex file transfer, remote protocol
38304
38305 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
38306 operations on the far side of a remote link.  For example, Host I/O is
38307 used to upload and download files to a remote target with its own
38308 filesystem.  Host I/O uses the same constant values and data structure
38309 layout as the target-initiated File-I/O protocol.  However, the
38310 Host I/O packets are structured differently.  The target-initiated
38311 protocol relies on target memory to store parameters and buffers.
38312 Host I/O requests are initiated by @value{GDBN}, and the
38313 target's memory is not involved.  @xref{File-I/O Remote Protocol
38314 Extension}, for more details on the target-initiated protocol.
38315
38316 The Host I/O request packets all encode a single operation along with
38317 its arguments.  They have this format:
38318
38319 @table @samp
38320
38321 @item vFile:@var{operation}: @var{parameter}@dots{}
38322 @var{operation} is the name of the particular request; the target
38323 should compare the entire packet name up to the second colon when checking
38324 for a supported operation.  The format of @var{parameter} depends on
38325 the operation.  Numbers are always passed in hexadecimal.  Negative
38326 numbers have an explicit minus sign (i.e.@: two's complement is not
38327 used).  Strings (e.g.@: filenames) are encoded as a series of
38328 hexadecimal bytes.  The last argument to a system call may be a
38329 buffer of escaped binary data (@pxref{Binary Data}).
38330
38331 @end table
38332
38333 The valid responses to Host I/O packets are:
38334
38335 @table @samp
38336
38337 @item F @var{result} [, @var{errno}] [; @var{attachment}]
38338 @var{result} is the integer value returned by this operation, usually
38339 non-negative for success and -1 for errors.  If an error has occured,
38340 @var{errno} will be included in the result.  @var{errno} will have a
38341 value defined by the File-I/O protocol (@pxref{Errno Values}).  For
38342 operations which return data, @var{attachment} supplies the data as a
38343 binary buffer.  Binary buffers in response packets are escaped in the
38344 normal way (@pxref{Binary Data}).  See the individual packet
38345 documentation for the interpretation of @var{result} and
38346 @var{attachment}.
38347
38348 @item
38349 An empty response indicates that this operation is not recognized.
38350
38351 @end table
38352
38353 These are the supported Host I/O operations:
38354
38355 @table @samp
38356 @item vFile:open: @var{pathname}, @var{flags}, @var{mode}
38357 Open a file at @var{pathname} and return a file descriptor for it, or
38358 return -1 if an error occurs.  @var{pathname} is a string,
38359 @var{flags} is an integer indicating a mask of open flags
38360 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
38361 of mode bits to use if the file is created (@pxref{mode_t Values}).
38362 @xref{open}, for details of the open flags and mode values.
38363
38364 @item vFile:close: @var{fd}
38365 Close the open file corresponding to @var{fd} and return 0, or
38366 -1 if an error occurs.
38367
38368 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
38369 Read data from the open file corresponding to @var{fd}.  Up to
38370 @var{count} bytes will be read from the file, starting at @var{offset}
38371 relative to the start of the file.  The target may read fewer bytes;
38372 common reasons include packet size limits and an end-of-file
38373 condition.  The number of bytes read is returned.  Zero should only be
38374 returned for a successful read at the end of the file, or if
38375 @var{count} was zero.
38376
38377 The data read should be returned as a binary attachment on success.
38378 If zero bytes were read, the response should include an empty binary
38379 attachment (i.e.@: a trailing semicolon).  The return value is the
38380 number of target bytes read; the binary attachment may be longer if
38381 some characters were escaped.
38382
38383 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
38384 Write @var{data} (a binary buffer) to the open file corresponding
38385 to @var{fd}.  Start the write at @var{offset} from the start of the
38386 file.  Unlike many @code{write} system calls, there is no
38387 separate @var{count} argument; the length of @var{data} in the
38388 packet is used.  @samp{vFile:write} returns the number of bytes written,
38389 which may be shorter than the length of @var{data}, or -1 if an
38390 error occurred.
38391
38392 @item vFile:unlink: @var{pathname}
38393 Delete the file at @var{pathname} on the target.  Return 0,
38394 or -1 if an error occurs.  @var{pathname} is a string.
38395
38396 @item vFile:readlink: @var{filename}
38397 Read value of symbolic link @var{filename} on the target.  Return
38398 the number of bytes read, or -1 if an error occurs.
38399
38400 The data read should be returned as a binary attachment on success.
38401 If zero bytes were read, the response should include an empty binary
38402 attachment (i.e.@: a trailing semicolon).  The return value is the
38403 number of target bytes read; the binary attachment may be longer if
38404 some characters were escaped.
38405
38406 @end table
38407
38408 @node Interrupts
38409 @section Interrupts
38410 @cindex interrupts (remote protocol)
38411
38412 When a program on the remote target is running, @value{GDBN} may
38413 attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
38414 a @code{BREAK} followed by @code{g},
38415 control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
38416
38417 The precise meaning of @code{BREAK} is defined by the transport
38418 mechanism and may, in fact, be undefined.  @value{GDBN} does not
38419 currently define a @code{BREAK} mechanism for any of the network
38420 interfaces except for TCP, in which case @value{GDBN} sends the
38421 @code{telnet} BREAK sequence.
38422
38423 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
38424 transport mechanisms.  It is represented by sending the single byte
38425 @code{0x03} without any of the usual packet overhead described in
38426 the Overview section (@pxref{Overview}).  When a @code{0x03} byte is
38427 transmitted as part of a packet, it is considered to be packet data
38428 and does @emph{not} represent an interrupt.  E.g., an @samp{X} packet
38429 (@pxref{X packet}), used for binary downloads, may include an unescaped
38430 @code{0x03} as part of its packet.
38431
38432 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
38433 When Linux kernel receives this sequence from serial port,
38434 it stops execution and connects to gdb.
38435
38436 Stubs are not required to recognize these interrupt mechanisms and the
38437 precise meaning associated with receipt of the interrupt is
38438 implementation defined.  If the target supports debugging of multiple
38439 threads and/or processes, it should attempt to interrupt all 
38440 currently-executing threads and processes.
38441 If the stub is successful at interrupting the
38442 running program, it should send one of the stop
38443 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
38444 of successfully stopping the program in all-stop mode, and a stop reply
38445 for each stopped thread in non-stop mode.
38446 Interrupts received while the
38447 program is stopped are discarded.
38448
38449 @node Notification Packets
38450 @section Notification Packets
38451 @cindex notification packets
38452 @cindex packets, notification
38453
38454 The @value{GDBN} remote serial protocol includes @dfn{notifications},
38455 packets that require no acknowledgment.  Both the GDB and the stub
38456 may send notifications (although the only notifications defined at
38457 present are sent by the stub).  Notifications carry information
38458 without incurring the round-trip latency of an acknowledgment, and so
38459 are useful for low-impact communications where occasional packet loss
38460 is not a problem.
38461
38462 A notification packet has the form @samp{% @var{data} #
38463 @var{checksum}}, where @var{data} is the content of the notification,
38464 and @var{checksum} is a checksum of @var{data}, computed and formatted
38465 as for ordinary @value{GDBN} packets.  A notification's @var{data}
38466 never contains @samp{$}, @samp{%} or @samp{#} characters.  Upon
38467 receiving a notification, the recipient sends no @samp{+} or @samp{-}
38468 to acknowledge the notification's receipt or to report its corruption.
38469
38470 Every notification's @var{data} begins with a name, which contains no
38471 colon characters, followed by a colon character.
38472
38473 Recipients should silently ignore corrupted notifications and
38474 notifications they do not understand.  Recipients should restart
38475 timeout periods on receipt of a well-formed notification, whether or
38476 not they understand it.
38477
38478 Senders should only send the notifications described here when this
38479 protocol description specifies that they are permitted.  In the
38480 future, we may extend the protocol to permit existing notifications in
38481 new contexts; this rule helps older senders avoid confusing newer
38482 recipients.
38483
38484 (Older versions of @value{GDBN} ignore bytes received until they see
38485 the @samp{$} byte that begins an ordinary packet, so new stubs may
38486 transmit notifications without fear of confusing older clients.  There
38487 are no notifications defined for @value{GDBN} to send at the moment, but we
38488 assume that most older stubs would ignore them, as well.)
38489
38490 Each notification is comprised of three parts:
38491 @table @samp
38492 @item @var{name}:@var{event}
38493 The notification packet is sent by the side that initiates the
38494 exchange (currently, only the stub does that), with @var{event}
38495 carrying the specific information about the notification.
38496 @var{name} is the name of the notification.
38497 @item @var{ack}
38498 The acknowledge sent by the other side, usually @value{GDBN}, to
38499 acknowledge the exchange and request the event.
38500 @end table
38501
38502 The purpose of an asynchronous notification mechanism is to report to
38503 @value{GDBN} that something interesting happened in the remote stub.
38504
38505 The remote stub may send notification @var{name}:@var{event}
38506 at any time, but @value{GDBN} acknowledges the notification when
38507 appropriate.  The notification event is pending before @value{GDBN}
38508 acknowledges.  Only one notification at a time may be pending; if
38509 additional events occur before @value{GDBN} has acknowledged the
38510 previous notification, they must be queued by the stub for later
38511 synchronous transmission in response to @var{ack} packets from
38512 @value{GDBN}.  Because the notification mechanism is unreliable,
38513 the stub is permitted to resend a notification if it believes
38514 @value{GDBN} may not have received it.
38515
38516 Specifically, notifications may appear when @value{GDBN} is not
38517 otherwise reading input from the stub, or when @value{GDBN} is
38518 expecting to read a normal synchronous response or a
38519 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
38520 Notification packets are distinct from any other communication from
38521 the stub so there is no ambiguity.
38522
38523 After receiving a notification, @value{GDBN} shall acknowledge it by
38524 sending a @var{ack} packet as a regular, synchronous request to the
38525 stub.  Such acknowledgment is not required to happen immediately, as
38526 @value{GDBN} is permitted to send other, unrelated packets to the
38527 stub first, which the stub should process normally.
38528
38529 Upon receiving a @var{ack} packet, if the stub has other queued
38530 events to report to @value{GDBN}, it shall respond by sending a
38531 normal @var{event}.  @value{GDBN} shall then send another @var{ack}
38532 packet to solicit further responses; again, it is permitted to send
38533 other, unrelated packets as well which the stub should process
38534 normally.
38535
38536 If the stub receives a @var{ack} packet and there are no additional
38537 @var{event} to report, the stub shall return an @samp{OK} response.
38538 At this point, @value{GDBN} has finished processing a notification
38539 and the stub has completed sending any queued events.  @value{GDBN}
38540 won't accept any new notifications until the final @samp{OK} is
38541 received .  If further notification events occur, the stub shall send
38542 a new notification, @value{GDBN} shall accept the notification, and
38543 the process shall be repeated.
38544
38545 The process of asynchronous notification can be illustrated by the
38546 following example:
38547 @smallexample
38548 <- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
38549 @code{...}
38550 -> @code{vStopped}
38551 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
38552 -> @code{vStopped}
38553 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
38554 -> @code{vStopped}
38555 <- @code{OK}
38556 @end smallexample
38557
38558 The following notifications are defined:
38559 @multitable @columnfractions 0.12 0.12 0.38 0.38
38560
38561 @item Notification
38562 @tab Ack
38563 @tab Event
38564 @tab Description
38565
38566 @item Stop
38567 @tab vStopped
38568 @tab @var{reply}.  The @var{reply} has the form of a stop reply, as
38569 described in @ref{Stop Reply Packets}.  Refer to @ref{Remote Non-Stop},
38570 for information on how these notifications are acknowledged by 
38571 @value{GDBN}.
38572 @tab Report an asynchronous stop event in non-stop mode.
38573
38574 @end multitable
38575
38576 @node Remote Non-Stop
38577 @section Remote Protocol Support for Non-Stop Mode
38578
38579 @value{GDBN}'s remote protocol supports non-stop debugging of
38580 multi-threaded programs, as described in @ref{Non-Stop Mode}.  If the stub
38581 supports non-stop mode, it should report that to @value{GDBN} by including
38582 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
38583
38584 @value{GDBN} typically sends a @samp{QNonStop} packet only when
38585 establishing a new connection with the stub.  Entering non-stop mode
38586 does not alter the state of any currently-running threads, but targets
38587 must stop all threads in any already-attached processes when entering
38588 all-stop mode.  @value{GDBN} uses the @samp{?} packet as necessary to
38589 probe the target state after a mode change.
38590
38591 In non-stop mode, when an attached process encounters an event that
38592 would otherwise be reported with a stop reply, it uses the
38593 asynchronous notification mechanism (@pxref{Notification Packets}) to
38594 inform @value{GDBN}.  In contrast to all-stop mode, where all threads
38595 in all processes are stopped when a stop reply is sent, in non-stop
38596 mode only the thread reporting the stop event is stopped.  That is,
38597 when reporting a @samp{S} or @samp{T} response to indicate completion
38598 of a step operation, hitting a breakpoint, or a fault, only the
38599 affected thread is stopped; any other still-running threads continue
38600 to run.  When reporting a @samp{W} or @samp{X} response, all running
38601 threads belonging to other attached processes continue to run.
38602
38603 In non-stop mode, the target shall respond to the @samp{?} packet as
38604 follows.  First, any incomplete stop reply notification/@samp{vStopped} 
38605 sequence in progress is abandoned.  The target must begin a new
38606 sequence reporting stop events for all stopped threads, whether or not
38607 it has previously reported those events to @value{GDBN}.  The first
38608 stop reply is sent as a synchronous reply to the @samp{?} packet, and
38609 subsequent stop replies are sent as responses to @samp{vStopped} packets
38610 using the mechanism described above.  The target must not send
38611 asynchronous stop reply notifications until the sequence is complete.
38612 If all threads are running when the target receives the @samp{?} packet,
38613 or if the target is not attached to any process, it shall respond
38614 @samp{OK}.
38615
38616 @node Packet Acknowledgment
38617 @section Packet Acknowledgment
38618
38619 @cindex acknowledgment, for @value{GDBN} remote
38620 @cindex packet acknowledgment, for @value{GDBN} remote
38621 By default, when either the host or the target machine receives a packet,
38622 the first response expected is an acknowledgment: either @samp{+} (to indicate
38623 the package was received correctly) or @samp{-} (to request retransmission).
38624 This mechanism allows the @value{GDBN} remote protocol to operate over
38625 unreliable transport mechanisms, such as a serial line.
38626
38627 In cases where the transport mechanism is itself reliable (such as a pipe or
38628 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
38629 It may be desirable to disable them in that case to reduce communication
38630 overhead, or for other reasons.  This can be accomplished by means of the
38631 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
38632
38633 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
38634 expect @samp{+}/@samp{-} protocol acknowledgments.  The packet
38635 and response format still includes the normal checksum, as described in
38636 @ref{Overview}, but the checksum may be ignored by the receiver.
38637
38638 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
38639 no-acknowledgment mode, it should report that to @value{GDBN}
38640 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
38641 @pxref{qSupported}.
38642 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
38643 disabled via the @code{set remote noack-packet off} command
38644 (@pxref{Remote Configuration}),
38645 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
38646 Only then may the stub actually turn off packet acknowledgments.
38647 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
38648 response, which can be safely ignored by the stub.
38649
38650 Note that @code{set remote noack-packet} command only affects negotiation
38651 between @value{GDBN} and the stub when subsequent connections are made;
38652 it does not affect the protocol acknowledgment state for any current
38653 connection.
38654 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
38655 new connection is established,
38656 there is also no protocol request to re-enable the acknowledgments
38657 for the current connection, once disabled.
38658
38659 @node Examples
38660 @section Examples
38661
38662 Example sequence of a target being re-started.  Notice how the restart
38663 does not get any direct output:
38664
38665 @smallexample
38666 -> @code{R00}
38667 <- @code{+}
38668 @emph{target restarts}
38669 -> @code{?}
38670 <- @code{+}
38671 <- @code{T001:1234123412341234}
38672 -> @code{+}
38673 @end smallexample
38674
38675 Example sequence of a target being stepped by a single instruction:
38676
38677 @smallexample
38678 -> @code{G1445@dots{}}
38679 <- @code{+}
38680 -> @code{s}
38681 <- @code{+}
38682 @emph{time passes}
38683 <- @code{T001:1234123412341234}
38684 -> @code{+}
38685 -> @code{g}
38686 <- @code{+}
38687 <- @code{1455@dots{}}
38688 -> @code{+}
38689 @end smallexample
38690
38691 @node File-I/O Remote Protocol Extension
38692 @section File-I/O Remote Protocol Extension
38693 @cindex File-I/O remote protocol extension
38694
38695 @menu
38696 * File-I/O Overview::
38697 * Protocol Basics::
38698 * The F Request Packet::
38699 * The F Reply Packet::
38700 * The Ctrl-C Message::
38701 * Console I/O::
38702 * List of Supported Calls::
38703 * Protocol-specific Representation of Datatypes::
38704 * Constants::
38705 * File-I/O Examples::
38706 @end menu
38707
38708 @node File-I/O Overview
38709 @subsection File-I/O Overview
38710 @cindex file-i/o overview
38711
38712 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
38713 target to use the host's file system and console I/O to perform various
38714 system calls.  System calls on the target system are translated into a
38715 remote protocol packet to the host system, which then performs the needed
38716 actions and returns a response packet to the target system.
38717 This simulates file system operations even on targets that lack file systems.
38718
38719 The protocol is defined to be independent of both the host and target systems.
38720 It uses its own internal representation of datatypes and values.  Both
38721 @value{GDBN} and the target's @value{GDBN} stub are responsible for
38722 translating the system-dependent value representations into the internal
38723 protocol representations when data is transmitted.
38724
38725 The communication is synchronous.  A system call is possible only when 
38726 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S} 
38727 or @samp{s} packets.  While @value{GDBN} handles the request for a system call,
38728 the target is stopped to allow deterministic access to the target's
38729 memory.  Therefore File-I/O is not interruptible by target signals.  On
38730 the other hand, it is possible to interrupt File-I/O by a user interrupt 
38731 (@samp{Ctrl-C}) within @value{GDBN}.
38732
38733 The target's request to perform a host system call does not finish
38734 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action.  That means,
38735 after finishing the system call, the target returns to continuing the
38736 previous activity (continue, step).  No additional continue or step
38737 request from @value{GDBN} is required.
38738
38739 @smallexample
38740 (@value{GDBP}) continue
38741   <- target requests 'system call X'
38742   target is stopped, @value{GDBN} executes system call
38743   -> @value{GDBN} returns result
38744   ... target continues, @value{GDBN} returns to wait for the target
38745   <- target hits breakpoint and sends a Txx packet
38746 @end smallexample
38747
38748 The protocol only supports I/O on the console and to regular files on 
38749 the host file system.  Character or block special devices, pipes,
38750 named pipes, sockets or any other communication method on the host
38751 system are not supported by this protocol.
38752
38753 File I/O is not supported in non-stop mode.
38754
38755 @node Protocol Basics
38756 @subsection Protocol Basics
38757 @cindex protocol basics, file-i/o
38758
38759 The File-I/O protocol uses the @code{F} packet as the request as well
38760 as reply packet.  Since a File-I/O system call can only occur when
38761 @value{GDBN} is waiting for a response from the continuing or stepping target, 
38762 the File-I/O request is a reply that @value{GDBN} has to expect as a result
38763 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
38764 This @code{F} packet contains all information needed to allow @value{GDBN}
38765 to call the appropriate host system call:
38766
38767 @itemize @bullet
38768 @item
38769 A unique identifier for the requested system call.
38770
38771 @item
38772 All parameters to the system call.  Pointers are given as addresses
38773 in the target memory address space.  Pointers to strings are given as
38774 pointer/length pair.  Numerical values are given as they are.
38775 Numerical control flags are given in a protocol-specific representation.
38776
38777 @end itemize
38778
38779 At this point, @value{GDBN} has to perform the following actions.
38780
38781 @itemize @bullet
38782 @item
38783 If the parameters include pointer values to data needed as input to a 
38784 system call, @value{GDBN} requests this data from the target with a
38785 standard @code{m} packet request.  This additional communication has to be
38786 expected by the target implementation and is handled as any other @code{m}
38787 packet.
38788
38789 @item
38790 @value{GDBN} translates all value from protocol representation to host
38791 representation as needed.  Datatypes are coerced into the host types.
38792
38793 @item
38794 @value{GDBN} calls the system call.
38795
38796 @item
38797 It then coerces datatypes back to protocol representation.
38798
38799 @item
38800 If the system call is expected to return data in buffer space specified
38801 by pointer parameters to the call, the data is transmitted to the
38802 target using a @code{M} or @code{X} packet.  This packet has to be expected
38803 by the target implementation and is handled as any other @code{M} or @code{X}
38804 packet.
38805
38806 @end itemize
38807
38808 Eventually @value{GDBN} replies with another @code{F} packet which contains all
38809 necessary information for the target to continue.  This at least contains
38810
38811 @itemize @bullet
38812 @item
38813 Return value.
38814
38815 @item
38816 @code{errno}, if has been changed by the system call.
38817
38818 @item
38819 ``Ctrl-C'' flag.
38820
38821 @end itemize
38822
38823 After having done the needed type and value coercion, the target continues
38824 the latest continue or step action.
38825
38826 @node The F Request Packet
38827 @subsection The @code{F} Request Packet
38828 @cindex file-i/o request packet
38829 @cindex @code{F} request packet
38830
38831 The @code{F} request packet has the following format:
38832
38833 @table @samp
38834 @item F@var{call-id},@var{parameter@dots{}}
38835
38836 @var{call-id} is the identifier to indicate the host system call to be called.
38837 This is just the name of the function.
38838
38839 @var{parameter@dots{}} are the parameters to the system call.  
38840 Parameters are hexadecimal integer values, either the actual values in case
38841 of scalar datatypes, pointers to target buffer space in case of compound
38842 datatypes and unspecified memory areas, or pointer/length pairs in case
38843 of string parameters.  These are appended to the @var{call-id} as a 
38844 comma-delimited list.  All values are transmitted in ASCII
38845 string representation, pointer/length pairs separated by a slash.
38846
38847 @end table
38848
38849
38850
38851 @node The F Reply Packet
38852 @subsection The @code{F} Reply Packet
38853 @cindex file-i/o reply packet
38854 @cindex @code{F} reply packet
38855
38856 The @code{F} reply packet has the following format:
38857
38858 @table @samp
38859
38860 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
38861
38862 @var{retcode} is the return code of the system call as hexadecimal value.
38863
38864 @var{errno} is the @code{errno} set by the call, in protocol-specific
38865 representation.
38866 This parameter can be omitted if the call was successful.
38867
38868 @var{Ctrl-C flag} is only sent if the user requested a break.  In this
38869 case, @var{errno} must be sent as well, even if the call was successful.
38870 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
38871
38872 @smallexample
38873 F0,0,C
38874 @end smallexample
38875
38876 @noindent
38877 or, if the call was interrupted before the host call has been performed:
38878
38879 @smallexample
38880 F-1,4,C
38881 @end smallexample
38882
38883 @noindent
38884 assuming 4 is the protocol-specific representation of @code{EINTR}.
38885
38886 @end table
38887
38888
38889 @node The Ctrl-C Message
38890 @subsection The @samp{Ctrl-C} Message
38891 @cindex ctrl-c message, in file-i/o protocol
38892
38893 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
38894 reply packet (@pxref{The F Reply Packet}),
38895 the target should behave as if it had
38896 gotten a break message.  The meaning for the target is ``system call
38897 interrupted by @code{SIGINT}''.  Consequentially, the target should actually stop
38898 (as with a break message) and return to @value{GDBN} with a @code{T02}
38899 packet.
38900
38901 It's important for the target to know in which
38902 state the system call was interrupted.  There are two possible cases:
38903
38904 @itemize @bullet
38905 @item
38906 The system call hasn't been performed on the host yet.
38907
38908 @item
38909 The system call on the host has been finished.
38910
38911 @end itemize
38912
38913 These two states can be distinguished by the target by the value of the
38914 returned @code{errno}.  If it's the protocol representation of @code{EINTR}, the system
38915 call hasn't been performed.  This is equivalent to the @code{EINTR} handling
38916 on POSIX systems.  In any other case, the target may presume that the
38917 system call has been finished --- successfully or not --- and should behave
38918 as if the break message arrived right after the system call.
38919
38920 @value{GDBN} must behave reliably.  If the system call has not been called
38921 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
38922 @code{errno} in the packet.  If the system call on the host has been finished
38923 before the user requests a break, the full action must be finished by
38924 @value{GDBN}.  This requires sending @code{M} or @code{X} packets as necessary.
38925 The @code{F} packet may only be sent when either nothing has happened
38926 or the full action has been completed.
38927
38928 @node Console I/O
38929 @subsection Console I/O
38930 @cindex console i/o as part of file-i/o
38931
38932 By default and if not explicitly closed by the target system, the file
38933 descriptors 0, 1 and 2 are connected to the @value{GDBN} console.  Output
38934 on the @value{GDBN} console is handled as any other file output operation
38935 (@code{write(1, @dots{})} or @code{write(2, @dots{})}).  Console input is handled
38936 by @value{GDBN} so that after the target read request from file descriptor
38937 0 all following typing is buffered until either one of the following
38938 conditions is met:
38939
38940 @itemize @bullet
38941 @item
38942 The user types @kbd{Ctrl-c}.  The behaviour is as explained above, and the
38943 @code{read}
38944 system call is treated as finished.
38945
38946 @item
38947 The user presses @key{RET}.  This is treated as end of input with a trailing
38948 newline.
38949
38950 @item
38951 The user types @kbd{Ctrl-d}.  This is treated as end of input.  No trailing
38952 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
38953
38954 @end itemize
38955
38956 If the user has typed more characters than fit in the buffer given to
38957 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
38958 either another @code{read(0, @dots{})} is requested by the target, or debugging
38959 is stopped at the user's request.
38960
38961
38962 @node List of Supported Calls
38963 @subsection List of Supported Calls
38964 @cindex list of supported file-i/o calls
38965
38966 @menu
38967 * open::
38968 * close::
38969 * read::
38970 * write::
38971 * lseek::
38972 * rename::
38973 * unlink::
38974 * stat/fstat::
38975 * gettimeofday::
38976 * isatty::
38977 * system::
38978 @end menu
38979
38980 @node open
38981 @unnumberedsubsubsec open
38982 @cindex open, file-i/o system call
38983
38984 @table @asis
38985 @item Synopsis:
38986 @smallexample
38987 int open(const char *pathname, int flags);
38988 int open(const char *pathname, int flags, mode_t mode);
38989 @end smallexample
38990
38991 @item Request:
38992 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
38993
38994 @noindent
38995 @var{flags} is the bitwise @code{OR} of the following values:
38996
38997 @table @code
38998 @item O_CREAT
38999 If the file does not exist it will be created.  The host
39000 rules apply as far as file ownership and time stamps
39001 are concerned.
39002
39003 @item O_EXCL
39004 When used with @code{O_CREAT}, if the file already exists it is
39005 an error and open() fails.
39006
39007 @item O_TRUNC
39008 If the file already exists and the open mode allows
39009 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
39010 truncated to zero length.
39011
39012 @item O_APPEND
39013 The file is opened in append mode.
39014
39015 @item O_RDONLY
39016 The file is opened for reading only.
39017
39018 @item O_WRONLY
39019 The file is opened for writing only.
39020
39021 @item O_RDWR
39022 The file is opened for reading and writing.
39023 @end table
39024
39025 @noindent
39026 Other bits are silently ignored.
39027
39028
39029 @noindent
39030 @var{mode} is the bitwise @code{OR} of the following values:
39031
39032 @table @code
39033 @item S_IRUSR
39034 User has read permission.
39035
39036 @item S_IWUSR
39037 User has write permission.
39038
39039 @item S_IRGRP
39040 Group has read permission.
39041
39042 @item S_IWGRP
39043 Group has write permission.
39044
39045 @item S_IROTH
39046 Others have read permission.
39047
39048 @item S_IWOTH
39049 Others have write permission.
39050 @end table
39051
39052 @noindent
39053 Other bits are silently ignored.
39054
39055
39056 @item Return value:
39057 @code{open} returns the new file descriptor or -1 if an error
39058 occurred.
39059
39060 @item Errors:
39061
39062 @table @code
39063 @item EEXIST
39064 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
39065
39066 @item EISDIR
39067 @var{pathname} refers to a directory.
39068
39069 @item EACCES
39070 The requested access is not allowed.
39071
39072 @item ENAMETOOLONG
39073 @var{pathname} was too long.
39074
39075 @item ENOENT
39076 A directory component in @var{pathname} does not exist.
39077
39078 @item ENODEV
39079 @var{pathname} refers to a device, pipe, named pipe or socket.
39080
39081 @item EROFS
39082 @var{pathname} refers to a file on a read-only filesystem and
39083 write access was requested.
39084
39085 @item EFAULT
39086 @var{pathname} is an invalid pointer value.
39087
39088 @item ENOSPC
39089 No space on device to create the file.
39090
39091 @item EMFILE
39092 The process already has the maximum number of files open.
39093
39094 @item ENFILE
39095 The limit on the total number of files open on the system
39096 has been reached.
39097
39098 @item EINTR
39099 The call was interrupted by the user.
39100 @end table
39101
39102 @end table
39103
39104 @node close
39105 @unnumberedsubsubsec close
39106 @cindex close, file-i/o system call
39107
39108 @table @asis
39109 @item Synopsis:
39110 @smallexample
39111 int close(int fd);
39112 @end smallexample
39113
39114 @item Request:
39115 @samp{Fclose,@var{fd}}
39116
39117 @item Return value:
39118 @code{close} returns zero on success, or -1 if an error occurred.
39119
39120 @item Errors:
39121
39122 @table @code
39123 @item EBADF
39124 @var{fd} isn't a valid open file descriptor.
39125
39126 @item EINTR
39127 The call was interrupted by the user.
39128 @end table
39129
39130 @end table
39131
39132 @node read
39133 @unnumberedsubsubsec read
39134 @cindex read, file-i/o system call
39135
39136 @table @asis
39137 @item Synopsis:
39138 @smallexample
39139 int read(int fd, void *buf, unsigned int count);
39140 @end smallexample
39141
39142 @item Request:
39143 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
39144
39145 @item Return value:
39146 On success, the number of bytes read is returned.
39147 Zero indicates end of file.  If count is zero, read
39148 returns zero as well.  On error, -1 is returned.
39149
39150 @item Errors:
39151
39152 @table @code
39153 @item EBADF
39154 @var{fd} is not a valid file descriptor or is not open for
39155 reading.
39156
39157 @item EFAULT
39158 @var{bufptr} is an invalid pointer value.
39159
39160 @item EINTR
39161 The call was interrupted by the user.
39162 @end table
39163
39164 @end table
39165
39166 @node write
39167 @unnumberedsubsubsec write
39168 @cindex write, file-i/o system call
39169
39170 @table @asis
39171 @item Synopsis:
39172 @smallexample
39173 int write(int fd, const void *buf, unsigned int count);
39174 @end smallexample
39175
39176 @item Request:
39177 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
39178
39179 @item Return value:
39180 On success, the number of bytes written are returned.
39181 Zero indicates nothing was written.  On error, -1
39182 is returned.
39183
39184 @item Errors:
39185
39186 @table @code
39187 @item EBADF
39188 @var{fd} is not a valid file descriptor or is not open for
39189 writing.
39190
39191 @item EFAULT
39192 @var{bufptr} is an invalid pointer value.
39193
39194 @item EFBIG
39195 An attempt was made to write a file that exceeds the
39196 host-specific maximum file size allowed.
39197
39198 @item ENOSPC
39199 No space on device to write the data.
39200
39201 @item EINTR
39202 The call was interrupted by the user.
39203 @end table
39204
39205 @end table
39206
39207 @node lseek
39208 @unnumberedsubsubsec lseek
39209 @cindex lseek, file-i/o system call
39210
39211 @table @asis
39212 @item Synopsis:
39213 @smallexample
39214 long lseek (int fd, long offset, int flag);
39215 @end smallexample
39216
39217 @item Request:
39218 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
39219
39220 @var{flag} is one of:
39221
39222 @table @code
39223 @item SEEK_SET
39224 The offset is set to @var{offset} bytes.
39225
39226 @item SEEK_CUR
39227 The offset is set to its current location plus @var{offset}
39228 bytes.
39229
39230 @item SEEK_END
39231 The offset is set to the size of the file plus @var{offset}
39232 bytes.
39233 @end table
39234
39235 @item Return value:
39236 On success, the resulting unsigned offset in bytes from
39237 the beginning of the file is returned.  Otherwise, a
39238 value of -1 is returned.
39239
39240 @item Errors:
39241
39242 @table @code
39243 @item EBADF
39244 @var{fd} is not a valid open file descriptor.
39245
39246 @item ESPIPE
39247 @var{fd} is associated with the @value{GDBN} console.
39248
39249 @item EINVAL
39250 @var{flag} is not a proper value.
39251
39252 @item EINTR
39253 The call was interrupted by the user.
39254 @end table
39255
39256 @end table
39257
39258 @node rename
39259 @unnumberedsubsubsec rename
39260 @cindex rename, file-i/o system call
39261
39262 @table @asis
39263 @item Synopsis:
39264 @smallexample
39265 int rename(const char *oldpath, const char *newpath);
39266 @end smallexample
39267
39268 @item Request:
39269 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
39270
39271 @item Return value:
39272 On success, zero is returned.  On error, -1 is returned.
39273
39274 @item Errors:
39275
39276 @table @code
39277 @item EISDIR
39278 @var{newpath} is an existing directory, but @var{oldpath} is not a
39279 directory.
39280
39281 @item EEXIST
39282 @var{newpath} is a non-empty directory.
39283
39284 @item EBUSY
39285 @var{oldpath} or @var{newpath} is a directory that is in use by some
39286 process.
39287
39288 @item EINVAL
39289 An attempt was made to make a directory a subdirectory
39290 of itself.
39291
39292 @item ENOTDIR
39293 A  component used as a directory in @var{oldpath} or new
39294 path is not a directory.  Or @var{oldpath} is a directory
39295 and @var{newpath} exists but is not a directory.
39296
39297 @item EFAULT
39298 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
39299
39300 @item EACCES
39301 No access to the file or the path of the file.
39302
39303 @item ENAMETOOLONG
39304
39305 @var{oldpath} or @var{newpath} was too long.
39306
39307 @item ENOENT
39308 A directory component in @var{oldpath} or @var{newpath} does not exist.
39309
39310 @item EROFS
39311 The file is on a read-only filesystem.
39312
39313 @item ENOSPC
39314 The device containing the file has no room for the new
39315 directory entry.
39316
39317 @item EINTR
39318 The call was interrupted by the user.
39319 @end table
39320
39321 @end table
39322
39323 @node unlink
39324 @unnumberedsubsubsec unlink
39325 @cindex unlink, file-i/o system call
39326
39327 @table @asis
39328 @item Synopsis:
39329 @smallexample
39330 int unlink(const char *pathname);
39331 @end smallexample
39332
39333 @item Request:
39334 @samp{Funlink,@var{pathnameptr}/@var{len}}
39335
39336 @item Return value:
39337 On success, zero is returned.  On error, -1 is returned.
39338
39339 @item Errors:
39340
39341 @table @code
39342 @item EACCES
39343 No access to the file or the path of the file.
39344
39345 @item EPERM
39346 The system does not allow unlinking of directories.
39347
39348 @item EBUSY
39349 The file @var{pathname} cannot be unlinked because it's
39350 being used by another process.
39351
39352 @item EFAULT
39353 @var{pathnameptr} is an invalid pointer value.
39354
39355 @item ENAMETOOLONG
39356 @var{pathname} was too long.
39357
39358 @item ENOENT
39359 A directory component in @var{pathname} does not exist.
39360
39361 @item ENOTDIR
39362 A component of the path is not a directory.
39363
39364 @item EROFS
39365 The file is on a read-only filesystem.
39366
39367 @item EINTR
39368 The call was interrupted by the user.
39369 @end table
39370
39371 @end table
39372
39373 @node stat/fstat
39374 @unnumberedsubsubsec stat/fstat
39375 @cindex fstat, file-i/o system call
39376 @cindex stat, file-i/o system call
39377
39378 @table @asis
39379 @item Synopsis:
39380 @smallexample
39381 int stat(const char *pathname, struct stat *buf);
39382 int fstat(int fd, struct stat *buf);
39383 @end smallexample
39384
39385 @item Request:
39386 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
39387 @samp{Ffstat,@var{fd},@var{bufptr}}
39388
39389 @item Return value:
39390 On success, zero is returned.  On error, -1 is returned.
39391
39392 @item Errors:
39393
39394 @table @code
39395 @item EBADF
39396 @var{fd} is not a valid open file.
39397
39398 @item ENOENT
39399 A directory component in @var{pathname} does not exist or the
39400 path is an empty string.
39401
39402 @item ENOTDIR
39403 A component of the path is not a directory.
39404
39405 @item EFAULT
39406 @var{pathnameptr} is an invalid pointer value.
39407
39408 @item EACCES
39409 No access to the file or the path of the file.
39410
39411 @item ENAMETOOLONG
39412 @var{pathname} was too long.
39413
39414 @item EINTR
39415 The call was interrupted by the user.
39416 @end table
39417
39418 @end table
39419
39420 @node gettimeofday
39421 @unnumberedsubsubsec gettimeofday
39422 @cindex gettimeofday, file-i/o system call
39423
39424 @table @asis
39425 @item Synopsis:
39426 @smallexample
39427 int gettimeofday(struct timeval *tv, void *tz);
39428 @end smallexample
39429
39430 @item Request:
39431 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
39432
39433 @item Return value:
39434 On success, 0 is returned, -1 otherwise.
39435
39436 @item Errors:
39437
39438 @table @code
39439 @item EINVAL
39440 @var{tz} is a non-NULL pointer.
39441
39442 @item EFAULT
39443 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
39444 @end table
39445
39446 @end table
39447
39448 @node isatty
39449 @unnumberedsubsubsec isatty
39450 @cindex isatty, file-i/o system call
39451
39452 @table @asis
39453 @item Synopsis:
39454 @smallexample
39455 int isatty(int fd);
39456 @end smallexample
39457
39458 @item Request:
39459 @samp{Fisatty,@var{fd}}
39460
39461 @item Return value:
39462 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
39463
39464 @item Errors:
39465
39466 @table @code
39467 @item EINTR
39468 The call was interrupted by the user.
39469 @end table
39470
39471 @end table
39472
39473 Note that the @code{isatty} call is treated as a special case: it returns
39474 1 to the target if the file descriptor is attached
39475 to the @value{GDBN} console, 0 otherwise.  Implementing through system calls
39476 would require implementing @code{ioctl} and would be more complex than
39477 needed.
39478
39479
39480 @node system
39481 @unnumberedsubsubsec system
39482 @cindex system, file-i/o system call
39483
39484 @table @asis
39485 @item Synopsis:
39486 @smallexample
39487 int system(const char *command);
39488 @end smallexample
39489
39490 @item Request:
39491 @samp{Fsystem,@var{commandptr}/@var{len}}
39492
39493 @item Return value:
39494 If @var{len} is zero, the return value indicates whether a shell is
39495 available.  A zero return value indicates a shell is not available.
39496 For non-zero @var{len}, the value returned is -1 on error and the
39497 return status of the command otherwise.  Only the exit status of the
39498 command is returned, which is extracted from the host's @code{system}
39499 return value by calling @code{WEXITSTATUS(retval)}.  In case
39500 @file{/bin/sh} could not be executed, 127 is returned.
39501
39502 @item Errors:
39503
39504 @table @code
39505 @item EINTR
39506 The call was interrupted by the user.
39507 @end table
39508
39509 @end table
39510
39511 @value{GDBN} takes over the full task of calling the necessary host calls 
39512 to perform the @code{system} call.  The return value of @code{system} on 
39513 the host is simplified before it's returned
39514 to the target.  Any termination signal information from the child process 
39515 is discarded, and the return value consists
39516 entirely of the exit status of the called command.
39517
39518 Due to security concerns, the @code{system} call is by default refused
39519 by @value{GDBN}.  The user has to allow this call explicitly with the
39520 @code{set remote system-call-allowed 1} command.
39521
39522 @table @code
39523 @item set remote system-call-allowed
39524 @kindex set remote system-call-allowed
39525 Control whether to allow the @code{system} calls in the File I/O
39526 protocol for the remote target.  The default is zero (disabled).
39527
39528 @item show remote system-call-allowed
39529 @kindex show remote system-call-allowed
39530 Show whether the @code{system} calls are allowed in the File I/O
39531 protocol.
39532 @end table
39533
39534 @node Protocol-specific Representation of Datatypes
39535 @subsection Protocol-specific Representation of Datatypes
39536 @cindex protocol-specific representation of datatypes, in file-i/o protocol
39537
39538 @menu
39539 * Integral Datatypes::
39540 * Pointer Values::
39541 * Memory Transfer::
39542 * struct stat::
39543 * struct timeval::
39544 @end menu
39545
39546 @node Integral Datatypes
39547 @unnumberedsubsubsec Integral Datatypes
39548 @cindex integral datatypes, in file-i/o protocol
39549
39550 The integral datatypes used in the system calls are @code{int}, 
39551 @code{unsigned int}, @code{long}, @code{unsigned long},
39552 @code{mode_t}, and @code{time_t}.  
39553
39554 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
39555 implemented as 32 bit values in this protocol.
39556
39557 @code{long} and @code{unsigned long} are implemented as 64 bit types.
39558
39559 @xref{Limits}, for corresponding MIN and MAX values (similar to those
39560 in @file{limits.h}) to allow range checking on host and target.
39561
39562 @code{time_t} datatypes are defined as seconds since the Epoch.
39563
39564 All integral datatypes transferred as part of a memory read or write of a
39565 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
39566 byte order.
39567
39568 @node Pointer Values
39569 @unnumberedsubsubsec Pointer Values
39570 @cindex pointer values, in file-i/o protocol
39571
39572 Pointers to target data are transmitted as they are.  An exception
39573 is made for pointers to buffers for which the length isn't
39574 transmitted as part of the function call, namely strings.  Strings
39575 are transmitted as a pointer/length pair, both as hex values, e.g.@:
39576
39577 @smallexample
39578 @code{1aaf/12}
39579 @end smallexample
39580
39581 @noindent
39582 which is a pointer to data of length 18 bytes at position 0x1aaf.
39583 The length is defined as the full string length in bytes, including
39584 the trailing null byte.  For example, the string @code{"hello world"}
39585 at address 0x123456 is transmitted as
39586
39587 @smallexample
39588 @code{123456/d}
39589 @end smallexample
39590
39591 @node Memory Transfer
39592 @unnumberedsubsubsec Memory Transfer
39593 @cindex memory transfer, in file-i/o protocol
39594
39595 Structured data which is transferred using a memory read or write (for
39596 example, a @code{struct stat}) is expected to be in a protocol-specific format 
39597 with all scalar multibyte datatypes being big endian.  Translation to
39598 this representation needs to be done both by the target before the @code{F} 
39599 packet is sent, and by @value{GDBN} before 
39600 it transfers memory to the target.  Transferred pointers to structured
39601 data should point to the already-coerced data at any time.
39602
39603
39604 @node struct stat
39605 @unnumberedsubsubsec struct stat
39606 @cindex struct stat, in file-i/o protocol
39607
39608 The buffer of type @code{struct stat} used by the target and @value{GDBN} 
39609 is defined as follows:
39610
39611 @smallexample
39612 struct stat @{
39613     unsigned int  st_dev;      /* device */
39614     unsigned int  st_ino;      /* inode */
39615     mode_t        st_mode;     /* protection */
39616     unsigned int  st_nlink;    /* number of hard links */
39617     unsigned int  st_uid;      /* user ID of owner */
39618     unsigned int  st_gid;      /* group ID of owner */
39619     unsigned int  st_rdev;     /* device type (if inode device) */
39620     unsigned long st_size;     /* total size, in bytes */
39621     unsigned long st_blksize;  /* blocksize for filesystem I/O */
39622     unsigned long st_blocks;   /* number of blocks allocated */
39623     time_t        st_atime;    /* time of last access */
39624     time_t        st_mtime;    /* time of last modification */
39625     time_t        st_ctime;    /* time of last change */
39626 @};
39627 @end smallexample
39628
39629 The integral datatypes conform to the definitions given in the
39630 appropriate section (see @ref{Integral Datatypes}, for details) so this
39631 structure is of size 64 bytes.
39632
39633 The values of several fields have a restricted meaning and/or
39634 range of values.
39635
39636 @table @code
39637
39638 @item st_dev
39639 A value of 0 represents a file, 1 the console.
39640
39641 @item st_ino
39642 No valid meaning for the target.  Transmitted unchanged.
39643
39644 @item st_mode
39645 Valid mode bits are described in @ref{Constants}.  Any other
39646 bits have currently no meaning for the target.
39647
39648 @item st_uid
39649 @itemx st_gid
39650 @itemx st_rdev
39651 No valid meaning for the target.  Transmitted unchanged.
39652
39653 @item st_atime
39654 @itemx st_mtime
39655 @itemx st_ctime
39656 These values have a host and file system dependent
39657 accuracy.  Especially on Windows hosts, the file system may not
39658 support exact timing values.
39659 @end table
39660
39661 The target gets a @code{struct stat} of the above representation and is
39662 responsible for coercing it to the target representation before
39663 continuing.
39664
39665 Note that due to size differences between the host, target, and protocol
39666 representations of @code{struct stat} members, these members could eventually
39667 get truncated on the target.
39668
39669 @node struct timeval
39670 @unnumberedsubsubsec struct timeval
39671 @cindex struct timeval, in file-i/o protocol
39672
39673 The buffer of type @code{struct timeval} used by the File-I/O protocol
39674 is defined as follows:
39675
39676 @smallexample
39677 struct timeval @{
39678     time_t tv_sec;  /* second */
39679     long   tv_usec; /* microsecond */
39680 @};
39681 @end smallexample
39682
39683 The integral datatypes conform to the definitions given in the
39684 appropriate section (see @ref{Integral Datatypes}, for details) so this
39685 structure is of size 8 bytes.
39686
39687 @node Constants
39688 @subsection Constants
39689 @cindex constants, in file-i/o protocol
39690
39691 The following values are used for the constants inside of the
39692 protocol.  @value{GDBN} and target are responsible for translating these
39693 values before and after the call as needed.
39694
39695 @menu
39696 * Open Flags::
39697 * mode_t Values::
39698 * Errno Values::
39699 * Lseek Flags::
39700 * Limits::
39701 @end menu
39702
39703 @node Open Flags
39704 @unnumberedsubsubsec Open Flags
39705 @cindex open flags, in file-i/o protocol
39706
39707 All values are given in hexadecimal representation.
39708
39709 @smallexample
39710   O_RDONLY        0x0
39711   O_WRONLY        0x1
39712   O_RDWR          0x2
39713   O_APPEND        0x8
39714   O_CREAT       0x200
39715   O_TRUNC       0x400
39716   O_EXCL        0x800
39717 @end smallexample
39718
39719 @node mode_t Values
39720 @unnumberedsubsubsec mode_t Values
39721 @cindex mode_t values, in file-i/o protocol
39722
39723 All values are given in octal representation.
39724
39725 @smallexample
39726   S_IFREG       0100000
39727   S_IFDIR        040000
39728   S_IRUSR          0400
39729   S_IWUSR          0200
39730   S_IXUSR          0100
39731   S_IRGRP           040
39732   S_IWGRP           020
39733   S_IXGRP           010
39734   S_IROTH            04
39735   S_IWOTH            02
39736   S_IXOTH            01
39737 @end smallexample
39738
39739 @node Errno Values
39740 @unnumberedsubsubsec Errno Values
39741 @cindex errno values, in file-i/o protocol
39742
39743 All values are given in decimal representation.
39744
39745 @smallexample
39746   EPERM           1
39747   ENOENT          2
39748   EINTR           4
39749   EBADF           9
39750   EACCES         13
39751   EFAULT         14
39752   EBUSY          16
39753   EEXIST         17
39754   ENODEV         19
39755   ENOTDIR        20
39756   EISDIR         21
39757   EINVAL         22
39758   ENFILE         23
39759   EMFILE         24
39760   EFBIG          27
39761   ENOSPC         28
39762   ESPIPE         29
39763   EROFS          30
39764   ENAMETOOLONG   91
39765   EUNKNOWN       9999
39766 @end smallexample
39767
39768   @code{EUNKNOWN} is used as a fallback error value if a host system returns
39769   any error value not in the list of supported error numbers.
39770
39771 @node Lseek Flags
39772 @unnumberedsubsubsec Lseek Flags
39773 @cindex lseek flags, in file-i/o protocol
39774
39775 @smallexample
39776   SEEK_SET      0
39777   SEEK_CUR      1
39778   SEEK_END      2
39779 @end smallexample
39780
39781 @node Limits
39782 @unnumberedsubsubsec Limits
39783 @cindex limits, in file-i/o protocol
39784
39785 All values are given in decimal representation.
39786
39787 @smallexample
39788   INT_MIN       -2147483648
39789   INT_MAX        2147483647
39790   UINT_MAX       4294967295
39791   LONG_MIN      -9223372036854775808
39792   LONG_MAX       9223372036854775807
39793   ULONG_MAX      18446744073709551615
39794 @end smallexample
39795
39796 @node File-I/O Examples
39797 @subsection File-I/O Examples
39798 @cindex file-i/o examples
39799
39800 Example sequence of a write call, file descriptor 3, buffer is at target
39801 address 0x1234, 6 bytes should be written:
39802
39803 @smallexample
39804 <- @code{Fwrite,3,1234,6}
39805 @emph{request memory read from target}
39806 -> @code{m1234,6}
39807 <- XXXXXX
39808 @emph{return "6 bytes written"}
39809 -> @code{F6}
39810 @end smallexample
39811
39812 Example sequence of a read call, file descriptor 3, buffer is at target
39813 address 0x1234, 6 bytes should be read:
39814
39815 @smallexample
39816 <- @code{Fread,3,1234,6}
39817 @emph{request memory write to target}
39818 -> @code{X1234,6:XXXXXX}
39819 @emph{return "6 bytes read"}
39820 -> @code{F6}
39821 @end smallexample
39822
39823 Example sequence of a read call, call fails on the host due to invalid
39824 file descriptor (@code{EBADF}):
39825
39826 @smallexample
39827 <- @code{Fread,3,1234,6}
39828 -> @code{F-1,9}
39829 @end smallexample
39830
39831 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
39832 host is called:
39833
39834 @smallexample
39835 <- @code{Fread,3,1234,6}
39836 -> @code{F-1,4,C}
39837 <- @code{T02}
39838 @end smallexample
39839
39840 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
39841 host is called:
39842
39843 @smallexample
39844 <- @code{Fread,3,1234,6}
39845 -> @code{X1234,6:XXXXXX}
39846 <- @code{T02}
39847 @end smallexample
39848
39849 @node Library List Format
39850 @section Library List Format
39851 @cindex library list format, remote protocol
39852
39853 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
39854 same process as your application to manage libraries.  In this case,
39855 @value{GDBN} can use the loader's symbol table and normal memory
39856 operations to maintain a list of shared libraries.  On other
39857 platforms, the operating system manages loaded libraries.
39858 @value{GDBN} can not retrieve the list of currently loaded libraries
39859 through memory operations, so it uses the @samp{qXfer:libraries:read}
39860 packet (@pxref{qXfer library list read}) instead.  The remote stub
39861 queries the target's operating system and reports which libraries
39862 are loaded.
39863
39864 The @samp{qXfer:libraries:read} packet returns an XML document which
39865 lists loaded libraries and their offsets.  Each library has an
39866 associated name and one or more segment or section base addresses,
39867 which report where the library was loaded in memory.
39868
39869 For the common case of libraries that are fully linked binaries, the
39870 library should have a list of segments.  If the target supports
39871 dynamic linking of a relocatable object file, its library XML element
39872 should instead include a list of allocated sections.  The segment or
39873 section bases are start addresses, not relocation offsets; they do not
39874 depend on the library's link-time base addresses.
39875
39876 @value{GDBN} must be linked with the Expat library to support XML
39877 library lists.  @xref{Expat}.
39878
39879 A simple memory map, with one loaded library relocated by a single
39880 offset, looks like this:
39881
39882 @smallexample
39883 <library-list>
39884   <library name="/lib/libc.so.6">
39885     <segment address="0x10000000"/>
39886   </library>
39887 </library-list>
39888 @end smallexample
39889
39890 Another simple memory map, with one loaded library with three
39891 allocated sections (.text, .data, .bss), looks like this:
39892
39893 @smallexample
39894 <library-list>
39895   <library name="sharedlib.o">
39896     <section address="0x10000000"/>
39897     <section address="0x20000000"/>
39898     <section address="0x30000000"/>
39899   </library>
39900 </library-list>
39901 @end smallexample
39902
39903 The format of a library list is described by this DTD:
39904
39905 @smallexample
39906 <!-- library-list: Root element with versioning -->
39907 <!ELEMENT library-list  (library)*>
39908 <!ATTLIST library-list  version CDATA   #FIXED  "1.0">
39909 <!ELEMENT library       (segment*, section*)>
39910 <!ATTLIST library       name    CDATA   #REQUIRED>
39911 <!ELEMENT segment       EMPTY>
39912 <!ATTLIST segment       address CDATA   #REQUIRED>
39913 <!ELEMENT section       EMPTY>
39914 <!ATTLIST section       address CDATA   #REQUIRED>
39915 @end smallexample
39916
39917 In addition, segments and section descriptors cannot be mixed within a
39918 single library element, and you must supply at least one segment or
39919 section for each library.
39920
39921 @node Library List Format for SVR4 Targets
39922 @section Library List Format for SVR4 Targets
39923 @cindex library list format, remote protocol
39924
39925 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
39926 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
39927 shared libraries.  Still a special library list provided by this packet is
39928 more efficient for the @value{GDBN} remote protocol.
39929
39930 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
39931 loaded libraries and their SVR4 linker parameters.  For each library on SVR4
39932 target, the following parameters are reported:
39933
39934 @itemize @minus
39935 @item
39936 @code{name}, the absolute file name from the @code{l_name} field of
39937 @code{struct link_map}.
39938 @item
39939 @code{lm} with address of @code{struct link_map} used for TLS
39940 (Thread Local Storage) access.
39941 @item
39942 @code{l_addr}, the displacement as read from the field @code{l_addr} of
39943 @code{struct link_map}.  For prelinked libraries this is not an absolute
39944 memory address.  It is a displacement of absolute memory address against
39945 address the file was prelinked to during the library load.
39946 @item
39947 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
39948 @end itemize
39949
39950 Additionally the single @code{main-lm} attribute specifies address of
39951 @code{struct link_map} used for the main executable.  This parameter is used
39952 for TLS access and its presence is optional.
39953
39954 @value{GDBN} must be linked with the Expat library to support XML
39955 SVR4 library lists.  @xref{Expat}.
39956
39957 A simple memory map, with two loaded libraries (which do not use prelink),
39958 looks like this:
39959
39960 @smallexample
39961 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
39962   <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
39963            l_ld="0xe4eefc"/>
39964   <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
39965            l_ld="0x152350"/>
39966 </library-list-svr>
39967 @end smallexample
39968
39969 The format of an SVR4 library list is described by this DTD:
39970
39971 @smallexample
39972 <!-- library-list-svr4: Root element with versioning -->
39973 <!ELEMENT library-list-svr4  (library)*>
39974 <!ATTLIST library-list-svr4  version CDATA   #FIXED  "1.0">
39975 <!ATTLIST library-list-svr4  main-lm CDATA   #IMPLIED>
39976 <!ELEMENT library            EMPTY>
39977 <!ATTLIST library            name    CDATA   #REQUIRED>
39978 <!ATTLIST library            lm      CDATA   #REQUIRED>
39979 <!ATTLIST library            l_addr  CDATA   #REQUIRED>
39980 <!ATTLIST library            l_ld    CDATA   #REQUIRED>
39981 @end smallexample
39982
39983 @node Memory Map Format
39984 @section Memory Map Format
39985 @cindex memory map format
39986
39987 To be able to write into flash memory, @value{GDBN} needs to obtain a
39988 memory map from the target.  This section describes the format of the
39989 memory map.
39990
39991 The memory map is obtained using the @samp{qXfer:memory-map:read}
39992 (@pxref{qXfer memory map read}) packet and is an XML document that
39993 lists memory regions.
39994
39995 @value{GDBN} must be linked with the Expat library to support XML
39996 memory maps.  @xref{Expat}.
39997
39998 The top-level structure of the document is shown below:
39999
40000 @smallexample
40001 <?xml version="1.0"?>
40002 <!DOCTYPE memory-map
40003           PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40004                  "http://sourceware.org/gdb/gdb-memory-map.dtd">
40005 <memory-map>
40006     region...
40007 </memory-map>
40008 @end smallexample
40009
40010 Each region can be either:
40011
40012 @itemize
40013
40014 @item
40015 A region of RAM starting at @var{addr} and extending for @var{length}
40016 bytes from there:
40017
40018 @smallexample
40019 <memory type="ram" start="@var{addr}" length="@var{length}"/>
40020 @end smallexample
40021
40022
40023 @item
40024 A region of read-only memory:
40025
40026 @smallexample
40027 <memory type="rom" start="@var{addr}" length="@var{length}"/>
40028 @end smallexample
40029
40030
40031 @item
40032 A region of flash memory, with erasure blocks @var{blocksize}
40033 bytes in length:
40034
40035 @smallexample
40036 <memory type="flash" start="@var{addr}" length="@var{length}">
40037   <property name="blocksize">@var{blocksize}</property>
40038 </memory>
40039 @end smallexample
40040
40041 @end itemize
40042
40043 Regions must not overlap.  @value{GDBN} assumes that areas of memory not covered
40044 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
40045 packets to write to addresses in such ranges.
40046
40047 The formal DTD for memory map format is given below:
40048
40049 @smallexample
40050 <!-- ................................................... -->
40051 <!-- Memory Map XML DTD ................................ -->
40052 <!-- File: memory-map.dtd .............................. -->
40053 <!-- .................................... .............. -->
40054 <!-- memory-map.dtd -->
40055 <!-- memory-map: Root element with versioning -->
40056 <!ELEMENT memory-map (memory | property)>
40057 <!ATTLIST memory-map    version CDATA   #FIXED  "1.0.0">
40058 <!ELEMENT memory (property)>
40059 <!-- memory: Specifies a memory region,
40060              and its type, or device. -->
40061 <!ATTLIST memory        type    CDATA   #REQUIRED
40062                         start   CDATA   #REQUIRED
40063                         length  CDATA   #REQUIRED
40064                         device  CDATA   #IMPLIED>
40065 <!-- property: Generic attribute tag -->
40066 <!ELEMENT property (#PCDATA | property)*>
40067 <!ATTLIST property      name    CDATA   #REQUIRED>
40068 @end smallexample
40069
40070 @node Thread List Format
40071 @section Thread List Format
40072 @cindex thread list format
40073
40074 To efficiently update the list of threads and their attributes,
40075 @value{GDBN} issues the @samp{qXfer:threads:read} packet
40076 (@pxref{qXfer threads read}) and obtains the XML document with
40077 the following structure:
40078
40079 @smallexample
40080 <?xml version="1.0"?>
40081 <threads>
40082     <thread id="id" core="0">
40083     ... description ...
40084     </thread>
40085 </threads>
40086 @end smallexample
40087
40088 Each @samp{thread} element must have the @samp{id} attribute that
40089 identifies the thread (@pxref{thread-id syntax}).  The
40090 @samp{core} attribute, if present, specifies which processor core
40091 the thread was last executing on.  The content of the of @samp{thread}
40092 element is interpreted as human-readable auxilliary information.
40093
40094 @node Traceframe Info Format
40095 @section Traceframe Info Format
40096 @cindex traceframe info format
40097
40098 To be able to know which objects in the inferior can be examined when
40099 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
40100 memory ranges, registers and trace state variables that have been
40101 collected in a traceframe.
40102
40103 This list is obtained using the @samp{qXfer:traceframe-info:read}
40104 (@pxref{qXfer traceframe info read}) packet and is an XML document.
40105
40106 @value{GDBN} must be linked with the Expat library to support XML
40107 traceframe info discovery.  @xref{Expat}.
40108
40109 The top-level structure of the document is shown below:
40110
40111 @smallexample
40112 <?xml version="1.0"?>
40113 <!DOCTYPE traceframe-info
40114           PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
40115                  "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
40116 <traceframe-info>
40117    block...
40118 </traceframe-info>
40119 @end smallexample
40120
40121 Each traceframe block can be either:
40122
40123 @itemize
40124
40125 @item
40126 A region of collected memory starting at @var{addr} and extending for
40127 @var{length} bytes from there:
40128
40129 @smallexample
40130 <memory start="@var{addr}" length="@var{length}"/>
40131 @end smallexample
40132
40133 @end itemize
40134
40135 The formal DTD for the traceframe info format is given below:
40136
40137 @smallexample
40138 <!ELEMENT traceframe-info  (memory)* >
40139 <!ATTLIST traceframe-info  version CDATA   #FIXED  "1.0">
40140
40141 <!ELEMENT memory        EMPTY>
40142 <!ATTLIST memory        start   CDATA   #REQUIRED
40143                         length  CDATA   #REQUIRED>
40144 @end smallexample
40145
40146 @include agentexpr.texi
40147
40148 @node Target Descriptions
40149 @appendix Target Descriptions
40150 @cindex target descriptions
40151
40152 One of the challenges of using @value{GDBN} to debug embedded systems
40153 is that there are so many minor variants of each processor
40154 architecture in use.  It is common practice for vendors to start with
40155 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
40156 and then make changes to adapt it to a particular market niche.  Some
40157 architectures have hundreds of variants, available from dozens of
40158 vendors.  This leads to a number of problems:
40159
40160 @itemize @bullet
40161 @item
40162 With so many different customized processors, it is difficult for
40163 the @value{GDBN} maintainers to keep up with the changes.
40164 @item
40165 Since individual variants may have short lifetimes or limited
40166 audiences, it may not be worthwhile to carry information about every
40167 variant in the @value{GDBN} source tree.
40168 @item
40169 When @value{GDBN} does support the architecture of the embedded system
40170 at hand, the task of finding the correct architecture name to give the
40171 @command{set architecture} command can be error-prone.
40172 @end itemize
40173
40174 To address these problems, the @value{GDBN} remote protocol allows a
40175 target system to not only identify itself to @value{GDBN}, but to
40176 actually describe its own features.  This lets @value{GDBN} support
40177 processor variants it has never seen before --- to the extent that the
40178 descriptions are accurate, and that @value{GDBN} understands them.
40179
40180 @value{GDBN} must be linked with the Expat library to support XML
40181 target descriptions.  @xref{Expat}.
40182
40183 @menu
40184 * Retrieving Descriptions::         How descriptions are fetched from a target.
40185 * Target Description Format::       The contents of a target description.
40186 * Predefined Target Types::         Standard types available for target
40187                                     descriptions.
40188 * Standard Target Features::        Features @value{GDBN} knows about.
40189 @end menu
40190
40191 @node Retrieving Descriptions
40192 @section Retrieving Descriptions
40193
40194 Target descriptions can be read from the target automatically, or
40195 specified by the user manually.  The default behavior is to read the
40196 description from the target.  @value{GDBN} retrieves it via the remote
40197 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
40198 qXfer}).  The @var{annex} in the @samp{qXfer} packet will be
40199 @samp{target.xml}.  The contents of the @samp{target.xml} annex are an
40200 XML document, of the form described in @ref{Target Description
40201 Format}.
40202
40203 Alternatively, you can specify a file to read for the target description.
40204 If a file is set, the target will not be queried.  The commands to
40205 specify a file are:
40206
40207 @table @code
40208 @cindex set tdesc filename
40209 @item set tdesc filename @var{path}
40210 Read the target description from @var{path}.
40211
40212 @cindex unset tdesc filename
40213 @item unset tdesc filename
40214 Do not read the XML target description from a file.  @value{GDBN}
40215 will use the description supplied by the current target.
40216
40217 @cindex show tdesc filename
40218 @item show tdesc filename
40219 Show the filename to read for a target description, if any.
40220 @end table
40221
40222
40223 @node Target Description Format
40224 @section Target Description Format
40225 @cindex target descriptions, XML format
40226
40227 A target description annex is an @uref{http://www.w3.org/XML/, XML}
40228 document which complies with the Document Type Definition provided in
40229 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}.  This
40230 means you can use generally available tools like @command{xmllint} to
40231 check that your feature descriptions are well-formed and valid.
40232 However, to help people unfamiliar with XML write descriptions for
40233 their targets, we also describe the grammar here.
40234
40235 Target descriptions can identify the architecture of the remote target
40236 and (for some architectures) provide information about custom register
40237 sets.  They can also identify the OS ABI of the remote target.
40238 @value{GDBN} can use this information to autoconfigure for your
40239 target, or to warn you if you connect to an unsupported target.
40240
40241 Here is a simple target description:
40242
40243 @smallexample
40244 <target version="1.0">
40245   <architecture>i386:x86-64</architecture>
40246 </target>
40247 @end smallexample
40248
40249 @noindent
40250 This minimal description only says that the target uses
40251 the x86-64 architecture.
40252
40253 A target description has the following overall form, with [ ] marking
40254 optional elements and @dots{} marking repeatable elements.  The elements
40255 are explained further below.
40256
40257 @smallexample
40258 <?xml version="1.0"?>
40259 <!DOCTYPE target SYSTEM "gdb-target.dtd">
40260 <target version="1.0">
40261   @r{[}@var{architecture}@r{]}
40262   @r{[}@var{osabi}@r{]}
40263   @r{[}@var{compatible}@r{]}
40264   @r{[}@var{feature}@dots{}@r{]}
40265 </target>
40266 @end smallexample
40267
40268 @noindent
40269 The description is generally insensitive to whitespace and line
40270 breaks, under the usual common-sense rules.  The XML version
40271 declaration and document type declaration can generally be omitted
40272 (@value{GDBN} does not require them), but specifying them may be
40273 useful for XML validation tools.  The @samp{version} attribute for
40274 @samp{<target>} may also be omitted, but we recommend
40275 including it; if future versions of @value{GDBN} use an incompatible
40276 revision of @file{gdb-target.dtd}, they will detect and report
40277 the version mismatch.
40278
40279 @subsection Inclusion
40280 @cindex target descriptions, inclusion
40281 @cindex XInclude
40282 @ifnotinfo
40283 @cindex <xi:include>
40284 @end ifnotinfo
40285
40286 It can sometimes be valuable to split a target description up into
40287 several different annexes, either for organizational purposes, or to
40288 share files between different possible target descriptions.  You can
40289 divide a description into multiple files by replacing any element of
40290 the target description with an inclusion directive of the form:
40291
40292 @smallexample
40293 <xi:include href="@var{document}"/>
40294 @end smallexample
40295
40296 @noindent
40297 When @value{GDBN} encounters an element of this form, it will retrieve
40298 the named XML @var{document}, and replace the inclusion directive with
40299 the contents of that document.  If the current description was read
40300 using @samp{qXfer}, then so will be the included document;
40301 @var{document} will be interpreted as the name of an annex.  If the
40302 current description was read from a file, @value{GDBN} will look for
40303 @var{document} as a file in the same directory where it found the
40304 original description.
40305
40306 @subsection Architecture
40307 @cindex <architecture>
40308
40309 An @samp{<architecture>} element has this form:
40310
40311 @smallexample
40312   <architecture>@var{arch}</architecture>
40313 @end smallexample
40314
40315 @var{arch} is one of the architectures from the set accepted by
40316 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
40317
40318 @subsection OS ABI
40319 @cindex @code{<osabi>}
40320
40321 This optional field was introduced in @value{GDBN} version 7.0.
40322 Previous versions of @value{GDBN} ignore it.
40323
40324 An @samp{<osabi>} element has this form:
40325
40326 @smallexample
40327   <osabi>@var{abi-name}</osabi>
40328 @end smallexample
40329
40330 @var{abi-name} is an OS ABI name from the same selection accepted by
40331 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
40332
40333 @subsection Compatible Architecture
40334 @cindex @code{<compatible>}
40335
40336 This optional field was introduced in @value{GDBN} version 7.0.
40337 Previous versions of @value{GDBN} ignore it.
40338
40339 A @samp{<compatible>} element has this form:
40340
40341 @smallexample
40342   <compatible>@var{arch}</compatible>
40343 @end smallexample
40344
40345 @var{arch} is one of the architectures from the set accepted by
40346 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
40347
40348 A @samp{<compatible>} element is used to specify that the target
40349 is able to run binaries in some other than the main target architecture
40350 given by the @samp{<architecture>} element.  For example, on the
40351 Cell Broadband Engine, the main architecture is @code{powerpc:common}
40352 or @code{powerpc:common64}, but the system is able to run binaries
40353 in the @code{spu} architecture as well.  The way to describe this
40354 capability with @samp{<compatible>} is as follows:
40355
40356 @smallexample
40357   <architecture>powerpc:common</architecture>
40358   <compatible>spu</compatible>
40359 @end smallexample
40360
40361 @subsection Features
40362 @cindex <feature>
40363
40364 Each @samp{<feature>} describes some logical portion of the target
40365 system.  Features are currently used to describe available CPU
40366 registers and the types of their contents.  A @samp{<feature>} element
40367 has this form:
40368
40369 @smallexample
40370 <feature name="@var{name}">
40371   @r{[}@var{type}@dots{}@r{]}
40372   @var{reg}@dots{}
40373 </feature>
40374 @end smallexample
40375
40376 @noindent
40377 Each feature's name should be unique within the description.  The name
40378 of a feature does not matter unless @value{GDBN} has some special
40379 knowledge of the contents of that feature; if it does, the feature
40380 should have its standard name.  @xref{Standard Target Features}.
40381
40382 @subsection Types
40383
40384 Any register's value is a collection of bits which @value{GDBN} must
40385 interpret.  The default interpretation is a two's complement integer,
40386 but other types can be requested by name in the register description.
40387 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
40388 Target Types}), and the description can define additional composite types.
40389
40390 Each type element must have an @samp{id} attribute, which gives
40391 a unique (within the containing @samp{<feature>}) name to the type.
40392 Types must be defined before they are used.
40393
40394 @cindex <vector>
40395 Some targets offer vector registers, which can be treated as arrays
40396 of scalar elements.  These types are written as @samp{<vector>} elements,
40397 specifying the array element type, @var{type}, and the number of elements,
40398 @var{count}:
40399
40400 @smallexample
40401 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
40402 @end smallexample
40403
40404 @cindex <union>
40405 If a register's value is usefully viewed in multiple ways, define it
40406 with a union type containing the useful representations.  The
40407 @samp{<union>} element contains one or more @samp{<field>} elements,
40408 each of which has a @var{name} and a @var{type}:
40409
40410 @smallexample
40411 <union id="@var{id}">
40412   <field name="@var{name}" type="@var{type}"/>
40413   @dots{}
40414 </union>
40415 @end smallexample
40416
40417 @cindex <struct>
40418 If a register's value is composed from several separate values, define
40419 it with a structure type.  There are two forms of the @samp{<struct>}
40420 element; a @samp{<struct>} element must either contain only bitfields
40421 or contain no bitfields.  If the structure contains only bitfields,
40422 its total size in bytes must be specified, each bitfield must have an
40423 explicit start and end, and bitfields are automatically assigned an
40424 integer type.  The field's @var{start} should be less than or
40425 equal to its @var{end}, and zero represents the least significant bit.
40426
40427 @smallexample
40428 <struct id="@var{id}" size="@var{size}">
40429   <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40430   @dots{}
40431 </struct>
40432 @end smallexample
40433
40434 If the structure contains no bitfields, then each field has an
40435 explicit type, and no implicit padding is added.
40436
40437 @smallexample
40438 <struct id="@var{id}">
40439   <field name="@var{name}" type="@var{type}"/>
40440   @dots{}
40441 </struct>
40442 @end smallexample
40443
40444 @cindex <flags>
40445 If a register's value is a series of single-bit flags, define it with
40446 a flags type.  The @samp{<flags>} element has an explicit @var{size}
40447 and contains one or more @samp{<field>} elements.  Each field has a
40448 @var{name}, a @var{start}, and an @var{end}.  Only single-bit flags
40449 are supported.
40450
40451 @smallexample
40452 <flags id="@var{id}" size="@var{size}">
40453   <field name="@var{name}" start="@var{start}" end="@var{end}"/>
40454   @dots{}
40455 </flags>
40456 @end smallexample
40457
40458 @subsection Registers
40459 @cindex <reg>
40460
40461 Each register is represented as an element with this form:
40462
40463 @smallexample
40464 <reg name="@var{name}"
40465      bitsize="@var{size}"
40466      @r{[}regnum="@var{num}"@r{]}
40467      @r{[}save-restore="@var{save-restore}"@r{]}
40468      @r{[}type="@var{type}"@r{]}
40469      @r{[}group="@var{group}"@r{]}/>
40470 @end smallexample
40471
40472 @noindent
40473 The components are as follows:
40474
40475 @table @var
40476
40477 @item name
40478 The register's name; it must be unique within the target description.
40479
40480 @item bitsize
40481 The register's size, in bits.
40482
40483 @item regnum
40484 The register's number.  If omitted, a register's number is one greater
40485 than that of the previous register (either in the current feature or in
40486 a preceding feature); the first register in the target description
40487 defaults to zero.  This register number is used to read or write
40488 the register; e.g.@: it is used in the remote @code{p} and @code{P}
40489 packets, and registers appear in the @code{g} and @code{G} packets
40490 in order of increasing register number.
40491
40492 @item save-restore
40493 Whether the register should be preserved across inferior function
40494 calls; this must be either @code{yes} or @code{no}.  The default is
40495 @code{yes}, which is appropriate for most registers except for
40496 some system control registers; this is not related to the target's
40497 ABI.
40498
40499 @item type
40500 The type of the register.  @var{type} may be a predefined type, a type
40501 defined in the current feature, or one of the special types @code{int}
40502 and @code{float}.  @code{int} is an integer type of the correct size
40503 for @var{bitsize}, and @code{float} is a floating point type (in the
40504 architecture's normal floating point format) of the correct size for
40505 @var{bitsize}.  The default is @code{int}.
40506
40507 @item group
40508 The register group to which this register belongs.  @var{group} must
40509 be either @code{general}, @code{float}, or @code{vector}.  If no
40510 @var{group} is specified, @value{GDBN} will not display the register
40511 in @code{info registers}.
40512
40513 @end table
40514
40515 @node Predefined Target Types
40516 @section Predefined Target Types
40517 @cindex target descriptions, predefined types
40518
40519 Type definitions in the self-description can build up composite types
40520 from basic building blocks, but can not define fundamental types.  Instead,
40521 standard identifiers are provided by @value{GDBN} for the fundamental
40522 types.  The currently supported types are:
40523
40524 @table @code
40525
40526 @item int8
40527 @itemx int16
40528 @itemx int32
40529 @itemx int64
40530 @itemx int128
40531 Signed integer types holding the specified number of bits.
40532
40533 @item uint8
40534 @itemx uint16
40535 @itemx uint32
40536 @itemx uint64
40537 @itemx uint128
40538 Unsigned integer types holding the specified number of bits.
40539
40540 @item code_ptr
40541 @itemx data_ptr
40542 Pointers to unspecified code and data.  The program counter and
40543 any dedicated return address register may be marked as code
40544 pointers; printing a code pointer converts it into a symbolic
40545 address.  The stack pointer and any dedicated address registers
40546 may be marked as data pointers.
40547
40548 @item ieee_single
40549 Single precision IEEE floating point.
40550
40551 @item ieee_double
40552 Double precision IEEE floating point.
40553
40554 @item arm_fpa_ext
40555 The 12-byte extended precision format used by ARM FPA registers.
40556
40557 @item i387_ext
40558 The 10-byte extended precision format used by x87 registers.
40559
40560 @item i386_eflags
40561 32bit @sc{eflags} register used by x86.
40562
40563 @item i386_mxcsr
40564 32bit @sc{mxcsr} register used by x86.
40565
40566 @end table
40567
40568 @node Standard Target Features
40569 @section Standard Target Features
40570 @cindex target descriptions, standard features
40571
40572 A target description must contain either no registers or all the
40573 target's registers.  If the description contains no registers, then
40574 @value{GDBN} will assume a default register layout, selected based on
40575 the architecture.  If the description contains any registers, the
40576 default layout will not be used; the standard registers must be
40577 described in the target description, in such a way that @value{GDBN}
40578 can recognize them.
40579
40580 This is accomplished by giving specific names to feature elements
40581 which contain standard registers.  @value{GDBN} will look for features
40582 with those names and verify that they contain the expected registers;
40583 if any known feature is missing required registers, or if any required
40584 feature is missing, @value{GDBN} will reject the target
40585 description.  You can add additional registers to any of the
40586 standard features --- @value{GDBN} will display them just as if
40587 they were added to an unrecognized feature.
40588
40589 This section lists the known features and their expected contents.
40590 Sample XML documents for these features are included in the
40591 @value{GDBN} source tree, in the directory @file{gdb/features}.
40592
40593 Names recognized by @value{GDBN} should include the name of the
40594 company or organization which selected the name, and the overall
40595 architecture to which the feature applies; so e.g.@: the feature
40596 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
40597
40598 The names of registers are not case sensitive for the purpose
40599 of recognizing standard features, but @value{GDBN} will only display
40600 registers using the capitalization used in the description.
40601
40602 @menu
40603 * ARM Features::
40604 * i386 Features::
40605 * MIPS Features::
40606 * M68K Features::
40607 * PowerPC Features::
40608 * TIC6x Features::
40609 @end menu
40610
40611
40612 @node ARM Features
40613 @subsection ARM Features
40614 @cindex target descriptions, ARM features
40615
40616 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
40617 ARM targets.
40618 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
40619 @samp{lr}, @samp{pc}, and @samp{cpsr}.
40620
40621 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
40622 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}.  It should contain
40623 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
40624 and @samp{xpsr}.
40625
40626 The @samp{org.gnu.gdb.arm.fpa} feature is optional.  If present, it
40627 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
40628
40629 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional.  If present,
40630 it should contain at least registers @samp{wR0} through @samp{wR15} and
40631 @samp{wCGR0} through @samp{wCGR3}.  The @samp{wCID}, @samp{wCon},
40632 @samp{wCSSF}, and @samp{wCASF} registers are optional.
40633
40634 The @samp{org.gnu.gdb.arm.vfp} feature is optional.  If present, it
40635 should contain at least registers @samp{d0} through @samp{d15}.  If
40636 they are present, @samp{d16} through @samp{d31} should also be included.
40637 @value{GDBN} will synthesize the single-precision registers from
40638 halves of the double-precision registers.
40639
40640 The @samp{org.gnu.gdb.arm.neon} feature is optional.  It does not
40641 need to contain registers; it instructs @value{GDBN} to display the
40642 VFP double-precision registers as vectors and to synthesize the
40643 quad-precision registers from pairs of double-precision registers.
40644 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
40645 be present and include 32 double-precision registers.
40646
40647 @node i386 Features
40648 @subsection i386 Features
40649 @cindex target descriptions, i386 features
40650
40651 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
40652 targets.  It should describe the following registers:
40653
40654 @itemize @minus
40655 @item
40656 @samp{eax} through @samp{edi} plus @samp{eip} for i386
40657 @item
40658 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
40659 @item
40660 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
40661 @samp{fs}, @samp{gs}
40662 @item 
40663 @samp{st0} through @samp{st7}
40664 @item 
40665 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
40666 @samp{foseg}, @samp{fooff} and @samp{fop}
40667 @end itemize
40668
40669 The register sets may be different, depending on the target.
40670
40671 The @samp{org.gnu.gdb.i386.sse} feature is optional.  It should
40672 describe registers:
40673
40674 @itemize @minus
40675 @item
40676 @samp{xmm0} through @samp{xmm7} for i386
40677 @item
40678 @samp{xmm0} through @samp{xmm15} for amd64
40679 @item 
40680 @samp{mxcsr}
40681 @end itemize
40682
40683 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
40684 @samp{org.gnu.gdb.i386.sse} feature.  It should
40685 describe the upper 128 bits of @sc{ymm} registers:
40686
40687 @itemize @minus
40688 @item
40689 @samp{ymm0h} through @samp{ymm7h} for i386
40690 @item
40691 @samp{ymm0h} through @samp{ymm15h} for amd64
40692 @end itemize
40693
40694 The @samp{org.gnu.gdb.i386.linux} feature is optional.  It should
40695 describe a single register, @samp{orig_eax}.
40696
40697 @node MIPS Features
40698 @subsection @acronym{MIPS} Features
40699 @cindex target descriptions, @acronym{MIPS} features
40700
40701 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
40702 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
40703 @samp{hi}, and @samp{pc}.  They may be 32-bit or 64-bit depending
40704 on the target.
40705
40706 The @samp{org.gnu.gdb.mips.cp0} feature is also required.  It should
40707 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
40708 registers.  They may be 32-bit or 64-bit depending on the target.
40709
40710 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
40711 it may be optional in a future version of @value{GDBN}.  It should
40712 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
40713 @samp{fir}.  They may be 32-bit or 64-bit depending on the target.
40714
40715 The @samp{org.gnu.gdb.mips.dsp} feature is optional.  It should
40716 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
40717 @samp{lo3}, and @samp{dspctl}.  The @samp{dspctl} register should
40718 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
40719
40720 The @samp{org.gnu.gdb.mips.linux} feature is optional.  It should
40721 contain a single register, @samp{restart}, which is used by the
40722 Linux kernel to control restartable syscalls.
40723
40724 @node M68K Features
40725 @subsection M68K Features
40726 @cindex target descriptions, M68K features
40727
40728 @table @code
40729 @item @samp{org.gnu.gdb.m68k.core}
40730 @itemx @samp{org.gnu.gdb.coldfire.core}
40731 @itemx @samp{org.gnu.gdb.fido.core}
40732 One of those features must be always present. 
40733 The feature that is present determines which flavor of m68k is
40734 used.  The feature that is present should contain registers
40735 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
40736 @samp{sp}, @samp{ps} and @samp{pc}.
40737
40738 @item @samp{org.gnu.gdb.coldfire.fp}
40739 This feature is optional.  If present, it should contain registers
40740 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
40741 @samp{fpiaddr}.
40742 @end table
40743
40744 @node PowerPC Features
40745 @subsection PowerPC Features
40746 @cindex target descriptions, PowerPC features
40747
40748 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
40749 targets.  It should contain registers @samp{r0} through @samp{r31},
40750 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
40751 @samp{xer}.  They may be 32-bit or 64-bit depending on the target.
40752
40753 The @samp{org.gnu.gdb.power.fpu} feature is optional.  It should
40754 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
40755
40756 The @samp{org.gnu.gdb.power.altivec} feature is optional.  It should
40757 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
40758 and @samp{vrsave}.
40759
40760 The @samp{org.gnu.gdb.power.vsx} feature is optional.  It should
40761 contain registers @samp{vs0h} through @samp{vs31h}.  @value{GDBN}
40762 will combine these registers with the floating point registers
40763 (@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
40764 through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
40765 through @samp{vs63}, the set of vector registers for POWER7.
40766
40767 The @samp{org.gnu.gdb.power.spe} feature is optional.  It should
40768 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
40769 @samp{spefscr}.  SPE targets should provide 32-bit registers in
40770 @samp{org.gnu.gdb.power.core} and provide the upper halves in
40771 @samp{ev0h} through @samp{ev31h}.  @value{GDBN} will combine
40772 these to present registers @samp{ev0} through @samp{ev31} to the
40773 user.
40774
40775 @node TIC6x Features
40776 @subsection TMS320C6x Features
40777 @cindex target descriptions, TIC6x features
40778 @cindex target descriptions, TMS320C6x features
40779 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
40780 targets.  It should contain registers @samp{A0} through @samp{A15},
40781 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
40782
40783 The @samp{org.gnu.gdb.tic6x.gp} feature is optional.  It should
40784 contain registers @samp{A16} through @samp{A31} and @samp{B16}
40785 through @samp{B31}.
40786
40787 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional.  It should
40788 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
40789
40790 @node Operating System Information
40791 @appendix Operating System Information
40792 @cindex operating system information
40793
40794 @menu
40795 * Process list::
40796 @end menu
40797
40798 Users of @value{GDBN} often wish to obtain information about the state of
40799 the operating system running on the target---for example the list of
40800 processes, or the list of open files.  This section describes the
40801 mechanism that makes it possible.  This mechanism is similar to the 
40802 target features mechanism (@pxref{Target Descriptions}), but focuses
40803 on a different aspect of target.
40804
40805 Operating system information is retrived from the target via the
40806 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
40807 read}).  The object name in the request should be @samp{osdata}, and
40808 the @var{annex} identifies the data to be fetched.
40809
40810 @node Process list
40811 @appendixsection Process list
40812 @cindex operating system information, process list
40813
40814 When requesting the process list, the @var{annex} field in the
40815 @samp{qXfer} request should be @samp{processes}.  The returned data is
40816 an XML document.  The formal syntax of this document is defined in
40817 @file{gdb/features/osdata.dtd}.
40818
40819 An example document is:
40820
40821 @smallexample
40822 <?xml version="1.0"?>
40823 <!DOCTYPE target SYSTEM "osdata.dtd">
40824 <osdata type="processes">
40825   <item>
40826     <column name="pid">1</column>
40827     <column name="user">root</column>
40828     <column name="command">/sbin/init</column>
40829     <column name="cores">1,2,3</column>
40830   </item>
40831 </osdata>
40832 @end smallexample
40833
40834 Each item should include a column whose name is @samp{pid}.  The value
40835 of that column should identify the process on the target.  The
40836 @samp{user} and @samp{command} columns are optional, and will be
40837 displayed by @value{GDBN}.  The @samp{cores} column, if present,
40838 should contain a comma-separated list of cores that this process
40839 is running on.  Target may provide additional columns,
40840 which @value{GDBN} currently ignores.
40841
40842 @node Trace File Format
40843 @appendix Trace File Format
40844 @cindex trace file format
40845
40846 The trace file comes in three parts: a header, a textual description
40847 section, and a trace frame section with binary data.
40848
40849 The header has the form @code{\x7fTRACE0\n}.  The first byte is
40850 @code{0x7f} so as to indicate that the file contains binary data,
40851 while the @code{0} is a version number that may have different values
40852 in the future.
40853
40854 The description section consists of multiple lines of @sc{ascii} text
40855 separated by newline characters (@code{0xa}).  The lines may include a
40856 variety of optional descriptive or context-setting information, such
40857 as tracepoint definitions or register set size.  @value{GDBN} will
40858 ignore any line that it does not recognize.  An empty line marks the end
40859 of this section.
40860
40861 @c FIXME add some specific types of data
40862
40863 The trace frame section consists of a number of consecutive frames.
40864 Each frame begins with a two-byte tracepoint number, followed by a
40865 four-byte size giving the amount of data in the frame.  The data in
40866 the frame consists of a number of blocks, each introduced by a
40867 character indicating its type (at least register, memory, and trace
40868 state variable).  The data in this section is raw binary, not a
40869 hexadecimal or other encoding; its endianness matches the target's
40870 endianness.
40871
40872 @c FIXME bi-arch may require endianness/arch info in description section
40873
40874 @table @code
40875 @item R @var{bytes}
40876 Register block.  The number and ordering of bytes matches that of a
40877 @code{g} packet in the remote protocol.  Note that these are the
40878 actual bytes, in target order and @value{GDBN} register order, not a
40879 hexadecimal encoding.
40880
40881 @item M @var{address} @var{length} @var{bytes}...
40882 Memory block.  This is a contiguous block of memory, at the 8-byte
40883 address @var{address}, with a 2-byte length @var{length}, followed by
40884 @var{length} bytes.
40885
40886 @item V @var{number} @var{value}
40887 Trace state variable block.  This records the 8-byte signed value
40888 @var{value} of trace state variable numbered @var{number}.
40889
40890 @end table
40891
40892 Future enhancements of the trace file format may include additional types
40893 of blocks.
40894
40895 @node Index Section Format
40896 @appendix @code{.gdb_index} section format
40897 @cindex .gdb_index section format
40898 @cindex index section format
40899
40900 This section documents the index section that is created by @code{save
40901 gdb-index} (@pxref{Index Files}).  The index section is
40902 DWARF-specific; some knowledge of DWARF is assumed in this
40903 description.
40904
40905 The mapped index file format is designed to be directly
40906 @code{mmap}able on any architecture.  In most cases, a datum is
40907 represented using a little-endian 32-bit integer value, called an
40908 @code{offset_type}.  Big endian machines must byte-swap the values
40909 before using them.  Exceptions to this rule are noted.  The data is
40910 laid out such that alignment is always respected.
40911
40912 A mapped index consists of several areas, laid out in order.
40913
40914 @enumerate
40915 @item
40916 The file header.  This is a sequence of values, of @code{offset_type}
40917 unless otherwise noted:
40918
40919 @enumerate
40920 @item
40921 The version number, currently 7.  Versions 1, 2 and 3 are obsolete.
40922 Version 4 uses a different hashing function from versions 5 and 6.
40923 Version 6 includes symbols for inlined functions, whereas versions 4
40924 and 5 do not.  Version 7 adds attributes to the CU indices in the
40925 symbol table.  @value{GDBN} will only read version 4, 5, or 6 indices
40926 by specifying @code{set use-deprecated-index-sections on}.
40927
40928 @item
40929 The offset, from the start of the file, of the CU list.
40930
40931 @item
40932 The offset, from the start of the file, of the types CU list.  Note
40933 that this area can be empty, in which case this offset will be equal
40934 to the next offset.
40935
40936 @item
40937 The offset, from the start of the file, of the address area.
40938
40939 @item
40940 The offset, from the start of the file, of the symbol table.
40941
40942 @item
40943 The offset, from the start of the file, of the constant pool.
40944 @end enumerate
40945
40946 @item
40947 The CU list.  This is a sequence of pairs of 64-bit little-endian
40948 values, sorted by the CU offset.  The first element in each pair is
40949 the offset of a CU in the @code{.debug_info} section.  The second
40950 element in each pair is the length of that CU.  References to a CU
40951 elsewhere in the map are done using a CU index, which is just the
40952 0-based index into this table.  Note that if there are type CUs, then
40953 conceptually CUs and type CUs form a single list for the purposes of
40954 CU indices.
40955
40956 @item
40957 The types CU list.  This is a sequence of triplets of 64-bit
40958 little-endian values.  In a triplet, the first value is the CU offset,
40959 the second value is the type offset in the CU, and the third value is
40960 the type signature.  The types CU list is not sorted.
40961
40962 @item
40963 The address area.  The address area consists of a sequence of address
40964 entries.  Each address entry has three elements:
40965
40966 @enumerate
40967 @item
40968 The low address.  This is a 64-bit little-endian value.
40969
40970 @item
40971 The high address.  This is a 64-bit little-endian value.  Like
40972 @code{DW_AT_high_pc}, the value is one byte beyond the end.
40973
40974 @item
40975 The CU index.  This is an @code{offset_type} value.
40976 @end enumerate
40977
40978 @item
40979 The symbol table.  This is an open-addressed hash table.  The size of
40980 the hash table is always a power of 2.
40981
40982 Each slot in the hash table consists of a pair of @code{offset_type}
40983 values.  The first value is the offset of the symbol's name in the
40984 constant pool.  The second value is the offset of the CU vector in the
40985 constant pool.
40986
40987 If both values are 0, then this slot in the hash table is empty.  This
40988 is ok because while 0 is a valid constant pool index, it cannot be a
40989 valid index for both a string and a CU vector.
40990
40991 The hash value for a table entry is computed by applying an
40992 iterative hash function to the symbol's name.  Starting with an
40993 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
40994 the string is incorporated into the hash using the formula depending on the
40995 index version:
40996
40997 @table @asis
40998 @item Version 4
40999 The formula is @code{r = r * 67 + c - 113}.
41000
41001 @item Versions 5 to 7
41002 The formula is @code{r = r * 67 + tolower (c) - 113}.
41003 @end table
41004
41005 The terminating @samp{\0} is not incorporated into the hash.
41006
41007 The step size used in the hash table is computed via
41008 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
41009 value, and @samp{size} is the size of the hash table.  The step size
41010 is used to find the next candidate slot when handling a hash
41011 collision.
41012
41013 The names of C@t{++} symbols in the hash table are canonicalized.  We
41014 don't currently have a simple description of the canonicalization
41015 algorithm; if you intend to create new index sections, you must read
41016 the code.
41017
41018 @item
41019 The constant pool.  This is simply a bunch of bytes.  It is organized
41020 so that alignment is correct: CU vectors are stored first, followed by
41021 strings.
41022
41023 A CU vector in the constant pool is a sequence of @code{offset_type}
41024 values.  The first value is the number of CU indices in the vector.
41025 Each subsequent value is the index and symbol attributes of a CU in
41026 the CU list.  This element in the hash table is used to indicate which
41027 CUs define the symbol and how the symbol is used.
41028 See below for the format of each CU index+attributes entry.
41029
41030 A string in the constant pool is zero-terminated.
41031 @end enumerate
41032
41033 Attributes were added to CU index values in @code{.gdb_index} version 7.
41034 If a symbol has multiple uses within a CU then there is one
41035 CU index+attributes value for each use.
41036
41037 The format of each CU index+attributes entry is as follows
41038 (bit 0 = LSB):
41039
41040 @table @asis
41041
41042 @item Bits 0-23
41043 This is the index of the CU in the CU list.
41044 @item Bits 24-27
41045 These bits are reserved for future purposes and must be zero.
41046 @item Bits 28-30
41047 The kind of the symbol in the CU.
41048
41049 @table @asis
41050 @item 0
41051 This value is reserved and should not be used.
41052 By reserving zero the full @code{offset_type} value is backwards compatible
41053 with previous versions of the index.
41054 @item 1
41055 The symbol is a type.
41056 @item 2
41057 The symbol is a variable or an enum value.
41058 @item 3
41059 The symbol is a function.
41060 @item 4
41061 Any other kind of symbol.
41062 @item 5,6,7
41063 These values are reserved.
41064 @end table
41065
41066 @item Bit 31
41067 This bit is zero if the value is global and one if it is static.
41068
41069 The determination of whether a symbol is global or static is complicated.
41070 The authorative reference is the file @file{dwarf2read.c} in
41071 @value{GDBN} sources.
41072
41073 @end table
41074
41075 This pseudo-code describes the computation of a symbol's kind and
41076 global/static attributes in the index.
41077
41078 @smallexample
41079 is_external = get_attribute (die, DW_AT_external);
41080 language = get_attribute (cu_die, DW_AT_language);
41081 switch (die->tag)
41082   @{
41083   case DW_TAG_typedef:
41084   case DW_TAG_base_type:
41085   case DW_TAG_subrange_type:
41086     kind = TYPE;
41087     is_static = 1;
41088     break;
41089   case DW_TAG_enumerator:
41090     kind = VARIABLE;
41091     is_static = (language != CPLUS && language != JAVA);
41092     break;
41093   case DW_TAG_subprogram:
41094     kind = FUNCTION;
41095     is_static = ! (is_external || language == ADA);
41096     break;
41097   case DW_TAG_constant:
41098     kind = VARIABLE;
41099     is_static = ! is_external;
41100     break;
41101   case DW_TAG_variable:
41102     kind = VARIABLE;
41103     is_static = ! is_external;
41104     break;
41105   case DW_TAG_namespace:
41106     kind = TYPE;
41107     is_static = 0;
41108     break;
41109   case DW_TAG_class_type:
41110   case DW_TAG_interface_type:
41111   case DW_TAG_structure_type:
41112   case DW_TAG_union_type:
41113   case DW_TAG_enumeration_type:
41114     kind = TYPE;
41115     is_static = (language != CPLUS && language != JAVA);
41116     break;
41117   default:
41118     assert (0);
41119   @}
41120 @end smallexample
41121
41122 @include gpl.texi
41123
41124 @node GNU Free Documentation License
41125 @appendix GNU Free Documentation License
41126 @include fdl.texi
41127
41128 @node Concept Index
41129 @unnumbered Concept Index
41130
41131 @printindex cp
41132
41133 @node Command and Variable Index
41134 @unnumbered Command, Variable, and Function Index
41135
41136 @printindex fn
41137
41138 @tex
41139 % I think something like @@colophon should be in texinfo.  In the
41140 % meantime:
41141 \long\def\colophon{\hbox to0pt{}\vfill
41142 \centerline{The body of this manual is set in}
41143 \centerline{\fontname\tenrm,}
41144 \centerline{with headings in {\bf\fontname\tenbf}}
41145 \centerline{and examples in {\tt\fontname\tentt}.}
41146 \centerline{{\it\fontname\tenit\/},}
41147 \centerline{{\bf\fontname\tenbf}, and}
41148 \centerline{{\sl\fontname\tensl\/}}
41149 \centerline{are used for emphasis.}\vfill}
41150 \page\colophon
41151 % Blame: doc@@cygnus.com, 1991.
41152 @end tex
41153
41154 @bye