gdb:
[deliverable/binutils-gdb.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 @syncodeindex ky cp
22 @syncodeindex tp cp
23
24 @c readline appendices use @vindex, @findex and @ftable,
25 @c annotate.texi and gdbmi use @findex.
26 @syncodeindex vr cp
27 @syncodeindex fn cp
28
29 @c !!set GDB manual's edition---not the same as GDB version!
30 @c This is updated by GNU Press.
31 @set EDITION Tenth
32
33 @c !!set GDB edit command default editor
34 @set EDITOR /bin/ex
35
36 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
37
38 @c This is a dir.info fragment to support semi-automated addition of
39 @c manuals to an info tree.
40 @dircategory Software development
41 @direntry
42 * Gdb: (gdb). The GNU debugger.
43 @end direntry
44
45 @copying
46 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
47 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
48 Free Software Foundation, Inc.
49
50 Permission is granted to copy, distribute and/or modify this document
51 under the terms of the GNU Free Documentation License, Version 1.3 or
52 any later version published by the Free Software Foundation; with the
53 Invariant Sections being ``Free Software'' and ``Free Software Needs
54 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
55 and with the Back-Cover Texts as in (a) below.
56
57 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
58 this GNU Manual. Buying copies from GNU Press supports the FSF in
59 developing GNU and promoting software freedom.''
60 @end copying
61
62 @ifnottex
63 This file documents the @sc{gnu} debugger @value{GDBN}.
64
65 This is the @value{EDITION} Edition, of @cite{Debugging with
66 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
67 @ifset VERSION_PACKAGE
68 @value{VERSION_PACKAGE}
69 @end ifset
70 Version @value{GDBVN}.
71
72 @insertcopying
73 @end ifnottex
74
75 @titlepage
76 @title Debugging with @value{GDBN}
77 @subtitle The @sc{gnu} Source-Level Debugger
78 @sp 1
79 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
80 @ifset VERSION_PACKAGE
81 @sp 1
82 @subtitle @value{VERSION_PACKAGE}
83 @end ifset
84 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
85 @page
86 @tex
87 {\parskip=0pt
88 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
89 \hfill {\it Debugging with @value{GDBN}}\par
90 \hfill \TeX{}info \texinfoversion\par
91 }
92 @end tex
93
94 @vskip 0pt plus 1filll
95 Published by the Free Software Foundation @*
96 51 Franklin Street, Fifth Floor,
97 Boston, MA 02110-1301, USA@*
98 ISBN 978-0-9831592-3-0 @*
99
100 @insertcopying
101 @end titlepage
102 @page
103
104 @ifnottex
105 @node Top, Summary, (dir), (dir)
106
107 @top Debugging with @value{GDBN}
108
109 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
110
111 This is the @value{EDITION} Edition, for @value{GDBN}
112 @ifset VERSION_PACKAGE
113 @value{VERSION_PACKAGE}
114 @end ifset
115 Version @value{GDBVN}.
116
117 Copyright (C) 1988-2010 Free Software Foundation, Inc.
118
119 This edition of the GDB manual is dedicated to the memory of Fred
120 Fish. Fred was a long-standing contributor to GDB and to Free
121 software in general. We will miss him.
122
123 @menu
124 * Summary:: Summary of @value{GDBN}
125 * Sample Session:: A sample @value{GDBN} session
126
127 * Invocation:: Getting in and out of @value{GDBN}
128 * Commands:: @value{GDBN} commands
129 * Running:: Running programs under @value{GDBN}
130 * Stopping:: Stopping and continuing
131 * Reverse Execution:: Running programs backward
132 * Process Record and Replay:: Recording inferior's execution and replaying it
133 * Stack:: Examining the stack
134 * Source:: Examining source files
135 * Data:: Examining data
136 * Optimized Code:: Debugging optimized code
137 * Macros:: Preprocessor Macros
138 * Tracepoints:: Debugging remote targets non-intrusively
139 * Overlays:: Debugging programs that use overlays
140
141 * Languages:: Using @value{GDBN} with different languages
142
143 * Symbols:: Examining the symbol table
144 * Altering:: Altering execution
145 * GDB Files:: @value{GDBN} files
146 * Targets:: Specifying a debugging target
147 * Remote Debugging:: Debugging remote programs
148 * Configurations:: Configuration-specific information
149 * Controlling GDB:: Controlling @value{GDBN}
150 * Extending GDB:: Extending @value{GDBN}
151 * Interpreters:: Command Interpreters
152 * TUI:: @value{GDBN} Text User Interface
153 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
154 * GDB/MI:: @value{GDBN}'s Machine Interface.
155 * Annotations:: @value{GDBN}'s annotation interface.
156 * JIT Interface:: Using the JIT debugging interface.
157 * In-Process Agent:: In-Process Agent
158
159 * GDB Bugs:: Reporting bugs in @value{GDBN}
160
161 @ifset SYSTEM_READLINE
162 * Command Line Editing: (rluserman). Command Line Editing
163 * Using History Interactively: (history). Using History Interactively
164 @end ifset
165 @ifclear SYSTEM_READLINE
166 * Command Line Editing:: Command Line Editing
167 * Using History Interactively:: Using History Interactively
168 @end ifclear
169 * In Memoriam:: In Memoriam
170 * Formatting Documentation:: How to format and print @value{GDBN} documentation
171 * Installing GDB:: Installing GDB
172 * Maintenance Commands:: Maintenance Commands
173 * Remote Protocol:: GDB Remote Serial Protocol
174 * Agent Expressions:: The GDB Agent Expression Mechanism
175 * Target Descriptions:: How targets can describe themselves to
176 @value{GDBN}
177 * Operating System Information:: Getting additional information from
178 the operating system
179 * Trace File Format:: GDB trace file format
180 * Index Section Format:: .gdb_index section format
181 * Copying:: GNU General Public License says
182 how you can copy and share GDB
183 * GNU Free Documentation License:: The license for this documentation
184 * Index:: Index
185 @end menu
186
187 @end ifnottex
188
189 @contents
190
191 @node Summary
192 @unnumbered Summary of @value{GDBN}
193
194 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
195 going on ``inside'' another program while it executes---or what another
196 program was doing at the moment it crashed.
197
198 @value{GDBN} can do four main kinds of things (plus other things in support of
199 these) to help you catch bugs in the act:
200
201 @itemize @bullet
202 @item
203 Start your program, specifying anything that might affect its behavior.
204
205 @item
206 Make your program stop on specified conditions.
207
208 @item
209 Examine what has happened, when your program has stopped.
210
211 @item
212 Change things in your program, so you can experiment with correcting the
213 effects of one bug and go on to learn about another.
214 @end itemize
215
216 You can use @value{GDBN} to debug programs written in C and C@t{++}.
217 For more information, see @ref{Supported Languages,,Supported Languages}.
218 For more information, see @ref{C,,C and C++}.
219
220 Support for D is partial. For information on D, see
221 @ref{D,,D}.
222
223 @cindex Modula-2
224 Support for Modula-2 is partial. For information on Modula-2, see
225 @ref{Modula-2,,Modula-2}.
226
227 Support for OpenCL C is partial. For information on OpenCL C, see
228 @ref{OpenCL C,,OpenCL C}.
229
230 @cindex Pascal
231 Debugging Pascal programs which use sets, subranges, file variables, or
232 nested functions does not currently work. @value{GDBN} does not support
233 entering expressions, printing values, or similar features using Pascal
234 syntax.
235
236 @cindex Fortran
237 @value{GDBN} can be used to debug programs written in Fortran, although
238 it may be necessary to refer to some variables with a trailing
239 underscore.
240
241 @value{GDBN} can be used to debug programs written in Objective-C,
242 using either the Apple/NeXT or the GNU Objective-C runtime.
243
244 @menu
245 * Free Software:: Freely redistributable software
246 * Contributors:: Contributors to GDB
247 @end menu
248
249 @node Free Software
250 @unnumberedsec Free Software
251
252 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
253 General Public License
254 (GPL). The GPL gives you the freedom to copy or adapt a licensed
255 program---but every person getting a copy also gets with it the
256 freedom to modify that copy (which means that they must get access to
257 the source code), and the freedom to distribute further copies.
258 Typical software companies use copyrights to limit your freedoms; the
259 Free Software Foundation uses the GPL to preserve these freedoms.
260
261 Fundamentally, the General Public License is a license which says that
262 you have these freedoms and that you cannot take these freedoms away
263 from anyone else.
264
265 @unnumberedsec Free Software Needs Free Documentation
266
267 The biggest deficiency in the free software community today is not in
268 the software---it is the lack of good free documentation that we can
269 include with the free software. Many of our most important
270 programs do not come with free reference manuals and free introductory
271 texts. Documentation is an essential part of any software package;
272 when an important free software package does not come with a free
273 manual and a free tutorial, that is a major gap. We have many such
274 gaps today.
275
276 Consider Perl, for instance. The tutorial manuals that people
277 normally use are non-free. How did this come about? Because the
278 authors of those manuals published them with restrictive terms---no
279 copying, no modification, source files not available---which exclude
280 them from the free software world.
281
282 That wasn't the first time this sort of thing happened, and it was far
283 from the last. Many times we have heard a GNU user eagerly describe a
284 manual that he is writing, his intended contribution to the community,
285 only to learn that he had ruined everything by signing a publication
286 contract to make it non-free.
287
288 Free documentation, like free software, is a matter of freedom, not
289 price. The problem with the non-free manual is not that publishers
290 charge a price for printed copies---that in itself is fine. (The Free
291 Software Foundation sells printed copies of manuals, too.) The
292 problem is the restrictions on the use of the manual. Free manuals
293 are available in source code form, and give you permission to copy and
294 modify. Non-free manuals do not allow this.
295
296 The criteria of freedom for a free manual are roughly the same as for
297 free software. Redistribution (including the normal kinds of
298 commercial redistribution) must be permitted, so that the manual can
299 accompany every copy of the program, both on-line and on paper.
300
301 Permission for modification of the technical content is crucial too.
302 When people modify the software, adding or changing features, if they
303 are conscientious they will change the manual too---so they can
304 provide accurate and clear documentation for the modified program. A
305 manual that leaves you no choice but to write a new manual to document
306 a changed version of the program is not really available to our
307 community.
308
309 Some kinds of limits on the way modification is handled are
310 acceptable. For example, requirements to preserve the original
311 author's copyright notice, the distribution terms, or the list of
312 authors, are ok. It is also no problem to require modified versions
313 to include notice that they were modified. Even entire sections that
314 may not be deleted or changed are acceptable, as long as they deal
315 with nontechnical topics (like this one). These kinds of restrictions
316 are acceptable because they don't obstruct the community's normal use
317 of the manual.
318
319 However, it must be possible to modify all the @emph{technical}
320 content of the manual, and then distribute the result in all the usual
321 media, through all the usual channels. Otherwise, the restrictions
322 obstruct the use of the manual, it is not free, and we need another
323 manual to replace it.
324
325 Please spread the word about this issue. Our community continues to
326 lose manuals to proprietary publishing. If we spread the word that
327 free software needs free reference manuals and free tutorials, perhaps
328 the next person who wants to contribute by writing documentation will
329 realize, before it is too late, that only free manuals contribute to
330 the free software community.
331
332 If you are writing documentation, please insist on publishing it under
333 the GNU Free Documentation License or another free documentation
334 license. Remember that this decision requires your approval---you
335 don't have to let the publisher decide. Some commercial publishers
336 will use a free license if you insist, but they will not propose the
337 option; it is up to you to raise the issue and say firmly that this is
338 what you want. If the publisher you are dealing with refuses, please
339 try other publishers. If you're not sure whether a proposed license
340 is free, write to @email{licensing@@gnu.org}.
341
342 You can encourage commercial publishers to sell more free, copylefted
343 manuals and tutorials by buying them, and particularly by buying
344 copies from the publishers that paid for their writing or for major
345 improvements. Meanwhile, try to avoid buying non-free documentation
346 at all. Check the distribution terms of a manual before you buy it,
347 and insist that whoever seeks your business must respect your freedom.
348 Check the history of the book, and try to reward the publishers that
349 have paid or pay the authors to work on it.
350
351 The Free Software Foundation maintains a list of free documentation
352 published by other publishers, at
353 @url{http://www.fsf.org/doc/other-free-books.html}.
354
355 @node Contributors
356 @unnumberedsec Contributors to @value{GDBN}
357
358 Richard Stallman was the original author of @value{GDBN}, and of many
359 other @sc{gnu} programs. Many others have contributed to its
360 development. This section attempts to credit major contributors. One
361 of the virtues of free software is that everyone is free to contribute
362 to it; with regret, we cannot actually acknowledge everyone here. The
363 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
364 blow-by-blow account.
365
366 Changes much prior to version 2.0 are lost in the mists of time.
367
368 @quotation
369 @emph{Plea:} Additions to this section are particularly welcome. If you
370 or your friends (or enemies, to be evenhanded) have been unfairly
371 omitted from this list, we would like to add your names!
372 @end quotation
373
374 So that they may not regard their many labors as thankless, we
375 particularly thank those who shepherded @value{GDBN} through major
376 releases:
377 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
378 Jim Blandy (release 4.18);
379 Jason Molenda (release 4.17);
380 Stan Shebs (release 4.14);
381 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
382 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
383 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
384 Jim Kingdon (releases 3.5, 3.4, and 3.3);
385 and Randy Smith (releases 3.2, 3.1, and 3.0).
386
387 Richard Stallman, assisted at various times by Peter TerMaat, Chris
388 Hanson, and Richard Mlynarik, handled releases through 2.8.
389
390 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
391 in @value{GDBN}, with significant additional contributions from Per
392 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
393 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
394 much general update work leading to release 3.0).
395
396 @value{GDBN} uses the BFD subroutine library to examine multiple
397 object-file formats; BFD was a joint project of David V.
398 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
399
400 David Johnson wrote the original COFF support; Pace Willison did
401 the original support for encapsulated COFF.
402
403 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
404
405 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
406 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
407 support.
408 Jean-Daniel Fekete contributed Sun 386i support.
409 Chris Hanson improved the HP9000 support.
410 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
411 David Johnson contributed Encore Umax support.
412 Jyrki Kuoppala contributed Altos 3068 support.
413 Jeff Law contributed HP PA and SOM support.
414 Keith Packard contributed NS32K support.
415 Doug Rabson contributed Acorn Risc Machine support.
416 Bob Rusk contributed Harris Nighthawk CX-UX support.
417 Chris Smith contributed Convex support (and Fortran debugging).
418 Jonathan Stone contributed Pyramid support.
419 Michael Tiemann contributed SPARC support.
420 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
421 Pace Willison contributed Intel 386 support.
422 Jay Vosburgh contributed Symmetry support.
423 Marko Mlinar contributed OpenRISC 1000 support.
424
425 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
426
427 Rich Schaefer and Peter Schauer helped with support of SunOS shared
428 libraries.
429
430 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
431 about several machine instruction sets.
432
433 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
434 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
435 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
436 and RDI targets, respectively.
437
438 Brian Fox is the author of the readline libraries providing
439 command-line editing and command history.
440
441 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
442 Modula-2 support, and contributed the Languages chapter of this manual.
443
444 Fred Fish wrote most of the support for Unix System Vr4.
445 He also enhanced the command-completion support to cover C@t{++} overloaded
446 symbols.
447
448 Hitachi America (now Renesas America), Ltd. sponsored the support for
449 H8/300, H8/500, and Super-H processors.
450
451 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
452
453 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
454 processors.
455
456 Toshiba sponsored the support for the TX39 Mips processor.
457
458 Matsushita sponsored the support for the MN10200 and MN10300 processors.
459
460 Fujitsu sponsored the support for SPARClite and FR30 processors.
461
462 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
463 watchpoints.
464
465 Michael Snyder added support for tracepoints.
466
467 Stu Grossman wrote gdbserver.
468
469 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
470 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
471
472 The following people at the Hewlett-Packard Company contributed
473 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
474 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
475 compiler, and the Text User Interface (nee Terminal User Interface):
476 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
477 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
478 provided HP-specific information in this manual.
479
480 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
481 Robert Hoehne made significant contributions to the DJGPP port.
482
483 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
484 development since 1991. Cygnus engineers who have worked on @value{GDBN}
485 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
486 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
487 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
488 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
489 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
490 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
491 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
492 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
493 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
494 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
495 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
496 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
497 Zuhn have made contributions both large and small.
498
499 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
500 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
501
502 Jim Blandy added support for preprocessor macros, while working for Red
503 Hat.
504
505 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
506 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
507 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
508 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
509 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
510 with the migration of old architectures to this new framework.
511
512 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
513 unwinder framework, this consisting of a fresh new design featuring
514 frame IDs, independent frame sniffers, and the sentinel frame. Mark
515 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
516 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
517 trad unwinders. The architecture-specific changes, each involving a
518 complete rewrite of the architecture's frame code, were carried out by
519 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
520 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
521 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
522 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
523 Weigand.
524
525 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
526 Tensilica, Inc.@: contributed support for Xtensa processors. Others
527 who have worked on the Xtensa port of @value{GDBN} in the past include
528 Steve Tjiang, John Newlin, and Scott Foehner.
529
530 Michael Eager and staff of Xilinx, Inc., contributed support for the
531 Xilinx MicroBlaze architecture.
532
533 @node Sample Session
534 @chapter A Sample @value{GDBN} Session
535
536 You can use this manual at your leisure to read all about @value{GDBN}.
537 However, a handful of commands are enough to get started using the
538 debugger. This chapter illustrates those commands.
539
540 @iftex
541 In this sample session, we emphasize user input like this: @b{input},
542 to make it easier to pick out from the surrounding output.
543 @end iftex
544
545 @c FIXME: this example may not be appropriate for some configs, where
546 @c FIXME...primary interest is in remote use.
547
548 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
549 processor) exhibits the following bug: sometimes, when we change its
550 quote strings from the default, the commands used to capture one macro
551 definition within another stop working. In the following short @code{m4}
552 session, we define a macro @code{foo} which expands to @code{0000}; we
553 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
554 same thing. However, when we change the open quote string to
555 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
556 procedure fails to define a new synonym @code{baz}:
557
558 @smallexample
559 $ @b{cd gnu/m4}
560 $ @b{./m4}
561 @b{define(foo,0000)}
562
563 @b{foo}
564 0000
565 @b{define(bar,defn(`foo'))}
566
567 @b{bar}
568 0000
569 @b{changequote(<QUOTE>,<UNQUOTE>)}
570
571 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
572 @b{baz}
573 @b{Ctrl-d}
574 m4: End of input: 0: fatal error: EOF in string
575 @end smallexample
576
577 @noindent
578 Let us use @value{GDBN} to try to see what is going on.
579
580 @smallexample
581 $ @b{@value{GDBP} m4}
582 @c FIXME: this falsifies the exact text played out, to permit smallbook
583 @c FIXME... format to come out better.
584 @value{GDBN} is free software and you are welcome to distribute copies
585 of it under certain conditions; type "show copying" to see
586 the conditions.
587 There is absolutely no warranty for @value{GDBN}; type "show warranty"
588 for details.
589
590 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
591 (@value{GDBP})
592 @end smallexample
593
594 @noindent
595 @value{GDBN} reads only enough symbol data to know where to find the
596 rest when needed; as a result, the first prompt comes up very quickly.
597 We now tell @value{GDBN} to use a narrower display width than usual, so
598 that examples fit in this manual.
599
600 @smallexample
601 (@value{GDBP}) @b{set width 70}
602 @end smallexample
603
604 @noindent
605 We need to see how the @code{m4} built-in @code{changequote} works.
606 Having looked at the source, we know the relevant subroutine is
607 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
608 @code{break} command.
609
610 @smallexample
611 (@value{GDBP}) @b{break m4_changequote}
612 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
613 @end smallexample
614
615 @noindent
616 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
617 control; as long as control does not reach the @code{m4_changequote}
618 subroutine, the program runs as usual:
619
620 @smallexample
621 (@value{GDBP}) @b{run}
622 Starting program: /work/Editorial/gdb/gnu/m4/m4
623 @b{define(foo,0000)}
624
625 @b{foo}
626 0000
627 @end smallexample
628
629 @noindent
630 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
631 suspends execution of @code{m4}, displaying information about the
632 context where it stops.
633
634 @smallexample
635 @b{changequote(<QUOTE>,<UNQUOTE>)}
636
637 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
638 at builtin.c:879
639 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
640 @end smallexample
641
642 @noindent
643 Now we use the command @code{n} (@code{next}) to advance execution to
644 the next line of the current function.
645
646 @smallexample
647 (@value{GDBP}) @b{n}
648 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
649 : nil,
650 @end smallexample
651
652 @noindent
653 @code{set_quotes} looks like a promising subroutine. We can go into it
654 by using the command @code{s} (@code{step}) instead of @code{next}.
655 @code{step} goes to the next line to be executed in @emph{any}
656 subroutine, so it steps into @code{set_quotes}.
657
658 @smallexample
659 (@value{GDBP}) @b{s}
660 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
661 at input.c:530
662 530 if (lquote != def_lquote)
663 @end smallexample
664
665 @noindent
666 The display that shows the subroutine where @code{m4} is now
667 suspended (and its arguments) is called a stack frame display. It
668 shows a summary of the stack. We can use the @code{backtrace}
669 command (which can also be spelled @code{bt}), to see where we are
670 in the stack as a whole: the @code{backtrace} command displays a
671 stack frame for each active subroutine.
672
673 @smallexample
674 (@value{GDBP}) @b{bt}
675 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
676 at input.c:530
677 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
678 at builtin.c:882
679 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
680 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
681 at macro.c:71
682 #4 0x79dc in expand_input () at macro.c:40
683 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
684 @end smallexample
685
686 @noindent
687 We step through a few more lines to see what happens. The first two
688 times, we can use @samp{s}; the next two times we use @code{n} to avoid
689 falling into the @code{xstrdup} subroutine.
690
691 @smallexample
692 (@value{GDBP}) @b{s}
693 0x3b5c 532 if (rquote != def_rquote)
694 (@value{GDBP}) @b{s}
695 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
696 def_lquote : xstrdup(lq);
697 (@value{GDBP}) @b{n}
698 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
699 : xstrdup(rq);
700 (@value{GDBP}) @b{n}
701 538 len_lquote = strlen(rquote);
702 @end smallexample
703
704 @noindent
705 The last line displayed looks a little odd; we can examine the variables
706 @code{lquote} and @code{rquote} to see if they are in fact the new left
707 and right quotes we specified. We use the command @code{p}
708 (@code{print}) to see their values.
709
710 @smallexample
711 (@value{GDBP}) @b{p lquote}
712 $1 = 0x35d40 "<QUOTE>"
713 (@value{GDBP}) @b{p rquote}
714 $2 = 0x35d50 "<UNQUOTE>"
715 @end smallexample
716
717 @noindent
718 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
719 To look at some context, we can display ten lines of source
720 surrounding the current line with the @code{l} (@code{list}) command.
721
722 @smallexample
723 (@value{GDBP}) @b{l}
724 533 xfree(rquote);
725 534
726 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
727 : xstrdup (lq);
728 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
729 : xstrdup (rq);
730 537
731 538 len_lquote = strlen(rquote);
732 539 len_rquote = strlen(lquote);
733 540 @}
734 541
735 542 void
736 @end smallexample
737
738 @noindent
739 Let us step past the two lines that set @code{len_lquote} and
740 @code{len_rquote}, and then examine the values of those variables.
741
742 @smallexample
743 (@value{GDBP}) @b{n}
744 539 len_rquote = strlen(lquote);
745 (@value{GDBP}) @b{n}
746 540 @}
747 (@value{GDBP}) @b{p len_lquote}
748 $3 = 9
749 (@value{GDBP}) @b{p len_rquote}
750 $4 = 7
751 @end smallexample
752
753 @noindent
754 That certainly looks wrong, assuming @code{len_lquote} and
755 @code{len_rquote} are meant to be the lengths of @code{lquote} and
756 @code{rquote} respectively. We can set them to better values using
757 the @code{p} command, since it can print the value of
758 any expression---and that expression can include subroutine calls and
759 assignments.
760
761 @smallexample
762 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
763 $5 = 7
764 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
765 $6 = 9
766 @end smallexample
767
768 @noindent
769 Is that enough to fix the problem of using the new quotes with the
770 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
771 executing with the @code{c} (@code{continue}) command, and then try the
772 example that caused trouble initially:
773
774 @smallexample
775 (@value{GDBP}) @b{c}
776 Continuing.
777
778 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
779
780 baz
781 0000
782 @end smallexample
783
784 @noindent
785 Success! The new quotes now work just as well as the default ones. The
786 problem seems to have been just the two typos defining the wrong
787 lengths. We allow @code{m4} exit by giving it an EOF as input:
788
789 @smallexample
790 @b{Ctrl-d}
791 Program exited normally.
792 @end smallexample
793
794 @noindent
795 The message @samp{Program exited normally.} is from @value{GDBN}; it
796 indicates @code{m4} has finished executing. We can end our @value{GDBN}
797 session with the @value{GDBN} @code{quit} command.
798
799 @smallexample
800 (@value{GDBP}) @b{quit}
801 @end smallexample
802
803 @node Invocation
804 @chapter Getting In and Out of @value{GDBN}
805
806 This chapter discusses how to start @value{GDBN}, and how to get out of it.
807 The essentials are:
808 @itemize @bullet
809 @item
810 type @samp{@value{GDBP}} to start @value{GDBN}.
811 @item
812 type @kbd{quit} or @kbd{Ctrl-d} to exit.
813 @end itemize
814
815 @menu
816 * Invoking GDB:: How to start @value{GDBN}
817 * Quitting GDB:: How to quit @value{GDBN}
818 * Shell Commands:: How to use shell commands inside @value{GDBN}
819 * Logging Output:: How to log @value{GDBN}'s output to a file
820 @end menu
821
822 @node Invoking GDB
823 @section Invoking @value{GDBN}
824
825 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
826 @value{GDBN} reads commands from the terminal until you tell it to exit.
827
828 You can also run @code{@value{GDBP}} with a variety of arguments and options,
829 to specify more of your debugging environment at the outset.
830
831 The command-line options described here are designed
832 to cover a variety of situations; in some environments, some of these
833 options may effectively be unavailable.
834
835 The most usual way to start @value{GDBN} is with one argument,
836 specifying an executable program:
837
838 @smallexample
839 @value{GDBP} @var{program}
840 @end smallexample
841
842 @noindent
843 You can also start with both an executable program and a core file
844 specified:
845
846 @smallexample
847 @value{GDBP} @var{program} @var{core}
848 @end smallexample
849
850 You can, instead, specify a process ID as a second argument, if you want
851 to debug a running process:
852
853 @smallexample
854 @value{GDBP} @var{program} 1234
855 @end smallexample
856
857 @noindent
858 would attach @value{GDBN} to process @code{1234} (unless you also have a file
859 named @file{1234}; @value{GDBN} does check for a core file first).
860
861 Taking advantage of the second command-line argument requires a fairly
862 complete operating system; when you use @value{GDBN} as a remote
863 debugger attached to a bare board, there may not be any notion of
864 ``process'', and there is often no way to get a core dump. @value{GDBN}
865 will warn you if it is unable to attach or to read core dumps.
866
867 You can optionally have @code{@value{GDBP}} pass any arguments after the
868 executable file to the inferior using @code{--args}. This option stops
869 option processing.
870 @smallexample
871 @value{GDBP} --args gcc -O2 -c foo.c
872 @end smallexample
873 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
874 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
875
876 You can run @code{@value{GDBP}} without printing the front material, which describes
877 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
878
879 @smallexample
880 @value{GDBP} -silent
881 @end smallexample
882
883 @noindent
884 You can further control how @value{GDBN} starts up by using command-line
885 options. @value{GDBN} itself can remind you of the options available.
886
887 @noindent
888 Type
889
890 @smallexample
891 @value{GDBP} -help
892 @end smallexample
893
894 @noindent
895 to display all available options and briefly describe their use
896 (@samp{@value{GDBP} -h} is a shorter equivalent).
897
898 All options and command line arguments you give are processed
899 in sequential order. The order makes a difference when the
900 @samp{-x} option is used.
901
902
903 @menu
904 * File Options:: Choosing files
905 * Mode Options:: Choosing modes
906 * Startup:: What @value{GDBN} does during startup
907 @end menu
908
909 @node File Options
910 @subsection Choosing Files
911
912 When @value{GDBN} starts, it reads any arguments other than options as
913 specifying an executable file and core file (or process ID). This is
914 the same as if the arguments were specified by the @samp{-se} and
915 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
916 first argument that does not have an associated option flag as
917 equivalent to the @samp{-se} option followed by that argument; and the
918 second argument that does not have an associated option flag, if any, as
919 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
920 If the second argument begins with a decimal digit, @value{GDBN} will
921 first attempt to attach to it as a process, and if that fails, attempt
922 to open it as a corefile. If you have a corefile whose name begins with
923 a digit, you can prevent @value{GDBN} from treating it as a pid by
924 prefixing it with @file{./}, e.g.@: @file{./12345}.
925
926 If @value{GDBN} has not been configured to included core file support,
927 such as for most embedded targets, then it will complain about a second
928 argument and ignore it.
929
930 Many options have both long and short forms; both are shown in the
931 following list. @value{GDBN} also recognizes the long forms if you truncate
932 them, so long as enough of the option is present to be unambiguous.
933 (If you prefer, you can flag option arguments with @samp{--} rather
934 than @samp{-}, though we illustrate the more usual convention.)
935
936 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
937 @c way, both those who look for -foo and --foo in the index, will find
938 @c it.
939
940 @table @code
941 @item -symbols @var{file}
942 @itemx -s @var{file}
943 @cindex @code{--symbols}
944 @cindex @code{-s}
945 Read symbol table from file @var{file}.
946
947 @item -exec @var{file}
948 @itemx -e @var{file}
949 @cindex @code{--exec}
950 @cindex @code{-e}
951 Use file @var{file} as the executable file to execute when appropriate,
952 and for examining pure data in conjunction with a core dump.
953
954 @item -se @var{file}
955 @cindex @code{--se}
956 Read symbol table from file @var{file} and use it as the executable
957 file.
958
959 @item -core @var{file}
960 @itemx -c @var{file}
961 @cindex @code{--core}
962 @cindex @code{-c}
963 Use file @var{file} as a core dump to examine.
964
965 @item -pid @var{number}
966 @itemx -p @var{number}
967 @cindex @code{--pid}
968 @cindex @code{-p}
969 Connect to process ID @var{number}, as with the @code{attach} command.
970
971 @item -command @var{file}
972 @itemx -x @var{file}
973 @cindex @code{--command}
974 @cindex @code{-x}
975 Execute commands from file @var{file}. The contents of this file is
976 evaluated exactly as the @code{source} command would.
977 @xref{Command Files,, Command files}.
978
979 @item -eval-command @var{command}
980 @itemx -ex @var{command}
981 @cindex @code{--eval-command}
982 @cindex @code{-ex}
983 Execute a single @value{GDBN} command.
984
985 This option may be used multiple times to call multiple commands. It may
986 also be interleaved with @samp{-command} as required.
987
988 @smallexample
989 @value{GDBP} -ex 'target sim' -ex 'load' \
990 -x setbreakpoints -ex 'run' a.out
991 @end smallexample
992
993 @item -directory @var{directory}
994 @itemx -d @var{directory}
995 @cindex @code{--directory}
996 @cindex @code{-d}
997 Add @var{directory} to the path to search for source and script files.
998
999 @item -r
1000 @itemx -readnow
1001 @cindex @code{--readnow}
1002 @cindex @code{-r}
1003 Read each symbol file's entire symbol table immediately, rather than
1004 the default, which is to read it incrementally as it is needed.
1005 This makes startup slower, but makes future operations faster.
1006
1007 @end table
1008
1009 @node Mode Options
1010 @subsection Choosing Modes
1011
1012 You can run @value{GDBN} in various alternative modes---for example, in
1013 batch mode or quiet mode.
1014
1015 @table @code
1016 @item -nx
1017 @itemx -n
1018 @cindex @code{--nx}
1019 @cindex @code{-n}
1020 Do not execute commands found in any initialization files. Normally,
1021 @value{GDBN} executes the commands in these files after all the command
1022 options and arguments have been processed. @xref{Command Files,,Command
1023 Files}.
1024
1025 @item -quiet
1026 @itemx -silent
1027 @itemx -q
1028 @cindex @code{--quiet}
1029 @cindex @code{--silent}
1030 @cindex @code{-q}
1031 ``Quiet''. Do not print the introductory and copyright messages. These
1032 messages are also suppressed in batch mode.
1033
1034 @item -batch
1035 @cindex @code{--batch}
1036 Run in batch mode. Exit with status @code{0} after processing all the
1037 command files specified with @samp{-x} (and all commands from
1038 initialization files, if not inhibited with @samp{-n}). Exit with
1039 nonzero status if an error occurs in executing the @value{GDBN} commands
1040 in the command files. Batch mode also disables pagination, sets unlimited
1041 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1042 off} were in effect (@pxref{Messages/Warnings}).
1043
1044 Batch mode may be useful for running @value{GDBN} as a filter, for
1045 example to download and run a program on another computer; in order to
1046 make this more useful, the message
1047
1048 @smallexample
1049 Program exited normally.
1050 @end smallexample
1051
1052 @noindent
1053 (which is ordinarily issued whenever a program running under
1054 @value{GDBN} control terminates) is not issued when running in batch
1055 mode.
1056
1057 @item -batch-silent
1058 @cindex @code{--batch-silent}
1059 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1060 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1061 unaffected). This is much quieter than @samp{-silent} and would be useless
1062 for an interactive session.
1063
1064 This is particularly useful when using targets that give @samp{Loading section}
1065 messages, for example.
1066
1067 Note that targets that give their output via @value{GDBN}, as opposed to
1068 writing directly to @code{stdout}, will also be made silent.
1069
1070 @item -return-child-result
1071 @cindex @code{--return-child-result}
1072 The return code from @value{GDBN} will be the return code from the child
1073 process (the process being debugged), with the following exceptions:
1074
1075 @itemize @bullet
1076 @item
1077 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1078 internal error. In this case the exit code is the same as it would have been
1079 without @samp{-return-child-result}.
1080 @item
1081 The user quits with an explicit value. E.g., @samp{quit 1}.
1082 @item
1083 The child process never runs, or is not allowed to terminate, in which case
1084 the exit code will be -1.
1085 @end itemize
1086
1087 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1088 when @value{GDBN} is being used as a remote program loader or simulator
1089 interface.
1090
1091 @item -nowindows
1092 @itemx -nw
1093 @cindex @code{--nowindows}
1094 @cindex @code{-nw}
1095 ``No windows''. If @value{GDBN} comes with a graphical user interface
1096 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1097 interface. If no GUI is available, this option has no effect.
1098
1099 @item -windows
1100 @itemx -w
1101 @cindex @code{--windows}
1102 @cindex @code{-w}
1103 If @value{GDBN} includes a GUI, then this option requires it to be
1104 used if possible.
1105
1106 @item -cd @var{directory}
1107 @cindex @code{--cd}
1108 Run @value{GDBN} using @var{directory} as its working directory,
1109 instead of the current directory.
1110
1111 @item -data-directory @var{directory}
1112 @cindex @code{--data-directory}
1113 Run @value{GDBN} using @var{directory} as its data directory.
1114 The data directory is where @value{GDBN} searches for its
1115 auxiliary files. @xref{Data Files}.
1116
1117 @item -fullname
1118 @itemx -f
1119 @cindex @code{--fullname}
1120 @cindex @code{-f}
1121 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1122 subprocess. It tells @value{GDBN} to output the full file name and line
1123 number in a standard, recognizable fashion each time a stack frame is
1124 displayed (which includes each time your program stops). This
1125 recognizable format looks like two @samp{\032} characters, followed by
1126 the file name, line number and character position separated by colons,
1127 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1128 @samp{\032} characters as a signal to display the source code for the
1129 frame.
1130
1131 @item -epoch
1132 @cindex @code{--epoch}
1133 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1134 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1135 routines so as to allow Epoch to display values of expressions in a
1136 separate window.
1137
1138 @item -annotate @var{level}
1139 @cindex @code{--annotate}
1140 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1141 effect is identical to using @samp{set annotate @var{level}}
1142 (@pxref{Annotations}). The annotation @var{level} controls how much
1143 information @value{GDBN} prints together with its prompt, values of
1144 expressions, source lines, and other types of output. Level 0 is the
1145 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1146 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1147 that control @value{GDBN}, and level 2 has been deprecated.
1148
1149 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1150 (@pxref{GDB/MI}).
1151
1152 @item --args
1153 @cindex @code{--args}
1154 Change interpretation of command line so that arguments following the
1155 executable file are passed as command line arguments to the inferior.
1156 This option stops option processing.
1157
1158 @item -baud @var{bps}
1159 @itemx -b @var{bps}
1160 @cindex @code{--baud}
1161 @cindex @code{-b}
1162 Set the line speed (baud rate or bits per second) of any serial
1163 interface used by @value{GDBN} for remote debugging.
1164
1165 @item -l @var{timeout}
1166 @cindex @code{-l}
1167 Set the timeout (in seconds) of any communication used by @value{GDBN}
1168 for remote debugging.
1169
1170 @item -tty @var{device}
1171 @itemx -t @var{device}
1172 @cindex @code{--tty}
1173 @cindex @code{-t}
1174 Run using @var{device} for your program's standard input and output.
1175 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1176
1177 @c resolve the situation of these eventually
1178 @item -tui
1179 @cindex @code{--tui}
1180 Activate the @dfn{Text User Interface} when starting. The Text User
1181 Interface manages several text windows on the terminal, showing
1182 source, assembly, registers and @value{GDBN} command outputs
1183 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1184 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1185 Using @value{GDBN} under @sc{gnu} Emacs}).
1186
1187 @c @item -xdb
1188 @c @cindex @code{--xdb}
1189 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1190 @c For information, see the file @file{xdb_trans.html}, which is usually
1191 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1192 @c systems.
1193
1194 @item -interpreter @var{interp}
1195 @cindex @code{--interpreter}
1196 Use the interpreter @var{interp} for interface with the controlling
1197 program or device. This option is meant to be set by programs which
1198 communicate with @value{GDBN} using it as a back end.
1199 @xref{Interpreters, , Command Interpreters}.
1200
1201 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1202 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1203 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
1204 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1205 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1206 @sc{gdb/mi} interfaces are no longer supported.
1207
1208 @item -write
1209 @cindex @code{--write}
1210 Open the executable and core files for both reading and writing. This
1211 is equivalent to the @samp{set write on} command inside @value{GDBN}
1212 (@pxref{Patching}).
1213
1214 @item -statistics
1215 @cindex @code{--statistics}
1216 This option causes @value{GDBN} to print statistics about time and
1217 memory usage after it completes each command and returns to the prompt.
1218
1219 @item -version
1220 @cindex @code{--version}
1221 This option causes @value{GDBN} to print its version number and
1222 no-warranty blurb, and exit.
1223
1224 @item -use-deprecated-index-sections
1225 @cindex @code{--use-deprecated-index-sections}
1226 This option causes @value{GDBN} to read and use deprecated
1227 @samp{.gdb_index} sections from symbol files. This can speed up
1228 startup, but may result in some functionality being lost.
1229 @xref{Index Section Format}.
1230
1231 @end table
1232
1233 @node Startup
1234 @subsection What @value{GDBN} Does During Startup
1235 @cindex @value{GDBN} startup
1236
1237 Here's the description of what @value{GDBN} does during session startup:
1238
1239 @enumerate
1240 @item
1241 Sets up the command interpreter as specified by the command line
1242 (@pxref{Mode Options, interpreter}).
1243
1244 @item
1245 @cindex init file
1246 Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1247 used when building @value{GDBN}; @pxref{System-wide configuration,
1248 ,System-wide configuration and settings}) and executes all the commands in
1249 that file.
1250
1251 @item
1252 Reads the init file (if any) in your home directory@footnote{On
1253 DOS/Windows systems, the home directory is the one pointed to by the
1254 @code{HOME} environment variable.} and executes all the commands in
1255 that file.
1256
1257 @item
1258 Processes command line options and operands.
1259
1260 @item
1261 Reads and executes the commands from init file (if any) in the current
1262 working directory. This is only done if the current directory is
1263 different from your home directory. Thus, you can have more than one
1264 init file, one generic in your home directory, and another, specific
1265 to the program you are debugging, in the directory where you invoke
1266 @value{GDBN}.
1267
1268 @item
1269 If the command line specified a program to debug, or a process to
1270 attach to, or a core file, @value{GDBN} loads any auto-loaded
1271 scripts provided for the program or for its loaded shared libraries.
1272 @xref{Auto-loading}.
1273
1274 If you wish to disable the auto-loading during startup,
1275 you must do something like the following:
1276
1277 @smallexample
1278 $ gdb -ex "set auto-load-scripts off" -ex "file myprogram"
1279 @end smallexample
1280
1281 The following does not work because the auto-loading is turned off too late:
1282
1283 @smallexample
1284 $ gdb -ex "set auto-load-scripts off" myprogram
1285 @end smallexample
1286
1287 @item
1288 Executes commands and command files specified by the @samp{-ex} and
1289 @samp{-x} options in their specified order. @xref{Command Files}, for
1290 more details about @value{GDBN} command files.
1291
1292 @item
1293 Reads the command history recorded in the @dfn{history file}.
1294 @xref{Command History}, for more details about the command history and the
1295 files where @value{GDBN} records it.
1296 @end enumerate
1297
1298 Init files use the same syntax as @dfn{command files} (@pxref{Command
1299 Files}) and are processed by @value{GDBN} in the same way. The init
1300 file in your home directory can set options (such as @samp{set
1301 complaints}) that affect subsequent processing of command line options
1302 and operands. Init files are not executed if you use the @samp{-nx}
1303 option (@pxref{Mode Options, ,Choosing Modes}).
1304
1305 To display the list of init files loaded by gdb at startup, you
1306 can use @kbd{gdb --help}.
1307
1308 @cindex init file name
1309 @cindex @file{.gdbinit}
1310 @cindex @file{gdb.ini}
1311 The @value{GDBN} init files are normally called @file{.gdbinit}.
1312 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1313 the limitations of file names imposed by DOS filesystems. The Windows
1314 ports of @value{GDBN} use the standard name, but if they find a
1315 @file{gdb.ini} file, they warn you about that and suggest to rename
1316 the file to the standard name.
1317
1318
1319 @node Quitting GDB
1320 @section Quitting @value{GDBN}
1321 @cindex exiting @value{GDBN}
1322 @cindex leaving @value{GDBN}
1323
1324 @table @code
1325 @kindex quit @r{[}@var{expression}@r{]}
1326 @kindex q @r{(@code{quit})}
1327 @item quit @r{[}@var{expression}@r{]}
1328 @itemx q
1329 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1330 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1331 do not supply @var{expression}, @value{GDBN} will terminate normally;
1332 otherwise it will terminate using the result of @var{expression} as the
1333 error code.
1334 @end table
1335
1336 @cindex interrupt
1337 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1338 terminates the action of any @value{GDBN} command that is in progress and
1339 returns to @value{GDBN} command level. It is safe to type the interrupt
1340 character at any time because @value{GDBN} does not allow it to take effect
1341 until a time when it is safe.
1342
1343 If you have been using @value{GDBN} to control an attached process or
1344 device, you can release it with the @code{detach} command
1345 (@pxref{Attach, ,Debugging an Already-running Process}).
1346
1347 @node Shell Commands
1348 @section Shell Commands
1349
1350 If you need to execute occasional shell commands during your
1351 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1352 just use the @code{shell} command.
1353
1354 @table @code
1355 @kindex shell
1356 @kindex !
1357 @cindex shell escape
1358 @item shell @var{command-string}
1359 @itemx !@var{command-string}
1360 Invoke a standard shell to execute @var{command-string}.
1361 Note that no space is needed between @code{!} and @var{command-string}.
1362 If it exists, the environment variable @code{SHELL} determines which
1363 shell to run. Otherwise @value{GDBN} uses the default shell
1364 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1365 @end table
1366
1367 The utility @code{make} is often needed in development environments.
1368 You do not have to use the @code{shell} command for this purpose in
1369 @value{GDBN}:
1370
1371 @table @code
1372 @kindex make
1373 @cindex calling make
1374 @item make @var{make-args}
1375 Execute the @code{make} program with the specified
1376 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1377 @end table
1378
1379 @node Logging Output
1380 @section Logging Output
1381 @cindex logging @value{GDBN} output
1382 @cindex save @value{GDBN} output to a file
1383
1384 You may want to save the output of @value{GDBN} commands to a file.
1385 There are several commands to control @value{GDBN}'s logging.
1386
1387 @table @code
1388 @kindex set logging
1389 @item set logging on
1390 Enable logging.
1391 @item set logging off
1392 Disable logging.
1393 @cindex logging file name
1394 @item set logging file @var{file}
1395 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1396 @item set logging overwrite [on|off]
1397 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1398 you want @code{set logging on} to overwrite the logfile instead.
1399 @item set logging redirect [on|off]
1400 By default, @value{GDBN} output will go to both the terminal and the logfile.
1401 Set @code{redirect} if you want output to go only to the log file.
1402 @kindex show logging
1403 @item show logging
1404 Show the current values of the logging settings.
1405 @end table
1406
1407 @node Commands
1408 @chapter @value{GDBN} Commands
1409
1410 You can abbreviate a @value{GDBN} command to the first few letters of the command
1411 name, if that abbreviation is unambiguous; and you can repeat certain
1412 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1413 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1414 show you the alternatives available, if there is more than one possibility).
1415
1416 @menu
1417 * Command Syntax:: How to give commands to @value{GDBN}
1418 * Completion:: Command completion
1419 * Help:: How to ask @value{GDBN} for help
1420 @end menu
1421
1422 @node Command Syntax
1423 @section Command Syntax
1424
1425 A @value{GDBN} command is a single line of input. There is no limit on
1426 how long it can be. It starts with a command name, which is followed by
1427 arguments whose meaning depends on the command name. For example, the
1428 command @code{step} accepts an argument which is the number of times to
1429 step, as in @samp{step 5}. You can also use the @code{step} command
1430 with no arguments. Some commands do not allow any arguments.
1431
1432 @cindex abbreviation
1433 @value{GDBN} command names may always be truncated if that abbreviation is
1434 unambiguous. Other possible command abbreviations are listed in the
1435 documentation for individual commands. In some cases, even ambiguous
1436 abbreviations are allowed; for example, @code{s} is specially defined as
1437 equivalent to @code{step} even though there are other commands whose
1438 names start with @code{s}. You can test abbreviations by using them as
1439 arguments to the @code{help} command.
1440
1441 @cindex repeating commands
1442 @kindex RET @r{(repeat last command)}
1443 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1444 repeat the previous command. Certain commands (for example, @code{run})
1445 will not repeat this way; these are commands whose unintentional
1446 repetition might cause trouble and which you are unlikely to want to
1447 repeat. User-defined commands can disable this feature; see
1448 @ref{Define, dont-repeat}.
1449
1450 The @code{list} and @code{x} commands, when you repeat them with
1451 @key{RET}, construct new arguments rather than repeating
1452 exactly as typed. This permits easy scanning of source or memory.
1453
1454 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1455 output, in a way similar to the common utility @code{more}
1456 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1457 @key{RET} too many in this situation, @value{GDBN} disables command
1458 repetition after any command that generates this sort of display.
1459
1460 @kindex # @r{(a comment)}
1461 @cindex comment
1462 Any text from a @kbd{#} to the end of the line is a comment; it does
1463 nothing. This is useful mainly in command files (@pxref{Command
1464 Files,,Command Files}).
1465
1466 @cindex repeating command sequences
1467 @kindex Ctrl-o @r{(operate-and-get-next)}
1468 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1469 commands. This command accepts the current line, like @key{RET}, and
1470 then fetches the next line relative to the current line from the history
1471 for editing.
1472
1473 @node Completion
1474 @section Command Completion
1475
1476 @cindex completion
1477 @cindex word completion
1478 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1479 only one possibility; it can also show you what the valid possibilities
1480 are for the next word in a command, at any time. This works for @value{GDBN}
1481 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1482
1483 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1484 of a word. If there is only one possibility, @value{GDBN} fills in the
1485 word, and waits for you to finish the command (or press @key{RET} to
1486 enter it). For example, if you type
1487
1488 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1489 @c complete accuracy in these examples; space introduced for clarity.
1490 @c If texinfo enhancements make it unnecessary, it would be nice to
1491 @c replace " @key" by "@key" in the following...
1492 @smallexample
1493 (@value{GDBP}) info bre @key{TAB}
1494 @end smallexample
1495
1496 @noindent
1497 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1498 the only @code{info} subcommand beginning with @samp{bre}:
1499
1500 @smallexample
1501 (@value{GDBP}) info breakpoints
1502 @end smallexample
1503
1504 @noindent
1505 You can either press @key{RET} at this point, to run the @code{info
1506 breakpoints} command, or backspace and enter something else, if
1507 @samp{breakpoints} does not look like the command you expected. (If you
1508 were sure you wanted @code{info breakpoints} in the first place, you
1509 might as well just type @key{RET} immediately after @samp{info bre},
1510 to exploit command abbreviations rather than command completion).
1511
1512 If there is more than one possibility for the next word when you press
1513 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1514 characters and try again, or just press @key{TAB} a second time;
1515 @value{GDBN} displays all the possible completions for that word. For
1516 example, you might want to set a breakpoint on a subroutine whose name
1517 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1518 just sounds the bell. Typing @key{TAB} again displays all the
1519 function names in your program that begin with those characters, for
1520 example:
1521
1522 @smallexample
1523 (@value{GDBP}) b make_ @key{TAB}
1524 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1525 make_a_section_from_file make_environ
1526 make_abs_section make_function_type
1527 make_blockvector make_pointer_type
1528 make_cleanup make_reference_type
1529 make_command make_symbol_completion_list
1530 (@value{GDBP}) b make_
1531 @end smallexample
1532
1533 @noindent
1534 After displaying the available possibilities, @value{GDBN} copies your
1535 partial input (@samp{b make_} in the example) so you can finish the
1536 command.
1537
1538 If you just want to see the list of alternatives in the first place, you
1539 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1540 means @kbd{@key{META} ?}. You can type this either by holding down a
1541 key designated as the @key{META} shift on your keyboard (if there is
1542 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1543
1544 @cindex quotes in commands
1545 @cindex completion of quoted strings
1546 Sometimes the string you need, while logically a ``word'', may contain
1547 parentheses or other characters that @value{GDBN} normally excludes from
1548 its notion of a word. To permit word completion to work in this
1549 situation, you may enclose words in @code{'} (single quote marks) in
1550 @value{GDBN} commands.
1551
1552 The most likely situation where you might need this is in typing the
1553 name of a C@t{++} function. This is because C@t{++} allows function
1554 overloading (multiple definitions of the same function, distinguished
1555 by argument type). For example, when you want to set a breakpoint you
1556 may need to distinguish whether you mean the version of @code{name}
1557 that takes an @code{int} parameter, @code{name(int)}, or the version
1558 that takes a @code{float} parameter, @code{name(float)}. To use the
1559 word-completion facilities in this situation, type a single quote
1560 @code{'} at the beginning of the function name. This alerts
1561 @value{GDBN} that it may need to consider more information than usual
1562 when you press @key{TAB} or @kbd{M-?} to request word completion:
1563
1564 @smallexample
1565 (@value{GDBP}) b 'bubble( @kbd{M-?}
1566 bubble(double,double) bubble(int,int)
1567 (@value{GDBP}) b 'bubble(
1568 @end smallexample
1569
1570 In some cases, @value{GDBN} can tell that completing a name requires using
1571 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1572 completing as much as it can) if you do not type the quote in the first
1573 place:
1574
1575 @smallexample
1576 (@value{GDBP}) b bub @key{TAB}
1577 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1578 (@value{GDBP}) b 'bubble(
1579 @end smallexample
1580
1581 @noindent
1582 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1583 you have not yet started typing the argument list when you ask for
1584 completion on an overloaded symbol.
1585
1586 For more information about overloaded functions, see @ref{C Plus Plus
1587 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1588 overload-resolution off} to disable overload resolution;
1589 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1590
1591 @cindex completion of structure field names
1592 @cindex structure field name completion
1593 @cindex completion of union field names
1594 @cindex union field name completion
1595 When completing in an expression which looks up a field in a
1596 structure, @value{GDBN} also tries@footnote{The completer can be
1597 confused by certain kinds of invalid expressions. Also, it only
1598 examines the static type of the expression, not the dynamic type.} to
1599 limit completions to the field names available in the type of the
1600 left-hand-side:
1601
1602 @smallexample
1603 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1604 magic to_fputs to_rewind
1605 to_data to_isatty to_write
1606 to_delete to_put to_write_async_safe
1607 to_flush to_read
1608 @end smallexample
1609
1610 @noindent
1611 This is because the @code{gdb_stdout} is a variable of the type
1612 @code{struct ui_file} that is defined in @value{GDBN} sources as
1613 follows:
1614
1615 @smallexample
1616 struct ui_file
1617 @{
1618 int *magic;
1619 ui_file_flush_ftype *to_flush;
1620 ui_file_write_ftype *to_write;
1621 ui_file_write_async_safe_ftype *to_write_async_safe;
1622 ui_file_fputs_ftype *to_fputs;
1623 ui_file_read_ftype *to_read;
1624 ui_file_delete_ftype *to_delete;
1625 ui_file_isatty_ftype *to_isatty;
1626 ui_file_rewind_ftype *to_rewind;
1627 ui_file_put_ftype *to_put;
1628 void *to_data;
1629 @}
1630 @end smallexample
1631
1632
1633 @node Help
1634 @section Getting Help
1635 @cindex online documentation
1636 @kindex help
1637
1638 You can always ask @value{GDBN} itself for information on its commands,
1639 using the command @code{help}.
1640
1641 @table @code
1642 @kindex h @r{(@code{help})}
1643 @item help
1644 @itemx h
1645 You can use @code{help} (abbreviated @code{h}) with no arguments to
1646 display a short list of named classes of commands:
1647
1648 @smallexample
1649 (@value{GDBP}) help
1650 List of classes of commands:
1651
1652 aliases -- Aliases of other commands
1653 breakpoints -- Making program stop at certain points
1654 data -- Examining data
1655 files -- Specifying and examining files
1656 internals -- Maintenance commands
1657 obscure -- Obscure features
1658 running -- Running the program
1659 stack -- Examining the stack
1660 status -- Status inquiries
1661 support -- Support facilities
1662 tracepoints -- Tracing of program execution without
1663 stopping the program
1664 user-defined -- User-defined commands
1665
1666 Type "help" followed by a class name for a list of
1667 commands in that class.
1668 Type "help" followed by command name for full
1669 documentation.
1670 Command name abbreviations are allowed if unambiguous.
1671 (@value{GDBP})
1672 @end smallexample
1673 @c the above line break eliminates huge line overfull...
1674
1675 @item help @var{class}
1676 Using one of the general help classes as an argument, you can get a
1677 list of the individual commands in that class. For example, here is the
1678 help display for the class @code{status}:
1679
1680 @smallexample
1681 (@value{GDBP}) help status
1682 Status inquiries.
1683
1684 List of commands:
1685
1686 @c Line break in "show" line falsifies real output, but needed
1687 @c to fit in smallbook page size.
1688 info -- Generic command for showing things
1689 about the program being debugged
1690 show -- Generic command for showing things
1691 about the debugger
1692
1693 Type "help" followed by command name for full
1694 documentation.
1695 Command name abbreviations are allowed if unambiguous.
1696 (@value{GDBP})
1697 @end smallexample
1698
1699 @item help @var{command}
1700 With a command name as @code{help} argument, @value{GDBN} displays a
1701 short paragraph on how to use that command.
1702
1703 @kindex apropos
1704 @item apropos @var{args}
1705 The @code{apropos} command searches through all of the @value{GDBN}
1706 commands, and their documentation, for the regular expression specified in
1707 @var{args}. It prints out all matches found. For example:
1708
1709 @smallexample
1710 apropos alias
1711 @end smallexample
1712
1713 @noindent
1714 results in:
1715
1716 @smallexample
1717 @c @group
1718 alias -- Define a new command that is an alias of an existing command
1719 aliases -- Aliases of other commands
1720 d -- Delete some breakpoints or auto-display expressions
1721 del -- Delete some breakpoints or auto-display expressions
1722 delete -- Delete some breakpoints or auto-display expressions
1723 @c @end group
1724 @end smallexample
1725
1726 @kindex complete
1727 @item complete @var{args}
1728 The @code{complete @var{args}} command lists all the possible completions
1729 for the beginning of a command. Use @var{args} to specify the beginning of the
1730 command you want completed. For example:
1731
1732 @smallexample
1733 complete i
1734 @end smallexample
1735
1736 @noindent results in:
1737
1738 @smallexample
1739 @group
1740 if
1741 ignore
1742 info
1743 inspect
1744 @end group
1745 @end smallexample
1746
1747 @noindent This is intended for use by @sc{gnu} Emacs.
1748 @end table
1749
1750 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1751 and @code{show} to inquire about the state of your program, or the state
1752 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1753 manual introduces each of them in the appropriate context. The listings
1754 under @code{info} and under @code{show} in the Index point to
1755 all the sub-commands. @xref{Index}.
1756
1757 @c @group
1758 @table @code
1759 @kindex info
1760 @kindex i @r{(@code{info})}
1761 @item info
1762 This command (abbreviated @code{i}) is for describing the state of your
1763 program. For example, you can show the arguments passed to a function
1764 with @code{info args}, list the registers currently in use with @code{info
1765 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1766 You can get a complete list of the @code{info} sub-commands with
1767 @w{@code{help info}}.
1768
1769 @kindex set
1770 @item set
1771 You can assign the result of an expression to an environment variable with
1772 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1773 @code{set prompt $}.
1774
1775 @kindex show
1776 @item show
1777 In contrast to @code{info}, @code{show} is for describing the state of
1778 @value{GDBN} itself.
1779 You can change most of the things you can @code{show}, by using the
1780 related command @code{set}; for example, you can control what number
1781 system is used for displays with @code{set radix}, or simply inquire
1782 which is currently in use with @code{show radix}.
1783
1784 @kindex info set
1785 To display all the settable parameters and their current
1786 values, you can use @code{show} with no arguments; you may also use
1787 @code{info set}. Both commands produce the same display.
1788 @c FIXME: "info set" violates the rule that "info" is for state of
1789 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1790 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1791 @end table
1792 @c @end group
1793
1794 Here are three miscellaneous @code{show} subcommands, all of which are
1795 exceptional in lacking corresponding @code{set} commands:
1796
1797 @table @code
1798 @kindex show version
1799 @cindex @value{GDBN} version number
1800 @item show version
1801 Show what version of @value{GDBN} is running. You should include this
1802 information in @value{GDBN} bug-reports. If multiple versions of
1803 @value{GDBN} are in use at your site, you may need to determine which
1804 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1805 commands are introduced, and old ones may wither away. Also, many
1806 system vendors ship variant versions of @value{GDBN}, and there are
1807 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1808 The version number is the same as the one announced when you start
1809 @value{GDBN}.
1810
1811 @kindex show copying
1812 @kindex info copying
1813 @cindex display @value{GDBN} copyright
1814 @item show copying
1815 @itemx info copying
1816 Display information about permission for copying @value{GDBN}.
1817
1818 @kindex show warranty
1819 @kindex info warranty
1820 @item show warranty
1821 @itemx info warranty
1822 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1823 if your version of @value{GDBN} comes with one.
1824
1825 @end table
1826
1827 @node Running
1828 @chapter Running Programs Under @value{GDBN}
1829
1830 When you run a program under @value{GDBN}, you must first generate
1831 debugging information when you compile it.
1832
1833 You may start @value{GDBN} with its arguments, if any, in an environment
1834 of your choice. If you are doing native debugging, you may redirect
1835 your program's input and output, debug an already running process, or
1836 kill a child process.
1837
1838 @menu
1839 * Compilation:: Compiling for debugging
1840 * Starting:: Starting your program
1841 * Arguments:: Your program's arguments
1842 * Environment:: Your program's environment
1843
1844 * Working Directory:: Your program's working directory
1845 * Input/Output:: Your program's input and output
1846 * Attach:: Debugging an already-running process
1847 * Kill Process:: Killing the child process
1848
1849 * Inferiors and Programs:: Debugging multiple inferiors and programs
1850 * Threads:: Debugging programs with multiple threads
1851 * Forks:: Debugging forks
1852 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
1853 @end menu
1854
1855 @node Compilation
1856 @section Compiling for Debugging
1857
1858 In order to debug a program effectively, you need to generate
1859 debugging information when you compile it. This debugging information
1860 is stored in the object file; it describes the data type of each
1861 variable or function and the correspondence between source line numbers
1862 and addresses in the executable code.
1863
1864 To request debugging information, specify the @samp{-g} option when you run
1865 the compiler.
1866
1867 Programs that are to be shipped to your customers are compiled with
1868 optimizations, using the @samp{-O} compiler option. However, some
1869 compilers are unable to handle the @samp{-g} and @samp{-O} options
1870 together. Using those compilers, you cannot generate optimized
1871 executables containing debugging information.
1872
1873 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1874 without @samp{-O}, making it possible to debug optimized code. We
1875 recommend that you @emph{always} use @samp{-g} whenever you compile a
1876 program. You may think your program is correct, but there is no sense
1877 in pushing your luck. For more information, see @ref{Optimized Code}.
1878
1879 Older versions of the @sc{gnu} C compiler permitted a variant option
1880 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1881 format; if your @sc{gnu} C compiler has this option, do not use it.
1882
1883 @value{GDBN} knows about preprocessor macros and can show you their
1884 expansion (@pxref{Macros}). Most compilers do not include information
1885 about preprocessor macros in the debugging information if you specify
1886 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1887 the @sc{gnu} C compiler, provides macro information if you are using
1888 the DWARF debugging format, and specify the option @option{-g3}.
1889
1890 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
1891 gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1892 information on @value{NGCC} options affecting debug information.
1893
1894 You will have the best debugging experience if you use the latest
1895 version of the DWARF debugging format that your compiler supports.
1896 DWARF is currently the most expressive and best supported debugging
1897 format in @value{GDBN}.
1898
1899 @need 2000
1900 @node Starting
1901 @section Starting your Program
1902 @cindex starting
1903 @cindex running
1904
1905 @table @code
1906 @kindex run
1907 @kindex r @r{(@code{run})}
1908 @item run
1909 @itemx r
1910 Use the @code{run} command to start your program under @value{GDBN}.
1911 You must first specify the program name (except on VxWorks) with an
1912 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1913 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1914 (@pxref{Files, ,Commands to Specify Files}).
1915
1916 @end table
1917
1918 If you are running your program in an execution environment that
1919 supports processes, @code{run} creates an inferior process and makes
1920 that process run your program. In some environments without processes,
1921 @code{run} jumps to the start of your program. Other targets,
1922 like @samp{remote}, are always running. If you get an error
1923 message like this one:
1924
1925 @smallexample
1926 The "remote" target does not support "run".
1927 Try "help target" or "continue".
1928 @end smallexample
1929
1930 @noindent
1931 then use @code{continue} to run your program. You may need @code{load}
1932 first (@pxref{load}).
1933
1934 The execution of a program is affected by certain information it
1935 receives from its superior. @value{GDBN} provides ways to specify this
1936 information, which you must do @emph{before} starting your program. (You
1937 can change it after starting your program, but such changes only affect
1938 your program the next time you start it.) This information may be
1939 divided into four categories:
1940
1941 @table @asis
1942 @item The @emph{arguments.}
1943 Specify the arguments to give your program as the arguments of the
1944 @code{run} command. If a shell is available on your target, the shell
1945 is used to pass the arguments, so that you may use normal conventions
1946 (such as wildcard expansion or variable substitution) in describing
1947 the arguments.
1948 In Unix systems, you can control which shell is used with the
1949 @code{SHELL} environment variable.
1950 @xref{Arguments, ,Your Program's Arguments}.
1951
1952 @item The @emph{environment.}
1953 Your program normally inherits its environment from @value{GDBN}, but you can
1954 use the @value{GDBN} commands @code{set environment} and @code{unset
1955 environment} to change parts of the environment that affect
1956 your program. @xref{Environment, ,Your Program's Environment}.
1957
1958 @item The @emph{working directory.}
1959 Your program inherits its working directory from @value{GDBN}. You can set
1960 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1961 @xref{Working Directory, ,Your Program's Working Directory}.
1962
1963 @item The @emph{standard input and output.}
1964 Your program normally uses the same device for standard input and
1965 standard output as @value{GDBN} is using. You can redirect input and output
1966 in the @code{run} command line, or you can use the @code{tty} command to
1967 set a different device for your program.
1968 @xref{Input/Output, ,Your Program's Input and Output}.
1969
1970 @cindex pipes
1971 @emph{Warning:} While input and output redirection work, you cannot use
1972 pipes to pass the output of the program you are debugging to another
1973 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1974 wrong program.
1975 @end table
1976
1977 When you issue the @code{run} command, your program begins to execute
1978 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
1979 of how to arrange for your program to stop. Once your program has
1980 stopped, you may call functions in your program, using the @code{print}
1981 or @code{call} commands. @xref{Data, ,Examining Data}.
1982
1983 If the modification time of your symbol file has changed since the last
1984 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1985 table, and reads it again. When it does this, @value{GDBN} tries to retain
1986 your current breakpoints.
1987
1988 @table @code
1989 @kindex start
1990 @item start
1991 @cindex run to main procedure
1992 The name of the main procedure can vary from language to language.
1993 With C or C@t{++}, the main procedure name is always @code{main}, but
1994 other languages such as Ada do not require a specific name for their
1995 main procedure. The debugger provides a convenient way to start the
1996 execution of the program and to stop at the beginning of the main
1997 procedure, depending on the language used.
1998
1999 The @samp{start} command does the equivalent of setting a temporary
2000 breakpoint at the beginning of the main procedure and then invoking
2001 the @samp{run} command.
2002
2003 @cindex elaboration phase
2004 Some programs contain an @dfn{elaboration} phase where some startup code is
2005 executed before the main procedure is called. This depends on the
2006 languages used to write your program. In C@t{++}, for instance,
2007 constructors for static and global objects are executed before
2008 @code{main} is called. It is therefore possible that the debugger stops
2009 before reaching the main procedure. However, the temporary breakpoint
2010 will remain to halt execution.
2011
2012 Specify the arguments to give to your program as arguments to the
2013 @samp{start} command. These arguments will be given verbatim to the
2014 underlying @samp{run} command. Note that the same arguments will be
2015 reused if no argument is provided during subsequent calls to
2016 @samp{start} or @samp{run}.
2017
2018 It is sometimes necessary to debug the program during elaboration. In
2019 these cases, using the @code{start} command would stop the execution of
2020 your program too late, as the program would have already completed the
2021 elaboration phase. Under these circumstances, insert breakpoints in your
2022 elaboration code before running your program.
2023
2024 @kindex set exec-wrapper
2025 @item set exec-wrapper @var{wrapper}
2026 @itemx show exec-wrapper
2027 @itemx unset exec-wrapper
2028 When @samp{exec-wrapper} is set, the specified wrapper is used to
2029 launch programs for debugging. @value{GDBN} starts your program
2030 with a shell command of the form @kbd{exec @var{wrapper}
2031 @var{program}}. Quoting is added to @var{program} and its
2032 arguments, but not to @var{wrapper}, so you should add quotes if
2033 appropriate for your shell. The wrapper runs until it executes
2034 your program, and then @value{GDBN} takes control.
2035
2036 You can use any program that eventually calls @code{execve} with
2037 its arguments as a wrapper. Several standard Unix utilities do
2038 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2039 with @code{exec "$@@"} will also work.
2040
2041 For example, you can use @code{env} to pass an environment variable to
2042 the debugged program, without setting the variable in your shell's
2043 environment:
2044
2045 @smallexample
2046 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2047 (@value{GDBP}) run
2048 @end smallexample
2049
2050 This command is available when debugging locally on most targets, excluding
2051 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2052
2053 @kindex set disable-randomization
2054 @item set disable-randomization
2055 @itemx set disable-randomization on
2056 This option (enabled by default in @value{GDBN}) will turn off the native
2057 randomization of the virtual address space of the started program. This option
2058 is useful for multiple debugging sessions to make the execution better
2059 reproducible and memory addresses reusable across debugging sessions.
2060
2061 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2062 On @sc{gnu}/Linux you can get the same behavior using
2063
2064 @smallexample
2065 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2066 @end smallexample
2067
2068 @item set disable-randomization off
2069 Leave the behavior of the started executable unchanged. Some bugs rear their
2070 ugly heads only when the program is loaded at certain addresses. If your bug
2071 disappears when you run the program under @value{GDBN}, that might be because
2072 @value{GDBN} by default disables the address randomization on platforms, such
2073 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2074 disable-randomization off} to try to reproduce such elusive bugs.
2075
2076 On targets where it is available, virtual address space randomization
2077 protects the programs against certain kinds of security attacks. In these
2078 cases the attacker needs to know the exact location of a concrete executable
2079 code. Randomizing its location makes it impossible to inject jumps misusing
2080 a code at its expected addresses.
2081
2082 Prelinking shared libraries provides a startup performance advantage but it
2083 makes addresses in these libraries predictable for privileged processes by
2084 having just unprivileged access at the target system. Reading the shared
2085 library binary gives enough information for assembling the malicious code
2086 misusing it. Still even a prelinked shared library can get loaded at a new
2087 random address just requiring the regular relocation process during the
2088 startup. Shared libraries not already prelinked are always loaded at
2089 a randomly chosen address.
2090
2091 Position independent executables (PIE) contain position independent code
2092 similar to the shared libraries and therefore such executables get loaded at
2093 a randomly chosen address upon startup. PIE executables always load even
2094 already prelinked shared libraries at a random address. You can build such
2095 executable using @command{gcc -fPIE -pie}.
2096
2097 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2098 (as long as the randomization is enabled).
2099
2100 @item show disable-randomization
2101 Show the current setting of the explicit disable of the native randomization of
2102 the virtual address space of the started program.
2103
2104 @end table
2105
2106 @node Arguments
2107 @section Your Program's Arguments
2108
2109 @cindex arguments (to your program)
2110 The arguments to your program can be specified by the arguments of the
2111 @code{run} command.
2112 They are passed to a shell, which expands wildcard characters and
2113 performs redirection of I/O, and thence to your program. Your
2114 @code{SHELL} environment variable (if it exists) specifies what shell
2115 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2116 the default shell (@file{/bin/sh} on Unix).
2117
2118 On non-Unix systems, the program is usually invoked directly by
2119 @value{GDBN}, which emulates I/O redirection via the appropriate system
2120 calls, and the wildcard characters are expanded by the startup code of
2121 the program, not by the shell.
2122
2123 @code{run} with no arguments uses the same arguments used by the previous
2124 @code{run}, or those set by the @code{set args} command.
2125
2126 @table @code
2127 @kindex set args
2128 @item set args
2129 Specify the arguments to be used the next time your program is run. If
2130 @code{set args} has no arguments, @code{run} executes your program
2131 with no arguments. Once you have run your program with arguments,
2132 using @code{set args} before the next @code{run} is the only way to run
2133 it again without arguments.
2134
2135 @kindex show args
2136 @item show args
2137 Show the arguments to give your program when it is started.
2138 @end table
2139
2140 @node Environment
2141 @section Your Program's Environment
2142
2143 @cindex environment (of your program)
2144 The @dfn{environment} consists of a set of environment variables and
2145 their values. Environment variables conventionally record such things as
2146 your user name, your home directory, your terminal type, and your search
2147 path for programs to run. Usually you set up environment variables with
2148 the shell and they are inherited by all the other programs you run. When
2149 debugging, it can be useful to try running your program with a modified
2150 environment without having to start @value{GDBN} over again.
2151
2152 @table @code
2153 @kindex path
2154 @item path @var{directory}
2155 Add @var{directory} to the front of the @code{PATH} environment variable
2156 (the search path for executables) that will be passed to your program.
2157 The value of @code{PATH} used by @value{GDBN} does not change.
2158 You may specify several directory names, separated by whitespace or by a
2159 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2160 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2161 is moved to the front, so it is searched sooner.
2162
2163 You can use the string @samp{$cwd} to refer to whatever is the current
2164 working directory at the time @value{GDBN} searches the path. If you
2165 use @samp{.} instead, it refers to the directory where you executed the
2166 @code{path} command. @value{GDBN} replaces @samp{.} in the
2167 @var{directory} argument (with the current path) before adding
2168 @var{directory} to the search path.
2169 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2170 @c document that, since repeating it would be a no-op.
2171
2172 @kindex show paths
2173 @item show paths
2174 Display the list of search paths for executables (the @code{PATH}
2175 environment variable).
2176
2177 @kindex show environment
2178 @item show environment @r{[}@var{varname}@r{]}
2179 Print the value of environment variable @var{varname} to be given to
2180 your program when it starts. If you do not supply @var{varname},
2181 print the names and values of all environment variables to be given to
2182 your program. You can abbreviate @code{environment} as @code{env}.
2183
2184 @kindex set environment
2185 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2186 Set environment variable @var{varname} to @var{value}. The value
2187 changes for your program only, not for @value{GDBN} itself. @var{value} may
2188 be any string; the values of environment variables are just strings, and
2189 any interpretation is supplied by your program itself. The @var{value}
2190 parameter is optional; if it is eliminated, the variable is set to a
2191 null value.
2192 @c "any string" here does not include leading, trailing
2193 @c blanks. Gnu asks: does anyone care?
2194
2195 For example, this command:
2196
2197 @smallexample
2198 set env USER = foo
2199 @end smallexample
2200
2201 @noindent
2202 tells the debugged program, when subsequently run, that its user is named
2203 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2204 are not actually required.)
2205
2206 @kindex unset environment
2207 @item unset environment @var{varname}
2208 Remove variable @var{varname} from the environment to be passed to your
2209 program. This is different from @samp{set env @var{varname} =};
2210 @code{unset environment} removes the variable from the environment,
2211 rather than assigning it an empty value.
2212 @end table
2213
2214 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2215 the shell indicated
2216 by your @code{SHELL} environment variable if it exists (or
2217 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2218 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2219 @file{.bashrc} for BASH---any variables you set in that file affect
2220 your program. You may wish to move setting of environment variables to
2221 files that are only run when you sign on, such as @file{.login} or
2222 @file{.profile}.
2223
2224 @node Working Directory
2225 @section Your Program's Working Directory
2226
2227 @cindex working directory (of your program)
2228 Each time you start your program with @code{run}, it inherits its
2229 working directory from the current working directory of @value{GDBN}.
2230 The @value{GDBN} working directory is initially whatever it inherited
2231 from its parent process (typically the shell), but you can specify a new
2232 working directory in @value{GDBN} with the @code{cd} command.
2233
2234 The @value{GDBN} working directory also serves as a default for the commands
2235 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2236 Specify Files}.
2237
2238 @table @code
2239 @kindex cd
2240 @cindex change working directory
2241 @item cd @var{directory}
2242 Set the @value{GDBN} working directory to @var{directory}.
2243
2244 @kindex pwd
2245 @item pwd
2246 Print the @value{GDBN} working directory.
2247 @end table
2248
2249 It is generally impossible to find the current working directory of
2250 the process being debugged (since a program can change its directory
2251 during its run). If you work on a system where @value{GDBN} is
2252 configured with the @file{/proc} support, you can use the @code{info
2253 proc} command (@pxref{SVR4 Process Information}) to find out the
2254 current working directory of the debuggee.
2255
2256 @node Input/Output
2257 @section Your Program's Input and Output
2258
2259 @cindex redirection
2260 @cindex i/o
2261 @cindex terminal
2262 By default, the program you run under @value{GDBN} does input and output to
2263 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2264 to its own terminal modes to interact with you, but it records the terminal
2265 modes your program was using and switches back to them when you continue
2266 running your program.
2267
2268 @table @code
2269 @kindex info terminal
2270 @item info terminal
2271 Displays information recorded by @value{GDBN} about the terminal modes your
2272 program is using.
2273 @end table
2274
2275 You can redirect your program's input and/or output using shell
2276 redirection with the @code{run} command. For example,
2277
2278 @smallexample
2279 run > outfile
2280 @end smallexample
2281
2282 @noindent
2283 starts your program, diverting its output to the file @file{outfile}.
2284
2285 @kindex tty
2286 @cindex controlling terminal
2287 Another way to specify where your program should do input and output is
2288 with the @code{tty} command. This command accepts a file name as
2289 argument, and causes this file to be the default for future @code{run}
2290 commands. It also resets the controlling terminal for the child
2291 process, for future @code{run} commands. For example,
2292
2293 @smallexample
2294 tty /dev/ttyb
2295 @end smallexample
2296
2297 @noindent
2298 directs that processes started with subsequent @code{run} commands
2299 default to do input and output on the terminal @file{/dev/ttyb} and have
2300 that as their controlling terminal.
2301
2302 An explicit redirection in @code{run} overrides the @code{tty} command's
2303 effect on the input/output device, but not its effect on the controlling
2304 terminal.
2305
2306 When you use the @code{tty} command or redirect input in the @code{run}
2307 command, only the input @emph{for your program} is affected. The input
2308 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2309 for @code{set inferior-tty}.
2310
2311 @cindex inferior tty
2312 @cindex set inferior controlling terminal
2313 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2314 display the name of the terminal that will be used for future runs of your
2315 program.
2316
2317 @table @code
2318 @item set inferior-tty /dev/ttyb
2319 @kindex set inferior-tty
2320 Set the tty for the program being debugged to /dev/ttyb.
2321
2322 @item show inferior-tty
2323 @kindex show inferior-tty
2324 Show the current tty for the program being debugged.
2325 @end table
2326
2327 @node Attach
2328 @section Debugging an Already-running Process
2329 @kindex attach
2330 @cindex attach
2331
2332 @table @code
2333 @item attach @var{process-id}
2334 This command attaches to a running process---one that was started
2335 outside @value{GDBN}. (@code{info files} shows your active
2336 targets.) The command takes as argument a process ID. The usual way to
2337 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2338 or with the @samp{jobs -l} shell command.
2339
2340 @code{attach} does not repeat if you press @key{RET} a second time after
2341 executing the command.
2342 @end table
2343
2344 To use @code{attach}, your program must be running in an environment
2345 which supports processes; for example, @code{attach} does not work for
2346 programs on bare-board targets that lack an operating system. You must
2347 also have permission to send the process a signal.
2348
2349 When you use @code{attach}, the debugger finds the program running in
2350 the process first by looking in the current working directory, then (if
2351 the program is not found) by using the source file search path
2352 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2353 the @code{file} command to load the program. @xref{Files, ,Commands to
2354 Specify Files}.
2355
2356 The first thing @value{GDBN} does after arranging to debug the specified
2357 process is to stop it. You can examine and modify an attached process
2358 with all the @value{GDBN} commands that are ordinarily available when
2359 you start processes with @code{run}. You can insert breakpoints; you
2360 can step and continue; you can modify storage. If you would rather the
2361 process continue running, you may use the @code{continue} command after
2362 attaching @value{GDBN} to the process.
2363
2364 @table @code
2365 @kindex detach
2366 @item detach
2367 When you have finished debugging the attached process, you can use the
2368 @code{detach} command to release it from @value{GDBN} control. Detaching
2369 the process continues its execution. After the @code{detach} command,
2370 that process and @value{GDBN} become completely independent once more, and you
2371 are ready to @code{attach} another process or start one with @code{run}.
2372 @code{detach} does not repeat if you press @key{RET} again after
2373 executing the command.
2374 @end table
2375
2376 If you exit @value{GDBN} while you have an attached process, you detach
2377 that process. If you use the @code{run} command, you kill that process.
2378 By default, @value{GDBN} asks for confirmation if you try to do either of these
2379 things; you can control whether or not you need to confirm by using the
2380 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2381 Messages}).
2382
2383 @node Kill Process
2384 @section Killing the Child Process
2385
2386 @table @code
2387 @kindex kill
2388 @item kill
2389 Kill the child process in which your program is running under @value{GDBN}.
2390 @end table
2391
2392 This command is useful if you wish to debug a core dump instead of a
2393 running process. @value{GDBN} ignores any core dump file while your program
2394 is running.
2395
2396 On some operating systems, a program cannot be executed outside @value{GDBN}
2397 while you have breakpoints set on it inside @value{GDBN}. You can use the
2398 @code{kill} command in this situation to permit running your program
2399 outside the debugger.
2400
2401 The @code{kill} command is also useful if you wish to recompile and
2402 relink your program, since on many systems it is impossible to modify an
2403 executable file while it is running in a process. In this case, when you
2404 next type @code{run}, @value{GDBN} notices that the file has changed, and
2405 reads the symbol table again (while trying to preserve your current
2406 breakpoint settings).
2407
2408 @node Inferiors and Programs
2409 @section Debugging Multiple Inferiors and Programs
2410
2411 @value{GDBN} lets you run and debug multiple programs in a single
2412 session. In addition, @value{GDBN} on some systems may let you run
2413 several programs simultaneously (otherwise you have to exit from one
2414 before starting another). In the most general case, you can have
2415 multiple threads of execution in each of multiple processes, launched
2416 from multiple executables.
2417
2418 @cindex inferior
2419 @value{GDBN} represents the state of each program execution with an
2420 object called an @dfn{inferior}. An inferior typically corresponds to
2421 a process, but is more general and applies also to targets that do not
2422 have processes. Inferiors may be created before a process runs, and
2423 may be retained after a process exits. Inferiors have unique
2424 identifiers that are different from process ids. Usually each
2425 inferior will also have its own distinct address space, although some
2426 embedded targets may have several inferiors running in different parts
2427 of a single address space. Each inferior may in turn have multiple
2428 threads running in it.
2429
2430 To find out what inferiors exist at any moment, use @w{@code{info
2431 inferiors}}:
2432
2433 @table @code
2434 @kindex info inferiors
2435 @item info inferiors
2436 Print a list of all inferiors currently being managed by @value{GDBN}.
2437
2438 @value{GDBN} displays for each inferior (in this order):
2439
2440 @enumerate
2441 @item
2442 the inferior number assigned by @value{GDBN}
2443
2444 @item
2445 the target system's inferior identifier
2446
2447 @item
2448 the name of the executable the inferior is running.
2449
2450 @end enumerate
2451
2452 @noindent
2453 An asterisk @samp{*} preceding the @value{GDBN} inferior number
2454 indicates the current inferior.
2455
2456 For example,
2457 @end table
2458 @c end table here to get a little more width for example
2459
2460 @smallexample
2461 (@value{GDBP}) info inferiors
2462 Num Description Executable
2463 2 process 2307 hello
2464 * 1 process 3401 goodbye
2465 @end smallexample
2466
2467 To switch focus between inferiors, use the @code{inferior} command:
2468
2469 @table @code
2470 @kindex inferior @var{infno}
2471 @item inferior @var{infno}
2472 Make inferior number @var{infno} the current inferior. The argument
2473 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
2474 in the first field of the @samp{info inferiors} display.
2475 @end table
2476
2477
2478 You can get multiple executables into a debugging session via the
2479 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2480 systems @value{GDBN} can add inferiors to the debug session
2481 automatically by following calls to @code{fork} and @code{exec}. To
2482 remove inferiors from the debugging session use the
2483 @w{@code{remove-inferiors}} command.
2484
2485 @table @code
2486 @kindex add-inferior
2487 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2488 Adds @var{n} inferiors to be run using @var{executable} as the
2489 executable. @var{n} defaults to 1. If no executable is specified,
2490 the inferiors begins empty, with no program. You can still assign or
2491 change the program assigned to the inferior at any time by using the
2492 @code{file} command with the executable name as its argument.
2493
2494 @kindex clone-inferior
2495 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2496 Adds @var{n} inferiors ready to execute the same program as inferior
2497 @var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2498 number of the current inferior. This is a convenient command when you
2499 want to run another instance of the inferior you are debugging.
2500
2501 @smallexample
2502 (@value{GDBP}) info inferiors
2503 Num Description Executable
2504 * 1 process 29964 helloworld
2505 (@value{GDBP}) clone-inferior
2506 Added inferior 2.
2507 1 inferiors added.
2508 (@value{GDBP}) info inferiors
2509 Num Description Executable
2510 2 <null> helloworld
2511 * 1 process 29964 helloworld
2512 @end smallexample
2513
2514 You can now simply switch focus to inferior 2 and run it.
2515
2516 @kindex remove-inferiors
2517 @item remove-inferiors @var{infno}@dots{}
2518 Removes the inferior or inferiors @var{infno}@dots{}. It is not
2519 possible to remove an inferior that is running with this command. For
2520 those, use the @code{kill} or @code{detach} command first.
2521
2522 @end table
2523
2524 To quit debugging one of the running inferiors that is not the current
2525 inferior, you can either detach from it by using the @w{@code{detach
2526 inferior}} command (allowing it to run independently), or kill it
2527 using the @w{@code{kill inferiors}} command:
2528
2529 @table @code
2530 @kindex detach inferiors @var{infno}@dots{}
2531 @item detach inferior @var{infno}@dots{}
2532 Detach from the inferior or inferiors identified by @value{GDBN}
2533 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
2534 still stays on the list of inferiors shown by @code{info inferiors},
2535 but its Description will show @samp{<null>}.
2536
2537 @kindex kill inferiors @var{infno}@dots{}
2538 @item kill inferiors @var{infno}@dots{}
2539 Kill the inferior or inferiors identified by @value{GDBN} inferior
2540 number(s) @var{infno}@dots{}. Note that the inferior's entry still
2541 stays on the list of inferiors shown by @code{info inferiors}, but its
2542 Description will show @samp{<null>}.
2543 @end table
2544
2545 After the successful completion of a command such as @code{detach},
2546 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
2547 a normal process exit, the inferior is still valid and listed with
2548 @code{info inferiors}, ready to be restarted.
2549
2550
2551 To be notified when inferiors are started or exit under @value{GDBN}'s
2552 control use @w{@code{set print inferior-events}}:
2553
2554 @table @code
2555 @kindex set print inferior-events
2556 @cindex print messages on inferior start and exit
2557 @item set print inferior-events
2558 @itemx set print inferior-events on
2559 @itemx set print inferior-events off
2560 The @code{set print inferior-events} command allows you to enable or
2561 disable printing of messages when @value{GDBN} notices that new
2562 inferiors have started or that inferiors have exited or have been
2563 detached. By default, these messages will not be printed.
2564
2565 @kindex show print inferior-events
2566 @item show print inferior-events
2567 Show whether messages will be printed when @value{GDBN} detects that
2568 inferiors have started, exited or have been detached.
2569 @end table
2570
2571 Many commands will work the same with multiple programs as with a
2572 single program: e.g., @code{print myglobal} will simply display the
2573 value of @code{myglobal} in the current inferior.
2574
2575
2576 Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2577 get more info about the relationship of inferiors, programs, address
2578 spaces in a debug session. You can do that with the @w{@code{maint
2579 info program-spaces}} command.
2580
2581 @table @code
2582 @kindex maint info program-spaces
2583 @item maint info program-spaces
2584 Print a list of all program spaces currently being managed by
2585 @value{GDBN}.
2586
2587 @value{GDBN} displays for each program space (in this order):
2588
2589 @enumerate
2590 @item
2591 the program space number assigned by @value{GDBN}
2592
2593 @item
2594 the name of the executable loaded into the program space, with e.g.,
2595 the @code{file} command.
2596
2597 @end enumerate
2598
2599 @noindent
2600 An asterisk @samp{*} preceding the @value{GDBN} program space number
2601 indicates the current program space.
2602
2603 In addition, below each program space line, @value{GDBN} prints extra
2604 information that isn't suitable to display in tabular form. For
2605 example, the list of inferiors bound to the program space.
2606
2607 @smallexample
2608 (@value{GDBP}) maint info program-spaces
2609 Id Executable
2610 2 goodbye
2611 Bound inferiors: ID 1 (process 21561)
2612 * 1 hello
2613 @end smallexample
2614
2615 Here we can see that no inferior is running the program @code{hello},
2616 while @code{process 21561} is running the program @code{goodbye}. On
2617 some targets, it is possible that multiple inferiors are bound to the
2618 same program space. The most common example is that of debugging both
2619 the parent and child processes of a @code{vfork} call. For example,
2620
2621 @smallexample
2622 (@value{GDBP}) maint info program-spaces
2623 Id Executable
2624 * 1 vfork-test
2625 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2626 @end smallexample
2627
2628 Here, both inferior 2 and inferior 1 are running in the same program
2629 space as a result of inferior 1 having executed a @code{vfork} call.
2630 @end table
2631
2632 @node Threads
2633 @section Debugging Programs with Multiple Threads
2634
2635 @cindex threads of execution
2636 @cindex multiple threads
2637 @cindex switching threads
2638 In some operating systems, such as HP-UX and Solaris, a single program
2639 may have more than one @dfn{thread} of execution. The precise semantics
2640 of threads differ from one operating system to another, but in general
2641 the threads of a single program are akin to multiple processes---except
2642 that they share one address space (that is, they can all examine and
2643 modify the same variables). On the other hand, each thread has its own
2644 registers and execution stack, and perhaps private memory.
2645
2646 @value{GDBN} provides these facilities for debugging multi-thread
2647 programs:
2648
2649 @itemize @bullet
2650 @item automatic notification of new threads
2651 @item @samp{thread @var{threadno}}, a command to switch among threads
2652 @item @samp{info threads}, a command to inquire about existing threads
2653 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2654 a command to apply a command to a list of threads
2655 @item thread-specific breakpoints
2656 @item @samp{set print thread-events}, which controls printing of
2657 messages on thread start and exit.
2658 @item @samp{set libthread-db-search-path @var{path}}, which lets
2659 the user specify which @code{libthread_db} to use if the default choice
2660 isn't compatible with the program.
2661 @end itemize
2662
2663 @quotation
2664 @emph{Warning:} These facilities are not yet available on every
2665 @value{GDBN} configuration where the operating system supports threads.
2666 If your @value{GDBN} does not support threads, these commands have no
2667 effect. For example, a system without thread support shows no output
2668 from @samp{info threads}, and always rejects the @code{thread} command,
2669 like this:
2670
2671 @smallexample
2672 (@value{GDBP}) info threads
2673 (@value{GDBP}) thread 1
2674 Thread ID 1 not known. Use the "info threads" command to
2675 see the IDs of currently known threads.
2676 @end smallexample
2677 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2678 @c doesn't support threads"?
2679 @end quotation
2680
2681 @cindex focus of debugging
2682 @cindex current thread
2683 The @value{GDBN} thread debugging facility allows you to observe all
2684 threads while your program runs---but whenever @value{GDBN} takes
2685 control, one thread in particular is always the focus of debugging.
2686 This thread is called the @dfn{current thread}. Debugging commands show
2687 program information from the perspective of the current thread.
2688
2689 @cindex @code{New} @var{systag} message
2690 @cindex thread identifier (system)
2691 @c FIXME-implementors!! It would be more helpful if the [New...] message
2692 @c included GDB's numeric thread handle, so you could just go to that
2693 @c thread without first checking `info threads'.
2694 Whenever @value{GDBN} detects a new thread in your program, it displays
2695 the target system's identification for the thread with a message in the
2696 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2697 whose form varies depending on the particular system. For example, on
2698 @sc{gnu}/Linux, you might see
2699
2700 @smallexample
2701 [New Thread 0x41e02940 (LWP 25582)]
2702 @end smallexample
2703
2704 @noindent
2705 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2706 the @var{systag} is simply something like @samp{process 368}, with no
2707 further qualifier.
2708
2709 @c FIXME!! (1) Does the [New...] message appear even for the very first
2710 @c thread of a program, or does it only appear for the
2711 @c second---i.e.@: when it becomes obvious we have a multithread
2712 @c program?
2713 @c (2) *Is* there necessarily a first thread always? Or do some
2714 @c multithread systems permit starting a program with multiple
2715 @c threads ab initio?
2716
2717 @cindex thread number
2718 @cindex thread identifier (GDB)
2719 For debugging purposes, @value{GDBN} associates its own thread
2720 number---always a single integer---with each thread in your program.
2721
2722 @table @code
2723 @kindex info threads
2724 @item info threads @r{[}@var{id}@dots{}@r{]}
2725 Display a summary of all threads currently in your program. Optional
2726 argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2727 means to print information only about the specified thread or threads.
2728 @value{GDBN} displays for each thread (in this order):
2729
2730 @enumerate
2731 @item
2732 the thread number assigned by @value{GDBN}
2733
2734 @item
2735 the target system's thread identifier (@var{systag})
2736
2737 @item
2738 the thread's name, if one is known. A thread can either be named by
2739 the user (see @code{thread name}, below), or, in some cases, by the
2740 program itself.
2741
2742 @item
2743 the current stack frame summary for that thread
2744 @end enumerate
2745
2746 @noindent
2747 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2748 indicates the current thread.
2749
2750 For example,
2751 @end table
2752 @c end table here to get a little more width for example
2753
2754 @smallexample
2755 (@value{GDBP}) info threads
2756 Id Target Id Frame
2757 3 process 35 thread 27 0x34e5 in sigpause ()
2758 2 process 35 thread 23 0x34e5 in sigpause ()
2759 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2760 at threadtest.c:68
2761 @end smallexample
2762
2763 On Solaris, you can display more information about user threads with a
2764 Solaris-specific command:
2765
2766 @table @code
2767 @item maint info sol-threads
2768 @kindex maint info sol-threads
2769 @cindex thread info (Solaris)
2770 Display info on Solaris user threads.
2771 @end table
2772
2773 @table @code
2774 @kindex thread @var{threadno}
2775 @item thread @var{threadno}
2776 Make thread number @var{threadno} the current thread. The command
2777 argument @var{threadno} is the internal @value{GDBN} thread number, as
2778 shown in the first field of the @samp{info threads} display.
2779 @value{GDBN} responds by displaying the system identifier of the thread
2780 you selected, and its current stack frame summary:
2781
2782 @smallexample
2783 (@value{GDBP}) thread 2
2784 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2785 #0 some_function (ignore=0x0) at example.c:8
2786 8 printf ("hello\n");
2787 @end smallexample
2788
2789 @noindent
2790 As with the @samp{[New @dots{}]} message, the form of the text after
2791 @samp{Switching to} depends on your system's conventions for identifying
2792 threads.
2793
2794 @vindex $_thread@r{, convenience variable}
2795 The debugger convenience variable @samp{$_thread} contains the number
2796 of the current thread. You may find this useful in writing breakpoint
2797 conditional expressions, command scripts, and so forth. See
2798 @xref{Convenience Vars,, Convenience Variables}, for general
2799 information on convenience variables.
2800
2801 @kindex thread apply
2802 @cindex apply command to several threads
2803 @item thread apply [@var{threadno} | all] @var{command}
2804 The @code{thread apply} command allows you to apply the named
2805 @var{command} to one or more threads. Specify the numbers of the
2806 threads that you want affected with the command argument
2807 @var{threadno}. It can be a single thread number, one of the numbers
2808 shown in the first field of the @samp{info threads} display; or it
2809 could be a range of thread numbers, as in @code{2-4}. To apply a
2810 command to all threads, type @kbd{thread apply all @var{command}}.
2811
2812 @kindex thread name
2813 @cindex name a thread
2814 @item thread name [@var{name}]
2815 This command assigns a name to the current thread. If no argument is
2816 given, any existing user-specified name is removed. The thread name
2817 appears in the @samp{info threads} display.
2818
2819 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2820 determine the name of the thread as given by the OS. On these
2821 systems, a name specified with @samp{thread name} will override the
2822 system-give name, and removing the user-specified name will cause
2823 @value{GDBN} to once again display the system-specified name.
2824
2825 @kindex thread find
2826 @cindex search for a thread
2827 @item thread find [@var{regexp}]
2828 Search for and display thread ids whose name or @var{systag}
2829 matches the supplied regular expression.
2830
2831 As well as being the complement to the @samp{thread name} command,
2832 this command also allows you to identify a thread by its target
2833 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
2834 is the LWP id.
2835
2836 @smallexample
2837 (@value{GDBN}) thread find 26688
2838 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2839 (@value{GDBN}) info thread 4
2840 Id Target Id Frame
2841 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2842 @end smallexample
2843
2844 @kindex set print thread-events
2845 @cindex print messages on thread start and exit
2846 @item set print thread-events
2847 @itemx set print thread-events on
2848 @itemx set print thread-events off
2849 The @code{set print thread-events} command allows you to enable or
2850 disable printing of messages when @value{GDBN} notices that new threads have
2851 started or that threads have exited. By default, these messages will
2852 be printed if detection of these events is supported by the target.
2853 Note that these messages cannot be disabled on all targets.
2854
2855 @kindex show print thread-events
2856 @item show print thread-events
2857 Show whether messages will be printed when @value{GDBN} detects that threads
2858 have started and exited.
2859 @end table
2860
2861 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2862 more information about how @value{GDBN} behaves when you stop and start
2863 programs with multiple threads.
2864
2865 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
2866 watchpoints in programs with multiple threads.
2867
2868 @table @code
2869 @kindex set libthread-db-search-path
2870 @cindex search path for @code{libthread_db}
2871 @item set libthread-db-search-path @r{[}@var{path}@r{]}
2872 If this variable is set, @var{path} is a colon-separated list of
2873 directories @value{GDBN} will use to search for @code{libthread_db}.
2874 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
2875 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
2876 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
2877 macro.
2878
2879 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2880 @code{libthread_db} library to obtain information about threads in the
2881 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
2882 to find @code{libthread_db}.
2883
2884 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
2885 refers to the default system directories that are
2886 normally searched for loading shared libraries.
2887
2888 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
2889 refers to the directory from which @code{libpthread}
2890 was loaded in the inferior process.
2891
2892 For any @code{libthread_db} library @value{GDBN} finds in above directories,
2893 @value{GDBN} attempts to initialize it with the current inferior process.
2894 If this initialization fails (which could happen because of a version
2895 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2896 will unload @code{libthread_db}, and continue with the next directory.
2897 If none of @code{libthread_db} libraries initialize successfully,
2898 @value{GDBN} will issue a warning and thread debugging will be disabled.
2899
2900 Setting @code{libthread-db-search-path} is currently implemented
2901 only on some platforms.
2902
2903 @kindex show libthread-db-search-path
2904 @item show libthread-db-search-path
2905 Display current libthread_db search path.
2906
2907 @kindex set debug libthread-db
2908 @kindex show debug libthread-db
2909 @cindex debugging @code{libthread_db}
2910 @item set debug libthread-db
2911 @itemx show debug libthread-db
2912 Turns on or off display of @code{libthread_db}-related events.
2913 Use @code{1} to enable, @code{0} to disable.
2914 @end table
2915
2916 @node Forks
2917 @section Debugging Forks
2918
2919 @cindex fork, debugging programs which call
2920 @cindex multiple processes
2921 @cindex processes, multiple
2922 On most systems, @value{GDBN} has no special support for debugging
2923 programs which create additional processes using the @code{fork}
2924 function. When a program forks, @value{GDBN} will continue to debug the
2925 parent process and the child process will run unimpeded. If you have
2926 set a breakpoint in any code which the child then executes, the child
2927 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2928 will cause it to terminate.
2929
2930 However, if you want to debug the child process there is a workaround
2931 which isn't too painful. Put a call to @code{sleep} in the code which
2932 the child process executes after the fork. It may be useful to sleep
2933 only if a certain environment variable is set, or a certain file exists,
2934 so that the delay need not occur when you don't want to run @value{GDBN}
2935 on the child. While the child is sleeping, use the @code{ps} program to
2936 get its process ID. Then tell @value{GDBN} (a new invocation of
2937 @value{GDBN} if you are also debugging the parent process) to attach to
2938 the child process (@pxref{Attach}). From that point on you can debug
2939 the child process just like any other process which you attached to.
2940
2941 On some systems, @value{GDBN} provides support for debugging programs that
2942 create additional processes using the @code{fork} or @code{vfork} functions.
2943 Currently, the only platforms with this feature are HP-UX (11.x and later
2944 only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
2945
2946 By default, when a program forks, @value{GDBN} will continue to debug
2947 the parent process and the child process will run unimpeded.
2948
2949 If you want to follow the child process instead of the parent process,
2950 use the command @w{@code{set follow-fork-mode}}.
2951
2952 @table @code
2953 @kindex set follow-fork-mode
2954 @item set follow-fork-mode @var{mode}
2955 Set the debugger response to a program call of @code{fork} or
2956 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2957 process. The @var{mode} argument can be:
2958
2959 @table @code
2960 @item parent
2961 The original process is debugged after a fork. The child process runs
2962 unimpeded. This is the default.
2963
2964 @item child
2965 The new process is debugged after a fork. The parent process runs
2966 unimpeded.
2967
2968 @end table
2969
2970 @kindex show follow-fork-mode
2971 @item show follow-fork-mode
2972 Display the current debugger response to a @code{fork} or @code{vfork} call.
2973 @end table
2974
2975 @cindex debugging multiple processes
2976 On Linux, if you want to debug both the parent and child processes, use the
2977 command @w{@code{set detach-on-fork}}.
2978
2979 @table @code
2980 @kindex set detach-on-fork
2981 @item set detach-on-fork @var{mode}
2982 Tells gdb whether to detach one of the processes after a fork, or
2983 retain debugger control over them both.
2984
2985 @table @code
2986 @item on
2987 The child process (or parent process, depending on the value of
2988 @code{follow-fork-mode}) will be detached and allowed to run
2989 independently. This is the default.
2990
2991 @item off
2992 Both processes will be held under the control of @value{GDBN}.
2993 One process (child or parent, depending on the value of
2994 @code{follow-fork-mode}) is debugged as usual, while the other
2995 is held suspended.
2996
2997 @end table
2998
2999 @kindex show detach-on-fork
3000 @item show detach-on-fork
3001 Show whether detach-on-fork mode is on/off.
3002 @end table
3003
3004 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3005 will retain control of all forked processes (including nested forks).
3006 You can list the forked processes under the control of @value{GDBN} by
3007 using the @w{@code{info inferiors}} command, and switch from one fork
3008 to another by using the @code{inferior} command (@pxref{Inferiors and
3009 Programs, ,Debugging Multiple Inferiors and Programs}).
3010
3011 To quit debugging one of the forked processes, you can either detach
3012 from it by using the @w{@code{detach inferiors}} command (allowing it
3013 to run independently), or kill it using the @w{@code{kill inferiors}}
3014 command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3015 and Programs}.
3016
3017 If you ask to debug a child process and a @code{vfork} is followed by an
3018 @code{exec}, @value{GDBN} executes the new target up to the first
3019 breakpoint in the new target. If you have a breakpoint set on
3020 @code{main} in your original program, the breakpoint will also be set on
3021 the child process's @code{main}.
3022
3023 On some systems, when a child process is spawned by @code{vfork}, you
3024 cannot debug the child or parent until an @code{exec} call completes.
3025
3026 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3027 call executes, the new target restarts. To restart the parent
3028 process, use the @code{file} command with the parent executable name
3029 as its argument. By default, after an @code{exec} call executes,
3030 @value{GDBN} discards the symbols of the previous executable image.
3031 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3032 command.
3033
3034 @table @code
3035 @kindex set follow-exec-mode
3036 @item set follow-exec-mode @var{mode}
3037
3038 Set debugger response to a program call of @code{exec}. An
3039 @code{exec} call replaces the program image of a process.
3040
3041 @code{follow-exec-mode} can be:
3042
3043 @table @code
3044 @item new
3045 @value{GDBN} creates a new inferior and rebinds the process to this
3046 new inferior. The program the process was running before the
3047 @code{exec} call can be restarted afterwards by restarting the
3048 original inferior.
3049
3050 For example:
3051
3052 @smallexample
3053 (@value{GDBP}) info inferiors
3054 (gdb) info inferior
3055 Id Description Executable
3056 * 1 <null> prog1
3057 (@value{GDBP}) run
3058 process 12020 is executing new program: prog2
3059 Program exited normally.
3060 (@value{GDBP}) info inferiors
3061 Id Description Executable
3062 * 2 <null> prog2
3063 1 <null> prog1
3064 @end smallexample
3065
3066 @item same
3067 @value{GDBN} keeps the process bound to the same inferior. The new
3068 executable image replaces the previous executable loaded in the
3069 inferior. Restarting the inferior after the @code{exec} call, with
3070 e.g., the @code{run} command, restarts the executable the process was
3071 running after the @code{exec} call. This is the default mode.
3072
3073 For example:
3074
3075 @smallexample
3076 (@value{GDBP}) info inferiors
3077 Id Description Executable
3078 * 1 <null> prog1
3079 (@value{GDBP}) run
3080 process 12020 is executing new program: prog2
3081 Program exited normally.
3082 (@value{GDBP}) info inferiors
3083 Id Description Executable
3084 * 1 <null> prog2
3085 @end smallexample
3086
3087 @end table
3088 @end table
3089
3090 You can use the @code{catch} command to make @value{GDBN} stop whenever
3091 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3092 Catchpoints, ,Setting Catchpoints}.
3093
3094 @node Checkpoint/Restart
3095 @section Setting a @emph{Bookmark} to Return to Later
3096
3097 @cindex checkpoint
3098 @cindex restart
3099 @cindex bookmark
3100 @cindex snapshot of a process
3101 @cindex rewind program state
3102
3103 On certain operating systems@footnote{Currently, only
3104 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3105 program's state, called a @dfn{checkpoint}, and come back to it
3106 later.
3107
3108 Returning to a checkpoint effectively undoes everything that has
3109 happened in the program since the @code{checkpoint} was saved. This
3110 includes changes in memory, registers, and even (within some limits)
3111 system state. Effectively, it is like going back in time to the
3112 moment when the checkpoint was saved.
3113
3114 Thus, if you're stepping thru a program and you think you're
3115 getting close to the point where things go wrong, you can save
3116 a checkpoint. Then, if you accidentally go too far and miss
3117 the critical statement, instead of having to restart your program
3118 from the beginning, you can just go back to the checkpoint and
3119 start again from there.
3120
3121 This can be especially useful if it takes a lot of time or
3122 steps to reach the point where you think the bug occurs.
3123
3124 To use the @code{checkpoint}/@code{restart} method of debugging:
3125
3126 @table @code
3127 @kindex checkpoint
3128 @item checkpoint
3129 Save a snapshot of the debugged program's current execution state.
3130 The @code{checkpoint} command takes no arguments, but each checkpoint
3131 is assigned a small integer id, similar to a breakpoint id.
3132
3133 @kindex info checkpoints
3134 @item info checkpoints
3135 List the checkpoints that have been saved in the current debugging
3136 session. For each checkpoint, the following information will be
3137 listed:
3138
3139 @table @code
3140 @item Checkpoint ID
3141 @item Process ID
3142 @item Code Address
3143 @item Source line, or label
3144 @end table
3145
3146 @kindex restart @var{checkpoint-id}
3147 @item restart @var{checkpoint-id}
3148 Restore the program state that was saved as checkpoint number
3149 @var{checkpoint-id}. All program variables, registers, stack frames
3150 etc.@: will be returned to the values that they had when the checkpoint
3151 was saved. In essence, gdb will ``wind back the clock'' to the point
3152 in time when the checkpoint was saved.
3153
3154 Note that breakpoints, @value{GDBN} variables, command history etc.
3155 are not affected by restoring a checkpoint. In general, a checkpoint
3156 only restores things that reside in the program being debugged, not in
3157 the debugger.
3158
3159 @kindex delete checkpoint @var{checkpoint-id}
3160 @item delete checkpoint @var{checkpoint-id}
3161 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3162
3163 @end table
3164
3165 Returning to a previously saved checkpoint will restore the user state
3166 of the program being debugged, plus a significant subset of the system
3167 (OS) state, including file pointers. It won't ``un-write'' data from
3168 a file, but it will rewind the file pointer to the previous location,
3169 so that the previously written data can be overwritten. For files
3170 opened in read mode, the pointer will also be restored so that the
3171 previously read data can be read again.
3172
3173 Of course, characters that have been sent to a printer (or other
3174 external device) cannot be ``snatched back'', and characters received
3175 from eg.@: a serial device can be removed from internal program buffers,
3176 but they cannot be ``pushed back'' into the serial pipeline, ready to
3177 be received again. Similarly, the actual contents of files that have
3178 been changed cannot be restored (at this time).
3179
3180 However, within those constraints, you actually can ``rewind'' your
3181 program to a previously saved point in time, and begin debugging it
3182 again --- and you can change the course of events so as to debug a
3183 different execution path this time.
3184
3185 @cindex checkpoints and process id
3186 Finally, there is one bit of internal program state that will be
3187 different when you return to a checkpoint --- the program's process
3188 id. Each checkpoint will have a unique process id (or @var{pid}),
3189 and each will be different from the program's original @var{pid}.
3190 If your program has saved a local copy of its process id, this could
3191 potentially pose a problem.
3192
3193 @subsection A Non-obvious Benefit of Using Checkpoints
3194
3195 On some systems such as @sc{gnu}/Linux, address space randomization
3196 is performed on new processes for security reasons. This makes it
3197 difficult or impossible to set a breakpoint, or watchpoint, on an
3198 absolute address if you have to restart the program, since the
3199 absolute location of a symbol will change from one execution to the
3200 next.
3201
3202 A checkpoint, however, is an @emph{identical} copy of a process.
3203 Therefore if you create a checkpoint at (eg.@:) the start of main,
3204 and simply return to that checkpoint instead of restarting the
3205 process, you can avoid the effects of address randomization and
3206 your symbols will all stay in the same place.
3207
3208 @node Stopping
3209 @chapter Stopping and Continuing
3210
3211 The principal purposes of using a debugger are so that you can stop your
3212 program before it terminates; or so that, if your program runs into
3213 trouble, you can investigate and find out why.
3214
3215 Inside @value{GDBN}, your program may stop for any of several reasons,
3216 such as a signal, a breakpoint, or reaching a new line after a
3217 @value{GDBN} command such as @code{step}. You may then examine and
3218 change variables, set new breakpoints or remove old ones, and then
3219 continue execution. Usually, the messages shown by @value{GDBN} provide
3220 ample explanation of the status of your program---but you can also
3221 explicitly request this information at any time.
3222
3223 @table @code
3224 @kindex info program
3225 @item info program
3226 Display information about the status of your program: whether it is
3227 running or not, what process it is, and why it stopped.
3228 @end table
3229
3230 @menu
3231 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
3232 * Continuing and Stepping:: Resuming execution
3233 * Skipping Over Functions and Files::
3234 Skipping over functions and files
3235 * Signals:: Signals
3236 * Thread Stops:: Stopping and starting multi-thread programs
3237 @end menu
3238
3239 @node Breakpoints
3240 @section Breakpoints, Watchpoints, and Catchpoints
3241
3242 @cindex breakpoints
3243 A @dfn{breakpoint} makes your program stop whenever a certain point in
3244 the program is reached. For each breakpoint, you can add conditions to
3245 control in finer detail whether your program stops. You can set
3246 breakpoints with the @code{break} command and its variants (@pxref{Set
3247 Breaks, ,Setting Breakpoints}), to specify the place where your program
3248 should stop by line number, function name or exact address in the
3249 program.
3250
3251 On some systems, you can set breakpoints in shared libraries before
3252 the executable is run. There is a minor limitation on HP-UX systems:
3253 you must wait until the executable is run in order to set breakpoints
3254 in shared library routines that are not called directly by the program
3255 (for example, routines that are arguments in a @code{pthread_create}
3256 call).
3257
3258 @cindex watchpoints
3259 @cindex data breakpoints
3260 @cindex memory tracing
3261 @cindex breakpoint on memory address
3262 @cindex breakpoint on variable modification
3263 A @dfn{watchpoint} is a special breakpoint that stops your program
3264 when the value of an expression changes. The expression may be a value
3265 of a variable, or it could involve values of one or more variables
3266 combined by operators, such as @samp{a + b}. This is sometimes called
3267 @dfn{data breakpoints}. You must use a different command to set
3268 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
3269 from that, you can manage a watchpoint like any other breakpoint: you
3270 enable, disable, and delete both breakpoints and watchpoints using the
3271 same commands.
3272
3273 You can arrange to have values from your program displayed automatically
3274 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
3275 Automatic Display}.
3276
3277 @cindex catchpoints
3278 @cindex breakpoint on events
3279 A @dfn{catchpoint} is another special breakpoint that stops your program
3280 when a certain kind of event occurs, such as the throwing of a C@t{++}
3281 exception or the loading of a library. As with watchpoints, you use a
3282 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
3283 Catchpoints}), but aside from that, you can manage a catchpoint like any
3284 other breakpoint. (To stop when your program receives a signal, use the
3285 @code{handle} command; see @ref{Signals, ,Signals}.)
3286
3287 @cindex breakpoint numbers
3288 @cindex numbers for breakpoints
3289 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
3290 catchpoint when you create it; these numbers are successive integers
3291 starting with one. In many of the commands for controlling various
3292 features of breakpoints you use the breakpoint number to say which
3293 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3294 @dfn{disabled}; if disabled, it has no effect on your program until you
3295 enable it again.
3296
3297 @cindex breakpoint ranges
3298 @cindex ranges of breakpoints
3299 Some @value{GDBN} commands accept a range of breakpoints on which to
3300 operate. A breakpoint range is either a single breakpoint number, like
3301 @samp{5}, or two such numbers, in increasing order, separated by a
3302 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
3303 all breakpoints in that range are operated on.
3304
3305 @menu
3306 * Set Breaks:: Setting breakpoints
3307 * Set Watchpoints:: Setting watchpoints
3308 * Set Catchpoints:: Setting catchpoints
3309 * Delete Breaks:: Deleting breakpoints
3310 * Disabling:: Disabling breakpoints
3311 * Conditions:: Break conditions
3312 * Break Commands:: Breakpoint command lists
3313 * Save Breakpoints:: How to save breakpoints in a file
3314 * Error in Breakpoints:: ``Cannot insert breakpoints''
3315 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
3316 @end menu
3317
3318 @node Set Breaks
3319 @subsection Setting Breakpoints
3320
3321 @c FIXME LMB what does GDB do if no code on line of breakpt?
3322 @c consider in particular declaration with/without initialization.
3323 @c
3324 @c FIXME 2 is there stuff on this already? break at fun start, already init?
3325
3326 @kindex break
3327 @kindex b @r{(@code{break})}
3328 @vindex $bpnum@r{, convenience variable}
3329 @cindex latest breakpoint
3330 Breakpoints are set with the @code{break} command (abbreviated
3331 @code{b}). The debugger convenience variable @samp{$bpnum} records the
3332 number of the breakpoint you've set most recently; see @ref{Convenience
3333 Vars,, Convenience Variables}, for a discussion of what you can do with
3334 convenience variables.
3335
3336 @table @code
3337 @item break @var{location}
3338 Set a breakpoint at the given @var{location}, which can specify a
3339 function name, a line number, or an address of an instruction.
3340 (@xref{Specify Location}, for a list of all the possible ways to
3341 specify a @var{location}.) The breakpoint will stop your program just
3342 before it executes any of the code in the specified @var{location}.
3343
3344 When using source languages that permit overloading of symbols, such as
3345 C@t{++}, a function name may refer to more than one possible place to break.
3346 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3347 that situation.
3348
3349 It is also possible to insert a breakpoint that will stop the program
3350 only if a specific thread (@pxref{Thread-Specific Breakpoints})
3351 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
3352
3353 @item break
3354 When called without any arguments, @code{break} sets a breakpoint at
3355 the next instruction to be executed in the selected stack frame
3356 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3357 innermost, this makes your program stop as soon as control
3358 returns to that frame. This is similar to the effect of a
3359 @code{finish} command in the frame inside the selected frame---except
3360 that @code{finish} does not leave an active breakpoint. If you use
3361 @code{break} without an argument in the innermost frame, @value{GDBN} stops
3362 the next time it reaches the current location; this may be useful
3363 inside loops.
3364
3365 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
3366 least one instruction has been executed. If it did not do this, you
3367 would be unable to proceed past a breakpoint without first disabling the
3368 breakpoint. This rule applies whether or not the breakpoint already
3369 existed when your program stopped.
3370
3371 @item break @dots{} if @var{cond}
3372 Set a breakpoint with condition @var{cond}; evaluate the expression
3373 @var{cond} each time the breakpoint is reached, and stop only if the
3374 value is nonzero---that is, if @var{cond} evaluates as true.
3375 @samp{@dots{}} stands for one of the possible arguments described
3376 above (or no argument) specifying where to break. @xref{Conditions,
3377 ,Break Conditions}, for more information on breakpoint conditions.
3378
3379 @kindex tbreak
3380 @item tbreak @var{args}
3381 Set a breakpoint enabled only for one stop. @var{args} are the
3382 same as for the @code{break} command, and the breakpoint is set in the same
3383 way, but the breakpoint is automatically deleted after the first time your
3384 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
3385
3386 @kindex hbreak
3387 @cindex hardware breakpoints
3388 @item hbreak @var{args}
3389 Set a hardware-assisted breakpoint. @var{args} are the same as for the
3390 @code{break} command and the breakpoint is set in the same way, but the
3391 breakpoint requires hardware support and some target hardware may not
3392 have this support. The main purpose of this is EPROM/ROM code
3393 debugging, so you can set a breakpoint at an instruction without
3394 changing the instruction. This can be used with the new trap-generation
3395 provided by SPARClite DSU and most x86-based targets. These targets
3396 will generate traps when a program accesses some data or instruction
3397 address that is assigned to the debug registers. However the hardware
3398 breakpoint registers can take a limited number of breakpoints. For
3399 example, on the DSU, only two data breakpoints can be set at a time, and
3400 @value{GDBN} will reject this command if more than two are used. Delete
3401 or disable unused hardware breakpoints before setting new ones
3402 (@pxref{Disabling, ,Disabling Breakpoints}).
3403 @xref{Conditions, ,Break Conditions}.
3404 For remote targets, you can restrict the number of hardware
3405 breakpoints @value{GDBN} will use, see @ref{set remote
3406 hardware-breakpoint-limit}.
3407
3408 @kindex thbreak
3409 @item thbreak @var{args}
3410 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3411 are the same as for the @code{hbreak} command and the breakpoint is set in
3412 the same way. However, like the @code{tbreak} command,
3413 the breakpoint is automatically deleted after the
3414 first time your program stops there. Also, like the @code{hbreak}
3415 command, the breakpoint requires hardware support and some target hardware
3416 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3417 See also @ref{Conditions, ,Break Conditions}.
3418
3419 @kindex rbreak
3420 @cindex regular expression
3421 @cindex breakpoints at functions matching a regexp
3422 @cindex set breakpoints in many functions
3423 @item rbreak @var{regex}
3424 Set breakpoints on all functions matching the regular expression
3425 @var{regex}. This command sets an unconditional breakpoint on all
3426 matches, printing a list of all breakpoints it set. Once these
3427 breakpoints are set, they are treated just like the breakpoints set with
3428 the @code{break} command. You can delete them, disable them, or make
3429 them conditional the same way as any other breakpoint.
3430
3431 The syntax of the regular expression is the standard one used with tools
3432 like @file{grep}. Note that this is different from the syntax used by
3433 shells, so for instance @code{foo*} matches all functions that include
3434 an @code{fo} followed by zero or more @code{o}s. There is an implicit
3435 @code{.*} leading and trailing the regular expression you supply, so to
3436 match only functions that begin with @code{foo}, use @code{^foo}.
3437
3438 @cindex non-member C@t{++} functions, set breakpoint in
3439 When debugging C@t{++} programs, @code{rbreak} is useful for setting
3440 breakpoints on overloaded functions that are not members of any special
3441 classes.
3442
3443 @cindex set breakpoints on all functions
3444 The @code{rbreak} command can be used to set breakpoints in
3445 @strong{all} the functions in a program, like this:
3446
3447 @smallexample
3448 (@value{GDBP}) rbreak .
3449 @end smallexample
3450
3451 @item rbreak @var{file}:@var{regex}
3452 If @code{rbreak} is called with a filename qualification, it limits
3453 the search for functions matching the given regular expression to the
3454 specified @var{file}. This can be used, for example, to set breakpoints on
3455 every function in a given file:
3456
3457 @smallexample
3458 (@value{GDBP}) rbreak file.c:.
3459 @end smallexample
3460
3461 The colon separating the filename qualifier from the regex may
3462 optionally be surrounded by spaces.
3463
3464 @kindex info breakpoints
3465 @cindex @code{$_} and @code{info breakpoints}
3466 @item info breakpoints @r{[}@var{n}@dots{}@r{]}
3467 @itemx info break @r{[}@var{n}@dots{}@r{]}
3468 Print a table of all breakpoints, watchpoints, and catchpoints set and
3469 not deleted. Optional argument @var{n} means print information only
3470 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3471 For each breakpoint, following columns are printed:
3472
3473 @table @emph
3474 @item Breakpoint Numbers
3475 @item Type
3476 Breakpoint, watchpoint, or catchpoint.
3477 @item Disposition
3478 Whether the breakpoint is marked to be disabled or deleted when hit.
3479 @item Enabled or Disabled
3480 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
3481 that are not enabled.
3482 @item Address
3483 Where the breakpoint is in your program, as a memory address. For a
3484 pending breakpoint whose address is not yet known, this field will
3485 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3486 library that has the symbol or line referred by breakpoint is loaded.
3487 See below for details. A breakpoint with several locations will
3488 have @samp{<MULTIPLE>} in this field---see below for details.
3489 @item What
3490 Where the breakpoint is in the source for your program, as a file and
3491 line number. For a pending breakpoint, the original string passed to
3492 the breakpoint command will be listed as it cannot be resolved until
3493 the appropriate shared library is loaded in the future.
3494 @end table
3495
3496 @noindent
3497 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3498 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
3499 @value{GDBN} on the host's side. If it is ``target'', then the condition
3500 is evaluated by the target. The @code{info break} command shows
3501 the condition on the line following the affected breakpoint, together with
3502 its condition evaluation mode in between parentheses.
3503
3504 Breakpoint commands, if any, are listed after that. A pending breakpoint is
3505 allowed to have a condition specified for it. The condition is not parsed for
3506 validity until a shared library is loaded that allows the pending
3507 breakpoint to resolve to a valid location.
3508
3509 @noindent
3510 @code{info break} with a breakpoint
3511 number @var{n} as argument lists only that breakpoint. The
3512 convenience variable @code{$_} and the default examining-address for
3513 the @code{x} command are set to the address of the last breakpoint
3514 listed (@pxref{Memory, ,Examining Memory}).
3515
3516 @noindent
3517 @code{info break} displays a count of the number of times the breakpoint
3518 has been hit. This is especially useful in conjunction with the
3519 @code{ignore} command. You can ignore a large number of breakpoint
3520 hits, look at the breakpoint info to see how many times the breakpoint
3521 was hit, and then run again, ignoring one less than that number. This
3522 will get you quickly to the last hit of that breakpoint.
3523
3524 @noindent
3525 For a breakpoints with an enable count (xref) greater than 1,
3526 @code{info break} also displays that count.
3527
3528 @end table
3529
3530 @value{GDBN} allows you to set any number of breakpoints at the same place in
3531 your program. There is nothing silly or meaningless about this. When
3532 the breakpoints are conditional, this is even useful
3533 (@pxref{Conditions, ,Break Conditions}).
3534
3535 @cindex multiple locations, breakpoints
3536 @cindex breakpoints, multiple locations
3537 It is possible that a breakpoint corresponds to several locations
3538 in your program. Examples of this situation are:
3539
3540 @itemize @bullet
3541 @item
3542 Multiple functions in the program may have the same name.
3543
3544 @item
3545 For a C@t{++} constructor, the @value{NGCC} compiler generates several
3546 instances of the function body, used in different cases.
3547
3548 @item
3549 For a C@t{++} template function, a given line in the function can
3550 correspond to any number of instantiations.
3551
3552 @item
3553 For an inlined function, a given source line can correspond to
3554 several places where that function is inlined.
3555 @end itemize
3556
3557 In all those cases, @value{GDBN} will insert a breakpoint at all
3558 the relevant locations.
3559
3560 A breakpoint with multiple locations is displayed in the breakpoint
3561 table using several rows---one header row, followed by one row for
3562 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3563 address column. The rows for individual locations contain the actual
3564 addresses for locations, and show the functions to which those
3565 locations belong. The number column for a location is of the form
3566 @var{breakpoint-number}.@var{location-number}.
3567
3568 For example:
3569
3570 @smallexample
3571 Num Type Disp Enb Address What
3572 1 breakpoint keep y <MULTIPLE>
3573 stop only if i==1
3574 breakpoint already hit 1 time
3575 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
3576 1.2 y 0x080486ca in void foo<double>() at t.cc:8
3577 @end smallexample
3578
3579 Each location can be individually enabled or disabled by passing
3580 @var{breakpoint-number}.@var{location-number} as argument to the
3581 @code{enable} and @code{disable} commands. Note that you cannot
3582 delete the individual locations from the list, you can only delete the
3583 entire list of locations that belong to their parent breakpoint (with
3584 the @kbd{delete @var{num}} command, where @var{num} is the number of
3585 the parent breakpoint, 1 in the above example). Disabling or enabling
3586 the parent breakpoint (@pxref{Disabling}) affects all of the locations
3587 that belong to that breakpoint.
3588
3589 @cindex pending breakpoints
3590 It's quite common to have a breakpoint inside a shared library.
3591 Shared libraries can be loaded and unloaded explicitly,
3592 and possibly repeatedly, as the program is executed. To support
3593 this use case, @value{GDBN} updates breakpoint locations whenever
3594 any shared library is loaded or unloaded. Typically, you would
3595 set a breakpoint in a shared library at the beginning of your
3596 debugging session, when the library is not loaded, and when the
3597 symbols from the library are not available. When you try to set
3598 breakpoint, @value{GDBN} will ask you if you want to set
3599 a so called @dfn{pending breakpoint}---breakpoint whose address
3600 is not yet resolved.
3601
3602 After the program is run, whenever a new shared library is loaded,
3603 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
3604 shared library contains the symbol or line referred to by some
3605 pending breakpoint, that breakpoint is resolved and becomes an
3606 ordinary breakpoint. When a library is unloaded, all breakpoints
3607 that refer to its symbols or source lines become pending again.
3608
3609 This logic works for breakpoints with multiple locations, too. For
3610 example, if you have a breakpoint in a C@t{++} template function, and
3611 a newly loaded shared library has an instantiation of that template,
3612 a new location is added to the list of locations for the breakpoint.
3613
3614 Except for having unresolved address, pending breakpoints do not
3615 differ from regular breakpoints. You can set conditions or commands,
3616 enable and disable them and perform other breakpoint operations.
3617
3618 @value{GDBN} provides some additional commands for controlling what
3619 happens when the @samp{break} command cannot resolve breakpoint
3620 address specification to an address:
3621
3622 @kindex set breakpoint pending
3623 @kindex show breakpoint pending
3624 @table @code
3625 @item set breakpoint pending auto
3626 This is the default behavior. When @value{GDBN} cannot find the breakpoint
3627 location, it queries you whether a pending breakpoint should be created.
3628
3629 @item set breakpoint pending on
3630 This indicates that an unrecognized breakpoint location should automatically
3631 result in a pending breakpoint being created.
3632
3633 @item set breakpoint pending off
3634 This indicates that pending breakpoints are not to be created. Any
3635 unrecognized breakpoint location results in an error. This setting does
3636 not affect any pending breakpoints previously created.
3637
3638 @item show breakpoint pending
3639 Show the current behavior setting for creating pending breakpoints.
3640 @end table
3641
3642 The settings above only affect the @code{break} command and its
3643 variants. Once breakpoint is set, it will be automatically updated
3644 as shared libraries are loaded and unloaded.
3645
3646 @cindex automatic hardware breakpoints
3647 For some targets, @value{GDBN} can automatically decide if hardware or
3648 software breakpoints should be used, depending on whether the
3649 breakpoint address is read-only or read-write. This applies to
3650 breakpoints set with the @code{break} command as well as to internal
3651 breakpoints set by commands like @code{next} and @code{finish}. For
3652 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3653 breakpoints.
3654
3655 You can control this automatic behaviour with the following commands::
3656
3657 @kindex set breakpoint auto-hw
3658 @kindex show breakpoint auto-hw
3659 @table @code
3660 @item set breakpoint auto-hw on
3661 This is the default behavior. When @value{GDBN} sets a breakpoint, it
3662 will try to use the target memory map to decide if software or hardware
3663 breakpoint must be used.
3664
3665 @item set breakpoint auto-hw off
3666 This indicates @value{GDBN} should not automatically select breakpoint
3667 type. If the target provides a memory map, @value{GDBN} will warn when
3668 trying to set software breakpoint at a read-only address.
3669 @end table
3670
3671 @value{GDBN} normally implements breakpoints by replacing the program code
3672 at the breakpoint address with a special instruction, which, when
3673 executed, given control to the debugger. By default, the program
3674 code is so modified only when the program is resumed. As soon as
3675 the program stops, @value{GDBN} restores the original instructions. This
3676 behaviour guards against leaving breakpoints inserted in the
3677 target should gdb abrubptly disconnect. However, with slow remote
3678 targets, inserting and removing breakpoint can reduce the performance.
3679 This behavior can be controlled with the following commands::
3680
3681 @kindex set breakpoint always-inserted
3682 @kindex show breakpoint always-inserted
3683 @table @code
3684 @item set breakpoint always-inserted off
3685 All breakpoints, including newly added by the user, are inserted in
3686 the target only when the target is resumed. All breakpoints are
3687 removed from the target when it stops.
3688
3689 @item set breakpoint always-inserted on
3690 Causes all breakpoints to be inserted in the target at all times. If
3691 the user adds a new breakpoint, or changes an existing breakpoint, the
3692 breakpoints in the target are updated immediately. A breakpoint is
3693 removed from the target only when breakpoint itself is removed.
3694
3695 @cindex non-stop mode, and @code{breakpoint always-inserted}
3696 @item set breakpoint always-inserted auto
3697 This is the default mode. If @value{GDBN} is controlling the inferior
3698 in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3699 @code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3700 controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3701 @code{breakpoint always-inserted} mode is off.
3702 @end table
3703
3704 @value{GDBN} handles conditional breakpoints by evaluating these conditions
3705 when a breakpoint breaks. If the condition is true, then the process being
3706 debugged stops, otherwise the process is resumed.
3707
3708 If the target supports evaluating conditions on its end, @value{GDBN} may
3709 download the breakpoint, together with its conditions, to it.
3710
3711 This feature can be controlled via the following commands:
3712
3713 @kindex set breakpoint condition-evaluation
3714 @kindex show breakpoint condition-evaluation
3715 @table @code
3716 @item set breakpoint condition-evaluation host
3717 This option commands @value{GDBN} to evaluate the breakpoint
3718 conditions on the host's side. Unconditional breakpoints are sent to
3719 the target which in turn receives the triggers and reports them back to GDB
3720 for condition evaluation. This is the standard evaluation mode.
3721
3722 @item set breakpoint condition-evaluation target
3723 This option commands @value{GDBN} to download breakpoint conditions
3724 to the target at the moment of their insertion. The target
3725 is responsible for evaluating the conditional expression and reporting
3726 breakpoint stop events back to @value{GDBN} whenever the condition
3727 is true. Due to limitations of target-side evaluation, some conditions
3728 cannot be evaluated there, e.g., conditions that depend on local data
3729 that is only known to the host. Examples include
3730 conditional expressions involving convenience variables, complex types
3731 that cannot be handled by the agent expression parser and expressions
3732 that are too long to be sent over to the target, specially when the
3733 target is a remote system. In these cases, the conditions will be
3734 evaluated by @value{GDBN}.
3735
3736 @item set breakpoint condition-evaluation auto
3737 This is the default mode. If the target supports evaluating breakpoint
3738 conditions on its end, @value{GDBN} will download breakpoint conditions to
3739 the target (limitations mentioned previously apply). If the target does
3740 not support breakpoint condition evaluation, then @value{GDBN} will fallback
3741 to evaluating all these conditions on the host's side.
3742 @end table
3743
3744
3745 @cindex negative breakpoint numbers
3746 @cindex internal @value{GDBN} breakpoints
3747 @value{GDBN} itself sometimes sets breakpoints in your program for
3748 special purposes, such as proper handling of @code{longjmp} (in C
3749 programs). These internal breakpoints are assigned negative numbers,
3750 starting with @code{-1}; @samp{info breakpoints} does not display them.
3751 You can see these breakpoints with the @value{GDBN} maintenance command
3752 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3753
3754
3755 @node Set Watchpoints
3756 @subsection Setting Watchpoints
3757
3758 @cindex setting watchpoints
3759 You can use a watchpoint to stop execution whenever the value of an
3760 expression changes, without having to predict a particular place where
3761 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3762 The expression may be as simple as the value of a single variable, or
3763 as complex as many variables combined by operators. Examples include:
3764
3765 @itemize @bullet
3766 @item
3767 A reference to the value of a single variable.
3768
3769 @item
3770 An address cast to an appropriate data type. For example,
3771 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3772 address (assuming an @code{int} occupies 4 bytes).
3773
3774 @item
3775 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3776 expression can use any operators valid in the program's native
3777 language (@pxref{Languages}).
3778 @end itemize
3779
3780 You can set a watchpoint on an expression even if the expression can
3781 not be evaluated yet. For instance, you can set a watchpoint on
3782 @samp{*global_ptr} before @samp{global_ptr} is initialized.
3783 @value{GDBN} will stop when your program sets @samp{global_ptr} and
3784 the expression produces a valid value. If the expression becomes
3785 valid in some other way than changing a variable (e.g.@: if the memory
3786 pointed to by @samp{*global_ptr} becomes readable as the result of a
3787 @code{malloc} call), @value{GDBN} may not stop until the next time
3788 the expression changes.
3789
3790 @cindex software watchpoints
3791 @cindex hardware watchpoints
3792 Depending on your system, watchpoints may be implemented in software or
3793 hardware. @value{GDBN} does software watchpointing by single-stepping your
3794 program and testing the variable's value each time, which is hundreds of
3795 times slower than normal execution. (But this may still be worth it, to
3796 catch errors where you have no clue what part of your program is the
3797 culprit.)
3798
3799 On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3800 x86-based targets, @value{GDBN} includes support for hardware
3801 watchpoints, which do not slow down the running of your program.
3802
3803 @table @code
3804 @kindex watch
3805 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3806 Set a watchpoint for an expression. @value{GDBN} will break when the
3807 expression @var{expr} is written into by the program and its value
3808 changes. The simplest (and the most popular) use of this command is
3809 to watch the value of a single variable:
3810
3811 @smallexample
3812 (@value{GDBP}) watch foo
3813 @end smallexample
3814
3815 If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3816 argument, @value{GDBN} breaks only when the thread identified by
3817 @var{threadnum} changes the value of @var{expr}. If any other threads
3818 change the value of @var{expr}, @value{GDBN} will not break. Note
3819 that watchpoints restricted to a single thread in this way only work
3820 with Hardware Watchpoints.
3821
3822 Ordinarily a watchpoint respects the scope of variables in @var{expr}
3823 (see below). The @code{-location} argument tells @value{GDBN} to
3824 instead watch the memory referred to by @var{expr}. In this case,
3825 @value{GDBN} will evaluate @var{expr}, take the address of the result,
3826 and watch the memory at that address. The type of the result is used
3827 to determine the size of the watched memory. If the expression's
3828 result does not have an address, then @value{GDBN} will print an
3829 error.
3830
3831 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3832 of masked watchpoints, if the current architecture supports this
3833 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3834 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
3835 to an address to watch. The mask specifies that some bits of an address
3836 (the bits which are reset in the mask) should be ignored when matching
3837 the address accessed by the inferior against the watchpoint address.
3838 Thus, a masked watchpoint watches many addresses simultaneously---those
3839 addresses whose unmasked bits are identical to the unmasked bits in the
3840 watchpoint address. The @code{mask} argument implies @code{-location}.
3841 Examples:
3842
3843 @smallexample
3844 (@value{GDBP}) watch foo mask 0xffff00ff
3845 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
3846 @end smallexample
3847
3848 @kindex rwatch
3849 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3850 Set a watchpoint that will break when the value of @var{expr} is read
3851 by the program.
3852
3853 @kindex awatch
3854 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3855 Set a watchpoint that will break when @var{expr} is either read from
3856 or written into by the program.
3857
3858 @kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
3859 @item info watchpoints @r{[}@var{n}@dots{}@r{]}
3860 This command prints a list of watchpoints, using the same format as
3861 @code{info break} (@pxref{Set Breaks}).
3862 @end table
3863
3864 If you watch for a change in a numerically entered address you need to
3865 dereference it, as the address itself is just a constant number which will
3866 never change. @value{GDBN} refuses to create a watchpoint that watches
3867 a never-changing value:
3868
3869 @smallexample
3870 (@value{GDBP}) watch 0x600850
3871 Cannot watch constant value 0x600850.
3872 (@value{GDBP}) watch *(int *) 0x600850
3873 Watchpoint 1: *(int *) 6293584
3874 @end smallexample
3875
3876 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3877 watchpoints execute very quickly, and the debugger reports a change in
3878 value at the exact instruction where the change occurs. If @value{GDBN}
3879 cannot set a hardware watchpoint, it sets a software watchpoint, which
3880 executes more slowly and reports the change in value at the next
3881 @emph{statement}, not the instruction, after the change occurs.
3882
3883 @cindex use only software watchpoints
3884 You can force @value{GDBN} to use only software watchpoints with the
3885 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3886 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3887 the underlying system supports them. (Note that hardware-assisted
3888 watchpoints that were set @emph{before} setting
3889 @code{can-use-hw-watchpoints} to zero will still use the hardware
3890 mechanism of watching expression values.)
3891
3892 @table @code
3893 @item set can-use-hw-watchpoints
3894 @kindex set can-use-hw-watchpoints
3895 Set whether or not to use hardware watchpoints.
3896
3897 @item show can-use-hw-watchpoints
3898 @kindex show can-use-hw-watchpoints
3899 Show the current mode of using hardware watchpoints.
3900 @end table
3901
3902 For remote targets, you can restrict the number of hardware
3903 watchpoints @value{GDBN} will use, see @ref{set remote
3904 hardware-breakpoint-limit}.
3905
3906 When you issue the @code{watch} command, @value{GDBN} reports
3907
3908 @smallexample
3909 Hardware watchpoint @var{num}: @var{expr}
3910 @end smallexample
3911
3912 @noindent
3913 if it was able to set a hardware watchpoint.
3914
3915 Currently, the @code{awatch} and @code{rwatch} commands can only set
3916 hardware watchpoints, because accesses to data that don't change the
3917 value of the watched expression cannot be detected without examining
3918 every instruction as it is being executed, and @value{GDBN} does not do
3919 that currently. If @value{GDBN} finds that it is unable to set a
3920 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3921 will print a message like this:
3922
3923 @smallexample
3924 Expression cannot be implemented with read/access watchpoint.
3925 @end smallexample
3926
3927 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3928 data type of the watched expression is wider than what a hardware
3929 watchpoint on the target machine can handle. For example, some systems
3930 can only watch regions that are up to 4 bytes wide; on such systems you
3931 cannot set hardware watchpoints for an expression that yields a
3932 double-precision floating-point number (which is typically 8 bytes
3933 wide). As a work-around, it might be possible to break the large region
3934 into a series of smaller ones and watch them with separate watchpoints.
3935
3936 If you set too many hardware watchpoints, @value{GDBN} might be unable
3937 to insert all of them when you resume the execution of your program.
3938 Since the precise number of active watchpoints is unknown until such
3939 time as the program is about to be resumed, @value{GDBN} might not be
3940 able to warn you about this when you set the watchpoints, and the
3941 warning will be printed only when the program is resumed:
3942
3943 @smallexample
3944 Hardware watchpoint @var{num}: Could not insert watchpoint
3945 @end smallexample
3946
3947 @noindent
3948 If this happens, delete or disable some of the watchpoints.
3949
3950 Watching complex expressions that reference many variables can also
3951 exhaust the resources available for hardware-assisted watchpoints.
3952 That's because @value{GDBN} needs to watch every variable in the
3953 expression with separately allocated resources.
3954
3955 If you call a function interactively using @code{print} or @code{call},
3956 any watchpoints you have set will be inactive until @value{GDBN} reaches another
3957 kind of breakpoint or the call completes.
3958
3959 @value{GDBN} automatically deletes watchpoints that watch local
3960 (automatic) variables, or expressions that involve such variables, when
3961 they go out of scope, that is, when the execution leaves the block in
3962 which these variables were defined. In particular, when the program
3963 being debugged terminates, @emph{all} local variables go out of scope,
3964 and so only watchpoints that watch global variables remain set. If you
3965 rerun the program, you will need to set all such watchpoints again. One
3966 way of doing that would be to set a code breakpoint at the entry to the
3967 @code{main} function and when it breaks, set all the watchpoints.
3968
3969 @cindex watchpoints and threads
3970 @cindex threads and watchpoints
3971 In multi-threaded programs, watchpoints will detect changes to the
3972 watched expression from every thread.
3973
3974 @quotation
3975 @emph{Warning:} In multi-threaded programs, software watchpoints
3976 have only limited usefulness. If @value{GDBN} creates a software
3977 watchpoint, it can only watch the value of an expression @emph{in a
3978 single thread}. If you are confident that the expression can only
3979 change due to the current thread's activity (and if you are also
3980 confident that no other thread can become current), then you can use
3981 software watchpoints as usual. However, @value{GDBN} may not notice
3982 when a non-current thread's activity changes the expression. (Hardware
3983 watchpoints, in contrast, watch an expression in all threads.)
3984 @end quotation
3985
3986 @xref{set remote hardware-watchpoint-limit}.
3987
3988 @node Set Catchpoints
3989 @subsection Setting Catchpoints
3990 @cindex catchpoints, setting
3991 @cindex exception handlers
3992 @cindex event handling
3993
3994 You can use @dfn{catchpoints} to cause the debugger to stop for certain
3995 kinds of program events, such as C@t{++} exceptions or the loading of a
3996 shared library. Use the @code{catch} command to set a catchpoint.
3997
3998 @table @code
3999 @kindex catch
4000 @item catch @var{event}
4001 Stop when @var{event} occurs. @var{event} can be any of the following:
4002 @table @code
4003 @item throw
4004 @cindex stop on C@t{++} exceptions
4005 The throwing of a C@t{++} exception.
4006
4007 @item catch
4008 The catching of a C@t{++} exception.
4009
4010 @item exception
4011 @cindex Ada exception catching
4012 @cindex catch Ada exceptions
4013 An Ada exception being raised. If an exception name is specified
4014 at the end of the command (eg @code{catch exception Program_Error}),
4015 the debugger will stop only when this specific exception is raised.
4016 Otherwise, the debugger stops execution when any Ada exception is raised.
4017
4018 When inserting an exception catchpoint on a user-defined exception whose
4019 name is identical to one of the exceptions defined by the language, the
4020 fully qualified name must be used as the exception name. Otherwise,
4021 @value{GDBN} will assume that it should stop on the pre-defined exception
4022 rather than the user-defined one. For instance, assuming an exception
4023 called @code{Constraint_Error} is defined in package @code{Pck}, then
4024 the command to use to catch such exceptions is @kbd{catch exception
4025 Pck.Constraint_Error}.
4026
4027 @item exception unhandled
4028 An exception that was raised but is not handled by the program.
4029
4030 @item assert
4031 A failed Ada assertion.
4032
4033 @item exec
4034 @cindex break on fork/exec
4035 A call to @code{exec}. This is currently only available for HP-UX
4036 and @sc{gnu}/Linux.
4037
4038 @item syscall
4039 @itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
4040 @cindex break on a system call.
4041 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4042 syscall is a mechanism for application programs to request a service
4043 from the operating system (OS) or one of the OS system services.
4044 @value{GDBN} can catch some or all of the syscalls issued by the
4045 debuggee, and show the related information for each syscall. If no
4046 argument is specified, calls to and returns from all system calls
4047 will be caught.
4048
4049 @var{name} can be any system call name that is valid for the
4050 underlying OS. Just what syscalls are valid depends on the OS. On
4051 GNU and Unix systems, you can find the full list of valid syscall
4052 names on @file{/usr/include/asm/unistd.h}.
4053
4054 @c For MS-Windows, the syscall names and the corresponding numbers
4055 @c can be found, e.g., on this URL:
4056 @c http://www.metasploit.com/users/opcode/syscalls.html
4057 @c but we don't support Windows syscalls yet.
4058
4059 Normally, @value{GDBN} knows in advance which syscalls are valid for
4060 each OS, so you can use the @value{GDBN} command-line completion
4061 facilities (@pxref{Completion,, command completion}) to list the
4062 available choices.
4063
4064 You may also specify the system call numerically. A syscall's
4065 number is the value passed to the OS's syscall dispatcher to
4066 identify the requested service. When you specify the syscall by its
4067 name, @value{GDBN} uses its database of syscalls to convert the name
4068 into the corresponding numeric code, but using the number directly
4069 may be useful if @value{GDBN}'s database does not have the complete
4070 list of syscalls on your system (e.g., because @value{GDBN} lags
4071 behind the OS upgrades).
4072
4073 The example below illustrates how this command works if you don't provide
4074 arguments to it:
4075
4076 @smallexample
4077 (@value{GDBP}) catch syscall
4078 Catchpoint 1 (syscall)
4079 (@value{GDBP}) r
4080 Starting program: /tmp/catch-syscall
4081
4082 Catchpoint 1 (call to syscall 'close'), \
4083 0xffffe424 in __kernel_vsyscall ()
4084 (@value{GDBP}) c
4085 Continuing.
4086
4087 Catchpoint 1 (returned from syscall 'close'), \
4088 0xffffe424 in __kernel_vsyscall ()
4089 (@value{GDBP})
4090 @end smallexample
4091
4092 Here is an example of catching a system call by name:
4093
4094 @smallexample
4095 (@value{GDBP}) catch syscall chroot
4096 Catchpoint 1 (syscall 'chroot' [61])
4097 (@value{GDBP}) r
4098 Starting program: /tmp/catch-syscall
4099
4100 Catchpoint 1 (call to syscall 'chroot'), \
4101 0xffffe424 in __kernel_vsyscall ()
4102 (@value{GDBP}) c
4103 Continuing.
4104
4105 Catchpoint 1 (returned from syscall 'chroot'), \
4106 0xffffe424 in __kernel_vsyscall ()
4107 (@value{GDBP})
4108 @end smallexample
4109
4110 An example of specifying a system call numerically. In the case
4111 below, the syscall number has a corresponding entry in the XML
4112 file, so @value{GDBN} finds its name and prints it:
4113
4114 @smallexample
4115 (@value{GDBP}) catch syscall 252
4116 Catchpoint 1 (syscall(s) 'exit_group')
4117 (@value{GDBP}) r
4118 Starting program: /tmp/catch-syscall
4119
4120 Catchpoint 1 (call to syscall 'exit_group'), \
4121 0xffffe424 in __kernel_vsyscall ()
4122 (@value{GDBP}) c
4123 Continuing.
4124
4125 Program exited normally.
4126 (@value{GDBP})
4127 @end smallexample
4128
4129 However, there can be situations when there is no corresponding name
4130 in XML file for that syscall number. In this case, @value{GDBN} prints
4131 a warning message saying that it was not able to find the syscall name,
4132 but the catchpoint will be set anyway. See the example below:
4133
4134 @smallexample
4135 (@value{GDBP}) catch syscall 764
4136 warning: The number '764' does not represent a known syscall.
4137 Catchpoint 2 (syscall 764)
4138 (@value{GDBP})
4139 @end smallexample
4140
4141 If you configure @value{GDBN} using the @samp{--without-expat} option,
4142 it will not be able to display syscall names. Also, if your
4143 architecture does not have an XML file describing its system calls,
4144 you will not be able to see the syscall names. It is important to
4145 notice that these two features are used for accessing the syscall
4146 name database. In either case, you will see a warning like this:
4147
4148 @smallexample
4149 (@value{GDBP}) catch syscall
4150 warning: Could not open "syscalls/i386-linux.xml"
4151 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4152 GDB will not be able to display syscall names.
4153 Catchpoint 1 (syscall)
4154 (@value{GDBP})
4155 @end smallexample
4156
4157 Of course, the file name will change depending on your architecture and system.
4158
4159 Still using the example above, you can also try to catch a syscall by its
4160 number. In this case, you would see something like:
4161
4162 @smallexample
4163 (@value{GDBP}) catch syscall 252
4164 Catchpoint 1 (syscall(s) 252)
4165 @end smallexample
4166
4167 Again, in this case @value{GDBN} would not be able to display syscall's names.
4168
4169 @item fork
4170 A call to @code{fork}. This is currently only available for HP-UX
4171 and @sc{gnu}/Linux.
4172
4173 @item vfork
4174 A call to @code{vfork}. This is currently only available for HP-UX
4175 and @sc{gnu}/Linux.
4176
4177 @item load @r{[}regexp@r{]}
4178 @itemx unload @r{[}regexp@r{]}
4179 The loading or unloading of a shared library. If @var{regexp} is
4180 given, then the catchpoint will stop only if the regular expression
4181 matches one of the affected libraries.
4182
4183 @end table
4184
4185 @item tcatch @var{event}
4186 Set a catchpoint that is enabled only for one stop. The catchpoint is
4187 automatically deleted after the first time the event is caught.
4188
4189 @end table
4190
4191 Use the @code{info break} command to list the current catchpoints.
4192
4193 There are currently some limitations to C@t{++} exception handling
4194 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4195
4196 @itemize @bullet
4197 @item
4198 If you call a function interactively, @value{GDBN} normally returns
4199 control to you when the function has finished executing. If the call
4200 raises an exception, however, the call may bypass the mechanism that
4201 returns control to you and cause your program either to abort or to
4202 simply continue running until it hits a breakpoint, catches a signal
4203 that @value{GDBN} is listening for, or exits. This is the case even if
4204 you set a catchpoint for the exception; catchpoints on exceptions are
4205 disabled within interactive calls.
4206
4207 @item
4208 You cannot raise an exception interactively.
4209
4210 @item
4211 You cannot install an exception handler interactively.
4212 @end itemize
4213
4214 @cindex raise exceptions
4215 Sometimes @code{catch} is not the best way to debug exception handling:
4216 if you need to know exactly where an exception is raised, it is better to
4217 stop @emph{before} the exception handler is called, since that way you
4218 can see the stack before any unwinding takes place. If you set a
4219 breakpoint in an exception handler instead, it may not be easy to find
4220 out where the exception was raised.
4221
4222 To stop just before an exception handler is called, you need some
4223 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
4224 raised by calling a library function named @code{__raise_exception}
4225 which has the following ANSI C interface:
4226
4227 @smallexample
4228 /* @var{addr} is where the exception identifier is stored.
4229 @var{id} is the exception identifier. */
4230 void __raise_exception (void **addr, void *id);
4231 @end smallexample
4232
4233 @noindent
4234 To make the debugger catch all exceptions before any stack
4235 unwinding takes place, set a breakpoint on @code{__raise_exception}
4236 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
4237
4238 With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
4239 that depends on the value of @var{id}, you can stop your program when
4240 a specific exception is raised. You can use multiple conditional
4241 breakpoints to stop your program when any of a number of exceptions are
4242 raised.
4243
4244
4245 @node Delete Breaks
4246 @subsection Deleting Breakpoints
4247
4248 @cindex clearing breakpoints, watchpoints, catchpoints
4249 @cindex deleting breakpoints, watchpoints, catchpoints
4250 It is often necessary to eliminate a breakpoint, watchpoint, or
4251 catchpoint once it has done its job and you no longer want your program
4252 to stop there. This is called @dfn{deleting} the breakpoint. A
4253 breakpoint that has been deleted no longer exists; it is forgotten.
4254
4255 With the @code{clear} command you can delete breakpoints according to
4256 where they are in your program. With the @code{delete} command you can
4257 delete individual breakpoints, watchpoints, or catchpoints by specifying
4258 their breakpoint numbers.
4259
4260 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4261 automatically ignores breakpoints on the first instruction to be executed
4262 when you continue execution without changing the execution address.
4263
4264 @table @code
4265 @kindex clear
4266 @item clear
4267 Delete any breakpoints at the next instruction to be executed in the
4268 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
4269 the innermost frame is selected, this is a good way to delete a
4270 breakpoint where your program just stopped.
4271
4272 @item clear @var{location}
4273 Delete any breakpoints set at the specified @var{location}.
4274 @xref{Specify Location}, for the various forms of @var{location}; the
4275 most useful ones are listed below:
4276
4277 @table @code
4278 @item clear @var{function}
4279 @itemx clear @var{filename}:@var{function}
4280 Delete any breakpoints set at entry to the named @var{function}.
4281
4282 @item clear @var{linenum}
4283 @itemx clear @var{filename}:@var{linenum}
4284 Delete any breakpoints set at or within the code of the specified
4285 @var{linenum} of the specified @var{filename}.
4286 @end table
4287
4288 @cindex delete breakpoints
4289 @kindex delete
4290 @kindex d @r{(@code{delete})}
4291 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4292 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4293 ranges specified as arguments. If no argument is specified, delete all
4294 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4295 confirm off}). You can abbreviate this command as @code{d}.
4296 @end table
4297
4298 @node Disabling
4299 @subsection Disabling Breakpoints
4300
4301 @cindex enable/disable a breakpoint
4302 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4303 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4304 it had been deleted, but remembers the information on the breakpoint so
4305 that you can @dfn{enable} it again later.
4306
4307 You disable and enable breakpoints, watchpoints, and catchpoints with
4308 the @code{enable} and @code{disable} commands, optionally specifying
4309 one or more breakpoint numbers as arguments. Use @code{info break} to
4310 print a list of all breakpoints, watchpoints, and catchpoints if you
4311 do not know which numbers to use.
4312
4313 Disabling and enabling a breakpoint that has multiple locations
4314 affects all of its locations.
4315
4316 A breakpoint, watchpoint, or catchpoint can have any of several
4317 different states of enablement:
4318
4319 @itemize @bullet
4320 @item
4321 Enabled. The breakpoint stops your program. A breakpoint set
4322 with the @code{break} command starts out in this state.
4323 @item
4324 Disabled. The breakpoint has no effect on your program.
4325 @item
4326 Enabled once. The breakpoint stops your program, but then becomes
4327 disabled.
4328 @item
4329 Enabled for a count. The breakpoint stops your program for the next
4330 N times, then becomes disabled.
4331 @item
4332 Enabled for deletion. The breakpoint stops your program, but
4333 immediately after it does so it is deleted permanently. A breakpoint
4334 set with the @code{tbreak} command starts out in this state.
4335 @end itemize
4336
4337 You can use the following commands to enable or disable breakpoints,
4338 watchpoints, and catchpoints:
4339
4340 @table @code
4341 @kindex disable
4342 @kindex dis @r{(@code{disable})}
4343 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4344 Disable the specified breakpoints---or all breakpoints, if none are
4345 listed. A disabled breakpoint has no effect but is not forgotten. All
4346 options such as ignore-counts, conditions and commands are remembered in
4347 case the breakpoint is enabled again later. You may abbreviate
4348 @code{disable} as @code{dis}.
4349
4350 @kindex enable
4351 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4352 Enable the specified breakpoints (or all defined breakpoints). They
4353 become effective once again in stopping your program.
4354
4355 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
4356 Enable the specified breakpoints temporarily. @value{GDBN} disables any
4357 of these breakpoints immediately after stopping your program.
4358
4359 @item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4360 Enable the specified breakpoints temporarily. @value{GDBN} records
4361 @var{count} with each of the specified breakpoints, and decrements a
4362 breakpoint's count when it is hit. When any count reaches 0,
4363 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4364 count (@pxref{Conditions, ,Break Conditions}), that will be
4365 decremented to 0 before @var{count} is affected.
4366
4367 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
4368 Enable the specified breakpoints to work once, then die. @value{GDBN}
4369 deletes any of these breakpoints as soon as your program stops there.
4370 Breakpoints set by the @code{tbreak} command start out in this state.
4371 @end table
4372
4373 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4374 @c confusing: tbreak is also initially enabled.
4375 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
4376 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
4377 subsequently, they become disabled or enabled only when you use one of
4378 the commands above. (The command @code{until} can set and delete a
4379 breakpoint of its own, but it does not change the state of your other
4380 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
4381 Stepping}.)
4382
4383 @node Conditions
4384 @subsection Break Conditions
4385 @cindex conditional breakpoints
4386 @cindex breakpoint conditions
4387
4388 @c FIXME what is scope of break condition expr? Context where wanted?
4389 @c in particular for a watchpoint?
4390 The simplest sort of breakpoint breaks every time your program reaches a
4391 specified place. You can also specify a @dfn{condition} for a
4392 breakpoint. A condition is just a Boolean expression in your
4393 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4394 a condition evaluates the expression each time your program reaches it,
4395 and your program stops only if the condition is @emph{true}.
4396
4397 This is the converse of using assertions for program validation; in that
4398 situation, you want to stop when the assertion is violated---that is,
4399 when the condition is false. In C, if you want to test an assertion expressed
4400 by the condition @var{assert}, you should set the condition
4401 @samp{! @var{assert}} on the appropriate breakpoint.
4402
4403 Conditions are also accepted for watchpoints; you may not need them,
4404 since a watchpoint is inspecting the value of an expression anyhow---but
4405 it might be simpler, say, to just set a watchpoint on a variable name,
4406 and specify a condition that tests whether the new value is an interesting
4407 one.
4408
4409 Break conditions can have side effects, and may even call functions in
4410 your program. This can be useful, for example, to activate functions
4411 that log program progress, or to use your own print functions to
4412 format special data structures. The effects are completely predictable
4413 unless there is another enabled breakpoint at the same address. (In
4414 that case, @value{GDBN} might see the other breakpoint first and stop your
4415 program without checking the condition of this one.) Note that
4416 breakpoint commands are usually more convenient and flexible than break
4417 conditions for the
4418 purpose of performing side effects when a breakpoint is reached
4419 (@pxref{Break Commands, ,Breakpoint Command Lists}).
4420
4421 Breakpoint conditions can also be evaluated on the target's side if
4422 the target supports it. Instead of evaluating the conditions locally,
4423 @value{GDBN} encodes the expression into an agent expression
4424 (@pxref{Agent Expressions}) suitable for execution on the target,
4425 independently of @value{GDBN}. Global variables become raw memory
4426 locations, locals become stack accesses, and so forth.
4427
4428 In this case, @value{GDBN} will only be notified of a breakpoint trigger
4429 when its condition evaluates to true. This mechanism may provide faster
4430 response times depending on the performance characteristics of the target
4431 since it does not need to keep @value{GDBN} informed about
4432 every breakpoint trigger, even those with false conditions.
4433
4434 Break conditions can be specified when a breakpoint is set, by using
4435 @samp{if} in the arguments to the @code{break} command. @xref{Set
4436 Breaks, ,Setting Breakpoints}. They can also be changed at any time
4437 with the @code{condition} command.
4438
4439 You can also use the @code{if} keyword with the @code{watch} command.
4440 The @code{catch} command does not recognize the @code{if} keyword;
4441 @code{condition} is the only way to impose a further condition on a
4442 catchpoint.
4443
4444 @table @code
4445 @kindex condition
4446 @item condition @var{bnum} @var{expression}
4447 Specify @var{expression} as the break condition for breakpoint,
4448 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4449 breakpoint @var{bnum} stops your program only if the value of
4450 @var{expression} is true (nonzero, in C). When you use
4451 @code{condition}, @value{GDBN} checks @var{expression} immediately for
4452 syntactic correctness, and to determine whether symbols in it have
4453 referents in the context of your breakpoint. If @var{expression} uses
4454 symbols not referenced in the context of the breakpoint, @value{GDBN}
4455 prints an error message:
4456
4457 @smallexample
4458 No symbol "foo" in current context.
4459 @end smallexample
4460
4461 @noindent
4462 @value{GDBN} does
4463 not actually evaluate @var{expression} at the time the @code{condition}
4464 command (or a command that sets a breakpoint with a condition, like
4465 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
4466
4467 @item condition @var{bnum}
4468 Remove the condition from breakpoint number @var{bnum}. It becomes
4469 an ordinary unconditional breakpoint.
4470 @end table
4471
4472 @cindex ignore count (of breakpoint)
4473 A special case of a breakpoint condition is to stop only when the
4474 breakpoint has been reached a certain number of times. This is so
4475 useful that there is a special way to do it, using the @dfn{ignore
4476 count} of the breakpoint. Every breakpoint has an ignore count, which
4477 is an integer. Most of the time, the ignore count is zero, and
4478 therefore has no effect. But if your program reaches a breakpoint whose
4479 ignore count is positive, then instead of stopping, it just decrements
4480 the ignore count by one and continues. As a result, if the ignore count
4481 value is @var{n}, the breakpoint does not stop the next @var{n} times
4482 your program reaches it.
4483
4484 @table @code
4485 @kindex ignore
4486 @item ignore @var{bnum} @var{count}
4487 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4488 The next @var{count} times the breakpoint is reached, your program's
4489 execution does not stop; other than to decrement the ignore count, @value{GDBN}
4490 takes no action.
4491
4492 To make the breakpoint stop the next time it is reached, specify
4493 a count of zero.
4494
4495 When you use @code{continue} to resume execution of your program from a
4496 breakpoint, you can specify an ignore count directly as an argument to
4497 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
4498 Stepping,,Continuing and Stepping}.
4499
4500 If a breakpoint has a positive ignore count and a condition, the
4501 condition is not checked. Once the ignore count reaches zero,
4502 @value{GDBN} resumes checking the condition.
4503
4504 You could achieve the effect of the ignore count with a condition such
4505 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4506 is decremented each time. @xref{Convenience Vars, ,Convenience
4507 Variables}.
4508 @end table
4509
4510 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4511
4512
4513 @node Break Commands
4514 @subsection Breakpoint Command Lists
4515
4516 @cindex breakpoint commands
4517 You can give any breakpoint (or watchpoint or catchpoint) a series of
4518 commands to execute when your program stops due to that breakpoint. For
4519 example, you might want to print the values of certain expressions, or
4520 enable other breakpoints.
4521
4522 @table @code
4523 @kindex commands
4524 @kindex end@r{ (breakpoint commands)}
4525 @item commands @r{[}@var{range}@dots{}@r{]}
4526 @itemx @dots{} @var{command-list} @dots{}
4527 @itemx end
4528 Specify a list of commands for the given breakpoints. The commands
4529 themselves appear on the following lines. Type a line containing just
4530 @code{end} to terminate the commands.
4531
4532 To remove all commands from a breakpoint, type @code{commands} and
4533 follow it immediately with @code{end}; that is, give no commands.
4534
4535 With no argument, @code{commands} refers to the last breakpoint,
4536 watchpoint, or catchpoint set (not to the breakpoint most recently
4537 encountered). If the most recent breakpoints were set with a single
4538 command, then the @code{commands} will apply to all the breakpoints
4539 set by that command. This applies to breakpoints set by
4540 @code{rbreak}, and also applies when a single @code{break} command
4541 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4542 Expressions}).
4543 @end table
4544
4545 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4546 disabled within a @var{command-list}.
4547
4548 You can use breakpoint commands to start your program up again. Simply
4549 use the @code{continue} command, or @code{step}, or any other command
4550 that resumes execution.
4551
4552 Any other commands in the command list, after a command that resumes
4553 execution, are ignored. This is because any time you resume execution
4554 (even with a simple @code{next} or @code{step}), you may encounter
4555 another breakpoint---which could have its own command list, leading to
4556 ambiguities about which list to execute.
4557
4558 @kindex silent
4559 If the first command you specify in a command list is @code{silent}, the
4560 usual message about stopping at a breakpoint is not printed. This may
4561 be desirable for breakpoints that are to print a specific message and
4562 then continue. If none of the remaining commands print anything, you
4563 see no sign that the breakpoint was reached. @code{silent} is
4564 meaningful only at the beginning of a breakpoint command list.
4565
4566 The commands @code{echo}, @code{output}, and @code{printf} allow you to
4567 print precisely controlled output, and are often useful in silent
4568 breakpoints. @xref{Output, ,Commands for Controlled Output}.
4569
4570 For example, here is how you could use breakpoint commands to print the
4571 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4572
4573 @smallexample
4574 break foo if x>0
4575 commands
4576 silent
4577 printf "x is %d\n",x
4578 cont
4579 end
4580 @end smallexample
4581
4582 One application for breakpoint commands is to compensate for one bug so
4583 you can test for another. Put a breakpoint just after the erroneous line
4584 of code, give it a condition to detect the case in which something
4585 erroneous has been done, and give it commands to assign correct values
4586 to any variables that need them. End with the @code{continue} command
4587 so that your program does not stop, and start with the @code{silent}
4588 command so that no output is produced. Here is an example:
4589
4590 @smallexample
4591 break 403
4592 commands
4593 silent
4594 set x = y + 4
4595 cont
4596 end
4597 @end smallexample
4598
4599 @node Save Breakpoints
4600 @subsection How to save breakpoints to a file
4601
4602 To save breakpoint definitions to a file use the @w{@code{save
4603 breakpoints}} command.
4604
4605 @table @code
4606 @kindex save breakpoints
4607 @cindex save breakpoints to a file for future sessions
4608 @item save breakpoints [@var{filename}]
4609 This command saves all current breakpoint definitions together with
4610 their commands and ignore counts, into a file @file{@var{filename}}
4611 suitable for use in a later debugging session. This includes all
4612 types of breakpoints (breakpoints, watchpoints, catchpoints,
4613 tracepoints). To read the saved breakpoint definitions, use the
4614 @code{source} command (@pxref{Command Files}). Note that watchpoints
4615 with expressions involving local variables may fail to be recreated
4616 because it may not be possible to access the context where the
4617 watchpoint is valid anymore. Because the saved breakpoint definitions
4618 are simply a sequence of @value{GDBN} commands that recreate the
4619 breakpoints, you can edit the file in your favorite editing program,
4620 and remove the breakpoint definitions you're not interested in, or
4621 that can no longer be recreated.
4622 @end table
4623
4624 @c @ifclear BARETARGET
4625 @node Error in Breakpoints
4626 @subsection ``Cannot insert breakpoints''
4627
4628 If you request too many active hardware-assisted breakpoints and
4629 watchpoints, you will see this error message:
4630
4631 @c FIXME: the precise wording of this message may change; the relevant
4632 @c source change is not committed yet (Sep 3, 1999).
4633 @smallexample
4634 Stopped; cannot insert breakpoints.
4635 You may have requested too many hardware breakpoints and watchpoints.
4636 @end smallexample
4637
4638 @noindent
4639 This message is printed when you attempt to resume the program, since
4640 only then @value{GDBN} knows exactly how many hardware breakpoints and
4641 watchpoints it needs to insert.
4642
4643 When this message is printed, you need to disable or remove some of the
4644 hardware-assisted breakpoints and watchpoints, and then continue.
4645
4646 @node Breakpoint-related Warnings
4647 @subsection ``Breakpoint address adjusted...''
4648 @cindex breakpoint address adjusted
4649
4650 Some processor architectures place constraints on the addresses at
4651 which breakpoints may be placed. For architectures thus constrained,
4652 @value{GDBN} will attempt to adjust the breakpoint's address to comply
4653 with the constraints dictated by the architecture.
4654
4655 One example of such an architecture is the Fujitsu FR-V. The FR-V is
4656 a VLIW architecture in which a number of RISC-like instructions may be
4657 bundled together for parallel execution. The FR-V architecture
4658 constrains the location of a breakpoint instruction within such a
4659 bundle to the instruction with the lowest address. @value{GDBN}
4660 honors this constraint by adjusting a breakpoint's address to the
4661 first in the bundle.
4662
4663 It is not uncommon for optimized code to have bundles which contain
4664 instructions from different source statements, thus it may happen that
4665 a breakpoint's address will be adjusted from one source statement to
4666 another. Since this adjustment may significantly alter @value{GDBN}'s
4667 breakpoint related behavior from what the user expects, a warning is
4668 printed when the breakpoint is first set and also when the breakpoint
4669 is hit.
4670
4671 A warning like the one below is printed when setting a breakpoint
4672 that's been subject to address adjustment:
4673
4674 @smallexample
4675 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4676 @end smallexample
4677
4678 Such warnings are printed both for user settable and @value{GDBN}'s
4679 internal breakpoints. If you see one of these warnings, you should
4680 verify that a breakpoint set at the adjusted address will have the
4681 desired affect. If not, the breakpoint in question may be removed and
4682 other breakpoints may be set which will have the desired behavior.
4683 E.g., it may be sufficient to place the breakpoint at a later
4684 instruction. A conditional breakpoint may also be useful in some
4685 cases to prevent the breakpoint from triggering too often.
4686
4687 @value{GDBN} will also issue a warning when stopping at one of these
4688 adjusted breakpoints:
4689
4690 @smallexample
4691 warning: Breakpoint 1 address previously adjusted from 0x00010414
4692 to 0x00010410.
4693 @end smallexample
4694
4695 When this warning is encountered, it may be too late to take remedial
4696 action except in cases where the breakpoint is hit earlier or more
4697 frequently than expected.
4698
4699 @node Continuing and Stepping
4700 @section Continuing and Stepping
4701
4702 @cindex stepping
4703 @cindex continuing
4704 @cindex resuming execution
4705 @dfn{Continuing} means resuming program execution until your program
4706 completes normally. In contrast, @dfn{stepping} means executing just
4707 one more ``step'' of your program, where ``step'' may mean either one
4708 line of source code, or one machine instruction (depending on what
4709 particular command you use). Either when continuing or when stepping,
4710 your program may stop even sooner, due to a breakpoint or a signal. (If
4711 it stops due to a signal, you may want to use @code{handle}, or use
4712 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
4713
4714 @table @code
4715 @kindex continue
4716 @kindex c @r{(@code{continue})}
4717 @kindex fg @r{(resume foreground execution)}
4718 @item continue @r{[}@var{ignore-count}@r{]}
4719 @itemx c @r{[}@var{ignore-count}@r{]}
4720 @itemx fg @r{[}@var{ignore-count}@r{]}
4721 Resume program execution, at the address where your program last stopped;
4722 any breakpoints set at that address are bypassed. The optional argument
4723 @var{ignore-count} allows you to specify a further number of times to
4724 ignore a breakpoint at this location; its effect is like that of
4725 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
4726
4727 The argument @var{ignore-count} is meaningful only when your program
4728 stopped due to a breakpoint. At other times, the argument to
4729 @code{continue} is ignored.
4730
4731 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4732 debugged program is deemed to be the foreground program) are provided
4733 purely for convenience, and have exactly the same behavior as
4734 @code{continue}.
4735 @end table
4736
4737 To resume execution at a different place, you can use @code{return}
4738 (@pxref{Returning, ,Returning from a Function}) to go back to the
4739 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
4740 Different Address}) to go to an arbitrary location in your program.
4741
4742 A typical technique for using stepping is to set a breakpoint
4743 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
4744 beginning of the function or the section of your program where a problem
4745 is believed to lie, run your program until it stops at that breakpoint,
4746 and then step through the suspect area, examining the variables that are
4747 interesting, until you see the problem happen.
4748
4749 @table @code
4750 @kindex step
4751 @kindex s @r{(@code{step})}
4752 @item step
4753 Continue running your program until control reaches a different source
4754 line, then stop it and return control to @value{GDBN}. This command is
4755 abbreviated @code{s}.
4756
4757 @quotation
4758 @c "without debugging information" is imprecise; actually "without line
4759 @c numbers in the debugging information". (gcc -g1 has debugging info but
4760 @c not line numbers). But it seems complex to try to make that
4761 @c distinction here.
4762 @emph{Warning:} If you use the @code{step} command while control is
4763 within a function that was compiled without debugging information,
4764 execution proceeds until control reaches a function that does have
4765 debugging information. Likewise, it will not step into a function which
4766 is compiled without debugging information. To step through functions
4767 without debugging information, use the @code{stepi} command, described
4768 below.
4769 @end quotation
4770
4771 The @code{step} command only stops at the first instruction of a source
4772 line. This prevents the multiple stops that could otherwise occur in
4773 @code{switch} statements, @code{for} loops, etc. @code{step} continues
4774 to stop if a function that has debugging information is called within
4775 the line. In other words, @code{step} @emph{steps inside} any functions
4776 called within the line.
4777
4778 Also, the @code{step} command only enters a function if there is line
4779 number information for the function. Otherwise it acts like the
4780 @code{next} command. This avoids problems when using @code{cc -gl}
4781 on MIPS machines. Previously, @code{step} entered subroutines if there
4782 was any debugging information about the routine.
4783
4784 @item step @var{count}
4785 Continue running as in @code{step}, but do so @var{count} times. If a
4786 breakpoint is reached, or a signal not related to stepping occurs before
4787 @var{count} steps, stepping stops right away.
4788
4789 @kindex next
4790 @kindex n @r{(@code{next})}
4791 @item next @r{[}@var{count}@r{]}
4792 Continue to the next source line in the current (innermost) stack frame.
4793 This is similar to @code{step}, but function calls that appear within
4794 the line of code are executed without stopping. Execution stops when
4795 control reaches a different line of code at the original stack level
4796 that was executing when you gave the @code{next} command. This command
4797 is abbreviated @code{n}.
4798
4799 An argument @var{count} is a repeat count, as for @code{step}.
4800
4801
4802 @c FIX ME!! Do we delete this, or is there a way it fits in with
4803 @c the following paragraph? --- Vctoria
4804 @c
4805 @c @code{next} within a function that lacks debugging information acts like
4806 @c @code{step}, but any function calls appearing within the code of the
4807 @c function are executed without stopping.
4808
4809 The @code{next} command only stops at the first instruction of a
4810 source line. This prevents multiple stops that could otherwise occur in
4811 @code{switch} statements, @code{for} loops, etc.
4812
4813 @kindex set step-mode
4814 @item set step-mode
4815 @cindex functions without line info, and stepping
4816 @cindex stepping into functions with no line info
4817 @itemx set step-mode on
4818 The @code{set step-mode on} command causes the @code{step} command to
4819 stop at the first instruction of a function which contains no debug line
4820 information rather than stepping over it.
4821
4822 This is useful in cases where you may be interested in inspecting the
4823 machine instructions of a function which has no symbolic info and do not
4824 want @value{GDBN} to automatically skip over this function.
4825
4826 @item set step-mode off
4827 Causes the @code{step} command to step over any functions which contains no
4828 debug information. This is the default.
4829
4830 @item show step-mode
4831 Show whether @value{GDBN} will stop in or step over functions without
4832 source line debug information.
4833
4834 @kindex finish
4835 @kindex fin @r{(@code{finish})}
4836 @item finish
4837 Continue running until just after function in the selected stack frame
4838 returns. Print the returned value (if any). This command can be
4839 abbreviated as @code{fin}.
4840
4841 Contrast this with the @code{return} command (@pxref{Returning,
4842 ,Returning from a Function}).
4843
4844 @kindex until
4845 @kindex u @r{(@code{until})}
4846 @cindex run until specified location
4847 @item until
4848 @itemx u
4849 Continue running until a source line past the current line, in the
4850 current stack frame, is reached. This command is used to avoid single
4851 stepping through a loop more than once. It is like the @code{next}
4852 command, except that when @code{until} encounters a jump, it
4853 automatically continues execution until the program counter is greater
4854 than the address of the jump.
4855
4856 This means that when you reach the end of a loop after single stepping
4857 though it, @code{until} makes your program continue execution until it
4858 exits the loop. In contrast, a @code{next} command at the end of a loop
4859 simply steps back to the beginning of the loop, which forces you to step
4860 through the next iteration.
4861
4862 @code{until} always stops your program if it attempts to exit the current
4863 stack frame.
4864
4865 @code{until} may produce somewhat counterintuitive results if the order
4866 of machine code does not match the order of the source lines. For
4867 example, in the following excerpt from a debugging session, the @code{f}
4868 (@code{frame}) command shows that execution is stopped at line
4869 @code{206}; yet when we use @code{until}, we get to line @code{195}:
4870
4871 @smallexample
4872 (@value{GDBP}) f
4873 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4874 206 expand_input();
4875 (@value{GDBP}) until
4876 195 for ( ; argc > 0; NEXTARG) @{
4877 @end smallexample
4878
4879 This happened because, for execution efficiency, the compiler had
4880 generated code for the loop closure test at the end, rather than the
4881 start, of the loop---even though the test in a C @code{for}-loop is
4882 written before the body of the loop. The @code{until} command appeared
4883 to step back to the beginning of the loop when it advanced to this
4884 expression; however, it has not really gone to an earlier
4885 statement---not in terms of the actual machine code.
4886
4887 @code{until} with no argument works by means of single
4888 instruction stepping, and hence is slower than @code{until} with an
4889 argument.
4890
4891 @item until @var{location}
4892 @itemx u @var{location}
4893 Continue running your program until either the specified location is
4894 reached, or the current stack frame returns. @var{location} is any of
4895 the forms described in @ref{Specify Location}.
4896 This form of the command uses temporary breakpoints, and
4897 hence is quicker than @code{until} without an argument. The specified
4898 location is actually reached only if it is in the current frame. This
4899 implies that @code{until} can be used to skip over recursive function
4900 invocations. For instance in the code below, if the current location is
4901 line @code{96}, issuing @code{until 99} will execute the program up to
4902 line @code{99} in the same invocation of factorial, i.e., after the inner
4903 invocations have returned.
4904
4905 @smallexample
4906 94 int factorial (int value)
4907 95 @{
4908 96 if (value > 1) @{
4909 97 value *= factorial (value - 1);
4910 98 @}
4911 99 return (value);
4912 100 @}
4913 @end smallexample
4914
4915
4916 @kindex advance @var{location}
4917 @itemx advance @var{location}
4918 Continue running the program up to the given @var{location}. An argument is
4919 required, which should be of one of the forms described in
4920 @ref{Specify Location}.
4921 Execution will also stop upon exit from the current stack
4922 frame. This command is similar to @code{until}, but @code{advance} will
4923 not skip over recursive function calls, and the target location doesn't
4924 have to be in the same frame as the current one.
4925
4926
4927 @kindex stepi
4928 @kindex si @r{(@code{stepi})}
4929 @item stepi
4930 @itemx stepi @var{arg}
4931 @itemx si
4932 Execute one machine instruction, then stop and return to the debugger.
4933
4934 It is often useful to do @samp{display/i $pc} when stepping by machine
4935 instructions. This makes @value{GDBN} automatically display the next
4936 instruction to be executed, each time your program stops. @xref{Auto
4937 Display,, Automatic Display}.
4938
4939 An argument is a repeat count, as in @code{step}.
4940
4941 @need 750
4942 @kindex nexti
4943 @kindex ni @r{(@code{nexti})}
4944 @item nexti
4945 @itemx nexti @var{arg}
4946 @itemx ni
4947 Execute one machine instruction, but if it is a function call,
4948 proceed until the function returns.
4949
4950 An argument is a repeat count, as in @code{next}.
4951 @end table
4952
4953 @node Skipping Over Functions and Files
4954 @section Skipping Over Functions and Files
4955 @cindex skipping over functions and files
4956
4957 The program you are debugging may contain some functions which are
4958 uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
4959 skip a function or all functions in a file when stepping.
4960
4961 For example, consider the following C function:
4962
4963 @smallexample
4964 101 int func()
4965 102 @{
4966 103 foo(boring());
4967 104 bar(boring());
4968 105 @}
4969 @end smallexample
4970
4971 @noindent
4972 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
4973 are not interested in stepping through @code{boring}. If you run @code{step}
4974 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
4975 step over both @code{foo} and @code{boring}!
4976
4977 One solution is to @code{step} into @code{boring} and use the @code{finish}
4978 command to immediately exit it. But this can become tedious if @code{boring}
4979 is called from many places.
4980
4981 A more flexible solution is to execute @kbd{skip boring}. This instructs
4982 @value{GDBN} never to step into @code{boring}. Now when you execute
4983 @code{step} at line 103, you'll step over @code{boring} and directly into
4984 @code{foo}.
4985
4986 You can also instruct @value{GDBN} to skip all functions in a file, with, for
4987 example, @code{skip file boring.c}.
4988
4989 @table @code
4990 @kindex skip function
4991 @item skip @r{[}@var{linespec}@r{]}
4992 @itemx skip function @r{[}@var{linespec}@r{]}
4993 After running this command, the function named by @var{linespec} or the
4994 function containing the line named by @var{linespec} will be skipped over when
4995 stepping. @xref{Specify Location}.
4996
4997 If you do not specify @var{linespec}, the function you're currently debugging
4998 will be skipped.
4999
5000 (If you have a function called @code{file} that you want to skip, use
5001 @kbd{skip function file}.)
5002
5003 @kindex skip file
5004 @item skip file @r{[}@var{filename}@r{]}
5005 After running this command, any function whose source lives in @var{filename}
5006 will be skipped over when stepping.
5007
5008 If you do not specify @var{filename}, functions whose source lives in the file
5009 you're currently debugging will be skipped.
5010 @end table
5011
5012 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5013 These are the commands for managing your list of skips:
5014
5015 @table @code
5016 @kindex info skip
5017 @item info skip @r{[}@var{range}@r{]}
5018 Print details about the specified skip(s). If @var{range} is not specified,
5019 print a table with details about all functions and files marked for skipping.
5020 @code{info skip} prints the following information about each skip:
5021
5022 @table @emph
5023 @item Identifier
5024 A number identifying this skip.
5025 @item Type
5026 The type of this skip, either @samp{function} or @samp{file}.
5027 @item Enabled or Disabled
5028 Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5029 @item Address
5030 For function skips, this column indicates the address in memory of the function
5031 being skipped. If you've set a function skip on a function which has not yet
5032 been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5033 which has the function is loaded, @code{info skip} will show the function's
5034 address here.
5035 @item What
5036 For file skips, this field contains the filename being skipped. For functions
5037 skips, this field contains the function name and its line number in the file
5038 where it is defined.
5039 @end table
5040
5041 @kindex skip delete
5042 @item skip delete @r{[}@var{range}@r{]}
5043 Delete the specified skip(s). If @var{range} is not specified, delete all
5044 skips.
5045
5046 @kindex skip enable
5047 @item skip enable @r{[}@var{range}@r{]}
5048 Enable the specified skip(s). If @var{range} is not specified, enable all
5049 skips.
5050
5051 @kindex skip disable
5052 @item skip disable @r{[}@var{range}@r{]}
5053 Disable the specified skip(s). If @var{range} is not specified, disable all
5054 skips.
5055
5056 @end table
5057
5058 @node Signals
5059 @section Signals
5060 @cindex signals
5061
5062 A signal is an asynchronous event that can happen in a program. The
5063 operating system defines the possible kinds of signals, and gives each
5064 kind a name and a number. For example, in Unix @code{SIGINT} is the
5065 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
5066 @code{SIGSEGV} is the signal a program gets from referencing a place in
5067 memory far away from all the areas in use; @code{SIGALRM} occurs when
5068 the alarm clock timer goes off (which happens only if your program has
5069 requested an alarm).
5070
5071 @cindex fatal signals
5072 Some signals, including @code{SIGALRM}, are a normal part of the
5073 functioning of your program. Others, such as @code{SIGSEGV}, indicate
5074 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
5075 program has not specified in advance some other way to handle the signal.
5076 @code{SIGINT} does not indicate an error in your program, but it is normally
5077 fatal so it can carry out the purpose of the interrupt: to kill the program.
5078
5079 @value{GDBN} has the ability to detect any occurrence of a signal in your
5080 program. You can tell @value{GDBN} in advance what to do for each kind of
5081 signal.
5082
5083 @cindex handling signals
5084 Normally, @value{GDBN} is set up to let the non-erroneous signals like
5085 @code{SIGALRM} be silently passed to your program
5086 (so as not to interfere with their role in the program's functioning)
5087 but to stop your program immediately whenever an error signal happens.
5088 You can change these settings with the @code{handle} command.
5089
5090 @table @code
5091 @kindex info signals
5092 @kindex info handle
5093 @item info signals
5094 @itemx info handle
5095 Print a table of all the kinds of signals and how @value{GDBN} has been told to
5096 handle each one. You can use this to see the signal numbers of all
5097 the defined types of signals.
5098
5099 @item info signals @var{sig}
5100 Similar, but print information only about the specified signal number.
5101
5102 @code{info handle} is an alias for @code{info signals}.
5103
5104 @kindex handle
5105 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5106 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
5107 can be the number of a signal or its name (with or without the
5108 @samp{SIG} at the beginning); a list of signal numbers of the form
5109 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
5110 known signals. Optional arguments @var{keywords}, described below,
5111 say what change to make.
5112 @end table
5113
5114 @c @group
5115 The keywords allowed by the @code{handle} command can be abbreviated.
5116 Their full names are:
5117
5118 @table @code
5119 @item nostop
5120 @value{GDBN} should not stop your program when this signal happens. It may
5121 still print a message telling you that the signal has come in.
5122
5123 @item stop
5124 @value{GDBN} should stop your program when this signal happens. This implies
5125 the @code{print} keyword as well.
5126
5127 @item print
5128 @value{GDBN} should print a message when this signal happens.
5129
5130 @item noprint
5131 @value{GDBN} should not mention the occurrence of the signal at all. This
5132 implies the @code{nostop} keyword as well.
5133
5134 @item pass
5135 @itemx noignore
5136 @value{GDBN} should allow your program to see this signal; your program
5137 can handle the signal, or else it may terminate if the signal is fatal
5138 and not handled. @code{pass} and @code{noignore} are synonyms.
5139
5140 @item nopass
5141 @itemx ignore
5142 @value{GDBN} should not allow your program to see this signal.
5143 @code{nopass} and @code{ignore} are synonyms.
5144 @end table
5145 @c @end group
5146
5147 When a signal stops your program, the signal is not visible to the
5148 program until you
5149 continue. Your program sees the signal then, if @code{pass} is in
5150 effect for the signal in question @emph{at that time}. In other words,
5151 after @value{GDBN} reports a signal, you can use the @code{handle}
5152 command with @code{pass} or @code{nopass} to control whether your
5153 program sees that signal when you continue.
5154
5155 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5156 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5157 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5158 erroneous signals.
5159
5160 You can also use the @code{signal} command to prevent your program from
5161 seeing a signal, or cause it to see a signal it normally would not see,
5162 or to give it any signal at any time. For example, if your program stopped
5163 due to some sort of memory reference error, you might store correct
5164 values into the erroneous variables and continue, hoping to see more
5165 execution; but your program would probably terminate immediately as
5166 a result of the fatal signal once it saw the signal. To prevent this,
5167 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5168 Program a Signal}.
5169
5170 @cindex extra signal information
5171 @anchor{extra signal information}
5172
5173 On some targets, @value{GDBN} can inspect extra signal information
5174 associated with the intercepted signal, before it is actually
5175 delivered to the program being debugged. This information is exported
5176 by the convenience variable @code{$_siginfo}, and consists of data
5177 that is passed by the kernel to the signal handler at the time of the
5178 receipt of a signal. The data type of the information itself is
5179 target dependent. You can see the data type using the @code{ptype
5180 $_siginfo} command. On Unix systems, it typically corresponds to the
5181 standard @code{siginfo_t} type, as defined in the @file{signal.h}
5182 system header.
5183
5184 Here's an example, on a @sc{gnu}/Linux system, printing the stray
5185 referenced address that raised a segmentation fault.
5186
5187 @smallexample
5188 @group
5189 (@value{GDBP}) continue
5190 Program received signal SIGSEGV, Segmentation fault.
5191 0x0000000000400766 in main ()
5192 69 *(int *)p = 0;
5193 (@value{GDBP}) ptype $_siginfo
5194 type = struct @{
5195 int si_signo;
5196 int si_errno;
5197 int si_code;
5198 union @{
5199 int _pad[28];
5200 struct @{...@} _kill;
5201 struct @{...@} _timer;
5202 struct @{...@} _rt;
5203 struct @{...@} _sigchld;
5204 struct @{...@} _sigfault;
5205 struct @{...@} _sigpoll;
5206 @} _sifields;
5207 @}
5208 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
5209 type = struct @{
5210 void *si_addr;
5211 @}
5212 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5213 $1 = (void *) 0x7ffff7ff7000
5214 @end group
5215 @end smallexample
5216
5217 Depending on target support, @code{$_siginfo} may also be writable.
5218
5219 @node Thread Stops
5220 @section Stopping and Starting Multi-thread Programs
5221
5222 @cindex stopped threads
5223 @cindex threads, stopped
5224
5225 @cindex continuing threads
5226 @cindex threads, continuing
5227
5228 @value{GDBN} supports debugging programs with multiple threads
5229 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5230 are two modes of controlling execution of your program within the
5231 debugger. In the default mode, referred to as @dfn{all-stop mode},
5232 when any thread in your program stops (for example, at a breakpoint
5233 or while being stepped), all other threads in the program are also stopped by
5234 @value{GDBN}. On some targets, @value{GDBN} also supports
5235 @dfn{non-stop mode}, in which other threads can continue to run freely while
5236 you examine the stopped thread in the debugger.
5237
5238 @menu
5239 * All-Stop Mode:: All threads stop when GDB takes control
5240 * Non-Stop Mode:: Other threads continue to execute
5241 * Background Execution:: Running your program asynchronously
5242 * Thread-Specific Breakpoints:: Controlling breakpoints
5243 * Interrupted System Calls:: GDB may interfere with system calls
5244 * Observer Mode:: GDB does not alter program behavior
5245 @end menu
5246
5247 @node All-Stop Mode
5248 @subsection All-Stop Mode
5249
5250 @cindex all-stop mode
5251
5252 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5253 @emph{all} threads of execution stop, not just the current thread. This
5254 allows you to examine the overall state of the program, including
5255 switching between threads, without worrying that things may change
5256 underfoot.
5257
5258 Conversely, whenever you restart the program, @emph{all} threads start
5259 executing. @emph{This is true even when single-stepping} with commands
5260 like @code{step} or @code{next}.
5261
5262 In particular, @value{GDBN} cannot single-step all threads in lockstep.
5263 Since thread scheduling is up to your debugging target's operating
5264 system (not controlled by @value{GDBN}), other threads may
5265 execute more than one statement while the current thread completes a
5266 single step. Moreover, in general other threads stop in the middle of a
5267 statement, rather than at a clean statement boundary, when the program
5268 stops.
5269
5270 You might even find your program stopped in another thread after
5271 continuing or even single-stepping. This happens whenever some other
5272 thread runs into a breakpoint, a signal, or an exception before the
5273 first thread completes whatever you requested.
5274
5275 @cindex automatic thread selection
5276 @cindex switching threads automatically
5277 @cindex threads, automatic switching
5278 Whenever @value{GDBN} stops your program, due to a breakpoint or a
5279 signal, it automatically selects the thread where that breakpoint or
5280 signal happened. @value{GDBN} alerts you to the context switch with a
5281 message such as @samp{[Switching to Thread @var{n}]} to identify the
5282 thread.
5283
5284 On some OSes, you can modify @value{GDBN}'s default behavior by
5285 locking the OS scheduler to allow only a single thread to run.
5286
5287 @table @code
5288 @item set scheduler-locking @var{mode}
5289 @cindex scheduler locking mode
5290 @cindex lock scheduler
5291 Set the scheduler locking mode. If it is @code{off}, then there is no
5292 locking and any thread may run at any time. If @code{on}, then only the
5293 current thread may run when the inferior is resumed. The @code{step}
5294 mode optimizes for single-stepping; it prevents other threads
5295 from preempting the current thread while you are stepping, so that
5296 the focus of debugging does not change unexpectedly.
5297 Other threads only rarely (or never) get a chance to run
5298 when you step. They are more likely to run when you @samp{next} over a
5299 function call, and they are completely free to run when you use commands
5300 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5301 thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5302 the current thread away from the thread that you are debugging.
5303
5304 @item show scheduler-locking
5305 Display the current scheduler locking mode.
5306 @end table
5307
5308 @cindex resume threads of multiple processes simultaneously
5309 By default, when you issue one of the execution commands such as
5310 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5311 threads of the current inferior to run. For example, if @value{GDBN}
5312 is attached to two inferiors, each with two threads, the
5313 @code{continue} command resumes only the two threads of the current
5314 inferior. This is useful, for example, when you debug a program that
5315 forks and you want to hold the parent stopped (so that, for instance,
5316 it doesn't run to exit), while you debug the child. In other
5317 situations, you may not be interested in inspecting the current state
5318 of any of the processes @value{GDBN} is attached to, and you may want
5319 to resume them all until some breakpoint is hit. In the latter case,
5320 you can instruct @value{GDBN} to allow all threads of all the
5321 inferiors to run with the @w{@code{set schedule-multiple}} command.
5322
5323 @table @code
5324 @kindex set schedule-multiple
5325 @item set schedule-multiple
5326 Set the mode for allowing threads of multiple processes to be resumed
5327 when an execution command is issued. When @code{on}, all threads of
5328 all processes are allowed to run. When @code{off}, only the threads
5329 of the current process are resumed. The default is @code{off}. The
5330 @code{scheduler-locking} mode takes precedence when set to @code{on},
5331 or while you are stepping and set to @code{step}.
5332
5333 @item show schedule-multiple
5334 Display the current mode for resuming the execution of threads of
5335 multiple processes.
5336 @end table
5337
5338 @node Non-Stop Mode
5339 @subsection Non-Stop Mode
5340
5341 @cindex non-stop mode
5342
5343 @c This section is really only a place-holder, and needs to be expanded
5344 @c with more details.
5345
5346 For some multi-threaded targets, @value{GDBN} supports an optional
5347 mode of operation in which you can examine stopped program threads in
5348 the debugger while other threads continue to execute freely. This
5349 minimizes intrusion when debugging live systems, such as programs
5350 where some threads have real-time constraints or must continue to
5351 respond to external events. This is referred to as @dfn{non-stop} mode.
5352
5353 In non-stop mode, when a thread stops to report a debugging event,
5354 @emph{only} that thread is stopped; @value{GDBN} does not stop other
5355 threads as well, in contrast to the all-stop mode behavior. Additionally,
5356 execution commands such as @code{continue} and @code{step} apply by default
5357 only to the current thread in non-stop mode, rather than all threads as
5358 in all-stop mode. This allows you to control threads explicitly in
5359 ways that are not possible in all-stop mode --- for example, stepping
5360 one thread while allowing others to run freely, stepping
5361 one thread while holding all others stopped, or stepping several threads
5362 independently and simultaneously.
5363
5364 To enter non-stop mode, use this sequence of commands before you run
5365 or attach to your program:
5366
5367 @smallexample
5368 # Enable the async interface.
5369 set target-async 1
5370
5371 # If using the CLI, pagination breaks non-stop.
5372 set pagination off
5373
5374 # Finally, turn it on!
5375 set non-stop on
5376 @end smallexample
5377
5378 You can use these commands to manipulate the non-stop mode setting:
5379
5380 @table @code
5381 @kindex set non-stop
5382 @item set non-stop on
5383 Enable selection of non-stop mode.
5384 @item set non-stop off
5385 Disable selection of non-stop mode.
5386 @kindex show non-stop
5387 @item show non-stop
5388 Show the current non-stop enablement setting.
5389 @end table
5390
5391 Note these commands only reflect whether non-stop mode is enabled,
5392 not whether the currently-executing program is being run in non-stop mode.
5393 In particular, the @code{set non-stop} preference is only consulted when
5394 @value{GDBN} starts or connects to the target program, and it is generally
5395 not possible to switch modes once debugging has started. Furthermore,
5396 since not all targets support non-stop mode, even when you have enabled
5397 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5398 default.
5399
5400 In non-stop mode, all execution commands apply only to the current thread
5401 by default. That is, @code{continue} only continues one thread.
5402 To continue all threads, issue @code{continue -a} or @code{c -a}.
5403
5404 You can use @value{GDBN}'s background execution commands
5405 (@pxref{Background Execution}) to run some threads in the background
5406 while you continue to examine or step others from @value{GDBN}.
5407 The MI execution commands (@pxref{GDB/MI Program Execution}) are
5408 always executed asynchronously in non-stop mode.
5409
5410 Suspending execution is done with the @code{interrupt} command when
5411 running in the background, or @kbd{Ctrl-c} during foreground execution.
5412 In all-stop mode, this stops the whole process;
5413 but in non-stop mode the interrupt applies only to the current thread.
5414 To stop the whole program, use @code{interrupt -a}.
5415
5416 Other execution commands do not currently support the @code{-a} option.
5417
5418 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5419 that thread current, as it does in all-stop mode. This is because the
5420 thread stop notifications are asynchronous with respect to @value{GDBN}'s
5421 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5422 changed to a different thread just as you entered a command to operate on the
5423 previously current thread.
5424
5425 @node Background Execution
5426 @subsection Background Execution
5427
5428 @cindex foreground execution
5429 @cindex background execution
5430 @cindex asynchronous execution
5431 @cindex execution, foreground, background and asynchronous
5432
5433 @value{GDBN}'s execution commands have two variants: the normal
5434 foreground (synchronous) behavior, and a background
5435 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5436 the program to report that some thread has stopped before prompting for
5437 another command. In background execution, @value{GDBN} immediately gives
5438 a command prompt so that you can issue other commands while your program runs.
5439
5440 You need to explicitly enable asynchronous mode before you can use
5441 background execution commands. You can use these commands to
5442 manipulate the asynchronous mode setting:
5443
5444 @table @code
5445 @kindex set target-async
5446 @item set target-async on
5447 Enable asynchronous mode.
5448 @item set target-async off
5449 Disable asynchronous mode.
5450 @kindex show target-async
5451 @item show target-async
5452 Show the current target-async setting.
5453 @end table
5454
5455 If the target doesn't support async mode, @value{GDBN} issues an error
5456 message if you attempt to use the background execution commands.
5457
5458 To specify background execution, add a @code{&} to the command. For example,
5459 the background form of the @code{continue} command is @code{continue&}, or
5460 just @code{c&}. The execution commands that accept background execution
5461 are:
5462
5463 @table @code
5464 @kindex run&
5465 @item run
5466 @xref{Starting, , Starting your Program}.
5467
5468 @item attach
5469 @kindex attach&
5470 @xref{Attach, , Debugging an Already-running Process}.
5471
5472 @item step
5473 @kindex step&
5474 @xref{Continuing and Stepping, step}.
5475
5476 @item stepi
5477 @kindex stepi&
5478 @xref{Continuing and Stepping, stepi}.
5479
5480 @item next
5481 @kindex next&
5482 @xref{Continuing and Stepping, next}.
5483
5484 @item nexti
5485 @kindex nexti&
5486 @xref{Continuing and Stepping, nexti}.
5487
5488 @item continue
5489 @kindex continue&
5490 @xref{Continuing and Stepping, continue}.
5491
5492 @item finish
5493 @kindex finish&
5494 @xref{Continuing and Stepping, finish}.
5495
5496 @item until
5497 @kindex until&
5498 @xref{Continuing and Stepping, until}.
5499
5500 @end table
5501
5502 Background execution is especially useful in conjunction with non-stop
5503 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5504 However, you can also use these commands in the normal all-stop mode with
5505 the restriction that you cannot issue another execution command until the
5506 previous one finishes. Examples of commands that are valid in all-stop
5507 mode while the program is running include @code{help} and @code{info break}.
5508
5509 You can interrupt your program while it is running in the background by
5510 using the @code{interrupt} command.
5511
5512 @table @code
5513 @kindex interrupt
5514 @item interrupt
5515 @itemx interrupt -a
5516
5517 Suspend execution of the running program. In all-stop mode,
5518 @code{interrupt} stops the whole process, but in non-stop mode, it stops
5519 only the current thread. To stop the whole program in non-stop mode,
5520 use @code{interrupt -a}.
5521 @end table
5522
5523 @node Thread-Specific Breakpoints
5524 @subsection Thread-Specific Breakpoints
5525
5526 When your program has multiple threads (@pxref{Threads,, Debugging
5527 Programs with Multiple Threads}), you can choose whether to set
5528 breakpoints on all threads, or on a particular thread.
5529
5530 @table @code
5531 @cindex breakpoints and threads
5532 @cindex thread breakpoints
5533 @kindex break @dots{} thread @var{threadno}
5534 @item break @var{linespec} thread @var{threadno}
5535 @itemx break @var{linespec} thread @var{threadno} if @dots{}
5536 @var{linespec} specifies source lines; there are several ways of
5537 writing them (@pxref{Specify Location}), but the effect is always to
5538 specify some source line.
5539
5540 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5541 to specify that you only want @value{GDBN} to stop the program when a
5542 particular thread reaches this breakpoint. @var{threadno} is one of the
5543 numeric thread identifiers assigned by @value{GDBN}, shown in the first
5544 column of the @samp{info threads} display.
5545
5546 If you do not specify @samp{thread @var{threadno}} when you set a
5547 breakpoint, the breakpoint applies to @emph{all} threads of your
5548 program.
5549
5550 You can use the @code{thread} qualifier on conditional breakpoints as
5551 well; in this case, place @samp{thread @var{threadno}} before or
5552 after the breakpoint condition, like this:
5553
5554 @smallexample
5555 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
5556 @end smallexample
5557
5558 @end table
5559
5560 @node Interrupted System Calls
5561 @subsection Interrupted System Calls
5562
5563 @cindex thread breakpoints and system calls
5564 @cindex system calls and thread breakpoints
5565 @cindex premature return from system calls
5566 There is an unfortunate side effect when using @value{GDBN} to debug
5567 multi-threaded programs. If one thread stops for a
5568 breakpoint, or for some other reason, and another thread is blocked in a
5569 system call, then the system call may return prematurely. This is a
5570 consequence of the interaction between multiple threads and the signals
5571 that @value{GDBN} uses to implement breakpoints and other events that
5572 stop execution.
5573
5574 To handle this problem, your program should check the return value of
5575 each system call and react appropriately. This is good programming
5576 style anyways.
5577
5578 For example, do not write code like this:
5579
5580 @smallexample
5581 sleep (10);
5582 @end smallexample
5583
5584 The call to @code{sleep} will return early if a different thread stops
5585 at a breakpoint or for some other reason.
5586
5587 Instead, write this:
5588
5589 @smallexample
5590 int unslept = 10;
5591 while (unslept > 0)
5592 unslept = sleep (unslept);
5593 @end smallexample
5594
5595 A system call is allowed to return early, so the system is still
5596 conforming to its specification. But @value{GDBN} does cause your
5597 multi-threaded program to behave differently than it would without
5598 @value{GDBN}.
5599
5600 Also, @value{GDBN} uses internal breakpoints in the thread library to
5601 monitor certain events such as thread creation and thread destruction.
5602 When such an event happens, a system call in another thread may return
5603 prematurely, even though your program does not appear to stop.
5604
5605 @node Observer Mode
5606 @subsection Observer Mode
5607
5608 If you want to build on non-stop mode and observe program behavior
5609 without any chance of disruption by @value{GDBN}, you can set
5610 variables to disable all of the debugger's attempts to modify state,
5611 whether by writing memory, inserting breakpoints, etc. These operate
5612 at a low level, intercepting operations from all commands.
5613
5614 When all of these are set to @code{off}, then @value{GDBN} is said to
5615 be @dfn{observer mode}. As a convenience, the variable
5616 @code{observer} can be set to disable these, plus enable non-stop
5617 mode.
5618
5619 Note that @value{GDBN} will not prevent you from making nonsensical
5620 combinations of these settings. For instance, if you have enabled
5621 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
5622 then breakpoints that work by writing trap instructions into the code
5623 stream will still not be able to be placed.
5624
5625 @table @code
5626
5627 @kindex observer
5628 @item set observer on
5629 @itemx set observer off
5630 When set to @code{on}, this disables all the permission variables
5631 below (except for @code{insert-fast-tracepoints}), plus enables
5632 non-stop debugging. Setting this to @code{off} switches back to
5633 normal debugging, though remaining in non-stop mode.
5634
5635 @item show observer
5636 Show whether observer mode is on or off.
5637
5638 @kindex may-write-registers
5639 @item set may-write-registers on
5640 @itemx set may-write-registers off
5641 This controls whether @value{GDBN} will attempt to alter the values of
5642 registers, such as with assignment expressions in @code{print}, or the
5643 @code{jump} command. It defaults to @code{on}.
5644
5645 @item show may-write-registers
5646 Show the current permission to write registers.
5647
5648 @kindex may-write-memory
5649 @item set may-write-memory on
5650 @itemx set may-write-memory off
5651 This controls whether @value{GDBN} will attempt to alter the contents
5652 of memory, such as with assignment expressions in @code{print}. It
5653 defaults to @code{on}.
5654
5655 @item show may-write-memory
5656 Show the current permission to write memory.
5657
5658 @kindex may-insert-breakpoints
5659 @item set may-insert-breakpoints on
5660 @itemx set may-insert-breakpoints off
5661 This controls whether @value{GDBN} will attempt to insert breakpoints.
5662 This affects all breakpoints, including internal breakpoints defined
5663 by @value{GDBN}. It defaults to @code{on}.
5664
5665 @item show may-insert-breakpoints
5666 Show the current permission to insert breakpoints.
5667
5668 @kindex may-insert-tracepoints
5669 @item set may-insert-tracepoints on
5670 @itemx set may-insert-tracepoints off
5671 This controls whether @value{GDBN} will attempt to insert (regular)
5672 tracepoints at the beginning of a tracing experiment. It affects only
5673 non-fast tracepoints, fast tracepoints being under the control of
5674 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5675
5676 @item show may-insert-tracepoints
5677 Show the current permission to insert tracepoints.
5678
5679 @kindex may-insert-fast-tracepoints
5680 @item set may-insert-fast-tracepoints on
5681 @itemx set may-insert-fast-tracepoints off
5682 This controls whether @value{GDBN} will attempt to insert fast
5683 tracepoints at the beginning of a tracing experiment. It affects only
5684 fast tracepoints, regular (non-fast) tracepoints being under the
5685 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5686
5687 @item show may-insert-fast-tracepoints
5688 Show the current permission to insert fast tracepoints.
5689
5690 @kindex may-interrupt
5691 @item set may-interrupt on
5692 @itemx set may-interrupt off
5693 This controls whether @value{GDBN} will attempt to interrupt or stop
5694 program execution. When this variable is @code{off}, the
5695 @code{interrupt} command will have no effect, nor will
5696 @kbd{Ctrl-c}. It defaults to @code{on}.
5697
5698 @item show may-interrupt
5699 Show the current permission to interrupt or stop the program.
5700
5701 @end table
5702
5703 @node Reverse Execution
5704 @chapter Running programs backward
5705 @cindex reverse execution
5706 @cindex running programs backward
5707
5708 When you are debugging a program, it is not unusual to realize that
5709 you have gone too far, and some event of interest has already happened.
5710 If the target environment supports it, @value{GDBN} can allow you to
5711 ``rewind'' the program by running it backward.
5712
5713 A target environment that supports reverse execution should be able
5714 to ``undo'' the changes in machine state that have taken place as the
5715 program was executing normally. Variables, registers etc.@: should
5716 revert to their previous values. Obviously this requires a great
5717 deal of sophistication on the part of the target environment; not
5718 all target environments can support reverse execution.
5719
5720 When a program is executed in reverse, the instructions that
5721 have most recently been executed are ``un-executed'', in reverse
5722 order. The program counter runs backward, following the previous
5723 thread of execution in reverse. As each instruction is ``un-executed'',
5724 the values of memory and/or registers that were changed by that
5725 instruction are reverted to their previous states. After executing
5726 a piece of source code in reverse, all side effects of that code
5727 should be ``undone'', and all variables should be returned to their
5728 prior values@footnote{
5729 Note that some side effects are easier to undo than others. For instance,
5730 memory and registers are relatively easy, but device I/O is hard. Some
5731 targets may be able undo things like device I/O, and some may not.
5732
5733 The contract between @value{GDBN} and the reverse executing target
5734 requires only that the target do something reasonable when
5735 @value{GDBN} tells it to execute backwards, and then report the
5736 results back to @value{GDBN}. Whatever the target reports back to
5737 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5738 assumes that the memory and registers that the target reports are in a
5739 consistant state, but @value{GDBN} accepts whatever it is given.
5740 }.
5741
5742 If you are debugging in a target environment that supports
5743 reverse execution, @value{GDBN} provides the following commands.
5744
5745 @table @code
5746 @kindex reverse-continue
5747 @kindex rc @r{(@code{reverse-continue})}
5748 @item reverse-continue @r{[}@var{ignore-count}@r{]}
5749 @itemx rc @r{[}@var{ignore-count}@r{]}
5750 Beginning at the point where your program last stopped, start executing
5751 in reverse. Reverse execution will stop for breakpoints and synchronous
5752 exceptions (signals), just like normal execution. Behavior of
5753 asynchronous signals depends on the target environment.
5754
5755 @kindex reverse-step
5756 @kindex rs @r{(@code{step})}
5757 @item reverse-step @r{[}@var{count}@r{]}
5758 Run the program backward until control reaches the start of a
5759 different source line; then stop it, and return control to @value{GDBN}.
5760
5761 Like the @code{step} command, @code{reverse-step} will only stop
5762 at the beginning of a source line. It ``un-executes'' the previously
5763 executed source line. If the previous source line included calls to
5764 debuggable functions, @code{reverse-step} will step (backward) into
5765 the called function, stopping at the beginning of the @emph{last}
5766 statement in the called function (typically a return statement).
5767
5768 Also, as with the @code{step} command, if non-debuggable functions are
5769 called, @code{reverse-step} will run thru them backward without stopping.
5770
5771 @kindex reverse-stepi
5772 @kindex rsi @r{(@code{reverse-stepi})}
5773 @item reverse-stepi @r{[}@var{count}@r{]}
5774 Reverse-execute one machine instruction. Note that the instruction
5775 to be reverse-executed is @emph{not} the one pointed to by the program
5776 counter, but the instruction executed prior to that one. For instance,
5777 if the last instruction was a jump, @code{reverse-stepi} will take you
5778 back from the destination of the jump to the jump instruction itself.
5779
5780 @kindex reverse-next
5781 @kindex rn @r{(@code{reverse-next})}
5782 @item reverse-next @r{[}@var{count}@r{]}
5783 Run backward to the beginning of the previous line executed in
5784 the current (innermost) stack frame. If the line contains function
5785 calls, they will be ``un-executed'' without stopping. Starting from
5786 the first line of a function, @code{reverse-next} will take you back
5787 to the caller of that function, @emph{before} the function was called,
5788 just as the normal @code{next} command would take you from the last
5789 line of a function back to its return to its caller
5790 @footnote{Unless the code is too heavily optimized.}.
5791
5792 @kindex reverse-nexti
5793 @kindex rni @r{(@code{reverse-nexti})}
5794 @item reverse-nexti @r{[}@var{count}@r{]}
5795 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
5796 in reverse, except that called functions are ``un-executed'' atomically.
5797 That is, if the previously executed instruction was a return from
5798 another function, @code{reverse-nexti} will continue to execute
5799 in reverse until the call to that function (from the current stack
5800 frame) is reached.
5801
5802 @kindex reverse-finish
5803 @item reverse-finish
5804 Just as the @code{finish} command takes you to the point where the
5805 current function returns, @code{reverse-finish} takes you to the point
5806 where it was called. Instead of ending up at the end of the current
5807 function invocation, you end up at the beginning.
5808
5809 @kindex set exec-direction
5810 @item set exec-direction
5811 Set the direction of target execution.
5812 @itemx set exec-direction reverse
5813 @cindex execute forward or backward in time
5814 @value{GDBN} will perform all execution commands in reverse, until the
5815 exec-direction mode is changed to ``forward''. Affected commands include
5816 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
5817 command cannot be used in reverse mode.
5818 @item set exec-direction forward
5819 @value{GDBN} will perform all execution commands in the normal fashion.
5820 This is the default.
5821 @end table
5822
5823
5824 @node Process Record and Replay
5825 @chapter Recording Inferior's Execution and Replaying It
5826 @cindex process record and replay
5827 @cindex recording inferior's execution and replaying it
5828
5829 On some platforms, @value{GDBN} provides a special @dfn{process record
5830 and replay} target that can record a log of the process execution, and
5831 replay it later with both forward and reverse execution commands.
5832
5833 @cindex replay mode
5834 When this target is in use, if the execution log includes the record
5835 for the next instruction, @value{GDBN} will debug in @dfn{replay
5836 mode}. In the replay mode, the inferior does not really execute code
5837 instructions. Instead, all the events that normally happen during
5838 code execution are taken from the execution log. While code is not
5839 really executed in replay mode, the values of registers (including the
5840 program counter register) and the memory of the inferior are still
5841 changed as they normally would. Their contents are taken from the
5842 execution log.
5843
5844 @cindex record mode
5845 If the record for the next instruction is not in the execution log,
5846 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
5847 inferior executes normally, and @value{GDBN} records the execution log
5848 for future replay.
5849
5850 The process record and replay target supports reverse execution
5851 (@pxref{Reverse Execution}), even if the platform on which the
5852 inferior runs does not. However, the reverse execution is limited in
5853 this case by the range of the instructions recorded in the execution
5854 log. In other words, reverse execution on platforms that don't
5855 support it directly can only be done in the replay mode.
5856
5857 When debugging in the reverse direction, @value{GDBN} will work in
5858 replay mode as long as the execution log includes the record for the
5859 previous instruction; otherwise, it will work in record mode, if the
5860 platform supports reverse execution, or stop if not.
5861
5862 For architecture environments that support process record and replay,
5863 @value{GDBN} provides the following commands:
5864
5865 @table @code
5866 @kindex target record
5867 @kindex record
5868 @kindex rec
5869 @item target record
5870 This command starts the process record and replay target. The process
5871 record and replay target can only debug a process that is already
5872 running. Therefore, you need first to start the process with the
5873 @kbd{run} or @kbd{start} commands, and then start the recording with
5874 the @kbd{target record} command.
5875
5876 Both @code{record} and @code{rec} are aliases of @code{target record}.
5877
5878 @cindex displaced stepping, and process record and replay
5879 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
5880 will be automatically disabled when process record and replay target
5881 is started. That's because the process record and replay target
5882 doesn't support displaced stepping.
5883
5884 @cindex non-stop mode, and process record and replay
5885 @cindex asynchronous execution, and process record and replay
5886 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
5887 the asynchronous execution mode (@pxref{Background Execution}), the
5888 process record and replay target cannot be started because it doesn't
5889 support these two modes.
5890
5891 @kindex record stop
5892 @kindex rec s
5893 @item record stop
5894 Stop the process record and replay target. When process record and
5895 replay target stops, the entire execution log will be deleted and the
5896 inferior will either be terminated, or will remain in its final state.
5897
5898 When you stop the process record and replay target in record mode (at
5899 the end of the execution log), the inferior will be stopped at the
5900 next instruction that would have been recorded. In other words, if
5901 you record for a while and then stop recording, the inferior process
5902 will be left in the same state as if the recording never happened.
5903
5904 On the other hand, if the process record and replay target is stopped
5905 while in replay mode (that is, not at the end of the execution log,
5906 but at some earlier point), the inferior process will become ``live''
5907 at that earlier state, and it will then be possible to continue the
5908 usual ``live'' debugging of the process from that state.
5909
5910 When the inferior process exits, or @value{GDBN} detaches from it,
5911 process record and replay target will automatically stop itself.
5912
5913 @kindex record save
5914 @item record save @var{filename}
5915 Save the execution log to a file @file{@var{filename}}.
5916 Default filename is @file{gdb_record.@var{process_id}}, where
5917 @var{process_id} is the process ID of the inferior.
5918
5919 @kindex record restore
5920 @item record restore @var{filename}
5921 Restore the execution log from a file @file{@var{filename}}.
5922 File must have been created with @code{record save}.
5923
5924 @kindex set record insn-number-max
5925 @item set record insn-number-max @var{limit}
5926 Set the limit of instructions to be recorded. Default value is 200000.
5927
5928 If @var{limit} is a positive number, then @value{GDBN} will start
5929 deleting instructions from the log once the number of the record
5930 instructions becomes greater than @var{limit}. For every new recorded
5931 instruction, @value{GDBN} will delete the earliest recorded
5932 instruction to keep the number of recorded instructions at the limit.
5933 (Since deleting recorded instructions loses information, @value{GDBN}
5934 lets you control what happens when the limit is reached, by means of
5935 the @code{stop-at-limit} option, described below.)
5936
5937 If @var{limit} is zero, @value{GDBN} will never delete recorded
5938 instructions from the execution log. The number of recorded
5939 instructions is unlimited in this case.
5940
5941 @kindex show record insn-number-max
5942 @item show record insn-number-max
5943 Show the limit of instructions to be recorded.
5944
5945 @kindex set record stop-at-limit
5946 @item set record stop-at-limit
5947 Control the behavior when the number of recorded instructions reaches
5948 the limit. If ON (the default), @value{GDBN} will stop when the limit
5949 is reached for the first time and ask you whether you want to stop the
5950 inferior or continue running it and recording the execution log. If
5951 you decide to continue recording, each new recorded instruction will
5952 cause the oldest one to be deleted.
5953
5954 If this option is OFF, @value{GDBN} will automatically delete the
5955 oldest record to make room for each new one, without asking.
5956
5957 @kindex show record stop-at-limit
5958 @item show record stop-at-limit
5959 Show the current setting of @code{stop-at-limit}.
5960
5961 @kindex set record memory-query
5962 @item set record memory-query
5963 Control the behavior when @value{GDBN} is unable to record memory
5964 changes caused by an instruction. If ON, @value{GDBN} will query
5965 whether to stop the inferior in that case.
5966
5967 If this option is OFF (the default), @value{GDBN} will automatically
5968 ignore the effect of such instructions on memory. Later, when
5969 @value{GDBN} replays this execution log, it will mark the log of this
5970 instruction as not accessible, and it will not affect the replay
5971 results.
5972
5973 @kindex show record memory-query
5974 @item show record memory-query
5975 Show the current setting of @code{memory-query}.
5976
5977 @kindex info record
5978 @item info record
5979 Show various statistics about the state of process record and its
5980 in-memory execution log buffer, including:
5981
5982 @itemize @bullet
5983 @item
5984 Whether in record mode or replay mode.
5985 @item
5986 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
5987 @item
5988 Highest recorded instruction number.
5989 @item
5990 Current instruction about to be replayed (if in replay mode).
5991 @item
5992 Number of instructions contained in the execution log.
5993 @item
5994 Maximum number of instructions that may be contained in the execution log.
5995 @end itemize
5996
5997 @kindex record delete
5998 @kindex rec del
5999 @item record delete
6000 When record target runs in replay mode (``in the past''), delete the
6001 subsequent execution log and begin to record a new execution log starting
6002 from the current address. This means you will abandon the previously
6003 recorded ``future'' and begin recording a new ``future''.
6004 @end table
6005
6006
6007 @node Stack
6008 @chapter Examining the Stack
6009
6010 When your program has stopped, the first thing you need to know is where it
6011 stopped and how it got there.
6012
6013 @cindex call stack
6014 Each time your program performs a function call, information about the call
6015 is generated.
6016 That information includes the location of the call in your program,
6017 the arguments of the call,
6018 and the local variables of the function being called.
6019 The information is saved in a block of data called a @dfn{stack frame}.
6020 The stack frames are allocated in a region of memory called the @dfn{call
6021 stack}.
6022
6023 When your program stops, the @value{GDBN} commands for examining the
6024 stack allow you to see all of this information.
6025
6026 @cindex selected frame
6027 One of the stack frames is @dfn{selected} by @value{GDBN} and many
6028 @value{GDBN} commands refer implicitly to the selected frame. In
6029 particular, whenever you ask @value{GDBN} for the value of a variable in
6030 your program, the value is found in the selected frame. There are
6031 special @value{GDBN} commands to select whichever frame you are
6032 interested in. @xref{Selection, ,Selecting a Frame}.
6033
6034 When your program stops, @value{GDBN} automatically selects the
6035 currently executing frame and describes it briefly, similar to the
6036 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
6037
6038 @menu
6039 * Frames:: Stack frames
6040 * Backtrace:: Backtraces
6041 * Selection:: Selecting a frame
6042 * Frame Info:: Information on a frame
6043
6044 @end menu
6045
6046 @node Frames
6047 @section Stack Frames
6048
6049 @cindex frame, definition
6050 @cindex stack frame
6051 The call stack is divided up into contiguous pieces called @dfn{stack
6052 frames}, or @dfn{frames} for short; each frame is the data associated
6053 with one call to one function. The frame contains the arguments given
6054 to the function, the function's local variables, and the address at
6055 which the function is executing.
6056
6057 @cindex initial frame
6058 @cindex outermost frame
6059 @cindex innermost frame
6060 When your program is started, the stack has only one frame, that of the
6061 function @code{main}. This is called the @dfn{initial} frame or the
6062 @dfn{outermost} frame. Each time a function is called, a new frame is
6063 made. Each time a function returns, the frame for that function invocation
6064 is eliminated. If a function is recursive, there can be many frames for
6065 the same function. The frame for the function in which execution is
6066 actually occurring is called the @dfn{innermost} frame. This is the most
6067 recently created of all the stack frames that still exist.
6068
6069 @cindex frame pointer
6070 Inside your program, stack frames are identified by their addresses. A
6071 stack frame consists of many bytes, each of which has its own address; each
6072 kind of computer has a convention for choosing one byte whose
6073 address serves as the address of the frame. Usually this address is kept
6074 in a register called the @dfn{frame pointer register}
6075 (@pxref{Registers, $fp}) while execution is going on in that frame.
6076
6077 @cindex frame number
6078 @value{GDBN} assigns numbers to all existing stack frames, starting with
6079 zero for the innermost frame, one for the frame that called it,
6080 and so on upward. These numbers do not really exist in your program;
6081 they are assigned by @value{GDBN} to give you a way of designating stack
6082 frames in @value{GDBN} commands.
6083
6084 @c The -fomit-frame-pointer below perennially causes hbox overflow
6085 @c underflow problems.
6086 @cindex frameless execution
6087 Some compilers provide a way to compile functions so that they operate
6088 without stack frames. (For example, the @value{NGCC} option
6089 @smallexample
6090 @samp{-fomit-frame-pointer}
6091 @end smallexample
6092 generates functions without a frame.)
6093 This is occasionally done with heavily used library functions to save
6094 the frame setup time. @value{GDBN} has limited facilities for dealing
6095 with these function invocations. If the innermost function invocation
6096 has no stack frame, @value{GDBN} nevertheless regards it as though
6097 it had a separate frame, which is numbered zero as usual, allowing
6098 correct tracing of the function call chain. However, @value{GDBN} has
6099 no provision for frameless functions elsewhere in the stack.
6100
6101 @table @code
6102 @kindex frame@r{, command}
6103 @cindex current stack frame
6104 @item frame @var{args}
6105 The @code{frame} command allows you to move from one stack frame to another,
6106 and to print the stack frame you select. @var{args} may be either the
6107 address of the frame or the stack frame number. Without an argument,
6108 @code{frame} prints the current stack frame.
6109
6110 @kindex select-frame
6111 @cindex selecting frame silently
6112 @item select-frame
6113 The @code{select-frame} command allows you to move from one stack frame
6114 to another without printing the frame. This is the silent version of
6115 @code{frame}.
6116 @end table
6117
6118 @node Backtrace
6119 @section Backtraces
6120
6121 @cindex traceback
6122 @cindex call stack traces
6123 A backtrace is a summary of how your program got where it is. It shows one
6124 line per frame, for many frames, starting with the currently executing
6125 frame (frame zero), followed by its caller (frame one), and on up the
6126 stack.
6127
6128 @table @code
6129 @kindex backtrace
6130 @kindex bt @r{(@code{backtrace})}
6131 @item backtrace
6132 @itemx bt
6133 Print a backtrace of the entire stack: one line per frame for all
6134 frames in the stack.
6135
6136 You can stop the backtrace at any time by typing the system interrupt
6137 character, normally @kbd{Ctrl-c}.
6138
6139 @item backtrace @var{n}
6140 @itemx bt @var{n}
6141 Similar, but print only the innermost @var{n} frames.
6142
6143 @item backtrace -@var{n}
6144 @itemx bt -@var{n}
6145 Similar, but print only the outermost @var{n} frames.
6146
6147 @item backtrace full
6148 @itemx bt full
6149 @itemx bt full @var{n}
6150 @itemx bt full -@var{n}
6151 Print the values of the local variables also. @var{n} specifies the
6152 number of frames to print, as described above.
6153 @end table
6154
6155 @kindex where
6156 @kindex info stack
6157 The names @code{where} and @code{info stack} (abbreviated @code{info s})
6158 are additional aliases for @code{backtrace}.
6159
6160 @cindex multiple threads, backtrace
6161 In a multi-threaded program, @value{GDBN} by default shows the
6162 backtrace only for the current thread. To display the backtrace for
6163 several or all of the threads, use the command @code{thread apply}
6164 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
6165 apply all backtrace}, @value{GDBN} will display the backtrace for all
6166 the threads; this is handy when you debug a core dump of a
6167 multi-threaded program.
6168
6169 Each line in the backtrace shows the frame number and the function name.
6170 The program counter value is also shown---unless you use @code{set
6171 print address off}. The backtrace also shows the source file name and
6172 line number, as well as the arguments to the function. The program
6173 counter value is omitted if it is at the beginning of the code for that
6174 line number.
6175
6176 Here is an example of a backtrace. It was made with the command
6177 @samp{bt 3}, so it shows the innermost three frames.
6178
6179 @smallexample
6180 @group
6181 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6182 at builtin.c:993
6183 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
6184 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6185 at macro.c:71
6186 (More stack frames follow...)
6187 @end group
6188 @end smallexample
6189
6190 @noindent
6191 The display for frame zero does not begin with a program counter
6192 value, indicating that your program has stopped at the beginning of the
6193 code for line @code{993} of @code{builtin.c}.
6194
6195 @noindent
6196 The value of parameter @code{data} in frame 1 has been replaced by
6197 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
6198 only if it is a scalar (integer, pointer, enumeration, etc). See command
6199 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
6200 on how to configure the way function parameter values are printed.
6201
6202 @cindex optimized out, in backtrace
6203 @cindex function call arguments, optimized out
6204 If your program was compiled with optimizations, some compilers will
6205 optimize away arguments passed to functions if those arguments are
6206 never used after the call. Such optimizations generate code that
6207 passes arguments through registers, but doesn't store those arguments
6208 in the stack frame. @value{GDBN} has no way of displaying such
6209 arguments in stack frames other than the innermost one. Here's what
6210 such a backtrace might look like:
6211
6212 @smallexample
6213 @group
6214 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6215 at builtin.c:993
6216 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6217 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
6218 at macro.c:71
6219 (More stack frames follow...)
6220 @end group
6221 @end smallexample
6222
6223 @noindent
6224 The values of arguments that were not saved in their stack frames are
6225 shown as @samp{<optimized out>}.
6226
6227 If you need to display the values of such optimized-out arguments,
6228 either deduce that from other variables whose values depend on the one
6229 you are interested in, or recompile without optimizations.
6230
6231 @cindex backtrace beyond @code{main} function
6232 @cindex program entry point
6233 @cindex startup code, and backtrace
6234 Most programs have a standard user entry point---a place where system
6235 libraries and startup code transition into user code. For C this is
6236 @code{main}@footnote{
6237 Note that embedded programs (the so-called ``free-standing''
6238 environment) are not required to have a @code{main} function as the
6239 entry point. They could even have multiple entry points.}.
6240 When @value{GDBN} finds the entry function in a backtrace
6241 it will terminate the backtrace, to avoid tracing into highly
6242 system-specific (and generally uninteresting) code.
6243
6244 If you need to examine the startup code, or limit the number of levels
6245 in a backtrace, you can change this behavior:
6246
6247 @table @code
6248 @item set backtrace past-main
6249 @itemx set backtrace past-main on
6250 @kindex set backtrace
6251 Backtraces will continue past the user entry point.
6252
6253 @item set backtrace past-main off
6254 Backtraces will stop when they encounter the user entry point. This is the
6255 default.
6256
6257 @item show backtrace past-main
6258 @kindex show backtrace
6259 Display the current user entry point backtrace policy.
6260
6261 @item set backtrace past-entry
6262 @itemx set backtrace past-entry on
6263 Backtraces will continue past the internal entry point of an application.
6264 This entry point is encoded by the linker when the application is built,
6265 and is likely before the user entry point @code{main} (or equivalent) is called.
6266
6267 @item set backtrace past-entry off
6268 Backtraces will stop when they encounter the internal entry point of an
6269 application. This is the default.
6270
6271 @item show backtrace past-entry
6272 Display the current internal entry point backtrace policy.
6273
6274 @item set backtrace limit @var{n}
6275 @itemx set backtrace limit 0
6276 @cindex backtrace limit
6277 Limit the backtrace to @var{n} levels. A value of zero means
6278 unlimited.
6279
6280 @item show backtrace limit
6281 Display the current limit on backtrace levels.
6282 @end table
6283
6284 @node Selection
6285 @section Selecting a Frame
6286
6287 Most commands for examining the stack and other data in your program work on
6288 whichever stack frame is selected at the moment. Here are the commands for
6289 selecting a stack frame; all of them finish by printing a brief description
6290 of the stack frame just selected.
6291
6292 @table @code
6293 @kindex frame@r{, selecting}
6294 @kindex f @r{(@code{frame})}
6295 @item frame @var{n}
6296 @itemx f @var{n}
6297 Select frame number @var{n}. Recall that frame zero is the innermost
6298 (currently executing) frame, frame one is the frame that called the
6299 innermost one, and so on. The highest-numbered frame is the one for
6300 @code{main}.
6301
6302 @item frame @var{addr}
6303 @itemx f @var{addr}
6304 Select the frame at address @var{addr}. This is useful mainly if the
6305 chaining of stack frames has been damaged by a bug, making it
6306 impossible for @value{GDBN} to assign numbers properly to all frames. In
6307 addition, this can be useful when your program has multiple stacks and
6308 switches between them.
6309
6310 On the SPARC architecture, @code{frame} needs two addresses to
6311 select an arbitrary frame: a frame pointer and a stack pointer.
6312
6313 On the MIPS and Alpha architecture, it needs two addresses: a stack
6314 pointer and a program counter.
6315
6316 On the 29k architecture, it needs three addresses: a register stack
6317 pointer, a program counter, and a memory stack pointer.
6318
6319 @kindex up
6320 @item up @var{n}
6321 Move @var{n} frames up the stack. For positive numbers @var{n}, this
6322 advances toward the outermost frame, to higher frame numbers, to frames
6323 that have existed longer. @var{n} defaults to one.
6324
6325 @kindex down
6326 @kindex do @r{(@code{down})}
6327 @item down @var{n}
6328 Move @var{n} frames down the stack. For positive numbers @var{n}, this
6329 advances toward the innermost frame, to lower frame numbers, to frames
6330 that were created more recently. @var{n} defaults to one. You may
6331 abbreviate @code{down} as @code{do}.
6332 @end table
6333
6334 All of these commands end by printing two lines of output describing the
6335 frame. The first line shows the frame number, the function name, the
6336 arguments, and the source file and line number of execution in that
6337 frame. The second line shows the text of that source line.
6338
6339 @need 1000
6340 For example:
6341
6342 @smallexample
6343 @group
6344 (@value{GDBP}) up
6345 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6346 at env.c:10
6347 10 read_input_file (argv[i]);
6348 @end group
6349 @end smallexample
6350
6351 After such a printout, the @code{list} command with no arguments
6352 prints ten lines centered on the point of execution in the frame.
6353 You can also edit the program at the point of execution with your favorite
6354 editing program by typing @code{edit}.
6355 @xref{List, ,Printing Source Lines},
6356 for details.
6357
6358 @table @code
6359 @kindex down-silently
6360 @kindex up-silently
6361 @item up-silently @var{n}
6362 @itemx down-silently @var{n}
6363 These two commands are variants of @code{up} and @code{down},
6364 respectively; they differ in that they do their work silently, without
6365 causing display of the new frame. They are intended primarily for use
6366 in @value{GDBN} command scripts, where the output might be unnecessary and
6367 distracting.
6368 @end table
6369
6370 @node Frame Info
6371 @section Information About a Frame
6372
6373 There are several other commands to print information about the selected
6374 stack frame.
6375
6376 @table @code
6377 @item frame
6378 @itemx f
6379 When used without any argument, this command does not change which
6380 frame is selected, but prints a brief description of the currently
6381 selected stack frame. It can be abbreviated @code{f}. With an
6382 argument, this command is used to select a stack frame.
6383 @xref{Selection, ,Selecting a Frame}.
6384
6385 @kindex info frame
6386 @kindex info f @r{(@code{info frame})}
6387 @item info frame
6388 @itemx info f
6389 This command prints a verbose description of the selected stack frame,
6390 including:
6391
6392 @itemize @bullet
6393 @item
6394 the address of the frame
6395 @item
6396 the address of the next frame down (called by this frame)
6397 @item
6398 the address of the next frame up (caller of this frame)
6399 @item
6400 the language in which the source code corresponding to this frame is written
6401 @item
6402 the address of the frame's arguments
6403 @item
6404 the address of the frame's local variables
6405 @item
6406 the program counter saved in it (the address of execution in the caller frame)
6407 @item
6408 which registers were saved in the frame
6409 @end itemize
6410
6411 @noindent The verbose description is useful when
6412 something has gone wrong that has made the stack format fail to fit
6413 the usual conventions.
6414
6415 @item info frame @var{addr}
6416 @itemx info f @var{addr}
6417 Print a verbose description of the frame at address @var{addr}, without
6418 selecting that frame. The selected frame remains unchanged by this
6419 command. This requires the same kind of address (more than one for some
6420 architectures) that you specify in the @code{frame} command.
6421 @xref{Selection, ,Selecting a Frame}.
6422
6423 @kindex info args
6424 @item info args
6425 Print the arguments of the selected frame, each on a separate line.
6426
6427 @item info locals
6428 @kindex info locals
6429 Print the local variables of the selected frame, each on a separate
6430 line. These are all variables (declared either static or automatic)
6431 accessible at the point of execution of the selected frame.
6432
6433 @end table
6434
6435
6436 @node Source
6437 @chapter Examining Source Files
6438
6439 @value{GDBN} can print parts of your program's source, since the debugging
6440 information recorded in the program tells @value{GDBN} what source files were
6441 used to build it. When your program stops, @value{GDBN} spontaneously prints
6442 the line where it stopped. Likewise, when you select a stack frame
6443 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
6444 execution in that frame has stopped. You can print other portions of
6445 source files by explicit command.
6446
6447 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
6448 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
6449 @value{GDBN} under @sc{gnu} Emacs}.
6450
6451 @menu
6452 * List:: Printing source lines
6453 * Specify Location:: How to specify code locations
6454 * Edit:: Editing source files
6455 * Search:: Searching source files
6456 * Source Path:: Specifying source directories
6457 * Machine Code:: Source and machine code
6458 @end menu
6459
6460 @node List
6461 @section Printing Source Lines
6462
6463 @kindex list
6464 @kindex l @r{(@code{list})}
6465 To print lines from a source file, use the @code{list} command
6466 (abbreviated @code{l}). By default, ten lines are printed.
6467 There are several ways to specify what part of the file you want to
6468 print; see @ref{Specify Location}, for the full list.
6469
6470 Here are the forms of the @code{list} command most commonly used:
6471
6472 @table @code
6473 @item list @var{linenum}
6474 Print lines centered around line number @var{linenum} in the
6475 current source file.
6476
6477 @item list @var{function}
6478 Print lines centered around the beginning of function
6479 @var{function}.
6480
6481 @item list
6482 Print more lines. If the last lines printed were printed with a
6483 @code{list} command, this prints lines following the last lines
6484 printed; however, if the last line printed was a solitary line printed
6485 as part of displaying a stack frame (@pxref{Stack, ,Examining the
6486 Stack}), this prints lines centered around that line.
6487
6488 @item list -
6489 Print lines just before the lines last printed.
6490 @end table
6491
6492 @cindex @code{list}, how many lines to display
6493 By default, @value{GDBN} prints ten source lines with any of these forms of
6494 the @code{list} command. You can change this using @code{set listsize}:
6495
6496 @table @code
6497 @kindex set listsize
6498 @item set listsize @var{count}
6499 Make the @code{list} command display @var{count} source lines (unless
6500 the @code{list} argument explicitly specifies some other number).
6501
6502 @kindex show listsize
6503 @item show listsize
6504 Display the number of lines that @code{list} prints.
6505 @end table
6506
6507 Repeating a @code{list} command with @key{RET} discards the argument,
6508 so it is equivalent to typing just @code{list}. This is more useful
6509 than listing the same lines again. An exception is made for an
6510 argument of @samp{-}; that argument is preserved in repetition so that
6511 each repetition moves up in the source file.
6512
6513 In general, the @code{list} command expects you to supply zero, one or two
6514 @dfn{linespecs}. Linespecs specify source lines; there are several ways
6515 of writing them (@pxref{Specify Location}), but the effect is always
6516 to specify some source line.
6517
6518 Here is a complete description of the possible arguments for @code{list}:
6519
6520 @table @code
6521 @item list @var{linespec}
6522 Print lines centered around the line specified by @var{linespec}.
6523
6524 @item list @var{first},@var{last}
6525 Print lines from @var{first} to @var{last}. Both arguments are
6526 linespecs. When a @code{list} command has two linespecs, and the
6527 source file of the second linespec is omitted, this refers to
6528 the same source file as the first linespec.
6529
6530 @item list ,@var{last}
6531 Print lines ending with @var{last}.
6532
6533 @item list @var{first},
6534 Print lines starting with @var{first}.
6535
6536 @item list +
6537 Print lines just after the lines last printed.
6538
6539 @item list -
6540 Print lines just before the lines last printed.
6541
6542 @item list
6543 As described in the preceding table.
6544 @end table
6545
6546 @node Specify Location
6547 @section Specifying a Location
6548 @cindex specifying location
6549 @cindex linespec
6550
6551 Several @value{GDBN} commands accept arguments that specify a location
6552 of your program's code. Since @value{GDBN} is a source-level
6553 debugger, a location usually specifies some line in the source code;
6554 for that reason, locations are also known as @dfn{linespecs}.
6555
6556 Here are all the different ways of specifying a code location that
6557 @value{GDBN} understands:
6558
6559 @table @code
6560 @item @var{linenum}
6561 Specifies the line number @var{linenum} of the current source file.
6562
6563 @item -@var{offset}
6564 @itemx +@var{offset}
6565 Specifies the line @var{offset} lines before or after the @dfn{current
6566 line}. For the @code{list} command, the current line is the last one
6567 printed; for the breakpoint commands, this is the line at which
6568 execution stopped in the currently selected @dfn{stack frame}
6569 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
6570 used as the second of the two linespecs in a @code{list} command,
6571 this specifies the line @var{offset} lines up or down from the first
6572 linespec.
6573
6574 @item @var{filename}:@var{linenum}
6575 Specifies the line @var{linenum} in the source file @var{filename}.
6576 If @var{filename} is a relative file name, then it will match any
6577 source file name with the same trailing components. For example, if
6578 @var{filename} is @samp{gcc/expr.c}, then it will match source file
6579 name of @file{/build/trunk/gcc/expr.c}, but not
6580 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
6581
6582 @item @var{function}
6583 Specifies the line that begins the body of the function @var{function}.
6584 For example, in C, this is the line with the open brace.
6585
6586 @item @var{function}:@var{label}
6587 Specifies the line where @var{label} appears in @var{function}.
6588
6589 @item @var{filename}:@var{function}
6590 Specifies the line that begins the body of the function @var{function}
6591 in the file @var{filename}. You only need the file name with a
6592 function name to avoid ambiguity when there are identically named
6593 functions in different source files.
6594
6595 @item @var{label}
6596 Specifies the line at which the label named @var{label} appears.
6597 @value{GDBN} searches for the label in the function corresponding to
6598 the currently selected stack frame. If there is no current selected
6599 stack frame (for instance, if the inferior is not running), then
6600 @value{GDBN} will not search for a label.
6601
6602 @item *@var{address}
6603 Specifies the program address @var{address}. For line-oriented
6604 commands, such as @code{list} and @code{edit}, this specifies a source
6605 line that contains @var{address}. For @code{break} and other
6606 breakpoint oriented commands, this can be used to set breakpoints in
6607 parts of your program which do not have debugging information or
6608 source files.
6609
6610 Here @var{address} may be any expression valid in the current working
6611 language (@pxref{Languages, working language}) that specifies a code
6612 address. In addition, as a convenience, @value{GDBN} extends the
6613 semantics of expressions used in locations to cover the situations
6614 that frequently happen during debugging. Here are the various forms
6615 of @var{address}:
6616
6617 @table @code
6618 @item @var{expression}
6619 Any expression valid in the current working language.
6620
6621 @item @var{funcaddr}
6622 An address of a function or procedure derived from its name. In C,
6623 C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
6624 simply the function's name @var{function} (and actually a special case
6625 of a valid expression). In Pascal and Modula-2, this is
6626 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
6627 (although the Pascal form also works).
6628
6629 This form specifies the address of the function's first instruction,
6630 before the stack frame and arguments have been set up.
6631
6632 @item '@var{filename}'::@var{funcaddr}
6633 Like @var{funcaddr} above, but also specifies the name of the source
6634 file explicitly. This is useful if the name of the function does not
6635 specify the function unambiguously, e.g., if there are several
6636 functions with identical names in different source files.
6637 @end table
6638
6639 @end table
6640
6641
6642 @node Edit
6643 @section Editing Source Files
6644 @cindex editing source files
6645
6646 @kindex edit
6647 @kindex e @r{(@code{edit})}
6648 To edit the lines in a source file, use the @code{edit} command.
6649 The editing program of your choice
6650 is invoked with the current line set to
6651 the active line in the program.
6652 Alternatively, there are several ways to specify what part of the file you
6653 want to print if you want to see other parts of the program:
6654
6655 @table @code
6656 @item edit @var{location}
6657 Edit the source file specified by @code{location}. Editing starts at
6658 that @var{location}, e.g., at the specified source line of the
6659 specified file. @xref{Specify Location}, for all the possible forms
6660 of the @var{location} argument; here are the forms of the @code{edit}
6661 command most commonly used:
6662
6663 @table @code
6664 @item edit @var{number}
6665 Edit the current source file with @var{number} as the active line number.
6666
6667 @item edit @var{function}
6668 Edit the file containing @var{function} at the beginning of its definition.
6669 @end table
6670
6671 @end table
6672
6673 @subsection Choosing your Editor
6674 You can customize @value{GDBN} to use any editor you want
6675 @footnote{
6676 The only restriction is that your editor (say @code{ex}), recognizes the
6677 following command-line syntax:
6678 @smallexample
6679 ex +@var{number} file
6680 @end smallexample
6681 The optional numeric value +@var{number} specifies the number of the line in
6682 the file where to start editing.}.
6683 By default, it is @file{@value{EDITOR}}, but you can change this
6684 by setting the environment variable @code{EDITOR} before using
6685 @value{GDBN}. For example, to configure @value{GDBN} to use the
6686 @code{vi} editor, you could use these commands with the @code{sh} shell:
6687 @smallexample
6688 EDITOR=/usr/bin/vi
6689 export EDITOR
6690 gdb @dots{}
6691 @end smallexample
6692 or in the @code{csh} shell,
6693 @smallexample
6694 setenv EDITOR /usr/bin/vi
6695 gdb @dots{}
6696 @end smallexample
6697
6698 @node Search
6699 @section Searching Source Files
6700 @cindex searching source files
6701
6702 There are two commands for searching through the current source file for a
6703 regular expression.
6704
6705 @table @code
6706 @kindex search
6707 @kindex forward-search
6708 @item forward-search @var{regexp}
6709 @itemx search @var{regexp}
6710 The command @samp{forward-search @var{regexp}} checks each line,
6711 starting with the one following the last line listed, for a match for
6712 @var{regexp}. It lists the line that is found. You can use the
6713 synonym @samp{search @var{regexp}} or abbreviate the command name as
6714 @code{fo}.
6715
6716 @kindex reverse-search
6717 @item reverse-search @var{regexp}
6718 The command @samp{reverse-search @var{regexp}} checks each line, starting
6719 with the one before the last line listed and going backward, for a match
6720 for @var{regexp}. It lists the line that is found. You can abbreviate
6721 this command as @code{rev}.
6722 @end table
6723
6724 @node Source Path
6725 @section Specifying Source Directories
6726
6727 @cindex source path
6728 @cindex directories for source files
6729 Executable programs sometimes do not record the directories of the source
6730 files from which they were compiled, just the names. Even when they do,
6731 the directories could be moved between the compilation and your debugging
6732 session. @value{GDBN} has a list of directories to search for source files;
6733 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
6734 it tries all the directories in the list, in the order they are present
6735 in the list, until it finds a file with the desired name.
6736
6737 For example, suppose an executable references the file
6738 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
6739 @file{/mnt/cross}. The file is first looked up literally; if this
6740 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
6741 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
6742 message is printed. @value{GDBN} does not look up the parts of the
6743 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
6744 Likewise, the subdirectories of the source path are not searched: if
6745 the source path is @file{/mnt/cross}, and the binary refers to
6746 @file{foo.c}, @value{GDBN} would not find it under
6747 @file{/mnt/cross/usr/src/foo-1.0/lib}.
6748
6749 Plain file names, relative file names with leading directories, file
6750 names containing dots, etc.@: are all treated as described above; for
6751 instance, if the source path is @file{/mnt/cross}, and the source file
6752 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
6753 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
6754 that---@file{/mnt/cross/foo.c}.
6755
6756 Note that the executable search path is @emph{not} used to locate the
6757 source files.
6758
6759 Whenever you reset or rearrange the source path, @value{GDBN} clears out
6760 any information it has cached about where source files are found and where
6761 each line is in the file.
6762
6763 @kindex directory
6764 @kindex dir
6765 When you start @value{GDBN}, its source path includes only @samp{cdir}
6766 and @samp{cwd}, in that order.
6767 To add other directories, use the @code{directory} command.
6768
6769 The search path is used to find both program source files and @value{GDBN}
6770 script files (read using the @samp{-command} option and @samp{source} command).
6771
6772 In addition to the source path, @value{GDBN} provides a set of commands
6773 that manage a list of source path substitution rules. A @dfn{substitution
6774 rule} specifies how to rewrite source directories stored in the program's
6775 debug information in case the sources were moved to a different
6776 directory between compilation and debugging. A rule is made of
6777 two strings, the first specifying what needs to be rewritten in
6778 the path, and the second specifying how it should be rewritten.
6779 In @ref{set substitute-path}, we name these two parts @var{from} and
6780 @var{to} respectively. @value{GDBN} does a simple string replacement
6781 of @var{from} with @var{to} at the start of the directory part of the
6782 source file name, and uses that result instead of the original file
6783 name to look up the sources.
6784
6785 Using the previous example, suppose the @file{foo-1.0} tree has been
6786 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
6787 @value{GDBN} to replace @file{/usr/src} in all source path names with
6788 @file{/mnt/cross}. The first lookup will then be
6789 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
6790 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
6791 substitution rule, use the @code{set substitute-path} command
6792 (@pxref{set substitute-path}).
6793
6794 To avoid unexpected substitution results, a rule is applied only if the
6795 @var{from} part of the directory name ends at a directory separator.
6796 For instance, a rule substituting @file{/usr/source} into
6797 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
6798 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
6799 is applied only at the beginning of the directory name, this rule will
6800 not be applied to @file{/root/usr/source/baz.c} either.
6801
6802 In many cases, you can achieve the same result using the @code{directory}
6803 command. However, @code{set substitute-path} can be more efficient in
6804 the case where the sources are organized in a complex tree with multiple
6805 subdirectories. With the @code{directory} command, you need to add each
6806 subdirectory of your project. If you moved the entire tree while
6807 preserving its internal organization, then @code{set substitute-path}
6808 allows you to direct the debugger to all the sources with one single
6809 command.
6810
6811 @code{set substitute-path} is also more than just a shortcut command.
6812 The source path is only used if the file at the original location no
6813 longer exists. On the other hand, @code{set substitute-path} modifies
6814 the debugger behavior to look at the rewritten location instead. So, if
6815 for any reason a source file that is not relevant to your executable is
6816 located at the original location, a substitution rule is the only
6817 method available to point @value{GDBN} at the new location.
6818
6819 @cindex @samp{--with-relocated-sources}
6820 @cindex default source path substitution
6821 You can configure a default source path substitution rule by
6822 configuring @value{GDBN} with the
6823 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
6824 should be the name of a directory under @value{GDBN}'s configured
6825 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
6826 directory names in debug information under @var{dir} will be adjusted
6827 automatically if the installed @value{GDBN} is moved to a new
6828 location. This is useful if @value{GDBN}, libraries or executables
6829 with debug information and corresponding source code are being moved
6830 together.
6831
6832 @table @code
6833 @item directory @var{dirname} @dots{}
6834 @item dir @var{dirname} @dots{}
6835 Add directory @var{dirname} to the front of the source path. Several
6836 directory names may be given to this command, separated by @samp{:}
6837 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
6838 part of absolute file names) or
6839 whitespace. You may specify a directory that is already in the source
6840 path; this moves it forward, so @value{GDBN} searches it sooner.
6841
6842 @kindex cdir
6843 @kindex cwd
6844 @vindex $cdir@r{, convenience variable}
6845 @vindex $cwd@r{, convenience variable}
6846 @cindex compilation directory
6847 @cindex current directory
6848 @cindex working directory
6849 @cindex directory, current
6850 @cindex directory, compilation
6851 You can use the string @samp{$cdir} to refer to the compilation
6852 directory (if one is recorded), and @samp{$cwd} to refer to the current
6853 working directory. @samp{$cwd} is not the same as @samp{.}---the former
6854 tracks the current working directory as it changes during your @value{GDBN}
6855 session, while the latter is immediately expanded to the current
6856 directory at the time you add an entry to the source path.
6857
6858 @item directory
6859 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
6860
6861 @c RET-repeat for @code{directory} is explicitly disabled, but since
6862 @c repeating it would be a no-op we do not say that. (thanks to RMS)
6863
6864 @item set directories @var{path-list}
6865 @kindex set directories
6866 Set the source path to @var{path-list}.
6867 @samp{$cdir:$cwd} are added if missing.
6868
6869 @item show directories
6870 @kindex show directories
6871 Print the source path: show which directories it contains.
6872
6873 @anchor{set substitute-path}
6874 @item set substitute-path @var{from} @var{to}
6875 @kindex set substitute-path
6876 Define a source path substitution rule, and add it at the end of the
6877 current list of existing substitution rules. If a rule with the same
6878 @var{from} was already defined, then the old rule is also deleted.
6879
6880 For example, if the file @file{/foo/bar/baz.c} was moved to
6881 @file{/mnt/cross/baz.c}, then the command
6882
6883 @smallexample
6884 (@value{GDBP}) set substitute-path /usr/src /mnt/cross
6885 @end smallexample
6886
6887 @noindent
6888 will tell @value{GDBN} to replace @samp{/usr/src} with
6889 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
6890 @file{baz.c} even though it was moved.
6891
6892 In the case when more than one substitution rule have been defined,
6893 the rules are evaluated one by one in the order where they have been
6894 defined. The first one matching, if any, is selected to perform
6895 the substitution.
6896
6897 For instance, if we had entered the following commands:
6898
6899 @smallexample
6900 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
6901 (@value{GDBP}) set substitute-path /usr/src /mnt/src
6902 @end smallexample
6903
6904 @noindent
6905 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
6906 @file{/mnt/include/defs.h} by using the first rule. However, it would
6907 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
6908 @file{/mnt/src/lib/foo.c}.
6909
6910
6911 @item unset substitute-path [path]
6912 @kindex unset substitute-path
6913 If a path is specified, search the current list of substitution rules
6914 for a rule that would rewrite that path. Delete that rule if found.
6915 A warning is emitted by the debugger if no rule could be found.
6916
6917 If no path is specified, then all substitution rules are deleted.
6918
6919 @item show substitute-path [path]
6920 @kindex show substitute-path
6921 If a path is specified, then print the source path substitution rule
6922 which would rewrite that path, if any.
6923
6924 If no path is specified, then print all existing source path substitution
6925 rules.
6926
6927 @end table
6928
6929 If your source path is cluttered with directories that are no longer of
6930 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
6931 versions of source. You can correct the situation as follows:
6932
6933 @enumerate
6934 @item
6935 Use @code{directory} with no argument to reset the source path to its default value.
6936
6937 @item
6938 Use @code{directory} with suitable arguments to reinstall the
6939 directories you want in the source path. You can add all the
6940 directories in one command.
6941 @end enumerate
6942
6943 @node Machine Code
6944 @section Source and Machine Code
6945 @cindex source line and its code address
6946
6947 You can use the command @code{info line} to map source lines to program
6948 addresses (and vice versa), and the command @code{disassemble} to display
6949 a range of addresses as machine instructions. You can use the command
6950 @code{set disassemble-next-line} to set whether to disassemble next
6951 source line when execution stops. When run under @sc{gnu} Emacs
6952 mode, the @code{info line} command causes the arrow to point to the
6953 line specified. Also, @code{info line} prints addresses in symbolic form as
6954 well as hex.
6955
6956 @table @code
6957 @kindex info line
6958 @item info line @var{linespec}
6959 Print the starting and ending addresses of the compiled code for
6960 source line @var{linespec}. You can specify source lines in any of
6961 the ways documented in @ref{Specify Location}.
6962 @end table
6963
6964 For example, we can use @code{info line} to discover the location of
6965 the object code for the first line of function
6966 @code{m4_changequote}:
6967
6968 @c FIXME: I think this example should also show the addresses in
6969 @c symbolic form, as they usually would be displayed.
6970 @smallexample
6971 (@value{GDBP}) info line m4_changequote
6972 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
6973 @end smallexample
6974
6975 @noindent
6976 @cindex code address and its source line
6977 We can also inquire (using @code{*@var{addr}} as the form for
6978 @var{linespec}) what source line covers a particular address:
6979 @smallexample
6980 (@value{GDBP}) info line *0x63ff
6981 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
6982 @end smallexample
6983
6984 @cindex @code{$_} and @code{info line}
6985 @cindex @code{x} command, default address
6986 @kindex x@r{(examine), and} info line
6987 After @code{info line}, the default address for the @code{x} command
6988 is changed to the starting address of the line, so that @samp{x/i} is
6989 sufficient to begin examining the machine code (@pxref{Memory,
6990 ,Examining Memory}). Also, this address is saved as the value of the
6991 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
6992 Variables}).
6993
6994 @table @code
6995 @kindex disassemble
6996 @cindex assembly instructions
6997 @cindex instructions, assembly
6998 @cindex machine instructions
6999 @cindex listing machine instructions
7000 @item disassemble
7001 @itemx disassemble /m
7002 @itemx disassemble /r
7003 This specialized command dumps a range of memory as machine
7004 instructions. It can also print mixed source+disassembly by specifying
7005 the @code{/m} modifier and print the raw instructions in hex as well as
7006 in symbolic form by specifying the @code{/r}.
7007 The default memory range is the function surrounding the
7008 program counter of the selected frame. A single argument to this
7009 command is a program counter value; @value{GDBN} dumps the function
7010 surrounding this value. When two arguments are given, they should
7011 be separated by a comma, possibly surrounded by whitespace. The
7012 arguments specify a range of addresses to dump, in one of two forms:
7013
7014 @table @code
7015 @item @var{start},@var{end}
7016 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7017 @item @var{start},+@var{length}
7018 the addresses from @var{start} (inclusive) to
7019 @code{@var{start}+@var{length}} (exclusive).
7020 @end table
7021
7022 @noindent
7023 When 2 arguments are specified, the name of the function is also
7024 printed (since there could be several functions in the given range).
7025
7026 The argument(s) can be any expression yielding a numeric value, such as
7027 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
7028
7029 If the range of memory being disassembled contains current program counter,
7030 the instruction at that location is shown with a @code{=>} marker.
7031 @end table
7032
7033 The following example shows the disassembly of a range of addresses of
7034 HP PA-RISC 2.0 code:
7035
7036 @smallexample
7037 (@value{GDBP}) disas 0x32c4, 0x32e4
7038 Dump of assembler code from 0x32c4 to 0x32e4:
7039 0x32c4 <main+204>: addil 0,dp
7040 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
7041 0x32cc <main+212>: ldil 0x3000,r31
7042 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
7043 0x32d4 <main+220>: ldo 0(r31),rp
7044 0x32d8 <main+224>: addil -0x800,dp
7045 0x32dc <main+228>: ldo 0x588(r1),r26
7046 0x32e0 <main+232>: ldil 0x3000,r31
7047 End of assembler dump.
7048 @end smallexample
7049
7050 Here is an example showing mixed source+assembly for Intel x86, when the
7051 program is stopped just after function prologue:
7052
7053 @smallexample
7054 (@value{GDBP}) disas /m main
7055 Dump of assembler code for function main:
7056 5 @{
7057 0x08048330 <+0>: push %ebp
7058 0x08048331 <+1>: mov %esp,%ebp
7059 0x08048333 <+3>: sub $0x8,%esp
7060 0x08048336 <+6>: and $0xfffffff0,%esp
7061 0x08048339 <+9>: sub $0x10,%esp
7062
7063 6 printf ("Hello.\n");
7064 => 0x0804833c <+12>: movl $0x8048440,(%esp)
7065 0x08048343 <+19>: call 0x8048284 <puts@@plt>
7066
7067 7 return 0;
7068 8 @}
7069 0x08048348 <+24>: mov $0x0,%eax
7070 0x0804834d <+29>: leave
7071 0x0804834e <+30>: ret
7072
7073 End of assembler dump.
7074 @end smallexample
7075
7076 Here is another example showing raw instructions in hex for AMD x86-64,
7077
7078 @smallexample
7079 (gdb) disas /r 0x400281,+10
7080 Dump of assembler code from 0x400281 to 0x40028b:
7081 0x0000000000400281: 38 36 cmp %dh,(%rsi)
7082 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
7083 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
7084 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
7085 End of assembler dump.
7086 @end smallexample
7087
7088 Some architectures have more than one commonly-used set of instruction
7089 mnemonics or other syntax.
7090
7091 For programs that were dynamically linked and use shared libraries,
7092 instructions that call functions or branch to locations in the shared
7093 libraries might show a seemingly bogus location---it's actually a
7094 location of the relocation table. On some architectures, @value{GDBN}
7095 might be able to resolve these to actual function names.
7096
7097 @table @code
7098 @kindex set disassembly-flavor
7099 @cindex Intel disassembly flavor
7100 @cindex AT&T disassembly flavor
7101 @item set disassembly-flavor @var{instruction-set}
7102 Select the instruction set to use when disassembling the
7103 program via the @code{disassemble} or @code{x/i} commands.
7104
7105 Currently this command is only defined for the Intel x86 family. You
7106 can set @var{instruction-set} to either @code{intel} or @code{att}.
7107 The default is @code{att}, the AT&T flavor used by default by Unix
7108 assemblers for x86-based targets.
7109
7110 @kindex show disassembly-flavor
7111 @item show disassembly-flavor
7112 Show the current setting of the disassembly flavor.
7113 @end table
7114
7115 @table @code
7116 @kindex set disassemble-next-line
7117 @kindex show disassemble-next-line
7118 @item set disassemble-next-line
7119 @itemx show disassemble-next-line
7120 Control whether or not @value{GDBN} will disassemble the next source
7121 line or instruction when execution stops. If ON, @value{GDBN} will
7122 display disassembly of the next source line when execution of the
7123 program being debugged stops. This is @emph{in addition} to
7124 displaying the source line itself, which @value{GDBN} always does if
7125 possible. If the next source line cannot be displayed for some reason
7126 (e.g., if @value{GDBN} cannot find the source file, or there's no line
7127 info in the debug info), @value{GDBN} will display disassembly of the
7128 next @emph{instruction} instead of showing the next source line. If
7129 AUTO, @value{GDBN} will display disassembly of next instruction only
7130 if the source line cannot be displayed. This setting causes
7131 @value{GDBN} to display some feedback when you step through a function
7132 with no line info or whose source file is unavailable. The default is
7133 OFF, which means never display the disassembly of the next line or
7134 instruction.
7135 @end table
7136
7137
7138 @node Data
7139 @chapter Examining Data
7140
7141 @cindex printing data
7142 @cindex examining data
7143 @kindex print
7144 @kindex inspect
7145 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
7146 @c document because it is nonstandard... Under Epoch it displays in a
7147 @c different window or something like that.
7148 The usual way to examine data in your program is with the @code{print}
7149 command (abbreviated @code{p}), or its synonym @code{inspect}. It
7150 evaluates and prints the value of an expression of the language your
7151 program is written in (@pxref{Languages, ,Using @value{GDBN} with
7152 Different Languages}). It may also print the expression using a
7153 Python-based pretty-printer (@pxref{Pretty Printing}).
7154
7155 @table @code
7156 @item print @var{expr}
7157 @itemx print /@var{f} @var{expr}
7158 @var{expr} is an expression (in the source language). By default the
7159 value of @var{expr} is printed in a format appropriate to its data type;
7160 you can choose a different format by specifying @samp{/@var{f}}, where
7161 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
7162 Formats}.
7163
7164 @item print
7165 @itemx print /@var{f}
7166 @cindex reprint the last value
7167 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
7168 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
7169 conveniently inspect the same value in an alternative format.
7170 @end table
7171
7172 A more low-level way of examining data is with the @code{x} command.
7173 It examines data in memory at a specified address and prints it in a
7174 specified format. @xref{Memory, ,Examining Memory}.
7175
7176 If you are interested in information about types, or about how the
7177 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7178 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7179 Table}.
7180
7181 @menu
7182 * Expressions:: Expressions
7183 * Ambiguous Expressions:: Ambiguous Expressions
7184 * Variables:: Program variables
7185 * Arrays:: Artificial arrays
7186 * Output Formats:: Output formats
7187 * Memory:: Examining memory
7188 * Auto Display:: Automatic display
7189 * Print Settings:: Print settings
7190 * Pretty Printing:: Python pretty printing
7191 * Value History:: Value history
7192 * Convenience Vars:: Convenience variables
7193 * Registers:: Registers
7194 * Floating Point Hardware:: Floating point hardware
7195 * Vector Unit:: Vector Unit
7196 * OS Information:: Auxiliary data provided by operating system
7197 * Memory Region Attributes:: Memory region attributes
7198 * Dump/Restore Files:: Copy between memory and a file
7199 * Core File Generation:: Cause a program dump its core
7200 * Character Sets:: Debugging programs that use a different
7201 character set than GDB does
7202 * Caching Remote Data:: Data caching for remote targets
7203 * Searching Memory:: Searching memory for a sequence of bytes
7204 @end menu
7205
7206 @node Expressions
7207 @section Expressions
7208
7209 @cindex expressions
7210 @code{print} and many other @value{GDBN} commands accept an expression and
7211 compute its value. Any kind of constant, variable or operator defined
7212 by the programming language you are using is valid in an expression in
7213 @value{GDBN}. This includes conditional expressions, function calls,
7214 casts, and string constants. It also includes preprocessor macros, if
7215 you compiled your program to include this information; see
7216 @ref{Compilation}.
7217
7218 @cindex arrays in expressions
7219 @value{GDBN} supports array constants in expressions input by
7220 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
7221 you can use the command @code{print @{1, 2, 3@}} to create an array
7222 of three integers. If you pass an array to a function or assign it
7223 to a program variable, @value{GDBN} copies the array to memory that
7224 is @code{malloc}ed in the target program.
7225
7226 Because C is so widespread, most of the expressions shown in examples in
7227 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
7228 Languages}, for information on how to use expressions in other
7229 languages.
7230
7231 In this section, we discuss operators that you can use in @value{GDBN}
7232 expressions regardless of your programming language.
7233
7234 @cindex casts, in expressions
7235 Casts are supported in all languages, not just in C, because it is so
7236 useful to cast a number into a pointer in order to examine a structure
7237 at that address in memory.
7238 @c FIXME: casts supported---Mod2 true?
7239
7240 @value{GDBN} supports these operators, in addition to those common
7241 to programming languages:
7242
7243 @table @code
7244 @item @@
7245 @samp{@@} is a binary operator for treating parts of memory as arrays.
7246 @xref{Arrays, ,Artificial Arrays}, for more information.
7247
7248 @item ::
7249 @samp{::} allows you to specify a variable in terms of the file or
7250 function where it is defined. @xref{Variables, ,Program Variables}.
7251
7252 @cindex @{@var{type}@}
7253 @cindex type casting memory
7254 @cindex memory, viewing as typed object
7255 @cindex casts, to view memory
7256 @item @{@var{type}@} @var{addr}
7257 Refers to an object of type @var{type} stored at address @var{addr} in
7258 memory. @var{addr} may be any expression whose value is an integer or
7259 pointer (but parentheses are required around binary operators, just as in
7260 a cast). This construct is allowed regardless of what kind of data is
7261 normally supposed to reside at @var{addr}.
7262 @end table
7263
7264 @node Ambiguous Expressions
7265 @section Ambiguous Expressions
7266 @cindex ambiguous expressions
7267
7268 Expressions can sometimes contain some ambiguous elements. For instance,
7269 some programming languages (notably Ada, C@t{++} and Objective-C) permit
7270 a single function name to be defined several times, for application in
7271 different contexts. This is called @dfn{overloading}. Another example
7272 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
7273 templates and is typically instantiated several times, resulting in
7274 the same function name being defined in different contexts.
7275
7276 In some cases and depending on the language, it is possible to adjust
7277 the expression to remove the ambiguity. For instance in C@t{++}, you
7278 can specify the signature of the function you want to break on, as in
7279 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
7280 qualified name of your function often makes the expression unambiguous
7281 as well.
7282
7283 When an ambiguity that needs to be resolved is detected, the debugger
7284 has the capability to display a menu of numbered choices for each
7285 possibility, and then waits for the selection with the prompt @samp{>}.
7286 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
7287 aborts the current command. If the command in which the expression was
7288 used allows more than one choice to be selected, the next option in the
7289 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
7290 choices.
7291
7292 For example, the following session excerpt shows an attempt to set a
7293 breakpoint at the overloaded symbol @code{String::after}.
7294 We choose three particular definitions of that function name:
7295
7296 @c FIXME! This is likely to change to show arg type lists, at least
7297 @smallexample
7298 @group
7299 (@value{GDBP}) b String::after
7300 [0] cancel
7301 [1] all
7302 [2] file:String.cc; line number:867
7303 [3] file:String.cc; line number:860
7304 [4] file:String.cc; line number:875
7305 [5] file:String.cc; line number:853
7306 [6] file:String.cc; line number:846
7307 [7] file:String.cc; line number:735
7308 > 2 4 6
7309 Breakpoint 1 at 0xb26c: file String.cc, line 867.
7310 Breakpoint 2 at 0xb344: file String.cc, line 875.
7311 Breakpoint 3 at 0xafcc: file String.cc, line 846.
7312 Multiple breakpoints were set.
7313 Use the "delete" command to delete unwanted
7314 breakpoints.
7315 (@value{GDBP})
7316 @end group
7317 @end smallexample
7318
7319 @table @code
7320 @kindex set multiple-symbols
7321 @item set multiple-symbols @var{mode}
7322 @cindex multiple-symbols menu
7323
7324 This option allows you to adjust the debugger behavior when an expression
7325 is ambiguous.
7326
7327 By default, @var{mode} is set to @code{all}. If the command with which
7328 the expression is used allows more than one choice, then @value{GDBN}
7329 automatically selects all possible choices. For instance, inserting
7330 a breakpoint on a function using an ambiguous name results in a breakpoint
7331 inserted on each possible match. However, if a unique choice must be made,
7332 then @value{GDBN} uses the menu to help you disambiguate the expression.
7333 For instance, printing the address of an overloaded function will result
7334 in the use of the menu.
7335
7336 When @var{mode} is set to @code{ask}, the debugger always uses the menu
7337 when an ambiguity is detected.
7338
7339 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7340 an error due to the ambiguity and the command is aborted.
7341
7342 @kindex show multiple-symbols
7343 @item show multiple-symbols
7344 Show the current value of the @code{multiple-symbols} setting.
7345 @end table
7346
7347 @node Variables
7348 @section Program Variables
7349
7350 The most common kind of expression to use is the name of a variable
7351 in your program.
7352
7353 Variables in expressions are understood in the selected stack frame
7354 (@pxref{Selection, ,Selecting a Frame}); they must be either:
7355
7356 @itemize @bullet
7357 @item
7358 global (or file-static)
7359 @end itemize
7360
7361 @noindent or
7362
7363 @itemize @bullet
7364 @item
7365 visible according to the scope rules of the
7366 programming language from the point of execution in that frame
7367 @end itemize
7368
7369 @noindent This means that in the function
7370
7371 @smallexample
7372 foo (a)
7373 int a;
7374 @{
7375 bar (a);
7376 @{
7377 int b = test ();
7378 bar (b);
7379 @}
7380 @}
7381 @end smallexample
7382
7383 @noindent
7384 you can examine and use the variable @code{a} whenever your program is
7385 executing within the function @code{foo}, but you can only use or
7386 examine the variable @code{b} while your program is executing inside
7387 the block where @code{b} is declared.
7388
7389 @cindex variable name conflict
7390 There is an exception: you can refer to a variable or function whose
7391 scope is a single source file even if the current execution point is not
7392 in this file. But it is possible to have more than one such variable or
7393 function with the same name (in different source files). If that
7394 happens, referring to that name has unpredictable effects. If you wish,
7395 you can specify a static variable in a particular function or file by
7396 using the colon-colon (@code{::}) notation:
7397
7398 @cindex colon-colon, context for variables/functions
7399 @ifnotinfo
7400 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
7401 @cindex @code{::}, context for variables/functions
7402 @end ifnotinfo
7403 @smallexample
7404 @var{file}::@var{variable}
7405 @var{function}::@var{variable}
7406 @end smallexample
7407
7408 @noindent
7409 Here @var{file} or @var{function} is the name of the context for the
7410 static @var{variable}. In the case of file names, you can use quotes to
7411 make sure @value{GDBN} parses the file name as a single word---for example,
7412 to print a global value of @code{x} defined in @file{f2.c}:
7413
7414 @smallexample
7415 (@value{GDBP}) p 'f2.c'::x
7416 @end smallexample
7417
7418 The @code{::} notation is normally used for referring to
7419 static variables, since you typically disambiguate uses of local variables
7420 in functions by selecting the appropriate frame and using the
7421 simple name of the variable. However, you may also use this notation
7422 to refer to local variables in frames enclosing the selected frame:
7423
7424 @smallexample
7425 void
7426 foo (int a)
7427 @{
7428 if (a < 10)
7429 bar (a);
7430 else
7431 process (a); /* Stop here */
7432 @}
7433
7434 int
7435 bar (int a)
7436 @{
7437 foo (a + 5);
7438 @}
7439 @end smallexample
7440
7441 @noindent
7442 For example, if there is a breakpoint at the commented line,
7443 here is what you might see
7444 when the program stops after executing the call @code{bar(0)}:
7445
7446 @smallexample
7447 (@value{GDBP}) p a
7448 $1 = 10
7449 (@value{GDBP}) p bar::a
7450 $2 = 5
7451 (@value{GDBP}) up 2
7452 #2 0x080483d0 in foo (a=5) at foobar.c:12
7453 (@value{GDBP}) p a
7454 $3 = 5
7455 (@value{GDBP}) p bar::a
7456 $4 = 0
7457 @end smallexample
7458
7459 @cindex C@t{++} scope resolution
7460 These uses of @samp{::} are very rarely in conflict with the very similar
7461 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
7462 scope resolution operator in @value{GDBN} expressions.
7463 @c FIXME: Um, so what happens in one of those rare cases where it's in
7464 @c conflict?? --mew
7465
7466 @cindex wrong values
7467 @cindex variable values, wrong
7468 @cindex function entry/exit, wrong values of variables
7469 @cindex optimized code, wrong values of variables
7470 @quotation
7471 @emph{Warning:} Occasionally, a local variable may appear to have the
7472 wrong value at certain points in a function---just after entry to a new
7473 scope, and just before exit.
7474 @end quotation
7475 You may see this problem when you are stepping by machine instructions.
7476 This is because, on most machines, it takes more than one instruction to
7477 set up a stack frame (including local variable definitions); if you are
7478 stepping by machine instructions, variables may appear to have the wrong
7479 values until the stack frame is completely built. On exit, it usually
7480 also takes more than one machine instruction to destroy a stack frame;
7481 after you begin stepping through that group of instructions, local
7482 variable definitions may be gone.
7483
7484 This may also happen when the compiler does significant optimizations.
7485 To be sure of always seeing accurate values, turn off all optimization
7486 when compiling.
7487
7488 @cindex ``No symbol "foo" in current context''
7489 Another possible effect of compiler optimizations is to optimize
7490 unused variables out of existence, or assign variables to registers (as
7491 opposed to memory addresses). Depending on the support for such cases
7492 offered by the debug info format used by the compiler, @value{GDBN}
7493 might not be able to display values for such local variables. If that
7494 happens, @value{GDBN} will print a message like this:
7495
7496 @smallexample
7497 No symbol "foo" in current context.
7498 @end smallexample
7499
7500 To solve such problems, either recompile without optimizations, or use a
7501 different debug info format, if the compiler supports several such
7502 formats. @xref{Compilation}, for more information on choosing compiler
7503 options. @xref{C, ,C and C@t{++}}, for more information about debug
7504 info formats that are best suited to C@t{++} programs.
7505
7506 If you ask to print an object whose contents are unknown to
7507 @value{GDBN}, e.g., because its data type is not completely specified
7508 by the debug information, @value{GDBN} will say @samp{<incomplete
7509 type>}. @xref{Symbols, incomplete type}, for more about this.
7510
7511 If you append @kbd{@@entry} string to a function parameter name you get its
7512 value at the time the function got called. If the value is not available an
7513 error message is printed. Entry values are available only with some compilers.
7514 Entry values are normally also printed at the function parameter list according
7515 to @ref{set print entry-values}.
7516
7517 @smallexample
7518 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
7519 29 i++;
7520 (gdb) next
7521 30 e (i);
7522 (gdb) print i
7523 $1 = 31
7524 (gdb) print i@@entry
7525 $2 = 30
7526 @end smallexample
7527
7528 Strings are identified as arrays of @code{char} values without specified
7529 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
7530 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
7531 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
7532 defines literal string type @code{"char"} as @code{char} without a sign.
7533 For program code
7534
7535 @smallexample
7536 char var0[] = "A";
7537 signed char var1[] = "A";
7538 @end smallexample
7539
7540 You get during debugging
7541 @smallexample
7542 (gdb) print var0
7543 $1 = "A"
7544 (gdb) print var1
7545 $2 = @{65 'A', 0 '\0'@}
7546 @end smallexample
7547
7548 @node Arrays
7549 @section Artificial Arrays
7550
7551 @cindex artificial array
7552 @cindex arrays
7553 @kindex @@@r{, referencing memory as an array}
7554 It is often useful to print out several successive objects of the
7555 same type in memory; a section of an array, or an array of
7556 dynamically determined size for which only a pointer exists in the
7557 program.
7558
7559 You can do this by referring to a contiguous span of memory as an
7560 @dfn{artificial array}, using the binary operator @samp{@@}. The left
7561 operand of @samp{@@} should be the first element of the desired array
7562 and be an individual object. The right operand should be the desired length
7563 of the array. The result is an array value whose elements are all of
7564 the type of the left argument. The first element is actually the left
7565 argument; the second element comes from bytes of memory immediately
7566 following those that hold the first element, and so on. Here is an
7567 example. If a program says
7568
7569 @smallexample
7570 int *array = (int *) malloc (len * sizeof (int));
7571 @end smallexample
7572
7573 @noindent
7574 you can print the contents of @code{array} with
7575
7576 @smallexample
7577 p *array@@len
7578 @end smallexample
7579
7580 The left operand of @samp{@@} must reside in memory. Array values made
7581 with @samp{@@} in this way behave just like other arrays in terms of
7582 subscripting, and are coerced to pointers when used in expressions.
7583 Artificial arrays most often appear in expressions via the value history
7584 (@pxref{Value History, ,Value History}), after printing one out.
7585
7586 Another way to create an artificial array is to use a cast.
7587 This re-interprets a value as if it were an array.
7588 The value need not be in memory:
7589 @smallexample
7590 (@value{GDBP}) p/x (short[2])0x12345678
7591 $1 = @{0x1234, 0x5678@}
7592 @end smallexample
7593
7594 As a convenience, if you leave the array length out (as in
7595 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
7596 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
7597 @smallexample
7598 (@value{GDBP}) p/x (short[])0x12345678
7599 $2 = @{0x1234, 0x5678@}
7600 @end smallexample
7601
7602 Sometimes the artificial array mechanism is not quite enough; in
7603 moderately complex data structures, the elements of interest may not
7604 actually be adjacent---for example, if you are interested in the values
7605 of pointers in an array. One useful work-around in this situation is
7606 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
7607 Variables}) as a counter in an expression that prints the first
7608 interesting value, and then repeat that expression via @key{RET}. For
7609 instance, suppose you have an array @code{dtab} of pointers to
7610 structures, and you are interested in the values of a field @code{fv}
7611 in each structure. Here is an example of what you might type:
7612
7613 @smallexample
7614 set $i = 0
7615 p dtab[$i++]->fv
7616 @key{RET}
7617 @key{RET}
7618 @dots{}
7619 @end smallexample
7620
7621 @node Output Formats
7622 @section Output Formats
7623
7624 @cindex formatted output
7625 @cindex output formats
7626 By default, @value{GDBN} prints a value according to its data type. Sometimes
7627 this is not what you want. For example, you might want to print a number
7628 in hex, or a pointer in decimal. Or you might want to view data in memory
7629 at a certain address as a character string or as an instruction. To do
7630 these things, specify an @dfn{output format} when you print a value.
7631
7632 The simplest use of output formats is to say how to print a value
7633 already computed. This is done by starting the arguments of the
7634 @code{print} command with a slash and a format letter. The format
7635 letters supported are:
7636
7637 @table @code
7638 @item x
7639 Regard the bits of the value as an integer, and print the integer in
7640 hexadecimal.
7641
7642 @item d
7643 Print as integer in signed decimal.
7644
7645 @item u
7646 Print as integer in unsigned decimal.
7647
7648 @item o
7649 Print as integer in octal.
7650
7651 @item t
7652 Print as integer in binary. The letter @samp{t} stands for ``two''.
7653 @footnote{@samp{b} cannot be used because these format letters are also
7654 used with the @code{x} command, where @samp{b} stands for ``byte'';
7655 see @ref{Memory,,Examining Memory}.}
7656
7657 @item a
7658 @cindex unknown address, locating
7659 @cindex locate address
7660 Print as an address, both absolute in hexadecimal and as an offset from
7661 the nearest preceding symbol. You can use this format used to discover
7662 where (in what function) an unknown address is located:
7663
7664 @smallexample
7665 (@value{GDBP}) p/a 0x54320
7666 $3 = 0x54320 <_initialize_vx+396>
7667 @end smallexample
7668
7669 @noindent
7670 The command @code{info symbol 0x54320} yields similar results.
7671 @xref{Symbols, info symbol}.
7672
7673 @item c
7674 Regard as an integer and print it as a character constant. This
7675 prints both the numerical value and its character representation. The
7676 character representation is replaced with the octal escape @samp{\nnn}
7677 for characters outside the 7-bit @sc{ascii} range.
7678
7679 Without this format, @value{GDBN} displays @code{char},
7680 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
7681 constants. Single-byte members of vectors are displayed as integer
7682 data.
7683
7684 @item f
7685 Regard the bits of the value as a floating point number and print
7686 using typical floating point syntax.
7687
7688 @item s
7689 @cindex printing strings
7690 @cindex printing byte arrays
7691 Regard as a string, if possible. With this format, pointers to single-byte
7692 data are displayed as null-terminated strings and arrays of single-byte data
7693 are displayed as fixed-length strings. Other values are displayed in their
7694 natural types.
7695
7696 Without this format, @value{GDBN} displays pointers to and arrays of
7697 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
7698 strings. Single-byte members of a vector are displayed as an integer
7699 array.
7700
7701 @item r
7702 @cindex raw printing
7703 Print using the @samp{raw} formatting. By default, @value{GDBN} will
7704 use a Python-based pretty-printer, if one is available (@pxref{Pretty
7705 Printing}). This typically results in a higher-level display of the
7706 value's contents. The @samp{r} format bypasses any Python
7707 pretty-printer which might exist.
7708 @end table
7709
7710 For example, to print the program counter in hex (@pxref{Registers}), type
7711
7712 @smallexample
7713 p/x $pc
7714 @end smallexample
7715
7716 @noindent
7717 Note that no space is required before the slash; this is because command
7718 names in @value{GDBN} cannot contain a slash.
7719
7720 To reprint the last value in the value history with a different format,
7721 you can use the @code{print} command with just a format and no
7722 expression. For example, @samp{p/x} reprints the last value in hex.
7723
7724 @node Memory
7725 @section Examining Memory
7726
7727 You can use the command @code{x} (for ``examine'') to examine memory in
7728 any of several formats, independently of your program's data types.
7729
7730 @cindex examining memory
7731 @table @code
7732 @kindex x @r{(examine memory)}
7733 @item x/@var{nfu} @var{addr}
7734 @itemx x @var{addr}
7735 @itemx x
7736 Use the @code{x} command to examine memory.
7737 @end table
7738
7739 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
7740 much memory to display and how to format it; @var{addr} is an
7741 expression giving the address where you want to start displaying memory.
7742 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
7743 Several commands set convenient defaults for @var{addr}.
7744
7745 @table @r
7746 @item @var{n}, the repeat count
7747 The repeat count is a decimal integer; the default is 1. It specifies
7748 how much memory (counting by units @var{u}) to display.
7749 @c This really is **decimal**; unaffected by 'set radix' as of GDB
7750 @c 4.1.2.
7751
7752 @item @var{f}, the display format
7753 The display format is one of the formats used by @code{print}
7754 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
7755 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
7756 The default is @samp{x} (hexadecimal) initially. The default changes
7757 each time you use either @code{x} or @code{print}.
7758
7759 @item @var{u}, the unit size
7760 The unit size is any of
7761
7762 @table @code
7763 @item b
7764 Bytes.
7765 @item h
7766 Halfwords (two bytes).
7767 @item w
7768 Words (four bytes). This is the initial default.
7769 @item g
7770 Giant words (eight bytes).
7771 @end table
7772
7773 Each time you specify a unit size with @code{x}, that size becomes the
7774 default unit the next time you use @code{x}. For the @samp{i} format,
7775 the unit size is ignored and is normally not written. For the @samp{s} format,
7776 the unit size defaults to @samp{b}, unless it is explicitly given.
7777 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
7778 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
7779 Note that the results depend on the programming language of the
7780 current compilation unit. If the language is C, the @samp{s}
7781 modifier will use the UTF-16 encoding while @samp{w} will use
7782 UTF-32. The encoding is set by the programming language and cannot
7783 be altered.
7784
7785 @item @var{addr}, starting display address
7786 @var{addr} is the address where you want @value{GDBN} to begin displaying
7787 memory. The expression need not have a pointer value (though it may);
7788 it is always interpreted as an integer address of a byte of memory.
7789 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
7790 @var{addr} is usually just after the last address examined---but several
7791 other commands also set the default address: @code{info breakpoints} (to
7792 the address of the last breakpoint listed), @code{info line} (to the
7793 starting address of a line), and @code{print} (if you use it to display
7794 a value from memory).
7795 @end table
7796
7797 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
7798 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
7799 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
7800 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
7801 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
7802
7803 Since the letters indicating unit sizes are all distinct from the
7804 letters specifying output formats, you do not have to remember whether
7805 unit size or format comes first; either order works. The output
7806 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
7807 (However, the count @var{n} must come first; @samp{wx4} does not work.)
7808
7809 Even though the unit size @var{u} is ignored for the formats @samp{s}
7810 and @samp{i}, you might still want to use a count @var{n}; for example,
7811 @samp{3i} specifies that you want to see three machine instructions,
7812 including any operands. For convenience, especially when used with
7813 the @code{display} command, the @samp{i} format also prints branch delay
7814 slot instructions, if any, beyond the count specified, which immediately
7815 follow the last instruction that is within the count. The command
7816 @code{disassemble} gives an alternative way of inspecting machine
7817 instructions; see @ref{Machine Code,,Source and Machine Code}.
7818
7819 All the defaults for the arguments to @code{x} are designed to make it
7820 easy to continue scanning memory with minimal specifications each time
7821 you use @code{x}. For example, after you have inspected three machine
7822 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
7823 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
7824 the repeat count @var{n} is used again; the other arguments default as
7825 for successive uses of @code{x}.
7826
7827 When examining machine instructions, the instruction at current program
7828 counter is shown with a @code{=>} marker. For example:
7829
7830 @smallexample
7831 (@value{GDBP}) x/5i $pc-6
7832 0x804837f <main+11>: mov %esp,%ebp
7833 0x8048381 <main+13>: push %ecx
7834 0x8048382 <main+14>: sub $0x4,%esp
7835 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
7836 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
7837 @end smallexample
7838
7839 @cindex @code{$_}, @code{$__}, and value history
7840 The addresses and contents printed by the @code{x} command are not saved
7841 in the value history because there is often too much of them and they
7842 would get in the way. Instead, @value{GDBN} makes these values available for
7843 subsequent use in expressions as values of the convenience variables
7844 @code{$_} and @code{$__}. After an @code{x} command, the last address
7845 examined is available for use in expressions in the convenience variable
7846 @code{$_}. The contents of that address, as examined, are available in
7847 the convenience variable @code{$__}.
7848
7849 If the @code{x} command has a repeat count, the address and contents saved
7850 are from the last memory unit printed; this is not the same as the last
7851 address printed if several units were printed on the last line of output.
7852
7853 @cindex remote memory comparison
7854 @cindex verify remote memory image
7855 When you are debugging a program running on a remote target machine
7856 (@pxref{Remote Debugging}), you may wish to verify the program's image in the
7857 remote machine's memory against the executable file you downloaded to
7858 the target. The @code{compare-sections} command is provided for such
7859 situations.
7860
7861 @table @code
7862 @kindex compare-sections
7863 @item compare-sections @r{[}@var{section-name}@r{]}
7864 Compare the data of a loadable section @var{section-name} in the
7865 executable file of the program being debugged with the same section in
7866 the remote machine's memory, and report any mismatches. With no
7867 arguments, compares all loadable sections. This command's
7868 availability depends on the target's support for the @code{"qCRC"}
7869 remote request.
7870 @end table
7871
7872 @node Auto Display
7873 @section Automatic Display
7874 @cindex automatic display
7875 @cindex display of expressions
7876
7877 If you find that you want to print the value of an expression frequently
7878 (to see how it changes), you might want to add it to the @dfn{automatic
7879 display list} so that @value{GDBN} prints its value each time your program stops.
7880 Each expression added to the list is given a number to identify it;
7881 to remove an expression from the list, you specify that number.
7882 The automatic display looks like this:
7883
7884 @smallexample
7885 2: foo = 38
7886 3: bar[5] = (struct hack *) 0x3804
7887 @end smallexample
7888
7889 @noindent
7890 This display shows item numbers, expressions and their current values. As with
7891 displays you request manually using @code{x} or @code{print}, you can
7892 specify the output format you prefer; in fact, @code{display} decides
7893 whether to use @code{print} or @code{x} depending your format
7894 specification---it uses @code{x} if you specify either the @samp{i}
7895 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
7896
7897 @table @code
7898 @kindex display
7899 @item display @var{expr}
7900 Add the expression @var{expr} to the list of expressions to display
7901 each time your program stops. @xref{Expressions, ,Expressions}.
7902
7903 @code{display} does not repeat if you press @key{RET} again after using it.
7904
7905 @item display/@var{fmt} @var{expr}
7906 For @var{fmt} specifying only a display format and not a size or
7907 count, add the expression @var{expr} to the auto-display list but
7908 arrange to display it each time in the specified format @var{fmt}.
7909 @xref{Output Formats,,Output Formats}.
7910
7911 @item display/@var{fmt} @var{addr}
7912 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
7913 number of units, add the expression @var{addr} as a memory address to
7914 be examined each time your program stops. Examining means in effect
7915 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
7916 @end table
7917
7918 For example, @samp{display/i $pc} can be helpful, to see the machine
7919 instruction about to be executed each time execution stops (@samp{$pc}
7920 is a common name for the program counter; @pxref{Registers, ,Registers}).
7921
7922 @table @code
7923 @kindex delete display
7924 @kindex undisplay
7925 @item undisplay @var{dnums}@dots{}
7926 @itemx delete display @var{dnums}@dots{}
7927 Remove items from the list of expressions to display. Specify the
7928 numbers of the displays that you want affected with the command
7929 argument @var{dnums}. It can be a single display number, one of the
7930 numbers shown in the first field of the @samp{info display} display;
7931 or it could be a range of display numbers, as in @code{2-4}.
7932
7933 @code{undisplay} does not repeat if you press @key{RET} after using it.
7934 (Otherwise you would just get the error @samp{No display number @dots{}}.)
7935
7936 @kindex disable display
7937 @item disable display @var{dnums}@dots{}
7938 Disable the display of item numbers @var{dnums}. A disabled display
7939 item is not printed automatically, but is not forgotten. It may be
7940 enabled again later. Specify the numbers of the displays that you
7941 want affected with the command argument @var{dnums}. It can be a
7942 single display number, one of the numbers shown in the first field of
7943 the @samp{info display} display; or it could be a range of display
7944 numbers, as in @code{2-4}.
7945
7946 @kindex enable display
7947 @item enable display @var{dnums}@dots{}
7948 Enable display of item numbers @var{dnums}. It becomes effective once
7949 again in auto display of its expression, until you specify otherwise.
7950 Specify the numbers of the displays that you want affected with the
7951 command argument @var{dnums}. It can be a single display number, one
7952 of the numbers shown in the first field of the @samp{info display}
7953 display; or it could be a range of display numbers, as in @code{2-4}.
7954
7955 @item display
7956 Display the current values of the expressions on the list, just as is
7957 done when your program stops.
7958
7959 @kindex info display
7960 @item info display
7961 Print the list of expressions previously set up to display
7962 automatically, each one with its item number, but without showing the
7963 values. This includes disabled expressions, which are marked as such.
7964 It also includes expressions which would not be displayed right now
7965 because they refer to automatic variables not currently available.
7966 @end table
7967
7968 @cindex display disabled out of scope
7969 If a display expression refers to local variables, then it does not make
7970 sense outside the lexical context for which it was set up. Such an
7971 expression is disabled when execution enters a context where one of its
7972 variables is not defined. For example, if you give the command
7973 @code{display last_char} while inside a function with an argument
7974 @code{last_char}, @value{GDBN} displays this argument while your program
7975 continues to stop inside that function. When it stops elsewhere---where
7976 there is no variable @code{last_char}---the display is disabled
7977 automatically. The next time your program stops where @code{last_char}
7978 is meaningful, you can enable the display expression once again.
7979
7980 @node Print Settings
7981 @section Print Settings
7982
7983 @cindex format options
7984 @cindex print settings
7985 @value{GDBN} provides the following ways to control how arrays, structures,
7986 and symbols are printed.
7987
7988 @noindent
7989 These settings are useful for debugging programs in any language:
7990
7991 @table @code
7992 @kindex set print
7993 @item set print address
7994 @itemx set print address on
7995 @cindex print/don't print memory addresses
7996 @value{GDBN} prints memory addresses showing the location of stack
7997 traces, structure values, pointer values, breakpoints, and so forth,
7998 even when it also displays the contents of those addresses. The default
7999 is @code{on}. For example, this is what a stack frame display looks like with
8000 @code{set print address on}:
8001
8002 @smallexample
8003 @group
8004 (@value{GDBP}) f
8005 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8006 at input.c:530
8007 530 if (lquote != def_lquote)
8008 @end group
8009 @end smallexample
8010
8011 @item set print address off
8012 Do not print addresses when displaying their contents. For example,
8013 this is the same stack frame displayed with @code{set print address off}:
8014
8015 @smallexample
8016 @group
8017 (@value{GDBP}) set print addr off
8018 (@value{GDBP}) f
8019 #0 set_quotes (lq="<<", rq=">>") at input.c:530
8020 530 if (lquote != def_lquote)
8021 @end group
8022 @end smallexample
8023
8024 You can use @samp{set print address off} to eliminate all machine
8025 dependent displays from the @value{GDBN} interface. For example, with
8026 @code{print address off}, you should get the same text for backtraces on
8027 all machines---whether or not they involve pointer arguments.
8028
8029 @kindex show print
8030 @item show print address
8031 Show whether or not addresses are to be printed.
8032 @end table
8033
8034 When @value{GDBN} prints a symbolic address, it normally prints the
8035 closest earlier symbol plus an offset. If that symbol does not uniquely
8036 identify the address (for example, it is a name whose scope is a single
8037 source file), you may need to clarify. One way to do this is with
8038 @code{info line}, for example @samp{info line *0x4537}. Alternately,
8039 you can set @value{GDBN} to print the source file and line number when
8040 it prints a symbolic address:
8041
8042 @table @code
8043 @item set print symbol-filename on
8044 @cindex source file and line of a symbol
8045 @cindex symbol, source file and line
8046 Tell @value{GDBN} to print the source file name and line number of a
8047 symbol in the symbolic form of an address.
8048
8049 @item set print symbol-filename off
8050 Do not print source file name and line number of a symbol. This is the
8051 default.
8052
8053 @item show print symbol-filename
8054 Show whether or not @value{GDBN} will print the source file name and
8055 line number of a symbol in the symbolic form of an address.
8056 @end table
8057
8058 Another situation where it is helpful to show symbol filenames and line
8059 numbers is when disassembling code; @value{GDBN} shows you the line
8060 number and source file that corresponds to each instruction.
8061
8062 Also, you may wish to see the symbolic form only if the address being
8063 printed is reasonably close to the closest earlier symbol:
8064
8065 @table @code
8066 @item set print max-symbolic-offset @var{max-offset}
8067 @cindex maximum value for offset of closest symbol
8068 Tell @value{GDBN} to only display the symbolic form of an address if the
8069 offset between the closest earlier symbol and the address is less than
8070 @var{max-offset}. The default is 0, which tells @value{GDBN}
8071 to always print the symbolic form of an address if any symbol precedes it.
8072
8073 @item show print max-symbolic-offset
8074 Ask how large the maximum offset is that @value{GDBN} prints in a
8075 symbolic address.
8076 @end table
8077
8078 @cindex wild pointer, interpreting
8079 @cindex pointer, finding referent
8080 If you have a pointer and you are not sure where it points, try
8081 @samp{set print symbol-filename on}. Then you can determine the name
8082 and source file location of the variable where it points, using
8083 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
8084 For example, here @value{GDBN} shows that a variable @code{ptt} points
8085 at another variable @code{t}, defined in @file{hi2.c}:
8086
8087 @smallexample
8088 (@value{GDBP}) set print symbol-filename on
8089 (@value{GDBP}) p/a ptt
8090 $4 = 0xe008 <t in hi2.c>
8091 @end smallexample
8092
8093 @quotation
8094 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
8095 does not show the symbol name and filename of the referent, even with
8096 the appropriate @code{set print} options turned on.
8097 @end quotation
8098
8099 Other settings control how different kinds of objects are printed:
8100
8101 @table @code
8102 @item set print array
8103 @itemx set print array on
8104 @cindex pretty print arrays
8105 Pretty print arrays. This format is more convenient to read,
8106 but uses more space. The default is off.
8107
8108 @item set print array off
8109 Return to compressed format for arrays.
8110
8111 @item show print array
8112 Show whether compressed or pretty format is selected for displaying
8113 arrays.
8114
8115 @cindex print array indexes
8116 @item set print array-indexes
8117 @itemx set print array-indexes on
8118 Print the index of each element when displaying arrays. May be more
8119 convenient to locate a given element in the array or quickly find the
8120 index of a given element in that printed array. The default is off.
8121
8122 @item set print array-indexes off
8123 Stop printing element indexes when displaying arrays.
8124
8125 @item show print array-indexes
8126 Show whether the index of each element is printed when displaying
8127 arrays.
8128
8129 @item set print elements @var{number-of-elements}
8130 @cindex number of array elements to print
8131 @cindex limit on number of printed array elements
8132 Set a limit on how many elements of an array @value{GDBN} will print.
8133 If @value{GDBN} is printing a large array, it stops printing after it has
8134 printed the number of elements set by the @code{set print elements} command.
8135 This limit also applies to the display of strings.
8136 When @value{GDBN} starts, this limit is set to 200.
8137 Setting @var{number-of-elements} to zero means that the printing is unlimited.
8138
8139 @item show print elements
8140 Display the number of elements of a large array that @value{GDBN} will print.
8141 If the number is 0, then the printing is unlimited.
8142
8143 @item set print frame-arguments @var{value}
8144 @kindex set print frame-arguments
8145 @cindex printing frame argument values
8146 @cindex print all frame argument values
8147 @cindex print frame argument values for scalars only
8148 @cindex do not print frame argument values
8149 This command allows to control how the values of arguments are printed
8150 when the debugger prints a frame (@pxref{Frames}). The possible
8151 values are:
8152
8153 @table @code
8154 @item all
8155 The values of all arguments are printed.
8156
8157 @item scalars
8158 Print the value of an argument only if it is a scalar. The value of more
8159 complex arguments such as arrays, structures, unions, etc, is replaced
8160 by @code{@dots{}}. This is the default. Here is an example where
8161 only scalar arguments are shown:
8162
8163 @smallexample
8164 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
8165 at frame-args.c:23
8166 @end smallexample
8167
8168 @item none
8169 None of the argument values are printed. Instead, the value of each argument
8170 is replaced by @code{@dots{}}. In this case, the example above now becomes:
8171
8172 @smallexample
8173 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
8174 at frame-args.c:23
8175 @end smallexample
8176 @end table
8177
8178 By default, only scalar arguments are printed. This command can be used
8179 to configure the debugger to print the value of all arguments, regardless
8180 of their type. However, it is often advantageous to not print the value
8181 of more complex parameters. For instance, it reduces the amount of
8182 information printed in each frame, making the backtrace more readable.
8183 Also, it improves performance when displaying Ada frames, because
8184 the computation of large arguments can sometimes be CPU-intensive,
8185 especially in large applications. Setting @code{print frame-arguments}
8186 to @code{scalars} (the default) or @code{none} avoids this computation,
8187 thus speeding up the display of each Ada frame.
8188
8189 @item show print frame-arguments
8190 Show how the value of arguments should be displayed when printing a frame.
8191
8192 @anchor{set print entry-values}
8193 @item set print entry-values @var{value}
8194 @kindex set print entry-values
8195 Set printing of frame argument values at function entry. In some cases
8196 @value{GDBN} can determine the value of function argument which was passed by
8197 the function caller, even if the value was modified inside the called function
8198 and therefore is different. With optimized code, the current value could be
8199 unavailable, but the entry value may still be known.
8200
8201 The default value is @code{default} (see below for its description). Older
8202 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
8203 this feature will behave in the @code{default} setting the same way as with the
8204 @code{no} setting.
8205
8206 This functionality is currently supported only by DWARF 2 debugging format and
8207 the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
8208 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
8209 this information.
8210
8211 The @var{value} parameter can be one of the following:
8212
8213 @table @code
8214 @item no
8215 Print only actual parameter values, never print values from function entry
8216 point.
8217 @smallexample
8218 #0 equal (val=5)
8219 #0 different (val=6)
8220 #0 lost (val=<optimized out>)
8221 #0 born (val=10)
8222 #0 invalid (val=<optimized out>)
8223 @end smallexample
8224
8225 @item only
8226 Print only parameter values from function entry point. The actual parameter
8227 values are never printed.
8228 @smallexample
8229 #0 equal (val@@entry=5)
8230 #0 different (val@@entry=5)
8231 #0 lost (val@@entry=5)
8232 #0 born (val@@entry=<optimized out>)
8233 #0 invalid (val@@entry=<optimized out>)
8234 @end smallexample
8235
8236 @item preferred
8237 Print only parameter values from function entry point. If value from function
8238 entry point is not known while the actual value is known, print the actual
8239 value for such parameter.
8240 @smallexample
8241 #0 equal (val@@entry=5)
8242 #0 different (val@@entry=5)
8243 #0 lost (val@@entry=5)
8244 #0 born (val=10)
8245 #0 invalid (val@@entry=<optimized out>)
8246 @end smallexample
8247
8248 @item if-needed
8249 Print actual parameter values. If actual parameter value is not known while
8250 value from function entry point is known, print the entry point value for such
8251 parameter.
8252 @smallexample
8253 #0 equal (val=5)
8254 #0 different (val=6)
8255 #0 lost (val@@entry=5)
8256 #0 born (val=10)
8257 #0 invalid (val=<optimized out>)
8258 @end smallexample
8259
8260 @item both
8261 Always print both the actual parameter value and its value from function entry
8262 point, even if values of one or both are not available due to compiler
8263 optimizations.
8264 @smallexample
8265 #0 equal (val=5, val@@entry=5)
8266 #0 different (val=6, val@@entry=5)
8267 #0 lost (val=<optimized out>, val@@entry=5)
8268 #0 born (val=10, val@@entry=<optimized out>)
8269 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
8270 @end smallexample
8271
8272 @item compact
8273 Print the actual parameter value if it is known and also its value from
8274 function entry point if it is known. If neither is known, print for the actual
8275 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
8276 values are known and identical, print the shortened
8277 @code{param=param@@entry=VALUE} notation.
8278 @smallexample
8279 #0 equal (val=val@@entry=5)
8280 #0 different (val=6, val@@entry=5)
8281 #0 lost (val@@entry=5)
8282 #0 born (val=10)
8283 #0 invalid (val=<optimized out>)
8284 @end smallexample
8285
8286 @item default
8287 Always print the actual parameter value. Print also its value from function
8288 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
8289 if both values are known and identical, print the shortened
8290 @code{param=param@@entry=VALUE} notation.
8291 @smallexample
8292 #0 equal (val=val@@entry=5)
8293 #0 different (val=6, val@@entry=5)
8294 #0 lost (val=<optimized out>, val@@entry=5)
8295 #0 born (val=10)
8296 #0 invalid (val=<optimized out>)
8297 @end smallexample
8298 @end table
8299
8300 For analysis messages on possible failures of frame argument values at function
8301 entry resolution see @ref{set debug entry-values}.
8302
8303 @item show print entry-values
8304 Show the method being used for printing of frame argument values at function
8305 entry.
8306
8307 @item set print repeats
8308 @cindex repeated array elements
8309 Set the threshold for suppressing display of repeated array
8310 elements. When the number of consecutive identical elements of an
8311 array exceeds the threshold, @value{GDBN} prints the string
8312 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
8313 identical repetitions, instead of displaying the identical elements
8314 themselves. Setting the threshold to zero will cause all elements to
8315 be individually printed. The default threshold is 10.
8316
8317 @item show print repeats
8318 Display the current threshold for printing repeated identical
8319 elements.
8320
8321 @item set print null-stop
8322 @cindex @sc{null} elements in arrays
8323 Cause @value{GDBN} to stop printing the characters of an array when the first
8324 @sc{null} is encountered. This is useful when large arrays actually
8325 contain only short strings.
8326 The default is off.
8327
8328 @item show print null-stop
8329 Show whether @value{GDBN} stops printing an array on the first
8330 @sc{null} character.
8331
8332 @item set print pretty on
8333 @cindex print structures in indented form
8334 @cindex indentation in structure display
8335 Cause @value{GDBN} to print structures in an indented format with one member
8336 per line, like this:
8337
8338 @smallexample
8339 @group
8340 $1 = @{
8341 next = 0x0,
8342 flags = @{
8343 sweet = 1,
8344 sour = 1
8345 @},
8346 meat = 0x54 "Pork"
8347 @}
8348 @end group
8349 @end smallexample
8350
8351 @item set print pretty off
8352 Cause @value{GDBN} to print structures in a compact format, like this:
8353
8354 @smallexample
8355 @group
8356 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
8357 meat = 0x54 "Pork"@}
8358 @end group
8359 @end smallexample
8360
8361 @noindent
8362 This is the default format.
8363
8364 @item show print pretty
8365 Show which format @value{GDBN} is using to print structures.
8366
8367 @item set print sevenbit-strings on
8368 @cindex eight-bit characters in strings
8369 @cindex octal escapes in strings
8370 Print using only seven-bit characters; if this option is set,
8371 @value{GDBN} displays any eight-bit characters (in strings or
8372 character values) using the notation @code{\}@var{nnn}. This setting is
8373 best if you are working in English (@sc{ascii}) and you use the
8374 high-order bit of characters as a marker or ``meta'' bit.
8375
8376 @item set print sevenbit-strings off
8377 Print full eight-bit characters. This allows the use of more
8378 international character sets, and is the default.
8379
8380 @item show print sevenbit-strings
8381 Show whether or not @value{GDBN} is printing only seven-bit characters.
8382
8383 @item set print union on
8384 @cindex unions in structures, printing
8385 Tell @value{GDBN} to print unions which are contained in structures
8386 and other unions. This is the default setting.
8387
8388 @item set print union off
8389 Tell @value{GDBN} not to print unions which are contained in
8390 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
8391 instead.
8392
8393 @item show print union
8394 Ask @value{GDBN} whether or not it will print unions which are contained in
8395 structures and other unions.
8396
8397 For example, given the declarations
8398
8399 @smallexample
8400 typedef enum @{Tree, Bug@} Species;
8401 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
8402 typedef enum @{Caterpillar, Cocoon, Butterfly@}
8403 Bug_forms;
8404
8405 struct thing @{
8406 Species it;
8407 union @{
8408 Tree_forms tree;
8409 Bug_forms bug;
8410 @} form;
8411 @};
8412
8413 struct thing foo = @{Tree, @{Acorn@}@};
8414 @end smallexample
8415
8416 @noindent
8417 with @code{set print union on} in effect @samp{p foo} would print
8418
8419 @smallexample
8420 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
8421 @end smallexample
8422
8423 @noindent
8424 and with @code{set print union off} in effect it would print
8425
8426 @smallexample
8427 $1 = @{it = Tree, form = @{...@}@}
8428 @end smallexample
8429
8430 @noindent
8431 @code{set print union} affects programs written in C-like languages
8432 and in Pascal.
8433 @end table
8434
8435 @need 1000
8436 @noindent
8437 These settings are of interest when debugging C@t{++} programs:
8438
8439 @table @code
8440 @cindex demangling C@t{++} names
8441 @item set print demangle
8442 @itemx set print demangle on
8443 Print C@t{++} names in their source form rather than in the encoded
8444 (``mangled'') form passed to the assembler and linker for type-safe
8445 linkage. The default is on.
8446
8447 @item show print demangle
8448 Show whether C@t{++} names are printed in mangled or demangled form.
8449
8450 @item set print asm-demangle
8451 @itemx set print asm-demangle on
8452 Print C@t{++} names in their source form rather than their mangled form, even
8453 in assembler code printouts such as instruction disassemblies.
8454 The default is off.
8455
8456 @item show print asm-demangle
8457 Show whether C@t{++} names in assembly listings are printed in mangled
8458 or demangled form.
8459
8460 @cindex C@t{++} symbol decoding style
8461 @cindex symbol decoding style, C@t{++}
8462 @kindex set demangle-style
8463 @item set demangle-style @var{style}
8464 Choose among several encoding schemes used by different compilers to
8465 represent C@t{++} names. The choices for @var{style} are currently:
8466
8467 @table @code
8468 @item auto
8469 Allow @value{GDBN} to choose a decoding style by inspecting your program.
8470
8471 @item gnu
8472 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
8473 This is the default.
8474
8475 @item hp
8476 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
8477
8478 @item lucid
8479 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
8480
8481 @item arm
8482 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
8483 @strong{Warning:} this setting alone is not sufficient to allow
8484 debugging @code{cfront}-generated executables. @value{GDBN} would
8485 require further enhancement to permit that.
8486
8487 @end table
8488 If you omit @var{style}, you will see a list of possible formats.
8489
8490 @item show demangle-style
8491 Display the encoding style currently in use for decoding C@t{++} symbols.
8492
8493 @item set print object
8494 @itemx set print object on
8495 @cindex derived type of an object, printing
8496 @cindex display derived types
8497 When displaying a pointer to an object, identify the @emph{actual}
8498 (derived) type of the object rather than the @emph{declared} type, using
8499 the virtual function table. Note that the virtual function table is
8500 required---this feature can only work for objects that have run-time
8501 type identification; a single virtual method in the object's declared
8502 type is sufficient.
8503
8504 @item set print object off
8505 Display only the declared type of objects, without reference to the
8506 virtual function table. This is the default setting.
8507
8508 @item show print object
8509 Show whether actual, or declared, object types are displayed.
8510
8511 @item set print static-members
8512 @itemx set print static-members on
8513 @cindex static members of C@t{++} objects
8514 Print static members when displaying a C@t{++} object. The default is on.
8515
8516 @item set print static-members off
8517 Do not print static members when displaying a C@t{++} object.
8518
8519 @item show print static-members
8520 Show whether C@t{++} static members are printed or not.
8521
8522 @item set print pascal_static-members
8523 @itemx set print pascal_static-members on
8524 @cindex static members of Pascal objects
8525 @cindex Pascal objects, static members display
8526 Print static members when displaying a Pascal object. The default is on.
8527
8528 @item set print pascal_static-members off
8529 Do not print static members when displaying a Pascal object.
8530
8531 @item show print pascal_static-members
8532 Show whether Pascal static members are printed or not.
8533
8534 @c These don't work with HP ANSI C++ yet.
8535 @item set print vtbl
8536 @itemx set print vtbl on
8537 @cindex pretty print C@t{++} virtual function tables
8538 @cindex virtual functions (C@t{++}) display
8539 @cindex VTBL display
8540 Pretty print C@t{++} virtual function tables. The default is off.
8541 (The @code{vtbl} commands do not work on programs compiled with the HP
8542 ANSI C@t{++} compiler (@code{aCC}).)
8543
8544 @item set print vtbl off
8545 Do not pretty print C@t{++} virtual function tables.
8546
8547 @item show print vtbl
8548 Show whether C@t{++} virtual function tables are pretty printed, or not.
8549 @end table
8550
8551 @node Pretty Printing
8552 @section Pretty Printing
8553
8554 @value{GDBN} provides a mechanism to allow pretty-printing of values using
8555 Python code. It greatly simplifies the display of complex objects. This
8556 mechanism works for both MI and the CLI.
8557
8558 @menu
8559 * Pretty-Printer Introduction:: Introduction to pretty-printers
8560 * Pretty-Printer Example:: An example pretty-printer
8561 * Pretty-Printer Commands:: Pretty-printer commands
8562 @end menu
8563
8564 @node Pretty-Printer Introduction
8565 @subsection Pretty-Printer Introduction
8566
8567 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
8568 registered for the value. If there is then @value{GDBN} invokes the
8569 pretty-printer to print the value. Otherwise the value is printed normally.
8570
8571 Pretty-printers are normally named. This makes them easy to manage.
8572 The @samp{info pretty-printer} command will list all the installed
8573 pretty-printers with their names.
8574 If a pretty-printer can handle multiple data types, then its
8575 @dfn{subprinters} are the printers for the individual data types.
8576 Each such subprinter has its own name.
8577 The format of the name is @var{printer-name};@var{subprinter-name}.
8578
8579 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
8580 Typically they are automatically loaded and registered when the corresponding
8581 debug information is loaded, thus making them available without having to
8582 do anything special.
8583
8584 There are three places where a pretty-printer can be registered.
8585
8586 @itemize @bullet
8587 @item
8588 Pretty-printers registered globally are available when debugging
8589 all inferiors.
8590
8591 @item
8592 Pretty-printers registered with a program space are available only
8593 when debugging that program.
8594 @xref{Progspaces In Python}, for more details on program spaces in Python.
8595
8596 @item
8597 Pretty-printers registered with an objfile are loaded and unloaded
8598 with the corresponding objfile (e.g., shared library).
8599 @xref{Objfiles In Python}, for more details on objfiles in Python.
8600 @end itemize
8601
8602 @xref{Selecting Pretty-Printers}, for further information on how
8603 pretty-printers are selected,
8604
8605 @xref{Writing a Pretty-Printer}, for implementing pretty printers
8606 for new types.
8607
8608 @node Pretty-Printer Example
8609 @subsection Pretty-Printer Example
8610
8611 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
8612
8613 @smallexample
8614 (@value{GDBP}) print s
8615 $1 = @{
8616 static npos = 4294967295,
8617 _M_dataplus = @{
8618 <std::allocator<char>> = @{
8619 <__gnu_cxx::new_allocator<char>> = @{
8620 <No data fields>@}, <No data fields>
8621 @},
8622 members of std::basic_string<char, std::char_traits<char>,
8623 std::allocator<char> >::_Alloc_hider:
8624 _M_p = 0x804a014 "abcd"
8625 @}
8626 @}
8627 @end smallexample
8628
8629 With a pretty-printer for @code{std::string} only the contents are printed:
8630
8631 @smallexample
8632 (@value{GDBP}) print s
8633 $2 = "abcd"
8634 @end smallexample
8635
8636 @node Pretty-Printer Commands
8637 @subsection Pretty-Printer Commands
8638 @cindex pretty-printer commands
8639
8640 @table @code
8641 @kindex info pretty-printer
8642 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
8643 Print the list of installed pretty-printers.
8644 This includes disabled pretty-printers, which are marked as such.
8645
8646 @var{object-regexp} is a regular expression matching the objects
8647 whose pretty-printers to list.
8648 Objects can be @code{global}, the program space's file
8649 (@pxref{Progspaces In Python}),
8650 and the object files within that program space (@pxref{Objfiles In Python}).
8651 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
8652 looks up a printer from these three objects.
8653
8654 @var{name-regexp} is a regular expression matching the name of the printers
8655 to list.
8656
8657 @kindex disable pretty-printer
8658 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
8659 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
8660 A disabled pretty-printer is not forgotten, it may be enabled again later.
8661
8662 @kindex enable pretty-printer
8663 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
8664 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
8665 @end table
8666
8667 Example:
8668
8669 Suppose we have three pretty-printers installed: one from library1.so
8670 named @code{foo} that prints objects of type @code{foo}, and
8671 another from library2.so named @code{bar} that prints two types of objects,
8672 @code{bar1} and @code{bar2}.
8673
8674 @smallexample
8675 (gdb) info pretty-printer
8676 library1.so:
8677 foo
8678 library2.so:
8679 bar
8680 bar1
8681 bar2
8682 (gdb) info pretty-printer library2
8683 library2.so:
8684 bar
8685 bar1
8686 bar2
8687 (gdb) disable pretty-printer library1
8688 1 printer disabled
8689 2 of 3 printers enabled
8690 (gdb) info pretty-printer
8691 library1.so:
8692 foo [disabled]
8693 library2.so:
8694 bar
8695 bar1
8696 bar2
8697 (gdb) disable pretty-printer library2 bar:bar1
8698 1 printer disabled
8699 1 of 3 printers enabled
8700 (gdb) info pretty-printer library2
8701 library1.so:
8702 foo [disabled]
8703 library2.so:
8704 bar
8705 bar1 [disabled]
8706 bar2
8707 (gdb) disable pretty-printer library2 bar
8708 1 printer disabled
8709 0 of 3 printers enabled
8710 (gdb) info pretty-printer library2
8711 library1.so:
8712 foo [disabled]
8713 library2.so:
8714 bar [disabled]
8715 bar1 [disabled]
8716 bar2
8717 @end smallexample
8718
8719 Note that for @code{bar} the entire printer can be disabled,
8720 as can each individual subprinter.
8721
8722 @node Value History
8723 @section Value History
8724
8725 @cindex value history
8726 @cindex history of values printed by @value{GDBN}
8727 Values printed by the @code{print} command are saved in the @value{GDBN}
8728 @dfn{value history}. This allows you to refer to them in other expressions.
8729 Values are kept until the symbol table is re-read or discarded
8730 (for example with the @code{file} or @code{symbol-file} commands).
8731 When the symbol table changes, the value history is discarded,
8732 since the values may contain pointers back to the types defined in the
8733 symbol table.
8734
8735 @cindex @code{$}
8736 @cindex @code{$$}
8737 @cindex history number
8738 The values printed are given @dfn{history numbers} by which you can
8739 refer to them. These are successive integers starting with one.
8740 @code{print} shows you the history number assigned to a value by
8741 printing @samp{$@var{num} = } before the value; here @var{num} is the
8742 history number.
8743
8744 To refer to any previous value, use @samp{$} followed by the value's
8745 history number. The way @code{print} labels its output is designed to
8746 remind you of this. Just @code{$} refers to the most recent value in
8747 the history, and @code{$$} refers to the value before that.
8748 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
8749 is the value just prior to @code{$$}, @code{$$1} is equivalent to
8750 @code{$$}, and @code{$$0} is equivalent to @code{$}.
8751
8752 For example, suppose you have just printed a pointer to a structure and
8753 want to see the contents of the structure. It suffices to type
8754
8755 @smallexample
8756 p *$
8757 @end smallexample
8758
8759 If you have a chain of structures where the component @code{next} points
8760 to the next one, you can print the contents of the next one with this:
8761
8762 @smallexample
8763 p *$.next
8764 @end smallexample
8765
8766 @noindent
8767 You can print successive links in the chain by repeating this
8768 command---which you can do by just typing @key{RET}.
8769
8770 Note that the history records values, not expressions. If the value of
8771 @code{x} is 4 and you type these commands:
8772
8773 @smallexample
8774 print x
8775 set x=5
8776 @end smallexample
8777
8778 @noindent
8779 then the value recorded in the value history by the @code{print} command
8780 remains 4 even though the value of @code{x} has changed.
8781
8782 @table @code
8783 @kindex show values
8784 @item show values
8785 Print the last ten values in the value history, with their item numbers.
8786 This is like @samp{p@ $$9} repeated ten times, except that @code{show
8787 values} does not change the history.
8788
8789 @item show values @var{n}
8790 Print ten history values centered on history item number @var{n}.
8791
8792 @item show values +
8793 Print ten history values just after the values last printed. If no more
8794 values are available, @code{show values +} produces no display.
8795 @end table
8796
8797 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
8798 same effect as @samp{show values +}.
8799
8800 @node Convenience Vars
8801 @section Convenience Variables
8802
8803 @cindex convenience variables
8804 @cindex user-defined variables
8805 @value{GDBN} provides @dfn{convenience variables} that you can use within
8806 @value{GDBN} to hold on to a value and refer to it later. These variables
8807 exist entirely within @value{GDBN}; they are not part of your program, and
8808 setting a convenience variable has no direct effect on further execution
8809 of your program. That is why you can use them freely.
8810
8811 Convenience variables are prefixed with @samp{$}. Any name preceded by
8812 @samp{$} can be used for a convenience variable, unless it is one of
8813 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
8814 (Value history references, in contrast, are @emph{numbers} preceded
8815 by @samp{$}. @xref{Value History, ,Value History}.)
8816
8817 You can save a value in a convenience variable with an assignment
8818 expression, just as you would set a variable in your program.
8819 For example:
8820
8821 @smallexample
8822 set $foo = *object_ptr
8823 @end smallexample
8824
8825 @noindent
8826 would save in @code{$foo} the value contained in the object pointed to by
8827 @code{object_ptr}.
8828
8829 Using a convenience variable for the first time creates it, but its
8830 value is @code{void} until you assign a new value. You can alter the
8831 value with another assignment at any time.
8832
8833 Convenience variables have no fixed types. You can assign a convenience
8834 variable any type of value, including structures and arrays, even if
8835 that variable already has a value of a different type. The convenience
8836 variable, when used as an expression, has the type of its current value.
8837
8838 @table @code
8839 @kindex show convenience
8840 @cindex show all user variables
8841 @item show convenience
8842 Print a list of convenience variables used so far, and their values.
8843 Abbreviated @code{show conv}.
8844
8845 @kindex init-if-undefined
8846 @cindex convenience variables, initializing
8847 @item init-if-undefined $@var{variable} = @var{expression}
8848 Set a convenience variable if it has not already been set. This is useful
8849 for user-defined commands that keep some state. It is similar, in concept,
8850 to using local static variables with initializers in C (except that
8851 convenience variables are global). It can also be used to allow users to
8852 override default values used in a command script.
8853
8854 If the variable is already defined then the expression is not evaluated so
8855 any side-effects do not occur.
8856 @end table
8857
8858 One of the ways to use a convenience variable is as a counter to be
8859 incremented or a pointer to be advanced. For example, to print
8860 a field from successive elements of an array of structures:
8861
8862 @smallexample
8863 set $i = 0
8864 print bar[$i++]->contents
8865 @end smallexample
8866
8867 @noindent
8868 Repeat that command by typing @key{RET}.
8869
8870 Some convenience variables are created automatically by @value{GDBN} and given
8871 values likely to be useful.
8872
8873 @table @code
8874 @vindex $_@r{, convenience variable}
8875 @item $_
8876 The variable @code{$_} is automatically set by the @code{x} command to
8877 the last address examined (@pxref{Memory, ,Examining Memory}). Other
8878 commands which provide a default address for @code{x} to examine also
8879 set @code{$_} to that address; these commands include @code{info line}
8880 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
8881 except when set by the @code{x} command, in which case it is a pointer
8882 to the type of @code{$__}.
8883
8884 @vindex $__@r{, convenience variable}
8885 @item $__
8886 The variable @code{$__} is automatically set by the @code{x} command
8887 to the value found in the last address examined. Its type is chosen
8888 to match the format in which the data was printed.
8889
8890 @item $_exitcode
8891 @vindex $_exitcode@r{, convenience variable}
8892 The variable @code{$_exitcode} is automatically set to the exit code when
8893 the program being debugged terminates.
8894
8895 @item $_sdata
8896 @vindex $_sdata@r{, inspect, convenience variable}
8897 The variable @code{$_sdata} contains extra collected static tracepoint
8898 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
8899 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
8900 if extra static tracepoint data has not been collected.
8901
8902 @item $_siginfo
8903 @vindex $_siginfo@r{, convenience variable}
8904 The variable @code{$_siginfo} contains extra signal information
8905 (@pxref{extra signal information}). Note that @code{$_siginfo}
8906 could be empty, if the application has not yet received any signals.
8907 For example, it will be empty before you execute the @code{run} command.
8908
8909 @item $_tlb
8910 @vindex $_tlb@r{, convenience variable}
8911 The variable @code{$_tlb} is automatically set when debugging
8912 applications running on MS-Windows in native mode or connected to
8913 gdbserver that supports the @code{qGetTIBAddr} request.
8914 @xref{General Query Packets}.
8915 This variable contains the address of the thread information block.
8916
8917 @end table
8918
8919 On HP-UX systems, if you refer to a function or variable name that
8920 begins with a dollar sign, @value{GDBN} searches for a user or system
8921 name first, before it searches for a convenience variable.
8922
8923 @cindex convenience functions
8924 @value{GDBN} also supplies some @dfn{convenience functions}. These
8925 have a syntax similar to convenience variables. A convenience
8926 function can be used in an expression just like an ordinary function;
8927 however, a convenience function is implemented internally to
8928 @value{GDBN}.
8929
8930 @table @code
8931 @item help function
8932 @kindex help function
8933 @cindex show all convenience functions
8934 Print a list of all convenience functions.
8935 @end table
8936
8937 @node Registers
8938 @section Registers
8939
8940 @cindex registers
8941 You can refer to machine register contents, in expressions, as variables
8942 with names starting with @samp{$}. The names of registers are different
8943 for each machine; use @code{info registers} to see the names used on
8944 your machine.
8945
8946 @table @code
8947 @kindex info registers
8948 @item info registers
8949 Print the names and values of all registers except floating-point
8950 and vector registers (in the selected stack frame).
8951
8952 @kindex info all-registers
8953 @cindex floating point registers
8954 @item info all-registers
8955 Print the names and values of all registers, including floating-point
8956 and vector registers (in the selected stack frame).
8957
8958 @item info registers @var{regname} @dots{}
8959 Print the @dfn{relativized} value of each specified register @var{regname}.
8960 As discussed in detail below, register values are normally relative to
8961 the selected stack frame. @var{regname} may be any register name valid on
8962 the machine you are using, with or without the initial @samp{$}.
8963 @end table
8964
8965 @cindex stack pointer register
8966 @cindex program counter register
8967 @cindex process status register
8968 @cindex frame pointer register
8969 @cindex standard registers
8970 @value{GDBN} has four ``standard'' register names that are available (in
8971 expressions) on most machines---whenever they do not conflict with an
8972 architecture's canonical mnemonics for registers. The register names
8973 @code{$pc} and @code{$sp} are used for the program counter register and
8974 the stack pointer. @code{$fp} is used for a register that contains a
8975 pointer to the current stack frame, and @code{$ps} is used for a
8976 register that contains the processor status. For example,
8977 you could print the program counter in hex with
8978
8979 @smallexample
8980 p/x $pc
8981 @end smallexample
8982
8983 @noindent
8984 or print the instruction to be executed next with
8985
8986 @smallexample
8987 x/i $pc
8988 @end smallexample
8989
8990 @noindent
8991 or add four to the stack pointer@footnote{This is a way of removing
8992 one word from the stack, on machines where stacks grow downward in
8993 memory (most machines, nowadays). This assumes that the innermost
8994 stack frame is selected; setting @code{$sp} is not allowed when other
8995 stack frames are selected. To pop entire frames off the stack,
8996 regardless of machine architecture, use @code{return};
8997 see @ref{Returning, ,Returning from a Function}.} with
8998
8999 @smallexample
9000 set $sp += 4
9001 @end smallexample
9002
9003 Whenever possible, these four standard register names are available on
9004 your machine even though the machine has different canonical mnemonics,
9005 so long as there is no conflict. The @code{info registers} command
9006 shows the canonical names. For example, on the SPARC, @code{info
9007 registers} displays the processor status register as @code{$psr} but you
9008 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
9009 is an alias for the @sc{eflags} register.
9010
9011 @value{GDBN} always considers the contents of an ordinary register as an
9012 integer when the register is examined in this way. Some machines have
9013 special registers which can hold nothing but floating point; these
9014 registers are considered to have floating point values. There is no way
9015 to refer to the contents of an ordinary register as floating point value
9016 (although you can @emph{print} it as a floating point value with
9017 @samp{print/f $@var{regname}}).
9018
9019 Some registers have distinct ``raw'' and ``virtual'' data formats. This
9020 means that the data format in which the register contents are saved by
9021 the operating system is not the same one that your program normally
9022 sees. For example, the registers of the 68881 floating point
9023 coprocessor are always saved in ``extended'' (raw) format, but all C
9024 programs expect to work with ``double'' (virtual) format. In such
9025 cases, @value{GDBN} normally works with the virtual format only (the format
9026 that makes sense for your program), but the @code{info registers} command
9027 prints the data in both formats.
9028
9029 @cindex SSE registers (x86)
9030 @cindex MMX registers (x86)
9031 Some machines have special registers whose contents can be interpreted
9032 in several different ways. For example, modern x86-based machines
9033 have SSE and MMX registers that can hold several values packed
9034 together in several different formats. @value{GDBN} refers to such
9035 registers in @code{struct} notation:
9036
9037 @smallexample
9038 (@value{GDBP}) print $xmm1
9039 $1 = @{
9040 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
9041 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
9042 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
9043 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
9044 v4_int32 = @{0, 20657912, 11, 13@},
9045 v2_int64 = @{88725056443645952, 55834574859@},
9046 uint128 = 0x0000000d0000000b013b36f800000000
9047 @}
9048 @end smallexample
9049
9050 @noindent
9051 To set values of such registers, you need to tell @value{GDBN} which
9052 view of the register you wish to change, as if you were assigning
9053 value to a @code{struct} member:
9054
9055 @smallexample
9056 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
9057 @end smallexample
9058
9059 Normally, register values are relative to the selected stack frame
9060 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
9061 value that the register would contain if all stack frames farther in
9062 were exited and their saved registers restored. In order to see the
9063 true contents of hardware registers, you must select the innermost
9064 frame (with @samp{frame 0}).
9065
9066 However, @value{GDBN} must deduce where registers are saved, from the machine
9067 code generated by your compiler. If some registers are not saved, or if
9068 @value{GDBN} is unable to locate the saved registers, the selected stack
9069 frame makes no difference.
9070
9071 @node Floating Point Hardware
9072 @section Floating Point Hardware
9073 @cindex floating point
9074
9075 Depending on the configuration, @value{GDBN} may be able to give
9076 you more information about the status of the floating point hardware.
9077
9078 @table @code
9079 @kindex info float
9080 @item info float
9081 Display hardware-dependent information about the floating
9082 point unit. The exact contents and layout vary depending on the
9083 floating point chip. Currently, @samp{info float} is supported on
9084 the ARM and x86 machines.
9085 @end table
9086
9087 @node Vector Unit
9088 @section Vector Unit
9089 @cindex vector unit
9090
9091 Depending on the configuration, @value{GDBN} may be able to give you
9092 more information about the status of the vector unit.
9093
9094 @table @code
9095 @kindex info vector
9096 @item info vector
9097 Display information about the vector unit. The exact contents and
9098 layout vary depending on the hardware.
9099 @end table
9100
9101 @node OS Information
9102 @section Operating System Auxiliary Information
9103 @cindex OS information
9104
9105 @value{GDBN} provides interfaces to useful OS facilities that can help
9106 you debug your program.
9107
9108 @cindex @code{ptrace} system call
9109 @cindex @code{struct user} contents
9110 When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
9111 machines), it interfaces with the inferior via the @code{ptrace}
9112 system call. The operating system creates a special sata structure,
9113 called @code{struct user}, for this interface. You can use the
9114 command @code{info udot} to display the contents of this data
9115 structure.
9116
9117 @table @code
9118 @item info udot
9119 @kindex info udot
9120 Display the contents of the @code{struct user} maintained by the OS
9121 kernel for the program being debugged. @value{GDBN} displays the
9122 contents of @code{struct user} as a list of hex numbers, similar to
9123 the @code{examine} command.
9124 @end table
9125
9126 @cindex auxiliary vector
9127 @cindex vector, auxiliary
9128 Some operating systems supply an @dfn{auxiliary vector} to programs at
9129 startup. This is akin to the arguments and environment that you
9130 specify for a program, but contains a system-dependent variety of
9131 binary values that tell system libraries important details about the
9132 hardware, operating system, and process. Each value's purpose is
9133 identified by an integer tag; the meanings are well-known but system-specific.
9134 Depending on the configuration and operating system facilities,
9135 @value{GDBN} may be able to show you this information. For remote
9136 targets, this functionality may further depend on the remote stub's
9137 support of the @samp{qXfer:auxv:read} packet, see
9138 @ref{qXfer auxiliary vector read}.
9139
9140 @table @code
9141 @kindex info auxv
9142 @item info auxv
9143 Display the auxiliary vector of the inferior, which can be either a
9144 live process or a core dump file. @value{GDBN} prints each tag value
9145 numerically, and also shows names and text descriptions for recognized
9146 tags. Some values in the vector are numbers, some bit masks, and some
9147 pointers to strings or other data. @value{GDBN} displays each value in the
9148 most appropriate form for a recognized tag, and in hexadecimal for
9149 an unrecognized tag.
9150 @end table
9151
9152 On some targets, @value{GDBN} can access operating-system-specific information
9153 and display it to user, without interpretation. For remote targets,
9154 this functionality depends on the remote stub's support of the
9155 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
9156
9157 @table @code
9158 @kindex info os
9159 @item info os
9160 List the types of OS information available for the target. If the
9161 target does not return a list of possible types, this command will
9162 report an error.
9163
9164 @kindex info os processes
9165 @item info os processes
9166 Display the list of processes on the target. For each process,
9167 @value{GDBN} prints the process identifier, the name of the user, and
9168 the command corresponding to the process.
9169 @end table
9170
9171 @node Memory Region Attributes
9172 @section Memory Region Attributes
9173 @cindex memory region attributes
9174
9175 @dfn{Memory region attributes} allow you to describe special handling
9176 required by regions of your target's memory. @value{GDBN} uses
9177 attributes to determine whether to allow certain types of memory
9178 accesses; whether to use specific width accesses; and whether to cache
9179 target memory. By default the description of memory regions is
9180 fetched from the target (if the current target supports this), but the
9181 user can override the fetched regions.
9182
9183 Defined memory regions can be individually enabled and disabled. When a
9184 memory region is disabled, @value{GDBN} uses the default attributes when
9185 accessing memory in that region. Similarly, if no memory regions have
9186 been defined, @value{GDBN} uses the default attributes when accessing
9187 all memory.
9188
9189 When a memory region is defined, it is given a number to identify it;
9190 to enable, disable, or remove a memory region, you specify that number.
9191
9192 @table @code
9193 @kindex mem
9194 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
9195 Define a memory region bounded by @var{lower} and @var{upper} with
9196 attributes @var{attributes}@dots{}, and add it to the list of regions
9197 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
9198 case: it is treated as the target's maximum memory address.
9199 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
9200
9201 @item mem auto
9202 Discard any user changes to the memory regions and use target-supplied
9203 regions, if available, or no regions if the target does not support.
9204
9205 @kindex delete mem
9206 @item delete mem @var{nums}@dots{}
9207 Remove memory regions @var{nums}@dots{} from the list of regions
9208 monitored by @value{GDBN}.
9209
9210 @kindex disable mem
9211 @item disable mem @var{nums}@dots{}
9212 Disable monitoring of memory regions @var{nums}@dots{}.
9213 A disabled memory region is not forgotten.
9214 It may be enabled again later.
9215
9216 @kindex enable mem
9217 @item enable mem @var{nums}@dots{}
9218 Enable monitoring of memory regions @var{nums}@dots{}.
9219
9220 @kindex info mem
9221 @item info mem
9222 Print a table of all defined memory regions, with the following columns
9223 for each region:
9224
9225 @table @emph
9226 @item Memory Region Number
9227 @item Enabled or Disabled.
9228 Enabled memory regions are marked with @samp{y}.
9229 Disabled memory regions are marked with @samp{n}.
9230
9231 @item Lo Address
9232 The address defining the inclusive lower bound of the memory region.
9233
9234 @item Hi Address
9235 The address defining the exclusive upper bound of the memory region.
9236
9237 @item Attributes
9238 The list of attributes set for this memory region.
9239 @end table
9240 @end table
9241
9242
9243 @subsection Attributes
9244
9245 @subsubsection Memory Access Mode
9246 The access mode attributes set whether @value{GDBN} may make read or
9247 write accesses to a memory region.
9248
9249 While these attributes prevent @value{GDBN} from performing invalid
9250 memory accesses, they do nothing to prevent the target system, I/O DMA,
9251 etc.@: from accessing memory.
9252
9253 @table @code
9254 @item ro
9255 Memory is read only.
9256 @item wo
9257 Memory is write only.
9258 @item rw
9259 Memory is read/write. This is the default.
9260 @end table
9261
9262 @subsubsection Memory Access Size
9263 The access size attribute tells @value{GDBN} to use specific sized
9264 accesses in the memory region. Often memory mapped device registers
9265 require specific sized accesses. If no access size attribute is
9266 specified, @value{GDBN} may use accesses of any size.
9267
9268 @table @code
9269 @item 8
9270 Use 8 bit memory accesses.
9271 @item 16
9272 Use 16 bit memory accesses.
9273 @item 32
9274 Use 32 bit memory accesses.
9275 @item 64
9276 Use 64 bit memory accesses.
9277 @end table
9278
9279 @c @subsubsection Hardware/Software Breakpoints
9280 @c The hardware/software breakpoint attributes set whether @value{GDBN}
9281 @c will use hardware or software breakpoints for the internal breakpoints
9282 @c used by the step, next, finish, until, etc. commands.
9283 @c
9284 @c @table @code
9285 @c @item hwbreak
9286 @c Always use hardware breakpoints
9287 @c @item swbreak (default)
9288 @c @end table
9289
9290 @subsubsection Data Cache
9291 The data cache attributes set whether @value{GDBN} will cache target
9292 memory. While this generally improves performance by reducing debug
9293 protocol overhead, it can lead to incorrect results because @value{GDBN}
9294 does not know about volatile variables or memory mapped device
9295 registers.
9296
9297 @table @code
9298 @item cache
9299 Enable @value{GDBN} to cache target memory.
9300 @item nocache
9301 Disable @value{GDBN} from caching target memory. This is the default.
9302 @end table
9303
9304 @subsection Memory Access Checking
9305 @value{GDBN} can be instructed to refuse accesses to memory that is
9306 not explicitly described. This can be useful if accessing such
9307 regions has undesired effects for a specific target, or to provide
9308 better error checking. The following commands control this behaviour.
9309
9310 @table @code
9311 @kindex set mem inaccessible-by-default
9312 @item set mem inaccessible-by-default [on|off]
9313 If @code{on} is specified, make @value{GDBN} treat memory not
9314 explicitly described by the memory ranges as non-existent and refuse accesses
9315 to such memory. The checks are only performed if there's at least one
9316 memory range defined. If @code{off} is specified, make @value{GDBN}
9317 treat the memory not explicitly described by the memory ranges as RAM.
9318 The default value is @code{on}.
9319 @kindex show mem inaccessible-by-default
9320 @item show mem inaccessible-by-default
9321 Show the current handling of accesses to unknown memory.
9322 @end table
9323
9324
9325 @c @subsubsection Memory Write Verification
9326 @c The memory write verification attributes set whether @value{GDBN}
9327 @c will re-reads data after each write to verify the write was successful.
9328 @c
9329 @c @table @code
9330 @c @item verify
9331 @c @item noverify (default)
9332 @c @end table
9333
9334 @node Dump/Restore Files
9335 @section Copy Between Memory and a File
9336 @cindex dump/restore files
9337 @cindex append data to a file
9338 @cindex dump data to a file
9339 @cindex restore data from a file
9340
9341 You can use the commands @code{dump}, @code{append}, and
9342 @code{restore} to copy data between target memory and a file. The
9343 @code{dump} and @code{append} commands write data to a file, and the
9344 @code{restore} command reads data from a file back into the inferior's
9345 memory. Files may be in binary, Motorola S-record, Intel hex, or
9346 Tektronix Hex format; however, @value{GDBN} can only append to binary
9347 files.
9348
9349 @table @code
9350
9351 @kindex dump
9352 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
9353 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
9354 Dump the contents of memory from @var{start_addr} to @var{end_addr},
9355 or the value of @var{expr}, to @var{filename} in the given format.
9356
9357 The @var{format} parameter may be any one of:
9358 @table @code
9359 @item binary
9360 Raw binary form.
9361 @item ihex
9362 Intel hex format.
9363 @item srec
9364 Motorola S-record format.
9365 @item tekhex
9366 Tektronix Hex format.
9367 @end table
9368
9369 @value{GDBN} uses the same definitions of these formats as the
9370 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
9371 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
9372 form.
9373
9374 @kindex append
9375 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
9376 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
9377 Append the contents of memory from @var{start_addr} to @var{end_addr},
9378 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
9379 (@value{GDBN} can only append data to files in raw binary form.)
9380
9381 @kindex restore
9382 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
9383 Restore the contents of file @var{filename} into memory. The
9384 @code{restore} command can automatically recognize any known @sc{bfd}
9385 file format, except for raw binary. To restore a raw binary file you
9386 must specify the optional keyword @code{binary} after the filename.
9387
9388 If @var{bias} is non-zero, its value will be added to the addresses
9389 contained in the file. Binary files always start at address zero, so
9390 they will be restored at address @var{bias}. Other bfd files have
9391 a built-in location; they will be restored at offset @var{bias}
9392 from that location.
9393
9394 If @var{start} and/or @var{end} are non-zero, then only data between
9395 file offset @var{start} and file offset @var{end} will be restored.
9396 These offsets are relative to the addresses in the file, before
9397 the @var{bias} argument is applied.
9398
9399 @end table
9400
9401 @node Core File Generation
9402 @section How to Produce a Core File from Your Program
9403 @cindex dump core from inferior
9404
9405 A @dfn{core file} or @dfn{core dump} is a file that records the memory
9406 image of a running process and its process status (register values
9407 etc.). Its primary use is post-mortem debugging of a program that
9408 crashed while it ran outside a debugger. A program that crashes
9409 automatically produces a core file, unless this feature is disabled by
9410 the user. @xref{Files}, for information on invoking @value{GDBN} in
9411 the post-mortem debugging mode.
9412
9413 Occasionally, you may wish to produce a core file of the program you
9414 are debugging in order to preserve a snapshot of its state.
9415 @value{GDBN} has a special command for that.
9416
9417 @table @code
9418 @kindex gcore
9419 @kindex generate-core-file
9420 @item generate-core-file [@var{file}]
9421 @itemx gcore [@var{file}]
9422 Produce a core dump of the inferior process. The optional argument
9423 @var{file} specifies the file name where to put the core dump. If not
9424 specified, the file name defaults to @file{core.@var{pid}}, where
9425 @var{pid} is the inferior process ID.
9426
9427 Note that this command is implemented only for some systems (as of
9428 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
9429 @end table
9430
9431 @node Character Sets
9432 @section Character Sets
9433 @cindex character sets
9434 @cindex charset
9435 @cindex translating between character sets
9436 @cindex host character set
9437 @cindex target character set
9438
9439 If the program you are debugging uses a different character set to
9440 represent characters and strings than the one @value{GDBN} uses itself,
9441 @value{GDBN} can automatically translate between the character sets for
9442 you. The character set @value{GDBN} uses we call the @dfn{host
9443 character set}; the one the inferior program uses we call the
9444 @dfn{target character set}.
9445
9446 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
9447 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
9448 remote protocol (@pxref{Remote Debugging}) to debug a program
9449 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
9450 then the host character set is Latin-1, and the target character set is
9451 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
9452 target-charset EBCDIC-US}, then @value{GDBN} translates between
9453 @sc{ebcdic} and Latin 1 as you print character or string values, or use
9454 character and string literals in expressions.
9455
9456 @value{GDBN} has no way to automatically recognize which character set
9457 the inferior program uses; you must tell it, using the @code{set
9458 target-charset} command, described below.
9459
9460 Here are the commands for controlling @value{GDBN}'s character set
9461 support:
9462
9463 @table @code
9464 @item set target-charset @var{charset}
9465 @kindex set target-charset
9466 Set the current target character set to @var{charset}. To display the
9467 list of supported target character sets, type
9468 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
9469
9470 @item set host-charset @var{charset}
9471 @kindex set host-charset
9472 Set the current host character set to @var{charset}.
9473
9474 By default, @value{GDBN} uses a host character set appropriate to the
9475 system it is running on; you can override that default using the
9476 @code{set host-charset} command. On some systems, @value{GDBN} cannot
9477 automatically determine the appropriate host character set. In this
9478 case, @value{GDBN} uses @samp{UTF-8}.
9479
9480 @value{GDBN} can only use certain character sets as its host character
9481 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
9482 @value{GDBN} will list the host character sets it supports.
9483
9484 @item set charset @var{charset}
9485 @kindex set charset
9486 Set the current host and target character sets to @var{charset}. As
9487 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
9488 @value{GDBN} will list the names of the character sets that can be used
9489 for both host and target.
9490
9491 @item show charset
9492 @kindex show charset
9493 Show the names of the current host and target character sets.
9494
9495 @item show host-charset
9496 @kindex show host-charset
9497 Show the name of the current host character set.
9498
9499 @item show target-charset
9500 @kindex show target-charset
9501 Show the name of the current target character set.
9502
9503 @item set target-wide-charset @var{charset}
9504 @kindex set target-wide-charset
9505 Set the current target's wide character set to @var{charset}. This is
9506 the character set used by the target's @code{wchar_t} type. To
9507 display the list of supported wide character sets, type
9508 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
9509
9510 @item show target-wide-charset
9511 @kindex show target-wide-charset
9512 Show the name of the current target's wide character set.
9513 @end table
9514
9515 Here is an example of @value{GDBN}'s character set support in action.
9516 Assume that the following source code has been placed in the file
9517 @file{charset-test.c}:
9518
9519 @smallexample
9520 #include <stdio.h>
9521
9522 char ascii_hello[]
9523 = @{72, 101, 108, 108, 111, 44, 32, 119,
9524 111, 114, 108, 100, 33, 10, 0@};
9525 char ibm1047_hello[]
9526 = @{200, 133, 147, 147, 150, 107, 64, 166,
9527 150, 153, 147, 132, 90, 37, 0@};
9528
9529 main ()
9530 @{
9531 printf ("Hello, world!\n");
9532 @}
9533 @end smallexample
9534
9535 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
9536 containing the string @samp{Hello, world!} followed by a newline,
9537 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
9538
9539 We compile the program, and invoke the debugger on it:
9540
9541 @smallexample
9542 $ gcc -g charset-test.c -o charset-test
9543 $ gdb -nw charset-test
9544 GNU gdb 2001-12-19-cvs
9545 Copyright 2001 Free Software Foundation, Inc.
9546 @dots{}
9547 (@value{GDBP})
9548 @end smallexample
9549
9550 We can use the @code{show charset} command to see what character sets
9551 @value{GDBN} is currently using to interpret and display characters and
9552 strings:
9553
9554 @smallexample
9555 (@value{GDBP}) show charset
9556 The current host and target character set is `ISO-8859-1'.
9557 (@value{GDBP})
9558 @end smallexample
9559
9560 For the sake of printing this manual, let's use @sc{ascii} as our
9561 initial character set:
9562 @smallexample
9563 (@value{GDBP}) set charset ASCII
9564 (@value{GDBP}) show charset
9565 The current host and target character set is `ASCII'.
9566 (@value{GDBP})
9567 @end smallexample
9568
9569 Let's assume that @sc{ascii} is indeed the correct character set for our
9570 host system --- in other words, let's assume that if @value{GDBN} prints
9571 characters using the @sc{ascii} character set, our terminal will display
9572 them properly. Since our current target character set is also
9573 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
9574
9575 @smallexample
9576 (@value{GDBP}) print ascii_hello
9577 $1 = 0x401698 "Hello, world!\n"
9578 (@value{GDBP}) print ascii_hello[0]
9579 $2 = 72 'H'
9580 (@value{GDBP})
9581 @end smallexample
9582
9583 @value{GDBN} uses the target character set for character and string
9584 literals you use in expressions:
9585
9586 @smallexample
9587 (@value{GDBP}) print '+'
9588 $3 = 43 '+'
9589 (@value{GDBP})
9590 @end smallexample
9591
9592 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
9593 character.
9594
9595 @value{GDBN} relies on the user to tell it which character set the
9596 target program uses. If we print @code{ibm1047_hello} while our target
9597 character set is still @sc{ascii}, we get jibberish:
9598
9599 @smallexample
9600 (@value{GDBP}) print ibm1047_hello
9601 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
9602 (@value{GDBP}) print ibm1047_hello[0]
9603 $5 = 200 '\310'
9604 (@value{GDBP})
9605 @end smallexample
9606
9607 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
9608 @value{GDBN} tells us the character sets it supports:
9609
9610 @smallexample
9611 (@value{GDBP}) set target-charset
9612 ASCII EBCDIC-US IBM1047 ISO-8859-1
9613 (@value{GDBP}) set target-charset
9614 @end smallexample
9615
9616 We can select @sc{ibm1047} as our target character set, and examine the
9617 program's strings again. Now the @sc{ascii} string is wrong, but
9618 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
9619 target character set, @sc{ibm1047}, to the host character set,
9620 @sc{ascii}, and they display correctly:
9621
9622 @smallexample
9623 (@value{GDBP}) set target-charset IBM1047
9624 (@value{GDBP}) show charset
9625 The current host character set is `ASCII'.
9626 The current target character set is `IBM1047'.
9627 (@value{GDBP}) print ascii_hello
9628 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
9629 (@value{GDBP}) print ascii_hello[0]
9630 $7 = 72 '\110'
9631 (@value{GDBP}) print ibm1047_hello
9632 $8 = 0x4016a8 "Hello, world!\n"
9633 (@value{GDBP}) print ibm1047_hello[0]
9634 $9 = 200 'H'
9635 (@value{GDBP})
9636 @end smallexample
9637
9638 As above, @value{GDBN} uses the target character set for character and
9639 string literals you use in expressions:
9640
9641 @smallexample
9642 (@value{GDBP}) print '+'
9643 $10 = 78 '+'
9644 (@value{GDBP})
9645 @end smallexample
9646
9647 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
9648 character.
9649
9650 @node Caching Remote Data
9651 @section Caching Data of Remote Targets
9652 @cindex caching data of remote targets
9653
9654 @value{GDBN} caches data exchanged between the debugger and a
9655 remote target (@pxref{Remote Debugging}). Such caching generally improves
9656 performance, because it reduces the overhead of the remote protocol by
9657 bundling memory reads and writes into large chunks. Unfortunately, simply
9658 caching everything would lead to incorrect results, since @value{GDBN}
9659 does not necessarily know anything about volatile values, memory-mapped I/O
9660 addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
9661 memory can be changed @emph{while} a gdb command is executing.
9662 Therefore, by default, @value{GDBN} only caches data
9663 known to be on the stack@footnote{In non-stop mode, it is moderately
9664 rare for a running thread to modify the stack of a stopped thread
9665 in a way that would interfere with a backtrace, and caching of
9666 stack reads provides a significant speed up of remote backtraces.}.
9667 Other regions of memory can be explicitly marked as
9668 cacheable; see @pxref{Memory Region Attributes}.
9669
9670 @table @code
9671 @kindex set remotecache
9672 @item set remotecache on
9673 @itemx set remotecache off
9674 This option no longer does anything; it exists for compatibility
9675 with old scripts.
9676
9677 @kindex show remotecache
9678 @item show remotecache
9679 Show the current state of the obsolete remotecache flag.
9680
9681 @kindex set stack-cache
9682 @item set stack-cache on
9683 @itemx set stack-cache off
9684 Enable or disable caching of stack accesses. When @code{ON}, use
9685 caching. By default, this option is @code{ON}.
9686
9687 @kindex show stack-cache
9688 @item show stack-cache
9689 Show the current state of data caching for memory accesses.
9690
9691 @kindex info dcache
9692 @item info dcache @r{[}line@r{]}
9693 Print the information about the data cache performance. The
9694 information displayed includes the dcache width and depth, and for
9695 each cache line, its number, address, and how many times it was
9696 referenced. This command is useful for debugging the data cache
9697 operation.
9698
9699 If a line number is specified, the contents of that line will be
9700 printed in hex.
9701
9702 @item set dcache size @var{size}
9703 @cindex dcache size
9704 @kindex set dcache size
9705 Set maximum number of entries in dcache (dcache depth above).
9706
9707 @item set dcache line-size @var{line-size}
9708 @cindex dcache line-size
9709 @kindex set dcache line-size
9710 Set number of bytes each dcache entry caches (dcache width above).
9711 Must be a power of 2.
9712
9713 @item show dcache size
9714 @kindex show dcache size
9715 Show maximum number of dcache entries. See also @ref{Caching Remote Data, info dcache}.
9716
9717 @item show dcache line-size
9718 @kindex show dcache line-size
9719 Show default size of dcache lines. See also @ref{Caching Remote Data, info dcache}.
9720
9721 @end table
9722
9723 @node Searching Memory
9724 @section Search Memory
9725 @cindex searching memory
9726
9727 Memory can be searched for a particular sequence of bytes with the
9728 @code{find} command.
9729
9730 @table @code
9731 @kindex find
9732 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
9733 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
9734 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
9735 etc. The search begins at address @var{start_addr} and continues for either
9736 @var{len} bytes or through to @var{end_addr} inclusive.
9737 @end table
9738
9739 @var{s} and @var{n} are optional parameters.
9740 They may be specified in either order, apart or together.
9741
9742 @table @r
9743 @item @var{s}, search query size
9744 The size of each search query value.
9745
9746 @table @code
9747 @item b
9748 bytes
9749 @item h
9750 halfwords (two bytes)
9751 @item w
9752 words (four bytes)
9753 @item g
9754 giant words (eight bytes)
9755 @end table
9756
9757 All values are interpreted in the current language.
9758 This means, for example, that if the current source language is C/C@t{++}
9759 then searching for the string ``hello'' includes the trailing '\0'.
9760
9761 If the value size is not specified, it is taken from the
9762 value's type in the current language.
9763 This is useful when one wants to specify the search
9764 pattern as a mixture of types.
9765 Note that this means, for example, that in the case of C-like languages
9766 a search for an untyped 0x42 will search for @samp{(int) 0x42}
9767 which is typically four bytes.
9768
9769 @item @var{n}, maximum number of finds
9770 The maximum number of matches to print. The default is to print all finds.
9771 @end table
9772
9773 You can use strings as search values. Quote them with double-quotes
9774 (@code{"}).
9775 The string value is copied into the search pattern byte by byte,
9776 regardless of the endianness of the target and the size specification.
9777
9778 The address of each match found is printed as well as a count of the
9779 number of matches found.
9780
9781 The address of the last value found is stored in convenience variable
9782 @samp{$_}.
9783 A count of the number of matches is stored in @samp{$numfound}.
9784
9785 For example, if stopped at the @code{printf} in this function:
9786
9787 @smallexample
9788 void
9789 hello ()
9790 @{
9791 static char hello[] = "hello-hello";
9792 static struct @{ char c; short s; int i; @}
9793 __attribute__ ((packed)) mixed
9794 = @{ 'c', 0x1234, 0x87654321 @};
9795 printf ("%s\n", hello);
9796 @}
9797 @end smallexample
9798
9799 @noindent
9800 you get during debugging:
9801
9802 @smallexample
9803 (gdb) find &hello[0], +sizeof(hello), "hello"
9804 0x804956d <hello.1620+6>
9805 1 pattern found
9806 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
9807 0x8049567 <hello.1620>
9808 0x804956d <hello.1620+6>
9809 2 patterns found
9810 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
9811 0x8049567 <hello.1620>
9812 1 pattern found
9813 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
9814 0x8049560 <mixed.1625>
9815 1 pattern found
9816 (gdb) print $numfound
9817 $1 = 1
9818 (gdb) print $_
9819 $2 = (void *) 0x8049560
9820 @end smallexample
9821
9822 @node Optimized Code
9823 @chapter Debugging Optimized Code
9824 @cindex optimized code, debugging
9825 @cindex debugging optimized code
9826
9827 Almost all compilers support optimization. With optimization
9828 disabled, the compiler generates assembly code that corresponds
9829 directly to your source code, in a simplistic way. As the compiler
9830 applies more powerful optimizations, the generated assembly code
9831 diverges from your original source code. With help from debugging
9832 information generated by the compiler, @value{GDBN} can map from
9833 the running program back to constructs from your original source.
9834
9835 @value{GDBN} is more accurate with optimization disabled. If you
9836 can recompile without optimization, it is easier to follow the
9837 progress of your program during debugging. But, there are many cases
9838 where you may need to debug an optimized version.
9839
9840 When you debug a program compiled with @samp{-g -O}, remember that the
9841 optimizer has rearranged your code; the debugger shows you what is
9842 really there. Do not be too surprised when the execution path does not
9843 exactly match your source file! An extreme example: if you define a
9844 variable, but never use it, @value{GDBN} never sees that
9845 variable---because the compiler optimizes it out of existence.
9846
9847 Some things do not work as well with @samp{-g -O} as with just
9848 @samp{-g}, particularly on machines with instruction scheduling. If in
9849 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
9850 please report it to us as a bug (including a test case!).
9851 @xref{Variables}, for more information about debugging optimized code.
9852
9853 @menu
9854 * Inline Functions:: How @value{GDBN} presents inlining
9855 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
9856 @end menu
9857
9858 @node Inline Functions
9859 @section Inline Functions
9860 @cindex inline functions, debugging
9861
9862 @dfn{Inlining} is an optimization that inserts a copy of the function
9863 body directly at each call site, instead of jumping to a shared
9864 routine. @value{GDBN} displays inlined functions just like
9865 non-inlined functions. They appear in backtraces. You can view their
9866 arguments and local variables, step into them with @code{step}, skip
9867 them with @code{next}, and escape from them with @code{finish}.
9868 You can check whether a function was inlined by using the
9869 @code{info frame} command.
9870
9871 For @value{GDBN} to support inlined functions, the compiler must
9872 record information about inlining in the debug information ---
9873 @value{NGCC} using the @sc{dwarf 2} format does this, and several
9874 other compilers do also. @value{GDBN} only supports inlined functions
9875 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
9876 do not emit two required attributes (@samp{DW_AT_call_file} and
9877 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
9878 function calls with earlier versions of @value{NGCC}. It instead
9879 displays the arguments and local variables of inlined functions as
9880 local variables in the caller.
9881
9882 The body of an inlined function is directly included at its call site;
9883 unlike a non-inlined function, there are no instructions devoted to
9884 the call. @value{GDBN} still pretends that the call site and the
9885 start of the inlined function are different instructions. Stepping to
9886 the call site shows the call site, and then stepping again shows
9887 the first line of the inlined function, even though no additional
9888 instructions are executed.
9889
9890 This makes source-level debugging much clearer; you can see both the
9891 context of the call and then the effect of the call. Only stepping by
9892 a single instruction using @code{stepi} or @code{nexti} does not do
9893 this; single instruction steps always show the inlined body.
9894
9895 There are some ways that @value{GDBN} does not pretend that inlined
9896 function calls are the same as normal calls:
9897
9898 @itemize @bullet
9899 @item
9900 Setting breakpoints at the call site of an inlined function may not
9901 work, because the call site does not contain any code. @value{GDBN}
9902 may incorrectly move the breakpoint to the next line of the enclosing
9903 function, after the call. This limitation will be removed in a future
9904 version of @value{GDBN}; until then, set a breakpoint on an earlier line
9905 or inside the inlined function instead.
9906
9907 @item
9908 @value{GDBN} cannot locate the return value of inlined calls after
9909 using the @code{finish} command. This is a limitation of compiler-generated
9910 debugging information; after @code{finish}, you can step to the next line
9911 and print a variable where your program stored the return value.
9912
9913 @end itemize
9914
9915 @node Tail Call Frames
9916 @section Tail Call Frames
9917 @cindex tail call frames, debugging
9918
9919 Function @code{B} can call function @code{C} in its very last statement. In
9920 unoptimized compilation the call of @code{C} is immediately followed by return
9921 instruction at the end of @code{B} code. Optimizing compiler may replace the
9922 call and return in function @code{B} into one jump to function @code{C}
9923 instead. Such use of a jump instruction is called @dfn{tail call}.
9924
9925 During execution of function @code{C}, there will be no indication in the
9926 function call stack frames that it was tail-called from @code{B}. If function
9927 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
9928 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
9929 some cases @value{GDBN} can determine that @code{C} was tail-called from
9930 @code{B}, and it will then create fictitious call frame for that, with the
9931 return address set up as if @code{B} called @code{C} normally.
9932
9933 This functionality is currently supported only by DWARF 2 debugging format and
9934 the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
9935 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
9936 this information.
9937
9938 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
9939 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
9940
9941 @smallexample
9942 (gdb) x/i $pc - 2
9943 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
9944 (gdb) info frame
9945 Stack level 1, frame at 0x7fffffffda30:
9946 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
9947 tail call frame, caller of frame at 0x7fffffffda30
9948 source language c++.
9949 Arglist at unknown address.
9950 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
9951 @end smallexample
9952
9953 The detection of all the possible code path executions can find them ambiguous.
9954 There is no execution history stored (possible @ref{Reverse Execution} is never
9955 used for this purpose) and the last known caller could have reached the known
9956 callee by multiple different jump sequences. In such case @value{GDBN} still
9957 tries to show at least all the unambiguous top tail callers and all the
9958 unambiguous bottom tail calees, if any.
9959
9960 @table @code
9961 @anchor{set debug entry-values}
9962 @item set debug entry-values
9963 @kindex set debug entry-values
9964 When set to on, enables printing of analysis messages for both frame argument
9965 values at function entry and tail calls. It will show all the possible valid
9966 tail calls code paths it has considered. It will also print the intersection
9967 of them with the final unambiguous (possibly partial or even empty) code path
9968 result.
9969
9970 @item show debug entry-values
9971 @kindex show debug entry-values
9972 Show the current state of analysis messages printing for both frame argument
9973 values at function entry and tail calls.
9974 @end table
9975
9976 The analysis messages for tail calls can for example show why the virtual tail
9977 call frame for function @code{c} has not been recognized (due to the indirect
9978 reference by variable @code{x}):
9979
9980 @smallexample
9981 static void __attribute__((noinline, noclone)) c (void);
9982 void (*x) (void) = c;
9983 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
9984 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
9985 int main (void) @{ x (); return 0; @}
9986
9987 Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
9988 DW_TAG_GNU_call_site 0x40039a in main
9989 a () at t.c:3
9990 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
9991 (gdb) bt
9992 #0 a () at t.c:3
9993 #1 0x000000000040039a in main () at t.c:5
9994 @end smallexample
9995
9996 Another possibility is an ambiguous virtual tail call frames resolution:
9997
9998 @smallexample
9999 int i;
10000 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
10001 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
10002 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
10003 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
10004 static void __attribute__((noinline, noclone)) b (void)
10005 @{ if (i) c (); else e (); @}
10006 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
10007 int main (void) @{ a (); return 0; @}
10008
10009 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
10010 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
10011 tailcall: reduced: 0x4004d2(a) |
10012 (gdb) bt
10013 #0 f () at t.c:2
10014 #1 0x00000000004004d2 in a () at t.c:8
10015 #2 0x0000000000400395 in main () at t.c:9
10016 @end smallexample
10017
10018 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
10019 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
10020
10021 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
10022 @ifset HAVE_MAKEINFO_CLICK
10023 @set ARROW @click{}
10024 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
10025 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
10026 @end ifset
10027 @ifclear HAVE_MAKEINFO_CLICK
10028 @set ARROW ->
10029 @set CALLSEQ1B @value{CALLSEQ1A}
10030 @set CALLSEQ2B @value{CALLSEQ2A}
10031 @end ifclear
10032
10033 Frames #0 and #2 are real, #1 is a virtual tail call frame.
10034 The code can have possible execution paths @value{CALLSEQ1B} or
10035 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
10036
10037 @code{initial:} state shows some random possible calling sequence @value{GDBN}
10038 has found. It then finds another possible calling sequcen - that one is
10039 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
10040 printed as the @code{reduced:} calling sequence. That one could have many
10041 futher @code{compare:} and @code{reduced:} statements as long as there remain
10042 any non-ambiguous sequence entries.
10043
10044 For the frame of function @code{b} in both cases there are different possible
10045 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
10046 also ambigous. The only non-ambiguous frame is the one for function @code{a},
10047 therefore this one is displayed to the user while the ambiguous frames are
10048 omitted.
10049
10050 There can be also reasons why printing of frame argument values at function
10051 entry may fail:
10052
10053 @smallexample
10054 int v;
10055 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
10056 static void __attribute__((noinline, noclone)) a (int i);
10057 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
10058 static void __attribute__((noinline, noclone)) a (int i)
10059 @{ if (i) b (i - 1); else c (0); @}
10060 int main (void) @{ a (5); return 0; @}
10061
10062 (gdb) bt
10063 #0 c (i=i@@entry=0) at t.c:2
10064 #1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
10065 function "a" at 0x400420 can call itself via tail calls
10066 i=<optimized out>) at t.c:6
10067 #2 0x000000000040036e in main () at t.c:7
10068 @end smallexample
10069
10070 @value{GDBN} cannot find out from the inferior state if and how many times did
10071 function @code{a} call itself (via function @code{b}) as these calls would be
10072 tail calls. Such tail calls would modify thue @code{i} variable, therefore
10073 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
10074 prints @code{<optimized out>} instead.
10075
10076 @node Macros
10077 @chapter C Preprocessor Macros
10078
10079 Some languages, such as C and C@t{++}, provide a way to define and invoke
10080 ``preprocessor macros'' which expand into strings of tokens.
10081 @value{GDBN} can evaluate expressions containing macro invocations, show
10082 the result of macro expansion, and show a macro's definition, including
10083 where it was defined.
10084
10085 You may need to compile your program specially to provide @value{GDBN}
10086 with information about preprocessor macros. Most compilers do not
10087 include macros in their debugging information, even when you compile
10088 with the @option{-g} flag. @xref{Compilation}.
10089
10090 A program may define a macro at one point, remove that definition later,
10091 and then provide a different definition after that. Thus, at different
10092 points in the program, a macro may have different definitions, or have
10093 no definition at all. If there is a current stack frame, @value{GDBN}
10094 uses the macros in scope at that frame's source code line. Otherwise,
10095 @value{GDBN} uses the macros in scope at the current listing location;
10096 see @ref{List}.
10097
10098 Whenever @value{GDBN} evaluates an expression, it always expands any
10099 macro invocations present in the expression. @value{GDBN} also provides
10100 the following commands for working with macros explicitly.
10101
10102 @table @code
10103
10104 @kindex macro expand
10105 @cindex macro expansion, showing the results of preprocessor
10106 @cindex preprocessor macro expansion, showing the results of
10107 @cindex expanding preprocessor macros
10108 @item macro expand @var{expression}
10109 @itemx macro exp @var{expression}
10110 Show the results of expanding all preprocessor macro invocations in
10111 @var{expression}. Since @value{GDBN} simply expands macros, but does
10112 not parse the result, @var{expression} need not be a valid expression;
10113 it can be any string of tokens.
10114
10115 @kindex macro exp1
10116 @item macro expand-once @var{expression}
10117 @itemx macro exp1 @var{expression}
10118 @cindex expand macro once
10119 @i{(This command is not yet implemented.)} Show the results of
10120 expanding those preprocessor macro invocations that appear explicitly in
10121 @var{expression}. Macro invocations appearing in that expansion are
10122 left unchanged. This command allows you to see the effect of a
10123 particular macro more clearly, without being confused by further
10124 expansions. Since @value{GDBN} simply expands macros, but does not
10125 parse the result, @var{expression} need not be a valid expression; it
10126 can be any string of tokens.
10127
10128 @kindex info macro
10129 @cindex macro definition, showing
10130 @cindex definition of a macro, showing
10131 @cindex macros, from debug info
10132 @item info macro [-a|-all] [--] @var{macro}
10133 Show the current definition or all definitions of the named @var{macro},
10134 and describe the source location or compiler command-line where that
10135 definition was established. The optional double dash is to signify the end of
10136 argument processing and the beginning of @var{macro} for non C-like macros where
10137 the macro may begin with a hyphen.
10138
10139 @kindex info macros
10140 @item info macros @var{linespec}
10141 Show all macro definitions that are in effect at the location specified
10142 by @var{linespec}, and describe the source location or compiler
10143 command-line where those definitions were established.
10144
10145 @kindex macro define
10146 @cindex user-defined macros
10147 @cindex defining macros interactively
10148 @cindex macros, user-defined
10149 @item macro define @var{macro} @var{replacement-list}
10150 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
10151 Introduce a definition for a preprocessor macro named @var{macro},
10152 invocations of which are replaced by the tokens given in
10153 @var{replacement-list}. The first form of this command defines an
10154 ``object-like'' macro, which takes no arguments; the second form
10155 defines a ``function-like'' macro, which takes the arguments given in
10156 @var{arglist}.
10157
10158 A definition introduced by this command is in scope in every
10159 expression evaluated in @value{GDBN}, until it is removed with the
10160 @code{macro undef} command, described below. The definition overrides
10161 all definitions for @var{macro} present in the program being debugged,
10162 as well as any previous user-supplied definition.
10163
10164 @kindex macro undef
10165 @item macro undef @var{macro}
10166 Remove any user-supplied definition for the macro named @var{macro}.
10167 This command only affects definitions provided with the @code{macro
10168 define} command, described above; it cannot remove definitions present
10169 in the program being debugged.
10170
10171 @kindex macro list
10172 @item macro list
10173 List all the macros defined using the @code{macro define} command.
10174 @end table
10175
10176 @cindex macros, example of debugging with
10177 Here is a transcript showing the above commands in action. First, we
10178 show our source files:
10179
10180 @smallexample
10181 $ cat sample.c
10182 #include <stdio.h>
10183 #include "sample.h"
10184
10185 #define M 42
10186 #define ADD(x) (M + x)
10187
10188 main ()
10189 @{
10190 #define N 28
10191 printf ("Hello, world!\n");
10192 #undef N
10193 printf ("We're so creative.\n");
10194 #define N 1729
10195 printf ("Goodbye, world!\n");
10196 @}
10197 $ cat sample.h
10198 #define Q <
10199 $
10200 @end smallexample
10201
10202 Now, we compile the program using the @sc{gnu} C compiler,
10203 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
10204 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
10205 and @option{-gdwarf-4}; we recommend always choosing the most recent
10206 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
10207 includes information about preprocessor macros in the debugging
10208 information.
10209
10210 @smallexample
10211 $ gcc -gdwarf-2 -g3 sample.c -o sample
10212 $
10213 @end smallexample
10214
10215 Now, we start @value{GDBN} on our sample program:
10216
10217 @smallexample
10218 $ gdb -nw sample
10219 GNU gdb 2002-05-06-cvs
10220 Copyright 2002 Free Software Foundation, Inc.
10221 GDB is free software, @dots{}
10222 (@value{GDBP})
10223 @end smallexample
10224
10225 We can expand macros and examine their definitions, even when the
10226 program is not running. @value{GDBN} uses the current listing position
10227 to decide which macro definitions are in scope:
10228
10229 @smallexample
10230 (@value{GDBP}) list main
10231 3
10232 4 #define M 42
10233 5 #define ADD(x) (M + x)
10234 6
10235 7 main ()
10236 8 @{
10237 9 #define N 28
10238 10 printf ("Hello, world!\n");
10239 11 #undef N
10240 12 printf ("We're so creative.\n");
10241 (@value{GDBP}) info macro ADD
10242 Defined at /home/jimb/gdb/macros/play/sample.c:5
10243 #define ADD(x) (M + x)
10244 (@value{GDBP}) info macro Q
10245 Defined at /home/jimb/gdb/macros/play/sample.h:1
10246 included at /home/jimb/gdb/macros/play/sample.c:2
10247 #define Q <
10248 (@value{GDBP}) macro expand ADD(1)
10249 expands to: (42 + 1)
10250 (@value{GDBP}) macro expand-once ADD(1)
10251 expands to: once (M + 1)
10252 (@value{GDBP})
10253 @end smallexample
10254
10255 In the example above, note that @code{macro expand-once} expands only
10256 the macro invocation explicit in the original text --- the invocation of
10257 @code{ADD} --- but does not expand the invocation of the macro @code{M},
10258 which was introduced by @code{ADD}.
10259
10260 Once the program is running, @value{GDBN} uses the macro definitions in
10261 force at the source line of the current stack frame:
10262
10263 @smallexample
10264 (@value{GDBP}) break main
10265 Breakpoint 1 at 0x8048370: file sample.c, line 10.
10266 (@value{GDBP}) run
10267 Starting program: /home/jimb/gdb/macros/play/sample
10268
10269 Breakpoint 1, main () at sample.c:10
10270 10 printf ("Hello, world!\n");
10271 (@value{GDBP})
10272 @end smallexample
10273
10274 At line 10, the definition of the macro @code{N} at line 9 is in force:
10275
10276 @smallexample
10277 (@value{GDBP}) info macro N
10278 Defined at /home/jimb/gdb/macros/play/sample.c:9
10279 #define N 28
10280 (@value{GDBP}) macro expand N Q M
10281 expands to: 28 < 42
10282 (@value{GDBP}) print N Q M
10283 $1 = 1
10284 (@value{GDBP})
10285 @end smallexample
10286
10287 As we step over directives that remove @code{N}'s definition, and then
10288 give it a new definition, @value{GDBN} finds the definition (or lack
10289 thereof) in force at each point:
10290
10291 @smallexample
10292 (@value{GDBP}) next
10293 Hello, world!
10294 12 printf ("We're so creative.\n");
10295 (@value{GDBP}) info macro N
10296 The symbol `N' has no definition as a C/C++ preprocessor macro
10297 at /home/jimb/gdb/macros/play/sample.c:12
10298 (@value{GDBP}) next
10299 We're so creative.
10300 14 printf ("Goodbye, world!\n");
10301 (@value{GDBP}) info macro N
10302 Defined at /home/jimb/gdb/macros/play/sample.c:13
10303 #define N 1729
10304 (@value{GDBP}) macro expand N Q M
10305 expands to: 1729 < 42
10306 (@value{GDBP}) print N Q M
10307 $2 = 0
10308 (@value{GDBP})
10309 @end smallexample
10310
10311 In addition to source files, macros can be defined on the compilation command
10312 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
10313 such a way, @value{GDBN} displays the location of their definition as line zero
10314 of the source file submitted to the compiler.
10315
10316 @smallexample
10317 (@value{GDBP}) info macro __STDC__
10318 Defined at /home/jimb/gdb/macros/play/sample.c:0
10319 -D__STDC__=1
10320 (@value{GDBP})
10321 @end smallexample
10322
10323
10324 @node Tracepoints
10325 @chapter Tracepoints
10326 @c This chapter is based on the documentation written by Michael
10327 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
10328
10329 @cindex tracepoints
10330 In some applications, it is not feasible for the debugger to interrupt
10331 the program's execution long enough for the developer to learn
10332 anything helpful about its behavior. If the program's correctness
10333 depends on its real-time behavior, delays introduced by a debugger
10334 might cause the program to change its behavior drastically, or perhaps
10335 fail, even when the code itself is correct. It is useful to be able
10336 to observe the program's behavior without interrupting it.
10337
10338 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
10339 specify locations in the program, called @dfn{tracepoints}, and
10340 arbitrary expressions to evaluate when those tracepoints are reached.
10341 Later, using the @code{tfind} command, you can examine the values
10342 those expressions had when the program hit the tracepoints. The
10343 expressions may also denote objects in memory---structures or arrays,
10344 for example---whose values @value{GDBN} should record; while visiting
10345 a particular tracepoint, you may inspect those objects as if they were
10346 in memory at that moment. However, because @value{GDBN} records these
10347 values without interacting with you, it can do so quickly and
10348 unobtrusively, hopefully not disturbing the program's behavior.
10349
10350 The tracepoint facility is currently available only for remote
10351 targets. @xref{Targets}. In addition, your remote target must know
10352 how to collect trace data. This functionality is implemented in the
10353 remote stub; however, none of the stubs distributed with @value{GDBN}
10354 support tracepoints as of this writing. The format of the remote
10355 packets used to implement tracepoints are described in @ref{Tracepoint
10356 Packets}.
10357
10358 It is also possible to get trace data from a file, in a manner reminiscent
10359 of corefiles; you specify the filename, and use @code{tfind} to search
10360 through the file. @xref{Trace Files}, for more details.
10361
10362 This chapter describes the tracepoint commands and features.
10363
10364 @menu
10365 * Set Tracepoints::
10366 * Analyze Collected Data::
10367 * Tracepoint Variables::
10368 * Trace Files::
10369 @end menu
10370
10371 @node Set Tracepoints
10372 @section Commands to Set Tracepoints
10373
10374 Before running such a @dfn{trace experiment}, an arbitrary number of
10375 tracepoints can be set. A tracepoint is actually a special type of
10376 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
10377 standard breakpoint commands. For instance, as with breakpoints,
10378 tracepoint numbers are successive integers starting from one, and many
10379 of the commands associated with tracepoints take the tracepoint number
10380 as their argument, to identify which tracepoint to work on.
10381
10382 For each tracepoint, you can specify, in advance, some arbitrary set
10383 of data that you want the target to collect in the trace buffer when
10384 it hits that tracepoint. The collected data can include registers,
10385 local variables, or global data. Later, you can use @value{GDBN}
10386 commands to examine the values these data had at the time the
10387 tracepoint was hit.
10388
10389 Tracepoints do not support every breakpoint feature. Ignore counts on
10390 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
10391 commands when they are hit. Tracepoints may not be thread-specific
10392 either.
10393
10394 @cindex fast tracepoints
10395 Some targets may support @dfn{fast tracepoints}, which are inserted in
10396 a different way (such as with a jump instead of a trap), that is
10397 faster but possibly restricted in where they may be installed.
10398
10399 @cindex static tracepoints
10400 @cindex markers, static tracepoints
10401 @cindex probing markers, static tracepoints
10402 Regular and fast tracepoints are dynamic tracing facilities, meaning
10403 that they can be used to insert tracepoints at (almost) any location
10404 in the target. Some targets may also support controlling @dfn{static
10405 tracepoints} from @value{GDBN}. With static tracing, a set of
10406 instrumentation points, also known as @dfn{markers}, are embedded in
10407 the target program, and can be activated or deactivated by name or
10408 address. These are usually placed at locations which facilitate
10409 investigating what the target is actually doing. @value{GDBN}'s
10410 support for static tracing includes being able to list instrumentation
10411 points, and attach them with @value{GDBN} defined high level
10412 tracepoints that expose the whole range of convenience of
10413 @value{GDBN}'s tracepoints support. Namely, support for collecting
10414 registers values and values of global or local (to the instrumentation
10415 point) variables; tracepoint conditions and trace state variables.
10416 The act of installing a @value{GDBN} static tracepoint on an
10417 instrumentation point, or marker, is referred to as @dfn{probing} a
10418 static tracepoint marker.
10419
10420 @code{gdbserver} supports tracepoints on some target systems.
10421 @xref{Server,,Tracepoints support in @code{gdbserver}}.
10422
10423 This section describes commands to set tracepoints and associated
10424 conditions and actions.
10425
10426 @menu
10427 * Create and Delete Tracepoints::
10428 * Enable and Disable Tracepoints::
10429 * Tracepoint Passcounts::
10430 * Tracepoint Conditions::
10431 * Trace State Variables::
10432 * Tracepoint Actions::
10433 * Listing Tracepoints::
10434 * Listing Static Tracepoint Markers::
10435 * Starting and Stopping Trace Experiments::
10436 * Tracepoint Restrictions::
10437 @end menu
10438
10439 @node Create and Delete Tracepoints
10440 @subsection Create and Delete Tracepoints
10441
10442 @table @code
10443 @cindex set tracepoint
10444 @kindex trace
10445 @item trace @var{location}
10446 The @code{trace} command is very similar to the @code{break} command.
10447 Its argument @var{location} can be a source line, a function name, or
10448 an address in the target program. @xref{Specify Location}. The
10449 @code{trace} command defines a tracepoint, which is a point in the
10450 target program where the debugger will briefly stop, collect some
10451 data, and then allow the program to continue. Setting a tracepoint or
10452 changing its actions takes effect immediately if the remote stub
10453 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
10454 in tracing}).
10455 If remote stub doesn't support the @samp{InstallInTrace} feature, all
10456 these changes don't take effect until the next @code{tstart}
10457 command, and once a trace experiment is running, further changes will
10458 not have any effect until the next trace experiment starts. In addition,
10459 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
10460 address is not yet resolved. (This is similar to pending breakpoints.)
10461 Pending tracepoints are not downloaded to the target and not installed
10462 until they are resolved. The resolution of pending tracepoints requires
10463 @value{GDBN} support---when debugging with the remote target, and
10464 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
10465 tracing}), pending tracepoints can not be resolved (and downloaded to
10466 the remote stub) while @value{GDBN} is disconnected.
10467
10468 Here are some examples of using the @code{trace} command:
10469
10470 @smallexample
10471 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
10472
10473 (@value{GDBP}) @b{trace +2} // 2 lines forward
10474
10475 (@value{GDBP}) @b{trace my_function} // first source line of function
10476
10477 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
10478
10479 (@value{GDBP}) @b{trace *0x2117c4} // an address
10480 @end smallexample
10481
10482 @noindent
10483 You can abbreviate @code{trace} as @code{tr}.
10484
10485 @item trace @var{location} if @var{cond}
10486 Set a tracepoint with condition @var{cond}; evaluate the expression
10487 @var{cond} each time the tracepoint is reached, and collect data only
10488 if the value is nonzero---that is, if @var{cond} evaluates as true.
10489 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
10490 information on tracepoint conditions.
10491
10492 @item ftrace @var{location} [ if @var{cond} ]
10493 @cindex set fast tracepoint
10494 @cindex fast tracepoints, setting
10495 @kindex ftrace
10496 The @code{ftrace} command sets a fast tracepoint. For targets that
10497 support them, fast tracepoints will use a more efficient but possibly
10498 less general technique to trigger data collection, such as a jump
10499 instruction instead of a trap, or some sort of hardware support. It
10500 may not be possible to create a fast tracepoint at the desired
10501 location, in which case the command will exit with an explanatory
10502 message.
10503
10504 @value{GDBN} handles arguments to @code{ftrace} exactly as for
10505 @code{trace}.
10506
10507 On 32-bit x86-architecture systems, fast tracepoints normally need to
10508 be placed at an instruction that is 5 bytes or longer, but can be
10509 placed at 4-byte instructions if the low 64K of memory of the target
10510 program is available to install trampolines. Some Unix-type systems,
10511 such as @sc{gnu}/Linux, exclude low addresses from the program's
10512 address space; but for instance with the Linux kernel it is possible
10513 to let @value{GDBN} use this area by doing a @command{sysctl} command
10514 to set the @code{mmap_min_addr} kernel parameter, as in
10515
10516 @example
10517 sudo sysctl -w vm.mmap_min_addr=32768
10518 @end example
10519
10520 @noindent
10521 which sets the low address to 32K, which leaves plenty of room for
10522 trampolines. The minimum address should be set to a page boundary.
10523
10524 @item strace @var{location} [ if @var{cond} ]
10525 @cindex set static tracepoint
10526 @cindex static tracepoints, setting
10527 @cindex probe static tracepoint marker
10528 @kindex strace
10529 The @code{strace} command sets a static tracepoint. For targets that
10530 support it, setting a static tracepoint probes a static
10531 instrumentation point, or marker, found at @var{location}. It may not
10532 be possible to set a static tracepoint at the desired location, in
10533 which case the command will exit with an explanatory message.
10534
10535 @value{GDBN} handles arguments to @code{strace} exactly as for
10536 @code{trace}, with the addition that the user can also specify
10537 @code{-m @var{marker}} as @var{location}. This probes the marker
10538 identified by the @var{marker} string identifier. This identifier
10539 depends on the static tracepoint backend library your program is
10540 using. You can find all the marker identifiers in the @samp{ID} field
10541 of the @code{info static-tracepoint-markers} command output.
10542 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
10543 Markers}. For example, in the following small program using the UST
10544 tracing engine:
10545
10546 @smallexample
10547 main ()
10548 @{
10549 trace_mark(ust, bar33, "str %s", "FOOBAZ");
10550 @}
10551 @end smallexample
10552
10553 @noindent
10554 the marker id is composed of joining the first two arguments to the
10555 @code{trace_mark} call with a slash, which translates to:
10556
10557 @smallexample
10558 (@value{GDBP}) info static-tracepoint-markers
10559 Cnt Enb ID Address What
10560 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
10561 Data: "str %s"
10562 [etc...]
10563 @end smallexample
10564
10565 @noindent
10566 so you may probe the marker above with:
10567
10568 @smallexample
10569 (@value{GDBP}) strace -m ust/bar33
10570 @end smallexample
10571
10572 Static tracepoints accept an extra collect action --- @code{collect
10573 $_sdata}. This collects arbitrary user data passed in the probe point
10574 call to the tracing library. In the UST example above, you'll see
10575 that the third argument to @code{trace_mark} is a printf-like format
10576 string. The user data is then the result of running that formating
10577 string against the following arguments. Note that @code{info
10578 static-tracepoint-markers} command output lists that format string in
10579 the @samp{Data:} field.
10580
10581 You can inspect this data when analyzing the trace buffer, by printing
10582 the $_sdata variable like any other variable available to
10583 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
10584
10585 @vindex $tpnum
10586 @cindex last tracepoint number
10587 @cindex recent tracepoint number
10588 @cindex tracepoint number
10589 The convenience variable @code{$tpnum} records the tracepoint number
10590 of the most recently set tracepoint.
10591
10592 @kindex delete tracepoint
10593 @cindex tracepoint deletion
10594 @item delete tracepoint @r{[}@var{num}@r{]}
10595 Permanently delete one or more tracepoints. With no argument, the
10596 default is to delete all tracepoints. Note that the regular
10597 @code{delete} command can remove tracepoints also.
10598
10599 Examples:
10600
10601 @smallexample
10602 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
10603
10604 (@value{GDBP}) @b{delete trace} // remove all tracepoints
10605 @end smallexample
10606
10607 @noindent
10608 You can abbreviate this command as @code{del tr}.
10609 @end table
10610
10611 @node Enable and Disable Tracepoints
10612 @subsection Enable and Disable Tracepoints
10613
10614 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
10615
10616 @table @code
10617 @kindex disable tracepoint
10618 @item disable tracepoint @r{[}@var{num}@r{]}
10619 Disable tracepoint @var{num}, or all tracepoints if no argument
10620 @var{num} is given. A disabled tracepoint will have no effect during
10621 a trace experiment, but it is not forgotten. You can re-enable
10622 a disabled tracepoint using the @code{enable tracepoint} command.
10623 If the command is issued during a trace experiment and the debug target
10624 has support for disabling tracepoints during a trace experiment, then the
10625 change will be effective immediately. Otherwise, it will be applied to the
10626 next trace experiment.
10627
10628 @kindex enable tracepoint
10629 @item enable tracepoint @r{[}@var{num}@r{]}
10630 Enable tracepoint @var{num}, or all tracepoints. If this command is
10631 issued during a trace experiment and the debug target supports enabling
10632 tracepoints during a trace experiment, then the enabled tracepoints will
10633 become effective immediately. Otherwise, they will become effective the
10634 next time a trace experiment is run.
10635 @end table
10636
10637 @node Tracepoint Passcounts
10638 @subsection Tracepoint Passcounts
10639
10640 @table @code
10641 @kindex passcount
10642 @cindex tracepoint pass count
10643 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
10644 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
10645 automatically stop a trace experiment. If a tracepoint's passcount is
10646 @var{n}, then the trace experiment will be automatically stopped on
10647 the @var{n}'th time that tracepoint is hit. If the tracepoint number
10648 @var{num} is not specified, the @code{passcount} command sets the
10649 passcount of the most recently defined tracepoint. If no passcount is
10650 given, the trace experiment will run until stopped explicitly by the
10651 user.
10652
10653 Examples:
10654
10655 @smallexample
10656 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
10657 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
10658
10659 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
10660 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
10661 (@value{GDBP}) @b{trace foo}
10662 (@value{GDBP}) @b{pass 3}
10663 (@value{GDBP}) @b{trace bar}
10664 (@value{GDBP}) @b{pass 2}
10665 (@value{GDBP}) @b{trace baz}
10666 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
10667 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
10668 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
10669 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
10670 @end smallexample
10671 @end table
10672
10673 @node Tracepoint Conditions
10674 @subsection Tracepoint Conditions
10675 @cindex conditional tracepoints
10676 @cindex tracepoint conditions
10677
10678 The simplest sort of tracepoint collects data every time your program
10679 reaches a specified place. You can also specify a @dfn{condition} for
10680 a tracepoint. A condition is just a Boolean expression in your
10681 programming language (@pxref{Expressions, ,Expressions}). A
10682 tracepoint with a condition evaluates the expression each time your
10683 program reaches it, and data collection happens only if the condition
10684 is true.
10685
10686 Tracepoint conditions can be specified when a tracepoint is set, by
10687 using @samp{if} in the arguments to the @code{trace} command.
10688 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
10689 also be set or changed at any time with the @code{condition} command,
10690 just as with breakpoints.
10691
10692 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
10693 the conditional expression itself. Instead, @value{GDBN} encodes the
10694 expression into an agent expression (@pxref{Agent Expressions})
10695 suitable for execution on the target, independently of @value{GDBN}.
10696 Global variables become raw memory locations, locals become stack
10697 accesses, and so forth.
10698
10699 For instance, suppose you have a function that is usually called
10700 frequently, but should not be called after an error has occurred. You
10701 could use the following tracepoint command to collect data about calls
10702 of that function that happen while the error code is propagating
10703 through the program; an unconditional tracepoint could end up
10704 collecting thousands of useless trace frames that you would have to
10705 search through.
10706
10707 @smallexample
10708 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
10709 @end smallexample
10710
10711 @node Trace State Variables
10712 @subsection Trace State Variables
10713 @cindex trace state variables
10714
10715 A @dfn{trace state variable} is a special type of variable that is
10716 created and managed by target-side code. The syntax is the same as
10717 that for GDB's convenience variables (a string prefixed with ``$''),
10718 but they are stored on the target. They must be created explicitly,
10719 using a @code{tvariable} command. They are always 64-bit signed
10720 integers.
10721
10722 Trace state variables are remembered by @value{GDBN}, and downloaded
10723 to the target along with tracepoint information when the trace
10724 experiment starts. There are no intrinsic limits on the number of
10725 trace state variables, beyond memory limitations of the target.
10726
10727 @cindex convenience variables, and trace state variables
10728 Although trace state variables are managed by the target, you can use
10729 them in print commands and expressions as if they were convenience
10730 variables; @value{GDBN} will get the current value from the target
10731 while the trace experiment is running. Trace state variables share
10732 the same namespace as other ``$'' variables, which means that you
10733 cannot have trace state variables with names like @code{$23} or
10734 @code{$pc}, nor can you have a trace state variable and a convenience
10735 variable with the same name.
10736
10737 @table @code
10738
10739 @item tvariable $@var{name} [ = @var{expression} ]
10740 @kindex tvariable
10741 The @code{tvariable} command creates a new trace state variable named
10742 @code{$@var{name}}, and optionally gives it an initial value of
10743 @var{expression}. @var{expression} is evaluated when this command is
10744 entered; the result will be converted to an integer if possible,
10745 otherwise @value{GDBN} will report an error. A subsequent
10746 @code{tvariable} command specifying the same name does not create a
10747 variable, but instead assigns the supplied initial value to the
10748 existing variable of that name, overwriting any previous initial
10749 value. The default initial value is 0.
10750
10751 @item info tvariables
10752 @kindex info tvariables
10753 List all the trace state variables along with their initial values.
10754 Their current values may also be displayed, if the trace experiment is
10755 currently running.
10756
10757 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
10758 @kindex delete tvariable
10759 Delete the given trace state variables, or all of them if no arguments
10760 are specified.
10761
10762 @end table
10763
10764 @node Tracepoint Actions
10765 @subsection Tracepoint Action Lists
10766
10767 @table @code
10768 @kindex actions
10769 @cindex tracepoint actions
10770 @item actions @r{[}@var{num}@r{]}
10771 This command will prompt for a list of actions to be taken when the
10772 tracepoint is hit. If the tracepoint number @var{num} is not
10773 specified, this command sets the actions for the one that was most
10774 recently defined (so that you can define a tracepoint and then say
10775 @code{actions} without bothering about its number). You specify the
10776 actions themselves on the following lines, one action at a time, and
10777 terminate the actions list with a line containing just @code{end}. So
10778 far, the only defined actions are @code{collect}, @code{teval}, and
10779 @code{while-stepping}.
10780
10781 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
10782 Commands, ,Breakpoint Command Lists}), except that only the defined
10783 actions are allowed; any other @value{GDBN} command is rejected.
10784
10785 @cindex remove actions from a tracepoint
10786 To remove all actions from a tracepoint, type @samp{actions @var{num}}
10787 and follow it immediately with @samp{end}.
10788
10789 @smallexample
10790 (@value{GDBP}) @b{collect @var{data}} // collect some data
10791
10792 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
10793
10794 (@value{GDBP}) @b{end} // signals the end of actions.
10795 @end smallexample
10796
10797 In the following example, the action list begins with @code{collect}
10798 commands indicating the things to be collected when the tracepoint is
10799 hit. Then, in order to single-step and collect additional data
10800 following the tracepoint, a @code{while-stepping} command is used,
10801 followed by the list of things to be collected after each step in a
10802 sequence of single steps. The @code{while-stepping} command is
10803 terminated by its own separate @code{end} command. Lastly, the action
10804 list is terminated by an @code{end} command.
10805
10806 @smallexample
10807 (@value{GDBP}) @b{trace foo}
10808 (@value{GDBP}) @b{actions}
10809 Enter actions for tracepoint 1, one per line:
10810 > collect bar,baz
10811 > collect $regs
10812 > while-stepping 12
10813 > collect $pc, arr[i]
10814 > end
10815 end
10816 @end smallexample
10817
10818 @kindex collect @r{(tracepoints)}
10819 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
10820 Collect values of the given expressions when the tracepoint is hit.
10821 This command accepts a comma-separated list of any valid expressions.
10822 In addition to global, static, or local variables, the following
10823 special arguments are supported:
10824
10825 @table @code
10826 @item $regs
10827 Collect all registers.
10828
10829 @item $args
10830 Collect all function arguments.
10831
10832 @item $locals
10833 Collect all local variables.
10834
10835 @item $_ret
10836 Collect the return address. This is helpful if you want to see more
10837 of a backtrace.
10838
10839 @item $_sdata
10840 @vindex $_sdata@r{, collect}
10841 Collect static tracepoint marker specific data. Only available for
10842 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
10843 Lists}. On the UST static tracepoints library backend, an
10844 instrumentation point resembles a @code{printf} function call. The
10845 tracing library is able to collect user specified data formatted to a
10846 character string using the format provided by the programmer that
10847 instrumented the program. Other backends have similar mechanisms.
10848 Here's an example of a UST marker call:
10849
10850 @smallexample
10851 const char master_name[] = "$your_name";
10852 trace_mark(channel1, marker1, "hello %s", master_name)
10853 @end smallexample
10854
10855 In this case, collecting @code{$_sdata} collects the string
10856 @samp{hello $yourname}. When analyzing the trace buffer, you can
10857 inspect @samp{$_sdata} like any other variable available to
10858 @value{GDBN}.
10859 @end table
10860
10861 You can give several consecutive @code{collect} commands, each one
10862 with a single argument, or one @code{collect} command with several
10863 arguments separated by commas; the effect is the same.
10864
10865 The optional @var{mods} changes the usual handling of the arguments.
10866 @code{s} requests that pointers to chars be handled as strings, in
10867 particular collecting the contents of the memory being pointed at, up
10868 to the first zero. The upper bound is by default the value of the
10869 @code{print elements} variable; if @code{s} is followed by a decimal
10870 number, that is the upper bound instead. So for instance
10871 @samp{collect/s25 mystr} collects as many as 25 characters at
10872 @samp{mystr}.
10873
10874 The command @code{info scope} (@pxref{Symbols, info scope}) is
10875 particularly useful for figuring out what data to collect.
10876
10877 @kindex teval @r{(tracepoints)}
10878 @item teval @var{expr1}, @var{expr2}, @dots{}
10879 Evaluate the given expressions when the tracepoint is hit. This
10880 command accepts a comma-separated list of expressions. The results
10881 are discarded, so this is mainly useful for assigning values to trace
10882 state variables (@pxref{Trace State Variables}) without adding those
10883 values to the trace buffer, as would be the case if the @code{collect}
10884 action were used.
10885
10886 @kindex while-stepping @r{(tracepoints)}
10887 @item while-stepping @var{n}
10888 Perform @var{n} single-step instruction traces after the tracepoint,
10889 collecting new data after each step. The @code{while-stepping}
10890 command is followed by the list of what to collect while stepping
10891 (followed by its own @code{end} command):
10892
10893 @smallexample
10894 > while-stepping 12
10895 > collect $regs, myglobal
10896 > end
10897 >
10898 @end smallexample
10899
10900 @noindent
10901 Note that @code{$pc} is not automatically collected by
10902 @code{while-stepping}; you need to explicitly collect that register if
10903 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
10904 @code{stepping}.
10905
10906 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
10907 @kindex set default-collect
10908 @cindex default collection action
10909 This variable is a list of expressions to collect at each tracepoint
10910 hit. It is effectively an additional @code{collect} action prepended
10911 to every tracepoint action list. The expressions are parsed
10912 individually for each tracepoint, so for instance a variable named
10913 @code{xyz} may be interpreted as a global for one tracepoint, and a
10914 local for another, as appropriate to the tracepoint's location.
10915
10916 @item show default-collect
10917 @kindex show default-collect
10918 Show the list of expressions that are collected by default at each
10919 tracepoint hit.
10920
10921 @end table
10922
10923 @node Listing Tracepoints
10924 @subsection Listing Tracepoints
10925
10926 @table @code
10927 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
10928 @kindex info tp @r{[}@var{n}@dots{}@r{]}
10929 @cindex information about tracepoints
10930 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
10931 Display information about the tracepoint @var{num}. If you don't
10932 specify a tracepoint number, displays information about all the
10933 tracepoints defined so far. The format is similar to that used for
10934 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
10935 command, simply restricting itself to tracepoints.
10936
10937 A tracepoint's listing may include additional information specific to
10938 tracing:
10939
10940 @itemize @bullet
10941 @item
10942 its passcount as given by the @code{passcount @var{n}} command
10943 @end itemize
10944
10945 @smallexample
10946 (@value{GDBP}) @b{info trace}
10947 Num Type Disp Enb Address What
10948 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
10949 while-stepping 20
10950 collect globfoo, $regs
10951 end
10952 collect globfoo2
10953 end
10954 pass count 1200
10955 (@value{GDBP})
10956 @end smallexample
10957
10958 @noindent
10959 This command can be abbreviated @code{info tp}.
10960 @end table
10961
10962 @node Listing Static Tracepoint Markers
10963 @subsection Listing Static Tracepoint Markers
10964
10965 @table @code
10966 @kindex info static-tracepoint-markers
10967 @cindex information about static tracepoint markers
10968 @item info static-tracepoint-markers
10969 Display information about all static tracepoint markers defined in the
10970 program.
10971
10972 For each marker, the following columns are printed:
10973
10974 @table @emph
10975 @item Count
10976 An incrementing counter, output to help readability. This is not a
10977 stable identifier.
10978 @item ID
10979 The marker ID, as reported by the target.
10980 @item Enabled or Disabled
10981 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
10982 that are not enabled.
10983 @item Address
10984 Where the marker is in your program, as a memory address.
10985 @item What
10986 Where the marker is in the source for your program, as a file and line
10987 number. If the debug information included in the program does not
10988 allow @value{GDBN} to locate the source of the marker, this column
10989 will be left blank.
10990 @end table
10991
10992 @noindent
10993 In addition, the following information may be printed for each marker:
10994
10995 @table @emph
10996 @item Data
10997 User data passed to the tracing library by the marker call. In the
10998 UST backend, this is the format string passed as argument to the
10999 marker call.
11000 @item Static tracepoints probing the marker
11001 The list of static tracepoints attached to the marker.
11002 @end table
11003
11004 @smallexample
11005 (@value{GDBP}) info static-tracepoint-markers
11006 Cnt ID Enb Address What
11007 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
11008 Data: number1 %d number2 %d
11009 Probed by static tracepoints: #2
11010 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
11011 Data: str %s
11012 (@value{GDBP})
11013 @end smallexample
11014 @end table
11015
11016 @node Starting and Stopping Trace Experiments
11017 @subsection Starting and Stopping Trace Experiments
11018
11019 @table @code
11020 @kindex tstart [ @var{notes} ]
11021 @cindex start a new trace experiment
11022 @cindex collected data discarded
11023 @item tstart
11024 This command starts the trace experiment, and begins collecting data.
11025 It has the side effect of discarding all the data collected in the
11026 trace buffer during the previous trace experiment. If any arguments
11027 are supplied, they are taken as a note and stored with the trace
11028 experiment's state. The notes may be arbitrary text, and are
11029 especially useful with disconnected tracing in a multi-user context;
11030 the notes can explain what the trace is doing, supply user contact
11031 information, and so forth.
11032
11033 @kindex tstop [ @var{notes} ]
11034 @cindex stop a running trace experiment
11035 @item tstop
11036 This command stops the trace experiment. If any arguments are
11037 supplied, they are recorded with the experiment as a note. This is
11038 useful if you are stopping a trace started by someone else, for
11039 instance if the trace is interfering with the system's behavior and
11040 needs to be stopped quickly.
11041
11042 @strong{Note}: a trace experiment and data collection may stop
11043 automatically if any tracepoint's passcount is reached
11044 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
11045
11046 @kindex tstatus
11047 @cindex status of trace data collection
11048 @cindex trace experiment, status of
11049 @item tstatus
11050 This command displays the status of the current trace data
11051 collection.
11052 @end table
11053
11054 Here is an example of the commands we described so far:
11055
11056 @smallexample
11057 (@value{GDBP}) @b{trace gdb_c_test}
11058 (@value{GDBP}) @b{actions}
11059 Enter actions for tracepoint #1, one per line.
11060 > collect $regs,$locals,$args
11061 > while-stepping 11
11062 > collect $regs
11063 > end
11064 > end
11065 (@value{GDBP}) @b{tstart}
11066 [time passes @dots{}]
11067 (@value{GDBP}) @b{tstop}
11068 @end smallexample
11069
11070 @anchor{disconnected tracing}
11071 @cindex disconnected tracing
11072 You can choose to continue running the trace experiment even if
11073 @value{GDBN} disconnects from the target, voluntarily or
11074 involuntarily. For commands such as @code{detach}, the debugger will
11075 ask what you want to do with the trace. But for unexpected
11076 terminations (@value{GDBN} crash, network outage), it would be
11077 unfortunate to lose hard-won trace data, so the variable
11078 @code{disconnected-tracing} lets you decide whether the trace should
11079 continue running without @value{GDBN}.
11080
11081 @table @code
11082 @item set disconnected-tracing on
11083 @itemx set disconnected-tracing off
11084 @kindex set disconnected-tracing
11085 Choose whether a tracing run should continue to run if @value{GDBN}
11086 has disconnected from the target. Note that @code{detach} or
11087 @code{quit} will ask you directly what to do about a running trace no
11088 matter what this variable's setting, so the variable is mainly useful
11089 for handling unexpected situations, such as loss of the network.
11090
11091 @item show disconnected-tracing
11092 @kindex show disconnected-tracing
11093 Show the current choice for disconnected tracing.
11094
11095 @end table
11096
11097 When you reconnect to the target, the trace experiment may or may not
11098 still be running; it might have filled the trace buffer in the
11099 meantime, or stopped for one of the other reasons. If it is running,
11100 it will continue after reconnection.
11101
11102 Upon reconnection, the target will upload information about the
11103 tracepoints in effect. @value{GDBN} will then compare that
11104 information to the set of tracepoints currently defined, and attempt
11105 to match them up, allowing for the possibility that the numbers may
11106 have changed due to creation and deletion in the meantime. If one of
11107 the target's tracepoints does not match any in @value{GDBN}, the
11108 debugger will create a new tracepoint, so that you have a number with
11109 which to specify that tracepoint. This matching-up process is
11110 necessarily heuristic, and it may result in useless tracepoints being
11111 created; you may simply delete them if they are of no use.
11112
11113 @cindex circular trace buffer
11114 If your target agent supports a @dfn{circular trace buffer}, then you
11115 can run a trace experiment indefinitely without filling the trace
11116 buffer; when space runs out, the agent deletes already-collected trace
11117 frames, oldest first, until there is enough room to continue
11118 collecting. This is especially useful if your tracepoints are being
11119 hit too often, and your trace gets terminated prematurely because the
11120 buffer is full. To ask for a circular trace buffer, simply set
11121 @samp{circular-trace-buffer} to on. You can set this at any time,
11122 including during tracing; if the agent can do it, it will change
11123 buffer handling on the fly, otherwise it will not take effect until
11124 the next run.
11125
11126 @table @code
11127 @item set circular-trace-buffer on
11128 @itemx set circular-trace-buffer off
11129 @kindex set circular-trace-buffer
11130 Choose whether a tracing run should use a linear or circular buffer
11131 for trace data. A linear buffer will not lose any trace data, but may
11132 fill up prematurely, while a circular buffer will discard old trace
11133 data, but it will have always room for the latest tracepoint hits.
11134
11135 @item show circular-trace-buffer
11136 @kindex show circular-trace-buffer
11137 Show the current choice for the trace buffer. Note that this may not
11138 match the agent's current buffer handling, nor is it guaranteed to
11139 match the setting that might have been in effect during a past run,
11140 for instance if you are looking at frames from a trace file.
11141
11142 @end table
11143
11144 @table @code
11145 @item set trace-user @var{text}
11146 @kindex set trace-user
11147
11148 @item show trace-user
11149 @kindex show trace-user
11150
11151 @item set trace-notes @var{text}
11152 @kindex set trace-notes
11153 Set the trace run's notes.
11154
11155 @item show trace-notes
11156 @kindex show trace-notes
11157 Show the trace run's notes.
11158
11159 @item set trace-stop-notes @var{text}
11160 @kindex set trace-stop-notes
11161 Set the trace run's stop notes. The handling of the note is as for
11162 @code{tstop} arguments; the set command is convenient way to fix a
11163 stop note that is mistaken or incomplete.
11164
11165 @item show trace-stop-notes
11166 @kindex show trace-stop-notes
11167 Show the trace run's stop notes.
11168
11169 @end table
11170
11171 @node Tracepoint Restrictions
11172 @subsection Tracepoint Restrictions
11173
11174 @cindex tracepoint restrictions
11175 There are a number of restrictions on the use of tracepoints. As
11176 described above, tracepoint data gathering occurs on the target
11177 without interaction from @value{GDBN}. Thus the full capabilities of
11178 the debugger are not available during data gathering, and then at data
11179 examination time, you will be limited by only having what was
11180 collected. The following items describe some common problems, but it
11181 is not exhaustive, and you may run into additional difficulties not
11182 mentioned here.
11183
11184 @itemize @bullet
11185
11186 @item
11187 Tracepoint expressions are intended to gather objects (lvalues). Thus
11188 the full flexibility of GDB's expression evaluator is not available.
11189 You cannot call functions, cast objects to aggregate types, access
11190 convenience variables or modify values (except by assignment to trace
11191 state variables). Some language features may implicitly call
11192 functions (for instance Objective-C fields with accessors), and therefore
11193 cannot be collected either.
11194
11195 @item
11196 Collection of local variables, either individually or in bulk with
11197 @code{$locals} or @code{$args}, during @code{while-stepping} may
11198 behave erratically. The stepping action may enter a new scope (for
11199 instance by stepping into a function), or the location of the variable
11200 may change (for instance it is loaded into a register). The
11201 tracepoint data recorded uses the location information for the
11202 variables that is correct for the tracepoint location. When the
11203 tracepoint is created, it is not possible, in general, to determine
11204 where the steps of a @code{while-stepping} sequence will advance the
11205 program---particularly if a conditional branch is stepped.
11206
11207 @item
11208 Collection of an incompletely-initialized or partially-destroyed object
11209 may result in something that @value{GDBN} cannot display, or displays
11210 in a misleading way.
11211
11212 @item
11213 When @value{GDBN} displays a pointer to character it automatically
11214 dereferences the pointer to also display characters of the string
11215 being pointed to. However, collecting the pointer during tracing does
11216 not automatically collect the string. You need to explicitly
11217 dereference the pointer and provide size information if you want to
11218 collect not only the pointer, but the memory pointed to. For example,
11219 @code{*ptr@@50} can be used to collect the 50 element array pointed to
11220 by @code{ptr}.
11221
11222 @item
11223 It is not possible to collect a complete stack backtrace at a
11224 tracepoint. Instead, you may collect the registers and a few hundred
11225 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
11226 (adjust to use the name of the actual stack pointer register on your
11227 target architecture, and the amount of stack you wish to capture).
11228 Then the @code{backtrace} command will show a partial backtrace when
11229 using a trace frame. The number of stack frames that can be examined
11230 depends on the sizes of the frames in the collected stack. Note that
11231 if you ask for a block so large that it goes past the bottom of the
11232 stack, the target agent may report an error trying to read from an
11233 invalid address.
11234
11235 @item
11236 If you do not collect registers at a tracepoint, @value{GDBN} can
11237 infer that the value of @code{$pc} must be the same as the address of
11238 the tracepoint and use that when you are looking at a trace frame
11239 for that tracepoint. However, this cannot work if the tracepoint has
11240 multiple locations (for instance if it was set in a function that was
11241 inlined), or if it has a @code{while-stepping} loop. In those cases
11242 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
11243 it to zero.
11244
11245 @end itemize
11246
11247 @node Analyze Collected Data
11248 @section Using the Collected Data
11249
11250 After the tracepoint experiment ends, you use @value{GDBN} commands
11251 for examining the trace data. The basic idea is that each tracepoint
11252 collects a trace @dfn{snapshot} every time it is hit and another
11253 snapshot every time it single-steps. All these snapshots are
11254 consecutively numbered from zero and go into a buffer, and you can
11255 examine them later. The way you examine them is to @dfn{focus} on a
11256 specific trace snapshot. When the remote stub is focused on a trace
11257 snapshot, it will respond to all @value{GDBN} requests for memory and
11258 registers by reading from the buffer which belongs to that snapshot,
11259 rather than from @emph{real} memory or registers of the program being
11260 debugged. This means that @strong{all} @value{GDBN} commands
11261 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
11262 behave as if we were currently debugging the program state as it was
11263 when the tracepoint occurred. Any requests for data that are not in
11264 the buffer will fail.
11265
11266 @menu
11267 * tfind:: How to select a trace snapshot
11268 * tdump:: How to display all data for a snapshot
11269 * save tracepoints:: How to save tracepoints for a future run
11270 @end menu
11271
11272 @node tfind
11273 @subsection @code{tfind @var{n}}
11274
11275 @kindex tfind
11276 @cindex select trace snapshot
11277 @cindex find trace snapshot
11278 The basic command for selecting a trace snapshot from the buffer is
11279 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
11280 counting from zero. If no argument @var{n} is given, the next
11281 snapshot is selected.
11282
11283 Here are the various forms of using the @code{tfind} command.
11284
11285 @table @code
11286 @item tfind start
11287 Find the first snapshot in the buffer. This is a synonym for
11288 @code{tfind 0} (since 0 is the number of the first snapshot).
11289
11290 @item tfind none
11291 Stop debugging trace snapshots, resume @emph{live} debugging.
11292
11293 @item tfind end
11294 Same as @samp{tfind none}.
11295
11296 @item tfind
11297 No argument means find the next trace snapshot.
11298
11299 @item tfind -
11300 Find the previous trace snapshot before the current one. This permits
11301 retracing earlier steps.
11302
11303 @item tfind tracepoint @var{num}
11304 Find the next snapshot associated with tracepoint @var{num}. Search
11305 proceeds forward from the last examined trace snapshot. If no
11306 argument @var{num} is given, it means find the next snapshot collected
11307 for the same tracepoint as the current snapshot.
11308
11309 @item tfind pc @var{addr}
11310 Find the next snapshot associated with the value @var{addr} of the
11311 program counter. Search proceeds forward from the last examined trace
11312 snapshot. If no argument @var{addr} is given, it means find the next
11313 snapshot with the same value of PC as the current snapshot.
11314
11315 @item tfind outside @var{addr1}, @var{addr2}
11316 Find the next snapshot whose PC is outside the given range of
11317 addresses (exclusive).
11318
11319 @item tfind range @var{addr1}, @var{addr2}
11320 Find the next snapshot whose PC is between @var{addr1} and
11321 @var{addr2} (inclusive).
11322
11323 @item tfind line @r{[}@var{file}:@r{]}@var{n}
11324 Find the next snapshot associated with the source line @var{n}. If
11325 the optional argument @var{file} is given, refer to line @var{n} in
11326 that source file. Search proceeds forward from the last examined
11327 trace snapshot. If no argument @var{n} is given, it means find the
11328 next line other than the one currently being examined; thus saying
11329 @code{tfind line} repeatedly can appear to have the same effect as
11330 stepping from line to line in a @emph{live} debugging session.
11331 @end table
11332
11333 The default arguments for the @code{tfind} commands are specifically
11334 designed to make it easy to scan through the trace buffer. For
11335 instance, @code{tfind} with no argument selects the next trace
11336 snapshot, and @code{tfind -} with no argument selects the previous
11337 trace snapshot. So, by giving one @code{tfind} command, and then
11338 simply hitting @key{RET} repeatedly you can examine all the trace
11339 snapshots in order. Or, by saying @code{tfind -} and then hitting
11340 @key{RET} repeatedly you can examine the snapshots in reverse order.
11341 The @code{tfind line} command with no argument selects the snapshot
11342 for the next source line executed. The @code{tfind pc} command with
11343 no argument selects the next snapshot with the same program counter
11344 (PC) as the current frame. The @code{tfind tracepoint} command with
11345 no argument selects the next trace snapshot collected by the same
11346 tracepoint as the current one.
11347
11348 In addition to letting you scan through the trace buffer manually,
11349 these commands make it easy to construct @value{GDBN} scripts that
11350 scan through the trace buffer and print out whatever collected data
11351 you are interested in. Thus, if we want to examine the PC, FP, and SP
11352 registers from each trace frame in the buffer, we can say this:
11353
11354 @smallexample
11355 (@value{GDBP}) @b{tfind start}
11356 (@value{GDBP}) @b{while ($trace_frame != -1)}
11357 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
11358 $trace_frame, $pc, $sp, $fp
11359 > tfind
11360 > end
11361
11362 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
11363 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
11364 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
11365 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
11366 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
11367 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
11368 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
11369 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
11370 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
11371 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
11372 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
11373 @end smallexample
11374
11375 Or, if we want to examine the variable @code{X} at each source line in
11376 the buffer:
11377
11378 @smallexample
11379 (@value{GDBP}) @b{tfind start}
11380 (@value{GDBP}) @b{while ($trace_frame != -1)}
11381 > printf "Frame %d, X == %d\n", $trace_frame, X
11382 > tfind line
11383 > end
11384
11385 Frame 0, X = 1
11386 Frame 7, X = 2
11387 Frame 13, X = 255
11388 @end smallexample
11389
11390 @node tdump
11391 @subsection @code{tdump}
11392 @kindex tdump
11393 @cindex dump all data collected at tracepoint
11394 @cindex tracepoint data, display
11395
11396 This command takes no arguments. It prints all the data collected at
11397 the current trace snapshot.
11398
11399 @smallexample
11400 (@value{GDBP}) @b{trace 444}
11401 (@value{GDBP}) @b{actions}
11402 Enter actions for tracepoint #2, one per line:
11403 > collect $regs, $locals, $args, gdb_long_test
11404 > end
11405
11406 (@value{GDBP}) @b{tstart}
11407
11408 (@value{GDBP}) @b{tfind line 444}
11409 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
11410 at gdb_test.c:444
11411 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
11412
11413 (@value{GDBP}) @b{tdump}
11414 Data collected at tracepoint 2, trace frame 1:
11415 d0 0xc4aa0085 -995491707
11416 d1 0x18 24
11417 d2 0x80 128
11418 d3 0x33 51
11419 d4 0x71aea3d 119204413
11420 d5 0x22 34
11421 d6 0xe0 224
11422 d7 0x380035 3670069
11423 a0 0x19e24a 1696330
11424 a1 0x3000668 50333288
11425 a2 0x100 256
11426 a3 0x322000 3284992
11427 a4 0x3000698 50333336
11428 a5 0x1ad3cc 1758156
11429 fp 0x30bf3c 0x30bf3c
11430 sp 0x30bf34 0x30bf34
11431 ps 0x0 0
11432 pc 0x20b2c8 0x20b2c8
11433 fpcontrol 0x0 0
11434 fpstatus 0x0 0
11435 fpiaddr 0x0 0
11436 p = 0x20e5b4 "gdb-test"
11437 p1 = (void *) 0x11
11438 p2 = (void *) 0x22
11439 p3 = (void *) 0x33
11440 p4 = (void *) 0x44
11441 p5 = (void *) 0x55
11442 p6 = (void *) 0x66
11443 gdb_long_test = 17 '\021'
11444
11445 (@value{GDBP})
11446 @end smallexample
11447
11448 @code{tdump} works by scanning the tracepoint's current collection
11449 actions and printing the value of each expression listed. So
11450 @code{tdump} can fail, if after a run, you change the tracepoint's
11451 actions to mention variables that were not collected during the run.
11452
11453 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
11454 uses the collected value of @code{$pc} to distinguish between trace
11455 frames that were collected at the tracepoint hit, and frames that were
11456 collected while stepping. This allows it to correctly choose whether
11457 to display the basic list of collections, or the collections from the
11458 body of the while-stepping loop. However, if @code{$pc} was not collected,
11459 then @code{tdump} will always attempt to dump using the basic collection
11460 list, and may fail if a while-stepping frame does not include all the
11461 same data that is collected at the tracepoint hit.
11462 @c This is getting pretty arcane, example would be good.
11463
11464 @node save tracepoints
11465 @subsection @code{save tracepoints @var{filename}}
11466 @kindex save tracepoints
11467 @kindex save-tracepoints
11468 @cindex save tracepoints for future sessions
11469
11470 This command saves all current tracepoint definitions together with
11471 their actions and passcounts, into a file @file{@var{filename}}
11472 suitable for use in a later debugging session. To read the saved
11473 tracepoint definitions, use the @code{source} command (@pxref{Command
11474 Files}). The @w{@code{save-tracepoints}} command is a deprecated
11475 alias for @w{@code{save tracepoints}}
11476
11477 @node Tracepoint Variables
11478 @section Convenience Variables for Tracepoints
11479 @cindex tracepoint variables
11480 @cindex convenience variables for tracepoints
11481
11482 @table @code
11483 @vindex $trace_frame
11484 @item (int) $trace_frame
11485 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
11486 snapshot is selected.
11487
11488 @vindex $tracepoint
11489 @item (int) $tracepoint
11490 The tracepoint for the current trace snapshot.
11491
11492 @vindex $trace_line
11493 @item (int) $trace_line
11494 The line number for the current trace snapshot.
11495
11496 @vindex $trace_file
11497 @item (char []) $trace_file
11498 The source file for the current trace snapshot.
11499
11500 @vindex $trace_func
11501 @item (char []) $trace_func
11502 The name of the function containing @code{$tracepoint}.
11503 @end table
11504
11505 Note: @code{$trace_file} is not suitable for use in @code{printf},
11506 use @code{output} instead.
11507
11508 Here's a simple example of using these convenience variables for
11509 stepping through all the trace snapshots and printing some of their
11510 data. Note that these are not the same as trace state variables,
11511 which are managed by the target.
11512
11513 @smallexample
11514 (@value{GDBP}) @b{tfind start}
11515
11516 (@value{GDBP}) @b{while $trace_frame != -1}
11517 > output $trace_file
11518 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
11519 > tfind
11520 > end
11521 @end smallexample
11522
11523 @node Trace Files
11524 @section Using Trace Files
11525 @cindex trace files
11526
11527 In some situations, the target running a trace experiment may no
11528 longer be available; perhaps it crashed, or the hardware was needed
11529 for a different activity. To handle these cases, you can arrange to
11530 dump the trace data into a file, and later use that file as a source
11531 of trace data, via the @code{target tfile} command.
11532
11533 @table @code
11534
11535 @kindex tsave
11536 @item tsave [ -r ] @var{filename}
11537 Save the trace data to @var{filename}. By default, this command
11538 assumes that @var{filename} refers to the host filesystem, so if
11539 necessary @value{GDBN} will copy raw trace data up from the target and
11540 then save it. If the target supports it, you can also supply the
11541 optional argument @code{-r} (``remote'') to direct the target to save
11542 the data directly into @var{filename} in its own filesystem, which may be
11543 more efficient if the trace buffer is very large. (Note, however, that
11544 @code{target tfile} can only read from files accessible to the host.)
11545
11546 @kindex target tfile
11547 @kindex tfile
11548 @item target tfile @var{filename}
11549 Use the file named @var{filename} as a source of trace data. Commands
11550 that examine data work as they do with a live target, but it is not
11551 possible to run any new trace experiments. @code{tstatus} will report
11552 the state of the trace run at the moment the data was saved, as well
11553 as the current trace frame you are examining. @var{filename} must be
11554 on a filesystem accessible to the host.
11555
11556 @end table
11557
11558 @node Overlays
11559 @chapter Debugging Programs That Use Overlays
11560 @cindex overlays
11561
11562 If your program is too large to fit completely in your target system's
11563 memory, you can sometimes use @dfn{overlays} to work around this
11564 problem. @value{GDBN} provides some support for debugging programs that
11565 use overlays.
11566
11567 @menu
11568 * How Overlays Work:: A general explanation of overlays.
11569 * Overlay Commands:: Managing overlays in @value{GDBN}.
11570 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
11571 mapped by asking the inferior.
11572 * Overlay Sample Program:: A sample program using overlays.
11573 @end menu
11574
11575 @node How Overlays Work
11576 @section How Overlays Work
11577 @cindex mapped overlays
11578 @cindex unmapped overlays
11579 @cindex load address, overlay's
11580 @cindex mapped address
11581 @cindex overlay area
11582
11583 Suppose you have a computer whose instruction address space is only 64
11584 kilobytes long, but which has much more memory which can be accessed by
11585 other means: special instructions, segment registers, or memory
11586 management hardware, for example. Suppose further that you want to
11587 adapt a program which is larger than 64 kilobytes to run on this system.
11588
11589 One solution is to identify modules of your program which are relatively
11590 independent, and need not call each other directly; call these modules
11591 @dfn{overlays}. Separate the overlays from the main program, and place
11592 their machine code in the larger memory. Place your main program in
11593 instruction memory, but leave at least enough space there to hold the
11594 largest overlay as well.
11595
11596 Now, to call a function located in an overlay, you must first copy that
11597 overlay's machine code from the large memory into the space set aside
11598 for it in the instruction memory, and then jump to its entry point
11599 there.
11600
11601 @c NB: In the below the mapped area's size is greater or equal to the
11602 @c size of all overlays. This is intentional to remind the developer
11603 @c that overlays don't necessarily need to be the same size.
11604
11605 @smallexample
11606 @group
11607 Data Instruction Larger
11608 Address Space Address Space Address Space
11609 +-----------+ +-----------+ +-----------+
11610 | | | | | |
11611 +-----------+ +-----------+ +-----------+<-- overlay 1
11612 | program | | main | .----| overlay 1 | load address
11613 | variables | | program | | +-----------+
11614 | and heap | | | | | |
11615 +-----------+ | | | +-----------+<-- overlay 2
11616 | | +-----------+ | | | load address
11617 +-----------+ | | | .-| overlay 2 |
11618 | | | | | |
11619 mapped --->+-----------+ | | +-----------+
11620 address | | | | | |
11621 | overlay | <-' | | |
11622 | area | <---' +-----------+<-- overlay 3
11623 | | <---. | | load address
11624 +-----------+ `--| overlay 3 |
11625 | | | |
11626 +-----------+ | |
11627 +-----------+
11628 | |
11629 +-----------+
11630
11631 @anchor{A code overlay}A code overlay
11632 @end group
11633 @end smallexample
11634
11635 The diagram (@pxref{A code overlay}) shows a system with separate data
11636 and instruction address spaces. To map an overlay, the program copies
11637 its code from the larger address space to the instruction address space.
11638 Since the overlays shown here all use the same mapped address, only one
11639 may be mapped at a time. For a system with a single address space for
11640 data and instructions, the diagram would be similar, except that the
11641 program variables and heap would share an address space with the main
11642 program and the overlay area.
11643
11644 An overlay loaded into instruction memory and ready for use is called a
11645 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
11646 instruction memory. An overlay not present (or only partially present)
11647 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
11648 is its address in the larger memory. The mapped address is also called
11649 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
11650 called the @dfn{load memory address}, or @dfn{LMA}.
11651
11652 Unfortunately, overlays are not a completely transparent way to adapt a
11653 program to limited instruction memory. They introduce a new set of
11654 global constraints you must keep in mind as you design your program:
11655
11656 @itemize @bullet
11657
11658 @item
11659 Before calling or returning to a function in an overlay, your program
11660 must make sure that overlay is actually mapped. Otherwise, the call or
11661 return will transfer control to the right address, but in the wrong
11662 overlay, and your program will probably crash.
11663
11664 @item
11665 If the process of mapping an overlay is expensive on your system, you
11666 will need to choose your overlays carefully to minimize their effect on
11667 your program's performance.
11668
11669 @item
11670 The executable file you load onto your system must contain each
11671 overlay's instructions, appearing at the overlay's load address, not its
11672 mapped address. However, each overlay's instructions must be relocated
11673 and its symbols defined as if the overlay were at its mapped address.
11674 You can use GNU linker scripts to specify different load and relocation
11675 addresses for pieces of your program; see @ref{Overlay Description,,,
11676 ld.info, Using ld: the GNU linker}.
11677
11678 @item
11679 The procedure for loading executable files onto your system must be able
11680 to load their contents into the larger address space as well as the
11681 instruction and data spaces.
11682
11683 @end itemize
11684
11685 The overlay system described above is rather simple, and could be
11686 improved in many ways:
11687
11688 @itemize @bullet
11689
11690 @item
11691 If your system has suitable bank switch registers or memory management
11692 hardware, you could use those facilities to make an overlay's load area
11693 contents simply appear at their mapped address in instruction space.
11694 This would probably be faster than copying the overlay to its mapped
11695 area in the usual way.
11696
11697 @item
11698 If your overlays are small enough, you could set aside more than one
11699 overlay area, and have more than one overlay mapped at a time.
11700
11701 @item
11702 You can use overlays to manage data, as well as instructions. In
11703 general, data overlays are even less transparent to your design than
11704 code overlays: whereas code overlays only require care when you call or
11705 return to functions, data overlays require care every time you access
11706 the data. Also, if you change the contents of a data overlay, you
11707 must copy its contents back out to its load address before you can copy a
11708 different data overlay into the same mapped area.
11709
11710 @end itemize
11711
11712
11713 @node Overlay Commands
11714 @section Overlay Commands
11715
11716 To use @value{GDBN}'s overlay support, each overlay in your program must
11717 correspond to a separate section of the executable file. The section's
11718 virtual memory address and load memory address must be the overlay's
11719 mapped and load addresses. Identifying overlays with sections allows
11720 @value{GDBN} to determine the appropriate address of a function or
11721 variable, depending on whether the overlay is mapped or not.
11722
11723 @value{GDBN}'s overlay commands all start with the word @code{overlay};
11724 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
11725
11726 @table @code
11727 @item overlay off
11728 @kindex overlay
11729 Disable @value{GDBN}'s overlay support. When overlay support is
11730 disabled, @value{GDBN} assumes that all functions and variables are
11731 always present at their mapped addresses. By default, @value{GDBN}'s
11732 overlay support is disabled.
11733
11734 @item overlay manual
11735 @cindex manual overlay debugging
11736 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
11737 relies on you to tell it which overlays are mapped, and which are not,
11738 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
11739 commands described below.
11740
11741 @item overlay map-overlay @var{overlay}
11742 @itemx overlay map @var{overlay}
11743 @cindex map an overlay
11744 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
11745 be the name of the object file section containing the overlay. When an
11746 overlay is mapped, @value{GDBN} assumes it can find the overlay's
11747 functions and variables at their mapped addresses. @value{GDBN} assumes
11748 that any other overlays whose mapped ranges overlap that of
11749 @var{overlay} are now unmapped.
11750
11751 @item overlay unmap-overlay @var{overlay}
11752 @itemx overlay unmap @var{overlay}
11753 @cindex unmap an overlay
11754 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
11755 must be the name of the object file section containing the overlay.
11756 When an overlay is unmapped, @value{GDBN} assumes it can find the
11757 overlay's functions and variables at their load addresses.
11758
11759 @item overlay auto
11760 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
11761 consults a data structure the overlay manager maintains in the inferior
11762 to see which overlays are mapped. For details, see @ref{Automatic
11763 Overlay Debugging}.
11764
11765 @item overlay load-target
11766 @itemx overlay load
11767 @cindex reloading the overlay table
11768 Re-read the overlay table from the inferior. Normally, @value{GDBN}
11769 re-reads the table @value{GDBN} automatically each time the inferior
11770 stops, so this command should only be necessary if you have changed the
11771 overlay mapping yourself using @value{GDBN}. This command is only
11772 useful when using automatic overlay debugging.
11773
11774 @item overlay list-overlays
11775 @itemx overlay list
11776 @cindex listing mapped overlays
11777 Display a list of the overlays currently mapped, along with their mapped
11778 addresses, load addresses, and sizes.
11779
11780 @end table
11781
11782 Normally, when @value{GDBN} prints a code address, it includes the name
11783 of the function the address falls in:
11784
11785 @smallexample
11786 (@value{GDBP}) print main
11787 $3 = @{int ()@} 0x11a0 <main>
11788 @end smallexample
11789 @noindent
11790 When overlay debugging is enabled, @value{GDBN} recognizes code in
11791 unmapped overlays, and prints the names of unmapped functions with
11792 asterisks around them. For example, if @code{foo} is a function in an
11793 unmapped overlay, @value{GDBN} prints it this way:
11794
11795 @smallexample
11796 (@value{GDBP}) overlay list
11797 No sections are mapped.
11798 (@value{GDBP}) print foo
11799 $5 = @{int (int)@} 0x100000 <*foo*>
11800 @end smallexample
11801 @noindent
11802 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
11803 name normally:
11804
11805 @smallexample
11806 (@value{GDBP}) overlay list
11807 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
11808 mapped at 0x1016 - 0x104a
11809 (@value{GDBP}) print foo
11810 $6 = @{int (int)@} 0x1016 <foo>
11811 @end smallexample
11812
11813 When overlay debugging is enabled, @value{GDBN} can find the correct
11814 address for functions and variables in an overlay, whether or not the
11815 overlay is mapped. This allows most @value{GDBN} commands, like
11816 @code{break} and @code{disassemble}, to work normally, even on unmapped
11817 code. However, @value{GDBN}'s breakpoint support has some limitations:
11818
11819 @itemize @bullet
11820 @item
11821 @cindex breakpoints in overlays
11822 @cindex overlays, setting breakpoints in
11823 You can set breakpoints in functions in unmapped overlays, as long as
11824 @value{GDBN} can write to the overlay at its load address.
11825 @item
11826 @value{GDBN} can not set hardware or simulator-based breakpoints in
11827 unmapped overlays. However, if you set a breakpoint at the end of your
11828 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
11829 you are using manual overlay management), @value{GDBN} will re-set its
11830 breakpoints properly.
11831 @end itemize
11832
11833
11834 @node Automatic Overlay Debugging
11835 @section Automatic Overlay Debugging
11836 @cindex automatic overlay debugging
11837
11838 @value{GDBN} can automatically track which overlays are mapped and which
11839 are not, given some simple co-operation from the overlay manager in the
11840 inferior. If you enable automatic overlay debugging with the
11841 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
11842 looks in the inferior's memory for certain variables describing the
11843 current state of the overlays.
11844
11845 Here are the variables your overlay manager must define to support
11846 @value{GDBN}'s automatic overlay debugging:
11847
11848 @table @asis
11849
11850 @item @code{_ovly_table}:
11851 This variable must be an array of the following structures:
11852
11853 @smallexample
11854 struct
11855 @{
11856 /* The overlay's mapped address. */
11857 unsigned long vma;
11858
11859 /* The size of the overlay, in bytes. */
11860 unsigned long size;
11861
11862 /* The overlay's load address. */
11863 unsigned long lma;
11864
11865 /* Non-zero if the overlay is currently mapped;
11866 zero otherwise. */
11867 unsigned long mapped;
11868 @}
11869 @end smallexample
11870
11871 @item @code{_novlys}:
11872 This variable must be a four-byte signed integer, holding the total
11873 number of elements in @code{_ovly_table}.
11874
11875 @end table
11876
11877 To decide whether a particular overlay is mapped or not, @value{GDBN}
11878 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
11879 @code{lma} members equal the VMA and LMA of the overlay's section in the
11880 executable file. When @value{GDBN} finds a matching entry, it consults
11881 the entry's @code{mapped} member to determine whether the overlay is
11882 currently mapped.
11883
11884 In addition, your overlay manager may define a function called
11885 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
11886 will silently set a breakpoint there. If the overlay manager then
11887 calls this function whenever it has changed the overlay table, this
11888 will enable @value{GDBN} to accurately keep track of which overlays
11889 are in program memory, and update any breakpoints that may be set
11890 in overlays. This will allow breakpoints to work even if the
11891 overlays are kept in ROM or other non-writable memory while they
11892 are not being executed.
11893
11894 @node Overlay Sample Program
11895 @section Overlay Sample Program
11896 @cindex overlay example program
11897
11898 When linking a program which uses overlays, you must place the overlays
11899 at their load addresses, while relocating them to run at their mapped
11900 addresses. To do this, you must write a linker script (@pxref{Overlay
11901 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
11902 since linker scripts are specific to a particular host system, target
11903 architecture, and target memory layout, this manual cannot provide
11904 portable sample code demonstrating @value{GDBN}'s overlay support.
11905
11906 However, the @value{GDBN} source distribution does contain an overlaid
11907 program, with linker scripts for a few systems, as part of its test
11908 suite. The program consists of the following files from
11909 @file{gdb/testsuite/gdb.base}:
11910
11911 @table @file
11912 @item overlays.c
11913 The main program file.
11914 @item ovlymgr.c
11915 A simple overlay manager, used by @file{overlays.c}.
11916 @item foo.c
11917 @itemx bar.c
11918 @itemx baz.c
11919 @itemx grbx.c
11920 Overlay modules, loaded and used by @file{overlays.c}.
11921 @item d10v.ld
11922 @itemx m32r.ld
11923 Linker scripts for linking the test program on the @code{d10v-elf}
11924 and @code{m32r-elf} targets.
11925 @end table
11926
11927 You can build the test program using the @code{d10v-elf} GCC
11928 cross-compiler like this:
11929
11930 @smallexample
11931 $ d10v-elf-gcc -g -c overlays.c
11932 $ d10v-elf-gcc -g -c ovlymgr.c
11933 $ d10v-elf-gcc -g -c foo.c
11934 $ d10v-elf-gcc -g -c bar.c
11935 $ d10v-elf-gcc -g -c baz.c
11936 $ d10v-elf-gcc -g -c grbx.c
11937 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
11938 baz.o grbx.o -Wl,-Td10v.ld -o overlays
11939 @end smallexample
11940
11941 The build process is identical for any other architecture, except that
11942 you must substitute the appropriate compiler and linker script for the
11943 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
11944
11945
11946 @node Languages
11947 @chapter Using @value{GDBN} with Different Languages
11948 @cindex languages
11949
11950 Although programming languages generally have common aspects, they are
11951 rarely expressed in the same manner. For instance, in ANSI C,
11952 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
11953 Modula-2, it is accomplished by @code{p^}. Values can also be
11954 represented (and displayed) differently. Hex numbers in C appear as
11955 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
11956
11957 @cindex working language
11958 Language-specific information is built into @value{GDBN} for some languages,
11959 allowing you to express operations like the above in your program's
11960 native language, and allowing @value{GDBN} to output values in a manner
11961 consistent with the syntax of your program's native language. The
11962 language you use to build expressions is called the @dfn{working
11963 language}.
11964
11965 @menu
11966 * Setting:: Switching between source languages
11967 * Show:: Displaying the language
11968 * Checks:: Type and range checks
11969 * Supported Languages:: Supported languages
11970 * Unsupported Languages:: Unsupported languages
11971 @end menu
11972
11973 @node Setting
11974 @section Switching Between Source Languages
11975
11976 There are two ways to control the working language---either have @value{GDBN}
11977 set it automatically, or select it manually yourself. You can use the
11978 @code{set language} command for either purpose. On startup, @value{GDBN}
11979 defaults to setting the language automatically. The working language is
11980 used to determine how expressions you type are interpreted, how values
11981 are printed, etc.
11982
11983 In addition to the working language, every source file that
11984 @value{GDBN} knows about has its own working language. For some object
11985 file formats, the compiler might indicate which language a particular
11986 source file is in. However, most of the time @value{GDBN} infers the
11987 language from the name of the file. The language of a source file
11988 controls whether C@t{++} names are demangled---this way @code{backtrace} can
11989 show each frame appropriately for its own language. There is no way to
11990 set the language of a source file from within @value{GDBN}, but you can
11991 set the language associated with a filename extension. @xref{Show, ,
11992 Displaying the Language}.
11993
11994 This is most commonly a problem when you use a program, such
11995 as @code{cfront} or @code{f2c}, that generates C but is written in
11996 another language. In that case, make the
11997 program use @code{#line} directives in its C output; that way
11998 @value{GDBN} will know the correct language of the source code of the original
11999 program, and will display that source code, not the generated C code.
12000
12001 @menu
12002 * Filenames:: Filename extensions and languages.
12003 * Manually:: Setting the working language manually
12004 * Automatically:: Having @value{GDBN} infer the source language
12005 @end menu
12006
12007 @node Filenames
12008 @subsection List of Filename Extensions and Languages
12009
12010 If a source file name ends in one of the following extensions, then
12011 @value{GDBN} infers that its language is the one indicated.
12012
12013 @table @file
12014 @item .ada
12015 @itemx .ads
12016 @itemx .adb
12017 @itemx .a
12018 Ada source file.
12019
12020 @item .c
12021 C source file
12022
12023 @item .C
12024 @itemx .cc
12025 @itemx .cp
12026 @itemx .cpp
12027 @itemx .cxx
12028 @itemx .c++
12029 C@t{++} source file
12030
12031 @item .d
12032 D source file
12033
12034 @item .m
12035 Objective-C source file
12036
12037 @item .f
12038 @itemx .F
12039 Fortran source file
12040
12041 @item .mod
12042 Modula-2 source file
12043
12044 @item .s
12045 @itemx .S
12046 Assembler source file. This actually behaves almost like C, but
12047 @value{GDBN} does not skip over function prologues when stepping.
12048 @end table
12049
12050 In addition, you may set the language associated with a filename
12051 extension. @xref{Show, , Displaying the Language}.
12052
12053 @node Manually
12054 @subsection Setting the Working Language
12055
12056 If you allow @value{GDBN} to set the language automatically,
12057 expressions are interpreted the same way in your debugging session and
12058 your program.
12059
12060 @kindex set language
12061 If you wish, you may set the language manually. To do this, issue the
12062 command @samp{set language @var{lang}}, where @var{lang} is the name of
12063 a language, such as
12064 @code{c} or @code{modula-2}.
12065 For a list of the supported languages, type @samp{set language}.
12066
12067 Setting the language manually prevents @value{GDBN} from updating the working
12068 language automatically. This can lead to confusion if you try
12069 to debug a program when the working language is not the same as the
12070 source language, when an expression is acceptable to both
12071 languages---but means different things. For instance, if the current
12072 source file were written in C, and @value{GDBN} was parsing Modula-2, a
12073 command such as:
12074
12075 @smallexample
12076 print a = b + c
12077 @end smallexample
12078
12079 @noindent
12080 might not have the effect you intended. In C, this means to add
12081 @code{b} and @code{c} and place the result in @code{a}. The result
12082 printed would be the value of @code{a}. In Modula-2, this means to compare
12083 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
12084
12085 @node Automatically
12086 @subsection Having @value{GDBN} Infer the Source Language
12087
12088 To have @value{GDBN} set the working language automatically, use
12089 @samp{set language local} or @samp{set language auto}. @value{GDBN}
12090 then infers the working language. That is, when your program stops in a
12091 frame (usually by encountering a breakpoint), @value{GDBN} sets the
12092 working language to the language recorded for the function in that
12093 frame. If the language for a frame is unknown (that is, if the function
12094 or block corresponding to the frame was defined in a source file that
12095 does not have a recognized extension), the current working language is
12096 not changed, and @value{GDBN} issues a warning.
12097
12098 This may not seem necessary for most programs, which are written
12099 entirely in one source language. However, program modules and libraries
12100 written in one source language can be used by a main program written in
12101 a different source language. Using @samp{set language auto} in this
12102 case frees you from having to set the working language manually.
12103
12104 @node Show
12105 @section Displaying the Language
12106
12107 The following commands help you find out which language is the
12108 working language, and also what language source files were written in.
12109
12110 @table @code
12111 @item show language
12112 @kindex show language
12113 Display the current working language. This is the
12114 language you can use with commands such as @code{print} to
12115 build and compute expressions that may involve variables in your program.
12116
12117 @item info frame
12118 @kindex info frame@r{, show the source language}
12119 Display the source language for this frame. This language becomes the
12120 working language if you use an identifier from this frame.
12121 @xref{Frame Info, ,Information about a Frame}, to identify the other
12122 information listed here.
12123
12124 @item info source
12125 @kindex info source@r{, show the source language}
12126 Display the source language of this source file.
12127 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
12128 information listed here.
12129 @end table
12130
12131 In unusual circumstances, you may have source files with extensions
12132 not in the standard list. You can then set the extension associated
12133 with a language explicitly:
12134
12135 @table @code
12136 @item set extension-language @var{ext} @var{language}
12137 @kindex set extension-language
12138 Tell @value{GDBN} that source files with extension @var{ext} are to be
12139 assumed as written in the source language @var{language}.
12140
12141 @item info extensions
12142 @kindex info extensions
12143 List all the filename extensions and the associated languages.
12144 @end table
12145
12146 @node Checks
12147 @section Type and Range Checking
12148
12149 @quotation
12150 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
12151 checking are included, but they do not yet have any effect. This
12152 section documents the intended facilities.
12153 @end quotation
12154 @c FIXME remove warning when type/range code added
12155
12156 Some languages are designed to guard you against making seemingly common
12157 errors through a series of compile- and run-time checks. These include
12158 checking the type of arguments to functions and operators, and making
12159 sure mathematical overflows are caught at run time. Checks such as
12160 these help to ensure a program's correctness once it has been compiled
12161 by eliminating type mismatches, and providing active checks for range
12162 errors when your program is running.
12163
12164 @value{GDBN} can check for conditions like the above if you wish.
12165 Although @value{GDBN} does not check the statements in your program,
12166 it can check expressions entered directly into @value{GDBN} for
12167 evaluation via the @code{print} command, for example. As with the
12168 working language, @value{GDBN} can also decide whether or not to check
12169 automatically based on your program's source language.
12170 @xref{Supported Languages, ,Supported Languages}, for the default
12171 settings of supported languages.
12172
12173 @menu
12174 * Type Checking:: An overview of type checking
12175 * Range Checking:: An overview of range checking
12176 @end menu
12177
12178 @cindex type checking
12179 @cindex checks, type
12180 @node Type Checking
12181 @subsection An Overview of Type Checking
12182
12183 Some languages, such as Modula-2, are strongly typed, meaning that the
12184 arguments to operators and functions have to be of the correct type,
12185 otherwise an error occurs. These checks prevent type mismatch
12186 errors from ever causing any run-time problems. For example,
12187
12188 @smallexample
12189 1 + 2 @result{} 3
12190 @exdent but
12191 @error{} 1 + 2.3
12192 @end smallexample
12193
12194 The second example fails because the @code{CARDINAL} 1 is not
12195 type-compatible with the @code{REAL} 2.3.
12196
12197 For the expressions you use in @value{GDBN} commands, you can tell the
12198 @value{GDBN} type checker to skip checking;
12199 to treat any mismatches as errors and abandon the expression;
12200 or to only issue warnings when type mismatches occur,
12201 but evaluate the expression anyway. When you choose the last of
12202 these, @value{GDBN} evaluates expressions like the second example above, but
12203 also issues a warning.
12204
12205 Even if you turn type checking off, there may be other reasons
12206 related to type that prevent @value{GDBN} from evaluating an expression.
12207 For instance, @value{GDBN} does not know how to add an @code{int} and
12208 a @code{struct foo}. These particular type errors have nothing to do
12209 with the language in use, and usually arise from expressions, such as
12210 the one described above, which make little sense to evaluate anyway.
12211
12212 Each language defines to what degree it is strict about type. For
12213 instance, both Modula-2 and C require the arguments to arithmetical
12214 operators to be numbers. In C, enumerated types and pointers can be
12215 represented as numbers, so that they are valid arguments to mathematical
12216 operators. @xref{Supported Languages, ,Supported Languages}, for further
12217 details on specific languages.
12218
12219 @value{GDBN} provides some additional commands for controlling the type checker:
12220
12221 @kindex set check type
12222 @kindex show check type
12223 @table @code
12224 @item set check type auto
12225 Set type checking on or off based on the current working language.
12226 @xref{Supported Languages, ,Supported Languages}, for the default settings for
12227 each language.
12228
12229 @item set check type on
12230 @itemx set check type off
12231 Set type checking on or off, overriding the default setting for the
12232 current working language. Issue a warning if the setting does not
12233 match the language default. If any type mismatches occur in
12234 evaluating an expression while type checking is on, @value{GDBN} prints a
12235 message and aborts evaluation of the expression.
12236
12237 @item set check type warn
12238 Cause the type checker to issue warnings, but to always attempt to
12239 evaluate the expression. Evaluating the expression may still
12240 be impossible for other reasons. For example, @value{GDBN} cannot add
12241 numbers and structures.
12242
12243 @item show type
12244 Show the current setting of the type checker, and whether or not @value{GDBN}
12245 is setting it automatically.
12246 @end table
12247
12248 @cindex range checking
12249 @cindex checks, range
12250 @node Range Checking
12251 @subsection An Overview of Range Checking
12252
12253 In some languages (such as Modula-2), it is an error to exceed the
12254 bounds of a type; this is enforced with run-time checks. Such range
12255 checking is meant to ensure program correctness by making sure
12256 computations do not overflow, or indices on an array element access do
12257 not exceed the bounds of the array.
12258
12259 For expressions you use in @value{GDBN} commands, you can tell
12260 @value{GDBN} to treat range errors in one of three ways: ignore them,
12261 always treat them as errors and abandon the expression, or issue
12262 warnings but evaluate the expression anyway.
12263
12264 A range error can result from numerical overflow, from exceeding an
12265 array index bound, or when you type a constant that is not a member
12266 of any type. Some languages, however, do not treat overflows as an
12267 error. In many implementations of C, mathematical overflow causes the
12268 result to ``wrap around'' to lower values---for example, if @var{m} is
12269 the largest integer value, and @var{s} is the smallest, then
12270
12271 @smallexample
12272 @var{m} + 1 @result{} @var{s}
12273 @end smallexample
12274
12275 This, too, is specific to individual languages, and in some cases
12276 specific to individual compilers or machines. @xref{Supported Languages, ,
12277 Supported Languages}, for further details on specific languages.
12278
12279 @value{GDBN} provides some additional commands for controlling the range checker:
12280
12281 @kindex set check range
12282 @kindex show check range
12283 @table @code
12284 @item set check range auto
12285 Set range checking on or off based on the current working language.
12286 @xref{Supported Languages, ,Supported Languages}, for the default settings for
12287 each language.
12288
12289 @item set check range on
12290 @itemx set check range off
12291 Set range checking on or off, overriding the default setting for the
12292 current working language. A warning is issued if the setting does not
12293 match the language default. If a range error occurs and range checking is on,
12294 then a message is printed and evaluation of the expression is aborted.
12295
12296 @item set check range warn
12297 Output messages when the @value{GDBN} range checker detects a range error,
12298 but attempt to evaluate the expression anyway. Evaluating the
12299 expression may still be impossible for other reasons, such as accessing
12300 memory that the process does not own (a typical example from many Unix
12301 systems).
12302
12303 @item show range
12304 Show the current setting of the range checker, and whether or not it is
12305 being set automatically by @value{GDBN}.
12306 @end table
12307
12308 @node Supported Languages
12309 @section Supported Languages
12310
12311 @value{GDBN} supports C, C@t{++}, D, Objective-C, Fortran, Java, OpenCL C, Pascal,
12312 assembly, Modula-2, and Ada.
12313 @c This is false ...
12314 Some @value{GDBN} features may be used in expressions regardless of the
12315 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
12316 and the @samp{@{type@}addr} construct (@pxref{Expressions,
12317 ,Expressions}) can be used with the constructs of any supported
12318 language.
12319
12320 The following sections detail to what degree each source language is
12321 supported by @value{GDBN}. These sections are not meant to be language
12322 tutorials or references, but serve only as a reference guide to what the
12323 @value{GDBN} expression parser accepts, and what input and output
12324 formats should look like for different languages. There are many good
12325 books written on each of these languages; please look to these for a
12326 language reference or tutorial.
12327
12328 @menu
12329 * C:: C and C@t{++}
12330 * D:: D
12331 * Objective-C:: Objective-C
12332 * OpenCL C:: OpenCL C
12333 * Fortran:: Fortran
12334 * Pascal:: Pascal
12335 * Modula-2:: Modula-2
12336 * Ada:: Ada
12337 @end menu
12338
12339 @node C
12340 @subsection C and C@t{++}
12341
12342 @cindex C and C@t{++}
12343 @cindex expressions in C or C@t{++}
12344
12345 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
12346 to both languages. Whenever this is the case, we discuss those languages
12347 together.
12348
12349 @cindex C@t{++}
12350 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
12351 @cindex @sc{gnu} C@t{++}
12352 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
12353 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
12354 effectively, you must compile your C@t{++} programs with a supported
12355 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
12356 compiler (@code{aCC}).
12357
12358 @menu
12359 * C Operators:: C and C@t{++} operators
12360 * C Constants:: C and C@t{++} constants
12361 * C Plus Plus Expressions:: C@t{++} expressions
12362 * C Defaults:: Default settings for C and C@t{++}
12363 * C Checks:: C and C@t{++} type and range checks
12364 * Debugging C:: @value{GDBN} and C
12365 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
12366 * Decimal Floating Point:: Numbers in Decimal Floating Point format
12367 @end menu
12368
12369 @node C Operators
12370 @subsubsection C and C@t{++} Operators
12371
12372 @cindex C and C@t{++} operators
12373
12374 Operators must be defined on values of specific types. For instance,
12375 @code{+} is defined on numbers, but not on structures. Operators are
12376 often defined on groups of types.
12377
12378 For the purposes of C and C@t{++}, the following definitions hold:
12379
12380 @itemize @bullet
12381
12382 @item
12383 @emph{Integral types} include @code{int} with any of its storage-class
12384 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
12385
12386 @item
12387 @emph{Floating-point types} include @code{float}, @code{double}, and
12388 @code{long double} (if supported by the target platform).
12389
12390 @item
12391 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
12392
12393 @item
12394 @emph{Scalar types} include all of the above.
12395
12396 @end itemize
12397
12398 @noindent
12399 The following operators are supported. They are listed here
12400 in order of increasing precedence:
12401
12402 @table @code
12403 @item ,
12404 The comma or sequencing operator. Expressions in a comma-separated list
12405 are evaluated from left to right, with the result of the entire
12406 expression being the last expression evaluated.
12407
12408 @item =
12409 Assignment. The value of an assignment expression is the value
12410 assigned. Defined on scalar types.
12411
12412 @item @var{op}=
12413 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
12414 and translated to @w{@code{@var{a} = @var{a op b}}}.
12415 @w{@code{@var{op}=}} and @code{=} have the same precedence.
12416 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
12417 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
12418
12419 @item ?:
12420 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
12421 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
12422 integral type.
12423
12424 @item ||
12425 Logical @sc{or}. Defined on integral types.
12426
12427 @item &&
12428 Logical @sc{and}. Defined on integral types.
12429
12430 @item |
12431 Bitwise @sc{or}. Defined on integral types.
12432
12433 @item ^
12434 Bitwise exclusive-@sc{or}. Defined on integral types.
12435
12436 @item &
12437 Bitwise @sc{and}. Defined on integral types.
12438
12439 @item ==@r{, }!=
12440 Equality and inequality. Defined on scalar types. The value of these
12441 expressions is 0 for false and non-zero for true.
12442
12443 @item <@r{, }>@r{, }<=@r{, }>=
12444 Less than, greater than, less than or equal, greater than or equal.
12445 Defined on scalar types. The value of these expressions is 0 for false
12446 and non-zero for true.
12447
12448 @item <<@r{, }>>
12449 left shift, and right shift. Defined on integral types.
12450
12451 @item @@
12452 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
12453
12454 @item +@r{, }-
12455 Addition and subtraction. Defined on integral types, floating-point types and
12456 pointer types.
12457
12458 @item *@r{, }/@r{, }%
12459 Multiplication, division, and modulus. Multiplication and division are
12460 defined on integral and floating-point types. Modulus is defined on
12461 integral types.
12462
12463 @item ++@r{, }--
12464 Increment and decrement. When appearing before a variable, the
12465 operation is performed before the variable is used in an expression;
12466 when appearing after it, the variable's value is used before the
12467 operation takes place.
12468
12469 @item *
12470 Pointer dereferencing. Defined on pointer types. Same precedence as
12471 @code{++}.
12472
12473 @item &
12474 Address operator. Defined on variables. Same precedence as @code{++}.
12475
12476 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
12477 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
12478 to examine the address
12479 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
12480 stored.
12481
12482 @item -
12483 Negative. Defined on integral and floating-point types. Same
12484 precedence as @code{++}.
12485
12486 @item !
12487 Logical negation. Defined on integral types. Same precedence as
12488 @code{++}.
12489
12490 @item ~
12491 Bitwise complement operator. Defined on integral types. Same precedence as
12492 @code{++}.
12493
12494
12495 @item .@r{, }->
12496 Structure member, and pointer-to-structure member. For convenience,
12497 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
12498 pointer based on the stored type information.
12499 Defined on @code{struct} and @code{union} data.
12500
12501 @item .*@r{, }->*
12502 Dereferences of pointers to members.
12503
12504 @item []
12505 Array indexing. @code{@var{a}[@var{i}]} is defined as
12506 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
12507
12508 @item ()
12509 Function parameter list. Same precedence as @code{->}.
12510
12511 @item ::
12512 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
12513 and @code{class} types.
12514
12515 @item ::
12516 Doubled colons also represent the @value{GDBN} scope operator
12517 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
12518 above.
12519 @end table
12520
12521 If an operator is redefined in the user code, @value{GDBN} usually
12522 attempts to invoke the redefined version instead of using the operator's
12523 predefined meaning.
12524
12525 @node C Constants
12526 @subsubsection C and C@t{++} Constants
12527
12528 @cindex C and C@t{++} constants
12529
12530 @value{GDBN} allows you to express the constants of C and C@t{++} in the
12531 following ways:
12532
12533 @itemize @bullet
12534 @item
12535 Integer constants are a sequence of digits. Octal constants are
12536 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
12537 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
12538 @samp{l}, specifying that the constant should be treated as a
12539 @code{long} value.
12540
12541 @item
12542 Floating point constants are a sequence of digits, followed by a decimal
12543 point, followed by a sequence of digits, and optionally followed by an
12544 exponent. An exponent is of the form:
12545 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
12546 sequence of digits. The @samp{+} is optional for positive exponents.
12547 A floating-point constant may also end with a letter @samp{f} or
12548 @samp{F}, specifying that the constant should be treated as being of
12549 the @code{float} (as opposed to the default @code{double}) type; or with
12550 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
12551 constant.
12552
12553 @item
12554 Enumerated constants consist of enumerated identifiers, or their
12555 integral equivalents.
12556
12557 @item
12558 Character constants are a single character surrounded by single quotes
12559 (@code{'}), or a number---the ordinal value of the corresponding character
12560 (usually its @sc{ascii} value). Within quotes, the single character may
12561 be represented by a letter or by @dfn{escape sequences}, which are of
12562 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
12563 of the character's ordinal value; or of the form @samp{\@var{x}}, where
12564 @samp{@var{x}} is a predefined special character---for example,
12565 @samp{\n} for newline.
12566
12567 Wide character constants can be written by prefixing a character
12568 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
12569 form of @samp{x}. The target wide character set is used when
12570 computing the value of this constant (@pxref{Character Sets}).
12571
12572 @item
12573 String constants are a sequence of character constants surrounded by
12574 double quotes (@code{"}). Any valid character constant (as described
12575 above) may appear. Double quotes within the string must be preceded by
12576 a backslash, so for instance @samp{"a\"b'c"} is a string of five
12577 characters.
12578
12579 Wide string constants can be written by prefixing a string constant
12580 with @samp{L}, as in C. The target wide character set is used when
12581 computing the value of this constant (@pxref{Character Sets}).
12582
12583 @item
12584 Pointer constants are an integral value. You can also write pointers
12585 to constants using the C operator @samp{&}.
12586
12587 @item
12588 Array constants are comma-separated lists surrounded by braces @samp{@{}
12589 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
12590 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
12591 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
12592 @end itemize
12593
12594 @node C Plus Plus Expressions
12595 @subsubsection C@t{++} Expressions
12596
12597 @cindex expressions in C@t{++}
12598 @value{GDBN} expression handling can interpret most C@t{++} expressions.
12599
12600 @cindex debugging C@t{++} programs
12601 @cindex C@t{++} compilers
12602 @cindex debug formats and C@t{++}
12603 @cindex @value{NGCC} and C@t{++}
12604 @quotation
12605 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
12606 the proper compiler and the proper debug format. Currently,
12607 @value{GDBN} works best when debugging C@t{++} code that is compiled
12608 with the most recent version of @value{NGCC} possible. The DWARF
12609 debugging format is preferred; @value{NGCC} defaults to this on most
12610 popular platforms. Other compilers and/or debug formats are likely to
12611 work badly or not at all when using @value{GDBN} to debug C@t{++}
12612 code. @xref{Compilation}.
12613 @end quotation
12614
12615 @enumerate
12616
12617 @cindex member functions
12618 @item
12619 Member function calls are allowed; you can use expressions like
12620
12621 @smallexample
12622 count = aml->GetOriginal(x, y)
12623 @end smallexample
12624
12625 @vindex this@r{, inside C@t{++} member functions}
12626 @cindex namespace in C@t{++}
12627 @item
12628 While a member function is active (in the selected stack frame), your
12629 expressions have the same namespace available as the member function;
12630 that is, @value{GDBN} allows implicit references to the class instance
12631 pointer @code{this} following the same rules as C@t{++}. @code{using}
12632 declarations in the current scope are also respected by @value{GDBN}.
12633
12634 @cindex call overloaded functions
12635 @cindex overloaded functions, calling
12636 @cindex type conversions in C@t{++}
12637 @item
12638 You can call overloaded functions; @value{GDBN} resolves the function
12639 call to the right definition, with some restrictions. @value{GDBN} does not
12640 perform overload resolution involving user-defined type conversions,
12641 calls to constructors, or instantiations of templates that do not exist
12642 in the program. It also cannot handle ellipsis argument lists or
12643 default arguments.
12644
12645 It does perform integral conversions and promotions, floating-point
12646 promotions, arithmetic conversions, pointer conversions, conversions of
12647 class objects to base classes, and standard conversions such as those of
12648 functions or arrays to pointers; it requires an exact match on the
12649 number of function arguments.
12650
12651 Overload resolution is always performed, unless you have specified
12652 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
12653 ,@value{GDBN} Features for C@t{++}}.
12654
12655 You must specify @code{set overload-resolution off} in order to use an
12656 explicit function signature to call an overloaded function, as in
12657 @smallexample
12658 p 'foo(char,int)'('x', 13)
12659 @end smallexample
12660
12661 The @value{GDBN} command-completion facility can simplify this;
12662 see @ref{Completion, ,Command Completion}.
12663
12664 @cindex reference declarations
12665 @item
12666 @value{GDBN} understands variables declared as C@t{++} references; you can use
12667 them in expressions just as you do in C@t{++} source---they are automatically
12668 dereferenced.
12669
12670 In the parameter list shown when @value{GDBN} displays a frame, the values of
12671 reference variables are not displayed (unlike other variables); this
12672 avoids clutter, since references are often used for large structures.
12673 The @emph{address} of a reference variable is always shown, unless
12674 you have specified @samp{set print address off}.
12675
12676 @item
12677 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
12678 expressions can use it just as expressions in your program do. Since
12679 one scope may be defined in another, you can use @code{::} repeatedly if
12680 necessary, for example in an expression like
12681 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
12682 resolving name scope by reference to source files, in both C and C@t{++}
12683 debugging (@pxref{Variables, ,Program Variables}).
12684
12685 @item
12686 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
12687 specification.
12688 @end enumerate
12689
12690 @node C Defaults
12691 @subsubsection C and C@t{++} Defaults
12692
12693 @cindex C and C@t{++} defaults
12694
12695 If you allow @value{GDBN} to set type and range checking automatically, they
12696 both default to @code{off} whenever the working language changes to
12697 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
12698 selects the working language.
12699
12700 If you allow @value{GDBN} to set the language automatically, it
12701 recognizes source files whose names end with @file{.c}, @file{.C}, or
12702 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
12703 these files, it sets the working language to C or C@t{++}.
12704 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
12705 for further details.
12706
12707 @c Type checking is (a) primarily motivated by Modula-2, and (b)
12708 @c unimplemented. If (b) changes, it might make sense to let this node
12709 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
12710
12711 @node C Checks
12712 @subsubsection C and C@t{++} Type and Range Checks
12713
12714 @cindex C and C@t{++} checks
12715
12716 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
12717 is not used. However, if you turn type checking on, @value{GDBN}
12718 considers two variables type equivalent if:
12719
12720 @itemize @bullet
12721 @item
12722 The two variables are structured and have the same structure, union, or
12723 enumerated tag.
12724
12725 @item
12726 The two variables have the same type name, or types that have been
12727 declared equivalent through @code{typedef}.
12728
12729 @ignore
12730 @c leaving this out because neither J Gilmore nor R Pesch understand it.
12731 @c FIXME--beers?
12732 @item
12733 The two @code{struct}, @code{union}, or @code{enum} variables are
12734 declared in the same declaration. (Note: this may not be true for all C
12735 compilers.)
12736 @end ignore
12737 @end itemize
12738
12739 Range checking, if turned on, is done on mathematical operations. Array
12740 indices are not checked, since they are often used to index a pointer
12741 that is not itself an array.
12742
12743 @node Debugging C
12744 @subsubsection @value{GDBN} and C
12745
12746 The @code{set print union} and @code{show print union} commands apply to
12747 the @code{union} type. When set to @samp{on}, any @code{union} that is
12748 inside a @code{struct} or @code{class} is also printed. Otherwise, it
12749 appears as @samp{@{...@}}.
12750
12751 The @code{@@} operator aids in the debugging of dynamic arrays, formed
12752 with pointers and a memory allocation function. @xref{Expressions,
12753 ,Expressions}.
12754
12755 @node Debugging C Plus Plus
12756 @subsubsection @value{GDBN} Features for C@t{++}
12757
12758 @cindex commands for C@t{++}
12759
12760 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
12761 designed specifically for use with C@t{++}. Here is a summary:
12762
12763 @table @code
12764 @cindex break in overloaded functions
12765 @item @r{breakpoint menus}
12766 When you want a breakpoint in a function whose name is overloaded,
12767 @value{GDBN} has the capability to display a menu of possible breakpoint
12768 locations to help you specify which function definition you want.
12769 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
12770
12771 @cindex overloading in C@t{++}
12772 @item rbreak @var{regex}
12773 Setting breakpoints using regular expressions is helpful for setting
12774 breakpoints on overloaded functions that are not members of any special
12775 classes.
12776 @xref{Set Breaks, ,Setting Breakpoints}.
12777
12778 @cindex C@t{++} exception handling
12779 @item catch throw
12780 @itemx catch catch
12781 Debug C@t{++} exception handling using these commands. @xref{Set
12782 Catchpoints, , Setting Catchpoints}.
12783
12784 @cindex inheritance
12785 @item ptype @var{typename}
12786 Print inheritance relationships as well as other information for type
12787 @var{typename}.
12788 @xref{Symbols, ,Examining the Symbol Table}.
12789
12790 @item info vtbl @var{expression}.
12791 The @code{info vtbl} command can be used to display the virtual
12792 method tables of the object computed by @var{expression}. This shows
12793 one entry per virtual table; there may be multiple virtual tables when
12794 multiple inheritance is in use.
12795
12796 @cindex C@t{++} symbol display
12797 @item set print demangle
12798 @itemx show print demangle
12799 @itemx set print asm-demangle
12800 @itemx show print asm-demangle
12801 Control whether C@t{++} symbols display in their source form, both when
12802 displaying code as C@t{++} source and when displaying disassemblies.
12803 @xref{Print Settings, ,Print Settings}.
12804
12805 @item set print object
12806 @itemx show print object
12807 Choose whether to print derived (actual) or declared types of objects.
12808 @xref{Print Settings, ,Print Settings}.
12809
12810 @item set print vtbl
12811 @itemx show print vtbl
12812 Control the format for printing virtual function tables.
12813 @xref{Print Settings, ,Print Settings}.
12814 (The @code{vtbl} commands do not work on programs compiled with the HP
12815 ANSI C@t{++} compiler (@code{aCC}).)
12816
12817 @kindex set overload-resolution
12818 @cindex overloaded functions, overload resolution
12819 @item set overload-resolution on
12820 Enable overload resolution for C@t{++} expression evaluation. The default
12821 is on. For overloaded functions, @value{GDBN} evaluates the arguments
12822 and searches for a function whose signature matches the argument types,
12823 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
12824 Expressions, ,C@t{++} Expressions}, for details).
12825 If it cannot find a match, it emits a message.
12826
12827 @item set overload-resolution off
12828 Disable overload resolution for C@t{++} expression evaluation. For
12829 overloaded functions that are not class member functions, @value{GDBN}
12830 chooses the first function of the specified name that it finds in the
12831 symbol table, whether or not its arguments are of the correct type. For
12832 overloaded functions that are class member functions, @value{GDBN}
12833 searches for a function whose signature @emph{exactly} matches the
12834 argument types.
12835
12836 @kindex show overload-resolution
12837 @item show overload-resolution
12838 Show the current setting of overload resolution.
12839
12840 @item @r{Overloaded symbol names}
12841 You can specify a particular definition of an overloaded symbol, using
12842 the same notation that is used to declare such symbols in C@t{++}: type
12843 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
12844 also use the @value{GDBN} command-line word completion facilities to list the
12845 available choices, or to finish the type list for you.
12846 @xref{Completion,, Command Completion}, for details on how to do this.
12847 @end table
12848
12849 @node Decimal Floating Point
12850 @subsubsection Decimal Floating Point format
12851 @cindex decimal floating point format
12852
12853 @value{GDBN} can examine, set and perform computations with numbers in
12854 decimal floating point format, which in the C language correspond to the
12855 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
12856 specified by the extension to support decimal floating-point arithmetic.
12857
12858 There are two encodings in use, depending on the architecture: BID (Binary
12859 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
12860 PowerPC. @value{GDBN} will use the appropriate encoding for the configured
12861 target.
12862
12863 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
12864 to manipulate decimal floating point numbers, it is not possible to convert
12865 (using a cast, for example) integers wider than 32-bit to decimal float.
12866
12867 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
12868 point computations, error checking in decimal float operations ignores
12869 underflow, overflow and divide by zero exceptions.
12870
12871 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
12872 to inspect @code{_Decimal128} values stored in floating point registers.
12873 See @ref{PowerPC,,PowerPC} for more details.
12874
12875 @node D
12876 @subsection D
12877
12878 @cindex D
12879 @value{GDBN} can be used to debug programs written in D and compiled with
12880 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
12881 specific feature --- dynamic arrays.
12882
12883 @node Objective-C
12884 @subsection Objective-C
12885
12886 @cindex Objective-C
12887 This section provides information about some commands and command
12888 options that are useful for debugging Objective-C code. See also
12889 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
12890 few more commands specific to Objective-C support.
12891
12892 @menu
12893 * Method Names in Commands::
12894 * The Print Command with Objective-C::
12895 @end menu
12896
12897 @node Method Names in Commands
12898 @subsubsection Method Names in Commands
12899
12900 The following commands have been extended to accept Objective-C method
12901 names as line specifications:
12902
12903 @kindex clear@r{, and Objective-C}
12904 @kindex break@r{, and Objective-C}
12905 @kindex info line@r{, and Objective-C}
12906 @kindex jump@r{, and Objective-C}
12907 @kindex list@r{, and Objective-C}
12908 @itemize
12909 @item @code{clear}
12910 @item @code{break}
12911 @item @code{info line}
12912 @item @code{jump}
12913 @item @code{list}
12914 @end itemize
12915
12916 A fully qualified Objective-C method name is specified as
12917
12918 @smallexample
12919 -[@var{Class} @var{methodName}]
12920 @end smallexample
12921
12922 where the minus sign is used to indicate an instance method and a
12923 plus sign (not shown) is used to indicate a class method. The class
12924 name @var{Class} and method name @var{methodName} are enclosed in
12925 brackets, similar to the way messages are specified in Objective-C
12926 source code. For example, to set a breakpoint at the @code{create}
12927 instance method of class @code{Fruit} in the program currently being
12928 debugged, enter:
12929
12930 @smallexample
12931 break -[Fruit create]
12932 @end smallexample
12933
12934 To list ten program lines around the @code{initialize} class method,
12935 enter:
12936
12937 @smallexample
12938 list +[NSText initialize]
12939 @end smallexample
12940
12941 In the current version of @value{GDBN}, the plus or minus sign is
12942 required. In future versions of @value{GDBN}, the plus or minus
12943 sign will be optional, but you can use it to narrow the search. It
12944 is also possible to specify just a method name:
12945
12946 @smallexample
12947 break create
12948 @end smallexample
12949
12950 You must specify the complete method name, including any colons. If
12951 your program's source files contain more than one @code{create} method,
12952 you'll be presented with a numbered list of classes that implement that
12953 method. Indicate your choice by number, or type @samp{0} to exit if
12954 none apply.
12955
12956 As another example, to clear a breakpoint established at the
12957 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
12958
12959 @smallexample
12960 clear -[NSWindow makeKeyAndOrderFront:]
12961 @end smallexample
12962
12963 @node The Print Command with Objective-C
12964 @subsubsection The Print Command With Objective-C
12965 @cindex Objective-C, print objects
12966 @kindex print-object
12967 @kindex po @r{(@code{print-object})}
12968
12969 The print command has also been extended to accept methods. For example:
12970
12971 @smallexample
12972 print -[@var{object} hash]
12973 @end smallexample
12974
12975 @cindex print an Objective-C object description
12976 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
12977 @noindent
12978 will tell @value{GDBN} to send the @code{hash} message to @var{object}
12979 and print the result. Also, an additional command has been added,
12980 @code{print-object} or @code{po} for short, which is meant to print
12981 the description of an object. However, this command may only work
12982 with certain Objective-C libraries that have a particular hook
12983 function, @code{_NSPrintForDebugger}, defined.
12984
12985 @node OpenCL C
12986 @subsection OpenCL C
12987
12988 @cindex OpenCL C
12989 This section provides information about @value{GDBN}s OpenCL C support.
12990
12991 @menu
12992 * OpenCL C Datatypes::
12993 * OpenCL C Expressions::
12994 * OpenCL C Operators::
12995 @end menu
12996
12997 @node OpenCL C Datatypes
12998 @subsubsection OpenCL C Datatypes
12999
13000 @cindex OpenCL C Datatypes
13001 @value{GDBN} supports the builtin scalar and vector datatypes specified
13002 by OpenCL 1.1. In addition the half- and double-precision floating point
13003 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
13004 extensions are also known to @value{GDBN}.
13005
13006 @node OpenCL C Expressions
13007 @subsubsection OpenCL C Expressions
13008
13009 @cindex OpenCL C Expressions
13010 @value{GDBN} supports accesses to vector components including the access as
13011 lvalue where possible. Since OpenCL C is based on C99 most C expressions
13012 supported by @value{GDBN} can be used as well.
13013
13014 @node OpenCL C Operators
13015 @subsubsection OpenCL C Operators
13016
13017 @cindex OpenCL C Operators
13018 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
13019 vector data types.
13020
13021 @node Fortran
13022 @subsection Fortran
13023 @cindex Fortran-specific support in @value{GDBN}
13024
13025 @value{GDBN} can be used to debug programs written in Fortran, but it
13026 currently supports only the features of Fortran 77 language.
13027
13028 @cindex trailing underscore, in Fortran symbols
13029 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
13030 among them) append an underscore to the names of variables and
13031 functions. When you debug programs compiled by those compilers, you
13032 will need to refer to variables and functions with a trailing
13033 underscore.
13034
13035 @menu
13036 * Fortran Operators:: Fortran operators and expressions
13037 * Fortran Defaults:: Default settings for Fortran
13038 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
13039 @end menu
13040
13041 @node Fortran Operators
13042 @subsubsection Fortran Operators and Expressions
13043
13044 @cindex Fortran operators and expressions
13045
13046 Operators must be defined on values of specific types. For instance,
13047 @code{+} is defined on numbers, but not on characters or other non-
13048 arithmetic types. Operators are often defined on groups of types.
13049
13050 @table @code
13051 @item **
13052 The exponentiation operator. It raises the first operand to the power
13053 of the second one.
13054
13055 @item :
13056 The range operator. Normally used in the form of array(low:high) to
13057 represent a section of array.
13058
13059 @item %
13060 The access component operator. Normally used to access elements in derived
13061 types. Also suitable for unions. As unions aren't part of regular Fortran,
13062 this can only happen when accessing a register that uses a gdbarch-defined
13063 union type.
13064 @end table
13065
13066 @node Fortran Defaults
13067 @subsubsection Fortran Defaults
13068
13069 @cindex Fortran Defaults
13070
13071 Fortran symbols are usually case-insensitive, so @value{GDBN} by
13072 default uses case-insensitive matches for Fortran symbols. You can
13073 change that with the @samp{set case-insensitive} command, see
13074 @ref{Symbols}, for the details.
13075
13076 @node Special Fortran Commands
13077 @subsubsection Special Fortran Commands
13078
13079 @cindex Special Fortran commands
13080
13081 @value{GDBN} has some commands to support Fortran-specific features,
13082 such as displaying common blocks.
13083
13084 @table @code
13085 @cindex @code{COMMON} blocks, Fortran
13086 @kindex info common
13087 @item info common @r{[}@var{common-name}@r{]}
13088 This command prints the values contained in the Fortran @code{COMMON}
13089 block whose name is @var{common-name}. With no argument, the names of
13090 all @code{COMMON} blocks visible at the current program location are
13091 printed.
13092 @end table
13093
13094 @node Pascal
13095 @subsection Pascal
13096
13097 @cindex Pascal support in @value{GDBN}, limitations
13098 Debugging Pascal programs which use sets, subranges, file variables, or
13099 nested functions does not currently work. @value{GDBN} does not support
13100 entering expressions, printing values, or similar features using Pascal
13101 syntax.
13102
13103 The Pascal-specific command @code{set print pascal_static-members}
13104 controls whether static members of Pascal objects are displayed.
13105 @xref{Print Settings, pascal_static-members}.
13106
13107 @node Modula-2
13108 @subsection Modula-2
13109
13110 @cindex Modula-2, @value{GDBN} support
13111
13112 The extensions made to @value{GDBN} to support Modula-2 only support
13113 output from the @sc{gnu} Modula-2 compiler (which is currently being
13114 developed). Other Modula-2 compilers are not currently supported, and
13115 attempting to debug executables produced by them is most likely
13116 to give an error as @value{GDBN} reads in the executable's symbol
13117 table.
13118
13119 @cindex expressions in Modula-2
13120 @menu
13121 * M2 Operators:: Built-in operators
13122 * Built-In Func/Proc:: Built-in functions and procedures
13123 * M2 Constants:: Modula-2 constants
13124 * M2 Types:: Modula-2 types
13125 * M2 Defaults:: Default settings for Modula-2
13126 * Deviations:: Deviations from standard Modula-2
13127 * M2 Checks:: Modula-2 type and range checks
13128 * M2 Scope:: The scope operators @code{::} and @code{.}
13129 * GDB/M2:: @value{GDBN} and Modula-2
13130 @end menu
13131
13132 @node M2 Operators
13133 @subsubsection Operators
13134 @cindex Modula-2 operators
13135
13136 Operators must be defined on values of specific types. For instance,
13137 @code{+} is defined on numbers, but not on structures. Operators are
13138 often defined on groups of types. For the purposes of Modula-2, the
13139 following definitions hold:
13140
13141 @itemize @bullet
13142
13143 @item
13144 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
13145 their subranges.
13146
13147 @item
13148 @emph{Character types} consist of @code{CHAR} and its subranges.
13149
13150 @item
13151 @emph{Floating-point types} consist of @code{REAL}.
13152
13153 @item
13154 @emph{Pointer types} consist of anything declared as @code{POINTER TO
13155 @var{type}}.
13156
13157 @item
13158 @emph{Scalar types} consist of all of the above.
13159
13160 @item
13161 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
13162
13163 @item
13164 @emph{Boolean types} consist of @code{BOOLEAN}.
13165 @end itemize
13166
13167 @noindent
13168 The following operators are supported, and appear in order of
13169 increasing precedence:
13170
13171 @table @code
13172 @item ,
13173 Function argument or array index separator.
13174
13175 @item :=
13176 Assignment. The value of @var{var} @code{:=} @var{value} is
13177 @var{value}.
13178
13179 @item <@r{, }>
13180 Less than, greater than on integral, floating-point, or enumerated
13181 types.
13182
13183 @item <=@r{, }>=
13184 Less than or equal to, greater than or equal to
13185 on integral, floating-point and enumerated types, or set inclusion on
13186 set types. Same precedence as @code{<}.
13187
13188 @item =@r{, }<>@r{, }#
13189 Equality and two ways of expressing inequality, valid on scalar types.
13190 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
13191 available for inequality, since @code{#} conflicts with the script
13192 comment character.
13193
13194 @item IN
13195 Set membership. Defined on set types and the types of their members.
13196 Same precedence as @code{<}.
13197
13198 @item OR
13199 Boolean disjunction. Defined on boolean types.
13200
13201 @item AND@r{, }&
13202 Boolean conjunction. Defined on boolean types.
13203
13204 @item @@
13205 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13206
13207 @item +@r{, }-
13208 Addition and subtraction on integral and floating-point types, or union
13209 and difference on set types.
13210
13211 @item *
13212 Multiplication on integral and floating-point types, or set intersection
13213 on set types.
13214
13215 @item /
13216 Division on floating-point types, or symmetric set difference on set
13217 types. Same precedence as @code{*}.
13218
13219 @item DIV@r{, }MOD
13220 Integer division and remainder. Defined on integral types. Same
13221 precedence as @code{*}.
13222
13223 @item -
13224 Negative. Defined on @code{INTEGER} and @code{REAL} data.
13225
13226 @item ^
13227 Pointer dereferencing. Defined on pointer types.
13228
13229 @item NOT
13230 Boolean negation. Defined on boolean types. Same precedence as
13231 @code{^}.
13232
13233 @item .
13234 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
13235 precedence as @code{^}.
13236
13237 @item []
13238 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
13239
13240 @item ()
13241 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
13242 as @code{^}.
13243
13244 @item ::@r{, }.
13245 @value{GDBN} and Modula-2 scope operators.
13246 @end table
13247
13248 @quotation
13249 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
13250 treats the use of the operator @code{IN}, or the use of operators
13251 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
13252 @code{<=}, and @code{>=} on sets as an error.
13253 @end quotation
13254
13255
13256 @node Built-In Func/Proc
13257 @subsubsection Built-in Functions and Procedures
13258 @cindex Modula-2 built-ins
13259
13260 Modula-2 also makes available several built-in procedures and functions.
13261 In describing these, the following metavariables are used:
13262
13263 @table @var
13264
13265 @item a
13266 represents an @code{ARRAY} variable.
13267
13268 @item c
13269 represents a @code{CHAR} constant or variable.
13270
13271 @item i
13272 represents a variable or constant of integral type.
13273
13274 @item m
13275 represents an identifier that belongs to a set. Generally used in the
13276 same function with the metavariable @var{s}. The type of @var{s} should
13277 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
13278
13279 @item n
13280 represents a variable or constant of integral or floating-point type.
13281
13282 @item r
13283 represents a variable or constant of floating-point type.
13284
13285 @item t
13286 represents a type.
13287
13288 @item v
13289 represents a variable.
13290
13291 @item x
13292 represents a variable or constant of one of many types. See the
13293 explanation of the function for details.
13294 @end table
13295
13296 All Modula-2 built-in procedures also return a result, described below.
13297
13298 @table @code
13299 @item ABS(@var{n})
13300 Returns the absolute value of @var{n}.
13301
13302 @item CAP(@var{c})
13303 If @var{c} is a lower case letter, it returns its upper case
13304 equivalent, otherwise it returns its argument.
13305
13306 @item CHR(@var{i})
13307 Returns the character whose ordinal value is @var{i}.
13308
13309 @item DEC(@var{v})
13310 Decrements the value in the variable @var{v} by one. Returns the new value.
13311
13312 @item DEC(@var{v},@var{i})
13313 Decrements the value in the variable @var{v} by @var{i}. Returns the
13314 new value.
13315
13316 @item EXCL(@var{m},@var{s})
13317 Removes the element @var{m} from the set @var{s}. Returns the new
13318 set.
13319
13320 @item FLOAT(@var{i})
13321 Returns the floating point equivalent of the integer @var{i}.
13322
13323 @item HIGH(@var{a})
13324 Returns the index of the last member of @var{a}.
13325
13326 @item INC(@var{v})
13327 Increments the value in the variable @var{v} by one. Returns the new value.
13328
13329 @item INC(@var{v},@var{i})
13330 Increments the value in the variable @var{v} by @var{i}. Returns the
13331 new value.
13332
13333 @item INCL(@var{m},@var{s})
13334 Adds the element @var{m} to the set @var{s} if it is not already
13335 there. Returns the new set.
13336
13337 @item MAX(@var{t})
13338 Returns the maximum value of the type @var{t}.
13339
13340 @item MIN(@var{t})
13341 Returns the minimum value of the type @var{t}.
13342
13343 @item ODD(@var{i})
13344 Returns boolean TRUE if @var{i} is an odd number.
13345
13346 @item ORD(@var{x})
13347 Returns the ordinal value of its argument. For example, the ordinal
13348 value of a character is its @sc{ascii} value (on machines supporting the
13349 @sc{ascii} character set). @var{x} must be of an ordered type, which include
13350 integral, character and enumerated types.
13351
13352 @item SIZE(@var{x})
13353 Returns the size of its argument. @var{x} can be a variable or a type.
13354
13355 @item TRUNC(@var{r})
13356 Returns the integral part of @var{r}.
13357
13358 @item TSIZE(@var{x})
13359 Returns the size of its argument. @var{x} can be a variable or a type.
13360
13361 @item VAL(@var{t},@var{i})
13362 Returns the member of the type @var{t} whose ordinal value is @var{i}.
13363 @end table
13364
13365 @quotation
13366 @emph{Warning:} Sets and their operations are not yet supported, so
13367 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
13368 an error.
13369 @end quotation
13370
13371 @cindex Modula-2 constants
13372 @node M2 Constants
13373 @subsubsection Constants
13374
13375 @value{GDBN} allows you to express the constants of Modula-2 in the following
13376 ways:
13377
13378 @itemize @bullet
13379
13380 @item
13381 Integer constants are simply a sequence of digits. When used in an
13382 expression, a constant is interpreted to be type-compatible with the
13383 rest of the expression. Hexadecimal integers are specified by a
13384 trailing @samp{H}, and octal integers by a trailing @samp{B}.
13385
13386 @item
13387 Floating point constants appear as a sequence of digits, followed by a
13388 decimal point and another sequence of digits. An optional exponent can
13389 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
13390 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
13391 digits of the floating point constant must be valid decimal (base 10)
13392 digits.
13393
13394 @item
13395 Character constants consist of a single character enclosed by a pair of
13396 like quotes, either single (@code{'}) or double (@code{"}). They may
13397 also be expressed by their ordinal value (their @sc{ascii} value, usually)
13398 followed by a @samp{C}.
13399
13400 @item
13401 String constants consist of a sequence of characters enclosed by a
13402 pair of like quotes, either single (@code{'}) or double (@code{"}).
13403 Escape sequences in the style of C are also allowed. @xref{C
13404 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
13405 sequences.
13406
13407 @item
13408 Enumerated constants consist of an enumerated identifier.
13409
13410 @item
13411 Boolean constants consist of the identifiers @code{TRUE} and
13412 @code{FALSE}.
13413
13414 @item
13415 Pointer constants consist of integral values only.
13416
13417 @item
13418 Set constants are not yet supported.
13419 @end itemize
13420
13421 @node M2 Types
13422 @subsubsection Modula-2 Types
13423 @cindex Modula-2 types
13424
13425 Currently @value{GDBN} can print the following data types in Modula-2
13426 syntax: array types, record types, set types, pointer types, procedure
13427 types, enumerated types, subrange types and base types. You can also
13428 print the contents of variables declared using these type.
13429 This section gives a number of simple source code examples together with
13430 sample @value{GDBN} sessions.
13431
13432 The first example contains the following section of code:
13433
13434 @smallexample
13435 VAR
13436 s: SET OF CHAR ;
13437 r: [20..40] ;
13438 @end smallexample
13439
13440 @noindent
13441 and you can request @value{GDBN} to interrogate the type and value of
13442 @code{r} and @code{s}.
13443
13444 @smallexample
13445 (@value{GDBP}) print s
13446 @{'A'..'C', 'Z'@}
13447 (@value{GDBP}) ptype s
13448 SET OF CHAR
13449 (@value{GDBP}) print r
13450 21
13451 (@value{GDBP}) ptype r
13452 [20..40]
13453 @end smallexample
13454
13455 @noindent
13456 Likewise if your source code declares @code{s} as:
13457
13458 @smallexample
13459 VAR
13460 s: SET ['A'..'Z'] ;
13461 @end smallexample
13462
13463 @noindent
13464 then you may query the type of @code{s} by:
13465
13466 @smallexample
13467 (@value{GDBP}) ptype s
13468 type = SET ['A'..'Z']
13469 @end smallexample
13470
13471 @noindent
13472 Note that at present you cannot interactively manipulate set
13473 expressions using the debugger.
13474
13475 The following example shows how you might declare an array in Modula-2
13476 and how you can interact with @value{GDBN} to print its type and contents:
13477
13478 @smallexample
13479 VAR
13480 s: ARRAY [-10..10] OF CHAR ;
13481 @end smallexample
13482
13483 @smallexample
13484 (@value{GDBP}) ptype s
13485 ARRAY [-10..10] OF CHAR
13486 @end smallexample
13487
13488 Note that the array handling is not yet complete and although the type
13489 is printed correctly, expression handling still assumes that all
13490 arrays have a lower bound of zero and not @code{-10} as in the example
13491 above.
13492
13493 Here are some more type related Modula-2 examples:
13494
13495 @smallexample
13496 TYPE
13497 colour = (blue, red, yellow, green) ;
13498 t = [blue..yellow] ;
13499 VAR
13500 s: t ;
13501 BEGIN
13502 s := blue ;
13503 @end smallexample
13504
13505 @noindent
13506 The @value{GDBN} interaction shows how you can query the data type
13507 and value of a variable.
13508
13509 @smallexample
13510 (@value{GDBP}) print s
13511 $1 = blue
13512 (@value{GDBP}) ptype t
13513 type = [blue..yellow]
13514 @end smallexample
13515
13516 @noindent
13517 In this example a Modula-2 array is declared and its contents
13518 displayed. Observe that the contents are written in the same way as
13519 their @code{C} counterparts.
13520
13521 @smallexample
13522 VAR
13523 s: ARRAY [1..5] OF CARDINAL ;
13524 BEGIN
13525 s[1] := 1 ;
13526 @end smallexample
13527
13528 @smallexample
13529 (@value{GDBP}) print s
13530 $1 = @{1, 0, 0, 0, 0@}
13531 (@value{GDBP}) ptype s
13532 type = ARRAY [1..5] OF CARDINAL
13533 @end smallexample
13534
13535 The Modula-2 language interface to @value{GDBN} also understands
13536 pointer types as shown in this example:
13537
13538 @smallexample
13539 VAR
13540 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
13541 BEGIN
13542 NEW(s) ;
13543 s^[1] := 1 ;
13544 @end smallexample
13545
13546 @noindent
13547 and you can request that @value{GDBN} describes the type of @code{s}.
13548
13549 @smallexample
13550 (@value{GDBP}) ptype s
13551 type = POINTER TO ARRAY [1..5] OF CARDINAL
13552 @end smallexample
13553
13554 @value{GDBN} handles compound types as we can see in this example.
13555 Here we combine array types, record types, pointer types and subrange
13556 types:
13557
13558 @smallexample
13559 TYPE
13560 foo = RECORD
13561 f1: CARDINAL ;
13562 f2: CHAR ;
13563 f3: myarray ;
13564 END ;
13565
13566 myarray = ARRAY myrange OF CARDINAL ;
13567 myrange = [-2..2] ;
13568 VAR
13569 s: POINTER TO ARRAY myrange OF foo ;
13570 @end smallexample
13571
13572 @noindent
13573 and you can ask @value{GDBN} to describe the type of @code{s} as shown
13574 below.
13575
13576 @smallexample
13577 (@value{GDBP}) ptype s
13578 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
13579 f1 : CARDINAL;
13580 f2 : CHAR;
13581 f3 : ARRAY [-2..2] OF CARDINAL;
13582 END
13583 @end smallexample
13584
13585 @node M2 Defaults
13586 @subsubsection Modula-2 Defaults
13587 @cindex Modula-2 defaults
13588
13589 If type and range checking are set automatically by @value{GDBN}, they
13590 both default to @code{on} whenever the working language changes to
13591 Modula-2. This happens regardless of whether you or @value{GDBN}
13592 selected the working language.
13593
13594 If you allow @value{GDBN} to set the language automatically, then entering
13595 code compiled from a file whose name ends with @file{.mod} sets the
13596 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
13597 Infer the Source Language}, for further details.
13598
13599 @node Deviations
13600 @subsubsection Deviations from Standard Modula-2
13601 @cindex Modula-2, deviations from
13602
13603 A few changes have been made to make Modula-2 programs easier to debug.
13604 This is done primarily via loosening its type strictness:
13605
13606 @itemize @bullet
13607 @item
13608 Unlike in standard Modula-2, pointer constants can be formed by
13609 integers. This allows you to modify pointer variables during
13610 debugging. (In standard Modula-2, the actual address contained in a
13611 pointer variable is hidden from you; it can only be modified
13612 through direct assignment to another pointer variable or expression that
13613 returned a pointer.)
13614
13615 @item
13616 C escape sequences can be used in strings and characters to represent
13617 non-printable characters. @value{GDBN} prints out strings with these
13618 escape sequences embedded. Single non-printable characters are
13619 printed using the @samp{CHR(@var{nnn})} format.
13620
13621 @item
13622 The assignment operator (@code{:=}) returns the value of its right-hand
13623 argument.
13624
13625 @item
13626 All built-in procedures both modify @emph{and} return their argument.
13627 @end itemize
13628
13629 @node M2 Checks
13630 @subsubsection Modula-2 Type and Range Checks
13631 @cindex Modula-2 checks
13632
13633 @quotation
13634 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
13635 range checking.
13636 @end quotation
13637 @c FIXME remove warning when type/range checks added
13638
13639 @value{GDBN} considers two Modula-2 variables type equivalent if:
13640
13641 @itemize @bullet
13642 @item
13643 They are of types that have been declared equivalent via a @code{TYPE
13644 @var{t1} = @var{t2}} statement
13645
13646 @item
13647 They have been declared on the same line. (Note: This is true of the
13648 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
13649 @end itemize
13650
13651 As long as type checking is enabled, any attempt to combine variables
13652 whose types are not equivalent is an error.
13653
13654 Range checking is done on all mathematical operations, assignment, array
13655 index bounds, and all built-in functions and procedures.
13656
13657 @node M2 Scope
13658 @subsubsection The Scope Operators @code{::} and @code{.}
13659 @cindex scope
13660 @cindex @code{.}, Modula-2 scope operator
13661 @cindex colon, doubled as scope operator
13662 @ifinfo
13663 @vindex colon-colon@r{, in Modula-2}
13664 @c Info cannot handle :: but TeX can.
13665 @end ifinfo
13666 @ifnotinfo
13667 @vindex ::@r{, in Modula-2}
13668 @end ifnotinfo
13669
13670 There are a few subtle differences between the Modula-2 scope operator
13671 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
13672 similar syntax:
13673
13674 @smallexample
13675
13676 @var{module} . @var{id}
13677 @var{scope} :: @var{id}
13678 @end smallexample
13679
13680 @noindent
13681 where @var{scope} is the name of a module or a procedure,
13682 @var{module} the name of a module, and @var{id} is any declared
13683 identifier within your program, except another module.
13684
13685 Using the @code{::} operator makes @value{GDBN} search the scope
13686 specified by @var{scope} for the identifier @var{id}. If it is not
13687 found in the specified scope, then @value{GDBN} searches all scopes
13688 enclosing the one specified by @var{scope}.
13689
13690 Using the @code{.} operator makes @value{GDBN} search the current scope for
13691 the identifier specified by @var{id} that was imported from the
13692 definition module specified by @var{module}. With this operator, it is
13693 an error if the identifier @var{id} was not imported from definition
13694 module @var{module}, or if @var{id} is not an identifier in
13695 @var{module}.
13696
13697 @node GDB/M2
13698 @subsubsection @value{GDBN} and Modula-2
13699
13700 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
13701 Five subcommands of @code{set print} and @code{show print} apply
13702 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
13703 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
13704 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
13705 analogue in Modula-2.
13706
13707 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
13708 with any language, is not useful with Modula-2. Its
13709 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
13710 created in Modula-2 as they can in C or C@t{++}. However, because an
13711 address can be specified by an integral constant, the construct
13712 @samp{@{@var{type}@}@var{adrexp}} is still useful.
13713
13714 @cindex @code{#} in Modula-2
13715 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
13716 interpreted as the beginning of a comment. Use @code{<>} instead.
13717
13718 @node Ada
13719 @subsection Ada
13720 @cindex Ada
13721
13722 The extensions made to @value{GDBN} for Ada only support
13723 output from the @sc{gnu} Ada (GNAT) compiler.
13724 Other Ada compilers are not currently supported, and
13725 attempting to debug executables produced by them is most likely
13726 to be difficult.
13727
13728
13729 @cindex expressions in Ada
13730 @menu
13731 * Ada Mode Intro:: General remarks on the Ada syntax
13732 and semantics supported by Ada mode
13733 in @value{GDBN}.
13734 * Omissions from Ada:: Restrictions on the Ada expression syntax.
13735 * Additions to Ada:: Extensions of the Ada expression syntax.
13736 * Stopping Before Main Program:: Debugging the program during elaboration.
13737 * Ada Tasks:: Listing and setting breakpoints in tasks.
13738 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
13739 * Ravenscar Profile:: Tasking Support when using the Ravenscar
13740 Profile
13741 * Ada Glitches:: Known peculiarities of Ada mode.
13742 @end menu
13743
13744 @node Ada Mode Intro
13745 @subsubsection Introduction
13746 @cindex Ada mode, general
13747
13748 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
13749 syntax, with some extensions.
13750 The philosophy behind the design of this subset is
13751
13752 @itemize @bullet
13753 @item
13754 That @value{GDBN} should provide basic literals and access to operations for
13755 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
13756 leaving more sophisticated computations to subprograms written into the
13757 program (which therefore may be called from @value{GDBN}).
13758
13759 @item
13760 That type safety and strict adherence to Ada language restrictions
13761 are not particularly important to the @value{GDBN} user.
13762
13763 @item
13764 That brevity is important to the @value{GDBN} user.
13765 @end itemize
13766
13767 Thus, for brevity, the debugger acts as if all names declared in
13768 user-written packages are directly visible, even if they are not visible
13769 according to Ada rules, thus making it unnecessary to fully qualify most
13770 names with their packages, regardless of context. Where this causes
13771 ambiguity, @value{GDBN} asks the user's intent.
13772
13773 The debugger will start in Ada mode if it detects an Ada main program.
13774 As for other languages, it will enter Ada mode when stopped in a program that
13775 was translated from an Ada source file.
13776
13777 While in Ada mode, you may use `@t{--}' for comments. This is useful
13778 mostly for documenting command files. The standard @value{GDBN} comment
13779 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
13780 middle (to allow based literals).
13781
13782 The debugger supports limited overloading. Given a subprogram call in which
13783 the function symbol has multiple definitions, it will use the number of
13784 actual parameters and some information about their types to attempt to narrow
13785 the set of definitions. It also makes very limited use of context, preferring
13786 procedures to functions in the context of the @code{call} command, and
13787 functions to procedures elsewhere.
13788
13789 @node Omissions from Ada
13790 @subsubsection Omissions from Ada
13791 @cindex Ada, omissions from
13792
13793 Here are the notable omissions from the subset:
13794
13795 @itemize @bullet
13796 @item
13797 Only a subset of the attributes are supported:
13798
13799 @itemize @minus
13800 @item
13801 @t{'First}, @t{'Last}, and @t{'Length}
13802 on array objects (not on types and subtypes).
13803
13804 @item
13805 @t{'Min} and @t{'Max}.
13806
13807 @item
13808 @t{'Pos} and @t{'Val}.
13809
13810 @item
13811 @t{'Tag}.
13812
13813 @item
13814 @t{'Range} on array objects (not subtypes), but only as the right
13815 operand of the membership (@code{in}) operator.
13816
13817 @item
13818 @t{'Access}, @t{'Unchecked_Access}, and
13819 @t{'Unrestricted_Access} (a GNAT extension).
13820
13821 @item
13822 @t{'Address}.
13823 @end itemize
13824
13825 @item
13826 The names in
13827 @code{Characters.Latin_1} are not available and
13828 concatenation is not implemented. Thus, escape characters in strings are
13829 not currently available.
13830
13831 @item
13832 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
13833 equality of representations. They will generally work correctly
13834 for strings and arrays whose elements have integer or enumeration types.
13835 They may not work correctly for arrays whose element
13836 types have user-defined equality, for arrays of real values
13837 (in particular, IEEE-conformant floating point, because of negative
13838 zeroes and NaNs), and for arrays whose elements contain unused bits with
13839 indeterminate values.
13840
13841 @item
13842 The other component-by-component array operations (@code{and}, @code{or},
13843 @code{xor}, @code{not}, and relational tests other than equality)
13844 are not implemented.
13845
13846 @item
13847 @cindex array aggregates (Ada)
13848 @cindex record aggregates (Ada)
13849 @cindex aggregates (Ada)
13850 There is limited support for array and record aggregates. They are
13851 permitted only on the right sides of assignments, as in these examples:
13852
13853 @smallexample
13854 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
13855 (@value{GDBP}) set An_Array := (1, others => 0)
13856 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
13857 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
13858 (@value{GDBP}) set A_Record := (1, "Peter", True);
13859 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
13860 @end smallexample
13861
13862 Changing a
13863 discriminant's value by assigning an aggregate has an
13864 undefined effect if that discriminant is used within the record.
13865 However, you can first modify discriminants by directly assigning to
13866 them (which normally would not be allowed in Ada), and then performing an
13867 aggregate assignment. For example, given a variable @code{A_Rec}
13868 declared to have a type such as:
13869
13870 @smallexample
13871 type Rec (Len : Small_Integer := 0) is record
13872 Id : Integer;
13873 Vals : IntArray (1 .. Len);
13874 end record;
13875 @end smallexample
13876
13877 you can assign a value with a different size of @code{Vals} with two
13878 assignments:
13879
13880 @smallexample
13881 (@value{GDBP}) set A_Rec.Len := 4
13882 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
13883 @end smallexample
13884
13885 As this example also illustrates, @value{GDBN} is very loose about the usual
13886 rules concerning aggregates. You may leave out some of the
13887 components of an array or record aggregate (such as the @code{Len}
13888 component in the assignment to @code{A_Rec} above); they will retain their
13889 original values upon assignment. You may freely use dynamic values as
13890 indices in component associations. You may even use overlapping or
13891 redundant component associations, although which component values are
13892 assigned in such cases is not defined.
13893
13894 @item
13895 Calls to dispatching subprograms are not implemented.
13896
13897 @item
13898 The overloading algorithm is much more limited (i.e., less selective)
13899 than that of real Ada. It makes only limited use of the context in
13900 which a subexpression appears to resolve its meaning, and it is much
13901 looser in its rules for allowing type matches. As a result, some
13902 function calls will be ambiguous, and the user will be asked to choose
13903 the proper resolution.
13904
13905 @item
13906 The @code{new} operator is not implemented.
13907
13908 @item
13909 Entry calls are not implemented.
13910
13911 @item
13912 Aside from printing, arithmetic operations on the native VAX floating-point
13913 formats are not supported.
13914
13915 @item
13916 It is not possible to slice a packed array.
13917
13918 @item
13919 The names @code{True} and @code{False}, when not part of a qualified name,
13920 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
13921 context.
13922 Should your program
13923 redefine these names in a package or procedure (at best a dubious practice),
13924 you will have to use fully qualified names to access their new definitions.
13925 @end itemize
13926
13927 @node Additions to Ada
13928 @subsubsection Additions to Ada
13929 @cindex Ada, deviations from
13930
13931 As it does for other languages, @value{GDBN} makes certain generic
13932 extensions to Ada (@pxref{Expressions}):
13933
13934 @itemize @bullet
13935 @item
13936 If the expression @var{E} is a variable residing in memory (typically
13937 a local variable or array element) and @var{N} is a positive integer,
13938 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
13939 @var{N}-1 adjacent variables following it in memory as an array. In
13940 Ada, this operator is generally not necessary, since its prime use is
13941 in displaying parts of an array, and slicing will usually do this in
13942 Ada. However, there are occasional uses when debugging programs in
13943 which certain debugging information has been optimized away.
13944
13945 @item
13946 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
13947 appears in function or file @var{B}.'' When @var{B} is a file name,
13948 you must typically surround it in single quotes.
13949
13950 @item
13951 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
13952 @var{type} that appears at address @var{addr}.''
13953
13954 @item
13955 A name starting with @samp{$} is a convenience variable
13956 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
13957 @end itemize
13958
13959 In addition, @value{GDBN} provides a few other shortcuts and outright
13960 additions specific to Ada:
13961
13962 @itemize @bullet
13963 @item
13964 The assignment statement is allowed as an expression, returning
13965 its right-hand operand as its value. Thus, you may enter
13966
13967 @smallexample
13968 (@value{GDBP}) set x := y + 3
13969 (@value{GDBP}) print A(tmp := y + 1)
13970 @end smallexample
13971
13972 @item
13973 The semicolon is allowed as an ``operator,'' returning as its value
13974 the value of its right-hand operand.
13975 This allows, for example,
13976 complex conditional breaks:
13977
13978 @smallexample
13979 (@value{GDBP}) break f
13980 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
13981 @end smallexample
13982
13983 @item
13984 Rather than use catenation and symbolic character names to introduce special
13985 characters into strings, one may instead use a special bracket notation,
13986 which is also used to print strings. A sequence of characters of the form
13987 @samp{["@var{XX}"]} within a string or character literal denotes the
13988 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
13989 sequence of characters @samp{["""]} also denotes a single quotation mark
13990 in strings. For example,
13991 @smallexample
13992 "One line.["0a"]Next line.["0a"]"
13993 @end smallexample
13994 @noindent
13995 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
13996 after each period.
13997
13998 @item
13999 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
14000 @t{'Max} is optional (and is ignored in any case). For example, it is valid
14001 to write
14002
14003 @smallexample
14004 (@value{GDBP}) print 'max(x, y)
14005 @end smallexample
14006
14007 @item
14008 When printing arrays, @value{GDBN} uses positional notation when the
14009 array has a lower bound of 1, and uses a modified named notation otherwise.
14010 For example, a one-dimensional array of three integers with a lower bound
14011 of 3 might print as
14012
14013 @smallexample
14014 (3 => 10, 17, 1)
14015 @end smallexample
14016
14017 @noindent
14018 That is, in contrast to valid Ada, only the first component has a @code{=>}
14019 clause.
14020
14021 @item
14022 You may abbreviate attributes in expressions with any unique,
14023 multi-character subsequence of
14024 their names (an exact match gets preference).
14025 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
14026 in place of @t{a'length}.
14027
14028 @item
14029 @cindex quoting Ada internal identifiers
14030 Since Ada is case-insensitive, the debugger normally maps identifiers you type
14031 to lower case. The GNAT compiler uses upper-case characters for
14032 some of its internal identifiers, which are normally of no interest to users.
14033 For the rare occasions when you actually have to look at them,
14034 enclose them in angle brackets to avoid the lower-case mapping.
14035 For example,
14036 @smallexample
14037 (@value{GDBP}) print <JMPBUF_SAVE>[0]
14038 @end smallexample
14039
14040 @item
14041 Printing an object of class-wide type or dereferencing an
14042 access-to-class-wide value will display all the components of the object's
14043 specific type (as indicated by its run-time tag). Likewise, component
14044 selection on such a value will operate on the specific type of the
14045 object.
14046
14047 @end itemize
14048
14049 @node Stopping Before Main Program
14050 @subsubsection Stopping at the Very Beginning
14051
14052 @cindex breakpointing Ada elaboration code
14053 It is sometimes necessary to debug the program during elaboration, and
14054 before reaching the main procedure.
14055 As defined in the Ada Reference
14056 Manual, the elaboration code is invoked from a procedure called
14057 @code{adainit}. To run your program up to the beginning of
14058 elaboration, simply use the following two commands:
14059 @code{tbreak adainit} and @code{run}.
14060
14061 @node Ada Tasks
14062 @subsubsection Extensions for Ada Tasks
14063 @cindex Ada, tasking
14064
14065 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
14066 @value{GDBN} provides the following task-related commands:
14067
14068 @table @code
14069 @kindex info tasks
14070 @item info tasks
14071 This command shows a list of current Ada tasks, as in the following example:
14072
14073
14074 @smallexample
14075 @iftex
14076 @leftskip=0.5cm
14077 @end iftex
14078 (@value{GDBP}) info tasks
14079 ID TID P-ID Pri State Name
14080 1 8088000 0 15 Child Activation Wait main_task
14081 2 80a4000 1 15 Accept Statement b
14082 3 809a800 1 15 Child Activation Wait a
14083 * 4 80ae800 3 15 Runnable c
14084
14085 @end smallexample
14086
14087 @noindent
14088 In this listing, the asterisk before the last task indicates it to be the
14089 task currently being inspected.
14090
14091 @table @asis
14092 @item ID
14093 Represents @value{GDBN}'s internal task number.
14094
14095 @item TID
14096 The Ada task ID.
14097
14098 @item P-ID
14099 The parent's task ID (@value{GDBN}'s internal task number).
14100
14101 @item Pri
14102 The base priority of the task.
14103
14104 @item State
14105 Current state of the task.
14106
14107 @table @code
14108 @item Unactivated
14109 The task has been created but has not been activated. It cannot be
14110 executing.
14111
14112 @item Runnable
14113 The task is not blocked for any reason known to Ada. (It may be waiting
14114 for a mutex, though.) It is conceptually "executing" in normal mode.
14115
14116 @item Terminated
14117 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
14118 that were waiting on terminate alternatives have been awakened and have
14119 terminated themselves.
14120
14121 @item Child Activation Wait
14122 The task is waiting for created tasks to complete activation.
14123
14124 @item Accept Statement
14125 The task is waiting on an accept or selective wait statement.
14126
14127 @item Waiting on entry call
14128 The task is waiting on an entry call.
14129
14130 @item Async Select Wait
14131 The task is waiting to start the abortable part of an asynchronous
14132 select statement.
14133
14134 @item Delay Sleep
14135 The task is waiting on a select statement with only a delay
14136 alternative open.
14137
14138 @item Child Termination Wait
14139 The task is sleeping having completed a master within itself, and is
14140 waiting for the tasks dependent on that master to become terminated or
14141 waiting on a terminate Phase.
14142
14143 @item Wait Child in Term Alt
14144 The task is sleeping waiting for tasks on terminate alternatives to
14145 finish terminating.
14146
14147 @item Accepting RV with @var{taskno}
14148 The task is accepting a rendez-vous with the task @var{taskno}.
14149 @end table
14150
14151 @item Name
14152 Name of the task in the program.
14153
14154 @end table
14155
14156 @kindex info task @var{taskno}
14157 @item info task @var{taskno}
14158 This command shows detailled informations on the specified task, as in
14159 the following example:
14160 @smallexample
14161 @iftex
14162 @leftskip=0.5cm
14163 @end iftex
14164 (@value{GDBP}) info tasks
14165 ID TID P-ID Pri State Name
14166 1 8077880 0 15 Child Activation Wait main_task
14167 * 2 807c468 1 15 Runnable task_1
14168 (@value{GDBP}) info task 2
14169 Ada Task: 0x807c468
14170 Name: task_1
14171 Thread: 0x807f378
14172 Parent: 1 (main_task)
14173 Base Priority: 15
14174 State: Runnable
14175 @end smallexample
14176
14177 @item task
14178 @kindex task@r{ (Ada)}
14179 @cindex current Ada task ID
14180 This command prints the ID of the current task.
14181
14182 @smallexample
14183 @iftex
14184 @leftskip=0.5cm
14185 @end iftex
14186 (@value{GDBP}) info tasks
14187 ID TID P-ID Pri State Name
14188 1 8077870 0 15 Child Activation Wait main_task
14189 * 2 807c458 1 15 Runnable t
14190 (@value{GDBP}) task
14191 [Current task is 2]
14192 @end smallexample
14193
14194 @item task @var{taskno}
14195 @cindex Ada task switching
14196 This command is like the @code{thread @var{threadno}}
14197 command (@pxref{Threads}). It switches the context of debugging
14198 from the current task to the given task.
14199
14200 @smallexample
14201 @iftex
14202 @leftskip=0.5cm
14203 @end iftex
14204 (@value{GDBP}) info tasks
14205 ID TID P-ID Pri State Name
14206 1 8077870 0 15 Child Activation Wait main_task
14207 * 2 807c458 1 15 Runnable t
14208 (@value{GDBP}) task 1
14209 [Switching to task 1]
14210 #0 0x8067726 in pthread_cond_wait ()
14211 (@value{GDBP}) bt
14212 #0 0x8067726 in pthread_cond_wait ()
14213 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
14214 #2 0x805cb63 in system.task_primitives.operations.sleep ()
14215 #3 0x806153e in system.tasking.stages.activate_tasks ()
14216 #4 0x804aacc in un () at un.adb:5
14217 @end smallexample
14218
14219 @item break @var{linespec} task @var{taskno}
14220 @itemx break @var{linespec} task @var{taskno} if @dots{}
14221 @cindex breakpoints and tasks, in Ada
14222 @cindex task breakpoints, in Ada
14223 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
14224 These commands are like the @code{break @dots{} thread @dots{}}
14225 command (@pxref{Thread Stops}).
14226 @var{linespec} specifies source lines, as described
14227 in @ref{Specify Location}.
14228
14229 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
14230 to specify that you only want @value{GDBN} to stop the program when a
14231 particular Ada task reaches this breakpoint. @var{taskno} is one of the
14232 numeric task identifiers assigned by @value{GDBN}, shown in the first
14233 column of the @samp{info tasks} display.
14234
14235 If you do not specify @samp{task @var{taskno}} when you set a
14236 breakpoint, the breakpoint applies to @emph{all} tasks of your
14237 program.
14238
14239 You can use the @code{task} qualifier on conditional breakpoints as
14240 well; in this case, place @samp{task @var{taskno}} before the
14241 breakpoint condition (before the @code{if}).
14242
14243 For example,
14244
14245 @smallexample
14246 @iftex
14247 @leftskip=0.5cm
14248 @end iftex
14249 (@value{GDBP}) info tasks
14250 ID TID P-ID Pri State Name
14251 1 140022020 0 15 Child Activation Wait main_task
14252 2 140045060 1 15 Accept/Select Wait t2
14253 3 140044840 1 15 Runnable t1
14254 * 4 140056040 1 15 Runnable t3
14255 (@value{GDBP}) b 15 task 2
14256 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
14257 (@value{GDBP}) cont
14258 Continuing.
14259 task # 1 running
14260 task # 2 running
14261
14262 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
14263 15 flush;
14264 (@value{GDBP}) info tasks
14265 ID TID P-ID Pri State Name
14266 1 140022020 0 15 Child Activation Wait main_task
14267 * 2 140045060 1 15 Runnable t2
14268 3 140044840 1 15 Runnable t1
14269 4 140056040 1 15 Delay Sleep t3
14270 @end smallexample
14271 @end table
14272
14273 @node Ada Tasks and Core Files
14274 @subsubsection Tasking Support when Debugging Core Files
14275 @cindex Ada tasking and core file debugging
14276
14277 When inspecting a core file, as opposed to debugging a live program,
14278 tasking support may be limited or even unavailable, depending on
14279 the platform being used.
14280 For instance, on x86-linux, the list of tasks is available, but task
14281 switching is not supported. On Tru64, however, task switching will work
14282 as usual.
14283
14284 On certain platforms, including Tru64, the debugger needs to perform some
14285 memory writes in order to provide Ada tasking support. When inspecting
14286 a core file, this means that the core file must be opened with read-write
14287 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
14288 Under these circumstances, you should make a backup copy of the core
14289 file before inspecting it with @value{GDBN}.
14290
14291 @node Ravenscar Profile
14292 @subsubsection Tasking Support when using the Ravenscar Profile
14293 @cindex Ravenscar Profile
14294
14295 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
14296 specifically designed for systems with safety-critical real-time
14297 requirements.
14298
14299 @table @code
14300 @kindex set ravenscar task-switching on
14301 @cindex task switching with program using Ravenscar Profile
14302 @item set ravenscar task-switching on
14303 Allows task switching when debugging a program that uses the Ravenscar
14304 Profile. This is the default.
14305
14306 @kindex set ravenscar task-switching off
14307 @item set ravenscar task-switching off
14308 Turn off task switching when debugging a program that uses the Ravenscar
14309 Profile. This is mostly intended to disable the code that adds support
14310 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
14311 the Ravenscar runtime is preventing @value{GDBN} from working properly.
14312 To be effective, this command should be run before the program is started.
14313
14314 @kindex show ravenscar task-switching
14315 @item show ravenscar task-switching
14316 Show whether it is possible to switch from task to task in a program
14317 using the Ravenscar Profile.
14318
14319 @end table
14320
14321 @node Ada Glitches
14322 @subsubsection Known Peculiarities of Ada Mode
14323 @cindex Ada, problems
14324
14325 Besides the omissions listed previously (@pxref{Omissions from Ada}),
14326 we know of several problems with and limitations of Ada mode in
14327 @value{GDBN},
14328 some of which will be fixed with planned future releases of the debugger
14329 and the GNU Ada compiler.
14330
14331 @itemize @bullet
14332 @item
14333 Static constants that the compiler chooses not to materialize as objects in
14334 storage are invisible to the debugger.
14335
14336 @item
14337 Named parameter associations in function argument lists are ignored (the
14338 argument lists are treated as positional).
14339
14340 @item
14341 Many useful library packages are currently invisible to the debugger.
14342
14343 @item
14344 Fixed-point arithmetic, conversions, input, and output is carried out using
14345 floating-point arithmetic, and may give results that only approximate those on
14346 the host machine.
14347
14348 @item
14349 The GNAT compiler never generates the prefix @code{Standard} for any of
14350 the standard symbols defined by the Ada language. @value{GDBN} knows about
14351 this: it will strip the prefix from names when you use it, and will never
14352 look for a name you have so qualified among local symbols, nor match against
14353 symbols in other packages or subprograms. If you have
14354 defined entities anywhere in your program other than parameters and
14355 local variables whose simple names match names in @code{Standard},
14356 GNAT's lack of qualification here can cause confusion. When this happens,
14357 you can usually resolve the confusion
14358 by qualifying the problematic names with package
14359 @code{Standard} explicitly.
14360 @end itemize
14361
14362 Older versions of the compiler sometimes generate erroneous debugging
14363 information, resulting in the debugger incorrectly printing the value
14364 of affected entities. In some cases, the debugger is able to work
14365 around an issue automatically. In other cases, the debugger is able
14366 to work around the issue, but the work-around has to be specifically
14367 enabled.
14368
14369 @kindex set ada trust-PAD-over-XVS
14370 @kindex show ada trust-PAD-over-XVS
14371 @table @code
14372
14373 @item set ada trust-PAD-over-XVS on
14374 Configure GDB to strictly follow the GNAT encoding when computing the
14375 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
14376 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
14377 a complete description of the encoding used by the GNAT compiler).
14378 This is the default.
14379
14380 @item set ada trust-PAD-over-XVS off
14381 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
14382 sometimes prints the wrong value for certain entities, changing @code{ada
14383 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
14384 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
14385 @code{off}, but this incurs a slight performance penalty, so it is
14386 recommended to leave this setting to @code{on} unless necessary.
14387
14388 @end table
14389
14390 @node Unsupported Languages
14391 @section Unsupported Languages
14392
14393 @cindex unsupported languages
14394 @cindex minimal language
14395 In addition to the other fully-supported programming languages,
14396 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
14397 It does not represent a real programming language, but provides a set
14398 of capabilities close to what the C or assembly languages provide.
14399 This should allow most simple operations to be performed while debugging
14400 an application that uses a language currently not supported by @value{GDBN}.
14401
14402 If the language is set to @code{auto}, @value{GDBN} will automatically
14403 select this language if the current frame corresponds to an unsupported
14404 language.
14405
14406 @node Symbols
14407 @chapter Examining the Symbol Table
14408
14409 The commands described in this chapter allow you to inquire about the
14410 symbols (names of variables, functions and types) defined in your
14411 program. This information is inherent in the text of your program and
14412 does not change as your program executes. @value{GDBN} finds it in your
14413 program's symbol table, in the file indicated when you started @value{GDBN}
14414 (@pxref{File Options, ,Choosing Files}), or by one of the
14415 file-management commands (@pxref{Files, ,Commands to Specify Files}).
14416
14417 @cindex symbol names
14418 @cindex names of symbols
14419 @cindex quoting names
14420 Occasionally, you may need to refer to symbols that contain unusual
14421 characters, which @value{GDBN} ordinarily treats as word delimiters. The
14422 most frequent case is in referring to static variables in other
14423 source files (@pxref{Variables,,Program Variables}). File names
14424 are recorded in object files as debugging symbols, but @value{GDBN} would
14425 ordinarily parse a typical file name, like @file{foo.c}, as the three words
14426 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
14427 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
14428
14429 @smallexample
14430 p 'foo.c'::x
14431 @end smallexample
14432
14433 @noindent
14434 looks up the value of @code{x} in the scope of the file @file{foo.c}.
14435
14436 @table @code
14437 @cindex case-insensitive symbol names
14438 @cindex case sensitivity in symbol names
14439 @kindex set case-sensitive
14440 @item set case-sensitive on
14441 @itemx set case-sensitive off
14442 @itemx set case-sensitive auto
14443 Normally, when @value{GDBN} looks up symbols, it matches their names
14444 with case sensitivity determined by the current source language.
14445 Occasionally, you may wish to control that. The command @code{set
14446 case-sensitive} lets you do that by specifying @code{on} for
14447 case-sensitive matches or @code{off} for case-insensitive ones. If
14448 you specify @code{auto}, case sensitivity is reset to the default
14449 suitable for the source language. The default is case-sensitive
14450 matches for all languages except for Fortran, for which the default is
14451 case-insensitive matches.
14452
14453 @kindex show case-sensitive
14454 @item show case-sensitive
14455 This command shows the current setting of case sensitivity for symbols
14456 lookups.
14457
14458 @kindex info address
14459 @cindex address of a symbol
14460 @item info address @var{symbol}
14461 Describe where the data for @var{symbol} is stored. For a register
14462 variable, this says which register it is kept in. For a non-register
14463 local variable, this prints the stack-frame offset at which the variable
14464 is always stored.
14465
14466 Note the contrast with @samp{print &@var{symbol}}, which does not work
14467 at all for a register variable, and for a stack local variable prints
14468 the exact address of the current instantiation of the variable.
14469
14470 @kindex info symbol
14471 @cindex symbol from address
14472 @cindex closest symbol and offset for an address
14473 @item info symbol @var{addr}
14474 Print the name of a symbol which is stored at the address @var{addr}.
14475 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
14476 nearest symbol and an offset from it:
14477
14478 @smallexample
14479 (@value{GDBP}) info symbol 0x54320
14480 _initialize_vx + 396 in section .text
14481 @end smallexample
14482
14483 @noindent
14484 This is the opposite of the @code{info address} command. You can use
14485 it to find out the name of a variable or a function given its address.
14486
14487 For dynamically linked executables, the name of executable or shared
14488 library containing the symbol is also printed:
14489
14490 @smallexample
14491 (@value{GDBP}) info symbol 0x400225
14492 _start + 5 in section .text of /tmp/a.out
14493 (@value{GDBP}) info symbol 0x2aaaac2811cf
14494 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
14495 @end smallexample
14496
14497 @kindex whatis
14498 @item whatis [@var{arg}]
14499 Print the data type of @var{arg}, which can be either an expression
14500 or a name of a data type. With no argument, print the data type of
14501 @code{$}, the last value in the value history.
14502
14503 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
14504 is not actually evaluated, and any side-effecting operations (such as
14505 assignments or function calls) inside it do not take place.
14506
14507 If @var{arg} is a variable or an expression, @code{whatis} prints its
14508 literal type as it is used in the source code. If the type was
14509 defined using a @code{typedef}, @code{whatis} will @emph{not} print
14510 the data type underlying the @code{typedef}. If the type of the
14511 variable or the expression is a compound data type, such as
14512 @code{struct} or @code{class}, @code{whatis} never prints their
14513 fields or methods. It just prints the @code{struct}/@code{class}
14514 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
14515 such a compound data type, use @code{ptype}.
14516
14517 If @var{arg} is a type name that was defined using @code{typedef},
14518 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
14519 Unrolling means that @code{whatis} will show the underlying type used
14520 in the @code{typedef} declaration of @var{arg}. However, if that
14521 underlying type is also a @code{typedef}, @code{whatis} will not
14522 unroll it.
14523
14524 For C code, the type names may also have the form @samp{class
14525 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
14526 @var{union-tag}} or @samp{enum @var{enum-tag}}.
14527
14528 @kindex ptype
14529 @item ptype [@var{arg}]
14530 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
14531 detailed description of the type, instead of just the name of the type.
14532 @xref{Expressions, ,Expressions}.
14533
14534 Contrary to @code{whatis}, @code{ptype} always unrolls any
14535 @code{typedef}s in its argument declaration, whether the argument is
14536 a variable, expression, or a data type. This means that @code{ptype}
14537 of a variable or an expression will not print literally its type as
14538 present in the source code---use @code{whatis} for that. @code{typedef}s at
14539 the pointer or reference targets are also unrolled. Only @code{typedef}s of
14540 fields, methods and inner @code{class typedef}s of @code{struct}s,
14541 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
14542
14543 For example, for this variable declaration:
14544
14545 @smallexample
14546 typedef double real_t;
14547 struct complex @{ real_t real; double imag; @};
14548 typedef struct complex complex_t;
14549 complex_t var;
14550 real_t *real_pointer_var;
14551 @end smallexample
14552
14553 @noindent
14554 the two commands give this output:
14555
14556 @smallexample
14557 @group
14558 (@value{GDBP}) whatis var
14559 type = complex_t
14560 (@value{GDBP}) ptype var
14561 type = struct complex @{
14562 real_t real;
14563 double imag;
14564 @}
14565 (@value{GDBP}) whatis complex_t
14566 type = struct complex
14567 (@value{GDBP}) whatis struct complex
14568 type = struct complex
14569 (@value{GDBP}) ptype struct complex
14570 type = struct complex @{
14571 real_t real;
14572 double imag;
14573 @}
14574 (@value{GDBP}) whatis real_pointer_var
14575 type = real_t *
14576 (@value{GDBP}) ptype real_pointer_var
14577 type = double *
14578 @end group
14579 @end smallexample
14580
14581 @noindent
14582 As with @code{whatis}, using @code{ptype} without an argument refers to
14583 the type of @code{$}, the last value in the value history.
14584
14585 @cindex incomplete type
14586 Sometimes, programs use opaque data types or incomplete specifications
14587 of complex data structure. If the debug information included in the
14588 program does not allow @value{GDBN} to display a full declaration of
14589 the data type, it will say @samp{<incomplete type>}. For example,
14590 given these declarations:
14591
14592 @smallexample
14593 struct foo;
14594 struct foo *fooptr;
14595 @end smallexample
14596
14597 @noindent
14598 but no definition for @code{struct foo} itself, @value{GDBN} will say:
14599
14600 @smallexample
14601 (@value{GDBP}) ptype foo
14602 $1 = <incomplete type>
14603 @end smallexample
14604
14605 @noindent
14606 ``Incomplete type'' is C terminology for data types that are not
14607 completely specified.
14608
14609 @kindex info types
14610 @item info types @var{regexp}
14611 @itemx info types
14612 Print a brief description of all types whose names match the regular
14613 expression @var{regexp} (or all types in your program, if you supply
14614 no argument). Each complete typename is matched as though it were a
14615 complete line; thus, @samp{i type value} gives information on all
14616 types in your program whose names include the string @code{value}, but
14617 @samp{i type ^value$} gives information only on types whose complete
14618 name is @code{value}.
14619
14620 This command differs from @code{ptype} in two ways: first, like
14621 @code{whatis}, it does not print a detailed description; second, it
14622 lists all source files where a type is defined.
14623
14624 @kindex info scope
14625 @cindex local variables
14626 @item info scope @var{location}
14627 List all the variables local to a particular scope. This command
14628 accepts a @var{location} argument---a function name, a source line, or
14629 an address preceded by a @samp{*}, and prints all the variables local
14630 to the scope defined by that location. (@xref{Specify Location}, for
14631 details about supported forms of @var{location}.) For example:
14632
14633 @smallexample
14634 (@value{GDBP}) @b{info scope command_line_handler}
14635 Scope for command_line_handler:
14636 Symbol rl is an argument at stack/frame offset 8, length 4.
14637 Symbol linebuffer is in static storage at address 0x150a18, length 4.
14638 Symbol linelength is in static storage at address 0x150a1c, length 4.
14639 Symbol p is a local variable in register $esi, length 4.
14640 Symbol p1 is a local variable in register $ebx, length 4.
14641 Symbol nline is a local variable in register $edx, length 4.
14642 Symbol repeat is a local variable at frame offset -8, length 4.
14643 @end smallexample
14644
14645 @noindent
14646 This command is especially useful for determining what data to collect
14647 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
14648 collect}.
14649
14650 @kindex info source
14651 @item info source
14652 Show information about the current source file---that is, the source file for
14653 the function containing the current point of execution:
14654 @itemize @bullet
14655 @item
14656 the name of the source file, and the directory containing it,
14657 @item
14658 the directory it was compiled in,
14659 @item
14660 its length, in lines,
14661 @item
14662 which programming language it is written in,
14663 @item
14664 whether the executable includes debugging information for that file, and
14665 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
14666 @item
14667 whether the debugging information includes information about
14668 preprocessor macros.
14669 @end itemize
14670
14671
14672 @kindex info sources
14673 @item info sources
14674 Print the names of all source files in your program for which there is
14675 debugging information, organized into two lists: files whose symbols
14676 have already been read, and files whose symbols will be read when needed.
14677
14678 @kindex info functions
14679 @item info functions
14680 Print the names and data types of all defined functions.
14681
14682 @item info functions @var{regexp}
14683 Print the names and data types of all defined functions
14684 whose names contain a match for regular expression @var{regexp}.
14685 Thus, @samp{info fun step} finds all functions whose names
14686 include @code{step}; @samp{info fun ^step} finds those whose names
14687 start with @code{step}. If a function name contains characters
14688 that conflict with the regular expression language (e.g.@:
14689 @samp{operator*()}), they may be quoted with a backslash.
14690
14691 @kindex info variables
14692 @item info variables
14693 Print the names and data types of all variables that are defined
14694 outside of functions (i.e.@: excluding local variables).
14695
14696 @item info variables @var{regexp}
14697 Print the names and data types of all variables (except for local
14698 variables) whose names contain a match for regular expression
14699 @var{regexp}.
14700
14701 @kindex info classes
14702 @cindex Objective-C, classes and selectors
14703 @item info classes
14704 @itemx info classes @var{regexp}
14705 Display all Objective-C classes in your program, or
14706 (with the @var{regexp} argument) all those matching a particular regular
14707 expression.
14708
14709 @kindex info selectors
14710 @item info selectors
14711 @itemx info selectors @var{regexp}
14712 Display all Objective-C selectors in your program, or
14713 (with the @var{regexp} argument) all those matching a particular regular
14714 expression.
14715
14716 @ignore
14717 This was never implemented.
14718 @kindex info methods
14719 @item info methods
14720 @itemx info methods @var{regexp}
14721 The @code{info methods} command permits the user to examine all defined
14722 methods within C@t{++} program, or (with the @var{regexp} argument) a
14723 specific set of methods found in the various C@t{++} classes. Many
14724 C@t{++} classes provide a large number of methods. Thus, the output
14725 from the @code{ptype} command can be overwhelming and hard to use. The
14726 @code{info-methods} command filters the methods, printing only those
14727 which match the regular-expression @var{regexp}.
14728 @end ignore
14729
14730 @cindex opaque data types
14731 @kindex set opaque-type-resolution
14732 @item set opaque-type-resolution on
14733 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
14734 declared as a pointer to a @code{struct}, @code{class}, or
14735 @code{union}---for example, @code{struct MyType *}---that is used in one
14736 source file although the full declaration of @code{struct MyType} is in
14737 another source file. The default is on.
14738
14739 A change in the setting of this subcommand will not take effect until
14740 the next time symbols for a file are loaded.
14741
14742 @item set opaque-type-resolution off
14743 Tell @value{GDBN} not to resolve opaque types. In this case, the type
14744 is printed as follows:
14745 @smallexample
14746 @{<no data fields>@}
14747 @end smallexample
14748
14749 @kindex show opaque-type-resolution
14750 @item show opaque-type-resolution
14751 Show whether opaque types are resolved or not.
14752
14753 @kindex maint print symbols
14754 @cindex symbol dump
14755 @kindex maint print psymbols
14756 @cindex partial symbol dump
14757 @item maint print symbols @var{filename}
14758 @itemx maint print psymbols @var{filename}
14759 @itemx maint print msymbols @var{filename}
14760 Write a dump of debugging symbol data into the file @var{filename}.
14761 These commands are used to debug the @value{GDBN} symbol-reading code. Only
14762 symbols with debugging data are included. If you use @samp{maint print
14763 symbols}, @value{GDBN} includes all the symbols for which it has already
14764 collected full details: that is, @var{filename} reflects symbols for
14765 only those files whose symbols @value{GDBN} has read. You can use the
14766 command @code{info sources} to find out which files these are. If you
14767 use @samp{maint print psymbols} instead, the dump shows information about
14768 symbols that @value{GDBN} only knows partially---that is, symbols defined in
14769 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
14770 @samp{maint print msymbols} dumps just the minimal symbol information
14771 required for each object file from which @value{GDBN} has read some symbols.
14772 @xref{Files, ,Commands to Specify Files}, for a discussion of how
14773 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
14774
14775 @kindex maint info symtabs
14776 @kindex maint info psymtabs
14777 @cindex listing @value{GDBN}'s internal symbol tables
14778 @cindex symbol tables, listing @value{GDBN}'s internal
14779 @cindex full symbol tables, listing @value{GDBN}'s internal
14780 @cindex partial symbol tables, listing @value{GDBN}'s internal
14781 @item maint info symtabs @r{[} @var{regexp} @r{]}
14782 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
14783
14784 List the @code{struct symtab} or @code{struct partial_symtab}
14785 structures whose names match @var{regexp}. If @var{regexp} is not
14786 given, list them all. The output includes expressions which you can
14787 copy into a @value{GDBN} debugging this one to examine a particular
14788 structure in more detail. For example:
14789
14790 @smallexample
14791 (@value{GDBP}) maint info psymtabs dwarf2read
14792 @{ objfile /home/gnu/build/gdb/gdb
14793 ((struct objfile *) 0x82e69d0)
14794 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
14795 ((struct partial_symtab *) 0x8474b10)
14796 readin no
14797 fullname (null)
14798 text addresses 0x814d3c8 -- 0x8158074
14799 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
14800 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
14801 dependencies (none)
14802 @}
14803 @}
14804 (@value{GDBP}) maint info symtabs
14805 (@value{GDBP})
14806 @end smallexample
14807 @noindent
14808 We see that there is one partial symbol table whose filename contains
14809 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
14810 and we see that @value{GDBN} has not read in any symtabs yet at all.
14811 If we set a breakpoint on a function, that will cause @value{GDBN} to
14812 read the symtab for the compilation unit containing that function:
14813
14814 @smallexample
14815 (@value{GDBP}) break dwarf2_psymtab_to_symtab
14816 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
14817 line 1574.
14818 (@value{GDBP}) maint info symtabs
14819 @{ objfile /home/gnu/build/gdb/gdb
14820 ((struct objfile *) 0x82e69d0)
14821 @{ symtab /home/gnu/src/gdb/dwarf2read.c
14822 ((struct symtab *) 0x86c1f38)
14823 dirname (null)
14824 fullname (null)
14825 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
14826 linetable ((struct linetable *) 0x8370fa0)
14827 debugformat DWARF 2
14828 @}
14829 @}
14830 (@value{GDBP})
14831 @end smallexample
14832 @end table
14833
14834
14835 @node Altering
14836 @chapter Altering Execution
14837
14838 Once you think you have found an error in your program, you might want to
14839 find out for certain whether correcting the apparent error would lead to
14840 correct results in the rest of the run. You can find the answer by
14841 experiment, using the @value{GDBN} features for altering execution of the
14842 program.
14843
14844 For example, you can store new values into variables or memory
14845 locations, give your program a signal, restart it at a different
14846 address, or even return prematurely from a function.
14847
14848 @menu
14849 * Assignment:: Assignment to variables
14850 * Jumping:: Continuing at a different address
14851 * Signaling:: Giving your program a signal
14852 * Returning:: Returning from a function
14853 * Calling:: Calling your program's functions
14854 * Patching:: Patching your program
14855 @end menu
14856
14857 @node Assignment
14858 @section Assignment to Variables
14859
14860 @cindex assignment
14861 @cindex setting variables
14862 To alter the value of a variable, evaluate an assignment expression.
14863 @xref{Expressions, ,Expressions}. For example,
14864
14865 @smallexample
14866 print x=4
14867 @end smallexample
14868
14869 @noindent
14870 stores the value 4 into the variable @code{x}, and then prints the
14871 value of the assignment expression (which is 4).
14872 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
14873 information on operators in supported languages.
14874
14875 @kindex set variable
14876 @cindex variables, setting
14877 If you are not interested in seeing the value of the assignment, use the
14878 @code{set} command instead of the @code{print} command. @code{set} is
14879 really the same as @code{print} except that the expression's value is
14880 not printed and is not put in the value history (@pxref{Value History,
14881 ,Value History}). The expression is evaluated only for its effects.
14882
14883 If the beginning of the argument string of the @code{set} command
14884 appears identical to a @code{set} subcommand, use the @code{set
14885 variable} command instead of just @code{set}. This command is identical
14886 to @code{set} except for its lack of subcommands. For example, if your
14887 program has a variable @code{width}, you get an error if you try to set
14888 a new value with just @samp{set width=13}, because @value{GDBN} has the
14889 command @code{set width}:
14890
14891 @smallexample
14892 (@value{GDBP}) whatis width
14893 type = double
14894 (@value{GDBP}) p width
14895 $4 = 13
14896 (@value{GDBP}) set width=47
14897 Invalid syntax in expression.
14898 @end smallexample
14899
14900 @noindent
14901 The invalid expression, of course, is @samp{=47}. In
14902 order to actually set the program's variable @code{width}, use
14903
14904 @smallexample
14905 (@value{GDBP}) set var width=47
14906 @end smallexample
14907
14908 Because the @code{set} command has many subcommands that can conflict
14909 with the names of program variables, it is a good idea to use the
14910 @code{set variable} command instead of just @code{set}. For example, if
14911 your program has a variable @code{g}, you run into problems if you try
14912 to set a new value with just @samp{set g=4}, because @value{GDBN} has
14913 the command @code{set gnutarget}, abbreviated @code{set g}:
14914
14915 @smallexample
14916 @group
14917 (@value{GDBP}) whatis g
14918 type = double
14919 (@value{GDBP}) p g
14920 $1 = 1
14921 (@value{GDBP}) set g=4
14922 (@value{GDBP}) p g
14923 $2 = 1
14924 (@value{GDBP}) r
14925 The program being debugged has been started already.
14926 Start it from the beginning? (y or n) y
14927 Starting program: /home/smith/cc_progs/a.out
14928 "/home/smith/cc_progs/a.out": can't open to read symbols:
14929 Invalid bfd target.
14930 (@value{GDBP}) show g
14931 The current BFD target is "=4".
14932 @end group
14933 @end smallexample
14934
14935 @noindent
14936 The program variable @code{g} did not change, and you silently set the
14937 @code{gnutarget} to an invalid value. In order to set the variable
14938 @code{g}, use
14939
14940 @smallexample
14941 (@value{GDBP}) set var g=4
14942 @end smallexample
14943
14944 @value{GDBN} allows more implicit conversions in assignments than C; you can
14945 freely store an integer value into a pointer variable or vice versa,
14946 and you can convert any structure to any other structure that is the
14947 same length or shorter.
14948 @comment FIXME: how do structs align/pad in these conversions?
14949 @comment /doc@cygnus.com 18dec1990
14950
14951 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
14952 construct to generate a value of specified type at a specified address
14953 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
14954 to memory location @code{0x83040} as an integer (which implies a certain size
14955 and representation in memory), and
14956
14957 @smallexample
14958 set @{int@}0x83040 = 4
14959 @end smallexample
14960
14961 @noindent
14962 stores the value 4 into that memory location.
14963
14964 @node Jumping
14965 @section Continuing at a Different Address
14966
14967 Ordinarily, when you continue your program, you do so at the place where
14968 it stopped, with the @code{continue} command. You can instead continue at
14969 an address of your own choosing, with the following commands:
14970
14971 @table @code
14972 @kindex jump
14973 @item jump @var{linespec}
14974 @itemx jump @var{location}
14975 Resume execution at line @var{linespec} or at address given by
14976 @var{location}. Execution stops again immediately if there is a
14977 breakpoint there. @xref{Specify Location}, for a description of the
14978 different forms of @var{linespec} and @var{location}. It is common
14979 practice to use the @code{tbreak} command in conjunction with
14980 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
14981
14982 The @code{jump} command does not change the current stack frame, or
14983 the stack pointer, or the contents of any memory location or any
14984 register other than the program counter. If line @var{linespec} is in
14985 a different function from the one currently executing, the results may
14986 be bizarre if the two functions expect different patterns of arguments or
14987 of local variables. For this reason, the @code{jump} command requests
14988 confirmation if the specified line is not in the function currently
14989 executing. However, even bizarre results are predictable if you are
14990 well acquainted with the machine-language code of your program.
14991 @end table
14992
14993 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
14994 On many systems, you can get much the same effect as the @code{jump}
14995 command by storing a new value into the register @code{$pc}. The
14996 difference is that this does not start your program running; it only
14997 changes the address of where it @emph{will} run when you continue. For
14998 example,
14999
15000 @smallexample
15001 set $pc = 0x485
15002 @end smallexample
15003
15004 @noindent
15005 makes the next @code{continue} command or stepping command execute at
15006 address @code{0x485}, rather than at the address where your program stopped.
15007 @xref{Continuing and Stepping, ,Continuing and Stepping}.
15008
15009 The most common occasion to use the @code{jump} command is to back
15010 up---perhaps with more breakpoints set---over a portion of a program
15011 that has already executed, in order to examine its execution in more
15012 detail.
15013
15014 @c @group
15015 @node Signaling
15016 @section Giving your Program a Signal
15017 @cindex deliver a signal to a program
15018
15019 @table @code
15020 @kindex signal
15021 @item signal @var{signal}
15022 Resume execution where your program stopped, but immediately give it the
15023 signal @var{signal}. @var{signal} can be the name or the number of a
15024 signal. For example, on many systems @code{signal 2} and @code{signal
15025 SIGINT} are both ways of sending an interrupt signal.
15026
15027 Alternatively, if @var{signal} is zero, continue execution without
15028 giving a signal. This is useful when your program stopped on account of
15029 a signal and would ordinary see the signal when resumed with the
15030 @code{continue} command; @samp{signal 0} causes it to resume without a
15031 signal.
15032
15033 @code{signal} does not repeat when you press @key{RET} a second time
15034 after executing the command.
15035 @end table
15036 @c @end group
15037
15038 Invoking the @code{signal} command is not the same as invoking the
15039 @code{kill} utility from the shell. Sending a signal with @code{kill}
15040 causes @value{GDBN} to decide what to do with the signal depending on
15041 the signal handling tables (@pxref{Signals}). The @code{signal} command
15042 passes the signal directly to your program.
15043
15044
15045 @node Returning
15046 @section Returning from a Function
15047
15048 @table @code
15049 @cindex returning from a function
15050 @kindex return
15051 @item return
15052 @itemx return @var{expression}
15053 You can cancel execution of a function call with the @code{return}
15054 command. If you give an
15055 @var{expression} argument, its value is used as the function's return
15056 value.
15057 @end table
15058
15059 When you use @code{return}, @value{GDBN} discards the selected stack frame
15060 (and all frames within it). You can think of this as making the
15061 discarded frame return prematurely. If you wish to specify a value to
15062 be returned, give that value as the argument to @code{return}.
15063
15064 This pops the selected stack frame (@pxref{Selection, ,Selecting a
15065 Frame}), and any other frames inside of it, leaving its caller as the
15066 innermost remaining frame. That frame becomes selected. The
15067 specified value is stored in the registers used for returning values
15068 of functions.
15069
15070 The @code{return} command does not resume execution; it leaves the
15071 program stopped in the state that would exist if the function had just
15072 returned. In contrast, the @code{finish} command (@pxref{Continuing
15073 and Stepping, ,Continuing and Stepping}) resumes execution until the
15074 selected stack frame returns naturally.
15075
15076 @value{GDBN} needs to know how the @var{expression} argument should be set for
15077 the inferior. The concrete registers assignment depends on the OS ABI and the
15078 type being returned by the selected stack frame. For example it is common for
15079 OS ABI to return floating point values in FPU registers while integer values in
15080 CPU registers. Still some ABIs return even floating point values in CPU
15081 registers. Larger integer widths (such as @code{long long int}) also have
15082 specific placement rules. @value{GDBN} already knows the OS ABI from its
15083 current target so it needs to find out also the type being returned to make the
15084 assignment into the right register(s).
15085
15086 Normally, the selected stack frame has debug info. @value{GDBN} will always
15087 use the debug info instead of the implicit type of @var{expression} when the
15088 debug info is available. For example, if you type @kbd{return -1}, and the
15089 function in the current stack frame is declared to return a @code{long long
15090 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
15091 into a @code{long long int}:
15092
15093 @smallexample
15094 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
15095 29 return 31;
15096 (@value{GDBP}) return -1
15097 Make func return now? (y or n) y
15098 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
15099 43 printf ("result=%lld\n", func ());
15100 (@value{GDBP})
15101 @end smallexample
15102
15103 However, if the selected stack frame does not have a debug info, e.g., if the
15104 function was compiled without debug info, @value{GDBN} has to find out the type
15105 to return from user. Specifying a different type by mistake may set the value
15106 in different inferior registers than the caller code expects. For example,
15107 typing @kbd{return -1} with its implicit type @code{int} would set only a part
15108 of a @code{long long int} result for a debug info less function (on 32-bit
15109 architectures). Therefore the user is required to specify the return type by
15110 an appropriate cast explicitly:
15111
15112 @smallexample
15113 Breakpoint 2, 0x0040050b in func ()
15114 (@value{GDBP}) return -1
15115 Return value type not available for selected stack frame.
15116 Please use an explicit cast of the value to return.
15117 (@value{GDBP}) return (long long int) -1
15118 Make selected stack frame return now? (y or n) y
15119 #0 0x00400526 in main ()
15120 (@value{GDBP})
15121 @end smallexample
15122
15123 @node Calling
15124 @section Calling Program Functions
15125
15126 @table @code
15127 @cindex calling functions
15128 @cindex inferior functions, calling
15129 @item print @var{expr}
15130 Evaluate the expression @var{expr} and display the resulting value.
15131 @var{expr} may include calls to functions in the program being
15132 debugged.
15133
15134 @kindex call
15135 @item call @var{expr}
15136 Evaluate the expression @var{expr} without displaying @code{void}
15137 returned values.
15138
15139 You can use this variant of the @code{print} command if you want to
15140 execute a function from your program that does not return anything
15141 (a.k.a.@: @dfn{a void function}), but without cluttering the output
15142 with @code{void} returned values that @value{GDBN} will otherwise
15143 print. If the result is not void, it is printed and saved in the
15144 value history.
15145 @end table
15146
15147 It is possible for the function you call via the @code{print} or
15148 @code{call} command to generate a signal (e.g., if there's a bug in
15149 the function, or if you passed it incorrect arguments). What happens
15150 in that case is controlled by the @code{set unwindonsignal} command.
15151
15152 Similarly, with a C@t{++} program it is possible for the function you
15153 call via the @code{print} or @code{call} command to generate an
15154 exception that is not handled due to the constraints of the dummy
15155 frame. In this case, any exception that is raised in the frame, but has
15156 an out-of-frame exception handler will not be found. GDB builds a
15157 dummy-frame for the inferior function call, and the unwinder cannot
15158 seek for exception handlers outside of this dummy-frame. What happens
15159 in that case is controlled by the
15160 @code{set unwind-on-terminating-exception} command.
15161
15162 @table @code
15163 @item set unwindonsignal
15164 @kindex set unwindonsignal
15165 @cindex unwind stack in called functions
15166 @cindex call dummy stack unwinding
15167 Set unwinding of the stack if a signal is received while in a function
15168 that @value{GDBN} called in the program being debugged. If set to on,
15169 @value{GDBN} unwinds the stack it created for the call and restores
15170 the context to what it was before the call. If set to off (the
15171 default), @value{GDBN} stops in the frame where the signal was
15172 received.
15173
15174 @item show unwindonsignal
15175 @kindex show unwindonsignal
15176 Show the current setting of stack unwinding in the functions called by
15177 @value{GDBN}.
15178
15179 @item set unwind-on-terminating-exception
15180 @kindex set unwind-on-terminating-exception
15181 @cindex unwind stack in called functions with unhandled exceptions
15182 @cindex call dummy stack unwinding on unhandled exception.
15183 Set unwinding of the stack if a C@t{++} exception is raised, but left
15184 unhandled while in a function that @value{GDBN} called in the program being
15185 debugged. If set to on (the default), @value{GDBN} unwinds the stack
15186 it created for the call and restores the context to what it was before
15187 the call. If set to off, @value{GDBN} the exception is delivered to
15188 the default C@t{++} exception handler and the inferior terminated.
15189
15190 @item show unwind-on-terminating-exception
15191 @kindex show unwind-on-terminating-exception
15192 Show the current setting of stack unwinding in the functions called by
15193 @value{GDBN}.
15194
15195 @end table
15196
15197 @cindex weak alias functions
15198 Sometimes, a function you wish to call is actually a @dfn{weak alias}
15199 for another function. In such case, @value{GDBN} might not pick up
15200 the type information, including the types of the function arguments,
15201 which causes @value{GDBN} to call the inferior function incorrectly.
15202 As a result, the called function will function erroneously and may
15203 even crash. A solution to that is to use the name of the aliased
15204 function instead.
15205
15206 @node Patching
15207 @section Patching Programs
15208
15209 @cindex patching binaries
15210 @cindex writing into executables
15211 @cindex writing into corefiles
15212
15213 By default, @value{GDBN} opens the file containing your program's
15214 executable code (or the corefile) read-only. This prevents accidental
15215 alterations to machine code; but it also prevents you from intentionally
15216 patching your program's binary.
15217
15218 If you'd like to be able to patch the binary, you can specify that
15219 explicitly with the @code{set write} command. For example, you might
15220 want to turn on internal debugging flags, or even to make emergency
15221 repairs.
15222
15223 @table @code
15224 @kindex set write
15225 @item set write on
15226 @itemx set write off
15227 If you specify @samp{set write on}, @value{GDBN} opens executable and
15228 core files for both reading and writing; if you specify @kbd{set write
15229 off} (the default), @value{GDBN} opens them read-only.
15230
15231 If you have already loaded a file, you must load it again (using the
15232 @code{exec-file} or @code{core-file} command) after changing @code{set
15233 write}, for your new setting to take effect.
15234
15235 @item show write
15236 @kindex show write
15237 Display whether executable files and core files are opened for writing
15238 as well as reading.
15239 @end table
15240
15241 @node GDB Files
15242 @chapter @value{GDBN} Files
15243
15244 @value{GDBN} needs to know the file name of the program to be debugged,
15245 both in order to read its symbol table and in order to start your
15246 program. To debug a core dump of a previous run, you must also tell
15247 @value{GDBN} the name of the core dump file.
15248
15249 @menu
15250 * Files:: Commands to specify files
15251 * Separate Debug Files:: Debugging information in separate files
15252 * Index Files:: Index files speed up GDB
15253 * Symbol Errors:: Errors reading symbol files
15254 * Data Files:: GDB data files
15255 @end menu
15256
15257 @node Files
15258 @section Commands to Specify Files
15259
15260 @cindex symbol table
15261 @cindex core dump file
15262
15263 You may want to specify executable and core dump file names. The usual
15264 way to do this is at start-up time, using the arguments to
15265 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
15266 Out of @value{GDBN}}).
15267
15268 Occasionally it is necessary to change to a different file during a
15269 @value{GDBN} session. Or you may run @value{GDBN} and forget to
15270 specify a file you want to use. Or you are debugging a remote target
15271 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
15272 Program}). In these situations the @value{GDBN} commands to specify
15273 new files are useful.
15274
15275 @table @code
15276 @cindex executable file
15277 @kindex file
15278 @item file @var{filename}
15279 Use @var{filename} as the program to be debugged. It is read for its
15280 symbols and for the contents of pure memory. It is also the program
15281 executed when you use the @code{run} command. If you do not specify a
15282 directory and the file is not found in the @value{GDBN} working directory,
15283 @value{GDBN} uses the environment variable @code{PATH} as a list of
15284 directories to search, just as the shell does when looking for a program
15285 to run. You can change the value of this variable, for both @value{GDBN}
15286 and your program, using the @code{path} command.
15287
15288 @cindex unlinked object files
15289 @cindex patching object files
15290 You can load unlinked object @file{.o} files into @value{GDBN} using
15291 the @code{file} command. You will not be able to ``run'' an object
15292 file, but you can disassemble functions and inspect variables. Also,
15293 if the underlying BFD functionality supports it, you could use
15294 @kbd{gdb -write} to patch object files using this technique. Note
15295 that @value{GDBN} can neither interpret nor modify relocations in this
15296 case, so branches and some initialized variables will appear to go to
15297 the wrong place. But this feature is still handy from time to time.
15298
15299 @item file
15300 @code{file} with no argument makes @value{GDBN} discard any information it
15301 has on both executable file and the symbol table.
15302
15303 @kindex exec-file
15304 @item exec-file @r{[} @var{filename} @r{]}
15305 Specify that the program to be run (but not the symbol table) is found
15306 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
15307 if necessary to locate your program. Omitting @var{filename} means to
15308 discard information on the executable file.
15309
15310 @kindex symbol-file
15311 @item symbol-file @r{[} @var{filename} @r{]}
15312 Read symbol table information from file @var{filename}. @code{PATH} is
15313 searched when necessary. Use the @code{file} command to get both symbol
15314 table and program to run from the same file.
15315
15316 @code{symbol-file} with no argument clears out @value{GDBN} information on your
15317 program's symbol table.
15318
15319 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
15320 some breakpoints and auto-display expressions. This is because they may
15321 contain pointers to the internal data recording symbols and data types,
15322 which are part of the old symbol table data being discarded inside
15323 @value{GDBN}.
15324
15325 @code{symbol-file} does not repeat if you press @key{RET} again after
15326 executing it once.
15327
15328 When @value{GDBN} is configured for a particular environment, it
15329 understands debugging information in whatever format is the standard
15330 generated for that environment; you may use either a @sc{gnu} compiler, or
15331 other compilers that adhere to the local conventions.
15332 Best results are usually obtained from @sc{gnu} compilers; for example,
15333 using @code{@value{NGCC}} you can generate debugging information for
15334 optimized code.
15335
15336 For most kinds of object files, with the exception of old SVR3 systems
15337 using COFF, the @code{symbol-file} command does not normally read the
15338 symbol table in full right away. Instead, it scans the symbol table
15339 quickly to find which source files and which symbols are present. The
15340 details are read later, one source file at a time, as they are needed.
15341
15342 The purpose of this two-stage reading strategy is to make @value{GDBN}
15343 start up faster. For the most part, it is invisible except for
15344 occasional pauses while the symbol table details for a particular source
15345 file are being read. (The @code{set verbose} command can turn these
15346 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
15347 Warnings and Messages}.)
15348
15349 We have not implemented the two-stage strategy for COFF yet. When the
15350 symbol table is stored in COFF format, @code{symbol-file} reads the
15351 symbol table data in full right away. Note that ``stabs-in-COFF''
15352 still does the two-stage strategy, since the debug info is actually
15353 in stabs format.
15354
15355 @kindex readnow
15356 @cindex reading symbols immediately
15357 @cindex symbols, reading immediately
15358 @item symbol-file @r{[} -readnow @r{]} @var{filename}
15359 @itemx file @r{[} -readnow @r{]} @var{filename}
15360 You can override the @value{GDBN} two-stage strategy for reading symbol
15361 tables by using the @samp{-readnow} option with any of the commands that
15362 load symbol table information, if you want to be sure @value{GDBN} has the
15363 entire symbol table available.
15364
15365 @c FIXME: for now no mention of directories, since this seems to be in
15366 @c flux. 13mar1992 status is that in theory GDB would look either in
15367 @c current dir or in same dir as myprog; but issues like competing
15368 @c GDB's, or clutter in system dirs, mean that in practice right now
15369 @c only current dir is used. FFish says maybe a special GDB hierarchy
15370 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
15371 @c files.
15372
15373 @kindex core-file
15374 @item core-file @r{[}@var{filename}@r{]}
15375 @itemx core
15376 Specify the whereabouts of a core dump file to be used as the ``contents
15377 of memory''. Traditionally, core files contain only some parts of the
15378 address space of the process that generated them; @value{GDBN} can access the
15379 executable file itself for other parts.
15380
15381 @code{core-file} with no argument specifies that no core file is
15382 to be used.
15383
15384 Note that the core file is ignored when your program is actually running
15385 under @value{GDBN}. So, if you have been running your program and you
15386 wish to debug a core file instead, you must kill the subprocess in which
15387 the program is running. To do this, use the @code{kill} command
15388 (@pxref{Kill Process, ,Killing the Child Process}).
15389
15390 @kindex add-symbol-file
15391 @cindex dynamic linking
15392 @item add-symbol-file @var{filename} @var{address}
15393 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
15394 @itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
15395 The @code{add-symbol-file} command reads additional symbol table
15396 information from the file @var{filename}. You would use this command
15397 when @var{filename} has been dynamically loaded (by some other means)
15398 into the program that is running. @var{address} should be the memory
15399 address at which the file has been loaded; @value{GDBN} cannot figure
15400 this out for itself. You can additionally specify an arbitrary number
15401 of @samp{-s @var{section} @var{address}} pairs, to give an explicit
15402 section name and base address for that section. You can specify any
15403 @var{address} as an expression.
15404
15405 The symbol table of the file @var{filename} is added to the symbol table
15406 originally read with the @code{symbol-file} command. You can use the
15407 @code{add-symbol-file} command any number of times; the new symbol data
15408 thus read keeps adding to the old. To discard all old symbol data
15409 instead, use the @code{symbol-file} command without any arguments.
15410
15411 @cindex relocatable object files, reading symbols from
15412 @cindex object files, relocatable, reading symbols from
15413 @cindex reading symbols from relocatable object files
15414 @cindex symbols, reading from relocatable object files
15415 @cindex @file{.o} files, reading symbols from
15416 Although @var{filename} is typically a shared library file, an
15417 executable file, or some other object file which has been fully
15418 relocated for loading into a process, you can also load symbolic
15419 information from relocatable @file{.o} files, as long as:
15420
15421 @itemize @bullet
15422 @item
15423 the file's symbolic information refers only to linker symbols defined in
15424 that file, not to symbols defined by other object files,
15425 @item
15426 every section the file's symbolic information refers to has actually
15427 been loaded into the inferior, as it appears in the file, and
15428 @item
15429 you can determine the address at which every section was loaded, and
15430 provide these to the @code{add-symbol-file} command.
15431 @end itemize
15432
15433 @noindent
15434 Some embedded operating systems, like Sun Chorus and VxWorks, can load
15435 relocatable files into an already running program; such systems
15436 typically make the requirements above easy to meet. However, it's
15437 important to recognize that many native systems use complex link
15438 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
15439 assembly, for example) that make the requirements difficult to meet. In
15440 general, one cannot assume that using @code{add-symbol-file} to read a
15441 relocatable object file's symbolic information will have the same effect
15442 as linking the relocatable object file into the program in the normal
15443 way.
15444
15445 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
15446
15447 @kindex add-symbol-file-from-memory
15448 @cindex @code{syscall DSO}
15449 @cindex load symbols from memory
15450 @item add-symbol-file-from-memory @var{address}
15451 Load symbols from the given @var{address} in a dynamically loaded
15452 object file whose image is mapped directly into the inferior's memory.
15453 For example, the Linux kernel maps a @code{syscall DSO} into each
15454 process's address space; this DSO provides kernel-specific code for
15455 some system calls. The argument can be any expression whose
15456 evaluation yields the address of the file's shared object file header.
15457 For this command to work, you must have used @code{symbol-file} or
15458 @code{exec-file} commands in advance.
15459
15460 @kindex add-shared-symbol-files
15461 @kindex assf
15462 @item add-shared-symbol-files @var{library-file}
15463 @itemx assf @var{library-file}
15464 The @code{add-shared-symbol-files} command can currently be used only
15465 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
15466 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
15467 @value{GDBN} automatically looks for shared libraries, however if
15468 @value{GDBN} does not find yours, you can invoke
15469 @code{add-shared-symbol-files}. It takes one argument: the shared
15470 library's file name. @code{assf} is a shorthand alias for
15471 @code{add-shared-symbol-files}.
15472
15473 @kindex section
15474 @item section @var{section} @var{addr}
15475 The @code{section} command changes the base address of the named
15476 @var{section} of the exec file to @var{addr}. This can be used if the
15477 exec file does not contain section addresses, (such as in the
15478 @code{a.out} format), or when the addresses specified in the file
15479 itself are wrong. Each section must be changed separately. The
15480 @code{info files} command, described below, lists all the sections and
15481 their addresses.
15482
15483 @kindex info files
15484 @kindex info target
15485 @item info files
15486 @itemx info target
15487 @code{info files} and @code{info target} are synonymous; both print the
15488 current target (@pxref{Targets, ,Specifying a Debugging Target}),
15489 including the names of the executable and core dump files currently in
15490 use by @value{GDBN}, and the files from which symbols were loaded. The
15491 command @code{help target} lists all possible targets rather than
15492 current ones.
15493
15494 @kindex maint info sections
15495 @item maint info sections
15496 Another command that can give you extra information about program sections
15497 is @code{maint info sections}. In addition to the section information
15498 displayed by @code{info files}, this command displays the flags and file
15499 offset of each section in the executable and core dump files. In addition,
15500 @code{maint info sections} provides the following command options (which
15501 may be arbitrarily combined):
15502
15503 @table @code
15504 @item ALLOBJ
15505 Display sections for all loaded object files, including shared libraries.
15506 @item @var{sections}
15507 Display info only for named @var{sections}.
15508 @item @var{section-flags}
15509 Display info only for sections for which @var{section-flags} are true.
15510 The section flags that @value{GDBN} currently knows about are:
15511 @table @code
15512 @item ALLOC
15513 Section will have space allocated in the process when loaded.
15514 Set for all sections except those containing debug information.
15515 @item LOAD
15516 Section will be loaded from the file into the child process memory.
15517 Set for pre-initialized code and data, clear for @code{.bss} sections.
15518 @item RELOC
15519 Section needs to be relocated before loading.
15520 @item READONLY
15521 Section cannot be modified by the child process.
15522 @item CODE
15523 Section contains executable code only.
15524 @item DATA
15525 Section contains data only (no executable code).
15526 @item ROM
15527 Section will reside in ROM.
15528 @item CONSTRUCTOR
15529 Section contains data for constructor/destructor lists.
15530 @item HAS_CONTENTS
15531 Section is not empty.
15532 @item NEVER_LOAD
15533 An instruction to the linker to not output the section.
15534 @item COFF_SHARED_LIBRARY
15535 A notification to the linker that the section contains
15536 COFF shared library information.
15537 @item IS_COMMON
15538 Section contains common symbols.
15539 @end table
15540 @end table
15541 @kindex set trust-readonly-sections
15542 @cindex read-only sections
15543 @item set trust-readonly-sections on
15544 Tell @value{GDBN} that readonly sections in your object file
15545 really are read-only (i.e.@: that their contents will not change).
15546 In that case, @value{GDBN} can fetch values from these sections
15547 out of the object file, rather than from the target program.
15548 For some targets (notably embedded ones), this can be a significant
15549 enhancement to debugging performance.
15550
15551 The default is off.
15552
15553 @item set trust-readonly-sections off
15554 Tell @value{GDBN} not to trust readonly sections. This means that
15555 the contents of the section might change while the program is running,
15556 and must therefore be fetched from the target when needed.
15557
15558 @item show trust-readonly-sections
15559 Show the current setting of trusting readonly sections.
15560 @end table
15561
15562 All file-specifying commands allow both absolute and relative file names
15563 as arguments. @value{GDBN} always converts the file name to an absolute file
15564 name and remembers it that way.
15565
15566 @cindex shared libraries
15567 @anchor{Shared Libraries}
15568 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
15569 and IBM RS/6000 AIX shared libraries.
15570
15571 On MS-Windows @value{GDBN} must be linked with the Expat library to support
15572 shared libraries. @xref{Expat}.
15573
15574 @value{GDBN} automatically loads symbol definitions from shared libraries
15575 when you use the @code{run} command, or when you examine a core file.
15576 (Before you issue the @code{run} command, @value{GDBN} does not understand
15577 references to a function in a shared library, however---unless you are
15578 debugging a core file).
15579
15580 On HP-UX, if the program loads a library explicitly, @value{GDBN}
15581 automatically loads the symbols at the time of the @code{shl_load} call.
15582
15583 @c FIXME: some @value{GDBN} release may permit some refs to undef
15584 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
15585 @c FIXME...lib; check this from time to time when updating manual
15586
15587 There are times, however, when you may wish to not automatically load
15588 symbol definitions from shared libraries, such as when they are
15589 particularly large or there are many of them.
15590
15591 To control the automatic loading of shared library symbols, use the
15592 commands:
15593
15594 @table @code
15595 @kindex set auto-solib-add
15596 @item set auto-solib-add @var{mode}
15597 If @var{mode} is @code{on}, symbols from all shared object libraries
15598 will be loaded automatically when the inferior begins execution, you
15599 attach to an independently started inferior, or when the dynamic linker
15600 informs @value{GDBN} that a new library has been loaded. If @var{mode}
15601 is @code{off}, symbols must be loaded manually, using the
15602 @code{sharedlibrary} command. The default value is @code{on}.
15603
15604 @cindex memory used for symbol tables
15605 If your program uses lots of shared libraries with debug info that
15606 takes large amounts of memory, you can decrease the @value{GDBN}
15607 memory footprint by preventing it from automatically loading the
15608 symbols from shared libraries. To that end, type @kbd{set
15609 auto-solib-add off} before running the inferior, then load each
15610 library whose debug symbols you do need with @kbd{sharedlibrary
15611 @var{regexp}}, where @var{regexp} is a regular expression that matches
15612 the libraries whose symbols you want to be loaded.
15613
15614 @kindex show auto-solib-add
15615 @item show auto-solib-add
15616 Display the current autoloading mode.
15617 @end table
15618
15619 @cindex load shared library
15620 To explicitly load shared library symbols, use the @code{sharedlibrary}
15621 command:
15622
15623 @table @code
15624 @kindex info sharedlibrary
15625 @kindex info share
15626 @item info share @var{regex}
15627 @itemx info sharedlibrary @var{regex}
15628 Print the names of the shared libraries which are currently loaded
15629 that match @var{regex}. If @var{regex} is omitted then print
15630 all shared libraries that are loaded.
15631
15632 @kindex sharedlibrary
15633 @kindex share
15634 @item sharedlibrary @var{regex}
15635 @itemx share @var{regex}
15636 Load shared object library symbols for files matching a
15637 Unix regular expression.
15638 As with files loaded automatically, it only loads shared libraries
15639 required by your program for a core file or after typing @code{run}. If
15640 @var{regex} is omitted all shared libraries required by your program are
15641 loaded.
15642
15643 @item nosharedlibrary
15644 @kindex nosharedlibrary
15645 @cindex unload symbols from shared libraries
15646 Unload all shared object library symbols. This discards all symbols
15647 that have been loaded from all shared libraries. Symbols from shared
15648 libraries that were loaded by explicit user requests are not
15649 discarded.
15650 @end table
15651
15652 Sometimes you may wish that @value{GDBN} stops and gives you control
15653 when any of shared library events happen. The best way to do this is
15654 to use @code{catch load} and @code{catch unload} (@pxref{Set
15655 Catchpoints}).
15656
15657 @value{GDBN} also supports the the @code{set stop-on-solib-events}
15658 command for this. This command exists for historical reasons. It is
15659 less useful than setting a catchpoint, because it does not allow for
15660 conditions or commands as a catchpoint does.
15661
15662 @table @code
15663 @item set stop-on-solib-events
15664 @kindex set stop-on-solib-events
15665 This command controls whether @value{GDBN} should give you control
15666 when the dynamic linker notifies it about some shared library event.
15667 The most common event of interest is loading or unloading of a new
15668 shared library.
15669
15670 @item show stop-on-solib-events
15671 @kindex show stop-on-solib-events
15672 Show whether @value{GDBN} stops and gives you control when shared
15673 library events happen.
15674 @end table
15675
15676 Shared libraries are also supported in many cross or remote debugging
15677 configurations. @value{GDBN} needs to have access to the target's libraries;
15678 this can be accomplished either by providing copies of the libraries
15679 on the host system, or by asking @value{GDBN} to automatically retrieve the
15680 libraries from the target. If copies of the target libraries are
15681 provided, they need to be the same as the target libraries, although the
15682 copies on the target can be stripped as long as the copies on the host are
15683 not.
15684
15685 @cindex where to look for shared libraries
15686 For remote debugging, you need to tell @value{GDBN} where the target
15687 libraries are, so that it can load the correct copies---otherwise, it
15688 may try to load the host's libraries. @value{GDBN} has two variables
15689 to specify the search directories for target libraries.
15690
15691 @table @code
15692 @cindex prefix for shared library file names
15693 @cindex system root, alternate
15694 @kindex set solib-absolute-prefix
15695 @kindex set sysroot
15696 @item set sysroot @var{path}
15697 Use @var{path} as the system root for the program being debugged. Any
15698 absolute shared library paths will be prefixed with @var{path}; many
15699 runtime loaders store the absolute paths to the shared library in the
15700 target program's memory. If you use @code{set sysroot} to find shared
15701 libraries, they need to be laid out in the same way that they are on
15702 the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
15703 under @var{path}.
15704
15705 If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
15706 retrieve the target libraries from the remote system. This is only
15707 supported when using a remote target that supports the @code{remote get}
15708 command (@pxref{File Transfer,,Sending files to a remote system}).
15709 The part of @var{path} following the initial @file{remote:}
15710 (if present) is used as system root prefix on the remote file system.
15711 @footnote{If you want to specify a local system root using a directory
15712 that happens to be named @file{remote:}, you need to use some equivalent
15713 variant of the name like @file{./remote:}.}
15714
15715 For targets with an MS-DOS based filesystem, such as MS-Windows and
15716 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
15717 absolute file name with @var{path}. But first, on Unix hosts,
15718 @value{GDBN} converts all backslash directory separators into forward
15719 slashes, because the backslash is not a directory separator on Unix:
15720
15721 @smallexample
15722 c:\foo\bar.dll @result{} c:/foo/bar.dll
15723 @end smallexample
15724
15725 Then, @value{GDBN} attempts prefixing the target file name with
15726 @var{path}, and looks for the resulting file name in the host file
15727 system:
15728
15729 @smallexample
15730 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
15731 @end smallexample
15732
15733 If that does not find the shared library, @value{GDBN} tries removing
15734 the @samp{:} character from the drive spec, both for convenience, and,
15735 for the case of the host file system not supporting file names with
15736 colons:
15737
15738 @smallexample
15739 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
15740 @end smallexample
15741
15742 This makes it possible to have a system root that mirrors a target
15743 with more than one drive. E.g., you may want to setup your local
15744 copies of the target system shared libraries like so (note @samp{c} vs
15745 @samp{z}):
15746
15747 @smallexample
15748 @file{/path/to/sysroot/c/sys/bin/foo.dll}
15749 @file{/path/to/sysroot/c/sys/bin/bar.dll}
15750 @file{/path/to/sysroot/z/sys/bin/bar.dll}
15751 @end smallexample
15752
15753 @noindent
15754 and point the system root at @file{/path/to/sysroot}, so that
15755 @value{GDBN} can find the correct copies of both
15756 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
15757
15758 If that still does not find the shared library, @value{GDBN} tries
15759 removing the whole drive spec from the target file name:
15760
15761 @smallexample
15762 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
15763 @end smallexample
15764
15765 This last lookup makes it possible to not care about the drive name,
15766 if you don't want or need to.
15767
15768 The @code{set solib-absolute-prefix} command is an alias for @code{set
15769 sysroot}.
15770
15771 @cindex default system root
15772 @cindex @samp{--with-sysroot}
15773 You can set the default system root by using the configure-time
15774 @samp{--with-sysroot} option. If the system root is inside
15775 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
15776 @samp{--exec-prefix}), then the default system root will be updated
15777 automatically if the installed @value{GDBN} is moved to a new
15778 location.
15779
15780 @kindex show sysroot
15781 @item show sysroot
15782 Display the current shared library prefix.
15783
15784 @kindex set solib-search-path
15785 @item set solib-search-path @var{path}
15786 If this variable is set, @var{path} is a colon-separated list of
15787 directories to search for shared libraries. @samp{solib-search-path}
15788 is used after @samp{sysroot} fails to locate the library, or if the
15789 path to the library is relative instead of absolute. If you want to
15790 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
15791 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
15792 finding your host's libraries. @samp{sysroot} is preferred; setting
15793 it to a nonexistent directory may interfere with automatic loading
15794 of shared library symbols.
15795
15796 @kindex show solib-search-path
15797 @item show solib-search-path
15798 Display the current shared library search path.
15799
15800 @cindex DOS file-name semantics of file names.
15801 @kindex set target-file-system-kind (unix|dos-based|auto)
15802 @kindex show target-file-system-kind
15803 @item set target-file-system-kind @var{kind}
15804 Set assumed file system kind for target reported file names.
15805
15806 Shared library file names as reported by the target system may not
15807 make sense as is on the system @value{GDBN} is running on. For
15808 example, when remote debugging a target that has MS-DOS based file
15809 system semantics, from a Unix host, the target may be reporting to
15810 @value{GDBN} a list of loaded shared libraries with file names such as
15811 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
15812 drive letters, so the @samp{c:\} prefix is not normally understood as
15813 indicating an absolute file name, and neither is the backslash
15814 normally considered a directory separator character. In that case,
15815 the native file system would interpret this whole absolute file name
15816 as a relative file name with no directory components. This would make
15817 it impossible to point @value{GDBN} at a copy of the remote target's
15818 shared libraries on the host using @code{set sysroot}, and impractical
15819 with @code{set solib-search-path}. Setting
15820 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
15821 to interpret such file names similarly to how the target would, and to
15822 map them to file names valid on @value{GDBN}'s native file system
15823 semantics. The value of @var{kind} can be @code{"auto"}, in addition
15824 to one of the supported file system kinds. In that case, @value{GDBN}
15825 tries to determine the appropriate file system variant based on the
15826 current target's operating system (@pxref{ABI, ,Configuring the
15827 Current ABI}). The supported file system settings are:
15828
15829 @table @code
15830 @item unix
15831 Instruct @value{GDBN} to assume the target file system is of Unix
15832 kind. Only file names starting the forward slash (@samp{/}) character
15833 are considered absolute, and the directory separator character is also
15834 the forward slash.
15835
15836 @item dos-based
15837 Instruct @value{GDBN} to assume the target file system is DOS based.
15838 File names starting with either a forward slash, or a drive letter
15839 followed by a colon (e.g., @samp{c:}), are considered absolute, and
15840 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
15841 considered directory separators.
15842
15843 @item auto
15844 Instruct @value{GDBN} to use the file system kind associated with the
15845 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
15846 This is the default.
15847 @end table
15848 @end table
15849
15850 @cindex file name canonicalization
15851 @cindex base name differences
15852 When processing file names provided by the user, @value{GDBN}
15853 frequently needs to compare them to the file names recorded in the
15854 program's debug info. Normally, @value{GDBN} compares just the
15855 @dfn{base names} of the files as strings, which is reasonably fast
15856 even for very large programs. (The base name of a file is the last
15857 portion of its name, after stripping all the leading directories.)
15858 This shortcut in comparison is based upon the assumption that files
15859 cannot have more than one base name. This is usually true, but
15860 references to files that use symlinks or similar filesystem
15861 facilities violate that assumption. If your program records files
15862 using such facilities, or if you provide file names to @value{GDBN}
15863 using symlinks etc., you can set @code{basenames-may-differ} to
15864 @code{true} to instruct @value{GDBN} to completely canonicalize each
15865 pair of file names it needs to compare. This will make file-name
15866 comparisons accurate, but at a price of a significant slowdown.
15867
15868 @table @code
15869 @item set basenames-may-differ
15870 @kindex set basenames-may-differ
15871 Set whether a source file may have multiple base names.
15872
15873 @item show basenames-may-differ
15874 @kindex show basenames-may-differ
15875 Show whether a source file may have multiple base names.
15876 @end table
15877
15878 @node Separate Debug Files
15879 @section Debugging Information in Separate Files
15880 @cindex separate debugging information files
15881 @cindex debugging information in separate files
15882 @cindex @file{.debug} subdirectories
15883 @cindex debugging information directory, global
15884 @cindex global debugging information directory
15885 @cindex build ID, and separate debugging files
15886 @cindex @file{.build-id} directory
15887
15888 @value{GDBN} allows you to put a program's debugging information in a
15889 file separate from the executable itself, in a way that allows
15890 @value{GDBN} to find and load the debugging information automatically.
15891 Since debugging information can be very large---sometimes larger
15892 than the executable code itself---some systems distribute debugging
15893 information for their executables in separate files, which users can
15894 install only when they need to debug a problem.
15895
15896 @value{GDBN} supports two ways of specifying the separate debug info
15897 file:
15898
15899 @itemize @bullet
15900 @item
15901 The executable contains a @dfn{debug link} that specifies the name of
15902 the separate debug info file. The separate debug file's name is
15903 usually @file{@var{executable}.debug}, where @var{executable} is the
15904 name of the corresponding executable file without leading directories
15905 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
15906 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
15907 checksum for the debug file, which @value{GDBN} uses to validate that
15908 the executable and the debug file came from the same build.
15909
15910 @item
15911 The executable contains a @dfn{build ID}, a unique bit string that is
15912 also present in the corresponding debug info file. (This is supported
15913 only on some operating systems, notably those which use the ELF format
15914 for binary files and the @sc{gnu} Binutils.) For more details about
15915 this feature, see the description of the @option{--build-id}
15916 command-line option in @ref{Options, , Command Line Options, ld.info,
15917 The GNU Linker}. The debug info file's name is not specified
15918 explicitly by the build ID, but can be computed from the build ID, see
15919 below.
15920 @end itemize
15921
15922 Depending on the way the debug info file is specified, @value{GDBN}
15923 uses two different methods of looking for the debug file:
15924
15925 @itemize @bullet
15926 @item
15927 For the ``debug link'' method, @value{GDBN} looks up the named file in
15928 the directory of the executable file, then in a subdirectory of that
15929 directory named @file{.debug}, and finally under the global debug
15930 directory, in a subdirectory whose name is identical to the leading
15931 directories of the executable's absolute file name.
15932
15933 @item
15934 For the ``build ID'' method, @value{GDBN} looks in the
15935 @file{.build-id} subdirectory of the global debug directory for a file
15936 named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
15937 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
15938 are the rest of the bit string. (Real build ID strings are 32 or more
15939 hex characters, not 10.)
15940 @end itemize
15941
15942 So, for example, suppose you ask @value{GDBN} to debug
15943 @file{/usr/bin/ls}, which has a debug link that specifies the
15944 file @file{ls.debug}, and a build ID whose value in hex is
15945 @code{abcdef1234}. If the global debug directory is
15946 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
15947 debug information files, in the indicated order:
15948
15949 @itemize @minus
15950 @item
15951 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
15952 @item
15953 @file{/usr/bin/ls.debug}
15954 @item
15955 @file{/usr/bin/.debug/ls.debug}
15956 @item
15957 @file{/usr/lib/debug/usr/bin/ls.debug}.
15958 @end itemize
15959
15960 You can set the global debugging info directory's name, and view the
15961 name @value{GDBN} is currently using.
15962
15963 @table @code
15964
15965 @kindex set debug-file-directory
15966 @item set debug-file-directory @var{directories}
15967 Set the directories which @value{GDBN} searches for separate debugging
15968 information files to @var{directory}. Multiple directory components can be set
15969 concatenating them by a directory separator.
15970
15971 @kindex show debug-file-directory
15972 @item show debug-file-directory
15973 Show the directories @value{GDBN} searches for separate debugging
15974 information files.
15975
15976 @end table
15977
15978 @cindex @code{.gnu_debuglink} sections
15979 @cindex debug link sections
15980 A debug link is a special section of the executable file named
15981 @code{.gnu_debuglink}. The section must contain:
15982
15983 @itemize
15984 @item
15985 A filename, with any leading directory components removed, followed by
15986 a zero byte,
15987 @item
15988 zero to three bytes of padding, as needed to reach the next four-byte
15989 boundary within the section, and
15990 @item
15991 a four-byte CRC checksum, stored in the same endianness used for the
15992 executable file itself. The checksum is computed on the debugging
15993 information file's full contents by the function given below, passing
15994 zero as the @var{crc} argument.
15995 @end itemize
15996
15997 Any executable file format can carry a debug link, as long as it can
15998 contain a section named @code{.gnu_debuglink} with the contents
15999 described above.
16000
16001 @cindex @code{.note.gnu.build-id} sections
16002 @cindex build ID sections
16003 The build ID is a special section in the executable file (and in other
16004 ELF binary files that @value{GDBN} may consider). This section is
16005 often named @code{.note.gnu.build-id}, but that name is not mandatory.
16006 It contains unique identification for the built files---the ID remains
16007 the same across multiple builds of the same build tree. The default
16008 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
16009 content for the build ID string. The same section with an identical
16010 value is present in the original built binary with symbols, in its
16011 stripped variant, and in the separate debugging information file.
16012
16013 The debugging information file itself should be an ordinary
16014 executable, containing a full set of linker symbols, sections, and
16015 debugging information. The sections of the debugging information file
16016 should have the same names, addresses, and sizes as the original file,
16017 but they need not contain any data---much like a @code{.bss} section
16018 in an ordinary executable.
16019
16020 The @sc{gnu} binary utilities (Binutils) package includes the
16021 @samp{objcopy} utility that can produce
16022 the separated executable / debugging information file pairs using the
16023 following commands:
16024
16025 @smallexample
16026 @kbd{objcopy --only-keep-debug foo foo.debug}
16027 @kbd{strip -g foo}
16028 @end smallexample
16029
16030 @noindent
16031 These commands remove the debugging
16032 information from the executable file @file{foo} and place it in the file
16033 @file{foo.debug}. You can use the first, second or both methods to link the
16034 two files:
16035
16036 @itemize @bullet
16037 @item
16038 The debug link method needs the following additional command to also leave
16039 behind a debug link in @file{foo}:
16040
16041 @smallexample
16042 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
16043 @end smallexample
16044
16045 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
16046 a version of the @code{strip} command such that the command @kbd{strip foo -f
16047 foo.debug} has the same functionality as the two @code{objcopy} commands and
16048 the @code{ln -s} command above, together.
16049
16050 @item
16051 Build ID gets embedded into the main executable using @code{ld --build-id} or
16052 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
16053 compatibility fixes for debug files separation are present in @sc{gnu} binary
16054 utilities (Binutils) package since version 2.18.
16055 @end itemize
16056
16057 @noindent
16058
16059 @cindex CRC algorithm definition
16060 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
16061 IEEE 802.3 using the polynomial:
16062
16063 @c TexInfo requires naked braces for multi-digit exponents for Tex
16064 @c output, but this causes HTML output to barf. HTML has to be set using
16065 @c raw commands. So we end up having to specify this equation in 2
16066 @c different ways!
16067 @ifhtml
16068 @display
16069 @html
16070 <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>
16071 + <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
16072 @end html
16073 @end display
16074 @end ifhtml
16075 @ifnothtml
16076 @display
16077 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
16078 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
16079 @end display
16080 @end ifnothtml
16081
16082 The function is computed byte at a time, taking the least
16083 significant bit of each byte first. The initial pattern
16084 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
16085 the final result is inverted to ensure trailing zeros also affect the
16086 CRC.
16087
16088 @emph{Note:} This is the same CRC polynomial as used in handling the
16089 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
16090 , @value{GDBN} Remote Serial Protocol}). However in the
16091 case of the Remote Serial Protocol, the CRC is computed @emph{most}
16092 significant bit first, and the result is not inverted, so trailing
16093 zeros have no effect on the CRC value.
16094
16095 To complete the description, we show below the code of the function
16096 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
16097 initially supplied @code{crc} argument means that an initial call to
16098 this function passing in zero will start computing the CRC using
16099 @code{0xffffffff}.
16100
16101 @kindex gnu_debuglink_crc32
16102 @smallexample
16103 unsigned long
16104 gnu_debuglink_crc32 (unsigned long crc,
16105 unsigned char *buf, size_t len)
16106 @{
16107 static const unsigned long crc32_table[256] =
16108 @{
16109 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
16110 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
16111 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
16112 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
16113 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
16114 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
16115 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
16116 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
16117 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
16118 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
16119 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
16120 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
16121 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
16122 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
16123 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
16124 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
16125 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
16126 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
16127 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
16128 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
16129 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
16130 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
16131 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
16132 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
16133 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
16134 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
16135 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
16136 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
16137 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
16138 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
16139 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
16140 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
16141 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
16142 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
16143 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
16144 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
16145 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
16146 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
16147 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
16148 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
16149 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
16150 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
16151 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
16152 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
16153 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
16154 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
16155 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
16156 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
16157 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
16158 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
16159 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
16160 0x2d02ef8d
16161 @};
16162 unsigned char *end;
16163
16164 crc = ~crc & 0xffffffff;
16165 for (end = buf + len; buf < end; ++buf)
16166 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
16167 return ~crc & 0xffffffff;
16168 @}
16169 @end smallexample
16170
16171 @noindent
16172 This computation does not apply to the ``build ID'' method.
16173
16174
16175 @node Index Files
16176 @section Index Files Speed Up @value{GDBN}
16177 @cindex index files
16178 @cindex @samp{.gdb_index} section
16179
16180 When @value{GDBN} finds a symbol file, it scans the symbols in the
16181 file in order to construct an internal symbol table. This lets most
16182 @value{GDBN} operations work quickly---at the cost of a delay early
16183 on. For large programs, this delay can be quite lengthy, so
16184 @value{GDBN} provides a way to build an index, which speeds up
16185 startup.
16186
16187 The index is stored as a section in the symbol file. @value{GDBN} can
16188 write the index to a file, then you can put it into the symbol file
16189 using @command{objcopy}.
16190
16191 To create an index file, use the @code{save gdb-index} command:
16192
16193 @table @code
16194 @item save gdb-index @var{directory}
16195 @kindex save gdb-index
16196 Create an index file for each symbol file currently known by
16197 @value{GDBN}. Each file is named after its corresponding symbol file,
16198 with @samp{.gdb-index} appended, and is written into the given
16199 @var{directory}.
16200 @end table
16201
16202 Once you have created an index file you can merge it into your symbol
16203 file, here named @file{symfile}, using @command{objcopy}:
16204
16205 @smallexample
16206 $ objcopy --add-section .gdb_index=symfile.gdb-index \
16207 --set-section-flags .gdb_index=readonly symfile symfile
16208 @end smallexample
16209
16210 There are currently some limitation on indices. They only work when
16211 for DWARF debugging information, not stabs. And, they do not
16212 currently work for programs using Ada.
16213
16214 @node Symbol Errors
16215 @section Errors Reading Symbol Files
16216
16217 While reading a symbol file, @value{GDBN} occasionally encounters problems,
16218 such as symbol types it does not recognize, or known bugs in compiler
16219 output. By default, @value{GDBN} does not notify you of such problems, since
16220 they are relatively common and primarily of interest to people
16221 debugging compilers. If you are interested in seeing information
16222 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
16223 only one message about each such type of problem, no matter how many
16224 times the problem occurs; or you can ask @value{GDBN} to print more messages,
16225 to see how many times the problems occur, with the @code{set
16226 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
16227 Messages}).
16228
16229 The messages currently printed, and their meanings, include:
16230
16231 @table @code
16232 @item inner block not inside outer block in @var{symbol}
16233
16234 The symbol information shows where symbol scopes begin and end
16235 (such as at the start of a function or a block of statements). This
16236 error indicates that an inner scope block is not fully contained
16237 in its outer scope blocks.
16238
16239 @value{GDBN} circumvents the problem by treating the inner block as if it had
16240 the same scope as the outer block. In the error message, @var{symbol}
16241 may be shown as ``@code{(don't know)}'' if the outer block is not a
16242 function.
16243
16244 @item block at @var{address} out of order
16245
16246 The symbol information for symbol scope blocks should occur in
16247 order of increasing addresses. This error indicates that it does not
16248 do so.
16249
16250 @value{GDBN} does not circumvent this problem, and has trouble
16251 locating symbols in the source file whose symbols it is reading. (You
16252 can often determine what source file is affected by specifying
16253 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
16254 Messages}.)
16255
16256 @item bad block start address patched
16257
16258 The symbol information for a symbol scope block has a start address
16259 smaller than the address of the preceding source line. This is known
16260 to occur in the SunOS 4.1.1 (and earlier) C compiler.
16261
16262 @value{GDBN} circumvents the problem by treating the symbol scope block as
16263 starting on the previous source line.
16264
16265 @item bad string table offset in symbol @var{n}
16266
16267 @cindex foo
16268 Symbol number @var{n} contains a pointer into the string table which is
16269 larger than the size of the string table.
16270
16271 @value{GDBN} circumvents the problem by considering the symbol to have the
16272 name @code{foo}, which may cause other problems if many symbols end up
16273 with this name.
16274
16275 @item unknown symbol type @code{0x@var{nn}}
16276
16277 The symbol information contains new data types that @value{GDBN} does
16278 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
16279 uncomprehended information, in hexadecimal.
16280
16281 @value{GDBN} circumvents the error by ignoring this symbol information.
16282 This usually allows you to debug your program, though certain symbols
16283 are not accessible. If you encounter such a problem and feel like
16284 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
16285 on @code{complain}, then go up to the function @code{read_dbx_symtab}
16286 and examine @code{*bufp} to see the symbol.
16287
16288 @item stub type has NULL name
16289
16290 @value{GDBN} could not find the full definition for a struct or class.
16291
16292 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
16293 The symbol information for a C@t{++} member function is missing some
16294 information that recent versions of the compiler should have output for
16295 it.
16296
16297 @item info mismatch between compiler and debugger
16298
16299 @value{GDBN} could not parse a type specification output by the compiler.
16300
16301 @end table
16302
16303 @node Data Files
16304 @section GDB Data Files
16305
16306 @cindex prefix for data files
16307 @value{GDBN} will sometimes read an auxiliary data file. These files
16308 are kept in a directory known as the @dfn{data directory}.
16309
16310 You can set the data directory's name, and view the name @value{GDBN}
16311 is currently using.
16312
16313 @table @code
16314 @kindex set data-directory
16315 @item set data-directory @var{directory}
16316 Set the directory which @value{GDBN} searches for auxiliary data files
16317 to @var{directory}.
16318
16319 @kindex show data-directory
16320 @item show data-directory
16321 Show the directory @value{GDBN} searches for auxiliary data files.
16322 @end table
16323
16324 @cindex default data directory
16325 @cindex @samp{--with-gdb-datadir}
16326 You can set the default data directory by using the configure-time
16327 @samp{--with-gdb-datadir} option. If the data directory is inside
16328 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
16329 @samp{--exec-prefix}), then the default data directory will be updated
16330 automatically if the installed @value{GDBN} is moved to a new
16331 location.
16332
16333 The data directory may also be specified with the
16334 @code{--data-directory} command line option.
16335 @xref{Mode Options}.
16336
16337 @node Targets
16338 @chapter Specifying a Debugging Target
16339
16340 @cindex debugging target
16341 A @dfn{target} is the execution environment occupied by your program.
16342
16343 Often, @value{GDBN} runs in the same host environment as your program;
16344 in that case, the debugging target is specified as a side effect when
16345 you use the @code{file} or @code{core} commands. When you need more
16346 flexibility---for example, running @value{GDBN} on a physically separate
16347 host, or controlling a standalone system over a serial port or a
16348 realtime system over a TCP/IP connection---you can use the @code{target}
16349 command to specify one of the target types configured for @value{GDBN}
16350 (@pxref{Target Commands, ,Commands for Managing Targets}).
16351
16352 @cindex target architecture
16353 It is possible to build @value{GDBN} for several different @dfn{target
16354 architectures}. When @value{GDBN} is built like that, you can choose
16355 one of the available architectures with the @kbd{set architecture}
16356 command.
16357
16358 @table @code
16359 @kindex set architecture
16360 @kindex show architecture
16361 @item set architecture @var{arch}
16362 This command sets the current target architecture to @var{arch}. The
16363 value of @var{arch} can be @code{"auto"}, in addition to one of the
16364 supported architectures.
16365
16366 @item show architecture
16367 Show the current target architecture.
16368
16369 @item set processor
16370 @itemx processor
16371 @kindex set processor
16372 @kindex show processor
16373 These are alias commands for, respectively, @code{set architecture}
16374 and @code{show architecture}.
16375 @end table
16376
16377 @menu
16378 * Active Targets:: Active targets
16379 * Target Commands:: Commands for managing targets
16380 * Byte Order:: Choosing target byte order
16381 @end menu
16382
16383 @node Active Targets
16384 @section Active Targets
16385
16386 @cindex stacking targets
16387 @cindex active targets
16388 @cindex multiple targets
16389
16390 There are multiple classes of targets such as: processes, executable files or
16391 recording sessions. Core files belong to the process class, making core file
16392 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
16393 on multiple active targets, one in each class. This allows you to (for
16394 example) start a process and inspect its activity, while still having access to
16395 the executable file after the process finishes. Or if you start process
16396 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
16397 presented a virtual layer of the recording target, while the process target
16398 remains stopped at the chronologically last point of the process execution.
16399
16400 Use the @code{core-file} and @code{exec-file} commands to select a new core
16401 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
16402 specify as a target a process that is already running, use the @code{attach}
16403 command (@pxref{Attach, ,Debugging an Already-running Process}).
16404
16405 @node Target Commands
16406 @section Commands for Managing Targets
16407
16408 @table @code
16409 @item target @var{type} @var{parameters}
16410 Connects the @value{GDBN} host environment to a target machine or
16411 process. A target is typically a protocol for talking to debugging
16412 facilities. You use the argument @var{type} to specify the type or
16413 protocol of the target machine.
16414
16415 Further @var{parameters} are interpreted by the target protocol, but
16416 typically include things like device names or host names to connect
16417 with, process numbers, and baud rates.
16418
16419 The @code{target} command does not repeat if you press @key{RET} again
16420 after executing the command.
16421
16422 @kindex help target
16423 @item help target
16424 Displays the names of all targets available. To display targets
16425 currently selected, use either @code{info target} or @code{info files}
16426 (@pxref{Files, ,Commands to Specify Files}).
16427
16428 @item help target @var{name}
16429 Describe a particular target, including any parameters necessary to
16430 select it.
16431
16432 @kindex set gnutarget
16433 @item set gnutarget @var{args}
16434 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
16435 knows whether it is reading an @dfn{executable},
16436 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
16437 with the @code{set gnutarget} command. Unlike most @code{target} commands,
16438 with @code{gnutarget} the @code{target} refers to a program, not a machine.
16439
16440 @quotation
16441 @emph{Warning:} To specify a file format with @code{set gnutarget},
16442 you must know the actual BFD name.
16443 @end quotation
16444
16445 @noindent
16446 @xref{Files, , Commands to Specify Files}.
16447
16448 @kindex show gnutarget
16449 @item show gnutarget
16450 Use the @code{show gnutarget} command to display what file format
16451 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
16452 @value{GDBN} will determine the file format for each file automatically,
16453 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
16454 @end table
16455
16456 @cindex common targets
16457 Here are some common targets (available, or not, depending on the GDB
16458 configuration):
16459
16460 @table @code
16461 @kindex target
16462 @item target exec @var{program}
16463 @cindex executable file target
16464 An executable file. @samp{target exec @var{program}} is the same as
16465 @samp{exec-file @var{program}}.
16466
16467 @item target core @var{filename}
16468 @cindex core dump file target
16469 A core dump file. @samp{target core @var{filename}} is the same as
16470 @samp{core-file @var{filename}}.
16471
16472 @item target remote @var{medium}
16473 @cindex remote target
16474 A remote system connected to @value{GDBN} via a serial line or network
16475 connection. This command tells @value{GDBN} to use its own remote
16476 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
16477
16478 For example, if you have a board connected to @file{/dev/ttya} on the
16479 machine running @value{GDBN}, you could say:
16480
16481 @smallexample
16482 target remote /dev/ttya
16483 @end smallexample
16484
16485 @code{target remote} supports the @code{load} command. This is only
16486 useful if you have some other way of getting the stub to the target
16487 system, and you can put it somewhere in memory where it won't get
16488 clobbered by the download.
16489
16490 @item target sim @r{[}@var{simargs}@r{]} @dots{}
16491 @cindex built-in simulator target
16492 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
16493 In general,
16494 @smallexample
16495 target sim
16496 load
16497 run
16498 @end smallexample
16499 @noindent
16500 works; however, you cannot assume that a specific memory map, device
16501 drivers, or even basic I/O is available, although some simulators do
16502 provide these. For info about any processor-specific simulator details,
16503 see the appropriate section in @ref{Embedded Processors, ,Embedded
16504 Processors}.
16505
16506 @end table
16507
16508 Some configurations may include these targets as well:
16509
16510 @table @code
16511
16512 @item target nrom @var{dev}
16513 @cindex NetROM ROM emulator target
16514 NetROM ROM emulator. This target only supports downloading.
16515
16516 @end table
16517
16518 Different targets are available on different configurations of @value{GDBN};
16519 your configuration may have more or fewer targets.
16520
16521 Many remote targets require you to download the executable's code once
16522 you've successfully established a connection. You may wish to control
16523 various aspects of this process.
16524
16525 @table @code
16526
16527 @item set hash
16528 @kindex set hash@r{, for remote monitors}
16529 @cindex hash mark while downloading
16530 This command controls whether a hash mark @samp{#} is displayed while
16531 downloading a file to the remote monitor. If on, a hash mark is
16532 displayed after each S-record is successfully downloaded to the
16533 monitor.
16534
16535 @item show hash
16536 @kindex show hash@r{, for remote monitors}
16537 Show the current status of displaying the hash mark.
16538
16539 @item set debug monitor
16540 @kindex set debug monitor
16541 @cindex display remote monitor communications
16542 Enable or disable display of communications messages between
16543 @value{GDBN} and the remote monitor.
16544
16545 @item show debug monitor
16546 @kindex show debug monitor
16547 Show the current status of displaying communications between
16548 @value{GDBN} and the remote monitor.
16549 @end table
16550
16551 @table @code
16552
16553 @kindex load @var{filename}
16554 @item load @var{filename}
16555 @anchor{load}
16556 Depending on what remote debugging facilities are configured into
16557 @value{GDBN}, the @code{load} command may be available. Where it exists, it
16558 is meant to make @var{filename} (an executable) available for debugging
16559 on the remote system---by downloading, or dynamic linking, for example.
16560 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
16561 the @code{add-symbol-file} command.
16562
16563 If your @value{GDBN} does not have a @code{load} command, attempting to
16564 execute it gets the error message ``@code{You can't do that when your
16565 target is @dots{}}''
16566
16567 The file is loaded at whatever address is specified in the executable.
16568 For some object file formats, you can specify the load address when you
16569 link the program; for other formats, like a.out, the object file format
16570 specifies a fixed address.
16571 @c FIXME! This would be a good place for an xref to the GNU linker doc.
16572
16573 Depending on the remote side capabilities, @value{GDBN} may be able to
16574 load programs into flash memory.
16575
16576 @code{load} does not repeat if you press @key{RET} again after using it.
16577 @end table
16578
16579 @node Byte Order
16580 @section Choosing Target Byte Order
16581
16582 @cindex choosing target byte order
16583 @cindex target byte order
16584
16585 Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
16586 offer the ability to run either big-endian or little-endian byte
16587 orders. Usually the executable or symbol will include a bit to
16588 designate the endian-ness, and you will not need to worry about
16589 which to use. However, you may still find it useful to adjust
16590 @value{GDBN}'s idea of processor endian-ness manually.
16591
16592 @table @code
16593 @kindex set endian
16594 @item set endian big
16595 Instruct @value{GDBN} to assume the target is big-endian.
16596
16597 @item set endian little
16598 Instruct @value{GDBN} to assume the target is little-endian.
16599
16600 @item set endian auto
16601 Instruct @value{GDBN} to use the byte order associated with the
16602 executable.
16603
16604 @item show endian
16605 Display @value{GDBN}'s current idea of the target byte order.
16606
16607 @end table
16608
16609 Note that these commands merely adjust interpretation of symbolic
16610 data on the host, and that they have absolutely no effect on the
16611 target system.
16612
16613
16614 @node Remote Debugging
16615 @chapter Debugging Remote Programs
16616 @cindex remote debugging
16617
16618 If you are trying to debug a program running on a machine that cannot run
16619 @value{GDBN} in the usual way, it is often useful to use remote debugging.
16620 For example, you might use remote debugging on an operating system kernel,
16621 or on a small system which does not have a general purpose operating system
16622 powerful enough to run a full-featured debugger.
16623
16624 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
16625 to make this work with particular debugging targets. In addition,
16626 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
16627 but not specific to any particular target system) which you can use if you
16628 write the remote stubs---the code that runs on the remote system to
16629 communicate with @value{GDBN}.
16630
16631 Other remote targets may be available in your
16632 configuration of @value{GDBN}; use @code{help target} to list them.
16633
16634 @menu
16635 * Connecting:: Connecting to a remote target
16636 * File Transfer:: Sending files to a remote system
16637 * Server:: Using the gdbserver program
16638 * Remote Configuration:: Remote configuration
16639 * Remote Stub:: Implementing a remote stub
16640 @end menu
16641
16642 @node Connecting
16643 @section Connecting to a Remote Target
16644
16645 On the @value{GDBN} host machine, you will need an unstripped copy of
16646 your program, since @value{GDBN} needs symbol and debugging information.
16647 Start up @value{GDBN} as usual, using the name of the local copy of your
16648 program as the first argument.
16649
16650 @cindex @code{target remote}
16651 @value{GDBN} can communicate with the target over a serial line, or
16652 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
16653 each case, @value{GDBN} uses the same protocol for debugging your
16654 program; only the medium carrying the debugging packets varies. The
16655 @code{target remote} command establishes a connection to the target.
16656 Its arguments indicate which medium to use:
16657
16658 @table @code
16659
16660 @item target remote @var{serial-device}
16661 @cindex serial line, @code{target remote}
16662 Use @var{serial-device} to communicate with the target. For example,
16663 to use a serial line connected to the device named @file{/dev/ttyb}:
16664
16665 @smallexample
16666 target remote /dev/ttyb
16667 @end smallexample
16668
16669 If you're using a serial line, you may want to give @value{GDBN} the
16670 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
16671 (@pxref{Remote Configuration, set remotebaud}) before the
16672 @code{target} command.
16673
16674 @item target remote @code{@var{host}:@var{port}}
16675 @itemx target remote @code{tcp:@var{host}:@var{port}}
16676 @cindex @acronym{TCP} port, @code{target remote}
16677 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
16678 The @var{host} may be either a host name or a numeric @acronym{IP}
16679 address; @var{port} must be a decimal number. The @var{host} could be
16680 the target machine itself, if it is directly connected to the net, or
16681 it might be a terminal server which in turn has a serial line to the
16682 target.
16683
16684 For example, to connect to port 2828 on a terminal server named
16685 @code{manyfarms}:
16686
16687 @smallexample
16688 target remote manyfarms:2828
16689 @end smallexample
16690
16691 If your remote target is actually running on the same machine as your
16692 debugger session (e.g.@: a simulator for your target running on the
16693 same host), you can omit the hostname. For example, to connect to
16694 port 1234 on your local machine:
16695
16696 @smallexample
16697 target remote :1234
16698 @end smallexample
16699 @noindent
16700
16701 Note that the colon is still required here.
16702
16703 @item target remote @code{udp:@var{host}:@var{port}}
16704 @cindex @acronym{UDP} port, @code{target remote}
16705 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
16706 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
16707
16708 @smallexample
16709 target remote udp:manyfarms:2828
16710 @end smallexample
16711
16712 When using a @acronym{UDP} connection for remote debugging, you should
16713 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
16714 can silently drop packets on busy or unreliable networks, which will
16715 cause havoc with your debugging session.
16716
16717 @item target remote | @var{command}
16718 @cindex pipe, @code{target remote} to
16719 Run @var{command} in the background and communicate with it using a
16720 pipe. The @var{command} is a shell command, to be parsed and expanded
16721 by the system's command shell, @code{/bin/sh}; it should expect remote
16722 protocol packets on its standard input, and send replies on its
16723 standard output. You could use this to run a stand-alone simulator
16724 that speaks the remote debugging protocol, to make net connections
16725 using programs like @code{ssh}, or for other similar tricks.
16726
16727 If @var{command} closes its standard output (perhaps by exiting),
16728 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
16729 program has already exited, this will have no effect.)
16730
16731 @end table
16732
16733 Once the connection has been established, you can use all the usual
16734 commands to examine and change data. The remote program is already
16735 running; you can use @kbd{step} and @kbd{continue}, and you do not
16736 need to use @kbd{run}.
16737
16738 @cindex interrupting remote programs
16739 @cindex remote programs, interrupting
16740 Whenever @value{GDBN} is waiting for the remote program, if you type the
16741 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
16742 program. This may or may not succeed, depending in part on the hardware
16743 and the serial drivers the remote system uses. If you type the
16744 interrupt character once again, @value{GDBN} displays this prompt:
16745
16746 @smallexample
16747 Interrupted while waiting for the program.
16748 Give up (and stop debugging it)? (y or n)
16749 @end smallexample
16750
16751 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
16752 (If you decide you want to try again later, you can use @samp{target
16753 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
16754 goes back to waiting.
16755
16756 @table @code
16757 @kindex detach (remote)
16758 @item detach
16759 When you have finished debugging the remote program, you can use the
16760 @code{detach} command to release it from @value{GDBN} control.
16761 Detaching from the target normally resumes its execution, but the results
16762 will depend on your particular remote stub. After the @code{detach}
16763 command, @value{GDBN} is free to connect to another target.
16764
16765 @kindex disconnect
16766 @item disconnect
16767 The @code{disconnect} command behaves like @code{detach}, except that
16768 the target is generally not resumed. It will wait for @value{GDBN}
16769 (this instance or another one) to connect and continue debugging. After
16770 the @code{disconnect} command, @value{GDBN} is again free to connect to
16771 another target.
16772
16773 @cindex send command to remote monitor
16774 @cindex extend @value{GDBN} for remote targets
16775 @cindex add new commands for external monitor
16776 @kindex monitor
16777 @item monitor @var{cmd}
16778 This command allows you to send arbitrary commands directly to the
16779 remote monitor. Since @value{GDBN} doesn't care about the commands it
16780 sends like this, this command is the way to extend @value{GDBN}---you
16781 can add new commands that only the external monitor will understand
16782 and implement.
16783 @end table
16784
16785 @node File Transfer
16786 @section Sending files to a remote system
16787 @cindex remote target, file transfer
16788 @cindex file transfer
16789 @cindex sending files to remote systems
16790
16791 Some remote targets offer the ability to transfer files over the same
16792 connection used to communicate with @value{GDBN}. This is convenient
16793 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
16794 running @code{gdbserver} over a network interface. For other targets,
16795 e.g.@: embedded devices with only a single serial port, this may be
16796 the only way to upload or download files.
16797
16798 Not all remote targets support these commands.
16799
16800 @table @code
16801 @kindex remote put
16802 @item remote put @var{hostfile} @var{targetfile}
16803 Copy file @var{hostfile} from the host system (the machine running
16804 @value{GDBN}) to @var{targetfile} on the target system.
16805
16806 @kindex remote get
16807 @item remote get @var{targetfile} @var{hostfile}
16808 Copy file @var{targetfile} from the target system to @var{hostfile}
16809 on the host system.
16810
16811 @kindex remote delete
16812 @item remote delete @var{targetfile}
16813 Delete @var{targetfile} from the target system.
16814
16815 @end table
16816
16817 @node Server
16818 @section Using the @code{gdbserver} Program
16819
16820 @kindex gdbserver
16821 @cindex remote connection without stubs
16822 @code{gdbserver} is a control program for Unix-like systems, which
16823 allows you to connect your program with a remote @value{GDBN} via
16824 @code{target remote}---but without linking in the usual debugging stub.
16825
16826 @code{gdbserver} is not a complete replacement for the debugging stubs,
16827 because it requires essentially the same operating-system facilities
16828 that @value{GDBN} itself does. In fact, a system that can run
16829 @code{gdbserver} to connect to a remote @value{GDBN} could also run
16830 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
16831 because it is a much smaller program than @value{GDBN} itself. It is
16832 also easier to port than all of @value{GDBN}, so you may be able to get
16833 started more quickly on a new system by using @code{gdbserver}.
16834 Finally, if you develop code for real-time systems, you may find that
16835 the tradeoffs involved in real-time operation make it more convenient to
16836 do as much development work as possible on another system, for example
16837 by cross-compiling. You can use @code{gdbserver} to make a similar
16838 choice for debugging.
16839
16840 @value{GDBN} and @code{gdbserver} communicate via either a serial line
16841 or a TCP connection, using the standard @value{GDBN} remote serial
16842 protocol.
16843
16844 @quotation
16845 @emph{Warning:} @code{gdbserver} does not have any built-in security.
16846 Do not run @code{gdbserver} connected to any public network; a
16847 @value{GDBN} connection to @code{gdbserver} provides access to the
16848 target system with the same privileges as the user running
16849 @code{gdbserver}.
16850 @end quotation
16851
16852 @subsection Running @code{gdbserver}
16853 @cindex arguments, to @code{gdbserver}
16854 @cindex @code{gdbserver}, command-line arguments
16855
16856 Run @code{gdbserver} on the target system. You need a copy of the
16857 program you want to debug, including any libraries it requires.
16858 @code{gdbserver} does not need your program's symbol table, so you can
16859 strip the program if necessary to save space. @value{GDBN} on the host
16860 system does all the symbol handling.
16861
16862 To use the server, you must tell it how to communicate with @value{GDBN};
16863 the name of your program; and the arguments for your program. The usual
16864 syntax is:
16865
16866 @smallexample
16867 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
16868 @end smallexample
16869
16870 @var{comm} is either a device name (to use a serial line), or a TCP
16871 hostname and portnumber, or @code{-} or @code{stdio} to use
16872 stdin/stdout of @code{gdbserver}.
16873 For example, to debug Emacs with the argument
16874 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
16875 @file{/dev/com1}:
16876
16877 @smallexample
16878 target> gdbserver /dev/com1 emacs foo.txt
16879 @end smallexample
16880
16881 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
16882 with it.
16883
16884 To use a TCP connection instead of a serial line:
16885
16886 @smallexample
16887 target> gdbserver host:2345 emacs foo.txt
16888 @end smallexample
16889
16890 The only difference from the previous example is the first argument,
16891 specifying that you are communicating with the host @value{GDBN} via
16892 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
16893 expect a TCP connection from machine @samp{host} to local TCP port 2345.
16894 (Currently, the @samp{host} part is ignored.) You can choose any number
16895 you want for the port number as long as it does not conflict with any
16896 TCP ports already in use on the target system (for example, @code{23} is
16897 reserved for @code{telnet}).@footnote{If you choose a port number that
16898 conflicts with another service, @code{gdbserver} prints an error message
16899 and exits.} You must use the same port number with the host @value{GDBN}
16900 @code{target remote} command.
16901
16902 The @code{stdio} connection is useful when starting @code{gdbserver}
16903 with ssh:
16904
16905 @smallexample
16906 (gdb) target remote | ssh -T hostname gdbserver - hello
16907 @end smallexample
16908
16909 The @samp{-T} option to ssh is provided because we don't need a remote pty,
16910 and we don't want escape-character handling. Ssh does this by default when
16911 a command is provided, the flag is provided to make it explicit.
16912 You could elide it if you want to.
16913
16914 Programs started with stdio-connected gdbserver have @file{/dev/null} for
16915 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
16916 display through a pipe connected to gdbserver.
16917 Both @code{stdout} and @code{stderr} use the same pipe.
16918
16919 @subsubsection Attaching to a Running Program
16920 @cindex attach to a program, @code{gdbserver}
16921 @cindex @option{--attach}, @code{gdbserver} option
16922
16923 On some targets, @code{gdbserver} can also attach to running programs.
16924 This is accomplished via the @code{--attach} argument. The syntax is:
16925
16926 @smallexample
16927 target> gdbserver --attach @var{comm} @var{pid}
16928 @end smallexample
16929
16930 @var{pid} is the process ID of a currently running process. It isn't necessary
16931 to point @code{gdbserver} at a binary for the running process.
16932
16933 @pindex pidof
16934 You can debug processes by name instead of process ID if your target has the
16935 @code{pidof} utility:
16936
16937 @smallexample
16938 target> gdbserver --attach @var{comm} `pidof @var{program}`
16939 @end smallexample
16940
16941 In case more than one copy of @var{program} is running, or @var{program}
16942 has multiple threads, most versions of @code{pidof} support the
16943 @code{-s} option to only return the first process ID.
16944
16945 @subsubsection Multi-Process Mode for @code{gdbserver}
16946 @cindex @code{gdbserver}, multiple processes
16947 @cindex multiple processes with @code{gdbserver}
16948
16949 When you connect to @code{gdbserver} using @code{target remote},
16950 @code{gdbserver} debugs the specified program only once. When the
16951 program exits, or you detach from it, @value{GDBN} closes the connection
16952 and @code{gdbserver} exits.
16953
16954 If you connect using @kbd{target extended-remote}, @code{gdbserver}
16955 enters multi-process mode. When the debugged program exits, or you
16956 detach from it, @value{GDBN} stays connected to @code{gdbserver} even
16957 though no program is running. The @code{run} and @code{attach}
16958 commands instruct @code{gdbserver} to run or attach to a new program.
16959 The @code{run} command uses @code{set remote exec-file} (@pxref{set
16960 remote exec-file}) to select the program to run. Command line
16961 arguments are supported, except for wildcard expansion and I/O
16962 redirection (@pxref{Arguments}).
16963
16964 @cindex @option{--multi}, @code{gdbserver} option
16965 To start @code{gdbserver} without supplying an initial command to run
16966 or process ID to attach, use the @option{--multi} command line option.
16967 Then you can connect using @kbd{target extended-remote} and start
16968 the program you want to debug.
16969
16970 In multi-process mode @code{gdbserver} does not automatically exit unless you
16971 use the option @option{--once}. You can terminate it by using
16972 @code{monitor exit} (@pxref{Monitor Commands for gdbserver}). Note that the
16973 conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
16974 connects to it (@kbd{target remote} or @kbd{target extended-remote}). The
16975 @option{--multi} option to @code{gdbserver} has no influence on that.
16976
16977 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
16978
16979 This section applies only when @code{gdbserver} is run to listen on a TCP port.
16980
16981 @code{gdbserver} normally terminates after all of its debugged processes have
16982 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
16983 extended-remote}, @code{gdbserver} stays running even with no processes left.
16984 @value{GDBN} normally terminates the spawned debugged process on its exit,
16985 which normally also terminates @code{gdbserver} in the @kbd{target remote}
16986 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
16987 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
16988 stays running even in the @kbd{target remote} mode.
16989
16990 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
16991 Such reconnecting is useful for features like @ref{disconnected tracing}. For
16992 completeness, at most one @value{GDBN} can be connected at a time.
16993
16994 @cindex @option{--once}, @code{gdbserver} option
16995 By default, @code{gdbserver} keeps the listening TCP port open, so that
16996 additional connections are possible. However, if you start @code{gdbserver}
16997 with the @option{--once} option, it will stop listening for any further
16998 connection attempts after connecting to the first @value{GDBN} session. This
16999 means no further connections to @code{gdbserver} will be possible after the
17000 first one. It also means @code{gdbserver} will terminate after the first
17001 connection with remote @value{GDBN} has closed, even for unexpectedly closed
17002 connections and even in the @kbd{target extended-remote} mode. The
17003 @option{--once} option allows reusing the same port number for connecting to
17004 multiple instances of @code{gdbserver} running on the same host, since each
17005 instance closes its port after the first connection.
17006
17007 @subsubsection Other Command-Line Arguments for @code{gdbserver}
17008
17009 @cindex @option{--debug}, @code{gdbserver} option
17010 The @option{--debug} option tells @code{gdbserver} to display extra
17011 status information about the debugging process.
17012 @cindex @option{--remote-debug}, @code{gdbserver} option
17013 The @option{--remote-debug} option tells @code{gdbserver} to display
17014 remote protocol debug output. These options are intended for
17015 @code{gdbserver} development and for bug reports to the developers.
17016
17017 @cindex @option{--wrapper}, @code{gdbserver} option
17018 The @option{--wrapper} option specifies a wrapper to launch programs
17019 for debugging. The option should be followed by the name of the
17020 wrapper, then any command-line arguments to pass to the wrapper, then
17021 @kbd{--} indicating the end of the wrapper arguments.
17022
17023 @code{gdbserver} runs the specified wrapper program with a combined
17024 command line including the wrapper arguments, then the name of the
17025 program to debug, then any arguments to the program. The wrapper
17026 runs until it executes your program, and then @value{GDBN} gains control.
17027
17028 You can use any program that eventually calls @code{execve} with
17029 its arguments as a wrapper. Several standard Unix utilities do
17030 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
17031 with @code{exec "$@@"} will also work.
17032
17033 For example, you can use @code{env} to pass an environment variable to
17034 the debugged program, without setting the variable in @code{gdbserver}'s
17035 environment:
17036
17037 @smallexample
17038 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
17039 @end smallexample
17040
17041 @subsection Connecting to @code{gdbserver}
17042
17043 Run @value{GDBN} on the host system.
17044
17045 First make sure you have the necessary symbol files. Load symbols for
17046 your application using the @code{file} command before you connect. Use
17047 @code{set sysroot} to locate target libraries (unless your @value{GDBN}
17048 was compiled with the correct sysroot using @code{--with-sysroot}).
17049
17050 The symbol file and target libraries must exactly match the executable
17051 and libraries on the target, with one exception: the files on the host
17052 system should not be stripped, even if the files on the target system
17053 are. Mismatched or missing files will lead to confusing results
17054 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
17055 files may also prevent @code{gdbserver} from debugging multi-threaded
17056 programs.
17057
17058 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
17059 For TCP connections, you must start up @code{gdbserver} prior to using
17060 the @code{target remote} command. Otherwise you may get an error whose
17061 text depends on the host system, but which usually looks something like
17062 @samp{Connection refused}. Don't use the @code{load}
17063 command in @value{GDBN} when using @code{gdbserver}, since the program is
17064 already on the target.
17065
17066 @subsection Monitor Commands for @code{gdbserver}
17067 @cindex monitor commands, for @code{gdbserver}
17068 @anchor{Monitor Commands for gdbserver}
17069
17070 During a @value{GDBN} session using @code{gdbserver}, you can use the
17071 @code{monitor} command to send special requests to @code{gdbserver}.
17072 Here are the available commands.
17073
17074 @table @code
17075 @item monitor help
17076 List the available monitor commands.
17077
17078 @item monitor set debug 0
17079 @itemx monitor set debug 1
17080 Disable or enable general debugging messages.
17081
17082 @item monitor set remote-debug 0
17083 @itemx monitor set remote-debug 1
17084 Disable or enable specific debugging messages associated with the remote
17085 protocol (@pxref{Remote Protocol}).
17086
17087 @item monitor set libthread-db-search-path [PATH]
17088 @cindex gdbserver, search path for @code{libthread_db}
17089 When this command is issued, @var{path} is a colon-separated list of
17090 directories to search for @code{libthread_db} (@pxref{Threads,,set
17091 libthread-db-search-path}). If you omit @var{path},
17092 @samp{libthread-db-search-path} will be reset to its default value.
17093
17094 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
17095 not supported in @code{gdbserver}.
17096
17097 @item monitor exit
17098 Tell gdbserver to exit immediately. This command should be followed by
17099 @code{disconnect} to close the debugging session. @code{gdbserver} will
17100 detach from any attached processes and kill any processes it created.
17101 Use @code{monitor exit} to terminate @code{gdbserver} at the end
17102 of a multi-process mode debug session.
17103
17104 @end table
17105
17106 @subsection Tracepoints support in @code{gdbserver}
17107 @cindex tracepoints support in @code{gdbserver}
17108
17109 On some targets, @code{gdbserver} supports tracepoints, fast
17110 tracepoints and static tracepoints.
17111
17112 For fast or static tracepoints to work, a special library called the
17113 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
17114 This library is built and distributed as an integral part of
17115 @code{gdbserver}. In addition, support for static tracepoints
17116 requires building the in-process agent library with static tracepoints
17117 support. At present, the UST (LTTng Userspace Tracer,
17118 @url{http://lttng.org/ust}) tracing engine is supported. This support
17119 is automatically available if UST development headers are found in the
17120 standard include path when @code{gdbserver} is built, or if
17121 @code{gdbserver} was explicitly configured using @option{--with-ust}
17122 to point at such headers. You can explicitly disable the support
17123 using @option{--with-ust=no}.
17124
17125 There are several ways to load the in-process agent in your program:
17126
17127 @table @code
17128 @item Specifying it as dependency at link time
17129
17130 You can link your program dynamically with the in-process agent
17131 library. On most systems, this is accomplished by adding
17132 @code{-linproctrace} to the link command.
17133
17134 @item Using the system's preloading mechanisms
17135
17136 You can force loading the in-process agent at startup time by using
17137 your system's support for preloading shared libraries. Many Unixes
17138 support the concept of preloading user defined libraries. In most
17139 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
17140 in the environment. See also the description of @code{gdbserver}'s
17141 @option{--wrapper} command line option.
17142
17143 @item Using @value{GDBN} to force loading the agent at run time
17144
17145 On some systems, you can force the inferior to load a shared library,
17146 by calling a dynamic loader function in the inferior that takes care
17147 of dynamically looking up and loading a shared library. On most Unix
17148 systems, the function is @code{dlopen}. You'll use the @code{call}
17149 command for that. For example:
17150
17151 @smallexample
17152 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
17153 @end smallexample
17154
17155 Note that on most Unix systems, for the @code{dlopen} function to be
17156 available, the program needs to be linked with @code{-ldl}.
17157 @end table
17158
17159 On systems that have a userspace dynamic loader, like most Unix
17160 systems, when you connect to @code{gdbserver} using @code{target
17161 remote}, you'll find that the program is stopped at the dynamic
17162 loader's entry point, and no shared library has been loaded in the
17163 program's address space yet, including the in-process agent. In that
17164 case, before being able to use any of the fast or static tracepoints
17165 features, you need to let the loader run and load the shared
17166 libraries. The simplest way to do that is to run the program to the
17167 main procedure. E.g., if debugging a C or C@t{++} program, start
17168 @code{gdbserver} like so:
17169
17170 @smallexample
17171 $ gdbserver :9999 myprogram
17172 @end smallexample
17173
17174 Start GDB and connect to @code{gdbserver} like so, and run to main:
17175
17176 @smallexample
17177 $ gdb myprogram
17178 (@value{GDBP}) target remote myhost:9999
17179 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
17180 (@value{GDBP}) b main
17181 (@value{GDBP}) continue
17182 @end smallexample
17183
17184 The in-process tracing agent library should now be loaded into the
17185 process; you can confirm it with the @code{info sharedlibrary}
17186 command, which will list @file{libinproctrace.so} as loaded in the
17187 process. You are now ready to install fast tracepoints, list static
17188 tracepoint markers, probe static tracepoints markers, and start
17189 tracing.
17190
17191 @node Remote Configuration
17192 @section Remote Configuration
17193
17194 @kindex set remote
17195 @kindex show remote
17196 This section documents the configuration options available when
17197 debugging remote programs. For the options related to the File I/O
17198 extensions of the remote protocol, see @ref{system,
17199 system-call-allowed}.
17200
17201 @table @code
17202 @item set remoteaddresssize @var{bits}
17203 @cindex address size for remote targets
17204 @cindex bits in remote address
17205 Set the maximum size of address in a memory packet to the specified
17206 number of bits. @value{GDBN} will mask off the address bits above
17207 that number, when it passes addresses to the remote target. The
17208 default value is the number of bits in the target's address.
17209
17210 @item show remoteaddresssize
17211 Show the current value of remote address size in bits.
17212
17213 @item set remotebaud @var{n}
17214 @cindex baud rate for remote targets
17215 Set the baud rate for the remote serial I/O to @var{n} baud. The
17216 value is used to set the speed of the serial port used for debugging
17217 remote targets.
17218
17219 @item show remotebaud
17220 Show the current speed of the remote connection.
17221
17222 @item set remotebreak
17223 @cindex interrupt remote programs
17224 @cindex BREAK signal instead of Ctrl-C
17225 @anchor{set remotebreak}
17226 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
17227 when you type @kbd{Ctrl-c} to interrupt the program running
17228 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
17229 character instead. The default is off, since most remote systems
17230 expect to see @samp{Ctrl-C} as the interrupt signal.
17231
17232 @item show remotebreak
17233 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
17234 interrupt the remote program.
17235
17236 @item set remoteflow on
17237 @itemx set remoteflow off
17238 @kindex set remoteflow
17239 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
17240 on the serial port used to communicate to the remote target.
17241
17242 @item show remoteflow
17243 @kindex show remoteflow
17244 Show the current setting of hardware flow control.
17245
17246 @item set remotelogbase @var{base}
17247 Set the base (a.k.a.@: radix) of logging serial protocol
17248 communications to @var{base}. Supported values of @var{base} are:
17249 @code{ascii}, @code{octal}, and @code{hex}. The default is
17250 @code{ascii}.
17251
17252 @item show remotelogbase
17253 Show the current setting of the radix for logging remote serial
17254 protocol.
17255
17256 @item set remotelogfile @var{file}
17257 @cindex record serial communications on file
17258 Record remote serial communications on the named @var{file}. The
17259 default is not to record at all.
17260
17261 @item show remotelogfile.
17262 Show the current setting of the file name on which to record the
17263 serial communications.
17264
17265 @item set remotetimeout @var{num}
17266 @cindex timeout for serial communications
17267 @cindex remote timeout
17268 Set the timeout limit to wait for the remote target to respond to
17269 @var{num} seconds. The default is 2 seconds.
17270
17271 @item show remotetimeout
17272 Show the current number of seconds to wait for the remote target
17273 responses.
17274
17275 @cindex limit hardware breakpoints and watchpoints
17276 @cindex remote target, limit break- and watchpoints
17277 @anchor{set remote hardware-watchpoint-limit}
17278 @anchor{set remote hardware-breakpoint-limit}
17279 @item set remote hardware-watchpoint-limit @var{limit}
17280 @itemx set remote hardware-breakpoint-limit @var{limit}
17281 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
17282 watchpoints. A limit of -1, the default, is treated as unlimited.
17283
17284 @cindex limit hardware watchpoints length
17285 @cindex remote target, limit watchpoints length
17286 @anchor{set remote hardware-watchpoint-length-limit}
17287 @item set remote hardware-watchpoint-length-limit @var{limit}
17288 Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
17289 a remote hardware watchpoint. A limit of -1, the default, is treated
17290 as unlimited.
17291
17292 @item show remote hardware-watchpoint-length-limit
17293 Show the current limit (in bytes) of the maximum length of
17294 a remote hardware watchpoint.
17295
17296 @item set remote exec-file @var{filename}
17297 @itemx show remote exec-file
17298 @anchor{set remote exec-file}
17299 @cindex executable file, for remote target
17300 Select the file used for @code{run} with @code{target
17301 extended-remote}. This should be set to a filename valid on the
17302 target system. If it is not set, the target will use a default
17303 filename (e.g.@: the last program run).
17304
17305 @item set remote interrupt-sequence
17306 @cindex interrupt remote programs
17307 @cindex select Ctrl-C, BREAK or BREAK-g
17308 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
17309 @samp{BREAK-g} as the
17310 sequence to the remote target in order to interrupt the execution.
17311 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
17312 is high level of serial line for some certain time.
17313 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
17314 It is @code{BREAK} signal followed by character @code{g}.
17315
17316 @item show interrupt-sequence
17317 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
17318 is sent by @value{GDBN} to interrupt the remote program.
17319 @code{BREAK-g} is BREAK signal followed by @code{g} and
17320 also known as Magic SysRq g.
17321
17322 @item set remote interrupt-on-connect
17323 @cindex send interrupt-sequence on start
17324 Specify whether interrupt-sequence is sent to remote target when
17325 @value{GDBN} connects to it. This is mostly needed when you debug
17326 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
17327 which is known as Magic SysRq g in order to connect @value{GDBN}.
17328
17329 @item show interrupt-on-connect
17330 Show whether interrupt-sequence is sent
17331 to remote target when @value{GDBN} connects to it.
17332
17333 @kindex set tcp
17334 @kindex show tcp
17335 @item set tcp auto-retry on
17336 @cindex auto-retry, for remote TCP target
17337 Enable auto-retry for remote TCP connections. This is useful if the remote
17338 debugging agent is launched in parallel with @value{GDBN}; there is a race
17339 condition because the agent may not become ready to accept the connection
17340 before @value{GDBN} attempts to connect. When auto-retry is
17341 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
17342 to establish the connection using the timeout specified by
17343 @code{set tcp connect-timeout}.
17344
17345 @item set tcp auto-retry off
17346 Do not auto-retry failed TCP connections.
17347
17348 @item show tcp auto-retry
17349 Show the current auto-retry setting.
17350
17351 @item set tcp connect-timeout @var{seconds}
17352 @cindex connection timeout, for remote TCP target
17353 @cindex timeout, for remote target connection
17354 Set the timeout for establishing a TCP connection to the remote target to
17355 @var{seconds}. The timeout affects both polling to retry failed connections
17356 (enabled by @code{set tcp auto-retry on}) and waiting for connections
17357 that are merely slow to complete, and represents an approximate cumulative
17358 value.
17359
17360 @item show tcp connect-timeout
17361 Show the current connection timeout setting.
17362 @end table
17363
17364 @cindex remote packets, enabling and disabling
17365 The @value{GDBN} remote protocol autodetects the packets supported by
17366 your debugging stub. If you need to override the autodetection, you
17367 can use these commands to enable or disable individual packets. Each
17368 packet can be set to @samp{on} (the remote target supports this
17369 packet), @samp{off} (the remote target does not support this packet),
17370 or @samp{auto} (detect remote target support for this packet). They
17371 all default to @samp{auto}. For more information about each packet,
17372 see @ref{Remote Protocol}.
17373
17374 During normal use, you should not have to use any of these commands.
17375 If you do, that may be a bug in your remote debugging stub, or a bug
17376 in @value{GDBN}. You may want to report the problem to the
17377 @value{GDBN} developers.
17378
17379 For each packet @var{name}, the command to enable or disable the
17380 packet is @code{set remote @var{name}-packet}. The available settings
17381 are:
17382
17383 @multitable @columnfractions 0.28 0.32 0.25
17384 @item Command Name
17385 @tab Remote Packet
17386 @tab Related Features
17387
17388 @item @code{fetch-register}
17389 @tab @code{p}
17390 @tab @code{info registers}
17391
17392 @item @code{set-register}
17393 @tab @code{P}
17394 @tab @code{set}
17395
17396 @item @code{binary-download}
17397 @tab @code{X}
17398 @tab @code{load}, @code{set}
17399
17400 @item @code{read-aux-vector}
17401 @tab @code{qXfer:auxv:read}
17402 @tab @code{info auxv}
17403
17404 @item @code{symbol-lookup}
17405 @tab @code{qSymbol}
17406 @tab Detecting multiple threads
17407
17408 @item @code{attach}
17409 @tab @code{vAttach}
17410 @tab @code{attach}
17411
17412 @item @code{verbose-resume}
17413 @tab @code{vCont}
17414 @tab Stepping or resuming multiple threads
17415
17416 @item @code{run}
17417 @tab @code{vRun}
17418 @tab @code{run}
17419
17420 @item @code{software-breakpoint}
17421 @tab @code{Z0}
17422 @tab @code{break}
17423
17424 @item @code{hardware-breakpoint}
17425 @tab @code{Z1}
17426 @tab @code{hbreak}
17427
17428 @item @code{write-watchpoint}
17429 @tab @code{Z2}
17430 @tab @code{watch}
17431
17432 @item @code{read-watchpoint}
17433 @tab @code{Z3}
17434 @tab @code{rwatch}
17435
17436 @item @code{access-watchpoint}
17437 @tab @code{Z4}
17438 @tab @code{awatch}
17439
17440 @item @code{target-features}
17441 @tab @code{qXfer:features:read}
17442 @tab @code{set architecture}
17443
17444 @item @code{library-info}
17445 @tab @code{qXfer:libraries:read}
17446 @tab @code{info sharedlibrary}
17447
17448 @item @code{memory-map}
17449 @tab @code{qXfer:memory-map:read}
17450 @tab @code{info mem}
17451
17452 @item @code{read-sdata-object}
17453 @tab @code{qXfer:sdata:read}
17454 @tab @code{print $_sdata}
17455
17456 @item @code{read-spu-object}
17457 @tab @code{qXfer:spu:read}
17458 @tab @code{info spu}
17459
17460 @item @code{write-spu-object}
17461 @tab @code{qXfer:spu:write}
17462 @tab @code{info spu}
17463
17464 @item @code{read-siginfo-object}
17465 @tab @code{qXfer:siginfo:read}
17466 @tab @code{print $_siginfo}
17467
17468 @item @code{write-siginfo-object}
17469 @tab @code{qXfer:siginfo:write}
17470 @tab @code{set $_siginfo}
17471
17472 @item @code{threads}
17473 @tab @code{qXfer:threads:read}
17474 @tab @code{info threads}
17475
17476 @item @code{get-thread-local-@*storage-address}
17477 @tab @code{qGetTLSAddr}
17478 @tab Displaying @code{__thread} variables
17479
17480 @item @code{get-thread-information-block-address}
17481 @tab @code{qGetTIBAddr}
17482 @tab Display MS-Windows Thread Information Block.
17483
17484 @item @code{search-memory}
17485 @tab @code{qSearch:memory}
17486 @tab @code{find}
17487
17488 @item @code{supported-packets}
17489 @tab @code{qSupported}
17490 @tab Remote communications parameters
17491
17492 @item @code{pass-signals}
17493 @tab @code{QPassSignals}
17494 @tab @code{handle @var{signal}}
17495
17496 @item @code{program-signals}
17497 @tab @code{QProgramSignals}
17498 @tab @code{handle @var{signal}}
17499
17500 @item @code{hostio-close-packet}
17501 @tab @code{vFile:close}
17502 @tab @code{remote get}, @code{remote put}
17503
17504 @item @code{hostio-open-packet}
17505 @tab @code{vFile:open}
17506 @tab @code{remote get}, @code{remote put}
17507
17508 @item @code{hostio-pread-packet}
17509 @tab @code{vFile:pread}
17510 @tab @code{remote get}, @code{remote put}
17511
17512 @item @code{hostio-pwrite-packet}
17513 @tab @code{vFile:pwrite}
17514 @tab @code{remote get}, @code{remote put}
17515
17516 @item @code{hostio-unlink-packet}
17517 @tab @code{vFile:unlink}
17518 @tab @code{remote delete}
17519
17520 @item @code{hostio-readlink-packet}
17521 @tab @code{vFile:readlink}
17522 @tab Host I/O
17523
17524 @item @code{noack-packet}
17525 @tab @code{QStartNoAckMode}
17526 @tab Packet acknowledgment
17527
17528 @item @code{osdata}
17529 @tab @code{qXfer:osdata:read}
17530 @tab @code{info os}
17531
17532 @item @code{query-attached}
17533 @tab @code{qAttached}
17534 @tab Querying remote process attach state.
17535
17536 @item @code{traceframe-info}
17537 @tab @code{qXfer:traceframe-info:read}
17538 @tab Traceframe info
17539
17540 @item @code{install-in-trace}
17541 @tab @code{InstallInTrace}
17542 @tab Install tracepoint in tracing
17543
17544 @item @code{disable-randomization}
17545 @tab @code{QDisableRandomization}
17546 @tab @code{set disable-randomization}
17547
17548 @item @code{conditional-breakpoints-packet}
17549 @tab @code{Z0 and Z1}
17550 @tab @code{Support for target-side breakpoint condition evaluation}
17551 @end multitable
17552
17553 @node Remote Stub
17554 @section Implementing a Remote Stub
17555
17556 @cindex debugging stub, example
17557 @cindex remote stub, example
17558 @cindex stub example, remote debugging
17559 The stub files provided with @value{GDBN} implement the target side of the
17560 communication protocol, and the @value{GDBN} side is implemented in the
17561 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
17562 these subroutines to communicate, and ignore the details. (If you're
17563 implementing your own stub file, you can still ignore the details: start
17564 with one of the existing stub files. @file{sparc-stub.c} is the best
17565 organized, and therefore the easiest to read.)
17566
17567 @cindex remote serial debugging, overview
17568 To debug a program running on another machine (the debugging
17569 @dfn{target} machine), you must first arrange for all the usual
17570 prerequisites for the program to run by itself. For example, for a C
17571 program, you need:
17572
17573 @enumerate
17574 @item
17575 A startup routine to set up the C runtime environment; these usually
17576 have a name like @file{crt0}. The startup routine may be supplied by
17577 your hardware supplier, or you may have to write your own.
17578
17579 @item
17580 A C subroutine library to support your program's
17581 subroutine calls, notably managing input and output.
17582
17583 @item
17584 A way of getting your program to the other machine---for example, a
17585 download program. These are often supplied by the hardware
17586 manufacturer, but you may have to write your own from hardware
17587 documentation.
17588 @end enumerate
17589
17590 The next step is to arrange for your program to use a serial port to
17591 communicate with the machine where @value{GDBN} is running (the @dfn{host}
17592 machine). In general terms, the scheme looks like this:
17593
17594 @table @emph
17595 @item On the host,
17596 @value{GDBN} already understands how to use this protocol; when everything
17597 else is set up, you can simply use the @samp{target remote} command
17598 (@pxref{Targets,,Specifying a Debugging Target}).
17599
17600 @item On the target,
17601 you must link with your program a few special-purpose subroutines that
17602 implement the @value{GDBN} remote serial protocol. The file containing these
17603 subroutines is called a @dfn{debugging stub}.
17604
17605 On certain remote targets, you can use an auxiliary program
17606 @code{gdbserver} instead of linking a stub into your program.
17607 @xref{Server,,Using the @code{gdbserver} Program}, for details.
17608 @end table
17609
17610 The debugging stub is specific to the architecture of the remote
17611 machine; for example, use @file{sparc-stub.c} to debug programs on
17612 @sc{sparc} boards.
17613
17614 @cindex remote serial stub list
17615 These working remote stubs are distributed with @value{GDBN}:
17616
17617 @table @code
17618
17619 @item i386-stub.c
17620 @cindex @file{i386-stub.c}
17621 @cindex Intel
17622 @cindex i386
17623 For Intel 386 and compatible architectures.
17624
17625 @item m68k-stub.c
17626 @cindex @file{m68k-stub.c}
17627 @cindex Motorola 680x0
17628 @cindex m680x0
17629 For Motorola 680x0 architectures.
17630
17631 @item sh-stub.c
17632 @cindex @file{sh-stub.c}
17633 @cindex Renesas
17634 @cindex SH
17635 For Renesas SH architectures.
17636
17637 @item sparc-stub.c
17638 @cindex @file{sparc-stub.c}
17639 @cindex Sparc
17640 For @sc{sparc} architectures.
17641
17642 @item sparcl-stub.c
17643 @cindex @file{sparcl-stub.c}
17644 @cindex Fujitsu
17645 @cindex SparcLite
17646 For Fujitsu @sc{sparclite} architectures.
17647
17648 @end table
17649
17650 The @file{README} file in the @value{GDBN} distribution may list other
17651 recently added stubs.
17652
17653 @menu
17654 * Stub Contents:: What the stub can do for you
17655 * Bootstrapping:: What you must do for the stub
17656 * Debug Session:: Putting it all together
17657 @end menu
17658
17659 @node Stub Contents
17660 @subsection What the Stub Can Do for You
17661
17662 @cindex remote serial stub
17663 The debugging stub for your architecture supplies these three
17664 subroutines:
17665
17666 @table @code
17667 @item set_debug_traps
17668 @findex set_debug_traps
17669 @cindex remote serial stub, initialization
17670 This routine arranges for @code{handle_exception} to run when your
17671 program stops. You must call this subroutine explicitly in your
17672 program's startup code.
17673
17674 @item handle_exception
17675 @findex handle_exception
17676 @cindex remote serial stub, main routine
17677 This is the central workhorse, but your program never calls it
17678 explicitly---the setup code arranges for @code{handle_exception} to
17679 run when a trap is triggered.
17680
17681 @code{handle_exception} takes control when your program stops during
17682 execution (for example, on a breakpoint), and mediates communications
17683 with @value{GDBN} on the host machine. This is where the communications
17684 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
17685 representative on the target machine. It begins by sending summary
17686 information on the state of your program, then continues to execute,
17687 retrieving and transmitting any information @value{GDBN} needs, until you
17688 execute a @value{GDBN} command that makes your program resume; at that point,
17689 @code{handle_exception} returns control to your own code on the target
17690 machine.
17691
17692 @item breakpoint
17693 @cindex @code{breakpoint} subroutine, remote
17694 Use this auxiliary subroutine to make your program contain a
17695 breakpoint. Depending on the particular situation, this may be the only
17696 way for @value{GDBN} to get control. For instance, if your target
17697 machine has some sort of interrupt button, you won't need to call this;
17698 pressing the interrupt button transfers control to
17699 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
17700 simply receiving characters on the serial port may also trigger a trap;
17701 again, in that situation, you don't need to call @code{breakpoint} from
17702 your own program---simply running @samp{target remote} from the host
17703 @value{GDBN} session gets control.
17704
17705 Call @code{breakpoint} if none of these is true, or if you simply want
17706 to make certain your program stops at a predetermined point for the
17707 start of your debugging session.
17708 @end table
17709
17710 @node Bootstrapping
17711 @subsection What You Must Do for the Stub
17712
17713 @cindex remote stub, support routines
17714 The debugging stubs that come with @value{GDBN} are set up for a particular
17715 chip architecture, but they have no information about the rest of your
17716 debugging target machine.
17717
17718 First of all you need to tell the stub how to communicate with the
17719 serial port.
17720
17721 @table @code
17722 @item int getDebugChar()
17723 @findex getDebugChar
17724 Write this subroutine to read a single character from the serial port.
17725 It may be identical to @code{getchar} for your target system; a
17726 different name is used to allow you to distinguish the two if you wish.
17727
17728 @item void putDebugChar(int)
17729 @findex putDebugChar
17730 Write this subroutine to write a single character to the serial port.
17731 It may be identical to @code{putchar} for your target system; a
17732 different name is used to allow you to distinguish the two if you wish.
17733 @end table
17734
17735 @cindex control C, and remote debugging
17736 @cindex interrupting remote targets
17737 If you want @value{GDBN} to be able to stop your program while it is
17738 running, you need to use an interrupt-driven serial driver, and arrange
17739 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
17740 character). That is the character which @value{GDBN} uses to tell the
17741 remote system to stop.
17742
17743 Getting the debugging target to return the proper status to @value{GDBN}
17744 probably requires changes to the standard stub; one quick and dirty way
17745 is to just execute a breakpoint instruction (the ``dirty'' part is that
17746 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
17747
17748 Other routines you need to supply are:
17749
17750 @table @code
17751 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
17752 @findex exceptionHandler
17753 Write this function to install @var{exception_address} in the exception
17754 handling tables. You need to do this because the stub does not have any
17755 way of knowing what the exception handling tables on your target system
17756 are like (for example, the processor's table might be in @sc{rom},
17757 containing entries which point to a table in @sc{ram}).
17758 @var{exception_number} is the exception number which should be changed;
17759 its meaning is architecture-dependent (for example, different numbers
17760 might represent divide by zero, misaligned access, etc). When this
17761 exception occurs, control should be transferred directly to
17762 @var{exception_address}, and the processor state (stack, registers,
17763 and so on) should be just as it is when a processor exception occurs. So if
17764 you want to use a jump instruction to reach @var{exception_address}, it
17765 should be a simple jump, not a jump to subroutine.
17766
17767 For the 386, @var{exception_address} should be installed as an interrupt
17768 gate so that interrupts are masked while the handler runs. The gate
17769 should be at privilege level 0 (the most privileged level). The
17770 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
17771 help from @code{exceptionHandler}.
17772
17773 @item void flush_i_cache()
17774 @findex flush_i_cache
17775 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
17776 instruction cache, if any, on your target machine. If there is no
17777 instruction cache, this subroutine may be a no-op.
17778
17779 On target machines that have instruction caches, @value{GDBN} requires this
17780 function to make certain that the state of your program is stable.
17781 @end table
17782
17783 @noindent
17784 You must also make sure this library routine is available:
17785
17786 @table @code
17787 @item void *memset(void *, int, int)
17788 @findex memset
17789 This is the standard library function @code{memset} that sets an area of
17790 memory to a known value. If you have one of the free versions of
17791 @code{libc.a}, @code{memset} can be found there; otherwise, you must
17792 either obtain it from your hardware manufacturer, or write your own.
17793 @end table
17794
17795 If you do not use the GNU C compiler, you may need other standard
17796 library subroutines as well; this varies from one stub to another,
17797 but in general the stubs are likely to use any of the common library
17798 subroutines which @code{@value{NGCC}} generates as inline code.
17799
17800
17801 @node Debug Session
17802 @subsection Putting it All Together
17803
17804 @cindex remote serial debugging summary
17805 In summary, when your program is ready to debug, you must follow these
17806 steps.
17807
17808 @enumerate
17809 @item
17810 Make sure you have defined the supporting low-level routines
17811 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
17812 @display
17813 @code{getDebugChar}, @code{putDebugChar},
17814 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
17815 @end display
17816
17817 @item
17818 Insert these lines in your program's startup code, before the main
17819 procedure is called:
17820
17821 @smallexample
17822 set_debug_traps();
17823 breakpoint();
17824 @end smallexample
17825
17826 On some machines, when a breakpoint trap is raised, the hardware
17827 automatically makes the PC point to the instruction after the
17828 breakpoint. If your machine doesn't do that, you may need to adjust
17829 @code{handle_exception} to arrange for it to return to the instruction
17830 after the breakpoint on this first invocation, so that your program
17831 doesn't keep hitting the initial breakpoint instead of making
17832 progress.
17833
17834 @item
17835 For the 680x0 stub only, you need to provide a variable called
17836 @code{exceptionHook}. Normally you just use:
17837
17838 @smallexample
17839 void (*exceptionHook)() = 0;
17840 @end smallexample
17841
17842 @noindent
17843 but if before calling @code{set_debug_traps}, you set it to point to a
17844 function in your program, that function is called when
17845 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
17846 error). The function indicated by @code{exceptionHook} is called with
17847 one parameter: an @code{int} which is the exception number.
17848
17849 @item
17850 Compile and link together: your program, the @value{GDBN} debugging stub for
17851 your target architecture, and the supporting subroutines.
17852
17853 @item
17854 Make sure you have a serial connection between your target machine and
17855 the @value{GDBN} host, and identify the serial port on the host.
17856
17857 @item
17858 @c The "remote" target now provides a `load' command, so we should
17859 @c document that. FIXME.
17860 Download your program to your target machine (or get it there by
17861 whatever means the manufacturer provides), and start it.
17862
17863 @item
17864 Start @value{GDBN} on the host, and connect to the target
17865 (@pxref{Connecting,,Connecting to a Remote Target}).
17866
17867 @end enumerate
17868
17869 @node Configurations
17870 @chapter Configuration-Specific Information
17871
17872 While nearly all @value{GDBN} commands are available for all native and
17873 cross versions of the debugger, there are some exceptions. This chapter
17874 describes things that are only available in certain configurations.
17875
17876 There are three major categories of configurations: native
17877 configurations, where the host and target are the same, embedded
17878 operating system configurations, which are usually the same for several
17879 different processor architectures, and bare embedded processors, which
17880 are quite different from each other.
17881
17882 @menu
17883 * Native::
17884 * Embedded OS::
17885 * Embedded Processors::
17886 * Architectures::
17887 @end menu
17888
17889 @node Native
17890 @section Native
17891
17892 This section describes details specific to particular native
17893 configurations.
17894
17895 @menu
17896 * HP-UX:: HP-UX
17897 * BSD libkvm Interface:: Debugging BSD kernel memory images
17898 * SVR4 Process Information:: SVR4 process information
17899 * DJGPP Native:: Features specific to the DJGPP port
17900 * Cygwin Native:: Features specific to the Cygwin port
17901 * Hurd Native:: Features specific to @sc{gnu} Hurd
17902 * Neutrino:: Features specific to QNX Neutrino
17903 * Darwin:: Features specific to Darwin
17904 @end menu
17905
17906 @node HP-UX
17907 @subsection HP-UX
17908
17909 On HP-UX systems, if you refer to a function or variable name that
17910 begins with a dollar sign, @value{GDBN} searches for a user or system
17911 name first, before it searches for a convenience variable.
17912
17913
17914 @node BSD libkvm Interface
17915 @subsection BSD libkvm Interface
17916
17917 @cindex libkvm
17918 @cindex kernel memory image
17919 @cindex kernel crash dump
17920
17921 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
17922 interface that provides a uniform interface for accessing kernel virtual
17923 memory images, including live systems and crash dumps. @value{GDBN}
17924 uses this interface to allow you to debug live kernels and kernel crash
17925 dumps on many native BSD configurations. This is implemented as a
17926 special @code{kvm} debugging target. For debugging a live system, load
17927 the currently running kernel into @value{GDBN} and connect to the
17928 @code{kvm} target:
17929
17930 @smallexample
17931 (@value{GDBP}) @b{target kvm}
17932 @end smallexample
17933
17934 For debugging crash dumps, provide the file name of the crash dump as an
17935 argument:
17936
17937 @smallexample
17938 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
17939 @end smallexample
17940
17941 Once connected to the @code{kvm} target, the following commands are
17942 available:
17943
17944 @table @code
17945 @kindex kvm
17946 @item kvm pcb
17947 Set current context from the @dfn{Process Control Block} (PCB) address.
17948
17949 @item kvm proc
17950 Set current context from proc address. This command isn't available on
17951 modern FreeBSD systems.
17952 @end table
17953
17954 @node SVR4 Process Information
17955 @subsection SVR4 Process Information
17956 @cindex /proc
17957 @cindex examine process image
17958 @cindex process info via @file{/proc}
17959
17960 Many versions of SVR4 and compatible systems provide a facility called
17961 @samp{/proc} that can be used to examine the image of a running
17962 process using file-system subroutines. If @value{GDBN} is configured
17963 for an operating system with this facility, the command @code{info
17964 proc} is available to report information about the process running
17965 your program, or about any process running on your system. @code{info
17966 proc} works only on SVR4 systems that include the @code{procfs} code.
17967 This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
17968 Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
17969
17970 @table @code
17971 @kindex info proc
17972 @cindex process ID
17973 @item info proc
17974 @itemx info proc @var{process-id}
17975 Summarize available information about any running process. If a
17976 process ID is specified by @var{process-id}, display information about
17977 that process; otherwise display information about the program being
17978 debugged. The summary includes the debugged process ID, the command
17979 line used to invoke it, its current working directory, and its
17980 executable file's absolute file name.
17981
17982 On some systems, @var{process-id} can be of the form
17983 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
17984 within a process. If the optional @var{pid} part is missing, it means
17985 a thread from the process being debugged (the leading @samp{/} still
17986 needs to be present, or else @value{GDBN} will interpret the number as
17987 a process ID rather than a thread ID).
17988
17989 @item info proc mappings
17990 @cindex memory address space mappings
17991 Report the memory address space ranges accessible in the program, with
17992 information on whether the process has read, write, or execute access
17993 rights to each range. On @sc{gnu}/Linux systems, each memory range
17994 includes the object file which is mapped to that range, instead of the
17995 memory access rights to that range.
17996
17997 @item info proc stat
17998 @itemx info proc status
17999 @cindex process detailed status information
18000 These subcommands are specific to @sc{gnu}/Linux systems. They show
18001 the process-related information, including the user ID and group ID;
18002 how many threads are there in the process; its virtual memory usage;
18003 the signals that are pending, blocked, and ignored; its TTY; its
18004 consumption of system and user time; its stack size; its @samp{nice}
18005 value; etc. For more information, see the @samp{proc} man page
18006 (type @kbd{man 5 proc} from your shell prompt).
18007
18008 @item info proc all
18009 Show all the information about the process described under all of the
18010 above @code{info proc} subcommands.
18011
18012 @ignore
18013 @comment These sub-options of 'info proc' were not included when
18014 @comment procfs.c was re-written. Keep their descriptions around
18015 @comment against the day when someone finds the time to put them back in.
18016 @kindex info proc times
18017 @item info proc times
18018 Starting time, user CPU time, and system CPU time for your program and
18019 its children.
18020
18021 @kindex info proc id
18022 @item info proc id
18023 Report on the process IDs related to your program: its own process ID,
18024 the ID of its parent, the process group ID, and the session ID.
18025 @end ignore
18026
18027 @item set procfs-trace
18028 @kindex set procfs-trace
18029 @cindex @code{procfs} API calls
18030 This command enables and disables tracing of @code{procfs} API calls.
18031
18032 @item show procfs-trace
18033 @kindex show procfs-trace
18034 Show the current state of @code{procfs} API call tracing.
18035
18036 @item set procfs-file @var{file}
18037 @kindex set procfs-file
18038 Tell @value{GDBN} to write @code{procfs} API trace to the named
18039 @var{file}. @value{GDBN} appends the trace info to the previous
18040 contents of the file. The default is to display the trace on the
18041 standard output.
18042
18043 @item show procfs-file
18044 @kindex show procfs-file
18045 Show the file to which @code{procfs} API trace is written.
18046
18047 @item proc-trace-entry
18048 @itemx proc-trace-exit
18049 @itemx proc-untrace-entry
18050 @itemx proc-untrace-exit
18051 @kindex proc-trace-entry
18052 @kindex proc-trace-exit
18053 @kindex proc-untrace-entry
18054 @kindex proc-untrace-exit
18055 These commands enable and disable tracing of entries into and exits
18056 from the @code{syscall} interface.
18057
18058 @item info pidlist
18059 @kindex info pidlist
18060 @cindex process list, QNX Neutrino
18061 For QNX Neutrino only, this command displays the list of all the
18062 processes and all the threads within each process.
18063
18064 @item info meminfo
18065 @kindex info meminfo
18066 @cindex mapinfo list, QNX Neutrino
18067 For QNX Neutrino only, this command displays the list of all mapinfos.
18068 @end table
18069
18070 @node DJGPP Native
18071 @subsection Features for Debugging @sc{djgpp} Programs
18072 @cindex @sc{djgpp} debugging
18073 @cindex native @sc{djgpp} debugging
18074 @cindex MS-DOS-specific commands
18075
18076 @cindex DPMI
18077 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
18078 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
18079 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
18080 top of real-mode DOS systems and their emulations.
18081
18082 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
18083 defines a few commands specific to the @sc{djgpp} port. This
18084 subsection describes those commands.
18085
18086 @table @code
18087 @kindex info dos
18088 @item info dos
18089 This is a prefix of @sc{djgpp}-specific commands which print
18090 information about the target system and important OS structures.
18091
18092 @kindex sysinfo
18093 @cindex MS-DOS system info
18094 @cindex free memory information (MS-DOS)
18095 @item info dos sysinfo
18096 This command displays assorted information about the underlying
18097 platform: the CPU type and features, the OS version and flavor, the
18098 DPMI version, and the available conventional and DPMI memory.
18099
18100 @cindex GDT
18101 @cindex LDT
18102 @cindex IDT
18103 @cindex segment descriptor tables
18104 @cindex descriptor tables display
18105 @item info dos gdt
18106 @itemx info dos ldt
18107 @itemx info dos idt
18108 These 3 commands display entries from, respectively, Global, Local,
18109 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
18110 tables are data structures which store a descriptor for each segment
18111 that is currently in use. The segment's selector is an index into a
18112 descriptor table; the table entry for that index holds the
18113 descriptor's base address and limit, and its attributes and access
18114 rights.
18115
18116 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
18117 segment (used for both data and the stack), and a DOS segment (which
18118 allows access to DOS/BIOS data structures and absolute addresses in
18119 conventional memory). However, the DPMI host will usually define
18120 additional segments in order to support the DPMI environment.
18121
18122 @cindex garbled pointers
18123 These commands allow to display entries from the descriptor tables.
18124 Without an argument, all entries from the specified table are
18125 displayed. An argument, which should be an integer expression, means
18126 display a single entry whose index is given by the argument. For
18127 example, here's a convenient way to display information about the
18128 debugged program's data segment:
18129
18130 @smallexample
18131 @exdent @code{(@value{GDBP}) info dos ldt $ds}
18132 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
18133 @end smallexample
18134
18135 @noindent
18136 This comes in handy when you want to see whether a pointer is outside
18137 the data segment's limit (i.e.@: @dfn{garbled}).
18138
18139 @cindex page tables display (MS-DOS)
18140 @item info dos pde
18141 @itemx info dos pte
18142 These two commands display entries from, respectively, the Page
18143 Directory and the Page Tables. Page Directories and Page Tables are
18144 data structures which control how virtual memory addresses are mapped
18145 into physical addresses. A Page Table includes an entry for every
18146 page of memory that is mapped into the program's address space; there
18147 may be several Page Tables, each one holding up to 4096 entries. A
18148 Page Directory has up to 4096 entries, one each for every Page Table
18149 that is currently in use.
18150
18151 Without an argument, @kbd{info dos pde} displays the entire Page
18152 Directory, and @kbd{info dos pte} displays all the entries in all of
18153 the Page Tables. An argument, an integer expression, given to the
18154 @kbd{info dos pde} command means display only that entry from the Page
18155 Directory table. An argument given to the @kbd{info dos pte} command
18156 means display entries from a single Page Table, the one pointed to by
18157 the specified entry in the Page Directory.
18158
18159 @cindex direct memory access (DMA) on MS-DOS
18160 These commands are useful when your program uses @dfn{DMA} (Direct
18161 Memory Access), which needs physical addresses to program the DMA
18162 controller.
18163
18164 These commands are supported only with some DPMI servers.
18165
18166 @cindex physical address from linear address
18167 @item info dos address-pte @var{addr}
18168 This command displays the Page Table entry for a specified linear
18169 address. The argument @var{addr} is a linear address which should
18170 already have the appropriate segment's base address added to it,
18171 because this command accepts addresses which may belong to @emph{any}
18172 segment. For example, here's how to display the Page Table entry for
18173 the page where a variable @code{i} is stored:
18174
18175 @smallexample
18176 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
18177 @exdent @code{Page Table entry for address 0x11a00d30:}
18178 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
18179 @end smallexample
18180
18181 @noindent
18182 This says that @code{i} is stored at offset @code{0xd30} from the page
18183 whose physical base address is @code{0x02698000}, and shows all the
18184 attributes of that page.
18185
18186 Note that you must cast the addresses of variables to a @code{char *},
18187 since otherwise the value of @code{__djgpp_base_address}, the base
18188 address of all variables and functions in a @sc{djgpp} program, will
18189 be added using the rules of C pointer arithmetics: if @code{i} is
18190 declared an @code{int}, @value{GDBN} will add 4 times the value of
18191 @code{__djgpp_base_address} to the address of @code{i}.
18192
18193 Here's another example, it displays the Page Table entry for the
18194 transfer buffer:
18195
18196 @smallexample
18197 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
18198 @exdent @code{Page Table entry for address 0x29110:}
18199 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
18200 @end smallexample
18201
18202 @noindent
18203 (The @code{+ 3} offset is because the transfer buffer's address is the
18204 3rd member of the @code{_go32_info_block} structure.) The output
18205 clearly shows that this DPMI server maps the addresses in conventional
18206 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
18207 linear (@code{0x29110}) addresses are identical.
18208
18209 This command is supported only with some DPMI servers.
18210 @end table
18211
18212 @cindex DOS serial data link, remote debugging
18213 In addition to native debugging, the DJGPP port supports remote
18214 debugging via a serial data link. The following commands are specific
18215 to remote serial debugging in the DJGPP port of @value{GDBN}.
18216
18217 @table @code
18218 @kindex set com1base
18219 @kindex set com1irq
18220 @kindex set com2base
18221 @kindex set com2irq
18222 @kindex set com3base
18223 @kindex set com3irq
18224 @kindex set com4base
18225 @kindex set com4irq
18226 @item set com1base @var{addr}
18227 This command sets the base I/O port address of the @file{COM1} serial
18228 port.
18229
18230 @item set com1irq @var{irq}
18231 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
18232 for the @file{COM1} serial port.
18233
18234 There are similar commands @samp{set com2base}, @samp{set com3irq},
18235 etc.@: for setting the port address and the @code{IRQ} lines for the
18236 other 3 COM ports.
18237
18238 @kindex show com1base
18239 @kindex show com1irq
18240 @kindex show com2base
18241 @kindex show com2irq
18242 @kindex show com3base
18243 @kindex show com3irq
18244 @kindex show com4base
18245 @kindex show com4irq
18246 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
18247 display the current settings of the base address and the @code{IRQ}
18248 lines used by the COM ports.
18249
18250 @item info serial
18251 @kindex info serial
18252 @cindex DOS serial port status
18253 This command prints the status of the 4 DOS serial ports. For each
18254 port, it prints whether it's active or not, its I/O base address and
18255 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
18256 counts of various errors encountered so far.
18257 @end table
18258
18259
18260 @node Cygwin Native
18261 @subsection Features for Debugging MS Windows PE Executables
18262 @cindex MS Windows debugging
18263 @cindex native Cygwin debugging
18264 @cindex Cygwin-specific commands
18265
18266 @value{GDBN} supports native debugging of MS Windows programs, including
18267 DLLs with and without symbolic debugging information.
18268
18269 @cindex Ctrl-BREAK, MS-Windows
18270 @cindex interrupt debuggee on MS-Windows
18271 MS-Windows programs that call @code{SetConsoleMode} to switch off the
18272 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
18273 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
18274 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
18275 sequence, which can be used to interrupt the debuggee even if it
18276 ignores @kbd{C-c}.
18277
18278 There are various additional Cygwin-specific commands, described in
18279 this section. Working with DLLs that have no debugging symbols is
18280 described in @ref{Non-debug DLL Symbols}.
18281
18282 @table @code
18283 @kindex info w32
18284 @item info w32
18285 This is a prefix of MS Windows-specific commands which print
18286 information about the target system and important OS structures.
18287
18288 @item info w32 selector
18289 This command displays information returned by
18290 the Win32 API @code{GetThreadSelectorEntry} function.
18291 It takes an optional argument that is evaluated to
18292 a long value to give the information about this given selector.
18293 Without argument, this command displays information
18294 about the six segment registers.
18295
18296 @item info w32 thread-information-block
18297 This command displays thread specific information stored in the
18298 Thread Information Block (readable on the X86 CPU family using @code{$fs}
18299 selector for 32-bit programs and @code{$gs} for 64-bit programs).
18300
18301 @kindex info dll
18302 @item info dll
18303 This is a Cygwin-specific alias of @code{info shared}.
18304
18305 @kindex dll-symbols
18306 @item dll-symbols
18307 This command loads symbols from a dll similarly to
18308 add-sym command but without the need to specify a base address.
18309
18310 @kindex set cygwin-exceptions
18311 @cindex debugging the Cygwin DLL
18312 @cindex Cygwin DLL, debugging
18313 @item set cygwin-exceptions @var{mode}
18314 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
18315 happen inside the Cygwin DLL. If @var{mode} is @code{off},
18316 @value{GDBN} will delay recognition of exceptions, and may ignore some
18317 exceptions which seem to be caused by internal Cygwin DLL
18318 ``bookkeeping''. This option is meant primarily for debugging the
18319 Cygwin DLL itself; the default value is @code{off} to avoid annoying
18320 @value{GDBN} users with false @code{SIGSEGV} signals.
18321
18322 @kindex show cygwin-exceptions
18323 @item show cygwin-exceptions
18324 Displays whether @value{GDBN} will break on exceptions that happen
18325 inside the Cygwin DLL itself.
18326
18327 @kindex set new-console
18328 @item set new-console @var{mode}
18329 If @var{mode} is @code{on} the debuggee will
18330 be started in a new console on next start.
18331 If @var{mode} is @code{off}, the debuggee will
18332 be started in the same console as the debugger.
18333
18334 @kindex show new-console
18335 @item show new-console
18336 Displays whether a new console is used
18337 when the debuggee is started.
18338
18339 @kindex set new-group
18340 @item set new-group @var{mode}
18341 This boolean value controls whether the debuggee should
18342 start a new group or stay in the same group as the debugger.
18343 This affects the way the Windows OS handles
18344 @samp{Ctrl-C}.
18345
18346 @kindex show new-group
18347 @item show new-group
18348 Displays current value of new-group boolean.
18349
18350 @kindex set debugevents
18351 @item set debugevents
18352 This boolean value adds debug output concerning kernel events related
18353 to the debuggee seen by the debugger. This includes events that
18354 signal thread and process creation and exit, DLL loading and
18355 unloading, console interrupts, and debugging messages produced by the
18356 Windows @code{OutputDebugString} API call.
18357
18358 @kindex set debugexec
18359 @item set debugexec
18360 This boolean value adds debug output concerning execute events
18361 (such as resume thread) seen by the debugger.
18362
18363 @kindex set debugexceptions
18364 @item set debugexceptions
18365 This boolean value adds debug output concerning exceptions in the
18366 debuggee seen by the debugger.
18367
18368 @kindex set debugmemory
18369 @item set debugmemory
18370 This boolean value adds debug output concerning debuggee memory reads
18371 and writes by the debugger.
18372
18373 @kindex set shell
18374 @item set shell
18375 This boolean values specifies whether the debuggee is called
18376 via a shell or directly (default value is on).
18377
18378 @kindex show shell
18379 @item show shell
18380 Displays if the debuggee will be started with a shell.
18381
18382 @end table
18383
18384 @menu
18385 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
18386 @end menu
18387
18388 @node Non-debug DLL Symbols
18389 @subsubsection Support for DLLs without Debugging Symbols
18390 @cindex DLLs with no debugging symbols
18391 @cindex Minimal symbols and DLLs
18392
18393 Very often on windows, some of the DLLs that your program relies on do
18394 not include symbolic debugging information (for example,
18395 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
18396 symbols in a DLL, it relies on the minimal amount of symbolic
18397 information contained in the DLL's export table. This section
18398 describes working with such symbols, known internally to @value{GDBN} as
18399 ``minimal symbols''.
18400
18401 Note that before the debugged program has started execution, no DLLs
18402 will have been loaded. The easiest way around this problem is simply to
18403 start the program --- either by setting a breakpoint or letting the
18404 program run once to completion. It is also possible to force
18405 @value{GDBN} to load a particular DLL before starting the executable ---
18406 see the shared library information in @ref{Files}, or the
18407 @code{dll-symbols} command in @ref{Cygwin Native}. Currently,
18408 explicitly loading symbols from a DLL with no debugging information will
18409 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
18410 which may adversely affect symbol lookup performance.
18411
18412 @subsubsection DLL Name Prefixes
18413
18414 In keeping with the naming conventions used by the Microsoft debugging
18415 tools, DLL export symbols are made available with a prefix based on the
18416 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
18417 also entered into the symbol table, so @code{CreateFileA} is often
18418 sufficient. In some cases there will be name clashes within a program
18419 (particularly if the executable itself includes full debugging symbols)
18420 necessitating the use of the fully qualified name when referring to the
18421 contents of the DLL. Use single-quotes around the name to avoid the
18422 exclamation mark (``!'') being interpreted as a language operator.
18423
18424 Note that the internal name of the DLL may be all upper-case, even
18425 though the file name of the DLL is lower-case, or vice-versa. Since
18426 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
18427 some confusion. If in doubt, try the @code{info functions} and
18428 @code{info variables} commands or even @code{maint print msymbols}
18429 (@pxref{Symbols}). Here's an example:
18430
18431 @smallexample
18432 (@value{GDBP}) info function CreateFileA
18433 All functions matching regular expression "CreateFileA":
18434
18435 Non-debugging symbols:
18436 0x77e885f4 CreateFileA
18437 0x77e885f4 KERNEL32!CreateFileA
18438 @end smallexample
18439
18440 @smallexample
18441 (@value{GDBP}) info function !
18442 All functions matching regular expression "!":
18443
18444 Non-debugging symbols:
18445 0x6100114c cygwin1!__assert
18446 0x61004034 cygwin1!_dll_crt0@@0
18447 0x61004240 cygwin1!dll_crt0(per_process *)
18448 [etc...]
18449 @end smallexample
18450
18451 @subsubsection Working with Minimal Symbols
18452
18453 Symbols extracted from a DLL's export table do not contain very much
18454 type information. All that @value{GDBN} can do is guess whether a symbol
18455 refers to a function or variable depending on the linker section that
18456 contains the symbol. Also note that the actual contents of the memory
18457 contained in a DLL are not available unless the program is running. This
18458 means that you cannot examine the contents of a variable or disassemble
18459 a function within a DLL without a running program.
18460
18461 Variables are generally treated as pointers and dereferenced
18462 automatically. For this reason, it is often necessary to prefix a
18463 variable name with the address-of operator (``&'') and provide explicit
18464 type information in the command. Here's an example of the type of
18465 problem:
18466
18467 @smallexample
18468 (@value{GDBP}) print 'cygwin1!__argv'
18469 $1 = 268572168
18470 @end smallexample
18471
18472 @smallexample
18473 (@value{GDBP}) x 'cygwin1!__argv'
18474 0x10021610: "\230y\""
18475 @end smallexample
18476
18477 And two possible solutions:
18478
18479 @smallexample
18480 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
18481 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
18482 @end smallexample
18483
18484 @smallexample
18485 (@value{GDBP}) x/2x &'cygwin1!__argv'
18486 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
18487 (@value{GDBP}) x/x 0x10021608
18488 0x10021608: 0x0022fd98
18489 (@value{GDBP}) x/s 0x0022fd98
18490 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
18491 @end smallexample
18492
18493 Setting a break point within a DLL is possible even before the program
18494 starts execution. However, under these circumstances, @value{GDBN} can't
18495 examine the initial instructions of the function in order to skip the
18496 function's frame set-up code. You can work around this by using ``*&''
18497 to set the breakpoint at a raw memory address:
18498
18499 @smallexample
18500 (@value{GDBP}) break *&'python22!PyOS_Readline'
18501 Breakpoint 1 at 0x1e04eff0
18502 @end smallexample
18503
18504 The author of these extensions is not entirely convinced that setting a
18505 break point within a shared DLL like @file{kernel32.dll} is completely
18506 safe.
18507
18508 @node Hurd Native
18509 @subsection Commands Specific to @sc{gnu} Hurd Systems
18510 @cindex @sc{gnu} Hurd debugging
18511
18512 This subsection describes @value{GDBN} commands specific to the
18513 @sc{gnu} Hurd native debugging.
18514
18515 @table @code
18516 @item set signals
18517 @itemx set sigs
18518 @kindex set signals@r{, Hurd command}
18519 @kindex set sigs@r{, Hurd command}
18520 This command toggles the state of inferior signal interception by
18521 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
18522 affected by this command. @code{sigs} is a shorthand alias for
18523 @code{signals}.
18524
18525 @item show signals
18526 @itemx show sigs
18527 @kindex show signals@r{, Hurd command}
18528 @kindex show sigs@r{, Hurd command}
18529 Show the current state of intercepting inferior's signals.
18530
18531 @item set signal-thread
18532 @itemx set sigthread
18533 @kindex set signal-thread
18534 @kindex set sigthread
18535 This command tells @value{GDBN} which thread is the @code{libc} signal
18536 thread. That thread is run when a signal is delivered to a running
18537 process. @code{set sigthread} is the shorthand alias of @code{set
18538 signal-thread}.
18539
18540 @item show signal-thread
18541 @itemx show sigthread
18542 @kindex show signal-thread
18543 @kindex show sigthread
18544 These two commands show which thread will run when the inferior is
18545 delivered a signal.
18546
18547 @item set stopped
18548 @kindex set stopped@r{, Hurd command}
18549 This commands tells @value{GDBN} that the inferior process is stopped,
18550 as with the @code{SIGSTOP} signal. The stopped process can be
18551 continued by delivering a signal to it.
18552
18553 @item show stopped
18554 @kindex show stopped@r{, Hurd command}
18555 This command shows whether @value{GDBN} thinks the debuggee is
18556 stopped.
18557
18558 @item set exceptions
18559 @kindex set exceptions@r{, Hurd command}
18560 Use this command to turn off trapping of exceptions in the inferior.
18561 When exception trapping is off, neither breakpoints nor
18562 single-stepping will work. To restore the default, set exception
18563 trapping on.
18564
18565 @item show exceptions
18566 @kindex show exceptions@r{, Hurd command}
18567 Show the current state of trapping exceptions in the inferior.
18568
18569 @item set task pause
18570 @kindex set task@r{, Hurd commands}
18571 @cindex task attributes (@sc{gnu} Hurd)
18572 @cindex pause current task (@sc{gnu} Hurd)
18573 This command toggles task suspension when @value{GDBN} has control.
18574 Setting it to on takes effect immediately, and the task is suspended
18575 whenever @value{GDBN} gets control. Setting it to off will take
18576 effect the next time the inferior is continued. If this option is set
18577 to off, you can use @code{set thread default pause on} or @code{set
18578 thread pause on} (see below) to pause individual threads.
18579
18580 @item show task pause
18581 @kindex show task@r{, Hurd commands}
18582 Show the current state of task suspension.
18583
18584 @item set task detach-suspend-count
18585 @cindex task suspend count
18586 @cindex detach from task, @sc{gnu} Hurd
18587 This command sets the suspend count the task will be left with when
18588 @value{GDBN} detaches from it.
18589
18590 @item show task detach-suspend-count
18591 Show the suspend count the task will be left with when detaching.
18592
18593 @item set task exception-port
18594 @itemx set task excp
18595 @cindex task exception port, @sc{gnu} Hurd
18596 This command sets the task exception port to which @value{GDBN} will
18597 forward exceptions. The argument should be the value of the @dfn{send
18598 rights} of the task. @code{set task excp} is a shorthand alias.
18599
18600 @item set noninvasive
18601 @cindex noninvasive task options
18602 This command switches @value{GDBN} to a mode that is the least
18603 invasive as far as interfering with the inferior is concerned. This
18604 is the same as using @code{set task pause}, @code{set exceptions}, and
18605 @code{set signals} to values opposite to the defaults.
18606
18607 @item info send-rights
18608 @itemx info receive-rights
18609 @itemx info port-rights
18610 @itemx info port-sets
18611 @itemx info dead-names
18612 @itemx info ports
18613 @itemx info psets
18614 @cindex send rights, @sc{gnu} Hurd
18615 @cindex receive rights, @sc{gnu} Hurd
18616 @cindex port rights, @sc{gnu} Hurd
18617 @cindex port sets, @sc{gnu} Hurd
18618 @cindex dead names, @sc{gnu} Hurd
18619 These commands display information about, respectively, send rights,
18620 receive rights, port rights, port sets, and dead names of a task.
18621 There are also shorthand aliases: @code{info ports} for @code{info
18622 port-rights} and @code{info psets} for @code{info port-sets}.
18623
18624 @item set thread pause
18625 @kindex set thread@r{, Hurd command}
18626 @cindex thread properties, @sc{gnu} Hurd
18627 @cindex pause current thread (@sc{gnu} Hurd)
18628 This command toggles current thread suspension when @value{GDBN} has
18629 control. Setting it to on takes effect immediately, and the current
18630 thread is suspended whenever @value{GDBN} gets control. Setting it to
18631 off will take effect the next time the inferior is continued.
18632 Normally, this command has no effect, since when @value{GDBN} has
18633 control, the whole task is suspended. However, if you used @code{set
18634 task pause off} (see above), this command comes in handy to suspend
18635 only the current thread.
18636
18637 @item show thread pause
18638 @kindex show thread@r{, Hurd command}
18639 This command shows the state of current thread suspension.
18640
18641 @item set thread run
18642 This command sets whether the current thread is allowed to run.
18643
18644 @item show thread run
18645 Show whether the current thread is allowed to run.
18646
18647 @item set thread detach-suspend-count
18648 @cindex thread suspend count, @sc{gnu} Hurd
18649 @cindex detach from thread, @sc{gnu} Hurd
18650 This command sets the suspend count @value{GDBN} will leave on a
18651 thread when detaching. This number is relative to the suspend count
18652 found by @value{GDBN} when it notices the thread; use @code{set thread
18653 takeover-suspend-count} to force it to an absolute value.
18654
18655 @item show thread detach-suspend-count
18656 Show the suspend count @value{GDBN} will leave on the thread when
18657 detaching.
18658
18659 @item set thread exception-port
18660 @itemx set thread excp
18661 Set the thread exception port to which to forward exceptions. This
18662 overrides the port set by @code{set task exception-port} (see above).
18663 @code{set thread excp} is the shorthand alias.
18664
18665 @item set thread takeover-suspend-count
18666 Normally, @value{GDBN}'s thread suspend counts are relative to the
18667 value @value{GDBN} finds when it notices each thread. This command
18668 changes the suspend counts to be absolute instead.
18669
18670 @item set thread default
18671 @itemx show thread default
18672 @cindex thread default settings, @sc{gnu} Hurd
18673 Each of the above @code{set thread} commands has a @code{set thread
18674 default} counterpart (e.g., @code{set thread default pause}, @code{set
18675 thread default exception-port}, etc.). The @code{thread default}
18676 variety of commands sets the default thread properties for all
18677 threads; you can then change the properties of individual threads with
18678 the non-default commands.
18679 @end table
18680
18681
18682 @node Neutrino
18683 @subsection QNX Neutrino
18684 @cindex QNX Neutrino
18685
18686 @value{GDBN} provides the following commands specific to the QNX
18687 Neutrino target:
18688
18689 @table @code
18690 @item set debug nto-debug
18691 @kindex set debug nto-debug
18692 When set to on, enables debugging messages specific to the QNX
18693 Neutrino support.
18694
18695 @item show debug nto-debug
18696 @kindex show debug nto-debug
18697 Show the current state of QNX Neutrino messages.
18698 @end table
18699
18700 @node Darwin
18701 @subsection Darwin
18702 @cindex Darwin
18703
18704 @value{GDBN} provides the following commands specific to the Darwin target:
18705
18706 @table @code
18707 @item set debug darwin @var{num}
18708 @kindex set debug darwin
18709 When set to a non zero value, enables debugging messages specific to
18710 the Darwin support. Higher values produce more verbose output.
18711
18712 @item show debug darwin
18713 @kindex show debug darwin
18714 Show the current state of Darwin messages.
18715
18716 @item set debug mach-o @var{num}
18717 @kindex set debug mach-o
18718 When set to a non zero value, enables debugging messages while
18719 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
18720 file format used on Darwin for object and executable files.) Higher
18721 values produce more verbose output. This is a command to diagnose
18722 problems internal to @value{GDBN} and should not be needed in normal
18723 usage.
18724
18725 @item show debug mach-o
18726 @kindex show debug mach-o
18727 Show the current state of Mach-O file messages.
18728
18729 @item set mach-exceptions on
18730 @itemx set mach-exceptions off
18731 @kindex set mach-exceptions
18732 On Darwin, faults are first reported as a Mach exception and are then
18733 mapped to a Posix signal. Use this command to turn on trapping of
18734 Mach exceptions in the inferior. This might be sometimes useful to
18735 better understand the cause of a fault. The default is off.
18736
18737 @item show mach-exceptions
18738 @kindex show mach-exceptions
18739 Show the current state of exceptions trapping.
18740 @end table
18741
18742
18743 @node Embedded OS
18744 @section Embedded Operating Systems
18745
18746 This section describes configurations involving the debugging of
18747 embedded operating systems that are available for several different
18748 architectures.
18749
18750 @menu
18751 * VxWorks:: Using @value{GDBN} with VxWorks
18752 @end menu
18753
18754 @value{GDBN} includes the ability to debug programs running on
18755 various real-time operating systems.
18756
18757 @node VxWorks
18758 @subsection Using @value{GDBN} with VxWorks
18759
18760 @cindex VxWorks
18761
18762 @table @code
18763
18764 @kindex target vxworks
18765 @item target vxworks @var{machinename}
18766 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
18767 is the target system's machine name or IP address.
18768
18769 @end table
18770
18771 On VxWorks, @code{load} links @var{filename} dynamically on the
18772 current target system as well as adding its symbols in @value{GDBN}.
18773
18774 @value{GDBN} enables developers to spawn and debug tasks running on networked
18775 VxWorks targets from a Unix host. Already-running tasks spawned from
18776 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
18777 both the Unix host and on the VxWorks target. The program
18778 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
18779 installed with the name @code{vxgdb}, to distinguish it from a
18780 @value{GDBN} for debugging programs on the host itself.)
18781
18782 @table @code
18783 @item VxWorks-timeout @var{args}
18784 @kindex vxworks-timeout
18785 All VxWorks-based targets now support the option @code{vxworks-timeout}.
18786 This option is set by the user, and @var{args} represents the number of
18787 seconds @value{GDBN} waits for responses to rpc's. You might use this if
18788 your VxWorks target is a slow software simulator or is on the far side
18789 of a thin network line.
18790 @end table
18791
18792 The following information on connecting to VxWorks was current when
18793 this manual was produced; newer releases of VxWorks may use revised
18794 procedures.
18795
18796 @findex INCLUDE_RDB
18797 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
18798 to include the remote debugging interface routines in the VxWorks
18799 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
18800 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
18801 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
18802 source debugging task @code{tRdbTask} when VxWorks is booted. For more
18803 information on configuring and remaking VxWorks, see the manufacturer's
18804 manual.
18805 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
18806
18807 Once you have included @file{rdb.a} in your VxWorks system image and set
18808 your Unix execution search path to find @value{GDBN}, you are ready to
18809 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
18810 @code{vxgdb}, depending on your installation).
18811
18812 @value{GDBN} comes up showing the prompt:
18813
18814 @smallexample
18815 (vxgdb)
18816 @end smallexample
18817
18818 @menu
18819 * VxWorks Connection:: Connecting to VxWorks
18820 * VxWorks Download:: VxWorks download
18821 * VxWorks Attach:: Running tasks
18822 @end menu
18823
18824 @node VxWorks Connection
18825 @subsubsection Connecting to VxWorks
18826
18827 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
18828 network. To connect to a target whose host name is ``@code{tt}'', type:
18829
18830 @smallexample
18831 (vxgdb) target vxworks tt
18832 @end smallexample
18833
18834 @need 750
18835 @value{GDBN} displays messages like these:
18836
18837 @smallexample
18838 Attaching remote machine across net...
18839 Connected to tt.
18840 @end smallexample
18841
18842 @need 1000
18843 @value{GDBN} then attempts to read the symbol tables of any object modules
18844 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
18845 these files by searching the directories listed in the command search
18846 path (@pxref{Environment, ,Your Program's Environment}); if it fails
18847 to find an object file, it displays a message such as:
18848
18849 @smallexample
18850 prog.o: No such file or directory.
18851 @end smallexample
18852
18853 When this happens, add the appropriate directory to the search path with
18854 the @value{GDBN} command @code{path}, and execute the @code{target}
18855 command again.
18856
18857 @node VxWorks Download
18858 @subsubsection VxWorks Download
18859
18860 @cindex download to VxWorks
18861 If you have connected to the VxWorks target and you want to debug an
18862 object that has not yet been loaded, you can use the @value{GDBN}
18863 @code{load} command to download a file from Unix to VxWorks
18864 incrementally. The object file given as an argument to the @code{load}
18865 command is actually opened twice: first by the VxWorks target in order
18866 to download the code, then by @value{GDBN} in order to read the symbol
18867 table. This can lead to problems if the current working directories on
18868 the two systems differ. If both systems have NFS mounted the same
18869 filesystems, you can avoid these problems by using absolute paths.
18870 Otherwise, it is simplest to set the working directory on both systems
18871 to the directory in which the object file resides, and then to reference
18872 the file by its name, without any path. For instance, a program
18873 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
18874 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
18875 program, type this on VxWorks:
18876
18877 @smallexample
18878 -> cd "@var{vxpath}/vw/demo/rdb"
18879 @end smallexample
18880
18881 @noindent
18882 Then, in @value{GDBN}, type:
18883
18884 @smallexample
18885 (vxgdb) cd @var{hostpath}/vw/demo/rdb
18886 (vxgdb) load prog.o
18887 @end smallexample
18888
18889 @value{GDBN} displays a response similar to this:
18890
18891 @smallexample
18892 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
18893 @end smallexample
18894
18895 You can also use the @code{load} command to reload an object module
18896 after editing and recompiling the corresponding source file. Note that
18897 this makes @value{GDBN} delete all currently-defined breakpoints,
18898 auto-displays, and convenience variables, and to clear the value
18899 history. (This is necessary in order to preserve the integrity of
18900 debugger's data structures that reference the target system's symbol
18901 table.)
18902
18903 @node VxWorks Attach
18904 @subsubsection Running Tasks
18905
18906 @cindex running VxWorks tasks
18907 You can also attach to an existing task using the @code{attach} command as
18908 follows:
18909
18910 @smallexample
18911 (vxgdb) attach @var{task}
18912 @end smallexample
18913
18914 @noindent
18915 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
18916 or suspended when you attach to it. Running tasks are suspended at
18917 the time of attachment.
18918
18919 @node Embedded Processors
18920 @section Embedded Processors
18921
18922 This section goes into details specific to particular embedded
18923 configurations.
18924
18925 @cindex send command to simulator
18926 Whenever a specific embedded processor has a simulator, @value{GDBN}
18927 allows to send an arbitrary command to the simulator.
18928
18929 @table @code
18930 @item sim @var{command}
18931 @kindex sim@r{, a command}
18932 Send an arbitrary @var{command} string to the simulator. Consult the
18933 documentation for the specific simulator in use for information about
18934 acceptable commands.
18935 @end table
18936
18937
18938 @menu
18939 * ARM:: ARM RDI
18940 * M32R/D:: Renesas M32R/D
18941 * M68K:: Motorola M68K
18942 * MicroBlaze:: Xilinx MicroBlaze
18943 * MIPS Embedded:: MIPS Embedded
18944 * OpenRISC 1000:: OpenRisc 1000
18945 * PA:: HP PA Embedded
18946 * PowerPC Embedded:: PowerPC Embedded
18947 * Sparclet:: Tsqware Sparclet
18948 * Sparclite:: Fujitsu Sparclite
18949 * Z8000:: Zilog Z8000
18950 * AVR:: Atmel AVR
18951 * CRIS:: CRIS
18952 * Super-H:: Renesas Super-H
18953 @end menu
18954
18955 @node ARM
18956 @subsection ARM
18957 @cindex ARM RDI
18958
18959 @table @code
18960 @kindex target rdi
18961 @item target rdi @var{dev}
18962 ARM Angel monitor, via RDI library interface to ADP protocol. You may
18963 use this target to communicate with both boards running the Angel
18964 monitor, or with the EmbeddedICE JTAG debug device.
18965
18966 @kindex target rdp
18967 @item target rdp @var{dev}
18968 ARM Demon monitor.
18969
18970 @end table
18971
18972 @value{GDBN} provides the following ARM-specific commands:
18973
18974 @table @code
18975 @item set arm disassembler
18976 @kindex set arm
18977 This commands selects from a list of disassembly styles. The
18978 @code{"std"} style is the standard style.
18979
18980 @item show arm disassembler
18981 @kindex show arm
18982 Show the current disassembly style.
18983
18984 @item set arm apcs32
18985 @cindex ARM 32-bit mode
18986 This command toggles ARM operation mode between 32-bit and 26-bit.
18987
18988 @item show arm apcs32
18989 Display the current usage of the ARM 32-bit mode.
18990
18991 @item set arm fpu @var{fputype}
18992 This command sets the ARM floating-point unit (FPU) type. The
18993 argument @var{fputype} can be one of these:
18994
18995 @table @code
18996 @item auto
18997 Determine the FPU type by querying the OS ABI.
18998 @item softfpa
18999 Software FPU, with mixed-endian doubles on little-endian ARM
19000 processors.
19001 @item fpa
19002 GCC-compiled FPA co-processor.
19003 @item softvfp
19004 Software FPU with pure-endian doubles.
19005 @item vfp
19006 VFP co-processor.
19007 @end table
19008
19009 @item show arm fpu
19010 Show the current type of the FPU.
19011
19012 @item set arm abi
19013 This command forces @value{GDBN} to use the specified ABI.
19014
19015 @item show arm abi
19016 Show the currently used ABI.
19017
19018 @item set arm fallback-mode (arm|thumb|auto)
19019 @value{GDBN} uses the symbol table, when available, to determine
19020 whether instructions are ARM or Thumb. This command controls
19021 @value{GDBN}'s default behavior when the symbol table is not
19022 available. The default is @samp{auto}, which causes @value{GDBN} to
19023 use the current execution mode (from the @code{T} bit in the @code{CPSR}
19024 register).
19025
19026 @item show arm fallback-mode
19027 Show the current fallback instruction mode.
19028
19029 @item set arm force-mode (arm|thumb|auto)
19030 This command overrides use of the symbol table to determine whether
19031 instructions are ARM or Thumb. The default is @samp{auto}, which
19032 causes @value{GDBN} to use the symbol table and then the setting
19033 of @samp{set arm fallback-mode}.
19034
19035 @item show arm force-mode
19036 Show the current forced instruction mode.
19037
19038 @item set debug arm
19039 Toggle whether to display ARM-specific debugging messages from the ARM
19040 target support subsystem.
19041
19042 @item show debug arm
19043 Show whether ARM-specific debugging messages are enabled.
19044 @end table
19045
19046 The following commands are available when an ARM target is debugged
19047 using the RDI interface:
19048
19049 @table @code
19050 @item rdilogfile @r{[}@var{file}@r{]}
19051 @kindex rdilogfile
19052 @cindex ADP (Angel Debugger Protocol) logging
19053 Set the filename for the ADP (Angel Debugger Protocol) packet log.
19054 With an argument, sets the log file to the specified @var{file}. With
19055 no argument, show the current log file name. The default log file is
19056 @file{rdi.log}.
19057
19058 @item rdilogenable @r{[}@var{arg}@r{]}
19059 @kindex rdilogenable
19060 Control logging of ADP packets. With an argument of 1 or @code{"yes"}
19061 enables logging, with an argument 0 or @code{"no"} disables it. With
19062 no arguments displays the current setting. When logging is enabled,
19063 ADP packets exchanged between @value{GDBN} and the RDI target device
19064 are logged to a file.
19065
19066 @item set rdiromatzero
19067 @kindex set rdiromatzero
19068 @cindex ROM at zero address, RDI
19069 Tell @value{GDBN} whether the target has ROM at address 0. If on,
19070 vector catching is disabled, so that zero address can be used. If off
19071 (the default), vector catching is enabled. For this command to take
19072 effect, it needs to be invoked prior to the @code{target rdi} command.
19073
19074 @item show rdiromatzero
19075 @kindex show rdiromatzero
19076 Show the current setting of ROM at zero address.
19077
19078 @item set rdiheartbeat
19079 @kindex set rdiheartbeat
19080 @cindex RDI heartbeat
19081 Enable or disable RDI heartbeat packets. It is not recommended to
19082 turn on this option, since it confuses ARM and EPI JTAG interface, as
19083 well as the Angel monitor.
19084
19085 @item show rdiheartbeat
19086 @kindex show rdiheartbeat
19087 Show the setting of RDI heartbeat packets.
19088 @end table
19089
19090 @table @code
19091 @item target sim @r{[}@var{simargs}@r{]} @dots{}
19092 The @value{GDBN} ARM simulator accepts the following optional arguments.
19093
19094 @table @code
19095 @item --swi-support=@var{type}
19096 Tell the simulator which SWI interfaces to support.
19097 @var{type} may be a comma separated list of the following values.
19098 The default value is @code{all}.
19099
19100 @table @code
19101 @item none
19102 @item demon
19103 @item angel
19104 @item redboot
19105 @item all
19106 @end table
19107 @end table
19108 @end table
19109
19110 @node M32R/D
19111 @subsection Renesas M32R/D and M32R/SDI
19112
19113 @table @code
19114 @kindex target m32r
19115 @item target m32r @var{dev}
19116 Renesas M32R/D ROM monitor.
19117
19118 @kindex target m32rsdi
19119 @item target m32rsdi @var{dev}
19120 Renesas M32R SDI server, connected via parallel port to the board.
19121 @end table
19122
19123 The following @value{GDBN} commands are specific to the M32R monitor:
19124
19125 @table @code
19126 @item set download-path @var{path}
19127 @kindex set download-path
19128 @cindex find downloadable @sc{srec} files (M32R)
19129 Set the default path for finding downloadable @sc{srec} files.
19130
19131 @item show download-path
19132 @kindex show download-path
19133 Show the default path for downloadable @sc{srec} files.
19134
19135 @item set board-address @var{addr}
19136 @kindex set board-address
19137 @cindex M32-EVA target board address
19138 Set the IP address for the M32R-EVA target board.
19139
19140 @item show board-address
19141 @kindex show board-address
19142 Show the current IP address of the target board.
19143
19144 @item set server-address @var{addr}
19145 @kindex set server-address
19146 @cindex download server address (M32R)
19147 Set the IP address for the download server, which is the @value{GDBN}'s
19148 host machine.
19149
19150 @item show server-address
19151 @kindex show server-address
19152 Display the IP address of the download server.
19153
19154 @item upload @r{[}@var{file}@r{]}
19155 @kindex upload@r{, M32R}
19156 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
19157 upload capability. If no @var{file} argument is given, the current
19158 executable file is uploaded.
19159
19160 @item tload @r{[}@var{file}@r{]}
19161 @kindex tload@r{, M32R}
19162 Test the @code{upload} command.
19163 @end table
19164
19165 The following commands are available for M32R/SDI:
19166
19167 @table @code
19168 @item sdireset
19169 @kindex sdireset
19170 @cindex reset SDI connection, M32R
19171 This command resets the SDI connection.
19172
19173 @item sdistatus
19174 @kindex sdistatus
19175 This command shows the SDI connection status.
19176
19177 @item debug_chaos
19178 @kindex debug_chaos
19179 @cindex M32R/Chaos debugging
19180 Instructs the remote that M32R/Chaos debugging is to be used.
19181
19182 @item use_debug_dma
19183 @kindex use_debug_dma
19184 Instructs the remote to use the DEBUG_DMA method of accessing memory.
19185
19186 @item use_mon_code
19187 @kindex use_mon_code
19188 Instructs the remote to use the MON_CODE method of accessing memory.
19189
19190 @item use_ib_break
19191 @kindex use_ib_break
19192 Instructs the remote to set breakpoints by IB break.
19193
19194 @item use_dbt_break
19195 @kindex use_dbt_break
19196 Instructs the remote to set breakpoints by DBT.
19197 @end table
19198
19199 @node M68K
19200 @subsection M68k
19201
19202 The Motorola m68k configuration includes ColdFire support, and a
19203 target command for the following ROM monitor.
19204
19205 @table @code
19206
19207 @kindex target dbug
19208 @item target dbug @var{dev}
19209 dBUG ROM monitor for Motorola ColdFire.
19210
19211 @end table
19212
19213 @node MicroBlaze
19214 @subsection MicroBlaze
19215 @cindex Xilinx MicroBlaze
19216 @cindex XMD, Xilinx Microprocessor Debugger
19217
19218 The MicroBlaze is a soft-core processor supported on various Xilinx
19219 FPGAs, such as Spartan or Virtex series. Boards with these processors
19220 usually have JTAG ports which connect to a host system running the Xilinx
19221 Embedded Development Kit (EDK) or Software Development Kit (SDK).
19222 This host system is used to download the configuration bitstream to
19223 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
19224 communicates with the target board using the JTAG interface and
19225 presents a @code{gdbserver} interface to the board. By default
19226 @code{xmd} uses port @code{1234}. (While it is possible to change
19227 this default port, it requires the use of undocumented @code{xmd}
19228 commands. Contact Xilinx support if you need to do this.)
19229
19230 Use these GDB commands to connect to the MicroBlaze target processor.
19231
19232 @table @code
19233 @item target remote :1234
19234 Use this command to connect to the target if you are running @value{GDBN}
19235 on the same system as @code{xmd}.
19236
19237 @item target remote @var{xmd-host}:1234
19238 Use this command to connect to the target if it is connected to @code{xmd}
19239 running on a different system named @var{xmd-host}.
19240
19241 @item load
19242 Use this command to download a program to the MicroBlaze target.
19243
19244 @item set debug microblaze @var{n}
19245 Enable MicroBlaze-specific debugging messages if non-zero.
19246
19247 @item show debug microblaze @var{n}
19248 Show MicroBlaze-specific debugging level.
19249 @end table
19250
19251 @node MIPS Embedded
19252 @subsection MIPS Embedded
19253
19254 @cindex MIPS boards
19255 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
19256 MIPS board attached to a serial line. This is available when
19257 you configure @value{GDBN} with @samp{--target=mips-elf}.
19258
19259 @need 1000
19260 Use these @value{GDBN} commands to specify the connection to your target board:
19261
19262 @table @code
19263 @item target mips @var{port}
19264 @kindex target mips @var{port}
19265 To run a program on the board, start up @code{@value{GDBP}} with the
19266 name of your program as the argument. To connect to the board, use the
19267 command @samp{target mips @var{port}}, where @var{port} is the name of
19268 the serial port connected to the board. If the program has not already
19269 been downloaded to the board, you may use the @code{load} command to
19270 download it. You can then use all the usual @value{GDBN} commands.
19271
19272 For example, this sequence connects to the target board through a serial
19273 port, and loads and runs a program called @var{prog} through the
19274 debugger:
19275
19276 @smallexample
19277 host$ @value{GDBP} @var{prog}
19278 @value{GDBN} is free software and @dots{}
19279 (@value{GDBP}) target mips /dev/ttyb
19280 (@value{GDBP}) load @var{prog}
19281 (@value{GDBP}) run
19282 @end smallexample
19283
19284 @item target mips @var{hostname}:@var{portnumber}
19285 On some @value{GDBN} host configurations, you can specify a TCP
19286 connection (for instance, to a serial line managed by a terminal
19287 concentrator) instead of a serial port, using the syntax
19288 @samp{@var{hostname}:@var{portnumber}}.
19289
19290 @item target pmon @var{port}
19291 @kindex target pmon @var{port}
19292 PMON ROM monitor.
19293
19294 @item target ddb @var{port}
19295 @kindex target ddb @var{port}
19296 NEC's DDB variant of PMON for Vr4300.
19297
19298 @item target lsi @var{port}
19299 @kindex target lsi @var{port}
19300 LSI variant of PMON.
19301
19302 @kindex target r3900
19303 @item target r3900 @var{dev}
19304 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
19305
19306 @kindex target array
19307 @item target array @var{dev}
19308 Array Tech LSI33K RAID controller board.
19309
19310 @end table
19311
19312
19313 @noindent
19314 @value{GDBN} also supports these special commands for MIPS targets:
19315
19316 @table @code
19317 @item set mipsfpu double
19318 @itemx set mipsfpu single
19319 @itemx set mipsfpu none
19320 @itemx set mipsfpu auto
19321 @itemx show mipsfpu
19322 @kindex set mipsfpu
19323 @kindex show mipsfpu
19324 @cindex MIPS remote floating point
19325 @cindex floating point, MIPS remote
19326 If your target board does not support the MIPS floating point
19327 coprocessor, you should use the command @samp{set mipsfpu none} (if you
19328 need this, you may wish to put the command in your @value{GDBN} init
19329 file). This tells @value{GDBN} how to find the return value of
19330 functions which return floating point values. It also allows
19331 @value{GDBN} to avoid saving the floating point registers when calling
19332 functions on the board. If you are using a floating point coprocessor
19333 with only single precision floating point support, as on the @sc{r4650}
19334 processor, use the command @samp{set mipsfpu single}. The default
19335 double precision floating point coprocessor may be selected using
19336 @samp{set mipsfpu double}.
19337
19338 In previous versions the only choices were double precision or no
19339 floating point, so @samp{set mipsfpu on} will select double precision
19340 and @samp{set mipsfpu off} will select no floating point.
19341
19342 As usual, you can inquire about the @code{mipsfpu} variable with
19343 @samp{show mipsfpu}.
19344
19345 @item set timeout @var{seconds}
19346 @itemx set retransmit-timeout @var{seconds}
19347 @itemx show timeout
19348 @itemx show retransmit-timeout
19349 @cindex @code{timeout}, MIPS protocol
19350 @cindex @code{retransmit-timeout}, MIPS protocol
19351 @kindex set timeout
19352 @kindex show timeout
19353 @kindex set retransmit-timeout
19354 @kindex show retransmit-timeout
19355 You can control the timeout used while waiting for a packet, in the MIPS
19356 remote protocol, with the @code{set timeout @var{seconds}} command. The
19357 default is 5 seconds. Similarly, you can control the timeout used while
19358 waiting for an acknowledgment of a packet with the @code{set
19359 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
19360 You can inspect both values with @code{show timeout} and @code{show
19361 retransmit-timeout}. (These commands are @emph{only} available when
19362 @value{GDBN} is configured for @samp{--target=mips-elf}.)
19363
19364 The timeout set by @code{set timeout} does not apply when @value{GDBN}
19365 is waiting for your program to stop. In that case, @value{GDBN} waits
19366 forever because it has no way of knowing how long the program is going
19367 to run before stopping.
19368
19369 @item set syn-garbage-limit @var{num}
19370 @kindex set syn-garbage-limit@r{, MIPS remote}
19371 @cindex synchronize with remote MIPS target
19372 Limit the maximum number of characters @value{GDBN} should ignore when
19373 it tries to synchronize with the remote target. The default is 10
19374 characters. Setting the limit to -1 means there's no limit.
19375
19376 @item show syn-garbage-limit
19377 @kindex show syn-garbage-limit@r{, MIPS remote}
19378 Show the current limit on the number of characters to ignore when
19379 trying to synchronize with the remote system.
19380
19381 @item set monitor-prompt @var{prompt}
19382 @kindex set monitor-prompt@r{, MIPS remote}
19383 @cindex remote monitor prompt
19384 Tell @value{GDBN} to expect the specified @var{prompt} string from the
19385 remote monitor. The default depends on the target:
19386 @table @asis
19387 @item pmon target
19388 @samp{PMON}
19389 @item ddb target
19390 @samp{NEC010}
19391 @item lsi target
19392 @samp{PMON>}
19393 @end table
19394
19395 @item show monitor-prompt
19396 @kindex show monitor-prompt@r{, MIPS remote}
19397 Show the current strings @value{GDBN} expects as the prompt from the
19398 remote monitor.
19399
19400 @item set monitor-warnings
19401 @kindex set monitor-warnings@r{, MIPS remote}
19402 Enable or disable monitor warnings about hardware breakpoints. This
19403 has effect only for the @code{lsi} target. When on, @value{GDBN} will
19404 display warning messages whose codes are returned by the @code{lsi}
19405 PMON monitor for breakpoint commands.
19406
19407 @item show monitor-warnings
19408 @kindex show monitor-warnings@r{, MIPS remote}
19409 Show the current setting of printing monitor warnings.
19410
19411 @item pmon @var{command}
19412 @kindex pmon@r{, MIPS remote}
19413 @cindex send PMON command
19414 This command allows sending an arbitrary @var{command} string to the
19415 monitor. The monitor must be in debug mode for this to work.
19416 @end table
19417
19418 @node OpenRISC 1000
19419 @subsection OpenRISC 1000
19420 @cindex OpenRISC 1000
19421
19422 @cindex or1k boards
19423 See OR1k Architecture document (@uref{www.opencores.org}) for more information
19424 about platform and commands.
19425
19426 @table @code
19427
19428 @kindex target jtag
19429 @item target jtag jtag://@var{host}:@var{port}
19430
19431 Connects to remote JTAG server.
19432 JTAG remote server can be either an or1ksim or JTAG server,
19433 connected via parallel port to the board.
19434
19435 Example: @code{target jtag jtag://localhost:9999}
19436
19437 @kindex or1ksim
19438 @item or1ksim @var{command}
19439 If connected to @code{or1ksim} OpenRISC 1000 Architectural
19440 Simulator, proprietary commands can be executed.
19441
19442 @kindex info or1k spr
19443 @item info or1k spr
19444 Displays spr groups.
19445
19446 @item info or1k spr @var{group}
19447 @itemx info or1k spr @var{groupno}
19448 Displays register names in selected group.
19449
19450 @item info or1k spr @var{group} @var{register}
19451 @itemx info or1k spr @var{register}
19452 @itemx info or1k spr @var{groupno} @var{registerno}
19453 @itemx info or1k spr @var{registerno}
19454 Shows information about specified spr register.
19455
19456 @kindex spr
19457 @item spr @var{group} @var{register} @var{value}
19458 @itemx spr @var{register @var{value}}
19459 @itemx spr @var{groupno} @var{registerno @var{value}}
19460 @itemx spr @var{registerno @var{value}}
19461 Writes @var{value} to specified spr register.
19462 @end table
19463
19464 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
19465 It is very similar to @value{GDBN} trace, except it does not interfere with normal
19466 program execution and is thus much faster. Hardware breakpoints/watchpoint
19467 triggers can be set using:
19468 @table @code
19469 @item $LEA/$LDATA
19470 Load effective address/data
19471 @item $SEA/$SDATA
19472 Store effective address/data
19473 @item $AEA/$ADATA
19474 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
19475 @item $FETCH
19476 Fetch data
19477 @end table
19478
19479 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
19480 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
19481
19482 @code{htrace} commands:
19483 @cindex OpenRISC 1000 htrace
19484 @table @code
19485 @kindex hwatch
19486 @item hwatch @var{conditional}
19487 Set hardware watchpoint on combination of Load/Store Effective Address(es)
19488 or Data. For example:
19489
19490 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
19491
19492 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
19493
19494 @kindex htrace
19495 @item htrace info
19496 Display information about current HW trace configuration.
19497
19498 @item htrace trigger @var{conditional}
19499 Set starting criteria for HW trace.
19500
19501 @item htrace qualifier @var{conditional}
19502 Set acquisition qualifier for HW trace.
19503
19504 @item htrace stop @var{conditional}
19505 Set HW trace stopping criteria.
19506
19507 @item htrace record [@var{data}]*
19508 Selects the data to be recorded, when qualifier is met and HW trace was
19509 triggered.
19510
19511 @item htrace enable
19512 @itemx htrace disable
19513 Enables/disables the HW trace.
19514
19515 @item htrace rewind [@var{filename}]
19516 Clears currently recorded trace data.
19517
19518 If filename is specified, new trace file is made and any newly collected data
19519 will be written there.
19520
19521 @item htrace print [@var{start} [@var{len}]]
19522 Prints trace buffer, using current record configuration.
19523
19524 @item htrace mode continuous
19525 Set continuous trace mode.
19526
19527 @item htrace mode suspend
19528 Set suspend trace mode.
19529
19530 @end table
19531
19532 @node PowerPC Embedded
19533 @subsection PowerPC Embedded
19534
19535 @cindex DVC register
19536 @value{GDBN} supports using the DVC (Data Value Compare) register to
19537 implement in hardware simple hardware watchpoint conditions of the form:
19538
19539 @smallexample
19540 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
19541 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
19542 @end smallexample
19543
19544 The DVC register will be automatically used when @value{GDBN} detects
19545 such pattern in a condition expression, and the created watchpoint uses one
19546 debug register (either the @code{exact-watchpoints} option is on and the
19547 variable is scalar, or the variable has a length of one byte). This feature
19548 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
19549 or newer.
19550
19551 When running on PowerPC embedded processors, @value{GDBN} automatically uses
19552 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
19553 in which case watchpoints using only one debug register are created when
19554 watching variables of scalar types.
19555
19556 You can create an artificial array to watch an arbitrary memory
19557 region using one of the following commands (@pxref{Expressions}):
19558
19559 @smallexample
19560 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
19561 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
19562 @end smallexample
19563
19564 PowerPC embedded processors support masked watchpoints. See the discussion
19565 about the @code{mask} argument in @ref{Set Watchpoints}.
19566
19567 @cindex ranged breakpoint
19568 PowerPC embedded processors support hardware accelerated
19569 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
19570 the inferior whenever it executes an instruction at any address within
19571 the range it specifies. To set a ranged breakpoint in @value{GDBN},
19572 use the @code{break-range} command.
19573
19574 @value{GDBN} provides the following PowerPC-specific commands:
19575
19576 @table @code
19577 @kindex break-range
19578 @item break-range @var{start-location}, @var{end-location}
19579 Set a breakpoint for an address range.
19580 @var{start-location} and @var{end-location} can specify a function name,
19581 a line number, an offset of lines from the current line or from the start
19582 location, or an address of an instruction (see @ref{Specify Location},
19583 for a list of all the possible ways to specify a @var{location}.)
19584 The breakpoint will stop execution of the inferior whenever it
19585 executes an instruction at any address within the specified range,
19586 (including @var{start-location} and @var{end-location}.)
19587
19588 @kindex set powerpc
19589 @item set powerpc soft-float
19590 @itemx show powerpc soft-float
19591 Force @value{GDBN} to use (or not use) a software floating point calling
19592 convention. By default, @value{GDBN} selects the calling convention based
19593 on the selected architecture and the provided executable file.
19594
19595 @item set powerpc vector-abi
19596 @itemx show powerpc vector-abi
19597 Force @value{GDBN} to use the specified calling convention for vector
19598 arguments and return values. The valid options are @samp{auto};
19599 @samp{generic}, to avoid vector registers even if they are present;
19600 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
19601 registers. By default, @value{GDBN} selects the calling convention
19602 based on the selected architecture and the provided executable file.
19603
19604 @item set powerpc exact-watchpoints
19605 @itemx show powerpc exact-watchpoints
19606 Allow @value{GDBN} to use only one debug register when watching a variable
19607 of scalar type, thus assuming that the variable is accessed through the
19608 address of its first byte.
19609
19610 @kindex target dink32
19611 @item target dink32 @var{dev}
19612 DINK32 ROM monitor.
19613
19614 @kindex target ppcbug
19615 @item target ppcbug @var{dev}
19616 @kindex target ppcbug1
19617 @item target ppcbug1 @var{dev}
19618 PPCBUG ROM monitor for PowerPC.
19619
19620 @kindex target sds
19621 @item target sds @var{dev}
19622 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
19623 @end table
19624
19625 @cindex SDS protocol
19626 The following commands specific to the SDS protocol are supported
19627 by @value{GDBN}:
19628
19629 @table @code
19630 @item set sdstimeout @var{nsec}
19631 @kindex set sdstimeout
19632 Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
19633 default is 2 seconds.
19634
19635 @item show sdstimeout
19636 @kindex show sdstimeout
19637 Show the current value of the SDS timeout.
19638
19639 @item sds @var{command}
19640 @kindex sds@r{, a command}
19641 Send the specified @var{command} string to the SDS monitor.
19642 @end table
19643
19644
19645 @node PA
19646 @subsection HP PA Embedded
19647
19648 @table @code
19649
19650 @kindex target op50n
19651 @item target op50n @var{dev}
19652 OP50N monitor, running on an OKI HPPA board.
19653
19654 @kindex target w89k
19655 @item target w89k @var{dev}
19656 W89K monitor, running on a Winbond HPPA board.
19657
19658 @end table
19659
19660 @node Sparclet
19661 @subsection Tsqware Sparclet
19662
19663 @cindex Sparclet
19664
19665 @value{GDBN} enables developers to debug tasks running on
19666 Sparclet targets from a Unix host.
19667 @value{GDBN} uses code that runs on
19668 both the Unix host and on the Sparclet target. The program
19669 @code{@value{GDBP}} is installed and executed on the Unix host.
19670
19671 @table @code
19672 @item remotetimeout @var{args}
19673 @kindex remotetimeout
19674 @value{GDBN} supports the option @code{remotetimeout}.
19675 This option is set by the user, and @var{args} represents the number of
19676 seconds @value{GDBN} waits for responses.
19677 @end table
19678
19679 @cindex compiling, on Sparclet
19680 When compiling for debugging, include the options @samp{-g} to get debug
19681 information and @samp{-Ttext} to relocate the program to where you wish to
19682 load it on the target. You may also want to add the options @samp{-n} or
19683 @samp{-N} in order to reduce the size of the sections. Example:
19684
19685 @smallexample
19686 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
19687 @end smallexample
19688
19689 You can use @code{objdump} to verify that the addresses are what you intended:
19690
19691 @smallexample
19692 sparclet-aout-objdump --headers --syms prog
19693 @end smallexample
19694
19695 @cindex running, on Sparclet
19696 Once you have set
19697 your Unix execution search path to find @value{GDBN}, you are ready to
19698 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
19699 (or @code{sparclet-aout-gdb}, depending on your installation).
19700
19701 @value{GDBN} comes up showing the prompt:
19702
19703 @smallexample
19704 (gdbslet)
19705 @end smallexample
19706
19707 @menu
19708 * Sparclet File:: Setting the file to debug
19709 * Sparclet Connection:: Connecting to Sparclet
19710 * Sparclet Download:: Sparclet download
19711 * Sparclet Execution:: Running and debugging
19712 @end menu
19713
19714 @node Sparclet File
19715 @subsubsection Setting File to Debug
19716
19717 The @value{GDBN} command @code{file} lets you choose with program to debug.
19718
19719 @smallexample
19720 (gdbslet) file prog
19721 @end smallexample
19722
19723 @need 1000
19724 @value{GDBN} then attempts to read the symbol table of @file{prog}.
19725 @value{GDBN} locates
19726 the file by searching the directories listed in the command search
19727 path.
19728 If the file was compiled with debug information (option @samp{-g}), source
19729 files will be searched as well.
19730 @value{GDBN} locates
19731 the source files by searching the directories listed in the directory search
19732 path (@pxref{Environment, ,Your Program's Environment}).
19733 If it fails
19734 to find a file, it displays a message such as:
19735
19736 @smallexample
19737 prog: No such file or directory.
19738 @end smallexample
19739
19740 When this happens, add the appropriate directories to the search paths with
19741 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
19742 @code{target} command again.
19743
19744 @node Sparclet Connection
19745 @subsubsection Connecting to Sparclet
19746
19747 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
19748 To connect to a target on serial port ``@code{ttya}'', type:
19749
19750 @smallexample
19751 (gdbslet) target sparclet /dev/ttya
19752 Remote target sparclet connected to /dev/ttya
19753 main () at ../prog.c:3
19754 @end smallexample
19755
19756 @need 750
19757 @value{GDBN} displays messages like these:
19758
19759 @smallexample
19760 Connected to ttya.
19761 @end smallexample
19762
19763 @node Sparclet Download
19764 @subsubsection Sparclet Download
19765
19766 @cindex download to Sparclet
19767 Once connected to the Sparclet target,
19768 you can use the @value{GDBN}
19769 @code{load} command to download the file from the host to the target.
19770 The file name and load offset should be given as arguments to the @code{load}
19771 command.
19772 Since the file format is aout, the program must be loaded to the starting
19773 address. You can use @code{objdump} to find out what this value is. The load
19774 offset is an offset which is added to the VMA (virtual memory address)
19775 of each of the file's sections.
19776 For instance, if the program
19777 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
19778 and bss at 0x12010170, in @value{GDBN}, type:
19779
19780 @smallexample
19781 (gdbslet) load prog 0x12010000
19782 Loading section .text, size 0xdb0 vma 0x12010000
19783 @end smallexample
19784
19785 If the code is loaded at a different address then what the program was linked
19786 to, you may need to use the @code{section} and @code{add-symbol-file} commands
19787 to tell @value{GDBN} where to map the symbol table.
19788
19789 @node Sparclet Execution
19790 @subsubsection Running and Debugging
19791
19792 @cindex running and debugging Sparclet programs
19793 You can now begin debugging the task using @value{GDBN}'s execution control
19794 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
19795 manual for the list of commands.
19796
19797 @smallexample
19798 (gdbslet) b main
19799 Breakpoint 1 at 0x12010000: file prog.c, line 3.
19800 (gdbslet) run
19801 Starting program: prog
19802 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
19803 3 char *symarg = 0;
19804 (gdbslet) step
19805 4 char *execarg = "hello!";
19806 (gdbslet)
19807 @end smallexample
19808
19809 @node Sparclite
19810 @subsection Fujitsu Sparclite
19811
19812 @table @code
19813
19814 @kindex target sparclite
19815 @item target sparclite @var{dev}
19816 Fujitsu sparclite boards, used only for the purpose of loading.
19817 You must use an additional command to debug the program.
19818 For example: target remote @var{dev} using @value{GDBN} standard
19819 remote protocol.
19820
19821 @end table
19822
19823 @node Z8000
19824 @subsection Zilog Z8000
19825
19826 @cindex Z8000
19827 @cindex simulator, Z8000
19828 @cindex Zilog Z8000 simulator
19829
19830 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
19831 a Z8000 simulator.
19832
19833 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
19834 unsegmented variant of the Z8000 architecture) or the Z8001 (the
19835 segmented variant). The simulator recognizes which architecture is
19836 appropriate by inspecting the object code.
19837
19838 @table @code
19839 @item target sim @var{args}
19840 @kindex sim
19841 @kindex target sim@r{, with Z8000}
19842 Debug programs on a simulated CPU. If the simulator supports setup
19843 options, specify them via @var{args}.
19844 @end table
19845
19846 @noindent
19847 After specifying this target, you can debug programs for the simulated
19848 CPU in the same style as programs for your host computer; use the
19849 @code{file} command to load a new program image, the @code{run} command
19850 to run your program, and so on.
19851
19852 As well as making available all the usual machine registers
19853 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
19854 additional items of information as specially named registers:
19855
19856 @table @code
19857
19858 @item cycles
19859 Counts clock-ticks in the simulator.
19860
19861 @item insts
19862 Counts instructions run in the simulator.
19863
19864 @item time
19865 Execution time in 60ths of a second.
19866
19867 @end table
19868
19869 You can refer to these values in @value{GDBN} expressions with the usual
19870 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
19871 conditional breakpoint that suspends only after at least 5000
19872 simulated clock ticks.
19873
19874 @node AVR
19875 @subsection Atmel AVR
19876 @cindex AVR
19877
19878 When configured for debugging the Atmel AVR, @value{GDBN} supports the
19879 following AVR-specific commands:
19880
19881 @table @code
19882 @item info io_registers
19883 @kindex info io_registers@r{, AVR}
19884 @cindex I/O registers (Atmel AVR)
19885 This command displays information about the AVR I/O registers. For
19886 each register, @value{GDBN} prints its number and value.
19887 @end table
19888
19889 @node CRIS
19890 @subsection CRIS
19891 @cindex CRIS
19892
19893 When configured for debugging CRIS, @value{GDBN} provides the
19894 following CRIS-specific commands:
19895
19896 @table @code
19897 @item set cris-version @var{ver}
19898 @cindex CRIS version
19899 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
19900 The CRIS version affects register names and sizes. This command is useful in
19901 case autodetection of the CRIS version fails.
19902
19903 @item show cris-version
19904 Show the current CRIS version.
19905
19906 @item set cris-dwarf2-cfi
19907 @cindex DWARF-2 CFI and CRIS
19908 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
19909 Change to @samp{off} when using @code{gcc-cris} whose version is below
19910 @code{R59}.
19911
19912 @item show cris-dwarf2-cfi
19913 Show the current state of using DWARF-2 CFI.
19914
19915 @item set cris-mode @var{mode}
19916 @cindex CRIS mode
19917 Set the current CRIS mode to @var{mode}. It should only be changed when
19918 debugging in guru mode, in which case it should be set to
19919 @samp{guru} (the default is @samp{normal}).
19920
19921 @item show cris-mode
19922 Show the current CRIS mode.
19923 @end table
19924
19925 @node Super-H
19926 @subsection Renesas Super-H
19927 @cindex Super-H
19928
19929 For the Renesas Super-H processor, @value{GDBN} provides these
19930 commands:
19931
19932 @table @code
19933 @item regs
19934 @kindex regs@r{, Super-H}
19935 Show the values of all Super-H registers.
19936
19937 @item set sh calling-convention @var{convention}
19938 @kindex set sh calling-convention
19939 Set the calling-convention used when calling functions from @value{GDBN}.
19940 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
19941 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
19942 convention. If the DWARF-2 information of the called function specifies
19943 that the function follows the Renesas calling convention, the function
19944 is called using the Renesas calling convention. If the calling convention
19945 is set to @samp{renesas}, the Renesas calling convention is always used,
19946 regardless of the DWARF-2 information. This can be used to override the
19947 default of @samp{gcc} if debug information is missing, or the compiler
19948 does not emit the DWARF-2 calling convention entry for a function.
19949
19950 @item show sh calling-convention
19951 @kindex show sh calling-convention
19952 Show the current calling convention setting.
19953
19954 @end table
19955
19956
19957 @node Architectures
19958 @section Architectures
19959
19960 This section describes characteristics of architectures that affect
19961 all uses of @value{GDBN} with the architecture, both native and cross.
19962
19963 @menu
19964 * i386::
19965 * A29K::
19966 * Alpha::
19967 * MIPS::
19968 * HPPA:: HP PA architecture
19969 * SPU:: Cell Broadband Engine SPU architecture
19970 * PowerPC::
19971 @end menu
19972
19973 @node i386
19974 @subsection x86 Architecture-specific Issues
19975
19976 @table @code
19977 @item set struct-convention @var{mode}
19978 @kindex set struct-convention
19979 @cindex struct return convention
19980 @cindex struct/union returned in registers
19981 Set the convention used by the inferior to return @code{struct}s and
19982 @code{union}s from functions to @var{mode}. Possible values of
19983 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
19984 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
19985 are returned on the stack, while @code{"reg"} means that a
19986 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
19987 be returned in a register.
19988
19989 @item show struct-convention
19990 @kindex show struct-convention
19991 Show the current setting of the convention to return @code{struct}s
19992 from functions.
19993 @end table
19994
19995 @node A29K
19996 @subsection A29K
19997
19998 @table @code
19999
20000 @kindex set rstack_high_address
20001 @cindex AMD 29K register stack
20002 @cindex register stack, AMD29K
20003 @item set rstack_high_address @var{address}
20004 On AMD 29000 family processors, registers are saved in a separate
20005 @dfn{register stack}. There is no way for @value{GDBN} to determine the
20006 extent of this stack. Normally, @value{GDBN} just assumes that the
20007 stack is ``large enough''. This may result in @value{GDBN} referencing
20008 memory locations that do not exist. If necessary, you can get around
20009 this problem by specifying the ending address of the register stack with
20010 the @code{set rstack_high_address} command. The argument should be an
20011 address, which you probably want to precede with @samp{0x} to specify in
20012 hexadecimal.
20013
20014 @kindex show rstack_high_address
20015 @item show rstack_high_address
20016 Display the current limit of the register stack, on AMD 29000 family
20017 processors.
20018
20019 @end table
20020
20021 @node Alpha
20022 @subsection Alpha
20023
20024 See the following section.
20025
20026 @node MIPS
20027 @subsection MIPS
20028
20029 @cindex stack on Alpha
20030 @cindex stack on MIPS
20031 @cindex Alpha stack
20032 @cindex MIPS stack
20033 Alpha- and MIPS-based computers use an unusual stack frame, which
20034 sometimes requires @value{GDBN} to search backward in the object code to
20035 find the beginning of a function.
20036
20037 @cindex response time, MIPS debugging
20038 To improve response time (especially for embedded applications, where
20039 @value{GDBN} may be restricted to a slow serial line for this search)
20040 you may want to limit the size of this search, using one of these
20041 commands:
20042
20043 @table @code
20044 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
20045 @item set heuristic-fence-post @var{limit}
20046 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
20047 search for the beginning of a function. A value of @var{0} (the
20048 default) means there is no limit. However, except for @var{0}, the
20049 larger the limit the more bytes @code{heuristic-fence-post} must search
20050 and therefore the longer it takes to run. You should only need to use
20051 this command when debugging a stripped executable.
20052
20053 @item show heuristic-fence-post
20054 Display the current limit.
20055 @end table
20056
20057 @noindent
20058 These commands are available @emph{only} when @value{GDBN} is configured
20059 for debugging programs on Alpha or MIPS processors.
20060
20061 Several MIPS-specific commands are available when debugging MIPS
20062 programs:
20063
20064 @table @code
20065 @item set mips abi @var{arg}
20066 @kindex set mips abi
20067 @cindex set ABI for MIPS
20068 Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
20069 values of @var{arg} are:
20070
20071 @table @samp
20072 @item auto
20073 The default ABI associated with the current binary (this is the
20074 default).
20075 @item o32
20076 @item o64
20077 @item n32
20078 @item n64
20079 @item eabi32
20080 @item eabi64
20081 @end table
20082
20083 @item show mips abi
20084 @kindex show mips abi
20085 Show the MIPS ABI used by @value{GDBN} to debug the inferior.
20086
20087 @item set mipsfpu
20088 @itemx show mipsfpu
20089 @xref{MIPS Embedded, set mipsfpu}.
20090
20091 @item set mips mask-address @var{arg}
20092 @kindex set mips mask-address
20093 @cindex MIPS addresses, masking
20094 This command determines whether the most-significant 32 bits of 64-bit
20095 MIPS addresses are masked off. The argument @var{arg} can be
20096 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
20097 setting, which lets @value{GDBN} determine the correct value.
20098
20099 @item show mips mask-address
20100 @kindex show mips mask-address
20101 Show whether the upper 32 bits of MIPS addresses are masked off or
20102 not.
20103
20104 @item set remote-mips64-transfers-32bit-regs
20105 @kindex set remote-mips64-transfers-32bit-regs
20106 This command controls compatibility with 64-bit MIPS targets that
20107 transfer data in 32-bit quantities. If you have an old MIPS 64 target
20108 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
20109 and 64 bits for other registers, set this option to @samp{on}.
20110
20111 @item show remote-mips64-transfers-32bit-regs
20112 @kindex show remote-mips64-transfers-32bit-regs
20113 Show the current setting of compatibility with older MIPS 64 targets.
20114
20115 @item set debug mips
20116 @kindex set debug mips
20117 This command turns on and off debugging messages for the MIPS-specific
20118 target code in @value{GDBN}.
20119
20120 @item show debug mips
20121 @kindex show debug mips
20122 Show the current setting of MIPS debugging messages.
20123 @end table
20124
20125
20126 @node HPPA
20127 @subsection HPPA
20128 @cindex HPPA support
20129
20130 When @value{GDBN} is debugging the HP PA architecture, it provides the
20131 following special commands:
20132
20133 @table @code
20134 @item set debug hppa
20135 @kindex set debug hppa
20136 This command determines whether HPPA architecture-specific debugging
20137 messages are to be displayed.
20138
20139 @item show debug hppa
20140 Show whether HPPA debugging messages are displayed.
20141
20142 @item maint print unwind @var{address}
20143 @kindex maint print unwind@r{, HPPA}
20144 This command displays the contents of the unwind table entry at the
20145 given @var{address}.
20146
20147 @end table
20148
20149
20150 @node SPU
20151 @subsection Cell Broadband Engine SPU architecture
20152 @cindex Cell Broadband Engine
20153 @cindex SPU
20154
20155 When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
20156 it provides the following special commands:
20157
20158 @table @code
20159 @item info spu event
20160 @kindex info spu
20161 Display SPU event facility status. Shows current event mask
20162 and pending event status.
20163
20164 @item info spu signal
20165 Display SPU signal notification facility status. Shows pending
20166 signal-control word and signal notification mode of both signal
20167 notification channels.
20168
20169 @item info spu mailbox
20170 Display SPU mailbox facility status. Shows all pending entries,
20171 in order of processing, in each of the SPU Write Outbound,
20172 SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
20173
20174 @item info spu dma
20175 Display MFC DMA status. Shows all pending commands in the MFC
20176 DMA queue. For each entry, opcode, tag, class IDs, effective
20177 and local store addresses and transfer size are shown.
20178
20179 @item info spu proxydma
20180 Display MFC Proxy-DMA status. Shows all pending commands in the MFC
20181 Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
20182 and local store addresses and transfer size are shown.
20183
20184 @end table
20185
20186 When @value{GDBN} is debugging a combined PowerPC/SPU application
20187 on the Cell Broadband Engine, it provides in addition the following
20188 special commands:
20189
20190 @table @code
20191 @item set spu stop-on-load @var{arg}
20192 @kindex set spu
20193 Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
20194 will give control to the user when a new SPE thread enters its @code{main}
20195 function. The default is @code{off}.
20196
20197 @item show spu stop-on-load
20198 @kindex show spu
20199 Show whether to stop for new SPE threads.
20200
20201 @item set spu auto-flush-cache @var{arg}
20202 Set whether to automatically flush the software-managed cache. When set to
20203 @code{on}, @value{GDBN} will automatically cause the SPE software-managed
20204 cache to be flushed whenever SPE execution stops. This provides a consistent
20205 view of PowerPC memory that is accessed via the cache. If an application
20206 does not use the software-managed cache, this option has no effect.
20207
20208 @item show spu auto-flush-cache
20209 Show whether to automatically flush the software-managed cache.
20210
20211 @end table
20212
20213 @node PowerPC
20214 @subsection PowerPC
20215 @cindex PowerPC architecture
20216
20217 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
20218 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
20219 numbers stored in the floating point registers. These values must be stored
20220 in two consecutive registers, always starting at an even register like
20221 @code{f0} or @code{f2}.
20222
20223 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
20224 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
20225 @code{f2} and @code{f3} for @code{$dl1} and so on.
20226
20227 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
20228 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
20229
20230
20231 @node Controlling GDB
20232 @chapter Controlling @value{GDBN}
20233
20234 You can alter the way @value{GDBN} interacts with you by using the
20235 @code{set} command. For commands controlling how @value{GDBN} displays
20236 data, see @ref{Print Settings, ,Print Settings}. Other settings are
20237 described here.
20238
20239 @menu
20240 * Prompt:: Prompt
20241 * Editing:: Command editing
20242 * Command History:: Command history
20243 * Screen Size:: Screen size
20244 * Numbers:: Numbers
20245 * ABI:: Configuring the current ABI
20246 * Messages/Warnings:: Optional warnings and messages
20247 * Debugging Output:: Optional messages about internal happenings
20248 * Other Misc Settings:: Other Miscellaneous Settings
20249 @end menu
20250
20251 @node Prompt
20252 @section Prompt
20253
20254 @cindex prompt
20255
20256 @value{GDBN} indicates its readiness to read a command by printing a string
20257 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
20258 can change the prompt string with the @code{set prompt} command. For
20259 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
20260 the prompt in one of the @value{GDBN} sessions so that you can always tell
20261 which one you are talking to.
20262
20263 @emph{Note:} @code{set prompt} does not add a space for you after the
20264 prompt you set. This allows you to set a prompt which ends in a space
20265 or a prompt that does not.
20266
20267 @table @code
20268 @kindex set prompt
20269 @item set prompt @var{newprompt}
20270 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
20271
20272 @kindex show prompt
20273 @item show prompt
20274 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
20275 @end table
20276
20277 Versions of @value{GDBN} that ship with Python scripting enabled have
20278 prompt extensions. The commands for interacting with these extensions
20279 are:
20280
20281 @table @code
20282 @kindex set extended-prompt
20283 @item set extended-prompt @var{prompt}
20284 Set an extended prompt that allows for substitutions.
20285 @xref{gdb.prompt}, for a list of escape sequences that can be used for
20286 substitution. Any escape sequences specified as part of the prompt
20287 string are replaced with the corresponding strings each time the prompt
20288 is displayed.
20289
20290 For example:
20291
20292 @smallexample
20293 set extended-prompt Current working directory: \w (gdb)
20294 @end smallexample
20295
20296 Note that when an extended-prompt is set, it takes control of the
20297 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
20298
20299 @kindex show extended-prompt
20300 @item show extended-prompt
20301 Prints the extended prompt. Any escape sequences specified as part of
20302 the prompt string with @code{set extended-prompt}, are replaced with the
20303 corresponding strings each time the prompt is displayed.
20304 @end table
20305
20306 @node Editing
20307 @section Command Editing
20308 @cindex readline
20309 @cindex command line editing
20310
20311 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
20312 @sc{gnu} library provides consistent behavior for programs which provide a
20313 command line interface to the user. Advantages are @sc{gnu} Emacs-style
20314 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
20315 substitution, and a storage and recall of command history across
20316 debugging sessions.
20317
20318 You may control the behavior of command line editing in @value{GDBN} with the
20319 command @code{set}.
20320
20321 @table @code
20322 @kindex set editing
20323 @cindex editing
20324 @item set editing
20325 @itemx set editing on
20326 Enable command line editing (enabled by default).
20327
20328 @item set editing off
20329 Disable command line editing.
20330
20331 @kindex show editing
20332 @item show editing
20333 Show whether command line editing is enabled.
20334 @end table
20335
20336 @ifset SYSTEM_READLINE
20337 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
20338 @end ifset
20339 @ifclear SYSTEM_READLINE
20340 @xref{Command Line Editing},
20341 @end ifclear
20342 for more details about the Readline
20343 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
20344 encouraged to read that chapter.
20345
20346 @node Command History
20347 @section Command History
20348 @cindex command history
20349
20350 @value{GDBN} can keep track of the commands you type during your
20351 debugging sessions, so that you can be certain of precisely what
20352 happened. Use these commands to manage the @value{GDBN} command
20353 history facility.
20354
20355 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
20356 package, to provide the history facility.
20357 @ifset SYSTEM_READLINE
20358 @xref{Using History Interactively, , , history, GNU History Library},
20359 @end ifset
20360 @ifclear SYSTEM_READLINE
20361 @xref{Using History Interactively},
20362 @end ifclear
20363 for the detailed description of the History library.
20364
20365 To issue a command to @value{GDBN} without affecting certain aspects of
20366 the state which is seen by users, prefix it with @samp{server }
20367 (@pxref{Server Prefix}). This
20368 means that this command will not affect the command history, nor will it
20369 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
20370 pressed on a line by itself.
20371
20372 @cindex @code{server}, command prefix
20373 The server prefix does not affect the recording of values into the value
20374 history; to print a value without recording it into the value history,
20375 use the @code{output} command instead of the @code{print} command.
20376
20377 Here is the description of @value{GDBN} commands related to command
20378 history.
20379
20380 @table @code
20381 @cindex history substitution
20382 @cindex history file
20383 @kindex set history filename
20384 @cindex @env{GDBHISTFILE}, environment variable
20385 @item set history filename @var{fname}
20386 Set the name of the @value{GDBN} command history file to @var{fname}.
20387 This is the file where @value{GDBN} reads an initial command history
20388 list, and where it writes the command history from this session when it
20389 exits. You can access this list through history expansion or through
20390 the history command editing characters listed below. This file defaults
20391 to the value of the environment variable @code{GDBHISTFILE}, or to
20392 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
20393 is not set.
20394
20395 @cindex save command history
20396 @kindex set history save
20397 @item set history save
20398 @itemx set history save on
20399 Record command history in a file, whose name may be specified with the
20400 @code{set history filename} command. By default, this option is disabled.
20401
20402 @item set history save off
20403 Stop recording command history in a file.
20404
20405 @cindex history size
20406 @kindex set history size
20407 @cindex @env{HISTSIZE}, environment variable
20408 @item set history size @var{size}
20409 Set the number of commands which @value{GDBN} keeps in its history list.
20410 This defaults to the value of the environment variable
20411 @code{HISTSIZE}, or to 256 if this variable is not set.
20412 @end table
20413
20414 History expansion assigns special meaning to the character @kbd{!}.
20415 @ifset SYSTEM_READLINE
20416 @xref{Event Designators, , , history, GNU History Library},
20417 @end ifset
20418 @ifclear SYSTEM_READLINE
20419 @xref{Event Designators},
20420 @end ifclear
20421 for more details.
20422
20423 @cindex history expansion, turn on/off
20424 Since @kbd{!} is also the logical not operator in C, history expansion
20425 is off by default. If you decide to enable history expansion with the
20426 @code{set history expansion on} command, you may sometimes need to
20427 follow @kbd{!} (when it is used as logical not, in an expression) with
20428 a space or a tab to prevent it from being expanded. The readline
20429 history facilities do not attempt substitution on the strings
20430 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
20431
20432 The commands to control history expansion are:
20433
20434 @table @code
20435 @item set history expansion on
20436 @itemx set history expansion
20437 @kindex set history expansion
20438 Enable history expansion. History expansion is off by default.
20439
20440 @item set history expansion off
20441 Disable history expansion.
20442
20443 @c @group
20444 @kindex show history
20445 @item show history
20446 @itemx show history filename
20447 @itemx show history save
20448 @itemx show history size
20449 @itemx show history expansion
20450 These commands display the state of the @value{GDBN} history parameters.
20451 @code{show history} by itself displays all four states.
20452 @c @end group
20453 @end table
20454
20455 @table @code
20456 @kindex show commands
20457 @cindex show last commands
20458 @cindex display command history
20459 @item show commands
20460 Display the last ten commands in the command history.
20461
20462 @item show commands @var{n}
20463 Print ten commands centered on command number @var{n}.
20464
20465 @item show commands +
20466 Print ten commands just after the commands last printed.
20467 @end table
20468
20469 @node Screen Size
20470 @section Screen Size
20471 @cindex size of screen
20472 @cindex pauses in output
20473
20474 Certain commands to @value{GDBN} may produce large amounts of
20475 information output to the screen. To help you read all of it,
20476 @value{GDBN} pauses and asks you for input at the end of each page of
20477 output. Type @key{RET} when you want to continue the output, or @kbd{q}
20478 to discard the remaining output. Also, the screen width setting
20479 determines when to wrap lines of output. Depending on what is being
20480 printed, @value{GDBN} tries to break the line at a readable place,
20481 rather than simply letting it overflow onto the following line.
20482
20483 Normally @value{GDBN} knows the size of the screen from the terminal
20484 driver software. For example, on Unix @value{GDBN} uses the termcap data base
20485 together with the value of the @code{TERM} environment variable and the
20486 @code{stty rows} and @code{stty cols} settings. If this is not correct,
20487 you can override it with the @code{set height} and @code{set
20488 width} commands:
20489
20490 @table @code
20491 @kindex set height
20492 @kindex set width
20493 @kindex show width
20494 @kindex show height
20495 @item set height @var{lpp}
20496 @itemx show height
20497 @itemx set width @var{cpl}
20498 @itemx show width
20499 These @code{set} commands specify a screen height of @var{lpp} lines and
20500 a screen width of @var{cpl} characters. The associated @code{show}
20501 commands display the current settings.
20502
20503 If you specify a height of zero lines, @value{GDBN} does not pause during
20504 output no matter how long the output is. This is useful if output is to a
20505 file or to an editor buffer.
20506
20507 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
20508 from wrapping its output.
20509
20510 @item set pagination on
20511 @itemx set pagination off
20512 @kindex set pagination
20513 Turn the output pagination on or off; the default is on. Turning
20514 pagination off is the alternative to @code{set height 0}. Note that
20515 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
20516 Options, -batch}) also automatically disables pagination.
20517
20518 @item show pagination
20519 @kindex show pagination
20520 Show the current pagination mode.
20521 @end table
20522
20523 @node Numbers
20524 @section Numbers
20525 @cindex number representation
20526 @cindex entering numbers
20527
20528 You can always enter numbers in octal, decimal, or hexadecimal in
20529 @value{GDBN} by the usual conventions: octal numbers begin with
20530 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
20531 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
20532 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
20533 10; likewise, the default display for numbers---when no particular
20534 format is specified---is base 10. You can change the default base for
20535 both input and output with the commands described below.
20536
20537 @table @code
20538 @kindex set input-radix
20539 @item set input-radix @var{base}
20540 Set the default base for numeric input. Supported choices
20541 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
20542 specified either unambiguously or using the current input radix; for
20543 example, any of
20544
20545 @smallexample
20546 set input-radix 012
20547 set input-radix 10.
20548 set input-radix 0xa
20549 @end smallexample
20550
20551 @noindent
20552 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
20553 leaves the input radix unchanged, no matter what it was, since
20554 @samp{10}, being without any leading or trailing signs of its base, is
20555 interpreted in the current radix. Thus, if the current radix is 16,
20556 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
20557 change the radix.
20558
20559 @kindex set output-radix
20560 @item set output-radix @var{base}
20561 Set the default base for numeric display. Supported choices
20562 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
20563 specified either unambiguously or using the current input radix.
20564
20565 @kindex show input-radix
20566 @item show input-radix
20567 Display the current default base for numeric input.
20568
20569 @kindex show output-radix
20570 @item show output-radix
20571 Display the current default base for numeric display.
20572
20573 @item set radix @r{[}@var{base}@r{]}
20574 @itemx show radix
20575 @kindex set radix
20576 @kindex show radix
20577 These commands set and show the default base for both input and output
20578 of numbers. @code{set radix} sets the radix of input and output to
20579 the same base; without an argument, it resets the radix back to its
20580 default value of 10.
20581
20582 @end table
20583
20584 @node ABI
20585 @section Configuring the Current ABI
20586
20587 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
20588 application automatically. However, sometimes you need to override its
20589 conclusions. Use these commands to manage @value{GDBN}'s view of the
20590 current ABI.
20591
20592 @cindex OS ABI
20593 @kindex set osabi
20594 @kindex show osabi
20595
20596 One @value{GDBN} configuration can debug binaries for multiple operating
20597 system targets, either via remote debugging or native emulation.
20598 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
20599 but you can override its conclusion using the @code{set osabi} command.
20600 One example where this is useful is in debugging of binaries which use
20601 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
20602 not have the same identifying marks that the standard C library for your
20603 platform provides.
20604
20605 @table @code
20606 @item show osabi
20607 Show the OS ABI currently in use.
20608
20609 @item set osabi
20610 With no argument, show the list of registered available OS ABI's.
20611
20612 @item set osabi @var{abi}
20613 Set the current OS ABI to @var{abi}.
20614 @end table
20615
20616 @cindex float promotion
20617
20618 Generally, the way that an argument of type @code{float} is passed to a
20619 function depends on whether the function is prototyped. For a prototyped
20620 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
20621 according to the architecture's convention for @code{float}. For unprototyped
20622 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
20623 @code{double} and then passed.
20624
20625 Unfortunately, some forms of debug information do not reliably indicate whether
20626 a function is prototyped. If @value{GDBN} calls a function that is not marked
20627 as prototyped, it consults @kbd{set coerce-float-to-double}.
20628
20629 @table @code
20630 @kindex set coerce-float-to-double
20631 @item set coerce-float-to-double
20632 @itemx set coerce-float-to-double on
20633 Arguments of type @code{float} will be promoted to @code{double} when passed
20634 to an unprototyped function. This is the default setting.
20635
20636 @item set coerce-float-to-double off
20637 Arguments of type @code{float} will be passed directly to unprototyped
20638 functions.
20639
20640 @kindex show coerce-float-to-double
20641 @item show coerce-float-to-double
20642 Show the current setting of promoting @code{float} to @code{double}.
20643 @end table
20644
20645 @kindex set cp-abi
20646 @kindex show cp-abi
20647 @value{GDBN} needs to know the ABI used for your program's C@t{++}
20648 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
20649 used to build your application. @value{GDBN} only fully supports
20650 programs with a single C@t{++} ABI; if your program contains code using
20651 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
20652 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
20653 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
20654 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
20655 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
20656 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
20657 ``auto''.
20658
20659 @table @code
20660 @item show cp-abi
20661 Show the C@t{++} ABI currently in use.
20662
20663 @item set cp-abi
20664 With no argument, show the list of supported C@t{++} ABI's.
20665
20666 @item set cp-abi @var{abi}
20667 @itemx set cp-abi auto
20668 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
20669 @end table
20670
20671 @node Messages/Warnings
20672 @section Optional Warnings and Messages
20673
20674 @cindex verbose operation
20675 @cindex optional warnings
20676 By default, @value{GDBN} is silent about its inner workings. If you are
20677 running on a slow machine, you may want to use the @code{set verbose}
20678 command. This makes @value{GDBN} tell you when it does a lengthy
20679 internal operation, so you will not think it has crashed.
20680
20681 Currently, the messages controlled by @code{set verbose} are those
20682 which announce that the symbol table for a source file is being read;
20683 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
20684
20685 @table @code
20686 @kindex set verbose
20687 @item set verbose on
20688 Enables @value{GDBN} output of certain informational messages.
20689
20690 @item set verbose off
20691 Disables @value{GDBN} output of certain informational messages.
20692
20693 @kindex show verbose
20694 @item show verbose
20695 Displays whether @code{set verbose} is on or off.
20696 @end table
20697
20698 By default, if @value{GDBN} encounters bugs in the symbol table of an
20699 object file, it is silent; but if you are debugging a compiler, you may
20700 find this information useful (@pxref{Symbol Errors, ,Errors Reading
20701 Symbol Files}).
20702
20703 @table @code
20704
20705 @kindex set complaints
20706 @item set complaints @var{limit}
20707 Permits @value{GDBN} to output @var{limit} complaints about each type of
20708 unusual symbols before becoming silent about the problem. Set
20709 @var{limit} to zero to suppress all complaints; set it to a large number
20710 to prevent complaints from being suppressed.
20711
20712 @kindex show complaints
20713 @item show complaints
20714 Displays how many symbol complaints @value{GDBN} is permitted to produce.
20715
20716 @end table
20717
20718 @anchor{confirmation requests}
20719 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
20720 lot of stupid questions to confirm certain commands. For example, if
20721 you try to run a program which is already running:
20722
20723 @smallexample
20724 (@value{GDBP}) run
20725 The program being debugged has been started already.
20726 Start it from the beginning? (y or n)
20727 @end smallexample
20728
20729 If you are willing to unflinchingly face the consequences of your own
20730 commands, you can disable this ``feature'':
20731
20732 @table @code
20733
20734 @kindex set confirm
20735 @cindex flinching
20736 @cindex confirmation
20737 @cindex stupid questions
20738 @item set confirm off
20739 Disables confirmation requests. Note that running @value{GDBN} with
20740 the @option{--batch} option (@pxref{Mode Options, -batch}) also
20741 automatically disables confirmation requests.
20742
20743 @item set confirm on
20744 Enables confirmation requests (the default).
20745
20746 @kindex show confirm
20747 @item show confirm
20748 Displays state of confirmation requests.
20749
20750 @end table
20751
20752 @cindex command tracing
20753 If you need to debug user-defined commands or sourced files you may find it
20754 useful to enable @dfn{command tracing}. In this mode each command will be
20755 printed as it is executed, prefixed with one or more @samp{+} symbols, the
20756 quantity denoting the call depth of each command.
20757
20758 @table @code
20759 @kindex set trace-commands
20760 @cindex command scripts, debugging
20761 @item set trace-commands on
20762 Enable command tracing.
20763 @item set trace-commands off
20764 Disable command tracing.
20765 @item show trace-commands
20766 Display the current state of command tracing.
20767 @end table
20768
20769 @node Debugging Output
20770 @section Optional Messages about Internal Happenings
20771 @cindex optional debugging messages
20772
20773 @value{GDBN} has commands that enable optional debugging messages from
20774 various @value{GDBN} subsystems; normally these commands are of
20775 interest to @value{GDBN} maintainers, or when reporting a bug. This
20776 section documents those commands.
20777
20778 @table @code
20779 @kindex set exec-done-display
20780 @item set exec-done-display
20781 Turns on or off the notification of asynchronous commands'
20782 completion. When on, @value{GDBN} will print a message when an
20783 asynchronous command finishes its execution. The default is off.
20784 @kindex show exec-done-display
20785 @item show exec-done-display
20786 Displays the current setting of asynchronous command completion
20787 notification.
20788 @kindex set debug
20789 @cindex gdbarch debugging info
20790 @cindex architecture debugging info
20791 @item set debug arch
20792 Turns on or off display of gdbarch debugging info. The default is off
20793 @kindex show debug
20794 @item show debug arch
20795 Displays the current state of displaying gdbarch debugging info.
20796 @item set debug aix-thread
20797 @cindex AIX threads
20798 Display debugging messages about inner workings of the AIX thread
20799 module.
20800 @item show debug aix-thread
20801 Show the current state of AIX thread debugging info display.
20802 @item set debug check-physname
20803 @cindex physname
20804 Check the results of the ``physname'' computation. When reading DWARF
20805 debugging information for C@t{++}, @value{GDBN} attempts to compute
20806 each entity's name. @value{GDBN} can do this computation in two
20807 different ways, depending on exactly what information is present.
20808 When enabled, this setting causes @value{GDBN} to compute the names
20809 both ways and display any discrepancies.
20810 @item show debug check-physname
20811 Show the current state of ``physname'' checking.
20812 @item set debug dwarf2-die
20813 @cindex DWARF2 DIEs
20814 Dump DWARF2 DIEs after they are read in.
20815 The value is the number of nesting levels to print.
20816 A value of zero turns off the display.
20817 @item show debug dwarf2-die
20818 Show the current state of DWARF2 DIE debugging.
20819 @item set debug displaced
20820 @cindex displaced stepping debugging info
20821 Turns on or off display of @value{GDBN} debugging info for the
20822 displaced stepping support. The default is off.
20823 @item show debug displaced
20824 Displays the current state of displaying @value{GDBN} debugging info
20825 related to displaced stepping.
20826 @item set debug event
20827 @cindex event debugging info
20828 Turns on or off display of @value{GDBN} event debugging info. The
20829 default is off.
20830 @item show debug event
20831 Displays the current state of displaying @value{GDBN} event debugging
20832 info.
20833 @item set debug expression
20834 @cindex expression debugging info
20835 Turns on or off display of debugging info about @value{GDBN}
20836 expression parsing. The default is off.
20837 @item show debug expression
20838 Displays the current state of displaying debugging info about
20839 @value{GDBN} expression parsing.
20840 @item set debug frame
20841 @cindex frame debugging info
20842 Turns on or off display of @value{GDBN} frame debugging info. The
20843 default is off.
20844 @item show debug frame
20845 Displays the current state of displaying @value{GDBN} frame debugging
20846 info.
20847 @item set debug gnu-nat
20848 @cindex @sc{gnu}/Hurd debug messages
20849 Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
20850 @item show debug gnu-nat
20851 Show the current state of @sc{gnu}/Hurd debugging messages.
20852 @item set debug infrun
20853 @cindex inferior debugging info
20854 Turns on or off display of @value{GDBN} debugging info for running the inferior.
20855 The default is off. @file{infrun.c} contains GDB's runtime state machine used
20856 for implementing operations such as single-stepping the inferior.
20857 @item show debug infrun
20858 Displays the current state of @value{GDBN} inferior debugging.
20859 @item set debug jit
20860 @cindex just-in-time compilation, debugging messages
20861 Turns on or off debugging messages from JIT debug support.
20862 @item show debug jit
20863 Displays the current state of @value{GDBN} JIT debugging.
20864 @item set debug lin-lwp
20865 @cindex @sc{gnu}/Linux LWP debug messages
20866 @cindex Linux lightweight processes
20867 Turns on or off debugging messages from the Linux LWP debug support.
20868 @item show debug lin-lwp
20869 Show the current state of Linux LWP debugging messages.
20870 @item set debug observer
20871 @cindex observer debugging info
20872 Turns on or off display of @value{GDBN} observer debugging. This
20873 includes info such as the notification of observable events.
20874 @item show debug observer
20875 Displays the current state of observer debugging.
20876 @item set debug overload
20877 @cindex C@t{++} overload debugging info
20878 Turns on or off display of @value{GDBN} C@t{++} overload debugging
20879 info. This includes info such as ranking of functions, etc. The default
20880 is off.
20881 @item show debug overload
20882 Displays the current state of displaying @value{GDBN} C@t{++} overload
20883 debugging info.
20884 @cindex expression parser, debugging info
20885 @cindex debug expression parser
20886 @item set debug parser
20887 Turns on or off the display of expression parser debugging output.
20888 Internally, this sets the @code{yydebug} variable in the expression
20889 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
20890 details. The default is off.
20891 @item show debug parser
20892 Show the current state of expression parser debugging.
20893 @cindex packets, reporting on stdout
20894 @cindex serial connections, debugging
20895 @cindex debug remote protocol
20896 @cindex remote protocol debugging
20897 @cindex display remote packets
20898 @item set debug remote
20899 Turns on or off display of reports on all packets sent back and forth across
20900 the serial line to the remote machine. The info is printed on the
20901 @value{GDBN} standard output stream. The default is off.
20902 @item show debug remote
20903 Displays the state of display of remote packets.
20904 @item set debug serial
20905 Turns on or off display of @value{GDBN} serial debugging info. The
20906 default is off.
20907 @item show debug serial
20908 Displays the current state of displaying @value{GDBN} serial debugging
20909 info.
20910 @item set debug solib-frv
20911 @cindex FR-V shared-library debugging
20912 Turns on or off debugging messages for FR-V shared-library code.
20913 @item show debug solib-frv
20914 Display the current state of FR-V shared-library code debugging
20915 messages.
20916 @item set debug target
20917 @cindex target debugging info
20918 Turns on or off display of @value{GDBN} target debugging info. This info
20919 includes what is going on at the target level of GDB, as it happens. The
20920 default is 0. Set it to 1 to track events, and to 2 to also track the
20921 value of large memory transfers. Changes to this flag do not take effect
20922 until the next time you connect to a target or use the @code{run} command.
20923 @item show debug target
20924 Displays the current state of displaying @value{GDBN} target debugging
20925 info.
20926 @item set debug timestamp
20927 @cindex timestampping debugging info
20928 Turns on or off display of timestamps with @value{GDBN} debugging info.
20929 When enabled, seconds and microseconds are displayed before each debugging
20930 message.
20931 @item show debug timestamp
20932 Displays the current state of displaying timestamps with @value{GDBN}
20933 debugging info.
20934 @item set debugvarobj
20935 @cindex variable object debugging info
20936 Turns on or off display of @value{GDBN} variable object debugging
20937 info. The default is off.
20938 @item show debugvarobj
20939 Displays the current state of displaying @value{GDBN} variable object
20940 debugging info.
20941 @item set debug xml
20942 @cindex XML parser debugging
20943 Turns on or off debugging messages for built-in XML parsers.
20944 @item show debug xml
20945 Displays the current state of XML debugging messages.
20946 @end table
20947
20948 @node Other Misc Settings
20949 @section Other Miscellaneous Settings
20950 @cindex miscellaneous settings
20951
20952 @table @code
20953 @kindex set interactive-mode
20954 @item set interactive-mode
20955 If @code{on}, forces @value{GDBN} to assume that GDB was started
20956 in a terminal. In practice, this means that @value{GDBN} should wait
20957 for the user to answer queries generated by commands entered at
20958 the command prompt. If @code{off}, forces @value{GDBN} to operate
20959 in the opposite mode, and it uses the default answers to all queries.
20960 If @code{auto} (the default), @value{GDBN} tries to determine whether
20961 its standard input is a terminal, and works in interactive-mode if it
20962 is, non-interactively otherwise.
20963
20964 In the vast majority of cases, the debugger should be able to guess
20965 correctly which mode should be used. But this setting can be useful
20966 in certain specific cases, such as running a MinGW @value{GDBN}
20967 inside a cygwin window.
20968
20969 @kindex show interactive-mode
20970 @item show interactive-mode
20971 Displays whether the debugger is operating in interactive mode or not.
20972 @end table
20973
20974 @node Extending GDB
20975 @chapter Extending @value{GDBN}
20976 @cindex extending GDB
20977
20978 @value{GDBN} provides three mechanisms for extension. The first is based
20979 on composition of @value{GDBN} commands, the second is based on the
20980 Python scripting language, and the third is for defining new aliases of
20981 existing commands.
20982
20983 To facilitate the use of the first two extensions, @value{GDBN} is capable
20984 of evaluating the contents of a file. When doing so, @value{GDBN}
20985 can recognize which scripting language is being used by looking at
20986 the filename extension. Files with an unrecognized filename extension
20987 are always treated as a @value{GDBN} Command Files.
20988 @xref{Command Files,, Command files}.
20989
20990 You can control how @value{GDBN} evaluates these files with the following
20991 setting:
20992
20993 @table @code
20994 @kindex set script-extension
20995 @kindex show script-extension
20996 @item set script-extension off
20997 All scripts are always evaluated as @value{GDBN} Command Files.
20998
20999 @item set script-extension soft
21000 The debugger determines the scripting language based on filename
21001 extension. If this scripting language is supported, @value{GDBN}
21002 evaluates the script using that language. Otherwise, it evaluates
21003 the file as a @value{GDBN} Command File.
21004
21005 @item set script-extension strict
21006 The debugger determines the scripting language based on filename
21007 extension, and evaluates the script using that language. If the
21008 language is not supported, then the evaluation fails.
21009
21010 @item show script-extension
21011 Display the current value of the @code{script-extension} option.
21012
21013 @end table
21014
21015 @menu
21016 * Sequences:: Canned Sequences of Commands
21017 * Python:: Scripting @value{GDBN} using Python
21018 * Aliases:: Creating new spellings of existing commands
21019 @end menu
21020
21021 @node Sequences
21022 @section Canned Sequences of Commands
21023
21024 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
21025 Command Lists}), @value{GDBN} provides two ways to store sequences of
21026 commands for execution as a unit: user-defined commands and command
21027 files.
21028
21029 @menu
21030 * Define:: How to define your own commands
21031 * Hooks:: Hooks for user-defined commands
21032 * Command Files:: How to write scripts of commands to be stored in a file
21033 * Output:: Commands for controlled output
21034 @end menu
21035
21036 @node Define
21037 @subsection User-defined Commands
21038
21039 @cindex user-defined command
21040 @cindex arguments, to user-defined commands
21041 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
21042 which you assign a new name as a command. This is done with the
21043 @code{define} command. User commands may accept up to 10 arguments
21044 separated by whitespace. Arguments are accessed within the user command
21045 via @code{$arg0@dots{}$arg9}. A trivial example:
21046
21047 @smallexample
21048 define adder
21049 print $arg0 + $arg1 + $arg2
21050 end
21051 @end smallexample
21052
21053 @noindent
21054 To execute the command use:
21055
21056 @smallexample
21057 adder 1 2 3
21058 @end smallexample
21059
21060 @noindent
21061 This defines the command @code{adder}, which prints the sum of
21062 its three arguments. Note the arguments are text substitutions, so they may
21063 reference variables, use complex expressions, or even perform inferior
21064 functions calls.
21065
21066 @cindex argument count in user-defined commands
21067 @cindex how many arguments (user-defined commands)
21068 In addition, @code{$argc} may be used to find out how many arguments have
21069 been passed. This expands to a number in the range 0@dots{}10.
21070
21071 @smallexample
21072 define adder
21073 if $argc == 2
21074 print $arg0 + $arg1
21075 end
21076 if $argc == 3
21077 print $arg0 + $arg1 + $arg2
21078 end
21079 end
21080 @end smallexample
21081
21082 @table @code
21083
21084 @kindex define
21085 @item define @var{commandname}
21086 Define a command named @var{commandname}. If there is already a command
21087 by that name, you are asked to confirm that you want to redefine it.
21088 @var{commandname} may be a bare command name consisting of letters,
21089 numbers, dashes, and underscores. It may also start with any predefined
21090 prefix command. For example, @samp{define target my-target} creates
21091 a user-defined @samp{target my-target} command.
21092
21093 The definition of the command is made up of other @value{GDBN} command lines,
21094 which are given following the @code{define} command. The end of these
21095 commands is marked by a line containing @code{end}.
21096
21097 @kindex document
21098 @kindex end@r{ (user-defined commands)}
21099 @item document @var{commandname}
21100 Document the user-defined command @var{commandname}, so that it can be
21101 accessed by @code{help}. The command @var{commandname} must already be
21102 defined. This command reads lines of documentation just as @code{define}
21103 reads the lines of the command definition, ending with @code{end}.
21104 After the @code{document} command is finished, @code{help} on command
21105 @var{commandname} displays the documentation you have written.
21106
21107 You may use the @code{document} command again to change the
21108 documentation of a command. Redefining the command with @code{define}
21109 does not change the documentation.
21110
21111 @kindex dont-repeat
21112 @cindex don't repeat command
21113 @item dont-repeat
21114 Used inside a user-defined command, this tells @value{GDBN} that this
21115 command should not be repeated when the user hits @key{RET}
21116 (@pxref{Command Syntax, repeat last command}).
21117
21118 @kindex help user-defined
21119 @item help user-defined
21120 List all user-defined commands and all python commands defined in class
21121 COMAND_USER. The first line of the documentation or docstring is
21122 included (if any).
21123
21124 @kindex show user
21125 @item show user
21126 @itemx show user @var{commandname}
21127 Display the @value{GDBN} commands used to define @var{commandname} (but
21128 not its documentation). If no @var{commandname} is given, display the
21129 definitions for all user-defined commands.
21130 This does not work for user-defined python commands.
21131
21132 @cindex infinite recursion in user-defined commands
21133 @kindex show max-user-call-depth
21134 @kindex set max-user-call-depth
21135 @item show max-user-call-depth
21136 @itemx set max-user-call-depth
21137 The value of @code{max-user-call-depth} controls how many recursion
21138 levels are allowed in user-defined commands before @value{GDBN} suspects an
21139 infinite recursion and aborts the command.
21140 This does not apply to user-defined python commands.
21141 @end table
21142
21143 In addition to the above commands, user-defined commands frequently
21144 use control flow commands, described in @ref{Command Files}.
21145
21146 When user-defined commands are executed, the
21147 commands of the definition are not printed. An error in any command
21148 stops execution of the user-defined command.
21149
21150 If used interactively, commands that would ask for confirmation proceed
21151 without asking when used inside a user-defined command. Many @value{GDBN}
21152 commands that normally print messages to say what they are doing omit the
21153 messages when used in a user-defined command.
21154
21155 @node Hooks
21156 @subsection User-defined Command Hooks
21157 @cindex command hooks
21158 @cindex hooks, for commands
21159 @cindex hooks, pre-command
21160
21161 @kindex hook
21162 You may define @dfn{hooks}, which are a special kind of user-defined
21163 command. Whenever you run the command @samp{foo}, if the user-defined
21164 command @samp{hook-foo} exists, it is executed (with no arguments)
21165 before that command.
21166
21167 @cindex hooks, post-command
21168 @kindex hookpost
21169 A hook may also be defined which is run after the command you executed.
21170 Whenever you run the command @samp{foo}, if the user-defined command
21171 @samp{hookpost-foo} exists, it is executed (with no arguments) after
21172 that command. Post-execution hooks may exist simultaneously with
21173 pre-execution hooks, for the same command.
21174
21175 It is valid for a hook to call the command which it hooks. If this
21176 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
21177
21178 @c It would be nice if hookpost could be passed a parameter indicating
21179 @c if the command it hooks executed properly or not. FIXME!
21180
21181 @kindex stop@r{, a pseudo-command}
21182 In addition, a pseudo-command, @samp{stop} exists. Defining
21183 (@samp{hook-stop}) makes the associated commands execute every time
21184 execution stops in your program: before breakpoint commands are run,
21185 displays are printed, or the stack frame is printed.
21186
21187 For example, to ignore @code{SIGALRM} signals while
21188 single-stepping, but treat them normally during normal execution,
21189 you could define:
21190
21191 @smallexample
21192 define hook-stop
21193 handle SIGALRM nopass
21194 end
21195
21196 define hook-run
21197 handle SIGALRM pass
21198 end
21199
21200 define hook-continue
21201 handle SIGALRM pass
21202 end
21203 @end smallexample
21204
21205 As a further example, to hook at the beginning and end of the @code{echo}
21206 command, and to add extra text to the beginning and end of the message,
21207 you could define:
21208
21209 @smallexample
21210 define hook-echo
21211 echo <<<---
21212 end
21213
21214 define hookpost-echo
21215 echo --->>>\n
21216 end
21217
21218 (@value{GDBP}) echo Hello World
21219 <<<---Hello World--->>>
21220 (@value{GDBP})
21221
21222 @end smallexample
21223
21224 You can define a hook for any single-word command in @value{GDBN}, but
21225 not for command aliases; you should define a hook for the basic command
21226 name, e.g.@: @code{backtrace} rather than @code{bt}.
21227 @c FIXME! So how does Joe User discover whether a command is an alias
21228 @c or not?
21229 You can hook a multi-word command by adding @code{hook-} or
21230 @code{hookpost-} to the last word of the command, e.g.@:
21231 @samp{define target hook-remote} to add a hook to @samp{target remote}.
21232
21233 If an error occurs during the execution of your hook, execution of
21234 @value{GDBN} commands stops and @value{GDBN} issues a prompt
21235 (before the command that you actually typed had a chance to run).
21236
21237 If you try to define a hook which does not match any known command, you
21238 get a warning from the @code{define} command.
21239
21240 @node Command Files
21241 @subsection Command Files
21242
21243 @cindex command files
21244 @cindex scripting commands
21245 A command file for @value{GDBN} is a text file made of lines that are
21246 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
21247 also be included. An empty line in a command file does nothing; it
21248 does not mean to repeat the last command, as it would from the
21249 terminal.
21250
21251 You can request the execution of a command file with the @code{source}
21252 command. Note that the @code{source} command is also used to evaluate
21253 scripts that are not Command Files. The exact behavior can be configured
21254 using the @code{script-extension} setting.
21255 @xref{Extending GDB,, Extending GDB}.
21256
21257 @table @code
21258 @kindex source
21259 @cindex execute commands from a file
21260 @item source [-s] [-v] @var{filename}
21261 Execute the command file @var{filename}.
21262 @end table
21263
21264 The lines in a command file are generally executed sequentially,
21265 unless the order of execution is changed by one of the
21266 @emph{flow-control commands} described below. The commands are not
21267 printed as they are executed. An error in any command terminates
21268 execution of the command file and control is returned to the console.
21269
21270 @value{GDBN} first searches for @var{filename} in the current directory.
21271 If the file is not found there, and @var{filename} does not specify a
21272 directory, then @value{GDBN} also looks for the file on the source search path
21273 (specified with the @samp{directory} command);
21274 except that @file{$cdir} is not searched because the compilation directory
21275 is not relevant to scripts.
21276
21277 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
21278 on the search path even if @var{filename} specifies a directory.
21279 The search is done by appending @var{filename} to each element of the
21280 search path. So, for example, if @var{filename} is @file{mylib/myscript}
21281 and the search path contains @file{/home/user} then @value{GDBN} will
21282 look for the script @file{/home/user/mylib/myscript}.
21283 The search is also done if @var{filename} is an absolute path.
21284 For example, if @var{filename} is @file{/tmp/myscript} and
21285 the search path contains @file{/home/user} then @value{GDBN} will
21286 look for the script @file{/home/user/tmp/myscript}.
21287 For DOS-like systems, if @var{filename} contains a drive specification,
21288 it is stripped before concatenation. For example, if @var{filename} is
21289 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
21290 will look for the script @file{c:/tmp/myscript}.
21291
21292 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
21293 each command as it is executed. The option must be given before
21294 @var{filename}, and is interpreted as part of the filename anywhere else.
21295
21296 Commands that would ask for confirmation if used interactively proceed
21297 without asking when used in a command file. Many @value{GDBN} commands that
21298 normally print messages to say what they are doing omit the messages
21299 when called from command files.
21300
21301 @value{GDBN} also accepts command input from standard input. In this
21302 mode, normal output goes to standard output and error output goes to
21303 standard error. Errors in a command file supplied on standard input do
21304 not terminate execution of the command file---execution continues with
21305 the next command.
21306
21307 @smallexample
21308 gdb < cmds > log 2>&1
21309 @end smallexample
21310
21311 (The syntax above will vary depending on the shell used.) This example
21312 will execute commands from the file @file{cmds}. All output and errors
21313 would be directed to @file{log}.
21314
21315 Since commands stored on command files tend to be more general than
21316 commands typed interactively, they frequently need to deal with
21317 complicated situations, such as different or unexpected values of
21318 variables and symbols, changes in how the program being debugged is
21319 built, etc. @value{GDBN} provides a set of flow-control commands to
21320 deal with these complexities. Using these commands, you can write
21321 complex scripts that loop over data structures, execute commands
21322 conditionally, etc.
21323
21324 @table @code
21325 @kindex if
21326 @kindex else
21327 @item if
21328 @itemx else
21329 This command allows to include in your script conditionally executed
21330 commands. The @code{if} command takes a single argument, which is an
21331 expression to evaluate. It is followed by a series of commands that
21332 are executed only if the expression is true (its value is nonzero).
21333 There can then optionally be an @code{else} line, followed by a series
21334 of commands that are only executed if the expression was false. The
21335 end of the list is marked by a line containing @code{end}.
21336
21337 @kindex while
21338 @item while
21339 This command allows to write loops. Its syntax is similar to
21340 @code{if}: the command takes a single argument, which is an expression
21341 to evaluate, and must be followed by the commands to execute, one per
21342 line, terminated by an @code{end}. These commands are called the
21343 @dfn{body} of the loop. The commands in the body of @code{while} are
21344 executed repeatedly as long as the expression evaluates to true.
21345
21346 @kindex loop_break
21347 @item loop_break
21348 This command exits the @code{while} loop in whose body it is included.
21349 Execution of the script continues after that @code{while}s @code{end}
21350 line.
21351
21352 @kindex loop_continue
21353 @item loop_continue
21354 This command skips the execution of the rest of the body of commands
21355 in the @code{while} loop in whose body it is included. Execution
21356 branches to the beginning of the @code{while} loop, where it evaluates
21357 the controlling expression.
21358
21359 @kindex end@r{ (if/else/while commands)}
21360 @item end
21361 Terminate the block of commands that are the body of @code{if},
21362 @code{else}, or @code{while} flow-control commands.
21363 @end table
21364
21365
21366 @node Output
21367 @subsection Commands for Controlled Output
21368
21369 During the execution of a command file or a user-defined command, normal
21370 @value{GDBN} output is suppressed; the only output that appears is what is
21371 explicitly printed by the commands in the definition. This section
21372 describes three commands useful for generating exactly the output you
21373 want.
21374
21375 @table @code
21376 @kindex echo
21377 @item echo @var{text}
21378 @c I do not consider backslash-space a standard C escape sequence
21379 @c because it is not in ANSI.
21380 Print @var{text}. Nonprinting characters can be included in
21381 @var{text} using C escape sequences, such as @samp{\n} to print a
21382 newline. @strong{No newline is printed unless you specify one.}
21383 In addition to the standard C escape sequences, a backslash followed
21384 by a space stands for a space. This is useful for displaying a
21385 string with spaces at the beginning or the end, since leading and
21386 trailing spaces are otherwise trimmed from all arguments.
21387 To print @samp{@w{ }and foo =@w{ }}, use the command
21388 @samp{echo \@w{ }and foo = \@w{ }}.
21389
21390 A backslash at the end of @var{text} can be used, as in C, to continue
21391 the command onto subsequent lines. For example,
21392
21393 @smallexample
21394 echo This is some text\n\
21395 which is continued\n\
21396 onto several lines.\n
21397 @end smallexample
21398
21399 produces the same output as
21400
21401 @smallexample
21402 echo This is some text\n
21403 echo which is continued\n
21404 echo onto several lines.\n
21405 @end smallexample
21406
21407 @kindex output
21408 @item output @var{expression}
21409 Print the value of @var{expression} and nothing but that value: no
21410 newlines, no @samp{$@var{nn} = }. The value is not entered in the
21411 value history either. @xref{Expressions, ,Expressions}, for more information
21412 on expressions.
21413
21414 @item output/@var{fmt} @var{expression}
21415 Print the value of @var{expression} in format @var{fmt}. You can use
21416 the same formats as for @code{print}. @xref{Output Formats,,Output
21417 Formats}, for more information.
21418
21419 @kindex printf
21420 @item printf @var{template}, @var{expressions}@dots{}
21421 Print the values of one or more @var{expressions} under the control of
21422 the string @var{template}. To print several values, make
21423 @var{expressions} be a comma-separated list of individual expressions,
21424 which may be either numbers or pointers. Their values are printed as
21425 specified by @var{template}, exactly as a C program would do by
21426 executing the code below:
21427
21428 @smallexample
21429 printf (@var{template}, @var{expressions}@dots{});
21430 @end smallexample
21431
21432 As in @code{C} @code{printf}, ordinary characters in @var{template}
21433 are printed verbatim, while @dfn{conversion specification} introduced
21434 by the @samp{%} character cause subsequent @var{expressions} to be
21435 evaluated, their values converted and formatted according to type and
21436 style information encoded in the conversion specifications, and then
21437 printed.
21438
21439 For example, you can print two values in hex like this:
21440
21441 @smallexample
21442 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
21443 @end smallexample
21444
21445 @code{printf} supports all the standard @code{C} conversion
21446 specifications, including the flags and modifiers between the @samp{%}
21447 character and the conversion letter, with the following exceptions:
21448
21449 @itemize @bullet
21450 @item
21451 The argument-ordering modifiers, such as @samp{2$}, are not supported.
21452
21453 @item
21454 The modifier @samp{*} is not supported for specifying precision or
21455 width.
21456
21457 @item
21458 The @samp{'} flag (for separation of digits into groups according to
21459 @code{LC_NUMERIC'}) is not supported.
21460
21461 @item
21462 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
21463 supported.
21464
21465 @item
21466 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
21467
21468 @item
21469 The conversion letters @samp{a} and @samp{A} are not supported.
21470 @end itemize
21471
21472 @noindent
21473 Note that the @samp{ll} type modifier is supported only if the
21474 underlying @code{C} implementation used to build @value{GDBN} supports
21475 the @code{long long int} type, and the @samp{L} type modifier is
21476 supported only if @code{long double} type is available.
21477
21478 As in @code{C}, @code{printf} supports simple backslash-escape
21479 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
21480 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
21481 single character. Octal and hexadecimal escape sequences are not
21482 supported.
21483
21484 Additionally, @code{printf} supports conversion specifications for DFP
21485 (@dfn{Decimal Floating Point}) types using the following length modifiers
21486 together with a floating point specifier.
21487 letters:
21488
21489 @itemize @bullet
21490 @item
21491 @samp{H} for printing @code{Decimal32} types.
21492
21493 @item
21494 @samp{D} for printing @code{Decimal64} types.
21495
21496 @item
21497 @samp{DD} for printing @code{Decimal128} types.
21498 @end itemize
21499
21500 If the underlying @code{C} implementation used to build @value{GDBN} has
21501 support for the three length modifiers for DFP types, other modifiers
21502 such as width and precision will also be available for @value{GDBN} to use.
21503
21504 In case there is no such @code{C} support, no additional modifiers will be
21505 available and the value will be printed in the standard way.
21506
21507 Here's an example of printing DFP types using the above conversion letters:
21508 @smallexample
21509 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
21510 @end smallexample
21511
21512 @kindex eval
21513 @item eval @var{template}, @var{expressions}@dots{}
21514 Convert the values of one or more @var{expressions} under the control of
21515 the string @var{template} to a command line, and call it.
21516
21517 @end table
21518
21519 @node Python
21520 @section Scripting @value{GDBN} using Python
21521 @cindex python scripting
21522 @cindex scripting with python
21523
21524 You can script @value{GDBN} using the @uref{http://www.python.org/,
21525 Python programming language}. This feature is available only if
21526 @value{GDBN} was configured using @option{--with-python}.
21527
21528 @cindex python directory
21529 Python scripts used by @value{GDBN} should be installed in
21530 @file{@var{data-directory}/python}, where @var{data-directory} is
21531 the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
21532 This directory, known as the @dfn{python directory},
21533 is automatically added to the Python Search Path in order to allow
21534 the Python interpreter to locate all scripts installed at this location.
21535
21536 Additionally, @value{GDBN} commands and convenience functions which
21537 are written in Python and are located in the
21538 @file{@var{data-directory}/python/gdb/command} or
21539 @file{@var{data-directory}/python/gdb/function} directories are
21540 automatically imported when @value{GDBN} starts.
21541
21542 @menu
21543 * Python Commands:: Accessing Python from @value{GDBN}.
21544 * Python API:: Accessing @value{GDBN} from Python.
21545 * Auto-loading:: Automatically loading Python code.
21546 * Python modules:: Python modules provided by @value{GDBN}.
21547 @end menu
21548
21549 @node Python Commands
21550 @subsection Python Commands
21551 @cindex python commands
21552 @cindex commands to access python
21553
21554 @value{GDBN} provides one command for accessing the Python interpreter,
21555 and one related setting:
21556
21557 @table @code
21558 @kindex python
21559 @item python @r{[}@var{code}@r{]}
21560 The @code{python} command can be used to evaluate Python code.
21561
21562 If given an argument, the @code{python} command will evaluate the
21563 argument as a Python command. For example:
21564
21565 @smallexample
21566 (@value{GDBP}) python print 23
21567 23
21568 @end smallexample
21569
21570 If you do not provide an argument to @code{python}, it will act as a
21571 multi-line command, like @code{define}. In this case, the Python
21572 script is made up of subsequent command lines, given after the
21573 @code{python} command. This command list is terminated using a line
21574 containing @code{end}. For example:
21575
21576 @smallexample
21577 (@value{GDBP}) python
21578 Type python script
21579 End with a line saying just "end".
21580 >print 23
21581 >end
21582 23
21583 @end smallexample
21584
21585 @kindex set python print-stack
21586 @item set python print-stack
21587 By default, @value{GDBN} will print only the message component of a
21588 Python exception when an error occurs in a Python script. This can be
21589 controlled using @code{set python print-stack}: if @code{full}, then
21590 full Python stack printing is enabled; if @code{none}, then Python stack
21591 and message printing is disabled; if @code{message}, the default, only
21592 the message component of the error is printed.
21593 @end table
21594
21595 It is also possible to execute a Python script from the @value{GDBN}
21596 interpreter:
21597
21598 @table @code
21599 @item source @file{script-name}
21600 The script name must end with @samp{.py} and @value{GDBN} must be configured
21601 to recognize the script language based on filename extension using
21602 the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
21603
21604 @item python execfile ("script-name")
21605 This method is based on the @code{execfile} Python built-in function,
21606 and thus is always available.
21607 @end table
21608
21609 @node Python API
21610 @subsection Python API
21611 @cindex python api
21612 @cindex programming in python
21613
21614 @cindex python stdout
21615 @cindex python pagination
21616 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
21617 @code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
21618 A Python program which outputs to one of these streams may have its
21619 output interrupted by the user (@pxref{Screen Size}). In this
21620 situation, a Python @code{KeyboardInterrupt} exception is thrown.
21621
21622 @menu
21623 * Basic Python:: Basic Python Functions.
21624 * Exception Handling:: How Python exceptions are translated.
21625 * Values From Inferior:: Python representation of values.
21626 * Types In Python:: Python representation of types.
21627 * Pretty Printing API:: Pretty-printing values.
21628 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
21629 * Writing a Pretty-Printer:: Writing a Pretty-Printer.
21630 * Inferiors In Python:: Python representation of inferiors (processes)
21631 * Events In Python:: Listening for events from @value{GDBN}.
21632 * Threads In Python:: Accessing inferior threads from Python.
21633 * Commands In Python:: Implementing new commands in Python.
21634 * Parameters In Python:: Adding new @value{GDBN} parameters.
21635 * Functions In Python:: Writing new convenience functions.
21636 * Progspaces In Python:: Program spaces.
21637 * Objfiles In Python:: Object files.
21638 * Frames In Python:: Accessing inferior stack frames from Python.
21639 * Blocks In Python:: Accessing frame blocks from Python.
21640 * Symbols In Python:: Python representation of symbols.
21641 * Symbol Tables In Python:: Python representation of symbol tables.
21642 * Lazy Strings In Python:: Python representation of lazy strings.
21643 * Breakpoints In Python:: Manipulating breakpoints using Python.
21644 * Finish Breakpoints in Python:: Setting Breakpoints on function return
21645 using Python.
21646 @end menu
21647
21648 @node Basic Python
21649 @subsubsection Basic Python
21650
21651 @cindex python functions
21652 @cindex python module
21653 @cindex gdb module
21654 @value{GDBN} introduces a new Python module, named @code{gdb}. All
21655 methods and classes added by @value{GDBN} are placed in this module.
21656 @value{GDBN} automatically @code{import}s the @code{gdb} module for
21657 use in all scripts evaluated by the @code{python} command.
21658
21659 @findex gdb.PYTHONDIR
21660 @defvar gdb.PYTHONDIR
21661 A string containing the python directory (@pxref{Python}).
21662 @end defvar
21663
21664 @findex gdb.execute
21665 @defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]})
21666 Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
21667 If a GDB exception happens while @var{command} runs, it is
21668 translated as described in @ref{Exception Handling,,Exception Handling}.
21669
21670 @var{from_tty} specifies whether @value{GDBN} ought to consider this
21671 command as having originated from the user invoking it interactively.
21672 It must be a boolean value. If omitted, it defaults to @code{False}.
21673
21674 By default, any output produced by @var{command} is sent to
21675 @value{GDBN}'s standard output. If the @var{to_string} parameter is
21676 @code{True}, then output will be collected by @code{gdb.execute} and
21677 returned as a string. The default is @code{False}, in which case the
21678 return value is @code{None}. If @var{to_string} is @code{True}, the
21679 @value{GDBN} virtual terminal will be temporarily set to unlimited width
21680 and height, and its pagination will be disabled; @pxref{Screen Size}.
21681 @end defun
21682
21683 @findex gdb.breakpoints
21684 @defun gdb.breakpoints ()
21685 Return a sequence holding all of @value{GDBN}'s breakpoints.
21686 @xref{Breakpoints In Python}, for more information.
21687 @end defun
21688
21689 @findex gdb.parameter
21690 @defun gdb.parameter (parameter)
21691 Return the value of a @value{GDBN} parameter. @var{parameter} is a
21692 string naming the parameter to look up; @var{parameter} may contain
21693 spaces if the parameter has a multi-part name. For example,
21694 @samp{print object} is a valid parameter name.
21695
21696 If the named parameter does not exist, this function throws a
21697 @code{gdb.error} (@pxref{Exception Handling}). Otherwise, the
21698 parameter's value is converted to a Python value of the appropriate
21699 type, and returned.
21700 @end defun
21701
21702 @findex gdb.history
21703 @defun gdb.history (number)
21704 Return a value from @value{GDBN}'s value history (@pxref{Value
21705 History}). @var{number} indicates which history element to return.
21706 If @var{number} is negative, then @value{GDBN} will take its absolute value
21707 and count backward from the last element (i.e., the most recent element) to
21708 find the value to return. If @var{number} is zero, then @value{GDBN} will
21709 return the most recent element. If the element specified by @var{number}
21710 doesn't exist in the value history, a @code{gdb.error} exception will be
21711 raised.
21712
21713 If no exception is raised, the return value is always an instance of
21714 @code{gdb.Value} (@pxref{Values From Inferior}).
21715 @end defun
21716
21717 @findex gdb.parse_and_eval
21718 @defun gdb.parse_and_eval (expression)
21719 Parse @var{expression} as an expression in the current language,
21720 evaluate it, and return the result as a @code{gdb.Value}.
21721 @var{expression} must be a string.
21722
21723 This function can be useful when implementing a new command
21724 (@pxref{Commands In Python}), as it provides a way to parse the
21725 command's argument as an expression. It is also useful simply to
21726 compute values, for example, it is the only way to get the value of a
21727 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
21728 @end defun
21729
21730 @findex gdb.post_event
21731 @defun gdb.post_event (event)
21732 Put @var{event}, a callable object taking no arguments, into
21733 @value{GDBN}'s internal event queue. This callable will be invoked at
21734 some later point, during @value{GDBN}'s event processing. Events
21735 posted using @code{post_event} will be run in the order in which they
21736 were posted; however, there is no way to know when they will be
21737 processed relative to other events inside @value{GDBN}.
21738
21739 @value{GDBN} is not thread-safe. If your Python program uses multiple
21740 threads, you must be careful to only call @value{GDBN}-specific
21741 functions in the main @value{GDBN} thread. @code{post_event} ensures
21742 this. For example:
21743
21744 @smallexample
21745 (@value{GDBP}) python
21746 >import threading
21747 >
21748 >class Writer():
21749 > def __init__(self, message):
21750 > self.message = message;
21751 > def __call__(self):
21752 > gdb.write(self.message)
21753 >
21754 >class MyThread1 (threading.Thread):
21755 > def run (self):
21756 > gdb.post_event(Writer("Hello "))
21757 >
21758 >class MyThread2 (threading.Thread):
21759 > def run (self):
21760 > gdb.post_event(Writer("World\n"))
21761 >
21762 >MyThread1().start()
21763 >MyThread2().start()
21764 >end
21765 (@value{GDBP}) Hello World
21766 @end smallexample
21767 @end defun
21768
21769 @findex gdb.write
21770 @defun gdb.write (string @r{[}, stream{]})
21771 Print a string to @value{GDBN}'s paginated output stream. The
21772 optional @var{stream} determines the stream to print to. The default
21773 stream is @value{GDBN}'s standard output stream. Possible stream
21774 values are:
21775
21776 @table @code
21777 @findex STDOUT
21778 @findex gdb.STDOUT
21779 @item gdb.STDOUT
21780 @value{GDBN}'s standard output stream.
21781
21782 @findex STDERR
21783 @findex gdb.STDERR
21784 @item gdb.STDERR
21785 @value{GDBN}'s standard error stream.
21786
21787 @findex STDLOG
21788 @findex gdb.STDLOG
21789 @item gdb.STDLOG
21790 @value{GDBN}'s log stream (@pxref{Logging Output}).
21791 @end table
21792
21793 Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
21794 call this function and will automatically direct the output to the
21795 relevant stream.
21796 @end defun
21797
21798 @findex gdb.flush
21799 @defun gdb.flush ()
21800 Flush the buffer of a @value{GDBN} paginated stream so that the
21801 contents are displayed immediately. @value{GDBN} will flush the
21802 contents of a stream automatically when it encounters a newline in the
21803 buffer. The optional @var{stream} determines the stream to flush. The
21804 default stream is @value{GDBN}'s standard output stream. Possible
21805 stream values are:
21806
21807 @table @code
21808 @findex STDOUT
21809 @findex gdb.STDOUT
21810 @item gdb.STDOUT
21811 @value{GDBN}'s standard output stream.
21812
21813 @findex STDERR
21814 @findex gdb.STDERR
21815 @item gdb.STDERR
21816 @value{GDBN}'s standard error stream.
21817
21818 @findex STDLOG
21819 @findex gdb.STDLOG
21820 @item gdb.STDLOG
21821 @value{GDBN}'s log stream (@pxref{Logging Output}).
21822
21823 @end table
21824
21825 Flushing @code{sys.stdout} or @code{sys.stderr} will automatically
21826 call this function for the relevant stream.
21827 @end defun
21828
21829 @findex gdb.target_charset
21830 @defun gdb.target_charset ()
21831 Return the name of the current target character set (@pxref{Character
21832 Sets}). This differs from @code{gdb.parameter('target-charset')} in
21833 that @samp{auto} is never returned.
21834 @end defun
21835
21836 @findex gdb.target_wide_charset
21837 @defun gdb.target_wide_charset ()
21838 Return the name of the current target wide character set
21839 (@pxref{Character Sets}). This differs from
21840 @code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
21841 never returned.
21842 @end defun
21843
21844 @findex gdb.solib_name
21845 @defun gdb.solib_name (address)
21846 Return the name of the shared library holding the given @var{address}
21847 as a string, or @code{None}.
21848 @end defun
21849
21850 @findex gdb.decode_line
21851 @defun gdb.decode_line @r{[}expression@r{]}
21852 Return locations of the line specified by @var{expression}, or of the
21853 current line if no argument was given. This function returns a Python
21854 tuple containing two elements. The first element contains a string
21855 holding any unparsed section of @var{expression} (or @code{None} if
21856 the expression has been fully parsed). The second element contains
21857 either @code{None} or another tuple that contains all the locations
21858 that match the expression represented as @code{gdb.Symtab_and_line}
21859 objects (@pxref{Symbol Tables In Python}). If @var{expression} is
21860 provided, it is decoded the way that @value{GDBN}'s inbuilt
21861 @code{break} or @code{edit} commands do (@pxref{Specify Location}).
21862 @end defun
21863
21864 @defun gdb.prompt_hook (current_prompt)
21865 @anchor{prompt_hook}
21866
21867 If @var{prompt_hook} is callable, @value{GDBN} will call the method
21868 assigned to this operation before a prompt is displayed by
21869 @value{GDBN}.
21870
21871 The parameter @code{current_prompt} contains the current @value{GDBN}
21872 prompt. This method must return a Python string, or @code{None}. If
21873 a string is returned, the @value{GDBN} prompt will be set to that
21874 string. If @code{None} is returned, @value{GDBN} will continue to use
21875 the current prompt.
21876
21877 Some prompts cannot be substituted in @value{GDBN}. Secondary prompts
21878 such as those used by readline for command input, and annotation
21879 related prompts are prohibited from being changed.
21880 @end defun
21881
21882 @node Exception Handling
21883 @subsubsection Exception Handling
21884 @cindex python exceptions
21885 @cindex exceptions, python
21886
21887 When executing the @code{python} command, Python exceptions
21888 uncaught within the Python code are translated to calls to
21889 @value{GDBN} error-reporting mechanism. If the command that called
21890 @code{python} does not handle the error, @value{GDBN} will
21891 terminate it and print an error message containing the Python
21892 exception name, the associated value, and the Python call stack
21893 backtrace at the point where the exception was raised. Example:
21894
21895 @smallexample
21896 (@value{GDBP}) python print foo
21897 Traceback (most recent call last):
21898 File "<string>", line 1, in <module>
21899 NameError: name 'foo' is not defined
21900 @end smallexample
21901
21902 @value{GDBN} errors that happen in @value{GDBN} commands invoked by
21903 Python code are converted to Python exceptions. The type of the
21904 Python exception depends on the error.
21905
21906 @ftable @code
21907 @item gdb.error
21908 This is the base class for most exceptions generated by @value{GDBN}.
21909 It is derived from @code{RuntimeError}, for compatibility with earlier
21910 versions of @value{GDBN}.
21911
21912 If an error occurring in @value{GDBN} does not fit into some more
21913 specific category, then the generated exception will have this type.
21914
21915 @item gdb.MemoryError
21916 This is a subclass of @code{gdb.error} which is thrown when an
21917 operation tried to access invalid memory in the inferior.
21918
21919 @item KeyboardInterrupt
21920 User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
21921 prompt) is translated to a Python @code{KeyboardInterrupt} exception.
21922 @end ftable
21923
21924 In all cases, your exception handler will see the @value{GDBN} error
21925 message as its value and the Python call stack backtrace at the Python
21926 statement closest to where the @value{GDBN} error occured as the
21927 traceback.
21928
21929 @findex gdb.GdbError
21930 When implementing @value{GDBN} commands in Python via @code{gdb.Command},
21931 it is useful to be able to throw an exception that doesn't cause a
21932 traceback to be printed. For example, the user may have invoked the
21933 command incorrectly. Use the @code{gdb.GdbError} exception
21934 to handle this case. Example:
21935
21936 @smallexample
21937 (gdb) python
21938 >class HelloWorld (gdb.Command):
21939 > """Greet the whole world."""
21940 > def __init__ (self):
21941 > super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
21942 > def invoke (self, args, from_tty):
21943 > argv = gdb.string_to_argv (args)
21944 > if len (argv) != 0:
21945 > raise gdb.GdbError ("hello-world takes no arguments")
21946 > print "Hello, World!"
21947 >HelloWorld ()
21948 >end
21949 (gdb) hello-world 42
21950 hello-world takes no arguments
21951 @end smallexample
21952
21953 @node Values From Inferior
21954 @subsubsection Values From Inferior
21955 @cindex values from inferior, with Python
21956 @cindex python, working with values from inferior
21957
21958 @cindex @code{gdb.Value}
21959 @value{GDBN} provides values it obtains from the inferior program in
21960 an object of type @code{gdb.Value}. @value{GDBN} uses this object
21961 for its internal bookkeeping of the inferior's values, and for
21962 fetching values when necessary.
21963
21964 Inferior values that are simple scalars can be used directly in
21965 Python expressions that are valid for the value's data type. Here's
21966 an example for an integer or floating-point value @code{some_val}:
21967
21968 @smallexample
21969 bar = some_val + 2
21970 @end smallexample
21971
21972 @noindent
21973 As result of this, @code{bar} will also be a @code{gdb.Value} object
21974 whose values are of the same type as those of @code{some_val}.
21975
21976 Inferior values that are structures or instances of some class can
21977 be accessed using the Python @dfn{dictionary syntax}. For example, if
21978 @code{some_val} is a @code{gdb.Value} instance holding a structure, you
21979 can access its @code{foo} element with:
21980
21981 @smallexample
21982 bar = some_val['foo']
21983 @end smallexample
21984
21985 Again, @code{bar} will also be a @code{gdb.Value} object.
21986
21987 A @code{gdb.Value} that represents a function can be executed via
21988 inferior function call. Any arguments provided to the call must match
21989 the function's prototype, and must be provided in the order specified
21990 by that prototype.
21991
21992 For example, @code{some_val} is a @code{gdb.Value} instance
21993 representing a function that takes two integers as arguments. To
21994 execute this function, call it like so:
21995
21996 @smallexample
21997 result = some_val (10,20)
21998 @end smallexample
21999
22000 Any values returned from a function call will be stored as a
22001 @code{gdb.Value}.
22002
22003 The following attributes are provided:
22004
22005 @table @code
22006 @defvar Value.address
22007 If this object is addressable, this read-only attribute holds a
22008 @code{gdb.Value} object representing the address. Otherwise,
22009 this attribute holds @code{None}.
22010 @end defvar
22011
22012 @cindex optimized out value in Python
22013 @defvar Value.is_optimized_out
22014 This read-only boolean attribute is true if the compiler optimized out
22015 this value, thus it is not available for fetching from the inferior.
22016 @end defvar
22017
22018 @defvar Value.type
22019 The type of this @code{gdb.Value}. The value of this attribute is a
22020 @code{gdb.Type} object (@pxref{Types In Python}).
22021 @end defvar
22022
22023 @defvar Value.dynamic_type
22024 The dynamic type of this @code{gdb.Value}. This uses C@t{++} run-time
22025 type information (@acronym{RTTI}) to determine the dynamic type of the
22026 value. If this value is of class type, it will return the class in
22027 which the value is embedded, if any. If this value is of pointer or
22028 reference to a class type, it will compute the dynamic type of the
22029 referenced object, and return a pointer or reference to that type,
22030 respectively. In all other cases, it will return the value's static
22031 type.
22032
22033 Note that this feature will only work when debugging a C@t{++} program
22034 that includes @acronym{RTTI} for the object in question. Otherwise,
22035 it will just return the static type of the value as in @kbd{ptype foo}
22036 (@pxref{Symbols, ptype}).
22037 @end defvar
22038
22039 @defvar Value.is_lazy
22040 The value of this read-only boolean attribute is @code{True} if this
22041 @code{gdb.Value} has not yet been fetched from the inferior.
22042 @value{GDBN} does not fetch values until necessary, for efficiency.
22043 For example:
22044
22045 @smallexample
22046 myval = gdb.parse_and_eval ('somevar')
22047 @end smallexample
22048
22049 The value of @code{somevar} is not fetched at this time. It will be
22050 fetched when the value is needed, or when the @code{fetch_lazy}
22051 method is invoked.
22052 @end defvar
22053 @end table
22054
22055 The following methods are provided:
22056
22057 @table @code
22058 @defun Value.__init__ (@var{val})
22059 Many Python values can be converted directly to a @code{gdb.Value} via
22060 this object initializer. Specifically:
22061
22062 @table @asis
22063 @item Python boolean
22064 A Python boolean is converted to the boolean type from the current
22065 language.
22066
22067 @item Python integer
22068 A Python integer is converted to the C @code{long} type for the
22069 current architecture.
22070
22071 @item Python long
22072 A Python long is converted to the C @code{long long} type for the
22073 current architecture.
22074
22075 @item Python float
22076 A Python float is converted to the C @code{double} type for the
22077 current architecture.
22078
22079 @item Python string
22080 A Python string is converted to a target string, using the current
22081 target encoding.
22082
22083 @item @code{gdb.Value}
22084 If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
22085
22086 @item @code{gdb.LazyString}
22087 If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
22088 Python}), then the lazy string's @code{value} method is called, and
22089 its result is used.
22090 @end table
22091 @end defun
22092
22093 @defun Value.cast (type)
22094 Return a new instance of @code{gdb.Value} that is the result of
22095 casting this instance to the type described by @var{type}, which must
22096 be a @code{gdb.Type} object. If the cast cannot be performed for some
22097 reason, this method throws an exception.
22098 @end defun
22099
22100 @defun Value.dereference ()
22101 For pointer data types, this method returns a new @code{gdb.Value} object
22102 whose contents is the object pointed to by the pointer. For example, if
22103 @code{foo} is a C pointer to an @code{int}, declared in your C program as
22104
22105 @smallexample
22106 int *foo;
22107 @end smallexample
22108
22109 @noindent
22110 then you can use the corresponding @code{gdb.Value} to access what
22111 @code{foo} points to like this:
22112
22113 @smallexample
22114 bar = foo.dereference ()
22115 @end smallexample
22116
22117 The result @code{bar} will be a @code{gdb.Value} object holding the
22118 value pointed to by @code{foo}.
22119 @end defun
22120
22121 @defun Value.dynamic_cast (type)
22122 Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
22123 operator were used. Consult a C@t{++} reference for details.
22124 @end defun
22125
22126 @defun Value.reinterpret_cast (type)
22127 Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
22128 operator were used. Consult a C@t{++} reference for details.
22129 @end defun
22130
22131 @defun Value.string (@r{[}encoding@r{[}, errors@r{[}, length@r{]]]})
22132 If this @code{gdb.Value} represents a string, then this method
22133 converts the contents to a Python string. Otherwise, this method will
22134 throw an exception.
22135
22136 Strings are recognized in a language-specific way; whether a given
22137 @code{gdb.Value} represents a string is determined by the current
22138 language.
22139
22140 For C-like languages, a value is a string if it is a pointer to or an
22141 array of characters or ints. The string is assumed to be terminated
22142 by a zero of the appropriate width. However if the optional length
22143 argument is given, the string will be converted to that given length,
22144 ignoring any embedded zeros that the string may contain.
22145
22146 If the optional @var{encoding} argument is given, it must be a string
22147 naming the encoding of the string in the @code{gdb.Value}, such as
22148 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
22149 the same encodings as the corresponding argument to Python's
22150 @code{string.decode} method, and the Python codec machinery will be used
22151 to convert the string. If @var{encoding} is not given, or if
22152 @var{encoding} is the empty string, then either the @code{target-charset}
22153 (@pxref{Character Sets}) will be used, or a language-specific encoding
22154 will be used, if the current language is able to supply one.
22155
22156 The optional @var{errors} argument is the same as the corresponding
22157 argument to Python's @code{string.decode} method.
22158
22159 If the optional @var{length} argument is given, the string will be
22160 fetched and converted to the given length.
22161 @end defun
22162
22163 @defun Value.lazy_string (@r{[}encoding @r{[}, length@r{]]})
22164 If this @code{gdb.Value} represents a string, then this method
22165 converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
22166 In Python}). Otherwise, this method will throw an exception.
22167
22168 If the optional @var{encoding} argument is given, it must be a string
22169 naming the encoding of the @code{gdb.LazyString}. Some examples are:
22170 @samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
22171 @var{encoding} argument is an encoding that @value{GDBN} does
22172 recognize, @value{GDBN} will raise an error.
22173
22174 When a lazy string is printed, the @value{GDBN} encoding machinery is
22175 used to convert the string during printing. If the optional
22176 @var{encoding} argument is not provided, or is an empty string,
22177 @value{GDBN} will automatically select the encoding most suitable for
22178 the string type. For further information on encoding in @value{GDBN}
22179 please see @ref{Character Sets}.
22180
22181 If the optional @var{length} argument is given, the string will be
22182 fetched and encoded to the length of characters specified. If
22183 the @var{length} argument is not provided, the string will be fetched
22184 and encoded until a null of appropriate width is found.
22185 @end defun
22186
22187 @defun Value.fetch_lazy ()
22188 If the @code{gdb.Value} object is currently a lazy value
22189 (@code{gdb.Value.is_lazy} is @code{True}), then the value is
22190 fetched from the inferior. Any errors that occur in the process
22191 will produce a Python exception.
22192
22193 If the @code{gdb.Value} object is not a lazy value, this method
22194 has no effect.
22195
22196 This method does not return a value.
22197 @end defun
22198
22199 @end table
22200
22201 @node Types In Python
22202 @subsubsection Types In Python
22203 @cindex types in Python
22204 @cindex Python, working with types
22205
22206 @tindex gdb.Type
22207 @value{GDBN} represents types from the inferior using the class
22208 @code{gdb.Type}.
22209
22210 The following type-related functions are available in the @code{gdb}
22211 module:
22212
22213 @findex gdb.lookup_type
22214 @defun gdb.lookup_type (name @r{[}, block@r{]})
22215 This function looks up a type by name. @var{name} is the name of the
22216 type to look up. It must be a string.
22217
22218 If @var{block} is given, then @var{name} is looked up in that scope.
22219 Otherwise, it is searched for globally.
22220
22221 Ordinarily, this function will return an instance of @code{gdb.Type}.
22222 If the named type cannot be found, it will throw an exception.
22223 @end defun
22224
22225 If the type is a structure or class type, or an enum type, the fields
22226 of that type can be accessed using the Python @dfn{dictionary syntax}.
22227 For example, if @code{some_type} is a @code{gdb.Type} instance holding
22228 a structure type, you can access its @code{foo} field with:
22229
22230 @smallexample
22231 bar = some_type['foo']
22232 @end smallexample
22233
22234 @code{bar} will be a @code{gdb.Field} object; see below under the
22235 description of the @code{Type.fields} method for a description of the
22236 @code{gdb.Field} class.
22237
22238 An instance of @code{Type} has the following attributes:
22239
22240 @table @code
22241 @defvar Type.code
22242 The type code for this type. The type code will be one of the
22243 @code{TYPE_CODE_} constants defined below.
22244 @end defvar
22245
22246 @defvar Type.sizeof
22247 The size of this type, in target @code{char} units. Usually, a
22248 target's @code{char} type will be an 8-bit byte. However, on some
22249 unusual platforms, this type may have a different size.
22250 @end defvar
22251
22252 @defvar Type.tag
22253 The tag name for this type. The tag name is the name after
22254 @code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
22255 languages have this concept. If this type has no tag name, then
22256 @code{None} is returned.
22257 @end defvar
22258 @end table
22259
22260 The following methods are provided:
22261
22262 @table @code
22263 @defun Type.fields ()
22264 For structure and union types, this method returns the fields. Range
22265 types have two fields, the minimum and maximum values. Enum types
22266 have one field per enum constant. Function and method types have one
22267 field per parameter. The base types of C@t{++} classes are also
22268 represented as fields. If the type has no fields, or does not fit
22269 into one of these categories, an empty sequence will be returned.
22270
22271 Each field is a @code{gdb.Field} object, with some pre-defined attributes:
22272 @table @code
22273 @item bitpos
22274 This attribute is not available for @code{static} fields (as in
22275 C@t{++} or Java). For non-@code{static} fields, the value is the bit
22276 position of the field. For @code{enum} fields, the value is the
22277 enumeration member's integer representation.
22278
22279 @item name
22280 The name of the field, or @code{None} for anonymous fields.
22281
22282 @item artificial
22283 This is @code{True} if the field is artificial, usually meaning that
22284 it was provided by the compiler and not the user. This attribute is
22285 always provided, and is @code{False} if the field is not artificial.
22286
22287 @item is_base_class
22288 This is @code{True} if the field represents a base class of a C@t{++}
22289 structure. This attribute is always provided, and is @code{False}
22290 if the field is not a base class of the type that is the argument of
22291 @code{fields}, or if that type was not a C@t{++} class.
22292
22293 @item bitsize
22294 If the field is packed, or is a bitfield, then this will have a
22295 non-zero value, which is the size of the field in bits. Otherwise,
22296 this will be zero; in this case the field's size is given by its type.
22297
22298 @item type
22299 The type of the field. This is usually an instance of @code{Type},
22300 but it can be @code{None} in some situations.
22301 @end table
22302 @end defun
22303
22304 @defun Type.array (@var{n1} @r{[}, @var{n2}@r{]})
22305 Return a new @code{gdb.Type} object which represents an array of this
22306 type. If one argument is given, it is the inclusive upper bound of
22307 the array; in this case the lower bound is zero. If two arguments are
22308 given, the first argument is the lower bound of the array, and the
22309 second argument is the upper bound of the array. An array's length
22310 must not be negative, but the bounds can be.
22311 @end defun
22312
22313 @defun Type.const ()
22314 Return a new @code{gdb.Type} object which represents a
22315 @code{const}-qualified variant of this type.
22316 @end defun
22317
22318 @defun Type.volatile ()
22319 Return a new @code{gdb.Type} object which represents a
22320 @code{volatile}-qualified variant of this type.
22321 @end defun
22322
22323 @defun Type.unqualified ()
22324 Return a new @code{gdb.Type} object which represents an unqualified
22325 variant of this type. That is, the result is neither @code{const} nor
22326 @code{volatile}.
22327 @end defun
22328
22329 @defun Type.range ()
22330 Return a Python @code{Tuple} object that contains two elements: the
22331 low bound of the argument type and the high bound of that type. If
22332 the type does not have a range, @value{GDBN} will raise a
22333 @code{gdb.error} exception (@pxref{Exception Handling}).
22334 @end defun
22335
22336 @defun Type.reference ()
22337 Return a new @code{gdb.Type} object which represents a reference to this
22338 type.
22339 @end defun
22340
22341 @defun Type.pointer ()
22342 Return a new @code{gdb.Type} object which represents a pointer to this
22343 type.
22344 @end defun
22345
22346 @defun Type.strip_typedefs ()
22347 Return a new @code{gdb.Type} that represents the real type,
22348 after removing all layers of typedefs.
22349 @end defun
22350
22351 @defun Type.target ()
22352 Return a new @code{gdb.Type} object which represents the target type
22353 of this type.
22354
22355 For a pointer type, the target type is the type of the pointed-to
22356 object. For an array type (meaning C-like arrays), the target type is
22357 the type of the elements of the array. For a function or method type,
22358 the target type is the type of the return value. For a complex type,
22359 the target type is the type of the elements. For a typedef, the
22360 target type is the aliased type.
22361
22362 If the type does not have a target, this method will throw an
22363 exception.
22364 @end defun
22365
22366 @defun Type.template_argument (n @r{[}, block@r{]})
22367 If this @code{gdb.Type} is an instantiation of a template, this will
22368 return a new @code{gdb.Type} which represents the type of the
22369 @var{n}th template argument.
22370
22371 If this @code{gdb.Type} is not a template type, this will throw an
22372 exception. Ordinarily, only C@t{++} code will have template types.
22373
22374 If @var{block} is given, then @var{name} is looked up in that scope.
22375 Otherwise, it is searched for globally.
22376 @end defun
22377 @end table
22378
22379
22380 Each type has a code, which indicates what category this type falls
22381 into. The available type categories are represented by constants
22382 defined in the @code{gdb} module:
22383
22384 @table @code
22385 @findex TYPE_CODE_PTR
22386 @findex gdb.TYPE_CODE_PTR
22387 @item gdb.TYPE_CODE_PTR
22388 The type is a pointer.
22389
22390 @findex TYPE_CODE_ARRAY
22391 @findex gdb.TYPE_CODE_ARRAY
22392 @item gdb.TYPE_CODE_ARRAY
22393 The type is an array.
22394
22395 @findex TYPE_CODE_STRUCT
22396 @findex gdb.TYPE_CODE_STRUCT
22397 @item gdb.TYPE_CODE_STRUCT
22398 The type is a structure.
22399
22400 @findex TYPE_CODE_UNION
22401 @findex gdb.TYPE_CODE_UNION
22402 @item gdb.TYPE_CODE_UNION
22403 The type is a union.
22404
22405 @findex TYPE_CODE_ENUM
22406 @findex gdb.TYPE_CODE_ENUM
22407 @item gdb.TYPE_CODE_ENUM
22408 The type is an enum.
22409
22410 @findex TYPE_CODE_FLAGS
22411 @findex gdb.TYPE_CODE_FLAGS
22412 @item gdb.TYPE_CODE_FLAGS
22413 A bit flags type, used for things such as status registers.
22414
22415 @findex TYPE_CODE_FUNC
22416 @findex gdb.TYPE_CODE_FUNC
22417 @item gdb.TYPE_CODE_FUNC
22418 The type is a function.
22419
22420 @findex TYPE_CODE_INT
22421 @findex gdb.TYPE_CODE_INT
22422 @item gdb.TYPE_CODE_INT
22423 The type is an integer type.
22424
22425 @findex TYPE_CODE_FLT
22426 @findex gdb.TYPE_CODE_FLT
22427 @item gdb.TYPE_CODE_FLT
22428 A floating point type.
22429
22430 @findex TYPE_CODE_VOID
22431 @findex gdb.TYPE_CODE_VOID
22432 @item gdb.TYPE_CODE_VOID
22433 The special type @code{void}.
22434
22435 @findex TYPE_CODE_SET
22436 @findex gdb.TYPE_CODE_SET
22437 @item gdb.TYPE_CODE_SET
22438 A Pascal set type.
22439
22440 @findex TYPE_CODE_RANGE
22441 @findex gdb.TYPE_CODE_RANGE
22442 @item gdb.TYPE_CODE_RANGE
22443 A range type, that is, an integer type with bounds.
22444
22445 @findex TYPE_CODE_STRING
22446 @findex gdb.TYPE_CODE_STRING
22447 @item gdb.TYPE_CODE_STRING
22448 A string type. Note that this is only used for certain languages with
22449 language-defined string types; C strings are not represented this way.
22450
22451 @findex TYPE_CODE_BITSTRING
22452 @findex gdb.TYPE_CODE_BITSTRING
22453 @item gdb.TYPE_CODE_BITSTRING
22454 A string of bits.
22455
22456 @findex TYPE_CODE_ERROR
22457 @findex gdb.TYPE_CODE_ERROR
22458 @item gdb.TYPE_CODE_ERROR
22459 An unknown or erroneous type.
22460
22461 @findex TYPE_CODE_METHOD
22462 @findex gdb.TYPE_CODE_METHOD
22463 @item gdb.TYPE_CODE_METHOD
22464 A method type, as found in C@t{++} or Java.
22465
22466 @findex TYPE_CODE_METHODPTR
22467 @findex gdb.TYPE_CODE_METHODPTR
22468 @item gdb.TYPE_CODE_METHODPTR
22469 A pointer-to-member-function.
22470
22471 @findex TYPE_CODE_MEMBERPTR
22472 @findex gdb.TYPE_CODE_MEMBERPTR
22473 @item gdb.TYPE_CODE_MEMBERPTR
22474 A pointer-to-member.
22475
22476 @findex TYPE_CODE_REF
22477 @findex gdb.TYPE_CODE_REF
22478 @item gdb.TYPE_CODE_REF
22479 A reference type.
22480
22481 @findex TYPE_CODE_CHAR
22482 @findex gdb.TYPE_CODE_CHAR
22483 @item gdb.TYPE_CODE_CHAR
22484 A character type.
22485
22486 @findex TYPE_CODE_BOOL
22487 @findex gdb.TYPE_CODE_BOOL
22488 @item gdb.TYPE_CODE_BOOL
22489 A boolean type.
22490
22491 @findex TYPE_CODE_COMPLEX
22492 @findex gdb.TYPE_CODE_COMPLEX
22493 @item gdb.TYPE_CODE_COMPLEX
22494 A complex float type.
22495
22496 @findex TYPE_CODE_TYPEDEF
22497 @findex gdb.TYPE_CODE_TYPEDEF
22498 @item gdb.TYPE_CODE_TYPEDEF
22499 A typedef to some other type.
22500
22501 @findex TYPE_CODE_NAMESPACE
22502 @findex gdb.TYPE_CODE_NAMESPACE
22503 @item gdb.TYPE_CODE_NAMESPACE
22504 A C@t{++} namespace.
22505
22506 @findex TYPE_CODE_DECFLOAT
22507 @findex gdb.TYPE_CODE_DECFLOAT
22508 @item gdb.TYPE_CODE_DECFLOAT
22509 A decimal floating point type.
22510
22511 @findex TYPE_CODE_INTERNAL_FUNCTION
22512 @findex gdb.TYPE_CODE_INTERNAL_FUNCTION
22513 @item gdb.TYPE_CODE_INTERNAL_FUNCTION
22514 A function internal to @value{GDBN}. This is the type used to represent
22515 convenience functions.
22516 @end table
22517
22518 Further support for types is provided in the @code{gdb.types}
22519 Python module (@pxref{gdb.types}).
22520
22521 @node Pretty Printing API
22522 @subsubsection Pretty Printing API
22523
22524 An example output is provided (@pxref{Pretty Printing}).
22525
22526 A pretty-printer is just an object that holds a value and implements a
22527 specific interface, defined here.
22528
22529 @defun pretty_printer.children (self)
22530 @value{GDBN} will call this method on a pretty-printer to compute the
22531 children of the pretty-printer's value.
22532
22533 This method must return an object conforming to the Python iterator
22534 protocol. Each item returned by the iterator must be a tuple holding
22535 two elements. The first element is the ``name'' of the child; the
22536 second element is the child's value. The value can be any Python
22537 object which is convertible to a @value{GDBN} value.
22538
22539 This method is optional. If it does not exist, @value{GDBN} will act
22540 as though the value has no children.
22541 @end defun
22542
22543 @defun pretty_printer.display_hint (self)
22544 The CLI may call this method and use its result to change the
22545 formatting of a value. The result will also be supplied to an MI
22546 consumer as a @samp{displayhint} attribute of the variable being
22547 printed.
22548
22549 This method is optional. If it does exist, this method must return a
22550 string.
22551
22552 Some display hints are predefined by @value{GDBN}:
22553
22554 @table @samp
22555 @item array
22556 Indicate that the object being printed is ``array-like''. The CLI
22557 uses this to respect parameters such as @code{set print elements} and
22558 @code{set print array}.
22559
22560 @item map
22561 Indicate that the object being printed is ``map-like'', and that the
22562 children of this value can be assumed to alternate between keys and
22563 values.
22564
22565 @item string
22566 Indicate that the object being printed is ``string-like''. If the
22567 printer's @code{to_string} method returns a Python string of some
22568 kind, then @value{GDBN} will call its internal language-specific
22569 string-printing function to format the string. For the CLI this means
22570 adding quotation marks, possibly escaping some characters, respecting
22571 @code{set print elements}, and the like.
22572 @end table
22573 @end defun
22574
22575 @defun pretty_printer.to_string (self)
22576 @value{GDBN} will call this method to display the string
22577 representation of the value passed to the object's constructor.
22578
22579 When printing from the CLI, if the @code{to_string} method exists,
22580 then @value{GDBN} will prepend its result to the values returned by
22581 @code{children}. Exactly how this formatting is done is dependent on
22582 the display hint, and may change as more hints are added. Also,
22583 depending on the print settings (@pxref{Print Settings}), the CLI may
22584 print just the result of @code{to_string} in a stack trace, omitting
22585 the result of @code{children}.
22586
22587 If this method returns a string, it is printed verbatim.
22588
22589 Otherwise, if this method returns an instance of @code{gdb.Value},
22590 then @value{GDBN} prints this value. This may result in a call to
22591 another pretty-printer.
22592
22593 If instead the method returns a Python value which is convertible to a
22594 @code{gdb.Value}, then @value{GDBN} performs the conversion and prints
22595 the resulting value. Again, this may result in a call to another
22596 pretty-printer. Python scalars (integers, floats, and booleans) and
22597 strings are convertible to @code{gdb.Value}; other types are not.
22598
22599 Finally, if this method returns @code{None} then no further operations
22600 are peformed in this method and nothing is printed.
22601
22602 If the result is not one of these types, an exception is raised.
22603 @end defun
22604
22605 @value{GDBN} provides a function which can be used to look up the
22606 default pretty-printer for a @code{gdb.Value}:
22607
22608 @findex gdb.default_visualizer
22609 @defun gdb.default_visualizer (value)
22610 This function takes a @code{gdb.Value} object as an argument. If a
22611 pretty-printer for this value exists, then it is returned. If no such
22612 printer exists, then this returns @code{None}.
22613 @end defun
22614
22615 @node Selecting Pretty-Printers
22616 @subsubsection Selecting Pretty-Printers
22617
22618 The Python list @code{gdb.pretty_printers} contains an array of
22619 functions or callable objects that have been registered via addition
22620 as a pretty-printer. Printers in this list are called @code{global}
22621 printers, they're available when debugging all inferiors.
22622 Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
22623 Each @code{gdb.Objfile} also contains a @code{pretty_printers}
22624 attribute.
22625
22626 Each function on these lists is passed a single @code{gdb.Value}
22627 argument and should return a pretty-printer object conforming to the
22628 interface definition above (@pxref{Pretty Printing API}). If a function
22629 cannot create a pretty-printer for the value, it should return
22630 @code{None}.
22631
22632 @value{GDBN} first checks the @code{pretty_printers} attribute of each
22633 @code{gdb.Objfile} in the current program space and iteratively calls
22634 each enabled lookup routine in the list for that @code{gdb.Objfile}
22635 until it receives a pretty-printer object.
22636 If no pretty-printer is found in the objfile lists, @value{GDBN} then
22637 searches the pretty-printer list of the current program space,
22638 calling each enabled function until an object is returned.
22639 After these lists have been exhausted, it tries the global
22640 @code{gdb.pretty_printers} list, again calling each enabled function until an
22641 object is returned.
22642
22643 The order in which the objfiles are searched is not specified. For a
22644 given list, functions are always invoked from the head of the list,
22645 and iterated over sequentially until the end of the list, or a printer
22646 object is returned.
22647
22648 For various reasons a pretty-printer may not work.
22649 For example, the underlying data structure may have changed and
22650 the pretty-printer is out of date.
22651
22652 The consequences of a broken pretty-printer are severe enough that
22653 @value{GDBN} provides support for enabling and disabling individual
22654 printers. For example, if @code{print frame-arguments} is on,
22655 a backtrace can become highly illegible if any argument is printed
22656 with a broken printer.
22657
22658 Pretty-printers are enabled and disabled by attaching an @code{enabled}
22659 attribute to the registered function or callable object. If this attribute
22660 is present and its value is @code{False}, the printer is disabled, otherwise
22661 the printer is enabled.
22662
22663 @node Writing a Pretty-Printer
22664 @subsubsection Writing a Pretty-Printer
22665 @cindex writing a pretty-printer
22666
22667 A pretty-printer consists of two parts: a lookup function to detect
22668 if the type is supported, and the printer itself.
22669
22670 Here is an example showing how a @code{std::string} printer might be
22671 written. @xref{Pretty Printing API}, for details on the API this class
22672 must provide.
22673
22674 @smallexample
22675 class StdStringPrinter(object):
22676 "Print a std::string"
22677
22678 def __init__(self, val):
22679 self.val = val
22680
22681 def to_string(self):
22682 return self.val['_M_dataplus']['_M_p']
22683
22684 def display_hint(self):
22685 return 'string'
22686 @end smallexample
22687
22688 And here is an example showing how a lookup function for the printer
22689 example above might be written.
22690
22691 @smallexample
22692 def str_lookup_function(val):
22693 lookup_tag = val.type.tag
22694 if lookup_tag == None:
22695 return None
22696 regex = re.compile("^std::basic_string<char,.*>$")
22697 if regex.match(lookup_tag):
22698 return StdStringPrinter(val)
22699 return None
22700 @end smallexample
22701
22702 The example lookup function extracts the value's type, and attempts to
22703 match it to a type that it can pretty-print. If it is a type the
22704 printer can pretty-print, it will return a printer object. If not, it
22705 returns @code{None}.
22706
22707 We recommend that you put your core pretty-printers into a Python
22708 package. If your pretty-printers are for use with a library, we
22709 further recommend embedding a version number into the package name.
22710 This practice will enable @value{GDBN} to load multiple versions of
22711 your pretty-printers at the same time, because they will have
22712 different names.
22713
22714 You should write auto-loaded code (@pxref{Auto-loading}) such that it
22715 can be evaluated multiple times without changing its meaning. An
22716 ideal auto-load file will consist solely of @code{import}s of your
22717 printer modules, followed by a call to a register pretty-printers with
22718 the current objfile.
22719
22720 Taken as a whole, this approach will scale nicely to multiple
22721 inferiors, each potentially using a different library version.
22722 Embedding a version number in the Python package name will ensure that
22723 @value{GDBN} is able to load both sets of printers simultaneously.
22724 Then, because the search for pretty-printers is done by objfile, and
22725 because your auto-loaded code took care to register your library's
22726 printers with a specific objfile, @value{GDBN} will find the correct
22727 printers for the specific version of the library used by each
22728 inferior.
22729
22730 To continue the @code{std::string} example (@pxref{Pretty Printing API}),
22731 this code might appear in @code{gdb.libstdcxx.v6}:
22732
22733 @smallexample
22734 def register_printers(objfile):
22735 objfile.pretty_printers.append(str_lookup_function)
22736 @end smallexample
22737
22738 @noindent
22739 And then the corresponding contents of the auto-load file would be:
22740
22741 @smallexample
22742 import gdb.libstdcxx.v6
22743 gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
22744 @end smallexample
22745
22746 The previous example illustrates a basic pretty-printer.
22747 There are a few things that can be improved on.
22748 The printer doesn't have a name, making it hard to identify in a
22749 list of installed printers. The lookup function has a name, but
22750 lookup functions can have arbitrary, even identical, names.
22751
22752 Second, the printer only handles one type, whereas a library typically has
22753 several types. One could install a lookup function for each desired type
22754 in the library, but one could also have a single lookup function recognize
22755 several types. The latter is the conventional way this is handled.
22756 If a pretty-printer can handle multiple data types, then its
22757 @dfn{subprinters} are the printers for the individual data types.
22758
22759 The @code{gdb.printing} module provides a formal way of solving these
22760 problems (@pxref{gdb.printing}).
22761 Here is another example that handles multiple types.
22762
22763 These are the types we are going to pretty-print:
22764
22765 @smallexample
22766 struct foo @{ int a, b; @};
22767 struct bar @{ struct foo x, y; @};
22768 @end smallexample
22769
22770 Here are the printers:
22771
22772 @smallexample
22773 class fooPrinter:
22774 """Print a foo object."""
22775
22776 def __init__(self, val):
22777 self.val = val
22778
22779 def to_string(self):
22780 return ("a=<" + str(self.val["a"]) +
22781 "> b=<" + str(self.val["b"]) + ">")
22782
22783 class barPrinter:
22784 """Print a bar object."""
22785
22786 def __init__(self, val):
22787 self.val = val
22788
22789 def to_string(self):
22790 return ("x=<" + str(self.val["x"]) +
22791 "> y=<" + str(self.val["y"]) + ">")
22792 @end smallexample
22793
22794 This example doesn't need a lookup function, that is handled by the
22795 @code{gdb.printing} module. Instead a function is provided to build up
22796 the object that handles the lookup.
22797
22798 @smallexample
22799 import gdb.printing
22800
22801 def build_pretty_printer():
22802 pp = gdb.printing.RegexpCollectionPrettyPrinter(
22803 "my_library")
22804 pp.add_printer('foo', '^foo$', fooPrinter)
22805 pp.add_printer('bar', '^bar$', barPrinter)
22806 return pp
22807 @end smallexample
22808
22809 And here is the autoload support:
22810
22811 @smallexample
22812 import gdb.printing
22813 import my_library
22814 gdb.printing.register_pretty_printer(
22815 gdb.current_objfile(),
22816 my_library.build_pretty_printer())
22817 @end smallexample
22818
22819 Finally, when this printer is loaded into @value{GDBN}, here is the
22820 corresponding output of @samp{info pretty-printer}:
22821
22822 @smallexample
22823 (gdb) info pretty-printer
22824 my_library.so:
22825 my_library
22826 foo
22827 bar
22828 @end smallexample
22829
22830 @node Inferiors In Python
22831 @subsubsection Inferiors In Python
22832 @cindex inferiors in Python
22833
22834 @findex gdb.Inferior
22835 Programs which are being run under @value{GDBN} are called inferiors
22836 (@pxref{Inferiors and Programs}). Python scripts can access
22837 information about and manipulate inferiors controlled by @value{GDBN}
22838 via objects of the @code{gdb.Inferior} class.
22839
22840 The following inferior-related functions are available in the @code{gdb}
22841 module:
22842
22843 @defun gdb.inferiors ()
22844 Return a tuple containing all inferior objects.
22845 @end defun
22846
22847 @defun gdb.selected_inferior ()
22848 Return an object representing the current inferior.
22849 @end defun
22850
22851 A @code{gdb.Inferior} object has the following attributes:
22852
22853 @table @code
22854 @defvar Inferior.num
22855 ID of inferior, as assigned by GDB.
22856 @end defvar
22857
22858 @defvar Inferior.pid
22859 Process ID of the inferior, as assigned by the underlying operating
22860 system.
22861 @end defvar
22862
22863 @defvar Inferior.was_attached
22864 Boolean signaling whether the inferior was created using `attach', or
22865 started by @value{GDBN} itself.
22866 @end defvar
22867 @end table
22868
22869 A @code{gdb.Inferior} object has the following methods:
22870
22871 @table @code
22872 @defun Inferior.is_valid ()
22873 Returns @code{True} if the @code{gdb.Inferior} object is valid,
22874 @code{False} if not. A @code{gdb.Inferior} object will become invalid
22875 if the inferior no longer exists within @value{GDBN}. All other
22876 @code{gdb.Inferior} methods will throw an exception if it is invalid
22877 at the time the method is called.
22878 @end defun
22879
22880 @defun Inferior.threads ()
22881 This method returns a tuple holding all the threads which are valid
22882 when it is called. If there are no valid threads, the method will
22883 return an empty tuple.
22884 @end defun
22885
22886 @findex gdb.read_memory
22887 @defun Inferior.read_memory (address, length)
22888 Read @var{length} bytes of memory from the inferior, starting at
22889 @var{address}. Returns a buffer object, which behaves much like an array
22890 or a string. It can be modified and given to the @code{gdb.write_memory}
22891 function.
22892 @end defun
22893
22894 @findex gdb.write_memory
22895 @defun Inferior.write_memory (address, buffer @r{[}, length@r{]})
22896 Write the contents of @var{buffer} to the inferior, starting at
22897 @var{address}. The @var{buffer} parameter must be a Python object
22898 which supports the buffer protocol, i.e., a string, an array or the
22899 object returned from @code{gdb.read_memory}. If given, @var{length}
22900 determines the number of bytes from @var{buffer} to be written.
22901 @end defun
22902
22903 @findex gdb.search_memory
22904 @defun Inferior.search_memory (address, length, pattern)
22905 Search a region of the inferior memory starting at @var{address} with
22906 the given @var{length} using the search pattern supplied in
22907 @var{pattern}. The @var{pattern} parameter must be a Python object
22908 which supports the buffer protocol, i.e., a string, an array or the
22909 object returned from @code{gdb.read_memory}. Returns a Python @code{Long}
22910 containing the address where the pattern was found, or @code{None} if
22911 the pattern could not be found.
22912 @end defun
22913 @end table
22914
22915 @node Events In Python
22916 @subsubsection Events In Python
22917 @cindex inferior events in Python
22918
22919 @value{GDBN} provides a general event facility so that Python code can be
22920 notified of various state changes, particularly changes that occur in
22921 the inferior.
22922
22923 An @dfn{event} is just an object that describes some state change. The
22924 type of the object and its attributes will vary depending on the details
22925 of the change. All the existing events are described below.
22926
22927 In order to be notified of an event, you must register an event handler
22928 with an @dfn{event registry}. An event registry is an object in the
22929 @code{gdb.events} module which dispatches particular events. A registry
22930 provides methods to register and unregister event handlers:
22931
22932 @table @code
22933 @defun EventRegistry.connect (object)
22934 Add the given callable @var{object} to the registry. This object will be
22935 called when an event corresponding to this registry occurs.
22936 @end defun
22937
22938 @defun EventRegistry.disconnect (object)
22939 Remove the given @var{object} from the registry. Once removed, the object
22940 will no longer receive notifications of events.
22941 @end defun
22942 @end table
22943
22944 Here is an example:
22945
22946 @smallexample
22947 def exit_handler (event):
22948 print "event type: exit"
22949 print "exit code: %d" % (event.exit_code)
22950
22951 gdb.events.exited.connect (exit_handler)
22952 @end smallexample
22953
22954 In the above example we connect our handler @code{exit_handler} to the
22955 registry @code{events.exited}. Once connected, @code{exit_handler} gets
22956 called when the inferior exits. The argument @dfn{event} in this example is
22957 of type @code{gdb.ExitedEvent}. As you can see in the example the
22958 @code{ExitedEvent} object has an attribute which indicates the exit code of
22959 the inferior.
22960
22961 The following is a listing of the event registries that are available and
22962 details of the events they emit:
22963
22964 @table @code
22965
22966 @item events.cont
22967 Emits @code{gdb.ThreadEvent}.
22968
22969 Some events can be thread specific when @value{GDBN} is running in non-stop
22970 mode. When represented in Python, these events all extend
22971 @code{gdb.ThreadEvent}. Note, this event is not emitted directly; instead,
22972 events which are emitted by this or other modules might extend this event.
22973 Examples of these events are @code{gdb.BreakpointEvent} and
22974 @code{gdb.ContinueEvent}.
22975
22976 @table @code
22977 @defvar ThreadEvent.inferior_thread
22978 In non-stop mode this attribute will be set to the specific thread which was
22979 involved in the emitted event. Otherwise, it will be set to @code{None}.
22980 @end defvar
22981 @end table
22982
22983 Emits @code{gdb.ContinueEvent} which extends @code{gdb.ThreadEvent}.
22984
22985 This event indicates that the inferior has been continued after a stop. For
22986 inherited attribute refer to @code{gdb.ThreadEvent} above.
22987
22988 @item events.exited
22989 Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
22990 @code{events.ExitedEvent} has two attributes:
22991 @table @code
22992 @defvar ExitedEvent.exit_code
22993 An integer representing the exit code, if available, which the inferior
22994 has returned. (The exit code could be unavailable if, for example,
22995 @value{GDBN} detaches from the inferior.) If the exit code is unavailable,
22996 the attribute does not exist.
22997 @end defvar
22998 @defvar ExitedEvent inferior
22999 A reference to the inferior which triggered the @code{exited} event.
23000 @end defvar
23001 @end table
23002
23003 @item events.stop
23004 Emits @code{gdb.StopEvent} which extends @code{gdb.ThreadEvent}.
23005
23006 Indicates that the inferior has stopped. All events emitted by this registry
23007 extend StopEvent. As a child of @code{gdb.ThreadEvent}, @code{gdb.StopEvent}
23008 will indicate the stopped thread when @value{GDBN} is running in non-stop
23009 mode. Refer to @code{gdb.ThreadEvent} above for more details.
23010
23011 Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}.
23012
23013 This event indicates that the inferior or one of its threads has received as
23014 signal. @code{gdb.SignalEvent} has the following attributes:
23015
23016 @table @code
23017 @defvar SignalEvent.stop_signal
23018 A string representing the signal received by the inferior. A list of possible
23019 signal values can be obtained by running the command @code{info signals} in
23020 the @value{GDBN} command prompt.
23021 @end defvar
23022 @end table
23023
23024 Also emits @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
23025
23026 @code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
23027 been hit, and has the following attributes:
23028
23029 @table @code
23030 @defvar BreakpointEvent.breakpoints
23031 A sequence containing references to all the breakpoints (type
23032 @code{gdb.Breakpoint}) that were hit.
23033 @xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
23034 @end defvar
23035 @defvar BreakpointEvent.breakpoint
23036 A reference to the first breakpoint that was hit.
23037 This function is maintained for backward compatibility and is now deprecated
23038 in favor of the @code{gdb.BreakpointEvent.breakpoints} attribute.
23039 @end defvar
23040 @end table
23041
23042 @item events.new_objfile
23043 Emits @code{gdb.NewObjFileEvent} which indicates that a new object file has
23044 been loaded by @value{GDBN}. @code{gdb.NewObjFileEvent} has one attribute:
23045
23046 @table @code
23047 @defvar NewObjFileEvent.new_objfile
23048 A reference to the object file (@code{gdb.Objfile}) which has been loaded.
23049 @xref{Objfiles In Python}, for details of the @code{gdb.Objfile} object.
23050 @end defvar
23051 @end table
23052
23053 @end table
23054
23055 @node Threads In Python
23056 @subsubsection Threads In Python
23057 @cindex threads in python
23058
23059 @findex gdb.InferiorThread
23060 Python scripts can access information about, and manipulate inferior threads
23061 controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
23062
23063 The following thread-related functions are available in the @code{gdb}
23064 module:
23065
23066 @findex gdb.selected_thread
23067 @defun gdb.selected_thread ()
23068 This function returns the thread object for the selected thread. If there
23069 is no selected thread, this will return @code{None}.
23070 @end defun
23071
23072 A @code{gdb.InferiorThread} object has the following attributes:
23073
23074 @table @code
23075 @defvar InferiorThread.name
23076 The name of the thread. If the user specified a name using
23077 @code{thread name}, then this returns that name. Otherwise, if an
23078 OS-supplied name is available, then it is returned. Otherwise, this
23079 returns @code{None}.
23080
23081 This attribute can be assigned to. The new value must be a string
23082 object, which sets the new name, or @code{None}, which removes any
23083 user-specified thread name.
23084 @end defvar
23085
23086 @defvar InferiorThread.num
23087 ID of the thread, as assigned by GDB.
23088 @end defvar
23089
23090 @defvar InferiorThread.ptid
23091 ID of the thread, as assigned by the operating system. This attribute is a
23092 tuple containing three integers. The first is the Process ID (PID); the second
23093 is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
23094 Either the LWPID or TID may be 0, which indicates that the operating system
23095 does not use that identifier.
23096 @end defvar
23097 @end table
23098
23099 A @code{gdb.InferiorThread} object has the following methods:
23100
23101 @table @code
23102 @defun InferiorThread.is_valid ()
23103 Returns @code{True} if the @code{gdb.InferiorThread} object is valid,
23104 @code{False} if not. A @code{gdb.InferiorThread} object will become
23105 invalid if the thread exits, or the inferior that the thread belongs
23106 is deleted. All other @code{gdb.InferiorThread} methods will throw an
23107 exception if it is invalid at the time the method is called.
23108 @end defun
23109
23110 @defun InferiorThread.switch ()
23111 This changes @value{GDBN}'s currently selected thread to the one represented
23112 by this object.
23113 @end defun
23114
23115 @defun InferiorThread.is_stopped ()
23116 Return a Boolean indicating whether the thread is stopped.
23117 @end defun
23118
23119 @defun InferiorThread.is_running ()
23120 Return a Boolean indicating whether the thread is running.
23121 @end defun
23122
23123 @defun InferiorThread.is_exited ()
23124 Return a Boolean indicating whether the thread is exited.
23125 @end defun
23126 @end table
23127
23128 @node Commands In Python
23129 @subsubsection Commands In Python
23130
23131 @cindex commands in python
23132 @cindex python commands
23133 You can implement new @value{GDBN} CLI commands in Python. A CLI
23134 command is implemented using an instance of the @code{gdb.Command}
23135 class, most commonly using a subclass.
23136
23137 @defun Command.__init__ (name, @var{command_class} @r{[}, @var{completer_class} @r{[}, @var{prefix}@r{]]})
23138 The object initializer for @code{Command} registers the new command
23139 with @value{GDBN}. This initializer is normally invoked from the
23140 subclass' own @code{__init__} method.
23141
23142 @var{name} is the name of the command. If @var{name} consists of
23143 multiple words, then the initial words are looked for as prefix
23144 commands. In this case, if one of the prefix commands does not exist,
23145 an exception is raised.
23146
23147 There is no support for multi-line commands.
23148
23149 @var{command_class} should be one of the @samp{COMMAND_} constants
23150 defined below. This argument tells @value{GDBN} how to categorize the
23151 new command in the help system.
23152
23153 @var{completer_class} is an optional argument. If given, it should be
23154 one of the @samp{COMPLETE_} constants defined below. This argument
23155 tells @value{GDBN} how to perform completion for this command. If not
23156 given, @value{GDBN} will attempt to complete using the object's
23157 @code{complete} method (see below); if no such method is found, an
23158 error will occur when completion is attempted.
23159
23160 @var{prefix} is an optional argument. If @code{True}, then the new
23161 command is a prefix command; sub-commands of this command may be
23162 registered.
23163
23164 The help text for the new command is taken from the Python
23165 documentation string for the command's class, if there is one. If no
23166 documentation string is provided, the default value ``This command is
23167 not documented.'' is used.
23168 @end defun
23169
23170 @cindex don't repeat Python command
23171 @defun Command.dont_repeat ()
23172 By default, a @value{GDBN} command is repeated when the user enters a
23173 blank line at the command prompt. A command can suppress this
23174 behavior by invoking the @code{dont_repeat} method. This is similar
23175 to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
23176 @end defun
23177
23178 @defun Command.invoke (argument, from_tty)
23179 This method is called by @value{GDBN} when this command is invoked.
23180
23181 @var{argument} is a string. It is the argument to the command, after
23182 leading and trailing whitespace has been stripped.
23183
23184 @var{from_tty} is a boolean argument. When true, this means that the
23185 command was entered by the user at the terminal; when false it means
23186 that the command came from elsewhere.
23187
23188 If this method throws an exception, it is turned into a @value{GDBN}
23189 @code{error} call. Otherwise, the return value is ignored.
23190
23191 @findex gdb.string_to_argv
23192 To break @var{argument} up into an argv-like string use
23193 @code{gdb.string_to_argv}. This function behaves identically to
23194 @value{GDBN}'s internal argument lexer @code{buildargv}.
23195 It is recommended to use this for consistency.
23196 Arguments are separated by spaces and may be quoted.
23197 Example:
23198
23199 @smallexample
23200 print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
23201 ['1', '2 "3', '4 "5', "6 '7"]
23202 @end smallexample
23203
23204 @end defun
23205
23206 @cindex completion of Python commands
23207 @defun Command.complete (text, word)
23208 This method is called by @value{GDBN} when the user attempts
23209 completion on this command. All forms of completion are handled by
23210 this method, that is, the @key{TAB} and @key{M-?} key bindings
23211 (@pxref{Completion}), and the @code{complete} command (@pxref{Help,
23212 complete}).
23213
23214 The arguments @var{text} and @var{word} are both strings. @var{text}
23215 holds the complete command line up to the cursor's location.
23216 @var{word} holds the last word of the command line; this is computed
23217 using a word-breaking heuristic.
23218
23219 The @code{complete} method can return several values:
23220 @itemize @bullet
23221 @item
23222 If the return value is a sequence, the contents of the sequence are
23223 used as the completions. It is up to @code{complete} to ensure that the
23224 contents actually do complete the word. A zero-length sequence is
23225 allowed, it means that there were no completions available. Only
23226 string elements of the sequence are used; other elements in the
23227 sequence are ignored.
23228
23229 @item
23230 If the return value is one of the @samp{COMPLETE_} constants defined
23231 below, then the corresponding @value{GDBN}-internal completion
23232 function is invoked, and its result is used.
23233
23234 @item
23235 All other results are treated as though there were no available
23236 completions.
23237 @end itemize
23238 @end defun
23239
23240 When a new command is registered, it must be declared as a member of
23241 some general class of commands. This is used to classify top-level
23242 commands in the on-line help system; note that prefix commands are not
23243 listed under their own category but rather that of their top-level
23244 command. The available classifications are represented by constants
23245 defined in the @code{gdb} module:
23246
23247 @table @code
23248 @findex COMMAND_NONE
23249 @findex gdb.COMMAND_NONE
23250 @item gdb.COMMAND_NONE
23251 The command does not belong to any particular class. A command in
23252 this category will not be displayed in any of the help categories.
23253
23254 @findex COMMAND_RUNNING
23255 @findex gdb.COMMAND_RUNNING
23256 @item gdb.COMMAND_RUNNING
23257 The command is related to running the inferior. For example,
23258 @code{start}, @code{step}, and @code{continue} are in this category.
23259 Type @kbd{help running} at the @value{GDBN} prompt to see a list of
23260 commands in this category.
23261
23262 @findex COMMAND_DATA
23263 @findex gdb.COMMAND_DATA
23264 @item gdb.COMMAND_DATA
23265 The command is related to data or variables. For example,
23266 @code{call}, @code{find}, and @code{print} are in this category. Type
23267 @kbd{help data} at the @value{GDBN} prompt to see a list of commands
23268 in this category.
23269
23270 @findex COMMAND_STACK
23271 @findex gdb.COMMAND_STACK
23272 @item gdb.COMMAND_STACK
23273 The command has to do with manipulation of the stack. For example,
23274 @code{backtrace}, @code{frame}, and @code{return} are in this
23275 category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
23276 list of commands in this category.
23277
23278 @findex COMMAND_FILES
23279 @findex gdb.COMMAND_FILES
23280 @item gdb.COMMAND_FILES
23281 This class is used for file-related commands. For example,
23282 @code{file}, @code{list} and @code{section} are in this category.
23283 Type @kbd{help files} at the @value{GDBN} prompt to see a list of
23284 commands in this category.
23285
23286 @findex COMMAND_SUPPORT
23287 @findex gdb.COMMAND_SUPPORT
23288 @item gdb.COMMAND_SUPPORT
23289 This should be used for ``support facilities'', generally meaning
23290 things that are useful to the user when interacting with @value{GDBN},
23291 but not related to the state of the inferior. For example,
23292 @code{help}, @code{make}, and @code{shell} are in this category. Type
23293 @kbd{help support} at the @value{GDBN} prompt to see a list of
23294 commands in this category.
23295
23296 @findex COMMAND_STATUS
23297 @findex gdb.COMMAND_STATUS
23298 @item gdb.COMMAND_STATUS
23299 The command is an @samp{info}-related command, that is, related to the
23300 state of @value{GDBN} itself. For example, @code{info}, @code{macro},
23301 and @code{show} are in this category. Type @kbd{help status} at the
23302 @value{GDBN} prompt to see a list of commands in this category.
23303
23304 @findex COMMAND_BREAKPOINTS
23305 @findex gdb.COMMAND_BREAKPOINTS
23306 @item gdb.COMMAND_BREAKPOINTS
23307 The command has to do with breakpoints. For example, @code{break},
23308 @code{clear}, and @code{delete} are in this category. Type @kbd{help
23309 breakpoints} at the @value{GDBN} prompt to see a list of commands in
23310 this category.
23311
23312 @findex COMMAND_TRACEPOINTS
23313 @findex gdb.COMMAND_TRACEPOINTS
23314 @item gdb.COMMAND_TRACEPOINTS
23315 The command has to do with tracepoints. For example, @code{trace},
23316 @code{actions}, and @code{tfind} are in this category. Type
23317 @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
23318 commands in this category.
23319
23320 @findex COMMAND_USER
23321 @findex gdb.COMMAND_USER
23322 @item gdb.COMMAND_USER
23323 The command is a general purpose command for the user, and typically
23324 does not fit in one of the other categories.
23325 Type @kbd{help user-defined} at the @value{GDBN} prompt to see
23326 a list of commands in this category, as well as the list of gdb macros
23327 (@pxref{Sequences}).
23328
23329 @findex COMMAND_OBSCURE
23330 @findex gdb.COMMAND_OBSCURE
23331 @item gdb.COMMAND_OBSCURE
23332 The command is only used in unusual circumstances, or is not of
23333 general interest to users. For example, @code{checkpoint},
23334 @code{fork}, and @code{stop} are in this category. Type @kbd{help
23335 obscure} at the @value{GDBN} prompt to see a list of commands in this
23336 category.
23337
23338 @findex COMMAND_MAINTENANCE
23339 @findex gdb.COMMAND_MAINTENANCE
23340 @item gdb.COMMAND_MAINTENANCE
23341 The command is only useful to @value{GDBN} maintainers. The
23342 @code{maintenance} and @code{flushregs} commands are in this category.
23343 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
23344 commands in this category.
23345 @end table
23346
23347 A new command can use a predefined completion function, either by
23348 specifying it via an argument at initialization, or by returning it
23349 from the @code{complete} method. These predefined completion
23350 constants are all defined in the @code{gdb} module:
23351
23352 @table @code
23353 @findex COMPLETE_NONE
23354 @findex gdb.COMPLETE_NONE
23355 @item gdb.COMPLETE_NONE
23356 This constant means that no completion should be done.
23357
23358 @findex COMPLETE_FILENAME
23359 @findex gdb.COMPLETE_FILENAME
23360 @item gdb.COMPLETE_FILENAME
23361 This constant means that filename completion should be performed.
23362
23363 @findex COMPLETE_LOCATION
23364 @findex gdb.COMPLETE_LOCATION
23365 @item gdb.COMPLETE_LOCATION
23366 This constant means that location completion should be done.
23367 @xref{Specify Location}.
23368
23369 @findex COMPLETE_COMMAND
23370 @findex gdb.COMPLETE_COMMAND
23371 @item gdb.COMPLETE_COMMAND
23372 This constant means that completion should examine @value{GDBN}
23373 command names.
23374
23375 @findex COMPLETE_SYMBOL
23376 @findex gdb.COMPLETE_SYMBOL
23377 @item gdb.COMPLETE_SYMBOL
23378 This constant means that completion should be done using symbol names
23379 as the source.
23380 @end table
23381
23382 The following code snippet shows how a trivial CLI command can be
23383 implemented in Python:
23384
23385 @smallexample
23386 class HelloWorld (gdb.Command):
23387 """Greet the whole world."""
23388
23389 def __init__ (self):
23390 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
23391
23392 def invoke (self, arg, from_tty):
23393 print "Hello, World!"
23394
23395 HelloWorld ()
23396 @end smallexample
23397
23398 The last line instantiates the class, and is necessary to trigger the
23399 registration of the command with @value{GDBN}. Depending on how the
23400 Python code is read into @value{GDBN}, you may need to import the
23401 @code{gdb} module explicitly.
23402
23403 @node Parameters In Python
23404 @subsubsection Parameters In Python
23405
23406 @cindex parameters in python
23407 @cindex python parameters
23408 @tindex gdb.Parameter
23409 @tindex Parameter
23410 You can implement new @value{GDBN} parameters using Python. A new
23411 parameter is implemented as an instance of the @code{gdb.Parameter}
23412 class.
23413
23414 Parameters are exposed to the user via the @code{set} and
23415 @code{show} commands. @xref{Help}.
23416
23417 There are many parameters that already exist and can be set in
23418 @value{GDBN}. Two examples are: @code{set follow fork} and
23419 @code{set charset}. Setting these parameters influences certain
23420 behavior in @value{GDBN}. Similarly, you can define parameters that
23421 can be used to influence behavior in custom Python scripts and commands.
23422
23423 @defun Parameter.__init__ (name, @var{command-class}, @var{parameter-class} @r{[}, @var{enum-sequence}@r{]})
23424 The object initializer for @code{Parameter} registers the new
23425 parameter with @value{GDBN}. This initializer is normally invoked
23426 from the subclass' own @code{__init__} method.
23427
23428 @var{name} is the name of the new parameter. If @var{name} consists
23429 of multiple words, then the initial words are looked for as prefix
23430 parameters. An example of this can be illustrated with the
23431 @code{set print} set of parameters. If @var{name} is
23432 @code{print foo}, then @code{print} will be searched as the prefix
23433 parameter. In this case the parameter can subsequently be accessed in
23434 @value{GDBN} as @code{set print foo}.
23435
23436 If @var{name} consists of multiple words, and no prefix parameter group
23437 can be found, an exception is raised.
23438
23439 @var{command-class} should be one of the @samp{COMMAND_} constants
23440 (@pxref{Commands In Python}). This argument tells @value{GDBN} how to
23441 categorize the new parameter in the help system.
23442
23443 @var{parameter-class} should be one of the @samp{PARAM_} constants
23444 defined below. This argument tells @value{GDBN} the type of the new
23445 parameter; this information is used for input validation and
23446 completion.
23447
23448 If @var{parameter-class} is @code{PARAM_ENUM}, then
23449 @var{enum-sequence} must be a sequence of strings. These strings
23450 represent the possible values for the parameter.
23451
23452 If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
23453 of a fourth argument will cause an exception to be thrown.
23454
23455 The help text for the new parameter is taken from the Python
23456 documentation string for the parameter's class, if there is one. If
23457 there is no documentation string, a default value is used.
23458 @end defun
23459
23460 @defvar Parameter.set_doc
23461 If this attribute exists, and is a string, then its value is used as
23462 the help text for this parameter's @code{set} command. The value is
23463 examined when @code{Parameter.__init__} is invoked; subsequent changes
23464 have no effect.
23465 @end defvar
23466
23467 @defvar Parameter.show_doc
23468 If this attribute exists, and is a string, then its value is used as
23469 the help text for this parameter's @code{show} command. The value is
23470 examined when @code{Parameter.__init__} is invoked; subsequent changes
23471 have no effect.
23472 @end defvar
23473
23474 @defvar Parameter.value
23475 The @code{value} attribute holds the underlying value of the
23476 parameter. It can be read and assigned to just as any other
23477 attribute. @value{GDBN} does validation when assignments are made.
23478 @end defvar
23479
23480 There are two methods that should be implemented in any
23481 @code{Parameter} class. These are:
23482
23483 @defun Parameter.get_set_string (self)
23484 @value{GDBN} will call this method when a @var{parameter}'s value has
23485 been changed via the @code{set} API (for example, @kbd{set foo off}).
23486 The @code{value} attribute has already been populated with the new
23487 value and may be used in output. This method must return a string.
23488 @end defun
23489
23490 @defun Parameter.get_show_string (self, svalue)
23491 @value{GDBN} will call this method when a @var{parameter}'s
23492 @code{show} API has been invoked (for example, @kbd{show foo}). The
23493 argument @code{svalue} receives the string representation of the
23494 current value. This method must return a string.
23495 @end defun
23496
23497 When a new parameter is defined, its type must be specified. The
23498 available types are represented by constants defined in the @code{gdb}
23499 module:
23500
23501 @table @code
23502 @findex PARAM_BOOLEAN
23503 @findex gdb.PARAM_BOOLEAN
23504 @item gdb.PARAM_BOOLEAN
23505 The value is a plain boolean. The Python boolean values, @code{True}
23506 and @code{False} are the only valid values.
23507
23508 @findex PARAM_AUTO_BOOLEAN
23509 @findex gdb.PARAM_AUTO_BOOLEAN
23510 @item gdb.PARAM_AUTO_BOOLEAN
23511 The value has three possible states: true, false, and @samp{auto}. In
23512 Python, true and false are represented using boolean constants, and
23513 @samp{auto} is represented using @code{None}.
23514
23515 @findex PARAM_UINTEGER
23516 @findex gdb.PARAM_UINTEGER
23517 @item gdb.PARAM_UINTEGER
23518 The value is an unsigned integer. The value of 0 should be
23519 interpreted to mean ``unlimited''.
23520
23521 @findex PARAM_INTEGER
23522 @findex gdb.PARAM_INTEGER
23523 @item gdb.PARAM_INTEGER
23524 The value is a signed integer. The value of 0 should be interpreted
23525 to mean ``unlimited''.
23526
23527 @findex PARAM_STRING
23528 @findex gdb.PARAM_STRING
23529 @item gdb.PARAM_STRING
23530 The value is a string. When the user modifies the string, any escape
23531 sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
23532 translated into corresponding characters and encoded into the current
23533 host charset.
23534
23535 @findex PARAM_STRING_NOESCAPE
23536 @findex gdb.PARAM_STRING_NOESCAPE
23537 @item gdb.PARAM_STRING_NOESCAPE
23538 The value is a string. When the user modifies the string, escapes are
23539 passed through untranslated.
23540
23541 @findex PARAM_OPTIONAL_FILENAME
23542 @findex gdb.PARAM_OPTIONAL_FILENAME
23543 @item gdb.PARAM_OPTIONAL_FILENAME
23544 The value is a either a filename (a string), or @code{None}.
23545
23546 @findex PARAM_FILENAME
23547 @findex gdb.PARAM_FILENAME
23548 @item gdb.PARAM_FILENAME
23549 The value is a filename. This is just like
23550 @code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
23551
23552 @findex PARAM_ZINTEGER
23553 @findex gdb.PARAM_ZINTEGER
23554 @item gdb.PARAM_ZINTEGER
23555 The value is an integer. This is like @code{PARAM_INTEGER}, except 0
23556 is interpreted as itself.
23557
23558 @findex PARAM_ENUM
23559 @findex gdb.PARAM_ENUM
23560 @item gdb.PARAM_ENUM
23561 The value is a string, which must be one of a collection string
23562 constants provided when the parameter is created.
23563 @end table
23564
23565 @node Functions In Python
23566 @subsubsection Writing new convenience functions
23567
23568 @cindex writing convenience functions
23569 @cindex convenience functions in python
23570 @cindex python convenience functions
23571 @tindex gdb.Function
23572 @tindex Function
23573 You can implement new convenience functions (@pxref{Convenience Vars})
23574 in Python. A convenience function is an instance of a subclass of the
23575 class @code{gdb.Function}.
23576
23577 @defun Function.__init__ (name)
23578 The initializer for @code{Function} registers the new function with
23579 @value{GDBN}. The argument @var{name} is the name of the function,
23580 a string. The function will be visible to the user as a convenience
23581 variable of type @code{internal function}, whose name is the same as
23582 the given @var{name}.
23583
23584 The documentation for the new function is taken from the documentation
23585 string for the new class.
23586 @end defun
23587
23588 @defun Function.invoke (@var{*args})
23589 When a convenience function is evaluated, its arguments are converted
23590 to instances of @code{gdb.Value}, and then the function's
23591 @code{invoke} method is called. Note that @value{GDBN} does not
23592 predetermine the arity of convenience functions. Instead, all
23593 available arguments are passed to @code{invoke}, following the
23594 standard Python calling convention. In particular, a convenience
23595 function can have default values for parameters without ill effect.
23596
23597 The return value of this method is used as its value in the enclosing
23598 expression. If an ordinary Python value is returned, it is converted
23599 to a @code{gdb.Value} following the usual rules.
23600 @end defun
23601
23602 The following code snippet shows how a trivial convenience function can
23603 be implemented in Python:
23604
23605 @smallexample
23606 class Greet (gdb.Function):
23607 """Return string to greet someone.
23608 Takes a name as argument."""
23609
23610 def __init__ (self):
23611 super (Greet, self).__init__ ("greet")
23612
23613 def invoke (self, name):
23614 return "Hello, %s!" % name.string ()
23615
23616 Greet ()
23617 @end smallexample
23618
23619 The last line instantiates the class, and is necessary to trigger the
23620 registration of the function with @value{GDBN}. Depending on how the
23621 Python code is read into @value{GDBN}, you may need to import the
23622 @code{gdb} module explicitly.
23623
23624 @node Progspaces In Python
23625 @subsubsection Program Spaces In Python
23626
23627 @cindex progspaces in python
23628 @tindex gdb.Progspace
23629 @tindex Progspace
23630 A program space, or @dfn{progspace}, represents a symbolic view
23631 of an address space.
23632 It consists of all of the objfiles of the program.
23633 @xref{Objfiles In Python}.
23634 @xref{Inferiors and Programs, program spaces}, for more details
23635 about program spaces.
23636
23637 The following progspace-related functions are available in the
23638 @code{gdb} module:
23639
23640 @findex gdb.current_progspace
23641 @defun gdb.current_progspace ()
23642 This function returns the program space of the currently selected inferior.
23643 @xref{Inferiors and Programs}.
23644 @end defun
23645
23646 @findex gdb.progspaces
23647 @defun gdb.progspaces ()
23648 Return a sequence of all the progspaces currently known to @value{GDBN}.
23649 @end defun
23650
23651 Each progspace is represented by an instance of the @code{gdb.Progspace}
23652 class.
23653
23654 @defvar Progspace.filename
23655 The file name of the progspace as a string.
23656 @end defvar
23657
23658 @defvar Progspace.pretty_printers
23659 The @code{pretty_printers} attribute is a list of functions. It is
23660 used to look up pretty-printers. A @code{Value} is passed to each
23661 function in order; if the function returns @code{None}, then the
23662 search continues. Otherwise, the return value should be an object
23663 which is used to format the value. @xref{Pretty Printing API}, for more
23664 information.
23665 @end defvar
23666
23667 @node Objfiles In Python
23668 @subsubsection Objfiles In Python
23669
23670 @cindex objfiles in python
23671 @tindex gdb.Objfile
23672 @tindex Objfile
23673 @value{GDBN} loads symbols for an inferior from various
23674 symbol-containing files (@pxref{Files}). These include the primary
23675 executable file, any shared libraries used by the inferior, and any
23676 separate debug info files (@pxref{Separate Debug Files}).
23677 @value{GDBN} calls these symbol-containing files @dfn{objfiles}.
23678
23679 The following objfile-related functions are available in the
23680 @code{gdb} module:
23681
23682 @findex gdb.current_objfile
23683 @defun gdb.current_objfile ()
23684 When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN}
23685 sets the ``current objfile'' to the corresponding objfile. This
23686 function returns the current objfile. If there is no current objfile,
23687 this function returns @code{None}.
23688 @end defun
23689
23690 @findex gdb.objfiles
23691 @defun gdb.objfiles ()
23692 Return a sequence of all the objfiles current known to @value{GDBN}.
23693 @xref{Objfiles In Python}.
23694 @end defun
23695
23696 Each objfile is represented by an instance of the @code{gdb.Objfile}
23697 class.
23698
23699 @defvar Objfile.filename
23700 The file name of the objfile as a string.
23701 @end defvar
23702
23703 @defvar Objfile.pretty_printers
23704 The @code{pretty_printers} attribute is a list of functions. It is
23705 used to look up pretty-printers. A @code{Value} is passed to each
23706 function in order; if the function returns @code{None}, then the
23707 search continues. Otherwise, the return value should be an object
23708 which is used to format the value. @xref{Pretty Printing API}, for more
23709 information.
23710 @end defvar
23711
23712 A @code{gdb.Objfile} object has the following methods:
23713
23714 @defun Objfile.is_valid ()
23715 Returns @code{True} if the @code{gdb.Objfile} object is valid,
23716 @code{False} if not. A @code{gdb.Objfile} object can become invalid
23717 if the object file it refers to is not loaded in @value{GDBN} any
23718 longer. All other @code{gdb.Objfile} methods will throw an exception
23719 if it is invalid at the time the method is called.
23720 @end defun
23721
23722 @node Frames In Python
23723 @subsubsection Accessing inferior stack frames from Python.
23724
23725 @cindex frames in python
23726 When the debugged program stops, @value{GDBN} is able to analyze its call
23727 stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
23728 represents a frame in the stack. A @code{gdb.Frame} object is only valid
23729 while its corresponding frame exists in the inferior's stack. If you try
23730 to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
23731 exception (@pxref{Exception Handling}).
23732
23733 Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
23734 operator, like:
23735
23736 @smallexample
23737 (@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
23738 True
23739 @end smallexample
23740
23741 The following frame-related functions are available in the @code{gdb} module:
23742
23743 @findex gdb.selected_frame
23744 @defun gdb.selected_frame ()
23745 Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
23746 @end defun
23747
23748 @findex gdb.newest_frame
23749 @defun gdb.newest_frame ()
23750 Return the newest frame object for the selected thread.
23751 @end defun
23752
23753 @defun gdb.frame_stop_reason_string (reason)
23754 Return a string explaining the reason why @value{GDBN} stopped unwinding
23755 frames, as expressed by the given @var{reason} code (an integer, see the
23756 @code{unwind_stop_reason} method further down in this section).
23757 @end defun
23758
23759 A @code{gdb.Frame} object has the following methods:
23760
23761 @table @code
23762 @defun Frame.is_valid ()
23763 Returns true if the @code{gdb.Frame} object is valid, false if not.
23764 A frame object can become invalid if the frame it refers to doesn't
23765 exist anymore in the inferior. All @code{gdb.Frame} methods will throw
23766 an exception if it is invalid at the time the method is called.
23767 @end defun
23768
23769 @defun Frame.name ()
23770 Returns the function name of the frame, or @code{None} if it can't be
23771 obtained.
23772 @end defun
23773
23774 @defun Frame.type ()
23775 Returns the type of the frame. The value can be one of:
23776 @table @code
23777 @item gdb.NORMAL_FRAME
23778 An ordinary stack frame.
23779
23780 @item gdb.DUMMY_FRAME
23781 A fake stack frame that was created by @value{GDBN} when performing an
23782 inferior function call.
23783
23784 @item gdb.INLINE_FRAME
23785 A frame representing an inlined function. The function was inlined
23786 into a @code{gdb.NORMAL_FRAME} that is older than this one.
23787
23788 @item gdb.TAILCALL_FRAME
23789 A frame representing a tail call. @xref{Tail Call Frames}.
23790
23791 @item gdb.SIGTRAMP_FRAME
23792 A signal trampoline frame. This is the frame created by the OS when
23793 it calls into a signal handler.
23794
23795 @item gdb.ARCH_FRAME
23796 A fake stack frame representing a cross-architecture call.
23797
23798 @item gdb.SENTINEL_FRAME
23799 This is like @code{gdb.NORMAL_FRAME}, but it is only used for the
23800 newest frame.
23801 @end table
23802 @end defun
23803
23804 @defun Frame.unwind_stop_reason ()
23805 Return an integer representing the reason why it's not possible to find
23806 more frames toward the outermost frame. Use
23807 @code{gdb.frame_stop_reason_string} to convert the value returned by this
23808 function to a string. The value can be one of:
23809
23810 @table @code
23811 @item gdb.FRAME_UNWIND_NO_REASON
23812 No particular reason (older frames should be available).
23813
23814 @item gdb.FRAME_UNWIND_NULL_ID
23815 The previous frame's analyzer returns an invalid result.
23816
23817 @item gdb.FRAME_UNWIND_OUTERMOST
23818 This frame is the outermost.
23819
23820 @item gdb.FRAME_UNWIND_UNAVAILABLE
23821 Cannot unwind further, because that would require knowing the
23822 values of registers or memory that have not been collected.
23823
23824 @item gdb.FRAME_UNWIND_INNER_ID
23825 This frame ID looks like it ought to belong to a NEXT frame,
23826 but we got it for a PREV frame. Normally, this is a sign of
23827 unwinder failure. It could also indicate stack corruption.
23828
23829 @item gdb.FRAME_UNWIND_SAME_ID
23830 This frame has the same ID as the previous one. That means
23831 that unwinding further would almost certainly give us another
23832 frame with exactly the same ID, so break the chain. Normally,
23833 this is a sign of unwinder failure. It could also indicate
23834 stack corruption.
23835
23836 @item gdb.FRAME_UNWIND_NO_SAVED_PC
23837 The frame unwinder did not find any saved PC, but we needed
23838 one to unwind further.
23839
23840 @item gdb.FRAME_UNWIND_FIRST_ERROR
23841 Any stop reason greater or equal to this value indicates some kind
23842 of error. This special value facilitates writing code that tests
23843 for errors in unwinding in a way that will work correctly even if
23844 the list of the other values is modified in future @value{GDBN}
23845 versions. Using it, you could write:
23846 @smallexample
23847 reason = gdb.selected_frame().unwind_stop_reason ()
23848 reason_str = gdb.frame_stop_reason_string (reason)
23849 if reason >= gdb.FRAME_UNWIND_FIRST_ERROR:
23850 print "An error occured: %s" % reason_str
23851 @end smallexample
23852 @end table
23853
23854 @end defun
23855
23856 @defun Frame.pc ()
23857 Returns the frame's resume address.
23858 @end defun
23859
23860 @defun Frame.block ()
23861 Return the frame's code block. @xref{Blocks In Python}.
23862 @end defun
23863
23864 @defun Frame.function ()
23865 Return the symbol for the function corresponding to this frame.
23866 @xref{Symbols In Python}.
23867 @end defun
23868
23869 @defun Frame.older ()
23870 Return the frame that called this frame.
23871 @end defun
23872
23873 @defun Frame.newer ()
23874 Return the frame called by this frame.
23875 @end defun
23876
23877 @defun Frame.find_sal ()
23878 Return the frame's symtab and line object.
23879 @xref{Symbol Tables In Python}.
23880 @end defun
23881
23882 @defun Frame.read_var (variable @r{[}, block@r{]})
23883 Return the value of @var{variable} in this frame. If the optional
23884 argument @var{block} is provided, search for the variable from that
23885 block; otherwise start at the frame's current block (which is
23886 determined by the frame's current program counter). @var{variable}
23887 must be a string or a @code{gdb.Symbol} object. @var{block} must be a
23888 @code{gdb.Block} object.
23889 @end defun
23890
23891 @defun Frame.select ()
23892 Set this frame to be the selected frame. @xref{Stack, ,Examining the
23893 Stack}.
23894 @end defun
23895 @end table
23896
23897 @node Blocks In Python
23898 @subsubsection Accessing frame blocks from Python.
23899
23900 @cindex blocks in python
23901 @tindex gdb.Block
23902
23903 Within each frame, @value{GDBN} maintains information on each block
23904 stored in that frame. These blocks are organized hierarchically, and
23905 are represented individually in Python as a @code{gdb.Block}.
23906 Please see @ref{Frames In Python}, for a more in-depth discussion on
23907 frames. Furthermore, see @ref{Stack, ,Examining the Stack}, for more
23908 detailed technical information on @value{GDBN}'s book-keeping of the
23909 stack.
23910
23911 A @code{gdb.Block} is iterable. The iterator returns the symbols
23912 (@pxref{Symbols In Python}) local to the block.
23913
23914 The following block-related functions are available in the @code{gdb}
23915 module:
23916
23917 @findex gdb.block_for_pc
23918 @defun gdb.block_for_pc (pc)
23919 Return the @code{gdb.Block} containing the given @var{pc} value. If the
23920 block cannot be found for the @var{pc} value specified, the function
23921 will return @code{None}.
23922 @end defun
23923
23924 A @code{gdb.Block} object has the following methods:
23925
23926 @table @code
23927 @defun Block.is_valid ()
23928 Returns @code{True} if the @code{gdb.Block} object is valid,
23929 @code{False} if not. A block object can become invalid if the block it
23930 refers to doesn't exist anymore in the inferior. All other
23931 @code{gdb.Block} methods will throw an exception if it is invalid at
23932 the time the method is called. The block's validity is also checked
23933 during iteration over symbols of the block.
23934 @end defun
23935 @end table
23936
23937 A @code{gdb.Block} object has the following attributes:
23938
23939 @table @code
23940 @defvar Block.start
23941 The start address of the block. This attribute is not writable.
23942 @end defvar
23943
23944 @defvar Block.end
23945 The end address of the block. This attribute is not writable.
23946 @end defvar
23947
23948 @defvar Block.function
23949 The name of the block represented as a @code{gdb.Symbol}. If the
23950 block is not named, then this attribute holds @code{None}. This
23951 attribute is not writable.
23952 @end defvar
23953
23954 @defvar Block.superblock
23955 The block containing this block. If this parent block does not exist,
23956 this attribute holds @code{None}. This attribute is not writable.
23957 @end defvar
23958
23959 @defvar Block.global_block
23960 The global block associated with this block. This attribute is not
23961 writable.
23962 @end defvar
23963
23964 @defvar Block.static_block
23965 The static block associated with this block. This attribute is not
23966 writable.
23967 @end defvar
23968
23969 @defvar Block.is_global
23970 @code{True} if the @code{gdb.Block} object is a global block,
23971 @code{False} if not. This attribute is not
23972 writable.
23973 @end defvar
23974
23975 @defvar Block.is_static
23976 @code{True} if the @code{gdb.Block} object is a static block,
23977 @code{False} if not. This attribute is not writable.
23978 @end defvar
23979 @end table
23980
23981 @node Symbols In Python
23982 @subsubsection Python representation of Symbols.
23983
23984 @cindex symbols in python
23985 @tindex gdb.Symbol
23986
23987 @value{GDBN} represents every variable, function and type as an
23988 entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
23989 Similarly, Python represents these symbols in @value{GDBN} with the
23990 @code{gdb.Symbol} object.
23991
23992 The following symbol-related functions are available in the @code{gdb}
23993 module:
23994
23995 @findex gdb.lookup_symbol
23996 @defun gdb.lookup_symbol (name @r{[}, block @r{[}, domain@r{]]})
23997 This function searches for a symbol by name. The search scope can be
23998 restricted to the parameters defined in the optional domain and block
23999 arguments.
24000
24001 @var{name} is the name of the symbol. It must be a string. The
24002 optional @var{block} argument restricts the search to symbols visible
24003 in that @var{block}. The @var{block} argument must be a
24004 @code{gdb.Block} object. If omitted, the block for the current frame
24005 is used. The optional @var{domain} argument restricts
24006 the search to the domain type. The @var{domain} argument must be a
24007 domain constant defined in the @code{gdb} module and described later
24008 in this chapter.
24009
24010 The result is a tuple of two elements.
24011 The first element is a @code{gdb.Symbol} object or @code{None} if the symbol
24012 is not found.
24013 If the symbol is found, the second element is @code{True} if the symbol
24014 is a field of a method's object (e.g., @code{this} in C@t{++}),
24015 otherwise it is @code{False}.
24016 If the symbol is not found, the second element is @code{False}.
24017 @end defun
24018
24019 @findex gdb.lookup_global_symbol
24020 @defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
24021 This function searches for a global symbol by name.
24022 The search scope can be restricted to by the domain argument.
24023
24024 @var{name} is the name of the symbol. It must be a string.
24025 The optional @var{domain} argument restricts the search to the domain type.
24026 The @var{domain} argument must be a domain constant defined in the @code{gdb}
24027 module and described later in this chapter.
24028
24029 The result is a @code{gdb.Symbol} object or @code{None} if the symbol
24030 is not found.
24031 @end defun
24032
24033 A @code{gdb.Symbol} object has the following attributes:
24034
24035 @table @code
24036 @defvar Symbol.type
24037 The type of the symbol or @code{None} if no type is recorded.
24038 This attribute is represented as a @code{gdb.Type} object.
24039 @xref{Types In Python}. This attribute is not writable.
24040 @end defvar
24041
24042 @defvar Symbol.symtab
24043 The symbol table in which the symbol appears. This attribute is
24044 represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
24045 Python}. This attribute is not writable.
24046 @end defvar
24047
24048 @defvar Symbol.line
24049 The line number in the source code at which the symbol was defined.
24050 This is an integer.
24051 @end defvar
24052
24053 @defvar Symbol.name
24054 The name of the symbol as a string. This attribute is not writable.
24055 @end defvar
24056
24057 @defvar Symbol.linkage_name
24058 The name of the symbol, as used by the linker (i.e., may be mangled).
24059 This attribute is not writable.
24060 @end defvar
24061
24062 @defvar Symbol.print_name
24063 The name of the symbol in a form suitable for output. This is either
24064 @code{name} or @code{linkage_name}, depending on whether the user
24065 asked @value{GDBN} to display demangled or mangled names.
24066 @end defvar
24067
24068 @defvar Symbol.addr_class
24069 The address class of the symbol. This classifies how to find the value
24070 of a symbol. Each address class is a constant defined in the
24071 @code{gdb} module and described later in this chapter.
24072 @end defvar
24073
24074 @defvar Symbol.needs_frame
24075 This is @code{True} if evaluating this symbol's value requires a frame
24076 (@pxref{Frames In Python}) and @code{False} otherwise. Typically,
24077 local variables will require a frame, but other symbols will not.
24078 @end defvar
24079
24080 @defvar Symbol.is_argument
24081 @code{True} if the symbol is an argument of a function.
24082 @end defvar
24083
24084 @defvar Symbol.is_constant
24085 @code{True} if the symbol is a constant.
24086 @end defvar
24087
24088 @defvar Symbol.is_function
24089 @code{True} if the symbol is a function or a method.
24090 @end defvar
24091
24092 @defvar Symbol.is_variable
24093 @code{True} if the symbol is a variable.
24094 @end defvar
24095 @end table
24096
24097 A @code{gdb.Symbol} object has the following methods:
24098
24099 @table @code
24100 @defun Symbol.is_valid ()
24101 Returns @code{True} if the @code{gdb.Symbol} object is valid,
24102 @code{False} if not. A @code{gdb.Symbol} object can become invalid if
24103 the symbol it refers to does not exist in @value{GDBN} any longer.
24104 All other @code{gdb.Symbol} methods will throw an exception if it is
24105 invalid at the time the method is called.
24106 @end defun
24107
24108 @defun Symbol.value (@r{[}frame@r{]})
24109 Compute the value of the symbol, as a @code{gdb.Value}. For
24110 functions, this computes the address of the function, cast to the
24111 appropriate type. If the symbol requires a frame in order to compute
24112 its value, then @var{frame} must be given. If @var{frame} is not
24113 given, or if @var{frame} is invalid, then this method will throw an
24114 exception.
24115 @end defun
24116 @end table
24117
24118 The available domain categories in @code{gdb.Symbol} are represented
24119 as constants in the @code{gdb} module:
24120
24121 @table @code
24122 @findex SYMBOL_UNDEF_DOMAIN
24123 @findex gdb.SYMBOL_UNDEF_DOMAIN
24124 @item gdb.SYMBOL_UNDEF_DOMAIN
24125 This is used when a domain has not been discovered or none of the
24126 following domains apply. This usually indicates an error either
24127 in the symbol information or in @value{GDBN}'s handling of symbols.
24128 @findex SYMBOL_VAR_DOMAIN
24129 @findex gdb.SYMBOL_VAR_DOMAIN
24130 @item gdb.SYMBOL_VAR_DOMAIN
24131 This domain contains variables, function names, typedef names and enum
24132 type values.
24133 @findex SYMBOL_STRUCT_DOMAIN
24134 @findex gdb.SYMBOL_STRUCT_DOMAIN
24135 @item gdb.SYMBOL_STRUCT_DOMAIN
24136 This domain holds struct, union and enum type names.
24137 @findex SYMBOL_LABEL_DOMAIN
24138 @findex gdb.SYMBOL_LABEL_DOMAIN
24139 @item gdb.SYMBOL_LABEL_DOMAIN
24140 This domain contains names of labels (for gotos).
24141 @findex SYMBOL_VARIABLES_DOMAIN
24142 @findex gdb.SYMBOL_VARIABLES_DOMAIN
24143 @item gdb.SYMBOL_VARIABLES_DOMAIN
24144 This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
24145 contains everything minus functions and types.
24146 @findex SYMBOL_FUNCTIONS_DOMAIN
24147 @findex gdb.SYMBOL_FUNCTIONS_DOMAIN
24148 @item gdb.SYMBOL_FUNCTION_DOMAIN
24149 This domain contains all functions.
24150 @findex SYMBOL_TYPES_DOMAIN
24151 @findex gdb.SYMBOL_TYPES_DOMAIN
24152 @item gdb.SYMBOL_TYPES_DOMAIN
24153 This domain contains all types.
24154 @end table
24155
24156 The available address class categories in @code{gdb.Symbol} are represented
24157 as constants in the @code{gdb} module:
24158
24159 @table @code
24160 @findex SYMBOL_LOC_UNDEF
24161 @findex gdb.SYMBOL_LOC_UNDEF
24162 @item gdb.SYMBOL_LOC_UNDEF
24163 If this is returned by address class, it indicates an error either in
24164 the symbol information or in @value{GDBN}'s handling of symbols.
24165 @findex SYMBOL_LOC_CONST
24166 @findex gdb.SYMBOL_LOC_CONST
24167 @item gdb.SYMBOL_LOC_CONST
24168 Value is constant int.
24169 @findex SYMBOL_LOC_STATIC
24170 @findex gdb.SYMBOL_LOC_STATIC
24171 @item gdb.SYMBOL_LOC_STATIC
24172 Value is at a fixed address.
24173 @findex SYMBOL_LOC_REGISTER
24174 @findex gdb.SYMBOL_LOC_REGISTER
24175 @item gdb.SYMBOL_LOC_REGISTER
24176 Value is in a register.
24177 @findex SYMBOL_LOC_ARG
24178 @findex gdb.SYMBOL_LOC_ARG
24179 @item gdb.SYMBOL_LOC_ARG
24180 Value is an argument. This value is at the offset stored within the
24181 symbol inside the frame's argument list.
24182 @findex SYMBOL_LOC_REF_ARG
24183 @findex gdb.SYMBOL_LOC_REF_ARG
24184 @item gdb.SYMBOL_LOC_REF_ARG
24185 Value address is stored in the frame's argument list. Just like
24186 @code{LOC_ARG} except that the value's address is stored at the
24187 offset, not the value itself.
24188 @findex SYMBOL_LOC_REGPARM_ADDR
24189 @findex gdb.SYMBOL_LOC_REGPARM_ADDR
24190 @item gdb.SYMBOL_LOC_REGPARM_ADDR
24191 Value is a specified register. Just like @code{LOC_REGISTER} except
24192 the register holds the address of the argument instead of the argument
24193 itself.
24194 @findex SYMBOL_LOC_LOCAL
24195 @findex gdb.SYMBOL_LOC_LOCAL
24196 @item gdb.SYMBOL_LOC_LOCAL
24197 Value is a local variable.
24198 @findex SYMBOL_LOC_TYPEDEF
24199 @findex gdb.SYMBOL_LOC_TYPEDEF
24200 @item gdb.SYMBOL_LOC_TYPEDEF
24201 Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
24202 have this class.
24203 @findex SYMBOL_LOC_BLOCK
24204 @findex gdb.SYMBOL_LOC_BLOCK
24205 @item gdb.SYMBOL_LOC_BLOCK
24206 Value is a block.
24207 @findex SYMBOL_LOC_CONST_BYTES
24208 @findex gdb.SYMBOL_LOC_CONST_BYTES
24209 @item gdb.SYMBOL_LOC_CONST_BYTES
24210 Value is a byte-sequence.
24211 @findex SYMBOL_LOC_UNRESOLVED
24212 @findex gdb.SYMBOL_LOC_UNRESOLVED
24213 @item gdb.SYMBOL_LOC_UNRESOLVED
24214 Value is at a fixed address, but the address of the variable has to be
24215 determined from the minimal symbol table whenever the variable is
24216 referenced.
24217 @findex SYMBOL_LOC_OPTIMIZED_OUT
24218 @findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
24219 @item gdb.SYMBOL_LOC_OPTIMIZED_OUT
24220 The value does not actually exist in the program.
24221 @findex SYMBOL_LOC_COMPUTED
24222 @findex gdb.SYMBOL_LOC_COMPUTED
24223 @item gdb.SYMBOL_LOC_COMPUTED
24224 The value's address is a computed location.
24225 @end table
24226
24227 @node Symbol Tables In Python
24228 @subsubsection Symbol table representation in Python.
24229
24230 @cindex symbol tables in python
24231 @tindex gdb.Symtab
24232 @tindex gdb.Symtab_and_line
24233
24234 Access to symbol table data maintained by @value{GDBN} on the inferior
24235 is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
24236 @code{gdb.Symtab}. Symbol table and line data for a frame is returned
24237 from the @code{find_sal} method in @code{gdb.Frame} object.
24238 @xref{Frames In Python}.
24239
24240 For more information on @value{GDBN}'s symbol table management, see
24241 @ref{Symbols, ,Examining the Symbol Table}, for more information.
24242
24243 A @code{gdb.Symtab_and_line} object has the following attributes:
24244
24245 @table @code
24246 @defvar Symtab_and_line.symtab
24247 The symbol table object (@code{gdb.Symtab}) for this frame.
24248 This attribute is not writable.
24249 @end defvar
24250
24251 @defvar Symtab_and_line.pc
24252 Indicates the current program counter address. This attribute is not
24253 writable.
24254 @end defvar
24255
24256 @defvar Symtab_and_line.line
24257 Indicates the current line number for this object. This
24258 attribute is not writable.
24259 @end defvar
24260 @end table
24261
24262 A @code{gdb.Symtab_and_line} object has the following methods:
24263
24264 @table @code
24265 @defun Symtab_and_line.is_valid ()
24266 Returns @code{True} if the @code{gdb.Symtab_and_line} object is valid,
24267 @code{False} if not. A @code{gdb.Symtab_and_line} object can become
24268 invalid if the Symbol table and line object it refers to does not
24269 exist in @value{GDBN} any longer. All other
24270 @code{gdb.Symtab_and_line} methods will throw an exception if it is
24271 invalid at the time the method is called.
24272 @end defun
24273 @end table
24274
24275 A @code{gdb.Symtab} object has the following attributes:
24276
24277 @table @code
24278 @defvar Symtab.filename
24279 The symbol table's source filename. This attribute is not writable.
24280 @end defvar
24281
24282 @defvar Symtab.objfile
24283 The symbol table's backing object file. @xref{Objfiles In Python}.
24284 This attribute is not writable.
24285 @end defvar
24286 @end table
24287
24288 A @code{gdb.Symtab} object has the following methods:
24289
24290 @table @code
24291 @defun Symtab.is_valid ()
24292 Returns @code{True} if the @code{gdb.Symtab} object is valid,
24293 @code{False} if not. A @code{gdb.Symtab} object can become invalid if
24294 the symbol table it refers to does not exist in @value{GDBN} any
24295 longer. All other @code{gdb.Symtab} methods will throw an exception
24296 if it is invalid at the time the method is called.
24297 @end defun
24298
24299 @defun Symtab.fullname ()
24300 Return the symbol table's source absolute file name.
24301 @end defun
24302 @end table
24303
24304 @node Breakpoints In Python
24305 @subsubsection Manipulating breakpoints using Python
24306
24307 @cindex breakpoints in python
24308 @tindex gdb.Breakpoint
24309
24310 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
24311 class.
24312
24313 @defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
24314 Create a new breakpoint. @var{spec} is a string naming the
24315 location of the breakpoint, or an expression that defines a
24316 watchpoint. The contents can be any location recognized by the
24317 @code{break} command, or in the case of a watchpoint, by the @code{watch}
24318 command. The optional @var{type} denotes the breakpoint to create
24319 from the types defined later in this chapter. This argument can be
24320 either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}. @var{type}
24321 defaults to @code{gdb.BP_BREAKPOINT}. The optional @var{internal} argument
24322 allows the breakpoint to become invisible to the user. The breakpoint
24323 will neither be reported when created, nor will it be listed in the
24324 output from @code{info breakpoints} (but will be listed with the
24325 @code{maint info breakpoints} command). The optional @var{wp_class}
24326 argument defines the class of watchpoint to create, if @var{type} is
24327 @code{gdb.BP_WATCHPOINT}. If a watchpoint class is not provided, it is
24328 assumed to be a @code{gdb.WP_WRITE} class.
24329 @end defun
24330
24331 @defun Breakpoint.stop (self)
24332 The @code{gdb.Breakpoint} class can be sub-classed and, in
24333 particular, you may choose to implement the @code{stop} method.
24334 If this method is defined as a sub-class of @code{gdb.Breakpoint},
24335 it will be called when the inferior reaches any location of a
24336 breakpoint which instantiates that sub-class. If the method returns
24337 @code{True}, the inferior will be stopped at the location of the
24338 breakpoint, otherwise the inferior will continue.
24339
24340 If there are multiple breakpoints at the same location with a
24341 @code{stop} method, each one will be called regardless of the
24342 return status of the previous. This ensures that all @code{stop}
24343 methods have a chance to execute at that location. In this scenario
24344 if one of the methods returns @code{True} but the others return
24345 @code{False}, the inferior will still be stopped.
24346
24347 You should not alter the execution state of the inferior (i.e.@:, step,
24348 next, etc.), alter the current frame context (i.e.@:, change the current
24349 active frame), or alter, add or delete any breakpoint. As a general
24350 rule, you should not alter any data within @value{GDBN} or the inferior
24351 at this time.
24352
24353 Example @code{stop} implementation:
24354
24355 @smallexample
24356 class MyBreakpoint (gdb.Breakpoint):
24357 def stop (self):
24358 inf_val = gdb.parse_and_eval("foo")
24359 if inf_val == 3:
24360 return True
24361 return False
24362 @end smallexample
24363 @end defun
24364
24365 The available watchpoint types represented by constants are defined in the
24366 @code{gdb} module:
24367
24368 @table @code
24369 @findex WP_READ
24370 @findex gdb.WP_READ
24371 @item gdb.WP_READ
24372 Read only watchpoint.
24373
24374 @findex WP_WRITE
24375 @findex gdb.WP_WRITE
24376 @item gdb.WP_WRITE
24377 Write only watchpoint.
24378
24379 @findex WP_ACCESS
24380 @findex gdb.WP_ACCESS
24381 @item gdb.WP_ACCESS
24382 Read/Write watchpoint.
24383 @end table
24384
24385 @defun Breakpoint.is_valid ()
24386 Return @code{True} if this @code{Breakpoint} object is valid,
24387 @code{False} otherwise. A @code{Breakpoint} object can become invalid
24388 if the user deletes the breakpoint. In this case, the object still
24389 exists, but the underlying breakpoint does not. In the cases of
24390 watchpoint scope, the watchpoint remains valid even if execution of the
24391 inferior leaves the scope of that watchpoint.
24392 @end defun
24393
24394 @defun Breakpoint.delete
24395 Permanently deletes the @value{GDBN} breakpoint. This also
24396 invalidates the Python @code{Breakpoint} object. Any further access
24397 to this object's attributes or methods will raise an error.
24398 @end defun
24399
24400 @defvar Breakpoint.enabled
24401 This attribute is @code{True} if the breakpoint is enabled, and
24402 @code{False} otherwise. This attribute is writable.
24403 @end defvar
24404
24405 @defvar Breakpoint.silent
24406 This attribute is @code{True} if the breakpoint is silent, and
24407 @code{False} otherwise. This attribute is writable.
24408
24409 Note that a breakpoint can also be silent if it has commands and the
24410 first command is @code{silent}. This is not reported by the
24411 @code{silent} attribute.
24412 @end defvar
24413
24414 @defvar Breakpoint.thread
24415 If the breakpoint is thread-specific, this attribute holds the thread
24416 id. If the breakpoint is not thread-specific, this attribute is
24417 @code{None}. This attribute is writable.
24418 @end defvar
24419
24420 @defvar Breakpoint.task
24421 If the breakpoint is Ada task-specific, this attribute holds the Ada task
24422 id. If the breakpoint is not task-specific (or the underlying
24423 language is not Ada), this attribute is @code{None}. This attribute
24424 is writable.
24425 @end defvar
24426
24427 @defvar Breakpoint.ignore_count
24428 This attribute holds the ignore count for the breakpoint, an integer.
24429 This attribute is writable.
24430 @end defvar
24431
24432 @defvar Breakpoint.number
24433 This attribute holds the breakpoint's number --- the identifier used by
24434 the user to manipulate the breakpoint. This attribute is not writable.
24435 @end defvar
24436
24437 @defvar Breakpoint.type
24438 This attribute holds the breakpoint's type --- the identifier used to
24439 determine the actual breakpoint type or use-case. This attribute is not
24440 writable.
24441 @end defvar
24442
24443 @defvar Breakpoint.visible
24444 This attribute tells whether the breakpoint is visible to the user
24445 when set, or when the @samp{info breakpoints} command is run. This
24446 attribute is not writable.
24447 @end defvar
24448
24449 The available types are represented by constants defined in the @code{gdb}
24450 module:
24451
24452 @table @code
24453 @findex BP_BREAKPOINT
24454 @findex gdb.BP_BREAKPOINT
24455 @item gdb.BP_BREAKPOINT
24456 Normal code breakpoint.
24457
24458 @findex BP_WATCHPOINT
24459 @findex gdb.BP_WATCHPOINT
24460 @item gdb.BP_WATCHPOINT
24461 Watchpoint breakpoint.
24462
24463 @findex BP_HARDWARE_WATCHPOINT
24464 @findex gdb.BP_HARDWARE_WATCHPOINT
24465 @item gdb.BP_HARDWARE_WATCHPOINT
24466 Hardware assisted watchpoint.
24467
24468 @findex BP_READ_WATCHPOINT
24469 @findex gdb.BP_READ_WATCHPOINT
24470 @item gdb.BP_READ_WATCHPOINT
24471 Hardware assisted read watchpoint.
24472
24473 @findex BP_ACCESS_WATCHPOINT
24474 @findex gdb.BP_ACCESS_WATCHPOINT
24475 @item gdb.BP_ACCESS_WATCHPOINT
24476 Hardware assisted access watchpoint.
24477 @end table
24478
24479 @defvar Breakpoint.hit_count
24480 This attribute holds the hit count for the breakpoint, an integer.
24481 This attribute is writable, but currently it can only be set to zero.
24482 @end defvar
24483
24484 @defvar Breakpoint.location
24485 This attribute holds the location of the breakpoint, as specified by
24486 the user. It is a string. If the breakpoint does not have a location
24487 (that is, it is a watchpoint) the attribute's value is @code{None}. This
24488 attribute is not writable.
24489 @end defvar
24490
24491 @defvar Breakpoint.expression
24492 This attribute holds a breakpoint expression, as specified by
24493 the user. It is a string. If the breakpoint does not have an
24494 expression (the breakpoint is not a watchpoint) the attribute's value
24495 is @code{None}. This attribute is not writable.
24496 @end defvar
24497
24498 @defvar Breakpoint.condition
24499 This attribute holds the condition of the breakpoint, as specified by
24500 the user. It is a string. If there is no condition, this attribute's
24501 value is @code{None}. This attribute is writable.
24502 @end defvar
24503
24504 @defvar Breakpoint.commands
24505 This attribute holds the commands attached to the breakpoint. If
24506 there are commands, this attribute's value is a string holding all the
24507 commands, separated by newlines. If there are no commands, this
24508 attribute is @code{None}. This attribute is not writable.
24509 @end defvar
24510
24511 @node Finish Breakpoints in Python
24512 @subsubsection Finish Breakpoints
24513
24514 @cindex python finish breakpoints
24515 @tindex gdb.FinishBreakpoint
24516
24517 A finish breakpoint is a temporary breakpoint set at the return address of
24518 a frame, based on the @code{finish} command. @code{gdb.FinishBreakpoint}
24519 extends @code{gdb.Breakpoint}. The underlying breakpoint will be disabled
24520 and deleted when the execution will run out of the breakpoint scope (i.e.@:
24521 @code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
24522 Finish breakpoints are thread specific and must be create with the right
24523 thread selected.
24524
24525 @defun FinishBreakpoint.__init__ (@r{[}frame@r{]} @r{[}, internal@r{]})
24526 Create a finish breakpoint at the return address of the @code{gdb.Frame}
24527 object @var{frame}. If @var{frame} is not provided, this defaults to the
24528 newest frame. The optional @var{internal} argument allows the breakpoint to
24529 become invisible to the user. @xref{Breakpoints In Python}, for further
24530 details about this argument.
24531 @end defun
24532
24533 @defun FinishBreakpoint.out_of_scope (self)
24534 In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN}
24535 @code{return} command, @dots{}), a function may not properly terminate, and
24536 thus never hit the finish breakpoint. When @value{GDBN} notices such a
24537 situation, the @code{out_of_scope} callback will be triggered.
24538
24539 You may want to sub-class @code{gdb.FinishBreakpoint} and override this
24540 method:
24541
24542 @smallexample
24543 class MyFinishBreakpoint (gdb.FinishBreakpoint)
24544 def stop (self):
24545 print "normal finish"
24546 return True
24547
24548 def out_of_scope ():
24549 print "abnormal finish"
24550 @end smallexample
24551 @end defun
24552
24553 @defvar FinishBreakpoint.return_value
24554 When @value{GDBN} is stopped at a finish breakpoint and the frame
24555 used to build the @code{gdb.FinishBreakpoint} object had debug symbols, this
24556 attribute will contain a @code{gdb.Value} object corresponding to the return
24557 value of the function. The value will be @code{None} if the function return
24558 type is @code{void} or if the return value was not computable. This attribute
24559 is not writable.
24560 @end defvar
24561
24562 @node Lazy Strings In Python
24563 @subsubsection Python representation of lazy strings.
24564
24565 @cindex lazy strings in python
24566 @tindex gdb.LazyString
24567
24568 A @dfn{lazy string} is a string whose contents is not retrieved or
24569 encoded until it is needed.
24570
24571 A @code{gdb.LazyString} is represented in @value{GDBN} as an
24572 @code{address} that points to a region of memory, an @code{encoding}
24573 that will be used to encode that region of memory, and a @code{length}
24574 to delimit the region of memory that represents the string. The
24575 difference between a @code{gdb.LazyString} and a string wrapped within
24576 a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
24577 differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
24578 retrieved and encoded during printing, while a @code{gdb.Value}
24579 wrapping a string is immediately retrieved and encoded on creation.
24580
24581 A @code{gdb.LazyString} object has the following functions:
24582
24583 @defun LazyString.value ()
24584 Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
24585 will point to the string in memory, but will lose all the delayed
24586 retrieval, encoding and handling that @value{GDBN} applies to a
24587 @code{gdb.LazyString}.
24588 @end defun
24589
24590 @defvar LazyString.address
24591 This attribute holds the address of the string. This attribute is not
24592 writable.
24593 @end defvar
24594
24595 @defvar LazyString.length
24596 This attribute holds the length of the string in characters. If the
24597 length is -1, then the string will be fetched and encoded up to the
24598 first null of appropriate width. This attribute is not writable.
24599 @end defvar
24600
24601 @defvar LazyString.encoding
24602 This attribute holds the encoding that will be applied to the string
24603 when the string is printed by @value{GDBN}. If the encoding is not
24604 set, or contains an empty string, then @value{GDBN} will select the
24605 most appropriate encoding when the string is printed. This attribute
24606 is not writable.
24607 @end defvar
24608
24609 @defvar LazyString.type
24610 This attribute holds the type that is represented by the lazy string's
24611 type. For a lazy string this will always be a pointer type. To
24612 resolve this to the lazy string's character type, use the type's
24613 @code{target} method. @xref{Types In Python}. This attribute is not
24614 writable.
24615 @end defvar
24616
24617 @node Auto-loading
24618 @subsection Auto-loading
24619 @cindex auto-loading, Python
24620
24621 When a new object file is read (for example, due to the @code{file}
24622 command, or because the inferior has loaded a shared library),
24623 @value{GDBN} will look for Python support scripts in several ways:
24624 @file{@var{objfile}-gdb.py} and @code{.debug_gdb_scripts} section.
24625
24626 @menu
24627 * objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
24628 * .debug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
24629 * Which flavor to choose?::
24630 @end menu
24631
24632 The auto-loading feature is useful for supplying application-specific
24633 debugging commands and scripts.
24634
24635 Auto-loading can be enabled or disabled,
24636 and the list of auto-loaded scripts can be printed.
24637
24638 @table @code
24639 @kindex set auto-load-scripts
24640 @item set auto-load-scripts [yes|no]
24641 Enable or disable the auto-loading of Python scripts.
24642
24643 @kindex show auto-load-scripts
24644 @item show auto-load-scripts
24645 Show whether auto-loading of Python scripts is enabled or disabled.
24646
24647 @kindex info auto-load-scripts
24648 @cindex print list of auto-loaded scripts
24649 @item info auto-load-scripts [@var{regexp}]
24650 Print the list of all scripts that @value{GDBN} auto-loaded.
24651
24652 Also printed is the list of scripts that were mentioned in
24653 the @code{.debug_gdb_scripts} section and were not found
24654 (@pxref{.debug_gdb_scripts section}).
24655 This is useful because their names are not printed when @value{GDBN}
24656 tries to load them and fails. There may be many of them, and printing
24657 an error message for each one is problematic.
24658
24659 If @var{regexp} is supplied only scripts with matching names are printed.
24660
24661 Example:
24662
24663 @smallexample
24664 (gdb) info auto-load-scripts
24665 Loaded Script
24666 Yes py-section-script.py
24667 full name: /tmp/py-section-script.py
24668 Missing my-foo-pretty-printers.py
24669 @end smallexample
24670 @end table
24671
24672 When reading an auto-loaded file, @value{GDBN} sets the
24673 @dfn{current objfile}. This is available via the @code{gdb.current_objfile}
24674 function (@pxref{Objfiles In Python}). This can be useful for
24675 registering objfile-specific pretty-printers.
24676
24677 @node objfile-gdb.py file
24678 @subsubsection The @file{@var{objfile}-gdb.py} file
24679 @cindex @file{@var{objfile}-gdb.py}
24680
24681 When a new object file is read, @value{GDBN} looks for
24682 a file named @file{@var{objfile}-gdb.py},
24683 where @var{objfile} is the object file's real name, formed by ensuring
24684 that the file name is absolute, following all symlinks, and resolving
24685 @code{.} and @code{..} components. If this file exists and is
24686 readable, @value{GDBN} will evaluate it as a Python script.
24687
24688 If this file does not exist, and if the parameter
24689 @code{debug-file-directory} is set (@pxref{Separate Debug Files}),
24690 then @value{GDBN} will look for @var{real-name} in all of the
24691 directories mentioned in the value of @code{debug-file-directory}.
24692
24693 Finally, if this file does not exist, then @value{GDBN} will look for
24694 a file named @file{@var{data-directory}/auto-load/@var{real-name}}, where
24695 @var{data-directory} is @value{GDBN}'s data directory (available via
24696 @code{show data-directory}, @pxref{Data Files}), and @var{real-name}
24697 is the object file's real name, as described above.
24698
24699 @value{GDBN} does not track which files it has already auto-loaded this way.
24700 @value{GDBN} will load the associated script every time the corresponding
24701 @var{objfile} is opened.
24702 So your @file{-gdb.py} file should be careful to avoid errors if it
24703 is evaluated more than once.
24704
24705 @node .debug_gdb_scripts section
24706 @subsubsection The @code{.debug_gdb_scripts} section
24707 @cindex @code{.debug_gdb_scripts} section
24708
24709 For systems using file formats like ELF and COFF,
24710 when @value{GDBN} loads a new object file
24711 it will look for a special section named @samp{.debug_gdb_scripts}.
24712 If this section exists, its contents is a list of names of scripts to load.
24713
24714 @value{GDBN} will look for each specified script file first in the
24715 current directory and then along the source search path
24716 (@pxref{Source Path, ,Specifying Source Directories}),
24717 except that @file{$cdir} is not searched, since the compilation
24718 directory is not relevant to scripts.
24719
24720 Entries can be placed in section @code{.debug_gdb_scripts} with,
24721 for example, this GCC macro:
24722
24723 @example
24724 /* Note: The "MS" section flags are to remove duplicates. */
24725 #define DEFINE_GDB_SCRIPT(script_name) \
24726 asm("\
24727 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
24728 .byte 1\n\
24729 .asciz \"" script_name "\"\n\
24730 .popsection \n\
24731 ");
24732 @end example
24733
24734 @noindent
24735 Then one can reference the macro in a header or source file like this:
24736
24737 @example
24738 DEFINE_GDB_SCRIPT ("my-app-scripts.py")
24739 @end example
24740
24741 The script name may include directories if desired.
24742
24743 If the macro is put in a header, any application or library
24744 using this header will get a reference to the specified script.
24745
24746 @node Which flavor to choose?
24747 @subsubsection Which flavor to choose?
24748
24749 Given the multiple ways of auto-loading Python scripts, it might not always
24750 be clear which one to choose. This section provides some guidance.
24751
24752 Benefits of the @file{-gdb.py} way:
24753
24754 @itemize @bullet
24755 @item
24756 Can be used with file formats that don't support multiple sections.
24757
24758 @item
24759 Ease of finding scripts for public libraries.
24760
24761 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
24762 in the source search path.
24763 For publicly installed libraries, e.g., @file{libstdc++}, there typically
24764 isn't a source directory in which to find the script.
24765
24766 @item
24767 Doesn't require source code additions.
24768 @end itemize
24769
24770 Benefits of the @code{.debug_gdb_scripts} way:
24771
24772 @itemize @bullet
24773 @item
24774 Works with static linking.
24775
24776 Scripts for libraries done the @file{-gdb.py} way require an objfile to
24777 trigger their loading. When an application is statically linked the only
24778 objfile available is the executable, and it is cumbersome to attach all the
24779 scripts from all the input libraries to the executable's @file{-gdb.py} script.
24780
24781 @item
24782 Works with classes that are entirely inlined.
24783
24784 Some classes can be entirely inlined, and thus there may not be an associated
24785 shared library to attach a @file{-gdb.py} script to.
24786
24787 @item
24788 Scripts needn't be copied out of the source tree.
24789
24790 In some circumstances, apps can be built out of large collections of internal
24791 libraries, and the build infrastructure necessary to install the
24792 @file{-gdb.py} scripts in a place where @value{GDBN} can find them is
24793 cumbersome. It may be easier to specify the scripts in the
24794 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
24795 top of the source tree to the source search path.
24796 @end itemize
24797
24798 @node Python modules
24799 @subsection Python modules
24800 @cindex python modules
24801
24802 @value{GDBN} comes with several modules to assist writing Python code.
24803
24804 @menu
24805 * gdb.printing:: Building and registering pretty-printers.
24806 * gdb.types:: Utilities for working with types.
24807 * gdb.prompt:: Utilities for prompt value substitution.
24808 @end menu
24809
24810 @node gdb.printing
24811 @subsubsection gdb.printing
24812 @cindex gdb.printing
24813
24814 This module provides a collection of utilities for working with
24815 pretty-printers.
24816
24817 @table @code
24818 @item PrettyPrinter (@var{name}, @var{subprinters}=None)
24819 This class specifies the API that makes @samp{info pretty-printer},
24820 @samp{enable pretty-printer} and @samp{disable pretty-printer} work.
24821 Pretty-printers should generally inherit from this class.
24822
24823 @item SubPrettyPrinter (@var{name})
24824 For printers that handle multiple types, this class specifies the
24825 corresponding API for the subprinters.
24826
24827 @item RegexpCollectionPrettyPrinter (@var{name})
24828 Utility class for handling multiple printers, all recognized via
24829 regular expressions.
24830 @xref{Writing a Pretty-Printer}, for an example.
24831
24832 @item FlagEnumerationPrinter (@var{name})
24833 A pretty-printer which handles printing of @code{enum} values. Unlike
24834 @value{GDBN}'s built-in @code{enum} printing, this printer attempts to
24835 work properly when there is some overlap between the enumeration
24836 constants. @var{name} is the name of the printer and also the name of
24837 the @code{enum} type to look up.
24838
24839 @item register_pretty_printer (@var{obj}, @var{printer}, @var{replace}=False)
24840 Register @var{printer} with the pretty-printer list of @var{obj}.
24841 If @var{replace} is @code{True} then any existing copy of the printer
24842 is replaced. Otherwise a @code{RuntimeError} exception is raised
24843 if a printer with the same name already exists.
24844 @end table
24845
24846 @node gdb.types
24847 @subsubsection gdb.types
24848 @cindex gdb.types
24849
24850 This module provides a collection of utilities for working with
24851 @code{gdb.Types} objects.
24852
24853 @table @code
24854 @item get_basic_type (@var{type})
24855 Return @var{type} with const and volatile qualifiers stripped,
24856 and with typedefs and C@t{++} references converted to the underlying type.
24857
24858 C@t{++} example:
24859
24860 @smallexample
24861 typedef const int const_int;
24862 const_int foo (3);
24863 const_int& foo_ref (foo);
24864 int main () @{ return 0; @}
24865 @end smallexample
24866
24867 Then in gdb:
24868
24869 @smallexample
24870 (gdb) start
24871 (gdb) python import gdb.types
24872 (gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
24873 (gdb) python print gdb.types.get_basic_type(foo_ref.type)
24874 int
24875 @end smallexample
24876
24877 @item has_field (@var{type}, @var{field})
24878 Return @code{True} if @var{type}, assumed to be a type with fields
24879 (e.g., a structure or union), has field @var{field}.
24880
24881 @item make_enum_dict (@var{enum_type})
24882 Return a Python @code{dictionary} type produced from @var{enum_type}.
24883
24884 @item deep_items (@var{type})
24885 Returns a Python iterator similar to the standard
24886 @code{gdb.Type.iteritems} method, except that the iterator returned
24887 by @code{deep_items} will recursively traverse anonymous struct or
24888 union fields. For example:
24889
24890 @smallexample
24891 struct A
24892 @{
24893 int a;
24894 union @{
24895 int b0;
24896 int b1;
24897 @};
24898 @};
24899 @end smallexample
24900
24901 @noindent
24902 Then in @value{GDBN}:
24903 @smallexample
24904 (@value{GDBP}) python import gdb.types
24905 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
24906 (@value{GDBP}) python print struct_a.keys ()
24907 @{['a', '']@}
24908 (@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
24909 @{['a', 'b0', 'b1']@}
24910 @end smallexample
24911
24912 @end table
24913
24914 @node gdb.prompt
24915 @subsubsection gdb.prompt
24916 @cindex gdb.prompt
24917
24918 This module provides a method for prompt value-substitution.
24919
24920 @table @code
24921 @item substitute_prompt (@var{string})
24922 Return @var{string} with escape sequences substituted by values. Some
24923 escape sequences take arguments. You can specify arguments inside
24924 ``@{@}'' immediately following the escape sequence.
24925
24926 The escape sequences you can pass to this function are:
24927
24928 @table @code
24929 @item \\
24930 Substitute a backslash.
24931 @item \e
24932 Substitute an ESC character.
24933 @item \f
24934 Substitute the selected frame; an argument names a frame parameter.
24935 @item \n
24936 Substitute a newline.
24937 @item \p
24938 Substitute a parameter's value; the argument names the parameter.
24939 @item \r
24940 Substitute a carriage return.
24941 @item \t
24942 Substitute the selected thread; an argument names a thread parameter.
24943 @item \v
24944 Substitute the version of GDB.
24945 @item \w
24946 Substitute the current working directory.
24947 @item \[
24948 Begin a sequence of non-printing characters. These sequences are
24949 typically used with the ESC character, and are not counted in the string
24950 length. Example: ``\[\e[0;34m\](gdb)\[\e[0m\]'' will return a
24951 blue-colored ``(gdb)'' prompt where the length is five.
24952 @item \]
24953 End a sequence of non-printing characters.
24954 @end table
24955
24956 For example:
24957
24958 @smallexample
24959 substitute_prompt (``frame: \f,
24960 print arguments: \p@{print frame-arguments@}'')
24961 @end smallexample
24962
24963 @exdent will return the string:
24964
24965 @smallexample
24966 "frame: main, print arguments: scalars"
24967 @end smallexample
24968 @end table
24969
24970 @node Aliases
24971 @section Creating new spellings of existing commands
24972 @cindex aliases for commands
24973
24974 It is often useful to define alternate spellings of existing commands.
24975 For example, if a new @value{GDBN} command defined in Python has
24976 a long name to type, it is handy to have an abbreviated version of it
24977 that involves less typing.
24978
24979 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
24980 of the @samp{step} command even though it is otherwise an ambiguous
24981 abbreviation of other commands like @samp{set} and @samp{show}.
24982
24983 Aliases are also used to provide shortened or more common versions
24984 of multi-word commands. For example, @value{GDBN} provides the
24985 @samp{tty} alias of the @samp{set inferior-tty} command.
24986
24987 You can define a new alias with the @samp{alias} command.
24988
24989 @table @code
24990
24991 @kindex alias
24992 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
24993
24994 @end table
24995
24996 @var{ALIAS} specifies the name of the new alias.
24997 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
24998 underscores.
24999
25000 @var{COMMAND} specifies the name of an existing command
25001 that is being aliased.
25002
25003 The @samp{-a} option specifies that the new alias is an abbreviation
25004 of the command. Abbreviations are not shown in command
25005 lists displayed by the @samp{help} command.
25006
25007 The @samp{--} option specifies the end of options,
25008 and is useful when @var{ALIAS} begins with a dash.
25009
25010 Here is a simple example showing how to make an abbreviation
25011 of a command so that there is less to type.
25012 Suppose you were tired of typing @samp{disas}, the current
25013 shortest unambiguous abbreviation of the @samp{disassemble} command
25014 and you wanted an even shorter version named @samp{di}.
25015 The following will accomplish this.
25016
25017 @smallexample
25018 (gdb) alias -a di = disas
25019 @end smallexample
25020
25021 Note that aliases are different from user-defined commands.
25022 With a user-defined command, you also need to write documentation
25023 for it with the @samp{document} command.
25024 An alias automatically picks up the documentation of the existing command.
25025
25026 Here is an example where we make @samp{elms} an abbreviation of
25027 @samp{elements} in the @samp{set print elements} command.
25028 This is to show that you can make an abbreviation of any part
25029 of a command.
25030
25031 @smallexample
25032 (gdb) alias -a set print elms = set print elements
25033 (gdb) alias -a show print elms = show print elements
25034 (gdb) set p elms 20
25035 (gdb) show p elms
25036 Limit on string chars or array elements to print is 200.
25037 @end smallexample
25038
25039 Note that if you are defining an alias of a @samp{set} command,
25040 and you want to have an alias for the corresponding @samp{show}
25041 command, then you need to define the latter separately.
25042
25043 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
25044 @var{ALIAS}, just as they are normally.
25045
25046 @smallexample
25047 (gdb) alias -a set pr elms = set p ele
25048 @end smallexample
25049
25050 Finally, here is an example showing the creation of a one word
25051 alias for a more complex command.
25052 This creates alias @samp{spe} of the command @samp{set print elements}.
25053
25054 @smallexample
25055 (gdb) alias spe = set print elements
25056 (gdb) spe 20
25057 @end smallexample
25058
25059 @node Interpreters
25060 @chapter Command Interpreters
25061 @cindex command interpreters
25062
25063 @value{GDBN} supports multiple command interpreters, and some command
25064 infrastructure to allow users or user interface writers to switch
25065 between interpreters or run commands in other interpreters.
25066
25067 @value{GDBN} currently supports two command interpreters, the console
25068 interpreter (sometimes called the command-line interpreter or @sc{cli})
25069 and the machine interface interpreter (or @sc{gdb/mi}). This manual
25070 describes both of these interfaces in great detail.
25071
25072 By default, @value{GDBN} will start with the console interpreter.
25073 However, the user may choose to start @value{GDBN} with another
25074 interpreter by specifying the @option{-i} or @option{--interpreter}
25075 startup options. Defined interpreters include:
25076
25077 @table @code
25078 @item console
25079 @cindex console interpreter
25080 The traditional console or command-line interpreter. This is the most often
25081 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
25082 @value{GDBN} will use this interpreter.
25083
25084 @item mi
25085 @cindex mi interpreter
25086 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
25087 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
25088 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
25089 Interface}.
25090
25091 @item mi2
25092 @cindex mi2 interpreter
25093 The current @sc{gdb/mi} interface.
25094
25095 @item mi1
25096 @cindex mi1 interpreter
25097 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
25098
25099 @end table
25100
25101 @cindex invoke another interpreter
25102 The interpreter being used by @value{GDBN} may not be dynamically
25103 switched at runtime. Although possible, this could lead to a very
25104 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
25105 enters the command "interpreter-set console" in a console view,
25106 @value{GDBN} would switch to using the console interpreter, rendering
25107 the IDE inoperable!
25108
25109 @kindex interpreter-exec
25110 Although you may only choose a single interpreter at startup, you may execute
25111 commands in any interpreter from the current interpreter using the appropriate
25112 command. If you are running the console interpreter, simply use the
25113 @code{interpreter-exec} command:
25114
25115 @smallexample
25116 interpreter-exec mi "-data-list-register-names"
25117 @end smallexample
25118
25119 @sc{gdb/mi} has a similar command, although it is only available in versions of
25120 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
25121
25122 @node TUI
25123 @chapter @value{GDBN} Text User Interface
25124 @cindex TUI
25125 @cindex Text User Interface
25126
25127 @menu
25128 * TUI Overview:: TUI overview
25129 * TUI Keys:: TUI key bindings
25130 * TUI Single Key Mode:: TUI single key mode
25131 * TUI Commands:: TUI-specific commands
25132 * TUI Configuration:: TUI configuration variables
25133 @end menu
25134
25135 The @value{GDBN} Text User Interface (TUI) is a terminal
25136 interface which uses the @code{curses} library to show the source
25137 file, the assembly output, the program registers and @value{GDBN}
25138 commands in separate text windows. The TUI mode is supported only
25139 on platforms where a suitable version of the @code{curses} library
25140 is available.
25141
25142 The TUI mode is enabled by default when you invoke @value{GDBN} as
25143 @samp{@value{GDBP} -tui}.
25144 You can also switch in and out of TUI mode while @value{GDBN} runs by
25145 using various TUI commands and key bindings, such as @kbd{C-x C-a}.
25146 @xref{TUI Keys, ,TUI Key Bindings}.
25147
25148 @node TUI Overview
25149 @section TUI Overview
25150
25151 In TUI mode, @value{GDBN} can display several text windows:
25152
25153 @table @emph
25154 @item command
25155 This window is the @value{GDBN} command window with the @value{GDBN}
25156 prompt and the @value{GDBN} output. The @value{GDBN} input is still
25157 managed using readline.
25158
25159 @item source
25160 The source window shows the source file of the program. The current
25161 line and active breakpoints are displayed in this window.
25162
25163 @item assembly
25164 The assembly window shows the disassembly output of the program.
25165
25166 @item register
25167 This window shows the processor registers. Registers are highlighted
25168 when their values change.
25169 @end table
25170
25171 The source and assembly windows show the current program position
25172 by highlighting the current line and marking it with a @samp{>} marker.
25173 Breakpoints are indicated with two markers. The first marker
25174 indicates the breakpoint type:
25175
25176 @table @code
25177 @item B
25178 Breakpoint which was hit at least once.
25179
25180 @item b
25181 Breakpoint which was never hit.
25182
25183 @item H
25184 Hardware breakpoint which was hit at least once.
25185
25186 @item h
25187 Hardware breakpoint which was never hit.
25188 @end table
25189
25190 The second marker indicates whether the breakpoint is enabled or not:
25191
25192 @table @code
25193 @item +
25194 Breakpoint is enabled.
25195
25196 @item -
25197 Breakpoint is disabled.
25198 @end table
25199
25200 The source, assembly and register windows are updated when the current
25201 thread changes, when the frame changes, or when the program counter
25202 changes.
25203
25204 These windows are not all visible at the same time. The command
25205 window is always visible. The others can be arranged in several
25206 layouts:
25207
25208 @itemize @bullet
25209 @item
25210 source only,
25211
25212 @item
25213 assembly only,
25214
25215 @item
25216 source and assembly,
25217
25218 @item
25219 source and registers, or
25220
25221 @item
25222 assembly and registers.
25223 @end itemize
25224
25225 A status line above the command window shows the following information:
25226
25227 @table @emph
25228 @item target
25229 Indicates the current @value{GDBN} target.
25230 (@pxref{Targets, ,Specifying a Debugging Target}).
25231
25232 @item process
25233 Gives the current process or thread number.
25234 When no process is being debugged, this field is set to @code{No process}.
25235
25236 @item function
25237 Gives the current function name for the selected frame.
25238 The name is demangled if demangling is turned on (@pxref{Print Settings}).
25239 When there is no symbol corresponding to the current program counter,
25240 the string @code{??} is displayed.
25241
25242 @item line
25243 Indicates the current line number for the selected frame.
25244 When the current line number is not known, the string @code{??} is displayed.
25245
25246 @item pc
25247 Indicates the current program counter address.
25248 @end table
25249
25250 @node TUI Keys
25251 @section TUI Key Bindings
25252 @cindex TUI key bindings
25253
25254 The TUI installs several key bindings in the readline keymaps
25255 @ifset SYSTEM_READLINE
25256 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
25257 @end ifset
25258 @ifclear SYSTEM_READLINE
25259 (@pxref{Command Line Editing}).
25260 @end ifclear
25261 The following key bindings are installed for both TUI mode and the
25262 @value{GDBN} standard mode.
25263
25264 @table @kbd
25265 @kindex C-x C-a
25266 @item C-x C-a
25267 @kindex C-x a
25268 @itemx C-x a
25269 @kindex C-x A
25270 @itemx C-x A
25271 Enter or leave the TUI mode. When leaving the TUI mode,
25272 the curses window management stops and @value{GDBN} operates using
25273 its standard mode, writing on the terminal directly. When reentering
25274 the TUI mode, control is given back to the curses windows.
25275 The screen is then refreshed.
25276
25277 @kindex C-x 1
25278 @item C-x 1
25279 Use a TUI layout with only one window. The layout will
25280 either be @samp{source} or @samp{assembly}. When the TUI mode
25281 is not active, it will switch to the TUI mode.
25282
25283 Think of this key binding as the Emacs @kbd{C-x 1} binding.
25284
25285 @kindex C-x 2
25286 @item C-x 2
25287 Use a TUI layout with at least two windows. When the current
25288 layout already has two windows, the next layout with two windows is used.
25289 When a new layout is chosen, one window will always be common to the
25290 previous layout and the new one.
25291
25292 Think of it as the Emacs @kbd{C-x 2} binding.
25293
25294 @kindex C-x o
25295 @item C-x o
25296 Change the active window. The TUI associates several key bindings
25297 (like scrolling and arrow keys) with the active window. This command
25298 gives the focus to the next TUI window.
25299
25300 Think of it as the Emacs @kbd{C-x o} binding.
25301
25302 @kindex C-x s
25303 @item C-x s
25304 Switch in and out of the TUI SingleKey mode that binds single
25305 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
25306 @end table
25307
25308 The following key bindings only work in the TUI mode:
25309
25310 @table @asis
25311 @kindex PgUp
25312 @item @key{PgUp}
25313 Scroll the active window one page up.
25314
25315 @kindex PgDn
25316 @item @key{PgDn}
25317 Scroll the active window one page down.
25318
25319 @kindex Up
25320 @item @key{Up}
25321 Scroll the active window one line up.
25322
25323 @kindex Down
25324 @item @key{Down}
25325 Scroll the active window one line down.
25326
25327 @kindex Left
25328 @item @key{Left}
25329 Scroll the active window one column left.
25330
25331 @kindex Right
25332 @item @key{Right}
25333 Scroll the active window one column right.
25334
25335 @kindex C-L
25336 @item @kbd{C-L}
25337 Refresh the screen.
25338 @end table
25339
25340 Because the arrow keys scroll the active window in the TUI mode, they
25341 are not available for their normal use by readline unless the command
25342 window has the focus. When another window is active, you must use
25343 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
25344 and @kbd{C-f} to control the command window.
25345
25346 @node TUI Single Key Mode
25347 @section TUI Single Key Mode
25348 @cindex TUI single key mode
25349
25350 The TUI also provides a @dfn{SingleKey} mode, which binds several
25351 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
25352 switch into this mode, where the following key bindings are used:
25353
25354 @table @kbd
25355 @kindex c @r{(SingleKey TUI key)}
25356 @item c
25357 continue
25358
25359 @kindex d @r{(SingleKey TUI key)}
25360 @item d
25361 down
25362
25363 @kindex f @r{(SingleKey TUI key)}
25364 @item f
25365 finish
25366
25367 @kindex n @r{(SingleKey TUI key)}
25368 @item n
25369 next
25370
25371 @kindex q @r{(SingleKey TUI key)}
25372 @item q
25373 exit the SingleKey mode.
25374
25375 @kindex r @r{(SingleKey TUI key)}
25376 @item r
25377 run
25378
25379 @kindex s @r{(SingleKey TUI key)}
25380 @item s
25381 step
25382
25383 @kindex u @r{(SingleKey TUI key)}
25384 @item u
25385 up
25386
25387 @kindex v @r{(SingleKey TUI key)}
25388 @item v
25389 info locals
25390
25391 @kindex w @r{(SingleKey TUI key)}
25392 @item w
25393 where
25394 @end table
25395
25396 Other keys temporarily switch to the @value{GDBN} command prompt.
25397 The key that was pressed is inserted in the editing buffer so that
25398 it is possible to type most @value{GDBN} commands without interaction
25399 with the TUI SingleKey mode. Once the command is entered the TUI
25400 SingleKey mode is restored. The only way to permanently leave
25401 this mode is by typing @kbd{q} or @kbd{C-x s}.
25402
25403
25404 @node TUI Commands
25405 @section TUI-specific Commands
25406 @cindex TUI commands
25407
25408 The TUI has specific commands to control the text windows.
25409 These commands are always available, even when @value{GDBN} is not in
25410 the TUI mode. When @value{GDBN} is in the standard mode, most
25411 of these commands will automatically switch to the TUI mode.
25412
25413 Note that if @value{GDBN}'s @code{stdout} is not connected to a
25414 terminal, or @value{GDBN} has been started with the machine interface
25415 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
25416 these commands will fail with an error, because it would not be
25417 possible or desirable to enable curses window management.
25418
25419 @table @code
25420 @item info win
25421 @kindex info win
25422 List and give the size of all displayed windows.
25423
25424 @item layout next
25425 @kindex layout
25426 Display the next layout.
25427
25428 @item layout prev
25429 Display the previous layout.
25430
25431 @item layout src
25432 Display the source window only.
25433
25434 @item layout asm
25435 Display the assembly window only.
25436
25437 @item layout split
25438 Display the source and assembly window.
25439
25440 @item layout regs
25441 Display the register window together with the source or assembly window.
25442
25443 @item focus next
25444 @kindex focus
25445 Make the next window active for scrolling.
25446
25447 @item focus prev
25448 Make the previous window active for scrolling.
25449
25450 @item focus src
25451 Make the source window active for scrolling.
25452
25453 @item focus asm
25454 Make the assembly window active for scrolling.
25455
25456 @item focus regs
25457 Make the register window active for scrolling.
25458
25459 @item focus cmd
25460 Make the command window active for scrolling.
25461
25462 @item refresh
25463 @kindex refresh
25464 Refresh the screen. This is similar to typing @kbd{C-L}.
25465
25466 @item tui reg float
25467 @kindex tui reg
25468 Show the floating point registers in the register window.
25469
25470 @item tui reg general
25471 Show the general registers in the register window.
25472
25473 @item tui reg next
25474 Show the next register group. The list of register groups as well as
25475 their order is target specific. The predefined register groups are the
25476 following: @code{general}, @code{float}, @code{system}, @code{vector},
25477 @code{all}, @code{save}, @code{restore}.
25478
25479 @item tui reg system
25480 Show the system registers in the register window.
25481
25482 @item update
25483 @kindex update
25484 Update the source window and the current execution point.
25485
25486 @item winheight @var{name} +@var{count}
25487 @itemx winheight @var{name} -@var{count}
25488 @kindex winheight
25489 Change the height of the window @var{name} by @var{count}
25490 lines. Positive counts increase the height, while negative counts
25491 decrease it.
25492
25493 @item tabset @var{nchars}
25494 @kindex tabset
25495 Set the width of tab stops to be @var{nchars} characters.
25496 @end table
25497
25498 @node TUI Configuration
25499 @section TUI Configuration Variables
25500 @cindex TUI configuration variables
25501
25502 Several configuration variables control the appearance of TUI windows.
25503
25504 @table @code
25505 @item set tui border-kind @var{kind}
25506 @kindex set tui border-kind
25507 Select the border appearance for the source, assembly and register windows.
25508 The possible values are the following:
25509 @table @code
25510 @item space
25511 Use a space character to draw the border.
25512
25513 @item ascii
25514 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
25515
25516 @item acs
25517 Use the Alternate Character Set to draw the border. The border is
25518 drawn using character line graphics if the terminal supports them.
25519 @end table
25520
25521 @item set tui border-mode @var{mode}
25522 @kindex set tui border-mode
25523 @itemx set tui active-border-mode @var{mode}
25524 @kindex set tui active-border-mode
25525 Select the display attributes for the borders of the inactive windows
25526 or the active window. The @var{mode} can be one of the following:
25527 @table @code
25528 @item normal
25529 Use normal attributes to display the border.
25530
25531 @item standout
25532 Use standout mode.
25533
25534 @item reverse
25535 Use reverse video mode.
25536
25537 @item half
25538 Use half bright mode.
25539
25540 @item half-standout
25541 Use half bright and standout mode.
25542
25543 @item bold
25544 Use extra bright or bold mode.
25545
25546 @item bold-standout
25547 Use extra bright or bold and standout mode.
25548 @end table
25549 @end table
25550
25551 @node Emacs
25552 @chapter Using @value{GDBN} under @sc{gnu} Emacs
25553
25554 @cindex Emacs
25555 @cindex @sc{gnu} Emacs
25556 A special interface allows you to use @sc{gnu} Emacs to view (and
25557 edit) the source files for the program you are debugging with
25558 @value{GDBN}.
25559
25560 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
25561 executable file you want to debug as an argument. This command starts
25562 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
25563 created Emacs buffer.
25564 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
25565
25566 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
25567 things:
25568
25569 @itemize @bullet
25570 @item
25571 All ``terminal'' input and output goes through an Emacs buffer, called
25572 the GUD buffer.
25573
25574 This applies both to @value{GDBN} commands and their output, and to the input
25575 and output done by the program you are debugging.
25576
25577 This is useful because it means that you can copy the text of previous
25578 commands and input them again; you can even use parts of the output
25579 in this way.
25580
25581 All the facilities of Emacs' Shell mode are available for interacting
25582 with your program. In particular, you can send signals the usual
25583 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
25584 stop.
25585
25586 @item
25587 @value{GDBN} displays source code through Emacs.
25588
25589 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
25590 source file for that frame and puts an arrow (@samp{=>}) at the
25591 left margin of the current line. Emacs uses a separate buffer for
25592 source display, and splits the screen to show both your @value{GDBN} session
25593 and the source.
25594
25595 Explicit @value{GDBN} @code{list} or search commands still produce output as
25596 usual, but you probably have no reason to use them from Emacs.
25597 @end itemize
25598
25599 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
25600 a graphical mode, enabled by default, which provides further buffers
25601 that can control the execution and describe the state of your program.
25602 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
25603
25604 If you specify an absolute file name when prompted for the @kbd{M-x
25605 gdb} argument, then Emacs sets your current working directory to where
25606 your program resides. If you only specify the file name, then Emacs
25607 sets your current working directory to the directory associated
25608 with the previous buffer. In this case, @value{GDBN} may find your
25609 program by searching your environment's @code{PATH} variable, but on
25610 some operating systems it might not find the source. So, although the
25611 @value{GDBN} input and output session proceeds normally, the auxiliary
25612 buffer does not display the current source and line of execution.
25613
25614 The initial working directory of @value{GDBN} is printed on the top
25615 line of the GUD buffer and this serves as a default for the commands
25616 that specify files for @value{GDBN} to operate on. @xref{Files,
25617 ,Commands to Specify Files}.
25618
25619 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
25620 need to call @value{GDBN} by a different name (for example, if you
25621 keep several configurations around, with different names) you can
25622 customize the Emacs variable @code{gud-gdb-command-name} to run the
25623 one you want.
25624
25625 In the GUD buffer, you can use these special Emacs commands in
25626 addition to the standard Shell mode commands:
25627
25628 @table @kbd
25629 @item C-h m
25630 Describe the features of Emacs' GUD Mode.
25631
25632 @item C-c C-s
25633 Execute to another source line, like the @value{GDBN} @code{step} command; also
25634 update the display window to show the current file and location.
25635
25636 @item C-c C-n
25637 Execute to next source line in this function, skipping all function
25638 calls, like the @value{GDBN} @code{next} command. Then update the display window
25639 to show the current file and location.
25640
25641 @item C-c C-i
25642 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
25643 display window accordingly.
25644
25645 @item C-c C-f
25646 Execute until exit from the selected stack frame, like the @value{GDBN}
25647 @code{finish} command.
25648
25649 @item C-c C-r
25650 Continue execution of your program, like the @value{GDBN} @code{continue}
25651 command.
25652
25653 @item C-c <
25654 Go up the number of frames indicated by the numeric argument
25655 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
25656 like the @value{GDBN} @code{up} command.
25657
25658 @item C-c >
25659 Go down the number of frames indicated by the numeric argument, like the
25660 @value{GDBN} @code{down} command.
25661 @end table
25662
25663 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
25664 tells @value{GDBN} to set a breakpoint on the source line point is on.
25665
25666 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
25667 separate frame which shows a backtrace when the GUD buffer is current.
25668 Move point to any frame in the stack and type @key{RET} to make it
25669 become the current frame and display the associated source in the
25670 source buffer. Alternatively, click @kbd{Mouse-2} to make the
25671 selected frame become the current one. In graphical mode, the
25672 speedbar displays watch expressions.
25673
25674 If you accidentally delete the source-display buffer, an easy way to get
25675 it back is to type the command @code{f} in the @value{GDBN} buffer, to
25676 request a frame display; when you run under Emacs, this recreates
25677 the source buffer if necessary to show you the context of the current
25678 frame.
25679
25680 The source files displayed in Emacs are in ordinary Emacs buffers
25681 which are visiting the source files in the usual way. You can edit
25682 the files with these buffers if you wish; but keep in mind that @value{GDBN}
25683 communicates with Emacs in terms of line numbers. If you add or
25684 delete lines from the text, the line numbers that @value{GDBN} knows cease
25685 to correspond properly with the code.
25686
25687 A more detailed description of Emacs' interaction with @value{GDBN} is
25688 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
25689 Emacs Manual}).
25690
25691 @c The following dropped because Epoch is nonstandard. Reactivate
25692 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
25693 @ignore
25694 @kindex Emacs Epoch environment
25695 @kindex Epoch
25696 @kindex inspect
25697
25698 Version 18 of @sc{gnu} Emacs has a built-in window system
25699 called the @code{epoch}
25700 environment. Users of this environment can use a new command,
25701 @code{inspect} which performs identically to @code{print} except that
25702 each value is printed in its own window.
25703 @end ignore
25704
25705
25706 @node GDB/MI
25707 @chapter The @sc{gdb/mi} Interface
25708
25709 @unnumberedsec Function and Purpose
25710
25711 @cindex @sc{gdb/mi}, its purpose
25712 @sc{gdb/mi} is a line based machine oriented text interface to
25713 @value{GDBN} and is activated by specifying using the
25714 @option{--interpreter} command line option (@pxref{Mode Options}). It
25715 is specifically intended to support the development of systems which
25716 use the debugger as just one small component of a larger system.
25717
25718 This chapter is a specification of the @sc{gdb/mi} interface. It is written
25719 in the form of a reference manual.
25720
25721 Note that @sc{gdb/mi} is still under construction, so some of the
25722 features described below are incomplete and subject to change
25723 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
25724
25725 @unnumberedsec Notation and Terminology
25726
25727 @cindex notational conventions, for @sc{gdb/mi}
25728 This chapter uses the following notation:
25729
25730 @itemize @bullet
25731 @item
25732 @code{|} separates two alternatives.
25733
25734 @item
25735 @code{[ @var{something} ]} indicates that @var{something} is optional:
25736 it may or may not be given.
25737
25738 @item
25739 @code{( @var{group} )*} means that @var{group} inside the parentheses
25740 may repeat zero or more times.
25741
25742 @item
25743 @code{( @var{group} )+} means that @var{group} inside the parentheses
25744 may repeat one or more times.
25745
25746 @item
25747 @code{"@var{string}"} means a literal @var{string}.
25748 @end itemize
25749
25750 @ignore
25751 @heading Dependencies
25752 @end ignore
25753
25754 @menu
25755 * GDB/MI General Design::
25756 * GDB/MI Command Syntax::
25757 * GDB/MI Compatibility with CLI::
25758 * GDB/MI Development and Front Ends::
25759 * GDB/MI Output Records::
25760 * GDB/MI Simple Examples::
25761 * GDB/MI Command Description Format::
25762 * GDB/MI Breakpoint Commands::
25763 * GDB/MI Program Context::
25764 * GDB/MI Thread Commands::
25765 * GDB/MI Ada Tasking Commands::
25766 * GDB/MI Program Execution::
25767 * GDB/MI Stack Manipulation::
25768 * GDB/MI Variable Objects::
25769 * GDB/MI Data Manipulation::
25770 * GDB/MI Tracepoint Commands::
25771 * GDB/MI Symbol Query::
25772 * GDB/MI File Commands::
25773 @ignore
25774 * GDB/MI Kod Commands::
25775 * GDB/MI Memory Overlay Commands::
25776 * GDB/MI Signal Handling Commands::
25777 @end ignore
25778 * GDB/MI Target Manipulation::
25779 * GDB/MI File Transfer Commands::
25780 * GDB/MI Miscellaneous Commands::
25781 @end menu
25782
25783 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25784 @node GDB/MI General Design
25785 @section @sc{gdb/mi} General Design
25786 @cindex GDB/MI General Design
25787
25788 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
25789 parts---commands sent to @value{GDBN}, responses to those commands
25790 and notifications. Each command results in exactly one response,
25791 indicating either successful completion of the command, or an error.
25792 For the commands that do not resume the target, the response contains the
25793 requested information. For the commands that resume the target, the
25794 response only indicates whether the target was successfully resumed.
25795 Notifications is the mechanism for reporting changes in the state of the
25796 target, or in @value{GDBN} state, that cannot conveniently be associated with
25797 a command and reported as part of that command response.
25798
25799 The important examples of notifications are:
25800 @itemize @bullet
25801
25802 @item
25803 Exec notifications. These are used to report changes in
25804 target state---when a target is resumed, or stopped. It would not
25805 be feasible to include this information in response of resuming
25806 commands, because one resume commands can result in multiple events in
25807 different threads. Also, quite some time may pass before any event
25808 happens in the target, while a frontend needs to know whether the resuming
25809 command itself was successfully executed.
25810
25811 @item
25812 Console output, and status notifications. Console output
25813 notifications are used to report output of CLI commands, as well as
25814 diagnostics for other commands. Status notifications are used to
25815 report the progress of a long-running operation. Naturally, including
25816 this information in command response would mean no output is produced
25817 until the command is finished, which is undesirable.
25818
25819 @item
25820 General notifications. Commands may have various side effects on
25821 the @value{GDBN} or target state beyond their official purpose. For example,
25822 a command may change the selected thread. Although such changes can
25823 be included in command response, using notification allows for more
25824 orthogonal frontend design.
25825
25826 @end itemize
25827
25828 There's no guarantee that whenever an MI command reports an error,
25829 @value{GDBN} or the target are in any specific state, and especially,
25830 the state is not reverted to the state before the MI command was
25831 processed. Therefore, whenever an MI command results in an error,
25832 we recommend that the frontend refreshes all the information shown in
25833 the user interface.
25834
25835
25836 @menu
25837 * Context management::
25838 * Asynchronous and non-stop modes::
25839 * Thread groups::
25840 @end menu
25841
25842 @node Context management
25843 @subsection Context management
25844
25845 In most cases when @value{GDBN} accesses the target, this access is
25846 done in context of a specific thread and frame (@pxref{Frames}).
25847 Often, even when accessing global data, the target requires that a thread
25848 be specified. The CLI interface maintains the selected thread and frame,
25849 and supplies them to target on each command. This is convenient,
25850 because a command line user would not want to specify that information
25851 explicitly on each command, and because user interacts with
25852 @value{GDBN} via a single terminal, so no confusion is possible as
25853 to what thread and frame are the current ones.
25854
25855 In the case of MI, the concept of selected thread and frame is less
25856 useful. First, a frontend can easily remember this information
25857 itself. Second, a graphical frontend can have more than one window,
25858 each one used for debugging a different thread, and the frontend might
25859 want to access additional threads for internal purposes. This
25860 increases the risk that by relying on implicitly selected thread, the
25861 frontend may be operating on a wrong one. Therefore, each MI command
25862 should explicitly specify which thread and frame to operate on. To
25863 make it possible, each MI command accepts the @samp{--thread} and
25864 @samp{--frame} options, the value to each is @value{GDBN} identifier
25865 for thread and frame to operate on.
25866
25867 Usually, each top-level window in a frontend allows the user to select
25868 a thread and a frame, and remembers the user selection for further
25869 operations. However, in some cases @value{GDBN} may suggest that the
25870 current thread be changed. For example, when stopping on a breakpoint
25871 it is reasonable to switch to the thread where breakpoint is hit. For
25872 another example, if the user issues the CLI @samp{thread} command via
25873 the frontend, it is desirable to change the frontend's selected thread to the
25874 one specified by user. @value{GDBN} communicates the suggestion to
25875 change current thread using the @samp{=thread-selected} notification.
25876 No such notification is available for the selected frame at the moment.
25877
25878 Note that historically, MI shares the selected thread with CLI, so
25879 frontends used the @code{-thread-select} to execute commands in the
25880 right context. However, getting this to work right is cumbersome. The
25881 simplest way is for frontend to emit @code{-thread-select} command
25882 before every command. This doubles the number of commands that need
25883 to be sent. The alternative approach is to suppress @code{-thread-select}
25884 if the selected thread in @value{GDBN} is supposed to be identical to the
25885 thread the frontend wants to operate on. However, getting this
25886 optimization right can be tricky. In particular, if the frontend
25887 sends several commands to @value{GDBN}, and one of the commands changes the
25888 selected thread, then the behaviour of subsequent commands will
25889 change. So, a frontend should either wait for response from such
25890 problematic commands, or explicitly add @code{-thread-select} for
25891 all subsequent commands. No frontend is known to do this exactly
25892 right, so it is suggested to just always pass the @samp{--thread} and
25893 @samp{--frame} options.
25894
25895 @node Asynchronous and non-stop modes
25896 @subsection Asynchronous command execution and non-stop mode
25897
25898 On some targets, @value{GDBN} is capable of processing MI commands
25899 even while the target is running. This is called @dfn{asynchronous
25900 command execution} (@pxref{Background Execution}). The frontend may
25901 specify a preferrence for asynchronous execution using the
25902 @code{-gdb-set target-async 1} command, which should be emitted before
25903 either running the executable or attaching to the target. After the
25904 frontend has started the executable or attached to the target, it can
25905 find if asynchronous execution is enabled using the
25906 @code{-list-target-features} command.
25907
25908 Even if @value{GDBN} can accept a command while target is running,
25909 many commands that access the target do not work when the target is
25910 running. Therefore, asynchronous command execution is most useful
25911 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
25912 it is possible to examine the state of one thread, while other threads
25913 are running.
25914
25915 When a given thread is running, MI commands that try to access the
25916 target in the context of that thread may not work, or may work only on
25917 some targets. In particular, commands that try to operate on thread's
25918 stack will not work, on any target. Commands that read memory, or
25919 modify breakpoints, may work or not work, depending on the target. Note
25920 that even commands that operate on global state, such as @code{print},
25921 @code{set}, and breakpoint commands, still access the target in the
25922 context of a specific thread, so frontend should try to find a
25923 stopped thread and perform the operation on that thread (using the
25924 @samp{--thread} option).
25925
25926 Which commands will work in the context of a running thread is
25927 highly target dependent. However, the two commands
25928 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
25929 to find the state of a thread, will always work.
25930
25931 @node Thread groups
25932 @subsection Thread groups
25933 @value{GDBN} may be used to debug several processes at the same time.
25934 On some platfroms, @value{GDBN} may support debugging of several
25935 hardware systems, each one having several cores with several different
25936 processes running on each core. This section describes the MI
25937 mechanism to support such debugging scenarios.
25938
25939 The key observation is that regardless of the structure of the
25940 target, MI can have a global list of threads, because most commands that
25941 accept the @samp{--thread} option do not need to know what process that
25942 thread belongs to. Therefore, it is not necessary to introduce
25943 neither additional @samp{--process} option, nor an notion of the
25944 current process in the MI interface. The only strictly new feature
25945 that is required is the ability to find how the threads are grouped
25946 into processes.
25947
25948 To allow the user to discover such grouping, and to support arbitrary
25949 hierarchy of machines/cores/processes, MI introduces the concept of a
25950 @dfn{thread group}. Thread group is a collection of threads and other
25951 thread groups. A thread group always has a string identifier, a type,
25952 and may have additional attributes specific to the type. A new
25953 command, @code{-list-thread-groups}, returns the list of top-level
25954 thread groups, which correspond to processes that @value{GDBN} is
25955 debugging at the moment. By passing an identifier of a thread group
25956 to the @code{-list-thread-groups} command, it is possible to obtain
25957 the members of specific thread group.
25958
25959 To allow the user to easily discover processes, and other objects, he
25960 wishes to debug, a concept of @dfn{available thread group} is
25961 introduced. Available thread group is an thread group that
25962 @value{GDBN} is not debugging, but that can be attached to, using the
25963 @code{-target-attach} command. The list of available top-level thread
25964 groups can be obtained using @samp{-list-thread-groups --available}.
25965 In general, the content of a thread group may be only retrieved only
25966 after attaching to that thread group.
25967
25968 Thread groups are related to inferiors (@pxref{Inferiors and
25969 Programs}). Each inferior corresponds to a thread group of a special
25970 type @samp{process}, and some additional operations are permitted on
25971 such thread groups.
25972
25973 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25974 @node GDB/MI Command Syntax
25975 @section @sc{gdb/mi} Command Syntax
25976
25977 @menu
25978 * GDB/MI Input Syntax::
25979 * GDB/MI Output Syntax::
25980 @end menu
25981
25982 @node GDB/MI Input Syntax
25983 @subsection @sc{gdb/mi} Input Syntax
25984
25985 @cindex input syntax for @sc{gdb/mi}
25986 @cindex @sc{gdb/mi}, input syntax
25987 @table @code
25988 @item @var{command} @expansion{}
25989 @code{@var{cli-command} | @var{mi-command}}
25990
25991 @item @var{cli-command} @expansion{}
25992 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
25993 @var{cli-command} is any existing @value{GDBN} CLI command.
25994
25995 @item @var{mi-command} @expansion{}
25996 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
25997 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
25998
25999 @item @var{token} @expansion{}
26000 "any sequence of digits"
26001
26002 @item @var{option} @expansion{}
26003 @code{"-" @var{parameter} [ " " @var{parameter} ]}
26004
26005 @item @var{parameter} @expansion{}
26006 @code{@var{non-blank-sequence} | @var{c-string}}
26007
26008 @item @var{operation} @expansion{}
26009 @emph{any of the operations described in this chapter}
26010
26011 @item @var{non-blank-sequence} @expansion{}
26012 @emph{anything, provided it doesn't contain special characters such as
26013 "-", @var{nl}, """ and of course " "}
26014
26015 @item @var{c-string} @expansion{}
26016 @code{""" @var{seven-bit-iso-c-string-content} """}
26017
26018 @item @var{nl} @expansion{}
26019 @code{CR | CR-LF}
26020 @end table
26021
26022 @noindent
26023 Notes:
26024
26025 @itemize @bullet
26026 @item
26027 The CLI commands are still handled by the @sc{mi} interpreter; their
26028 output is described below.
26029
26030 @item
26031 The @code{@var{token}}, when present, is passed back when the command
26032 finishes.
26033
26034 @item
26035 Some @sc{mi} commands accept optional arguments as part of the parameter
26036 list. Each option is identified by a leading @samp{-} (dash) and may be
26037 followed by an optional argument parameter. Options occur first in the
26038 parameter list and can be delimited from normal parameters using
26039 @samp{--} (this is useful when some parameters begin with a dash).
26040 @end itemize
26041
26042 Pragmatics:
26043
26044 @itemize @bullet
26045 @item
26046 We want easy access to the existing CLI syntax (for debugging).
26047
26048 @item
26049 We want it to be easy to spot a @sc{mi} operation.
26050 @end itemize
26051
26052 @node GDB/MI Output Syntax
26053 @subsection @sc{gdb/mi} Output Syntax
26054
26055 @cindex output syntax of @sc{gdb/mi}
26056 @cindex @sc{gdb/mi}, output syntax
26057 The output from @sc{gdb/mi} consists of zero or more out-of-band records
26058 followed, optionally, by a single result record. This result record
26059 is for the most recent command. The sequence of output records is
26060 terminated by @samp{(gdb)}.
26061
26062 If an input command was prefixed with a @code{@var{token}} then the
26063 corresponding output for that command will also be prefixed by that same
26064 @var{token}.
26065
26066 @table @code
26067 @item @var{output} @expansion{}
26068 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
26069
26070 @item @var{result-record} @expansion{}
26071 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
26072
26073 @item @var{out-of-band-record} @expansion{}
26074 @code{@var{async-record} | @var{stream-record}}
26075
26076 @item @var{async-record} @expansion{}
26077 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
26078
26079 @item @var{exec-async-output} @expansion{}
26080 @code{[ @var{token} ] "*" @var{async-output}}
26081
26082 @item @var{status-async-output} @expansion{}
26083 @code{[ @var{token} ] "+" @var{async-output}}
26084
26085 @item @var{notify-async-output} @expansion{}
26086 @code{[ @var{token} ] "=" @var{async-output}}
26087
26088 @item @var{async-output} @expansion{}
26089 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
26090
26091 @item @var{result-class} @expansion{}
26092 @code{"done" | "running" | "connected" | "error" | "exit"}
26093
26094 @item @var{async-class} @expansion{}
26095 @code{"stopped" | @var{others}} (where @var{others} will be added
26096 depending on the needs---this is still in development).
26097
26098 @item @var{result} @expansion{}
26099 @code{ @var{variable} "=" @var{value}}
26100
26101 @item @var{variable} @expansion{}
26102 @code{ @var{string} }
26103
26104 @item @var{value} @expansion{}
26105 @code{ @var{const} | @var{tuple} | @var{list} }
26106
26107 @item @var{const} @expansion{}
26108 @code{@var{c-string}}
26109
26110 @item @var{tuple} @expansion{}
26111 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
26112
26113 @item @var{list} @expansion{}
26114 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
26115 @var{result} ( "," @var{result} )* "]" }
26116
26117 @item @var{stream-record} @expansion{}
26118 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
26119
26120 @item @var{console-stream-output} @expansion{}
26121 @code{"~" @var{c-string}}
26122
26123 @item @var{target-stream-output} @expansion{}
26124 @code{"@@" @var{c-string}}
26125
26126 @item @var{log-stream-output} @expansion{}
26127 @code{"&" @var{c-string}}
26128
26129 @item @var{nl} @expansion{}
26130 @code{CR | CR-LF}
26131
26132 @item @var{token} @expansion{}
26133 @emph{any sequence of digits}.
26134 @end table
26135
26136 @noindent
26137 Notes:
26138
26139 @itemize @bullet
26140 @item
26141 All output sequences end in a single line containing a period.
26142
26143 @item
26144 The @code{@var{token}} is from the corresponding request. Note that
26145 for all async output, while the token is allowed by the grammar and
26146 may be output by future versions of @value{GDBN} for select async
26147 output messages, it is generally omitted. Frontends should treat
26148 all async output as reporting general changes in the state of the
26149 target and there should be no need to associate async output to any
26150 prior command.
26151
26152 @item
26153 @cindex status output in @sc{gdb/mi}
26154 @var{status-async-output} contains on-going status information about the
26155 progress of a slow operation. It can be discarded. All status output is
26156 prefixed by @samp{+}.
26157
26158 @item
26159 @cindex async output in @sc{gdb/mi}
26160 @var{exec-async-output} contains asynchronous state change on the target
26161 (stopped, started, disappeared). All async output is prefixed by
26162 @samp{*}.
26163
26164 @item
26165 @cindex notify output in @sc{gdb/mi}
26166 @var{notify-async-output} contains supplementary information that the
26167 client should handle (e.g., a new breakpoint information). All notify
26168 output is prefixed by @samp{=}.
26169
26170 @item
26171 @cindex console output in @sc{gdb/mi}
26172 @var{console-stream-output} is output that should be displayed as is in the
26173 console. It is the textual response to a CLI command. All the console
26174 output is prefixed by @samp{~}.
26175
26176 @item
26177 @cindex target output in @sc{gdb/mi}
26178 @var{target-stream-output} is the output produced by the target program.
26179 All the target output is prefixed by @samp{@@}.
26180
26181 @item
26182 @cindex log output in @sc{gdb/mi}
26183 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
26184 instance messages that should be displayed as part of an error log. All
26185 the log output is prefixed by @samp{&}.
26186
26187 @item
26188 @cindex list output in @sc{gdb/mi}
26189 New @sc{gdb/mi} commands should only output @var{lists} containing
26190 @var{values}.
26191
26192
26193 @end itemize
26194
26195 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
26196 details about the various output records.
26197
26198 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26199 @node GDB/MI Compatibility with CLI
26200 @section @sc{gdb/mi} Compatibility with CLI
26201
26202 @cindex compatibility, @sc{gdb/mi} and CLI
26203 @cindex @sc{gdb/mi}, compatibility with CLI
26204
26205 For the developers convenience CLI commands can be entered directly,
26206 but there may be some unexpected behaviour. For example, commands
26207 that query the user will behave as if the user replied yes, breakpoint
26208 command lists are not executed and some CLI commands, such as
26209 @code{if}, @code{when} and @code{define}, prompt for further input with
26210 @samp{>}, which is not valid MI output.
26211
26212 This feature may be removed at some stage in the future and it is
26213 recommended that front ends use the @code{-interpreter-exec} command
26214 (@pxref{-interpreter-exec}).
26215
26216 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26217 @node GDB/MI Development and Front Ends
26218 @section @sc{gdb/mi} Development and Front Ends
26219 @cindex @sc{gdb/mi} development
26220
26221 The application which takes the MI output and presents the state of the
26222 program being debugged to the user is called a @dfn{front end}.
26223
26224 Although @sc{gdb/mi} is still incomplete, it is currently being used
26225 by a variety of front ends to @value{GDBN}. This makes it difficult
26226 to introduce new functionality without breaking existing usage. This
26227 section tries to minimize the problems by describing how the protocol
26228 might change.
26229
26230 Some changes in MI need not break a carefully designed front end, and
26231 for these the MI version will remain unchanged. The following is a
26232 list of changes that may occur within one level, so front ends should
26233 parse MI output in a way that can handle them:
26234
26235 @itemize @bullet
26236 @item
26237 New MI commands may be added.
26238
26239 @item
26240 New fields may be added to the output of any MI command.
26241
26242 @item
26243 The range of values for fields with specified values, e.g.,
26244 @code{in_scope} (@pxref{-var-update}) may be extended.
26245
26246 @c The format of field's content e.g type prefix, may change so parse it
26247 @c at your own risk. Yes, in general?
26248
26249 @c The order of fields may change? Shouldn't really matter but it might
26250 @c resolve inconsistencies.
26251 @end itemize
26252
26253 If the changes are likely to break front ends, the MI version level
26254 will be increased by one. This will allow the front end to parse the
26255 output according to the MI version. Apart from mi0, new versions of
26256 @value{GDBN} will not support old versions of MI and it will be the
26257 responsibility of the front end to work with the new one.
26258
26259 @c Starting with mi3, add a new command -mi-version that prints the MI
26260 @c version?
26261
26262 The best way to avoid unexpected changes in MI that might break your front
26263 end is to make your project known to @value{GDBN} developers and
26264 follow development on @email{gdb@@sourceware.org} and
26265 @email{gdb-patches@@sourceware.org}.
26266 @cindex mailing lists
26267
26268 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26269 @node GDB/MI Output Records
26270 @section @sc{gdb/mi} Output Records
26271
26272 @menu
26273 * GDB/MI Result Records::
26274 * GDB/MI Stream Records::
26275 * GDB/MI Async Records::
26276 * GDB/MI Frame Information::
26277 * GDB/MI Thread Information::
26278 * GDB/MI Ada Exception Information::
26279 @end menu
26280
26281 @node GDB/MI Result Records
26282 @subsection @sc{gdb/mi} Result Records
26283
26284 @cindex result records in @sc{gdb/mi}
26285 @cindex @sc{gdb/mi}, result records
26286 In addition to a number of out-of-band notifications, the response to a
26287 @sc{gdb/mi} command includes one of the following result indications:
26288
26289 @table @code
26290 @findex ^done
26291 @item "^done" [ "," @var{results} ]
26292 The synchronous operation was successful, @code{@var{results}} are the return
26293 values.
26294
26295 @item "^running"
26296 @findex ^running
26297 This result record is equivalent to @samp{^done}. Historically, it
26298 was output instead of @samp{^done} if the command has resumed the
26299 target. This behaviour is maintained for backward compatibility, but
26300 all frontends should treat @samp{^done} and @samp{^running}
26301 identically and rely on the @samp{*running} output record to determine
26302 which threads are resumed.
26303
26304 @item "^connected"
26305 @findex ^connected
26306 @value{GDBN} has connected to a remote target.
26307
26308 @item "^error" "," @var{c-string}
26309 @findex ^error
26310 The operation failed. The @code{@var{c-string}} contains the corresponding
26311 error message.
26312
26313 @item "^exit"
26314 @findex ^exit
26315 @value{GDBN} has terminated.
26316
26317 @end table
26318
26319 @node GDB/MI Stream Records
26320 @subsection @sc{gdb/mi} Stream Records
26321
26322 @cindex @sc{gdb/mi}, stream records
26323 @cindex stream records in @sc{gdb/mi}
26324 @value{GDBN} internally maintains a number of output streams: the console, the
26325 target, and the log. The output intended for each of these streams is
26326 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
26327
26328 Each stream record begins with a unique @dfn{prefix character} which
26329 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
26330 Syntax}). In addition to the prefix, each stream record contains a
26331 @code{@var{string-output}}. This is either raw text (with an implicit new
26332 line) or a quoted C string (which does not contain an implicit newline).
26333
26334 @table @code
26335 @item "~" @var{string-output}
26336 The console output stream contains text that should be displayed in the
26337 CLI console window. It contains the textual responses to CLI commands.
26338
26339 @item "@@" @var{string-output}
26340 The target output stream contains any textual output from the running
26341 target. This is only present when GDB's event loop is truly
26342 asynchronous, which is currently only the case for remote targets.
26343
26344 @item "&" @var{string-output}
26345 The log stream contains debugging messages being produced by @value{GDBN}'s
26346 internals.
26347 @end table
26348
26349 @node GDB/MI Async Records
26350 @subsection @sc{gdb/mi} Async Records
26351
26352 @cindex async records in @sc{gdb/mi}
26353 @cindex @sc{gdb/mi}, async records
26354 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
26355 additional changes that have occurred. Those changes can either be a
26356 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
26357 target activity (e.g., target stopped).
26358
26359 The following is the list of possible async records:
26360
26361 @table @code
26362
26363 @item *running,thread-id="@var{thread}"
26364 The target is now running. The @var{thread} field tells which
26365 specific thread is now running, and can be @samp{all} if all threads
26366 are running. The frontend should assume that no interaction with a
26367 running thread is possible after this notification is produced.
26368 The frontend should not assume that this notification is output
26369 only once for any command. @value{GDBN} may emit this notification
26370 several times, either for different threads, because it cannot resume
26371 all threads together, or even for a single thread, if the thread must
26372 be stepped though some code before letting it run freely.
26373
26374 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
26375 The target has stopped. The @var{reason} field can have one of the
26376 following values:
26377
26378 @table @code
26379 @item breakpoint-hit
26380 A breakpoint was reached.
26381 @item watchpoint-trigger
26382 A watchpoint was triggered.
26383 @item read-watchpoint-trigger
26384 A read watchpoint was triggered.
26385 @item access-watchpoint-trigger
26386 An access watchpoint was triggered.
26387 @item function-finished
26388 An -exec-finish or similar CLI command was accomplished.
26389 @item location-reached
26390 An -exec-until or similar CLI command was accomplished.
26391 @item watchpoint-scope
26392 A watchpoint has gone out of scope.
26393 @item end-stepping-range
26394 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
26395 similar CLI command was accomplished.
26396 @item exited-signalled
26397 The inferior exited because of a signal.
26398 @item exited
26399 The inferior exited.
26400 @item exited-normally
26401 The inferior exited normally.
26402 @item signal-received
26403 A signal was received by the inferior.
26404 @item solib-event
26405 The inferior has stopped due to a library being loaded or unloaded.
26406 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
26407 set or when a @code{catch load} or @code{catch unload} catchpoint is
26408 in use (@pxref{Set Catchpoints}).
26409 @item fork
26410 The inferior has forked. This is reported when @code{catch fork}
26411 (@pxref{Set Catchpoints}) has been used.
26412 @item vfork
26413 The inferior has vforked. This is reported in when @code{catch vfork}
26414 (@pxref{Set Catchpoints}) has been used.
26415 @item syscall-entry
26416 The inferior entered a system call. This is reported when @code{catch
26417 syscall} (@pxref{Set Catchpoints}) has been used.
26418 @item syscall-entry
26419 The inferior returned from a system call. This is reported when
26420 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
26421 @item exec
26422 The inferior called @code{exec}. This is reported when @code{catch exec}
26423 (@pxref{Set Catchpoints}) has been used.
26424 @end table
26425
26426 The @var{id} field identifies the thread that directly caused the stop
26427 -- for example by hitting a breakpoint. Depending on whether all-stop
26428 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
26429 stop all threads, or only the thread that directly triggered the stop.
26430 If all threads are stopped, the @var{stopped} field will have the
26431 value of @code{"all"}. Otherwise, the value of the @var{stopped}
26432 field will be a list of thread identifiers. Presently, this list will
26433 always include a single thread, but frontend should be prepared to see
26434 several threads in the list. The @var{core} field reports the
26435 processor core on which the stop event has happened. This field may be absent
26436 if such information is not available.
26437
26438 @item =thread-group-added,id="@var{id}"
26439 @itemx =thread-group-removed,id="@var{id}"
26440 A thread group was either added or removed. The @var{id} field
26441 contains the @value{GDBN} identifier of the thread group. When a thread
26442 group is added, it generally might not be associated with a running
26443 process. When a thread group is removed, its id becomes invalid and
26444 cannot be used in any way.
26445
26446 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
26447 A thread group became associated with a running program,
26448 either because the program was just started or the thread group
26449 was attached to a program. The @var{id} field contains the
26450 @value{GDBN} identifier of the thread group. The @var{pid} field
26451 contains process identifier, specific to the operating system.
26452
26453 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
26454 A thread group is no longer associated with a running program,
26455 either because the program has exited, or because it was detached
26456 from. The @var{id} field contains the @value{GDBN} identifier of the
26457 thread group. @var{code} is the exit code of the inferior; it exists
26458 only when the inferior exited with some code.
26459
26460 @item =thread-created,id="@var{id}",group-id="@var{gid}"
26461 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
26462 A thread either was created, or has exited. The @var{id} field
26463 contains the @value{GDBN} identifier of the thread. The @var{gid}
26464 field identifies the thread group this thread belongs to.
26465
26466 @item =thread-selected,id="@var{id}"
26467 Informs that the selected thread was changed as result of the last
26468 command. This notification is not emitted as result of @code{-thread-select}
26469 command but is emitted whenever an MI command that is not documented
26470 to change the selected thread actually changes it. In particular,
26471 invoking, directly or indirectly (via user-defined command), the CLI
26472 @code{thread} command, will generate this notification.
26473
26474 We suggest that in response to this notification, front ends
26475 highlight the selected thread and cause subsequent commands to apply to
26476 that thread.
26477
26478 @item =library-loaded,...
26479 Reports that a new library file was loaded by the program. This
26480 notification has 4 fields---@var{id}, @var{target-name},
26481 @var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
26482 opaque identifier of the library. For remote debugging case,
26483 @var{target-name} and @var{host-name} fields give the name of the
26484 library file on the target, and on the host respectively. For native
26485 debugging, both those fields have the same value. The
26486 @var{symbols-loaded} field is emitted only for backward compatibility
26487 and should not be relied on to convey any useful information. The
26488 @var{thread-group} field, if present, specifies the id of the thread
26489 group in whose context the library was loaded. If the field is
26490 absent, it means the library was loaded in the context of all present
26491 thread groups.
26492
26493 @item =library-unloaded,...
26494 Reports that a library was unloaded by the program. This notification
26495 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
26496 the same meaning as for the @code{=library-loaded} notification.
26497 The @var{thread-group} field, if present, specifies the id of the
26498 thread group in whose context the library was unloaded. If the field is
26499 absent, it means the library was unloaded in the context of all present
26500 thread groups.
26501
26502 @item =breakpoint-created,bkpt=@{...@}
26503 @itemx =breakpoint-modified,bkpt=@{...@}
26504 @itemx =breakpoint-deleted,bkpt=@{...@}
26505 Reports that a breakpoint was created, modified, or deleted,
26506 respectively. Only user-visible breakpoints are reported to the MI
26507 user.
26508
26509 The @var{bkpt} argument is of the same form as returned by the various
26510 breakpoint commands; @xref{GDB/MI Breakpoint Commands}.
26511
26512 Note that if a breakpoint is emitted in the result record of a
26513 command, then it will not also be emitted in an async record.
26514
26515 @end table
26516
26517 @node GDB/MI Frame Information
26518 @subsection @sc{gdb/mi} Frame Information
26519
26520 Response from many MI commands includes an information about stack
26521 frame. This information is a tuple that may have the following
26522 fields:
26523
26524 @table @code
26525 @item level
26526 The level of the stack frame. The innermost frame has the level of
26527 zero. This field is always present.
26528
26529 @item func
26530 The name of the function corresponding to the frame. This field may
26531 be absent if @value{GDBN} is unable to determine the function name.
26532
26533 @item addr
26534 The code address for the frame. This field is always present.
26535
26536 @item file
26537 The name of the source files that correspond to the frame's code
26538 address. This field may be absent.
26539
26540 @item line
26541 The source line corresponding to the frames' code address. This field
26542 may be absent.
26543
26544 @item from
26545 The name of the binary file (either executable or shared library) the
26546 corresponds to the frame's code address. This field may be absent.
26547
26548 @end table
26549
26550 @node GDB/MI Thread Information
26551 @subsection @sc{gdb/mi} Thread Information
26552
26553 Whenever @value{GDBN} has to report an information about a thread, it
26554 uses a tuple with the following fields:
26555
26556 @table @code
26557 @item id
26558 The numeric id assigned to the thread by @value{GDBN}. This field is
26559 always present.
26560
26561 @item target-id
26562 Target-specific string identifying the thread. This field is always present.
26563
26564 @item details
26565 Additional information about the thread provided by the target.
26566 It is supposed to be human-readable and not interpreted by the
26567 frontend. This field is optional.
26568
26569 @item state
26570 Either @samp{stopped} or @samp{running}, depending on whether the
26571 thread is presently running. This field is always present.
26572
26573 @item core
26574 The value of this field is an integer number of the processor core the
26575 thread was last seen on. This field is optional.
26576 @end table
26577
26578 @node GDB/MI Ada Exception Information
26579 @subsection @sc{gdb/mi} Ada Exception Information
26580
26581 Whenever a @code{*stopped} record is emitted because the program
26582 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
26583 @value{GDBN} provides the name of the exception that was raised via
26584 the @code{exception-name} field.
26585
26586 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26587 @node GDB/MI Simple Examples
26588 @section Simple Examples of @sc{gdb/mi} Interaction
26589 @cindex @sc{gdb/mi}, simple examples
26590
26591 This subsection presents several simple examples of interaction using
26592 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
26593 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
26594 the output received from @sc{gdb/mi}.
26595
26596 Note the line breaks shown in the examples are here only for
26597 readability, they don't appear in the real output.
26598
26599 @subheading Setting a Breakpoint
26600
26601 Setting a breakpoint generates synchronous output which contains detailed
26602 information of the breakpoint.
26603
26604 @smallexample
26605 -> -break-insert main
26606 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26607 enabled="y",addr="0x08048564",func="main",file="myprog.c",
26608 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
26609 <- (gdb)
26610 @end smallexample
26611
26612 @subheading Program Execution
26613
26614 Program execution generates asynchronous records and MI gives the
26615 reason that execution stopped.
26616
26617 @smallexample
26618 -> -exec-run
26619 <- ^running
26620 <- (gdb)
26621 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
26622 frame=@{addr="0x08048564",func="main",
26623 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
26624 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
26625 <- (gdb)
26626 -> -exec-continue
26627 <- ^running
26628 <- (gdb)
26629 <- *stopped,reason="exited-normally"
26630 <- (gdb)
26631 @end smallexample
26632
26633 @subheading Quitting @value{GDBN}
26634
26635 Quitting @value{GDBN} just prints the result class @samp{^exit}.
26636
26637 @smallexample
26638 -> (gdb)
26639 <- -gdb-exit
26640 <- ^exit
26641 @end smallexample
26642
26643 Please note that @samp{^exit} is printed immediately, but it might
26644 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
26645 performs necessary cleanups, including killing programs being debugged
26646 or disconnecting from debug hardware, so the frontend should wait till
26647 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
26648 fails to exit in reasonable time.
26649
26650 @subheading A Bad Command
26651
26652 Here's what happens if you pass a non-existent command:
26653
26654 @smallexample
26655 -> -rubbish
26656 <- ^error,msg="Undefined MI command: rubbish"
26657 <- (gdb)
26658 @end smallexample
26659
26660
26661 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26662 @node GDB/MI Command Description Format
26663 @section @sc{gdb/mi} Command Description Format
26664
26665 The remaining sections describe blocks of commands. Each block of
26666 commands is laid out in a fashion similar to this section.
26667
26668 @subheading Motivation
26669
26670 The motivation for this collection of commands.
26671
26672 @subheading Introduction
26673
26674 A brief introduction to this collection of commands as a whole.
26675
26676 @subheading Commands
26677
26678 For each command in the block, the following is described:
26679
26680 @subsubheading Synopsis
26681
26682 @smallexample
26683 -command @var{args}@dots{}
26684 @end smallexample
26685
26686 @subsubheading Result
26687
26688 @subsubheading @value{GDBN} Command
26689
26690 The corresponding @value{GDBN} CLI command(s), if any.
26691
26692 @subsubheading Example
26693
26694 Example(s) formatted for readability. Some of the described commands have
26695 not been implemented yet and these are labeled N.A.@: (not available).
26696
26697
26698 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26699 @node GDB/MI Breakpoint Commands
26700 @section @sc{gdb/mi} Breakpoint Commands
26701
26702 @cindex breakpoint commands for @sc{gdb/mi}
26703 @cindex @sc{gdb/mi}, breakpoint commands
26704 This section documents @sc{gdb/mi} commands for manipulating
26705 breakpoints.
26706
26707 @subheading The @code{-break-after} Command
26708 @findex -break-after
26709
26710 @subsubheading Synopsis
26711
26712 @smallexample
26713 -break-after @var{number} @var{count}
26714 @end smallexample
26715
26716 The breakpoint number @var{number} is not in effect until it has been
26717 hit @var{count} times. To see how this is reflected in the output of
26718 the @samp{-break-list} command, see the description of the
26719 @samp{-break-list} command below.
26720
26721 @subsubheading @value{GDBN} Command
26722
26723 The corresponding @value{GDBN} command is @samp{ignore}.
26724
26725 @subsubheading Example
26726
26727 @smallexample
26728 (gdb)
26729 -break-insert main
26730 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26731 enabled="y",addr="0x000100d0",func="main",file="hello.c",
26732 fullname="/home/foo/hello.c",line="5",times="0"@}
26733 (gdb)
26734 -break-after 1 3
26735 ~
26736 ^done
26737 (gdb)
26738 -break-list
26739 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26740 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26741 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26742 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26743 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26744 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26745 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
26746 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
26747 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
26748 line="5",times="0",ignore="3"@}]@}
26749 (gdb)
26750 @end smallexample
26751
26752 @ignore
26753 @subheading The @code{-break-catch} Command
26754 @findex -break-catch
26755 @end ignore
26756
26757 @subheading The @code{-break-commands} Command
26758 @findex -break-commands
26759
26760 @subsubheading Synopsis
26761
26762 @smallexample
26763 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
26764 @end smallexample
26765
26766 Specifies the CLI commands that should be executed when breakpoint
26767 @var{number} is hit. The parameters @var{command1} to @var{commandN}
26768 are the commands. If no command is specified, any previously-set
26769 commands are cleared. @xref{Break Commands}. Typical use of this
26770 functionality is tracing a program, that is, printing of values of
26771 some variables whenever breakpoint is hit and then continuing.
26772
26773 @subsubheading @value{GDBN} Command
26774
26775 The corresponding @value{GDBN} command is @samp{commands}.
26776
26777 @subsubheading Example
26778
26779 @smallexample
26780 (gdb)
26781 -break-insert main
26782 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
26783 enabled="y",addr="0x000100d0",func="main",file="hello.c",
26784 fullname="/home/foo/hello.c",line="5",times="0"@}
26785 (gdb)
26786 -break-commands 1 "print v" "continue"
26787 ^done
26788 (gdb)
26789 @end smallexample
26790
26791 @subheading The @code{-break-condition} Command
26792 @findex -break-condition
26793
26794 @subsubheading Synopsis
26795
26796 @smallexample
26797 -break-condition @var{number} @var{expr}
26798 @end smallexample
26799
26800 Breakpoint @var{number} will stop the program only if the condition in
26801 @var{expr} is true. The condition becomes part of the
26802 @samp{-break-list} output (see the description of the @samp{-break-list}
26803 command below).
26804
26805 @subsubheading @value{GDBN} Command
26806
26807 The corresponding @value{GDBN} command is @samp{condition}.
26808
26809 @subsubheading Example
26810
26811 @smallexample
26812 (gdb)
26813 -break-condition 1 1
26814 ^done
26815 (gdb)
26816 -break-list
26817 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26818 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26819 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26820 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26821 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26822 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26823 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
26824 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
26825 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
26826 line="5",cond="1",times="0",ignore="3"@}]@}
26827 (gdb)
26828 @end smallexample
26829
26830 @subheading The @code{-break-delete} Command
26831 @findex -break-delete
26832
26833 @subsubheading Synopsis
26834
26835 @smallexample
26836 -break-delete ( @var{breakpoint} )+
26837 @end smallexample
26838
26839 Delete the breakpoint(s) whose number(s) are specified in the argument
26840 list. This is obviously reflected in the breakpoint list.
26841
26842 @subsubheading @value{GDBN} Command
26843
26844 The corresponding @value{GDBN} command is @samp{delete}.
26845
26846 @subsubheading Example
26847
26848 @smallexample
26849 (gdb)
26850 -break-delete 1
26851 ^done
26852 (gdb)
26853 -break-list
26854 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
26855 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26856 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26857 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26858 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26859 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26860 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
26861 body=[]@}
26862 (gdb)
26863 @end smallexample
26864
26865 @subheading The @code{-break-disable} Command
26866 @findex -break-disable
26867
26868 @subsubheading Synopsis
26869
26870 @smallexample
26871 -break-disable ( @var{breakpoint} )+
26872 @end smallexample
26873
26874 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
26875 break list is now set to @samp{n} for the named @var{breakpoint}(s).
26876
26877 @subsubheading @value{GDBN} Command
26878
26879 The corresponding @value{GDBN} command is @samp{disable}.
26880
26881 @subsubheading Example
26882
26883 @smallexample
26884 (gdb)
26885 -break-disable 2
26886 ^done
26887 (gdb)
26888 -break-list
26889 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26890 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26891 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26892 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26893 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26894 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26895 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
26896 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
26897 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
26898 line="5",times="0"@}]@}
26899 (gdb)
26900 @end smallexample
26901
26902 @subheading The @code{-break-enable} Command
26903 @findex -break-enable
26904
26905 @subsubheading Synopsis
26906
26907 @smallexample
26908 -break-enable ( @var{breakpoint} )+
26909 @end smallexample
26910
26911 Enable (previously disabled) @var{breakpoint}(s).
26912
26913 @subsubheading @value{GDBN} Command
26914
26915 The corresponding @value{GDBN} command is @samp{enable}.
26916
26917 @subsubheading Example
26918
26919 @smallexample
26920 (gdb)
26921 -break-enable 2
26922 ^done
26923 (gdb)
26924 -break-list
26925 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
26926 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
26927 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
26928 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
26929 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
26930 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
26931 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
26932 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
26933 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
26934 line="5",times="0"@}]@}
26935 (gdb)
26936 @end smallexample
26937
26938 @subheading The @code{-break-info} Command
26939 @findex -break-info
26940
26941 @subsubheading Synopsis
26942
26943 @smallexample
26944 -break-info @var{breakpoint}
26945 @end smallexample
26946
26947 @c REDUNDANT???
26948 Get information about a single breakpoint.
26949
26950 @subsubheading @value{GDBN} Command
26951
26952 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
26953
26954 @subsubheading Example
26955 N.A.
26956
26957 @subheading The @code{-break-insert} Command
26958 @findex -break-insert
26959
26960 @subsubheading Synopsis
26961
26962 @smallexample
26963 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
26964 [ -c @var{condition} ] [ -i @var{ignore-count} ]
26965 [ -p @var{thread} ] [ @var{location} ]
26966 @end smallexample
26967
26968 @noindent
26969 If specified, @var{location}, can be one of:
26970
26971 @itemize @bullet
26972 @item function
26973 @c @item +offset
26974 @c @item -offset
26975 @c @item linenum
26976 @item filename:linenum
26977 @item filename:function
26978 @item *address
26979 @end itemize
26980
26981 The possible optional parameters of this command are:
26982
26983 @table @samp
26984 @item -t
26985 Insert a temporary breakpoint.
26986 @item -h
26987 Insert a hardware breakpoint.
26988 @item -c @var{condition}
26989 Make the breakpoint conditional on @var{condition}.
26990 @item -i @var{ignore-count}
26991 Initialize the @var{ignore-count}.
26992 @item -f
26993 If @var{location} cannot be parsed (for example if it
26994 refers to unknown files or functions), create a pending
26995 breakpoint. Without this flag, @value{GDBN} will report
26996 an error, and won't create a breakpoint, if @var{location}
26997 cannot be parsed.
26998 @item -d
26999 Create a disabled breakpoint.
27000 @item -a
27001 Create a tracepoint. @xref{Tracepoints}. When this parameter
27002 is used together with @samp{-h}, a fast tracepoint is created.
27003 @end table
27004
27005 @subsubheading Result
27006
27007 The result is in the form:
27008
27009 @smallexample
27010 ^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
27011 enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
27012 fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
27013 times="@var{times}"@}
27014 @end smallexample
27015
27016 @noindent
27017 where @var{number} is the @value{GDBN} number for this breakpoint,
27018 @var{funcname} is the name of the function where the breakpoint was
27019 inserted, @var{filename} is the name of the source file which contains
27020 this function, @var{lineno} is the source line number within that file
27021 and @var{times} the number of times that the breakpoint has been hit
27022 (always 0 for -break-insert but may be greater for -break-info or -break-list
27023 which use the same output).
27024
27025 Note: this format is open to change.
27026 @c An out-of-band breakpoint instead of part of the result?
27027
27028 @subsubheading @value{GDBN} Command
27029
27030 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
27031 @samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
27032
27033 @subsubheading Example
27034
27035 @smallexample
27036 (gdb)
27037 -break-insert main
27038 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
27039 fullname="/home/foo/recursive2.c,line="4",times="0"@}
27040 (gdb)
27041 -break-insert -t foo
27042 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
27043 fullname="/home/foo/recursive2.c,line="11",times="0"@}
27044 (gdb)
27045 -break-list
27046 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27047 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27048 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27049 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27050 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27051 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27052 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
27053 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27054 addr="0x0001072c", func="main",file="recursive2.c",
27055 fullname="/home/foo/recursive2.c,"line="4",times="0"@},
27056 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
27057 addr="0x00010774",func="foo",file="recursive2.c",
27058 fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
27059 (gdb)
27060 -break-insert -r foo.*
27061 ~int foo(int, int);
27062 ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
27063 "fullname="/home/foo/recursive2.c",line="11",times="0"@}
27064 (gdb)
27065 @end smallexample
27066
27067 @subheading The @code{-break-list} Command
27068 @findex -break-list
27069
27070 @subsubheading Synopsis
27071
27072 @smallexample
27073 -break-list
27074 @end smallexample
27075
27076 Displays the list of inserted breakpoints, showing the following fields:
27077
27078 @table @samp
27079 @item Number
27080 number of the breakpoint
27081 @item Type
27082 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
27083 @item Disposition
27084 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
27085 or @samp{nokeep}
27086 @item Enabled
27087 is the breakpoint enabled or no: @samp{y} or @samp{n}
27088 @item Address
27089 memory location at which the breakpoint is set
27090 @item What
27091 logical location of the breakpoint, expressed by function name, file
27092 name, line number
27093 @item Times
27094 number of times the breakpoint has been hit
27095 @end table
27096
27097 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
27098 @code{body} field is an empty list.
27099
27100 @subsubheading @value{GDBN} Command
27101
27102 The corresponding @value{GDBN} command is @samp{info break}.
27103
27104 @subsubheading Example
27105
27106 @smallexample
27107 (gdb)
27108 -break-list
27109 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27110 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27111 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27112 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27113 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27114 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27115 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
27116 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27117 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
27118 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
27119 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
27120 line="13",times="0"@}]@}
27121 (gdb)
27122 @end smallexample
27123
27124 Here's an example of the result when there are no breakpoints:
27125
27126 @smallexample
27127 (gdb)
27128 -break-list
27129 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
27130 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27131 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27132 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27133 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27134 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27135 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
27136 body=[]@}
27137 (gdb)
27138 @end smallexample
27139
27140 @subheading The @code{-break-passcount} Command
27141 @findex -break-passcount
27142
27143 @subsubheading Synopsis
27144
27145 @smallexample
27146 -break-passcount @var{tracepoint-number} @var{passcount}
27147 @end smallexample
27148
27149 Set the passcount for tracepoint @var{tracepoint-number} to
27150 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
27151 is not a tracepoint, error is emitted. This corresponds to CLI
27152 command @samp{passcount}.
27153
27154 @subheading The @code{-break-watch} Command
27155 @findex -break-watch
27156
27157 @subsubheading Synopsis
27158
27159 @smallexample
27160 -break-watch [ -a | -r ]
27161 @end smallexample
27162
27163 Create a watchpoint. With the @samp{-a} option it will create an
27164 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
27165 read from or on a write to the memory location. With the @samp{-r}
27166 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
27167 trigger only when the memory location is accessed for reading. Without
27168 either of the options, the watchpoint created is a regular watchpoint,
27169 i.e., it will trigger when the memory location is accessed for writing.
27170 @xref{Set Watchpoints, , Setting Watchpoints}.
27171
27172 Note that @samp{-break-list} will report a single list of watchpoints and
27173 breakpoints inserted.
27174
27175 @subsubheading @value{GDBN} Command
27176
27177 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
27178 @samp{rwatch}.
27179
27180 @subsubheading Example
27181
27182 Setting a watchpoint on a variable in the @code{main} function:
27183
27184 @smallexample
27185 (gdb)
27186 -break-watch x
27187 ^done,wpt=@{number="2",exp="x"@}
27188 (gdb)
27189 -exec-continue
27190 ^running
27191 (gdb)
27192 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
27193 value=@{old="-268439212",new="55"@},
27194 frame=@{func="main",args=[],file="recursive2.c",
27195 fullname="/home/foo/bar/recursive2.c",line="5"@}
27196 (gdb)
27197 @end smallexample
27198
27199 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
27200 the program execution twice: first for the variable changing value, then
27201 for the watchpoint going out of scope.
27202
27203 @smallexample
27204 (gdb)
27205 -break-watch C
27206 ^done,wpt=@{number="5",exp="C"@}
27207 (gdb)
27208 -exec-continue
27209 ^running
27210 (gdb)
27211 *stopped,reason="watchpoint-trigger",
27212 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
27213 frame=@{func="callee4",args=[],
27214 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27215 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
27216 (gdb)
27217 -exec-continue
27218 ^running
27219 (gdb)
27220 *stopped,reason="watchpoint-scope",wpnum="5",
27221 frame=@{func="callee3",args=[@{name="strarg",
27222 value="0x11940 \"A string argument.\""@}],
27223 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27224 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
27225 (gdb)
27226 @end smallexample
27227
27228 Listing breakpoints and watchpoints, at different points in the program
27229 execution. Note that once the watchpoint goes out of scope, it is
27230 deleted.
27231
27232 @smallexample
27233 (gdb)
27234 -break-watch C
27235 ^done,wpt=@{number="2",exp="C"@}
27236 (gdb)
27237 -break-list
27238 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27239 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27240 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27241 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27242 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27243 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27244 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
27245 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27246 addr="0x00010734",func="callee4",
27247 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27248 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
27249 bkpt=@{number="2",type="watchpoint",disp="keep",
27250 enabled="y",addr="",what="C",times="0"@}]@}
27251 (gdb)
27252 -exec-continue
27253 ^running
27254 (gdb)
27255 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
27256 value=@{old="-276895068",new="3"@},
27257 frame=@{func="callee4",args=[],
27258 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27259 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
27260 (gdb)
27261 -break-list
27262 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
27263 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27264 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27265 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27266 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27267 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27268 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
27269 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27270 addr="0x00010734",func="callee4",
27271 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27272 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
27273 bkpt=@{number="2",type="watchpoint",disp="keep",
27274 enabled="y",addr="",what="C",times="-5"@}]@}
27275 (gdb)
27276 -exec-continue
27277 ^running
27278 ^done,reason="watchpoint-scope",wpnum="2",
27279 frame=@{func="callee3",args=[@{name="strarg",
27280 value="0x11940 \"A string argument.\""@}],
27281 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27282 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
27283 (gdb)
27284 -break-list
27285 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
27286 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
27287 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
27288 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
27289 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
27290 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
27291 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
27292 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
27293 addr="0x00010734",func="callee4",
27294 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
27295 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
27296 times="1"@}]@}
27297 (gdb)
27298 @end smallexample
27299
27300 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27301 @node GDB/MI Program Context
27302 @section @sc{gdb/mi} Program Context
27303
27304 @subheading The @code{-exec-arguments} Command
27305 @findex -exec-arguments
27306
27307
27308 @subsubheading Synopsis
27309
27310 @smallexample
27311 -exec-arguments @var{args}
27312 @end smallexample
27313
27314 Set the inferior program arguments, to be used in the next
27315 @samp{-exec-run}.
27316
27317 @subsubheading @value{GDBN} Command
27318
27319 The corresponding @value{GDBN} command is @samp{set args}.
27320
27321 @subsubheading Example
27322
27323 @smallexample
27324 (gdb)
27325 -exec-arguments -v word
27326 ^done
27327 (gdb)
27328 @end smallexample
27329
27330
27331 @ignore
27332 @subheading The @code{-exec-show-arguments} Command
27333 @findex -exec-show-arguments
27334
27335 @subsubheading Synopsis
27336
27337 @smallexample
27338 -exec-show-arguments
27339 @end smallexample
27340
27341 Print the arguments of the program.
27342
27343 @subsubheading @value{GDBN} Command
27344
27345 The corresponding @value{GDBN} command is @samp{show args}.
27346
27347 @subsubheading Example
27348 N.A.
27349 @end ignore
27350
27351
27352 @subheading The @code{-environment-cd} Command
27353 @findex -environment-cd
27354
27355 @subsubheading Synopsis
27356
27357 @smallexample
27358 -environment-cd @var{pathdir}
27359 @end smallexample
27360
27361 Set @value{GDBN}'s working directory.
27362
27363 @subsubheading @value{GDBN} Command
27364
27365 The corresponding @value{GDBN} command is @samp{cd}.
27366
27367 @subsubheading Example
27368
27369 @smallexample
27370 (gdb)
27371 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
27372 ^done
27373 (gdb)
27374 @end smallexample
27375
27376
27377 @subheading The @code{-environment-directory} Command
27378 @findex -environment-directory
27379
27380 @subsubheading Synopsis
27381
27382 @smallexample
27383 -environment-directory [ -r ] [ @var{pathdir} ]+
27384 @end smallexample
27385
27386 Add directories @var{pathdir} to beginning of search path for source files.
27387 If the @samp{-r} option is used, the search path is reset to the default
27388 search path. If directories @var{pathdir} are supplied in addition to the
27389 @samp{-r} option, the search path is first reset and then addition
27390 occurs as normal.
27391 Multiple directories may be specified, separated by blanks. Specifying
27392 multiple directories in a single command
27393 results in the directories added to the beginning of the
27394 search path in the same order they were presented in the command.
27395 If blanks are needed as
27396 part of a directory name, double-quotes should be used around
27397 the name. In the command output, the path will show up separated
27398 by the system directory-separator character. The directory-separator
27399 character must not be used
27400 in any directory name.
27401 If no directories are specified, the current search path is displayed.
27402
27403 @subsubheading @value{GDBN} Command
27404
27405 The corresponding @value{GDBN} command is @samp{dir}.
27406
27407 @subsubheading Example
27408
27409 @smallexample
27410 (gdb)
27411 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
27412 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
27413 (gdb)
27414 -environment-directory ""
27415 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
27416 (gdb)
27417 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
27418 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
27419 (gdb)
27420 -environment-directory -r
27421 ^done,source-path="$cdir:$cwd"
27422 (gdb)
27423 @end smallexample
27424
27425
27426 @subheading The @code{-environment-path} Command
27427 @findex -environment-path
27428
27429 @subsubheading Synopsis
27430
27431 @smallexample
27432 -environment-path [ -r ] [ @var{pathdir} ]+
27433 @end smallexample
27434
27435 Add directories @var{pathdir} to beginning of search path for object files.
27436 If the @samp{-r} option is used, the search path is reset to the original
27437 search path that existed at gdb start-up. If directories @var{pathdir} are
27438 supplied in addition to the
27439 @samp{-r} option, the search path is first reset and then addition
27440 occurs as normal.
27441 Multiple directories may be specified, separated by blanks. Specifying
27442 multiple directories in a single command
27443 results in the directories added to the beginning of the
27444 search path in the same order they were presented in the command.
27445 If blanks are needed as
27446 part of a directory name, double-quotes should be used around
27447 the name. In the command output, the path will show up separated
27448 by the system directory-separator character. The directory-separator
27449 character must not be used
27450 in any directory name.
27451 If no directories are specified, the current path is displayed.
27452
27453
27454 @subsubheading @value{GDBN} Command
27455
27456 The corresponding @value{GDBN} command is @samp{path}.
27457
27458 @subsubheading Example
27459
27460 @smallexample
27461 (gdb)
27462 -environment-path
27463 ^done,path="/usr/bin"
27464 (gdb)
27465 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
27466 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
27467 (gdb)
27468 -environment-path -r /usr/local/bin
27469 ^done,path="/usr/local/bin:/usr/bin"
27470 (gdb)
27471 @end smallexample
27472
27473
27474 @subheading The @code{-environment-pwd} Command
27475 @findex -environment-pwd
27476
27477 @subsubheading Synopsis
27478
27479 @smallexample
27480 -environment-pwd
27481 @end smallexample
27482
27483 Show the current working directory.
27484
27485 @subsubheading @value{GDBN} Command
27486
27487 The corresponding @value{GDBN} command is @samp{pwd}.
27488
27489 @subsubheading Example
27490
27491 @smallexample
27492 (gdb)
27493 -environment-pwd
27494 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
27495 (gdb)
27496 @end smallexample
27497
27498 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27499 @node GDB/MI Thread Commands
27500 @section @sc{gdb/mi} Thread Commands
27501
27502
27503 @subheading The @code{-thread-info} Command
27504 @findex -thread-info
27505
27506 @subsubheading Synopsis
27507
27508 @smallexample
27509 -thread-info [ @var{thread-id} ]
27510 @end smallexample
27511
27512 Reports information about either a specific thread, if
27513 the @var{thread-id} parameter is present, or about all
27514 threads. When printing information about all threads,
27515 also reports the current thread.
27516
27517 @subsubheading @value{GDBN} Command
27518
27519 The @samp{info thread} command prints the same information
27520 about all threads.
27521
27522 @subsubheading Result
27523
27524 The result is a list of threads. The following attributes are
27525 defined for a given thread:
27526
27527 @table @samp
27528 @item current
27529 This field exists only for the current thread. It has the value @samp{*}.
27530
27531 @item id
27532 The identifier that @value{GDBN} uses to refer to the thread.
27533
27534 @item target-id
27535 The identifier that the target uses to refer to the thread.
27536
27537 @item details
27538 Extra information about the thread, in a target-specific format. This
27539 field is optional.
27540
27541 @item name
27542 The name of the thread. If the user specified a name using the
27543 @code{thread name} command, then this name is given. Otherwise, if
27544 @value{GDBN} can extract the thread name from the target, then that
27545 name is given. If @value{GDBN} cannot find the thread name, then this
27546 field is omitted.
27547
27548 @item frame
27549 The stack frame currently executing in the thread.
27550
27551 @item state
27552 The thread's state. The @samp{state} field may have the following
27553 values:
27554
27555 @table @code
27556 @item stopped
27557 The thread is stopped. Frame information is available for stopped
27558 threads.
27559
27560 @item running
27561 The thread is running. There's no frame information for running
27562 threads.
27563
27564 @end table
27565
27566 @item core
27567 If @value{GDBN} can find the CPU core on which this thread is running,
27568 then this field is the core identifier. This field is optional.
27569
27570 @end table
27571
27572 @subsubheading Example
27573
27574 @smallexample
27575 -thread-info
27576 ^done,threads=[
27577 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
27578 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
27579 args=[]@},state="running"@},
27580 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
27581 frame=@{level="0",addr="0x0804891f",func="foo",
27582 args=[@{name="i",value="10"@}],
27583 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
27584 state="running"@}],
27585 current-thread-id="1"
27586 (gdb)
27587 @end smallexample
27588
27589 @subheading The @code{-thread-list-ids} Command
27590 @findex -thread-list-ids
27591
27592 @subsubheading Synopsis
27593
27594 @smallexample
27595 -thread-list-ids
27596 @end smallexample
27597
27598 Produces a list of the currently known @value{GDBN} thread ids. At the
27599 end of the list it also prints the total number of such threads.
27600
27601 This command is retained for historical reasons, the
27602 @code{-thread-info} command should be used instead.
27603
27604 @subsubheading @value{GDBN} Command
27605
27606 Part of @samp{info threads} supplies the same information.
27607
27608 @subsubheading Example
27609
27610 @smallexample
27611 (gdb)
27612 -thread-list-ids
27613 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
27614 current-thread-id="1",number-of-threads="3"
27615 (gdb)
27616 @end smallexample
27617
27618
27619 @subheading The @code{-thread-select} Command
27620 @findex -thread-select
27621
27622 @subsubheading Synopsis
27623
27624 @smallexample
27625 -thread-select @var{threadnum}
27626 @end smallexample
27627
27628 Make @var{threadnum} the current thread. It prints the number of the new
27629 current thread, and the topmost frame for that thread.
27630
27631 This command is deprecated in favor of explicitly using the
27632 @samp{--thread} option to each command.
27633
27634 @subsubheading @value{GDBN} Command
27635
27636 The corresponding @value{GDBN} command is @samp{thread}.
27637
27638 @subsubheading Example
27639
27640 @smallexample
27641 (gdb)
27642 -exec-next
27643 ^running
27644 (gdb)
27645 *stopped,reason="end-stepping-range",thread-id="2",line="187",
27646 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
27647 (gdb)
27648 -thread-list-ids
27649 ^done,
27650 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
27651 number-of-threads="3"
27652 (gdb)
27653 -thread-select 3
27654 ^done,new-thread-id="3",
27655 frame=@{level="0",func="vprintf",
27656 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
27657 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
27658 (gdb)
27659 @end smallexample
27660
27661 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27662 @node GDB/MI Ada Tasking Commands
27663 @section @sc{gdb/mi} Ada Tasking Commands
27664
27665 @subheading The @code{-ada-task-info} Command
27666 @findex -ada-task-info
27667
27668 @subsubheading Synopsis
27669
27670 @smallexample
27671 -ada-task-info [ @var{task-id} ]
27672 @end smallexample
27673
27674 Reports information about either a specific Ada task, if the
27675 @var{task-id} parameter is present, or about all Ada tasks.
27676
27677 @subsubheading @value{GDBN} Command
27678
27679 The @samp{info tasks} command prints the same information
27680 about all Ada tasks (@pxref{Ada Tasks}).
27681
27682 @subsubheading Result
27683
27684 The result is a table of Ada tasks. The following columns are
27685 defined for each Ada task:
27686
27687 @table @samp
27688 @item current
27689 This field exists only for the current thread. It has the value @samp{*}.
27690
27691 @item id
27692 The identifier that @value{GDBN} uses to refer to the Ada task.
27693
27694 @item task-id
27695 The identifier that the target uses to refer to the Ada task.
27696
27697 @item thread-id
27698 The identifier of the thread corresponding to the Ada task.
27699
27700 This field should always exist, as Ada tasks are always implemented
27701 on top of a thread. But if @value{GDBN} cannot find this corresponding
27702 thread for any reason, the field is omitted.
27703
27704 @item parent-id
27705 This field exists only when the task was created by another task.
27706 In this case, it provides the ID of the parent task.
27707
27708 @item priority
27709 The base priority of the task.
27710
27711 @item state
27712 The current state of the task. For a detailed description of the
27713 possible states, see @ref{Ada Tasks}.
27714
27715 @item name
27716 The name of the task.
27717
27718 @end table
27719
27720 @subsubheading Example
27721
27722 @smallexample
27723 -ada-task-info
27724 ^done,tasks=@{nr_rows="3",nr_cols="8",
27725 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
27726 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
27727 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
27728 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
27729 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
27730 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
27731 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
27732 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
27733 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
27734 state="Child Termination Wait",name="main_task"@}]@}
27735 (gdb)
27736 @end smallexample
27737
27738 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27739 @node GDB/MI Program Execution
27740 @section @sc{gdb/mi} Program Execution
27741
27742 These are the asynchronous commands which generate the out-of-band
27743 record @samp{*stopped}. Currently @value{GDBN} only really executes
27744 asynchronously with remote targets and this interaction is mimicked in
27745 other cases.
27746
27747 @subheading The @code{-exec-continue} Command
27748 @findex -exec-continue
27749
27750 @subsubheading Synopsis
27751
27752 @smallexample
27753 -exec-continue [--reverse] [--all|--thread-group N]
27754 @end smallexample
27755
27756 Resumes the execution of the inferior program, which will continue
27757 to execute until it reaches a debugger stop event. If the
27758 @samp{--reverse} option is specified, execution resumes in reverse until
27759 it reaches a stop event. Stop events may include
27760 @itemize @bullet
27761 @item
27762 breakpoints or watchpoints
27763 @item
27764 signals or exceptions
27765 @item
27766 the end of the process (or its beginning under @samp{--reverse})
27767 @item
27768 the end or beginning of a replay log if one is being used.
27769 @end itemize
27770 In all-stop mode (@pxref{All-Stop
27771 Mode}), may resume only one thread, or all threads, depending on the
27772 value of the @samp{scheduler-locking} variable. If @samp{--all} is
27773 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
27774 ignored in all-stop mode. If the @samp{--thread-group} options is
27775 specified, then all threads in that thread group are resumed.
27776
27777 @subsubheading @value{GDBN} Command
27778
27779 The corresponding @value{GDBN} corresponding is @samp{continue}.
27780
27781 @subsubheading Example
27782
27783 @smallexample
27784 -exec-continue
27785 ^running
27786 (gdb)
27787 @@Hello world
27788 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
27789 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
27790 line="13"@}
27791 (gdb)
27792 @end smallexample
27793
27794
27795 @subheading The @code{-exec-finish} Command
27796 @findex -exec-finish
27797
27798 @subsubheading Synopsis
27799
27800 @smallexample
27801 -exec-finish [--reverse]
27802 @end smallexample
27803
27804 Resumes the execution of the inferior program until the current
27805 function is exited. Displays the results returned by the function.
27806 If the @samp{--reverse} option is specified, resumes the reverse
27807 execution of the inferior program until the point where current
27808 function was called.
27809
27810 @subsubheading @value{GDBN} Command
27811
27812 The corresponding @value{GDBN} command is @samp{finish}.
27813
27814 @subsubheading Example
27815
27816 Function returning @code{void}.
27817
27818 @smallexample
27819 -exec-finish
27820 ^running
27821 (gdb)
27822 @@hello from foo
27823 *stopped,reason="function-finished",frame=@{func="main",args=[],
27824 file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
27825 (gdb)
27826 @end smallexample
27827
27828 Function returning other than @code{void}. The name of the internal
27829 @value{GDBN} variable storing the result is printed, together with the
27830 value itself.
27831
27832 @smallexample
27833 -exec-finish
27834 ^running
27835 (gdb)
27836 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
27837 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
27838 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
27839 gdb-result-var="$1",return-value="0"
27840 (gdb)
27841 @end smallexample
27842
27843
27844 @subheading The @code{-exec-interrupt} Command
27845 @findex -exec-interrupt
27846
27847 @subsubheading Synopsis
27848
27849 @smallexample
27850 -exec-interrupt [--all|--thread-group N]
27851 @end smallexample
27852
27853 Interrupts the background execution of the target. Note how the token
27854 associated with the stop message is the one for the execution command
27855 that has been interrupted. The token for the interrupt itself only
27856 appears in the @samp{^done} output. If the user is trying to
27857 interrupt a non-running program, an error message will be printed.
27858
27859 Note that when asynchronous execution is enabled, this command is
27860 asynchronous just like other execution commands. That is, first the
27861 @samp{^done} response will be printed, and the target stop will be
27862 reported after that using the @samp{*stopped} notification.
27863
27864 In non-stop mode, only the context thread is interrupted by default.
27865 All threads (in all inferiors) will be interrupted if the
27866 @samp{--all} option is specified. If the @samp{--thread-group}
27867 option is specified, all threads in that group will be interrupted.
27868
27869 @subsubheading @value{GDBN} Command
27870
27871 The corresponding @value{GDBN} command is @samp{interrupt}.
27872
27873 @subsubheading Example
27874
27875 @smallexample
27876 (gdb)
27877 111-exec-continue
27878 111^running
27879
27880 (gdb)
27881 222-exec-interrupt
27882 222^done
27883 (gdb)
27884 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
27885 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
27886 fullname="/home/foo/bar/try.c",line="13"@}
27887 (gdb)
27888
27889 (gdb)
27890 -exec-interrupt
27891 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
27892 (gdb)
27893 @end smallexample
27894
27895 @subheading The @code{-exec-jump} Command
27896 @findex -exec-jump
27897
27898 @subsubheading Synopsis
27899
27900 @smallexample
27901 -exec-jump @var{location}
27902 @end smallexample
27903
27904 Resumes execution of the inferior program at the location specified by
27905 parameter. @xref{Specify Location}, for a description of the
27906 different forms of @var{location}.
27907
27908 @subsubheading @value{GDBN} Command
27909
27910 The corresponding @value{GDBN} command is @samp{jump}.
27911
27912 @subsubheading Example
27913
27914 @smallexample
27915 -exec-jump foo.c:10
27916 *running,thread-id="all"
27917 ^running
27918 @end smallexample
27919
27920
27921 @subheading The @code{-exec-next} Command
27922 @findex -exec-next
27923
27924 @subsubheading Synopsis
27925
27926 @smallexample
27927 -exec-next [--reverse]
27928 @end smallexample
27929
27930 Resumes execution of the inferior program, stopping when the beginning
27931 of the next source line is reached.
27932
27933 If the @samp{--reverse} option is specified, resumes reverse execution
27934 of the inferior program, stopping at the beginning of the previous
27935 source line. If you issue this command on the first line of a
27936 function, it will take you back to the caller of that function, to the
27937 source line where the function was called.
27938
27939
27940 @subsubheading @value{GDBN} Command
27941
27942 The corresponding @value{GDBN} command is @samp{next}.
27943
27944 @subsubheading Example
27945
27946 @smallexample
27947 -exec-next
27948 ^running
27949 (gdb)
27950 *stopped,reason="end-stepping-range",line="8",file="hello.c"
27951 (gdb)
27952 @end smallexample
27953
27954
27955 @subheading The @code{-exec-next-instruction} Command
27956 @findex -exec-next-instruction
27957
27958 @subsubheading Synopsis
27959
27960 @smallexample
27961 -exec-next-instruction [--reverse]
27962 @end smallexample
27963
27964 Executes one machine instruction. If the instruction is a function
27965 call, continues until the function returns. If the program stops at an
27966 instruction in the middle of a source line, the address will be
27967 printed as well.
27968
27969 If the @samp{--reverse} option is specified, resumes reverse execution
27970 of the inferior program, stopping at the previous instruction. If the
27971 previously executed instruction was a return from another function,
27972 it will continue to execute in reverse until the call to that function
27973 (from the current stack frame) is reached.
27974
27975 @subsubheading @value{GDBN} Command
27976
27977 The corresponding @value{GDBN} command is @samp{nexti}.
27978
27979 @subsubheading Example
27980
27981 @smallexample
27982 (gdb)
27983 -exec-next-instruction
27984 ^running
27985
27986 (gdb)
27987 *stopped,reason="end-stepping-range",
27988 addr="0x000100d4",line="5",file="hello.c"
27989 (gdb)
27990 @end smallexample
27991
27992
27993 @subheading The @code{-exec-return} Command
27994 @findex -exec-return
27995
27996 @subsubheading Synopsis
27997
27998 @smallexample
27999 -exec-return
28000 @end smallexample
28001
28002 Makes current function return immediately. Doesn't execute the inferior.
28003 Displays the new current frame.
28004
28005 @subsubheading @value{GDBN} Command
28006
28007 The corresponding @value{GDBN} command is @samp{return}.
28008
28009 @subsubheading Example
28010
28011 @smallexample
28012 (gdb)
28013 200-break-insert callee4
28014 200^done,bkpt=@{number="1",addr="0x00010734",
28015 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
28016 (gdb)
28017 000-exec-run
28018 000^running
28019 (gdb)
28020 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
28021 frame=@{func="callee4",args=[],
28022 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28023 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
28024 (gdb)
28025 205-break-delete
28026 205^done
28027 (gdb)
28028 111-exec-return
28029 111^done,frame=@{level="0",func="callee3",
28030 args=[@{name="strarg",
28031 value="0x11940 \"A string argument.\""@}],
28032 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28033 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
28034 (gdb)
28035 @end smallexample
28036
28037
28038 @subheading The @code{-exec-run} Command
28039 @findex -exec-run
28040
28041 @subsubheading Synopsis
28042
28043 @smallexample
28044 -exec-run [--all | --thread-group N]
28045 @end smallexample
28046
28047 Starts execution of the inferior from the beginning. The inferior
28048 executes until either a breakpoint is encountered or the program
28049 exits. In the latter case the output will include an exit code, if
28050 the program has exited exceptionally.
28051
28052 When no option is specified, the current inferior is started. If the
28053 @samp{--thread-group} option is specified, it should refer to a thread
28054 group of type @samp{process}, and that thread group will be started.
28055 If the @samp{--all} option is specified, then all inferiors will be started.
28056
28057 @subsubheading @value{GDBN} Command
28058
28059 The corresponding @value{GDBN} command is @samp{run}.
28060
28061 @subsubheading Examples
28062
28063 @smallexample
28064 (gdb)
28065 -break-insert main
28066 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
28067 (gdb)
28068 -exec-run
28069 ^running
28070 (gdb)
28071 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
28072 frame=@{func="main",args=[],file="recursive2.c",
28073 fullname="/home/foo/bar/recursive2.c",line="4"@}
28074 (gdb)
28075 @end smallexample
28076
28077 @noindent
28078 Program exited normally:
28079
28080 @smallexample
28081 (gdb)
28082 -exec-run
28083 ^running
28084 (gdb)
28085 x = 55
28086 *stopped,reason="exited-normally"
28087 (gdb)
28088 @end smallexample
28089
28090 @noindent
28091 Program exited exceptionally:
28092
28093 @smallexample
28094 (gdb)
28095 -exec-run
28096 ^running
28097 (gdb)
28098 x = 55
28099 *stopped,reason="exited",exit-code="01"
28100 (gdb)
28101 @end smallexample
28102
28103 Another way the program can terminate is if it receives a signal such as
28104 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
28105
28106 @smallexample
28107 (gdb)
28108 *stopped,reason="exited-signalled",signal-name="SIGINT",
28109 signal-meaning="Interrupt"
28110 @end smallexample
28111
28112
28113 @c @subheading -exec-signal
28114
28115
28116 @subheading The @code{-exec-step} Command
28117 @findex -exec-step
28118
28119 @subsubheading Synopsis
28120
28121 @smallexample
28122 -exec-step [--reverse]
28123 @end smallexample
28124
28125 Resumes execution of the inferior program, stopping when the beginning
28126 of the next source line is reached, if the next source line is not a
28127 function call. If it is, stop at the first instruction of the called
28128 function. If the @samp{--reverse} option is specified, resumes reverse
28129 execution of the inferior program, stopping at the beginning of the
28130 previously executed source line.
28131
28132 @subsubheading @value{GDBN} Command
28133
28134 The corresponding @value{GDBN} command is @samp{step}.
28135
28136 @subsubheading Example
28137
28138 Stepping into a function:
28139
28140 @smallexample
28141 -exec-step
28142 ^running
28143 (gdb)
28144 *stopped,reason="end-stepping-range",
28145 frame=@{func="foo",args=[@{name="a",value="10"@},
28146 @{name="b",value="0"@}],file="recursive2.c",
28147 fullname="/home/foo/bar/recursive2.c",line="11"@}
28148 (gdb)
28149 @end smallexample
28150
28151 Regular stepping:
28152
28153 @smallexample
28154 -exec-step
28155 ^running
28156 (gdb)
28157 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
28158 (gdb)
28159 @end smallexample
28160
28161
28162 @subheading The @code{-exec-step-instruction} Command
28163 @findex -exec-step-instruction
28164
28165 @subsubheading Synopsis
28166
28167 @smallexample
28168 -exec-step-instruction [--reverse]
28169 @end smallexample
28170
28171 Resumes the inferior which executes one machine instruction. If the
28172 @samp{--reverse} option is specified, resumes reverse execution of the
28173 inferior program, stopping at the previously executed instruction.
28174 The output, once @value{GDBN} has stopped, will vary depending on
28175 whether we have stopped in the middle of a source line or not. In the
28176 former case, the address at which the program stopped will be printed
28177 as well.
28178
28179 @subsubheading @value{GDBN} Command
28180
28181 The corresponding @value{GDBN} command is @samp{stepi}.
28182
28183 @subsubheading Example
28184
28185 @smallexample
28186 (gdb)
28187 -exec-step-instruction
28188 ^running
28189
28190 (gdb)
28191 *stopped,reason="end-stepping-range",
28192 frame=@{func="foo",args=[],file="try.c",
28193 fullname="/home/foo/bar/try.c",line="10"@}
28194 (gdb)
28195 -exec-step-instruction
28196 ^running
28197
28198 (gdb)
28199 *stopped,reason="end-stepping-range",
28200 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
28201 fullname="/home/foo/bar/try.c",line="10"@}
28202 (gdb)
28203 @end smallexample
28204
28205
28206 @subheading The @code{-exec-until} Command
28207 @findex -exec-until
28208
28209 @subsubheading Synopsis
28210
28211 @smallexample
28212 -exec-until [ @var{location} ]
28213 @end smallexample
28214
28215 Executes the inferior until the @var{location} specified in the
28216 argument is reached. If there is no argument, the inferior executes
28217 until a source line greater than the current one is reached. The
28218 reason for stopping in this case will be @samp{location-reached}.
28219
28220 @subsubheading @value{GDBN} Command
28221
28222 The corresponding @value{GDBN} command is @samp{until}.
28223
28224 @subsubheading Example
28225
28226 @smallexample
28227 (gdb)
28228 -exec-until recursive2.c:6
28229 ^running
28230 (gdb)
28231 x = 55
28232 *stopped,reason="location-reached",frame=@{func="main",args=[],
28233 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
28234 (gdb)
28235 @end smallexample
28236
28237 @ignore
28238 @subheading -file-clear
28239 Is this going away????
28240 @end ignore
28241
28242 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28243 @node GDB/MI Stack Manipulation
28244 @section @sc{gdb/mi} Stack Manipulation Commands
28245
28246
28247 @subheading The @code{-stack-info-frame} Command
28248 @findex -stack-info-frame
28249
28250 @subsubheading Synopsis
28251
28252 @smallexample
28253 -stack-info-frame
28254 @end smallexample
28255
28256 Get info on the selected frame.
28257
28258 @subsubheading @value{GDBN} Command
28259
28260 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
28261 (without arguments).
28262
28263 @subsubheading Example
28264
28265 @smallexample
28266 (gdb)
28267 -stack-info-frame
28268 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
28269 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28270 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
28271 (gdb)
28272 @end smallexample
28273
28274 @subheading The @code{-stack-info-depth} Command
28275 @findex -stack-info-depth
28276
28277 @subsubheading Synopsis
28278
28279 @smallexample
28280 -stack-info-depth [ @var{max-depth} ]
28281 @end smallexample
28282
28283 Return the depth of the stack. If the integer argument @var{max-depth}
28284 is specified, do not count beyond @var{max-depth} frames.
28285
28286 @subsubheading @value{GDBN} Command
28287
28288 There's no equivalent @value{GDBN} command.
28289
28290 @subsubheading Example
28291
28292 For a stack with frame levels 0 through 11:
28293
28294 @smallexample
28295 (gdb)
28296 -stack-info-depth
28297 ^done,depth="12"
28298 (gdb)
28299 -stack-info-depth 4
28300 ^done,depth="4"
28301 (gdb)
28302 -stack-info-depth 12
28303 ^done,depth="12"
28304 (gdb)
28305 -stack-info-depth 11
28306 ^done,depth="11"
28307 (gdb)
28308 -stack-info-depth 13
28309 ^done,depth="12"
28310 (gdb)
28311 @end smallexample
28312
28313 @subheading The @code{-stack-list-arguments} Command
28314 @findex -stack-list-arguments
28315
28316 @subsubheading Synopsis
28317
28318 @smallexample
28319 -stack-list-arguments @var{print-values}
28320 [ @var{low-frame} @var{high-frame} ]
28321 @end smallexample
28322
28323 Display a list of the arguments for the frames between @var{low-frame}
28324 and @var{high-frame} (inclusive). If @var{low-frame} and
28325 @var{high-frame} are not provided, list the arguments for the whole
28326 call stack. If the two arguments are equal, show the single frame
28327 at the corresponding level. It is an error if @var{low-frame} is
28328 larger than the actual number of frames. On the other hand,
28329 @var{high-frame} may be larger than the actual number of frames, in
28330 which case only existing frames will be returned.
28331
28332 If @var{print-values} is 0 or @code{--no-values}, print only the names of
28333 the variables; if it is 1 or @code{--all-values}, print also their
28334 values; and if it is 2 or @code{--simple-values}, print the name,
28335 type and value for simple data types, and the name and type for arrays,
28336 structures and unions.
28337
28338 Use of this command to obtain arguments in a single frame is
28339 deprecated in favor of the @samp{-stack-list-variables} command.
28340
28341 @subsubheading @value{GDBN} Command
28342
28343 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
28344 @samp{gdb_get_args} command which partially overlaps with the
28345 functionality of @samp{-stack-list-arguments}.
28346
28347 @subsubheading Example
28348
28349 @smallexample
28350 (gdb)
28351 -stack-list-frames
28352 ^done,
28353 stack=[
28354 frame=@{level="0",addr="0x00010734",func="callee4",
28355 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28356 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
28357 frame=@{level="1",addr="0x0001076c",func="callee3",
28358 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28359 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
28360 frame=@{level="2",addr="0x0001078c",func="callee2",
28361 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28362 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
28363 frame=@{level="3",addr="0x000107b4",func="callee1",
28364 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28365 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
28366 frame=@{level="4",addr="0x000107e0",func="main",
28367 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
28368 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
28369 (gdb)
28370 -stack-list-arguments 0
28371 ^done,
28372 stack-args=[
28373 frame=@{level="0",args=[]@},
28374 frame=@{level="1",args=[name="strarg"]@},
28375 frame=@{level="2",args=[name="intarg",name="strarg"]@},
28376 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
28377 frame=@{level="4",args=[]@}]
28378 (gdb)
28379 -stack-list-arguments 1
28380 ^done,
28381 stack-args=[
28382 frame=@{level="0",args=[]@},
28383 frame=@{level="1",
28384 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
28385 frame=@{level="2",args=[
28386 @{name="intarg",value="2"@},
28387 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
28388 @{frame=@{level="3",args=[
28389 @{name="intarg",value="2"@},
28390 @{name="strarg",value="0x11940 \"A string argument.\""@},
28391 @{name="fltarg",value="3.5"@}]@},
28392 frame=@{level="4",args=[]@}]
28393 (gdb)
28394 -stack-list-arguments 0 2 2
28395 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
28396 (gdb)
28397 -stack-list-arguments 1 2 2
28398 ^done,stack-args=[frame=@{level="2",
28399 args=[@{name="intarg",value="2"@},
28400 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
28401 (gdb)
28402 @end smallexample
28403
28404 @c @subheading -stack-list-exception-handlers
28405
28406
28407 @subheading The @code{-stack-list-frames} Command
28408 @findex -stack-list-frames
28409
28410 @subsubheading Synopsis
28411
28412 @smallexample
28413 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
28414 @end smallexample
28415
28416 List the frames currently on the stack. For each frame it displays the
28417 following info:
28418
28419 @table @samp
28420 @item @var{level}
28421 The frame number, 0 being the topmost frame, i.e., the innermost function.
28422 @item @var{addr}
28423 The @code{$pc} value for that frame.
28424 @item @var{func}
28425 Function name.
28426 @item @var{file}
28427 File name of the source file where the function lives.
28428 @item @var{fullname}
28429 The full file name of the source file where the function lives.
28430 @item @var{line}
28431 Line number corresponding to the @code{$pc}.
28432 @item @var{from}
28433 The shared library where this function is defined. This is only given
28434 if the frame's function is not known.
28435 @end table
28436
28437 If invoked without arguments, this command prints a backtrace for the
28438 whole stack. If given two integer arguments, it shows the frames whose
28439 levels are between the two arguments (inclusive). If the two arguments
28440 are equal, it shows the single frame at the corresponding level. It is
28441 an error if @var{low-frame} is larger than the actual number of
28442 frames. On the other hand, @var{high-frame} may be larger than the
28443 actual number of frames, in which case only existing frames will be returned.
28444
28445 @subsubheading @value{GDBN} Command
28446
28447 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
28448
28449 @subsubheading Example
28450
28451 Full stack backtrace:
28452
28453 @smallexample
28454 (gdb)
28455 -stack-list-frames
28456 ^done,stack=
28457 [frame=@{level="0",addr="0x0001076c",func="foo",
28458 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
28459 frame=@{level="1",addr="0x000107a4",func="foo",
28460 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28461 frame=@{level="2",addr="0x000107a4",func="foo",
28462 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28463 frame=@{level="3",addr="0x000107a4",func="foo",
28464 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28465 frame=@{level="4",addr="0x000107a4",func="foo",
28466 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28467 frame=@{level="5",addr="0x000107a4",func="foo",
28468 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28469 frame=@{level="6",addr="0x000107a4",func="foo",
28470 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28471 frame=@{level="7",addr="0x000107a4",func="foo",
28472 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28473 frame=@{level="8",addr="0x000107a4",func="foo",
28474 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28475 frame=@{level="9",addr="0x000107a4",func="foo",
28476 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28477 frame=@{level="10",addr="0x000107a4",func="foo",
28478 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28479 frame=@{level="11",addr="0x00010738",func="main",
28480 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
28481 (gdb)
28482 @end smallexample
28483
28484 Show frames between @var{low_frame} and @var{high_frame}:
28485
28486 @smallexample
28487 (gdb)
28488 -stack-list-frames 3 5
28489 ^done,stack=
28490 [frame=@{level="3",addr="0x000107a4",func="foo",
28491 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28492 frame=@{level="4",addr="0x000107a4",func="foo",
28493 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
28494 frame=@{level="5",addr="0x000107a4",func="foo",
28495 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
28496 (gdb)
28497 @end smallexample
28498
28499 Show a single frame:
28500
28501 @smallexample
28502 (gdb)
28503 -stack-list-frames 3 3
28504 ^done,stack=
28505 [frame=@{level="3",addr="0x000107a4",func="foo",
28506 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
28507 (gdb)
28508 @end smallexample
28509
28510
28511 @subheading The @code{-stack-list-locals} Command
28512 @findex -stack-list-locals
28513
28514 @subsubheading Synopsis
28515
28516 @smallexample
28517 -stack-list-locals @var{print-values}
28518 @end smallexample
28519
28520 Display the local variable names for the selected frame. If
28521 @var{print-values} is 0 or @code{--no-values}, print only the names of
28522 the variables; if it is 1 or @code{--all-values}, print also their
28523 values; and if it is 2 or @code{--simple-values}, print the name,
28524 type and value for simple data types, and the name and type for arrays,
28525 structures and unions. In this last case, a frontend can immediately
28526 display the value of simple data types and create variable objects for
28527 other data types when the user wishes to explore their values in
28528 more detail.
28529
28530 This command is deprecated in favor of the
28531 @samp{-stack-list-variables} command.
28532
28533 @subsubheading @value{GDBN} Command
28534
28535 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
28536
28537 @subsubheading Example
28538
28539 @smallexample
28540 (gdb)
28541 -stack-list-locals 0
28542 ^done,locals=[name="A",name="B",name="C"]
28543 (gdb)
28544 -stack-list-locals --all-values
28545 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
28546 @{name="C",value="@{1, 2, 3@}"@}]
28547 -stack-list-locals --simple-values
28548 ^done,locals=[@{name="A",type="int",value="1"@},
28549 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
28550 (gdb)
28551 @end smallexample
28552
28553 @subheading The @code{-stack-list-variables} Command
28554 @findex -stack-list-variables
28555
28556 @subsubheading Synopsis
28557
28558 @smallexample
28559 -stack-list-variables @var{print-values}
28560 @end smallexample
28561
28562 Display the names of local variables and function arguments for the selected frame. If
28563 @var{print-values} is 0 or @code{--no-values}, print only the names of
28564 the variables; if it is 1 or @code{--all-values}, print also their
28565 values; and if it is 2 or @code{--simple-values}, print the name,
28566 type and value for simple data types, and the name and type for arrays,
28567 structures and unions.
28568
28569 @subsubheading Example
28570
28571 @smallexample
28572 (gdb)
28573 -stack-list-variables --thread 1 --frame 0 --all-values
28574 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
28575 (gdb)
28576 @end smallexample
28577
28578
28579 @subheading The @code{-stack-select-frame} Command
28580 @findex -stack-select-frame
28581
28582 @subsubheading Synopsis
28583
28584 @smallexample
28585 -stack-select-frame @var{framenum}
28586 @end smallexample
28587
28588 Change the selected frame. Select a different frame @var{framenum} on
28589 the stack.
28590
28591 This command in deprecated in favor of passing the @samp{--frame}
28592 option to every command.
28593
28594 @subsubheading @value{GDBN} Command
28595
28596 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
28597 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
28598
28599 @subsubheading Example
28600
28601 @smallexample
28602 (gdb)
28603 -stack-select-frame 2
28604 ^done
28605 (gdb)
28606 @end smallexample
28607
28608 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28609 @node GDB/MI Variable Objects
28610 @section @sc{gdb/mi} Variable Objects
28611
28612 @ignore
28613
28614 @subheading Motivation for Variable Objects in @sc{gdb/mi}
28615
28616 For the implementation of a variable debugger window (locals, watched
28617 expressions, etc.), we are proposing the adaptation of the existing code
28618 used by @code{Insight}.
28619
28620 The two main reasons for that are:
28621
28622 @enumerate 1
28623 @item
28624 It has been proven in practice (it is already on its second generation).
28625
28626 @item
28627 It will shorten development time (needless to say how important it is
28628 now).
28629 @end enumerate
28630
28631 The original interface was designed to be used by Tcl code, so it was
28632 slightly changed so it could be used through @sc{gdb/mi}. This section
28633 describes the @sc{gdb/mi} operations that will be available and gives some
28634 hints about their use.
28635
28636 @emph{Note}: In addition to the set of operations described here, we
28637 expect the @sc{gui} implementation of a variable window to require, at
28638 least, the following operations:
28639
28640 @itemize @bullet
28641 @item @code{-gdb-show} @code{output-radix}
28642 @item @code{-stack-list-arguments}
28643 @item @code{-stack-list-locals}
28644 @item @code{-stack-select-frame}
28645 @end itemize
28646
28647 @end ignore
28648
28649 @subheading Introduction to Variable Objects
28650
28651 @cindex variable objects in @sc{gdb/mi}
28652
28653 Variable objects are "object-oriented" MI interface for examining and
28654 changing values of expressions. Unlike some other MI interfaces that
28655 work with expressions, variable objects are specifically designed for
28656 simple and efficient presentation in the frontend. A variable object
28657 is identified by string name. When a variable object is created, the
28658 frontend specifies the expression for that variable object. The
28659 expression can be a simple variable, or it can be an arbitrary complex
28660 expression, and can even involve CPU registers. After creating a
28661 variable object, the frontend can invoke other variable object
28662 operations---for example to obtain or change the value of a variable
28663 object, or to change display format.
28664
28665 Variable objects have hierarchical tree structure. Any variable object
28666 that corresponds to a composite type, such as structure in C, has
28667 a number of child variable objects, for example corresponding to each
28668 element of a structure. A child variable object can itself have
28669 children, recursively. Recursion ends when we reach
28670 leaf variable objects, which always have built-in types. Child variable
28671 objects are created only by explicit request, so if a frontend
28672 is not interested in the children of a particular variable object, no
28673 child will be created.
28674
28675 For a leaf variable object it is possible to obtain its value as a
28676 string, or set the value from a string. String value can be also
28677 obtained for a non-leaf variable object, but it's generally a string
28678 that only indicates the type of the object, and does not list its
28679 contents. Assignment to a non-leaf variable object is not allowed.
28680
28681 A frontend does not need to read the values of all variable objects each time
28682 the program stops. Instead, MI provides an update command that lists all
28683 variable objects whose values has changed since the last update
28684 operation. This considerably reduces the amount of data that must
28685 be transferred to the frontend. As noted above, children variable
28686 objects are created on demand, and only leaf variable objects have a
28687 real value. As result, gdb will read target memory only for leaf
28688 variables that frontend has created.
28689
28690 The automatic update is not always desirable. For example, a frontend
28691 might want to keep a value of some expression for future reference,
28692 and never update it. For another example, fetching memory is
28693 relatively slow for embedded targets, so a frontend might want
28694 to disable automatic update for the variables that are either not
28695 visible on the screen, or ``closed''. This is possible using so
28696 called ``frozen variable objects''. Such variable objects are never
28697 implicitly updated.
28698
28699 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
28700 fixed variable object, the expression is parsed when the variable
28701 object is created, including associating identifiers to specific
28702 variables. The meaning of expression never changes. For a floating
28703 variable object the values of variables whose names appear in the
28704 expressions are re-evaluated every time in the context of the current
28705 frame. Consider this example:
28706
28707 @smallexample
28708 void do_work(...)
28709 @{
28710 struct work_state state;
28711
28712 if (...)
28713 do_work(...);
28714 @}
28715 @end smallexample
28716
28717 If a fixed variable object for the @code{state} variable is created in
28718 this function, and we enter the recursive call, the variable
28719 object will report the value of @code{state} in the top-level
28720 @code{do_work} invocation. On the other hand, a floating variable
28721 object will report the value of @code{state} in the current frame.
28722
28723 If an expression specified when creating a fixed variable object
28724 refers to a local variable, the variable object becomes bound to the
28725 thread and frame in which the variable object is created. When such
28726 variable object is updated, @value{GDBN} makes sure that the
28727 thread/frame combination the variable object is bound to still exists,
28728 and re-evaluates the variable object in context of that thread/frame.
28729
28730 The following is the complete set of @sc{gdb/mi} operations defined to
28731 access this functionality:
28732
28733 @multitable @columnfractions .4 .6
28734 @item @strong{Operation}
28735 @tab @strong{Description}
28736
28737 @item @code{-enable-pretty-printing}
28738 @tab enable Python-based pretty-printing
28739 @item @code{-var-create}
28740 @tab create a variable object
28741 @item @code{-var-delete}
28742 @tab delete the variable object and/or its children
28743 @item @code{-var-set-format}
28744 @tab set the display format of this variable
28745 @item @code{-var-show-format}
28746 @tab show the display format of this variable
28747 @item @code{-var-info-num-children}
28748 @tab tells how many children this object has
28749 @item @code{-var-list-children}
28750 @tab return a list of the object's children
28751 @item @code{-var-info-type}
28752 @tab show the type of this variable object
28753 @item @code{-var-info-expression}
28754 @tab print parent-relative expression that this variable object represents
28755 @item @code{-var-info-path-expression}
28756 @tab print full expression that this variable object represents
28757 @item @code{-var-show-attributes}
28758 @tab is this variable editable? does it exist here?
28759 @item @code{-var-evaluate-expression}
28760 @tab get the value of this variable
28761 @item @code{-var-assign}
28762 @tab set the value of this variable
28763 @item @code{-var-update}
28764 @tab update the variable and its children
28765 @item @code{-var-set-frozen}
28766 @tab set frozeness attribute
28767 @item @code{-var-set-update-range}
28768 @tab set range of children to display on update
28769 @end multitable
28770
28771 In the next subsection we describe each operation in detail and suggest
28772 how it can be used.
28773
28774 @subheading Description And Use of Operations on Variable Objects
28775
28776 @subheading The @code{-enable-pretty-printing} Command
28777 @findex -enable-pretty-printing
28778
28779 @smallexample
28780 -enable-pretty-printing
28781 @end smallexample
28782
28783 @value{GDBN} allows Python-based visualizers to affect the output of the
28784 MI variable object commands. However, because there was no way to
28785 implement this in a fully backward-compatible way, a front end must
28786 request that this functionality be enabled.
28787
28788 Once enabled, this feature cannot be disabled.
28789
28790 Note that if Python support has not been compiled into @value{GDBN},
28791 this command will still succeed (and do nothing).
28792
28793 This feature is currently (as of @value{GDBN} 7.0) experimental, and
28794 may work differently in future versions of @value{GDBN}.
28795
28796 @subheading The @code{-var-create} Command
28797 @findex -var-create
28798
28799 @subsubheading Synopsis
28800
28801 @smallexample
28802 -var-create @{@var{name} | "-"@}
28803 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
28804 @end smallexample
28805
28806 This operation creates a variable object, which allows the monitoring of
28807 a variable, the result of an expression, a memory cell or a CPU
28808 register.
28809
28810 The @var{name} parameter is the string by which the object can be
28811 referenced. It must be unique. If @samp{-} is specified, the varobj
28812 system will generate a string ``varNNNNNN'' automatically. It will be
28813 unique provided that one does not specify @var{name} of that format.
28814 The command fails if a duplicate name is found.
28815
28816 The frame under which the expression should be evaluated can be
28817 specified by @var{frame-addr}. A @samp{*} indicates that the current
28818 frame should be used. A @samp{@@} indicates that a floating variable
28819 object must be created.
28820
28821 @var{expression} is any expression valid on the current language set (must not
28822 begin with a @samp{*}), or one of the following:
28823
28824 @itemize @bullet
28825 @item
28826 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
28827
28828 @item
28829 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
28830
28831 @item
28832 @samp{$@var{regname}} --- a CPU register name
28833 @end itemize
28834
28835 @cindex dynamic varobj
28836 A varobj's contents may be provided by a Python-based pretty-printer. In this
28837 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
28838 have slightly different semantics in some cases. If the
28839 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
28840 will never create a dynamic varobj. This ensures backward
28841 compatibility for existing clients.
28842
28843 @subsubheading Result
28844
28845 This operation returns attributes of the newly-created varobj. These
28846 are:
28847
28848 @table @samp
28849 @item name
28850 The name of the varobj.
28851
28852 @item numchild
28853 The number of children of the varobj. This number is not necessarily
28854 reliable for a dynamic varobj. Instead, you must examine the
28855 @samp{has_more} attribute.
28856
28857 @item value
28858 The varobj's scalar value. For a varobj whose type is some sort of
28859 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
28860 will not be interesting.
28861
28862 @item type
28863 The varobj's type. This is a string representation of the type, as
28864 would be printed by the @value{GDBN} CLI.
28865
28866 @item thread-id
28867 If a variable object is bound to a specific thread, then this is the
28868 thread's identifier.
28869
28870 @item has_more
28871 For a dynamic varobj, this indicates whether there appear to be any
28872 children available. For a non-dynamic varobj, this will be 0.
28873
28874 @item dynamic
28875 This attribute will be present and have the value @samp{1} if the
28876 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
28877 then this attribute will not be present.
28878
28879 @item displayhint
28880 A dynamic varobj can supply a display hint to the front end. The
28881 value comes directly from the Python pretty-printer object's
28882 @code{display_hint} method. @xref{Pretty Printing API}.
28883 @end table
28884
28885 Typical output will look like this:
28886
28887 @smallexample
28888 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
28889 has_more="@var{has_more}"
28890 @end smallexample
28891
28892
28893 @subheading The @code{-var-delete} Command
28894 @findex -var-delete
28895
28896 @subsubheading Synopsis
28897
28898 @smallexample
28899 -var-delete [ -c ] @var{name}
28900 @end smallexample
28901
28902 Deletes a previously created variable object and all of its children.
28903 With the @samp{-c} option, just deletes the children.
28904
28905 Returns an error if the object @var{name} is not found.
28906
28907
28908 @subheading The @code{-var-set-format} Command
28909 @findex -var-set-format
28910
28911 @subsubheading Synopsis
28912
28913 @smallexample
28914 -var-set-format @var{name} @var{format-spec}
28915 @end smallexample
28916
28917 Sets the output format for the value of the object @var{name} to be
28918 @var{format-spec}.
28919
28920 @anchor{-var-set-format}
28921 The syntax for the @var{format-spec} is as follows:
28922
28923 @smallexample
28924 @var{format-spec} @expansion{}
28925 @{binary | decimal | hexadecimal | octal | natural@}
28926 @end smallexample
28927
28928 The natural format is the default format choosen automatically
28929 based on the variable type (like decimal for an @code{int}, hex
28930 for pointers, etc.).
28931
28932 For a variable with children, the format is set only on the
28933 variable itself, and the children are not affected.
28934
28935 @subheading The @code{-var-show-format} Command
28936 @findex -var-show-format
28937
28938 @subsubheading Synopsis
28939
28940 @smallexample
28941 -var-show-format @var{name}
28942 @end smallexample
28943
28944 Returns the format used to display the value of the object @var{name}.
28945
28946 @smallexample
28947 @var{format} @expansion{}
28948 @var{format-spec}
28949 @end smallexample
28950
28951
28952 @subheading The @code{-var-info-num-children} Command
28953 @findex -var-info-num-children
28954
28955 @subsubheading Synopsis
28956
28957 @smallexample
28958 -var-info-num-children @var{name}
28959 @end smallexample
28960
28961 Returns the number of children of a variable object @var{name}:
28962
28963 @smallexample
28964 numchild=@var{n}
28965 @end smallexample
28966
28967 Note that this number is not completely reliable for a dynamic varobj.
28968 It will return the current number of children, but more children may
28969 be available.
28970
28971
28972 @subheading The @code{-var-list-children} Command
28973 @findex -var-list-children
28974
28975 @subsubheading Synopsis
28976
28977 @smallexample
28978 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
28979 @end smallexample
28980 @anchor{-var-list-children}
28981
28982 Return a list of the children of the specified variable object and
28983 create variable objects for them, if they do not already exist. With
28984 a single argument or if @var{print-values} has a value of 0 or
28985 @code{--no-values}, print only the names of the variables; if
28986 @var{print-values} is 1 or @code{--all-values}, also print their
28987 values; and if it is 2 or @code{--simple-values} print the name and
28988 value for simple data types and just the name for arrays, structures
28989 and unions.
28990
28991 @var{from} and @var{to}, if specified, indicate the range of children
28992 to report. If @var{from} or @var{to} is less than zero, the range is
28993 reset and all children will be reported. Otherwise, children starting
28994 at @var{from} (zero-based) and up to and excluding @var{to} will be
28995 reported.
28996
28997 If a child range is requested, it will only affect the current call to
28998 @code{-var-list-children}, but not future calls to @code{-var-update}.
28999 For this, you must instead use @code{-var-set-update-range}. The
29000 intent of this approach is to enable a front end to implement any
29001 update approach it likes; for example, scrolling a view may cause the
29002 front end to request more children with @code{-var-list-children}, and
29003 then the front end could call @code{-var-set-update-range} with a
29004 different range to ensure that future updates are restricted to just
29005 the visible items.
29006
29007 For each child the following results are returned:
29008
29009 @table @var
29010
29011 @item name
29012 Name of the variable object created for this child.
29013
29014 @item exp
29015 The expression to be shown to the user by the front end to designate this child.
29016 For example this may be the name of a structure member.
29017
29018 For a dynamic varobj, this value cannot be used to form an
29019 expression. There is no way to do this at all with a dynamic varobj.
29020
29021 For C/C@t{++} structures there are several pseudo children returned to
29022 designate access qualifiers. For these pseudo children @var{exp} is
29023 @samp{public}, @samp{private}, or @samp{protected}. In this case the
29024 type and value are not present.
29025
29026 A dynamic varobj will not report the access qualifying
29027 pseudo-children, regardless of the language. This information is not
29028 available at all with a dynamic varobj.
29029
29030 @item numchild
29031 Number of children this child has. For a dynamic varobj, this will be
29032 0.
29033
29034 @item type
29035 The type of the child.
29036
29037 @item value
29038 If values were requested, this is the value.
29039
29040 @item thread-id
29041 If this variable object is associated with a thread, this is the thread id.
29042 Otherwise this result is not present.
29043
29044 @item frozen
29045 If the variable object is frozen, this variable will be present with a value of 1.
29046 @end table
29047
29048 The result may have its own attributes:
29049
29050 @table @samp
29051 @item displayhint
29052 A dynamic varobj can supply a display hint to the front end. The
29053 value comes directly from the Python pretty-printer object's
29054 @code{display_hint} method. @xref{Pretty Printing API}.
29055
29056 @item has_more
29057 This is an integer attribute which is nonzero if there are children
29058 remaining after the end of the selected range.
29059 @end table
29060
29061 @subsubheading Example
29062
29063 @smallexample
29064 (gdb)
29065 -var-list-children n
29066 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
29067 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
29068 (gdb)
29069 -var-list-children --all-values n
29070 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
29071 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
29072 @end smallexample
29073
29074
29075 @subheading The @code{-var-info-type} Command
29076 @findex -var-info-type
29077
29078 @subsubheading Synopsis
29079
29080 @smallexample
29081 -var-info-type @var{name}
29082 @end smallexample
29083
29084 Returns the type of the specified variable @var{name}. The type is
29085 returned as a string in the same format as it is output by the
29086 @value{GDBN} CLI:
29087
29088 @smallexample
29089 type=@var{typename}
29090 @end smallexample
29091
29092
29093 @subheading The @code{-var-info-expression} Command
29094 @findex -var-info-expression
29095
29096 @subsubheading Synopsis
29097
29098 @smallexample
29099 -var-info-expression @var{name}
29100 @end smallexample
29101
29102 Returns a string that is suitable for presenting this
29103 variable object in user interface. The string is generally
29104 not valid expression in the current language, and cannot be evaluated.
29105
29106 For example, if @code{a} is an array, and variable object
29107 @code{A} was created for @code{a}, then we'll get this output:
29108
29109 @smallexample
29110 (gdb) -var-info-expression A.1
29111 ^done,lang="C",exp="1"
29112 @end smallexample
29113
29114 @noindent
29115 Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
29116
29117 Note that the output of the @code{-var-list-children} command also
29118 includes those expressions, so the @code{-var-info-expression} command
29119 is of limited use.
29120
29121 @subheading The @code{-var-info-path-expression} Command
29122 @findex -var-info-path-expression
29123
29124 @subsubheading Synopsis
29125
29126 @smallexample
29127 -var-info-path-expression @var{name}
29128 @end smallexample
29129
29130 Returns an expression that can be evaluated in the current
29131 context and will yield the same value that a variable object has.
29132 Compare this with the @code{-var-info-expression} command, which
29133 result can be used only for UI presentation. Typical use of
29134 the @code{-var-info-path-expression} command is creating a
29135 watchpoint from a variable object.
29136
29137 This command is currently not valid for children of a dynamic varobj,
29138 and will give an error when invoked on one.
29139
29140 For example, suppose @code{C} is a C@t{++} class, derived from class
29141 @code{Base}, and that the @code{Base} class has a member called
29142 @code{m_size}. Assume a variable @code{c} is has the type of
29143 @code{C} and a variable object @code{C} was created for variable
29144 @code{c}. Then, we'll get this output:
29145 @smallexample
29146 (gdb) -var-info-path-expression C.Base.public.m_size
29147 ^done,path_expr=((Base)c).m_size)
29148 @end smallexample
29149
29150 @subheading The @code{-var-show-attributes} Command
29151 @findex -var-show-attributes
29152
29153 @subsubheading Synopsis
29154
29155 @smallexample
29156 -var-show-attributes @var{name}
29157 @end smallexample
29158
29159 List attributes of the specified variable object @var{name}:
29160
29161 @smallexample
29162 status=@var{attr} [ ( ,@var{attr} )* ]
29163 @end smallexample
29164
29165 @noindent
29166 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
29167
29168 @subheading The @code{-var-evaluate-expression} Command
29169 @findex -var-evaluate-expression
29170
29171 @subsubheading Synopsis
29172
29173 @smallexample
29174 -var-evaluate-expression [-f @var{format-spec}] @var{name}
29175 @end smallexample
29176
29177 Evaluates the expression that is represented by the specified variable
29178 object and returns its value as a string. The format of the string
29179 can be specified with the @samp{-f} option. The possible values of
29180 this option are the same as for @code{-var-set-format}
29181 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
29182 the current display format will be used. The current display format
29183 can be changed using the @code{-var-set-format} command.
29184
29185 @smallexample
29186 value=@var{value}
29187 @end smallexample
29188
29189 Note that one must invoke @code{-var-list-children} for a variable
29190 before the value of a child variable can be evaluated.
29191
29192 @subheading The @code{-var-assign} Command
29193 @findex -var-assign
29194
29195 @subsubheading Synopsis
29196
29197 @smallexample
29198 -var-assign @var{name} @var{expression}
29199 @end smallexample
29200
29201 Assigns the value of @var{expression} to the variable object specified
29202 by @var{name}. The object must be @samp{editable}. If the variable's
29203 value is altered by the assign, the variable will show up in any
29204 subsequent @code{-var-update} list.
29205
29206 @subsubheading Example
29207
29208 @smallexample
29209 (gdb)
29210 -var-assign var1 3
29211 ^done,value="3"
29212 (gdb)
29213 -var-update *
29214 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
29215 (gdb)
29216 @end smallexample
29217
29218 @subheading The @code{-var-update} Command
29219 @findex -var-update
29220
29221 @subsubheading Synopsis
29222
29223 @smallexample
29224 -var-update [@var{print-values}] @{@var{name} | "*"@}
29225 @end smallexample
29226
29227 Reevaluate the expressions corresponding to the variable object
29228 @var{name} and all its direct and indirect children, and return the
29229 list of variable objects whose values have changed; @var{name} must
29230 be a root variable object. Here, ``changed'' means that the result of
29231 @code{-var-evaluate-expression} before and after the
29232 @code{-var-update} is different. If @samp{*} is used as the variable
29233 object names, all existing variable objects are updated, except
29234 for frozen ones (@pxref{-var-set-frozen}). The option
29235 @var{print-values} determines whether both names and values, or just
29236 names are printed. The possible values of this option are the same
29237 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
29238 recommended to use the @samp{--all-values} option, to reduce the
29239 number of MI commands needed on each program stop.
29240
29241 With the @samp{*} parameter, if a variable object is bound to a
29242 currently running thread, it will not be updated, without any
29243 diagnostic.
29244
29245 If @code{-var-set-update-range} was previously used on a varobj, then
29246 only the selected range of children will be reported.
29247
29248 @code{-var-update} reports all the changed varobjs in a tuple named
29249 @samp{changelist}.
29250
29251 Each item in the change list is itself a tuple holding:
29252
29253 @table @samp
29254 @item name
29255 The name of the varobj.
29256
29257 @item value
29258 If values were requested for this update, then this field will be
29259 present and will hold the value of the varobj.
29260
29261 @item in_scope
29262 @anchor{-var-update}
29263 This field is a string which may take one of three values:
29264
29265 @table @code
29266 @item "true"
29267 The variable object's current value is valid.
29268
29269 @item "false"
29270 The variable object does not currently hold a valid value but it may
29271 hold one in the future if its associated expression comes back into
29272 scope.
29273
29274 @item "invalid"
29275 The variable object no longer holds a valid value.
29276 This can occur when the executable file being debugged has changed,
29277 either through recompilation or by using the @value{GDBN} @code{file}
29278 command. The front end should normally choose to delete these variable
29279 objects.
29280 @end table
29281
29282 In the future new values may be added to this list so the front should
29283 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
29284
29285 @item type_changed
29286 This is only present if the varobj is still valid. If the type
29287 changed, then this will be the string @samp{true}; otherwise it will
29288 be @samp{false}.
29289
29290 @item new_type
29291 If the varobj's type changed, then this field will be present and will
29292 hold the new type.
29293
29294 @item new_num_children
29295 For a dynamic varobj, if the number of children changed, or if the
29296 type changed, this will be the new number of children.
29297
29298 The @samp{numchild} field in other varobj responses is generally not
29299 valid for a dynamic varobj -- it will show the number of children that
29300 @value{GDBN} knows about, but because dynamic varobjs lazily
29301 instantiate their children, this will not reflect the number of
29302 children which may be available.
29303
29304 The @samp{new_num_children} attribute only reports changes to the
29305 number of children known by @value{GDBN}. This is the only way to
29306 detect whether an update has removed children (which necessarily can
29307 only happen at the end of the update range).
29308
29309 @item displayhint
29310 The display hint, if any.
29311
29312 @item has_more
29313 This is an integer value, which will be 1 if there are more children
29314 available outside the varobj's update range.
29315
29316 @item dynamic
29317 This attribute will be present and have the value @samp{1} if the
29318 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
29319 then this attribute will not be present.
29320
29321 @item new_children
29322 If new children were added to a dynamic varobj within the selected
29323 update range (as set by @code{-var-set-update-range}), then they will
29324 be listed in this attribute.
29325 @end table
29326
29327 @subsubheading Example
29328
29329 @smallexample
29330 (gdb)
29331 -var-assign var1 3
29332 ^done,value="3"
29333 (gdb)
29334 -var-update --all-values var1
29335 ^done,changelist=[@{name="var1",value="3",in_scope="true",
29336 type_changed="false"@}]
29337 (gdb)
29338 @end smallexample
29339
29340 @subheading The @code{-var-set-frozen} Command
29341 @findex -var-set-frozen
29342 @anchor{-var-set-frozen}
29343
29344 @subsubheading Synopsis
29345
29346 @smallexample
29347 -var-set-frozen @var{name} @var{flag}
29348 @end smallexample
29349
29350 Set the frozenness flag on the variable object @var{name}. The
29351 @var{flag} parameter should be either @samp{1} to make the variable
29352 frozen or @samp{0} to make it unfrozen. If a variable object is
29353 frozen, then neither itself, nor any of its children, are
29354 implicitly updated by @code{-var-update} of
29355 a parent variable or by @code{-var-update *}. Only
29356 @code{-var-update} of the variable itself will update its value and
29357 values of its children. After a variable object is unfrozen, it is
29358 implicitly updated by all subsequent @code{-var-update} operations.
29359 Unfreezing a variable does not update it, only subsequent
29360 @code{-var-update} does.
29361
29362 @subsubheading Example
29363
29364 @smallexample
29365 (gdb)
29366 -var-set-frozen V 1
29367 ^done
29368 (gdb)
29369 @end smallexample
29370
29371 @subheading The @code{-var-set-update-range} command
29372 @findex -var-set-update-range
29373 @anchor{-var-set-update-range}
29374
29375 @subsubheading Synopsis
29376
29377 @smallexample
29378 -var-set-update-range @var{name} @var{from} @var{to}
29379 @end smallexample
29380
29381 Set the range of children to be returned by future invocations of
29382 @code{-var-update}.
29383
29384 @var{from} and @var{to} indicate the range of children to report. If
29385 @var{from} or @var{to} is less than zero, the range is reset and all
29386 children will be reported. Otherwise, children starting at @var{from}
29387 (zero-based) and up to and excluding @var{to} will be reported.
29388
29389 @subsubheading Example
29390
29391 @smallexample
29392 (gdb)
29393 -var-set-update-range V 1 2
29394 ^done
29395 @end smallexample
29396
29397 @subheading The @code{-var-set-visualizer} command
29398 @findex -var-set-visualizer
29399 @anchor{-var-set-visualizer}
29400
29401 @subsubheading Synopsis
29402
29403 @smallexample
29404 -var-set-visualizer @var{name} @var{visualizer}
29405 @end smallexample
29406
29407 Set a visualizer for the variable object @var{name}.
29408
29409 @var{visualizer} is the visualizer to use. The special value
29410 @samp{None} means to disable any visualizer in use.
29411
29412 If not @samp{None}, @var{visualizer} must be a Python expression.
29413 This expression must evaluate to a callable object which accepts a
29414 single argument. @value{GDBN} will call this object with the value of
29415 the varobj @var{name} as an argument (this is done so that the same
29416 Python pretty-printing code can be used for both the CLI and MI).
29417 When called, this object must return an object which conforms to the
29418 pretty-printing interface (@pxref{Pretty Printing API}).
29419
29420 The pre-defined function @code{gdb.default_visualizer} may be used to
29421 select a visualizer by following the built-in process
29422 (@pxref{Selecting Pretty-Printers}). This is done automatically when
29423 a varobj is created, and so ordinarily is not needed.
29424
29425 This feature is only available if Python support is enabled. The MI
29426 command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
29427 can be used to check this.
29428
29429 @subsubheading Example
29430
29431 Resetting the visualizer:
29432
29433 @smallexample
29434 (gdb)
29435 -var-set-visualizer V None
29436 ^done
29437 @end smallexample
29438
29439 Reselecting the default (type-based) visualizer:
29440
29441 @smallexample
29442 (gdb)
29443 -var-set-visualizer V gdb.default_visualizer
29444 ^done
29445 @end smallexample
29446
29447 Suppose @code{SomeClass} is a visualizer class. A lambda expression
29448 can be used to instantiate this class for a varobj:
29449
29450 @smallexample
29451 (gdb)
29452 -var-set-visualizer V "lambda val: SomeClass()"
29453 ^done
29454 @end smallexample
29455
29456 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29457 @node GDB/MI Data Manipulation
29458 @section @sc{gdb/mi} Data Manipulation
29459
29460 @cindex data manipulation, in @sc{gdb/mi}
29461 @cindex @sc{gdb/mi}, data manipulation
29462 This section describes the @sc{gdb/mi} commands that manipulate data:
29463 examine memory and registers, evaluate expressions, etc.
29464
29465 @c REMOVED FROM THE INTERFACE.
29466 @c @subheading -data-assign
29467 @c Change the value of a program variable. Plenty of side effects.
29468 @c @subsubheading GDB Command
29469 @c set variable
29470 @c @subsubheading Example
29471 @c N.A.
29472
29473 @subheading The @code{-data-disassemble} Command
29474 @findex -data-disassemble
29475
29476 @subsubheading Synopsis
29477
29478 @smallexample
29479 -data-disassemble
29480 [ -s @var{start-addr} -e @var{end-addr} ]
29481 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
29482 -- @var{mode}
29483 @end smallexample
29484
29485 @noindent
29486 Where:
29487
29488 @table @samp
29489 @item @var{start-addr}
29490 is the beginning address (or @code{$pc})
29491 @item @var{end-addr}
29492 is the end address
29493 @item @var{filename}
29494 is the name of the file to disassemble
29495 @item @var{linenum}
29496 is the line number to disassemble around
29497 @item @var{lines}
29498 is the number of disassembly lines to be produced. If it is -1,
29499 the whole function will be disassembled, in case no @var{end-addr} is
29500 specified. If @var{end-addr} is specified as a non-zero value, and
29501 @var{lines} is lower than the number of disassembly lines between
29502 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
29503 displayed; if @var{lines} is higher than the number of lines between
29504 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
29505 are displayed.
29506 @item @var{mode}
29507 is either 0 (meaning only disassembly), 1 (meaning mixed source and
29508 disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
29509 mixed source and disassembly with raw opcodes).
29510 @end table
29511
29512 @subsubheading Result
29513
29514 The output for each instruction is composed of four fields:
29515
29516 @itemize @bullet
29517 @item Address
29518 @item Func-name
29519 @item Offset
29520 @item Instruction
29521 @end itemize
29522
29523 Note that whatever included in the instruction field, is not manipulated
29524 directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
29525
29526 @subsubheading @value{GDBN} Command
29527
29528 There's no direct mapping from this command to the CLI.
29529
29530 @subsubheading Example
29531
29532 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
29533
29534 @smallexample
29535 (gdb)
29536 -data-disassemble -s $pc -e "$pc + 20" -- 0
29537 ^done,
29538 asm_insns=[
29539 @{address="0x000107c0",func-name="main",offset="4",
29540 inst="mov 2, %o0"@},
29541 @{address="0x000107c4",func-name="main",offset="8",
29542 inst="sethi %hi(0x11800), %o2"@},
29543 @{address="0x000107c8",func-name="main",offset="12",
29544 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
29545 @{address="0x000107cc",func-name="main",offset="16",
29546 inst="sethi %hi(0x11800), %o2"@},
29547 @{address="0x000107d0",func-name="main",offset="20",
29548 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
29549 (gdb)
29550 @end smallexample
29551
29552 Disassemble the whole @code{main} function. Line 32 is part of
29553 @code{main}.
29554
29555 @smallexample
29556 -data-disassemble -f basics.c -l 32 -- 0
29557 ^done,asm_insns=[
29558 @{address="0x000107bc",func-name="main",offset="0",
29559 inst="save %sp, -112, %sp"@},
29560 @{address="0x000107c0",func-name="main",offset="4",
29561 inst="mov 2, %o0"@},
29562 @{address="0x000107c4",func-name="main",offset="8",
29563 inst="sethi %hi(0x11800), %o2"@},
29564 [@dots{}]
29565 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
29566 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
29567 (gdb)
29568 @end smallexample
29569
29570 Disassemble 3 instructions from the start of @code{main}:
29571
29572 @smallexample
29573 (gdb)
29574 -data-disassemble -f basics.c -l 32 -n 3 -- 0
29575 ^done,asm_insns=[
29576 @{address="0x000107bc",func-name="main",offset="0",
29577 inst="save %sp, -112, %sp"@},
29578 @{address="0x000107c0",func-name="main",offset="4",
29579 inst="mov 2, %o0"@},
29580 @{address="0x000107c4",func-name="main",offset="8",
29581 inst="sethi %hi(0x11800), %o2"@}]
29582 (gdb)
29583 @end smallexample
29584
29585 Disassemble 3 instructions from the start of @code{main} in mixed mode:
29586
29587 @smallexample
29588 (gdb)
29589 -data-disassemble -f basics.c -l 32 -n 3 -- 1
29590 ^done,asm_insns=[
29591 src_and_asm_line=@{line="31",
29592 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
29593 testsuite/gdb.mi/basics.c",line_asm_insn=[
29594 @{address="0x000107bc",func-name="main",offset="0",
29595 inst="save %sp, -112, %sp"@}]@},
29596 src_and_asm_line=@{line="32",
29597 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
29598 testsuite/gdb.mi/basics.c",line_asm_insn=[
29599 @{address="0x000107c0",func-name="main",offset="4",
29600 inst="mov 2, %o0"@},
29601 @{address="0x000107c4",func-name="main",offset="8",
29602 inst="sethi %hi(0x11800), %o2"@}]@}]
29603 (gdb)
29604 @end smallexample
29605
29606
29607 @subheading The @code{-data-evaluate-expression} Command
29608 @findex -data-evaluate-expression
29609
29610 @subsubheading Synopsis
29611
29612 @smallexample
29613 -data-evaluate-expression @var{expr}
29614 @end smallexample
29615
29616 Evaluate @var{expr} as an expression. The expression could contain an
29617 inferior function call. The function call will execute synchronously.
29618 If the expression contains spaces, it must be enclosed in double quotes.
29619
29620 @subsubheading @value{GDBN} Command
29621
29622 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
29623 @samp{call}. In @code{gdbtk} only, there's a corresponding
29624 @samp{gdb_eval} command.
29625
29626 @subsubheading Example
29627
29628 In the following example, the numbers that precede the commands are the
29629 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
29630 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
29631 output.
29632
29633 @smallexample
29634 211-data-evaluate-expression A
29635 211^done,value="1"
29636 (gdb)
29637 311-data-evaluate-expression &A
29638 311^done,value="0xefffeb7c"
29639 (gdb)
29640 411-data-evaluate-expression A+3
29641 411^done,value="4"
29642 (gdb)
29643 511-data-evaluate-expression "A + 3"
29644 511^done,value="4"
29645 (gdb)
29646 @end smallexample
29647
29648
29649 @subheading The @code{-data-list-changed-registers} Command
29650 @findex -data-list-changed-registers
29651
29652 @subsubheading Synopsis
29653
29654 @smallexample
29655 -data-list-changed-registers
29656 @end smallexample
29657
29658 Display a list of the registers that have changed.
29659
29660 @subsubheading @value{GDBN} Command
29661
29662 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
29663 has the corresponding command @samp{gdb_changed_register_list}.
29664
29665 @subsubheading Example
29666
29667 On a PPC MBX board:
29668
29669 @smallexample
29670 (gdb)
29671 -exec-continue
29672 ^running
29673
29674 (gdb)
29675 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
29676 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
29677 line="5"@}
29678 (gdb)
29679 -data-list-changed-registers
29680 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
29681 "10","11","13","14","15","16","17","18","19","20","21","22","23",
29682 "24","25","26","27","28","30","31","64","65","66","67","69"]
29683 (gdb)
29684 @end smallexample
29685
29686
29687 @subheading The @code{-data-list-register-names} Command
29688 @findex -data-list-register-names
29689
29690 @subsubheading Synopsis
29691
29692 @smallexample
29693 -data-list-register-names [ ( @var{regno} )+ ]
29694 @end smallexample
29695
29696 Show a list of register names for the current target. If no arguments
29697 are given, it shows a list of the names of all the registers. If
29698 integer numbers are given as arguments, it will print a list of the
29699 names of the registers corresponding to the arguments. To ensure
29700 consistency between a register name and its number, the output list may
29701 include empty register names.
29702
29703 @subsubheading @value{GDBN} Command
29704
29705 @value{GDBN} does not have a command which corresponds to
29706 @samp{-data-list-register-names}. In @code{gdbtk} there is a
29707 corresponding command @samp{gdb_regnames}.
29708
29709 @subsubheading Example
29710
29711 For the PPC MBX board:
29712 @smallexample
29713 (gdb)
29714 -data-list-register-names
29715 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
29716 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
29717 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
29718 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
29719 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
29720 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
29721 "", "pc","ps","cr","lr","ctr","xer"]
29722 (gdb)
29723 -data-list-register-names 1 2 3
29724 ^done,register-names=["r1","r2","r3"]
29725 (gdb)
29726 @end smallexample
29727
29728 @subheading The @code{-data-list-register-values} Command
29729 @findex -data-list-register-values
29730
29731 @subsubheading Synopsis
29732
29733 @smallexample
29734 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
29735 @end smallexample
29736
29737 Display the registers' contents. @var{fmt} is the format according to
29738 which the registers' contents are to be returned, followed by an optional
29739 list of numbers specifying the registers to display. A missing list of
29740 numbers indicates that the contents of all the registers must be returned.
29741
29742 Allowed formats for @var{fmt} are:
29743
29744 @table @code
29745 @item x
29746 Hexadecimal
29747 @item o
29748 Octal
29749 @item t
29750 Binary
29751 @item d
29752 Decimal
29753 @item r
29754 Raw
29755 @item N
29756 Natural
29757 @end table
29758
29759 @subsubheading @value{GDBN} Command
29760
29761 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
29762 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
29763
29764 @subsubheading Example
29765
29766 For a PPC MBX board (note: line breaks are for readability only, they
29767 don't appear in the actual output):
29768
29769 @smallexample
29770 (gdb)
29771 -data-list-register-values r 64 65
29772 ^done,register-values=[@{number="64",value="0xfe00a300"@},
29773 @{number="65",value="0x00029002"@}]
29774 (gdb)
29775 -data-list-register-values x
29776 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
29777 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
29778 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
29779 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
29780 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
29781 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
29782 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
29783 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
29784 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
29785 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
29786 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
29787 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
29788 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
29789 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
29790 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
29791 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
29792 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
29793 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
29794 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
29795 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
29796 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
29797 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
29798 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
29799 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
29800 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
29801 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
29802 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
29803 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
29804 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
29805 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
29806 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
29807 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
29808 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
29809 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
29810 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
29811 @{number="69",value="0x20002b03"@}]
29812 (gdb)
29813 @end smallexample
29814
29815
29816 @subheading The @code{-data-read-memory} Command
29817 @findex -data-read-memory
29818
29819 This command is deprecated, use @code{-data-read-memory-bytes} instead.
29820
29821 @subsubheading Synopsis
29822
29823 @smallexample
29824 -data-read-memory [ -o @var{byte-offset} ]
29825 @var{address} @var{word-format} @var{word-size}
29826 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
29827 @end smallexample
29828
29829 @noindent
29830 where:
29831
29832 @table @samp
29833 @item @var{address}
29834 An expression specifying the address of the first memory word to be
29835 read. Complex expressions containing embedded white space should be
29836 quoted using the C convention.
29837
29838 @item @var{word-format}
29839 The format to be used to print the memory words. The notation is the
29840 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
29841 ,Output Formats}).
29842
29843 @item @var{word-size}
29844 The size of each memory word in bytes.
29845
29846 @item @var{nr-rows}
29847 The number of rows in the output table.
29848
29849 @item @var{nr-cols}
29850 The number of columns in the output table.
29851
29852 @item @var{aschar}
29853 If present, indicates that each row should include an @sc{ascii} dump. The
29854 value of @var{aschar} is used as a padding character when a byte is not a
29855 member of the printable @sc{ascii} character set (printable @sc{ascii}
29856 characters are those whose code is between 32 and 126, inclusively).
29857
29858 @item @var{byte-offset}
29859 An offset to add to the @var{address} before fetching memory.
29860 @end table
29861
29862 This command displays memory contents as a table of @var{nr-rows} by
29863 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
29864 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
29865 (returned as @samp{total-bytes}). Should less than the requested number
29866 of bytes be returned by the target, the missing words are identified
29867 using @samp{N/A}. The number of bytes read from the target is returned
29868 in @samp{nr-bytes} and the starting address used to read memory in
29869 @samp{addr}.
29870
29871 The address of the next/previous row or page is available in
29872 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
29873 @samp{prev-page}.
29874
29875 @subsubheading @value{GDBN} Command
29876
29877 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
29878 @samp{gdb_get_mem} memory read command.
29879
29880 @subsubheading Example
29881
29882 Read six bytes of memory starting at @code{bytes+6} but then offset by
29883 @code{-6} bytes. Format as three rows of two columns. One byte per
29884 word. Display each word in hex.
29885
29886 @smallexample
29887 (gdb)
29888 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
29889 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
29890 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
29891 prev-page="0x0000138a",memory=[
29892 @{addr="0x00001390",data=["0x00","0x01"]@},
29893 @{addr="0x00001392",data=["0x02","0x03"]@},
29894 @{addr="0x00001394",data=["0x04","0x05"]@}]
29895 (gdb)
29896 @end smallexample
29897
29898 Read two bytes of memory starting at address @code{shorts + 64} and
29899 display as a single word formatted in decimal.
29900
29901 @smallexample
29902 (gdb)
29903 5-data-read-memory shorts+64 d 2 1 1
29904 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
29905 next-row="0x00001512",prev-row="0x0000150e",
29906 next-page="0x00001512",prev-page="0x0000150e",memory=[
29907 @{addr="0x00001510",data=["128"]@}]
29908 (gdb)
29909 @end smallexample
29910
29911 Read thirty two bytes of memory starting at @code{bytes+16} and format
29912 as eight rows of four columns. Include a string encoding with @samp{x}
29913 used as the non-printable character.
29914
29915 @smallexample
29916 (gdb)
29917 4-data-read-memory bytes+16 x 1 8 4 x
29918 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
29919 next-row="0x000013c0",prev-row="0x0000139c",
29920 next-page="0x000013c0",prev-page="0x00001380",memory=[
29921 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
29922 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
29923 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
29924 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
29925 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
29926 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
29927 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
29928 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
29929 (gdb)
29930 @end smallexample
29931
29932 @subheading The @code{-data-read-memory-bytes} Command
29933 @findex -data-read-memory-bytes
29934
29935 @subsubheading Synopsis
29936
29937 @smallexample
29938 -data-read-memory-bytes [ -o @var{byte-offset} ]
29939 @var{address} @var{count}
29940 @end smallexample
29941
29942 @noindent
29943 where:
29944
29945 @table @samp
29946 @item @var{address}
29947 An expression specifying the address of the first memory word to be
29948 read. Complex expressions containing embedded white space should be
29949 quoted using the C convention.
29950
29951 @item @var{count}
29952 The number of bytes to read. This should be an integer literal.
29953
29954 @item @var{byte-offset}
29955 The offsets in bytes relative to @var{address} at which to start
29956 reading. This should be an integer literal. This option is provided
29957 so that a frontend is not required to first evaluate address and then
29958 perform address arithmetics itself.
29959
29960 @end table
29961
29962 This command attempts to read all accessible memory regions in the
29963 specified range. First, all regions marked as unreadable in the memory
29964 map (if one is defined) will be skipped. @xref{Memory Region
29965 Attributes}. Second, @value{GDBN} will attempt to read the remaining
29966 regions. For each one, if reading full region results in an errors,
29967 @value{GDBN} will try to read a subset of the region.
29968
29969 In general, every single byte in the region may be readable or not,
29970 and the only way to read every readable byte is to try a read at
29971 every address, which is not practical. Therefore, @value{GDBN} will
29972 attempt to read all accessible bytes at either beginning or the end
29973 of the region, using a binary division scheme. This heuristic works
29974 well for reading accross a memory map boundary. Note that if a region
29975 has a readable range that is neither at the beginning or the end,
29976 @value{GDBN} will not read it.
29977
29978 The result record (@pxref{GDB/MI Result Records}) that is output of
29979 the command includes a field named @samp{memory} whose content is a
29980 list of tuples. Each tuple represent a successfully read memory block
29981 and has the following fields:
29982
29983 @table @code
29984 @item begin
29985 The start address of the memory block, as hexadecimal literal.
29986
29987 @item end
29988 The end address of the memory block, as hexadecimal literal.
29989
29990 @item offset
29991 The offset of the memory block, as hexadecimal literal, relative to
29992 the start address passed to @code{-data-read-memory-bytes}.
29993
29994 @item contents
29995 The contents of the memory block, in hex.
29996
29997 @end table
29998
29999
30000
30001 @subsubheading @value{GDBN} Command
30002
30003 The corresponding @value{GDBN} command is @samp{x}.
30004
30005 @subsubheading Example
30006
30007 @smallexample
30008 (gdb)
30009 -data-read-memory-bytes &a 10
30010 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
30011 end="0xbffff15e",
30012 contents="01000000020000000300"@}]
30013 (gdb)
30014 @end smallexample
30015
30016
30017 @subheading The @code{-data-write-memory-bytes} Command
30018 @findex -data-write-memory-bytes
30019
30020 @subsubheading Synopsis
30021
30022 @smallexample
30023 -data-write-memory-bytes @var{address} @var{contents}
30024 @end smallexample
30025
30026 @noindent
30027 where:
30028
30029 @table @samp
30030 @item @var{address}
30031 An expression specifying the address of the first memory word to be
30032 read. Complex expressions containing embedded white space should be
30033 quoted using the C convention.
30034
30035 @item @var{contents}
30036 The hex-encoded bytes to write.
30037
30038 @end table
30039
30040 @subsubheading @value{GDBN} Command
30041
30042 There's no corresponding @value{GDBN} command.
30043
30044 @subsubheading Example
30045
30046 @smallexample
30047 (gdb)
30048 -data-write-memory-bytes &a "aabbccdd"
30049 ^done
30050 (gdb)
30051 @end smallexample
30052
30053
30054 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30055 @node GDB/MI Tracepoint Commands
30056 @section @sc{gdb/mi} Tracepoint Commands
30057
30058 The commands defined in this section implement MI support for
30059 tracepoints. For detailed introduction, see @ref{Tracepoints}.
30060
30061 @subheading The @code{-trace-find} Command
30062 @findex -trace-find
30063
30064 @subsubheading Synopsis
30065
30066 @smallexample
30067 -trace-find @var{mode} [@var{parameters}@dots{}]
30068 @end smallexample
30069
30070 Find a trace frame using criteria defined by @var{mode} and
30071 @var{parameters}. The following table lists permissible
30072 modes and their parameters. For details of operation, see @ref{tfind}.
30073
30074 @table @samp
30075
30076 @item none
30077 No parameters are required. Stops examining trace frames.
30078
30079 @item frame-number
30080 An integer is required as parameter. Selects tracepoint frame with
30081 that index.
30082
30083 @item tracepoint-number
30084 An integer is required as parameter. Finds next
30085 trace frame that corresponds to tracepoint with the specified number.
30086
30087 @item pc
30088 An address is required as parameter. Finds
30089 next trace frame that corresponds to any tracepoint at the specified
30090 address.
30091
30092 @item pc-inside-range
30093 Two addresses are required as parameters. Finds next trace
30094 frame that corresponds to a tracepoint at an address inside the
30095 specified range. Both bounds are considered to be inside the range.
30096
30097 @item pc-outside-range
30098 Two addresses are required as parameters. Finds
30099 next trace frame that corresponds to a tracepoint at an address outside
30100 the specified range. Both bounds are considered to be inside the range.
30101
30102 @item line
30103 Line specification is required as parameter. @xref{Specify Location}.
30104 Finds next trace frame that corresponds to a tracepoint at
30105 the specified location.
30106
30107 @end table
30108
30109 If @samp{none} was passed as @var{mode}, the response does not
30110 have fields. Otherwise, the response may have the following fields:
30111
30112 @table @samp
30113 @item found
30114 This field has either @samp{0} or @samp{1} as the value, depending
30115 on whether a matching tracepoint was found.
30116
30117 @item traceframe
30118 The index of the found traceframe. This field is present iff
30119 the @samp{found} field has value of @samp{1}.
30120
30121 @item tracepoint
30122 The index of the found tracepoint. This field is present iff
30123 the @samp{found} field has value of @samp{1}.
30124
30125 @item frame
30126 The information about the frame corresponding to the found trace
30127 frame. This field is present only if a trace frame was found.
30128 @xref{GDB/MI Frame Information}, for description of this field.
30129
30130 @end table
30131
30132 @subsubheading @value{GDBN} Command
30133
30134 The corresponding @value{GDBN} command is @samp{tfind}.
30135
30136 @subheading -trace-define-variable
30137 @findex -trace-define-variable
30138
30139 @subsubheading Synopsis
30140
30141 @smallexample
30142 -trace-define-variable @var{name} [ @var{value} ]
30143 @end smallexample
30144
30145 Create trace variable @var{name} if it does not exist. If
30146 @var{value} is specified, sets the initial value of the specified
30147 trace variable to that value. Note that the @var{name} should start
30148 with the @samp{$} character.
30149
30150 @subsubheading @value{GDBN} Command
30151
30152 The corresponding @value{GDBN} command is @samp{tvariable}.
30153
30154 @subheading -trace-list-variables
30155 @findex -trace-list-variables
30156
30157 @subsubheading Synopsis
30158
30159 @smallexample
30160 -trace-list-variables
30161 @end smallexample
30162
30163 Return a table of all defined trace variables. Each element of the
30164 table has the following fields:
30165
30166 @table @samp
30167 @item name
30168 The name of the trace variable. This field is always present.
30169
30170 @item initial
30171 The initial value. This is a 64-bit signed integer. This
30172 field is always present.
30173
30174 @item current
30175 The value the trace variable has at the moment. This is a 64-bit
30176 signed integer. This field is absent iff current value is
30177 not defined, for example if the trace was never run, or is
30178 presently running.
30179
30180 @end table
30181
30182 @subsubheading @value{GDBN} Command
30183
30184 The corresponding @value{GDBN} command is @samp{tvariables}.
30185
30186 @subsubheading Example
30187
30188 @smallexample
30189 (gdb)
30190 -trace-list-variables
30191 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
30192 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
30193 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
30194 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
30195 body=[variable=@{name="$trace_timestamp",initial="0"@}
30196 variable=@{name="$foo",initial="10",current="15"@}]@}
30197 (gdb)
30198 @end smallexample
30199
30200 @subheading -trace-save
30201 @findex -trace-save
30202
30203 @subsubheading Synopsis
30204
30205 @smallexample
30206 -trace-save [-r ] @var{filename}
30207 @end smallexample
30208
30209 Saves the collected trace data to @var{filename}. Without the
30210 @samp{-r} option, the data is downloaded from the target and saved
30211 in a local file. With the @samp{-r} option the target is asked
30212 to perform the save.
30213
30214 @subsubheading @value{GDBN} Command
30215
30216 The corresponding @value{GDBN} command is @samp{tsave}.
30217
30218
30219 @subheading -trace-start
30220 @findex -trace-start
30221
30222 @subsubheading Synopsis
30223
30224 @smallexample
30225 -trace-start
30226 @end smallexample
30227
30228 Starts a tracing experiments. The result of this command does not
30229 have any fields.
30230
30231 @subsubheading @value{GDBN} Command
30232
30233 The corresponding @value{GDBN} command is @samp{tstart}.
30234
30235 @subheading -trace-status
30236 @findex -trace-status
30237
30238 @subsubheading Synopsis
30239
30240 @smallexample
30241 -trace-status
30242 @end smallexample
30243
30244 Obtains the status of a tracing experiment. The result may include
30245 the following fields:
30246
30247 @table @samp
30248
30249 @item supported
30250 May have a value of either @samp{0}, when no tracing operations are
30251 supported, @samp{1}, when all tracing operations are supported, or
30252 @samp{file} when examining trace file. In the latter case, examining
30253 of trace frame is possible but new tracing experiement cannot be
30254 started. This field is always present.
30255
30256 @item running
30257 May have a value of either @samp{0} or @samp{1} depending on whether
30258 tracing experiement is in progress on target. This field is present
30259 if @samp{supported} field is not @samp{0}.
30260
30261 @item stop-reason
30262 Report the reason why the tracing was stopped last time. This field
30263 may be absent iff tracing was never stopped on target yet. The
30264 value of @samp{request} means the tracing was stopped as result of
30265 the @code{-trace-stop} command. The value of @samp{overflow} means
30266 the tracing buffer is full. The value of @samp{disconnection} means
30267 tracing was automatically stopped when @value{GDBN} has disconnected.
30268 The value of @samp{passcount} means tracing was stopped when a
30269 tracepoint was passed a maximal number of times for that tracepoint.
30270 This field is present if @samp{supported} field is not @samp{0}.
30271
30272 @item stopping-tracepoint
30273 The number of tracepoint whose passcount as exceeded. This field is
30274 present iff the @samp{stop-reason} field has the value of
30275 @samp{passcount}.
30276
30277 @item frames
30278 @itemx frames-created
30279 The @samp{frames} field is a count of the total number of trace frames
30280 in the trace buffer, while @samp{frames-created} is the total created
30281 during the run, including ones that were discarded, such as when a
30282 circular trace buffer filled up. Both fields are optional.
30283
30284 @item buffer-size
30285 @itemx buffer-free
30286 These fields tell the current size of the tracing buffer and the
30287 remaining space. These fields are optional.
30288
30289 @item circular
30290 The value of the circular trace buffer flag. @code{1} means that the
30291 trace buffer is circular and old trace frames will be discarded if
30292 necessary to make room, @code{0} means that the trace buffer is linear
30293 and may fill up.
30294
30295 @item disconnected
30296 The value of the disconnected tracing flag. @code{1} means that
30297 tracing will continue after @value{GDBN} disconnects, @code{0} means
30298 that the trace run will stop.
30299
30300 @end table
30301
30302 @subsubheading @value{GDBN} Command
30303
30304 The corresponding @value{GDBN} command is @samp{tstatus}.
30305
30306 @subheading -trace-stop
30307 @findex -trace-stop
30308
30309 @subsubheading Synopsis
30310
30311 @smallexample
30312 -trace-stop
30313 @end smallexample
30314
30315 Stops a tracing experiment. The result of this command has the same
30316 fields as @code{-trace-status}, except that the @samp{supported} and
30317 @samp{running} fields are not output.
30318
30319 @subsubheading @value{GDBN} Command
30320
30321 The corresponding @value{GDBN} command is @samp{tstop}.
30322
30323
30324 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30325 @node GDB/MI Symbol Query
30326 @section @sc{gdb/mi} Symbol Query Commands
30327
30328
30329 @ignore
30330 @subheading The @code{-symbol-info-address} Command
30331 @findex -symbol-info-address
30332
30333 @subsubheading Synopsis
30334
30335 @smallexample
30336 -symbol-info-address @var{symbol}
30337 @end smallexample
30338
30339 Describe where @var{symbol} is stored.
30340
30341 @subsubheading @value{GDBN} Command
30342
30343 The corresponding @value{GDBN} command is @samp{info address}.
30344
30345 @subsubheading Example
30346 N.A.
30347
30348
30349 @subheading The @code{-symbol-info-file} Command
30350 @findex -symbol-info-file
30351
30352 @subsubheading Synopsis
30353
30354 @smallexample
30355 -symbol-info-file
30356 @end smallexample
30357
30358 Show the file for the symbol.
30359
30360 @subsubheading @value{GDBN} Command
30361
30362 There's no equivalent @value{GDBN} command. @code{gdbtk} has
30363 @samp{gdb_find_file}.
30364
30365 @subsubheading Example
30366 N.A.
30367
30368
30369 @subheading The @code{-symbol-info-function} Command
30370 @findex -symbol-info-function
30371
30372 @subsubheading Synopsis
30373
30374 @smallexample
30375 -symbol-info-function
30376 @end smallexample
30377
30378 Show which function the symbol lives in.
30379
30380 @subsubheading @value{GDBN} Command
30381
30382 @samp{gdb_get_function} in @code{gdbtk}.
30383
30384 @subsubheading Example
30385 N.A.
30386
30387
30388 @subheading The @code{-symbol-info-line} Command
30389 @findex -symbol-info-line
30390
30391 @subsubheading Synopsis
30392
30393 @smallexample
30394 -symbol-info-line
30395 @end smallexample
30396
30397 Show the core addresses of the code for a source line.
30398
30399 @subsubheading @value{GDBN} Command
30400
30401 The corresponding @value{GDBN} command is @samp{info line}.
30402 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
30403
30404 @subsubheading Example
30405 N.A.
30406
30407
30408 @subheading The @code{-symbol-info-symbol} Command
30409 @findex -symbol-info-symbol
30410
30411 @subsubheading Synopsis
30412
30413 @smallexample
30414 -symbol-info-symbol @var{addr}
30415 @end smallexample
30416
30417 Describe what symbol is at location @var{addr}.
30418
30419 @subsubheading @value{GDBN} Command
30420
30421 The corresponding @value{GDBN} command is @samp{info symbol}.
30422
30423 @subsubheading Example
30424 N.A.
30425
30426
30427 @subheading The @code{-symbol-list-functions} Command
30428 @findex -symbol-list-functions
30429
30430 @subsubheading Synopsis
30431
30432 @smallexample
30433 -symbol-list-functions
30434 @end smallexample
30435
30436 List the functions in the executable.
30437
30438 @subsubheading @value{GDBN} Command
30439
30440 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
30441 @samp{gdb_search} in @code{gdbtk}.
30442
30443 @subsubheading Example
30444 N.A.
30445 @end ignore
30446
30447
30448 @subheading The @code{-symbol-list-lines} Command
30449 @findex -symbol-list-lines
30450
30451 @subsubheading Synopsis
30452
30453 @smallexample
30454 -symbol-list-lines @var{filename}
30455 @end smallexample
30456
30457 Print the list of lines that contain code and their associated program
30458 addresses for the given source filename. The entries are sorted in
30459 ascending PC order.
30460
30461 @subsubheading @value{GDBN} Command
30462
30463 There is no corresponding @value{GDBN} command.
30464
30465 @subsubheading Example
30466 @smallexample
30467 (gdb)
30468 -symbol-list-lines basics.c
30469 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
30470 (gdb)
30471 @end smallexample
30472
30473
30474 @ignore
30475 @subheading The @code{-symbol-list-types} Command
30476 @findex -symbol-list-types
30477
30478 @subsubheading Synopsis
30479
30480 @smallexample
30481 -symbol-list-types
30482 @end smallexample
30483
30484 List all the type names.
30485
30486 @subsubheading @value{GDBN} Command
30487
30488 The corresponding commands are @samp{info types} in @value{GDBN},
30489 @samp{gdb_search} in @code{gdbtk}.
30490
30491 @subsubheading Example
30492 N.A.
30493
30494
30495 @subheading The @code{-symbol-list-variables} Command
30496 @findex -symbol-list-variables
30497
30498 @subsubheading Synopsis
30499
30500 @smallexample
30501 -symbol-list-variables
30502 @end smallexample
30503
30504 List all the global and static variable names.
30505
30506 @subsubheading @value{GDBN} Command
30507
30508 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
30509
30510 @subsubheading Example
30511 N.A.
30512
30513
30514 @subheading The @code{-symbol-locate} Command
30515 @findex -symbol-locate
30516
30517 @subsubheading Synopsis
30518
30519 @smallexample
30520 -symbol-locate
30521 @end smallexample
30522
30523 @subsubheading @value{GDBN} Command
30524
30525 @samp{gdb_loc} in @code{gdbtk}.
30526
30527 @subsubheading Example
30528 N.A.
30529
30530
30531 @subheading The @code{-symbol-type} Command
30532 @findex -symbol-type
30533
30534 @subsubheading Synopsis
30535
30536 @smallexample
30537 -symbol-type @var{variable}
30538 @end smallexample
30539
30540 Show type of @var{variable}.
30541
30542 @subsubheading @value{GDBN} Command
30543
30544 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
30545 @samp{gdb_obj_variable}.
30546
30547 @subsubheading Example
30548 N.A.
30549 @end ignore
30550
30551
30552 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30553 @node GDB/MI File Commands
30554 @section @sc{gdb/mi} File Commands
30555
30556 This section describes the GDB/MI commands to specify executable file names
30557 and to read in and obtain symbol table information.
30558
30559 @subheading The @code{-file-exec-and-symbols} Command
30560 @findex -file-exec-and-symbols
30561
30562 @subsubheading Synopsis
30563
30564 @smallexample
30565 -file-exec-and-symbols @var{file}
30566 @end smallexample
30567
30568 Specify the executable file to be debugged. This file is the one from
30569 which the symbol table is also read. If no file is specified, the
30570 command clears the executable and symbol information. If breakpoints
30571 are set when using this command with no arguments, @value{GDBN} will produce
30572 error messages. Otherwise, no output is produced, except a completion
30573 notification.
30574
30575 @subsubheading @value{GDBN} Command
30576
30577 The corresponding @value{GDBN} command is @samp{file}.
30578
30579 @subsubheading Example
30580
30581 @smallexample
30582 (gdb)
30583 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
30584 ^done
30585 (gdb)
30586 @end smallexample
30587
30588
30589 @subheading The @code{-file-exec-file} Command
30590 @findex -file-exec-file
30591
30592 @subsubheading Synopsis
30593
30594 @smallexample
30595 -file-exec-file @var{file}
30596 @end smallexample
30597
30598 Specify the executable file to be debugged. Unlike
30599 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
30600 from this file. If used without argument, @value{GDBN} clears the information
30601 about the executable file. No output is produced, except a completion
30602 notification.
30603
30604 @subsubheading @value{GDBN} Command
30605
30606 The corresponding @value{GDBN} command is @samp{exec-file}.
30607
30608 @subsubheading Example
30609
30610 @smallexample
30611 (gdb)
30612 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
30613 ^done
30614 (gdb)
30615 @end smallexample
30616
30617
30618 @ignore
30619 @subheading The @code{-file-list-exec-sections} Command
30620 @findex -file-list-exec-sections
30621
30622 @subsubheading Synopsis
30623
30624 @smallexample
30625 -file-list-exec-sections
30626 @end smallexample
30627
30628 List the sections of the current executable file.
30629
30630 @subsubheading @value{GDBN} Command
30631
30632 The @value{GDBN} command @samp{info file} shows, among the rest, the same
30633 information as this command. @code{gdbtk} has a corresponding command
30634 @samp{gdb_load_info}.
30635
30636 @subsubheading Example
30637 N.A.
30638 @end ignore
30639
30640
30641 @subheading The @code{-file-list-exec-source-file} Command
30642 @findex -file-list-exec-source-file
30643
30644 @subsubheading Synopsis
30645
30646 @smallexample
30647 -file-list-exec-source-file
30648 @end smallexample
30649
30650 List the line number, the current source file, and the absolute path
30651 to the current source file for the current executable. The macro
30652 information field has a value of @samp{1} or @samp{0} depending on
30653 whether or not the file includes preprocessor macro information.
30654
30655 @subsubheading @value{GDBN} Command
30656
30657 The @value{GDBN} equivalent is @samp{info source}
30658
30659 @subsubheading Example
30660
30661 @smallexample
30662 (gdb)
30663 123-file-list-exec-source-file
30664 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
30665 (gdb)
30666 @end smallexample
30667
30668
30669 @subheading The @code{-file-list-exec-source-files} Command
30670 @findex -file-list-exec-source-files
30671
30672 @subsubheading Synopsis
30673
30674 @smallexample
30675 -file-list-exec-source-files
30676 @end smallexample
30677
30678 List the source files for the current executable.
30679
30680 It will always output the filename, but only when @value{GDBN} can find
30681 the absolute file name of a source file, will it output the fullname.
30682
30683 @subsubheading @value{GDBN} Command
30684
30685 The @value{GDBN} equivalent is @samp{info sources}.
30686 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
30687
30688 @subsubheading Example
30689 @smallexample
30690 (gdb)
30691 -file-list-exec-source-files
30692 ^done,files=[
30693 @{file=foo.c,fullname=/home/foo.c@},
30694 @{file=/home/bar.c,fullname=/home/bar.c@},
30695 @{file=gdb_could_not_find_fullpath.c@}]
30696 (gdb)
30697 @end smallexample
30698
30699 @ignore
30700 @subheading The @code{-file-list-shared-libraries} Command
30701 @findex -file-list-shared-libraries
30702
30703 @subsubheading Synopsis
30704
30705 @smallexample
30706 -file-list-shared-libraries
30707 @end smallexample
30708
30709 List the shared libraries in the program.
30710
30711 @subsubheading @value{GDBN} Command
30712
30713 The corresponding @value{GDBN} command is @samp{info shared}.
30714
30715 @subsubheading Example
30716 N.A.
30717
30718
30719 @subheading The @code{-file-list-symbol-files} Command
30720 @findex -file-list-symbol-files
30721
30722 @subsubheading Synopsis
30723
30724 @smallexample
30725 -file-list-symbol-files
30726 @end smallexample
30727
30728 List symbol files.
30729
30730 @subsubheading @value{GDBN} Command
30731
30732 The corresponding @value{GDBN} command is @samp{info file} (part of it).
30733
30734 @subsubheading Example
30735 N.A.
30736 @end ignore
30737
30738
30739 @subheading The @code{-file-symbol-file} Command
30740 @findex -file-symbol-file
30741
30742 @subsubheading Synopsis
30743
30744 @smallexample
30745 -file-symbol-file @var{file}
30746 @end smallexample
30747
30748 Read symbol table info from the specified @var{file} argument. When
30749 used without arguments, clears @value{GDBN}'s symbol table info. No output is
30750 produced, except for a completion notification.
30751
30752 @subsubheading @value{GDBN} Command
30753
30754 The corresponding @value{GDBN} command is @samp{symbol-file}.
30755
30756 @subsubheading Example
30757
30758 @smallexample
30759 (gdb)
30760 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
30761 ^done
30762 (gdb)
30763 @end smallexample
30764
30765 @ignore
30766 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30767 @node GDB/MI Memory Overlay Commands
30768 @section @sc{gdb/mi} Memory Overlay Commands
30769
30770 The memory overlay commands are not implemented.
30771
30772 @c @subheading -overlay-auto
30773
30774 @c @subheading -overlay-list-mapping-state
30775
30776 @c @subheading -overlay-list-overlays
30777
30778 @c @subheading -overlay-map
30779
30780 @c @subheading -overlay-off
30781
30782 @c @subheading -overlay-on
30783
30784 @c @subheading -overlay-unmap
30785
30786 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30787 @node GDB/MI Signal Handling Commands
30788 @section @sc{gdb/mi} Signal Handling Commands
30789
30790 Signal handling commands are not implemented.
30791
30792 @c @subheading -signal-handle
30793
30794 @c @subheading -signal-list-handle-actions
30795
30796 @c @subheading -signal-list-signal-types
30797 @end ignore
30798
30799
30800 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30801 @node GDB/MI Target Manipulation
30802 @section @sc{gdb/mi} Target Manipulation Commands
30803
30804
30805 @subheading The @code{-target-attach} Command
30806 @findex -target-attach
30807
30808 @subsubheading Synopsis
30809
30810 @smallexample
30811 -target-attach @var{pid} | @var{gid} | @var{file}
30812 @end smallexample
30813
30814 Attach to a process @var{pid} or a file @var{file} outside of
30815 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
30816 group, the id previously returned by
30817 @samp{-list-thread-groups --available} must be used.
30818
30819 @subsubheading @value{GDBN} Command
30820
30821 The corresponding @value{GDBN} command is @samp{attach}.
30822
30823 @subsubheading Example
30824 @smallexample
30825 (gdb)
30826 -target-attach 34
30827 =thread-created,id="1"
30828 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
30829 ^done
30830 (gdb)
30831 @end smallexample
30832
30833 @ignore
30834 @subheading The @code{-target-compare-sections} Command
30835 @findex -target-compare-sections
30836
30837 @subsubheading Synopsis
30838
30839 @smallexample
30840 -target-compare-sections [ @var{section} ]
30841 @end smallexample
30842
30843 Compare data of section @var{section} on target to the exec file.
30844 Without the argument, all sections are compared.
30845
30846 @subsubheading @value{GDBN} Command
30847
30848 The @value{GDBN} equivalent is @samp{compare-sections}.
30849
30850 @subsubheading Example
30851 N.A.
30852 @end ignore
30853
30854
30855 @subheading The @code{-target-detach} Command
30856 @findex -target-detach
30857
30858 @subsubheading Synopsis
30859
30860 @smallexample
30861 -target-detach [ @var{pid} | @var{gid} ]
30862 @end smallexample
30863
30864 Detach from the remote target which normally resumes its execution.
30865 If either @var{pid} or @var{gid} is specified, detaches from either
30866 the specified process, or specified thread group. There's no output.
30867
30868 @subsubheading @value{GDBN} Command
30869
30870 The corresponding @value{GDBN} command is @samp{detach}.
30871
30872 @subsubheading Example
30873
30874 @smallexample
30875 (gdb)
30876 -target-detach
30877 ^done
30878 (gdb)
30879 @end smallexample
30880
30881
30882 @subheading The @code{-target-disconnect} Command
30883 @findex -target-disconnect
30884
30885 @subsubheading Synopsis
30886
30887 @smallexample
30888 -target-disconnect
30889 @end smallexample
30890
30891 Disconnect from the remote target. There's no output and the target is
30892 generally not resumed.
30893
30894 @subsubheading @value{GDBN} Command
30895
30896 The corresponding @value{GDBN} command is @samp{disconnect}.
30897
30898 @subsubheading Example
30899
30900 @smallexample
30901 (gdb)
30902 -target-disconnect
30903 ^done
30904 (gdb)
30905 @end smallexample
30906
30907
30908 @subheading The @code{-target-download} Command
30909 @findex -target-download
30910
30911 @subsubheading Synopsis
30912
30913 @smallexample
30914 -target-download
30915 @end smallexample
30916
30917 Loads the executable onto the remote target.
30918 It prints out an update message every half second, which includes the fields:
30919
30920 @table @samp
30921 @item section
30922 The name of the section.
30923 @item section-sent
30924 The size of what has been sent so far for that section.
30925 @item section-size
30926 The size of the section.
30927 @item total-sent
30928 The total size of what was sent so far (the current and the previous sections).
30929 @item total-size
30930 The size of the overall executable to download.
30931 @end table
30932
30933 @noindent
30934 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
30935 @sc{gdb/mi} Output Syntax}).
30936
30937 In addition, it prints the name and size of the sections, as they are
30938 downloaded. These messages include the following fields:
30939
30940 @table @samp
30941 @item section
30942 The name of the section.
30943 @item section-size
30944 The size of the section.
30945 @item total-size
30946 The size of the overall executable to download.
30947 @end table
30948
30949 @noindent
30950 At the end, a summary is printed.
30951
30952 @subsubheading @value{GDBN} Command
30953
30954 The corresponding @value{GDBN} command is @samp{load}.
30955
30956 @subsubheading Example
30957
30958 Note: each status message appears on a single line. Here the messages
30959 have been broken down so that they can fit onto a page.
30960
30961 @smallexample
30962 (gdb)
30963 -target-download
30964 +download,@{section=".text",section-size="6668",total-size="9880"@}
30965 +download,@{section=".text",section-sent="512",section-size="6668",
30966 total-sent="512",total-size="9880"@}
30967 +download,@{section=".text",section-sent="1024",section-size="6668",
30968 total-sent="1024",total-size="9880"@}
30969 +download,@{section=".text",section-sent="1536",section-size="6668",
30970 total-sent="1536",total-size="9880"@}
30971 +download,@{section=".text",section-sent="2048",section-size="6668",
30972 total-sent="2048",total-size="9880"@}
30973 +download,@{section=".text",section-sent="2560",section-size="6668",
30974 total-sent="2560",total-size="9880"@}
30975 +download,@{section=".text",section-sent="3072",section-size="6668",
30976 total-sent="3072",total-size="9880"@}
30977 +download,@{section=".text",section-sent="3584",section-size="6668",
30978 total-sent="3584",total-size="9880"@}
30979 +download,@{section=".text",section-sent="4096",section-size="6668",
30980 total-sent="4096",total-size="9880"@}
30981 +download,@{section=".text",section-sent="4608",section-size="6668",
30982 total-sent="4608",total-size="9880"@}
30983 +download,@{section=".text",section-sent="5120",section-size="6668",
30984 total-sent="5120",total-size="9880"@}
30985 +download,@{section=".text",section-sent="5632",section-size="6668",
30986 total-sent="5632",total-size="9880"@}
30987 +download,@{section=".text",section-sent="6144",section-size="6668",
30988 total-sent="6144",total-size="9880"@}
30989 +download,@{section=".text",section-sent="6656",section-size="6668",
30990 total-sent="6656",total-size="9880"@}
30991 +download,@{section=".init",section-size="28",total-size="9880"@}
30992 +download,@{section=".fini",section-size="28",total-size="9880"@}
30993 +download,@{section=".data",section-size="3156",total-size="9880"@}
30994 +download,@{section=".data",section-sent="512",section-size="3156",
30995 total-sent="7236",total-size="9880"@}
30996 +download,@{section=".data",section-sent="1024",section-size="3156",
30997 total-sent="7748",total-size="9880"@}
30998 +download,@{section=".data",section-sent="1536",section-size="3156",
30999 total-sent="8260",total-size="9880"@}
31000 +download,@{section=".data",section-sent="2048",section-size="3156",
31001 total-sent="8772",total-size="9880"@}
31002 +download,@{section=".data",section-sent="2560",section-size="3156",
31003 total-sent="9284",total-size="9880"@}
31004 +download,@{section=".data",section-sent="3072",section-size="3156",
31005 total-sent="9796",total-size="9880"@}
31006 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
31007 write-rate="429"
31008 (gdb)
31009 @end smallexample
31010
31011
31012 @ignore
31013 @subheading The @code{-target-exec-status} Command
31014 @findex -target-exec-status
31015
31016 @subsubheading Synopsis
31017
31018 @smallexample
31019 -target-exec-status
31020 @end smallexample
31021
31022 Provide information on the state of the target (whether it is running or
31023 not, for instance).
31024
31025 @subsubheading @value{GDBN} Command
31026
31027 There's no equivalent @value{GDBN} command.
31028
31029 @subsubheading Example
31030 N.A.
31031
31032
31033 @subheading The @code{-target-list-available-targets} Command
31034 @findex -target-list-available-targets
31035
31036 @subsubheading Synopsis
31037
31038 @smallexample
31039 -target-list-available-targets
31040 @end smallexample
31041
31042 List the possible targets to connect to.
31043
31044 @subsubheading @value{GDBN} Command
31045
31046 The corresponding @value{GDBN} command is @samp{help target}.
31047
31048 @subsubheading Example
31049 N.A.
31050
31051
31052 @subheading The @code{-target-list-current-targets} Command
31053 @findex -target-list-current-targets
31054
31055 @subsubheading Synopsis
31056
31057 @smallexample
31058 -target-list-current-targets
31059 @end smallexample
31060
31061 Describe the current target.
31062
31063 @subsubheading @value{GDBN} Command
31064
31065 The corresponding information is printed by @samp{info file} (among
31066 other things).
31067
31068 @subsubheading Example
31069 N.A.
31070
31071
31072 @subheading The @code{-target-list-parameters} Command
31073 @findex -target-list-parameters
31074
31075 @subsubheading Synopsis
31076
31077 @smallexample
31078 -target-list-parameters
31079 @end smallexample
31080
31081 @c ????
31082 @end ignore
31083
31084 @subsubheading @value{GDBN} Command
31085
31086 No equivalent.
31087
31088 @subsubheading Example
31089 N.A.
31090
31091
31092 @subheading The @code{-target-select} Command
31093 @findex -target-select
31094
31095 @subsubheading Synopsis
31096
31097 @smallexample
31098 -target-select @var{type} @var{parameters @dots{}}
31099 @end smallexample
31100
31101 Connect @value{GDBN} to the remote target. This command takes two args:
31102
31103 @table @samp
31104 @item @var{type}
31105 The type of target, for instance @samp{remote}, etc.
31106 @item @var{parameters}
31107 Device names, host names and the like. @xref{Target Commands, ,
31108 Commands for Managing Targets}, for more details.
31109 @end table
31110
31111 The output is a connection notification, followed by the address at
31112 which the target program is, in the following form:
31113
31114 @smallexample
31115 ^connected,addr="@var{address}",func="@var{function name}",
31116 args=[@var{arg list}]
31117 @end smallexample
31118
31119 @subsubheading @value{GDBN} Command
31120
31121 The corresponding @value{GDBN} command is @samp{target}.
31122
31123 @subsubheading Example
31124
31125 @smallexample
31126 (gdb)
31127 -target-select remote /dev/ttya
31128 ^connected,addr="0xfe00a300",func="??",args=[]
31129 (gdb)
31130 @end smallexample
31131
31132 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31133 @node GDB/MI File Transfer Commands
31134 @section @sc{gdb/mi} File Transfer Commands
31135
31136
31137 @subheading The @code{-target-file-put} Command
31138 @findex -target-file-put
31139
31140 @subsubheading Synopsis
31141
31142 @smallexample
31143 -target-file-put @var{hostfile} @var{targetfile}
31144 @end smallexample
31145
31146 Copy file @var{hostfile} from the host system (the machine running
31147 @value{GDBN}) to @var{targetfile} on the target system.
31148
31149 @subsubheading @value{GDBN} Command
31150
31151 The corresponding @value{GDBN} command is @samp{remote put}.
31152
31153 @subsubheading Example
31154
31155 @smallexample
31156 (gdb)
31157 -target-file-put localfile remotefile
31158 ^done
31159 (gdb)
31160 @end smallexample
31161
31162
31163 @subheading The @code{-target-file-get} Command
31164 @findex -target-file-get
31165
31166 @subsubheading Synopsis
31167
31168 @smallexample
31169 -target-file-get @var{targetfile} @var{hostfile}
31170 @end smallexample
31171
31172 Copy file @var{targetfile} from the target system to @var{hostfile}
31173 on the host system.
31174
31175 @subsubheading @value{GDBN} Command
31176
31177 The corresponding @value{GDBN} command is @samp{remote get}.
31178
31179 @subsubheading Example
31180
31181 @smallexample
31182 (gdb)
31183 -target-file-get remotefile localfile
31184 ^done
31185 (gdb)
31186 @end smallexample
31187
31188
31189 @subheading The @code{-target-file-delete} Command
31190 @findex -target-file-delete
31191
31192 @subsubheading Synopsis
31193
31194 @smallexample
31195 -target-file-delete @var{targetfile}
31196 @end smallexample
31197
31198 Delete @var{targetfile} from the target system.
31199
31200 @subsubheading @value{GDBN} Command
31201
31202 The corresponding @value{GDBN} command is @samp{remote delete}.
31203
31204 @subsubheading Example
31205
31206 @smallexample
31207 (gdb)
31208 -target-file-delete remotefile
31209 ^done
31210 (gdb)
31211 @end smallexample
31212
31213
31214 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31215 @node GDB/MI Miscellaneous Commands
31216 @section Miscellaneous @sc{gdb/mi} Commands
31217
31218 @c @subheading -gdb-complete
31219
31220 @subheading The @code{-gdb-exit} Command
31221 @findex -gdb-exit
31222
31223 @subsubheading Synopsis
31224
31225 @smallexample
31226 -gdb-exit
31227 @end smallexample
31228
31229 Exit @value{GDBN} immediately.
31230
31231 @subsubheading @value{GDBN} Command
31232
31233 Approximately corresponds to @samp{quit}.
31234
31235 @subsubheading Example
31236
31237 @smallexample
31238 (gdb)
31239 -gdb-exit
31240 ^exit
31241 @end smallexample
31242
31243
31244 @ignore
31245 @subheading The @code{-exec-abort} Command
31246 @findex -exec-abort
31247
31248 @subsubheading Synopsis
31249
31250 @smallexample
31251 -exec-abort
31252 @end smallexample
31253
31254 Kill the inferior running program.
31255
31256 @subsubheading @value{GDBN} Command
31257
31258 The corresponding @value{GDBN} command is @samp{kill}.
31259
31260 @subsubheading Example
31261 N.A.
31262 @end ignore
31263
31264
31265 @subheading The @code{-gdb-set} Command
31266 @findex -gdb-set
31267
31268 @subsubheading Synopsis
31269
31270 @smallexample
31271 -gdb-set
31272 @end smallexample
31273
31274 Set an internal @value{GDBN} variable.
31275 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
31276
31277 @subsubheading @value{GDBN} Command
31278
31279 The corresponding @value{GDBN} command is @samp{set}.
31280
31281 @subsubheading Example
31282
31283 @smallexample
31284 (gdb)
31285 -gdb-set $foo=3
31286 ^done
31287 (gdb)
31288 @end smallexample
31289
31290
31291 @subheading The @code{-gdb-show} Command
31292 @findex -gdb-show
31293
31294 @subsubheading Synopsis
31295
31296 @smallexample
31297 -gdb-show
31298 @end smallexample
31299
31300 Show the current value of a @value{GDBN} variable.
31301
31302 @subsubheading @value{GDBN} Command
31303
31304 The corresponding @value{GDBN} command is @samp{show}.
31305
31306 @subsubheading Example
31307
31308 @smallexample
31309 (gdb)
31310 -gdb-show annotate
31311 ^done,value="0"
31312 (gdb)
31313 @end smallexample
31314
31315 @c @subheading -gdb-source
31316
31317
31318 @subheading The @code{-gdb-version} Command
31319 @findex -gdb-version
31320
31321 @subsubheading Synopsis
31322
31323 @smallexample
31324 -gdb-version
31325 @end smallexample
31326
31327 Show version information for @value{GDBN}. Used mostly in testing.
31328
31329 @subsubheading @value{GDBN} Command
31330
31331 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
31332 default shows this information when you start an interactive session.
31333
31334 @subsubheading Example
31335
31336 @c This example modifies the actual output from GDB to avoid overfull
31337 @c box in TeX.
31338 @smallexample
31339 (gdb)
31340 -gdb-version
31341 ~GNU gdb 5.2.1
31342 ~Copyright 2000 Free Software Foundation, Inc.
31343 ~GDB is free software, covered by the GNU General Public License, and
31344 ~you are welcome to change it and/or distribute copies of it under
31345 ~ certain conditions.
31346 ~Type "show copying" to see the conditions.
31347 ~There is absolutely no warranty for GDB. Type "show warranty" for
31348 ~ details.
31349 ~This GDB was configured as
31350 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
31351 ^done
31352 (gdb)
31353 @end smallexample
31354
31355 @subheading The @code{-list-features} Command
31356 @findex -list-features
31357
31358 Returns a list of particular features of the MI protocol that
31359 this version of gdb implements. A feature can be a command,
31360 or a new field in an output of some command, or even an
31361 important bugfix. While a frontend can sometimes detect presence
31362 of a feature at runtime, it is easier to perform detection at debugger
31363 startup.
31364
31365 The command returns a list of strings, with each string naming an
31366 available feature. Each returned string is just a name, it does not
31367 have any internal structure. The list of possible feature names
31368 is given below.
31369
31370 Example output:
31371
31372 @smallexample
31373 (gdb) -list-features
31374 ^done,result=["feature1","feature2"]
31375 @end smallexample
31376
31377 The current list of features is:
31378
31379 @table @samp
31380 @item frozen-varobjs
31381 Indicates support for the @code{-var-set-frozen} command, as well
31382 as possible presense of the @code{frozen} field in the output
31383 of @code{-varobj-create}.
31384 @item pending-breakpoints
31385 Indicates support for the @option{-f} option to the @code{-break-insert}
31386 command.
31387 @item python
31388 Indicates Python scripting support, Python-based
31389 pretty-printing commands, and possible presence of the
31390 @samp{display_hint} field in the output of @code{-var-list-children}
31391 @item thread-info
31392 Indicates support for the @code{-thread-info} command.
31393 @item data-read-memory-bytes
31394 Indicates support for the @code{-data-read-memory-bytes} and the
31395 @code{-data-write-memory-bytes} commands.
31396 @item breakpoint-notifications
31397 Indicates that changes to breakpoints and breakpoints created via the
31398 CLI will be announced via async records.
31399 @item ada-task-info
31400 Indicates support for the @code{-ada-task-info} command.
31401 @end table
31402
31403 @subheading The @code{-list-target-features} Command
31404 @findex -list-target-features
31405
31406 Returns a list of particular features that are supported by the
31407 target. Those features affect the permitted MI commands, but
31408 unlike the features reported by the @code{-list-features} command, the
31409 features depend on which target GDB is using at the moment. Whenever
31410 a target can change, due to commands such as @code{-target-select},
31411 @code{-target-attach} or @code{-exec-run}, the list of target features
31412 may change, and the frontend should obtain it again.
31413 Example output:
31414
31415 @smallexample
31416 (gdb) -list-features
31417 ^done,result=["async"]
31418 @end smallexample
31419
31420 The current list of features is:
31421
31422 @table @samp
31423 @item async
31424 Indicates that the target is capable of asynchronous command
31425 execution, which means that @value{GDBN} will accept further commands
31426 while the target is running.
31427
31428 @item reverse
31429 Indicates that the target is capable of reverse execution.
31430 @xref{Reverse Execution}, for more information.
31431
31432 @end table
31433
31434 @subheading The @code{-list-thread-groups} Command
31435 @findex -list-thread-groups
31436
31437 @subheading Synopsis
31438
31439 @smallexample
31440 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
31441 @end smallexample
31442
31443 Lists thread groups (@pxref{Thread groups}). When a single thread
31444 group is passed as the argument, lists the children of that group.
31445 When several thread group are passed, lists information about those
31446 thread groups. Without any parameters, lists information about all
31447 top-level thread groups.
31448
31449 Normally, thread groups that are being debugged are reported.
31450 With the @samp{--available} option, @value{GDBN} reports thread groups
31451 available on the target.
31452
31453 The output of this command may have either a @samp{threads} result or
31454 a @samp{groups} result. The @samp{thread} result has a list of tuples
31455 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
31456 Information}). The @samp{groups} result has a list of tuples as value,
31457 each tuple describing a thread group. If top-level groups are
31458 requested (that is, no parameter is passed), or when several groups
31459 are passed, the output always has a @samp{groups} result. The format
31460 of the @samp{group} result is described below.
31461
31462 To reduce the number of roundtrips it's possible to list thread groups
31463 together with their children, by passing the @samp{--recurse} option
31464 and the recursion depth. Presently, only recursion depth of 1 is
31465 permitted. If this option is present, then every reported thread group
31466 will also include its children, either as @samp{group} or
31467 @samp{threads} field.
31468
31469 In general, any combination of option and parameters is permitted, with
31470 the following caveats:
31471
31472 @itemize @bullet
31473 @item
31474 When a single thread group is passed, the output will typically
31475 be the @samp{threads} result. Because threads may not contain
31476 anything, the @samp{recurse} option will be ignored.
31477
31478 @item
31479 When the @samp{--available} option is passed, limited information may
31480 be available. In particular, the list of threads of a process might
31481 be inaccessible. Further, specifying specific thread groups might
31482 not give any performance advantage over listing all thread groups.
31483 The frontend should assume that @samp{-list-thread-groups --available}
31484 is always an expensive operation and cache the results.
31485
31486 @end itemize
31487
31488 The @samp{groups} result is a list of tuples, where each tuple may
31489 have the following fields:
31490
31491 @table @code
31492 @item id
31493 Identifier of the thread group. This field is always present.
31494 The identifier is an opaque string; frontends should not try to
31495 convert it to an integer, even though it might look like one.
31496
31497 @item type
31498 The type of the thread group. At present, only @samp{process} is a
31499 valid type.
31500
31501 @item pid
31502 The target-specific process identifier. This field is only present
31503 for thread groups of type @samp{process} and only if the process exists.
31504
31505 @item num_children
31506 The number of children this thread group has. This field may be
31507 absent for an available thread group.
31508
31509 @item threads
31510 This field has a list of tuples as value, each tuple describing a
31511 thread. It may be present if the @samp{--recurse} option is
31512 specified, and it's actually possible to obtain the threads.
31513
31514 @item cores
31515 This field is a list of integers, each identifying a core that one
31516 thread of the group is running on. This field may be absent if
31517 such information is not available.
31518
31519 @item executable
31520 The name of the executable file that corresponds to this thread group.
31521 The field is only present for thread groups of type @samp{process},
31522 and only if there is a corresponding executable file.
31523
31524 @end table
31525
31526 @subheading Example
31527
31528 @smallexample
31529 @value{GDBP}
31530 -list-thread-groups
31531 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
31532 -list-thread-groups 17
31533 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31534 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
31535 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31536 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
31537 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
31538 -list-thread-groups --available
31539 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
31540 -list-thread-groups --available --recurse 1
31541 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
31542 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
31543 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
31544 -list-thread-groups --available --recurse 1 17 18
31545 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
31546 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
31547 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
31548 @end smallexample
31549
31550
31551 @subheading The @code{-add-inferior} Command
31552 @findex -add-inferior
31553
31554 @subheading Synopsis
31555
31556 @smallexample
31557 -add-inferior
31558 @end smallexample
31559
31560 Creates a new inferior (@pxref{Inferiors and Programs}). The created
31561 inferior is not associated with any executable. Such association may
31562 be established with the @samp{-file-exec-and-symbols} command
31563 (@pxref{GDB/MI File Commands}). The command response has a single
31564 field, @samp{thread-group}, whose value is the identifier of the
31565 thread group corresponding to the new inferior.
31566
31567 @subheading Example
31568
31569 @smallexample
31570 @value{GDBP}
31571 -add-inferior
31572 ^done,thread-group="i3"
31573 @end smallexample
31574
31575 @subheading The @code{-interpreter-exec} Command
31576 @findex -interpreter-exec
31577
31578 @subheading Synopsis
31579
31580 @smallexample
31581 -interpreter-exec @var{interpreter} @var{command}
31582 @end smallexample
31583 @anchor{-interpreter-exec}
31584
31585 Execute the specified @var{command} in the given @var{interpreter}.
31586
31587 @subheading @value{GDBN} Command
31588
31589 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
31590
31591 @subheading Example
31592
31593 @smallexample
31594 (gdb)
31595 -interpreter-exec console "break main"
31596 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
31597 &"During symbol reading, bad structure-type format.\n"
31598 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
31599 ^done
31600 (gdb)
31601 @end smallexample
31602
31603 @subheading The @code{-inferior-tty-set} Command
31604 @findex -inferior-tty-set
31605
31606 @subheading Synopsis
31607
31608 @smallexample
31609 -inferior-tty-set /dev/pts/1
31610 @end smallexample
31611
31612 Set terminal for future runs of the program being debugged.
31613
31614 @subheading @value{GDBN} Command
31615
31616 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
31617
31618 @subheading Example
31619
31620 @smallexample
31621 (gdb)
31622 -inferior-tty-set /dev/pts/1
31623 ^done
31624 (gdb)
31625 @end smallexample
31626
31627 @subheading The @code{-inferior-tty-show} Command
31628 @findex -inferior-tty-show
31629
31630 @subheading Synopsis
31631
31632 @smallexample
31633 -inferior-tty-show
31634 @end smallexample
31635
31636 Show terminal for future runs of program being debugged.
31637
31638 @subheading @value{GDBN} Command
31639
31640 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
31641
31642 @subheading Example
31643
31644 @smallexample
31645 (gdb)
31646 -inferior-tty-set /dev/pts/1
31647 ^done
31648 (gdb)
31649 -inferior-tty-show
31650 ^done,inferior_tty_terminal="/dev/pts/1"
31651 (gdb)
31652 @end smallexample
31653
31654 @subheading The @code{-enable-timings} Command
31655 @findex -enable-timings
31656
31657 @subheading Synopsis
31658
31659 @smallexample
31660 -enable-timings [yes | no]
31661 @end smallexample
31662
31663 Toggle the printing of the wallclock, user and system times for an MI
31664 command as a field in its output. This command is to help frontend
31665 developers optimize the performance of their code. No argument is
31666 equivalent to @samp{yes}.
31667
31668 @subheading @value{GDBN} Command
31669
31670 No equivalent.
31671
31672 @subheading Example
31673
31674 @smallexample
31675 (gdb)
31676 -enable-timings
31677 ^done
31678 (gdb)
31679 -break-insert main
31680 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31681 addr="0x080484ed",func="main",file="myprog.c",
31682 fullname="/home/nickrob/myprog.c",line="73",times="0"@},
31683 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
31684 (gdb)
31685 -enable-timings no
31686 ^done
31687 (gdb)
31688 -exec-run
31689 ^running
31690 (gdb)
31691 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
31692 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
31693 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
31694 fullname="/home/nickrob/myprog.c",line="73"@}
31695 (gdb)
31696 @end smallexample
31697
31698 @node Annotations
31699 @chapter @value{GDBN} Annotations
31700
31701 This chapter describes annotations in @value{GDBN}. Annotations were
31702 designed to interface @value{GDBN} to graphical user interfaces or other
31703 similar programs which want to interact with @value{GDBN} at a
31704 relatively high level.
31705
31706 The annotation mechanism has largely been superseded by @sc{gdb/mi}
31707 (@pxref{GDB/MI}).
31708
31709 @ignore
31710 This is Edition @value{EDITION}, @value{DATE}.
31711 @end ignore
31712
31713 @menu
31714 * Annotations Overview:: What annotations are; the general syntax.
31715 * Server Prefix:: Issuing a command without affecting user state.
31716 * Prompting:: Annotations marking @value{GDBN}'s need for input.
31717 * Errors:: Annotations for error messages.
31718 * Invalidation:: Some annotations describe things now invalid.
31719 * Annotations for Running::
31720 Whether the program is running, how it stopped, etc.
31721 * Source Annotations:: Annotations describing source code.
31722 @end menu
31723
31724 @node Annotations Overview
31725 @section What is an Annotation?
31726 @cindex annotations
31727
31728 Annotations start with a newline character, two @samp{control-z}
31729 characters, and the name of the annotation. If there is no additional
31730 information associated with this annotation, the name of the annotation
31731 is followed immediately by a newline. If there is additional
31732 information, the name of the annotation is followed by a space, the
31733 additional information, and a newline. The additional information
31734 cannot contain newline characters.
31735
31736 Any output not beginning with a newline and two @samp{control-z}
31737 characters denotes literal output from @value{GDBN}. Currently there is
31738 no need for @value{GDBN} to output a newline followed by two
31739 @samp{control-z} characters, but if there was such a need, the
31740 annotations could be extended with an @samp{escape} annotation which
31741 means those three characters as output.
31742
31743 The annotation @var{level}, which is specified using the
31744 @option{--annotate} command line option (@pxref{Mode Options}), controls
31745 how much information @value{GDBN} prints together with its prompt,
31746 values of expressions, source lines, and other types of output. Level 0
31747 is for no annotations, level 1 is for use when @value{GDBN} is run as a
31748 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
31749 for programs that control @value{GDBN}, and level 2 annotations have
31750 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
31751 Interface, annotate, GDB's Obsolete Annotations}).
31752
31753 @table @code
31754 @kindex set annotate
31755 @item set annotate @var{level}
31756 The @value{GDBN} command @code{set annotate} sets the level of
31757 annotations to the specified @var{level}.
31758
31759 @item show annotate
31760 @kindex show annotate
31761 Show the current annotation level.
31762 @end table
31763
31764 This chapter describes level 3 annotations.
31765
31766 A simple example of starting up @value{GDBN} with annotations is:
31767
31768 @smallexample
31769 $ @kbd{gdb --annotate=3}
31770 GNU gdb 6.0
31771 Copyright 2003 Free Software Foundation, Inc.
31772 GDB is free software, covered by the GNU General Public License,
31773 and you are welcome to change it and/or distribute copies of it
31774 under certain conditions.
31775 Type "show copying" to see the conditions.
31776 There is absolutely no warranty for GDB. Type "show warranty"
31777 for details.
31778 This GDB was configured as "i386-pc-linux-gnu"
31779
31780 ^Z^Zpre-prompt
31781 (@value{GDBP})
31782 ^Z^Zprompt
31783 @kbd{quit}
31784
31785 ^Z^Zpost-prompt
31786 $
31787 @end smallexample
31788
31789 Here @samp{quit} is input to @value{GDBN}; the rest is output from
31790 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
31791 denotes a @samp{control-z} character) are annotations; the rest is
31792 output from @value{GDBN}.
31793
31794 @node Server Prefix
31795 @section The Server Prefix
31796 @cindex server prefix
31797
31798 If you prefix a command with @samp{server } then it will not affect
31799 the command history, nor will it affect @value{GDBN}'s notion of which
31800 command to repeat if @key{RET} is pressed on a line by itself. This
31801 means that commands can be run behind a user's back by a front-end in
31802 a transparent manner.
31803
31804 The @code{server } prefix does not affect the recording of values into
31805 the value history; to print a value without recording it into the
31806 value history, use the @code{output} command instead of the
31807 @code{print} command.
31808
31809 Using this prefix also disables confirmation requests
31810 (@pxref{confirmation requests}).
31811
31812 @node Prompting
31813 @section Annotation for @value{GDBN} Input
31814
31815 @cindex annotations for prompts
31816 When @value{GDBN} prompts for input, it annotates this fact so it is possible
31817 to know when to send output, when the output from a given command is
31818 over, etc.
31819
31820 Different kinds of input each have a different @dfn{input type}. Each
31821 input type has three annotations: a @code{pre-} annotation, which
31822 denotes the beginning of any prompt which is being output, a plain
31823 annotation, which denotes the end of the prompt, and then a @code{post-}
31824 annotation which denotes the end of any echo which may (or may not) be
31825 associated with the input. For example, the @code{prompt} input type
31826 features the following annotations:
31827
31828 @smallexample
31829 ^Z^Zpre-prompt
31830 ^Z^Zprompt
31831 ^Z^Zpost-prompt
31832 @end smallexample
31833
31834 The input types are
31835
31836 @table @code
31837 @findex pre-prompt annotation
31838 @findex prompt annotation
31839 @findex post-prompt annotation
31840 @item prompt
31841 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
31842
31843 @findex pre-commands annotation
31844 @findex commands annotation
31845 @findex post-commands annotation
31846 @item commands
31847 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
31848 command. The annotations are repeated for each command which is input.
31849
31850 @findex pre-overload-choice annotation
31851 @findex overload-choice annotation
31852 @findex post-overload-choice annotation
31853 @item overload-choice
31854 When @value{GDBN} wants the user to select between various overloaded functions.
31855
31856 @findex pre-query annotation
31857 @findex query annotation
31858 @findex post-query annotation
31859 @item query
31860 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
31861
31862 @findex pre-prompt-for-continue annotation
31863 @findex prompt-for-continue annotation
31864 @findex post-prompt-for-continue annotation
31865 @item prompt-for-continue
31866 When @value{GDBN} is asking the user to press return to continue. Note: Don't
31867 expect this to work well; instead use @code{set height 0} to disable
31868 prompting. This is because the counting of lines is buggy in the
31869 presence of annotations.
31870 @end table
31871
31872 @node Errors
31873 @section Errors
31874 @cindex annotations for errors, warnings and interrupts
31875
31876 @findex quit annotation
31877 @smallexample
31878 ^Z^Zquit
31879 @end smallexample
31880
31881 This annotation occurs right before @value{GDBN} responds to an interrupt.
31882
31883 @findex error annotation
31884 @smallexample
31885 ^Z^Zerror
31886 @end smallexample
31887
31888 This annotation occurs right before @value{GDBN} responds to an error.
31889
31890 Quit and error annotations indicate that any annotations which @value{GDBN} was
31891 in the middle of may end abruptly. For example, if a
31892 @code{value-history-begin} annotation is followed by a @code{error}, one
31893 cannot expect to receive the matching @code{value-history-end}. One
31894 cannot expect not to receive it either, however; an error annotation
31895 does not necessarily mean that @value{GDBN} is immediately returning all the way
31896 to the top level.
31897
31898 @findex error-begin annotation
31899 A quit or error annotation may be preceded by
31900
31901 @smallexample
31902 ^Z^Zerror-begin
31903 @end smallexample
31904
31905 Any output between that and the quit or error annotation is the error
31906 message.
31907
31908 Warning messages are not yet annotated.
31909 @c If we want to change that, need to fix warning(), type_error(),
31910 @c range_error(), and possibly other places.
31911
31912 @node Invalidation
31913 @section Invalidation Notices
31914
31915 @cindex annotations for invalidation messages
31916 The following annotations say that certain pieces of state may have
31917 changed.
31918
31919 @table @code
31920 @findex frames-invalid annotation
31921 @item ^Z^Zframes-invalid
31922
31923 The frames (for example, output from the @code{backtrace} command) may
31924 have changed.
31925
31926 @findex breakpoints-invalid annotation
31927 @item ^Z^Zbreakpoints-invalid
31928
31929 The breakpoints may have changed. For example, the user just added or
31930 deleted a breakpoint.
31931 @end table
31932
31933 @node Annotations for Running
31934 @section Running the Program
31935 @cindex annotations for running programs
31936
31937 @findex starting annotation
31938 @findex stopping annotation
31939 When the program starts executing due to a @value{GDBN} command such as
31940 @code{step} or @code{continue},
31941
31942 @smallexample
31943 ^Z^Zstarting
31944 @end smallexample
31945
31946 is output. When the program stops,
31947
31948 @smallexample
31949 ^Z^Zstopped
31950 @end smallexample
31951
31952 is output. Before the @code{stopped} annotation, a variety of
31953 annotations describe how the program stopped.
31954
31955 @table @code
31956 @findex exited annotation
31957 @item ^Z^Zexited @var{exit-status}
31958 The program exited, and @var{exit-status} is the exit status (zero for
31959 successful exit, otherwise nonzero).
31960
31961 @findex signalled annotation
31962 @findex signal-name annotation
31963 @findex signal-name-end annotation
31964 @findex signal-string annotation
31965 @findex signal-string-end annotation
31966 @item ^Z^Zsignalled
31967 The program exited with a signal. After the @code{^Z^Zsignalled}, the
31968 annotation continues:
31969
31970 @smallexample
31971 @var{intro-text}
31972 ^Z^Zsignal-name
31973 @var{name}
31974 ^Z^Zsignal-name-end
31975 @var{middle-text}
31976 ^Z^Zsignal-string
31977 @var{string}
31978 ^Z^Zsignal-string-end
31979 @var{end-text}
31980 @end smallexample
31981
31982 @noindent
31983 where @var{name} is the name of the signal, such as @code{SIGILL} or
31984 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
31985 as @code{Illegal Instruction} or @code{Segmentation fault}.
31986 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
31987 user's benefit and have no particular format.
31988
31989 @findex signal annotation
31990 @item ^Z^Zsignal
31991 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
31992 just saying that the program received the signal, not that it was
31993 terminated with it.
31994
31995 @findex breakpoint annotation
31996 @item ^Z^Zbreakpoint @var{number}
31997 The program hit breakpoint number @var{number}.
31998
31999 @findex watchpoint annotation
32000 @item ^Z^Zwatchpoint @var{number}
32001 The program hit watchpoint number @var{number}.
32002 @end table
32003
32004 @node Source Annotations
32005 @section Displaying Source
32006 @cindex annotations for source display
32007
32008 @findex source annotation
32009 The following annotation is used instead of displaying source code:
32010
32011 @smallexample
32012 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
32013 @end smallexample
32014
32015 where @var{filename} is an absolute file name indicating which source
32016 file, @var{line} is the line number within that file (where 1 is the
32017 first line in the file), @var{character} is the character position
32018 within the file (where 0 is the first character in the file) (for most
32019 debug formats this will necessarily point to the beginning of a line),
32020 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
32021 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
32022 @var{addr} is the address in the target program associated with the
32023 source which is being displayed. @var{addr} is in the form @samp{0x}
32024 followed by one or more lowercase hex digits (note that this does not
32025 depend on the language).
32026
32027 @node JIT Interface
32028 @chapter JIT Compilation Interface
32029 @cindex just-in-time compilation
32030 @cindex JIT compilation interface
32031
32032 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
32033 interface. A JIT compiler is a program or library that generates native
32034 executable code at runtime and executes it, usually in order to achieve good
32035 performance while maintaining platform independence.
32036
32037 Programs that use JIT compilation are normally difficult to debug because
32038 portions of their code are generated at runtime, instead of being loaded from
32039 object files, which is where @value{GDBN} normally finds the program's symbols
32040 and debug information. In order to debug programs that use JIT compilation,
32041 @value{GDBN} has an interface that allows the program to register in-memory
32042 symbol files with @value{GDBN} at runtime.
32043
32044 If you are using @value{GDBN} to debug a program that uses this interface, then
32045 it should work transparently so long as you have not stripped the binary. If
32046 you are developing a JIT compiler, then the interface is documented in the rest
32047 of this chapter. At this time, the only known client of this interface is the
32048 LLVM JIT.
32049
32050 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
32051 JIT compiler communicates with @value{GDBN} by writing data into a global
32052 variable and calling a fuction at a well-known symbol. When @value{GDBN}
32053 attaches, it reads a linked list of symbol files from the global variable to
32054 find existing code, and puts a breakpoint in the function so that it can find
32055 out about additional code.
32056
32057 @menu
32058 * Declarations:: Relevant C struct declarations
32059 * Registering Code:: Steps to register code
32060 * Unregistering Code:: Steps to unregister code
32061 * Custom Debug Info:: Emit debug information in a custom format
32062 @end menu
32063
32064 @node Declarations
32065 @section JIT Declarations
32066
32067 These are the relevant struct declarations that a C program should include to
32068 implement the interface:
32069
32070 @smallexample
32071 typedef enum
32072 @{
32073 JIT_NOACTION = 0,
32074 JIT_REGISTER_FN,
32075 JIT_UNREGISTER_FN
32076 @} jit_actions_t;
32077
32078 struct jit_code_entry
32079 @{
32080 struct jit_code_entry *next_entry;
32081 struct jit_code_entry *prev_entry;
32082 const char *symfile_addr;
32083 uint64_t symfile_size;
32084 @};
32085
32086 struct jit_descriptor
32087 @{
32088 uint32_t version;
32089 /* This type should be jit_actions_t, but we use uint32_t
32090 to be explicit about the bitwidth. */
32091 uint32_t action_flag;
32092 struct jit_code_entry *relevant_entry;
32093 struct jit_code_entry *first_entry;
32094 @};
32095
32096 /* GDB puts a breakpoint in this function. */
32097 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
32098
32099 /* Make sure to specify the version statically, because the
32100 debugger may check the version before we can set it. */
32101 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
32102 @end smallexample
32103
32104 If the JIT is multi-threaded, then it is important that the JIT synchronize any
32105 modifications to this global data properly, which can easily be done by putting
32106 a global mutex around modifications to these structures.
32107
32108 @node Registering Code
32109 @section Registering Code
32110
32111 To register code with @value{GDBN}, the JIT should follow this protocol:
32112
32113 @itemize @bullet
32114 @item
32115 Generate an object file in memory with symbols and other desired debug
32116 information. The file must include the virtual addresses of the sections.
32117
32118 @item
32119 Create a code entry for the file, which gives the start and size of the symbol
32120 file.
32121
32122 @item
32123 Add it to the linked list in the JIT descriptor.
32124
32125 @item
32126 Point the relevant_entry field of the descriptor at the entry.
32127
32128 @item
32129 Set @code{action_flag} to @code{JIT_REGISTER} and call
32130 @code{__jit_debug_register_code}.
32131 @end itemize
32132
32133 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
32134 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
32135 new code. However, the linked list must still be maintained in order to allow
32136 @value{GDBN} to attach to a running process and still find the symbol files.
32137
32138 @node Unregistering Code
32139 @section Unregistering Code
32140
32141 If code is freed, then the JIT should use the following protocol:
32142
32143 @itemize @bullet
32144 @item
32145 Remove the code entry corresponding to the code from the linked list.
32146
32147 @item
32148 Point the @code{relevant_entry} field of the descriptor at the code entry.
32149
32150 @item
32151 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
32152 @code{__jit_debug_register_code}.
32153 @end itemize
32154
32155 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
32156 and the JIT will leak the memory used for the associated symbol files.
32157
32158 @node Custom Debug Info
32159 @section Custom Debug Info
32160 @cindex custom JIT debug info
32161 @cindex JIT debug info reader
32162
32163 Generating debug information in platform-native file formats (like ELF
32164 or COFF) may be an overkill for JIT compilers; especially if all the
32165 debug info is used for is displaying a meaningful backtrace. The
32166 issue can be resolved by having the JIT writers decide on a debug info
32167 format and also provide a reader that parses the debug info generated
32168 by the JIT compiler. This section gives a brief overview on writing
32169 such a parser. More specific details can be found in the source file
32170 @file{gdb/jit-reader.in}, which is also installed as a header at
32171 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
32172
32173 The reader is implemented as a shared object (so this functionality is
32174 not available on platforms which don't allow loading shared objects at
32175 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
32176 @code{jit-reader-unload} are provided, to be used to load and unload
32177 the readers from a preconfigured directory. Once loaded, the shared
32178 object is used the parse the debug information emitted by the JIT
32179 compiler.
32180
32181 @menu
32182 * Using JIT Debug Info Readers:: How to use supplied readers correctly
32183 * Writing JIT Debug Info Readers:: Creating a debug-info reader
32184 @end menu
32185
32186 @node Using JIT Debug Info Readers
32187 @subsection Using JIT Debug Info Readers
32188 @kindex jit-reader-load
32189 @kindex jit-reader-unload
32190
32191 Readers can be loaded and unloaded using the @code{jit-reader-load}
32192 and @code{jit-reader-unload} commands.
32193
32194 @table @code
32195 @item jit-reader-load @var{reader-name}
32196 Load the JIT reader named @var{reader-name}. On a UNIX system, this
32197 will usually load @file{@var{libdir}/gdb/@var{reader-name}}, where
32198 @var{libdir} is the system library directory, usually
32199 @file{/usr/local/lib}. Only one reader can be active at a time;
32200 trying to load a second reader when one is already loaded will result
32201 in @value{GDBN} reporting an error. A new JIT reader can be loaded by
32202 first unloading the current one using @code{jit-reader-load} and then
32203 invoking @code{jit-reader-load}.
32204
32205 @item jit-reader-unload
32206 Unload the currently loaded JIT reader.
32207
32208 @end table
32209
32210 @node Writing JIT Debug Info Readers
32211 @subsection Writing JIT Debug Info Readers
32212 @cindex writing JIT debug info readers
32213
32214 As mentioned, a reader is essentially a shared object conforming to a
32215 certain ABI. This ABI is described in @file{jit-reader.h}.
32216
32217 @file{jit-reader.h} defines the structures, macros and functions
32218 required to write a reader. It is installed (along with
32219 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
32220 the system include directory.
32221
32222 Readers need to be released under a GPL compatible license. A reader
32223 can be declared as released under such a license by placing the macro
32224 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
32225
32226 The entry point for readers is the symbol @code{gdb_init_reader},
32227 which is expected to be a function with the prototype
32228
32229 @findex gdb_init_reader
32230 @smallexample
32231 extern struct gdb_reader_funcs *gdb_init_reader (void);
32232 @end smallexample
32233
32234 @cindex @code{struct gdb_reader_funcs}
32235
32236 @code{struct gdb_reader_funcs} contains a set of pointers to callback
32237 functions. These functions are executed to read the debug info
32238 generated by the JIT compiler (@code{read}), to unwind stack frames
32239 (@code{unwind}) and to create canonical frame IDs
32240 (@code{get_Frame_id}). It also has a callback that is called when the
32241 reader is being unloaded (@code{destroy}). The struct looks like this
32242
32243 @smallexample
32244 struct gdb_reader_funcs
32245 @{
32246 /* Must be set to GDB_READER_INTERFACE_VERSION. */
32247 int reader_version;
32248
32249 /* For use by the reader. */
32250 void *priv_data;
32251
32252 gdb_read_debug_info *read;
32253 gdb_unwind_frame *unwind;
32254 gdb_get_frame_id *get_frame_id;
32255 gdb_destroy_reader *destroy;
32256 @};
32257 @end smallexample
32258
32259 @cindex @code{struct gdb_symbol_callbacks}
32260 @cindex @code{struct gdb_unwind_callbacks}
32261
32262 The callbacks are provided with another set of callbacks by
32263 @value{GDBN} to do their job. For @code{read}, these callbacks are
32264 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
32265 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
32266 @code{struct gdb_symbol_callbacks} has callbacks to create new object
32267 files and new symbol tables inside those object files. @code{struct
32268 gdb_unwind_callbacks} has callbacks to read registers off the current
32269 frame and to write out the values of the registers in the previous
32270 frame. Both have a callback (@code{target_read}) to read bytes off the
32271 target's address space.
32272
32273 @node In-Process Agent
32274 @chapter In-Process Agent
32275 @cindex debugging agent
32276 The traditional debugging model is conceptually low-speed, but works fine,
32277 because most bugs can be reproduced in debugging-mode execution. However,
32278 as multi-core or many-core processors are becoming mainstream, and
32279 multi-threaded programs become more and more popular, there should be more
32280 and more bugs that only manifest themselves at normal-mode execution, for
32281 example, thread races, because debugger's interference with the program's
32282 timing may conceal the bugs. On the other hand, in some applications,
32283 it is not feasible for the debugger to interrupt the program's execution
32284 long enough for the developer to learn anything helpful about its behavior.
32285 If the program's correctness depends on its real-time behavior, delays
32286 introduced by a debugger might cause the program to fail, even when the
32287 code itself is correct. It is useful to be able to observe the program's
32288 behavior without interrupting it.
32289
32290 Therefore, traditional debugging model is too intrusive to reproduce
32291 some bugs. In order to reduce the interference with the program, we can
32292 reduce the number of operations performed by debugger. The
32293 @dfn{In-Process Agent}, a shared library, is running within the same
32294 process with inferior, and is able to perform some debugging operations
32295 itself. As a result, debugger is only involved when necessary, and
32296 performance of debugging can be improved accordingly. Note that
32297 interference with program can be reduced but can't be removed completely,
32298 because the in-process agent will still stop or slow down the program.
32299
32300 The in-process agent can interpret and execute Agent Expressions
32301 (@pxref{Agent Expressions}) during performing debugging operations. The
32302 agent expressions can be used for different purposes, such as collecting
32303 data in tracepoints, and condition evaluation in breakpoints.
32304
32305 @anchor{Control Agent}
32306 You can control whether the in-process agent is used as an aid for
32307 debugging with the following commands:
32308
32309 @table @code
32310 @kindex set agent on
32311 @item set agent on
32312 Causes the in-process agent to perform some operations on behalf of the
32313 debugger. Just which operations requested by the user will be done
32314 by the in-process agent depends on the its capabilities. For example,
32315 if you request to evaluate breakpoint conditions in the in-process agent,
32316 and the in-process agent has such capability as well, then breakpoint
32317 conditions will be evaluated in the in-process agent.
32318
32319 @kindex set agent off
32320 @item set agent off
32321 Disables execution of debugging operations by the in-process agent. All
32322 of the operations will be performed by @value{GDBN}.
32323
32324 @kindex show agent
32325 @item show agent
32326 Display the current setting of execution of debugging operations by
32327 the in-process agent.
32328 @end table
32329
32330 @node GDB Bugs
32331 @chapter Reporting Bugs in @value{GDBN}
32332 @cindex bugs in @value{GDBN}
32333 @cindex reporting bugs in @value{GDBN}
32334
32335 Your bug reports play an essential role in making @value{GDBN} reliable.
32336
32337 Reporting a bug may help you by bringing a solution to your problem, or it
32338 may not. But in any case the principal function of a bug report is to help
32339 the entire community by making the next version of @value{GDBN} work better. Bug
32340 reports are your contribution to the maintenance of @value{GDBN}.
32341
32342 In order for a bug report to serve its purpose, you must include the
32343 information that enables us to fix the bug.
32344
32345 @menu
32346 * Bug Criteria:: Have you found a bug?
32347 * Bug Reporting:: How to report bugs
32348 @end menu
32349
32350 @node Bug Criteria
32351 @section Have You Found a Bug?
32352 @cindex bug criteria
32353
32354 If you are not sure whether you have found a bug, here are some guidelines:
32355
32356 @itemize @bullet
32357 @cindex fatal signal
32358 @cindex debugger crash
32359 @cindex crash of debugger
32360 @item
32361 If the debugger gets a fatal signal, for any input whatever, that is a
32362 @value{GDBN} bug. Reliable debuggers never crash.
32363
32364 @cindex error on valid input
32365 @item
32366 If @value{GDBN} produces an error message for valid input, that is a
32367 bug. (Note that if you're cross debugging, the problem may also be
32368 somewhere in the connection to the target.)
32369
32370 @cindex invalid input
32371 @item
32372 If @value{GDBN} does not produce an error message for invalid input,
32373 that is a bug. However, you should note that your idea of
32374 ``invalid input'' might be our idea of ``an extension'' or ``support
32375 for traditional practice''.
32376
32377 @item
32378 If you are an experienced user of debugging tools, your suggestions
32379 for improvement of @value{GDBN} are welcome in any case.
32380 @end itemize
32381
32382 @node Bug Reporting
32383 @section How to Report Bugs
32384 @cindex bug reports
32385 @cindex @value{GDBN} bugs, reporting
32386
32387 A number of companies and individuals offer support for @sc{gnu} products.
32388 If you obtained @value{GDBN} from a support organization, we recommend you
32389 contact that organization first.
32390
32391 You can find contact information for many support companies and
32392 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
32393 distribution.
32394 @c should add a web page ref...
32395
32396 @ifset BUGURL
32397 @ifset BUGURL_DEFAULT
32398 In any event, we also recommend that you submit bug reports for
32399 @value{GDBN}. The preferred method is to submit them directly using
32400 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
32401 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
32402 be used.
32403
32404 @strong{Do not send bug reports to @samp{info-gdb}, or to
32405 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
32406 not want to receive bug reports. Those that do have arranged to receive
32407 @samp{bug-gdb}.
32408
32409 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
32410 serves as a repeater. The mailing list and the newsgroup carry exactly
32411 the same messages. Often people think of posting bug reports to the
32412 newsgroup instead of mailing them. This appears to work, but it has one
32413 problem which can be crucial: a newsgroup posting often lacks a mail
32414 path back to the sender. Thus, if we need to ask for more information,
32415 we may be unable to reach you. For this reason, it is better to send
32416 bug reports to the mailing list.
32417 @end ifset
32418 @ifclear BUGURL_DEFAULT
32419 In any event, we also recommend that you submit bug reports for
32420 @value{GDBN} to @value{BUGURL}.
32421 @end ifclear
32422 @end ifset
32423
32424 The fundamental principle of reporting bugs usefully is this:
32425 @strong{report all the facts}. If you are not sure whether to state a
32426 fact or leave it out, state it!
32427
32428 Often people omit facts because they think they know what causes the
32429 problem and assume that some details do not matter. Thus, you might
32430 assume that the name of the variable you use in an example does not matter.
32431 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
32432 stray memory reference which happens to fetch from the location where that
32433 name is stored in memory; perhaps, if the name were different, the contents
32434 of that location would fool the debugger into doing the right thing despite
32435 the bug. Play it safe and give a specific, complete example. That is the
32436 easiest thing for you to do, and the most helpful.
32437
32438 Keep in mind that the purpose of a bug report is to enable us to fix the
32439 bug. It may be that the bug has been reported previously, but neither
32440 you nor we can know that unless your bug report is complete and
32441 self-contained.
32442
32443 Sometimes people give a few sketchy facts and ask, ``Does this ring a
32444 bell?'' Those bug reports are useless, and we urge everyone to
32445 @emph{refuse to respond to them} except to chide the sender to report
32446 bugs properly.
32447
32448 To enable us to fix the bug, you should include all these things:
32449
32450 @itemize @bullet
32451 @item
32452 The version of @value{GDBN}. @value{GDBN} announces it if you start
32453 with no arguments; you can also print it at any time using @code{show
32454 version}.
32455
32456 Without this, we will not know whether there is any point in looking for
32457 the bug in the current version of @value{GDBN}.
32458
32459 @item
32460 The type of machine you are using, and the operating system name and
32461 version number.
32462
32463 @item
32464 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
32465 ``@value{GCC}--2.8.1''.
32466
32467 @item
32468 What compiler (and its version) was used to compile the program you are
32469 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
32470 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
32471 to get this information; for other compilers, see the documentation for
32472 those compilers.
32473
32474 @item
32475 The command arguments you gave the compiler to compile your example and
32476 observe the bug. For example, did you use @samp{-O}? To guarantee
32477 you will not omit something important, list them all. A copy of the
32478 Makefile (or the output from make) is sufficient.
32479
32480 If we were to try to guess the arguments, we would probably guess wrong
32481 and then we might not encounter the bug.
32482
32483 @item
32484 A complete input script, and all necessary source files, that will
32485 reproduce the bug.
32486
32487 @item
32488 A description of what behavior you observe that you believe is
32489 incorrect. For example, ``It gets a fatal signal.''
32490
32491 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
32492 will certainly notice it. But if the bug is incorrect output, we might
32493 not notice unless it is glaringly wrong. You might as well not give us
32494 a chance to make a mistake.
32495
32496 Even if the problem you experience is a fatal signal, you should still
32497 say so explicitly. Suppose something strange is going on, such as, your
32498 copy of @value{GDBN} is out of synch, or you have encountered a bug in
32499 the C library on your system. (This has happened!) Your copy might
32500 crash and ours would not. If you told us to expect a crash, then when
32501 ours fails to crash, we would know that the bug was not happening for
32502 us. If you had not told us to expect a crash, then we would not be able
32503 to draw any conclusion from our observations.
32504
32505 @pindex script
32506 @cindex recording a session script
32507 To collect all this information, you can use a session recording program
32508 such as @command{script}, which is available on many Unix systems.
32509 Just run your @value{GDBN} session inside @command{script} and then
32510 include the @file{typescript} file with your bug report.
32511
32512 Another way to record a @value{GDBN} session is to run @value{GDBN}
32513 inside Emacs and then save the entire buffer to a file.
32514
32515 @item
32516 If you wish to suggest changes to the @value{GDBN} source, send us context
32517 diffs. If you even discuss something in the @value{GDBN} source, refer to
32518 it by context, not by line number.
32519
32520 The line numbers in our development sources will not match those in your
32521 sources. Your line numbers would convey no useful information to us.
32522
32523 @end itemize
32524
32525 Here are some things that are not necessary:
32526
32527 @itemize @bullet
32528 @item
32529 A description of the envelope of the bug.
32530
32531 Often people who encounter a bug spend a lot of time investigating
32532 which changes to the input file will make the bug go away and which
32533 changes will not affect it.
32534
32535 This is often time consuming and not very useful, because the way we
32536 will find the bug is by running a single example under the debugger
32537 with breakpoints, not by pure deduction from a series of examples.
32538 We recommend that you save your time for something else.
32539
32540 Of course, if you can find a simpler example to report @emph{instead}
32541 of the original one, that is a convenience for us. Errors in the
32542 output will be easier to spot, running under the debugger will take
32543 less time, and so on.
32544
32545 However, simplification is not vital; if you do not want to do this,
32546 report the bug anyway and send us the entire test case you used.
32547
32548 @item
32549 A patch for the bug.
32550
32551 A patch for the bug does help us if it is a good one. But do not omit
32552 the necessary information, such as the test case, on the assumption that
32553 a patch is all we need. We might see problems with your patch and decide
32554 to fix the problem another way, or we might not understand it at all.
32555
32556 Sometimes with a program as complicated as @value{GDBN} it is very hard to
32557 construct an example that will make the program follow a certain path
32558 through the code. If you do not send us the example, we will not be able
32559 to construct one, so we will not be able to verify that the bug is fixed.
32560
32561 And if we cannot understand what bug you are trying to fix, or why your
32562 patch should be an improvement, we will not install it. A test case will
32563 help us to understand.
32564
32565 @item
32566 A guess about what the bug is or what it depends on.
32567
32568 Such guesses are usually wrong. Even we cannot guess right about such
32569 things without first using the debugger to find the facts.
32570 @end itemize
32571
32572 @c The readline documentation is distributed with the readline code
32573 @c and consists of the two following files:
32574 @c rluser.texi
32575 @c hsuser.texi
32576 @c Use -I with makeinfo to point to the appropriate directory,
32577 @c environment var TEXINPUTS with TeX.
32578 @ifclear SYSTEM_READLINE
32579 @include rluser.texi
32580 @include hsuser.texi
32581 @end ifclear
32582
32583 @node In Memoriam
32584 @appendix In Memoriam
32585
32586 The @value{GDBN} project mourns the loss of the following long-time
32587 contributors:
32588
32589 @table @code
32590 @item Fred Fish
32591 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
32592 to Free Software in general. Outside of @value{GDBN}, he was known in
32593 the Amiga world for his series of Fish Disks, and the GeekGadget project.
32594
32595 @item Michael Snyder
32596 Michael was one of the Global Maintainers of the @value{GDBN} project,
32597 with contributions recorded as early as 1996, until 2011. In addition
32598 to his day to day participation, he was a large driving force behind
32599 adding Reverse Debugging to @value{GDBN}.
32600 @end table
32601
32602 Beyond their technical contributions to the project, they were also
32603 enjoyable members of the Free Software Community. We will miss them.
32604
32605 @node Formatting Documentation
32606 @appendix Formatting Documentation
32607
32608 @cindex @value{GDBN} reference card
32609 @cindex reference card
32610 The @value{GDBN} 4 release includes an already-formatted reference card, ready
32611 for printing with PostScript or Ghostscript, in the @file{gdb}
32612 subdirectory of the main source directory@footnote{In
32613 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
32614 release.}. If you can use PostScript or Ghostscript with your printer,
32615 you can print the reference card immediately with @file{refcard.ps}.
32616
32617 The release also includes the source for the reference card. You
32618 can format it, using @TeX{}, by typing:
32619
32620 @smallexample
32621 make refcard.dvi
32622 @end smallexample
32623
32624 The @value{GDBN} reference card is designed to print in @dfn{landscape}
32625 mode on US ``letter'' size paper;
32626 that is, on a sheet 11 inches wide by 8.5 inches
32627 high. You will need to specify this form of printing as an option to
32628 your @sc{dvi} output program.
32629
32630 @cindex documentation
32631
32632 All the documentation for @value{GDBN} comes as part of the machine-readable
32633 distribution. The documentation is written in Texinfo format, which is
32634 a documentation system that uses a single source file to produce both
32635 on-line information and a printed manual. You can use one of the Info
32636 formatting commands to create the on-line version of the documentation
32637 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
32638
32639 @value{GDBN} includes an already formatted copy of the on-line Info
32640 version of this manual in the @file{gdb} subdirectory. The main Info
32641 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
32642 subordinate files matching @samp{gdb.info*} in the same directory. If
32643 necessary, you can print out these files, or read them with any editor;
32644 but they are easier to read using the @code{info} subsystem in @sc{gnu}
32645 Emacs or the standalone @code{info} program, available as part of the
32646 @sc{gnu} Texinfo distribution.
32647
32648 If you want to format these Info files yourself, you need one of the
32649 Info formatting programs, such as @code{texinfo-format-buffer} or
32650 @code{makeinfo}.
32651
32652 If you have @code{makeinfo} installed, and are in the top level
32653 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
32654 version @value{GDBVN}), you can make the Info file by typing:
32655
32656 @smallexample
32657 cd gdb
32658 make gdb.info
32659 @end smallexample
32660
32661 If you want to typeset and print copies of this manual, you need @TeX{},
32662 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
32663 Texinfo definitions file.
32664
32665 @TeX{} is a typesetting program; it does not print files directly, but
32666 produces output files called @sc{dvi} files. To print a typeset
32667 document, you need a program to print @sc{dvi} files. If your system
32668 has @TeX{} installed, chances are it has such a program. The precise
32669 command to use depends on your system; @kbd{lpr -d} is common; another
32670 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
32671 require a file name without any extension or a @samp{.dvi} extension.
32672
32673 @TeX{} also requires a macro definitions file called
32674 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
32675 written in Texinfo format. On its own, @TeX{} cannot either read or
32676 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
32677 and is located in the @file{gdb-@var{version-number}/texinfo}
32678 directory.
32679
32680 If you have @TeX{} and a @sc{dvi} printer program installed, you can
32681 typeset and print this manual. First switch to the @file{gdb}
32682 subdirectory of the main source directory (for example, to
32683 @file{gdb-@value{GDBVN}/gdb}) and type:
32684
32685 @smallexample
32686 make gdb.dvi
32687 @end smallexample
32688
32689 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
32690
32691 @node Installing GDB
32692 @appendix Installing @value{GDBN}
32693 @cindex installation
32694
32695 @menu
32696 * Requirements:: Requirements for building @value{GDBN}
32697 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
32698 * Separate Objdir:: Compiling @value{GDBN} in another directory
32699 * Config Names:: Specifying names for hosts and targets
32700 * Configure Options:: Summary of options for configure
32701 * System-wide configuration:: Having a system-wide init file
32702 @end menu
32703
32704 @node Requirements
32705 @section Requirements for Building @value{GDBN}
32706 @cindex building @value{GDBN}, requirements for
32707
32708 Building @value{GDBN} requires various tools and packages to be available.
32709 Other packages will be used only if they are found.
32710
32711 @heading Tools/Packages Necessary for Building @value{GDBN}
32712 @table @asis
32713 @item ISO C90 compiler
32714 @value{GDBN} is written in ISO C90. It should be buildable with any
32715 working C90 compiler, e.g.@: GCC.
32716
32717 @end table
32718
32719 @heading Tools/Packages Optional for Building @value{GDBN}
32720 @table @asis
32721 @item Expat
32722 @anchor{Expat}
32723 @value{GDBN} can use the Expat XML parsing library. This library may be
32724 included with your operating system distribution; if it is not, you
32725 can get the latest version from @url{http://expat.sourceforge.net}.
32726 The @file{configure} script will search for this library in several
32727 standard locations; if it is installed in an unusual path, you can
32728 use the @option{--with-libexpat-prefix} option to specify its location.
32729
32730 Expat is used for:
32731
32732 @itemize @bullet
32733 @item
32734 Remote protocol memory maps (@pxref{Memory Map Format})
32735 @item
32736 Target descriptions (@pxref{Target Descriptions})
32737 @item
32738 Remote shared library lists (@xref{Library List Format},
32739 or alternatively @pxref{Library List Format for SVR4 Targets})
32740 @item
32741 MS-Windows shared libraries (@pxref{Shared Libraries})
32742 @item
32743 Traceframe info (@pxref{Traceframe Info Format})
32744 @end itemize
32745
32746 @item zlib
32747 @cindex compressed debug sections
32748 @value{GDBN} will use the @samp{zlib} library, if available, to read
32749 compressed debug sections. Some linkers, such as GNU gold, are capable
32750 of producing binaries with compressed debug sections. If @value{GDBN}
32751 is compiled with @samp{zlib}, it will be able to read the debug
32752 information in such binaries.
32753
32754 The @samp{zlib} library is likely included with your operating system
32755 distribution; if it is not, you can get the latest version from
32756 @url{http://zlib.net}.
32757
32758 @item iconv
32759 @value{GDBN}'s features related to character sets (@pxref{Character
32760 Sets}) require a functioning @code{iconv} implementation. If you are
32761 on a GNU system, then this is provided by the GNU C Library. Some
32762 other systems also provide a working @code{iconv}.
32763
32764 If @value{GDBN} is using the @code{iconv} program which is installed
32765 in a non-standard place, you will need to tell @value{GDBN} where to find it.
32766 This is done with @option{--with-iconv-bin} which specifies the
32767 directory that contains the @code{iconv} program.
32768
32769 On systems without @code{iconv}, you can install GNU Libiconv. If you
32770 have previously installed Libiconv, you can use the
32771 @option{--with-libiconv-prefix} option to configure.
32772
32773 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
32774 arrange to build Libiconv if a directory named @file{libiconv} appears
32775 in the top-most source directory. If Libiconv is built this way, and
32776 if the operating system does not provide a suitable @code{iconv}
32777 implementation, then the just-built library will automatically be used
32778 by @value{GDBN}. One easy way to set this up is to download GNU
32779 Libiconv, unpack it, and then rename the directory holding the
32780 Libiconv source code to @samp{libiconv}.
32781 @end table
32782
32783 @node Running Configure
32784 @section Invoking the @value{GDBN} @file{configure} Script
32785 @cindex configuring @value{GDBN}
32786 @value{GDBN} comes with a @file{configure} script that automates the process
32787 of preparing @value{GDBN} for installation; you can then use @code{make} to
32788 build the @code{gdb} program.
32789 @iftex
32790 @c irrelevant in info file; it's as current as the code it lives with.
32791 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
32792 look at the @file{README} file in the sources; we may have improved the
32793 installation procedures since publishing this manual.}
32794 @end iftex
32795
32796 The @value{GDBN} distribution includes all the source code you need for
32797 @value{GDBN} in a single directory, whose name is usually composed by
32798 appending the version number to @samp{gdb}.
32799
32800 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
32801 @file{gdb-@value{GDBVN}} directory. That directory contains:
32802
32803 @table @code
32804 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
32805 script for configuring @value{GDBN} and all its supporting libraries
32806
32807 @item gdb-@value{GDBVN}/gdb
32808 the source specific to @value{GDBN} itself
32809
32810 @item gdb-@value{GDBVN}/bfd
32811 source for the Binary File Descriptor library
32812
32813 @item gdb-@value{GDBVN}/include
32814 @sc{gnu} include files
32815
32816 @item gdb-@value{GDBVN}/libiberty
32817 source for the @samp{-liberty} free software library
32818
32819 @item gdb-@value{GDBVN}/opcodes
32820 source for the library of opcode tables and disassemblers
32821
32822 @item gdb-@value{GDBVN}/readline
32823 source for the @sc{gnu} command-line interface
32824
32825 @item gdb-@value{GDBVN}/glob
32826 source for the @sc{gnu} filename pattern-matching subroutine
32827
32828 @item gdb-@value{GDBVN}/mmalloc
32829 source for the @sc{gnu} memory-mapped malloc package
32830 @end table
32831
32832 The simplest way to configure and build @value{GDBN} is to run @file{configure}
32833 from the @file{gdb-@var{version-number}} source directory, which in
32834 this example is the @file{gdb-@value{GDBVN}} directory.
32835
32836 First switch to the @file{gdb-@var{version-number}} source directory
32837 if you are not already in it; then run @file{configure}. Pass the
32838 identifier for the platform on which @value{GDBN} will run as an
32839 argument.
32840
32841 For example:
32842
32843 @smallexample
32844 cd gdb-@value{GDBVN}
32845 ./configure @var{host}
32846 make
32847 @end smallexample
32848
32849 @noindent
32850 where @var{host} is an identifier such as @samp{sun4} or
32851 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
32852 (You can often leave off @var{host}; @file{configure} tries to guess the
32853 correct value by examining your system.)
32854
32855 Running @samp{configure @var{host}} and then running @code{make} builds the
32856 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
32857 libraries, then @code{gdb} itself. The configured source files, and the
32858 binaries, are left in the corresponding source directories.
32859
32860 @need 750
32861 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
32862 system does not recognize this automatically when you run a different
32863 shell, you may need to run @code{sh} on it explicitly:
32864
32865 @smallexample
32866 sh configure @var{host}
32867 @end smallexample
32868
32869 If you run @file{configure} from a directory that contains source
32870 directories for multiple libraries or programs, such as the
32871 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
32872 @file{configure}
32873 creates configuration files for every directory level underneath (unless
32874 you tell it not to, with the @samp{--norecursion} option).
32875
32876 You should run the @file{configure} script from the top directory in the
32877 source tree, the @file{gdb-@var{version-number}} directory. If you run
32878 @file{configure} from one of the subdirectories, you will configure only
32879 that subdirectory. That is usually not what you want. In particular,
32880 if you run the first @file{configure} from the @file{gdb} subdirectory
32881 of the @file{gdb-@var{version-number}} directory, you will omit the
32882 configuration of @file{bfd}, @file{readline}, and other sibling
32883 directories of the @file{gdb} subdirectory. This leads to build errors
32884 about missing include files such as @file{bfd/bfd.h}.
32885
32886 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
32887 However, you should make sure that the shell on your path (named by
32888 the @samp{SHELL} environment variable) is publicly readable. Remember
32889 that @value{GDBN} uses the shell to start your program---some systems refuse to
32890 let @value{GDBN} debug child processes whose programs are not readable.
32891
32892 @node Separate Objdir
32893 @section Compiling @value{GDBN} in Another Directory
32894
32895 If you want to run @value{GDBN} versions for several host or target machines,
32896 you need a different @code{gdb} compiled for each combination of
32897 host and target. @file{configure} is designed to make this easy by
32898 allowing you to generate each configuration in a separate subdirectory,
32899 rather than in the source directory. If your @code{make} program
32900 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
32901 @code{make} in each of these directories builds the @code{gdb}
32902 program specified there.
32903
32904 To build @code{gdb} in a separate directory, run @file{configure}
32905 with the @samp{--srcdir} option to specify where to find the source.
32906 (You also need to specify a path to find @file{configure}
32907 itself from your working directory. If the path to @file{configure}
32908 would be the same as the argument to @samp{--srcdir}, you can leave out
32909 the @samp{--srcdir} option; it is assumed.)
32910
32911 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
32912 separate directory for a Sun 4 like this:
32913
32914 @smallexample
32915 @group
32916 cd gdb-@value{GDBVN}
32917 mkdir ../gdb-sun4
32918 cd ../gdb-sun4
32919 ../gdb-@value{GDBVN}/configure sun4
32920 make
32921 @end group
32922 @end smallexample
32923
32924 When @file{configure} builds a configuration using a remote source
32925 directory, it creates a tree for the binaries with the same structure
32926 (and using the same names) as the tree under the source directory. In
32927 the example, you'd find the Sun 4 library @file{libiberty.a} in the
32928 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
32929 @file{gdb-sun4/gdb}.
32930
32931 Make sure that your path to the @file{configure} script has just one
32932 instance of @file{gdb} in it. If your path to @file{configure} looks
32933 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
32934 one subdirectory of @value{GDBN}, not the whole package. This leads to
32935 build errors about missing include files such as @file{bfd/bfd.h}.
32936
32937 One popular reason to build several @value{GDBN} configurations in separate
32938 directories is to configure @value{GDBN} for cross-compiling (where
32939 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
32940 programs that run on another machine---the @dfn{target}).
32941 You specify a cross-debugging target by
32942 giving the @samp{--target=@var{target}} option to @file{configure}.
32943
32944 When you run @code{make} to build a program or library, you must run
32945 it in a configured directory---whatever directory you were in when you
32946 called @file{configure} (or one of its subdirectories).
32947
32948 The @code{Makefile} that @file{configure} generates in each source
32949 directory also runs recursively. If you type @code{make} in a source
32950 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
32951 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
32952 will build all the required libraries, and then build GDB.
32953
32954 When you have multiple hosts or targets configured in separate
32955 directories, you can run @code{make} on them in parallel (for example,
32956 if they are NFS-mounted on each of the hosts); they will not interfere
32957 with each other.
32958
32959 @node Config Names
32960 @section Specifying Names for Hosts and Targets
32961
32962 The specifications used for hosts and targets in the @file{configure}
32963 script are based on a three-part naming scheme, but some short predefined
32964 aliases are also supported. The full naming scheme encodes three pieces
32965 of information in the following pattern:
32966
32967 @smallexample
32968 @var{architecture}-@var{vendor}-@var{os}
32969 @end smallexample
32970
32971 For example, you can use the alias @code{sun4} as a @var{host} argument,
32972 or as the value for @var{target} in a @code{--target=@var{target}}
32973 option. The equivalent full name is @samp{sparc-sun-sunos4}.
32974
32975 The @file{configure} script accompanying @value{GDBN} does not provide
32976 any query facility to list all supported host and target names or
32977 aliases. @file{configure} calls the Bourne shell script
32978 @code{config.sub} to map abbreviations to full names; you can read the
32979 script, if you wish, or you can use it to test your guesses on
32980 abbreviations---for example:
32981
32982 @smallexample
32983 % sh config.sub i386-linux
32984 i386-pc-linux-gnu
32985 % sh config.sub alpha-linux
32986 alpha-unknown-linux-gnu
32987 % sh config.sub hp9k700
32988 hppa1.1-hp-hpux
32989 % sh config.sub sun4
32990 sparc-sun-sunos4.1.1
32991 % sh config.sub sun3
32992 m68k-sun-sunos4.1.1
32993 % sh config.sub i986v
32994 Invalid configuration `i986v': machine `i986v' not recognized
32995 @end smallexample
32996
32997 @noindent
32998 @code{config.sub} is also distributed in the @value{GDBN} source
32999 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
33000
33001 @node Configure Options
33002 @section @file{configure} Options
33003
33004 Here is a summary of the @file{configure} options and arguments that
33005 are most often useful for building @value{GDBN}. @file{configure} also has
33006 several other options not listed here. @inforef{What Configure
33007 Does,,configure.info}, for a full explanation of @file{configure}.
33008
33009 @smallexample
33010 configure @r{[}--help@r{]}
33011 @r{[}--prefix=@var{dir}@r{]}
33012 @r{[}--exec-prefix=@var{dir}@r{]}
33013 @r{[}--srcdir=@var{dirname}@r{]}
33014 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
33015 @r{[}--target=@var{target}@r{]}
33016 @var{host}
33017 @end smallexample
33018
33019 @noindent
33020 You may introduce options with a single @samp{-} rather than
33021 @samp{--} if you prefer; but you may abbreviate option names if you use
33022 @samp{--}.
33023
33024 @table @code
33025 @item --help
33026 Display a quick summary of how to invoke @file{configure}.
33027
33028 @item --prefix=@var{dir}
33029 Configure the source to install programs and files under directory
33030 @file{@var{dir}}.
33031
33032 @item --exec-prefix=@var{dir}
33033 Configure the source to install programs under directory
33034 @file{@var{dir}}.
33035
33036 @c avoid splitting the warning from the explanation:
33037 @need 2000
33038 @item --srcdir=@var{dirname}
33039 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
33040 @code{make} that implements the @code{VPATH} feature.}@*
33041 Use this option to make configurations in directories separate from the
33042 @value{GDBN} source directories. Among other things, you can use this to
33043 build (or maintain) several configurations simultaneously, in separate
33044 directories. @file{configure} writes configuration-specific files in
33045 the current directory, but arranges for them to use the source in the
33046 directory @var{dirname}. @file{configure} creates directories under
33047 the working directory in parallel to the source directories below
33048 @var{dirname}.
33049
33050 @item --norecursion
33051 Configure only the directory level where @file{configure} is executed; do not
33052 propagate configuration to subdirectories.
33053
33054 @item --target=@var{target}
33055 Configure @value{GDBN} for cross-debugging programs running on the specified
33056 @var{target}. Without this option, @value{GDBN} is configured to debug
33057 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
33058
33059 There is no convenient way to generate a list of all available targets.
33060
33061 @item @var{host} @dots{}
33062 Configure @value{GDBN} to run on the specified @var{host}.
33063
33064 There is no convenient way to generate a list of all available hosts.
33065 @end table
33066
33067 There are many other options available as well, but they are generally
33068 needed for special purposes only.
33069
33070 @node System-wide configuration
33071 @section System-wide configuration and settings
33072 @cindex system-wide init file
33073
33074 @value{GDBN} can be configured to have a system-wide init file;
33075 this file will be read and executed at startup (@pxref{Startup, , What
33076 @value{GDBN} does during startup}).
33077
33078 Here is the corresponding configure option:
33079
33080 @table @code
33081 @item --with-system-gdbinit=@var{file}
33082 Specify that the default location of the system-wide init file is
33083 @var{file}.
33084 @end table
33085
33086 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
33087 it may be subject to relocation. Two possible cases:
33088
33089 @itemize @bullet
33090 @item
33091 If the default location of this init file contains @file{$prefix},
33092 it will be subject to relocation. Suppose that the configure options
33093 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
33094 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
33095 init file is looked for as @file{$install/etc/gdbinit} instead of
33096 @file{$prefix/etc/gdbinit}.
33097
33098 @item
33099 By contrast, if the default location does not contain the prefix,
33100 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
33101 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
33102 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
33103 wherever @value{GDBN} is installed.
33104 @end itemize
33105
33106 @node Maintenance Commands
33107 @appendix Maintenance Commands
33108 @cindex maintenance commands
33109 @cindex internal commands
33110
33111 In addition to commands intended for @value{GDBN} users, @value{GDBN}
33112 includes a number of commands intended for @value{GDBN} developers,
33113 that are not documented elsewhere in this manual. These commands are
33114 provided here for reference. (For commands that turn on debugging
33115 messages, see @ref{Debugging Output}.)
33116
33117 @table @code
33118 @kindex maint agent
33119 @kindex maint agent-eval
33120 @item maint agent @var{expression}
33121 @itemx maint agent-eval @var{expression}
33122 Translate the given @var{expression} into remote agent bytecodes.
33123 This command is useful for debugging the Agent Expression mechanism
33124 (@pxref{Agent Expressions}). The @samp{agent} version produces an
33125 expression useful for data collection, such as by tracepoints, while
33126 @samp{maint agent-eval} produces an expression that evaluates directly
33127 to a result. For instance, a collection expression for @code{globa +
33128 globb} will include bytecodes to record four bytes of memory at each
33129 of the addresses of @code{globa} and @code{globb}, while discarding
33130 the result of the addition, while an evaluation expression will do the
33131 addition and return the sum.
33132
33133 @kindex maint info breakpoints
33134 @item @anchor{maint info breakpoints}maint info breakpoints
33135 Using the same format as @samp{info breakpoints}, display both the
33136 breakpoints you've set explicitly, and those @value{GDBN} is using for
33137 internal purposes. Internal breakpoints are shown with negative
33138 breakpoint numbers. The type column identifies what kind of breakpoint
33139 is shown:
33140
33141 @table @code
33142 @item breakpoint
33143 Normal, explicitly set breakpoint.
33144
33145 @item watchpoint
33146 Normal, explicitly set watchpoint.
33147
33148 @item longjmp
33149 Internal breakpoint, used to handle correctly stepping through
33150 @code{longjmp} calls.
33151
33152 @item longjmp resume
33153 Internal breakpoint at the target of a @code{longjmp}.
33154
33155 @item until
33156 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
33157
33158 @item finish
33159 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
33160
33161 @item shlib events
33162 Shared library events.
33163
33164 @end table
33165
33166 @kindex set displaced-stepping
33167 @kindex show displaced-stepping
33168 @cindex displaced stepping support
33169 @cindex out-of-line single-stepping
33170 @item set displaced-stepping
33171 @itemx show displaced-stepping
33172 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
33173 if the target supports it. Displaced stepping is a way to single-step
33174 over breakpoints without removing them from the inferior, by executing
33175 an out-of-line copy of the instruction that was originally at the
33176 breakpoint location. It is also known as out-of-line single-stepping.
33177
33178 @table @code
33179 @item set displaced-stepping on
33180 If the target architecture supports it, @value{GDBN} will use
33181 displaced stepping to step over breakpoints.
33182
33183 @item set displaced-stepping off
33184 @value{GDBN} will not use displaced stepping to step over breakpoints,
33185 even if such is supported by the target architecture.
33186
33187 @cindex non-stop mode, and @samp{set displaced-stepping}
33188 @item set displaced-stepping auto
33189 This is the default mode. @value{GDBN} will use displaced stepping
33190 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
33191 architecture supports displaced stepping.
33192 @end table
33193
33194 @kindex maint check-symtabs
33195 @item maint check-symtabs
33196 Check the consistency of psymtabs and symtabs.
33197
33198 @kindex maint cplus first_component
33199 @item maint cplus first_component @var{name}
33200 Print the first C@t{++} class/namespace component of @var{name}.
33201
33202 @kindex maint cplus namespace
33203 @item maint cplus namespace
33204 Print the list of possible C@t{++} namespaces.
33205
33206 @kindex maint demangle
33207 @item maint demangle @var{name}
33208 Demangle a C@t{++} or Objective-C mangled @var{name}.
33209
33210 @kindex maint deprecate
33211 @kindex maint undeprecate
33212 @cindex deprecated commands
33213 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
33214 @itemx maint undeprecate @var{command}
33215 Deprecate or undeprecate the named @var{command}. Deprecated commands
33216 cause @value{GDBN} to issue a warning when you use them. The optional
33217 argument @var{replacement} says which newer command should be used in
33218 favor of the deprecated one; if it is given, @value{GDBN} will mention
33219 the replacement as part of the warning.
33220
33221 @kindex maint dump-me
33222 @item maint dump-me
33223 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
33224 Cause a fatal signal in the debugger and force it to dump its core.
33225 This is supported only on systems which support aborting a program
33226 with the @code{SIGQUIT} signal.
33227
33228 @kindex maint internal-error
33229 @kindex maint internal-warning
33230 @item maint internal-error @r{[}@var{message-text}@r{]}
33231 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
33232 Cause @value{GDBN} to call the internal function @code{internal_error}
33233 or @code{internal_warning} and hence behave as though an internal error
33234 or internal warning has been detected. In addition to reporting the
33235 internal problem, these functions give the user the opportunity to
33236 either quit @value{GDBN} or create a core file of the current
33237 @value{GDBN} session.
33238
33239 These commands take an optional parameter @var{message-text} that is
33240 used as the text of the error or warning message.
33241
33242 Here's an example of using @code{internal-error}:
33243
33244 @smallexample
33245 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
33246 @dots{}/maint.c:121: internal-error: testing, 1, 2
33247 A problem internal to GDB has been detected. Further
33248 debugging may prove unreliable.
33249 Quit this debugging session? (y or n) @kbd{n}
33250 Create a core file? (y or n) @kbd{n}
33251 (@value{GDBP})
33252 @end smallexample
33253
33254 @cindex @value{GDBN} internal error
33255 @cindex internal errors, control of @value{GDBN} behavior
33256
33257 @kindex maint set internal-error
33258 @kindex maint show internal-error
33259 @kindex maint set internal-warning
33260 @kindex maint show internal-warning
33261 @item maint set internal-error @var{action} [ask|yes|no]
33262 @itemx maint show internal-error @var{action}
33263 @itemx maint set internal-warning @var{action} [ask|yes|no]
33264 @itemx maint show internal-warning @var{action}
33265 When @value{GDBN} reports an internal problem (error or warning) it
33266 gives the user the opportunity to both quit @value{GDBN} and create a
33267 core file of the current @value{GDBN} session. These commands let you
33268 override the default behaviour for each particular @var{action},
33269 described in the table below.
33270
33271 @table @samp
33272 @item quit
33273 You can specify that @value{GDBN} should always (yes) or never (no)
33274 quit. The default is to ask the user what to do.
33275
33276 @item corefile
33277 You can specify that @value{GDBN} should always (yes) or never (no)
33278 create a core file. The default is to ask the user what to do.
33279 @end table
33280
33281 @kindex maint packet
33282 @item maint packet @var{text}
33283 If @value{GDBN} is talking to an inferior via the serial protocol,
33284 then this command sends the string @var{text} to the inferior, and
33285 displays the response packet. @value{GDBN} supplies the initial
33286 @samp{$} character, the terminating @samp{#} character, and the
33287 checksum.
33288
33289 @kindex maint print architecture
33290 @item maint print architecture @r{[}@var{file}@r{]}
33291 Print the entire architecture configuration. The optional argument
33292 @var{file} names the file where the output goes.
33293
33294 @kindex maint print c-tdesc
33295 @item maint print c-tdesc
33296 Print the current target description (@pxref{Target Descriptions}) as
33297 a C source file. The created source file can be used in @value{GDBN}
33298 when an XML parser is not available to parse the description.
33299
33300 @kindex maint print dummy-frames
33301 @item maint print dummy-frames
33302 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
33303
33304 @smallexample
33305 (@value{GDBP}) @kbd{b add}
33306 @dots{}
33307 (@value{GDBP}) @kbd{print add(2,3)}
33308 Breakpoint 2, add (a=2, b=3) at @dots{}
33309 58 return (a + b);
33310 The program being debugged stopped while in a function called from GDB.
33311 @dots{}
33312 (@value{GDBP}) @kbd{maint print dummy-frames}
33313 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
33314 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
33315 call_lo=0x01014000 call_hi=0x01014001
33316 (@value{GDBP})
33317 @end smallexample
33318
33319 Takes an optional file parameter.
33320
33321 @kindex maint print registers
33322 @kindex maint print raw-registers
33323 @kindex maint print cooked-registers
33324 @kindex maint print register-groups
33325 @kindex maint print remote-registers
33326 @item maint print registers @r{[}@var{file}@r{]}
33327 @itemx maint print raw-registers @r{[}@var{file}@r{]}
33328 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
33329 @itemx maint print register-groups @r{[}@var{file}@r{]}
33330 @itemx maint print remote-registers @r{[}@var{file}@r{]}
33331 Print @value{GDBN}'s internal register data structures.
33332
33333 The command @code{maint print raw-registers} includes the contents of
33334 the raw register cache; the command @code{maint print
33335 cooked-registers} includes the (cooked) value of all registers,
33336 including registers which aren't available on the target nor visible
33337 to user; the command @code{maint print register-groups} includes the
33338 groups that each register is a member of; and the command @code{maint
33339 print remote-registers} includes the remote target's register numbers
33340 and offsets in the `G' packets. @xref{Registers,, Registers, gdbint,
33341 @value{GDBN} Internals}.
33342
33343 These commands take an optional parameter, a file name to which to
33344 write the information.
33345
33346 @kindex maint print reggroups
33347 @item maint print reggroups @r{[}@var{file}@r{]}
33348 Print @value{GDBN}'s internal register group data structures. The
33349 optional argument @var{file} tells to what file to write the
33350 information.
33351
33352 The register groups info looks like this:
33353
33354 @smallexample
33355 (@value{GDBP}) @kbd{maint print reggroups}
33356 Group Type
33357 general user
33358 float user
33359 all user
33360 vector user
33361 system user
33362 save internal
33363 restore internal
33364 @end smallexample
33365
33366 @kindex flushregs
33367 @item flushregs
33368 This command forces @value{GDBN} to flush its internal register cache.
33369
33370 @kindex maint print objfiles
33371 @cindex info for known object files
33372 @item maint print objfiles
33373 Print a dump of all known object files. For each object file, this
33374 command prints its name, address in memory, and all of its psymtabs
33375 and symtabs.
33376
33377 @kindex maint print section-scripts
33378 @cindex info for known .debug_gdb_scripts-loaded scripts
33379 @item maint print section-scripts [@var{regexp}]
33380 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
33381 If @var{regexp} is specified, only print scripts loaded by object files
33382 matching @var{regexp}.
33383 For each script, this command prints its name as specified in the objfile,
33384 and the full path if known.
33385 @xref{.debug_gdb_scripts section}.
33386
33387 @kindex maint print statistics
33388 @cindex bcache statistics
33389 @item maint print statistics
33390 This command prints, for each object file in the program, various data
33391 about that object file followed by the byte cache (@dfn{bcache})
33392 statistics for the object file. The objfile data includes the number
33393 of minimal, partial, full, and stabs symbols, the number of types
33394 defined by the objfile, the number of as yet unexpanded psym tables,
33395 the number of line tables and string tables, and the amount of memory
33396 used by the various tables. The bcache statistics include the counts,
33397 sizes, and counts of duplicates of all and unique objects, max,
33398 average, and median entry size, total memory used and its overhead and
33399 savings, and various measures of the hash table size and chain
33400 lengths.
33401
33402 @kindex maint print target-stack
33403 @cindex target stack description
33404 @item maint print target-stack
33405 A @dfn{target} is an interface between the debugger and a particular
33406 kind of file or process. Targets can be stacked in @dfn{strata},
33407 so that more than one target can potentially respond to a request.
33408 In particular, memory accesses will walk down the stack of targets
33409 until they find a target that is interested in handling that particular
33410 address.
33411
33412 This command prints a short description of each layer that was pushed on
33413 the @dfn{target stack}, starting from the top layer down to the bottom one.
33414
33415 @kindex maint print type
33416 @cindex type chain of a data type
33417 @item maint print type @var{expr}
33418 Print the type chain for a type specified by @var{expr}. The argument
33419 can be either a type name or a symbol. If it is a symbol, the type of
33420 that symbol is described. The type chain produced by this command is
33421 a recursive definition of the data type as stored in @value{GDBN}'s
33422 data structures, including its flags and contained types.
33423
33424 @kindex maint set dwarf2 always-disassemble
33425 @kindex maint show dwarf2 always-disassemble
33426 @item maint set dwarf2 always-disassemble
33427 @item maint show dwarf2 always-disassemble
33428 Control the behavior of @code{info address} when using DWARF debugging
33429 information.
33430
33431 The default is @code{off}, which means that @value{GDBN} should try to
33432 describe a variable's location in an easily readable format. When
33433 @code{on}, @value{GDBN} will instead display the DWARF location
33434 expression in an assembly-like format. Note that some locations are
33435 too complex for @value{GDBN} to describe simply; in this case you will
33436 always see the disassembly form.
33437
33438 Here is an example of the resulting disassembly:
33439
33440 @smallexample
33441 (gdb) info addr argc
33442 Symbol "argc" is a complex DWARF expression:
33443 1: DW_OP_fbreg 0
33444 @end smallexample
33445
33446 For more information on these expressions, see
33447 @uref{http://www.dwarfstd.org/, the DWARF standard}.
33448
33449 @kindex maint set dwarf2 max-cache-age
33450 @kindex maint show dwarf2 max-cache-age
33451 @item maint set dwarf2 max-cache-age
33452 @itemx maint show dwarf2 max-cache-age
33453 Control the DWARF 2 compilation unit cache.
33454
33455 @cindex DWARF 2 compilation units cache
33456 In object files with inter-compilation-unit references, such as those
33457 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
33458 reader needs to frequently refer to previously read compilation units.
33459 This setting controls how long a compilation unit will remain in the
33460 cache if it is not referenced. A higher limit means that cached
33461 compilation units will be stored in memory longer, and more total
33462 memory will be used. Setting it to zero disables caching, which will
33463 slow down @value{GDBN} startup, but reduce memory consumption.
33464
33465 @kindex maint set profile
33466 @kindex maint show profile
33467 @cindex profiling GDB
33468 @item maint set profile
33469 @itemx maint show profile
33470 Control profiling of @value{GDBN}.
33471
33472 Profiling will be disabled until you use the @samp{maint set profile}
33473 command to enable it. When you enable profiling, the system will begin
33474 collecting timing and execution count data; when you disable profiling or
33475 exit @value{GDBN}, the results will be written to a log file. Remember that
33476 if you use profiling, @value{GDBN} will overwrite the profiling log file
33477 (often called @file{gmon.out}). If you have a record of important profiling
33478 data in a @file{gmon.out} file, be sure to move it to a safe location.
33479
33480 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
33481 compiled with the @samp{-pg} compiler option.
33482
33483 @kindex maint set show-debug-regs
33484 @kindex maint show show-debug-regs
33485 @cindex hardware debug registers
33486 @item maint set show-debug-regs
33487 @itemx maint show show-debug-regs
33488 Control whether to show variables that mirror the hardware debug
33489 registers. Use @code{ON} to enable, @code{OFF} to disable. If
33490 enabled, the debug registers values are shown when @value{GDBN} inserts or
33491 removes a hardware breakpoint or watchpoint, and when the inferior
33492 triggers a hardware-assisted breakpoint or watchpoint.
33493
33494 @kindex maint set show-all-tib
33495 @kindex maint show show-all-tib
33496 @item maint set show-all-tib
33497 @itemx maint show show-all-tib
33498 Control whether to show all non zero areas within a 1k block starting
33499 at thread local base, when using the @samp{info w32 thread-information-block}
33500 command.
33501
33502 @kindex maint space
33503 @cindex memory used by commands
33504 @item maint space
33505 Control whether to display memory usage for each command. If set to a
33506 nonzero value, @value{GDBN} will display how much memory each command
33507 took, following the command's own output. This can also be requested
33508 by invoking @value{GDBN} with the @option{--statistics} command-line
33509 switch (@pxref{Mode Options}).
33510
33511 @kindex maint time
33512 @cindex time of command execution
33513 @item maint time
33514 Control whether to display the execution time of @value{GDBN} for each command.
33515 If set to a nonzero value, @value{GDBN} will display how much time it
33516 took to execute each command, following the command's own output.
33517 Both CPU time and wallclock time are printed.
33518 Printing both is useful when trying to determine whether the cost is
33519 CPU or, e.g., disk/network, latency.
33520 Note that the CPU time printed is for @value{GDBN} only, it does not include
33521 the execution time of the inferior because there's no mechanism currently
33522 to compute how much time was spent by @value{GDBN} and how much time was
33523 spent by the program been debugged.
33524 This can also be requested by invoking @value{GDBN} with the
33525 @option{--statistics} command-line switch (@pxref{Mode Options}).
33526
33527 @kindex maint translate-address
33528 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
33529 Find the symbol stored at the location specified by the address
33530 @var{addr} and an optional section name @var{section}. If found,
33531 @value{GDBN} prints the name of the closest symbol and an offset from
33532 the symbol's location to the specified address. This is similar to
33533 the @code{info address} command (@pxref{Symbols}), except that this
33534 command also allows to find symbols in other sections.
33535
33536 If section was not specified, the section in which the symbol was found
33537 is also printed. For dynamically linked executables, the name of
33538 executable or shared library containing the symbol is printed as well.
33539
33540 @end table
33541
33542 The following command is useful for non-interactive invocations of
33543 @value{GDBN}, such as in the test suite.
33544
33545 @table @code
33546 @item set watchdog @var{nsec}
33547 @kindex set watchdog
33548 @cindex watchdog timer
33549 @cindex timeout for commands
33550 Set the maximum number of seconds @value{GDBN} will wait for the
33551 target operation to finish. If this time expires, @value{GDBN}
33552 reports and error and the command is aborted.
33553
33554 @item show watchdog
33555 Show the current setting of the target wait timeout.
33556 @end table
33557
33558 @node Remote Protocol
33559 @appendix @value{GDBN} Remote Serial Protocol
33560
33561 @menu
33562 * Overview::
33563 * Packets::
33564 * Stop Reply Packets::
33565 * General Query Packets::
33566 * Architecture-Specific Protocol Details::
33567 * Tracepoint Packets::
33568 * Host I/O Packets::
33569 * Interrupts::
33570 * Notification Packets::
33571 * Remote Non-Stop::
33572 * Packet Acknowledgment::
33573 * Examples::
33574 * File-I/O Remote Protocol Extension::
33575 * Library List Format::
33576 * Library List Format for SVR4 Targets::
33577 * Memory Map Format::
33578 * Thread List Format::
33579 * Traceframe Info Format::
33580 @end menu
33581
33582 @node Overview
33583 @section Overview
33584
33585 There may be occasions when you need to know something about the
33586 protocol---for example, if there is only one serial port to your target
33587 machine, you might want your program to do something special if it
33588 recognizes a packet meant for @value{GDBN}.
33589
33590 In the examples below, @samp{->} and @samp{<-} are used to indicate
33591 transmitted and received data, respectively.
33592
33593 @cindex protocol, @value{GDBN} remote serial
33594 @cindex serial protocol, @value{GDBN} remote
33595 @cindex remote serial protocol
33596 All @value{GDBN} commands and responses (other than acknowledgments
33597 and notifications, see @ref{Notification Packets}) are sent as a
33598 @var{packet}. A @var{packet} is introduced with the character
33599 @samp{$}, the actual @var{packet-data}, and the terminating character
33600 @samp{#} followed by a two-digit @var{checksum}:
33601
33602 @smallexample
33603 @code{$}@var{packet-data}@code{#}@var{checksum}
33604 @end smallexample
33605 @noindent
33606
33607 @cindex checksum, for @value{GDBN} remote
33608 @noindent
33609 The two-digit @var{checksum} is computed as the modulo 256 sum of all
33610 characters between the leading @samp{$} and the trailing @samp{#} (an
33611 eight bit unsigned checksum).
33612
33613 Implementors should note that prior to @value{GDBN} 5.0 the protocol
33614 specification also included an optional two-digit @var{sequence-id}:
33615
33616 @smallexample
33617 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
33618 @end smallexample
33619
33620 @cindex sequence-id, for @value{GDBN} remote
33621 @noindent
33622 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
33623 has never output @var{sequence-id}s. Stubs that handle packets added
33624 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
33625
33626 When either the host or the target machine receives a packet, the first
33627 response expected is an acknowledgment: either @samp{+} (to indicate
33628 the package was received correctly) or @samp{-} (to request
33629 retransmission):
33630
33631 @smallexample
33632 -> @code{$}@var{packet-data}@code{#}@var{checksum}
33633 <- @code{+}
33634 @end smallexample
33635 @noindent
33636
33637 The @samp{+}/@samp{-} acknowledgments can be disabled
33638 once a connection is established.
33639 @xref{Packet Acknowledgment}, for details.
33640
33641 The host (@value{GDBN}) sends @var{command}s, and the target (the
33642 debugging stub incorporated in your program) sends a @var{response}. In
33643 the case of step and continue @var{command}s, the response is only sent
33644 when the operation has completed, and the target has again stopped all
33645 threads in all attached processes. This is the default all-stop mode
33646 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
33647 execution mode; see @ref{Remote Non-Stop}, for details.
33648
33649 @var{packet-data} consists of a sequence of characters with the
33650 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
33651 exceptions).
33652
33653 @cindex remote protocol, field separator
33654 Fields within the packet should be separated using @samp{,} @samp{;} or
33655 @samp{:}. Except where otherwise noted all numbers are represented in
33656 @sc{hex} with leading zeros suppressed.
33657
33658 Implementors should note that prior to @value{GDBN} 5.0, the character
33659 @samp{:} could not appear as the third character in a packet (as it
33660 would potentially conflict with the @var{sequence-id}).
33661
33662 @cindex remote protocol, binary data
33663 @anchor{Binary Data}
33664 Binary data in most packets is encoded either as two hexadecimal
33665 digits per byte of binary data. This allowed the traditional remote
33666 protocol to work over connections which were only seven-bit clean.
33667 Some packets designed more recently assume an eight-bit clean
33668 connection, and use a more efficient encoding to send and receive
33669 binary data.
33670
33671 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
33672 as an escape character. Any escaped byte is transmitted as the escape
33673 character followed by the original character XORed with @code{0x20}.
33674 For example, the byte @code{0x7d} would be transmitted as the two
33675 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
33676 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
33677 @samp{@}}) must always be escaped. Responses sent by the stub
33678 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
33679 is not interpreted as the start of a run-length encoded sequence
33680 (described next).
33681
33682 Response @var{data} can be run-length encoded to save space.
33683 Run-length encoding replaces runs of identical characters with one
33684 instance of the repeated character, followed by a @samp{*} and a
33685 repeat count. The repeat count is itself sent encoded, to avoid
33686 binary characters in @var{data}: a value of @var{n} is sent as
33687 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
33688 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
33689 code 32) for a repeat count of 3. (This is because run-length
33690 encoding starts to win for counts 3 or more.) Thus, for example,
33691 @samp{0* } is a run-length encoding of ``0000'': the space character
33692 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
33693 3}} more times.
33694
33695 The printable characters @samp{#} and @samp{$} or with a numeric value
33696 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
33697 seven repeats (@samp{$}) can be expanded using a repeat count of only
33698 five (@samp{"}). For example, @samp{00000000} can be encoded as
33699 @samp{0*"00}.
33700
33701 The error response returned for some packets includes a two character
33702 error number. That number is not well defined.
33703
33704 @cindex empty response, for unsupported packets
33705 For any @var{command} not supported by the stub, an empty response
33706 (@samp{$#00}) should be returned. That way it is possible to extend the
33707 protocol. A newer @value{GDBN} can tell if a packet is supported based
33708 on that response.
33709
33710 At a minimum, a stub is required to support the @samp{g} and @samp{G}
33711 commands for register access, and the @samp{m} and @samp{M} commands
33712 for memory access. Stubs that only control single-threaded targets
33713 can implement run control with the @samp{c} (continue), and @samp{s}
33714 (step) commands. Stubs that support multi-threading targets should
33715 support the @samp{vCont} command. All other commands are optional.
33716
33717 @node Packets
33718 @section Packets
33719
33720 The following table provides a complete list of all currently defined
33721 @var{command}s and their corresponding response @var{data}.
33722 @xref{File-I/O Remote Protocol Extension}, for details about the File
33723 I/O extension of the remote protocol.
33724
33725 Each packet's description has a template showing the packet's overall
33726 syntax, followed by an explanation of the packet's meaning. We
33727 include spaces in some of the templates for clarity; these are not
33728 part of the packet's syntax. No @value{GDBN} packet uses spaces to
33729 separate its components. For example, a template like @samp{foo
33730 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
33731 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
33732 @var{baz}. @value{GDBN} does not transmit a space character between the
33733 @samp{foo} and the @var{bar}, or between the @var{bar} and the
33734 @var{baz}.
33735
33736 @cindex @var{thread-id}, in remote protocol
33737 @anchor{thread-id syntax}
33738 Several packets and replies include a @var{thread-id} field to identify
33739 a thread. Normally these are positive numbers with a target-specific
33740 interpretation, formatted as big-endian hex strings. A @var{thread-id}
33741 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
33742 pick any thread.
33743
33744 In addition, the remote protocol supports a multiprocess feature in
33745 which the @var{thread-id} syntax is extended to optionally include both
33746 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
33747 The @var{pid} (process) and @var{tid} (thread) components each have the
33748 format described above: a positive number with target-specific
33749 interpretation formatted as a big-endian hex string, literal @samp{-1}
33750 to indicate all processes or threads (respectively), or @samp{0} to
33751 indicate an arbitrary process or thread. Specifying just a process, as
33752 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
33753 error to specify all processes but a specific thread, such as
33754 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
33755 for those packets and replies explicitly documented to include a process
33756 ID, rather than a @var{thread-id}.
33757
33758 The multiprocess @var{thread-id} syntax extensions are only used if both
33759 @value{GDBN} and the stub report support for the @samp{multiprocess}
33760 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
33761 more information.
33762
33763 Note that all packet forms beginning with an upper- or lower-case
33764 letter, other than those described here, are reserved for future use.
33765
33766 Here are the packet descriptions.
33767
33768 @table @samp
33769
33770 @item !
33771 @cindex @samp{!} packet
33772 @anchor{extended mode}
33773 Enable extended mode. In extended mode, the remote server is made
33774 persistent. The @samp{R} packet is used to restart the program being
33775 debugged.
33776
33777 Reply:
33778 @table @samp
33779 @item OK
33780 The remote target both supports and has enabled extended mode.
33781 @end table
33782
33783 @item ?
33784 @cindex @samp{?} packet
33785 Indicate the reason the target halted. The reply is the same as for
33786 step and continue. This packet has a special interpretation when the
33787 target is in non-stop mode; see @ref{Remote Non-Stop}.
33788
33789 Reply:
33790 @xref{Stop Reply Packets}, for the reply specifications.
33791
33792 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
33793 @cindex @samp{A} packet
33794 Initialized @code{argv[]} array passed into program. @var{arglen}
33795 specifies the number of bytes in the hex encoded byte stream
33796 @var{arg}. See @code{gdbserver} for more details.
33797
33798 Reply:
33799 @table @samp
33800 @item OK
33801 The arguments were set.
33802 @item E @var{NN}
33803 An error occurred.
33804 @end table
33805
33806 @item b @var{baud}
33807 @cindex @samp{b} packet
33808 (Don't use this packet; its behavior is not well-defined.)
33809 Change the serial line speed to @var{baud}.
33810
33811 JTC: @emph{When does the transport layer state change? When it's
33812 received, or after the ACK is transmitted. In either case, there are
33813 problems if the command or the acknowledgment packet is dropped.}
33814
33815 Stan: @emph{If people really wanted to add something like this, and get
33816 it working for the first time, they ought to modify ser-unix.c to send
33817 some kind of out-of-band message to a specially-setup stub and have the
33818 switch happen "in between" packets, so that from remote protocol's point
33819 of view, nothing actually happened.}
33820
33821 @item B @var{addr},@var{mode}
33822 @cindex @samp{B} packet
33823 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
33824 breakpoint at @var{addr}.
33825
33826 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
33827 (@pxref{insert breakpoint or watchpoint packet}).
33828
33829 @cindex @samp{bc} packet
33830 @anchor{bc}
33831 @item bc
33832 Backward continue. Execute the target system in reverse. No parameter.
33833 @xref{Reverse Execution}, for more information.
33834
33835 Reply:
33836 @xref{Stop Reply Packets}, for the reply specifications.
33837
33838 @cindex @samp{bs} packet
33839 @anchor{bs}
33840 @item bs
33841 Backward single step. Execute one instruction in reverse. No parameter.
33842 @xref{Reverse Execution}, for more information.
33843
33844 Reply:
33845 @xref{Stop Reply Packets}, for the reply specifications.
33846
33847 @item c @r{[}@var{addr}@r{]}
33848 @cindex @samp{c} packet
33849 Continue. @var{addr} is address to resume. If @var{addr} is omitted,
33850 resume at current address.
33851
33852 This packet is deprecated for multi-threading support. @xref{vCont
33853 packet}.
33854
33855 Reply:
33856 @xref{Stop Reply Packets}, for the reply specifications.
33857
33858 @item C @var{sig}@r{[};@var{addr}@r{]}
33859 @cindex @samp{C} packet
33860 Continue with signal @var{sig} (hex signal number). If
33861 @samp{;@var{addr}} is omitted, resume at same address.
33862
33863 This packet is deprecated for multi-threading support. @xref{vCont
33864 packet}.
33865
33866 Reply:
33867 @xref{Stop Reply Packets}, for the reply specifications.
33868
33869 @item d
33870 @cindex @samp{d} packet
33871 Toggle debug flag.
33872
33873 Don't use this packet; instead, define a general set packet
33874 (@pxref{General Query Packets}).
33875
33876 @item D
33877 @itemx D;@var{pid}
33878 @cindex @samp{D} packet
33879 The first form of the packet is used to detach @value{GDBN} from the
33880 remote system. It is sent to the remote target
33881 before @value{GDBN} disconnects via the @code{detach} command.
33882
33883 The second form, including a process ID, is used when multiprocess
33884 protocol extensions are enabled (@pxref{multiprocess extensions}), to
33885 detach only a specific process. The @var{pid} is specified as a
33886 big-endian hex string.
33887
33888 Reply:
33889 @table @samp
33890 @item OK
33891 for success
33892 @item E @var{NN}
33893 for an error
33894 @end table
33895
33896 @item F @var{RC},@var{EE},@var{CF};@var{XX}
33897 @cindex @samp{F} packet
33898 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
33899 This is part of the File-I/O protocol extension. @xref{File-I/O
33900 Remote Protocol Extension}, for the specification.
33901
33902 @item g
33903 @anchor{read registers packet}
33904 @cindex @samp{g} packet
33905 Read general registers.
33906
33907 Reply:
33908 @table @samp
33909 @item @var{XX@dots{}}
33910 Each byte of register data is described by two hex digits. The bytes
33911 with the register are transmitted in target byte order. The size of
33912 each register and their position within the @samp{g} packet are
33913 determined by the @value{GDBN} internal gdbarch functions
33914 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
33915 specification of several standard @samp{g} packets is specified below.
33916
33917 When reading registers from a trace frame (@pxref{Analyze Collected
33918 Data,,Using the Collected Data}), the stub may also return a string of
33919 literal @samp{x}'s in place of the register data digits, to indicate
33920 that the corresponding register has not been collected, thus its value
33921 is unavailable. For example, for an architecture with 4 registers of
33922 4 bytes each, the following reply indicates to @value{GDBN} that
33923 registers 0 and 2 have not been collected, while registers 1 and 3
33924 have been collected, and both have zero value:
33925
33926 @smallexample
33927 -> @code{g}
33928 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
33929 @end smallexample
33930
33931 @item E @var{NN}
33932 for an error.
33933 @end table
33934
33935 @item G @var{XX@dots{}}
33936 @cindex @samp{G} packet
33937 Write general registers. @xref{read registers packet}, for a
33938 description of the @var{XX@dots{}} data.
33939
33940 Reply:
33941 @table @samp
33942 @item OK
33943 for success
33944 @item E @var{NN}
33945 for an error
33946 @end table
33947
33948 @item H @var{op} @var{thread-id}
33949 @cindex @samp{H} packet
33950 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
33951 @samp{G}, et.al.). @var{op} depends on the operation to be performed:
33952 it should be @samp{c} for step and continue operations (note that this
33953 is deprecated, supporting the @samp{vCont} command is a better
33954 option), @samp{g} for other operations. The thread designator
33955 @var{thread-id} has the format and interpretation described in
33956 @ref{thread-id syntax}.
33957
33958 Reply:
33959 @table @samp
33960 @item OK
33961 for success
33962 @item E @var{NN}
33963 for an error
33964 @end table
33965
33966 @c FIXME: JTC:
33967 @c 'H': How restrictive (or permissive) is the thread model. If a
33968 @c thread is selected and stopped, are other threads allowed
33969 @c to continue to execute? As I mentioned above, I think the
33970 @c semantics of each command when a thread is selected must be
33971 @c described. For example:
33972 @c
33973 @c 'g': If the stub supports threads and a specific thread is
33974 @c selected, returns the register block from that thread;
33975 @c otherwise returns current registers.
33976 @c
33977 @c 'G' If the stub supports threads and a specific thread is
33978 @c selected, sets the registers of the register block of
33979 @c that thread; otherwise sets current registers.
33980
33981 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
33982 @anchor{cycle step packet}
33983 @cindex @samp{i} packet
33984 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
33985 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
33986 step starting at that address.
33987
33988 @item I
33989 @cindex @samp{I} packet
33990 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
33991 step packet}.
33992
33993 @item k
33994 @cindex @samp{k} packet
33995 Kill request.
33996
33997 FIXME: @emph{There is no description of how to operate when a specific
33998 thread context has been selected (i.e.@: does 'k' kill only that
33999 thread?)}.
34000
34001 @item m @var{addr},@var{length}
34002 @cindex @samp{m} packet
34003 Read @var{length} bytes of memory starting at address @var{addr}.
34004 Note that @var{addr} may not be aligned to any particular boundary.
34005
34006 The stub need not use any particular size or alignment when gathering
34007 data from memory for the response; even if @var{addr} is word-aligned
34008 and @var{length} is a multiple of the word size, the stub is free to
34009 use byte accesses, or not. For this reason, this packet may not be
34010 suitable for accessing memory-mapped I/O devices.
34011 @cindex alignment of remote memory accesses
34012 @cindex size of remote memory accesses
34013 @cindex memory, alignment and size of remote accesses
34014
34015 Reply:
34016 @table @samp
34017 @item @var{XX@dots{}}
34018 Memory contents; each byte is transmitted as a two-digit hexadecimal
34019 number. The reply may contain fewer bytes than requested if the
34020 server was able to read only part of the region of memory.
34021 @item E @var{NN}
34022 @var{NN} is errno
34023 @end table
34024
34025 @item M @var{addr},@var{length}:@var{XX@dots{}}
34026 @cindex @samp{M} packet
34027 Write @var{length} bytes of memory starting at address @var{addr}.
34028 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
34029 hexadecimal number.
34030
34031 Reply:
34032 @table @samp
34033 @item OK
34034 for success
34035 @item E @var{NN}
34036 for an error (this includes the case where only part of the data was
34037 written).
34038 @end table
34039
34040 @item p @var{n}
34041 @cindex @samp{p} packet
34042 Read the value of register @var{n}; @var{n} is in hex.
34043 @xref{read registers packet}, for a description of how the returned
34044 register value is encoded.
34045
34046 Reply:
34047 @table @samp
34048 @item @var{XX@dots{}}
34049 the register's value
34050 @item E @var{NN}
34051 for an error
34052 @item
34053 Indicating an unrecognized @var{query}.
34054 @end table
34055
34056 @item P @var{n@dots{}}=@var{r@dots{}}
34057 @anchor{write register packet}
34058 @cindex @samp{P} packet
34059 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
34060 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
34061 digits for each byte in the register (target byte order).
34062
34063 Reply:
34064 @table @samp
34065 @item OK
34066 for success
34067 @item E @var{NN}
34068 for an error
34069 @end table
34070
34071 @item q @var{name} @var{params}@dots{}
34072 @itemx Q @var{name} @var{params}@dots{}
34073 @cindex @samp{q} packet
34074 @cindex @samp{Q} packet
34075 General query (@samp{q}) and set (@samp{Q}). These packets are
34076 described fully in @ref{General Query Packets}.
34077
34078 @item r
34079 @cindex @samp{r} packet
34080 Reset the entire system.
34081
34082 Don't use this packet; use the @samp{R} packet instead.
34083
34084 @item R @var{XX}
34085 @cindex @samp{R} packet
34086 Restart the program being debugged. @var{XX}, while needed, is ignored.
34087 This packet is only available in extended mode (@pxref{extended mode}).
34088
34089 The @samp{R} packet has no reply.
34090
34091 @item s @r{[}@var{addr}@r{]}
34092 @cindex @samp{s} packet
34093 Single step. @var{addr} is the address at which to resume. If
34094 @var{addr} is omitted, resume at same address.
34095
34096 This packet is deprecated for multi-threading support. @xref{vCont
34097 packet}.
34098
34099 Reply:
34100 @xref{Stop Reply Packets}, for the reply specifications.
34101
34102 @item S @var{sig}@r{[};@var{addr}@r{]}
34103 @anchor{step with signal packet}
34104 @cindex @samp{S} packet
34105 Step with signal. This is analogous to the @samp{C} packet, but
34106 requests a single-step, rather than a normal resumption of execution.
34107
34108 This packet is deprecated for multi-threading support. @xref{vCont
34109 packet}.
34110
34111 Reply:
34112 @xref{Stop Reply Packets}, for the reply specifications.
34113
34114 @item t @var{addr}:@var{PP},@var{MM}
34115 @cindex @samp{t} packet
34116 Search backwards starting at address @var{addr} for a match with pattern
34117 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
34118 @var{addr} must be at least 3 digits.
34119
34120 @item T @var{thread-id}
34121 @cindex @samp{T} packet
34122 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
34123
34124 Reply:
34125 @table @samp
34126 @item OK
34127 thread is still alive
34128 @item E @var{NN}
34129 thread is dead
34130 @end table
34131
34132 @item v
34133 Packets starting with @samp{v} are identified by a multi-letter name,
34134 up to the first @samp{;} or @samp{?} (or the end of the packet).
34135
34136 @item vAttach;@var{pid}
34137 @cindex @samp{vAttach} packet
34138 Attach to a new process with the specified process ID @var{pid}.
34139 The process ID is a
34140 hexadecimal integer identifying the process. In all-stop mode, all
34141 threads in the attached process are stopped; in non-stop mode, it may be
34142 attached without being stopped if that is supported by the target.
34143
34144 @c In non-stop mode, on a successful vAttach, the stub should set the
34145 @c current thread to a thread of the newly-attached process. After
34146 @c attaching, GDB queries for the attached process's thread ID with qC.
34147 @c Also note that, from a user perspective, whether or not the
34148 @c target is stopped on attach in non-stop mode depends on whether you
34149 @c use the foreground or background version of the attach command, not
34150 @c on what vAttach does; GDB does the right thing with respect to either
34151 @c stopping or restarting threads.
34152
34153 This packet is only available in extended mode (@pxref{extended mode}).
34154
34155 Reply:
34156 @table @samp
34157 @item E @var{nn}
34158 for an error
34159 @item @r{Any stop packet}
34160 for success in all-stop mode (@pxref{Stop Reply Packets})
34161 @item OK
34162 for success in non-stop mode (@pxref{Remote Non-Stop})
34163 @end table
34164
34165 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
34166 @cindex @samp{vCont} packet
34167 @anchor{vCont packet}
34168 Resume the inferior, specifying different actions for each thread.
34169 If an action is specified with no @var{thread-id}, then it is applied to any
34170 threads that don't have a specific action specified; if no default action is
34171 specified then other threads should remain stopped in all-stop mode and
34172 in their current state in non-stop mode.
34173 Specifying multiple
34174 default actions is an error; specifying no actions is also an error.
34175 Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
34176
34177 Currently supported actions are:
34178
34179 @table @samp
34180 @item c
34181 Continue.
34182 @item C @var{sig}
34183 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
34184 @item s
34185 Step.
34186 @item S @var{sig}
34187 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
34188 @item t
34189 Stop.
34190 @end table
34191
34192 The optional argument @var{addr} normally associated with the
34193 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
34194 not supported in @samp{vCont}.
34195
34196 The @samp{t} action is only relevant in non-stop mode
34197 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
34198 A stop reply should be generated for any affected thread not already stopped.
34199 When a thread is stopped by means of a @samp{t} action,
34200 the corresponding stop reply should indicate that the thread has stopped with
34201 signal @samp{0}, regardless of whether the target uses some other signal
34202 as an implementation detail.
34203
34204 The stub must support @samp{vCont} if it reports support for
34205 multiprocess extensions (@pxref{multiprocess extensions}). Note that in
34206 this case @samp{vCont} actions can be specified to apply to all threads
34207 in a process by using the @samp{p@var{pid}.-1} form of the
34208 @var{thread-id}.
34209
34210 Reply:
34211 @xref{Stop Reply Packets}, for the reply specifications.
34212
34213 @item vCont?
34214 @cindex @samp{vCont?} packet
34215 Request a list of actions supported by the @samp{vCont} packet.
34216
34217 Reply:
34218 @table @samp
34219 @item vCont@r{[};@var{action}@dots{}@r{]}
34220 The @samp{vCont} packet is supported. Each @var{action} is a supported
34221 command in the @samp{vCont} packet.
34222 @item
34223 The @samp{vCont} packet is not supported.
34224 @end table
34225
34226 @item vFile:@var{operation}:@var{parameter}@dots{}
34227 @cindex @samp{vFile} packet
34228 Perform a file operation on the target system. For details,
34229 see @ref{Host I/O Packets}.
34230
34231 @item vFlashErase:@var{addr},@var{length}
34232 @cindex @samp{vFlashErase} packet
34233 Direct the stub to erase @var{length} bytes of flash starting at
34234 @var{addr}. The region may enclose any number of flash blocks, but
34235 its start and end must fall on block boundaries, as indicated by the
34236 flash block size appearing in the memory map (@pxref{Memory Map
34237 Format}). @value{GDBN} groups flash memory programming operations
34238 together, and sends a @samp{vFlashDone} request after each group; the
34239 stub is allowed to delay erase operation until the @samp{vFlashDone}
34240 packet is received.
34241
34242 Reply:
34243 @table @samp
34244 @item OK
34245 for success
34246 @item E @var{NN}
34247 for an error
34248 @end table
34249
34250 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
34251 @cindex @samp{vFlashWrite} packet
34252 Direct the stub to write data to flash address @var{addr}. The data
34253 is passed in binary form using the same encoding as for the @samp{X}
34254 packet (@pxref{Binary Data}). The memory ranges specified by
34255 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
34256 not overlap, and must appear in order of increasing addresses
34257 (although @samp{vFlashErase} packets for higher addresses may already
34258 have been received; the ordering is guaranteed only between
34259 @samp{vFlashWrite} packets). If a packet writes to an address that was
34260 neither erased by a preceding @samp{vFlashErase} packet nor by some other
34261 target-specific method, the results are unpredictable.
34262
34263
34264 Reply:
34265 @table @samp
34266 @item OK
34267 for success
34268 @item E.memtype
34269 for vFlashWrite addressing non-flash memory
34270 @item E @var{NN}
34271 for an error
34272 @end table
34273
34274 @item vFlashDone
34275 @cindex @samp{vFlashDone} packet
34276 Indicate to the stub that flash programming operation is finished.
34277 The stub is permitted to delay or batch the effects of a group of
34278 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
34279 @samp{vFlashDone} packet is received. The contents of the affected
34280 regions of flash memory are unpredictable until the @samp{vFlashDone}
34281 request is completed.
34282
34283 @item vKill;@var{pid}
34284 @cindex @samp{vKill} packet
34285 Kill the process with the specified process ID. @var{pid} is a
34286 hexadecimal integer identifying the process. This packet is used in
34287 preference to @samp{k} when multiprocess protocol extensions are
34288 supported; see @ref{multiprocess extensions}.
34289
34290 Reply:
34291 @table @samp
34292 @item E @var{nn}
34293 for an error
34294 @item OK
34295 for success
34296 @end table
34297
34298 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
34299 @cindex @samp{vRun} packet
34300 Run the program @var{filename}, passing it each @var{argument} on its
34301 command line. The file and arguments are hex-encoded strings. If
34302 @var{filename} is an empty string, the stub may use a default program
34303 (e.g.@: the last program run). The program is created in the stopped
34304 state.
34305
34306 @c FIXME: What about non-stop mode?
34307
34308 This packet is only available in extended mode (@pxref{extended mode}).
34309
34310 Reply:
34311 @table @samp
34312 @item E @var{nn}
34313 for an error
34314 @item @r{Any stop packet}
34315 for success (@pxref{Stop Reply Packets})
34316 @end table
34317
34318 @item vStopped
34319 @anchor{vStopped packet}
34320 @cindex @samp{vStopped} packet
34321
34322 In non-stop mode (@pxref{Remote Non-Stop}), acknowledge a previous stop
34323 reply and prompt for the stub to report another one.
34324
34325 Reply:
34326 @table @samp
34327 @item @r{Any stop packet}
34328 if there is another unreported stop event (@pxref{Stop Reply Packets})
34329 @item OK
34330 if there are no unreported stop events
34331 @end table
34332
34333 @item X @var{addr},@var{length}:@var{XX@dots{}}
34334 @anchor{X packet}
34335 @cindex @samp{X} packet
34336 Write data to memory, where the data is transmitted in binary.
34337 @var{addr} is address, @var{length} is number of bytes,
34338 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
34339
34340 Reply:
34341 @table @samp
34342 @item OK
34343 for success
34344 @item E @var{NN}
34345 for an error
34346 @end table
34347
34348 @item z @var{type},@var{addr},@var{kind}
34349 @itemx Z @var{type},@var{addr},@var{kind}
34350 @anchor{insert breakpoint or watchpoint packet}
34351 @cindex @samp{z} packet
34352 @cindex @samp{Z} packets
34353 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
34354 watchpoint starting at address @var{address} of kind @var{kind}.
34355
34356 Each breakpoint and watchpoint packet @var{type} is documented
34357 separately.
34358
34359 @emph{Implementation notes: A remote target shall return an empty string
34360 for an unrecognized breakpoint or watchpoint packet @var{type}. A
34361 remote target shall support either both or neither of a given
34362 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
34363 avoid potential problems with duplicate packets, the operations should
34364 be implemented in an idempotent way.}
34365
34366 @item z0,@var{addr},@var{kind}
34367 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
34368 @cindex @samp{z0} packet
34369 @cindex @samp{Z0} packet
34370 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
34371 @var{addr} of type @var{kind}.
34372
34373 A memory breakpoint is implemented by replacing the instruction at
34374 @var{addr} with a software breakpoint or trap instruction. The
34375 @var{kind} is target-specific and typically indicates the size of
34376 the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
34377 and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
34378 architectures have additional meanings for @var{kind};
34379 @var{cond_list} is an optional list of conditional expressions in bytecode
34380 form that should be evaluated on the target's side. These are the
34381 conditions that should be taken into consideration when deciding if
34382 the breakpoint trigger should be reported back to @var{GDBN}.
34383
34384 The @var{cond_list} parameter is comprised of a series of expressions,
34385 concatenated without separators. Each expression has the following form:
34386
34387 @table @samp
34388
34389 @item X @var{len},@var{expr}
34390 @var{len} is the length of the bytecode expression and @var{expr} is the
34391 actual conditional expression in bytecode form.
34392
34393 @end table
34394
34395 see @ref{Architecture-Specific Protocol Details}.
34396
34397 @emph{Implementation note: It is possible for a target to copy or move
34398 code that contains memory breakpoints (e.g., when implementing
34399 overlays). The behavior of this packet, in the presence of such a
34400 target, is not defined.}
34401
34402 Reply:
34403 @table @samp
34404 @item OK
34405 success
34406 @item
34407 not supported
34408 @item E @var{NN}
34409 for an error
34410 @end table
34411
34412 @item z1,@var{addr},@var{kind}
34413 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
34414 @cindex @samp{z1} packet
34415 @cindex @samp{Z1} packet
34416 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
34417 address @var{addr}.
34418
34419 A hardware breakpoint is implemented using a mechanism that is not
34420 dependant on being able to modify the target's memory. @var{kind}
34421 and @var{cond_list} have the same meaning as in @samp{Z0} packets.
34422
34423 @emph{Implementation note: A hardware breakpoint is not affected by code
34424 movement.}
34425
34426 Reply:
34427 @table @samp
34428 @item OK
34429 success
34430 @item
34431 not supported
34432 @item E @var{NN}
34433 for an error
34434 @end table
34435
34436 @item z2,@var{addr},@var{kind}
34437 @itemx Z2,@var{addr},@var{kind}
34438 @cindex @samp{z2} packet
34439 @cindex @samp{Z2} packet
34440 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
34441 @var{kind} is interpreted as the number of bytes to watch.
34442
34443 Reply:
34444 @table @samp
34445 @item OK
34446 success
34447 @item
34448 not supported
34449 @item E @var{NN}
34450 for an error
34451 @end table
34452
34453 @item z3,@var{addr},@var{kind}
34454 @itemx Z3,@var{addr},@var{kind}
34455 @cindex @samp{z3} packet
34456 @cindex @samp{Z3} packet
34457 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
34458 @var{kind} is interpreted as the number of bytes to watch.
34459
34460 Reply:
34461 @table @samp
34462 @item OK
34463 success
34464 @item
34465 not supported
34466 @item E @var{NN}
34467 for an error
34468 @end table
34469
34470 @item z4,@var{addr},@var{kind}
34471 @itemx Z4,@var{addr},@var{kind}
34472 @cindex @samp{z4} packet
34473 @cindex @samp{Z4} packet
34474 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
34475 @var{kind} is interpreted as the number of bytes to watch.
34476
34477 Reply:
34478 @table @samp
34479 @item OK
34480 success
34481 @item
34482 not supported
34483 @item E @var{NN}
34484 for an error
34485 @end table
34486
34487 @end table
34488
34489 @node Stop Reply Packets
34490 @section Stop Reply Packets
34491 @cindex stop reply packets
34492
34493 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
34494 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
34495 receive any of the below as a reply. Except for @samp{?}
34496 and @samp{vStopped}, that reply is only returned
34497 when the target halts. In the below the exact meaning of @dfn{signal
34498 number} is defined by the header @file{include/gdb/signals.h} in the
34499 @value{GDBN} source code.
34500
34501 As in the description of request packets, we include spaces in the
34502 reply templates for clarity; these are not part of the reply packet's
34503 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
34504 components.
34505
34506 @table @samp
34507
34508 @item S @var{AA}
34509 The program received signal number @var{AA} (a two-digit hexadecimal
34510 number). This is equivalent to a @samp{T} response with no
34511 @var{n}:@var{r} pairs.
34512
34513 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
34514 @cindex @samp{T} packet reply
34515 The program received signal number @var{AA} (a two-digit hexadecimal
34516 number). This is equivalent to an @samp{S} response, except that the
34517 @samp{@var{n}:@var{r}} pairs can carry values of important registers
34518 and other information directly in the stop reply packet, reducing
34519 round-trip latency. Single-step and breakpoint traps are reported
34520 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
34521
34522 @itemize @bullet
34523 @item
34524 If @var{n} is a hexadecimal number, it is a register number, and the
34525 corresponding @var{r} gives that register's value. @var{r} is a
34526 series of bytes in target byte order, with each byte given by a
34527 two-digit hex number.
34528
34529 @item
34530 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
34531 the stopped thread, as specified in @ref{thread-id syntax}.
34532
34533 @item
34534 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
34535 the core on which the stop event was detected.
34536
34537 @item
34538 If @var{n} is a recognized @dfn{stop reason}, it describes a more
34539 specific event that stopped the target. The currently defined stop
34540 reasons are listed below. @var{aa} should be @samp{05}, the trap
34541 signal. At most one stop reason should be present.
34542
34543 @item
34544 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
34545 and go on to the next; this allows us to extend the protocol in the
34546 future.
34547 @end itemize
34548
34549 The currently defined stop reasons are:
34550
34551 @table @samp
34552 @item watch
34553 @itemx rwatch
34554 @itemx awatch
34555 The packet indicates a watchpoint hit, and @var{r} is the data address, in
34556 hex.
34557
34558 @cindex shared library events, remote reply
34559 @item library
34560 The packet indicates that the loaded libraries have changed.
34561 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
34562 list of loaded libraries. @var{r} is ignored.
34563
34564 @cindex replay log events, remote reply
34565 @item replaylog
34566 The packet indicates that the target cannot continue replaying
34567 logged execution events, because it has reached the end (or the
34568 beginning when executing backward) of the log. The value of @var{r}
34569 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
34570 for more information.
34571 @end table
34572
34573 @item W @var{AA}
34574 @itemx W @var{AA} ; process:@var{pid}
34575 The process exited, and @var{AA} is the exit status. This is only
34576 applicable to certain targets.
34577
34578 The second form of the response, including the process ID of the exited
34579 process, can be used only when @value{GDBN} has reported support for
34580 multiprocess protocol extensions; see @ref{multiprocess extensions}.
34581 The @var{pid} is formatted as a big-endian hex string.
34582
34583 @item X @var{AA}
34584 @itemx X @var{AA} ; process:@var{pid}
34585 The process terminated with signal @var{AA}.
34586
34587 The second form of the response, including the process ID of the
34588 terminated process, can be used only when @value{GDBN} has reported
34589 support for multiprocess protocol extensions; see @ref{multiprocess
34590 extensions}. The @var{pid} is formatted as a big-endian hex string.
34591
34592 @item O @var{XX}@dots{}
34593 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
34594 written as the program's console output. This can happen at any time
34595 while the program is running and the debugger should continue to wait
34596 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
34597
34598 @item F @var{call-id},@var{parameter}@dots{}
34599 @var{call-id} is the identifier which says which host system call should
34600 be called. This is just the name of the function. Translation into the
34601 correct system call is only applicable as it's defined in @value{GDBN}.
34602 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
34603 system calls.
34604
34605 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
34606 this very system call.
34607
34608 The target replies with this packet when it expects @value{GDBN} to
34609 call a host system call on behalf of the target. @value{GDBN} replies
34610 with an appropriate @samp{F} packet and keeps up waiting for the next
34611 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
34612 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
34613 Protocol Extension}, for more details.
34614
34615 @end table
34616
34617 @node General Query Packets
34618 @section General Query Packets
34619 @cindex remote query requests
34620
34621 Packets starting with @samp{q} are @dfn{general query packets};
34622 packets starting with @samp{Q} are @dfn{general set packets}. General
34623 query and set packets are a semi-unified form for retrieving and
34624 sending information to and from the stub.
34625
34626 The initial letter of a query or set packet is followed by a name
34627 indicating what sort of thing the packet applies to. For example,
34628 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
34629 definitions with the stub. These packet names follow some
34630 conventions:
34631
34632 @itemize @bullet
34633 @item
34634 The name must not contain commas, colons or semicolons.
34635 @item
34636 Most @value{GDBN} query and set packets have a leading upper case
34637 letter.
34638 @item
34639 The names of custom vendor packets should use a company prefix, in
34640 lower case, followed by a period. For example, packets designed at
34641 the Acme Corporation might begin with @samp{qacme.foo} (for querying
34642 foos) or @samp{Qacme.bar} (for setting bars).
34643 @end itemize
34644
34645 The name of a query or set packet should be separated from any
34646 parameters by a @samp{:}; the parameters themselves should be
34647 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
34648 full packet name, and check for a separator or the end of the packet,
34649 in case two packet names share a common prefix. New packets should not begin
34650 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
34651 packets predate these conventions, and have arguments without any terminator
34652 for the packet name; we suspect they are in widespread use in places that
34653 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
34654 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
34655 packet.}.
34656
34657 Like the descriptions of the other packets, each description here
34658 has a template showing the packet's overall syntax, followed by an
34659 explanation of the packet's meaning. We include spaces in some of the
34660 templates for clarity; these are not part of the packet's syntax. No
34661 @value{GDBN} packet uses spaces to separate its components.
34662
34663 Here are the currently defined query and set packets:
34664
34665 @table @samp
34666
34667 @item QAgent:1
34668 @item QAgent:0
34669 Turn on or off the agent as a helper to perform some debugging operations
34670 delegated from @value{GDBN} (@pxref{Control Agent}).
34671
34672 @item QAllow:@var{op}:@var{val}@dots{}
34673 @cindex @samp{QAllow} packet
34674 Specify which operations @value{GDBN} expects to request of the
34675 target, as a semicolon-separated list of operation name and value
34676 pairs. Possible values for @var{op} include @samp{WriteReg},
34677 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
34678 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
34679 indicating that @value{GDBN} will not request the operation, or 1,
34680 indicating that it may. (The target can then use this to set up its
34681 own internals optimally, for instance if the debugger never expects to
34682 insert breakpoints, it may not need to install its own trap handler.)
34683
34684 @item qC
34685 @cindex current thread, remote request
34686 @cindex @samp{qC} packet
34687 Return the current thread ID.
34688
34689 Reply:
34690 @table @samp
34691 @item QC @var{thread-id}
34692 Where @var{thread-id} is a thread ID as documented in
34693 @ref{thread-id syntax}.
34694 @item @r{(anything else)}
34695 Any other reply implies the old thread ID.
34696 @end table
34697
34698 @item qCRC:@var{addr},@var{length}
34699 @cindex CRC of memory block, remote request
34700 @cindex @samp{qCRC} packet
34701 Compute the CRC checksum of a block of memory using CRC-32 defined in
34702 IEEE 802.3. The CRC is computed byte at a time, taking the most
34703 significant bit of each byte first. The initial pattern code
34704 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
34705
34706 @emph{Note:} This is the same CRC used in validating separate debug
34707 files (@pxref{Separate Debug Files, , Debugging Information in Separate
34708 Files}). However the algorithm is slightly different. When validating
34709 separate debug files, the CRC is computed taking the @emph{least}
34710 significant bit of each byte first, and the final result is inverted to
34711 detect trailing zeros.
34712
34713 Reply:
34714 @table @samp
34715 @item E @var{NN}
34716 An error (such as memory fault)
34717 @item C @var{crc32}
34718 The specified memory region's checksum is @var{crc32}.
34719 @end table
34720
34721 @item QDisableRandomization:@var{value}
34722 @cindex disable address space randomization, remote request
34723 @cindex @samp{QDisableRandomization} packet
34724 Some target operating systems will randomize the virtual address space
34725 of the inferior process as a security feature, but provide a feature
34726 to disable such randomization, e.g.@: to allow for a more deterministic
34727 debugging experience. On such systems, this packet with a @var{value}
34728 of 1 directs the target to disable address space randomization for
34729 processes subsequently started via @samp{vRun} packets, while a packet
34730 with a @var{value} of 0 tells the target to enable address space
34731 randomization.
34732
34733 This packet is only available in extended mode (@pxref{extended mode}).
34734
34735 Reply:
34736 @table @samp
34737 @item OK
34738 The request succeeded.
34739
34740 @item E @var{nn}
34741 An error occurred. @var{nn} are hex digits.
34742
34743 @item
34744 An empty reply indicates that @samp{QDisableRandomization} is not supported
34745 by the stub.
34746 @end table
34747
34748 This packet is not probed by default; the remote stub must request it,
34749 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
34750 This should only be done on targets that actually support disabling
34751 address space randomization.
34752
34753 @item qfThreadInfo
34754 @itemx qsThreadInfo
34755 @cindex list active threads, remote request
34756 @cindex @samp{qfThreadInfo} packet
34757 @cindex @samp{qsThreadInfo} packet
34758 Obtain a list of all active thread IDs from the target (OS). Since there
34759 may be too many active threads to fit into one reply packet, this query
34760 works iteratively: it may require more than one query/reply sequence to
34761 obtain the entire list of threads. The first query of the sequence will
34762 be the @samp{qfThreadInfo} query; subsequent queries in the
34763 sequence will be the @samp{qsThreadInfo} query.
34764
34765 NOTE: This packet replaces the @samp{qL} query (see below).
34766
34767 Reply:
34768 @table @samp
34769 @item m @var{thread-id}
34770 A single thread ID
34771 @item m @var{thread-id},@var{thread-id}@dots{}
34772 a comma-separated list of thread IDs
34773 @item l
34774 (lower case letter @samp{L}) denotes end of list.
34775 @end table
34776
34777 In response to each query, the target will reply with a list of one or
34778 more thread IDs, separated by commas.
34779 @value{GDBN} will respond to each reply with a request for more thread
34780 ids (using the @samp{qs} form of the query), until the target responds
34781 with @samp{l} (lower-case ell, for @dfn{last}).
34782 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
34783 fields.
34784
34785 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
34786 @cindex get thread-local storage address, remote request
34787 @cindex @samp{qGetTLSAddr} packet
34788 Fetch the address associated with thread local storage specified
34789 by @var{thread-id}, @var{offset}, and @var{lm}.
34790
34791 @var{thread-id} is the thread ID associated with the
34792 thread for which to fetch the TLS address. @xref{thread-id syntax}.
34793
34794 @var{offset} is the (big endian, hex encoded) offset associated with the
34795 thread local variable. (This offset is obtained from the debug
34796 information associated with the variable.)
34797
34798 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
34799 load module associated with the thread local storage. For example,
34800 a @sc{gnu}/Linux system will pass the link map address of the shared
34801 object associated with the thread local storage under consideration.
34802 Other operating environments may choose to represent the load module
34803 differently, so the precise meaning of this parameter will vary.
34804
34805 Reply:
34806 @table @samp
34807 @item @var{XX}@dots{}
34808 Hex encoded (big endian) bytes representing the address of the thread
34809 local storage requested.
34810
34811 @item E @var{nn}
34812 An error occurred. @var{nn} are hex digits.
34813
34814 @item
34815 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
34816 @end table
34817
34818 @item qGetTIBAddr:@var{thread-id}
34819 @cindex get thread information block address
34820 @cindex @samp{qGetTIBAddr} packet
34821 Fetch address of the Windows OS specific Thread Information Block.
34822
34823 @var{thread-id} is the thread ID associated with the thread.
34824
34825 Reply:
34826 @table @samp
34827 @item @var{XX}@dots{}
34828 Hex encoded (big endian) bytes representing the linear address of the
34829 thread information block.
34830
34831 @item E @var{nn}
34832 An error occured. This means that either the thread was not found, or the
34833 address could not be retrieved.
34834
34835 @item
34836 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
34837 @end table
34838
34839 @item qL @var{startflag} @var{threadcount} @var{nextthread}
34840 Obtain thread information from RTOS. Where: @var{startflag} (one hex
34841 digit) is one to indicate the first query and zero to indicate a
34842 subsequent query; @var{threadcount} (two hex digits) is the maximum
34843 number of threads the response packet can contain; and @var{nextthread}
34844 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
34845 returned in the response as @var{argthread}.
34846
34847 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
34848
34849 Reply:
34850 @table @samp
34851 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
34852 Where: @var{count} (two hex digits) is the number of threads being
34853 returned; @var{done} (one hex digit) is zero to indicate more threads
34854 and one indicates no further threads; @var{argthreadid} (eight hex
34855 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
34856 is a sequence of thread IDs from the target. @var{threadid} (eight hex
34857 digits). See @code{remote.c:parse_threadlist_response()}.
34858 @end table
34859
34860 @item qOffsets
34861 @cindex section offsets, remote request
34862 @cindex @samp{qOffsets} packet
34863 Get section offsets that the target used when relocating the downloaded
34864 image.
34865
34866 Reply:
34867 @table @samp
34868 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
34869 Relocate the @code{Text} section by @var{xxx} from its original address.
34870 Relocate the @code{Data} section by @var{yyy} from its original address.
34871 If the object file format provides segment information (e.g.@: @sc{elf}
34872 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
34873 segments by the supplied offsets.
34874
34875 @emph{Note: while a @code{Bss} offset may be included in the response,
34876 @value{GDBN} ignores this and instead applies the @code{Data} offset
34877 to the @code{Bss} section.}
34878
34879 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
34880 Relocate the first segment of the object file, which conventionally
34881 contains program code, to a starting address of @var{xxx}. If
34882 @samp{DataSeg} is specified, relocate the second segment, which
34883 conventionally contains modifiable data, to a starting address of
34884 @var{yyy}. @value{GDBN} will report an error if the object file
34885 does not contain segment information, or does not contain at least
34886 as many segments as mentioned in the reply. Extra segments are
34887 kept at fixed offsets relative to the last relocated segment.
34888 @end table
34889
34890 @item qP @var{mode} @var{thread-id}
34891 @cindex thread information, remote request
34892 @cindex @samp{qP} packet
34893 Returns information on @var{thread-id}. Where: @var{mode} is a hex
34894 encoded 32 bit mode; @var{thread-id} is a thread ID
34895 (@pxref{thread-id syntax}).
34896
34897 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
34898 (see below).
34899
34900 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
34901
34902 @item QNonStop:1
34903 @item QNonStop:0
34904 @cindex non-stop mode, remote request
34905 @cindex @samp{QNonStop} packet
34906 @anchor{QNonStop}
34907 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
34908 @xref{Remote Non-Stop}, for more information.
34909
34910 Reply:
34911 @table @samp
34912 @item OK
34913 The request succeeded.
34914
34915 @item E @var{nn}
34916 An error occurred. @var{nn} are hex digits.
34917
34918 @item
34919 An empty reply indicates that @samp{QNonStop} is not supported by
34920 the stub.
34921 @end table
34922
34923 This packet is not probed by default; the remote stub must request it,
34924 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
34925 Use of this packet is controlled by the @code{set non-stop} command;
34926 @pxref{Non-Stop Mode}.
34927
34928 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
34929 @cindex pass signals to inferior, remote request
34930 @cindex @samp{QPassSignals} packet
34931 @anchor{QPassSignals}
34932 Each listed @var{signal} should be passed directly to the inferior process.
34933 Signals are numbered identically to continue packets and stop replies
34934 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
34935 strictly greater than the previous item. These signals do not need to stop
34936 the inferior, or be reported to @value{GDBN}. All other signals should be
34937 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
34938 combine; any earlier @samp{QPassSignals} list is completely replaced by the
34939 new list. This packet improves performance when using @samp{handle
34940 @var{signal} nostop noprint pass}.
34941
34942 Reply:
34943 @table @samp
34944 @item OK
34945 The request succeeded.
34946
34947 @item E @var{nn}
34948 An error occurred. @var{nn} are hex digits.
34949
34950 @item
34951 An empty reply indicates that @samp{QPassSignals} is not supported by
34952 the stub.
34953 @end table
34954
34955 Use of this packet is controlled by the @code{set remote pass-signals}
34956 command (@pxref{Remote Configuration, set remote pass-signals}).
34957 This packet is not probed by default; the remote stub must request it,
34958 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
34959
34960 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
34961 @cindex signals the inferior may see, remote request
34962 @cindex @samp{QProgramSignals} packet
34963 @anchor{QProgramSignals}
34964 Each listed @var{signal} may be delivered to the inferior process.
34965 Others should be silently discarded.
34966
34967 In some cases, the remote stub may need to decide whether to deliver a
34968 signal to the program or not without @value{GDBN} involvement. One
34969 example of that is while detaching --- the program's threads may have
34970 stopped for signals that haven't yet had a chance of being reported to
34971 @value{GDBN}, and so the remote stub can use the signal list specified
34972 by this packet to know whether to deliver or ignore those pending
34973 signals.
34974
34975 This does not influence whether to deliver a signal as requested by a
34976 resumption packet (@pxref{vCont packet}).
34977
34978 Signals are numbered identically to continue packets and stop replies
34979 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
34980 strictly greater than the previous item. Multiple
34981 @samp{QProgramSignals} packets do not combine; any earlier
34982 @samp{QProgramSignals} list is completely replaced by the new list.
34983
34984 Reply:
34985 @table @samp
34986 @item OK
34987 The request succeeded.
34988
34989 @item E @var{nn}
34990 An error occurred. @var{nn} are hex digits.
34991
34992 @item
34993 An empty reply indicates that @samp{QProgramSignals} is not supported
34994 by the stub.
34995 @end table
34996
34997 Use of this packet is controlled by the @code{set remote program-signals}
34998 command (@pxref{Remote Configuration, set remote program-signals}).
34999 This packet is not probed by default; the remote stub must request it,
35000 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35001
35002 @item qRcmd,@var{command}
35003 @cindex execute remote command, remote request
35004 @cindex @samp{qRcmd} packet
35005 @var{command} (hex encoded) is passed to the local interpreter for
35006 execution. Invalid commands should be reported using the output
35007 string. Before the final result packet, the target may also respond
35008 with a number of intermediate @samp{O@var{output}} console output
35009 packets. @emph{Implementors should note that providing access to a
35010 stubs's interpreter may have security implications}.
35011
35012 Reply:
35013 @table @samp
35014 @item OK
35015 A command response with no output.
35016 @item @var{OUTPUT}
35017 A command response with the hex encoded output string @var{OUTPUT}.
35018 @item E @var{NN}
35019 Indicate a badly formed request.
35020 @item
35021 An empty reply indicates that @samp{qRcmd} is not recognized.
35022 @end table
35023
35024 (Note that the @code{qRcmd} packet's name is separated from the
35025 command by a @samp{,}, not a @samp{:}, contrary to the naming
35026 conventions above. Please don't use this packet as a model for new
35027 packets.)
35028
35029 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
35030 @cindex searching memory, in remote debugging
35031 @cindex @samp{qSearch:memory} packet
35032 @anchor{qSearch memory}
35033 Search @var{length} bytes at @var{address} for @var{search-pattern}.
35034 @var{address} and @var{length} are encoded in hex.
35035 @var{search-pattern} is a sequence of bytes, hex encoded.
35036
35037 Reply:
35038 @table @samp
35039 @item 0
35040 The pattern was not found.
35041 @item 1,address
35042 The pattern was found at @var{address}.
35043 @item E @var{NN}
35044 A badly formed request or an error was encountered while searching memory.
35045 @item
35046 An empty reply indicates that @samp{qSearch:memory} is not recognized.
35047 @end table
35048
35049 @item QStartNoAckMode
35050 @cindex @samp{QStartNoAckMode} packet
35051 @anchor{QStartNoAckMode}
35052 Request that the remote stub disable the normal @samp{+}/@samp{-}
35053 protocol acknowledgments (@pxref{Packet Acknowledgment}).
35054
35055 Reply:
35056 @table @samp
35057 @item OK
35058 The stub has switched to no-acknowledgment mode.
35059 @value{GDBN} acknowledges this reponse,
35060 but neither the stub nor @value{GDBN} shall send or expect further
35061 @samp{+}/@samp{-} acknowledgments in the current connection.
35062 @item
35063 An empty reply indicates that the stub does not support no-acknowledgment mode.
35064 @end table
35065
35066 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
35067 @cindex supported packets, remote query
35068 @cindex features of the remote protocol
35069 @cindex @samp{qSupported} packet
35070 @anchor{qSupported}
35071 Tell the remote stub about features supported by @value{GDBN}, and
35072 query the stub for features it supports. This packet allows
35073 @value{GDBN} and the remote stub to take advantage of each others'
35074 features. @samp{qSupported} also consolidates multiple feature probes
35075 at startup, to improve @value{GDBN} performance---a single larger
35076 packet performs better than multiple smaller probe packets on
35077 high-latency links. Some features may enable behavior which must not
35078 be on by default, e.g.@: because it would confuse older clients or
35079 stubs. Other features may describe packets which could be
35080 automatically probed for, but are not. These features must be
35081 reported before @value{GDBN} will use them. This ``default
35082 unsupported'' behavior is not appropriate for all packets, but it
35083 helps to keep the initial connection time under control with new
35084 versions of @value{GDBN} which support increasing numbers of packets.
35085
35086 Reply:
35087 @table @samp
35088 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
35089 The stub supports or does not support each returned @var{stubfeature},
35090 depending on the form of each @var{stubfeature} (see below for the
35091 possible forms).
35092 @item
35093 An empty reply indicates that @samp{qSupported} is not recognized,
35094 or that no features needed to be reported to @value{GDBN}.
35095 @end table
35096
35097 The allowed forms for each feature (either a @var{gdbfeature} in the
35098 @samp{qSupported} packet, or a @var{stubfeature} in the response)
35099 are:
35100
35101 @table @samp
35102 @item @var{name}=@var{value}
35103 The remote protocol feature @var{name} is supported, and associated
35104 with the specified @var{value}. The format of @var{value} depends
35105 on the feature, but it must not include a semicolon.
35106 @item @var{name}+
35107 The remote protocol feature @var{name} is supported, and does not
35108 need an associated value.
35109 @item @var{name}-
35110 The remote protocol feature @var{name} is not supported.
35111 @item @var{name}?
35112 The remote protocol feature @var{name} may be supported, and
35113 @value{GDBN} should auto-detect support in some other way when it is
35114 needed. This form will not be used for @var{gdbfeature} notifications,
35115 but may be used for @var{stubfeature} responses.
35116 @end table
35117
35118 Whenever the stub receives a @samp{qSupported} request, the
35119 supplied set of @value{GDBN} features should override any previous
35120 request. This allows @value{GDBN} to put the stub in a known
35121 state, even if the stub had previously been communicating with
35122 a different version of @value{GDBN}.
35123
35124 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
35125 are defined:
35126
35127 @table @samp
35128 @item multiprocess
35129 This feature indicates whether @value{GDBN} supports multiprocess
35130 extensions to the remote protocol. @value{GDBN} does not use such
35131 extensions unless the stub also reports that it supports them by
35132 including @samp{multiprocess+} in its @samp{qSupported} reply.
35133 @xref{multiprocess extensions}, for details.
35134
35135 @item xmlRegisters
35136 This feature indicates that @value{GDBN} supports the XML target
35137 description. If the stub sees @samp{xmlRegisters=} with target
35138 specific strings separated by a comma, it will report register
35139 description.
35140
35141 @item qRelocInsn
35142 This feature indicates whether @value{GDBN} supports the
35143 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
35144 instruction reply packet}).
35145 @end table
35146
35147 Stubs should ignore any unknown values for
35148 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
35149 packet supports receiving packets of unlimited length (earlier
35150 versions of @value{GDBN} may reject overly long responses). Additional values
35151 for @var{gdbfeature} may be defined in the future to let the stub take
35152 advantage of new features in @value{GDBN}, e.g.@: incompatible
35153 improvements in the remote protocol---the @samp{multiprocess} feature is
35154 an example of such a feature. The stub's reply should be independent
35155 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
35156 describes all the features it supports, and then the stub replies with
35157 all the features it supports.
35158
35159 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
35160 responses, as long as each response uses one of the standard forms.
35161
35162 Some features are flags. A stub which supports a flag feature
35163 should respond with a @samp{+} form response. Other features
35164 require values, and the stub should respond with an @samp{=}
35165 form response.
35166
35167 Each feature has a default value, which @value{GDBN} will use if
35168 @samp{qSupported} is not available or if the feature is not mentioned
35169 in the @samp{qSupported} response. The default values are fixed; a
35170 stub is free to omit any feature responses that match the defaults.
35171
35172 Not all features can be probed, but for those which can, the probing
35173 mechanism is useful: in some cases, a stub's internal
35174 architecture may not allow the protocol layer to know some information
35175 about the underlying target in advance. This is especially common in
35176 stubs which may be configured for multiple targets.
35177
35178 These are the currently defined stub features and their properties:
35179
35180 @multitable @columnfractions 0.35 0.2 0.12 0.2
35181 @c NOTE: The first row should be @headitem, but we do not yet require
35182 @c a new enough version of Texinfo (4.7) to use @headitem.
35183 @item Feature Name
35184 @tab Value Required
35185 @tab Default
35186 @tab Probe Allowed
35187
35188 @item @samp{PacketSize}
35189 @tab Yes
35190 @tab @samp{-}
35191 @tab No
35192
35193 @item @samp{qXfer:auxv:read}
35194 @tab No
35195 @tab @samp{-}
35196 @tab Yes
35197
35198 @item @samp{qXfer:features:read}
35199 @tab No
35200 @tab @samp{-}
35201 @tab Yes
35202
35203 @item @samp{qXfer:libraries:read}
35204 @tab No
35205 @tab @samp{-}
35206 @tab Yes
35207
35208 @item @samp{qXfer:memory-map:read}
35209 @tab No
35210 @tab @samp{-}
35211 @tab Yes
35212
35213 @item @samp{qXfer:sdata:read}
35214 @tab No
35215 @tab @samp{-}
35216 @tab Yes
35217
35218 @item @samp{qXfer:spu:read}
35219 @tab No
35220 @tab @samp{-}
35221 @tab Yes
35222
35223 @item @samp{qXfer:spu:write}
35224 @tab No
35225 @tab @samp{-}
35226 @tab Yes
35227
35228 @item @samp{qXfer:siginfo:read}
35229 @tab No
35230 @tab @samp{-}
35231 @tab Yes
35232
35233 @item @samp{qXfer:siginfo:write}
35234 @tab No
35235 @tab @samp{-}
35236 @tab Yes
35237
35238 @item @samp{qXfer:threads:read}
35239 @tab No
35240 @tab @samp{-}
35241 @tab Yes
35242
35243 @item @samp{qXfer:traceframe-info:read}
35244 @tab No
35245 @tab @samp{-}
35246 @tab Yes
35247
35248 @item @samp{qXfer:uib:read}
35249 @tab No
35250 @tab @samp{-}
35251 @tab Yes
35252
35253 @item @samp{qXfer:fdpic:read}
35254 @tab No
35255 @tab @samp{-}
35256 @tab Yes
35257
35258 @item @samp{QNonStop}
35259 @tab No
35260 @tab @samp{-}
35261 @tab Yes
35262
35263 @item @samp{QPassSignals}
35264 @tab No
35265 @tab @samp{-}
35266 @tab Yes
35267
35268 @item @samp{QStartNoAckMode}
35269 @tab No
35270 @tab @samp{-}
35271 @tab Yes
35272
35273 @item @samp{multiprocess}
35274 @tab No
35275 @tab @samp{-}
35276 @tab No
35277
35278 @item @samp{ConditionalBreakpoints}
35279 @tab No
35280 @tab @samp{-}
35281 @tab No
35282
35283 @item @samp{ConditionalTracepoints}
35284 @tab No
35285 @tab @samp{-}
35286 @tab No
35287
35288 @item @samp{ReverseContinue}
35289 @tab No
35290 @tab @samp{-}
35291 @tab No
35292
35293 @item @samp{ReverseStep}
35294 @tab No
35295 @tab @samp{-}
35296 @tab No
35297
35298 @item @samp{TracepointSource}
35299 @tab No
35300 @tab @samp{-}
35301 @tab No
35302
35303 @item @samp{QAgent}
35304 @tab No
35305 @tab @samp{-}
35306 @tab No
35307
35308 @item @samp{QAllow}
35309 @tab No
35310 @tab @samp{-}
35311 @tab No
35312
35313 @item @samp{QDisableRandomization}
35314 @tab No
35315 @tab @samp{-}
35316 @tab No
35317
35318 @item @samp{EnableDisableTracepoints}
35319 @tab No
35320 @tab @samp{-}
35321 @tab No
35322
35323 @item @samp{tracenz}
35324 @tab No
35325 @tab @samp{-}
35326 @tab No
35327
35328 @end multitable
35329
35330 These are the currently defined stub features, in more detail:
35331
35332 @table @samp
35333 @cindex packet size, remote protocol
35334 @item PacketSize=@var{bytes}
35335 The remote stub can accept packets up to at least @var{bytes} in
35336 length. @value{GDBN} will send packets up to this size for bulk
35337 transfers, and will never send larger packets. This is a limit on the
35338 data characters in the packet, including the frame and checksum.
35339 There is no trailing NUL byte in a remote protocol packet; if the stub
35340 stores packets in a NUL-terminated format, it should allow an extra
35341 byte in its buffer for the NUL. If this stub feature is not supported,
35342 @value{GDBN} guesses based on the size of the @samp{g} packet response.
35343
35344 @item qXfer:auxv:read
35345 The remote stub understands the @samp{qXfer:auxv:read} packet
35346 (@pxref{qXfer auxiliary vector read}).
35347
35348 @item qXfer:features:read
35349 The remote stub understands the @samp{qXfer:features:read} packet
35350 (@pxref{qXfer target description read}).
35351
35352 @item qXfer:libraries:read
35353 The remote stub understands the @samp{qXfer:libraries:read} packet
35354 (@pxref{qXfer library list read}).
35355
35356 @item qXfer:libraries-svr4:read
35357 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
35358 (@pxref{qXfer svr4 library list read}).
35359
35360 @item qXfer:memory-map:read
35361 The remote stub understands the @samp{qXfer:memory-map:read} packet
35362 (@pxref{qXfer memory map read}).
35363
35364 @item qXfer:sdata:read
35365 The remote stub understands the @samp{qXfer:sdata:read} packet
35366 (@pxref{qXfer sdata read}).
35367
35368 @item qXfer:spu:read
35369 The remote stub understands the @samp{qXfer:spu:read} packet
35370 (@pxref{qXfer spu read}).
35371
35372 @item qXfer:spu:write
35373 The remote stub understands the @samp{qXfer:spu:write} packet
35374 (@pxref{qXfer spu write}).
35375
35376 @item qXfer:siginfo:read
35377 The remote stub understands the @samp{qXfer:siginfo:read} packet
35378 (@pxref{qXfer siginfo read}).
35379
35380 @item qXfer:siginfo:write
35381 The remote stub understands the @samp{qXfer:siginfo:write} packet
35382 (@pxref{qXfer siginfo write}).
35383
35384 @item qXfer:threads:read
35385 The remote stub understands the @samp{qXfer:threads:read} packet
35386 (@pxref{qXfer threads read}).
35387
35388 @item qXfer:traceframe-info:read
35389 The remote stub understands the @samp{qXfer:traceframe-info:read}
35390 packet (@pxref{qXfer traceframe info read}).
35391
35392 @item qXfer:uib:read
35393 The remote stub understands the @samp{qXfer:uib:read}
35394 packet (@pxref{qXfer unwind info block}).
35395
35396 @item qXfer:fdpic:read
35397 The remote stub understands the @samp{qXfer:fdpic:read}
35398 packet (@pxref{qXfer fdpic loadmap read}).
35399
35400 @item QNonStop
35401 The remote stub understands the @samp{QNonStop} packet
35402 (@pxref{QNonStop}).
35403
35404 @item QPassSignals
35405 The remote stub understands the @samp{QPassSignals} packet
35406 (@pxref{QPassSignals}).
35407
35408 @item QStartNoAckMode
35409 The remote stub understands the @samp{QStartNoAckMode} packet and
35410 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
35411
35412 @item multiprocess
35413 @anchor{multiprocess extensions}
35414 @cindex multiprocess extensions, in remote protocol
35415 The remote stub understands the multiprocess extensions to the remote
35416 protocol syntax. The multiprocess extensions affect the syntax of
35417 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
35418 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
35419 replies. Note that reporting this feature indicates support for the
35420 syntactic extensions only, not that the stub necessarily supports
35421 debugging of more than one process at a time. The stub must not use
35422 multiprocess extensions in packet replies unless @value{GDBN} has also
35423 indicated it supports them in its @samp{qSupported} request.
35424
35425 @item qXfer:osdata:read
35426 The remote stub understands the @samp{qXfer:osdata:read} packet
35427 ((@pxref{qXfer osdata read}).
35428
35429 @item ConditionalBreakpoints
35430 The target accepts and implements evaluation of conditional expressions
35431 defined for breakpoints. The target will only report breakpoint triggers
35432 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
35433
35434 @item ConditionalTracepoints
35435 The remote stub accepts and implements conditional expressions defined
35436 for tracepoints (@pxref{Tracepoint Conditions}).
35437
35438 @item ReverseContinue
35439 The remote stub accepts and implements the reverse continue packet
35440 (@pxref{bc}).
35441
35442 @item ReverseStep
35443 The remote stub accepts and implements the reverse step packet
35444 (@pxref{bs}).
35445
35446 @item TracepointSource
35447 The remote stub understands the @samp{QTDPsrc} packet that supplies
35448 the source form of tracepoint definitions.
35449
35450 @item QAgent
35451 The remote stub understands the @samp{QAgent} packet.
35452
35453 @item QAllow
35454 The remote stub understands the @samp{QAllow} packet.
35455
35456 @item QDisableRandomization
35457 The remote stub understands the @samp{QDisableRandomization} packet.
35458
35459 @item StaticTracepoint
35460 @cindex static tracepoints, in remote protocol
35461 The remote stub supports static tracepoints.
35462
35463 @item InstallInTrace
35464 @anchor{install tracepoint in tracing}
35465 The remote stub supports installing tracepoint in tracing.
35466
35467 @item EnableDisableTracepoints
35468 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
35469 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
35470 to be enabled and disabled while a trace experiment is running.
35471
35472 @item tracenz
35473 @cindex string tracing, in remote protocol
35474 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
35475 See @ref{Bytecode Descriptions} for details about the bytecode.
35476
35477 @end table
35478
35479 @item qSymbol::
35480 @cindex symbol lookup, remote request
35481 @cindex @samp{qSymbol} packet
35482 Notify the target that @value{GDBN} is prepared to serve symbol lookup
35483 requests. Accept requests from the target for the values of symbols.
35484
35485 Reply:
35486 @table @samp
35487 @item OK
35488 The target does not need to look up any (more) symbols.
35489 @item qSymbol:@var{sym_name}
35490 The target requests the value of symbol @var{sym_name} (hex encoded).
35491 @value{GDBN} may provide the value by using the
35492 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
35493 below.
35494 @end table
35495
35496 @item qSymbol:@var{sym_value}:@var{sym_name}
35497 Set the value of @var{sym_name} to @var{sym_value}.
35498
35499 @var{sym_name} (hex encoded) is the name of a symbol whose value the
35500 target has previously requested.
35501
35502 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
35503 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
35504 will be empty.
35505
35506 Reply:
35507 @table @samp
35508 @item OK
35509 The target does not need to look up any (more) symbols.
35510 @item qSymbol:@var{sym_name}
35511 The target requests the value of a new symbol @var{sym_name} (hex
35512 encoded). @value{GDBN} will continue to supply the values of symbols
35513 (if available), until the target ceases to request them.
35514 @end table
35515
35516 @item qTBuffer
35517 @item QTBuffer
35518 @item QTDisconnected
35519 @itemx QTDP
35520 @itemx QTDPsrc
35521 @itemx QTDV
35522 @itemx qTfP
35523 @itemx qTfV
35524 @itemx QTFrame
35525 @itemx qTMinFTPILen
35526
35527 @xref{Tracepoint Packets}.
35528
35529 @item qThreadExtraInfo,@var{thread-id}
35530 @cindex thread attributes info, remote request
35531 @cindex @samp{qThreadExtraInfo} packet
35532 Obtain a printable string description of a thread's attributes from
35533 the target OS. @var{thread-id} is a thread ID;
35534 see @ref{thread-id syntax}. This
35535 string may contain anything that the target OS thinks is interesting
35536 for @value{GDBN} to tell the user about the thread. The string is
35537 displayed in @value{GDBN}'s @code{info threads} display. Some
35538 examples of possible thread extra info strings are @samp{Runnable}, or
35539 @samp{Blocked on Mutex}.
35540
35541 Reply:
35542 @table @samp
35543 @item @var{XX}@dots{}
35544 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
35545 comprising the printable string containing the extra information about
35546 the thread's attributes.
35547 @end table
35548
35549 (Note that the @code{qThreadExtraInfo} packet's name is separated from
35550 the command by a @samp{,}, not a @samp{:}, contrary to the naming
35551 conventions above. Please don't use this packet as a model for new
35552 packets.)
35553
35554 @item QTNotes
35555 @item qTP
35556 @item QTSave
35557 @item qTsP
35558 @item qTsV
35559 @itemx QTStart
35560 @itemx QTStop
35561 @itemx QTEnable
35562 @itemx QTDisable
35563 @itemx QTinit
35564 @itemx QTro
35565 @itemx qTStatus
35566 @itemx qTV
35567 @itemx qTfSTM
35568 @itemx qTsSTM
35569 @itemx qTSTMat
35570 @xref{Tracepoint Packets}.
35571
35572 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
35573 @cindex read special object, remote request
35574 @cindex @samp{qXfer} packet
35575 @anchor{qXfer read}
35576 Read uninterpreted bytes from the target's special data area
35577 identified by the keyword @var{object}. Request @var{length} bytes
35578 starting at @var{offset} bytes into the data. The content and
35579 encoding of @var{annex} is specific to @var{object}; it can supply
35580 additional details about what data to access.
35581
35582 Here are the specific requests of this form defined so far. All
35583 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
35584 formats, listed below.
35585
35586 @table @samp
35587 @item qXfer:auxv:read::@var{offset},@var{length}
35588 @anchor{qXfer auxiliary vector read}
35589 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
35590 auxiliary vector}. Note @var{annex} must be empty.
35591
35592 This packet is not probed by default; the remote stub must request it,
35593 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35594
35595 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
35596 @anchor{qXfer target description read}
35597 Access the @dfn{target description}. @xref{Target Descriptions}. The
35598 annex specifies which XML document to access. The main description is
35599 always loaded from the @samp{target.xml} annex.
35600
35601 This packet is not probed by default; the remote stub must request it,
35602 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35603
35604 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
35605 @anchor{qXfer library list read}
35606 Access the target's list of loaded libraries. @xref{Library List Format}.
35607 The annex part of the generic @samp{qXfer} packet must be empty
35608 (@pxref{qXfer read}).
35609
35610 Targets which maintain a list of libraries in the program's memory do
35611 not need to implement this packet; it is designed for platforms where
35612 the operating system manages the list of loaded libraries.
35613
35614 This packet is not probed by default; the remote stub must request it,
35615 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35616
35617 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
35618 @anchor{qXfer svr4 library list read}
35619 Access the target's list of loaded libraries when the target is an SVR4
35620 platform. @xref{Library List Format for SVR4 Targets}. The annex part
35621 of the generic @samp{qXfer} packet must be empty (@pxref{qXfer read}).
35622
35623 This packet is optional for better performance on SVR4 targets.
35624 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
35625
35626 This packet is not probed by default; the remote stub must request it,
35627 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35628
35629 @item qXfer:memory-map:read::@var{offset},@var{length}
35630 @anchor{qXfer memory map read}
35631 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
35632 annex part of the generic @samp{qXfer} packet must be empty
35633 (@pxref{qXfer read}).
35634
35635 This packet is not probed by default; the remote stub must request it,
35636 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35637
35638 @item qXfer:sdata:read::@var{offset},@var{length}
35639 @anchor{qXfer sdata read}
35640
35641 Read contents of the extra collected static tracepoint marker
35642 information. The annex part of the generic @samp{qXfer} packet must
35643 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
35644 Action Lists}.
35645
35646 This packet is not probed by default; the remote stub must request it,
35647 by supplying an appropriate @samp{qSupported} response
35648 (@pxref{qSupported}).
35649
35650 @item qXfer:siginfo:read::@var{offset},@var{length}
35651 @anchor{qXfer siginfo read}
35652 Read contents of the extra signal information on the target
35653 system. The annex part of the generic @samp{qXfer} packet must be
35654 empty (@pxref{qXfer read}).
35655
35656 This packet is not probed by default; the remote stub must request it,
35657 by supplying an appropriate @samp{qSupported} response
35658 (@pxref{qSupported}).
35659
35660 @item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
35661 @anchor{qXfer spu read}
35662 Read contents of an @code{spufs} file on the target system. The
35663 annex specifies which file to read; it must be of the form
35664 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
35665 in the target process, and @var{name} identifes the @code{spufs} file
35666 in that context to be accessed.
35667
35668 This packet is not probed by default; the remote stub must request it,
35669 by supplying an appropriate @samp{qSupported} response
35670 (@pxref{qSupported}).
35671
35672 @item qXfer:threads:read::@var{offset},@var{length}
35673 @anchor{qXfer threads read}
35674 Access the list of threads on target. @xref{Thread List Format}. The
35675 annex part of the generic @samp{qXfer} packet must be empty
35676 (@pxref{qXfer read}).
35677
35678 This packet is not probed by default; the remote stub must request it,
35679 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35680
35681 @item qXfer:traceframe-info:read::@var{offset},@var{length}
35682 @anchor{qXfer traceframe info read}
35683
35684 Return a description of the current traceframe's contents.
35685 @xref{Traceframe Info Format}. The annex part of the generic
35686 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
35687
35688 This packet is not probed by default; the remote stub must request it,
35689 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35690
35691 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
35692 @anchor{qXfer unwind info block}
35693
35694 Return the unwind information block for @var{pc}. This packet is used
35695 on OpenVMS/ia64 to ask the kernel unwind information.
35696
35697 This packet is not probed by default.
35698
35699 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
35700 @anchor{qXfer fdpic loadmap read}
35701 Read contents of @code{loadmap}s on the target system. The
35702 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
35703 executable @code{loadmap} or interpreter @code{loadmap} to read.
35704
35705 This packet is not probed by default; the remote stub must request it,
35706 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35707
35708 @item qXfer:osdata:read::@var{offset},@var{length}
35709 @anchor{qXfer osdata read}
35710 Access the target's @dfn{operating system information}.
35711 @xref{Operating System Information}.
35712
35713 @end table
35714
35715 Reply:
35716 @table @samp
35717 @item m @var{data}
35718 Data @var{data} (@pxref{Binary Data}) has been read from the
35719 target. There may be more data at a higher address (although
35720 it is permitted to return @samp{m} even for the last valid
35721 block of data, as long as at least one byte of data was read).
35722 @var{data} may have fewer bytes than the @var{length} in the
35723 request.
35724
35725 @item l @var{data}
35726 Data @var{data} (@pxref{Binary Data}) has been read from the target.
35727 There is no more data to be read. @var{data} may have fewer bytes
35728 than the @var{length} in the request.
35729
35730 @item l
35731 The @var{offset} in the request is at the end of the data.
35732 There is no more data to be read.
35733
35734 @item E00
35735 The request was malformed, or @var{annex} was invalid.
35736
35737 @item E @var{nn}
35738 The offset was invalid, or there was an error encountered reading the data.
35739 @var{nn} is a hex-encoded @code{errno} value.
35740
35741 @item
35742 An empty reply indicates the @var{object} string was not recognized by
35743 the stub, or that the object does not support reading.
35744 @end table
35745
35746 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
35747 @cindex write data into object, remote request
35748 @anchor{qXfer write}
35749 Write uninterpreted bytes into the target's special data area
35750 identified by the keyword @var{object}, starting at @var{offset} bytes
35751 into the data. @var{data}@dots{} is the binary-encoded data
35752 (@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
35753 is specific to @var{object}; it can supply additional details about what data
35754 to access.
35755
35756 Here are the specific requests of this form defined so far. All
35757 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
35758 formats, listed below.
35759
35760 @table @samp
35761 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
35762 @anchor{qXfer siginfo write}
35763 Write @var{data} to the extra signal information on the target system.
35764 The annex part of the generic @samp{qXfer} packet must be
35765 empty (@pxref{qXfer write}).
35766
35767 This packet is not probed by default; the remote stub must request it,
35768 by supplying an appropriate @samp{qSupported} response
35769 (@pxref{qSupported}).
35770
35771 @item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
35772 @anchor{qXfer spu write}
35773 Write @var{data} to an @code{spufs} file on the target system. The
35774 annex specifies which file to write; it must be of the form
35775 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
35776 in the target process, and @var{name} identifes the @code{spufs} file
35777 in that context to be accessed.
35778
35779 This packet is not probed by default; the remote stub must request it,
35780 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
35781 @end table
35782
35783 Reply:
35784 @table @samp
35785 @item @var{nn}
35786 @var{nn} (hex encoded) is the number of bytes written.
35787 This may be fewer bytes than supplied in the request.
35788
35789 @item E00
35790 The request was malformed, or @var{annex} was invalid.
35791
35792 @item E @var{nn}
35793 The offset was invalid, or there was an error encountered writing the data.
35794 @var{nn} is a hex-encoded @code{errno} value.
35795
35796 @item
35797 An empty reply indicates the @var{object} string was not
35798 recognized by the stub, or that the object does not support writing.
35799 @end table
35800
35801 @item qXfer:@var{object}:@var{operation}:@dots{}
35802 Requests of this form may be added in the future. When a stub does
35803 not recognize the @var{object} keyword, or its support for
35804 @var{object} does not recognize the @var{operation} keyword, the stub
35805 must respond with an empty packet.
35806
35807 @item qAttached:@var{pid}
35808 @cindex query attached, remote request
35809 @cindex @samp{qAttached} packet
35810 Return an indication of whether the remote server attached to an
35811 existing process or created a new process. When the multiprocess
35812 protocol extensions are supported (@pxref{multiprocess extensions}),
35813 @var{pid} is an integer in hexadecimal format identifying the target
35814 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
35815 the query packet will be simplified as @samp{qAttached}.
35816
35817 This query is used, for example, to know whether the remote process
35818 should be detached or killed when a @value{GDBN} session is ended with
35819 the @code{quit} command.
35820
35821 Reply:
35822 @table @samp
35823 @item 1
35824 The remote server attached to an existing process.
35825 @item 0
35826 The remote server created a new process.
35827 @item E @var{NN}
35828 A badly formed request or an error was encountered.
35829 @end table
35830
35831 @end table
35832
35833 @node Architecture-Specific Protocol Details
35834 @section Architecture-Specific Protocol Details
35835
35836 This section describes how the remote protocol is applied to specific
35837 target architectures. Also see @ref{Standard Target Features}, for
35838 details of XML target descriptions for each architecture.
35839
35840 @subsection ARM
35841
35842 @subsubsection Breakpoint Kinds
35843
35844 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
35845
35846 @table @r
35847
35848 @item 2
35849 16-bit Thumb mode breakpoint.
35850
35851 @item 3
35852 32-bit Thumb mode (Thumb-2) breakpoint.
35853
35854 @item 4
35855 32-bit ARM mode breakpoint.
35856
35857 @end table
35858
35859 @subsection MIPS
35860
35861 @subsubsection Register Packet Format
35862
35863 The following @code{g}/@code{G} packets have previously been defined.
35864 In the below, some thirty-two bit registers are transferred as
35865 sixty-four bits. Those registers should be zero/sign extended (which?)
35866 to fill the space allocated. Register bytes are transferred in target
35867 byte order. The two nibbles within a register byte are transferred
35868 most-significant - least-significant.
35869
35870 @table @r
35871
35872 @item MIPS32
35873
35874 All registers are transferred as thirty-two bit quantities in the order:
35875 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
35876 registers; fsr; fir; fp.
35877
35878 @item MIPS64
35879
35880 All registers are transferred as sixty-four bit quantities (including
35881 thirty-two bit registers such as @code{sr}). The ordering is the same
35882 as @code{MIPS32}.
35883
35884 @end table
35885
35886 @node Tracepoint Packets
35887 @section Tracepoint Packets
35888 @cindex tracepoint packets
35889 @cindex packets, tracepoint
35890
35891 Here we describe the packets @value{GDBN} uses to implement
35892 tracepoints (@pxref{Tracepoints}).
35893
35894 @table @samp
35895
35896 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
35897 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
35898 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
35899 the tracepoint is disabled. @var{step} is the tracepoint's step
35900 count, and @var{pass} is its pass count. If an @samp{F} is present,
35901 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
35902 the number of bytes that the target should copy elsewhere to make room
35903 for the tracepoint. If an @samp{X} is present, it introduces a
35904 tracepoint condition, which consists of a hexadecimal length, followed
35905 by a comma and hex-encoded bytes, in a manner similar to action
35906 encodings as described below. If the trailing @samp{-} is present,
35907 further @samp{QTDP} packets will follow to specify this tracepoint's
35908 actions.
35909
35910 Replies:
35911 @table @samp
35912 @item OK
35913 The packet was understood and carried out.
35914 @item qRelocInsn
35915 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
35916 @item
35917 The packet was not recognized.
35918 @end table
35919
35920 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
35921 Define actions to be taken when a tracepoint is hit. @var{n} and
35922 @var{addr} must be the same as in the initial @samp{QTDP} packet for
35923 this tracepoint. This packet may only be sent immediately after
35924 another @samp{QTDP} packet that ended with a @samp{-}. If the
35925 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
35926 specifying more actions for this tracepoint.
35927
35928 In the series of action packets for a given tracepoint, at most one
35929 can have an @samp{S} before its first @var{action}. If such a packet
35930 is sent, it and the following packets define ``while-stepping''
35931 actions. Any prior packets define ordinary actions --- that is, those
35932 taken when the tracepoint is first hit. If no action packet has an
35933 @samp{S}, then all the packets in the series specify ordinary
35934 tracepoint actions.
35935
35936 The @samp{@var{action}@dots{}} portion of the packet is a series of
35937 actions, concatenated without separators. Each action has one of the
35938 following forms:
35939
35940 @table @samp
35941
35942 @item R @var{mask}
35943 Collect the registers whose bits are set in @var{mask}. @var{mask} is
35944 a hexadecimal number whose @var{i}'th bit is set if register number
35945 @var{i} should be collected. (The least significant bit is numbered
35946 zero.) Note that @var{mask} may be any number of digits long; it may
35947 not fit in a 32-bit word.
35948
35949 @item M @var{basereg},@var{offset},@var{len}
35950 Collect @var{len} bytes of memory starting at the address in register
35951 number @var{basereg}, plus @var{offset}. If @var{basereg} is
35952 @samp{-1}, then the range has a fixed address: @var{offset} is the
35953 address of the lowest byte to collect. The @var{basereg},
35954 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
35955 values (the @samp{-1} value for @var{basereg} is a special case).
35956
35957 @item X @var{len},@var{expr}
35958 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
35959 it directs. @var{expr} is an agent expression, as described in
35960 @ref{Agent Expressions}. Each byte of the expression is encoded as a
35961 two-digit hex number in the packet; @var{len} is the number of bytes
35962 in the expression (and thus one-half the number of hex digits in the
35963 packet).
35964
35965 @end table
35966
35967 Any number of actions may be packed together in a single @samp{QTDP}
35968 packet, as long as the packet does not exceed the maximum packet
35969 length (400 bytes, for many stubs). There may be only one @samp{R}
35970 action per tracepoint, and it must precede any @samp{M} or @samp{X}
35971 actions. Any registers referred to by @samp{M} and @samp{X} actions
35972 must be collected by a preceding @samp{R} action. (The
35973 ``while-stepping'' actions are treated as if they were attached to a
35974 separate tracepoint, as far as these restrictions are concerned.)
35975
35976 Replies:
35977 @table @samp
35978 @item OK
35979 The packet was understood and carried out.
35980 @item qRelocInsn
35981 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
35982 @item
35983 The packet was not recognized.
35984 @end table
35985
35986 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
35987 @cindex @samp{QTDPsrc} packet
35988 Specify a source string of tracepoint @var{n} at address @var{addr}.
35989 This is useful to get accurate reproduction of the tracepoints
35990 originally downloaded at the beginning of the trace run. @var{type}
35991 is the name of the tracepoint part, such as @samp{cond} for the
35992 tracepoint's conditional expression (see below for a list of types), while
35993 @var{bytes} is the string, encoded in hexadecimal.
35994
35995 @var{start} is the offset of the @var{bytes} within the overall source
35996 string, while @var{slen} is the total length of the source string.
35997 This is intended for handling source strings that are longer than will
35998 fit in a single packet.
35999 @c Add detailed example when this info is moved into a dedicated
36000 @c tracepoint descriptions section.
36001
36002 The available string types are @samp{at} for the location,
36003 @samp{cond} for the conditional, and @samp{cmd} for an action command.
36004 @value{GDBN} sends a separate packet for each command in the action
36005 list, in the same order in which the commands are stored in the list.
36006
36007 The target does not need to do anything with source strings except
36008 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
36009 query packets.
36010
36011 Although this packet is optional, and @value{GDBN} will only send it
36012 if the target replies with @samp{TracepointSource} @xref{General
36013 Query Packets}, it makes both disconnected tracing and trace files
36014 much easier to use. Otherwise the user must be careful that the
36015 tracepoints in effect while looking at trace frames are identical to
36016 the ones in effect during the trace run; even a small discrepancy
36017 could cause @samp{tdump} not to work, or a particular trace frame not
36018 be found.
36019
36020 @item QTDV:@var{n}:@var{value}
36021 @cindex define trace state variable, remote request
36022 @cindex @samp{QTDV} packet
36023 Create a new trace state variable, number @var{n}, with an initial
36024 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
36025 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
36026 the option of not using this packet for initial values of zero; the
36027 target should simply create the trace state variables as they are
36028 mentioned in expressions.
36029
36030 @item QTFrame:@var{n}
36031 Select the @var{n}'th tracepoint frame from the buffer, and use the
36032 register and memory contents recorded there to answer subsequent
36033 request packets from @value{GDBN}.
36034
36035 A successful reply from the stub indicates that the stub has found the
36036 requested frame. The response is a series of parts, concatenated
36037 without separators, describing the frame we selected. Each part has
36038 one of the following forms:
36039
36040 @table @samp
36041 @item F @var{f}
36042 The selected frame is number @var{n} in the trace frame buffer;
36043 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
36044 was no frame matching the criteria in the request packet.
36045
36046 @item T @var{t}
36047 The selected trace frame records a hit of tracepoint number @var{t};
36048 @var{t} is a hexadecimal number.
36049
36050 @end table
36051
36052 @item QTFrame:pc:@var{addr}
36053 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
36054 currently selected frame whose PC is @var{addr};
36055 @var{addr} is a hexadecimal number.
36056
36057 @item QTFrame:tdp:@var{t}
36058 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
36059 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
36060 is a hexadecimal number.
36061
36062 @item QTFrame:range:@var{start}:@var{end}
36063 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
36064 currently selected frame whose PC is between @var{start} (inclusive)
36065 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
36066 numbers.
36067
36068 @item QTFrame:outside:@var{start}:@var{end}
36069 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
36070 frame @emph{outside} the given range of addresses (exclusive).
36071
36072 @item qTMinFTPILen
36073 This packet requests the minimum length of instruction at which a fast
36074 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
36075 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
36076 it depends on the target system being able to create trampolines in
36077 the first 64K of memory, which might or might not be possible for that
36078 system. So the reply to this packet will be 4 if it is able to
36079 arrange for that.
36080
36081 Replies:
36082
36083 @table @samp
36084 @item 0
36085 The minimum instruction length is currently unknown.
36086 @item @var{length}
36087 The minimum instruction length is @var{length}, where @var{length} is greater
36088 or equal to 1. @var{length} is a hexadecimal number. A reply of 1 means
36089 that a fast tracepoint may be placed on any instruction regardless of size.
36090 @item E
36091 An error has occurred.
36092 @item
36093 An empty reply indicates that the request is not supported by the stub.
36094 @end table
36095
36096 @item QTStart
36097 Begin the tracepoint experiment. Begin collecting data from
36098 tracepoint hits in the trace frame buffer. This packet supports the
36099 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
36100 instruction reply packet}).
36101
36102 @item QTStop
36103 End the tracepoint experiment. Stop collecting trace frames.
36104
36105 @item QTEnable:@var{n}:@var{addr}
36106 @anchor{QTEnable}
36107 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
36108 experiment. If the tracepoint was previously disabled, then collection
36109 of data from it will resume.
36110
36111 @item QTDisable:@var{n}:@var{addr}
36112 @anchor{QTDisable}
36113 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
36114 experiment. No more data will be collected from the tracepoint unless
36115 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
36116
36117 @item QTinit
36118 Clear the table of tracepoints, and empty the trace frame buffer.
36119
36120 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
36121 Establish the given ranges of memory as ``transparent''. The stub
36122 will answer requests for these ranges from memory's current contents,
36123 if they were not collected as part of the tracepoint hit.
36124
36125 @value{GDBN} uses this to mark read-only regions of memory, like those
36126 containing program code. Since these areas never change, they should
36127 still have the same contents they did when the tracepoint was hit, so
36128 there's no reason for the stub to refuse to provide their contents.
36129
36130 @item QTDisconnected:@var{value}
36131 Set the choice to what to do with the tracing run when @value{GDBN}
36132 disconnects from the target. A @var{value} of 1 directs the target to
36133 continue the tracing run, while 0 tells the target to stop tracing if
36134 @value{GDBN} is no longer in the picture.
36135
36136 @item qTStatus
36137 Ask the stub if there is a trace experiment running right now.
36138
36139 The reply has the form:
36140
36141 @table @samp
36142
36143 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
36144 @var{running} is a single digit @code{1} if the trace is presently
36145 running, or @code{0} if not. It is followed by semicolon-separated
36146 optional fields that an agent may use to report additional status.
36147
36148 @end table
36149
36150 If the trace is not running, the agent may report any of several
36151 explanations as one of the optional fields:
36152
36153 @table @samp
36154
36155 @item tnotrun:0
36156 No trace has been run yet.
36157
36158 @item tstop[:@var{text}]:0
36159 The trace was stopped by a user-originated stop command. The optional
36160 @var{text} field is a user-supplied string supplied as part of the
36161 stop command (for instance, an explanation of why the trace was
36162 stopped manually). It is hex-encoded.
36163
36164 @item tfull:0
36165 The trace stopped because the trace buffer filled up.
36166
36167 @item tdisconnected:0
36168 The trace stopped because @value{GDBN} disconnected from the target.
36169
36170 @item tpasscount:@var{tpnum}
36171 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
36172
36173 @item terror:@var{text}:@var{tpnum}
36174 The trace stopped because tracepoint @var{tpnum} had an error. The
36175 string @var{text} is available to describe the nature of the error
36176 (for instance, a divide by zero in the condition expression).
36177 @var{text} is hex encoded.
36178
36179 @item tunknown:0
36180 The trace stopped for some other reason.
36181
36182 @end table
36183
36184 Additional optional fields supply statistical and other information.
36185 Although not required, they are extremely useful for users monitoring
36186 the progress of a trace run. If a trace has stopped, and these
36187 numbers are reported, they must reflect the state of the just-stopped
36188 trace.
36189
36190 @table @samp
36191
36192 @item tframes:@var{n}
36193 The number of trace frames in the buffer.
36194
36195 @item tcreated:@var{n}
36196 The total number of trace frames created during the run. This may
36197 be larger than the trace frame count, if the buffer is circular.
36198
36199 @item tsize:@var{n}
36200 The total size of the trace buffer, in bytes.
36201
36202 @item tfree:@var{n}
36203 The number of bytes still unused in the buffer.
36204
36205 @item circular:@var{n}
36206 The value of the circular trace buffer flag. @code{1} means that the
36207 trace buffer is circular and old trace frames will be discarded if
36208 necessary to make room, @code{0} means that the trace buffer is linear
36209 and may fill up.
36210
36211 @item disconn:@var{n}
36212 The value of the disconnected tracing flag. @code{1} means that
36213 tracing will continue after @value{GDBN} disconnects, @code{0} means
36214 that the trace run will stop.
36215
36216 @end table
36217
36218 @item qTP:@var{tp}:@var{addr}
36219 @cindex tracepoint status, remote request
36220 @cindex @samp{qTP} packet
36221 Ask the stub for the current state of tracepoint number @var{tp} at
36222 address @var{addr}.
36223
36224 Replies:
36225 @table @samp
36226 @item V@var{hits}:@var{usage}
36227 The tracepoint has been hit @var{hits} times so far during the trace
36228 run, and accounts for @var{usage} in the trace buffer. Note that
36229 @code{while-stepping} steps are not counted as separate hits, but the
36230 steps' space consumption is added into the usage number.
36231
36232 @end table
36233
36234 @item qTV:@var{var}
36235 @cindex trace state variable value, remote request
36236 @cindex @samp{qTV} packet
36237 Ask the stub for the value of the trace state variable number @var{var}.
36238
36239 Replies:
36240 @table @samp
36241 @item V@var{value}
36242 The value of the variable is @var{value}. This will be the current
36243 value of the variable if the user is examining a running target, or a
36244 saved value if the variable was collected in the trace frame that the
36245 user is looking at. Note that multiple requests may result in
36246 different reply values, such as when requesting values while the
36247 program is running.
36248
36249 @item U
36250 The value of the variable is unknown. This would occur, for example,
36251 if the user is examining a trace frame in which the requested variable
36252 was not collected.
36253 @end table
36254
36255 @item qTfP
36256 @itemx qTsP
36257 These packets request data about tracepoints that are being used by
36258 the target. @value{GDBN} sends @code{qTfP} to get the first piece
36259 of data, and multiple @code{qTsP} to get additional pieces. Replies
36260 to these packets generally take the form of the @code{QTDP} packets
36261 that define tracepoints. (FIXME add detailed syntax)
36262
36263 @item qTfV
36264 @itemx qTsV
36265 These packets request data about trace state variables that are on the
36266 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
36267 and multiple @code{qTsV} to get additional variables. Replies to
36268 these packets follow the syntax of the @code{QTDV} packets that define
36269 trace state variables.
36270
36271 @item qTfSTM
36272 @itemx qTsSTM
36273 These packets request data about static tracepoint markers that exist
36274 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
36275 first piece of data, and multiple @code{qTsSTM} to get additional
36276 pieces. Replies to these packets take the following form:
36277
36278 Reply:
36279 @table @samp
36280 @item m @var{address}:@var{id}:@var{extra}
36281 A single marker
36282 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
36283 a comma-separated list of markers
36284 @item l
36285 (lower case letter @samp{L}) denotes end of list.
36286 @item E @var{nn}
36287 An error occurred. @var{nn} are hex digits.
36288 @item
36289 An empty reply indicates that the request is not supported by the
36290 stub.
36291 @end table
36292
36293 @var{address} is encoded in hex.
36294 @var{id} and @var{extra} are strings encoded in hex.
36295
36296 In response to each query, the target will reply with a list of one or
36297 more markers, separated by commas. @value{GDBN} will respond to each
36298 reply with a request for more markers (using the @samp{qs} form of the
36299 query), until the target responds with @samp{l} (lower-case ell, for
36300 @dfn{last}).
36301
36302 @item qTSTMat:@var{address}
36303 This packets requests data about static tracepoint markers in the
36304 target program at @var{address}. Replies to this packet follow the
36305 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
36306 tracepoint markers.
36307
36308 @item QTSave:@var{filename}
36309 This packet directs the target to save trace data to the file name
36310 @var{filename} in the target's filesystem. @var{filename} is encoded
36311 as a hex string; the interpretation of the file name (relative vs
36312 absolute, wild cards, etc) is up to the target.
36313
36314 @item qTBuffer:@var{offset},@var{len}
36315 Return up to @var{len} bytes of the current contents of trace buffer,
36316 starting at @var{offset}. The trace buffer is treated as if it were
36317 a contiguous collection of traceframes, as per the trace file format.
36318 The reply consists as many hex-encoded bytes as the target can deliver
36319 in a packet; it is not an error to return fewer than were asked for.
36320 A reply consisting of just @code{l} indicates that no bytes are
36321 available.
36322
36323 @item QTBuffer:circular:@var{value}
36324 This packet directs the target to use a circular trace buffer if
36325 @var{value} is 1, or a linear buffer if the value is 0.
36326
36327 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
36328 This packet adds optional textual notes to the trace run. Allowable
36329 types include @code{user}, @code{notes}, and @code{tstop}, the
36330 @var{text} fields are arbitrary strings, hex-encoded.
36331
36332 @end table
36333
36334 @subsection Relocate instruction reply packet
36335 When installing fast tracepoints in memory, the target may need to
36336 relocate the instruction currently at the tracepoint address to a
36337 different address in memory. For most instructions, a simple copy is
36338 enough, but, for example, call instructions that implicitly push the
36339 return address on the stack, and relative branches or other
36340 PC-relative instructions require offset adjustment, so that the effect
36341 of executing the instruction at a different address is the same as if
36342 it had executed in the original location.
36343
36344 In response to several of the tracepoint packets, the target may also
36345 respond with a number of intermediate @samp{qRelocInsn} request
36346 packets before the final result packet, to have @value{GDBN} handle
36347 this relocation operation. If a packet supports this mechanism, its
36348 documentation will explicitly say so. See for example the above
36349 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
36350 format of the request is:
36351
36352 @table @samp
36353 @item qRelocInsn:@var{from};@var{to}
36354
36355 This requests @value{GDBN} to copy instruction at address @var{from}
36356 to address @var{to}, possibly adjusted so that executing the
36357 instruction at @var{to} has the same effect as executing it at
36358 @var{from}. @value{GDBN} writes the adjusted instruction to target
36359 memory starting at @var{to}.
36360 @end table
36361
36362 Replies:
36363 @table @samp
36364 @item qRelocInsn:@var{adjusted_size}
36365 Informs the stub the relocation is complete. @var{adjusted_size} is
36366 the length in bytes of resulting relocated instruction sequence.
36367 @item E @var{NN}
36368 A badly formed request was detected, or an error was encountered while
36369 relocating the instruction.
36370 @end table
36371
36372 @node Host I/O Packets
36373 @section Host I/O Packets
36374 @cindex Host I/O, remote protocol
36375 @cindex file transfer, remote protocol
36376
36377 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
36378 operations on the far side of a remote link. For example, Host I/O is
36379 used to upload and download files to a remote target with its own
36380 filesystem. Host I/O uses the same constant values and data structure
36381 layout as the target-initiated File-I/O protocol. However, the
36382 Host I/O packets are structured differently. The target-initiated
36383 protocol relies on target memory to store parameters and buffers.
36384 Host I/O requests are initiated by @value{GDBN}, and the
36385 target's memory is not involved. @xref{File-I/O Remote Protocol
36386 Extension}, for more details on the target-initiated protocol.
36387
36388 The Host I/O request packets all encode a single operation along with
36389 its arguments. They have this format:
36390
36391 @table @samp
36392
36393 @item vFile:@var{operation}: @var{parameter}@dots{}
36394 @var{operation} is the name of the particular request; the target
36395 should compare the entire packet name up to the second colon when checking
36396 for a supported operation. The format of @var{parameter} depends on
36397 the operation. Numbers are always passed in hexadecimal. Negative
36398 numbers have an explicit minus sign (i.e.@: two's complement is not
36399 used). Strings (e.g.@: filenames) are encoded as a series of
36400 hexadecimal bytes. The last argument to a system call may be a
36401 buffer of escaped binary data (@pxref{Binary Data}).
36402
36403 @end table
36404
36405 The valid responses to Host I/O packets are:
36406
36407 @table @samp
36408
36409 @item F @var{result} [, @var{errno}] [; @var{attachment}]
36410 @var{result} is the integer value returned by this operation, usually
36411 non-negative for success and -1 for errors. If an error has occured,
36412 @var{errno} will be included in the result. @var{errno} will have a
36413 value defined by the File-I/O protocol (@pxref{Errno Values}). For
36414 operations which return data, @var{attachment} supplies the data as a
36415 binary buffer. Binary buffers in response packets are escaped in the
36416 normal way (@pxref{Binary Data}). See the individual packet
36417 documentation for the interpretation of @var{result} and
36418 @var{attachment}.
36419
36420 @item
36421 An empty response indicates that this operation is not recognized.
36422
36423 @end table
36424
36425 These are the supported Host I/O operations:
36426
36427 @table @samp
36428 @item vFile:open: @var{pathname}, @var{flags}, @var{mode}
36429 Open a file at @var{pathname} and return a file descriptor for it, or
36430 return -1 if an error occurs. @var{pathname} is a string,
36431 @var{flags} is an integer indicating a mask of open flags
36432 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
36433 of mode bits to use if the file is created (@pxref{mode_t Values}).
36434 @xref{open}, for details of the open flags and mode values.
36435
36436 @item vFile:close: @var{fd}
36437 Close the open file corresponding to @var{fd} and return 0, or
36438 -1 if an error occurs.
36439
36440 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
36441 Read data from the open file corresponding to @var{fd}. Up to
36442 @var{count} bytes will be read from the file, starting at @var{offset}
36443 relative to the start of the file. The target may read fewer bytes;
36444 common reasons include packet size limits and an end-of-file
36445 condition. The number of bytes read is returned. Zero should only be
36446 returned for a successful read at the end of the file, or if
36447 @var{count} was zero.
36448
36449 The data read should be returned as a binary attachment on success.
36450 If zero bytes were read, the response should include an empty binary
36451 attachment (i.e.@: a trailing semicolon). The return value is the
36452 number of target bytes read; the binary attachment may be longer if
36453 some characters were escaped.
36454
36455 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
36456 Write @var{data} (a binary buffer) to the open file corresponding
36457 to @var{fd}. Start the write at @var{offset} from the start of the
36458 file. Unlike many @code{write} system calls, there is no
36459 separate @var{count} argument; the length of @var{data} in the
36460 packet is used. @samp{vFile:write} returns the number of bytes written,
36461 which may be shorter than the length of @var{data}, or -1 if an
36462 error occurred.
36463
36464 @item vFile:unlink: @var{pathname}
36465 Delete the file at @var{pathname} on the target. Return 0,
36466 or -1 if an error occurs. @var{pathname} is a string.
36467
36468 @item vFile:readlink: @var{filename}
36469 Read value of symbolic link @var{filename} on the target. Return
36470 the number of bytes read, or -1 if an error occurs.
36471
36472 The data read should be returned as a binary attachment on success.
36473 If zero bytes were read, the response should include an empty binary
36474 attachment (i.e.@: a trailing semicolon). The return value is the
36475 number of target bytes read; the binary attachment may be longer if
36476 some characters were escaped.
36477
36478 @end table
36479
36480 @node Interrupts
36481 @section Interrupts
36482 @cindex interrupts (remote protocol)
36483
36484 When a program on the remote target is running, @value{GDBN} may
36485 attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
36486 a @code{BREAK} followed by @code{g},
36487 control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
36488
36489 The precise meaning of @code{BREAK} is defined by the transport
36490 mechanism and may, in fact, be undefined. @value{GDBN} does not
36491 currently define a @code{BREAK} mechanism for any of the network
36492 interfaces except for TCP, in which case @value{GDBN} sends the
36493 @code{telnet} BREAK sequence.
36494
36495 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
36496 transport mechanisms. It is represented by sending the single byte
36497 @code{0x03} without any of the usual packet overhead described in
36498 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
36499 transmitted as part of a packet, it is considered to be packet data
36500 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
36501 (@pxref{X packet}), used for binary downloads, may include an unescaped
36502 @code{0x03} as part of its packet.
36503
36504 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
36505 When Linux kernel receives this sequence from serial port,
36506 it stops execution and connects to gdb.
36507
36508 Stubs are not required to recognize these interrupt mechanisms and the
36509 precise meaning associated with receipt of the interrupt is
36510 implementation defined. If the target supports debugging of multiple
36511 threads and/or processes, it should attempt to interrupt all
36512 currently-executing threads and processes.
36513 If the stub is successful at interrupting the
36514 running program, it should send one of the stop
36515 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
36516 of successfully stopping the program in all-stop mode, and a stop reply
36517 for each stopped thread in non-stop mode.
36518 Interrupts received while the
36519 program is stopped are discarded.
36520
36521 @node Notification Packets
36522 @section Notification Packets
36523 @cindex notification packets
36524 @cindex packets, notification
36525
36526 The @value{GDBN} remote serial protocol includes @dfn{notifications},
36527 packets that require no acknowledgment. Both the GDB and the stub
36528 may send notifications (although the only notifications defined at
36529 present are sent by the stub). Notifications carry information
36530 without incurring the round-trip latency of an acknowledgment, and so
36531 are useful for low-impact communications where occasional packet loss
36532 is not a problem.
36533
36534 A notification packet has the form @samp{% @var{data} #
36535 @var{checksum}}, where @var{data} is the content of the notification,
36536 and @var{checksum} is a checksum of @var{data}, computed and formatted
36537 as for ordinary @value{GDBN} packets. A notification's @var{data}
36538 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
36539 receiving a notification, the recipient sends no @samp{+} or @samp{-}
36540 to acknowledge the notification's receipt or to report its corruption.
36541
36542 Every notification's @var{data} begins with a name, which contains no
36543 colon characters, followed by a colon character.
36544
36545 Recipients should silently ignore corrupted notifications and
36546 notifications they do not understand. Recipients should restart
36547 timeout periods on receipt of a well-formed notification, whether or
36548 not they understand it.
36549
36550 Senders should only send the notifications described here when this
36551 protocol description specifies that they are permitted. In the
36552 future, we may extend the protocol to permit existing notifications in
36553 new contexts; this rule helps older senders avoid confusing newer
36554 recipients.
36555
36556 (Older versions of @value{GDBN} ignore bytes received until they see
36557 the @samp{$} byte that begins an ordinary packet, so new stubs may
36558 transmit notifications without fear of confusing older clients. There
36559 are no notifications defined for @value{GDBN} to send at the moment, but we
36560 assume that most older stubs would ignore them, as well.)
36561
36562 The following notification packets from the stub to @value{GDBN} are
36563 defined:
36564
36565 @table @samp
36566 @item Stop: @var{reply}
36567 Report an asynchronous stop event in non-stop mode.
36568 The @var{reply} has the form of a stop reply, as
36569 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
36570 for information on how these notifications are acknowledged by
36571 @value{GDBN}.
36572 @end table
36573
36574 @node Remote Non-Stop
36575 @section Remote Protocol Support for Non-Stop Mode
36576
36577 @value{GDBN}'s remote protocol supports non-stop debugging of
36578 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
36579 supports non-stop mode, it should report that to @value{GDBN} by including
36580 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
36581
36582 @value{GDBN} typically sends a @samp{QNonStop} packet only when
36583 establishing a new connection with the stub. Entering non-stop mode
36584 does not alter the state of any currently-running threads, but targets
36585 must stop all threads in any already-attached processes when entering
36586 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
36587 probe the target state after a mode change.
36588
36589 In non-stop mode, when an attached process encounters an event that
36590 would otherwise be reported with a stop reply, it uses the
36591 asynchronous notification mechanism (@pxref{Notification Packets}) to
36592 inform @value{GDBN}. In contrast to all-stop mode, where all threads
36593 in all processes are stopped when a stop reply is sent, in non-stop
36594 mode only the thread reporting the stop event is stopped. That is,
36595 when reporting a @samp{S} or @samp{T} response to indicate completion
36596 of a step operation, hitting a breakpoint, or a fault, only the
36597 affected thread is stopped; any other still-running threads continue
36598 to run. When reporting a @samp{W} or @samp{X} response, all running
36599 threads belonging to other attached processes continue to run.
36600
36601 Only one stop reply notification at a time may be pending; if
36602 additional stop events occur before @value{GDBN} has acknowledged the
36603 previous notification, they must be queued by the stub for later
36604 synchronous transmission in response to @samp{vStopped} packets from
36605 @value{GDBN}. Because the notification mechanism is unreliable,
36606 the stub is permitted to resend a stop reply notification
36607 if it believes @value{GDBN} may not have received it. @value{GDBN}
36608 ignores additional stop reply notifications received before it has
36609 finished processing a previous notification and the stub has completed
36610 sending any queued stop events.
36611
36612 Otherwise, @value{GDBN} must be prepared to receive a stop reply
36613 notification at any time. Specifically, they may appear when
36614 @value{GDBN} is not otherwise reading input from the stub, or when
36615 @value{GDBN} is expecting to read a normal synchronous response or a
36616 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
36617 Notification packets are distinct from any other communication from
36618 the stub so there is no ambiguity.
36619
36620 After receiving a stop reply notification, @value{GDBN} shall
36621 acknowledge it by sending a @samp{vStopped} packet (@pxref{vStopped packet})
36622 as a regular, synchronous request to the stub. Such acknowledgment
36623 is not required to happen immediately, as @value{GDBN} is permitted to
36624 send other, unrelated packets to the stub first, which the stub should
36625 process normally.
36626
36627 Upon receiving a @samp{vStopped} packet, if the stub has other queued
36628 stop events to report to @value{GDBN}, it shall respond by sending a
36629 normal stop reply response. @value{GDBN} shall then send another
36630 @samp{vStopped} packet to solicit further responses; again, it is
36631 permitted to send other, unrelated packets as well which the stub
36632 should process normally.
36633
36634 If the stub receives a @samp{vStopped} packet and there are no
36635 additional stop events to report, the stub shall return an @samp{OK}
36636 response. At this point, if further stop events occur, the stub shall
36637 send a new stop reply notification, @value{GDBN} shall accept the
36638 notification, and the process shall be repeated.
36639
36640 In non-stop mode, the target shall respond to the @samp{?} packet as
36641 follows. First, any incomplete stop reply notification/@samp{vStopped}
36642 sequence in progress is abandoned. The target must begin a new
36643 sequence reporting stop events for all stopped threads, whether or not
36644 it has previously reported those events to @value{GDBN}. The first
36645 stop reply is sent as a synchronous reply to the @samp{?} packet, and
36646 subsequent stop replies are sent as responses to @samp{vStopped} packets
36647 using the mechanism described above. The target must not send
36648 asynchronous stop reply notifications until the sequence is complete.
36649 If all threads are running when the target receives the @samp{?} packet,
36650 or if the target is not attached to any process, it shall respond
36651 @samp{OK}.
36652
36653 @node Packet Acknowledgment
36654 @section Packet Acknowledgment
36655
36656 @cindex acknowledgment, for @value{GDBN} remote
36657 @cindex packet acknowledgment, for @value{GDBN} remote
36658 By default, when either the host or the target machine receives a packet,
36659 the first response expected is an acknowledgment: either @samp{+} (to indicate
36660 the package was received correctly) or @samp{-} (to request retransmission).
36661 This mechanism allows the @value{GDBN} remote protocol to operate over
36662 unreliable transport mechanisms, such as a serial line.
36663
36664 In cases where the transport mechanism is itself reliable (such as a pipe or
36665 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
36666 It may be desirable to disable them in that case to reduce communication
36667 overhead, or for other reasons. This can be accomplished by means of the
36668 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
36669
36670 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
36671 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
36672 and response format still includes the normal checksum, as described in
36673 @ref{Overview}, but the checksum may be ignored by the receiver.
36674
36675 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
36676 no-acknowledgment mode, it should report that to @value{GDBN}
36677 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
36678 @pxref{qSupported}.
36679 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
36680 disabled via the @code{set remote noack-packet off} command
36681 (@pxref{Remote Configuration}),
36682 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
36683 Only then may the stub actually turn off packet acknowledgments.
36684 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
36685 response, which can be safely ignored by the stub.
36686
36687 Note that @code{set remote noack-packet} command only affects negotiation
36688 between @value{GDBN} and the stub when subsequent connections are made;
36689 it does not affect the protocol acknowledgment state for any current
36690 connection.
36691 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
36692 new connection is established,
36693 there is also no protocol request to re-enable the acknowledgments
36694 for the current connection, once disabled.
36695
36696 @node Examples
36697 @section Examples
36698
36699 Example sequence of a target being re-started. Notice how the restart
36700 does not get any direct output:
36701
36702 @smallexample
36703 -> @code{R00}
36704 <- @code{+}
36705 @emph{target restarts}
36706 -> @code{?}
36707 <- @code{+}
36708 <- @code{T001:1234123412341234}
36709 -> @code{+}
36710 @end smallexample
36711
36712 Example sequence of a target being stepped by a single instruction:
36713
36714 @smallexample
36715 -> @code{G1445@dots{}}
36716 <- @code{+}
36717 -> @code{s}
36718 <- @code{+}
36719 @emph{time passes}
36720 <- @code{T001:1234123412341234}
36721 -> @code{+}
36722 -> @code{g}
36723 <- @code{+}
36724 <- @code{1455@dots{}}
36725 -> @code{+}
36726 @end smallexample
36727
36728 @node File-I/O Remote Protocol Extension
36729 @section File-I/O Remote Protocol Extension
36730 @cindex File-I/O remote protocol extension
36731
36732 @menu
36733 * File-I/O Overview::
36734 * Protocol Basics::
36735 * The F Request Packet::
36736 * The F Reply Packet::
36737 * The Ctrl-C Message::
36738 * Console I/O::
36739 * List of Supported Calls::
36740 * Protocol-specific Representation of Datatypes::
36741 * Constants::
36742 * File-I/O Examples::
36743 @end menu
36744
36745 @node File-I/O Overview
36746 @subsection File-I/O Overview
36747 @cindex file-i/o overview
36748
36749 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
36750 target to use the host's file system and console I/O to perform various
36751 system calls. System calls on the target system are translated into a
36752 remote protocol packet to the host system, which then performs the needed
36753 actions and returns a response packet to the target system.
36754 This simulates file system operations even on targets that lack file systems.
36755
36756 The protocol is defined to be independent of both the host and target systems.
36757 It uses its own internal representation of datatypes and values. Both
36758 @value{GDBN} and the target's @value{GDBN} stub are responsible for
36759 translating the system-dependent value representations into the internal
36760 protocol representations when data is transmitted.
36761
36762 The communication is synchronous. A system call is possible only when
36763 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
36764 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
36765 the target is stopped to allow deterministic access to the target's
36766 memory. Therefore File-I/O is not interruptible by target signals. On
36767 the other hand, it is possible to interrupt File-I/O by a user interrupt
36768 (@samp{Ctrl-C}) within @value{GDBN}.
36769
36770 The target's request to perform a host system call does not finish
36771 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
36772 after finishing the system call, the target returns to continuing the
36773 previous activity (continue, step). No additional continue or step
36774 request from @value{GDBN} is required.
36775
36776 @smallexample
36777 (@value{GDBP}) continue
36778 <- target requests 'system call X'
36779 target is stopped, @value{GDBN} executes system call
36780 -> @value{GDBN} returns result
36781 ... target continues, @value{GDBN} returns to wait for the target
36782 <- target hits breakpoint and sends a Txx packet
36783 @end smallexample
36784
36785 The protocol only supports I/O on the console and to regular files on
36786 the host file system. Character or block special devices, pipes,
36787 named pipes, sockets or any other communication method on the host
36788 system are not supported by this protocol.
36789
36790 File I/O is not supported in non-stop mode.
36791
36792 @node Protocol Basics
36793 @subsection Protocol Basics
36794 @cindex protocol basics, file-i/o
36795
36796 The File-I/O protocol uses the @code{F} packet as the request as well
36797 as reply packet. Since a File-I/O system call can only occur when
36798 @value{GDBN} is waiting for a response from the continuing or stepping target,
36799 the File-I/O request is a reply that @value{GDBN} has to expect as a result
36800 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
36801 This @code{F} packet contains all information needed to allow @value{GDBN}
36802 to call the appropriate host system call:
36803
36804 @itemize @bullet
36805 @item
36806 A unique identifier for the requested system call.
36807
36808 @item
36809 All parameters to the system call. Pointers are given as addresses
36810 in the target memory address space. Pointers to strings are given as
36811 pointer/length pair. Numerical values are given as they are.
36812 Numerical control flags are given in a protocol-specific representation.
36813
36814 @end itemize
36815
36816 At this point, @value{GDBN} has to perform the following actions.
36817
36818 @itemize @bullet
36819 @item
36820 If the parameters include pointer values to data needed as input to a
36821 system call, @value{GDBN} requests this data from the target with a
36822 standard @code{m} packet request. This additional communication has to be
36823 expected by the target implementation and is handled as any other @code{m}
36824 packet.
36825
36826 @item
36827 @value{GDBN} translates all value from protocol representation to host
36828 representation as needed. Datatypes are coerced into the host types.
36829
36830 @item
36831 @value{GDBN} calls the system call.
36832
36833 @item
36834 It then coerces datatypes back to protocol representation.
36835
36836 @item
36837 If the system call is expected to return data in buffer space specified
36838 by pointer parameters to the call, the data is transmitted to the
36839 target using a @code{M} or @code{X} packet. This packet has to be expected
36840 by the target implementation and is handled as any other @code{M} or @code{X}
36841 packet.
36842
36843 @end itemize
36844
36845 Eventually @value{GDBN} replies with another @code{F} packet which contains all
36846 necessary information for the target to continue. This at least contains
36847
36848 @itemize @bullet
36849 @item
36850 Return value.
36851
36852 @item
36853 @code{errno}, if has been changed by the system call.
36854
36855 @item
36856 ``Ctrl-C'' flag.
36857
36858 @end itemize
36859
36860 After having done the needed type and value coercion, the target continues
36861 the latest continue or step action.
36862
36863 @node The F Request Packet
36864 @subsection The @code{F} Request Packet
36865 @cindex file-i/o request packet
36866 @cindex @code{F} request packet
36867
36868 The @code{F} request packet has the following format:
36869
36870 @table @samp
36871 @item F@var{call-id},@var{parameter@dots{}}
36872
36873 @var{call-id} is the identifier to indicate the host system call to be called.
36874 This is just the name of the function.
36875
36876 @var{parameter@dots{}} are the parameters to the system call.
36877 Parameters are hexadecimal integer values, either the actual values in case
36878 of scalar datatypes, pointers to target buffer space in case of compound
36879 datatypes and unspecified memory areas, or pointer/length pairs in case
36880 of string parameters. These are appended to the @var{call-id} as a
36881 comma-delimited list. All values are transmitted in ASCII
36882 string representation, pointer/length pairs separated by a slash.
36883
36884 @end table
36885
36886
36887
36888 @node The F Reply Packet
36889 @subsection The @code{F} Reply Packet
36890 @cindex file-i/o reply packet
36891 @cindex @code{F} reply packet
36892
36893 The @code{F} reply packet has the following format:
36894
36895 @table @samp
36896
36897 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
36898
36899 @var{retcode} is the return code of the system call as hexadecimal value.
36900
36901 @var{errno} is the @code{errno} set by the call, in protocol-specific
36902 representation.
36903 This parameter can be omitted if the call was successful.
36904
36905 @var{Ctrl-C flag} is only sent if the user requested a break. In this
36906 case, @var{errno} must be sent as well, even if the call was successful.
36907 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
36908
36909 @smallexample
36910 F0,0,C
36911 @end smallexample
36912
36913 @noindent
36914 or, if the call was interrupted before the host call has been performed:
36915
36916 @smallexample
36917 F-1,4,C
36918 @end smallexample
36919
36920 @noindent
36921 assuming 4 is the protocol-specific representation of @code{EINTR}.
36922
36923 @end table
36924
36925
36926 @node The Ctrl-C Message
36927 @subsection The @samp{Ctrl-C} Message
36928 @cindex ctrl-c message, in file-i/o protocol
36929
36930 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
36931 reply packet (@pxref{The F Reply Packet}),
36932 the target should behave as if it had
36933 gotten a break message. The meaning for the target is ``system call
36934 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
36935 (as with a break message) and return to @value{GDBN} with a @code{T02}
36936 packet.
36937
36938 It's important for the target to know in which
36939 state the system call was interrupted. There are two possible cases:
36940
36941 @itemize @bullet
36942 @item
36943 The system call hasn't been performed on the host yet.
36944
36945 @item
36946 The system call on the host has been finished.
36947
36948 @end itemize
36949
36950 These two states can be distinguished by the target by the value of the
36951 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
36952 call hasn't been performed. This is equivalent to the @code{EINTR} handling
36953 on POSIX systems. In any other case, the target may presume that the
36954 system call has been finished --- successfully or not --- and should behave
36955 as if the break message arrived right after the system call.
36956
36957 @value{GDBN} must behave reliably. If the system call has not been called
36958 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
36959 @code{errno} in the packet. If the system call on the host has been finished
36960 before the user requests a break, the full action must be finished by
36961 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
36962 The @code{F} packet may only be sent when either nothing has happened
36963 or the full action has been completed.
36964
36965 @node Console I/O
36966 @subsection Console I/O
36967 @cindex console i/o as part of file-i/o
36968
36969 By default and if not explicitly closed by the target system, the file
36970 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
36971 on the @value{GDBN} console is handled as any other file output operation
36972 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
36973 by @value{GDBN} so that after the target read request from file descriptor
36974 0 all following typing is buffered until either one of the following
36975 conditions is met:
36976
36977 @itemize @bullet
36978 @item
36979 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
36980 @code{read}
36981 system call is treated as finished.
36982
36983 @item
36984 The user presses @key{RET}. This is treated as end of input with a trailing
36985 newline.
36986
36987 @item
36988 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
36989 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
36990
36991 @end itemize
36992
36993 If the user has typed more characters than fit in the buffer given to
36994 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
36995 either another @code{read(0, @dots{})} is requested by the target, or debugging
36996 is stopped at the user's request.
36997
36998
36999 @node List of Supported Calls
37000 @subsection List of Supported Calls
37001 @cindex list of supported file-i/o calls
37002
37003 @menu
37004 * open::
37005 * close::
37006 * read::
37007 * write::
37008 * lseek::
37009 * rename::
37010 * unlink::
37011 * stat/fstat::
37012 * gettimeofday::
37013 * isatty::
37014 * system::
37015 @end menu
37016
37017 @node open
37018 @unnumberedsubsubsec open
37019 @cindex open, file-i/o system call
37020
37021 @table @asis
37022 @item Synopsis:
37023 @smallexample
37024 int open(const char *pathname, int flags);
37025 int open(const char *pathname, int flags, mode_t mode);
37026 @end smallexample
37027
37028 @item Request:
37029 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
37030
37031 @noindent
37032 @var{flags} is the bitwise @code{OR} of the following values:
37033
37034 @table @code
37035 @item O_CREAT
37036 If the file does not exist it will be created. The host
37037 rules apply as far as file ownership and time stamps
37038 are concerned.
37039
37040 @item O_EXCL
37041 When used with @code{O_CREAT}, if the file already exists it is
37042 an error and open() fails.
37043
37044 @item O_TRUNC
37045 If the file already exists and the open mode allows
37046 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
37047 truncated to zero length.
37048
37049 @item O_APPEND
37050 The file is opened in append mode.
37051
37052 @item O_RDONLY
37053 The file is opened for reading only.
37054
37055 @item O_WRONLY
37056 The file is opened for writing only.
37057
37058 @item O_RDWR
37059 The file is opened for reading and writing.
37060 @end table
37061
37062 @noindent
37063 Other bits are silently ignored.
37064
37065
37066 @noindent
37067 @var{mode} is the bitwise @code{OR} of the following values:
37068
37069 @table @code
37070 @item S_IRUSR
37071 User has read permission.
37072
37073 @item S_IWUSR
37074 User has write permission.
37075
37076 @item S_IRGRP
37077 Group has read permission.
37078
37079 @item S_IWGRP
37080 Group has write permission.
37081
37082 @item S_IROTH
37083 Others have read permission.
37084
37085 @item S_IWOTH
37086 Others have write permission.
37087 @end table
37088
37089 @noindent
37090 Other bits are silently ignored.
37091
37092
37093 @item Return value:
37094 @code{open} returns the new file descriptor or -1 if an error
37095 occurred.
37096
37097 @item Errors:
37098
37099 @table @code
37100 @item EEXIST
37101 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
37102
37103 @item EISDIR
37104 @var{pathname} refers to a directory.
37105
37106 @item EACCES
37107 The requested access is not allowed.
37108
37109 @item ENAMETOOLONG
37110 @var{pathname} was too long.
37111
37112 @item ENOENT
37113 A directory component in @var{pathname} does not exist.
37114
37115 @item ENODEV
37116 @var{pathname} refers to a device, pipe, named pipe or socket.
37117
37118 @item EROFS
37119 @var{pathname} refers to a file on a read-only filesystem and
37120 write access was requested.
37121
37122 @item EFAULT
37123 @var{pathname} is an invalid pointer value.
37124
37125 @item ENOSPC
37126 No space on device to create the file.
37127
37128 @item EMFILE
37129 The process already has the maximum number of files open.
37130
37131 @item ENFILE
37132 The limit on the total number of files open on the system
37133 has been reached.
37134
37135 @item EINTR
37136 The call was interrupted by the user.
37137 @end table
37138
37139 @end table
37140
37141 @node close
37142 @unnumberedsubsubsec close
37143 @cindex close, file-i/o system call
37144
37145 @table @asis
37146 @item Synopsis:
37147 @smallexample
37148 int close(int fd);
37149 @end smallexample
37150
37151 @item Request:
37152 @samp{Fclose,@var{fd}}
37153
37154 @item Return value:
37155 @code{close} returns zero on success, or -1 if an error occurred.
37156
37157 @item Errors:
37158
37159 @table @code
37160 @item EBADF
37161 @var{fd} isn't a valid open file descriptor.
37162
37163 @item EINTR
37164 The call was interrupted by the user.
37165 @end table
37166
37167 @end table
37168
37169 @node read
37170 @unnumberedsubsubsec read
37171 @cindex read, file-i/o system call
37172
37173 @table @asis
37174 @item Synopsis:
37175 @smallexample
37176 int read(int fd, void *buf, unsigned int count);
37177 @end smallexample
37178
37179 @item Request:
37180 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
37181
37182 @item Return value:
37183 On success, the number of bytes read is returned.
37184 Zero indicates end of file. If count is zero, read
37185 returns zero as well. On error, -1 is returned.
37186
37187 @item Errors:
37188
37189 @table @code
37190 @item EBADF
37191 @var{fd} is not a valid file descriptor or is not open for
37192 reading.
37193
37194 @item EFAULT
37195 @var{bufptr} is an invalid pointer value.
37196
37197 @item EINTR
37198 The call was interrupted by the user.
37199 @end table
37200
37201 @end table
37202
37203 @node write
37204 @unnumberedsubsubsec write
37205 @cindex write, file-i/o system call
37206
37207 @table @asis
37208 @item Synopsis:
37209 @smallexample
37210 int write(int fd, const void *buf, unsigned int count);
37211 @end smallexample
37212
37213 @item Request:
37214 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
37215
37216 @item Return value:
37217 On success, the number of bytes written are returned.
37218 Zero indicates nothing was written. On error, -1
37219 is returned.
37220
37221 @item Errors:
37222
37223 @table @code
37224 @item EBADF
37225 @var{fd} is not a valid file descriptor or is not open for
37226 writing.
37227
37228 @item EFAULT
37229 @var{bufptr} is an invalid pointer value.
37230
37231 @item EFBIG
37232 An attempt was made to write a file that exceeds the
37233 host-specific maximum file size allowed.
37234
37235 @item ENOSPC
37236 No space on device to write the data.
37237
37238 @item EINTR
37239 The call was interrupted by the user.
37240 @end table
37241
37242 @end table
37243
37244 @node lseek
37245 @unnumberedsubsubsec lseek
37246 @cindex lseek, file-i/o system call
37247
37248 @table @asis
37249 @item Synopsis:
37250 @smallexample
37251 long lseek (int fd, long offset, int flag);
37252 @end smallexample
37253
37254 @item Request:
37255 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
37256
37257 @var{flag} is one of:
37258
37259 @table @code
37260 @item SEEK_SET
37261 The offset is set to @var{offset} bytes.
37262
37263 @item SEEK_CUR
37264 The offset is set to its current location plus @var{offset}
37265 bytes.
37266
37267 @item SEEK_END
37268 The offset is set to the size of the file plus @var{offset}
37269 bytes.
37270 @end table
37271
37272 @item Return value:
37273 On success, the resulting unsigned offset in bytes from
37274 the beginning of the file is returned. Otherwise, a
37275 value of -1 is returned.
37276
37277 @item Errors:
37278
37279 @table @code
37280 @item EBADF
37281 @var{fd} is not a valid open file descriptor.
37282
37283 @item ESPIPE
37284 @var{fd} is associated with the @value{GDBN} console.
37285
37286 @item EINVAL
37287 @var{flag} is not a proper value.
37288
37289 @item EINTR
37290 The call was interrupted by the user.
37291 @end table
37292
37293 @end table
37294
37295 @node rename
37296 @unnumberedsubsubsec rename
37297 @cindex rename, file-i/o system call
37298
37299 @table @asis
37300 @item Synopsis:
37301 @smallexample
37302 int rename(const char *oldpath, const char *newpath);
37303 @end smallexample
37304
37305 @item Request:
37306 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
37307
37308 @item Return value:
37309 On success, zero is returned. On error, -1 is returned.
37310
37311 @item Errors:
37312
37313 @table @code
37314 @item EISDIR
37315 @var{newpath} is an existing directory, but @var{oldpath} is not a
37316 directory.
37317
37318 @item EEXIST
37319 @var{newpath} is a non-empty directory.
37320
37321 @item EBUSY
37322 @var{oldpath} or @var{newpath} is a directory that is in use by some
37323 process.
37324
37325 @item EINVAL
37326 An attempt was made to make a directory a subdirectory
37327 of itself.
37328
37329 @item ENOTDIR
37330 A component used as a directory in @var{oldpath} or new
37331 path is not a directory. Or @var{oldpath} is a directory
37332 and @var{newpath} exists but is not a directory.
37333
37334 @item EFAULT
37335 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
37336
37337 @item EACCES
37338 No access to the file or the path of the file.
37339
37340 @item ENAMETOOLONG
37341
37342 @var{oldpath} or @var{newpath} was too long.
37343
37344 @item ENOENT
37345 A directory component in @var{oldpath} or @var{newpath} does not exist.
37346
37347 @item EROFS
37348 The file is on a read-only filesystem.
37349
37350 @item ENOSPC
37351 The device containing the file has no room for the new
37352 directory entry.
37353
37354 @item EINTR
37355 The call was interrupted by the user.
37356 @end table
37357
37358 @end table
37359
37360 @node unlink
37361 @unnumberedsubsubsec unlink
37362 @cindex unlink, file-i/o system call
37363
37364 @table @asis
37365 @item Synopsis:
37366 @smallexample
37367 int unlink(const char *pathname);
37368 @end smallexample
37369
37370 @item Request:
37371 @samp{Funlink,@var{pathnameptr}/@var{len}}
37372
37373 @item Return value:
37374 On success, zero is returned. On error, -1 is returned.
37375
37376 @item Errors:
37377
37378 @table @code
37379 @item EACCES
37380 No access to the file or the path of the file.
37381
37382 @item EPERM
37383 The system does not allow unlinking of directories.
37384
37385 @item EBUSY
37386 The file @var{pathname} cannot be unlinked because it's
37387 being used by another process.
37388
37389 @item EFAULT
37390 @var{pathnameptr} is an invalid pointer value.
37391
37392 @item ENAMETOOLONG
37393 @var{pathname} was too long.
37394
37395 @item ENOENT
37396 A directory component in @var{pathname} does not exist.
37397
37398 @item ENOTDIR
37399 A component of the path is not a directory.
37400
37401 @item EROFS
37402 The file is on a read-only filesystem.
37403
37404 @item EINTR
37405 The call was interrupted by the user.
37406 @end table
37407
37408 @end table
37409
37410 @node stat/fstat
37411 @unnumberedsubsubsec stat/fstat
37412 @cindex fstat, file-i/o system call
37413 @cindex stat, file-i/o system call
37414
37415 @table @asis
37416 @item Synopsis:
37417 @smallexample
37418 int stat(const char *pathname, struct stat *buf);
37419 int fstat(int fd, struct stat *buf);
37420 @end smallexample
37421
37422 @item Request:
37423 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
37424 @samp{Ffstat,@var{fd},@var{bufptr}}
37425
37426 @item Return value:
37427 On success, zero is returned. On error, -1 is returned.
37428
37429 @item Errors:
37430
37431 @table @code
37432 @item EBADF
37433 @var{fd} is not a valid open file.
37434
37435 @item ENOENT
37436 A directory component in @var{pathname} does not exist or the
37437 path is an empty string.
37438
37439 @item ENOTDIR
37440 A component of the path is not a directory.
37441
37442 @item EFAULT
37443 @var{pathnameptr} is an invalid pointer value.
37444
37445 @item EACCES
37446 No access to the file or the path of the file.
37447
37448 @item ENAMETOOLONG
37449 @var{pathname} was too long.
37450
37451 @item EINTR
37452 The call was interrupted by the user.
37453 @end table
37454
37455 @end table
37456
37457 @node gettimeofday
37458 @unnumberedsubsubsec gettimeofday
37459 @cindex gettimeofday, file-i/o system call
37460
37461 @table @asis
37462 @item Synopsis:
37463 @smallexample
37464 int gettimeofday(struct timeval *tv, void *tz);
37465 @end smallexample
37466
37467 @item Request:
37468 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
37469
37470 @item Return value:
37471 On success, 0 is returned, -1 otherwise.
37472
37473 @item Errors:
37474
37475 @table @code
37476 @item EINVAL
37477 @var{tz} is a non-NULL pointer.
37478
37479 @item EFAULT
37480 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
37481 @end table
37482
37483 @end table
37484
37485 @node isatty
37486 @unnumberedsubsubsec isatty
37487 @cindex isatty, file-i/o system call
37488
37489 @table @asis
37490 @item Synopsis:
37491 @smallexample
37492 int isatty(int fd);
37493 @end smallexample
37494
37495 @item Request:
37496 @samp{Fisatty,@var{fd}}
37497
37498 @item Return value:
37499 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
37500
37501 @item Errors:
37502
37503 @table @code
37504 @item EINTR
37505 The call was interrupted by the user.
37506 @end table
37507
37508 @end table
37509
37510 Note that the @code{isatty} call is treated as a special case: it returns
37511 1 to the target if the file descriptor is attached
37512 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
37513 would require implementing @code{ioctl} and would be more complex than
37514 needed.
37515
37516
37517 @node system
37518 @unnumberedsubsubsec system
37519 @cindex system, file-i/o system call
37520
37521 @table @asis
37522 @item Synopsis:
37523 @smallexample
37524 int system(const char *command);
37525 @end smallexample
37526
37527 @item Request:
37528 @samp{Fsystem,@var{commandptr}/@var{len}}
37529
37530 @item Return value:
37531 If @var{len} is zero, the return value indicates whether a shell is
37532 available. A zero return value indicates a shell is not available.
37533 For non-zero @var{len}, the value returned is -1 on error and the
37534 return status of the command otherwise. Only the exit status of the
37535 command is returned, which is extracted from the host's @code{system}
37536 return value by calling @code{WEXITSTATUS(retval)}. In case
37537 @file{/bin/sh} could not be executed, 127 is returned.
37538
37539 @item Errors:
37540
37541 @table @code
37542 @item EINTR
37543 The call was interrupted by the user.
37544 @end table
37545
37546 @end table
37547
37548 @value{GDBN} takes over the full task of calling the necessary host calls
37549 to perform the @code{system} call. The return value of @code{system} on
37550 the host is simplified before it's returned
37551 to the target. Any termination signal information from the child process
37552 is discarded, and the return value consists
37553 entirely of the exit status of the called command.
37554
37555 Due to security concerns, the @code{system} call is by default refused
37556 by @value{GDBN}. The user has to allow this call explicitly with the
37557 @code{set remote system-call-allowed 1} command.
37558
37559 @table @code
37560 @item set remote system-call-allowed
37561 @kindex set remote system-call-allowed
37562 Control whether to allow the @code{system} calls in the File I/O
37563 protocol for the remote target. The default is zero (disabled).
37564
37565 @item show remote system-call-allowed
37566 @kindex show remote system-call-allowed
37567 Show whether the @code{system} calls are allowed in the File I/O
37568 protocol.
37569 @end table
37570
37571 @node Protocol-specific Representation of Datatypes
37572 @subsection Protocol-specific Representation of Datatypes
37573 @cindex protocol-specific representation of datatypes, in file-i/o protocol
37574
37575 @menu
37576 * Integral Datatypes::
37577 * Pointer Values::
37578 * Memory Transfer::
37579 * struct stat::
37580 * struct timeval::
37581 @end menu
37582
37583 @node Integral Datatypes
37584 @unnumberedsubsubsec Integral Datatypes
37585 @cindex integral datatypes, in file-i/o protocol
37586
37587 The integral datatypes used in the system calls are @code{int},
37588 @code{unsigned int}, @code{long}, @code{unsigned long},
37589 @code{mode_t}, and @code{time_t}.
37590
37591 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
37592 implemented as 32 bit values in this protocol.
37593
37594 @code{long} and @code{unsigned long} are implemented as 64 bit types.
37595
37596 @xref{Limits}, for corresponding MIN and MAX values (similar to those
37597 in @file{limits.h}) to allow range checking on host and target.
37598
37599 @code{time_t} datatypes are defined as seconds since the Epoch.
37600
37601 All integral datatypes transferred as part of a memory read or write of a
37602 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
37603 byte order.
37604
37605 @node Pointer Values
37606 @unnumberedsubsubsec Pointer Values
37607 @cindex pointer values, in file-i/o protocol
37608
37609 Pointers to target data are transmitted as they are. An exception
37610 is made for pointers to buffers for which the length isn't
37611 transmitted as part of the function call, namely strings. Strings
37612 are transmitted as a pointer/length pair, both as hex values, e.g.@:
37613
37614 @smallexample
37615 @code{1aaf/12}
37616 @end smallexample
37617
37618 @noindent
37619 which is a pointer to data of length 18 bytes at position 0x1aaf.
37620 The length is defined as the full string length in bytes, including
37621 the trailing null byte. For example, the string @code{"hello world"}
37622 at address 0x123456 is transmitted as
37623
37624 @smallexample
37625 @code{123456/d}
37626 @end smallexample
37627
37628 @node Memory Transfer
37629 @unnumberedsubsubsec Memory Transfer
37630 @cindex memory transfer, in file-i/o protocol
37631
37632 Structured data which is transferred using a memory read or write (for
37633 example, a @code{struct stat}) is expected to be in a protocol-specific format
37634 with all scalar multibyte datatypes being big endian. Translation to
37635 this representation needs to be done both by the target before the @code{F}
37636 packet is sent, and by @value{GDBN} before
37637 it transfers memory to the target. Transferred pointers to structured
37638 data should point to the already-coerced data at any time.
37639
37640
37641 @node struct stat
37642 @unnumberedsubsubsec struct stat
37643 @cindex struct stat, in file-i/o protocol
37644
37645 The buffer of type @code{struct stat} used by the target and @value{GDBN}
37646 is defined as follows:
37647
37648 @smallexample
37649 struct stat @{
37650 unsigned int st_dev; /* device */
37651 unsigned int st_ino; /* inode */
37652 mode_t st_mode; /* protection */
37653 unsigned int st_nlink; /* number of hard links */
37654 unsigned int st_uid; /* user ID of owner */
37655 unsigned int st_gid; /* group ID of owner */
37656 unsigned int st_rdev; /* device type (if inode device) */
37657 unsigned long st_size; /* total size, in bytes */
37658 unsigned long st_blksize; /* blocksize for filesystem I/O */
37659 unsigned long st_blocks; /* number of blocks allocated */
37660 time_t st_atime; /* time of last access */
37661 time_t st_mtime; /* time of last modification */
37662 time_t st_ctime; /* time of last change */
37663 @};
37664 @end smallexample
37665
37666 The integral datatypes conform to the definitions given in the
37667 appropriate section (see @ref{Integral Datatypes}, for details) so this
37668 structure is of size 64 bytes.
37669
37670 The values of several fields have a restricted meaning and/or
37671 range of values.
37672
37673 @table @code
37674
37675 @item st_dev
37676 A value of 0 represents a file, 1 the console.
37677
37678 @item st_ino
37679 No valid meaning for the target. Transmitted unchanged.
37680
37681 @item st_mode
37682 Valid mode bits are described in @ref{Constants}. Any other
37683 bits have currently no meaning for the target.
37684
37685 @item st_uid
37686 @itemx st_gid
37687 @itemx st_rdev
37688 No valid meaning for the target. Transmitted unchanged.
37689
37690 @item st_atime
37691 @itemx st_mtime
37692 @itemx st_ctime
37693 These values have a host and file system dependent
37694 accuracy. Especially on Windows hosts, the file system may not
37695 support exact timing values.
37696 @end table
37697
37698 The target gets a @code{struct stat} of the above representation and is
37699 responsible for coercing it to the target representation before
37700 continuing.
37701
37702 Note that due to size differences between the host, target, and protocol
37703 representations of @code{struct stat} members, these members could eventually
37704 get truncated on the target.
37705
37706 @node struct timeval
37707 @unnumberedsubsubsec struct timeval
37708 @cindex struct timeval, in file-i/o protocol
37709
37710 The buffer of type @code{struct timeval} used by the File-I/O protocol
37711 is defined as follows:
37712
37713 @smallexample
37714 struct timeval @{
37715 time_t tv_sec; /* second */
37716 long tv_usec; /* microsecond */
37717 @};
37718 @end smallexample
37719
37720 The integral datatypes conform to the definitions given in the
37721 appropriate section (see @ref{Integral Datatypes}, for details) so this
37722 structure is of size 8 bytes.
37723
37724 @node Constants
37725 @subsection Constants
37726 @cindex constants, in file-i/o protocol
37727
37728 The following values are used for the constants inside of the
37729 protocol. @value{GDBN} and target are responsible for translating these
37730 values before and after the call as needed.
37731
37732 @menu
37733 * Open Flags::
37734 * mode_t Values::
37735 * Errno Values::
37736 * Lseek Flags::
37737 * Limits::
37738 @end menu
37739
37740 @node Open Flags
37741 @unnumberedsubsubsec Open Flags
37742 @cindex open flags, in file-i/o protocol
37743
37744 All values are given in hexadecimal representation.
37745
37746 @smallexample
37747 O_RDONLY 0x0
37748 O_WRONLY 0x1
37749 O_RDWR 0x2
37750 O_APPEND 0x8
37751 O_CREAT 0x200
37752 O_TRUNC 0x400
37753 O_EXCL 0x800
37754 @end smallexample
37755
37756 @node mode_t Values
37757 @unnumberedsubsubsec mode_t Values
37758 @cindex mode_t values, in file-i/o protocol
37759
37760 All values are given in octal representation.
37761
37762 @smallexample
37763 S_IFREG 0100000
37764 S_IFDIR 040000
37765 S_IRUSR 0400
37766 S_IWUSR 0200
37767 S_IXUSR 0100
37768 S_IRGRP 040
37769 S_IWGRP 020
37770 S_IXGRP 010
37771 S_IROTH 04
37772 S_IWOTH 02
37773 S_IXOTH 01
37774 @end smallexample
37775
37776 @node Errno Values
37777 @unnumberedsubsubsec Errno Values
37778 @cindex errno values, in file-i/o protocol
37779
37780 All values are given in decimal representation.
37781
37782 @smallexample
37783 EPERM 1
37784 ENOENT 2
37785 EINTR 4
37786 EBADF 9
37787 EACCES 13
37788 EFAULT 14
37789 EBUSY 16
37790 EEXIST 17
37791 ENODEV 19
37792 ENOTDIR 20
37793 EISDIR 21
37794 EINVAL 22
37795 ENFILE 23
37796 EMFILE 24
37797 EFBIG 27
37798 ENOSPC 28
37799 ESPIPE 29
37800 EROFS 30
37801 ENAMETOOLONG 91
37802 EUNKNOWN 9999
37803 @end smallexample
37804
37805 @code{EUNKNOWN} is used as a fallback error value if a host system returns
37806 any error value not in the list of supported error numbers.
37807
37808 @node Lseek Flags
37809 @unnumberedsubsubsec Lseek Flags
37810 @cindex lseek flags, in file-i/o protocol
37811
37812 @smallexample
37813 SEEK_SET 0
37814 SEEK_CUR 1
37815 SEEK_END 2
37816 @end smallexample
37817
37818 @node Limits
37819 @unnumberedsubsubsec Limits
37820 @cindex limits, in file-i/o protocol
37821
37822 All values are given in decimal representation.
37823
37824 @smallexample
37825 INT_MIN -2147483648
37826 INT_MAX 2147483647
37827 UINT_MAX 4294967295
37828 LONG_MIN -9223372036854775808
37829 LONG_MAX 9223372036854775807
37830 ULONG_MAX 18446744073709551615
37831 @end smallexample
37832
37833 @node File-I/O Examples
37834 @subsection File-I/O Examples
37835 @cindex file-i/o examples
37836
37837 Example sequence of a write call, file descriptor 3, buffer is at target
37838 address 0x1234, 6 bytes should be written:
37839
37840 @smallexample
37841 <- @code{Fwrite,3,1234,6}
37842 @emph{request memory read from target}
37843 -> @code{m1234,6}
37844 <- XXXXXX
37845 @emph{return "6 bytes written"}
37846 -> @code{F6}
37847 @end smallexample
37848
37849 Example sequence of a read call, file descriptor 3, buffer is at target
37850 address 0x1234, 6 bytes should be read:
37851
37852 @smallexample
37853 <- @code{Fread,3,1234,6}
37854 @emph{request memory write to target}
37855 -> @code{X1234,6:XXXXXX}
37856 @emph{return "6 bytes read"}
37857 -> @code{F6}
37858 @end smallexample
37859
37860 Example sequence of a read call, call fails on the host due to invalid
37861 file descriptor (@code{EBADF}):
37862
37863 @smallexample
37864 <- @code{Fread,3,1234,6}
37865 -> @code{F-1,9}
37866 @end smallexample
37867
37868 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
37869 host is called:
37870
37871 @smallexample
37872 <- @code{Fread,3,1234,6}
37873 -> @code{F-1,4,C}
37874 <- @code{T02}
37875 @end smallexample
37876
37877 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
37878 host is called:
37879
37880 @smallexample
37881 <- @code{Fread,3,1234,6}
37882 -> @code{X1234,6:XXXXXX}
37883 <- @code{T02}
37884 @end smallexample
37885
37886 @node Library List Format
37887 @section Library List Format
37888 @cindex library list format, remote protocol
37889
37890 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
37891 same process as your application to manage libraries. In this case,
37892 @value{GDBN} can use the loader's symbol table and normal memory
37893 operations to maintain a list of shared libraries. On other
37894 platforms, the operating system manages loaded libraries.
37895 @value{GDBN} can not retrieve the list of currently loaded libraries
37896 through memory operations, so it uses the @samp{qXfer:libraries:read}
37897 packet (@pxref{qXfer library list read}) instead. The remote stub
37898 queries the target's operating system and reports which libraries
37899 are loaded.
37900
37901 The @samp{qXfer:libraries:read} packet returns an XML document which
37902 lists loaded libraries and their offsets. Each library has an
37903 associated name and one or more segment or section base addresses,
37904 which report where the library was loaded in memory.
37905
37906 For the common case of libraries that are fully linked binaries, the
37907 library should have a list of segments. If the target supports
37908 dynamic linking of a relocatable object file, its library XML element
37909 should instead include a list of allocated sections. The segment or
37910 section bases are start addresses, not relocation offsets; they do not
37911 depend on the library's link-time base addresses.
37912
37913 @value{GDBN} must be linked with the Expat library to support XML
37914 library lists. @xref{Expat}.
37915
37916 A simple memory map, with one loaded library relocated by a single
37917 offset, looks like this:
37918
37919 @smallexample
37920 <library-list>
37921 <library name="/lib/libc.so.6">
37922 <segment address="0x10000000"/>
37923 </library>
37924 </library-list>
37925 @end smallexample
37926
37927 Another simple memory map, with one loaded library with three
37928 allocated sections (.text, .data, .bss), looks like this:
37929
37930 @smallexample
37931 <library-list>
37932 <library name="sharedlib.o">
37933 <section address="0x10000000"/>
37934 <section address="0x20000000"/>
37935 <section address="0x30000000"/>
37936 </library>
37937 </library-list>
37938 @end smallexample
37939
37940 The format of a library list is described by this DTD:
37941
37942 @smallexample
37943 <!-- library-list: Root element with versioning -->
37944 <!ELEMENT library-list (library)*>
37945 <!ATTLIST library-list version CDATA #FIXED "1.0">
37946 <!ELEMENT library (segment*, section*)>
37947 <!ATTLIST library name CDATA #REQUIRED>
37948 <!ELEMENT segment EMPTY>
37949 <!ATTLIST segment address CDATA #REQUIRED>
37950 <!ELEMENT section EMPTY>
37951 <!ATTLIST section address CDATA #REQUIRED>
37952 @end smallexample
37953
37954 In addition, segments and section descriptors cannot be mixed within a
37955 single library element, and you must supply at least one segment or
37956 section for each library.
37957
37958 @node Library List Format for SVR4 Targets
37959 @section Library List Format for SVR4 Targets
37960 @cindex library list format, remote protocol
37961
37962 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
37963 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
37964 shared libraries. Still a special library list provided by this packet is
37965 more efficient for the @value{GDBN} remote protocol.
37966
37967 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
37968 loaded libraries and their SVR4 linker parameters. For each library on SVR4
37969 target, the following parameters are reported:
37970
37971 @itemize @minus
37972 @item
37973 @code{name}, the absolute file name from the @code{l_name} field of
37974 @code{struct link_map}.
37975 @item
37976 @code{lm} with address of @code{struct link_map} used for TLS
37977 (Thread Local Storage) access.
37978 @item
37979 @code{l_addr}, the displacement as read from the field @code{l_addr} of
37980 @code{struct link_map}. For prelinked libraries this is not an absolute
37981 memory address. It is a displacement of absolute memory address against
37982 address the file was prelinked to during the library load.
37983 @item
37984 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
37985 @end itemize
37986
37987 Additionally the single @code{main-lm} attribute specifies address of
37988 @code{struct link_map} used for the main executable. This parameter is used
37989 for TLS access and its presence is optional.
37990
37991 @value{GDBN} must be linked with the Expat library to support XML
37992 SVR4 library lists. @xref{Expat}.
37993
37994 A simple memory map, with two loaded libraries (which do not use prelink),
37995 looks like this:
37996
37997 @smallexample
37998 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
37999 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
38000 l_ld="0xe4eefc"/>
38001 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
38002 l_ld="0x152350"/>
38003 </library-list-svr>
38004 @end smallexample
38005
38006 The format of an SVR4 library list is described by this DTD:
38007
38008 @smallexample
38009 <!-- library-list-svr4: Root element with versioning -->
38010 <!ELEMENT library-list-svr4 (library)*>
38011 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
38012 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
38013 <!ELEMENT library EMPTY>
38014 <!ATTLIST library name CDATA #REQUIRED>
38015 <!ATTLIST library lm CDATA #REQUIRED>
38016 <!ATTLIST library l_addr CDATA #REQUIRED>
38017 <!ATTLIST library l_ld CDATA #REQUIRED>
38018 @end smallexample
38019
38020 @node Memory Map Format
38021 @section Memory Map Format
38022 @cindex memory map format
38023
38024 To be able to write into flash memory, @value{GDBN} needs to obtain a
38025 memory map from the target. This section describes the format of the
38026 memory map.
38027
38028 The memory map is obtained using the @samp{qXfer:memory-map:read}
38029 (@pxref{qXfer memory map read}) packet and is an XML document that
38030 lists memory regions.
38031
38032 @value{GDBN} must be linked with the Expat library to support XML
38033 memory maps. @xref{Expat}.
38034
38035 The top-level structure of the document is shown below:
38036
38037 @smallexample
38038 <?xml version="1.0"?>
38039 <!DOCTYPE memory-map
38040 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
38041 "http://sourceware.org/gdb/gdb-memory-map.dtd">
38042 <memory-map>
38043 region...
38044 </memory-map>
38045 @end smallexample
38046
38047 Each region can be either:
38048
38049 @itemize
38050
38051 @item
38052 A region of RAM starting at @var{addr} and extending for @var{length}
38053 bytes from there:
38054
38055 @smallexample
38056 <memory type="ram" start="@var{addr}" length="@var{length}"/>
38057 @end smallexample
38058
38059
38060 @item
38061 A region of read-only memory:
38062
38063 @smallexample
38064 <memory type="rom" start="@var{addr}" length="@var{length}"/>
38065 @end smallexample
38066
38067
38068 @item
38069 A region of flash memory, with erasure blocks @var{blocksize}
38070 bytes in length:
38071
38072 @smallexample
38073 <memory type="flash" start="@var{addr}" length="@var{length}">
38074 <property name="blocksize">@var{blocksize}</property>
38075 </memory>
38076 @end smallexample
38077
38078 @end itemize
38079
38080 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
38081 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
38082 packets to write to addresses in such ranges.
38083
38084 The formal DTD for memory map format is given below:
38085
38086 @smallexample
38087 <!-- ................................................... -->
38088 <!-- Memory Map XML DTD ................................ -->
38089 <!-- File: memory-map.dtd .............................. -->
38090 <!-- .................................... .............. -->
38091 <!-- memory-map.dtd -->
38092 <!-- memory-map: Root element with versioning -->
38093 <!ELEMENT memory-map (memory | property)>
38094 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
38095 <!ELEMENT memory (property)>
38096 <!-- memory: Specifies a memory region,
38097 and its type, or device. -->
38098 <!ATTLIST memory type CDATA #REQUIRED
38099 start CDATA #REQUIRED
38100 length CDATA #REQUIRED
38101 device CDATA #IMPLIED>
38102 <!-- property: Generic attribute tag -->
38103 <!ELEMENT property (#PCDATA | property)*>
38104 <!ATTLIST property name CDATA #REQUIRED>
38105 @end smallexample
38106
38107 @node Thread List Format
38108 @section Thread List Format
38109 @cindex thread list format
38110
38111 To efficiently update the list of threads and their attributes,
38112 @value{GDBN} issues the @samp{qXfer:threads:read} packet
38113 (@pxref{qXfer threads read}) and obtains the XML document with
38114 the following structure:
38115
38116 @smallexample
38117 <?xml version="1.0"?>
38118 <threads>
38119 <thread id="id" core="0">
38120 ... description ...
38121 </thread>
38122 </threads>
38123 @end smallexample
38124
38125 Each @samp{thread} element must have the @samp{id} attribute that
38126 identifies the thread (@pxref{thread-id syntax}). The
38127 @samp{core} attribute, if present, specifies which processor core
38128 the thread was last executing on. The content of the of @samp{thread}
38129 element is interpreted as human-readable auxilliary information.
38130
38131 @node Traceframe Info Format
38132 @section Traceframe Info Format
38133 @cindex traceframe info format
38134
38135 To be able to know which objects in the inferior can be examined when
38136 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
38137 memory ranges, registers and trace state variables that have been
38138 collected in a traceframe.
38139
38140 This list is obtained using the @samp{qXfer:traceframe-info:read}
38141 (@pxref{qXfer traceframe info read}) packet and is an XML document.
38142
38143 @value{GDBN} must be linked with the Expat library to support XML
38144 traceframe info discovery. @xref{Expat}.
38145
38146 The top-level structure of the document is shown below:
38147
38148 @smallexample
38149 <?xml version="1.0"?>
38150 <!DOCTYPE traceframe-info
38151 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
38152 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
38153 <traceframe-info>
38154 block...
38155 </traceframe-info>
38156 @end smallexample
38157
38158 Each traceframe block can be either:
38159
38160 @itemize
38161
38162 @item
38163 A region of collected memory starting at @var{addr} and extending for
38164 @var{length} bytes from there:
38165
38166 @smallexample
38167 <memory start="@var{addr}" length="@var{length}"/>
38168 @end smallexample
38169
38170 @end itemize
38171
38172 The formal DTD for the traceframe info format is given below:
38173
38174 @smallexample
38175 <!ELEMENT traceframe-info (memory)* >
38176 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
38177
38178 <!ELEMENT memory EMPTY>
38179 <!ATTLIST memory start CDATA #REQUIRED
38180 length CDATA #REQUIRED>
38181 @end smallexample
38182
38183 @include agentexpr.texi
38184
38185 @node Target Descriptions
38186 @appendix Target Descriptions
38187 @cindex target descriptions
38188
38189 One of the challenges of using @value{GDBN} to debug embedded systems
38190 is that there are so many minor variants of each processor
38191 architecture in use. It is common practice for vendors to start with
38192 a standard processor core --- ARM, PowerPC, or MIPS, for example ---
38193 and then make changes to adapt it to a particular market niche. Some
38194 architectures have hundreds of variants, available from dozens of
38195 vendors. This leads to a number of problems:
38196
38197 @itemize @bullet
38198 @item
38199 With so many different customized processors, it is difficult for
38200 the @value{GDBN} maintainers to keep up with the changes.
38201 @item
38202 Since individual variants may have short lifetimes or limited
38203 audiences, it may not be worthwhile to carry information about every
38204 variant in the @value{GDBN} source tree.
38205 @item
38206 When @value{GDBN} does support the architecture of the embedded system
38207 at hand, the task of finding the correct architecture name to give the
38208 @command{set architecture} command can be error-prone.
38209 @end itemize
38210
38211 To address these problems, the @value{GDBN} remote protocol allows a
38212 target system to not only identify itself to @value{GDBN}, but to
38213 actually describe its own features. This lets @value{GDBN} support
38214 processor variants it has never seen before --- to the extent that the
38215 descriptions are accurate, and that @value{GDBN} understands them.
38216
38217 @value{GDBN} must be linked with the Expat library to support XML
38218 target descriptions. @xref{Expat}.
38219
38220 @menu
38221 * Retrieving Descriptions:: How descriptions are fetched from a target.
38222 * Target Description Format:: The contents of a target description.
38223 * Predefined Target Types:: Standard types available for target
38224 descriptions.
38225 * Standard Target Features:: Features @value{GDBN} knows about.
38226 @end menu
38227
38228 @node Retrieving Descriptions
38229 @section Retrieving Descriptions
38230
38231 Target descriptions can be read from the target automatically, or
38232 specified by the user manually. The default behavior is to read the
38233 description from the target. @value{GDBN} retrieves it via the remote
38234 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
38235 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
38236 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
38237 XML document, of the form described in @ref{Target Description
38238 Format}.
38239
38240 Alternatively, you can specify a file to read for the target description.
38241 If a file is set, the target will not be queried. The commands to
38242 specify a file are:
38243
38244 @table @code
38245 @cindex set tdesc filename
38246 @item set tdesc filename @var{path}
38247 Read the target description from @var{path}.
38248
38249 @cindex unset tdesc filename
38250 @item unset tdesc filename
38251 Do not read the XML target description from a file. @value{GDBN}
38252 will use the description supplied by the current target.
38253
38254 @cindex show tdesc filename
38255 @item show tdesc filename
38256 Show the filename to read for a target description, if any.
38257 @end table
38258
38259
38260 @node Target Description Format
38261 @section Target Description Format
38262 @cindex target descriptions, XML format
38263
38264 A target description annex is an @uref{http://www.w3.org/XML/, XML}
38265 document which complies with the Document Type Definition provided in
38266 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
38267 means you can use generally available tools like @command{xmllint} to
38268 check that your feature descriptions are well-formed and valid.
38269 However, to help people unfamiliar with XML write descriptions for
38270 their targets, we also describe the grammar here.
38271
38272 Target descriptions can identify the architecture of the remote target
38273 and (for some architectures) provide information about custom register
38274 sets. They can also identify the OS ABI of the remote target.
38275 @value{GDBN} can use this information to autoconfigure for your
38276 target, or to warn you if you connect to an unsupported target.
38277
38278 Here is a simple target description:
38279
38280 @smallexample
38281 <target version="1.0">
38282 <architecture>i386:x86-64</architecture>
38283 </target>
38284 @end smallexample
38285
38286 @noindent
38287 This minimal description only says that the target uses
38288 the x86-64 architecture.
38289
38290 A target description has the following overall form, with [ ] marking
38291 optional elements and @dots{} marking repeatable elements. The elements
38292 are explained further below.
38293
38294 @smallexample
38295 <?xml version="1.0"?>
38296 <!DOCTYPE target SYSTEM "gdb-target.dtd">
38297 <target version="1.0">
38298 @r{[}@var{architecture}@r{]}
38299 @r{[}@var{osabi}@r{]}
38300 @r{[}@var{compatible}@r{]}
38301 @r{[}@var{feature}@dots{}@r{]}
38302 </target>
38303 @end smallexample
38304
38305 @noindent
38306 The description is generally insensitive to whitespace and line
38307 breaks, under the usual common-sense rules. The XML version
38308 declaration and document type declaration can generally be omitted
38309 (@value{GDBN} does not require them), but specifying them may be
38310 useful for XML validation tools. The @samp{version} attribute for
38311 @samp{<target>} may also be omitted, but we recommend
38312 including it; if future versions of @value{GDBN} use an incompatible
38313 revision of @file{gdb-target.dtd}, they will detect and report
38314 the version mismatch.
38315
38316 @subsection Inclusion
38317 @cindex target descriptions, inclusion
38318 @cindex XInclude
38319 @ifnotinfo
38320 @cindex <xi:include>
38321 @end ifnotinfo
38322
38323 It can sometimes be valuable to split a target description up into
38324 several different annexes, either for organizational purposes, or to
38325 share files between different possible target descriptions. You can
38326 divide a description into multiple files by replacing any element of
38327 the target description with an inclusion directive of the form:
38328
38329 @smallexample
38330 <xi:include href="@var{document}"/>
38331 @end smallexample
38332
38333 @noindent
38334 When @value{GDBN} encounters an element of this form, it will retrieve
38335 the named XML @var{document}, and replace the inclusion directive with
38336 the contents of that document. If the current description was read
38337 using @samp{qXfer}, then so will be the included document;
38338 @var{document} will be interpreted as the name of an annex. If the
38339 current description was read from a file, @value{GDBN} will look for
38340 @var{document} as a file in the same directory where it found the
38341 original description.
38342
38343 @subsection Architecture
38344 @cindex <architecture>
38345
38346 An @samp{<architecture>} element has this form:
38347
38348 @smallexample
38349 <architecture>@var{arch}</architecture>
38350 @end smallexample
38351
38352 @var{arch} is one of the architectures from the set accepted by
38353 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
38354
38355 @subsection OS ABI
38356 @cindex @code{<osabi>}
38357
38358 This optional field was introduced in @value{GDBN} version 7.0.
38359 Previous versions of @value{GDBN} ignore it.
38360
38361 An @samp{<osabi>} element has this form:
38362
38363 @smallexample
38364 <osabi>@var{abi-name}</osabi>
38365 @end smallexample
38366
38367 @var{abi-name} is an OS ABI name from the same selection accepted by
38368 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
38369
38370 @subsection Compatible Architecture
38371 @cindex @code{<compatible>}
38372
38373 This optional field was introduced in @value{GDBN} version 7.0.
38374 Previous versions of @value{GDBN} ignore it.
38375
38376 A @samp{<compatible>} element has this form:
38377
38378 @smallexample
38379 <compatible>@var{arch}</compatible>
38380 @end smallexample
38381
38382 @var{arch} is one of the architectures from the set accepted by
38383 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
38384
38385 A @samp{<compatible>} element is used to specify that the target
38386 is able to run binaries in some other than the main target architecture
38387 given by the @samp{<architecture>} element. For example, on the
38388 Cell Broadband Engine, the main architecture is @code{powerpc:common}
38389 or @code{powerpc:common64}, but the system is able to run binaries
38390 in the @code{spu} architecture as well. The way to describe this
38391 capability with @samp{<compatible>} is as follows:
38392
38393 @smallexample
38394 <architecture>powerpc:common</architecture>
38395 <compatible>spu</compatible>
38396 @end smallexample
38397
38398 @subsection Features
38399 @cindex <feature>
38400
38401 Each @samp{<feature>} describes some logical portion of the target
38402 system. Features are currently used to describe available CPU
38403 registers and the types of their contents. A @samp{<feature>} element
38404 has this form:
38405
38406 @smallexample
38407 <feature name="@var{name}">
38408 @r{[}@var{type}@dots{}@r{]}
38409 @var{reg}@dots{}
38410 </feature>
38411 @end smallexample
38412
38413 @noindent
38414 Each feature's name should be unique within the description. The name
38415 of a feature does not matter unless @value{GDBN} has some special
38416 knowledge of the contents of that feature; if it does, the feature
38417 should have its standard name. @xref{Standard Target Features}.
38418
38419 @subsection Types
38420
38421 Any register's value is a collection of bits which @value{GDBN} must
38422 interpret. The default interpretation is a two's complement integer,
38423 but other types can be requested by name in the register description.
38424 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
38425 Target Types}), and the description can define additional composite types.
38426
38427 Each type element must have an @samp{id} attribute, which gives
38428 a unique (within the containing @samp{<feature>}) name to the type.
38429 Types must be defined before they are used.
38430
38431 @cindex <vector>
38432 Some targets offer vector registers, which can be treated as arrays
38433 of scalar elements. These types are written as @samp{<vector>} elements,
38434 specifying the array element type, @var{type}, and the number of elements,
38435 @var{count}:
38436
38437 @smallexample
38438 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
38439 @end smallexample
38440
38441 @cindex <union>
38442 If a register's value is usefully viewed in multiple ways, define it
38443 with a union type containing the useful representations. The
38444 @samp{<union>} element contains one or more @samp{<field>} elements,
38445 each of which has a @var{name} and a @var{type}:
38446
38447 @smallexample
38448 <union id="@var{id}">
38449 <field name="@var{name}" type="@var{type}"/>
38450 @dots{}
38451 </union>
38452 @end smallexample
38453
38454 @cindex <struct>
38455 If a register's value is composed from several separate values, define
38456 it with a structure type. There are two forms of the @samp{<struct>}
38457 element; a @samp{<struct>} element must either contain only bitfields
38458 or contain no bitfields. If the structure contains only bitfields,
38459 its total size in bytes must be specified, each bitfield must have an
38460 explicit start and end, and bitfields are automatically assigned an
38461 integer type. The field's @var{start} should be less than or
38462 equal to its @var{end}, and zero represents the least significant bit.
38463
38464 @smallexample
38465 <struct id="@var{id}" size="@var{size}">
38466 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
38467 @dots{}
38468 </struct>
38469 @end smallexample
38470
38471 If the structure contains no bitfields, then each field has an
38472 explicit type, and no implicit padding is added.
38473
38474 @smallexample
38475 <struct id="@var{id}">
38476 <field name="@var{name}" type="@var{type}"/>
38477 @dots{}
38478 </struct>
38479 @end smallexample
38480
38481 @cindex <flags>
38482 If a register's value is a series of single-bit flags, define it with
38483 a flags type. The @samp{<flags>} element has an explicit @var{size}
38484 and contains one or more @samp{<field>} elements. Each field has a
38485 @var{name}, a @var{start}, and an @var{end}. Only single-bit flags
38486 are supported.
38487
38488 @smallexample
38489 <flags id="@var{id}" size="@var{size}">
38490 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
38491 @dots{}
38492 </flags>
38493 @end smallexample
38494
38495 @subsection Registers
38496 @cindex <reg>
38497
38498 Each register is represented as an element with this form:
38499
38500 @smallexample
38501 <reg name="@var{name}"
38502 bitsize="@var{size}"
38503 @r{[}regnum="@var{num}"@r{]}
38504 @r{[}save-restore="@var{save-restore}"@r{]}
38505 @r{[}type="@var{type}"@r{]}
38506 @r{[}group="@var{group}"@r{]}/>
38507 @end smallexample
38508
38509 @noindent
38510 The components are as follows:
38511
38512 @table @var
38513
38514 @item name
38515 The register's name; it must be unique within the target description.
38516
38517 @item bitsize
38518 The register's size, in bits.
38519
38520 @item regnum
38521 The register's number. If omitted, a register's number is one greater
38522 than that of the previous register (either in the current feature or in
38523 a preceding feature); the first register in the target description
38524 defaults to zero. This register number is used to read or write
38525 the register; e.g.@: it is used in the remote @code{p} and @code{P}
38526 packets, and registers appear in the @code{g} and @code{G} packets
38527 in order of increasing register number.
38528
38529 @item save-restore
38530 Whether the register should be preserved across inferior function
38531 calls; this must be either @code{yes} or @code{no}. The default is
38532 @code{yes}, which is appropriate for most registers except for
38533 some system control registers; this is not related to the target's
38534 ABI.
38535
38536 @item type
38537 The type of the register. @var{type} may be a predefined type, a type
38538 defined in the current feature, or one of the special types @code{int}
38539 and @code{float}. @code{int} is an integer type of the correct size
38540 for @var{bitsize}, and @code{float} is a floating point type (in the
38541 architecture's normal floating point format) of the correct size for
38542 @var{bitsize}. The default is @code{int}.
38543
38544 @item group
38545 The register group to which this register belongs. @var{group} must
38546 be either @code{general}, @code{float}, or @code{vector}. If no
38547 @var{group} is specified, @value{GDBN} will not display the register
38548 in @code{info registers}.
38549
38550 @end table
38551
38552 @node Predefined Target Types
38553 @section Predefined Target Types
38554 @cindex target descriptions, predefined types
38555
38556 Type definitions in the self-description can build up composite types
38557 from basic building blocks, but can not define fundamental types. Instead,
38558 standard identifiers are provided by @value{GDBN} for the fundamental
38559 types. The currently supported types are:
38560
38561 @table @code
38562
38563 @item int8
38564 @itemx int16
38565 @itemx int32
38566 @itemx int64
38567 @itemx int128
38568 Signed integer types holding the specified number of bits.
38569
38570 @item uint8
38571 @itemx uint16
38572 @itemx uint32
38573 @itemx uint64
38574 @itemx uint128
38575 Unsigned integer types holding the specified number of bits.
38576
38577 @item code_ptr
38578 @itemx data_ptr
38579 Pointers to unspecified code and data. The program counter and
38580 any dedicated return address register may be marked as code
38581 pointers; printing a code pointer converts it into a symbolic
38582 address. The stack pointer and any dedicated address registers
38583 may be marked as data pointers.
38584
38585 @item ieee_single
38586 Single precision IEEE floating point.
38587
38588 @item ieee_double
38589 Double precision IEEE floating point.
38590
38591 @item arm_fpa_ext
38592 The 12-byte extended precision format used by ARM FPA registers.
38593
38594 @item i387_ext
38595 The 10-byte extended precision format used by x87 registers.
38596
38597 @item i386_eflags
38598 32bit @sc{eflags} register used by x86.
38599
38600 @item i386_mxcsr
38601 32bit @sc{mxcsr} register used by x86.
38602
38603 @end table
38604
38605 @node Standard Target Features
38606 @section Standard Target Features
38607 @cindex target descriptions, standard features
38608
38609 A target description must contain either no registers or all the
38610 target's registers. If the description contains no registers, then
38611 @value{GDBN} will assume a default register layout, selected based on
38612 the architecture. If the description contains any registers, the
38613 default layout will not be used; the standard registers must be
38614 described in the target description, in such a way that @value{GDBN}
38615 can recognize them.
38616
38617 This is accomplished by giving specific names to feature elements
38618 which contain standard registers. @value{GDBN} will look for features
38619 with those names and verify that they contain the expected registers;
38620 if any known feature is missing required registers, or if any required
38621 feature is missing, @value{GDBN} will reject the target
38622 description. You can add additional registers to any of the
38623 standard features --- @value{GDBN} will display them just as if
38624 they were added to an unrecognized feature.
38625
38626 This section lists the known features and their expected contents.
38627 Sample XML documents for these features are included in the
38628 @value{GDBN} source tree, in the directory @file{gdb/features}.
38629
38630 Names recognized by @value{GDBN} should include the name of the
38631 company or organization which selected the name, and the overall
38632 architecture to which the feature applies; so e.g.@: the feature
38633 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
38634
38635 The names of registers are not case sensitive for the purpose
38636 of recognizing standard features, but @value{GDBN} will only display
38637 registers using the capitalization used in the description.
38638
38639 @menu
38640 * ARM Features::
38641 * i386 Features::
38642 * MIPS Features::
38643 * M68K Features::
38644 * PowerPC Features::
38645 * TIC6x Features::
38646 @end menu
38647
38648
38649 @node ARM Features
38650 @subsection ARM Features
38651 @cindex target descriptions, ARM features
38652
38653 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
38654 ARM targets.
38655 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
38656 @samp{lr}, @samp{pc}, and @samp{cpsr}.
38657
38658 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
38659 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
38660 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
38661 and @samp{xpsr}.
38662
38663 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
38664 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
38665
38666 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
38667 it should contain at least registers @samp{wR0} through @samp{wR15} and
38668 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
38669 @samp{wCSSF}, and @samp{wCASF} registers are optional.
38670
38671 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
38672 should contain at least registers @samp{d0} through @samp{d15}. If
38673 they are present, @samp{d16} through @samp{d31} should also be included.
38674 @value{GDBN} will synthesize the single-precision registers from
38675 halves of the double-precision registers.
38676
38677 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
38678 need to contain registers; it instructs @value{GDBN} to display the
38679 VFP double-precision registers as vectors and to synthesize the
38680 quad-precision registers from pairs of double-precision registers.
38681 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
38682 be present and include 32 double-precision registers.
38683
38684 @node i386 Features
38685 @subsection i386 Features
38686 @cindex target descriptions, i386 features
38687
38688 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
38689 targets. It should describe the following registers:
38690
38691 @itemize @minus
38692 @item
38693 @samp{eax} through @samp{edi} plus @samp{eip} for i386
38694 @item
38695 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
38696 @item
38697 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
38698 @samp{fs}, @samp{gs}
38699 @item
38700 @samp{st0} through @samp{st7}
38701 @item
38702 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
38703 @samp{foseg}, @samp{fooff} and @samp{fop}
38704 @end itemize
38705
38706 The register sets may be different, depending on the target.
38707
38708 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
38709 describe registers:
38710
38711 @itemize @minus
38712 @item
38713 @samp{xmm0} through @samp{xmm7} for i386
38714 @item
38715 @samp{xmm0} through @samp{xmm15} for amd64
38716 @item
38717 @samp{mxcsr}
38718 @end itemize
38719
38720 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
38721 @samp{org.gnu.gdb.i386.sse} feature. It should
38722 describe the upper 128 bits of @sc{ymm} registers:
38723
38724 @itemize @minus
38725 @item
38726 @samp{ymm0h} through @samp{ymm7h} for i386
38727 @item
38728 @samp{ymm0h} through @samp{ymm15h} for amd64
38729 @end itemize
38730
38731 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
38732 describe a single register, @samp{orig_eax}.
38733
38734 @node MIPS Features
38735 @subsection MIPS Features
38736 @cindex target descriptions, MIPS features
38737
38738 The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
38739 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
38740 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
38741 on the target.
38742
38743 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
38744 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
38745 registers. They may be 32-bit or 64-bit depending on the target.
38746
38747 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
38748 it may be optional in a future version of @value{GDBN}. It should
38749 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
38750 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
38751
38752 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
38753 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
38754 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
38755 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
38756
38757 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
38758 contain a single register, @samp{restart}, which is used by the
38759 Linux kernel to control restartable syscalls.
38760
38761 @node M68K Features
38762 @subsection M68K Features
38763 @cindex target descriptions, M68K features
38764
38765 @table @code
38766 @item @samp{org.gnu.gdb.m68k.core}
38767 @itemx @samp{org.gnu.gdb.coldfire.core}
38768 @itemx @samp{org.gnu.gdb.fido.core}
38769 One of those features must be always present.
38770 The feature that is present determines which flavor of m68k is
38771 used. The feature that is present should contain registers
38772 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
38773 @samp{sp}, @samp{ps} and @samp{pc}.
38774
38775 @item @samp{org.gnu.gdb.coldfire.fp}
38776 This feature is optional. If present, it should contain registers
38777 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
38778 @samp{fpiaddr}.
38779 @end table
38780
38781 @node PowerPC Features
38782 @subsection PowerPC Features
38783 @cindex target descriptions, PowerPC features
38784
38785 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
38786 targets. It should contain registers @samp{r0} through @samp{r31},
38787 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
38788 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
38789
38790 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
38791 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
38792
38793 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
38794 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
38795 and @samp{vrsave}.
38796
38797 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
38798 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
38799 will combine these registers with the floating point registers
38800 (@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
38801 through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
38802 through @samp{vs63}, the set of vector registers for POWER7.
38803
38804 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
38805 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
38806 @samp{spefscr}. SPE targets should provide 32-bit registers in
38807 @samp{org.gnu.gdb.power.core} and provide the upper halves in
38808 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
38809 these to present registers @samp{ev0} through @samp{ev31} to the
38810 user.
38811
38812 @node TIC6x Features
38813 @subsection TMS320C6x Features
38814 @cindex target descriptions, TIC6x features
38815 @cindex target descriptions, TMS320C6x features
38816 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
38817 targets. It should contain registers @samp{A0} through @samp{A15},
38818 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
38819
38820 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
38821 contain registers @samp{A16} through @samp{A31} and @samp{B16}
38822 through @samp{B31}.
38823
38824 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
38825 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
38826
38827 @node Operating System Information
38828 @appendix Operating System Information
38829 @cindex operating system information
38830
38831 @menu
38832 * Process list::
38833 @end menu
38834
38835 Users of @value{GDBN} often wish to obtain information about the state of
38836 the operating system running on the target---for example the list of
38837 processes, or the list of open files. This section describes the
38838 mechanism that makes it possible. This mechanism is similar to the
38839 target features mechanism (@pxref{Target Descriptions}), but focuses
38840 on a different aspect of target.
38841
38842 Operating system information is retrived from the target via the
38843 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
38844 read}). The object name in the request should be @samp{osdata}, and
38845 the @var{annex} identifies the data to be fetched.
38846
38847 @node Process list
38848 @appendixsection Process list
38849 @cindex operating system information, process list
38850
38851 When requesting the process list, the @var{annex} field in the
38852 @samp{qXfer} request should be @samp{processes}. The returned data is
38853 an XML document. The formal syntax of this document is defined in
38854 @file{gdb/features/osdata.dtd}.
38855
38856 An example document is:
38857
38858 @smallexample
38859 <?xml version="1.0"?>
38860 <!DOCTYPE target SYSTEM "osdata.dtd">
38861 <osdata type="processes">
38862 <item>
38863 <column name="pid">1</column>
38864 <column name="user">root</column>
38865 <column name="command">/sbin/init</column>
38866 <column name="cores">1,2,3</column>
38867 </item>
38868 </osdata>
38869 @end smallexample
38870
38871 Each item should include a column whose name is @samp{pid}. The value
38872 of that column should identify the process on the target. The
38873 @samp{user} and @samp{command} columns are optional, and will be
38874 displayed by @value{GDBN}. The @samp{cores} column, if present,
38875 should contain a comma-separated list of cores that this process
38876 is running on. Target may provide additional columns,
38877 which @value{GDBN} currently ignores.
38878
38879 @node Trace File Format
38880 @appendix Trace File Format
38881 @cindex trace file format
38882
38883 The trace file comes in three parts: a header, a textual description
38884 section, and a trace frame section with binary data.
38885
38886 The header has the form @code{\x7fTRACE0\n}. The first byte is
38887 @code{0x7f} so as to indicate that the file contains binary data,
38888 while the @code{0} is a version number that may have different values
38889 in the future.
38890
38891 The description section consists of multiple lines of @sc{ascii} text
38892 separated by newline characters (@code{0xa}). The lines may include a
38893 variety of optional descriptive or context-setting information, such
38894 as tracepoint definitions or register set size. @value{GDBN} will
38895 ignore any line that it does not recognize. An empty line marks the end
38896 of this section.
38897
38898 @c FIXME add some specific types of data
38899
38900 The trace frame section consists of a number of consecutive frames.
38901 Each frame begins with a two-byte tracepoint number, followed by a
38902 four-byte size giving the amount of data in the frame. The data in
38903 the frame consists of a number of blocks, each introduced by a
38904 character indicating its type (at least register, memory, and trace
38905 state variable). The data in this section is raw binary, not a
38906 hexadecimal or other encoding; its endianness matches the target's
38907 endianness.
38908
38909 @c FIXME bi-arch may require endianness/arch info in description section
38910
38911 @table @code
38912 @item R @var{bytes}
38913 Register block. The number and ordering of bytes matches that of a
38914 @code{g} packet in the remote protocol. Note that these are the
38915 actual bytes, in target order and @value{GDBN} register order, not a
38916 hexadecimal encoding.
38917
38918 @item M @var{address} @var{length} @var{bytes}...
38919 Memory block. This is a contiguous block of memory, at the 8-byte
38920 address @var{address}, with a 2-byte length @var{length}, followed by
38921 @var{length} bytes.
38922
38923 @item V @var{number} @var{value}
38924 Trace state variable block. This records the 8-byte signed value
38925 @var{value} of trace state variable numbered @var{number}.
38926
38927 @end table
38928
38929 Future enhancements of the trace file format may include additional types
38930 of blocks.
38931
38932 @node Index Section Format
38933 @appendix @code{.gdb_index} section format
38934 @cindex .gdb_index section format
38935 @cindex index section format
38936
38937 This section documents the index section that is created by @code{save
38938 gdb-index} (@pxref{Index Files}). The index section is
38939 DWARF-specific; some knowledge of DWARF is assumed in this
38940 description.
38941
38942 The mapped index file format is designed to be directly
38943 @code{mmap}able on any architecture. In most cases, a datum is
38944 represented using a little-endian 32-bit integer value, called an
38945 @code{offset_type}. Big endian machines must byte-swap the values
38946 before using them. Exceptions to this rule are noted. The data is
38947 laid out such that alignment is always respected.
38948
38949 A mapped index consists of several areas, laid out in order.
38950
38951 @enumerate
38952 @item
38953 The file header. This is a sequence of values, of @code{offset_type}
38954 unless otherwise noted:
38955
38956 @enumerate
38957 @item
38958 The version number, currently 6. Versions 1, 2 and 3 are obsolete.
38959 Version 4 uses a different hashing function from versions 5 and 6.
38960 Version 6 includes symbols for inlined functions, whereas versions
38961 4 and 5 do not. @value{GDBN} will only read version 4 and 5 indices
38962 if the @code{--use-deprecated-index-sections} option is used.
38963
38964 @item
38965 The offset, from the start of the file, of the CU list.
38966
38967 @item
38968 The offset, from the start of the file, of the types CU list. Note
38969 that this area can be empty, in which case this offset will be equal
38970 to the next offset.
38971
38972 @item
38973 The offset, from the start of the file, of the address area.
38974
38975 @item
38976 The offset, from the start of the file, of the symbol table.
38977
38978 @item
38979 The offset, from the start of the file, of the constant pool.
38980 @end enumerate
38981
38982 @item
38983 The CU list. This is a sequence of pairs of 64-bit little-endian
38984 values, sorted by the CU offset. The first element in each pair is
38985 the offset of a CU in the @code{.debug_info} section. The second
38986 element in each pair is the length of that CU. References to a CU
38987 elsewhere in the map are done using a CU index, which is just the
38988 0-based index into this table. Note that if there are type CUs, then
38989 conceptually CUs and type CUs form a single list for the purposes of
38990 CU indices.
38991
38992 @item
38993 The types CU list. This is a sequence of triplets of 64-bit
38994 little-endian values. In a triplet, the first value is the CU offset,
38995 the second value is the type offset in the CU, and the third value is
38996 the type signature. The types CU list is not sorted.
38997
38998 @item
38999 The address area. The address area consists of a sequence of address
39000 entries. Each address entry has three elements:
39001
39002 @enumerate
39003 @item
39004 The low address. This is a 64-bit little-endian value.
39005
39006 @item
39007 The high address. This is a 64-bit little-endian value. Like
39008 @code{DW_AT_high_pc}, the value is one byte beyond the end.
39009
39010 @item
39011 The CU index. This is an @code{offset_type} value.
39012 @end enumerate
39013
39014 @item
39015 The symbol table. This is an open-addressed hash table. The size of
39016 the hash table is always a power of 2.
39017
39018 Each slot in the hash table consists of a pair of @code{offset_type}
39019 values. The first value is the offset of the symbol's name in the
39020 constant pool. The second value is the offset of the CU vector in the
39021 constant pool.
39022
39023 If both values are 0, then this slot in the hash table is empty. This
39024 is ok because while 0 is a valid constant pool index, it cannot be a
39025 valid index for both a string and a CU vector.
39026
39027 The hash value for a table entry is computed by applying an
39028 iterative hash function to the symbol's name. Starting with an
39029 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
39030 the string is incorporated into the hash using the formula depending on the
39031 index version:
39032
39033 @table @asis
39034 @item Version 4
39035 The formula is @code{r = r * 67 + c - 113}.
39036
39037 @item Versions 5 and 6
39038 The formula is @code{r = r * 67 + tolower (c) - 113}.
39039 @end table
39040
39041 The terminating @samp{\0} is not incorporated into the hash.
39042
39043 The step size used in the hash table is computed via
39044 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
39045 value, and @samp{size} is the size of the hash table. The step size
39046 is used to find the next candidate slot when handling a hash
39047 collision.
39048
39049 The names of C@t{++} symbols in the hash table are canonicalized. We
39050 don't currently have a simple description of the canonicalization
39051 algorithm; if you intend to create new index sections, you must read
39052 the code.
39053
39054 @item
39055 The constant pool. This is simply a bunch of bytes. It is organized
39056 so that alignment is correct: CU vectors are stored first, followed by
39057 strings.
39058
39059 A CU vector in the constant pool is a sequence of @code{offset_type}
39060 values. The first value is the number of CU indices in the vector.
39061 Each subsequent value is the index of a CU in the CU list. This
39062 element in the hash table is used to indicate which CUs define the
39063 symbol.
39064
39065 A string in the constant pool is zero-terminated.
39066 @end enumerate
39067
39068 @include gpl.texi
39069
39070 @node GNU Free Documentation License
39071 @appendix GNU Free Documentation License
39072 @include fdl.texi
39073
39074 @node Index
39075 @unnumbered Index
39076
39077 @printindex cp
39078
39079 @tex
39080 % I think something like @colophon should be in texinfo. In the
39081 % meantime:
39082 \long\def\colophon{\hbox to0pt{}\vfill
39083 \centerline{The body of this manual is set in}
39084 \centerline{\fontname\tenrm,}
39085 \centerline{with headings in {\bf\fontname\tenbf}}
39086 \centerline{and examples in {\tt\fontname\tentt}.}
39087 \centerline{{\it\fontname\tenit\/},}
39088 \centerline{{\bf\fontname\tenbf}, and}
39089 \centerline{{\sl\fontname\tensl\/}}
39090 \centerline{are used for emphasis.}\vfill}
39091 \page\colophon
39092 % Blame: doc@cygnus.com, 1991.
39093 @end tex
39094
39095 @bye
This page took 0.916881 seconds and 5 git commands to generate.