Based on the discussion at:
[binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988-2013 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 @c man begin INCLUDE
10 @include gdb-cfg.texi
11 @c man end
12 @c
13 @settitle Debugging with @value{GDBN}
14 @setchapternewpage odd
15 @c %**end of header
16
17 @iftex
18 @c @smallbook
19 @c @cropmarks
20 @end iftex
21
22 @finalout
23 @c To avoid file-name clashes between index.html and Index.html, when
24 @c the manual is produced on a Posix host and then moved to a
25 @c case-insensitive filesystem (e.g., MS-Windows), we separate the
26 @c indices into two: Concept Index and all the rest.
27 @syncodeindex ky fn
28 @syncodeindex tp fn
29
30 @c readline appendices use @vindex, @findex and @ftable,
31 @c annotate.texi and gdbmi use @findex.
32 @syncodeindex vr fn
33
34 @c !!set GDB manual's edition---not the same as GDB version!
35 @c This is updated by GNU Press.
36 @set EDITION Tenth
37
38 @c !!set GDB edit command default editor
39 @set EDITOR /bin/ex
40
41 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
42
43 @c This is a dir.info fragment to support semi-automated addition of
44 @c manuals to an info tree.
45 @dircategory Software development
46 @direntry
47 * Gdb: (gdb). The GNU debugger.
48 @end direntry
49
50 @copying
51 @c man begin COPYRIGHT
52 Copyright @copyright{} 1988-2013 Free Software Foundation, Inc.
53
54 Permission is granted to copy, distribute and/or modify this document
55 under the terms of the GNU Free Documentation License, Version 1.3 or
56 any later version published by the Free Software Foundation; with the
57 Invariant Sections being ``Free Software'' and ``Free Software Needs
58 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
59 and with the Back-Cover Texts as in (a) below.
60
61 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
62 this GNU Manual. Buying copies from GNU Press supports the FSF in
63 developing GNU and promoting software freedom.''
64 @c man end
65 @end copying
66
67 @ifnottex
68 This file documents the @sc{gnu} debugger @value{GDBN}.
69
70 This is the @value{EDITION} Edition, of @cite{Debugging with
71 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
72 @ifset VERSION_PACKAGE
73 @value{VERSION_PACKAGE}
74 @end ifset
75 Version @value{GDBVN}.
76
77 @insertcopying
78 @end ifnottex
79
80 @titlepage
81 @title Debugging with @value{GDBN}
82 @subtitle The @sc{gnu} Source-Level Debugger
83 @sp 1
84 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
85 @ifset VERSION_PACKAGE
86 @sp 1
87 @subtitle @value{VERSION_PACKAGE}
88 @end ifset
89 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
90 @page
91 @tex
92 {\parskip=0pt
93 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
94 \hfill {\it Debugging with @value{GDBN}}\par
95 \hfill \TeX{}info \texinfoversion\par
96 }
97 @end tex
98
99 @vskip 0pt plus 1filll
100 Published by the Free Software Foundation @*
101 51 Franklin Street, Fifth Floor,
102 Boston, MA 02110-1301, USA@*
103 ISBN 978-0-9831592-3-0 @*
104
105 @insertcopying
106 @end titlepage
107 @page
108
109 @ifnottex
110 @node Top, Summary, (dir), (dir)
111
112 @top Debugging with @value{GDBN}
113
114 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
115
116 This is the @value{EDITION} Edition, for @value{GDBN}
117 @ifset VERSION_PACKAGE
118 @value{VERSION_PACKAGE}
119 @end ifset
120 Version @value{GDBVN}.
121
122 Copyright (C) 1988-2013 Free Software Foundation, Inc.
123
124 This edition of the GDB manual is dedicated to the memory of Fred
125 Fish. Fred was a long-standing contributor to GDB and to Free
126 software in general. We will miss him.
127
128 @menu
129 * Summary:: Summary of @value{GDBN}
130 * Sample Session:: A sample @value{GDBN} session
131
132 * Invocation:: Getting in and out of @value{GDBN}
133 * Commands:: @value{GDBN} commands
134 * Running:: Running programs under @value{GDBN}
135 * Stopping:: Stopping and continuing
136 * Reverse Execution:: Running programs backward
137 * Process Record and Replay:: Recording inferior's execution and replaying it
138 * Stack:: Examining the stack
139 * Source:: Examining source files
140 * Data:: Examining data
141 * Optimized Code:: Debugging optimized code
142 * Macros:: Preprocessor Macros
143 * Tracepoints:: Debugging remote targets non-intrusively
144 * Overlays:: Debugging programs that use overlays
145
146 * Languages:: Using @value{GDBN} with different languages
147
148 * Symbols:: Examining the symbol table
149 * Altering:: Altering execution
150 * GDB Files:: @value{GDBN} files
151 * Targets:: Specifying a debugging target
152 * Remote Debugging:: Debugging remote programs
153 * Configurations:: Configuration-specific information
154 * Controlling GDB:: Controlling @value{GDBN}
155 * Extending GDB:: Extending @value{GDBN}
156 * Interpreters:: Command Interpreters
157 * TUI:: @value{GDBN} Text User Interface
158 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
159 * GDB/MI:: @value{GDBN}'s Machine Interface.
160 * Annotations:: @value{GDBN}'s annotation interface.
161 * JIT Interface:: Using the JIT debugging interface.
162 * In-Process Agent:: In-Process Agent
163
164 * GDB Bugs:: Reporting bugs in @value{GDBN}
165
166 @ifset SYSTEM_READLINE
167 * Command Line Editing: (rluserman). Command Line Editing
168 * Using History Interactively: (history). Using History Interactively
169 @end ifset
170 @ifclear SYSTEM_READLINE
171 * Command Line Editing:: Command Line Editing
172 * Using History Interactively:: Using History Interactively
173 @end ifclear
174 * In Memoriam:: In Memoriam
175 * Formatting Documentation:: How to format and print @value{GDBN} documentation
176 * Installing GDB:: Installing GDB
177 * Maintenance Commands:: Maintenance Commands
178 * Remote Protocol:: GDB Remote Serial Protocol
179 * Agent Expressions:: The GDB Agent Expression Mechanism
180 * Target Descriptions:: How targets can describe themselves to
181 @value{GDBN}
182 * Operating System Information:: Getting additional information from
183 the operating system
184 * Trace File Format:: GDB trace file format
185 * Index Section Format:: .gdb_index section format
186 * Man Pages:: Manual pages
187 * Copying:: GNU General Public License says
188 how you can copy and share GDB
189 * GNU Free Documentation License:: The license for this documentation
190 * Concept Index:: Index of @value{GDBN} concepts
191 * Command and Variable Index:: Index of @value{GDBN} commands, variables,
192 functions, and Python data types
193 @end menu
194
195 @end ifnottex
196
197 @contents
198
199 @node Summary
200 @unnumbered Summary of @value{GDBN}
201
202 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
203 going on ``inside'' another program while it executes---or what another
204 program was doing at the moment it crashed.
205
206 @value{GDBN} can do four main kinds of things (plus other things in support of
207 these) to help you catch bugs in the act:
208
209 @itemize @bullet
210 @item
211 Start your program, specifying anything that might affect its behavior.
212
213 @item
214 Make your program stop on specified conditions.
215
216 @item
217 Examine what has happened, when your program has stopped.
218
219 @item
220 Change things in your program, so you can experiment with correcting the
221 effects of one bug and go on to learn about another.
222 @end itemize
223
224 You can use @value{GDBN} to debug programs written in C and C@t{++}.
225 For more information, see @ref{Supported Languages,,Supported Languages}.
226 For more information, see @ref{C,,C and C++}.
227
228 Support for D is partial. For information on D, see
229 @ref{D,,D}.
230
231 @cindex Modula-2
232 Support for Modula-2 is partial. For information on Modula-2, see
233 @ref{Modula-2,,Modula-2}.
234
235 Support for OpenCL C is partial. For information on OpenCL C, see
236 @ref{OpenCL C,,OpenCL C}.
237
238 @cindex Pascal
239 Debugging Pascal programs which use sets, subranges, file variables, or
240 nested functions does not currently work. @value{GDBN} does not support
241 entering expressions, printing values, or similar features using Pascal
242 syntax.
243
244 @cindex Fortran
245 @value{GDBN} can be used to debug programs written in Fortran, although
246 it may be necessary to refer to some variables with a trailing
247 underscore.
248
249 @value{GDBN} can be used to debug programs written in Objective-C,
250 using either the Apple/NeXT or the GNU Objective-C runtime.
251
252 @menu
253 * Free Software:: Freely redistributable software
254 * Free Documentation:: Free Software Needs Free Documentation
255 * Contributors:: Contributors to GDB
256 @end menu
257
258 @node Free Software
259 @unnumberedsec Free Software
260
261 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
262 General Public License
263 (GPL). The GPL gives you the freedom to copy or adapt a licensed
264 program---but every person getting a copy also gets with it the
265 freedom to modify that copy (which means that they must get access to
266 the source code), and the freedom to distribute further copies.
267 Typical software companies use copyrights to limit your freedoms; the
268 Free Software Foundation uses the GPL to preserve these freedoms.
269
270 Fundamentally, the General Public License is a license which says that
271 you have these freedoms and that you cannot take these freedoms away
272 from anyone else.
273
274 @node Free Documentation
275 @unnumberedsec Free Software Needs Free Documentation
276
277 The biggest deficiency in the free software community today is not in
278 the software---it is the lack of good free documentation that we can
279 include with the free software. Many of our most important
280 programs do not come with free reference manuals and free introductory
281 texts. Documentation is an essential part of any software package;
282 when an important free software package does not come with a free
283 manual and a free tutorial, that is a major gap. We have many such
284 gaps today.
285
286 Consider Perl, for instance. The tutorial manuals that people
287 normally use are non-free. How did this come about? Because the
288 authors of those manuals published them with restrictive terms---no
289 copying, no modification, source files not available---which exclude
290 them from the free software world.
291
292 That wasn't the first time this sort of thing happened, and it was far
293 from the last. Many times we have heard a GNU user eagerly describe a
294 manual that he is writing, his intended contribution to the community,
295 only to learn that he had ruined everything by signing a publication
296 contract to make it non-free.
297
298 Free documentation, like free software, is a matter of freedom, not
299 price. The problem with the non-free manual is not that publishers
300 charge a price for printed copies---that in itself is fine. (The Free
301 Software Foundation sells printed copies of manuals, too.) The
302 problem is the restrictions on the use of the manual. Free manuals
303 are available in source code form, and give you permission to copy and
304 modify. Non-free manuals do not allow this.
305
306 The criteria of freedom for a free manual are roughly the same as for
307 free software. Redistribution (including the normal kinds of
308 commercial redistribution) must be permitted, so that the manual can
309 accompany every copy of the program, both on-line and on paper.
310
311 Permission for modification of the technical content is crucial too.
312 When people modify the software, adding or changing features, if they
313 are conscientious they will change the manual too---so they can
314 provide accurate and clear documentation for the modified program. A
315 manual that leaves you no choice but to write a new manual to document
316 a changed version of the program is not really available to our
317 community.
318
319 Some kinds of limits on the way modification is handled are
320 acceptable. For example, requirements to preserve the original
321 author's copyright notice, the distribution terms, or the list of
322 authors, are ok. It is also no problem to require modified versions
323 to include notice that they were modified. Even entire sections that
324 may not be deleted or changed are acceptable, as long as they deal
325 with nontechnical topics (like this one). These kinds of restrictions
326 are acceptable because they don't obstruct the community's normal use
327 of the manual.
328
329 However, it must be possible to modify all the @emph{technical}
330 content of the manual, and then distribute the result in all the usual
331 media, through all the usual channels. Otherwise, the restrictions
332 obstruct the use of the manual, it is not free, and we need another
333 manual to replace it.
334
335 Please spread the word about this issue. Our community continues to
336 lose manuals to proprietary publishing. If we spread the word that
337 free software needs free reference manuals and free tutorials, perhaps
338 the next person who wants to contribute by writing documentation will
339 realize, before it is too late, that only free manuals contribute to
340 the free software community.
341
342 If you are writing documentation, please insist on publishing it under
343 the GNU Free Documentation License or another free documentation
344 license. Remember that this decision requires your approval---you
345 don't have to let the publisher decide. Some commercial publishers
346 will use a free license if you insist, but they will not propose the
347 option; it is up to you to raise the issue and say firmly that this is
348 what you want. If the publisher you are dealing with refuses, please
349 try other publishers. If you're not sure whether a proposed license
350 is free, write to @email{licensing@@gnu.org}.
351
352 You can encourage commercial publishers to sell more free, copylefted
353 manuals and tutorials by buying them, and particularly by buying
354 copies from the publishers that paid for their writing or for major
355 improvements. Meanwhile, try to avoid buying non-free documentation
356 at all. Check the distribution terms of a manual before you buy it,
357 and insist that whoever seeks your business must respect your freedom.
358 Check the history of the book, and try to reward the publishers that
359 have paid or pay the authors to work on it.
360
361 The Free Software Foundation maintains a list of free documentation
362 published by other publishers, at
363 @url{http://www.fsf.org/doc/other-free-books.html}.
364
365 @node Contributors
366 @unnumberedsec Contributors to @value{GDBN}
367
368 Richard Stallman was the original author of @value{GDBN}, and of many
369 other @sc{gnu} programs. Many others have contributed to its
370 development. This section attempts to credit major contributors. One
371 of the virtues of free software is that everyone is free to contribute
372 to it; with regret, we cannot actually acknowledge everyone here. The
373 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
374 blow-by-blow account.
375
376 Changes much prior to version 2.0 are lost in the mists of time.
377
378 @quotation
379 @emph{Plea:} Additions to this section are particularly welcome. If you
380 or your friends (or enemies, to be evenhanded) have been unfairly
381 omitted from this list, we would like to add your names!
382 @end quotation
383
384 So that they may not regard their many labors as thankless, we
385 particularly thank those who shepherded @value{GDBN} through major
386 releases:
387 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
388 Jim Blandy (release 4.18);
389 Jason Molenda (release 4.17);
390 Stan Shebs (release 4.14);
391 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
392 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
393 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
394 Jim Kingdon (releases 3.5, 3.4, and 3.3);
395 and Randy Smith (releases 3.2, 3.1, and 3.0).
396
397 Richard Stallman, assisted at various times by Peter TerMaat, Chris
398 Hanson, and Richard Mlynarik, handled releases through 2.8.
399
400 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
401 in @value{GDBN}, with significant additional contributions from Per
402 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
403 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
404 much general update work leading to release 3.0).
405
406 @value{GDBN} uses the BFD subroutine library to examine multiple
407 object-file formats; BFD was a joint project of David V.
408 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
409
410 David Johnson wrote the original COFF support; Pace Willison did
411 the original support for encapsulated COFF.
412
413 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
414
415 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
416 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
417 support.
418 Jean-Daniel Fekete contributed Sun 386i support.
419 Chris Hanson improved the HP9000 support.
420 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
421 David Johnson contributed Encore Umax support.
422 Jyrki Kuoppala contributed Altos 3068 support.
423 Jeff Law contributed HP PA and SOM support.
424 Keith Packard contributed NS32K support.
425 Doug Rabson contributed Acorn Risc Machine support.
426 Bob Rusk contributed Harris Nighthawk CX-UX support.
427 Chris Smith contributed Convex support (and Fortran debugging).
428 Jonathan Stone contributed Pyramid support.
429 Michael Tiemann contributed SPARC support.
430 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
431 Pace Willison contributed Intel 386 support.
432 Jay Vosburgh contributed Symmetry support.
433 Marko Mlinar contributed OpenRISC 1000 support.
434
435 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
436
437 Rich Schaefer and Peter Schauer helped with support of SunOS shared
438 libraries.
439
440 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
441 about several machine instruction sets.
442
443 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
444 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
445 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
446 and RDI targets, respectively.
447
448 Brian Fox is the author of the readline libraries providing
449 command-line editing and command history.
450
451 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
452 Modula-2 support, and contributed the Languages chapter of this manual.
453
454 Fred Fish wrote most of the support for Unix System Vr4.
455 He also enhanced the command-completion support to cover C@t{++} overloaded
456 symbols.
457
458 Hitachi America (now Renesas America), Ltd. sponsored the support for
459 H8/300, H8/500, and Super-H processors.
460
461 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
462
463 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
464 processors.
465
466 Toshiba sponsored the support for the TX39 Mips processor.
467
468 Matsushita sponsored the support for the MN10200 and MN10300 processors.
469
470 Fujitsu sponsored the support for SPARClite and FR30 processors.
471
472 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
473 watchpoints.
474
475 Michael Snyder added support for tracepoints.
476
477 Stu Grossman wrote gdbserver.
478
479 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
480 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
481
482 The following people at the Hewlett-Packard Company contributed
483 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
484 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
485 compiler, and the Text User Interface (nee Terminal User Interface):
486 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
487 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
488 provided HP-specific information in this manual.
489
490 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
491 Robert Hoehne made significant contributions to the DJGPP port.
492
493 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
494 development since 1991. Cygnus engineers who have worked on @value{GDBN}
495 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
496 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
497 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
498 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
499 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
500 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
501 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
502 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
503 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
504 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
505 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
506 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
507 Zuhn have made contributions both large and small.
508
509 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
510 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
511
512 Jim Blandy added support for preprocessor macros, while working for Red
513 Hat.
514
515 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
516 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
517 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
518 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
519 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
520 with the migration of old architectures to this new framework.
521
522 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
523 unwinder framework, this consisting of a fresh new design featuring
524 frame IDs, independent frame sniffers, and the sentinel frame. Mark
525 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
526 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
527 trad unwinders. The architecture-specific changes, each involving a
528 complete rewrite of the architecture's frame code, were carried out by
529 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
530 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
531 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
532 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
533 Weigand.
534
535 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
536 Tensilica, Inc.@: contributed support for Xtensa processors. Others
537 who have worked on the Xtensa port of @value{GDBN} in the past include
538 Steve Tjiang, John Newlin, and Scott Foehner.
539
540 Michael Eager and staff of Xilinx, Inc., contributed support for the
541 Xilinx MicroBlaze architecture.
542
543 @node Sample Session
544 @chapter A Sample @value{GDBN} Session
545
546 You can use this manual at your leisure to read all about @value{GDBN}.
547 However, a handful of commands are enough to get started using the
548 debugger. This chapter illustrates those commands.
549
550 @iftex
551 In this sample session, we emphasize user input like this: @b{input},
552 to make it easier to pick out from the surrounding output.
553 @end iftex
554
555 @c FIXME: this example may not be appropriate for some configs, where
556 @c FIXME...primary interest is in remote use.
557
558 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
559 processor) exhibits the following bug: sometimes, when we change its
560 quote strings from the default, the commands used to capture one macro
561 definition within another stop working. In the following short @code{m4}
562 session, we define a macro @code{foo} which expands to @code{0000}; we
563 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
564 same thing. However, when we change the open quote string to
565 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
566 procedure fails to define a new synonym @code{baz}:
567
568 @smallexample
569 $ @b{cd gnu/m4}
570 $ @b{./m4}
571 @b{define(foo,0000)}
572
573 @b{foo}
574 0000
575 @b{define(bar,defn(`foo'))}
576
577 @b{bar}
578 0000
579 @b{changequote(<QUOTE>,<UNQUOTE>)}
580
581 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
582 @b{baz}
583 @b{Ctrl-d}
584 m4: End of input: 0: fatal error: EOF in string
585 @end smallexample
586
587 @noindent
588 Let us use @value{GDBN} to try to see what is going on.
589
590 @smallexample
591 $ @b{@value{GDBP} m4}
592 @c FIXME: this falsifies the exact text played out, to permit smallbook
593 @c FIXME... format to come out better.
594 @value{GDBN} is free software and you are welcome to distribute copies
595 of it under certain conditions; type "show copying" to see
596 the conditions.
597 There is absolutely no warranty for @value{GDBN}; type "show warranty"
598 for details.
599
600 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
601 (@value{GDBP})
602 @end smallexample
603
604 @noindent
605 @value{GDBN} reads only enough symbol data to know where to find the
606 rest when needed; as a result, the first prompt comes up very quickly.
607 We now tell @value{GDBN} to use a narrower display width than usual, so
608 that examples fit in this manual.
609
610 @smallexample
611 (@value{GDBP}) @b{set width 70}
612 @end smallexample
613
614 @noindent
615 We need to see how the @code{m4} built-in @code{changequote} works.
616 Having looked at the source, we know the relevant subroutine is
617 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
618 @code{break} command.
619
620 @smallexample
621 (@value{GDBP}) @b{break m4_changequote}
622 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
623 @end smallexample
624
625 @noindent
626 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
627 control; as long as control does not reach the @code{m4_changequote}
628 subroutine, the program runs as usual:
629
630 @smallexample
631 (@value{GDBP}) @b{run}
632 Starting program: /work/Editorial/gdb/gnu/m4/m4
633 @b{define(foo,0000)}
634
635 @b{foo}
636 0000
637 @end smallexample
638
639 @noindent
640 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
641 suspends execution of @code{m4}, displaying information about the
642 context where it stops.
643
644 @smallexample
645 @b{changequote(<QUOTE>,<UNQUOTE>)}
646
647 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
648 at builtin.c:879
649 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
650 @end smallexample
651
652 @noindent
653 Now we use the command @code{n} (@code{next}) to advance execution to
654 the next line of the current function.
655
656 @smallexample
657 (@value{GDBP}) @b{n}
658 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
659 : nil,
660 @end smallexample
661
662 @noindent
663 @code{set_quotes} looks like a promising subroutine. We can go into it
664 by using the command @code{s} (@code{step}) instead of @code{next}.
665 @code{step} goes to the next line to be executed in @emph{any}
666 subroutine, so it steps into @code{set_quotes}.
667
668 @smallexample
669 (@value{GDBP}) @b{s}
670 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
671 at input.c:530
672 530 if (lquote != def_lquote)
673 @end smallexample
674
675 @noindent
676 The display that shows the subroutine where @code{m4} is now
677 suspended (and its arguments) is called a stack frame display. It
678 shows a summary of the stack. We can use the @code{backtrace}
679 command (which can also be spelled @code{bt}), to see where we are
680 in the stack as a whole: the @code{backtrace} command displays a
681 stack frame for each active subroutine.
682
683 @smallexample
684 (@value{GDBP}) @b{bt}
685 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
686 at input.c:530
687 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
688 at builtin.c:882
689 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
690 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
691 at macro.c:71
692 #4 0x79dc in expand_input () at macro.c:40
693 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
694 @end smallexample
695
696 @noindent
697 We step through a few more lines to see what happens. The first two
698 times, we can use @samp{s}; the next two times we use @code{n} to avoid
699 falling into the @code{xstrdup} subroutine.
700
701 @smallexample
702 (@value{GDBP}) @b{s}
703 0x3b5c 532 if (rquote != def_rquote)
704 (@value{GDBP}) @b{s}
705 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
706 def_lquote : xstrdup(lq);
707 (@value{GDBP}) @b{n}
708 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
709 : xstrdup(rq);
710 (@value{GDBP}) @b{n}
711 538 len_lquote = strlen(rquote);
712 @end smallexample
713
714 @noindent
715 The last line displayed looks a little odd; we can examine the variables
716 @code{lquote} and @code{rquote} to see if they are in fact the new left
717 and right quotes we specified. We use the command @code{p}
718 (@code{print}) to see their values.
719
720 @smallexample
721 (@value{GDBP}) @b{p lquote}
722 $1 = 0x35d40 "<QUOTE>"
723 (@value{GDBP}) @b{p rquote}
724 $2 = 0x35d50 "<UNQUOTE>"
725 @end smallexample
726
727 @noindent
728 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
729 To look at some context, we can display ten lines of source
730 surrounding the current line with the @code{l} (@code{list}) command.
731
732 @smallexample
733 (@value{GDBP}) @b{l}
734 533 xfree(rquote);
735 534
736 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
737 : xstrdup (lq);
738 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
739 : xstrdup (rq);
740 537
741 538 len_lquote = strlen(rquote);
742 539 len_rquote = strlen(lquote);
743 540 @}
744 541
745 542 void
746 @end smallexample
747
748 @noindent
749 Let us step past the two lines that set @code{len_lquote} and
750 @code{len_rquote}, and then examine the values of those variables.
751
752 @smallexample
753 (@value{GDBP}) @b{n}
754 539 len_rquote = strlen(lquote);
755 (@value{GDBP}) @b{n}
756 540 @}
757 (@value{GDBP}) @b{p len_lquote}
758 $3 = 9
759 (@value{GDBP}) @b{p len_rquote}
760 $4 = 7
761 @end smallexample
762
763 @noindent
764 That certainly looks wrong, assuming @code{len_lquote} and
765 @code{len_rquote} are meant to be the lengths of @code{lquote} and
766 @code{rquote} respectively. We can set them to better values using
767 the @code{p} command, since it can print the value of
768 any expression---and that expression can include subroutine calls and
769 assignments.
770
771 @smallexample
772 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
773 $5 = 7
774 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
775 $6 = 9
776 @end smallexample
777
778 @noindent
779 Is that enough to fix the problem of using the new quotes with the
780 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
781 executing with the @code{c} (@code{continue}) command, and then try the
782 example that caused trouble initially:
783
784 @smallexample
785 (@value{GDBP}) @b{c}
786 Continuing.
787
788 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
789
790 baz
791 0000
792 @end smallexample
793
794 @noindent
795 Success! The new quotes now work just as well as the default ones. The
796 problem seems to have been just the two typos defining the wrong
797 lengths. We allow @code{m4} exit by giving it an EOF as input:
798
799 @smallexample
800 @b{Ctrl-d}
801 Program exited normally.
802 @end smallexample
803
804 @noindent
805 The message @samp{Program exited normally.} is from @value{GDBN}; it
806 indicates @code{m4} has finished executing. We can end our @value{GDBN}
807 session with the @value{GDBN} @code{quit} command.
808
809 @smallexample
810 (@value{GDBP}) @b{quit}
811 @end smallexample
812
813 @node Invocation
814 @chapter Getting In and Out of @value{GDBN}
815
816 This chapter discusses how to start @value{GDBN}, and how to get out of it.
817 The essentials are:
818 @itemize @bullet
819 @item
820 type @samp{@value{GDBP}} to start @value{GDBN}.
821 @item
822 type @kbd{quit} or @kbd{Ctrl-d} to exit.
823 @end itemize
824
825 @menu
826 * Invoking GDB:: How to start @value{GDBN}
827 * Quitting GDB:: How to quit @value{GDBN}
828 * Shell Commands:: How to use shell commands inside @value{GDBN}
829 * Logging Output:: How to log @value{GDBN}'s output to a file
830 @end menu
831
832 @node Invoking GDB
833 @section Invoking @value{GDBN}
834
835 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
836 @value{GDBN} reads commands from the terminal until you tell it to exit.
837
838 You can also run @code{@value{GDBP}} with a variety of arguments and options,
839 to specify more of your debugging environment at the outset.
840
841 The command-line options described here are designed
842 to cover a variety of situations; in some environments, some of these
843 options may effectively be unavailable.
844
845 The most usual way to start @value{GDBN} is with one argument,
846 specifying an executable program:
847
848 @smallexample
849 @value{GDBP} @var{program}
850 @end smallexample
851
852 @noindent
853 You can also start with both an executable program and a core file
854 specified:
855
856 @smallexample
857 @value{GDBP} @var{program} @var{core}
858 @end smallexample
859
860 You can, instead, specify a process ID as a second argument, if you want
861 to debug a running process:
862
863 @smallexample
864 @value{GDBP} @var{program} 1234
865 @end smallexample
866
867 @noindent
868 would attach @value{GDBN} to process @code{1234} (unless you also have a file
869 named @file{1234}; @value{GDBN} does check for a core file first).
870
871 Taking advantage of the second command-line argument requires a fairly
872 complete operating system; when you use @value{GDBN} as a remote
873 debugger attached to a bare board, there may not be any notion of
874 ``process'', and there is often no way to get a core dump. @value{GDBN}
875 will warn you if it is unable to attach or to read core dumps.
876
877 You can optionally have @code{@value{GDBP}} pass any arguments after the
878 executable file to the inferior using @code{--args}. This option stops
879 option processing.
880 @smallexample
881 @value{GDBP} --args gcc -O2 -c foo.c
882 @end smallexample
883 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
884 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
885
886 You can run @code{@value{GDBP}} without printing the front material, which describes
887 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
888
889 @smallexample
890 @value{GDBP} -silent
891 @end smallexample
892
893 @noindent
894 You can further control how @value{GDBN} starts up by using command-line
895 options. @value{GDBN} itself can remind you of the options available.
896
897 @noindent
898 Type
899
900 @smallexample
901 @value{GDBP} -help
902 @end smallexample
903
904 @noindent
905 to display all available options and briefly describe their use
906 (@samp{@value{GDBP} -h} is a shorter equivalent).
907
908 All options and command line arguments you give are processed
909 in sequential order. The order makes a difference when the
910 @samp{-x} option is used.
911
912
913 @menu
914 * File Options:: Choosing files
915 * Mode Options:: Choosing modes
916 * Startup:: What @value{GDBN} does during startup
917 @end menu
918
919 @node File Options
920 @subsection Choosing Files
921
922 When @value{GDBN} starts, it reads any arguments other than options as
923 specifying an executable file and core file (or process ID). This is
924 the same as if the arguments were specified by the @samp{-se} and
925 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
926 first argument that does not have an associated option flag as
927 equivalent to the @samp{-se} option followed by that argument; and the
928 second argument that does not have an associated option flag, if any, as
929 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
930 If the second argument begins with a decimal digit, @value{GDBN} will
931 first attempt to attach to it as a process, and if that fails, attempt
932 to open it as a corefile. If you have a corefile whose name begins with
933 a digit, you can prevent @value{GDBN} from treating it as a pid by
934 prefixing it with @file{./}, e.g.@: @file{./12345}.
935
936 If @value{GDBN} has not been configured to included core file support,
937 such as for most embedded targets, then it will complain about a second
938 argument and ignore it.
939
940 Many options have both long and short forms; both are shown in the
941 following list. @value{GDBN} also recognizes the long forms if you truncate
942 them, so long as enough of the option is present to be unambiguous.
943 (If you prefer, you can flag option arguments with @samp{--} rather
944 than @samp{-}, though we illustrate the more usual convention.)
945
946 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
947 @c way, both those who look for -foo and --foo in the index, will find
948 @c it.
949
950 @table @code
951 @item -symbols @var{file}
952 @itemx -s @var{file}
953 @cindex @code{--symbols}
954 @cindex @code{-s}
955 Read symbol table from file @var{file}.
956
957 @item -exec @var{file}
958 @itemx -e @var{file}
959 @cindex @code{--exec}
960 @cindex @code{-e}
961 Use file @var{file} as the executable file to execute when appropriate,
962 and for examining pure data in conjunction with a core dump.
963
964 @item -se @var{file}
965 @cindex @code{--se}
966 Read symbol table from file @var{file} and use it as the executable
967 file.
968
969 @item -core @var{file}
970 @itemx -c @var{file}
971 @cindex @code{--core}
972 @cindex @code{-c}
973 Use file @var{file} as a core dump to examine.
974
975 @item -pid @var{number}
976 @itemx -p @var{number}
977 @cindex @code{--pid}
978 @cindex @code{-p}
979 Connect to process ID @var{number}, as with the @code{attach} command.
980
981 @item -command @var{file}
982 @itemx -x @var{file}
983 @cindex @code{--command}
984 @cindex @code{-x}
985 Execute commands from file @var{file}. The contents of this file is
986 evaluated exactly as the @code{source} command would.
987 @xref{Command Files,, Command files}.
988
989 @item -eval-command @var{command}
990 @itemx -ex @var{command}
991 @cindex @code{--eval-command}
992 @cindex @code{-ex}
993 Execute a single @value{GDBN} command.
994
995 This option may be used multiple times to call multiple commands. It may
996 also be interleaved with @samp{-command} as required.
997
998 @smallexample
999 @value{GDBP} -ex 'target sim' -ex 'load' \
1000 -x setbreakpoints -ex 'run' a.out
1001 @end smallexample
1002
1003 @item -init-command @var{file}
1004 @itemx -ix @var{file}
1005 @cindex @code{--init-command}
1006 @cindex @code{-ix}
1007 Execute commands from file @var{file} before loading the inferior (but
1008 after loading gdbinit files).
1009 @xref{Startup}.
1010
1011 @item -init-eval-command @var{command}
1012 @itemx -iex @var{command}
1013 @cindex @code{--init-eval-command}
1014 @cindex @code{-iex}
1015 Execute a single @value{GDBN} command before loading the inferior (but
1016 after loading gdbinit files).
1017 @xref{Startup}.
1018
1019 @item -directory @var{directory}
1020 @itemx -d @var{directory}
1021 @cindex @code{--directory}
1022 @cindex @code{-d}
1023 Add @var{directory} to the path to search for source and script files.
1024
1025 @item -r
1026 @itemx -readnow
1027 @cindex @code{--readnow}
1028 @cindex @code{-r}
1029 Read each symbol file's entire symbol table immediately, rather than
1030 the default, which is to read it incrementally as it is needed.
1031 This makes startup slower, but makes future operations faster.
1032
1033 @end table
1034
1035 @node Mode Options
1036 @subsection Choosing Modes
1037
1038 You can run @value{GDBN} in various alternative modes---for example, in
1039 batch mode or quiet mode.
1040
1041 @table @code
1042 @anchor{-nx}
1043 @item -nx
1044 @itemx -n
1045 @cindex @code{--nx}
1046 @cindex @code{-n}
1047 Do not execute commands found in any initialization file.
1048 There are three init files, loaded in the following order:
1049
1050 @table @code
1051 @item @file{system.gdbinit}
1052 This is the system-wide init file.
1053 Its location is specified with the @code{--with-system-gdbinit}
1054 configure option (@pxref{System-wide configuration}).
1055 It is loaded first when @value{GDBN} starts, before command line options
1056 have been processed.
1057 @item @file{~/.gdbinit}
1058 This is the init file in your home directory.
1059 It is loaded next, after @file{system.gdbinit}, and before
1060 command options have been processed.
1061 @item @file{./.gdbinit}
1062 This is the init file in the current directory.
1063 It is loaded last, after command line options other than @code{-x} and
1064 @code{-ex} have been processed. Command line options @code{-x} and
1065 @code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1066 @end table
1067
1068 For further documentation on startup processing, @xref{Startup}.
1069 For documentation on how to write command files,
1070 @xref{Command Files,,Command Files}.
1071
1072 @anchor{-nh}
1073 @item -nh
1074 @cindex @code{--nh}
1075 Do not execute commands found in @file{~/.gdbinit}, the init file
1076 in your home directory.
1077 @xref{Startup}.
1078
1079 @item -quiet
1080 @itemx -silent
1081 @itemx -q
1082 @cindex @code{--quiet}
1083 @cindex @code{--silent}
1084 @cindex @code{-q}
1085 ``Quiet''. Do not print the introductory and copyright messages. These
1086 messages are also suppressed in batch mode.
1087
1088 @item -batch
1089 @cindex @code{--batch}
1090 Run in batch mode. Exit with status @code{0} after processing all the
1091 command files specified with @samp{-x} (and all commands from
1092 initialization files, if not inhibited with @samp{-n}). Exit with
1093 nonzero status if an error occurs in executing the @value{GDBN} commands
1094 in the command files. Batch mode also disables pagination, sets unlimited
1095 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1096 off} were in effect (@pxref{Messages/Warnings}).
1097
1098 Batch mode may be useful for running @value{GDBN} as a filter, for
1099 example to download and run a program on another computer; in order to
1100 make this more useful, the message
1101
1102 @smallexample
1103 Program exited normally.
1104 @end smallexample
1105
1106 @noindent
1107 (which is ordinarily issued whenever a program running under
1108 @value{GDBN} control terminates) is not issued when running in batch
1109 mode.
1110
1111 @item -batch-silent
1112 @cindex @code{--batch-silent}
1113 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1114 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1115 unaffected). This is much quieter than @samp{-silent} and would be useless
1116 for an interactive session.
1117
1118 This is particularly useful when using targets that give @samp{Loading section}
1119 messages, for example.
1120
1121 Note that targets that give their output via @value{GDBN}, as opposed to
1122 writing directly to @code{stdout}, will also be made silent.
1123
1124 @item -return-child-result
1125 @cindex @code{--return-child-result}
1126 The return code from @value{GDBN} will be the return code from the child
1127 process (the process being debugged), with the following exceptions:
1128
1129 @itemize @bullet
1130 @item
1131 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1132 internal error. In this case the exit code is the same as it would have been
1133 without @samp{-return-child-result}.
1134 @item
1135 The user quits with an explicit value. E.g., @samp{quit 1}.
1136 @item
1137 The child process never runs, or is not allowed to terminate, in which case
1138 the exit code will be -1.
1139 @end itemize
1140
1141 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1142 when @value{GDBN} is being used as a remote program loader or simulator
1143 interface.
1144
1145 @item -nowindows
1146 @itemx -nw
1147 @cindex @code{--nowindows}
1148 @cindex @code{-nw}
1149 ``No windows''. If @value{GDBN} comes with a graphical user interface
1150 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1151 interface. If no GUI is available, this option has no effect.
1152
1153 @item -windows
1154 @itemx -w
1155 @cindex @code{--windows}
1156 @cindex @code{-w}
1157 If @value{GDBN} includes a GUI, then this option requires it to be
1158 used if possible.
1159
1160 @item -cd @var{directory}
1161 @cindex @code{--cd}
1162 Run @value{GDBN} using @var{directory} as its working directory,
1163 instead of the current directory.
1164
1165 @item -data-directory @var{directory}
1166 @cindex @code{--data-directory}
1167 Run @value{GDBN} using @var{directory} as its data directory.
1168 The data directory is where @value{GDBN} searches for its
1169 auxiliary files. @xref{Data Files}.
1170
1171 @item -fullname
1172 @itemx -f
1173 @cindex @code{--fullname}
1174 @cindex @code{-f}
1175 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1176 subprocess. It tells @value{GDBN} to output the full file name and line
1177 number in a standard, recognizable fashion each time a stack frame is
1178 displayed (which includes each time your program stops). This
1179 recognizable format looks like two @samp{\032} characters, followed by
1180 the file name, line number and character position separated by colons,
1181 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1182 @samp{\032} characters as a signal to display the source code for the
1183 frame.
1184
1185 @item -annotate @var{level}
1186 @cindex @code{--annotate}
1187 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1188 effect is identical to using @samp{set annotate @var{level}}
1189 (@pxref{Annotations}). The annotation @var{level} controls how much
1190 information @value{GDBN} prints together with its prompt, values of
1191 expressions, source lines, and other types of output. Level 0 is the
1192 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1193 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1194 that control @value{GDBN}, and level 2 has been deprecated.
1195
1196 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1197 (@pxref{GDB/MI}).
1198
1199 @item --args
1200 @cindex @code{--args}
1201 Change interpretation of command line so that arguments following the
1202 executable file are passed as command line arguments to the inferior.
1203 This option stops option processing.
1204
1205 @item -baud @var{bps}
1206 @itemx -b @var{bps}
1207 @cindex @code{--baud}
1208 @cindex @code{-b}
1209 Set the line speed (baud rate or bits per second) of any serial
1210 interface used by @value{GDBN} for remote debugging.
1211
1212 @item -l @var{timeout}
1213 @cindex @code{-l}
1214 Set the timeout (in seconds) of any communication used by @value{GDBN}
1215 for remote debugging.
1216
1217 @item -tty @var{device}
1218 @itemx -t @var{device}
1219 @cindex @code{--tty}
1220 @cindex @code{-t}
1221 Run using @var{device} for your program's standard input and output.
1222 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1223
1224 @c resolve the situation of these eventually
1225 @item -tui
1226 @cindex @code{--tui}
1227 Activate the @dfn{Text User Interface} when starting. The Text User
1228 Interface manages several text windows on the terminal, showing
1229 source, assembly, registers and @value{GDBN} command outputs
1230 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1231 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1232 Using @value{GDBN} under @sc{gnu} Emacs}).
1233
1234 @c @item -xdb
1235 @c @cindex @code{--xdb}
1236 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1237 @c For information, see the file @file{xdb_trans.html}, which is usually
1238 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1239 @c systems.
1240
1241 @item -interpreter @var{interp}
1242 @cindex @code{--interpreter}
1243 Use the interpreter @var{interp} for interface with the controlling
1244 program or device. This option is meant to be set by programs which
1245 communicate with @value{GDBN} using it as a back end.
1246 @xref{Interpreters, , Command Interpreters}.
1247
1248 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1249 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1250 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
1251 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1252 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1253 @sc{gdb/mi} interfaces are no longer supported.
1254
1255 @item -write
1256 @cindex @code{--write}
1257 Open the executable and core files for both reading and writing. This
1258 is equivalent to the @samp{set write on} command inside @value{GDBN}
1259 (@pxref{Patching}).
1260
1261 @item -statistics
1262 @cindex @code{--statistics}
1263 This option causes @value{GDBN} to print statistics about time and
1264 memory usage after it completes each command and returns to the prompt.
1265
1266 @item -version
1267 @cindex @code{--version}
1268 This option causes @value{GDBN} to print its version number and
1269 no-warranty blurb, and exit.
1270
1271 @item -configuration
1272 @cindex @code{--configuration}
1273 This option causes @value{GDBN} to print details about its build-time
1274 configuration parameters, and then exit. These details can be
1275 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1276
1277 @end table
1278
1279 @node Startup
1280 @subsection What @value{GDBN} Does During Startup
1281 @cindex @value{GDBN} startup
1282
1283 Here's the description of what @value{GDBN} does during session startup:
1284
1285 @enumerate
1286 @item
1287 Sets up the command interpreter as specified by the command line
1288 (@pxref{Mode Options, interpreter}).
1289
1290 @item
1291 @cindex init file
1292 Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1293 used when building @value{GDBN}; @pxref{System-wide configuration,
1294 ,System-wide configuration and settings}) and executes all the commands in
1295 that file.
1296
1297 @anchor{Home Directory Init File}
1298 @item
1299 Reads the init file (if any) in your home directory@footnote{On
1300 DOS/Windows systems, the home directory is the one pointed to by the
1301 @code{HOME} environment variable.} and executes all the commands in
1302 that file.
1303
1304 @anchor{Option -init-eval-command}
1305 @item
1306 Executes commands and command files specified by the @samp{-iex} and
1307 @samp{-ix} options in their specified order. Usually you should use the
1308 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1309 settings before @value{GDBN} init files get executed and before inferior
1310 gets loaded.
1311
1312 @item
1313 Processes command line options and operands.
1314
1315 @anchor{Init File in the Current Directory during Startup}
1316 @item
1317 Reads and executes the commands from init file (if any) in the current
1318 working directory as long as @samp{set auto-load local-gdbinit} is set to
1319 @samp{on} (@pxref{Init File in the Current Directory}).
1320 This is only done if the current directory is
1321 different from your home directory. Thus, you can have more than one
1322 init file, one generic in your home directory, and another, specific
1323 to the program you are debugging, in the directory where you invoke
1324 @value{GDBN}.
1325
1326 @item
1327 If the command line specified a program to debug, or a process to
1328 attach to, or a core file, @value{GDBN} loads any auto-loaded
1329 scripts provided for the program or for its loaded shared libraries.
1330 @xref{Auto-loading}.
1331
1332 If you wish to disable the auto-loading during startup,
1333 you must do something like the following:
1334
1335 @smallexample
1336 $ gdb -iex "set auto-load python-scripts off" myprogram
1337 @end smallexample
1338
1339 Option @samp{-ex} does not work because the auto-loading is then turned
1340 off too late.
1341
1342 @item
1343 Executes commands and command files specified by the @samp{-ex} and
1344 @samp{-x} options in their specified order. @xref{Command Files}, for
1345 more details about @value{GDBN} command files.
1346
1347 @item
1348 Reads the command history recorded in the @dfn{history file}.
1349 @xref{Command History}, for more details about the command history and the
1350 files where @value{GDBN} records it.
1351 @end enumerate
1352
1353 Init files use the same syntax as @dfn{command files} (@pxref{Command
1354 Files}) and are processed by @value{GDBN} in the same way. The init
1355 file in your home directory can set options (such as @samp{set
1356 complaints}) that affect subsequent processing of command line options
1357 and operands. Init files are not executed if you use the @samp{-nx}
1358 option (@pxref{Mode Options, ,Choosing Modes}).
1359
1360 To display the list of init files loaded by gdb at startup, you
1361 can use @kbd{gdb --help}.
1362
1363 @cindex init file name
1364 @cindex @file{.gdbinit}
1365 @cindex @file{gdb.ini}
1366 The @value{GDBN} init files are normally called @file{.gdbinit}.
1367 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1368 the limitations of file names imposed by DOS filesystems. The Windows
1369 port of @value{GDBN} uses the standard name, but if it finds a
1370 @file{gdb.ini} file in your home directory, it warns you about that
1371 and suggests to rename the file to the standard name.
1372
1373
1374 @node Quitting GDB
1375 @section Quitting @value{GDBN}
1376 @cindex exiting @value{GDBN}
1377 @cindex leaving @value{GDBN}
1378
1379 @table @code
1380 @kindex quit @r{[}@var{expression}@r{]}
1381 @kindex q @r{(@code{quit})}
1382 @item quit @r{[}@var{expression}@r{]}
1383 @itemx q
1384 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1385 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1386 do not supply @var{expression}, @value{GDBN} will terminate normally;
1387 otherwise it will terminate using the result of @var{expression} as the
1388 error code.
1389 @end table
1390
1391 @cindex interrupt
1392 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1393 terminates the action of any @value{GDBN} command that is in progress and
1394 returns to @value{GDBN} command level. It is safe to type the interrupt
1395 character at any time because @value{GDBN} does not allow it to take effect
1396 until a time when it is safe.
1397
1398 If you have been using @value{GDBN} to control an attached process or
1399 device, you can release it with the @code{detach} command
1400 (@pxref{Attach, ,Debugging an Already-running Process}).
1401
1402 @node Shell Commands
1403 @section Shell Commands
1404
1405 If you need to execute occasional shell commands during your
1406 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1407 just use the @code{shell} command.
1408
1409 @table @code
1410 @kindex shell
1411 @kindex !
1412 @cindex shell escape
1413 @item shell @var{command-string}
1414 @itemx !@var{command-string}
1415 Invoke a standard shell to execute @var{command-string}.
1416 Note that no space is needed between @code{!} and @var{command-string}.
1417 If it exists, the environment variable @code{SHELL} determines which
1418 shell to run. Otherwise @value{GDBN} uses the default shell
1419 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1420 @end table
1421
1422 The utility @code{make} is often needed in development environments.
1423 You do not have to use the @code{shell} command for this purpose in
1424 @value{GDBN}:
1425
1426 @table @code
1427 @kindex make
1428 @cindex calling make
1429 @item make @var{make-args}
1430 Execute the @code{make} program with the specified
1431 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1432 @end table
1433
1434 @node Logging Output
1435 @section Logging Output
1436 @cindex logging @value{GDBN} output
1437 @cindex save @value{GDBN} output to a file
1438
1439 You may want to save the output of @value{GDBN} commands to a file.
1440 There are several commands to control @value{GDBN}'s logging.
1441
1442 @table @code
1443 @kindex set logging
1444 @item set logging on
1445 Enable logging.
1446 @item set logging off
1447 Disable logging.
1448 @cindex logging file name
1449 @item set logging file @var{file}
1450 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1451 @item set logging overwrite [on|off]
1452 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1453 you want @code{set logging on} to overwrite the logfile instead.
1454 @item set logging redirect [on|off]
1455 By default, @value{GDBN} output will go to both the terminal and the logfile.
1456 Set @code{redirect} if you want output to go only to the log file.
1457 @kindex show logging
1458 @item show logging
1459 Show the current values of the logging settings.
1460 @end table
1461
1462 @node Commands
1463 @chapter @value{GDBN} Commands
1464
1465 You can abbreviate a @value{GDBN} command to the first few letters of the command
1466 name, if that abbreviation is unambiguous; and you can repeat certain
1467 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1468 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1469 show you the alternatives available, if there is more than one possibility).
1470
1471 @menu
1472 * Command Syntax:: How to give commands to @value{GDBN}
1473 * Completion:: Command completion
1474 * Help:: How to ask @value{GDBN} for help
1475 @end menu
1476
1477 @node Command Syntax
1478 @section Command Syntax
1479
1480 A @value{GDBN} command is a single line of input. There is no limit on
1481 how long it can be. It starts with a command name, which is followed by
1482 arguments whose meaning depends on the command name. For example, the
1483 command @code{step} accepts an argument which is the number of times to
1484 step, as in @samp{step 5}. You can also use the @code{step} command
1485 with no arguments. Some commands do not allow any arguments.
1486
1487 @cindex abbreviation
1488 @value{GDBN} command names may always be truncated if that abbreviation is
1489 unambiguous. Other possible command abbreviations are listed in the
1490 documentation for individual commands. In some cases, even ambiguous
1491 abbreviations are allowed; for example, @code{s} is specially defined as
1492 equivalent to @code{step} even though there are other commands whose
1493 names start with @code{s}. You can test abbreviations by using them as
1494 arguments to the @code{help} command.
1495
1496 @cindex repeating commands
1497 @kindex RET @r{(repeat last command)}
1498 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1499 repeat the previous command. Certain commands (for example, @code{run})
1500 will not repeat this way; these are commands whose unintentional
1501 repetition might cause trouble and which you are unlikely to want to
1502 repeat. User-defined commands can disable this feature; see
1503 @ref{Define, dont-repeat}.
1504
1505 The @code{list} and @code{x} commands, when you repeat them with
1506 @key{RET}, construct new arguments rather than repeating
1507 exactly as typed. This permits easy scanning of source or memory.
1508
1509 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1510 output, in a way similar to the common utility @code{more}
1511 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1512 @key{RET} too many in this situation, @value{GDBN} disables command
1513 repetition after any command that generates this sort of display.
1514
1515 @kindex # @r{(a comment)}
1516 @cindex comment
1517 Any text from a @kbd{#} to the end of the line is a comment; it does
1518 nothing. This is useful mainly in command files (@pxref{Command
1519 Files,,Command Files}).
1520
1521 @cindex repeating command sequences
1522 @kindex Ctrl-o @r{(operate-and-get-next)}
1523 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1524 commands. This command accepts the current line, like @key{RET}, and
1525 then fetches the next line relative to the current line from the history
1526 for editing.
1527
1528 @node Completion
1529 @section Command Completion
1530
1531 @cindex completion
1532 @cindex word completion
1533 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1534 only one possibility; it can also show you what the valid possibilities
1535 are for the next word in a command, at any time. This works for @value{GDBN}
1536 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1537
1538 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1539 of a word. If there is only one possibility, @value{GDBN} fills in the
1540 word, and waits for you to finish the command (or press @key{RET} to
1541 enter it). For example, if you type
1542
1543 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1544 @c complete accuracy in these examples; space introduced for clarity.
1545 @c If texinfo enhancements make it unnecessary, it would be nice to
1546 @c replace " @key" by "@key" in the following...
1547 @smallexample
1548 (@value{GDBP}) info bre @key{TAB}
1549 @end smallexample
1550
1551 @noindent
1552 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1553 the only @code{info} subcommand beginning with @samp{bre}:
1554
1555 @smallexample
1556 (@value{GDBP}) info breakpoints
1557 @end smallexample
1558
1559 @noindent
1560 You can either press @key{RET} at this point, to run the @code{info
1561 breakpoints} command, or backspace and enter something else, if
1562 @samp{breakpoints} does not look like the command you expected. (If you
1563 were sure you wanted @code{info breakpoints} in the first place, you
1564 might as well just type @key{RET} immediately after @samp{info bre},
1565 to exploit command abbreviations rather than command completion).
1566
1567 If there is more than one possibility for the next word when you press
1568 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1569 characters and try again, or just press @key{TAB} a second time;
1570 @value{GDBN} displays all the possible completions for that word. For
1571 example, you might want to set a breakpoint on a subroutine whose name
1572 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1573 just sounds the bell. Typing @key{TAB} again displays all the
1574 function names in your program that begin with those characters, for
1575 example:
1576
1577 @smallexample
1578 (@value{GDBP}) b make_ @key{TAB}
1579 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1580 make_a_section_from_file make_environ
1581 make_abs_section make_function_type
1582 make_blockvector make_pointer_type
1583 make_cleanup make_reference_type
1584 make_command make_symbol_completion_list
1585 (@value{GDBP}) b make_
1586 @end smallexample
1587
1588 @noindent
1589 After displaying the available possibilities, @value{GDBN} copies your
1590 partial input (@samp{b make_} in the example) so you can finish the
1591 command.
1592
1593 If you just want to see the list of alternatives in the first place, you
1594 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1595 means @kbd{@key{META} ?}. You can type this either by holding down a
1596 key designated as the @key{META} shift on your keyboard (if there is
1597 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1598
1599 @cindex quotes in commands
1600 @cindex completion of quoted strings
1601 Sometimes the string you need, while logically a ``word'', may contain
1602 parentheses or other characters that @value{GDBN} normally excludes from
1603 its notion of a word. To permit word completion to work in this
1604 situation, you may enclose words in @code{'} (single quote marks) in
1605 @value{GDBN} commands.
1606
1607 The most likely situation where you might need this is in typing the
1608 name of a C@t{++} function. This is because C@t{++} allows function
1609 overloading (multiple definitions of the same function, distinguished
1610 by argument type). For example, when you want to set a breakpoint you
1611 may need to distinguish whether you mean the version of @code{name}
1612 that takes an @code{int} parameter, @code{name(int)}, or the version
1613 that takes a @code{float} parameter, @code{name(float)}. To use the
1614 word-completion facilities in this situation, type a single quote
1615 @code{'} at the beginning of the function name. This alerts
1616 @value{GDBN} that it may need to consider more information than usual
1617 when you press @key{TAB} or @kbd{M-?} to request word completion:
1618
1619 @smallexample
1620 (@value{GDBP}) b 'bubble( @kbd{M-?}
1621 bubble(double,double) bubble(int,int)
1622 (@value{GDBP}) b 'bubble(
1623 @end smallexample
1624
1625 In some cases, @value{GDBN} can tell that completing a name requires using
1626 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1627 completing as much as it can) if you do not type the quote in the first
1628 place:
1629
1630 @smallexample
1631 (@value{GDBP}) b bub @key{TAB}
1632 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1633 (@value{GDBP}) b 'bubble(
1634 @end smallexample
1635
1636 @noindent
1637 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1638 you have not yet started typing the argument list when you ask for
1639 completion on an overloaded symbol.
1640
1641 For more information about overloaded functions, see @ref{C Plus Plus
1642 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1643 overload-resolution off} to disable overload resolution;
1644 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1645
1646 @cindex completion of structure field names
1647 @cindex structure field name completion
1648 @cindex completion of union field names
1649 @cindex union field name completion
1650 When completing in an expression which looks up a field in a
1651 structure, @value{GDBN} also tries@footnote{The completer can be
1652 confused by certain kinds of invalid expressions. Also, it only
1653 examines the static type of the expression, not the dynamic type.} to
1654 limit completions to the field names available in the type of the
1655 left-hand-side:
1656
1657 @smallexample
1658 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1659 magic to_fputs to_rewind
1660 to_data to_isatty to_write
1661 to_delete to_put to_write_async_safe
1662 to_flush to_read
1663 @end smallexample
1664
1665 @noindent
1666 This is because the @code{gdb_stdout} is a variable of the type
1667 @code{struct ui_file} that is defined in @value{GDBN} sources as
1668 follows:
1669
1670 @smallexample
1671 struct ui_file
1672 @{
1673 int *magic;
1674 ui_file_flush_ftype *to_flush;
1675 ui_file_write_ftype *to_write;
1676 ui_file_write_async_safe_ftype *to_write_async_safe;
1677 ui_file_fputs_ftype *to_fputs;
1678 ui_file_read_ftype *to_read;
1679 ui_file_delete_ftype *to_delete;
1680 ui_file_isatty_ftype *to_isatty;
1681 ui_file_rewind_ftype *to_rewind;
1682 ui_file_put_ftype *to_put;
1683 void *to_data;
1684 @}
1685 @end smallexample
1686
1687
1688 @node Help
1689 @section Getting Help
1690 @cindex online documentation
1691 @kindex help
1692
1693 You can always ask @value{GDBN} itself for information on its commands,
1694 using the command @code{help}.
1695
1696 @table @code
1697 @kindex h @r{(@code{help})}
1698 @item help
1699 @itemx h
1700 You can use @code{help} (abbreviated @code{h}) with no arguments to
1701 display a short list of named classes of commands:
1702
1703 @smallexample
1704 (@value{GDBP}) help
1705 List of classes of commands:
1706
1707 aliases -- Aliases of other commands
1708 breakpoints -- Making program stop at certain points
1709 data -- Examining data
1710 files -- Specifying and examining files
1711 internals -- Maintenance commands
1712 obscure -- Obscure features
1713 running -- Running the program
1714 stack -- Examining the stack
1715 status -- Status inquiries
1716 support -- Support facilities
1717 tracepoints -- Tracing of program execution without
1718 stopping the program
1719 user-defined -- User-defined commands
1720
1721 Type "help" followed by a class name for a list of
1722 commands in that class.
1723 Type "help" followed by command name for full
1724 documentation.
1725 Command name abbreviations are allowed if unambiguous.
1726 (@value{GDBP})
1727 @end smallexample
1728 @c the above line break eliminates huge line overfull...
1729
1730 @item help @var{class}
1731 Using one of the general help classes as an argument, you can get a
1732 list of the individual commands in that class. For example, here is the
1733 help display for the class @code{status}:
1734
1735 @smallexample
1736 (@value{GDBP}) help status
1737 Status inquiries.
1738
1739 List of commands:
1740
1741 @c Line break in "show" line falsifies real output, but needed
1742 @c to fit in smallbook page size.
1743 info -- Generic command for showing things
1744 about the program being debugged
1745 show -- Generic command for showing things
1746 about the debugger
1747
1748 Type "help" followed by command name for full
1749 documentation.
1750 Command name abbreviations are allowed if unambiguous.
1751 (@value{GDBP})
1752 @end smallexample
1753
1754 @item help @var{command}
1755 With a command name as @code{help} argument, @value{GDBN} displays a
1756 short paragraph on how to use that command.
1757
1758 @kindex apropos
1759 @item apropos @var{args}
1760 The @code{apropos} command searches through all of the @value{GDBN}
1761 commands, and their documentation, for the regular expression specified in
1762 @var{args}. It prints out all matches found. For example:
1763
1764 @smallexample
1765 apropos alias
1766 @end smallexample
1767
1768 @noindent
1769 results in:
1770
1771 @smallexample
1772 @c @group
1773 alias -- Define a new command that is an alias of an existing command
1774 aliases -- Aliases of other commands
1775 d -- Delete some breakpoints or auto-display expressions
1776 del -- Delete some breakpoints or auto-display expressions
1777 delete -- Delete some breakpoints or auto-display expressions
1778 @c @end group
1779 @end smallexample
1780
1781 @kindex complete
1782 @item complete @var{args}
1783 The @code{complete @var{args}} command lists all the possible completions
1784 for the beginning of a command. Use @var{args} to specify the beginning of the
1785 command you want completed. For example:
1786
1787 @smallexample
1788 complete i
1789 @end smallexample
1790
1791 @noindent results in:
1792
1793 @smallexample
1794 @group
1795 if
1796 ignore
1797 info
1798 inspect
1799 @end group
1800 @end smallexample
1801
1802 @noindent This is intended for use by @sc{gnu} Emacs.
1803 @end table
1804
1805 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1806 and @code{show} to inquire about the state of your program, or the state
1807 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1808 manual introduces each of them in the appropriate context. The listings
1809 under @code{info} and under @code{show} in the Command, Variable, and
1810 Function Index point to all the sub-commands. @xref{Command and Variable
1811 Index}.
1812
1813 @c @group
1814 @table @code
1815 @kindex info
1816 @kindex i @r{(@code{info})}
1817 @item info
1818 This command (abbreviated @code{i}) is for describing the state of your
1819 program. For example, you can show the arguments passed to a function
1820 with @code{info args}, list the registers currently in use with @code{info
1821 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1822 You can get a complete list of the @code{info} sub-commands with
1823 @w{@code{help info}}.
1824
1825 @kindex set
1826 @item set
1827 You can assign the result of an expression to an environment variable with
1828 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1829 @code{set prompt $}.
1830
1831 @kindex show
1832 @item show
1833 In contrast to @code{info}, @code{show} is for describing the state of
1834 @value{GDBN} itself.
1835 You can change most of the things you can @code{show}, by using the
1836 related command @code{set}; for example, you can control what number
1837 system is used for displays with @code{set radix}, or simply inquire
1838 which is currently in use with @code{show radix}.
1839
1840 @kindex info set
1841 To display all the settable parameters and their current
1842 values, you can use @code{show} with no arguments; you may also use
1843 @code{info set}. Both commands produce the same display.
1844 @c FIXME: "info set" violates the rule that "info" is for state of
1845 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1846 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1847 @end table
1848 @c @end group
1849
1850 Here are several miscellaneous @code{show} subcommands, all of which are
1851 exceptional in lacking corresponding @code{set} commands:
1852
1853 @table @code
1854 @kindex show version
1855 @cindex @value{GDBN} version number
1856 @item show version
1857 Show what version of @value{GDBN} is running. You should include this
1858 information in @value{GDBN} bug-reports. If multiple versions of
1859 @value{GDBN} are in use at your site, you may need to determine which
1860 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1861 commands are introduced, and old ones may wither away. Also, many
1862 system vendors ship variant versions of @value{GDBN}, and there are
1863 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1864 The version number is the same as the one announced when you start
1865 @value{GDBN}.
1866
1867 @kindex show copying
1868 @kindex info copying
1869 @cindex display @value{GDBN} copyright
1870 @item show copying
1871 @itemx info copying
1872 Display information about permission for copying @value{GDBN}.
1873
1874 @kindex show warranty
1875 @kindex info warranty
1876 @item show warranty
1877 @itemx info warranty
1878 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1879 if your version of @value{GDBN} comes with one.
1880
1881 @kindex show configuration
1882 @item show configuration
1883 Display detailed information about the way @value{GDBN} was configured
1884 when it was built. This displays the optional arguments passed to the
1885 @file{configure} script and also configuration parameters detected
1886 automatically by @command{configure}. When reporting a @value{GDBN}
1887 bug (@pxref{GDB Bugs}), it is important to include this information in
1888 your report.
1889
1890 @end table
1891
1892 @node Running
1893 @chapter Running Programs Under @value{GDBN}
1894
1895 When you run a program under @value{GDBN}, you must first generate
1896 debugging information when you compile it.
1897
1898 You may start @value{GDBN} with its arguments, if any, in an environment
1899 of your choice. If you are doing native debugging, you may redirect
1900 your program's input and output, debug an already running process, or
1901 kill a child process.
1902
1903 @menu
1904 * Compilation:: Compiling for debugging
1905 * Starting:: Starting your program
1906 * Arguments:: Your program's arguments
1907 * Environment:: Your program's environment
1908
1909 * Working Directory:: Your program's working directory
1910 * Input/Output:: Your program's input and output
1911 * Attach:: Debugging an already-running process
1912 * Kill Process:: Killing the child process
1913
1914 * Inferiors and Programs:: Debugging multiple inferiors and programs
1915 * Threads:: Debugging programs with multiple threads
1916 * Forks:: Debugging forks
1917 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
1918 @end menu
1919
1920 @node Compilation
1921 @section Compiling for Debugging
1922
1923 In order to debug a program effectively, you need to generate
1924 debugging information when you compile it. This debugging information
1925 is stored in the object file; it describes the data type of each
1926 variable or function and the correspondence between source line numbers
1927 and addresses in the executable code.
1928
1929 To request debugging information, specify the @samp{-g} option when you run
1930 the compiler.
1931
1932 Programs that are to be shipped to your customers are compiled with
1933 optimizations, using the @samp{-O} compiler option. However, some
1934 compilers are unable to handle the @samp{-g} and @samp{-O} options
1935 together. Using those compilers, you cannot generate optimized
1936 executables containing debugging information.
1937
1938 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1939 without @samp{-O}, making it possible to debug optimized code. We
1940 recommend that you @emph{always} use @samp{-g} whenever you compile a
1941 program. You may think your program is correct, but there is no sense
1942 in pushing your luck. For more information, see @ref{Optimized Code}.
1943
1944 Older versions of the @sc{gnu} C compiler permitted a variant option
1945 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1946 format; if your @sc{gnu} C compiler has this option, do not use it.
1947
1948 @value{GDBN} knows about preprocessor macros and can show you their
1949 expansion (@pxref{Macros}). Most compilers do not include information
1950 about preprocessor macros in the debugging information if you specify
1951 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
1952 the @sc{gnu} C compiler, provides macro information if you are using
1953 the DWARF debugging format, and specify the option @option{-g3}.
1954
1955 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
1956 gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}, for more
1957 information on @value{NGCC} options affecting debug information.
1958
1959 You will have the best debugging experience if you use the latest
1960 version of the DWARF debugging format that your compiler supports.
1961 DWARF is currently the most expressive and best supported debugging
1962 format in @value{GDBN}.
1963
1964 @need 2000
1965 @node Starting
1966 @section Starting your Program
1967 @cindex starting
1968 @cindex running
1969
1970 @table @code
1971 @kindex run
1972 @kindex r @r{(@code{run})}
1973 @item run
1974 @itemx r
1975 Use the @code{run} command to start your program under @value{GDBN}.
1976 You must first specify the program name (except on VxWorks) with an
1977 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1978 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1979 (@pxref{Files, ,Commands to Specify Files}).
1980
1981 @end table
1982
1983 If you are running your program in an execution environment that
1984 supports processes, @code{run} creates an inferior process and makes
1985 that process run your program. In some environments without processes,
1986 @code{run} jumps to the start of your program. Other targets,
1987 like @samp{remote}, are always running. If you get an error
1988 message like this one:
1989
1990 @smallexample
1991 The "remote" target does not support "run".
1992 Try "help target" or "continue".
1993 @end smallexample
1994
1995 @noindent
1996 then use @code{continue} to run your program. You may need @code{load}
1997 first (@pxref{load}).
1998
1999 The execution of a program is affected by certain information it
2000 receives from its superior. @value{GDBN} provides ways to specify this
2001 information, which you must do @emph{before} starting your program. (You
2002 can change it after starting your program, but such changes only affect
2003 your program the next time you start it.) This information may be
2004 divided into four categories:
2005
2006 @table @asis
2007 @item The @emph{arguments.}
2008 Specify the arguments to give your program as the arguments of the
2009 @code{run} command. If a shell is available on your target, the shell
2010 is used to pass the arguments, so that you may use normal conventions
2011 (such as wildcard expansion or variable substitution) in describing
2012 the arguments.
2013 In Unix systems, you can control which shell is used with the
2014 @code{SHELL} environment variable.
2015 @xref{Arguments, ,Your Program's Arguments}.
2016
2017 @item The @emph{environment.}
2018 Your program normally inherits its environment from @value{GDBN}, but you can
2019 use the @value{GDBN} commands @code{set environment} and @code{unset
2020 environment} to change parts of the environment that affect
2021 your program. @xref{Environment, ,Your Program's Environment}.
2022
2023 @item The @emph{working directory.}
2024 Your program inherits its working directory from @value{GDBN}. You can set
2025 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
2026 @xref{Working Directory, ,Your Program's Working Directory}.
2027
2028 @item The @emph{standard input and output.}
2029 Your program normally uses the same device for standard input and
2030 standard output as @value{GDBN} is using. You can redirect input and output
2031 in the @code{run} command line, or you can use the @code{tty} command to
2032 set a different device for your program.
2033 @xref{Input/Output, ,Your Program's Input and Output}.
2034
2035 @cindex pipes
2036 @emph{Warning:} While input and output redirection work, you cannot use
2037 pipes to pass the output of the program you are debugging to another
2038 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2039 wrong program.
2040 @end table
2041
2042 When you issue the @code{run} command, your program begins to execute
2043 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2044 of how to arrange for your program to stop. Once your program has
2045 stopped, you may call functions in your program, using the @code{print}
2046 or @code{call} commands. @xref{Data, ,Examining Data}.
2047
2048 If the modification time of your symbol file has changed since the last
2049 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2050 table, and reads it again. When it does this, @value{GDBN} tries to retain
2051 your current breakpoints.
2052
2053 @table @code
2054 @kindex start
2055 @item start
2056 @cindex run to main procedure
2057 The name of the main procedure can vary from language to language.
2058 With C or C@t{++}, the main procedure name is always @code{main}, but
2059 other languages such as Ada do not require a specific name for their
2060 main procedure. The debugger provides a convenient way to start the
2061 execution of the program and to stop at the beginning of the main
2062 procedure, depending on the language used.
2063
2064 The @samp{start} command does the equivalent of setting a temporary
2065 breakpoint at the beginning of the main procedure and then invoking
2066 the @samp{run} command.
2067
2068 @cindex elaboration phase
2069 Some programs contain an @dfn{elaboration} phase where some startup code is
2070 executed before the main procedure is called. This depends on the
2071 languages used to write your program. In C@t{++}, for instance,
2072 constructors for static and global objects are executed before
2073 @code{main} is called. It is therefore possible that the debugger stops
2074 before reaching the main procedure. However, the temporary breakpoint
2075 will remain to halt execution.
2076
2077 Specify the arguments to give to your program as arguments to the
2078 @samp{start} command. These arguments will be given verbatim to the
2079 underlying @samp{run} command. Note that the same arguments will be
2080 reused if no argument is provided during subsequent calls to
2081 @samp{start} or @samp{run}.
2082
2083 It is sometimes necessary to debug the program during elaboration. In
2084 these cases, using the @code{start} command would stop the execution of
2085 your program too late, as the program would have already completed the
2086 elaboration phase. Under these circumstances, insert breakpoints in your
2087 elaboration code before running your program.
2088
2089 @kindex set exec-wrapper
2090 @item set exec-wrapper @var{wrapper}
2091 @itemx show exec-wrapper
2092 @itemx unset exec-wrapper
2093 When @samp{exec-wrapper} is set, the specified wrapper is used to
2094 launch programs for debugging. @value{GDBN} starts your program
2095 with a shell command of the form @kbd{exec @var{wrapper}
2096 @var{program}}. Quoting is added to @var{program} and its
2097 arguments, but not to @var{wrapper}, so you should add quotes if
2098 appropriate for your shell. The wrapper runs until it executes
2099 your program, and then @value{GDBN} takes control.
2100
2101 You can use any program that eventually calls @code{execve} with
2102 its arguments as a wrapper. Several standard Unix utilities do
2103 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2104 with @code{exec "$@@"} will also work.
2105
2106 For example, you can use @code{env} to pass an environment variable to
2107 the debugged program, without setting the variable in your shell's
2108 environment:
2109
2110 @smallexample
2111 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2112 (@value{GDBP}) run
2113 @end smallexample
2114
2115 This command is available when debugging locally on most targets, excluding
2116 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2117
2118 @kindex set disable-randomization
2119 @item set disable-randomization
2120 @itemx set disable-randomization on
2121 This option (enabled by default in @value{GDBN}) will turn off the native
2122 randomization of the virtual address space of the started program. This option
2123 is useful for multiple debugging sessions to make the execution better
2124 reproducible and memory addresses reusable across debugging sessions.
2125
2126 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2127 On @sc{gnu}/Linux you can get the same behavior using
2128
2129 @smallexample
2130 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2131 @end smallexample
2132
2133 @item set disable-randomization off
2134 Leave the behavior of the started executable unchanged. Some bugs rear their
2135 ugly heads only when the program is loaded at certain addresses. If your bug
2136 disappears when you run the program under @value{GDBN}, that might be because
2137 @value{GDBN} by default disables the address randomization on platforms, such
2138 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2139 disable-randomization off} to try to reproduce such elusive bugs.
2140
2141 On targets where it is available, virtual address space randomization
2142 protects the programs against certain kinds of security attacks. In these
2143 cases the attacker needs to know the exact location of a concrete executable
2144 code. Randomizing its location makes it impossible to inject jumps misusing
2145 a code at its expected addresses.
2146
2147 Prelinking shared libraries provides a startup performance advantage but it
2148 makes addresses in these libraries predictable for privileged processes by
2149 having just unprivileged access at the target system. Reading the shared
2150 library binary gives enough information for assembling the malicious code
2151 misusing it. Still even a prelinked shared library can get loaded at a new
2152 random address just requiring the regular relocation process during the
2153 startup. Shared libraries not already prelinked are always loaded at
2154 a randomly chosen address.
2155
2156 Position independent executables (PIE) contain position independent code
2157 similar to the shared libraries and therefore such executables get loaded at
2158 a randomly chosen address upon startup. PIE executables always load even
2159 already prelinked shared libraries at a random address. You can build such
2160 executable using @command{gcc -fPIE -pie}.
2161
2162 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2163 (as long as the randomization is enabled).
2164
2165 @item show disable-randomization
2166 Show the current setting of the explicit disable of the native randomization of
2167 the virtual address space of the started program.
2168
2169 @end table
2170
2171 @node Arguments
2172 @section Your Program's Arguments
2173
2174 @cindex arguments (to your program)
2175 The arguments to your program can be specified by the arguments of the
2176 @code{run} command.
2177 They are passed to a shell, which expands wildcard characters and
2178 performs redirection of I/O, and thence to your program. Your
2179 @code{SHELL} environment variable (if it exists) specifies what shell
2180 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2181 the default shell (@file{/bin/sh} on Unix).
2182
2183 On non-Unix systems, the program is usually invoked directly by
2184 @value{GDBN}, which emulates I/O redirection via the appropriate system
2185 calls, and the wildcard characters are expanded by the startup code of
2186 the program, not by the shell.
2187
2188 @code{run} with no arguments uses the same arguments used by the previous
2189 @code{run}, or those set by the @code{set args} command.
2190
2191 @table @code
2192 @kindex set args
2193 @item set args
2194 Specify the arguments to be used the next time your program is run. If
2195 @code{set args} has no arguments, @code{run} executes your program
2196 with no arguments. Once you have run your program with arguments,
2197 using @code{set args} before the next @code{run} is the only way to run
2198 it again without arguments.
2199
2200 @kindex show args
2201 @item show args
2202 Show the arguments to give your program when it is started.
2203 @end table
2204
2205 @node Environment
2206 @section Your Program's Environment
2207
2208 @cindex environment (of your program)
2209 The @dfn{environment} consists of a set of environment variables and
2210 their values. Environment variables conventionally record such things as
2211 your user name, your home directory, your terminal type, and your search
2212 path for programs to run. Usually you set up environment variables with
2213 the shell and they are inherited by all the other programs you run. When
2214 debugging, it can be useful to try running your program with a modified
2215 environment without having to start @value{GDBN} over again.
2216
2217 @table @code
2218 @kindex path
2219 @item path @var{directory}
2220 Add @var{directory} to the front of the @code{PATH} environment variable
2221 (the search path for executables) that will be passed to your program.
2222 The value of @code{PATH} used by @value{GDBN} does not change.
2223 You may specify several directory names, separated by whitespace or by a
2224 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2225 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2226 is moved to the front, so it is searched sooner.
2227
2228 You can use the string @samp{$cwd} to refer to whatever is the current
2229 working directory at the time @value{GDBN} searches the path. If you
2230 use @samp{.} instead, it refers to the directory where you executed the
2231 @code{path} command. @value{GDBN} replaces @samp{.} in the
2232 @var{directory} argument (with the current path) before adding
2233 @var{directory} to the search path.
2234 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2235 @c document that, since repeating it would be a no-op.
2236
2237 @kindex show paths
2238 @item show paths
2239 Display the list of search paths for executables (the @code{PATH}
2240 environment variable).
2241
2242 @kindex show environment
2243 @item show environment @r{[}@var{varname}@r{]}
2244 Print the value of environment variable @var{varname} to be given to
2245 your program when it starts. If you do not supply @var{varname},
2246 print the names and values of all environment variables to be given to
2247 your program. You can abbreviate @code{environment} as @code{env}.
2248
2249 @kindex set environment
2250 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2251 Set environment variable @var{varname} to @var{value}. The value
2252 changes for your program only, not for @value{GDBN} itself. @var{value} may
2253 be any string; the values of environment variables are just strings, and
2254 any interpretation is supplied by your program itself. The @var{value}
2255 parameter is optional; if it is eliminated, the variable is set to a
2256 null value.
2257 @c "any string" here does not include leading, trailing
2258 @c blanks. Gnu asks: does anyone care?
2259
2260 For example, this command:
2261
2262 @smallexample
2263 set env USER = foo
2264 @end smallexample
2265
2266 @noindent
2267 tells the debugged program, when subsequently run, that its user is named
2268 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2269 are not actually required.)
2270
2271 @kindex unset environment
2272 @item unset environment @var{varname}
2273 Remove variable @var{varname} from the environment to be passed to your
2274 program. This is different from @samp{set env @var{varname} =};
2275 @code{unset environment} removes the variable from the environment,
2276 rather than assigning it an empty value.
2277 @end table
2278
2279 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2280 the shell indicated
2281 by your @code{SHELL} environment variable if it exists (or
2282 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2283 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2284 @file{.bashrc} for BASH---any variables you set in that file affect
2285 your program. You may wish to move setting of environment variables to
2286 files that are only run when you sign on, such as @file{.login} or
2287 @file{.profile}.
2288
2289 @node Working Directory
2290 @section Your Program's Working Directory
2291
2292 @cindex working directory (of your program)
2293 Each time you start your program with @code{run}, it inherits its
2294 working directory from the current working directory of @value{GDBN}.
2295 The @value{GDBN} working directory is initially whatever it inherited
2296 from its parent process (typically the shell), but you can specify a new
2297 working directory in @value{GDBN} with the @code{cd} command.
2298
2299 The @value{GDBN} working directory also serves as a default for the commands
2300 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2301 Specify Files}.
2302
2303 @table @code
2304 @kindex cd
2305 @cindex change working directory
2306 @item cd @r{[}@var{directory}@r{]}
2307 Set the @value{GDBN} working directory to @var{directory}. If not
2308 given, @var{directory} uses @file{'~'}.
2309
2310 @kindex pwd
2311 @item pwd
2312 Print the @value{GDBN} working directory.
2313 @end table
2314
2315 It is generally impossible to find the current working directory of
2316 the process being debugged (since a program can change its directory
2317 during its run). If you work on a system where @value{GDBN} is
2318 configured with the @file{/proc} support, you can use the @code{info
2319 proc} command (@pxref{SVR4 Process Information}) to find out the
2320 current working directory of the debuggee.
2321
2322 @node Input/Output
2323 @section Your Program's Input and Output
2324
2325 @cindex redirection
2326 @cindex i/o
2327 @cindex terminal
2328 By default, the program you run under @value{GDBN} does input and output to
2329 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2330 to its own terminal modes to interact with you, but it records the terminal
2331 modes your program was using and switches back to them when you continue
2332 running your program.
2333
2334 @table @code
2335 @kindex info terminal
2336 @item info terminal
2337 Displays information recorded by @value{GDBN} about the terminal modes your
2338 program is using.
2339 @end table
2340
2341 You can redirect your program's input and/or output using shell
2342 redirection with the @code{run} command. For example,
2343
2344 @smallexample
2345 run > outfile
2346 @end smallexample
2347
2348 @noindent
2349 starts your program, diverting its output to the file @file{outfile}.
2350
2351 @kindex tty
2352 @cindex controlling terminal
2353 Another way to specify where your program should do input and output is
2354 with the @code{tty} command. This command accepts a file name as
2355 argument, and causes this file to be the default for future @code{run}
2356 commands. It also resets the controlling terminal for the child
2357 process, for future @code{run} commands. For example,
2358
2359 @smallexample
2360 tty /dev/ttyb
2361 @end smallexample
2362
2363 @noindent
2364 directs that processes started with subsequent @code{run} commands
2365 default to do input and output on the terminal @file{/dev/ttyb} and have
2366 that as their controlling terminal.
2367
2368 An explicit redirection in @code{run} overrides the @code{tty} command's
2369 effect on the input/output device, but not its effect on the controlling
2370 terminal.
2371
2372 When you use the @code{tty} command or redirect input in the @code{run}
2373 command, only the input @emph{for your program} is affected. The input
2374 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2375 for @code{set inferior-tty}.
2376
2377 @cindex inferior tty
2378 @cindex set inferior controlling terminal
2379 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2380 display the name of the terminal that will be used for future runs of your
2381 program.
2382
2383 @table @code
2384 @item set inferior-tty /dev/ttyb
2385 @kindex set inferior-tty
2386 Set the tty for the program being debugged to /dev/ttyb.
2387
2388 @item show inferior-tty
2389 @kindex show inferior-tty
2390 Show the current tty for the program being debugged.
2391 @end table
2392
2393 @node Attach
2394 @section Debugging an Already-running Process
2395 @kindex attach
2396 @cindex attach
2397
2398 @table @code
2399 @item attach @var{process-id}
2400 This command attaches to a running process---one that was started
2401 outside @value{GDBN}. (@code{info files} shows your active
2402 targets.) The command takes as argument a process ID. The usual way to
2403 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2404 or with the @samp{jobs -l} shell command.
2405
2406 @code{attach} does not repeat if you press @key{RET} a second time after
2407 executing the command.
2408 @end table
2409
2410 To use @code{attach}, your program must be running in an environment
2411 which supports processes; for example, @code{attach} does not work for
2412 programs on bare-board targets that lack an operating system. You must
2413 also have permission to send the process a signal.
2414
2415 When you use @code{attach}, the debugger finds the program running in
2416 the process first by looking in the current working directory, then (if
2417 the program is not found) by using the source file search path
2418 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2419 the @code{file} command to load the program. @xref{Files, ,Commands to
2420 Specify Files}.
2421
2422 The first thing @value{GDBN} does after arranging to debug the specified
2423 process is to stop it. You can examine and modify an attached process
2424 with all the @value{GDBN} commands that are ordinarily available when
2425 you start processes with @code{run}. You can insert breakpoints; you
2426 can step and continue; you can modify storage. If you would rather the
2427 process continue running, you may use the @code{continue} command after
2428 attaching @value{GDBN} to the process.
2429
2430 @table @code
2431 @kindex detach
2432 @item detach
2433 When you have finished debugging the attached process, you can use the
2434 @code{detach} command to release it from @value{GDBN} control. Detaching
2435 the process continues its execution. After the @code{detach} command,
2436 that process and @value{GDBN} become completely independent once more, and you
2437 are ready to @code{attach} another process or start one with @code{run}.
2438 @code{detach} does not repeat if you press @key{RET} again after
2439 executing the command.
2440 @end table
2441
2442 If you exit @value{GDBN} while you have an attached process, you detach
2443 that process. If you use the @code{run} command, you kill that process.
2444 By default, @value{GDBN} asks for confirmation if you try to do either of these
2445 things; you can control whether or not you need to confirm by using the
2446 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2447 Messages}).
2448
2449 @node Kill Process
2450 @section Killing the Child Process
2451
2452 @table @code
2453 @kindex kill
2454 @item kill
2455 Kill the child process in which your program is running under @value{GDBN}.
2456 @end table
2457
2458 This command is useful if you wish to debug a core dump instead of a
2459 running process. @value{GDBN} ignores any core dump file while your program
2460 is running.
2461
2462 On some operating systems, a program cannot be executed outside @value{GDBN}
2463 while you have breakpoints set on it inside @value{GDBN}. You can use the
2464 @code{kill} command in this situation to permit running your program
2465 outside the debugger.
2466
2467 The @code{kill} command is also useful if you wish to recompile and
2468 relink your program, since on many systems it is impossible to modify an
2469 executable file while it is running in a process. In this case, when you
2470 next type @code{run}, @value{GDBN} notices that the file has changed, and
2471 reads the symbol table again (while trying to preserve your current
2472 breakpoint settings).
2473
2474 @node Inferiors and Programs
2475 @section Debugging Multiple Inferiors and Programs
2476
2477 @value{GDBN} lets you run and debug multiple programs in a single
2478 session. In addition, @value{GDBN} on some systems may let you run
2479 several programs simultaneously (otherwise you have to exit from one
2480 before starting another). In the most general case, you can have
2481 multiple threads of execution in each of multiple processes, launched
2482 from multiple executables.
2483
2484 @cindex inferior
2485 @value{GDBN} represents the state of each program execution with an
2486 object called an @dfn{inferior}. An inferior typically corresponds to
2487 a process, but is more general and applies also to targets that do not
2488 have processes. Inferiors may be created before a process runs, and
2489 may be retained after a process exits. Inferiors have unique
2490 identifiers that are different from process ids. Usually each
2491 inferior will also have its own distinct address space, although some
2492 embedded targets may have several inferiors running in different parts
2493 of a single address space. Each inferior may in turn have multiple
2494 threads running in it.
2495
2496 To find out what inferiors exist at any moment, use @w{@code{info
2497 inferiors}}:
2498
2499 @table @code
2500 @kindex info inferiors
2501 @item info inferiors
2502 Print a list of all inferiors currently being managed by @value{GDBN}.
2503
2504 @value{GDBN} displays for each inferior (in this order):
2505
2506 @enumerate
2507 @item
2508 the inferior number assigned by @value{GDBN}
2509
2510 @item
2511 the target system's inferior identifier
2512
2513 @item
2514 the name of the executable the inferior is running.
2515
2516 @end enumerate
2517
2518 @noindent
2519 An asterisk @samp{*} preceding the @value{GDBN} inferior number
2520 indicates the current inferior.
2521
2522 For example,
2523 @end table
2524 @c end table here to get a little more width for example
2525
2526 @smallexample
2527 (@value{GDBP}) info inferiors
2528 Num Description Executable
2529 2 process 2307 hello
2530 * 1 process 3401 goodbye
2531 @end smallexample
2532
2533 To switch focus between inferiors, use the @code{inferior} command:
2534
2535 @table @code
2536 @kindex inferior @var{infno}
2537 @item inferior @var{infno}
2538 Make inferior number @var{infno} the current inferior. The argument
2539 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
2540 in the first field of the @samp{info inferiors} display.
2541 @end table
2542
2543
2544 You can get multiple executables into a debugging session via the
2545 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2546 systems @value{GDBN} can add inferiors to the debug session
2547 automatically by following calls to @code{fork} and @code{exec}. To
2548 remove inferiors from the debugging session use the
2549 @w{@code{remove-inferiors}} command.
2550
2551 @table @code
2552 @kindex add-inferior
2553 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2554 Adds @var{n} inferiors to be run using @var{executable} as the
2555 executable. @var{n} defaults to 1. If no executable is specified,
2556 the inferiors begins empty, with no program. You can still assign or
2557 change the program assigned to the inferior at any time by using the
2558 @code{file} command with the executable name as its argument.
2559
2560 @kindex clone-inferior
2561 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2562 Adds @var{n} inferiors ready to execute the same program as inferior
2563 @var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2564 number of the current inferior. This is a convenient command when you
2565 want to run another instance of the inferior you are debugging.
2566
2567 @smallexample
2568 (@value{GDBP}) info inferiors
2569 Num Description Executable
2570 * 1 process 29964 helloworld
2571 (@value{GDBP}) clone-inferior
2572 Added inferior 2.
2573 1 inferiors added.
2574 (@value{GDBP}) info inferiors
2575 Num Description Executable
2576 2 <null> helloworld
2577 * 1 process 29964 helloworld
2578 @end smallexample
2579
2580 You can now simply switch focus to inferior 2 and run it.
2581
2582 @kindex remove-inferiors
2583 @item remove-inferiors @var{infno}@dots{}
2584 Removes the inferior or inferiors @var{infno}@dots{}. It is not
2585 possible to remove an inferior that is running with this command. For
2586 those, use the @code{kill} or @code{detach} command first.
2587
2588 @end table
2589
2590 To quit debugging one of the running inferiors that is not the current
2591 inferior, you can either detach from it by using the @w{@code{detach
2592 inferior}} command (allowing it to run independently), or kill it
2593 using the @w{@code{kill inferiors}} command:
2594
2595 @table @code
2596 @kindex detach inferiors @var{infno}@dots{}
2597 @item detach inferior @var{infno}@dots{}
2598 Detach from the inferior or inferiors identified by @value{GDBN}
2599 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
2600 still stays on the list of inferiors shown by @code{info inferiors},
2601 but its Description will show @samp{<null>}.
2602
2603 @kindex kill inferiors @var{infno}@dots{}
2604 @item kill inferiors @var{infno}@dots{}
2605 Kill the inferior or inferiors identified by @value{GDBN} inferior
2606 number(s) @var{infno}@dots{}. Note that the inferior's entry still
2607 stays on the list of inferiors shown by @code{info inferiors}, but its
2608 Description will show @samp{<null>}.
2609 @end table
2610
2611 After the successful completion of a command such as @code{detach},
2612 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
2613 a normal process exit, the inferior is still valid and listed with
2614 @code{info inferiors}, ready to be restarted.
2615
2616
2617 To be notified when inferiors are started or exit under @value{GDBN}'s
2618 control use @w{@code{set print inferior-events}}:
2619
2620 @table @code
2621 @kindex set print inferior-events
2622 @cindex print messages on inferior start and exit
2623 @item set print inferior-events
2624 @itemx set print inferior-events on
2625 @itemx set print inferior-events off
2626 The @code{set print inferior-events} command allows you to enable or
2627 disable printing of messages when @value{GDBN} notices that new
2628 inferiors have started or that inferiors have exited or have been
2629 detached. By default, these messages will not be printed.
2630
2631 @kindex show print inferior-events
2632 @item show print inferior-events
2633 Show whether messages will be printed when @value{GDBN} detects that
2634 inferiors have started, exited or have been detached.
2635 @end table
2636
2637 Many commands will work the same with multiple programs as with a
2638 single program: e.g., @code{print myglobal} will simply display the
2639 value of @code{myglobal} in the current inferior.
2640
2641
2642 Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2643 get more info about the relationship of inferiors, programs, address
2644 spaces in a debug session. You can do that with the @w{@code{maint
2645 info program-spaces}} command.
2646
2647 @table @code
2648 @kindex maint info program-spaces
2649 @item maint info program-spaces
2650 Print a list of all program spaces currently being managed by
2651 @value{GDBN}.
2652
2653 @value{GDBN} displays for each program space (in this order):
2654
2655 @enumerate
2656 @item
2657 the program space number assigned by @value{GDBN}
2658
2659 @item
2660 the name of the executable loaded into the program space, with e.g.,
2661 the @code{file} command.
2662
2663 @end enumerate
2664
2665 @noindent
2666 An asterisk @samp{*} preceding the @value{GDBN} program space number
2667 indicates the current program space.
2668
2669 In addition, below each program space line, @value{GDBN} prints extra
2670 information that isn't suitable to display in tabular form. For
2671 example, the list of inferiors bound to the program space.
2672
2673 @smallexample
2674 (@value{GDBP}) maint info program-spaces
2675 Id Executable
2676 2 goodbye
2677 Bound inferiors: ID 1 (process 21561)
2678 * 1 hello
2679 @end smallexample
2680
2681 Here we can see that no inferior is running the program @code{hello},
2682 while @code{process 21561} is running the program @code{goodbye}. On
2683 some targets, it is possible that multiple inferiors are bound to the
2684 same program space. The most common example is that of debugging both
2685 the parent and child processes of a @code{vfork} call. For example,
2686
2687 @smallexample
2688 (@value{GDBP}) maint info program-spaces
2689 Id Executable
2690 * 1 vfork-test
2691 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2692 @end smallexample
2693
2694 Here, both inferior 2 and inferior 1 are running in the same program
2695 space as a result of inferior 1 having executed a @code{vfork} call.
2696 @end table
2697
2698 @node Threads
2699 @section Debugging Programs with Multiple Threads
2700
2701 @cindex threads of execution
2702 @cindex multiple threads
2703 @cindex switching threads
2704 In some operating systems, such as HP-UX and Solaris, a single program
2705 may have more than one @dfn{thread} of execution. The precise semantics
2706 of threads differ from one operating system to another, but in general
2707 the threads of a single program are akin to multiple processes---except
2708 that they share one address space (that is, they can all examine and
2709 modify the same variables). On the other hand, each thread has its own
2710 registers and execution stack, and perhaps private memory.
2711
2712 @value{GDBN} provides these facilities for debugging multi-thread
2713 programs:
2714
2715 @itemize @bullet
2716 @item automatic notification of new threads
2717 @item @samp{thread @var{threadno}}, a command to switch among threads
2718 @item @samp{info threads}, a command to inquire about existing threads
2719 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2720 a command to apply a command to a list of threads
2721 @item thread-specific breakpoints
2722 @item @samp{set print thread-events}, which controls printing of
2723 messages on thread start and exit.
2724 @item @samp{set libthread-db-search-path @var{path}}, which lets
2725 the user specify which @code{libthread_db} to use if the default choice
2726 isn't compatible with the program.
2727 @end itemize
2728
2729 @quotation
2730 @emph{Warning:} These facilities are not yet available on every
2731 @value{GDBN} configuration where the operating system supports threads.
2732 If your @value{GDBN} does not support threads, these commands have no
2733 effect. For example, a system without thread support shows no output
2734 from @samp{info threads}, and always rejects the @code{thread} command,
2735 like this:
2736
2737 @smallexample
2738 (@value{GDBP}) info threads
2739 (@value{GDBP}) thread 1
2740 Thread ID 1 not known. Use the "info threads" command to
2741 see the IDs of currently known threads.
2742 @end smallexample
2743 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2744 @c doesn't support threads"?
2745 @end quotation
2746
2747 @cindex focus of debugging
2748 @cindex current thread
2749 The @value{GDBN} thread debugging facility allows you to observe all
2750 threads while your program runs---but whenever @value{GDBN} takes
2751 control, one thread in particular is always the focus of debugging.
2752 This thread is called the @dfn{current thread}. Debugging commands show
2753 program information from the perspective of the current thread.
2754
2755 @cindex @code{New} @var{systag} message
2756 @cindex thread identifier (system)
2757 @c FIXME-implementors!! It would be more helpful if the [New...] message
2758 @c included GDB's numeric thread handle, so you could just go to that
2759 @c thread without first checking `info threads'.
2760 Whenever @value{GDBN} detects a new thread in your program, it displays
2761 the target system's identification for the thread with a message in the
2762 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2763 whose form varies depending on the particular system. For example, on
2764 @sc{gnu}/Linux, you might see
2765
2766 @smallexample
2767 [New Thread 0x41e02940 (LWP 25582)]
2768 @end smallexample
2769
2770 @noindent
2771 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2772 the @var{systag} is simply something like @samp{process 368}, with no
2773 further qualifier.
2774
2775 @c FIXME!! (1) Does the [New...] message appear even for the very first
2776 @c thread of a program, or does it only appear for the
2777 @c second---i.e.@: when it becomes obvious we have a multithread
2778 @c program?
2779 @c (2) *Is* there necessarily a first thread always? Or do some
2780 @c multithread systems permit starting a program with multiple
2781 @c threads ab initio?
2782
2783 @cindex thread number
2784 @cindex thread identifier (GDB)
2785 For debugging purposes, @value{GDBN} associates its own thread
2786 number---always a single integer---with each thread in your program.
2787
2788 @table @code
2789 @kindex info threads
2790 @item info threads @r{[}@var{id}@dots{}@r{]}
2791 Display a summary of all threads currently in your program. Optional
2792 argument @var{id}@dots{} is one or more thread ids separated by spaces, and
2793 means to print information only about the specified thread or threads.
2794 @value{GDBN} displays for each thread (in this order):
2795
2796 @enumerate
2797 @item
2798 the thread number assigned by @value{GDBN}
2799
2800 @item
2801 the target system's thread identifier (@var{systag})
2802
2803 @item
2804 the thread's name, if one is known. A thread can either be named by
2805 the user (see @code{thread name}, below), or, in some cases, by the
2806 program itself.
2807
2808 @item
2809 the current stack frame summary for that thread
2810 @end enumerate
2811
2812 @noindent
2813 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2814 indicates the current thread.
2815
2816 For example,
2817 @end table
2818 @c end table here to get a little more width for example
2819
2820 @smallexample
2821 (@value{GDBP}) info threads
2822 Id Target Id Frame
2823 3 process 35 thread 27 0x34e5 in sigpause ()
2824 2 process 35 thread 23 0x34e5 in sigpause ()
2825 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2826 at threadtest.c:68
2827 @end smallexample
2828
2829 On Solaris, you can display more information about user threads with a
2830 Solaris-specific command:
2831
2832 @table @code
2833 @item maint info sol-threads
2834 @kindex maint info sol-threads
2835 @cindex thread info (Solaris)
2836 Display info on Solaris user threads.
2837 @end table
2838
2839 @table @code
2840 @kindex thread @var{threadno}
2841 @item thread @var{threadno}
2842 Make thread number @var{threadno} the current thread. The command
2843 argument @var{threadno} is the internal @value{GDBN} thread number, as
2844 shown in the first field of the @samp{info threads} display.
2845 @value{GDBN} responds by displaying the system identifier of the thread
2846 you selected, and its current stack frame summary:
2847
2848 @smallexample
2849 (@value{GDBP}) thread 2
2850 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
2851 #0 some_function (ignore=0x0) at example.c:8
2852 8 printf ("hello\n");
2853 @end smallexample
2854
2855 @noindent
2856 As with the @samp{[New @dots{}]} message, the form of the text after
2857 @samp{Switching to} depends on your system's conventions for identifying
2858 threads.
2859
2860 @vindex $_thread@r{, convenience variable}
2861 The debugger convenience variable @samp{$_thread} contains the number
2862 of the current thread. You may find this useful in writing breakpoint
2863 conditional expressions, command scripts, and so forth. See
2864 @xref{Convenience Vars,, Convenience Variables}, for general
2865 information on convenience variables.
2866
2867 @kindex thread apply
2868 @cindex apply command to several threads
2869 @item thread apply [@var{threadno} | all] @var{command}
2870 The @code{thread apply} command allows you to apply the named
2871 @var{command} to one or more threads. Specify the numbers of the
2872 threads that you want affected with the command argument
2873 @var{threadno}. It can be a single thread number, one of the numbers
2874 shown in the first field of the @samp{info threads} display; or it
2875 could be a range of thread numbers, as in @code{2-4}. To apply a
2876 command to all threads, type @kbd{thread apply all @var{command}}.
2877
2878 @kindex thread name
2879 @cindex name a thread
2880 @item thread name [@var{name}]
2881 This command assigns a name to the current thread. If no argument is
2882 given, any existing user-specified name is removed. The thread name
2883 appears in the @samp{info threads} display.
2884
2885 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
2886 determine the name of the thread as given by the OS. On these
2887 systems, a name specified with @samp{thread name} will override the
2888 system-give name, and removing the user-specified name will cause
2889 @value{GDBN} to once again display the system-specified name.
2890
2891 @kindex thread find
2892 @cindex search for a thread
2893 @item thread find [@var{regexp}]
2894 Search for and display thread ids whose name or @var{systag}
2895 matches the supplied regular expression.
2896
2897 As well as being the complement to the @samp{thread name} command,
2898 this command also allows you to identify a thread by its target
2899 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
2900 is the LWP id.
2901
2902 @smallexample
2903 (@value{GDBN}) thread find 26688
2904 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
2905 (@value{GDBN}) info thread 4
2906 Id Target Id Frame
2907 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
2908 @end smallexample
2909
2910 @kindex set print thread-events
2911 @cindex print messages on thread start and exit
2912 @item set print thread-events
2913 @itemx set print thread-events on
2914 @itemx set print thread-events off
2915 The @code{set print thread-events} command allows you to enable or
2916 disable printing of messages when @value{GDBN} notices that new threads have
2917 started or that threads have exited. By default, these messages will
2918 be printed if detection of these events is supported by the target.
2919 Note that these messages cannot be disabled on all targets.
2920
2921 @kindex show print thread-events
2922 @item show print thread-events
2923 Show whether messages will be printed when @value{GDBN} detects that threads
2924 have started and exited.
2925 @end table
2926
2927 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2928 more information about how @value{GDBN} behaves when you stop and start
2929 programs with multiple threads.
2930
2931 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
2932 watchpoints in programs with multiple threads.
2933
2934 @anchor{set libthread-db-search-path}
2935 @table @code
2936 @kindex set libthread-db-search-path
2937 @cindex search path for @code{libthread_db}
2938 @item set libthread-db-search-path @r{[}@var{path}@r{]}
2939 If this variable is set, @var{path} is a colon-separated list of
2940 directories @value{GDBN} will use to search for @code{libthread_db}.
2941 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
2942 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
2943 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
2944 macro.
2945
2946 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2947 @code{libthread_db} library to obtain information about threads in the
2948 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
2949 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
2950 specific thread debugging library loading is enabled
2951 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
2952
2953 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
2954 refers to the default system directories that are
2955 normally searched for loading shared libraries. The @samp{$sdir} entry
2956 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
2957 (@pxref{libthread_db.so.1 file}).
2958
2959 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
2960 refers to the directory from which @code{libpthread}
2961 was loaded in the inferior process.
2962
2963 For any @code{libthread_db} library @value{GDBN} finds in above directories,
2964 @value{GDBN} attempts to initialize it with the current inferior process.
2965 If this initialization fails (which could happen because of a version
2966 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2967 will unload @code{libthread_db}, and continue with the next directory.
2968 If none of @code{libthread_db} libraries initialize successfully,
2969 @value{GDBN} will issue a warning and thread debugging will be disabled.
2970
2971 Setting @code{libthread-db-search-path} is currently implemented
2972 only on some platforms.
2973
2974 @kindex show libthread-db-search-path
2975 @item show libthread-db-search-path
2976 Display current libthread_db search path.
2977
2978 @kindex set debug libthread-db
2979 @kindex show debug libthread-db
2980 @cindex debugging @code{libthread_db}
2981 @item set debug libthread-db
2982 @itemx show debug libthread-db
2983 Turns on or off display of @code{libthread_db}-related events.
2984 Use @code{1} to enable, @code{0} to disable.
2985 @end table
2986
2987 @node Forks
2988 @section Debugging Forks
2989
2990 @cindex fork, debugging programs which call
2991 @cindex multiple processes
2992 @cindex processes, multiple
2993 On most systems, @value{GDBN} has no special support for debugging
2994 programs which create additional processes using the @code{fork}
2995 function. When a program forks, @value{GDBN} will continue to debug the
2996 parent process and the child process will run unimpeded. If you have
2997 set a breakpoint in any code which the child then executes, the child
2998 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2999 will cause it to terminate.
3000
3001 However, if you want to debug the child process there is a workaround
3002 which isn't too painful. Put a call to @code{sleep} in the code which
3003 the child process executes after the fork. It may be useful to sleep
3004 only if a certain environment variable is set, or a certain file exists,
3005 so that the delay need not occur when you don't want to run @value{GDBN}
3006 on the child. While the child is sleeping, use the @code{ps} program to
3007 get its process ID. Then tell @value{GDBN} (a new invocation of
3008 @value{GDBN} if you are also debugging the parent process) to attach to
3009 the child process (@pxref{Attach}). From that point on you can debug
3010 the child process just like any other process which you attached to.
3011
3012 On some systems, @value{GDBN} provides support for debugging programs that
3013 create additional processes using the @code{fork} or @code{vfork} functions.
3014 Currently, the only platforms with this feature are HP-UX (11.x and later
3015 only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
3016
3017 By default, when a program forks, @value{GDBN} will continue to debug
3018 the parent process and the child process will run unimpeded.
3019
3020 If you want to follow the child process instead of the parent process,
3021 use the command @w{@code{set follow-fork-mode}}.
3022
3023 @table @code
3024 @kindex set follow-fork-mode
3025 @item set follow-fork-mode @var{mode}
3026 Set the debugger response to a program call of @code{fork} or
3027 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3028 process. The @var{mode} argument can be:
3029
3030 @table @code
3031 @item parent
3032 The original process is debugged after a fork. The child process runs
3033 unimpeded. This is the default.
3034
3035 @item child
3036 The new process is debugged after a fork. The parent process runs
3037 unimpeded.
3038
3039 @end table
3040
3041 @kindex show follow-fork-mode
3042 @item show follow-fork-mode
3043 Display the current debugger response to a @code{fork} or @code{vfork} call.
3044 @end table
3045
3046 @cindex debugging multiple processes
3047 On Linux, if you want to debug both the parent and child processes, use the
3048 command @w{@code{set detach-on-fork}}.
3049
3050 @table @code
3051 @kindex set detach-on-fork
3052 @item set detach-on-fork @var{mode}
3053 Tells gdb whether to detach one of the processes after a fork, or
3054 retain debugger control over them both.
3055
3056 @table @code
3057 @item on
3058 The child process (or parent process, depending on the value of
3059 @code{follow-fork-mode}) will be detached and allowed to run
3060 independently. This is the default.
3061
3062 @item off
3063 Both processes will be held under the control of @value{GDBN}.
3064 One process (child or parent, depending on the value of
3065 @code{follow-fork-mode}) is debugged as usual, while the other
3066 is held suspended.
3067
3068 @end table
3069
3070 @kindex show detach-on-fork
3071 @item show detach-on-fork
3072 Show whether detach-on-fork mode is on/off.
3073 @end table
3074
3075 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3076 will retain control of all forked processes (including nested forks).
3077 You can list the forked processes under the control of @value{GDBN} by
3078 using the @w{@code{info inferiors}} command, and switch from one fork
3079 to another by using the @code{inferior} command (@pxref{Inferiors and
3080 Programs, ,Debugging Multiple Inferiors and Programs}).
3081
3082 To quit debugging one of the forked processes, you can either detach
3083 from it by using the @w{@code{detach inferiors}} command (allowing it
3084 to run independently), or kill it using the @w{@code{kill inferiors}}
3085 command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3086 and Programs}.
3087
3088 If you ask to debug a child process and a @code{vfork} is followed by an
3089 @code{exec}, @value{GDBN} executes the new target up to the first
3090 breakpoint in the new target. If you have a breakpoint set on
3091 @code{main} in your original program, the breakpoint will also be set on
3092 the child process's @code{main}.
3093
3094 On some systems, when a child process is spawned by @code{vfork}, you
3095 cannot debug the child or parent until an @code{exec} call completes.
3096
3097 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3098 call executes, the new target restarts. To restart the parent
3099 process, use the @code{file} command with the parent executable name
3100 as its argument. By default, after an @code{exec} call executes,
3101 @value{GDBN} discards the symbols of the previous executable image.
3102 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3103 command.
3104
3105 @table @code
3106 @kindex set follow-exec-mode
3107 @item set follow-exec-mode @var{mode}
3108
3109 Set debugger response to a program call of @code{exec}. An
3110 @code{exec} call replaces the program image of a process.
3111
3112 @code{follow-exec-mode} can be:
3113
3114 @table @code
3115 @item new
3116 @value{GDBN} creates a new inferior and rebinds the process to this
3117 new inferior. The program the process was running before the
3118 @code{exec} call can be restarted afterwards by restarting the
3119 original inferior.
3120
3121 For example:
3122
3123 @smallexample
3124 (@value{GDBP}) info inferiors
3125 (gdb) info inferior
3126 Id Description Executable
3127 * 1 <null> prog1
3128 (@value{GDBP}) run
3129 process 12020 is executing new program: prog2
3130 Program exited normally.
3131 (@value{GDBP}) info inferiors
3132 Id Description Executable
3133 * 2 <null> prog2
3134 1 <null> prog1
3135 @end smallexample
3136
3137 @item same
3138 @value{GDBN} keeps the process bound to the same inferior. The new
3139 executable image replaces the previous executable loaded in the
3140 inferior. Restarting the inferior after the @code{exec} call, with
3141 e.g., the @code{run} command, restarts the executable the process was
3142 running after the @code{exec} call. This is the default mode.
3143
3144 For example:
3145
3146 @smallexample
3147 (@value{GDBP}) info inferiors
3148 Id Description Executable
3149 * 1 <null> prog1
3150 (@value{GDBP}) run
3151 process 12020 is executing new program: prog2
3152 Program exited normally.
3153 (@value{GDBP}) info inferiors
3154 Id Description Executable
3155 * 1 <null> prog2
3156 @end smallexample
3157
3158 @end table
3159 @end table
3160
3161 You can use the @code{catch} command to make @value{GDBN} stop whenever
3162 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3163 Catchpoints, ,Setting Catchpoints}.
3164
3165 @node Checkpoint/Restart
3166 @section Setting a @emph{Bookmark} to Return to Later
3167
3168 @cindex checkpoint
3169 @cindex restart
3170 @cindex bookmark
3171 @cindex snapshot of a process
3172 @cindex rewind program state
3173
3174 On certain operating systems@footnote{Currently, only
3175 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3176 program's state, called a @dfn{checkpoint}, and come back to it
3177 later.
3178
3179 Returning to a checkpoint effectively undoes everything that has
3180 happened in the program since the @code{checkpoint} was saved. This
3181 includes changes in memory, registers, and even (within some limits)
3182 system state. Effectively, it is like going back in time to the
3183 moment when the checkpoint was saved.
3184
3185 Thus, if you're stepping thru a program and you think you're
3186 getting close to the point where things go wrong, you can save
3187 a checkpoint. Then, if you accidentally go too far and miss
3188 the critical statement, instead of having to restart your program
3189 from the beginning, you can just go back to the checkpoint and
3190 start again from there.
3191
3192 This can be especially useful if it takes a lot of time or
3193 steps to reach the point where you think the bug occurs.
3194
3195 To use the @code{checkpoint}/@code{restart} method of debugging:
3196
3197 @table @code
3198 @kindex checkpoint
3199 @item checkpoint
3200 Save a snapshot of the debugged program's current execution state.
3201 The @code{checkpoint} command takes no arguments, but each checkpoint
3202 is assigned a small integer id, similar to a breakpoint id.
3203
3204 @kindex info checkpoints
3205 @item info checkpoints
3206 List the checkpoints that have been saved in the current debugging
3207 session. For each checkpoint, the following information will be
3208 listed:
3209
3210 @table @code
3211 @item Checkpoint ID
3212 @item Process ID
3213 @item Code Address
3214 @item Source line, or label
3215 @end table
3216
3217 @kindex restart @var{checkpoint-id}
3218 @item restart @var{checkpoint-id}
3219 Restore the program state that was saved as checkpoint number
3220 @var{checkpoint-id}. All program variables, registers, stack frames
3221 etc.@: will be returned to the values that they had when the checkpoint
3222 was saved. In essence, gdb will ``wind back the clock'' to the point
3223 in time when the checkpoint was saved.
3224
3225 Note that breakpoints, @value{GDBN} variables, command history etc.
3226 are not affected by restoring a checkpoint. In general, a checkpoint
3227 only restores things that reside in the program being debugged, not in
3228 the debugger.
3229
3230 @kindex delete checkpoint @var{checkpoint-id}
3231 @item delete checkpoint @var{checkpoint-id}
3232 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3233
3234 @end table
3235
3236 Returning to a previously saved checkpoint will restore the user state
3237 of the program being debugged, plus a significant subset of the system
3238 (OS) state, including file pointers. It won't ``un-write'' data from
3239 a file, but it will rewind the file pointer to the previous location,
3240 so that the previously written data can be overwritten. For files
3241 opened in read mode, the pointer will also be restored so that the
3242 previously read data can be read again.
3243
3244 Of course, characters that have been sent to a printer (or other
3245 external device) cannot be ``snatched back'', and characters received
3246 from eg.@: a serial device can be removed from internal program buffers,
3247 but they cannot be ``pushed back'' into the serial pipeline, ready to
3248 be received again. Similarly, the actual contents of files that have
3249 been changed cannot be restored (at this time).
3250
3251 However, within those constraints, you actually can ``rewind'' your
3252 program to a previously saved point in time, and begin debugging it
3253 again --- and you can change the course of events so as to debug a
3254 different execution path this time.
3255
3256 @cindex checkpoints and process id
3257 Finally, there is one bit of internal program state that will be
3258 different when you return to a checkpoint --- the program's process
3259 id. Each checkpoint will have a unique process id (or @var{pid}),
3260 and each will be different from the program's original @var{pid}.
3261 If your program has saved a local copy of its process id, this could
3262 potentially pose a problem.
3263
3264 @subsection A Non-obvious Benefit of Using Checkpoints
3265
3266 On some systems such as @sc{gnu}/Linux, address space randomization
3267 is performed on new processes for security reasons. This makes it
3268 difficult or impossible to set a breakpoint, or watchpoint, on an
3269 absolute address if you have to restart the program, since the
3270 absolute location of a symbol will change from one execution to the
3271 next.
3272
3273 A checkpoint, however, is an @emph{identical} copy of a process.
3274 Therefore if you create a checkpoint at (eg.@:) the start of main,
3275 and simply return to that checkpoint instead of restarting the
3276 process, you can avoid the effects of address randomization and
3277 your symbols will all stay in the same place.
3278
3279 @node Stopping
3280 @chapter Stopping and Continuing
3281
3282 The principal purposes of using a debugger are so that you can stop your
3283 program before it terminates; or so that, if your program runs into
3284 trouble, you can investigate and find out why.
3285
3286 Inside @value{GDBN}, your program may stop for any of several reasons,
3287 such as a signal, a breakpoint, or reaching a new line after a
3288 @value{GDBN} command such as @code{step}. You may then examine and
3289 change variables, set new breakpoints or remove old ones, and then
3290 continue execution. Usually, the messages shown by @value{GDBN} provide
3291 ample explanation of the status of your program---but you can also
3292 explicitly request this information at any time.
3293
3294 @table @code
3295 @kindex info program
3296 @item info program
3297 Display information about the status of your program: whether it is
3298 running or not, what process it is, and why it stopped.
3299 @end table
3300
3301 @menu
3302 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
3303 * Continuing and Stepping:: Resuming execution
3304 * Skipping Over Functions and Files::
3305 Skipping over functions and files
3306 * Signals:: Signals
3307 * Thread Stops:: Stopping and starting multi-thread programs
3308 @end menu
3309
3310 @node Breakpoints
3311 @section Breakpoints, Watchpoints, and Catchpoints
3312
3313 @cindex breakpoints
3314 A @dfn{breakpoint} makes your program stop whenever a certain point in
3315 the program is reached. For each breakpoint, you can add conditions to
3316 control in finer detail whether your program stops. You can set
3317 breakpoints with the @code{break} command and its variants (@pxref{Set
3318 Breaks, ,Setting Breakpoints}), to specify the place where your program
3319 should stop by line number, function name or exact address in the
3320 program.
3321
3322 On some systems, you can set breakpoints in shared libraries before
3323 the executable is run. There is a minor limitation on HP-UX systems:
3324 you must wait until the executable is run in order to set breakpoints
3325 in shared library routines that are not called directly by the program
3326 (for example, routines that are arguments in a @code{pthread_create}
3327 call).
3328
3329 @cindex watchpoints
3330 @cindex data breakpoints
3331 @cindex memory tracing
3332 @cindex breakpoint on memory address
3333 @cindex breakpoint on variable modification
3334 A @dfn{watchpoint} is a special breakpoint that stops your program
3335 when the value of an expression changes. The expression may be a value
3336 of a variable, or it could involve values of one or more variables
3337 combined by operators, such as @samp{a + b}. This is sometimes called
3338 @dfn{data breakpoints}. You must use a different command to set
3339 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
3340 from that, you can manage a watchpoint like any other breakpoint: you
3341 enable, disable, and delete both breakpoints and watchpoints using the
3342 same commands.
3343
3344 You can arrange to have values from your program displayed automatically
3345 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
3346 Automatic Display}.
3347
3348 @cindex catchpoints
3349 @cindex breakpoint on events
3350 A @dfn{catchpoint} is another special breakpoint that stops your program
3351 when a certain kind of event occurs, such as the throwing of a C@t{++}
3352 exception or the loading of a library. As with watchpoints, you use a
3353 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
3354 Catchpoints}), but aside from that, you can manage a catchpoint like any
3355 other breakpoint. (To stop when your program receives a signal, use the
3356 @code{handle} command; see @ref{Signals, ,Signals}.)
3357
3358 @cindex breakpoint numbers
3359 @cindex numbers for breakpoints
3360 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
3361 catchpoint when you create it; these numbers are successive integers
3362 starting with one. In many of the commands for controlling various
3363 features of breakpoints you use the breakpoint number to say which
3364 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3365 @dfn{disabled}; if disabled, it has no effect on your program until you
3366 enable it again.
3367
3368 @cindex breakpoint ranges
3369 @cindex ranges of breakpoints
3370 Some @value{GDBN} commands accept a range of breakpoints on which to
3371 operate. A breakpoint range is either a single breakpoint number, like
3372 @samp{5}, or two such numbers, in increasing order, separated by a
3373 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
3374 all breakpoints in that range are operated on.
3375
3376 @menu
3377 * Set Breaks:: Setting breakpoints
3378 * Set Watchpoints:: Setting watchpoints
3379 * Set Catchpoints:: Setting catchpoints
3380 * Delete Breaks:: Deleting breakpoints
3381 * Disabling:: Disabling breakpoints
3382 * Conditions:: Break conditions
3383 * Break Commands:: Breakpoint command lists
3384 * Dynamic Printf:: Dynamic printf
3385 * Save Breakpoints:: How to save breakpoints in a file
3386 * Static Probe Points:: Listing static probe points
3387 * Error in Breakpoints:: ``Cannot insert breakpoints''
3388 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
3389 @end menu
3390
3391 @node Set Breaks
3392 @subsection Setting Breakpoints
3393
3394 @c FIXME LMB what does GDB do if no code on line of breakpt?
3395 @c consider in particular declaration with/without initialization.
3396 @c
3397 @c FIXME 2 is there stuff on this already? break at fun start, already init?
3398
3399 @kindex break
3400 @kindex b @r{(@code{break})}
3401 @vindex $bpnum@r{, convenience variable}
3402 @cindex latest breakpoint
3403 Breakpoints are set with the @code{break} command (abbreviated
3404 @code{b}). The debugger convenience variable @samp{$bpnum} records the
3405 number of the breakpoint you've set most recently; see @ref{Convenience
3406 Vars,, Convenience Variables}, for a discussion of what you can do with
3407 convenience variables.
3408
3409 @table @code
3410 @item break @var{location}
3411 Set a breakpoint at the given @var{location}, which can specify a
3412 function name, a line number, or an address of an instruction.
3413 (@xref{Specify Location}, for a list of all the possible ways to
3414 specify a @var{location}.) The breakpoint will stop your program just
3415 before it executes any of the code in the specified @var{location}.
3416
3417 When using source languages that permit overloading of symbols, such as
3418 C@t{++}, a function name may refer to more than one possible place to break.
3419 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3420 that situation.
3421
3422 It is also possible to insert a breakpoint that will stop the program
3423 only if a specific thread (@pxref{Thread-Specific Breakpoints})
3424 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
3425
3426 @item break
3427 When called without any arguments, @code{break} sets a breakpoint at
3428 the next instruction to be executed in the selected stack frame
3429 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3430 innermost, this makes your program stop as soon as control
3431 returns to that frame. This is similar to the effect of a
3432 @code{finish} command in the frame inside the selected frame---except
3433 that @code{finish} does not leave an active breakpoint. If you use
3434 @code{break} without an argument in the innermost frame, @value{GDBN} stops
3435 the next time it reaches the current location; this may be useful
3436 inside loops.
3437
3438 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
3439 least one instruction has been executed. If it did not do this, you
3440 would be unable to proceed past a breakpoint without first disabling the
3441 breakpoint. This rule applies whether or not the breakpoint already
3442 existed when your program stopped.
3443
3444 @item break @dots{} if @var{cond}
3445 Set a breakpoint with condition @var{cond}; evaluate the expression
3446 @var{cond} each time the breakpoint is reached, and stop only if the
3447 value is nonzero---that is, if @var{cond} evaluates as true.
3448 @samp{@dots{}} stands for one of the possible arguments described
3449 above (or no argument) specifying where to break. @xref{Conditions,
3450 ,Break Conditions}, for more information on breakpoint conditions.
3451
3452 @kindex tbreak
3453 @item tbreak @var{args}
3454 Set a breakpoint enabled only for one stop. @var{args} are the
3455 same as for the @code{break} command, and the breakpoint is set in the same
3456 way, but the breakpoint is automatically deleted after the first time your
3457 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
3458
3459 @kindex hbreak
3460 @cindex hardware breakpoints
3461 @item hbreak @var{args}
3462 Set a hardware-assisted breakpoint. @var{args} are the same as for the
3463 @code{break} command and the breakpoint is set in the same way, but the
3464 breakpoint requires hardware support and some target hardware may not
3465 have this support. The main purpose of this is EPROM/ROM code
3466 debugging, so you can set a breakpoint at an instruction without
3467 changing the instruction. This can be used with the new trap-generation
3468 provided by SPARClite DSU and most x86-based targets. These targets
3469 will generate traps when a program accesses some data or instruction
3470 address that is assigned to the debug registers. However the hardware
3471 breakpoint registers can take a limited number of breakpoints. For
3472 example, on the DSU, only two data breakpoints can be set at a time, and
3473 @value{GDBN} will reject this command if more than two are used. Delete
3474 or disable unused hardware breakpoints before setting new ones
3475 (@pxref{Disabling, ,Disabling Breakpoints}).
3476 @xref{Conditions, ,Break Conditions}.
3477 For remote targets, you can restrict the number of hardware
3478 breakpoints @value{GDBN} will use, see @ref{set remote
3479 hardware-breakpoint-limit}.
3480
3481 @kindex thbreak
3482 @item thbreak @var{args}
3483 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3484 are the same as for the @code{hbreak} command and the breakpoint is set in
3485 the same way. However, like the @code{tbreak} command,
3486 the breakpoint is automatically deleted after the
3487 first time your program stops there. Also, like the @code{hbreak}
3488 command, the breakpoint requires hardware support and some target hardware
3489 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3490 See also @ref{Conditions, ,Break Conditions}.
3491
3492 @kindex rbreak
3493 @cindex regular expression
3494 @cindex breakpoints at functions matching a regexp
3495 @cindex set breakpoints in many functions
3496 @item rbreak @var{regex}
3497 Set breakpoints on all functions matching the regular expression
3498 @var{regex}. This command sets an unconditional breakpoint on all
3499 matches, printing a list of all breakpoints it set. Once these
3500 breakpoints are set, they are treated just like the breakpoints set with
3501 the @code{break} command. You can delete them, disable them, or make
3502 them conditional the same way as any other breakpoint.
3503
3504 The syntax of the regular expression is the standard one used with tools
3505 like @file{grep}. Note that this is different from the syntax used by
3506 shells, so for instance @code{foo*} matches all functions that include
3507 an @code{fo} followed by zero or more @code{o}s. There is an implicit
3508 @code{.*} leading and trailing the regular expression you supply, so to
3509 match only functions that begin with @code{foo}, use @code{^foo}.
3510
3511 @cindex non-member C@t{++} functions, set breakpoint in
3512 When debugging C@t{++} programs, @code{rbreak} is useful for setting
3513 breakpoints on overloaded functions that are not members of any special
3514 classes.
3515
3516 @cindex set breakpoints on all functions
3517 The @code{rbreak} command can be used to set breakpoints in
3518 @strong{all} the functions in a program, like this:
3519
3520 @smallexample
3521 (@value{GDBP}) rbreak .
3522 @end smallexample
3523
3524 @item rbreak @var{file}:@var{regex}
3525 If @code{rbreak} is called with a filename qualification, it limits
3526 the search for functions matching the given regular expression to the
3527 specified @var{file}. This can be used, for example, to set breakpoints on
3528 every function in a given file:
3529
3530 @smallexample
3531 (@value{GDBP}) rbreak file.c:.
3532 @end smallexample
3533
3534 The colon separating the filename qualifier from the regex may
3535 optionally be surrounded by spaces.
3536
3537 @kindex info breakpoints
3538 @cindex @code{$_} and @code{info breakpoints}
3539 @item info breakpoints @r{[}@var{n}@dots{}@r{]}
3540 @itemx info break @r{[}@var{n}@dots{}@r{]}
3541 Print a table of all breakpoints, watchpoints, and catchpoints set and
3542 not deleted. Optional argument @var{n} means print information only
3543 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
3544 For each breakpoint, following columns are printed:
3545
3546 @table @emph
3547 @item Breakpoint Numbers
3548 @item Type
3549 Breakpoint, watchpoint, or catchpoint.
3550 @item Disposition
3551 Whether the breakpoint is marked to be disabled or deleted when hit.
3552 @item Enabled or Disabled
3553 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
3554 that are not enabled.
3555 @item Address
3556 Where the breakpoint is in your program, as a memory address. For a
3557 pending breakpoint whose address is not yet known, this field will
3558 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3559 library that has the symbol or line referred by breakpoint is loaded.
3560 See below for details. A breakpoint with several locations will
3561 have @samp{<MULTIPLE>} in this field---see below for details.
3562 @item What
3563 Where the breakpoint is in the source for your program, as a file and
3564 line number. For a pending breakpoint, the original string passed to
3565 the breakpoint command will be listed as it cannot be resolved until
3566 the appropriate shared library is loaded in the future.
3567 @end table
3568
3569 @noindent
3570 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
3571 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
3572 @value{GDBN} on the host's side. If it is ``target'', then the condition
3573 is evaluated by the target. The @code{info break} command shows
3574 the condition on the line following the affected breakpoint, together with
3575 its condition evaluation mode in between parentheses.
3576
3577 Breakpoint commands, if any, are listed after that. A pending breakpoint is
3578 allowed to have a condition specified for it. The condition is not parsed for
3579 validity until a shared library is loaded that allows the pending
3580 breakpoint to resolve to a valid location.
3581
3582 @noindent
3583 @code{info break} with a breakpoint
3584 number @var{n} as argument lists only that breakpoint. The
3585 convenience variable @code{$_} and the default examining-address for
3586 the @code{x} command are set to the address of the last breakpoint
3587 listed (@pxref{Memory, ,Examining Memory}).
3588
3589 @noindent
3590 @code{info break} displays a count of the number of times the breakpoint
3591 has been hit. This is especially useful in conjunction with the
3592 @code{ignore} command. You can ignore a large number of breakpoint
3593 hits, look at the breakpoint info to see how many times the breakpoint
3594 was hit, and then run again, ignoring one less than that number. This
3595 will get you quickly to the last hit of that breakpoint.
3596
3597 @noindent
3598 For a breakpoints with an enable count (xref) greater than 1,
3599 @code{info break} also displays that count.
3600
3601 @end table
3602
3603 @value{GDBN} allows you to set any number of breakpoints at the same place in
3604 your program. There is nothing silly or meaningless about this. When
3605 the breakpoints are conditional, this is even useful
3606 (@pxref{Conditions, ,Break Conditions}).
3607
3608 @cindex multiple locations, breakpoints
3609 @cindex breakpoints, multiple locations
3610 It is possible that a breakpoint corresponds to several locations
3611 in your program. Examples of this situation are:
3612
3613 @itemize @bullet
3614 @item
3615 Multiple functions in the program may have the same name.
3616
3617 @item
3618 For a C@t{++} constructor, the @value{NGCC} compiler generates several
3619 instances of the function body, used in different cases.
3620
3621 @item
3622 For a C@t{++} template function, a given line in the function can
3623 correspond to any number of instantiations.
3624
3625 @item
3626 For an inlined function, a given source line can correspond to
3627 several places where that function is inlined.
3628 @end itemize
3629
3630 In all those cases, @value{GDBN} will insert a breakpoint at all
3631 the relevant locations.
3632
3633 A breakpoint with multiple locations is displayed in the breakpoint
3634 table using several rows---one header row, followed by one row for
3635 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3636 address column. The rows for individual locations contain the actual
3637 addresses for locations, and show the functions to which those
3638 locations belong. The number column for a location is of the form
3639 @var{breakpoint-number}.@var{location-number}.
3640
3641 For example:
3642
3643 @smallexample
3644 Num Type Disp Enb Address What
3645 1 breakpoint keep y <MULTIPLE>
3646 stop only if i==1
3647 breakpoint already hit 1 time
3648 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
3649 1.2 y 0x080486ca in void foo<double>() at t.cc:8
3650 @end smallexample
3651
3652 Each location can be individually enabled or disabled by passing
3653 @var{breakpoint-number}.@var{location-number} as argument to the
3654 @code{enable} and @code{disable} commands. Note that you cannot
3655 delete the individual locations from the list, you can only delete the
3656 entire list of locations that belong to their parent breakpoint (with
3657 the @kbd{delete @var{num}} command, where @var{num} is the number of
3658 the parent breakpoint, 1 in the above example). Disabling or enabling
3659 the parent breakpoint (@pxref{Disabling}) affects all of the locations
3660 that belong to that breakpoint.
3661
3662 @cindex pending breakpoints
3663 It's quite common to have a breakpoint inside a shared library.
3664 Shared libraries can be loaded and unloaded explicitly,
3665 and possibly repeatedly, as the program is executed. To support
3666 this use case, @value{GDBN} updates breakpoint locations whenever
3667 any shared library is loaded or unloaded. Typically, you would
3668 set a breakpoint in a shared library at the beginning of your
3669 debugging session, when the library is not loaded, and when the
3670 symbols from the library are not available. When you try to set
3671 breakpoint, @value{GDBN} will ask you if you want to set
3672 a so called @dfn{pending breakpoint}---breakpoint whose address
3673 is not yet resolved.
3674
3675 After the program is run, whenever a new shared library is loaded,
3676 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
3677 shared library contains the symbol or line referred to by some
3678 pending breakpoint, that breakpoint is resolved and becomes an
3679 ordinary breakpoint. When a library is unloaded, all breakpoints
3680 that refer to its symbols or source lines become pending again.
3681
3682 This logic works for breakpoints with multiple locations, too. For
3683 example, if you have a breakpoint in a C@t{++} template function, and
3684 a newly loaded shared library has an instantiation of that template,
3685 a new location is added to the list of locations for the breakpoint.
3686
3687 Except for having unresolved address, pending breakpoints do not
3688 differ from regular breakpoints. You can set conditions or commands,
3689 enable and disable them and perform other breakpoint operations.
3690
3691 @value{GDBN} provides some additional commands for controlling what
3692 happens when the @samp{break} command cannot resolve breakpoint
3693 address specification to an address:
3694
3695 @kindex set breakpoint pending
3696 @kindex show breakpoint pending
3697 @table @code
3698 @item set breakpoint pending auto
3699 This is the default behavior. When @value{GDBN} cannot find the breakpoint
3700 location, it queries you whether a pending breakpoint should be created.
3701
3702 @item set breakpoint pending on
3703 This indicates that an unrecognized breakpoint location should automatically
3704 result in a pending breakpoint being created.
3705
3706 @item set breakpoint pending off
3707 This indicates that pending breakpoints are not to be created. Any
3708 unrecognized breakpoint location results in an error. This setting does
3709 not affect any pending breakpoints previously created.
3710
3711 @item show breakpoint pending
3712 Show the current behavior setting for creating pending breakpoints.
3713 @end table
3714
3715 The settings above only affect the @code{break} command and its
3716 variants. Once breakpoint is set, it will be automatically updated
3717 as shared libraries are loaded and unloaded.
3718
3719 @cindex automatic hardware breakpoints
3720 For some targets, @value{GDBN} can automatically decide if hardware or
3721 software breakpoints should be used, depending on whether the
3722 breakpoint address is read-only or read-write. This applies to
3723 breakpoints set with the @code{break} command as well as to internal
3724 breakpoints set by commands like @code{next} and @code{finish}. For
3725 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3726 breakpoints.
3727
3728 You can control this automatic behaviour with the following commands::
3729
3730 @kindex set breakpoint auto-hw
3731 @kindex show breakpoint auto-hw
3732 @table @code
3733 @item set breakpoint auto-hw on
3734 This is the default behavior. When @value{GDBN} sets a breakpoint, it
3735 will try to use the target memory map to decide if software or hardware
3736 breakpoint must be used.
3737
3738 @item set breakpoint auto-hw off
3739 This indicates @value{GDBN} should not automatically select breakpoint
3740 type. If the target provides a memory map, @value{GDBN} will warn when
3741 trying to set software breakpoint at a read-only address.
3742 @end table
3743
3744 @value{GDBN} normally implements breakpoints by replacing the program code
3745 at the breakpoint address with a special instruction, which, when
3746 executed, given control to the debugger. By default, the program
3747 code is so modified only when the program is resumed. As soon as
3748 the program stops, @value{GDBN} restores the original instructions. This
3749 behaviour guards against leaving breakpoints inserted in the
3750 target should gdb abrubptly disconnect. However, with slow remote
3751 targets, inserting and removing breakpoint can reduce the performance.
3752 This behavior can be controlled with the following commands::
3753
3754 @kindex set breakpoint always-inserted
3755 @kindex show breakpoint always-inserted
3756 @table @code
3757 @item set breakpoint always-inserted off
3758 All breakpoints, including newly added by the user, are inserted in
3759 the target only when the target is resumed. All breakpoints are
3760 removed from the target when it stops.
3761
3762 @item set breakpoint always-inserted on
3763 Causes all breakpoints to be inserted in the target at all times. If
3764 the user adds a new breakpoint, or changes an existing breakpoint, the
3765 breakpoints in the target are updated immediately. A breakpoint is
3766 removed from the target only when breakpoint itself is removed.
3767
3768 @cindex non-stop mode, and @code{breakpoint always-inserted}
3769 @item set breakpoint always-inserted auto
3770 This is the default mode. If @value{GDBN} is controlling the inferior
3771 in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3772 @code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3773 controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3774 @code{breakpoint always-inserted} mode is off.
3775 @end table
3776
3777 @value{GDBN} handles conditional breakpoints by evaluating these conditions
3778 when a breakpoint breaks. If the condition is true, then the process being
3779 debugged stops, otherwise the process is resumed.
3780
3781 If the target supports evaluating conditions on its end, @value{GDBN} may
3782 download the breakpoint, together with its conditions, to it.
3783
3784 This feature can be controlled via the following commands:
3785
3786 @kindex set breakpoint condition-evaluation
3787 @kindex show breakpoint condition-evaluation
3788 @table @code
3789 @item set breakpoint condition-evaluation host
3790 This option commands @value{GDBN} to evaluate the breakpoint
3791 conditions on the host's side. Unconditional breakpoints are sent to
3792 the target which in turn receives the triggers and reports them back to GDB
3793 for condition evaluation. This is the standard evaluation mode.
3794
3795 @item set breakpoint condition-evaluation target
3796 This option commands @value{GDBN} to download breakpoint conditions
3797 to the target at the moment of their insertion. The target
3798 is responsible for evaluating the conditional expression and reporting
3799 breakpoint stop events back to @value{GDBN} whenever the condition
3800 is true. Due to limitations of target-side evaluation, some conditions
3801 cannot be evaluated there, e.g., conditions that depend on local data
3802 that is only known to the host. Examples include
3803 conditional expressions involving convenience variables, complex types
3804 that cannot be handled by the agent expression parser and expressions
3805 that are too long to be sent over to the target, specially when the
3806 target is a remote system. In these cases, the conditions will be
3807 evaluated by @value{GDBN}.
3808
3809 @item set breakpoint condition-evaluation auto
3810 This is the default mode. If the target supports evaluating breakpoint
3811 conditions on its end, @value{GDBN} will download breakpoint conditions to
3812 the target (limitations mentioned previously apply). If the target does
3813 not support breakpoint condition evaluation, then @value{GDBN} will fallback
3814 to evaluating all these conditions on the host's side.
3815 @end table
3816
3817
3818 @cindex negative breakpoint numbers
3819 @cindex internal @value{GDBN} breakpoints
3820 @value{GDBN} itself sometimes sets breakpoints in your program for
3821 special purposes, such as proper handling of @code{longjmp} (in C
3822 programs). These internal breakpoints are assigned negative numbers,
3823 starting with @code{-1}; @samp{info breakpoints} does not display them.
3824 You can see these breakpoints with the @value{GDBN} maintenance command
3825 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3826
3827
3828 @node Set Watchpoints
3829 @subsection Setting Watchpoints
3830
3831 @cindex setting watchpoints
3832 You can use a watchpoint to stop execution whenever the value of an
3833 expression changes, without having to predict a particular place where
3834 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3835 The expression may be as simple as the value of a single variable, or
3836 as complex as many variables combined by operators. Examples include:
3837
3838 @itemize @bullet
3839 @item
3840 A reference to the value of a single variable.
3841
3842 @item
3843 An address cast to an appropriate data type. For example,
3844 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3845 address (assuming an @code{int} occupies 4 bytes).
3846
3847 @item
3848 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3849 expression can use any operators valid in the program's native
3850 language (@pxref{Languages}).
3851 @end itemize
3852
3853 You can set a watchpoint on an expression even if the expression can
3854 not be evaluated yet. For instance, you can set a watchpoint on
3855 @samp{*global_ptr} before @samp{global_ptr} is initialized.
3856 @value{GDBN} will stop when your program sets @samp{global_ptr} and
3857 the expression produces a valid value. If the expression becomes
3858 valid in some other way than changing a variable (e.g.@: if the memory
3859 pointed to by @samp{*global_ptr} becomes readable as the result of a
3860 @code{malloc} call), @value{GDBN} may not stop until the next time
3861 the expression changes.
3862
3863 @cindex software watchpoints
3864 @cindex hardware watchpoints
3865 Depending on your system, watchpoints may be implemented in software or
3866 hardware. @value{GDBN} does software watchpointing by single-stepping your
3867 program and testing the variable's value each time, which is hundreds of
3868 times slower than normal execution. (But this may still be worth it, to
3869 catch errors where you have no clue what part of your program is the
3870 culprit.)
3871
3872 On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3873 x86-based targets, @value{GDBN} includes support for hardware
3874 watchpoints, which do not slow down the running of your program.
3875
3876 @table @code
3877 @kindex watch
3878 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3879 Set a watchpoint for an expression. @value{GDBN} will break when the
3880 expression @var{expr} is written into by the program and its value
3881 changes. The simplest (and the most popular) use of this command is
3882 to watch the value of a single variable:
3883
3884 @smallexample
3885 (@value{GDBP}) watch foo
3886 @end smallexample
3887
3888 If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3889 argument, @value{GDBN} breaks only when the thread identified by
3890 @var{threadnum} changes the value of @var{expr}. If any other threads
3891 change the value of @var{expr}, @value{GDBN} will not break. Note
3892 that watchpoints restricted to a single thread in this way only work
3893 with Hardware Watchpoints.
3894
3895 Ordinarily a watchpoint respects the scope of variables in @var{expr}
3896 (see below). The @code{-location} argument tells @value{GDBN} to
3897 instead watch the memory referred to by @var{expr}. In this case,
3898 @value{GDBN} will evaluate @var{expr}, take the address of the result,
3899 and watch the memory at that address. The type of the result is used
3900 to determine the size of the watched memory. If the expression's
3901 result does not have an address, then @value{GDBN} will print an
3902 error.
3903
3904 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
3905 of masked watchpoints, if the current architecture supports this
3906 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
3907 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
3908 to an address to watch. The mask specifies that some bits of an address
3909 (the bits which are reset in the mask) should be ignored when matching
3910 the address accessed by the inferior against the watchpoint address.
3911 Thus, a masked watchpoint watches many addresses simultaneously---those
3912 addresses whose unmasked bits are identical to the unmasked bits in the
3913 watchpoint address. The @code{mask} argument implies @code{-location}.
3914 Examples:
3915
3916 @smallexample
3917 (@value{GDBP}) watch foo mask 0xffff00ff
3918 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
3919 @end smallexample
3920
3921 @kindex rwatch
3922 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3923 Set a watchpoint that will break when the value of @var{expr} is read
3924 by the program.
3925
3926 @kindex awatch
3927 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{threadnum}@r{]} @r{[}mask @var{maskvalue}@r{]}
3928 Set a watchpoint that will break when @var{expr} is either read from
3929 or written into by the program.
3930
3931 @kindex info watchpoints @r{[}@var{n}@dots{}@r{]}
3932 @item info watchpoints @r{[}@var{n}@dots{}@r{]}
3933 This command prints a list of watchpoints, using the same format as
3934 @code{info break} (@pxref{Set Breaks}).
3935 @end table
3936
3937 If you watch for a change in a numerically entered address you need to
3938 dereference it, as the address itself is just a constant number which will
3939 never change. @value{GDBN} refuses to create a watchpoint that watches
3940 a never-changing value:
3941
3942 @smallexample
3943 (@value{GDBP}) watch 0x600850
3944 Cannot watch constant value 0x600850.
3945 (@value{GDBP}) watch *(int *) 0x600850
3946 Watchpoint 1: *(int *) 6293584
3947 @end smallexample
3948
3949 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3950 watchpoints execute very quickly, and the debugger reports a change in
3951 value at the exact instruction where the change occurs. If @value{GDBN}
3952 cannot set a hardware watchpoint, it sets a software watchpoint, which
3953 executes more slowly and reports the change in value at the next
3954 @emph{statement}, not the instruction, after the change occurs.
3955
3956 @cindex use only software watchpoints
3957 You can force @value{GDBN} to use only software watchpoints with the
3958 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3959 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3960 the underlying system supports them. (Note that hardware-assisted
3961 watchpoints that were set @emph{before} setting
3962 @code{can-use-hw-watchpoints} to zero will still use the hardware
3963 mechanism of watching expression values.)
3964
3965 @table @code
3966 @item set can-use-hw-watchpoints
3967 @kindex set can-use-hw-watchpoints
3968 Set whether or not to use hardware watchpoints.
3969
3970 @item show can-use-hw-watchpoints
3971 @kindex show can-use-hw-watchpoints
3972 Show the current mode of using hardware watchpoints.
3973 @end table
3974
3975 For remote targets, you can restrict the number of hardware
3976 watchpoints @value{GDBN} will use, see @ref{set remote
3977 hardware-breakpoint-limit}.
3978
3979 When you issue the @code{watch} command, @value{GDBN} reports
3980
3981 @smallexample
3982 Hardware watchpoint @var{num}: @var{expr}
3983 @end smallexample
3984
3985 @noindent
3986 if it was able to set a hardware watchpoint.
3987
3988 Currently, the @code{awatch} and @code{rwatch} commands can only set
3989 hardware watchpoints, because accesses to data that don't change the
3990 value of the watched expression cannot be detected without examining
3991 every instruction as it is being executed, and @value{GDBN} does not do
3992 that currently. If @value{GDBN} finds that it is unable to set a
3993 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3994 will print a message like this:
3995
3996 @smallexample
3997 Expression cannot be implemented with read/access watchpoint.
3998 @end smallexample
3999
4000 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4001 data type of the watched expression is wider than what a hardware
4002 watchpoint on the target machine can handle. For example, some systems
4003 can only watch regions that are up to 4 bytes wide; on such systems you
4004 cannot set hardware watchpoints for an expression that yields a
4005 double-precision floating-point number (which is typically 8 bytes
4006 wide). As a work-around, it might be possible to break the large region
4007 into a series of smaller ones and watch them with separate watchpoints.
4008
4009 If you set too many hardware watchpoints, @value{GDBN} might be unable
4010 to insert all of them when you resume the execution of your program.
4011 Since the precise number of active watchpoints is unknown until such
4012 time as the program is about to be resumed, @value{GDBN} might not be
4013 able to warn you about this when you set the watchpoints, and the
4014 warning will be printed only when the program is resumed:
4015
4016 @smallexample
4017 Hardware watchpoint @var{num}: Could not insert watchpoint
4018 @end smallexample
4019
4020 @noindent
4021 If this happens, delete or disable some of the watchpoints.
4022
4023 Watching complex expressions that reference many variables can also
4024 exhaust the resources available for hardware-assisted watchpoints.
4025 That's because @value{GDBN} needs to watch every variable in the
4026 expression with separately allocated resources.
4027
4028 If you call a function interactively using @code{print} or @code{call},
4029 any watchpoints you have set will be inactive until @value{GDBN} reaches another
4030 kind of breakpoint or the call completes.
4031
4032 @value{GDBN} automatically deletes watchpoints that watch local
4033 (automatic) variables, or expressions that involve such variables, when
4034 they go out of scope, that is, when the execution leaves the block in
4035 which these variables were defined. In particular, when the program
4036 being debugged terminates, @emph{all} local variables go out of scope,
4037 and so only watchpoints that watch global variables remain set. If you
4038 rerun the program, you will need to set all such watchpoints again. One
4039 way of doing that would be to set a code breakpoint at the entry to the
4040 @code{main} function and when it breaks, set all the watchpoints.
4041
4042 @cindex watchpoints and threads
4043 @cindex threads and watchpoints
4044 In multi-threaded programs, watchpoints will detect changes to the
4045 watched expression from every thread.
4046
4047 @quotation
4048 @emph{Warning:} In multi-threaded programs, software watchpoints
4049 have only limited usefulness. If @value{GDBN} creates a software
4050 watchpoint, it can only watch the value of an expression @emph{in a
4051 single thread}. If you are confident that the expression can only
4052 change due to the current thread's activity (and if you are also
4053 confident that no other thread can become current), then you can use
4054 software watchpoints as usual. However, @value{GDBN} may not notice
4055 when a non-current thread's activity changes the expression. (Hardware
4056 watchpoints, in contrast, watch an expression in all threads.)
4057 @end quotation
4058
4059 @xref{set remote hardware-watchpoint-limit}.
4060
4061 @node Set Catchpoints
4062 @subsection Setting Catchpoints
4063 @cindex catchpoints, setting
4064 @cindex exception handlers
4065 @cindex event handling
4066
4067 You can use @dfn{catchpoints} to cause the debugger to stop for certain
4068 kinds of program events, such as C@t{++} exceptions or the loading of a
4069 shared library. Use the @code{catch} command to set a catchpoint.
4070
4071 @table @code
4072 @kindex catch
4073 @item catch @var{event}
4074 Stop when @var{event} occurs. @var{event} can be any of the following:
4075
4076 @table @code
4077 @item throw @r{[}@var{regexp}@r{]}
4078 @itemx rethrow @r{[}@var{regexp}@r{]}
4079 @itemx catch @r{[}@var{regexp}@r{]}
4080 @cindex stop on C@t{++} exceptions
4081 The throwing, re-throwing, or catching of a C@t{++} exception.
4082
4083 If @var{regexp} is given, then only exceptions whose type matches the
4084 regular expression will be caught.
4085
4086 @vindex $_exception@r{, convenience variable}
4087 The convenience variable @code{$_exception} is available at an
4088 exception-related catchpoint, on some systems. This holds the
4089 exception being thrown.
4090
4091 There are currently some limitations to C@t{++} exception handling in
4092 @value{GDBN}:
4093
4094 @itemize @bullet
4095 @item
4096 The support for these commands is system-dependent. Currently, only
4097 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4098 supported.
4099
4100 @item
4101 The regular expression feature and the @code{$_exception} convenience
4102 variable rely on the presence of some SDT probes in @code{libstdc++}.
4103 If these probes are not present, then these features cannot be used.
4104 These probes were first available in the GCC 4.8 release, but whether
4105 or not they are available in your GCC also depends on how it was
4106 built.
4107
4108 @item
4109 The @code{$_exception} convenience variable is only valid at the
4110 instruction at which an exception-related catchpoint is set.
4111
4112 @item
4113 When an exception-related catchpoint is hit, @value{GDBN} stops at a
4114 location in the system library which implements runtime exception
4115 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4116 (@pxref{Selection}) to get to your code.
4117
4118 @item
4119 If you call a function interactively, @value{GDBN} normally returns
4120 control to you when the function has finished executing. If the call
4121 raises an exception, however, the call may bypass the mechanism that
4122 returns control to you and cause your program either to abort or to
4123 simply continue running until it hits a breakpoint, catches a signal
4124 that @value{GDBN} is listening for, or exits. This is the case even if
4125 you set a catchpoint for the exception; catchpoints on exceptions are
4126 disabled within interactive calls. @xref{Calling}, for information on
4127 controlling this with @code{set unwind-on-terminating-exception}.
4128
4129 @item
4130 You cannot raise an exception interactively.
4131
4132 @item
4133 You cannot install an exception handler interactively.
4134 @end itemize
4135
4136 @item exception
4137 @cindex Ada exception catching
4138 @cindex catch Ada exceptions
4139 An Ada exception being raised. If an exception name is specified
4140 at the end of the command (eg @code{catch exception Program_Error}),
4141 the debugger will stop only when this specific exception is raised.
4142 Otherwise, the debugger stops execution when any Ada exception is raised.
4143
4144 When inserting an exception catchpoint on a user-defined exception whose
4145 name is identical to one of the exceptions defined by the language, the
4146 fully qualified name must be used as the exception name. Otherwise,
4147 @value{GDBN} will assume that it should stop on the pre-defined exception
4148 rather than the user-defined one. For instance, assuming an exception
4149 called @code{Constraint_Error} is defined in package @code{Pck}, then
4150 the command to use to catch such exceptions is @kbd{catch exception
4151 Pck.Constraint_Error}.
4152
4153 @item exception unhandled
4154 An exception that was raised but is not handled by the program.
4155
4156 @item assert
4157 A failed Ada assertion.
4158
4159 @item exec
4160 @cindex break on fork/exec
4161 A call to @code{exec}. This is currently only available for HP-UX
4162 and @sc{gnu}/Linux.
4163
4164 @item syscall
4165 @itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
4166 @cindex break on a system call.
4167 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4168 syscall is a mechanism for application programs to request a service
4169 from the operating system (OS) or one of the OS system services.
4170 @value{GDBN} can catch some or all of the syscalls issued by the
4171 debuggee, and show the related information for each syscall. If no
4172 argument is specified, calls to and returns from all system calls
4173 will be caught.
4174
4175 @var{name} can be any system call name that is valid for the
4176 underlying OS. Just what syscalls are valid depends on the OS. On
4177 GNU and Unix systems, you can find the full list of valid syscall
4178 names on @file{/usr/include/asm/unistd.h}.
4179
4180 @c For MS-Windows, the syscall names and the corresponding numbers
4181 @c can be found, e.g., on this URL:
4182 @c http://www.metasploit.com/users/opcode/syscalls.html
4183 @c but we don't support Windows syscalls yet.
4184
4185 Normally, @value{GDBN} knows in advance which syscalls are valid for
4186 each OS, so you can use the @value{GDBN} command-line completion
4187 facilities (@pxref{Completion,, command completion}) to list the
4188 available choices.
4189
4190 You may also specify the system call numerically. A syscall's
4191 number is the value passed to the OS's syscall dispatcher to
4192 identify the requested service. When you specify the syscall by its
4193 name, @value{GDBN} uses its database of syscalls to convert the name
4194 into the corresponding numeric code, but using the number directly
4195 may be useful if @value{GDBN}'s database does not have the complete
4196 list of syscalls on your system (e.g., because @value{GDBN} lags
4197 behind the OS upgrades).
4198
4199 The example below illustrates how this command works if you don't provide
4200 arguments to it:
4201
4202 @smallexample
4203 (@value{GDBP}) catch syscall
4204 Catchpoint 1 (syscall)
4205 (@value{GDBP}) r
4206 Starting program: /tmp/catch-syscall
4207
4208 Catchpoint 1 (call to syscall 'close'), \
4209 0xffffe424 in __kernel_vsyscall ()
4210 (@value{GDBP}) c
4211 Continuing.
4212
4213 Catchpoint 1 (returned from syscall 'close'), \
4214 0xffffe424 in __kernel_vsyscall ()
4215 (@value{GDBP})
4216 @end smallexample
4217
4218 Here is an example of catching a system call by name:
4219
4220 @smallexample
4221 (@value{GDBP}) catch syscall chroot
4222 Catchpoint 1 (syscall 'chroot' [61])
4223 (@value{GDBP}) r
4224 Starting program: /tmp/catch-syscall
4225
4226 Catchpoint 1 (call to syscall 'chroot'), \
4227 0xffffe424 in __kernel_vsyscall ()
4228 (@value{GDBP}) c
4229 Continuing.
4230
4231 Catchpoint 1 (returned from syscall 'chroot'), \
4232 0xffffe424 in __kernel_vsyscall ()
4233 (@value{GDBP})
4234 @end smallexample
4235
4236 An example of specifying a system call numerically. In the case
4237 below, the syscall number has a corresponding entry in the XML
4238 file, so @value{GDBN} finds its name and prints it:
4239
4240 @smallexample
4241 (@value{GDBP}) catch syscall 252
4242 Catchpoint 1 (syscall(s) 'exit_group')
4243 (@value{GDBP}) r
4244 Starting program: /tmp/catch-syscall
4245
4246 Catchpoint 1 (call to syscall 'exit_group'), \
4247 0xffffe424 in __kernel_vsyscall ()
4248 (@value{GDBP}) c
4249 Continuing.
4250
4251 Program exited normally.
4252 (@value{GDBP})
4253 @end smallexample
4254
4255 However, there can be situations when there is no corresponding name
4256 in XML file for that syscall number. In this case, @value{GDBN} prints
4257 a warning message saying that it was not able to find the syscall name,
4258 but the catchpoint will be set anyway. See the example below:
4259
4260 @smallexample
4261 (@value{GDBP}) catch syscall 764
4262 warning: The number '764' does not represent a known syscall.
4263 Catchpoint 2 (syscall 764)
4264 (@value{GDBP})
4265 @end smallexample
4266
4267 If you configure @value{GDBN} using the @samp{--without-expat} option,
4268 it will not be able to display syscall names. Also, if your
4269 architecture does not have an XML file describing its system calls,
4270 you will not be able to see the syscall names. It is important to
4271 notice that these two features are used for accessing the syscall
4272 name database. In either case, you will see a warning like this:
4273
4274 @smallexample
4275 (@value{GDBP}) catch syscall
4276 warning: Could not open "syscalls/i386-linux.xml"
4277 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4278 GDB will not be able to display syscall names.
4279 Catchpoint 1 (syscall)
4280 (@value{GDBP})
4281 @end smallexample
4282
4283 Of course, the file name will change depending on your architecture and system.
4284
4285 Still using the example above, you can also try to catch a syscall by its
4286 number. In this case, you would see something like:
4287
4288 @smallexample
4289 (@value{GDBP}) catch syscall 252
4290 Catchpoint 1 (syscall(s) 252)
4291 @end smallexample
4292
4293 Again, in this case @value{GDBN} would not be able to display syscall's names.
4294
4295 @item fork
4296 A call to @code{fork}. This is currently only available for HP-UX
4297 and @sc{gnu}/Linux.
4298
4299 @item vfork
4300 A call to @code{vfork}. This is currently only available for HP-UX
4301 and @sc{gnu}/Linux.
4302
4303 @item load @r{[}regexp@r{]}
4304 @itemx unload @r{[}regexp@r{]}
4305 The loading or unloading of a shared library. If @var{regexp} is
4306 given, then the catchpoint will stop only if the regular expression
4307 matches one of the affected libraries.
4308
4309 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
4310 The delivery of a signal.
4311
4312 With no arguments, this catchpoint will catch any signal that is not
4313 used internally by @value{GDBN}, specifically, all signals except
4314 @samp{SIGTRAP} and @samp{SIGINT}.
4315
4316 With the argument @samp{all}, all signals, including those used by
4317 @value{GDBN}, will be caught. This argument cannot be used with other
4318 signal names.
4319
4320 Otherwise, the arguments are a list of signal names as given to
4321 @code{handle} (@pxref{Signals}). Only signals specified in this list
4322 will be caught.
4323
4324 One reason that @code{catch signal} can be more useful than
4325 @code{handle} is that you can attach commands and conditions to the
4326 catchpoint.
4327
4328 When a signal is caught by a catchpoint, the signal's @code{stop} and
4329 @code{print} settings, as specified by @code{handle}, are ignored.
4330 However, whether the signal is still delivered to the inferior depends
4331 on the @code{pass} setting; this can be changed in the catchpoint's
4332 commands.
4333
4334 @end table
4335
4336 @item tcatch @var{event}
4337 Set a catchpoint that is enabled only for one stop. The catchpoint is
4338 automatically deleted after the first time the event is caught.
4339
4340 @end table
4341
4342 Use the @code{info break} command to list the current catchpoints.
4343
4344
4345 @node Delete Breaks
4346 @subsection Deleting Breakpoints
4347
4348 @cindex clearing breakpoints, watchpoints, catchpoints
4349 @cindex deleting breakpoints, watchpoints, catchpoints
4350 It is often necessary to eliminate a breakpoint, watchpoint, or
4351 catchpoint once it has done its job and you no longer want your program
4352 to stop there. This is called @dfn{deleting} the breakpoint. A
4353 breakpoint that has been deleted no longer exists; it is forgotten.
4354
4355 With the @code{clear} command you can delete breakpoints according to
4356 where they are in your program. With the @code{delete} command you can
4357 delete individual breakpoints, watchpoints, or catchpoints by specifying
4358 their breakpoint numbers.
4359
4360 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4361 automatically ignores breakpoints on the first instruction to be executed
4362 when you continue execution without changing the execution address.
4363
4364 @table @code
4365 @kindex clear
4366 @item clear
4367 Delete any breakpoints at the next instruction to be executed in the
4368 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
4369 the innermost frame is selected, this is a good way to delete a
4370 breakpoint where your program just stopped.
4371
4372 @item clear @var{location}
4373 Delete any breakpoints set at the specified @var{location}.
4374 @xref{Specify Location}, for the various forms of @var{location}; the
4375 most useful ones are listed below:
4376
4377 @table @code
4378 @item clear @var{function}
4379 @itemx clear @var{filename}:@var{function}
4380 Delete any breakpoints set at entry to the named @var{function}.
4381
4382 @item clear @var{linenum}
4383 @itemx clear @var{filename}:@var{linenum}
4384 Delete any breakpoints set at or within the code of the specified
4385 @var{linenum} of the specified @var{filename}.
4386 @end table
4387
4388 @cindex delete breakpoints
4389 @kindex delete
4390 @kindex d @r{(@code{delete})}
4391 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4392 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4393 ranges specified as arguments. If no argument is specified, delete all
4394 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4395 confirm off}). You can abbreviate this command as @code{d}.
4396 @end table
4397
4398 @node Disabling
4399 @subsection Disabling Breakpoints
4400
4401 @cindex enable/disable a breakpoint
4402 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4403 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4404 it had been deleted, but remembers the information on the breakpoint so
4405 that you can @dfn{enable} it again later.
4406
4407 You disable and enable breakpoints, watchpoints, and catchpoints with
4408 the @code{enable} and @code{disable} commands, optionally specifying
4409 one or more breakpoint numbers as arguments. Use @code{info break} to
4410 print a list of all breakpoints, watchpoints, and catchpoints if you
4411 do not know which numbers to use.
4412
4413 Disabling and enabling a breakpoint that has multiple locations
4414 affects all of its locations.
4415
4416 A breakpoint, watchpoint, or catchpoint can have any of several
4417 different states of enablement:
4418
4419 @itemize @bullet
4420 @item
4421 Enabled. The breakpoint stops your program. A breakpoint set
4422 with the @code{break} command starts out in this state.
4423 @item
4424 Disabled. The breakpoint has no effect on your program.
4425 @item
4426 Enabled once. The breakpoint stops your program, but then becomes
4427 disabled.
4428 @item
4429 Enabled for a count. The breakpoint stops your program for the next
4430 N times, then becomes disabled.
4431 @item
4432 Enabled for deletion. The breakpoint stops your program, but
4433 immediately after it does so it is deleted permanently. A breakpoint
4434 set with the @code{tbreak} command starts out in this state.
4435 @end itemize
4436
4437 You can use the following commands to enable or disable breakpoints,
4438 watchpoints, and catchpoints:
4439
4440 @table @code
4441 @kindex disable
4442 @kindex dis @r{(@code{disable})}
4443 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4444 Disable the specified breakpoints---or all breakpoints, if none are
4445 listed. A disabled breakpoint has no effect but is not forgotten. All
4446 options such as ignore-counts, conditions and commands are remembered in
4447 case the breakpoint is enabled again later. You may abbreviate
4448 @code{disable} as @code{dis}.
4449
4450 @kindex enable
4451 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4452 Enable the specified breakpoints (or all defined breakpoints). They
4453 become effective once again in stopping your program.
4454
4455 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
4456 Enable the specified breakpoints temporarily. @value{GDBN} disables any
4457 of these breakpoints immediately after stopping your program.
4458
4459 @item enable @r{[}breakpoints@r{]} count @var{count} @var{range}@dots{}
4460 Enable the specified breakpoints temporarily. @value{GDBN} records
4461 @var{count} with each of the specified breakpoints, and decrements a
4462 breakpoint's count when it is hit. When any count reaches 0,
4463 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4464 count (@pxref{Conditions, ,Break Conditions}), that will be
4465 decremented to 0 before @var{count} is affected.
4466
4467 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
4468 Enable the specified breakpoints to work once, then die. @value{GDBN}
4469 deletes any of these breakpoints as soon as your program stops there.
4470 Breakpoints set by the @code{tbreak} command start out in this state.
4471 @end table
4472
4473 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4474 @c confusing: tbreak is also initially enabled.
4475 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
4476 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
4477 subsequently, they become disabled or enabled only when you use one of
4478 the commands above. (The command @code{until} can set and delete a
4479 breakpoint of its own, but it does not change the state of your other
4480 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
4481 Stepping}.)
4482
4483 @node Conditions
4484 @subsection Break Conditions
4485 @cindex conditional breakpoints
4486 @cindex breakpoint conditions
4487
4488 @c FIXME what is scope of break condition expr? Context where wanted?
4489 @c in particular for a watchpoint?
4490 The simplest sort of breakpoint breaks every time your program reaches a
4491 specified place. You can also specify a @dfn{condition} for a
4492 breakpoint. A condition is just a Boolean expression in your
4493 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4494 a condition evaluates the expression each time your program reaches it,
4495 and your program stops only if the condition is @emph{true}.
4496
4497 This is the converse of using assertions for program validation; in that
4498 situation, you want to stop when the assertion is violated---that is,
4499 when the condition is false. In C, if you want to test an assertion expressed
4500 by the condition @var{assert}, you should set the condition
4501 @samp{! @var{assert}} on the appropriate breakpoint.
4502
4503 Conditions are also accepted for watchpoints; you may not need them,
4504 since a watchpoint is inspecting the value of an expression anyhow---but
4505 it might be simpler, say, to just set a watchpoint on a variable name,
4506 and specify a condition that tests whether the new value is an interesting
4507 one.
4508
4509 Break conditions can have side effects, and may even call functions in
4510 your program. This can be useful, for example, to activate functions
4511 that log program progress, or to use your own print functions to
4512 format special data structures. The effects are completely predictable
4513 unless there is another enabled breakpoint at the same address. (In
4514 that case, @value{GDBN} might see the other breakpoint first and stop your
4515 program without checking the condition of this one.) Note that
4516 breakpoint commands are usually more convenient and flexible than break
4517 conditions for the
4518 purpose of performing side effects when a breakpoint is reached
4519 (@pxref{Break Commands, ,Breakpoint Command Lists}).
4520
4521 Breakpoint conditions can also be evaluated on the target's side if
4522 the target supports it. Instead of evaluating the conditions locally,
4523 @value{GDBN} encodes the expression into an agent expression
4524 (@pxref{Agent Expressions}) suitable for execution on the target,
4525 independently of @value{GDBN}. Global variables become raw memory
4526 locations, locals become stack accesses, and so forth.
4527
4528 In this case, @value{GDBN} will only be notified of a breakpoint trigger
4529 when its condition evaluates to true. This mechanism may provide faster
4530 response times depending on the performance characteristics of the target
4531 since it does not need to keep @value{GDBN} informed about
4532 every breakpoint trigger, even those with false conditions.
4533
4534 Break conditions can be specified when a breakpoint is set, by using
4535 @samp{if} in the arguments to the @code{break} command. @xref{Set
4536 Breaks, ,Setting Breakpoints}. They can also be changed at any time
4537 with the @code{condition} command.
4538
4539 You can also use the @code{if} keyword with the @code{watch} command.
4540 The @code{catch} command does not recognize the @code{if} keyword;
4541 @code{condition} is the only way to impose a further condition on a
4542 catchpoint.
4543
4544 @table @code
4545 @kindex condition
4546 @item condition @var{bnum} @var{expression}
4547 Specify @var{expression} as the break condition for breakpoint,
4548 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4549 breakpoint @var{bnum} stops your program only if the value of
4550 @var{expression} is true (nonzero, in C). When you use
4551 @code{condition}, @value{GDBN} checks @var{expression} immediately for
4552 syntactic correctness, and to determine whether symbols in it have
4553 referents in the context of your breakpoint. If @var{expression} uses
4554 symbols not referenced in the context of the breakpoint, @value{GDBN}
4555 prints an error message:
4556
4557 @smallexample
4558 No symbol "foo" in current context.
4559 @end smallexample
4560
4561 @noindent
4562 @value{GDBN} does
4563 not actually evaluate @var{expression} at the time the @code{condition}
4564 command (or a command that sets a breakpoint with a condition, like
4565 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
4566
4567 @item condition @var{bnum}
4568 Remove the condition from breakpoint number @var{bnum}. It becomes
4569 an ordinary unconditional breakpoint.
4570 @end table
4571
4572 @cindex ignore count (of breakpoint)
4573 A special case of a breakpoint condition is to stop only when the
4574 breakpoint has been reached a certain number of times. This is so
4575 useful that there is a special way to do it, using the @dfn{ignore
4576 count} of the breakpoint. Every breakpoint has an ignore count, which
4577 is an integer. Most of the time, the ignore count is zero, and
4578 therefore has no effect. But if your program reaches a breakpoint whose
4579 ignore count is positive, then instead of stopping, it just decrements
4580 the ignore count by one and continues. As a result, if the ignore count
4581 value is @var{n}, the breakpoint does not stop the next @var{n} times
4582 your program reaches it.
4583
4584 @table @code
4585 @kindex ignore
4586 @item ignore @var{bnum} @var{count}
4587 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4588 The next @var{count} times the breakpoint is reached, your program's
4589 execution does not stop; other than to decrement the ignore count, @value{GDBN}
4590 takes no action.
4591
4592 To make the breakpoint stop the next time it is reached, specify
4593 a count of zero.
4594
4595 When you use @code{continue} to resume execution of your program from a
4596 breakpoint, you can specify an ignore count directly as an argument to
4597 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
4598 Stepping,,Continuing and Stepping}.
4599
4600 If a breakpoint has a positive ignore count and a condition, the
4601 condition is not checked. Once the ignore count reaches zero,
4602 @value{GDBN} resumes checking the condition.
4603
4604 You could achieve the effect of the ignore count with a condition such
4605 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4606 is decremented each time. @xref{Convenience Vars, ,Convenience
4607 Variables}.
4608 @end table
4609
4610 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4611
4612
4613 @node Break Commands
4614 @subsection Breakpoint Command Lists
4615
4616 @cindex breakpoint commands
4617 You can give any breakpoint (or watchpoint or catchpoint) a series of
4618 commands to execute when your program stops due to that breakpoint. For
4619 example, you might want to print the values of certain expressions, or
4620 enable other breakpoints.
4621
4622 @table @code
4623 @kindex commands
4624 @kindex end@r{ (breakpoint commands)}
4625 @item commands @r{[}@var{range}@dots{}@r{]}
4626 @itemx @dots{} @var{command-list} @dots{}
4627 @itemx end
4628 Specify a list of commands for the given breakpoints. The commands
4629 themselves appear on the following lines. Type a line containing just
4630 @code{end} to terminate the commands.
4631
4632 To remove all commands from a breakpoint, type @code{commands} and
4633 follow it immediately with @code{end}; that is, give no commands.
4634
4635 With no argument, @code{commands} refers to the last breakpoint,
4636 watchpoint, or catchpoint set (not to the breakpoint most recently
4637 encountered). If the most recent breakpoints were set with a single
4638 command, then the @code{commands} will apply to all the breakpoints
4639 set by that command. This applies to breakpoints set by
4640 @code{rbreak}, and also applies when a single @code{break} command
4641 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4642 Expressions}).
4643 @end table
4644
4645 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4646 disabled within a @var{command-list}.
4647
4648 You can use breakpoint commands to start your program up again. Simply
4649 use the @code{continue} command, or @code{step}, or any other command
4650 that resumes execution.
4651
4652 Any other commands in the command list, after a command that resumes
4653 execution, are ignored. This is because any time you resume execution
4654 (even with a simple @code{next} or @code{step}), you may encounter
4655 another breakpoint---which could have its own command list, leading to
4656 ambiguities about which list to execute.
4657
4658 @kindex silent
4659 If the first command you specify in a command list is @code{silent}, the
4660 usual message about stopping at a breakpoint is not printed. This may
4661 be desirable for breakpoints that are to print a specific message and
4662 then continue. If none of the remaining commands print anything, you
4663 see no sign that the breakpoint was reached. @code{silent} is
4664 meaningful only at the beginning of a breakpoint command list.
4665
4666 The commands @code{echo}, @code{output}, and @code{printf} allow you to
4667 print precisely controlled output, and are often useful in silent
4668 breakpoints. @xref{Output, ,Commands for Controlled Output}.
4669
4670 For example, here is how you could use breakpoint commands to print the
4671 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4672
4673 @smallexample
4674 break foo if x>0
4675 commands
4676 silent
4677 printf "x is %d\n",x
4678 cont
4679 end
4680 @end smallexample
4681
4682 One application for breakpoint commands is to compensate for one bug so
4683 you can test for another. Put a breakpoint just after the erroneous line
4684 of code, give it a condition to detect the case in which something
4685 erroneous has been done, and give it commands to assign correct values
4686 to any variables that need them. End with the @code{continue} command
4687 so that your program does not stop, and start with the @code{silent}
4688 command so that no output is produced. Here is an example:
4689
4690 @smallexample
4691 break 403
4692 commands
4693 silent
4694 set x = y + 4
4695 cont
4696 end
4697 @end smallexample
4698
4699 @node Dynamic Printf
4700 @subsection Dynamic Printf
4701
4702 @cindex dynamic printf
4703 @cindex dprintf
4704 The dynamic printf command @code{dprintf} combines a breakpoint with
4705 formatted printing of your program's data to give you the effect of
4706 inserting @code{printf} calls into your program on-the-fly, without
4707 having to recompile it.
4708
4709 In its most basic form, the output goes to the GDB console. However,
4710 you can set the variable @code{dprintf-style} for alternate handling.
4711 For instance, you can ask to format the output by calling your
4712 program's @code{printf} function. This has the advantage that the
4713 characters go to the program's output device, so they can recorded in
4714 redirects to files and so forth.
4715
4716 If you are doing remote debugging with a stub or agent, you can also
4717 ask to have the printf handled by the remote agent. In addition to
4718 ensuring that the output goes to the remote program's device along
4719 with any other output the program might produce, you can also ask that
4720 the dprintf remain active even after disconnecting from the remote
4721 target. Using the stub/agent is also more efficient, as it can do
4722 everything without needing to communicate with @value{GDBN}.
4723
4724 @table @code
4725 @kindex dprintf
4726 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
4727 Whenever execution reaches @var{location}, print the values of one or
4728 more @var{expressions} under the control of the string @var{template}.
4729 To print several values, separate them with commas.
4730
4731 @item set dprintf-style @var{style}
4732 Set the dprintf output to be handled in one of several different
4733 styles enumerated below. A change of style affects all existing
4734 dynamic printfs immediately. (If you need individual control over the
4735 print commands, simply define normal breakpoints with
4736 explicitly-supplied command lists.)
4737
4738 @item gdb
4739 @kindex dprintf-style gdb
4740 Handle the output using the @value{GDBN} @code{printf} command.
4741
4742 @item call
4743 @kindex dprintf-style call
4744 Handle the output by calling a function in your program (normally
4745 @code{printf}).
4746
4747 @item agent
4748 @kindex dprintf-style agent
4749 Have the remote debugging agent (such as @code{gdbserver}) handle
4750 the output itself. This style is only available for agents that
4751 support running commands on the target.
4752
4753 @item set dprintf-function @var{function}
4754 Set the function to call if the dprintf style is @code{call}. By
4755 default its value is @code{printf}. You may set it to any expression.
4756 that @value{GDBN} can evaluate to a function, as per the @code{call}
4757 command.
4758
4759 @item set dprintf-channel @var{channel}
4760 Set a ``channel'' for dprintf. If set to a non-empty value,
4761 @value{GDBN} will evaluate it as an expression and pass the result as
4762 a first argument to the @code{dprintf-function}, in the manner of
4763 @code{fprintf} and similar functions. Otherwise, the dprintf format
4764 string will be the first argument, in the manner of @code{printf}.
4765
4766 As an example, if you wanted @code{dprintf} output to go to a logfile
4767 that is a standard I/O stream assigned to the variable @code{mylog},
4768 you could do the following:
4769
4770 @example
4771 (gdb) set dprintf-style call
4772 (gdb) set dprintf-function fprintf
4773 (gdb) set dprintf-channel mylog
4774 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
4775 Dprintf 1 at 0x123456: file main.c, line 25.
4776 (gdb) info break
4777 1 dprintf keep y 0x00123456 in main at main.c:25
4778 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
4779 continue
4780 (gdb)
4781 @end example
4782
4783 Note that the @code{info break} displays the dynamic printf commands
4784 as normal breakpoint commands; you can thus easily see the effect of
4785 the variable settings.
4786
4787 @item set disconnected-dprintf on
4788 @itemx set disconnected-dprintf off
4789 @kindex set disconnected-dprintf
4790 Choose whether @code{dprintf} commands should continue to run if
4791 @value{GDBN} has disconnected from the target. This only applies
4792 if the @code{dprintf-style} is @code{agent}.
4793
4794 @item show disconnected-dprintf off
4795 @kindex show disconnected-dprintf
4796 Show the current choice for disconnected @code{dprintf}.
4797
4798 @end table
4799
4800 @value{GDBN} does not check the validity of function and channel,
4801 relying on you to supply values that are meaningful for the contexts
4802 in which they are being used. For instance, the function and channel
4803 may be the values of local variables, but if that is the case, then
4804 all enabled dynamic prints must be at locations within the scope of
4805 those locals. If evaluation fails, @value{GDBN} will report an error.
4806
4807 @node Save Breakpoints
4808 @subsection How to save breakpoints to a file
4809
4810 To save breakpoint definitions to a file use the @w{@code{save
4811 breakpoints}} command.
4812
4813 @table @code
4814 @kindex save breakpoints
4815 @cindex save breakpoints to a file for future sessions
4816 @item save breakpoints [@var{filename}]
4817 This command saves all current breakpoint definitions together with
4818 their commands and ignore counts, into a file @file{@var{filename}}
4819 suitable for use in a later debugging session. This includes all
4820 types of breakpoints (breakpoints, watchpoints, catchpoints,
4821 tracepoints). To read the saved breakpoint definitions, use the
4822 @code{source} command (@pxref{Command Files}). Note that watchpoints
4823 with expressions involving local variables may fail to be recreated
4824 because it may not be possible to access the context where the
4825 watchpoint is valid anymore. Because the saved breakpoint definitions
4826 are simply a sequence of @value{GDBN} commands that recreate the
4827 breakpoints, you can edit the file in your favorite editing program,
4828 and remove the breakpoint definitions you're not interested in, or
4829 that can no longer be recreated.
4830 @end table
4831
4832 @node Static Probe Points
4833 @subsection Static Probe Points
4834
4835 @cindex static probe point, SystemTap
4836 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
4837 for Statically Defined Tracing, and the probes are designed to have a tiny
4838 runtime code and data footprint, and no dynamic relocations. They are
4839 usable from assembly, C and C@t{++} languages. See
4840 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
4841 for a good reference on how the @acronym{SDT} probes are implemented.
4842
4843 Currently, @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
4844 @acronym{SDT} probes are supported on ELF-compatible systems. See
4845 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
4846 for more information on how to add @code{SystemTap} @acronym{SDT} probes
4847 in your applications.
4848
4849 @cindex semaphores on static probe points
4850 Some probes have an associated semaphore variable; for instance, this
4851 happens automatically if you defined your probe using a DTrace-style
4852 @file{.d} file. If your probe has a semaphore, @value{GDBN} will
4853 automatically enable it when you specify a breakpoint using the
4854 @samp{-probe-stap} notation. But, if you put a breakpoint at a probe's
4855 location by some other method (e.g., @code{break file:line}), then
4856 @value{GDBN} will not automatically set the semaphore.
4857
4858 You can examine the available static static probes using @code{info
4859 probes}, with optional arguments:
4860
4861 @table @code
4862 @kindex info probes
4863 @item info probes stap @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
4864 If given, @var{provider} is a regular expression used to match against provider
4865 names when selecting which probes to list. If omitted, probes by all
4866 probes from all providers are listed.
4867
4868 If given, @var{name} is a regular expression to match against probe names
4869 when selecting which probes to list. If omitted, probe names are not
4870 considered when deciding whether to display them.
4871
4872 If given, @var{objfile} is a regular expression used to select which
4873 object files (executable or shared libraries) to examine. If not
4874 given, all object files are considered.
4875
4876 @item info probes all
4877 List the available static probes, from all types.
4878 @end table
4879
4880 @vindex $_probe_arg@r{, convenience variable}
4881 A probe may specify up to twelve arguments. These are available at the
4882 point at which the probe is defined---that is, when the current PC is
4883 at the probe's location. The arguments are available using the
4884 convenience variables (@pxref{Convenience Vars})
4885 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. Each probe argument is
4886 an integer of the appropriate size; types are not preserved. The
4887 convenience variable @code{$_probe_argc} holds the number of arguments
4888 at the current probe point.
4889
4890 These variables are always available, but attempts to access them at
4891 any location other than a probe point will cause @value{GDBN} to give
4892 an error message.
4893
4894
4895 @c @ifclear BARETARGET
4896 @node Error in Breakpoints
4897 @subsection ``Cannot insert breakpoints''
4898
4899 If you request too many active hardware-assisted breakpoints and
4900 watchpoints, you will see this error message:
4901
4902 @c FIXME: the precise wording of this message may change; the relevant
4903 @c source change is not committed yet (Sep 3, 1999).
4904 @smallexample
4905 Stopped; cannot insert breakpoints.
4906 You may have requested too many hardware breakpoints and watchpoints.
4907 @end smallexample
4908
4909 @noindent
4910 This message is printed when you attempt to resume the program, since
4911 only then @value{GDBN} knows exactly how many hardware breakpoints and
4912 watchpoints it needs to insert.
4913
4914 When this message is printed, you need to disable or remove some of the
4915 hardware-assisted breakpoints and watchpoints, and then continue.
4916
4917 @node Breakpoint-related Warnings
4918 @subsection ``Breakpoint address adjusted...''
4919 @cindex breakpoint address adjusted
4920
4921 Some processor architectures place constraints on the addresses at
4922 which breakpoints may be placed. For architectures thus constrained,
4923 @value{GDBN} will attempt to adjust the breakpoint's address to comply
4924 with the constraints dictated by the architecture.
4925
4926 One example of such an architecture is the Fujitsu FR-V. The FR-V is
4927 a VLIW architecture in which a number of RISC-like instructions may be
4928 bundled together for parallel execution. The FR-V architecture
4929 constrains the location of a breakpoint instruction within such a
4930 bundle to the instruction with the lowest address. @value{GDBN}
4931 honors this constraint by adjusting a breakpoint's address to the
4932 first in the bundle.
4933
4934 It is not uncommon for optimized code to have bundles which contain
4935 instructions from different source statements, thus it may happen that
4936 a breakpoint's address will be adjusted from one source statement to
4937 another. Since this adjustment may significantly alter @value{GDBN}'s
4938 breakpoint related behavior from what the user expects, a warning is
4939 printed when the breakpoint is first set and also when the breakpoint
4940 is hit.
4941
4942 A warning like the one below is printed when setting a breakpoint
4943 that's been subject to address adjustment:
4944
4945 @smallexample
4946 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4947 @end smallexample
4948
4949 Such warnings are printed both for user settable and @value{GDBN}'s
4950 internal breakpoints. If you see one of these warnings, you should
4951 verify that a breakpoint set at the adjusted address will have the
4952 desired affect. If not, the breakpoint in question may be removed and
4953 other breakpoints may be set which will have the desired behavior.
4954 E.g., it may be sufficient to place the breakpoint at a later
4955 instruction. A conditional breakpoint may also be useful in some
4956 cases to prevent the breakpoint from triggering too often.
4957
4958 @value{GDBN} will also issue a warning when stopping at one of these
4959 adjusted breakpoints:
4960
4961 @smallexample
4962 warning: Breakpoint 1 address previously adjusted from 0x00010414
4963 to 0x00010410.
4964 @end smallexample
4965
4966 When this warning is encountered, it may be too late to take remedial
4967 action except in cases where the breakpoint is hit earlier or more
4968 frequently than expected.
4969
4970 @node Continuing and Stepping
4971 @section Continuing and Stepping
4972
4973 @cindex stepping
4974 @cindex continuing
4975 @cindex resuming execution
4976 @dfn{Continuing} means resuming program execution until your program
4977 completes normally. In contrast, @dfn{stepping} means executing just
4978 one more ``step'' of your program, where ``step'' may mean either one
4979 line of source code, or one machine instruction (depending on what
4980 particular command you use). Either when continuing or when stepping,
4981 your program may stop even sooner, due to a breakpoint or a signal. (If
4982 it stops due to a signal, you may want to use @code{handle}, or use
4983 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
4984
4985 @table @code
4986 @kindex continue
4987 @kindex c @r{(@code{continue})}
4988 @kindex fg @r{(resume foreground execution)}
4989 @item continue @r{[}@var{ignore-count}@r{]}
4990 @itemx c @r{[}@var{ignore-count}@r{]}
4991 @itemx fg @r{[}@var{ignore-count}@r{]}
4992 Resume program execution, at the address where your program last stopped;
4993 any breakpoints set at that address are bypassed. The optional argument
4994 @var{ignore-count} allows you to specify a further number of times to
4995 ignore a breakpoint at this location; its effect is like that of
4996 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
4997
4998 The argument @var{ignore-count} is meaningful only when your program
4999 stopped due to a breakpoint. At other times, the argument to
5000 @code{continue} is ignored.
5001
5002 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5003 debugged program is deemed to be the foreground program) are provided
5004 purely for convenience, and have exactly the same behavior as
5005 @code{continue}.
5006 @end table
5007
5008 To resume execution at a different place, you can use @code{return}
5009 (@pxref{Returning, ,Returning from a Function}) to go back to the
5010 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
5011 Different Address}) to go to an arbitrary location in your program.
5012
5013 A typical technique for using stepping is to set a breakpoint
5014 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
5015 beginning of the function or the section of your program where a problem
5016 is believed to lie, run your program until it stops at that breakpoint,
5017 and then step through the suspect area, examining the variables that are
5018 interesting, until you see the problem happen.
5019
5020 @table @code
5021 @kindex step
5022 @kindex s @r{(@code{step})}
5023 @item step
5024 Continue running your program until control reaches a different source
5025 line, then stop it and return control to @value{GDBN}. This command is
5026 abbreviated @code{s}.
5027
5028 @quotation
5029 @c "without debugging information" is imprecise; actually "without line
5030 @c numbers in the debugging information". (gcc -g1 has debugging info but
5031 @c not line numbers). But it seems complex to try to make that
5032 @c distinction here.
5033 @emph{Warning:} If you use the @code{step} command while control is
5034 within a function that was compiled without debugging information,
5035 execution proceeds until control reaches a function that does have
5036 debugging information. Likewise, it will not step into a function which
5037 is compiled without debugging information. To step through functions
5038 without debugging information, use the @code{stepi} command, described
5039 below.
5040 @end quotation
5041
5042 The @code{step} command only stops at the first instruction of a source
5043 line. This prevents the multiple stops that could otherwise occur in
5044 @code{switch} statements, @code{for} loops, etc. @code{step} continues
5045 to stop if a function that has debugging information is called within
5046 the line. In other words, @code{step} @emph{steps inside} any functions
5047 called within the line.
5048
5049 Also, the @code{step} command only enters a function if there is line
5050 number information for the function. Otherwise it acts like the
5051 @code{next} command. This avoids problems when using @code{cc -gl}
5052 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5053 was any debugging information about the routine.
5054
5055 @item step @var{count}
5056 Continue running as in @code{step}, but do so @var{count} times. If a
5057 breakpoint is reached, or a signal not related to stepping occurs before
5058 @var{count} steps, stepping stops right away.
5059
5060 @kindex next
5061 @kindex n @r{(@code{next})}
5062 @item next @r{[}@var{count}@r{]}
5063 Continue to the next source line in the current (innermost) stack frame.
5064 This is similar to @code{step}, but function calls that appear within
5065 the line of code are executed without stopping. Execution stops when
5066 control reaches a different line of code at the original stack level
5067 that was executing when you gave the @code{next} command. This command
5068 is abbreviated @code{n}.
5069
5070 An argument @var{count} is a repeat count, as for @code{step}.
5071
5072
5073 @c FIX ME!! Do we delete this, or is there a way it fits in with
5074 @c the following paragraph? --- Vctoria
5075 @c
5076 @c @code{next} within a function that lacks debugging information acts like
5077 @c @code{step}, but any function calls appearing within the code of the
5078 @c function are executed without stopping.
5079
5080 The @code{next} command only stops at the first instruction of a
5081 source line. This prevents multiple stops that could otherwise occur in
5082 @code{switch} statements, @code{for} loops, etc.
5083
5084 @kindex set step-mode
5085 @item set step-mode
5086 @cindex functions without line info, and stepping
5087 @cindex stepping into functions with no line info
5088 @itemx set step-mode on
5089 The @code{set step-mode on} command causes the @code{step} command to
5090 stop at the first instruction of a function which contains no debug line
5091 information rather than stepping over it.
5092
5093 This is useful in cases where you may be interested in inspecting the
5094 machine instructions of a function which has no symbolic info and do not
5095 want @value{GDBN} to automatically skip over this function.
5096
5097 @item set step-mode off
5098 Causes the @code{step} command to step over any functions which contains no
5099 debug information. This is the default.
5100
5101 @item show step-mode
5102 Show whether @value{GDBN} will stop in or step over functions without
5103 source line debug information.
5104
5105 @kindex finish
5106 @kindex fin @r{(@code{finish})}
5107 @item finish
5108 Continue running until just after function in the selected stack frame
5109 returns. Print the returned value (if any). This command can be
5110 abbreviated as @code{fin}.
5111
5112 Contrast this with the @code{return} command (@pxref{Returning,
5113 ,Returning from a Function}).
5114
5115 @kindex until
5116 @kindex u @r{(@code{until})}
5117 @cindex run until specified location
5118 @item until
5119 @itemx u
5120 Continue running until a source line past the current line, in the
5121 current stack frame, is reached. This command is used to avoid single
5122 stepping through a loop more than once. It is like the @code{next}
5123 command, except that when @code{until} encounters a jump, it
5124 automatically continues execution until the program counter is greater
5125 than the address of the jump.
5126
5127 This means that when you reach the end of a loop after single stepping
5128 though it, @code{until} makes your program continue execution until it
5129 exits the loop. In contrast, a @code{next} command at the end of a loop
5130 simply steps back to the beginning of the loop, which forces you to step
5131 through the next iteration.
5132
5133 @code{until} always stops your program if it attempts to exit the current
5134 stack frame.
5135
5136 @code{until} may produce somewhat counterintuitive results if the order
5137 of machine code does not match the order of the source lines. For
5138 example, in the following excerpt from a debugging session, the @code{f}
5139 (@code{frame}) command shows that execution is stopped at line
5140 @code{206}; yet when we use @code{until}, we get to line @code{195}:
5141
5142 @smallexample
5143 (@value{GDBP}) f
5144 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5145 206 expand_input();
5146 (@value{GDBP}) until
5147 195 for ( ; argc > 0; NEXTARG) @{
5148 @end smallexample
5149
5150 This happened because, for execution efficiency, the compiler had
5151 generated code for the loop closure test at the end, rather than the
5152 start, of the loop---even though the test in a C @code{for}-loop is
5153 written before the body of the loop. The @code{until} command appeared
5154 to step back to the beginning of the loop when it advanced to this
5155 expression; however, it has not really gone to an earlier
5156 statement---not in terms of the actual machine code.
5157
5158 @code{until} with no argument works by means of single
5159 instruction stepping, and hence is slower than @code{until} with an
5160 argument.
5161
5162 @item until @var{location}
5163 @itemx u @var{location}
5164 Continue running your program until either the specified location is
5165 reached, or the current stack frame returns. @var{location} is any of
5166 the forms described in @ref{Specify Location}.
5167 This form of the command uses temporary breakpoints, and
5168 hence is quicker than @code{until} without an argument. The specified
5169 location is actually reached only if it is in the current frame. This
5170 implies that @code{until} can be used to skip over recursive function
5171 invocations. For instance in the code below, if the current location is
5172 line @code{96}, issuing @code{until 99} will execute the program up to
5173 line @code{99} in the same invocation of factorial, i.e., after the inner
5174 invocations have returned.
5175
5176 @smallexample
5177 94 int factorial (int value)
5178 95 @{
5179 96 if (value > 1) @{
5180 97 value *= factorial (value - 1);
5181 98 @}
5182 99 return (value);
5183 100 @}
5184 @end smallexample
5185
5186
5187 @kindex advance @var{location}
5188 @item advance @var{location}
5189 Continue running the program up to the given @var{location}. An argument is
5190 required, which should be of one of the forms described in
5191 @ref{Specify Location}.
5192 Execution will also stop upon exit from the current stack
5193 frame. This command is similar to @code{until}, but @code{advance} will
5194 not skip over recursive function calls, and the target location doesn't
5195 have to be in the same frame as the current one.
5196
5197
5198 @kindex stepi
5199 @kindex si @r{(@code{stepi})}
5200 @item stepi
5201 @itemx stepi @var{arg}
5202 @itemx si
5203 Execute one machine instruction, then stop and return to the debugger.
5204
5205 It is often useful to do @samp{display/i $pc} when stepping by machine
5206 instructions. This makes @value{GDBN} automatically display the next
5207 instruction to be executed, each time your program stops. @xref{Auto
5208 Display,, Automatic Display}.
5209
5210 An argument is a repeat count, as in @code{step}.
5211
5212 @need 750
5213 @kindex nexti
5214 @kindex ni @r{(@code{nexti})}
5215 @item nexti
5216 @itemx nexti @var{arg}
5217 @itemx ni
5218 Execute one machine instruction, but if it is a function call,
5219 proceed until the function returns.
5220
5221 An argument is a repeat count, as in @code{next}.
5222
5223 @end table
5224
5225 @anchor{range stepping}
5226 @cindex range stepping
5227 @cindex target-assisted range stepping
5228 By default, and if available, @value{GDBN} makes use of
5229 target-assisted @dfn{range stepping}. In other words, whenever you
5230 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
5231 tells the target to step the corresponding range of instruction
5232 addresses instead of issuing multiple single-steps. This speeds up
5233 line stepping, particularly for remote targets. Ideally, there should
5234 be no reason you would want to turn range stepping off. However, it's
5235 possible that a bug in the debug info, a bug in the remote stub (for
5236 remote targets), or even a bug in @value{GDBN} could make line
5237 stepping behave incorrectly when target-assisted range stepping is
5238 enabled. You can use the following command to turn off range stepping
5239 if necessary:
5240
5241 @table @code
5242 @kindex set range-stepping
5243 @kindex show range-stepping
5244 @item set range-stepping
5245 @itemx show range-stepping
5246 Control whether range stepping is enabled.
5247
5248 If @code{on}, and the target supports it, @value{GDBN} tells the
5249 target to step a range of addresses itself, instead of issuing
5250 multiple single-steps. If @code{off}, @value{GDBN} always issues
5251 single-steps, even if range stepping is supported by the target. The
5252 default is @code{on}.
5253
5254 @end table
5255
5256 @node Skipping Over Functions and Files
5257 @section Skipping Over Functions and Files
5258 @cindex skipping over functions and files
5259
5260 The program you are debugging may contain some functions which are
5261 uninteresting to debug. The @code{skip} comand lets you tell @value{GDBN} to
5262 skip a function or all functions in a file when stepping.
5263
5264 For example, consider the following C function:
5265
5266 @smallexample
5267 101 int func()
5268 102 @{
5269 103 foo(boring());
5270 104 bar(boring());
5271 105 @}
5272 @end smallexample
5273
5274 @noindent
5275 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5276 are not interested in stepping through @code{boring}. If you run @code{step}
5277 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5278 step over both @code{foo} and @code{boring}!
5279
5280 One solution is to @code{step} into @code{boring} and use the @code{finish}
5281 command to immediately exit it. But this can become tedious if @code{boring}
5282 is called from many places.
5283
5284 A more flexible solution is to execute @kbd{skip boring}. This instructs
5285 @value{GDBN} never to step into @code{boring}. Now when you execute
5286 @code{step} at line 103, you'll step over @code{boring} and directly into
5287 @code{foo}.
5288
5289 You can also instruct @value{GDBN} to skip all functions in a file, with, for
5290 example, @code{skip file boring.c}.
5291
5292 @table @code
5293 @kindex skip function
5294 @item skip @r{[}@var{linespec}@r{]}
5295 @itemx skip function @r{[}@var{linespec}@r{]}
5296 After running this command, the function named by @var{linespec} or the
5297 function containing the line named by @var{linespec} will be skipped over when
5298 stepping. @xref{Specify Location}.
5299
5300 If you do not specify @var{linespec}, the function you're currently debugging
5301 will be skipped.
5302
5303 (If you have a function called @code{file} that you want to skip, use
5304 @kbd{skip function file}.)
5305
5306 @kindex skip file
5307 @item skip file @r{[}@var{filename}@r{]}
5308 After running this command, any function whose source lives in @var{filename}
5309 will be skipped over when stepping.
5310
5311 If you do not specify @var{filename}, functions whose source lives in the file
5312 you're currently debugging will be skipped.
5313 @end table
5314
5315 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5316 These are the commands for managing your list of skips:
5317
5318 @table @code
5319 @kindex info skip
5320 @item info skip @r{[}@var{range}@r{]}
5321 Print details about the specified skip(s). If @var{range} is not specified,
5322 print a table with details about all functions and files marked for skipping.
5323 @code{info skip} prints the following information about each skip:
5324
5325 @table @emph
5326 @item Identifier
5327 A number identifying this skip.
5328 @item Type
5329 The type of this skip, either @samp{function} or @samp{file}.
5330 @item Enabled or Disabled
5331 Enabled skips are marked with @samp{y}. Disabled skips are marked with @samp{n}.
5332 @item Address
5333 For function skips, this column indicates the address in memory of the function
5334 being skipped. If you've set a function skip on a function which has not yet
5335 been loaded, this field will contain @samp{<PENDING>}. Once a shared library
5336 which has the function is loaded, @code{info skip} will show the function's
5337 address here.
5338 @item What
5339 For file skips, this field contains the filename being skipped. For functions
5340 skips, this field contains the function name and its line number in the file
5341 where it is defined.
5342 @end table
5343
5344 @kindex skip delete
5345 @item skip delete @r{[}@var{range}@r{]}
5346 Delete the specified skip(s). If @var{range} is not specified, delete all
5347 skips.
5348
5349 @kindex skip enable
5350 @item skip enable @r{[}@var{range}@r{]}
5351 Enable the specified skip(s). If @var{range} is not specified, enable all
5352 skips.
5353
5354 @kindex skip disable
5355 @item skip disable @r{[}@var{range}@r{]}
5356 Disable the specified skip(s). If @var{range} is not specified, disable all
5357 skips.
5358
5359 @end table
5360
5361 @node Signals
5362 @section Signals
5363 @cindex signals
5364
5365 A signal is an asynchronous event that can happen in a program. The
5366 operating system defines the possible kinds of signals, and gives each
5367 kind a name and a number. For example, in Unix @code{SIGINT} is the
5368 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
5369 @code{SIGSEGV} is the signal a program gets from referencing a place in
5370 memory far away from all the areas in use; @code{SIGALRM} occurs when
5371 the alarm clock timer goes off (which happens only if your program has
5372 requested an alarm).
5373
5374 @cindex fatal signals
5375 Some signals, including @code{SIGALRM}, are a normal part of the
5376 functioning of your program. Others, such as @code{SIGSEGV}, indicate
5377 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
5378 program has not specified in advance some other way to handle the signal.
5379 @code{SIGINT} does not indicate an error in your program, but it is normally
5380 fatal so it can carry out the purpose of the interrupt: to kill the program.
5381
5382 @value{GDBN} has the ability to detect any occurrence of a signal in your
5383 program. You can tell @value{GDBN} in advance what to do for each kind of
5384 signal.
5385
5386 @cindex handling signals
5387 Normally, @value{GDBN} is set up to let the non-erroneous signals like
5388 @code{SIGALRM} be silently passed to your program
5389 (so as not to interfere with their role in the program's functioning)
5390 but to stop your program immediately whenever an error signal happens.
5391 You can change these settings with the @code{handle} command.
5392
5393 @table @code
5394 @kindex info signals
5395 @kindex info handle
5396 @item info signals
5397 @itemx info handle
5398 Print a table of all the kinds of signals and how @value{GDBN} has been told to
5399 handle each one. You can use this to see the signal numbers of all
5400 the defined types of signals.
5401
5402 @item info signals @var{sig}
5403 Similar, but print information only about the specified signal number.
5404
5405 @code{info handle} is an alias for @code{info signals}.
5406
5407 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5408 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
5409 for details about this command.
5410
5411 @kindex handle
5412 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
5413 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
5414 can be the number of a signal or its name (with or without the
5415 @samp{SIG} at the beginning); a list of signal numbers of the form
5416 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
5417 known signals. Optional arguments @var{keywords}, described below,
5418 say what change to make.
5419 @end table
5420
5421 @c @group
5422 The keywords allowed by the @code{handle} command can be abbreviated.
5423 Their full names are:
5424
5425 @table @code
5426 @item nostop
5427 @value{GDBN} should not stop your program when this signal happens. It may
5428 still print a message telling you that the signal has come in.
5429
5430 @item stop
5431 @value{GDBN} should stop your program when this signal happens. This implies
5432 the @code{print} keyword as well.
5433
5434 @item print
5435 @value{GDBN} should print a message when this signal happens.
5436
5437 @item noprint
5438 @value{GDBN} should not mention the occurrence of the signal at all. This
5439 implies the @code{nostop} keyword as well.
5440
5441 @item pass
5442 @itemx noignore
5443 @value{GDBN} should allow your program to see this signal; your program
5444 can handle the signal, or else it may terminate if the signal is fatal
5445 and not handled. @code{pass} and @code{noignore} are synonyms.
5446
5447 @item nopass
5448 @itemx ignore
5449 @value{GDBN} should not allow your program to see this signal.
5450 @code{nopass} and @code{ignore} are synonyms.
5451 @end table
5452 @c @end group
5453
5454 When a signal stops your program, the signal is not visible to the
5455 program until you
5456 continue. Your program sees the signal then, if @code{pass} is in
5457 effect for the signal in question @emph{at that time}. In other words,
5458 after @value{GDBN} reports a signal, you can use the @code{handle}
5459 command with @code{pass} or @code{nopass} to control whether your
5460 program sees that signal when you continue.
5461
5462 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
5463 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
5464 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
5465 erroneous signals.
5466
5467 You can also use the @code{signal} command to prevent your program from
5468 seeing a signal, or cause it to see a signal it normally would not see,
5469 or to give it any signal at any time. For example, if your program stopped
5470 due to some sort of memory reference error, you might store correct
5471 values into the erroneous variables and continue, hoping to see more
5472 execution; but your program would probably terminate immediately as
5473 a result of the fatal signal once it saw the signal. To prevent this,
5474 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
5475 Program a Signal}.
5476
5477 @cindex extra signal information
5478 @anchor{extra signal information}
5479
5480 On some targets, @value{GDBN} can inspect extra signal information
5481 associated with the intercepted signal, before it is actually
5482 delivered to the program being debugged. This information is exported
5483 by the convenience variable @code{$_siginfo}, and consists of data
5484 that is passed by the kernel to the signal handler at the time of the
5485 receipt of a signal. The data type of the information itself is
5486 target dependent. You can see the data type using the @code{ptype
5487 $_siginfo} command. On Unix systems, it typically corresponds to the
5488 standard @code{siginfo_t} type, as defined in the @file{signal.h}
5489 system header.
5490
5491 Here's an example, on a @sc{gnu}/Linux system, printing the stray
5492 referenced address that raised a segmentation fault.
5493
5494 @smallexample
5495 @group
5496 (@value{GDBP}) continue
5497 Program received signal SIGSEGV, Segmentation fault.
5498 0x0000000000400766 in main ()
5499 69 *(int *)p = 0;
5500 (@value{GDBP}) ptype $_siginfo
5501 type = struct @{
5502 int si_signo;
5503 int si_errno;
5504 int si_code;
5505 union @{
5506 int _pad[28];
5507 struct @{...@} _kill;
5508 struct @{...@} _timer;
5509 struct @{...@} _rt;
5510 struct @{...@} _sigchld;
5511 struct @{...@} _sigfault;
5512 struct @{...@} _sigpoll;
5513 @} _sifields;
5514 @}
5515 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
5516 type = struct @{
5517 void *si_addr;
5518 @}
5519 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
5520 $1 = (void *) 0x7ffff7ff7000
5521 @end group
5522 @end smallexample
5523
5524 Depending on target support, @code{$_siginfo} may also be writable.
5525
5526 @node Thread Stops
5527 @section Stopping and Starting Multi-thread Programs
5528
5529 @cindex stopped threads
5530 @cindex threads, stopped
5531
5532 @cindex continuing threads
5533 @cindex threads, continuing
5534
5535 @value{GDBN} supports debugging programs with multiple threads
5536 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
5537 are two modes of controlling execution of your program within the
5538 debugger. In the default mode, referred to as @dfn{all-stop mode},
5539 when any thread in your program stops (for example, at a breakpoint
5540 or while being stepped), all other threads in the program are also stopped by
5541 @value{GDBN}. On some targets, @value{GDBN} also supports
5542 @dfn{non-stop mode}, in which other threads can continue to run freely while
5543 you examine the stopped thread in the debugger.
5544
5545 @menu
5546 * All-Stop Mode:: All threads stop when GDB takes control
5547 * Non-Stop Mode:: Other threads continue to execute
5548 * Background Execution:: Running your program asynchronously
5549 * Thread-Specific Breakpoints:: Controlling breakpoints
5550 * Interrupted System Calls:: GDB may interfere with system calls
5551 * Observer Mode:: GDB does not alter program behavior
5552 @end menu
5553
5554 @node All-Stop Mode
5555 @subsection All-Stop Mode
5556
5557 @cindex all-stop mode
5558
5559 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
5560 @emph{all} threads of execution stop, not just the current thread. This
5561 allows you to examine the overall state of the program, including
5562 switching between threads, without worrying that things may change
5563 underfoot.
5564
5565 Conversely, whenever you restart the program, @emph{all} threads start
5566 executing. @emph{This is true even when single-stepping} with commands
5567 like @code{step} or @code{next}.
5568
5569 In particular, @value{GDBN} cannot single-step all threads in lockstep.
5570 Since thread scheduling is up to your debugging target's operating
5571 system (not controlled by @value{GDBN}), other threads may
5572 execute more than one statement while the current thread completes a
5573 single step. Moreover, in general other threads stop in the middle of a
5574 statement, rather than at a clean statement boundary, when the program
5575 stops.
5576
5577 You might even find your program stopped in another thread after
5578 continuing or even single-stepping. This happens whenever some other
5579 thread runs into a breakpoint, a signal, or an exception before the
5580 first thread completes whatever you requested.
5581
5582 @cindex automatic thread selection
5583 @cindex switching threads automatically
5584 @cindex threads, automatic switching
5585 Whenever @value{GDBN} stops your program, due to a breakpoint or a
5586 signal, it automatically selects the thread where that breakpoint or
5587 signal happened. @value{GDBN} alerts you to the context switch with a
5588 message such as @samp{[Switching to Thread @var{n}]} to identify the
5589 thread.
5590
5591 On some OSes, you can modify @value{GDBN}'s default behavior by
5592 locking the OS scheduler to allow only a single thread to run.
5593
5594 @table @code
5595 @item set scheduler-locking @var{mode}
5596 @cindex scheduler locking mode
5597 @cindex lock scheduler
5598 Set the scheduler locking mode. If it is @code{off}, then there is no
5599 locking and any thread may run at any time. If @code{on}, then only the
5600 current thread may run when the inferior is resumed. The @code{step}
5601 mode optimizes for single-stepping; it prevents other threads
5602 from preempting the current thread while you are stepping, so that
5603 the focus of debugging does not change unexpectedly.
5604 Other threads only rarely (or never) get a chance to run
5605 when you step. They are more likely to run when you @samp{next} over a
5606 function call, and they are completely free to run when you use commands
5607 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5608 thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5609 the current thread away from the thread that you are debugging.
5610
5611 @item show scheduler-locking
5612 Display the current scheduler locking mode.
5613 @end table
5614
5615 @cindex resume threads of multiple processes simultaneously
5616 By default, when you issue one of the execution commands such as
5617 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5618 threads of the current inferior to run. For example, if @value{GDBN}
5619 is attached to two inferiors, each with two threads, the
5620 @code{continue} command resumes only the two threads of the current
5621 inferior. This is useful, for example, when you debug a program that
5622 forks and you want to hold the parent stopped (so that, for instance,
5623 it doesn't run to exit), while you debug the child. In other
5624 situations, you may not be interested in inspecting the current state
5625 of any of the processes @value{GDBN} is attached to, and you may want
5626 to resume them all until some breakpoint is hit. In the latter case,
5627 you can instruct @value{GDBN} to allow all threads of all the
5628 inferiors to run with the @w{@code{set schedule-multiple}} command.
5629
5630 @table @code
5631 @kindex set schedule-multiple
5632 @item set schedule-multiple
5633 Set the mode for allowing threads of multiple processes to be resumed
5634 when an execution command is issued. When @code{on}, all threads of
5635 all processes are allowed to run. When @code{off}, only the threads
5636 of the current process are resumed. The default is @code{off}. The
5637 @code{scheduler-locking} mode takes precedence when set to @code{on},
5638 or while you are stepping and set to @code{step}.
5639
5640 @item show schedule-multiple
5641 Display the current mode for resuming the execution of threads of
5642 multiple processes.
5643 @end table
5644
5645 @node Non-Stop Mode
5646 @subsection Non-Stop Mode
5647
5648 @cindex non-stop mode
5649
5650 @c This section is really only a place-holder, and needs to be expanded
5651 @c with more details.
5652
5653 For some multi-threaded targets, @value{GDBN} supports an optional
5654 mode of operation in which you can examine stopped program threads in
5655 the debugger while other threads continue to execute freely. This
5656 minimizes intrusion when debugging live systems, such as programs
5657 where some threads have real-time constraints or must continue to
5658 respond to external events. This is referred to as @dfn{non-stop} mode.
5659
5660 In non-stop mode, when a thread stops to report a debugging event,
5661 @emph{only} that thread is stopped; @value{GDBN} does not stop other
5662 threads as well, in contrast to the all-stop mode behavior. Additionally,
5663 execution commands such as @code{continue} and @code{step} apply by default
5664 only to the current thread in non-stop mode, rather than all threads as
5665 in all-stop mode. This allows you to control threads explicitly in
5666 ways that are not possible in all-stop mode --- for example, stepping
5667 one thread while allowing others to run freely, stepping
5668 one thread while holding all others stopped, or stepping several threads
5669 independently and simultaneously.
5670
5671 To enter non-stop mode, use this sequence of commands before you run
5672 or attach to your program:
5673
5674 @smallexample
5675 # Enable the async interface.
5676 set target-async 1
5677
5678 # If using the CLI, pagination breaks non-stop.
5679 set pagination off
5680
5681 # Finally, turn it on!
5682 set non-stop on
5683 @end smallexample
5684
5685 You can use these commands to manipulate the non-stop mode setting:
5686
5687 @table @code
5688 @kindex set non-stop
5689 @item set non-stop on
5690 Enable selection of non-stop mode.
5691 @item set non-stop off
5692 Disable selection of non-stop mode.
5693 @kindex show non-stop
5694 @item show non-stop
5695 Show the current non-stop enablement setting.
5696 @end table
5697
5698 Note these commands only reflect whether non-stop mode is enabled,
5699 not whether the currently-executing program is being run in non-stop mode.
5700 In particular, the @code{set non-stop} preference is only consulted when
5701 @value{GDBN} starts or connects to the target program, and it is generally
5702 not possible to switch modes once debugging has started. Furthermore,
5703 since not all targets support non-stop mode, even when you have enabled
5704 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5705 default.
5706
5707 In non-stop mode, all execution commands apply only to the current thread
5708 by default. That is, @code{continue} only continues one thread.
5709 To continue all threads, issue @code{continue -a} or @code{c -a}.
5710
5711 You can use @value{GDBN}'s background execution commands
5712 (@pxref{Background Execution}) to run some threads in the background
5713 while you continue to examine or step others from @value{GDBN}.
5714 The MI execution commands (@pxref{GDB/MI Program Execution}) are
5715 always executed asynchronously in non-stop mode.
5716
5717 Suspending execution is done with the @code{interrupt} command when
5718 running in the background, or @kbd{Ctrl-c} during foreground execution.
5719 In all-stop mode, this stops the whole process;
5720 but in non-stop mode the interrupt applies only to the current thread.
5721 To stop the whole program, use @code{interrupt -a}.
5722
5723 Other execution commands do not currently support the @code{-a} option.
5724
5725 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5726 that thread current, as it does in all-stop mode. This is because the
5727 thread stop notifications are asynchronous with respect to @value{GDBN}'s
5728 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5729 changed to a different thread just as you entered a command to operate on the
5730 previously current thread.
5731
5732 @node Background Execution
5733 @subsection Background Execution
5734
5735 @cindex foreground execution
5736 @cindex background execution
5737 @cindex asynchronous execution
5738 @cindex execution, foreground, background and asynchronous
5739
5740 @value{GDBN}'s execution commands have two variants: the normal
5741 foreground (synchronous) behavior, and a background
5742 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5743 the program to report that some thread has stopped before prompting for
5744 another command. In background execution, @value{GDBN} immediately gives
5745 a command prompt so that you can issue other commands while your program runs.
5746
5747 You need to explicitly enable asynchronous mode before you can use
5748 background execution commands. You can use these commands to
5749 manipulate the asynchronous mode setting:
5750
5751 @table @code
5752 @kindex set target-async
5753 @item set target-async on
5754 Enable asynchronous mode.
5755 @item set target-async off
5756 Disable asynchronous mode.
5757 @kindex show target-async
5758 @item show target-async
5759 Show the current target-async setting.
5760 @end table
5761
5762 If the target doesn't support async mode, @value{GDBN} issues an error
5763 message if you attempt to use the background execution commands.
5764
5765 To specify background execution, add a @code{&} to the command. For example,
5766 the background form of the @code{continue} command is @code{continue&}, or
5767 just @code{c&}. The execution commands that accept background execution
5768 are:
5769
5770 @table @code
5771 @kindex run&
5772 @item run
5773 @xref{Starting, , Starting your Program}.
5774
5775 @item attach
5776 @kindex attach&
5777 @xref{Attach, , Debugging an Already-running Process}.
5778
5779 @item step
5780 @kindex step&
5781 @xref{Continuing and Stepping, step}.
5782
5783 @item stepi
5784 @kindex stepi&
5785 @xref{Continuing and Stepping, stepi}.
5786
5787 @item next
5788 @kindex next&
5789 @xref{Continuing and Stepping, next}.
5790
5791 @item nexti
5792 @kindex nexti&
5793 @xref{Continuing and Stepping, nexti}.
5794
5795 @item continue
5796 @kindex continue&
5797 @xref{Continuing and Stepping, continue}.
5798
5799 @item finish
5800 @kindex finish&
5801 @xref{Continuing and Stepping, finish}.
5802
5803 @item until
5804 @kindex until&
5805 @xref{Continuing and Stepping, until}.
5806
5807 @end table
5808
5809 Background execution is especially useful in conjunction with non-stop
5810 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5811 However, you can also use these commands in the normal all-stop mode with
5812 the restriction that you cannot issue another execution command until the
5813 previous one finishes. Examples of commands that are valid in all-stop
5814 mode while the program is running include @code{help} and @code{info break}.
5815
5816 You can interrupt your program while it is running in the background by
5817 using the @code{interrupt} command.
5818
5819 @table @code
5820 @kindex interrupt
5821 @item interrupt
5822 @itemx interrupt -a
5823
5824 Suspend execution of the running program. In all-stop mode,
5825 @code{interrupt} stops the whole process, but in non-stop mode, it stops
5826 only the current thread. To stop the whole program in non-stop mode,
5827 use @code{interrupt -a}.
5828 @end table
5829
5830 @node Thread-Specific Breakpoints
5831 @subsection Thread-Specific Breakpoints
5832
5833 When your program has multiple threads (@pxref{Threads,, Debugging
5834 Programs with Multiple Threads}), you can choose whether to set
5835 breakpoints on all threads, or on a particular thread.
5836
5837 @table @code
5838 @cindex breakpoints and threads
5839 @cindex thread breakpoints
5840 @kindex break @dots{} thread @var{threadno}
5841 @item break @var{linespec} thread @var{threadno}
5842 @itemx break @var{linespec} thread @var{threadno} if @dots{}
5843 @var{linespec} specifies source lines; there are several ways of
5844 writing them (@pxref{Specify Location}), but the effect is always to
5845 specify some source line.
5846
5847 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5848 to specify that you only want @value{GDBN} to stop the program when a
5849 particular thread reaches this breakpoint. @var{threadno} is one of the
5850 numeric thread identifiers assigned by @value{GDBN}, shown in the first
5851 column of the @samp{info threads} display.
5852
5853 If you do not specify @samp{thread @var{threadno}} when you set a
5854 breakpoint, the breakpoint applies to @emph{all} threads of your
5855 program.
5856
5857 You can use the @code{thread} qualifier on conditional breakpoints as
5858 well; in this case, place @samp{thread @var{threadno}} before or
5859 after the breakpoint condition, like this:
5860
5861 @smallexample
5862 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
5863 @end smallexample
5864
5865 @end table
5866
5867 @node Interrupted System Calls
5868 @subsection Interrupted System Calls
5869
5870 @cindex thread breakpoints and system calls
5871 @cindex system calls and thread breakpoints
5872 @cindex premature return from system calls
5873 There is an unfortunate side effect when using @value{GDBN} to debug
5874 multi-threaded programs. If one thread stops for a
5875 breakpoint, or for some other reason, and another thread is blocked in a
5876 system call, then the system call may return prematurely. This is a
5877 consequence of the interaction between multiple threads and the signals
5878 that @value{GDBN} uses to implement breakpoints and other events that
5879 stop execution.
5880
5881 To handle this problem, your program should check the return value of
5882 each system call and react appropriately. This is good programming
5883 style anyways.
5884
5885 For example, do not write code like this:
5886
5887 @smallexample
5888 sleep (10);
5889 @end smallexample
5890
5891 The call to @code{sleep} will return early if a different thread stops
5892 at a breakpoint or for some other reason.
5893
5894 Instead, write this:
5895
5896 @smallexample
5897 int unslept = 10;
5898 while (unslept > 0)
5899 unslept = sleep (unslept);
5900 @end smallexample
5901
5902 A system call is allowed to return early, so the system is still
5903 conforming to its specification. But @value{GDBN} does cause your
5904 multi-threaded program to behave differently than it would without
5905 @value{GDBN}.
5906
5907 Also, @value{GDBN} uses internal breakpoints in the thread library to
5908 monitor certain events such as thread creation and thread destruction.
5909 When such an event happens, a system call in another thread may return
5910 prematurely, even though your program does not appear to stop.
5911
5912 @node Observer Mode
5913 @subsection Observer Mode
5914
5915 If you want to build on non-stop mode and observe program behavior
5916 without any chance of disruption by @value{GDBN}, you can set
5917 variables to disable all of the debugger's attempts to modify state,
5918 whether by writing memory, inserting breakpoints, etc. These operate
5919 at a low level, intercepting operations from all commands.
5920
5921 When all of these are set to @code{off}, then @value{GDBN} is said to
5922 be @dfn{observer mode}. As a convenience, the variable
5923 @code{observer} can be set to disable these, plus enable non-stop
5924 mode.
5925
5926 Note that @value{GDBN} will not prevent you from making nonsensical
5927 combinations of these settings. For instance, if you have enabled
5928 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
5929 then breakpoints that work by writing trap instructions into the code
5930 stream will still not be able to be placed.
5931
5932 @table @code
5933
5934 @kindex observer
5935 @item set observer on
5936 @itemx set observer off
5937 When set to @code{on}, this disables all the permission variables
5938 below (except for @code{insert-fast-tracepoints}), plus enables
5939 non-stop debugging. Setting this to @code{off} switches back to
5940 normal debugging, though remaining in non-stop mode.
5941
5942 @item show observer
5943 Show whether observer mode is on or off.
5944
5945 @kindex may-write-registers
5946 @item set may-write-registers on
5947 @itemx set may-write-registers off
5948 This controls whether @value{GDBN} will attempt to alter the values of
5949 registers, such as with assignment expressions in @code{print}, or the
5950 @code{jump} command. It defaults to @code{on}.
5951
5952 @item show may-write-registers
5953 Show the current permission to write registers.
5954
5955 @kindex may-write-memory
5956 @item set may-write-memory on
5957 @itemx set may-write-memory off
5958 This controls whether @value{GDBN} will attempt to alter the contents
5959 of memory, such as with assignment expressions in @code{print}. It
5960 defaults to @code{on}.
5961
5962 @item show may-write-memory
5963 Show the current permission to write memory.
5964
5965 @kindex may-insert-breakpoints
5966 @item set may-insert-breakpoints on
5967 @itemx set may-insert-breakpoints off
5968 This controls whether @value{GDBN} will attempt to insert breakpoints.
5969 This affects all breakpoints, including internal breakpoints defined
5970 by @value{GDBN}. It defaults to @code{on}.
5971
5972 @item show may-insert-breakpoints
5973 Show the current permission to insert breakpoints.
5974
5975 @kindex may-insert-tracepoints
5976 @item set may-insert-tracepoints on
5977 @itemx set may-insert-tracepoints off
5978 This controls whether @value{GDBN} will attempt to insert (regular)
5979 tracepoints at the beginning of a tracing experiment. It affects only
5980 non-fast tracepoints, fast tracepoints being under the control of
5981 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5982
5983 @item show may-insert-tracepoints
5984 Show the current permission to insert tracepoints.
5985
5986 @kindex may-insert-fast-tracepoints
5987 @item set may-insert-fast-tracepoints on
5988 @itemx set may-insert-fast-tracepoints off
5989 This controls whether @value{GDBN} will attempt to insert fast
5990 tracepoints at the beginning of a tracing experiment. It affects only
5991 fast tracepoints, regular (non-fast) tracepoints being under the
5992 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5993
5994 @item show may-insert-fast-tracepoints
5995 Show the current permission to insert fast tracepoints.
5996
5997 @kindex may-interrupt
5998 @item set may-interrupt on
5999 @itemx set may-interrupt off
6000 This controls whether @value{GDBN} will attempt to interrupt or stop
6001 program execution. When this variable is @code{off}, the
6002 @code{interrupt} command will have no effect, nor will
6003 @kbd{Ctrl-c}. It defaults to @code{on}.
6004
6005 @item show may-interrupt
6006 Show the current permission to interrupt or stop the program.
6007
6008 @end table
6009
6010 @node Reverse Execution
6011 @chapter Running programs backward
6012 @cindex reverse execution
6013 @cindex running programs backward
6014
6015 When you are debugging a program, it is not unusual to realize that
6016 you have gone too far, and some event of interest has already happened.
6017 If the target environment supports it, @value{GDBN} can allow you to
6018 ``rewind'' the program by running it backward.
6019
6020 A target environment that supports reverse execution should be able
6021 to ``undo'' the changes in machine state that have taken place as the
6022 program was executing normally. Variables, registers etc.@: should
6023 revert to their previous values. Obviously this requires a great
6024 deal of sophistication on the part of the target environment; not
6025 all target environments can support reverse execution.
6026
6027 When a program is executed in reverse, the instructions that
6028 have most recently been executed are ``un-executed'', in reverse
6029 order. The program counter runs backward, following the previous
6030 thread of execution in reverse. As each instruction is ``un-executed'',
6031 the values of memory and/or registers that were changed by that
6032 instruction are reverted to their previous states. After executing
6033 a piece of source code in reverse, all side effects of that code
6034 should be ``undone'', and all variables should be returned to their
6035 prior values@footnote{
6036 Note that some side effects are easier to undo than others. For instance,
6037 memory and registers are relatively easy, but device I/O is hard. Some
6038 targets may be able undo things like device I/O, and some may not.
6039
6040 The contract between @value{GDBN} and the reverse executing target
6041 requires only that the target do something reasonable when
6042 @value{GDBN} tells it to execute backwards, and then report the
6043 results back to @value{GDBN}. Whatever the target reports back to
6044 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
6045 assumes that the memory and registers that the target reports are in a
6046 consistant state, but @value{GDBN} accepts whatever it is given.
6047 }.
6048
6049 If you are debugging in a target environment that supports
6050 reverse execution, @value{GDBN} provides the following commands.
6051
6052 @table @code
6053 @kindex reverse-continue
6054 @kindex rc @r{(@code{reverse-continue})}
6055 @item reverse-continue @r{[}@var{ignore-count}@r{]}
6056 @itemx rc @r{[}@var{ignore-count}@r{]}
6057 Beginning at the point where your program last stopped, start executing
6058 in reverse. Reverse execution will stop for breakpoints and synchronous
6059 exceptions (signals), just like normal execution. Behavior of
6060 asynchronous signals depends on the target environment.
6061
6062 @kindex reverse-step
6063 @kindex rs @r{(@code{step})}
6064 @item reverse-step @r{[}@var{count}@r{]}
6065 Run the program backward until control reaches the start of a
6066 different source line; then stop it, and return control to @value{GDBN}.
6067
6068 Like the @code{step} command, @code{reverse-step} will only stop
6069 at the beginning of a source line. It ``un-executes'' the previously
6070 executed source line. If the previous source line included calls to
6071 debuggable functions, @code{reverse-step} will step (backward) into
6072 the called function, stopping at the beginning of the @emph{last}
6073 statement in the called function (typically a return statement).
6074
6075 Also, as with the @code{step} command, if non-debuggable functions are
6076 called, @code{reverse-step} will run thru them backward without stopping.
6077
6078 @kindex reverse-stepi
6079 @kindex rsi @r{(@code{reverse-stepi})}
6080 @item reverse-stepi @r{[}@var{count}@r{]}
6081 Reverse-execute one machine instruction. Note that the instruction
6082 to be reverse-executed is @emph{not} the one pointed to by the program
6083 counter, but the instruction executed prior to that one. For instance,
6084 if the last instruction was a jump, @code{reverse-stepi} will take you
6085 back from the destination of the jump to the jump instruction itself.
6086
6087 @kindex reverse-next
6088 @kindex rn @r{(@code{reverse-next})}
6089 @item reverse-next @r{[}@var{count}@r{]}
6090 Run backward to the beginning of the previous line executed in
6091 the current (innermost) stack frame. If the line contains function
6092 calls, they will be ``un-executed'' without stopping. Starting from
6093 the first line of a function, @code{reverse-next} will take you back
6094 to the caller of that function, @emph{before} the function was called,
6095 just as the normal @code{next} command would take you from the last
6096 line of a function back to its return to its caller
6097 @footnote{Unless the code is too heavily optimized.}.
6098
6099 @kindex reverse-nexti
6100 @kindex rni @r{(@code{reverse-nexti})}
6101 @item reverse-nexti @r{[}@var{count}@r{]}
6102 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6103 in reverse, except that called functions are ``un-executed'' atomically.
6104 That is, if the previously executed instruction was a return from
6105 another function, @code{reverse-nexti} will continue to execute
6106 in reverse until the call to that function (from the current stack
6107 frame) is reached.
6108
6109 @kindex reverse-finish
6110 @item reverse-finish
6111 Just as the @code{finish} command takes you to the point where the
6112 current function returns, @code{reverse-finish} takes you to the point
6113 where it was called. Instead of ending up at the end of the current
6114 function invocation, you end up at the beginning.
6115
6116 @kindex set exec-direction
6117 @item set exec-direction
6118 Set the direction of target execution.
6119 @item set exec-direction reverse
6120 @cindex execute forward or backward in time
6121 @value{GDBN} will perform all execution commands in reverse, until the
6122 exec-direction mode is changed to ``forward''. Affected commands include
6123 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6124 command cannot be used in reverse mode.
6125 @item set exec-direction forward
6126 @value{GDBN} will perform all execution commands in the normal fashion.
6127 This is the default.
6128 @end table
6129
6130
6131 @node Process Record and Replay
6132 @chapter Recording Inferior's Execution and Replaying It
6133 @cindex process record and replay
6134 @cindex recording inferior's execution and replaying it
6135
6136 On some platforms, @value{GDBN} provides a special @dfn{process record
6137 and replay} target that can record a log of the process execution, and
6138 replay it later with both forward and reverse execution commands.
6139
6140 @cindex replay mode
6141 When this target is in use, if the execution log includes the record
6142 for the next instruction, @value{GDBN} will debug in @dfn{replay
6143 mode}. In the replay mode, the inferior does not really execute code
6144 instructions. Instead, all the events that normally happen during
6145 code execution are taken from the execution log. While code is not
6146 really executed in replay mode, the values of registers (including the
6147 program counter register) and the memory of the inferior are still
6148 changed as they normally would. Their contents are taken from the
6149 execution log.
6150
6151 @cindex record mode
6152 If the record for the next instruction is not in the execution log,
6153 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
6154 inferior executes normally, and @value{GDBN} records the execution log
6155 for future replay.
6156
6157 The process record and replay target supports reverse execution
6158 (@pxref{Reverse Execution}), even if the platform on which the
6159 inferior runs does not. However, the reverse execution is limited in
6160 this case by the range of the instructions recorded in the execution
6161 log. In other words, reverse execution on platforms that don't
6162 support it directly can only be done in the replay mode.
6163
6164 When debugging in the reverse direction, @value{GDBN} will work in
6165 replay mode as long as the execution log includes the record for the
6166 previous instruction; otherwise, it will work in record mode, if the
6167 platform supports reverse execution, or stop if not.
6168
6169 For architecture environments that support process record and replay,
6170 @value{GDBN} provides the following commands:
6171
6172 @table @code
6173 @kindex target record
6174 @kindex target record-full
6175 @kindex target record-btrace
6176 @kindex record
6177 @kindex record full
6178 @kindex record btrace
6179 @kindex rec
6180 @kindex rec full
6181 @kindex rec btrace
6182 @item record @var{method}
6183 This command starts the process record and replay target. The
6184 recording method can be specified as parameter. Without a parameter
6185 the command uses the @code{full} recording method. The following
6186 recording methods are available:
6187
6188 @table @code
6189 @item full
6190 Full record/replay recording using @value{GDBN}'s software record and
6191 replay implementation. This method allows replaying and reverse
6192 execution.
6193
6194 @item btrace
6195 Hardware-supported instruction recording. This method does not allow
6196 replaying and reverse execution.
6197
6198 This recording method may not be available on all processors.
6199 @end table
6200
6201 The process record and replay target can only debug a process that is
6202 already running. Therefore, you need first to start the process with
6203 the @kbd{run} or @kbd{start} commands, and then start the recording
6204 with the @kbd{record @var{method}} command.
6205
6206 Both @code{record @var{method}} and @code{rec @var{method}} are
6207 aliases of @code{target record-@var{method}}.
6208
6209 @cindex displaced stepping, and process record and replay
6210 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
6211 will be automatically disabled when process record and replay target
6212 is started. That's because the process record and replay target
6213 doesn't support displaced stepping.
6214
6215 @cindex non-stop mode, and process record and replay
6216 @cindex asynchronous execution, and process record and replay
6217 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
6218 the asynchronous execution mode (@pxref{Background Execution}), not
6219 all recording methods are available. The @code{full} recording method
6220 does not support these two modes.
6221
6222 @kindex record stop
6223 @kindex rec s
6224 @item record stop
6225 Stop the process record and replay target. When process record and
6226 replay target stops, the entire execution log will be deleted and the
6227 inferior will either be terminated, or will remain in its final state.
6228
6229 When you stop the process record and replay target in record mode (at
6230 the end of the execution log), the inferior will be stopped at the
6231 next instruction that would have been recorded. In other words, if
6232 you record for a while and then stop recording, the inferior process
6233 will be left in the same state as if the recording never happened.
6234
6235 On the other hand, if the process record and replay target is stopped
6236 while in replay mode (that is, not at the end of the execution log,
6237 but at some earlier point), the inferior process will become ``live''
6238 at that earlier state, and it will then be possible to continue the
6239 usual ``live'' debugging of the process from that state.
6240
6241 When the inferior process exits, or @value{GDBN} detaches from it,
6242 process record and replay target will automatically stop itself.
6243
6244 @kindex record goto
6245 @item record goto
6246 Go to a specific location in the execution log. There are several
6247 ways to specify the location to go to:
6248
6249 @table @code
6250 @item record goto begin
6251 @itemx record goto start
6252 Go to the beginning of the execution log.
6253
6254 @item record goto end
6255 Go to the end of the execution log.
6256
6257 @item record goto @var{n}
6258 Go to instruction number @var{n} in the execution log.
6259 @end table
6260
6261 @kindex record save
6262 @item record save @var{filename}
6263 Save the execution log to a file @file{@var{filename}}.
6264 Default filename is @file{gdb_record.@var{process_id}}, where
6265 @var{process_id} is the process ID of the inferior.
6266
6267 This command may not be available for all recording methods.
6268
6269 @kindex record restore
6270 @item record restore @var{filename}
6271 Restore the execution log from a file @file{@var{filename}}.
6272 File must have been created with @code{record save}.
6273
6274 @kindex set record full
6275 @item set record full insn-number-max @var{limit}
6276 @itemx set record full insn-number-max unlimited
6277 Set the limit of instructions to be recorded for the @code{full}
6278 recording method. Default value is 200000.
6279
6280 If @var{limit} is a positive number, then @value{GDBN} will start
6281 deleting instructions from the log once the number of the record
6282 instructions becomes greater than @var{limit}. For every new recorded
6283 instruction, @value{GDBN} will delete the earliest recorded
6284 instruction to keep the number of recorded instructions at the limit.
6285 (Since deleting recorded instructions loses information, @value{GDBN}
6286 lets you control what happens when the limit is reached, by means of
6287 the @code{stop-at-limit} option, described below.)
6288
6289 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
6290 delete recorded instructions from the execution log. The number of
6291 recorded instructions is limited only by the available memory.
6292
6293 @kindex show record full
6294 @item show record full insn-number-max
6295 Show the limit of instructions to be recorded with the @code{full}
6296 recording method.
6297
6298 @item set record full stop-at-limit
6299 Control the behavior of the @code{full} recording method when the
6300 number of recorded instructions reaches the limit. If ON (the
6301 default), @value{GDBN} will stop when the limit is reached for the
6302 first time and ask you whether you want to stop the inferior or
6303 continue running it and recording the execution log. If you decide
6304 to continue recording, each new recorded instruction will cause the
6305 oldest one to be deleted.
6306
6307 If this option is OFF, @value{GDBN} will automatically delete the
6308 oldest record to make room for each new one, without asking.
6309
6310 @item show record full stop-at-limit
6311 Show the current setting of @code{stop-at-limit}.
6312
6313 @item set record full memory-query
6314 Control the behavior when @value{GDBN} is unable to record memory
6315 changes caused by an instruction for the @code{full} recording method.
6316 If ON, @value{GDBN} will query whether to stop the inferior in that
6317 case.
6318
6319 If this option is OFF (the default), @value{GDBN} will automatically
6320 ignore the effect of such instructions on memory. Later, when
6321 @value{GDBN} replays this execution log, it will mark the log of this
6322 instruction as not accessible, and it will not affect the replay
6323 results.
6324
6325 @item show record full memory-query
6326 Show the current setting of @code{memory-query}.
6327
6328 @kindex info record
6329 @item info record
6330 Show various statistics about the recording depending on the recording
6331 method:
6332
6333 @table @code
6334 @item full
6335 For the @code{full} recording method, it shows the state of process
6336 record and its in-memory execution log buffer, including:
6337
6338 @itemize @bullet
6339 @item
6340 Whether in record mode or replay mode.
6341 @item
6342 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
6343 @item
6344 Highest recorded instruction number.
6345 @item
6346 Current instruction about to be replayed (if in replay mode).
6347 @item
6348 Number of instructions contained in the execution log.
6349 @item
6350 Maximum number of instructions that may be contained in the execution log.
6351 @end itemize
6352
6353 @item btrace
6354 For the @code{btrace} recording method, it shows the number of
6355 instructions that have been recorded and the number of blocks of
6356 sequential control-flow that is formed by the recorded instructions.
6357 @end table
6358
6359 @kindex record delete
6360 @kindex rec del
6361 @item record delete
6362 When record target runs in replay mode (``in the past''), delete the
6363 subsequent execution log and begin to record a new execution log starting
6364 from the current address. This means you will abandon the previously
6365 recorded ``future'' and begin recording a new ``future''.
6366
6367 @kindex record instruction-history
6368 @kindex rec instruction-history
6369 @item record instruction-history
6370 Disassembles instructions from the recorded execution log. By
6371 default, ten instructions are disassembled. This can be changed using
6372 the @code{set record instruction-history-size} command. Instructions
6373 are printed in execution order. There are several ways to specify
6374 what part of the execution log to disassemble:
6375
6376 @table @code
6377 @item record instruction-history @var{insn}
6378 Disassembles ten instructions starting from instruction number
6379 @var{insn}.
6380
6381 @item record instruction-history @var{insn}, +/-@var{n}
6382 Disassembles @var{n} instructions around instruction number
6383 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
6384 @var{n} instructions after instruction number @var{insn}. If
6385 @var{n} is preceded with @code{-}, disassembles @var{n}
6386 instructions before instruction number @var{insn}.
6387
6388 @item record instruction-history
6389 Disassembles ten more instructions after the last disassembly.
6390
6391 @item record instruction-history -
6392 Disassembles ten more instructions before the last disassembly.
6393
6394 @item record instruction-history @var{begin} @var{end}
6395 Disassembles instructions beginning with instruction number
6396 @var{begin} until instruction number @var{end}. The instruction
6397 number @var{end} is not included.
6398 @end table
6399
6400 This command may not be available for all recording methods.
6401
6402 @kindex set record
6403 @item set record instruction-history-size @var{size}
6404 @itemx set record instruction-history-size unlimited
6405 Define how many instructions to disassemble in the @code{record
6406 instruction-history} command. The default value is 10.
6407 A @var{size} of @code{unlimited} means unlimited instructions.
6408
6409 @kindex show record
6410 @item show record instruction-history-size
6411 Show how many instructions to disassemble in the @code{record
6412 instruction-history} command.
6413
6414 @kindex record function-call-history
6415 @kindex rec function-call-history
6416 @item record function-call-history
6417 Prints the execution history at function granularity. It prints one
6418 line for each sequence of instructions that belong to the same
6419 function giving the name of that function, the source lines
6420 for this instruction sequence (if the @code{/l} modifier is
6421 specified), and the instructions numbers that form the sequence (if
6422 the @code{/i} modifier is specified).
6423
6424 @smallexample
6425 (@value{GDBP}) @b{list 1, 10}
6426 1 void foo (void)
6427 2 @{
6428 3 @}
6429 4
6430 5 void bar (void)
6431 6 @{
6432 7 ...
6433 8 foo ();
6434 9 ...
6435 10 @}
6436 (@value{GDBP}) @b{record function-call-history /l}
6437 1 foo.c:6-8 bar
6438 2 foo.c:2-3 foo
6439 3 foo.c:9-10 bar
6440 @end smallexample
6441
6442 By default, ten lines are printed. This can be changed using the
6443 @code{set record function-call-history-size} command. Functions are
6444 printed in execution order. There are several ways to specify what
6445 to print:
6446
6447 @table @code
6448 @item record function-call-history @var{func}
6449 Prints ten functions starting from function number @var{func}.
6450
6451 @item record function-call-history @var{func}, +/-@var{n}
6452 Prints @var{n} functions around function number @var{func}. If
6453 @var{n} is preceded with @code{+}, prints @var{n} functions after
6454 function number @var{func}. If @var{n} is preceded with @code{-},
6455 prints @var{n} functions before function number @var{func}.
6456
6457 @item record function-call-history
6458 Prints ten more functions after the last ten-line print.
6459
6460 @item record function-call-history -
6461 Prints ten more functions before the last ten-line print.
6462
6463 @item record function-call-history @var{begin} @var{end}
6464 Prints functions beginning with function number @var{begin} until
6465 function number @var{end}. The function number @var{end} is not
6466 included.
6467 @end table
6468
6469 This command may not be available for all recording methods.
6470
6471 @item set record function-call-history-size @var{size}
6472 @itemx set record function-call-history-size unlimited
6473 Define how many lines to print in the
6474 @code{record function-call-history} command. The default value is 10.
6475 A size of @code{unlimited} means unlimited lines.
6476
6477 @item show record function-call-history-size
6478 Show how many lines to print in the
6479 @code{record function-call-history} command.
6480 @end table
6481
6482
6483 @node Stack
6484 @chapter Examining the Stack
6485
6486 When your program has stopped, the first thing you need to know is where it
6487 stopped and how it got there.
6488
6489 @cindex call stack
6490 Each time your program performs a function call, information about the call
6491 is generated.
6492 That information includes the location of the call in your program,
6493 the arguments of the call,
6494 and the local variables of the function being called.
6495 The information is saved in a block of data called a @dfn{stack frame}.
6496 The stack frames are allocated in a region of memory called the @dfn{call
6497 stack}.
6498
6499 When your program stops, the @value{GDBN} commands for examining the
6500 stack allow you to see all of this information.
6501
6502 @cindex selected frame
6503 One of the stack frames is @dfn{selected} by @value{GDBN} and many
6504 @value{GDBN} commands refer implicitly to the selected frame. In
6505 particular, whenever you ask @value{GDBN} for the value of a variable in
6506 your program, the value is found in the selected frame. There are
6507 special @value{GDBN} commands to select whichever frame you are
6508 interested in. @xref{Selection, ,Selecting a Frame}.
6509
6510 When your program stops, @value{GDBN} automatically selects the
6511 currently executing frame and describes it briefly, similar to the
6512 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
6513
6514 @menu
6515 * Frames:: Stack frames
6516 * Backtrace:: Backtraces
6517 * Frame Filter Management:: Managing frame filters
6518 * Selection:: Selecting a frame
6519 * Frame Info:: Information on a frame
6520
6521 @end menu
6522
6523 @node Frames
6524 @section Stack Frames
6525
6526 @cindex frame, definition
6527 @cindex stack frame
6528 The call stack is divided up into contiguous pieces called @dfn{stack
6529 frames}, or @dfn{frames} for short; each frame is the data associated
6530 with one call to one function. The frame contains the arguments given
6531 to the function, the function's local variables, and the address at
6532 which the function is executing.
6533
6534 @cindex initial frame
6535 @cindex outermost frame
6536 @cindex innermost frame
6537 When your program is started, the stack has only one frame, that of the
6538 function @code{main}. This is called the @dfn{initial} frame or the
6539 @dfn{outermost} frame. Each time a function is called, a new frame is
6540 made. Each time a function returns, the frame for that function invocation
6541 is eliminated. If a function is recursive, there can be many frames for
6542 the same function. The frame for the function in which execution is
6543 actually occurring is called the @dfn{innermost} frame. This is the most
6544 recently created of all the stack frames that still exist.
6545
6546 @cindex frame pointer
6547 Inside your program, stack frames are identified by their addresses. A
6548 stack frame consists of many bytes, each of which has its own address; each
6549 kind of computer has a convention for choosing one byte whose
6550 address serves as the address of the frame. Usually this address is kept
6551 in a register called the @dfn{frame pointer register}
6552 (@pxref{Registers, $fp}) while execution is going on in that frame.
6553
6554 @cindex frame number
6555 @value{GDBN} assigns numbers to all existing stack frames, starting with
6556 zero for the innermost frame, one for the frame that called it,
6557 and so on upward. These numbers do not really exist in your program;
6558 they are assigned by @value{GDBN} to give you a way of designating stack
6559 frames in @value{GDBN} commands.
6560
6561 @c The -fomit-frame-pointer below perennially causes hbox overflow
6562 @c underflow problems.
6563 @cindex frameless execution
6564 Some compilers provide a way to compile functions so that they operate
6565 without stack frames. (For example, the @value{NGCC} option
6566 @smallexample
6567 @samp{-fomit-frame-pointer}
6568 @end smallexample
6569 generates functions without a frame.)
6570 This is occasionally done with heavily used library functions to save
6571 the frame setup time. @value{GDBN} has limited facilities for dealing
6572 with these function invocations. If the innermost function invocation
6573 has no stack frame, @value{GDBN} nevertheless regards it as though
6574 it had a separate frame, which is numbered zero as usual, allowing
6575 correct tracing of the function call chain. However, @value{GDBN} has
6576 no provision for frameless functions elsewhere in the stack.
6577
6578 @table @code
6579 @kindex frame@r{, command}
6580 @cindex current stack frame
6581 @item frame @var{args}
6582 The @code{frame} command allows you to move from one stack frame to another,
6583 and to print the stack frame you select. @var{args} may be either the
6584 address of the frame or the stack frame number. Without an argument,
6585 @code{frame} prints the current stack frame.
6586
6587 @kindex select-frame
6588 @cindex selecting frame silently
6589 @item select-frame
6590 The @code{select-frame} command allows you to move from one stack frame
6591 to another without printing the frame. This is the silent version of
6592 @code{frame}.
6593 @end table
6594
6595 @node Backtrace
6596 @section Backtraces
6597
6598 @cindex traceback
6599 @cindex call stack traces
6600 A backtrace is a summary of how your program got where it is. It shows one
6601 line per frame, for many frames, starting with the currently executing
6602 frame (frame zero), followed by its caller (frame one), and on up the
6603 stack.
6604
6605 @anchor{backtrace-command}
6606 @table @code
6607 @kindex backtrace
6608 @kindex bt @r{(@code{backtrace})}
6609 @item backtrace
6610 @itemx bt
6611 Print a backtrace of the entire stack: one line per frame for all
6612 frames in the stack.
6613
6614 You can stop the backtrace at any time by typing the system interrupt
6615 character, normally @kbd{Ctrl-c}.
6616
6617 @item backtrace @var{n}
6618 @itemx bt @var{n}
6619 Similar, but print only the innermost @var{n} frames.
6620
6621 @item backtrace -@var{n}
6622 @itemx bt -@var{n}
6623 Similar, but print only the outermost @var{n} frames.
6624
6625 @item backtrace full
6626 @itemx bt full
6627 @itemx bt full @var{n}
6628 @itemx bt full -@var{n}
6629 Print the values of the local variables also. @var{n} specifies the
6630 number of frames to print, as described above.
6631
6632 @item backtrace no-filters
6633 @itemx bt no-filters
6634 @itemx bt no-filters @var{n}
6635 @itemx bt no-filters -@var{n}
6636 @itemx bt no-filters full
6637 @itemx bt no-filters full @var{n}
6638 @itemx bt no-filters full -@var{n}
6639 Do not run Python frame filters on this backtrace. @xref{Frame
6640 Filter API}, for more information. Additionally use @ref{disable
6641 frame-filter all} to turn off all frame filters. This is only
6642 relevant when @value{GDBN} has been configured with @code{Python}
6643 support.
6644 @end table
6645
6646 @kindex where
6647 @kindex info stack
6648 The names @code{where} and @code{info stack} (abbreviated @code{info s})
6649 are additional aliases for @code{backtrace}.
6650
6651 @cindex multiple threads, backtrace
6652 In a multi-threaded program, @value{GDBN} by default shows the
6653 backtrace only for the current thread. To display the backtrace for
6654 several or all of the threads, use the command @code{thread apply}
6655 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
6656 apply all backtrace}, @value{GDBN} will display the backtrace for all
6657 the threads; this is handy when you debug a core dump of a
6658 multi-threaded program.
6659
6660 Each line in the backtrace shows the frame number and the function name.
6661 The program counter value is also shown---unless you use @code{set
6662 print address off}. The backtrace also shows the source file name and
6663 line number, as well as the arguments to the function. The program
6664 counter value is omitted if it is at the beginning of the code for that
6665 line number.
6666
6667 Here is an example of a backtrace. It was made with the command
6668 @samp{bt 3}, so it shows the innermost three frames.
6669
6670 @smallexample
6671 @group
6672 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6673 at builtin.c:993
6674 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
6675 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
6676 at macro.c:71
6677 (More stack frames follow...)
6678 @end group
6679 @end smallexample
6680
6681 @noindent
6682 The display for frame zero does not begin with a program counter
6683 value, indicating that your program has stopped at the beginning of the
6684 code for line @code{993} of @code{builtin.c}.
6685
6686 @noindent
6687 The value of parameter @code{data} in frame 1 has been replaced by
6688 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
6689 only if it is a scalar (integer, pointer, enumeration, etc). See command
6690 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
6691 on how to configure the way function parameter values are printed.
6692
6693 @cindex optimized out, in backtrace
6694 @cindex function call arguments, optimized out
6695 If your program was compiled with optimizations, some compilers will
6696 optimize away arguments passed to functions if those arguments are
6697 never used after the call. Such optimizations generate code that
6698 passes arguments through registers, but doesn't store those arguments
6699 in the stack frame. @value{GDBN} has no way of displaying such
6700 arguments in stack frames other than the innermost one. Here's what
6701 such a backtrace might look like:
6702
6703 @smallexample
6704 @group
6705 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
6706 at builtin.c:993
6707 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
6708 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
6709 at macro.c:71
6710 (More stack frames follow...)
6711 @end group
6712 @end smallexample
6713
6714 @noindent
6715 The values of arguments that were not saved in their stack frames are
6716 shown as @samp{<optimized out>}.
6717
6718 If you need to display the values of such optimized-out arguments,
6719 either deduce that from other variables whose values depend on the one
6720 you are interested in, or recompile without optimizations.
6721
6722 @cindex backtrace beyond @code{main} function
6723 @cindex program entry point
6724 @cindex startup code, and backtrace
6725 Most programs have a standard user entry point---a place where system
6726 libraries and startup code transition into user code. For C this is
6727 @code{main}@footnote{
6728 Note that embedded programs (the so-called ``free-standing''
6729 environment) are not required to have a @code{main} function as the
6730 entry point. They could even have multiple entry points.}.
6731 When @value{GDBN} finds the entry function in a backtrace
6732 it will terminate the backtrace, to avoid tracing into highly
6733 system-specific (and generally uninteresting) code.
6734
6735 If you need to examine the startup code, or limit the number of levels
6736 in a backtrace, you can change this behavior:
6737
6738 @table @code
6739 @item set backtrace past-main
6740 @itemx set backtrace past-main on
6741 @kindex set backtrace
6742 Backtraces will continue past the user entry point.
6743
6744 @item set backtrace past-main off
6745 Backtraces will stop when they encounter the user entry point. This is the
6746 default.
6747
6748 @item show backtrace past-main
6749 @kindex show backtrace
6750 Display the current user entry point backtrace policy.
6751
6752 @item set backtrace past-entry
6753 @itemx set backtrace past-entry on
6754 Backtraces will continue past the internal entry point of an application.
6755 This entry point is encoded by the linker when the application is built,
6756 and is likely before the user entry point @code{main} (or equivalent) is called.
6757
6758 @item set backtrace past-entry off
6759 Backtraces will stop when they encounter the internal entry point of an
6760 application. This is the default.
6761
6762 @item show backtrace past-entry
6763 Display the current internal entry point backtrace policy.
6764
6765 @item set backtrace limit @var{n}
6766 @itemx set backtrace limit 0
6767 @itemx set backtrace limit unlimited
6768 @cindex backtrace limit
6769 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
6770 or zero means unlimited levels.
6771
6772 @item show backtrace limit
6773 Display the current limit on backtrace levels.
6774 @end table
6775
6776 You can control how file names are displayed.
6777
6778 @table @code
6779 @item set filename-display
6780 @itemx set filename-display relative
6781 @cindex filename-display
6782 Display file names relative to the compilation directory. This is the default.
6783
6784 @item set filename-display basename
6785 Display only basename of a filename.
6786
6787 @item set filename-display absolute
6788 Display an absolute filename.
6789
6790 @item show filename-display
6791 Show the current way to display filenames.
6792 @end table
6793
6794 @node Frame Filter Management
6795 @section Management of Frame Filters.
6796 @cindex managing frame filters
6797
6798 Frame filters are Python based utilities to manage and decorate the
6799 output of frames. @xref{Frame Filter API}, for further information.
6800
6801 Managing frame filters is performed by several commands available
6802 within @value{GDBN}, detailed here.
6803
6804 @table @code
6805 @kindex info frame-filter
6806 @item info frame-filter
6807 Print a list of installed frame filters from all dictionaries, showing
6808 their name, priority and enabled status.
6809
6810 @kindex disable frame-filter
6811 @anchor{disable frame-filter all}
6812 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
6813 Disable a frame filter in the dictionary matching
6814 @var{filter-dictionary}, or @code{all}, and @var{filter-name}.
6815 @var{filter-dictionary} may be @code{all}, @code{global},
6816 @code{progspace} or the name of the object file where the frame filter
6817 dictionary resides. When @code{all} is specified, all frame filters
6818 across all dictionaries are disabled. @var{filter-name} is the name
6819 of the frame filter and is used when @code{all} is not the option for
6820 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
6821 may be enabled again later.
6822
6823 @kindex enable frame-filter
6824 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
6825 Enable a frame filter in the dictionary matching
6826 @var{filter-dictionary}, or @code{all}, and @var{filter-name}.
6827 @var{filter-dictionary} may be @code{all}, @code{global},
6828 @code{progspace} or the name of the object file where the frame filter
6829 dictionary resides. When @code{all} is specified, all frame filters across
6830 all dictionaries are enabled. @var{filter-name} is the name of the frame
6831 filter and is used when @code{all} is not the option for
6832 @var{filter-dictionary}.
6833
6834 Example:
6835
6836 @smallexample
6837 (gdb) info frame-filter
6838
6839 global frame-filters:
6840 Priority Enabled Name
6841 1000 No PrimaryFunctionFilter
6842 100 Yes Reverse
6843
6844 progspace /build/test frame-filters:
6845 Priority Enabled Name
6846 100 Yes ProgspaceFilter
6847
6848 objfile /build/test frame-filters:
6849 Priority Enabled Name
6850 999 Yes BuildProgra Filter
6851
6852 (gdb) disable frame-filter /build/test BuildProgramFilter
6853 (gdb) info frame-filter
6854
6855 global frame-filters:
6856 Priority Enabled Name
6857 1000 No PrimaryFunctionFilter
6858 100 Yes Reverse
6859
6860 progspace /build/test frame-filters:
6861 Priority Enabled Name
6862 100 Yes ProgspaceFilter
6863
6864 objfile /build/test frame-filters:
6865 Priority Enabled Name
6866 999 No BuildProgramFilter
6867
6868 (gdb) enable frame-filter global PrimaryFunctionFilter
6869 (gdb) info frame-filter
6870
6871 global frame-filters:
6872 Priority Enabled Name
6873 1000 Yes PrimaryFunctionFilter
6874 100 Yes Reverse
6875
6876 progspace /build/test frame-filters:
6877 Priority Enabled Name
6878 100 Yes ProgspaceFilter
6879
6880 objfile /build/test frame-filters:
6881 Priority Enabled Name
6882 999 No BuildProgramFilter
6883 @end smallexample
6884
6885 @kindex set frame-filter priority
6886 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
6887 Set the @var{priority} of a frame filter in the dictionary matching
6888 @var{filter-dictionary}, and the frame filter name matching
6889 @var{filter-name}. @var{filter-dictionary} may be @code{global},
6890 @code{progspace} or the name of the object file where the frame filter
6891 dictionary resides. @var{priority} is an integer.
6892
6893 @kindex show frame-filter priority
6894 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
6895 Show the @var{priority} of a frame filter in the dictionary matching
6896 @var{filter-dictionary}, and the frame filter name matching
6897 @var{filter-name}. @var{filter-dictionary} may be @code{global},
6898 @code{progspace} or the name of the object file where the frame filter
6899 dictionary resides.
6900
6901 Example:
6902
6903 @smallexample
6904 (gdb) info frame-filter
6905
6906 global frame-filters:
6907 Priority Enabled Name
6908 1000 Yes PrimaryFunctionFilter
6909 100 Yes Reverse
6910
6911 progspace /build/test frame-filters:
6912 Priority Enabled Name
6913 100 Yes ProgspaceFilter
6914
6915 objfile /build/test frame-filters:
6916 Priority Enabled Name
6917 999 No BuildProgramFilter
6918
6919 (gdb) set frame-filter priority global Reverse 50
6920 (gdb) info frame-filter
6921
6922 global frame-filters:
6923 Priority Enabled Name
6924 1000 Yes PrimaryFunctionFilter
6925 50 Yes Reverse
6926
6927 progspace /build/test frame-filters:
6928 Priority Enabled Name
6929 100 Yes ProgspaceFilter
6930
6931 objfile /build/test frame-filters:
6932 Priority Enabled Name
6933 999 No BuildProgramFilter
6934 @end smallexample
6935 @end table
6936
6937 @node Selection
6938 @section Selecting a Frame
6939
6940 Most commands for examining the stack and other data in your program work on
6941 whichever stack frame is selected at the moment. Here are the commands for
6942 selecting a stack frame; all of them finish by printing a brief description
6943 of the stack frame just selected.
6944
6945 @table @code
6946 @kindex frame@r{, selecting}
6947 @kindex f @r{(@code{frame})}
6948 @item frame @var{n}
6949 @itemx f @var{n}
6950 Select frame number @var{n}. Recall that frame zero is the innermost
6951 (currently executing) frame, frame one is the frame that called the
6952 innermost one, and so on. The highest-numbered frame is the one for
6953 @code{main}.
6954
6955 @item frame @var{addr}
6956 @itemx f @var{addr}
6957 Select the frame at address @var{addr}. This is useful mainly if the
6958 chaining of stack frames has been damaged by a bug, making it
6959 impossible for @value{GDBN} to assign numbers properly to all frames. In
6960 addition, this can be useful when your program has multiple stacks and
6961 switches between them.
6962
6963 On the SPARC architecture, @code{frame} needs two addresses to
6964 select an arbitrary frame: a frame pointer and a stack pointer.
6965
6966 On the @acronym{MIPS} and Alpha architecture, it needs two addresses: a stack
6967 pointer and a program counter.
6968
6969 On the 29k architecture, it needs three addresses: a register stack
6970 pointer, a program counter, and a memory stack pointer.
6971
6972 @kindex up
6973 @item up @var{n}
6974 Move @var{n} frames up the stack. For positive numbers @var{n}, this
6975 advances toward the outermost frame, to higher frame numbers, to frames
6976 that have existed longer. @var{n} defaults to one.
6977
6978 @kindex down
6979 @kindex do @r{(@code{down})}
6980 @item down @var{n}
6981 Move @var{n} frames down the stack. For positive numbers @var{n}, this
6982 advances toward the innermost frame, to lower frame numbers, to frames
6983 that were created more recently. @var{n} defaults to one. You may
6984 abbreviate @code{down} as @code{do}.
6985 @end table
6986
6987 All of these commands end by printing two lines of output describing the
6988 frame. The first line shows the frame number, the function name, the
6989 arguments, and the source file and line number of execution in that
6990 frame. The second line shows the text of that source line.
6991
6992 @need 1000
6993 For example:
6994
6995 @smallexample
6996 @group
6997 (@value{GDBP}) up
6998 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6999 at env.c:10
7000 10 read_input_file (argv[i]);
7001 @end group
7002 @end smallexample
7003
7004 After such a printout, the @code{list} command with no arguments
7005 prints ten lines centered on the point of execution in the frame.
7006 You can also edit the program at the point of execution with your favorite
7007 editing program by typing @code{edit}.
7008 @xref{List, ,Printing Source Lines},
7009 for details.
7010
7011 @table @code
7012 @kindex down-silently
7013 @kindex up-silently
7014 @item up-silently @var{n}
7015 @itemx down-silently @var{n}
7016 These two commands are variants of @code{up} and @code{down},
7017 respectively; they differ in that they do their work silently, without
7018 causing display of the new frame. They are intended primarily for use
7019 in @value{GDBN} command scripts, where the output might be unnecessary and
7020 distracting.
7021 @end table
7022
7023 @node Frame Info
7024 @section Information About a Frame
7025
7026 There are several other commands to print information about the selected
7027 stack frame.
7028
7029 @table @code
7030 @item frame
7031 @itemx f
7032 When used without any argument, this command does not change which
7033 frame is selected, but prints a brief description of the currently
7034 selected stack frame. It can be abbreviated @code{f}. With an
7035 argument, this command is used to select a stack frame.
7036 @xref{Selection, ,Selecting a Frame}.
7037
7038 @kindex info frame
7039 @kindex info f @r{(@code{info frame})}
7040 @item info frame
7041 @itemx info f
7042 This command prints a verbose description of the selected stack frame,
7043 including:
7044
7045 @itemize @bullet
7046 @item
7047 the address of the frame
7048 @item
7049 the address of the next frame down (called by this frame)
7050 @item
7051 the address of the next frame up (caller of this frame)
7052 @item
7053 the language in which the source code corresponding to this frame is written
7054 @item
7055 the address of the frame's arguments
7056 @item
7057 the address of the frame's local variables
7058 @item
7059 the program counter saved in it (the address of execution in the caller frame)
7060 @item
7061 which registers were saved in the frame
7062 @end itemize
7063
7064 @noindent The verbose description is useful when
7065 something has gone wrong that has made the stack format fail to fit
7066 the usual conventions.
7067
7068 @item info frame @var{addr}
7069 @itemx info f @var{addr}
7070 Print a verbose description of the frame at address @var{addr}, without
7071 selecting that frame. The selected frame remains unchanged by this
7072 command. This requires the same kind of address (more than one for some
7073 architectures) that you specify in the @code{frame} command.
7074 @xref{Selection, ,Selecting a Frame}.
7075
7076 @kindex info args
7077 @item info args
7078 Print the arguments of the selected frame, each on a separate line.
7079
7080 @item info locals
7081 @kindex info locals
7082 Print the local variables of the selected frame, each on a separate
7083 line. These are all variables (declared either static or automatic)
7084 accessible at the point of execution of the selected frame.
7085
7086 @end table
7087
7088
7089 @node Source
7090 @chapter Examining Source Files
7091
7092 @value{GDBN} can print parts of your program's source, since the debugging
7093 information recorded in the program tells @value{GDBN} what source files were
7094 used to build it. When your program stops, @value{GDBN} spontaneously prints
7095 the line where it stopped. Likewise, when you select a stack frame
7096 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
7097 execution in that frame has stopped. You can print other portions of
7098 source files by explicit command.
7099
7100 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
7101 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7102 @value{GDBN} under @sc{gnu} Emacs}.
7103
7104 @menu
7105 * List:: Printing source lines
7106 * Specify Location:: How to specify code locations
7107 * Edit:: Editing source files
7108 * Search:: Searching source files
7109 * Source Path:: Specifying source directories
7110 * Machine Code:: Source and machine code
7111 @end menu
7112
7113 @node List
7114 @section Printing Source Lines
7115
7116 @kindex list
7117 @kindex l @r{(@code{list})}
7118 To print lines from a source file, use the @code{list} command
7119 (abbreviated @code{l}). By default, ten lines are printed.
7120 There are several ways to specify what part of the file you want to
7121 print; see @ref{Specify Location}, for the full list.
7122
7123 Here are the forms of the @code{list} command most commonly used:
7124
7125 @table @code
7126 @item list @var{linenum}
7127 Print lines centered around line number @var{linenum} in the
7128 current source file.
7129
7130 @item list @var{function}
7131 Print lines centered around the beginning of function
7132 @var{function}.
7133
7134 @item list
7135 Print more lines. If the last lines printed were printed with a
7136 @code{list} command, this prints lines following the last lines
7137 printed; however, if the last line printed was a solitary line printed
7138 as part of displaying a stack frame (@pxref{Stack, ,Examining the
7139 Stack}), this prints lines centered around that line.
7140
7141 @item list -
7142 Print lines just before the lines last printed.
7143 @end table
7144
7145 @cindex @code{list}, how many lines to display
7146 By default, @value{GDBN} prints ten source lines with any of these forms of
7147 the @code{list} command. You can change this using @code{set listsize}:
7148
7149 @table @code
7150 @kindex set listsize
7151 @item set listsize @var{count}
7152 @itemx set listsize unlimited
7153 Make the @code{list} command display @var{count} source lines (unless
7154 the @code{list} argument explicitly specifies some other number).
7155 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
7156
7157 @kindex show listsize
7158 @item show listsize
7159 Display the number of lines that @code{list} prints.
7160 @end table
7161
7162 Repeating a @code{list} command with @key{RET} discards the argument,
7163 so it is equivalent to typing just @code{list}. This is more useful
7164 than listing the same lines again. An exception is made for an
7165 argument of @samp{-}; that argument is preserved in repetition so that
7166 each repetition moves up in the source file.
7167
7168 In general, the @code{list} command expects you to supply zero, one or two
7169 @dfn{linespecs}. Linespecs specify source lines; there are several ways
7170 of writing them (@pxref{Specify Location}), but the effect is always
7171 to specify some source line.
7172
7173 Here is a complete description of the possible arguments for @code{list}:
7174
7175 @table @code
7176 @item list @var{linespec}
7177 Print lines centered around the line specified by @var{linespec}.
7178
7179 @item list @var{first},@var{last}
7180 Print lines from @var{first} to @var{last}. Both arguments are
7181 linespecs. When a @code{list} command has two linespecs, and the
7182 source file of the second linespec is omitted, this refers to
7183 the same source file as the first linespec.
7184
7185 @item list ,@var{last}
7186 Print lines ending with @var{last}.
7187
7188 @item list @var{first},
7189 Print lines starting with @var{first}.
7190
7191 @item list +
7192 Print lines just after the lines last printed.
7193
7194 @item list -
7195 Print lines just before the lines last printed.
7196
7197 @item list
7198 As described in the preceding table.
7199 @end table
7200
7201 @node Specify Location
7202 @section Specifying a Location
7203 @cindex specifying location
7204 @cindex linespec
7205
7206 Several @value{GDBN} commands accept arguments that specify a location
7207 of your program's code. Since @value{GDBN} is a source-level
7208 debugger, a location usually specifies some line in the source code;
7209 for that reason, locations are also known as @dfn{linespecs}.
7210
7211 Here are all the different ways of specifying a code location that
7212 @value{GDBN} understands:
7213
7214 @table @code
7215 @item @var{linenum}
7216 Specifies the line number @var{linenum} of the current source file.
7217
7218 @item -@var{offset}
7219 @itemx +@var{offset}
7220 Specifies the line @var{offset} lines before or after the @dfn{current
7221 line}. For the @code{list} command, the current line is the last one
7222 printed; for the breakpoint commands, this is the line at which
7223 execution stopped in the currently selected @dfn{stack frame}
7224 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
7225 used as the second of the two linespecs in a @code{list} command,
7226 this specifies the line @var{offset} lines up or down from the first
7227 linespec.
7228
7229 @item @var{filename}:@var{linenum}
7230 Specifies the line @var{linenum} in the source file @var{filename}.
7231 If @var{filename} is a relative file name, then it will match any
7232 source file name with the same trailing components. For example, if
7233 @var{filename} is @samp{gcc/expr.c}, then it will match source file
7234 name of @file{/build/trunk/gcc/expr.c}, but not
7235 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
7236
7237 @item @var{function}
7238 Specifies the line that begins the body of the function @var{function}.
7239 For example, in C, this is the line with the open brace.
7240
7241 @item @var{function}:@var{label}
7242 Specifies the line where @var{label} appears in @var{function}.
7243
7244 @item @var{filename}:@var{function}
7245 Specifies the line that begins the body of the function @var{function}
7246 in the file @var{filename}. You only need the file name with a
7247 function name to avoid ambiguity when there are identically named
7248 functions in different source files.
7249
7250 @item @var{label}
7251 Specifies the line at which the label named @var{label} appears.
7252 @value{GDBN} searches for the label in the function corresponding to
7253 the currently selected stack frame. If there is no current selected
7254 stack frame (for instance, if the inferior is not running), then
7255 @value{GDBN} will not search for a label.
7256
7257 @item *@var{address}
7258 Specifies the program address @var{address}. For line-oriented
7259 commands, such as @code{list} and @code{edit}, this specifies a source
7260 line that contains @var{address}. For @code{break} and other
7261 breakpoint oriented commands, this can be used to set breakpoints in
7262 parts of your program which do not have debugging information or
7263 source files.
7264
7265 Here @var{address} may be any expression valid in the current working
7266 language (@pxref{Languages, working language}) that specifies a code
7267 address. In addition, as a convenience, @value{GDBN} extends the
7268 semantics of expressions used in locations to cover the situations
7269 that frequently happen during debugging. Here are the various forms
7270 of @var{address}:
7271
7272 @table @code
7273 @item @var{expression}
7274 Any expression valid in the current working language.
7275
7276 @item @var{funcaddr}
7277 An address of a function or procedure derived from its name. In C,
7278 C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
7279 simply the function's name @var{function} (and actually a special case
7280 of a valid expression). In Pascal and Modula-2, this is
7281 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
7282 (although the Pascal form also works).
7283
7284 This form specifies the address of the function's first instruction,
7285 before the stack frame and arguments have been set up.
7286
7287 @item '@var{filename}'::@var{funcaddr}
7288 Like @var{funcaddr} above, but also specifies the name of the source
7289 file explicitly. This is useful if the name of the function does not
7290 specify the function unambiguously, e.g., if there are several
7291 functions with identical names in different source files.
7292 @end table
7293
7294 @cindex breakpoint at static probe point
7295 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
7296 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
7297 applications to embed static probes. @xref{Static Probe Points}, for more
7298 information on finding and using static probes. This form of linespec
7299 specifies the location of such a static probe.
7300
7301 If @var{objfile} is given, only probes coming from that shared library
7302 or executable matching @var{objfile} as a regular expression are considered.
7303 If @var{provider} is given, then only probes from that provider are considered.
7304 If several probes match the spec, @value{GDBN} will insert a breakpoint at
7305 each one of those probes.
7306
7307 @end table
7308
7309
7310 @node Edit
7311 @section Editing Source Files
7312 @cindex editing source files
7313
7314 @kindex edit
7315 @kindex e @r{(@code{edit})}
7316 To edit the lines in a source file, use the @code{edit} command.
7317 The editing program of your choice
7318 is invoked with the current line set to
7319 the active line in the program.
7320 Alternatively, there are several ways to specify what part of the file you
7321 want to print if you want to see other parts of the program:
7322
7323 @table @code
7324 @item edit @var{location}
7325 Edit the source file specified by @code{location}. Editing starts at
7326 that @var{location}, e.g., at the specified source line of the
7327 specified file. @xref{Specify Location}, for all the possible forms
7328 of the @var{location} argument; here are the forms of the @code{edit}
7329 command most commonly used:
7330
7331 @table @code
7332 @item edit @var{number}
7333 Edit the current source file with @var{number} as the active line number.
7334
7335 @item edit @var{function}
7336 Edit the file containing @var{function} at the beginning of its definition.
7337 @end table
7338
7339 @end table
7340
7341 @subsection Choosing your Editor
7342 You can customize @value{GDBN} to use any editor you want
7343 @footnote{
7344 The only restriction is that your editor (say @code{ex}), recognizes the
7345 following command-line syntax:
7346 @smallexample
7347 ex +@var{number} file
7348 @end smallexample
7349 The optional numeric value +@var{number} specifies the number of the line in
7350 the file where to start editing.}.
7351 By default, it is @file{@value{EDITOR}}, but you can change this
7352 by setting the environment variable @code{EDITOR} before using
7353 @value{GDBN}. For example, to configure @value{GDBN} to use the
7354 @code{vi} editor, you could use these commands with the @code{sh} shell:
7355 @smallexample
7356 EDITOR=/usr/bin/vi
7357 export EDITOR
7358 gdb @dots{}
7359 @end smallexample
7360 or in the @code{csh} shell,
7361 @smallexample
7362 setenv EDITOR /usr/bin/vi
7363 gdb @dots{}
7364 @end smallexample
7365
7366 @node Search
7367 @section Searching Source Files
7368 @cindex searching source files
7369
7370 There are two commands for searching through the current source file for a
7371 regular expression.
7372
7373 @table @code
7374 @kindex search
7375 @kindex forward-search
7376 @kindex fo @r{(@code{forward-search})}
7377 @item forward-search @var{regexp}
7378 @itemx search @var{regexp}
7379 The command @samp{forward-search @var{regexp}} checks each line,
7380 starting with the one following the last line listed, for a match for
7381 @var{regexp}. It lists the line that is found. You can use the
7382 synonym @samp{search @var{regexp}} or abbreviate the command name as
7383 @code{fo}.
7384
7385 @kindex reverse-search
7386 @item reverse-search @var{regexp}
7387 The command @samp{reverse-search @var{regexp}} checks each line, starting
7388 with the one before the last line listed and going backward, for a match
7389 for @var{regexp}. It lists the line that is found. You can abbreviate
7390 this command as @code{rev}.
7391 @end table
7392
7393 @node Source Path
7394 @section Specifying Source Directories
7395
7396 @cindex source path
7397 @cindex directories for source files
7398 Executable programs sometimes do not record the directories of the source
7399 files from which they were compiled, just the names. Even when they do,
7400 the directories could be moved between the compilation and your debugging
7401 session. @value{GDBN} has a list of directories to search for source files;
7402 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
7403 it tries all the directories in the list, in the order they are present
7404 in the list, until it finds a file with the desired name.
7405
7406 For example, suppose an executable references the file
7407 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
7408 @file{/mnt/cross}. The file is first looked up literally; if this
7409 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
7410 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
7411 message is printed. @value{GDBN} does not look up the parts of the
7412 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
7413 Likewise, the subdirectories of the source path are not searched: if
7414 the source path is @file{/mnt/cross}, and the binary refers to
7415 @file{foo.c}, @value{GDBN} would not find it under
7416 @file{/mnt/cross/usr/src/foo-1.0/lib}.
7417
7418 Plain file names, relative file names with leading directories, file
7419 names containing dots, etc.@: are all treated as described above; for
7420 instance, if the source path is @file{/mnt/cross}, and the source file
7421 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
7422 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
7423 that---@file{/mnt/cross/foo.c}.
7424
7425 Note that the executable search path is @emph{not} used to locate the
7426 source files.
7427
7428 Whenever you reset or rearrange the source path, @value{GDBN} clears out
7429 any information it has cached about where source files are found and where
7430 each line is in the file.
7431
7432 @kindex directory
7433 @kindex dir
7434 When you start @value{GDBN}, its source path includes only @samp{cdir}
7435 and @samp{cwd}, in that order.
7436 To add other directories, use the @code{directory} command.
7437
7438 The search path is used to find both program source files and @value{GDBN}
7439 script files (read using the @samp{-command} option and @samp{source} command).
7440
7441 In addition to the source path, @value{GDBN} provides a set of commands
7442 that manage a list of source path substitution rules. A @dfn{substitution
7443 rule} specifies how to rewrite source directories stored in the program's
7444 debug information in case the sources were moved to a different
7445 directory between compilation and debugging. A rule is made of
7446 two strings, the first specifying what needs to be rewritten in
7447 the path, and the second specifying how it should be rewritten.
7448 In @ref{set substitute-path}, we name these two parts @var{from} and
7449 @var{to} respectively. @value{GDBN} does a simple string replacement
7450 of @var{from} with @var{to} at the start of the directory part of the
7451 source file name, and uses that result instead of the original file
7452 name to look up the sources.
7453
7454 Using the previous example, suppose the @file{foo-1.0} tree has been
7455 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
7456 @value{GDBN} to replace @file{/usr/src} in all source path names with
7457 @file{/mnt/cross}. The first lookup will then be
7458 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
7459 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
7460 substitution rule, use the @code{set substitute-path} command
7461 (@pxref{set substitute-path}).
7462
7463 To avoid unexpected substitution results, a rule is applied only if the
7464 @var{from} part of the directory name ends at a directory separator.
7465 For instance, a rule substituting @file{/usr/source} into
7466 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
7467 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
7468 is applied only at the beginning of the directory name, this rule will
7469 not be applied to @file{/root/usr/source/baz.c} either.
7470
7471 In many cases, you can achieve the same result using the @code{directory}
7472 command. However, @code{set substitute-path} can be more efficient in
7473 the case where the sources are organized in a complex tree with multiple
7474 subdirectories. With the @code{directory} command, you need to add each
7475 subdirectory of your project. If you moved the entire tree while
7476 preserving its internal organization, then @code{set substitute-path}
7477 allows you to direct the debugger to all the sources with one single
7478 command.
7479
7480 @code{set substitute-path} is also more than just a shortcut command.
7481 The source path is only used if the file at the original location no
7482 longer exists. On the other hand, @code{set substitute-path} modifies
7483 the debugger behavior to look at the rewritten location instead. So, if
7484 for any reason a source file that is not relevant to your executable is
7485 located at the original location, a substitution rule is the only
7486 method available to point @value{GDBN} at the new location.
7487
7488 @cindex @samp{--with-relocated-sources}
7489 @cindex default source path substitution
7490 You can configure a default source path substitution rule by
7491 configuring @value{GDBN} with the
7492 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
7493 should be the name of a directory under @value{GDBN}'s configured
7494 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
7495 directory names in debug information under @var{dir} will be adjusted
7496 automatically if the installed @value{GDBN} is moved to a new
7497 location. This is useful if @value{GDBN}, libraries or executables
7498 with debug information and corresponding source code are being moved
7499 together.
7500
7501 @table @code
7502 @item directory @var{dirname} @dots{}
7503 @item dir @var{dirname} @dots{}
7504 Add directory @var{dirname} to the front of the source path. Several
7505 directory names may be given to this command, separated by @samp{:}
7506 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
7507 part of absolute file names) or
7508 whitespace. You may specify a directory that is already in the source
7509 path; this moves it forward, so @value{GDBN} searches it sooner.
7510
7511 @kindex cdir
7512 @kindex cwd
7513 @vindex $cdir@r{, convenience variable}
7514 @vindex $cwd@r{, convenience variable}
7515 @cindex compilation directory
7516 @cindex current directory
7517 @cindex working directory
7518 @cindex directory, current
7519 @cindex directory, compilation
7520 You can use the string @samp{$cdir} to refer to the compilation
7521 directory (if one is recorded), and @samp{$cwd} to refer to the current
7522 working directory. @samp{$cwd} is not the same as @samp{.}---the former
7523 tracks the current working directory as it changes during your @value{GDBN}
7524 session, while the latter is immediately expanded to the current
7525 directory at the time you add an entry to the source path.
7526
7527 @item directory
7528 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
7529
7530 @c RET-repeat for @code{directory} is explicitly disabled, but since
7531 @c repeating it would be a no-op we do not say that. (thanks to RMS)
7532
7533 @item set directories @var{path-list}
7534 @kindex set directories
7535 Set the source path to @var{path-list}.
7536 @samp{$cdir:$cwd} are added if missing.
7537
7538 @item show directories
7539 @kindex show directories
7540 Print the source path: show which directories it contains.
7541
7542 @anchor{set substitute-path}
7543 @item set substitute-path @var{from} @var{to}
7544 @kindex set substitute-path
7545 Define a source path substitution rule, and add it at the end of the
7546 current list of existing substitution rules. If a rule with the same
7547 @var{from} was already defined, then the old rule is also deleted.
7548
7549 For example, if the file @file{/foo/bar/baz.c} was moved to
7550 @file{/mnt/cross/baz.c}, then the command
7551
7552 @smallexample
7553 (@value{GDBP}) set substitute-path /usr/src /mnt/cross
7554 @end smallexample
7555
7556 @noindent
7557 will tell @value{GDBN} to replace @samp{/usr/src} with
7558 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
7559 @file{baz.c} even though it was moved.
7560
7561 In the case when more than one substitution rule have been defined,
7562 the rules are evaluated one by one in the order where they have been
7563 defined. The first one matching, if any, is selected to perform
7564 the substitution.
7565
7566 For instance, if we had entered the following commands:
7567
7568 @smallexample
7569 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
7570 (@value{GDBP}) set substitute-path /usr/src /mnt/src
7571 @end smallexample
7572
7573 @noindent
7574 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
7575 @file{/mnt/include/defs.h} by using the first rule. However, it would
7576 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
7577 @file{/mnt/src/lib/foo.c}.
7578
7579
7580 @item unset substitute-path [path]
7581 @kindex unset substitute-path
7582 If a path is specified, search the current list of substitution rules
7583 for a rule that would rewrite that path. Delete that rule if found.
7584 A warning is emitted by the debugger if no rule could be found.
7585
7586 If no path is specified, then all substitution rules are deleted.
7587
7588 @item show substitute-path [path]
7589 @kindex show substitute-path
7590 If a path is specified, then print the source path substitution rule
7591 which would rewrite that path, if any.
7592
7593 If no path is specified, then print all existing source path substitution
7594 rules.
7595
7596 @end table
7597
7598 If your source path is cluttered with directories that are no longer of
7599 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
7600 versions of source. You can correct the situation as follows:
7601
7602 @enumerate
7603 @item
7604 Use @code{directory} with no argument to reset the source path to its default value.
7605
7606 @item
7607 Use @code{directory} with suitable arguments to reinstall the
7608 directories you want in the source path. You can add all the
7609 directories in one command.
7610 @end enumerate
7611
7612 @node Machine Code
7613 @section Source and Machine Code
7614 @cindex source line and its code address
7615
7616 You can use the command @code{info line} to map source lines to program
7617 addresses (and vice versa), and the command @code{disassemble} to display
7618 a range of addresses as machine instructions. You can use the command
7619 @code{set disassemble-next-line} to set whether to disassemble next
7620 source line when execution stops. When run under @sc{gnu} Emacs
7621 mode, the @code{info line} command causes the arrow to point to the
7622 line specified. Also, @code{info line} prints addresses in symbolic form as
7623 well as hex.
7624
7625 @table @code
7626 @kindex info line
7627 @item info line @var{linespec}
7628 Print the starting and ending addresses of the compiled code for
7629 source line @var{linespec}. You can specify source lines in any of
7630 the ways documented in @ref{Specify Location}.
7631 @end table
7632
7633 For example, we can use @code{info line} to discover the location of
7634 the object code for the first line of function
7635 @code{m4_changequote}:
7636
7637 @c FIXME: I think this example should also show the addresses in
7638 @c symbolic form, as they usually would be displayed.
7639 @smallexample
7640 (@value{GDBP}) info line m4_changequote
7641 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
7642 @end smallexample
7643
7644 @noindent
7645 @cindex code address and its source line
7646 We can also inquire (using @code{*@var{addr}} as the form for
7647 @var{linespec}) what source line covers a particular address:
7648 @smallexample
7649 (@value{GDBP}) info line *0x63ff
7650 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
7651 @end smallexample
7652
7653 @cindex @code{$_} and @code{info line}
7654 @cindex @code{x} command, default address
7655 @kindex x@r{(examine), and} info line
7656 After @code{info line}, the default address for the @code{x} command
7657 is changed to the starting address of the line, so that @samp{x/i} is
7658 sufficient to begin examining the machine code (@pxref{Memory,
7659 ,Examining Memory}). Also, this address is saved as the value of the
7660 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
7661 Variables}).
7662
7663 @table @code
7664 @kindex disassemble
7665 @cindex assembly instructions
7666 @cindex instructions, assembly
7667 @cindex machine instructions
7668 @cindex listing machine instructions
7669 @item disassemble
7670 @itemx disassemble /m
7671 @itemx disassemble /r
7672 This specialized command dumps a range of memory as machine
7673 instructions. It can also print mixed source+disassembly by specifying
7674 the @code{/m} modifier and print the raw instructions in hex as well as
7675 in symbolic form by specifying the @code{/r}.
7676 The default memory range is the function surrounding the
7677 program counter of the selected frame. A single argument to this
7678 command is a program counter value; @value{GDBN} dumps the function
7679 surrounding this value. When two arguments are given, they should
7680 be separated by a comma, possibly surrounded by whitespace. The
7681 arguments specify a range of addresses to dump, in one of two forms:
7682
7683 @table @code
7684 @item @var{start},@var{end}
7685 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
7686 @item @var{start},+@var{length}
7687 the addresses from @var{start} (inclusive) to
7688 @code{@var{start}+@var{length}} (exclusive).
7689 @end table
7690
7691 @noindent
7692 When 2 arguments are specified, the name of the function is also
7693 printed (since there could be several functions in the given range).
7694
7695 The argument(s) can be any expression yielding a numeric value, such as
7696 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
7697
7698 If the range of memory being disassembled contains current program counter,
7699 the instruction at that location is shown with a @code{=>} marker.
7700 @end table
7701
7702 The following example shows the disassembly of a range of addresses of
7703 HP PA-RISC 2.0 code:
7704
7705 @smallexample
7706 (@value{GDBP}) disas 0x32c4, 0x32e4
7707 Dump of assembler code from 0x32c4 to 0x32e4:
7708 0x32c4 <main+204>: addil 0,dp
7709 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
7710 0x32cc <main+212>: ldil 0x3000,r31
7711 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
7712 0x32d4 <main+220>: ldo 0(r31),rp
7713 0x32d8 <main+224>: addil -0x800,dp
7714 0x32dc <main+228>: ldo 0x588(r1),r26
7715 0x32e0 <main+232>: ldil 0x3000,r31
7716 End of assembler dump.
7717 @end smallexample
7718
7719 Here is an example showing mixed source+assembly for Intel x86, when the
7720 program is stopped just after function prologue:
7721
7722 @smallexample
7723 (@value{GDBP}) disas /m main
7724 Dump of assembler code for function main:
7725 5 @{
7726 0x08048330 <+0>: push %ebp
7727 0x08048331 <+1>: mov %esp,%ebp
7728 0x08048333 <+3>: sub $0x8,%esp
7729 0x08048336 <+6>: and $0xfffffff0,%esp
7730 0x08048339 <+9>: sub $0x10,%esp
7731
7732 6 printf ("Hello.\n");
7733 => 0x0804833c <+12>: movl $0x8048440,(%esp)
7734 0x08048343 <+19>: call 0x8048284 <puts@@plt>
7735
7736 7 return 0;
7737 8 @}
7738 0x08048348 <+24>: mov $0x0,%eax
7739 0x0804834d <+29>: leave
7740 0x0804834e <+30>: ret
7741
7742 End of assembler dump.
7743 @end smallexample
7744
7745 Here is another example showing raw instructions in hex for AMD x86-64,
7746
7747 @smallexample
7748 (gdb) disas /r 0x400281,+10
7749 Dump of assembler code from 0x400281 to 0x40028b:
7750 0x0000000000400281: 38 36 cmp %dh,(%rsi)
7751 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
7752 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
7753 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
7754 End of assembler dump.
7755 @end smallexample
7756
7757 Addresses cannot be specified as a linespec (@pxref{Specify Location}).
7758 So, for example, if you want to disassemble function @code{bar}
7759 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
7760 and not @samp{disassemble foo.c:bar}.
7761
7762 Some architectures have more than one commonly-used set of instruction
7763 mnemonics or other syntax.
7764
7765 For programs that were dynamically linked and use shared libraries,
7766 instructions that call functions or branch to locations in the shared
7767 libraries might show a seemingly bogus location---it's actually a
7768 location of the relocation table. On some architectures, @value{GDBN}
7769 might be able to resolve these to actual function names.
7770
7771 @table @code
7772 @kindex set disassembly-flavor
7773 @cindex Intel disassembly flavor
7774 @cindex AT&T disassembly flavor
7775 @item set disassembly-flavor @var{instruction-set}
7776 Select the instruction set to use when disassembling the
7777 program via the @code{disassemble} or @code{x/i} commands.
7778
7779 Currently this command is only defined for the Intel x86 family. You
7780 can set @var{instruction-set} to either @code{intel} or @code{att}.
7781 The default is @code{att}, the AT&T flavor used by default by Unix
7782 assemblers for x86-based targets.
7783
7784 @kindex show disassembly-flavor
7785 @item show disassembly-flavor
7786 Show the current setting of the disassembly flavor.
7787 @end table
7788
7789 @table @code
7790 @kindex set disassemble-next-line
7791 @kindex show disassemble-next-line
7792 @item set disassemble-next-line
7793 @itemx show disassemble-next-line
7794 Control whether or not @value{GDBN} will disassemble the next source
7795 line or instruction when execution stops. If ON, @value{GDBN} will
7796 display disassembly of the next source line when execution of the
7797 program being debugged stops. This is @emph{in addition} to
7798 displaying the source line itself, which @value{GDBN} always does if
7799 possible. If the next source line cannot be displayed for some reason
7800 (e.g., if @value{GDBN} cannot find the source file, or there's no line
7801 info in the debug info), @value{GDBN} will display disassembly of the
7802 next @emph{instruction} instead of showing the next source line. If
7803 AUTO, @value{GDBN} will display disassembly of next instruction only
7804 if the source line cannot be displayed. This setting causes
7805 @value{GDBN} to display some feedback when you step through a function
7806 with no line info or whose source file is unavailable. The default is
7807 OFF, which means never display the disassembly of the next line or
7808 instruction.
7809 @end table
7810
7811
7812 @node Data
7813 @chapter Examining Data
7814
7815 @cindex printing data
7816 @cindex examining data
7817 @kindex print
7818 @kindex inspect
7819 The usual way to examine data in your program is with the @code{print}
7820 command (abbreviated @code{p}), or its synonym @code{inspect}. It
7821 evaluates and prints the value of an expression of the language your
7822 program is written in (@pxref{Languages, ,Using @value{GDBN} with
7823 Different Languages}). It may also print the expression using a
7824 Python-based pretty-printer (@pxref{Pretty Printing}).
7825
7826 @table @code
7827 @item print @var{expr}
7828 @itemx print /@var{f} @var{expr}
7829 @var{expr} is an expression (in the source language). By default the
7830 value of @var{expr} is printed in a format appropriate to its data type;
7831 you can choose a different format by specifying @samp{/@var{f}}, where
7832 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
7833 Formats}.
7834
7835 @item print
7836 @itemx print /@var{f}
7837 @cindex reprint the last value
7838 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
7839 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
7840 conveniently inspect the same value in an alternative format.
7841 @end table
7842
7843 A more low-level way of examining data is with the @code{x} command.
7844 It examines data in memory at a specified address and prints it in a
7845 specified format. @xref{Memory, ,Examining Memory}.
7846
7847 If you are interested in information about types, or about how the
7848 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
7849 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7850 Table}.
7851
7852 @cindex exploring hierarchical data structures
7853 @kindex explore
7854 Another way of examining values of expressions and type information is
7855 through the Python extension command @code{explore} (available only if
7856 the @value{GDBN} build is configured with @code{--with-python}). It
7857 offers an interactive way to start at the highest level (or, the most
7858 abstract level) of the data type of an expression (or, the data type
7859 itself) and explore all the way down to leaf scalar values/fields
7860 embedded in the higher level data types.
7861
7862 @table @code
7863 @item explore @var{arg}
7864 @var{arg} is either an expression (in the source language), or a type
7865 visible in the current context of the program being debugged.
7866 @end table
7867
7868 The working of the @code{explore} command can be illustrated with an
7869 example. If a data type @code{struct ComplexStruct} is defined in your
7870 C program as
7871
7872 @smallexample
7873 struct SimpleStruct
7874 @{
7875 int i;
7876 double d;
7877 @};
7878
7879 struct ComplexStruct
7880 @{
7881 struct SimpleStruct *ss_p;
7882 int arr[10];
7883 @};
7884 @end smallexample
7885
7886 @noindent
7887 followed by variable declarations as
7888
7889 @smallexample
7890 struct SimpleStruct ss = @{ 10, 1.11 @};
7891 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
7892 @end smallexample
7893
7894 @noindent
7895 then, the value of the variable @code{cs} can be explored using the
7896 @code{explore} command as follows.
7897
7898 @smallexample
7899 (gdb) explore cs
7900 The value of `cs' is a struct/class of type `struct ComplexStruct' with
7901 the following fields:
7902
7903 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
7904 arr = <Enter 1 to explore this field of type `int [10]'>
7905
7906 Enter the field number of choice:
7907 @end smallexample
7908
7909 @noindent
7910 Since the fields of @code{cs} are not scalar values, you are being
7911 prompted to chose the field you want to explore. Let's say you choose
7912 the field @code{ss_p} by entering @code{0}. Then, since this field is a
7913 pointer, you will be asked if it is pointing to a single value. From
7914 the declaration of @code{cs} above, it is indeed pointing to a single
7915 value, hence you enter @code{y}. If you enter @code{n}, then you will
7916 be asked if it were pointing to an array of values, in which case this
7917 field will be explored as if it were an array.
7918
7919 @smallexample
7920 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
7921 Continue exploring it as a pointer to a single value [y/n]: y
7922 The value of `*(cs.ss_p)' is a struct/class of type `struct
7923 SimpleStruct' with the following fields:
7924
7925 i = 10 .. (Value of type `int')
7926 d = 1.1100000000000001 .. (Value of type `double')
7927
7928 Press enter to return to parent value:
7929 @end smallexample
7930
7931 @noindent
7932 If the field @code{arr} of @code{cs} was chosen for exploration by
7933 entering @code{1} earlier, then since it is as array, you will be
7934 prompted to enter the index of the element in the array that you want
7935 to explore.
7936
7937 @smallexample
7938 `cs.arr' is an array of `int'.
7939 Enter the index of the element you want to explore in `cs.arr': 5
7940
7941 `(cs.arr)[5]' is a scalar value of type `int'.
7942
7943 (cs.arr)[5] = 4
7944
7945 Press enter to return to parent value:
7946 @end smallexample
7947
7948 In general, at any stage of exploration, you can go deeper towards the
7949 leaf values by responding to the prompts appropriately, or hit the
7950 return key to return to the enclosing data structure (the @i{higher}
7951 level data structure).
7952
7953 Similar to exploring values, you can use the @code{explore} command to
7954 explore types. Instead of specifying a value (which is typically a
7955 variable name or an expression valid in the current context of the
7956 program being debugged), you specify a type name. If you consider the
7957 same example as above, your can explore the type
7958 @code{struct ComplexStruct} by passing the argument
7959 @code{struct ComplexStruct} to the @code{explore} command.
7960
7961 @smallexample
7962 (gdb) explore struct ComplexStruct
7963 @end smallexample
7964
7965 @noindent
7966 By responding to the prompts appropriately in the subsequent interactive
7967 session, you can explore the type @code{struct ComplexStruct} in a
7968 manner similar to how the value @code{cs} was explored in the above
7969 example.
7970
7971 The @code{explore} command also has two sub-commands,
7972 @code{explore value} and @code{explore type}. The former sub-command is
7973 a way to explicitly specify that value exploration of the argument is
7974 being invoked, while the latter is a way to explicitly specify that type
7975 exploration of the argument is being invoked.
7976
7977 @table @code
7978 @item explore value @var{expr}
7979 @cindex explore value
7980 This sub-command of @code{explore} explores the value of the
7981 expression @var{expr} (if @var{expr} is an expression valid in the
7982 current context of the program being debugged). The behavior of this
7983 command is identical to that of the behavior of the @code{explore}
7984 command being passed the argument @var{expr}.
7985
7986 @item explore type @var{arg}
7987 @cindex explore type
7988 This sub-command of @code{explore} explores the type of @var{arg} (if
7989 @var{arg} is a type visible in the current context of program being
7990 debugged), or the type of the value/expression @var{arg} (if @var{arg}
7991 is an expression valid in the current context of the program being
7992 debugged). If @var{arg} is a type, then the behavior of this command is
7993 identical to that of the @code{explore} command being passed the
7994 argument @var{arg}. If @var{arg} is an expression, then the behavior of
7995 this command will be identical to that of the @code{explore} command
7996 being passed the type of @var{arg} as the argument.
7997 @end table
7998
7999 @menu
8000 * Expressions:: Expressions
8001 * Ambiguous Expressions:: Ambiguous Expressions
8002 * Variables:: Program variables
8003 * Arrays:: Artificial arrays
8004 * Output Formats:: Output formats
8005 * Memory:: Examining memory
8006 * Auto Display:: Automatic display
8007 * Print Settings:: Print settings
8008 * Pretty Printing:: Python pretty printing
8009 * Value History:: Value history
8010 * Convenience Vars:: Convenience variables
8011 * Convenience Funs:: Convenience functions
8012 * Registers:: Registers
8013 * Floating Point Hardware:: Floating point hardware
8014 * Vector Unit:: Vector Unit
8015 * OS Information:: Auxiliary data provided by operating system
8016 * Memory Region Attributes:: Memory region attributes
8017 * Dump/Restore Files:: Copy between memory and a file
8018 * Core File Generation:: Cause a program dump its core
8019 * Character Sets:: Debugging programs that use a different
8020 character set than GDB does
8021 * Caching Remote Data:: Data caching for remote targets
8022 * Searching Memory:: Searching memory for a sequence of bytes
8023 @end menu
8024
8025 @node Expressions
8026 @section Expressions
8027
8028 @cindex expressions
8029 @code{print} and many other @value{GDBN} commands accept an expression and
8030 compute its value. Any kind of constant, variable or operator defined
8031 by the programming language you are using is valid in an expression in
8032 @value{GDBN}. This includes conditional expressions, function calls,
8033 casts, and string constants. It also includes preprocessor macros, if
8034 you compiled your program to include this information; see
8035 @ref{Compilation}.
8036
8037 @cindex arrays in expressions
8038 @value{GDBN} supports array constants in expressions input by
8039 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
8040 you can use the command @code{print @{1, 2, 3@}} to create an array
8041 of three integers. If you pass an array to a function or assign it
8042 to a program variable, @value{GDBN} copies the array to memory that
8043 is @code{malloc}ed in the target program.
8044
8045 Because C is so widespread, most of the expressions shown in examples in
8046 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
8047 Languages}, for information on how to use expressions in other
8048 languages.
8049
8050 In this section, we discuss operators that you can use in @value{GDBN}
8051 expressions regardless of your programming language.
8052
8053 @cindex casts, in expressions
8054 Casts are supported in all languages, not just in C, because it is so
8055 useful to cast a number into a pointer in order to examine a structure
8056 at that address in memory.
8057 @c FIXME: casts supported---Mod2 true?
8058
8059 @value{GDBN} supports these operators, in addition to those common
8060 to programming languages:
8061
8062 @table @code
8063 @item @@
8064 @samp{@@} is a binary operator for treating parts of memory as arrays.
8065 @xref{Arrays, ,Artificial Arrays}, for more information.
8066
8067 @item ::
8068 @samp{::} allows you to specify a variable in terms of the file or
8069 function where it is defined. @xref{Variables, ,Program Variables}.
8070
8071 @cindex @{@var{type}@}
8072 @cindex type casting memory
8073 @cindex memory, viewing as typed object
8074 @cindex casts, to view memory
8075 @item @{@var{type}@} @var{addr}
8076 Refers to an object of type @var{type} stored at address @var{addr} in
8077 memory. @var{addr} may be any expression whose value is an integer or
8078 pointer (but parentheses are required around binary operators, just as in
8079 a cast). This construct is allowed regardless of what kind of data is
8080 normally supposed to reside at @var{addr}.
8081 @end table
8082
8083 @node Ambiguous Expressions
8084 @section Ambiguous Expressions
8085 @cindex ambiguous expressions
8086
8087 Expressions can sometimes contain some ambiguous elements. For instance,
8088 some programming languages (notably Ada, C@t{++} and Objective-C) permit
8089 a single function name to be defined several times, for application in
8090 different contexts. This is called @dfn{overloading}. Another example
8091 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
8092 templates and is typically instantiated several times, resulting in
8093 the same function name being defined in different contexts.
8094
8095 In some cases and depending on the language, it is possible to adjust
8096 the expression to remove the ambiguity. For instance in C@t{++}, you
8097 can specify the signature of the function you want to break on, as in
8098 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
8099 qualified name of your function often makes the expression unambiguous
8100 as well.
8101
8102 When an ambiguity that needs to be resolved is detected, the debugger
8103 has the capability to display a menu of numbered choices for each
8104 possibility, and then waits for the selection with the prompt @samp{>}.
8105 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
8106 aborts the current command. If the command in which the expression was
8107 used allows more than one choice to be selected, the next option in the
8108 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
8109 choices.
8110
8111 For example, the following session excerpt shows an attempt to set a
8112 breakpoint at the overloaded symbol @code{String::after}.
8113 We choose three particular definitions of that function name:
8114
8115 @c FIXME! This is likely to change to show arg type lists, at least
8116 @smallexample
8117 @group
8118 (@value{GDBP}) b String::after
8119 [0] cancel
8120 [1] all
8121 [2] file:String.cc; line number:867
8122 [3] file:String.cc; line number:860
8123 [4] file:String.cc; line number:875
8124 [5] file:String.cc; line number:853
8125 [6] file:String.cc; line number:846
8126 [7] file:String.cc; line number:735
8127 > 2 4 6
8128 Breakpoint 1 at 0xb26c: file String.cc, line 867.
8129 Breakpoint 2 at 0xb344: file String.cc, line 875.
8130 Breakpoint 3 at 0xafcc: file String.cc, line 846.
8131 Multiple breakpoints were set.
8132 Use the "delete" command to delete unwanted
8133 breakpoints.
8134 (@value{GDBP})
8135 @end group
8136 @end smallexample
8137
8138 @table @code
8139 @kindex set multiple-symbols
8140 @item set multiple-symbols @var{mode}
8141 @cindex multiple-symbols menu
8142
8143 This option allows you to adjust the debugger behavior when an expression
8144 is ambiguous.
8145
8146 By default, @var{mode} is set to @code{all}. If the command with which
8147 the expression is used allows more than one choice, then @value{GDBN}
8148 automatically selects all possible choices. For instance, inserting
8149 a breakpoint on a function using an ambiguous name results in a breakpoint
8150 inserted on each possible match. However, if a unique choice must be made,
8151 then @value{GDBN} uses the menu to help you disambiguate the expression.
8152 For instance, printing the address of an overloaded function will result
8153 in the use of the menu.
8154
8155 When @var{mode} is set to @code{ask}, the debugger always uses the menu
8156 when an ambiguity is detected.
8157
8158 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
8159 an error due to the ambiguity and the command is aborted.
8160
8161 @kindex show multiple-symbols
8162 @item show multiple-symbols
8163 Show the current value of the @code{multiple-symbols} setting.
8164 @end table
8165
8166 @node Variables
8167 @section Program Variables
8168
8169 The most common kind of expression to use is the name of a variable
8170 in your program.
8171
8172 Variables in expressions are understood in the selected stack frame
8173 (@pxref{Selection, ,Selecting a Frame}); they must be either:
8174
8175 @itemize @bullet
8176 @item
8177 global (or file-static)
8178 @end itemize
8179
8180 @noindent or
8181
8182 @itemize @bullet
8183 @item
8184 visible according to the scope rules of the
8185 programming language from the point of execution in that frame
8186 @end itemize
8187
8188 @noindent This means that in the function
8189
8190 @smallexample
8191 foo (a)
8192 int a;
8193 @{
8194 bar (a);
8195 @{
8196 int b = test ();
8197 bar (b);
8198 @}
8199 @}
8200 @end smallexample
8201
8202 @noindent
8203 you can examine and use the variable @code{a} whenever your program is
8204 executing within the function @code{foo}, but you can only use or
8205 examine the variable @code{b} while your program is executing inside
8206 the block where @code{b} is declared.
8207
8208 @cindex variable name conflict
8209 There is an exception: you can refer to a variable or function whose
8210 scope is a single source file even if the current execution point is not
8211 in this file. But it is possible to have more than one such variable or
8212 function with the same name (in different source files). If that
8213 happens, referring to that name has unpredictable effects. If you wish,
8214 you can specify a static variable in a particular function or file by
8215 using the colon-colon (@code{::}) notation:
8216
8217 @cindex colon-colon, context for variables/functions
8218 @ifnotinfo
8219 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
8220 @cindex @code{::}, context for variables/functions
8221 @end ifnotinfo
8222 @smallexample
8223 @var{file}::@var{variable}
8224 @var{function}::@var{variable}
8225 @end smallexample
8226
8227 @noindent
8228 Here @var{file} or @var{function} is the name of the context for the
8229 static @var{variable}. In the case of file names, you can use quotes to
8230 make sure @value{GDBN} parses the file name as a single word---for example,
8231 to print a global value of @code{x} defined in @file{f2.c}:
8232
8233 @smallexample
8234 (@value{GDBP}) p 'f2.c'::x
8235 @end smallexample
8236
8237 The @code{::} notation is normally used for referring to
8238 static variables, since you typically disambiguate uses of local variables
8239 in functions by selecting the appropriate frame and using the
8240 simple name of the variable. However, you may also use this notation
8241 to refer to local variables in frames enclosing the selected frame:
8242
8243 @smallexample
8244 void
8245 foo (int a)
8246 @{
8247 if (a < 10)
8248 bar (a);
8249 else
8250 process (a); /* Stop here */
8251 @}
8252
8253 int
8254 bar (int a)
8255 @{
8256 foo (a + 5);
8257 @}
8258 @end smallexample
8259
8260 @noindent
8261 For example, if there is a breakpoint at the commented line,
8262 here is what you might see
8263 when the program stops after executing the call @code{bar(0)}:
8264
8265 @smallexample
8266 (@value{GDBP}) p a
8267 $1 = 10
8268 (@value{GDBP}) p bar::a
8269 $2 = 5
8270 (@value{GDBP}) up 2
8271 #2 0x080483d0 in foo (a=5) at foobar.c:12
8272 (@value{GDBP}) p a
8273 $3 = 5
8274 (@value{GDBP}) p bar::a
8275 $4 = 0
8276 @end smallexample
8277
8278 @cindex C@t{++} scope resolution
8279 These uses of @samp{::} are very rarely in conflict with the very similar
8280 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
8281 scope resolution operator in @value{GDBN} expressions.
8282 @c FIXME: Um, so what happens in one of those rare cases where it's in
8283 @c conflict?? --mew
8284
8285 @cindex wrong values
8286 @cindex variable values, wrong
8287 @cindex function entry/exit, wrong values of variables
8288 @cindex optimized code, wrong values of variables
8289 @quotation
8290 @emph{Warning:} Occasionally, a local variable may appear to have the
8291 wrong value at certain points in a function---just after entry to a new
8292 scope, and just before exit.
8293 @end quotation
8294 You may see this problem when you are stepping by machine instructions.
8295 This is because, on most machines, it takes more than one instruction to
8296 set up a stack frame (including local variable definitions); if you are
8297 stepping by machine instructions, variables may appear to have the wrong
8298 values until the stack frame is completely built. On exit, it usually
8299 also takes more than one machine instruction to destroy a stack frame;
8300 after you begin stepping through that group of instructions, local
8301 variable definitions may be gone.
8302
8303 This may also happen when the compiler does significant optimizations.
8304 To be sure of always seeing accurate values, turn off all optimization
8305 when compiling.
8306
8307 @cindex ``No symbol "foo" in current context''
8308 Another possible effect of compiler optimizations is to optimize
8309 unused variables out of existence, or assign variables to registers (as
8310 opposed to memory addresses). Depending on the support for such cases
8311 offered by the debug info format used by the compiler, @value{GDBN}
8312 might not be able to display values for such local variables. If that
8313 happens, @value{GDBN} will print a message like this:
8314
8315 @smallexample
8316 No symbol "foo" in current context.
8317 @end smallexample
8318
8319 To solve such problems, either recompile without optimizations, or use a
8320 different debug info format, if the compiler supports several such
8321 formats. @xref{Compilation}, for more information on choosing compiler
8322 options. @xref{C, ,C and C@t{++}}, for more information about debug
8323 info formats that are best suited to C@t{++} programs.
8324
8325 If you ask to print an object whose contents are unknown to
8326 @value{GDBN}, e.g., because its data type is not completely specified
8327 by the debug information, @value{GDBN} will say @samp{<incomplete
8328 type>}. @xref{Symbols, incomplete type}, for more about this.
8329
8330 If you append @kbd{@@entry} string to a function parameter name you get its
8331 value at the time the function got called. If the value is not available an
8332 error message is printed. Entry values are available only with some compilers.
8333 Entry values are normally also printed at the function parameter list according
8334 to @ref{set print entry-values}.
8335
8336 @smallexample
8337 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
8338 29 i++;
8339 (gdb) next
8340 30 e (i);
8341 (gdb) print i
8342 $1 = 31
8343 (gdb) print i@@entry
8344 $2 = 30
8345 @end smallexample
8346
8347 Strings are identified as arrays of @code{char} values without specified
8348 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
8349 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
8350 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
8351 defines literal string type @code{"char"} as @code{char} without a sign.
8352 For program code
8353
8354 @smallexample
8355 char var0[] = "A";
8356 signed char var1[] = "A";
8357 @end smallexample
8358
8359 You get during debugging
8360 @smallexample
8361 (gdb) print var0
8362 $1 = "A"
8363 (gdb) print var1
8364 $2 = @{65 'A', 0 '\0'@}
8365 @end smallexample
8366
8367 @node Arrays
8368 @section Artificial Arrays
8369
8370 @cindex artificial array
8371 @cindex arrays
8372 @kindex @@@r{, referencing memory as an array}
8373 It is often useful to print out several successive objects of the
8374 same type in memory; a section of an array, or an array of
8375 dynamically determined size for which only a pointer exists in the
8376 program.
8377
8378 You can do this by referring to a contiguous span of memory as an
8379 @dfn{artificial array}, using the binary operator @samp{@@}. The left
8380 operand of @samp{@@} should be the first element of the desired array
8381 and be an individual object. The right operand should be the desired length
8382 of the array. The result is an array value whose elements are all of
8383 the type of the left argument. The first element is actually the left
8384 argument; the second element comes from bytes of memory immediately
8385 following those that hold the first element, and so on. Here is an
8386 example. If a program says
8387
8388 @smallexample
8389 int *array = (int *) malloc (len * sizeof (int));
8390 @end smallexample
8391
8392 @noindent
8393 you can print the contents of @code{array} with
8394
8395 @smallexample
8396 p *array@@len
8397 @end smallexample
8398
8399 The left operand of @samp{@@} must reside in memory. Array values made
8400 with @samp{@@} in this way behave just like other arrays in terms of
8401 subscripting, and are coerced to pointers when used in expressions.
8402 Artificial arrays most often appear in expressions via the value history
8403 (@pxref{Value History, ,Value History}), after printing one out.
8404
8405 Another way to create an artificial array is to use a cast.
8406 This re-interprets a value as if it were an array.
8407 The value need not be in memory:
8408 @smallexample
8409 (@value{GDBP}) p/x (short[2])0x12345678
8410 $1 = @{0x1234, 0x5678@}
8411 @end smallexample
8412
8413 As a convenience, if you leave the array length out (as in
8414 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
8415 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
8416 @smallexample
8417 (@value{GDBP}) p/x (short[])0x12345678
8418 $2 = @{0x1234, 0x5678@}
8419 @end smallexample
8420
8421 Sometimes the artificial array mechanism is not quite enough; in
8422 moderately complex data structures, the elements of interest may not
8423 actually be adjacent---for example, if you are interested in the values
8424 of pointers in an array. One useful work-around in this situation is
8425 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
8426 Variables}) as a counter in an expression that prints the first
8427 interesting value, and then repeat that expression via @key{RET}. For
8428 instance, suppose you have an array @code{dtab} of pointers to
8429 structures, and you are interested in the values of a field @code{fv}
8430 in each structure. Here is an example of what you might type:
8431
8432 @smallexample
8433 set $i = 0
8434 p dtab[$i++]->fv
8435 @key{RET}
8436 @key{RET}
8437 @dots{}
8438 @end smallexample
8439
8440 @node Output Formats
8441 @section Output Formats
8442
8443 @cindex formatted output
8444 @cindex output formats
8445 By default, @value{GDBN} prints a value according to its data type. Sometimes
8446 this is not what you want. For example, you might want to print a number
8447 in hex, or a pointer in decimal. Or you might want to view data in memory
8448 at a certain address as a character string or as an instruction. To do
8449 these things, specify an @dfn{output format} when you print a value.
8450
8451 The simplest use of output formats is to say how to print a value
8452 already computed. This is done by starting the arguments of the
8453 @code{print} command with a slash and a format letter. The format
8454 letters supported are:
8455
8456 @table @code
8457 @item x
8458 Regard the bits of the value as an integer, and print the integer in
8459 hexadecimal.
8460
8461 @item d
8462 Print as integer in signed decimal.
8463
8464 @item u
8465 Print as integer in unsigned decimal.
8466
8467 @item o
8468 Print as integer in octal.
8469
8470 @item t
8471 Print as integer in binary. The letter @samp{t} stands for ``two''.
8472 @footnote{@samp{b} cannot be used because these format letters are also
8473 used with the @code{x} command, where @samp{b} stands for ``byte'';
8474 see @ref{Memory,,Examining Memory}.}
8475
8476 @item a
8477 @cindex unknown address, locating
8478 @cindex locate address
8479 Print as an address, both absolute in hexadecimal and as an offset from
8480 the nearest preceding symbol. You can use this format used to discover
8481 where (in what function) an unknown address is located:
8482
8483 @smallexample
8484 (@value{GDBP}) p/a 0x54320
8485 $3 = 0x54320 <_initialize_vx+396>
8486 @end smallexample
8487
8488 @noindent
8489 The command @code{info symbol 0x54320} yields similar results.
8490 @xref{Symbols, info symbol}.
8491
8492 @item c
8493 Regard as an integer and print it as a character constant. This
8494 prints both the numerical value and its character representation. The
8495 character representation is replaced with the octal escape @samp{\nnn}
8496 for characters outside the 7-bit @sc{ascii} range.
8497
8498 Without this format, @value{GDBN} displays @code{char},
8499 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
8500 constants. Single-byte members of vectors are displayed as integer
8501 data.
8502
8503 @item f
8504 Regard the bits of the value as a floating point number and print
8505 using typical floating point syntax.
8506
8507 @item s
8508 @cindex printing strings
8509 @cindex printing byte arrays
8510 Regard as a string, if possible. With this format, pointers to single-byte
8511 data are displayed as null-terminated strings and arrays of single-byte data
8512 are displayed as fixed-length strings. Other values are displayed in their
8513 natural types.
8514
8515 Without this format, @value{GDBN} displays pointers to and arrays of
8516 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
8517 strings. Single-byte members of a vector are displayed as an integer
8518 array.
8519
8520 @item z
8521 Like @samp{x} formatting, the value is treated as an integer and
8522 printed as hexadecimal, but leading zeros are printed to pad the value
8523 to the size of the integer type.
8524
8525 @item r
8526 @cindex raw printing
8527 Print using the @samp{raw} formatting. By default, @value{GDBN} will
8528 use a Python-based pretty-printer, if one is available (@pxref{Pretty
8529 Printing}). This typically results in a higher-level display of the
8530 value's contents. The @samp{r} format bypasses any Python
8531 pretty-printer which might exist.
8532 @end table
8533
8534 For example, to print the program counter in hex (@pxref{Registers}), type
8535
8536 @smallexample
8537 p/x $pc
8538 @end smallexample
8539
8540 @noindent
8541 Note that no space is required before the slash; this is because command
8542 names in @value{GDBN} cannot contain a slash.
8543
8544 To reprint the last value in the value history with a different format,
8545 you can use the @code{print} command with just a format and no
8546 expression. For example, @samp{p/x} reprints the last value in hex.
8547
8548 @node Memory
8549 @section Examining Memory
8550
8551 You can use the command @code{x} (for ``examine'') to examine memory in
8552 any of several formats, independently of your program's data types.
8553
8554 @cindex examining memory
8555 @table @code
8556 @kindex x @r{(examine memory)}
8557 @item x/@var{nfu} @var{addr}
8558 @itemx x @var{addr}
8559 @itemx x
8560 Use the @code{x} command to examine memory.
8561 @end table
8562
8563 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
8564 much memory to display and how to format it; @var{addr} is an
8565 expression giving the address where you want to start displaying memory.
8566 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
8567 Several commands set convenient defaults for @var{addr}.
8568
8569 @table @r
8570 @item @var{n}, the repeat count
8571 The repeat count is a decimal integer; the default is 1. It specifies
8572 how much memory (counting by units @var{u}) to display.
8573 @c This really is **decimal**; unaffected by 'set radix' as of GDB
8574 @c 4.1.2.
8575
8576 @item @var{f}, the display format
8577 The display format is one of the formats used by @code{print}
8578 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
8579 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
8580 The default is @samp{x} (hexadecimal) initially. The default changes
8581 each time you use either @code{x} or @code{print}.
8582
8583 @item @var{u}, the unit size
8584 The unit size is any of
8585
8586 @table @code
8587 @item b
8588 Bytes.
8589 @item h
8590 Halfwords (two bytes).
8591 @item w
8592 Words (four bytes). This is the initial default.
8593 @item g
8594 Giant words (eight bytes).
8595 @end table
8596
8597 Each time you specify a unit size with @code{x}, that size becomes the
8598 default unit the next time you use @code{x}. For the @samp{i} format,
8599 the unit size is ignored and is normally not written. For the @samp{s} format,
8600 the unit size defaults to @samp{b}, unless it is explicitly given.
8601 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
8602 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
8603 Note that the results depend on the programming language of the
8604 current compilation unit. If the language is C, the @samp{s}
8605 modifier will use the UTF-16 encoding while @samp{w} will use
8606 UTF-32. The encoding is set by the programming language and cannot
8607 be altered.
8608
8609 @item @var{addr}, starting display address
8610 @var{addr} is the address where you want @value{GDBN} to begin displaying
8611 memory. The expression need not have a pointer value (though it may);
8612 it is always interpreted as an integer address of a byte of memory.
8613 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
8614 @var{addr} is usually just after the last address examined---but several
8615 other commands also set the default address: @code{info breakpoints} (to
8616 the address of the last breakpoint listed), @code{info line} (to the
8617 starting address of a line), and @code{print} (if you use it to display
8618 a value from memory).
8619 @end table
8620
8621 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
8622 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
8623 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
8624 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
8625 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
8626
8627 Since the letters indicating unit sizes are all distinct from the
8628 letters specifying output formats, you do not have to remember whether
8629 unit size or format comes first; either order works. The output
8630 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
8631 (However, the count @var{n} must come first; @samp{wx4} does not work.)
8632
8633 Even though the unit size @var{u} is ignored for the formats @samp{s}
8634 and @samp{i}, you might still want to use a count @var{n}; for example,
8635 @samp{3i} specifies that you want to see three machine instructions,
8636 including any operands. For convenience, especially when used with
8637 the @code{display} command, the @samp{i} format also prints branch delay
8638 slot instructions, if any, beyond the count specified, which immediately
8639 follow the last instruction that is within the count. The command
8640 @code{disassemble} gives an alternative way of inspecting machine
8641 instructions; see @ref{Machine Code,,Source and Machine Code}.
8642
8643 All the defaults for the arguments to @code{x} are designed to make it
8644 easy to continue scanning memory with minimal specifications each time
8645 you use @code{x}. For example, after you have inspected three machine
8646 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
8647 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
8648 the repeat count @var{n} is used again; the other arguments default as
8649 for successive uses of @code{x}.
8650
8651 When examining machine instructions, the instruction at current program
8652 counter is shown with a @code{=>} marker. For example:
8653
8654 @smallexample
8655 (@value{GDBP}) x/5i $pc-6
8656 0x804837f <main+11>: mov %esp,%ebp
8657 0x8048381 <main+13>: push %ecx
8658 0x8048382 <main+14>: sub $0x4,%esp
8659 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
8660 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
8661 @end smallexample
8662
8663 @cindex @code{$_}, @code{$__}, and value history
8664 The addresses and contents printed by the @code{x} command are not saved
8665 in the value history because there is often too much of them and they
8666 would get in the way. Instead, @value{GDBN} makes these values available for
8667 subsequent use in expressions as values of the convenience variables
8668 @code{$_} and @code{$__}. After an @code{x} command, the last address
8669 examined is available for use in expressions in the convenience variable
8670 @code{$_}. The contents of that address, as examined, are available in
8671 the convenience variable @code{$__}.
8672
8673 If the @code{x} command has a repeat count, the address and contents saved
8674 are from the last memory unit printed; this is not the same as the last
8675 address printed if several units were printed on the last line of output.
8676
8677 @cindex remote memory comparison
8678 @cindex verify remote memory image
8679 When you are debugging a program running on a remote target machine
8680 (@pxref{Remote Debugging}), you may wish to verify the program's image in the
8681 remote machine's memory against the executable file you downloaded to
8682 the target. The @code{compare-sections} command is provided for such
8683 situations.
8684
8685 @table @code
8686 @kindex compare-sections
8687 @item compare-sections @r{[}@var{section-name}@r{]}
8688 Compare the data of a loadable section @var{section-name} in the
8689 executable file of the program being debugged with the same section in
8690 the remote machine's memory, and report any mismatches. With no
8691 arguments, compares all loadable sections. This command's
8692 availability depends on the target's support for the @code{"qCRC"}
8693 remote request.
8694 @end table
8695
8696 @node Auto Display
8697 @section Automatic Display
8698 @cindex automatic display
8699 @cindex display of expressions
8700
8701 If you find that you want to print the value of an expression frequently
8702 (to see how it changes), you might want to add it to the @dfn{automatic
8703 display list} so that @value{GDBN} prints its value each time your program stops.
8704 Each expression added to the list is given a number to identify it;
8705 to remove an expression from the list, you specify that number.
8706 The automatic display looks like this:
8707
8708 @smallexample
8709 2: foo = 38
8710 3: bar[5] = (struct hack *) 0x3804
8711 @end smallexample
8712
8713 @noindent
8714 This display shows item numbers, expressions and their current values. As with
8715 displays you request manually using @code{x} or @code{print}, you can
8716 specify the output format you prefer; in fact, @code{display} decides
8717 whether to use @code{print} or @code{x} depending your format
8718 specification---it uses @code{x} if you specify either the @samp{i}
8719 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
8720
8721 @table @code
8722 @kindex display
8723 @item display @var{expr}
8724 Add the expression @var{expr} to the list of expressions to display
8725 each time your program stops. @xref{Expressions, ,Expressions}.
8726
8727 @code{display} does not repeat if you press @key{RET} again after using it.
8728
8729 @item display/@var{fmt} @var{expr}
8730 For @var{fmt} specifying only a display format and not a size or
8731 count, add the expression @var{expr} to the auto-display list but
8732 arrange to display it each time in the specified format @var{fmt}.
8733 @xref{Output Formats,,Output Formats}.
8734
8735 @item display/@var{fmt} @var{addr}
8736 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
8737 number of units, add the expression @var{addr} as a memory address to
8738 be examined each time your program stops. Examining means in effect
8739 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
8740 @end table
8741
8742 For example, @samp{display/i $pc} can be helpful, to see the machine
8743 instruction about to be executed each time execution stops (@samp{$pc}
8744 is a common name for the program counter; @pxref{Registers, ,Registers}).
8745
8746 @table @code
8747 @kindex delete display
8748 @kindex undisplay
8749 @item undisplay @var{dnums}@dots{}
8750 @itemx delete display @var{dnums}@dots{}
8751 Remove items from the list of expressions to display. Specify the
8752 numbers of the displays that you want affected with the command
8753 argument @var{dnums}. It can be a single display number, one of the
8754 numbers shown in the first field of the @samp{info display} display;
8755 or it could be a range of display numbers, as in @code{2-4}.
8756
8757 @code{undisplay} does not repeat if you press @key{RET} after using it.
8758 (Otherwise you would just get the error @samp{No display number @dots{}}.)
8759
8760 @kindex disable display
8761 @item disable display @var{dnums}@dots{}
8762 Disable the display of item numbers @var{dnums}. A disabled display
8763 item is not printed automatically, but is not forgotten. It may be
8764 enabled again later. Specify the numbers of the displays that you
8765 want affected with the command argument @var{dnums}. It can be a
8766 single display number, one of the numbers shown in the first field of
8767 the @samp{info display} display; or it could be a range of display
8768 numbers, as in @code{2-4}.
8769
8770 @kindex enable display
8771 @item enable display @var{dnums}@dots{}
8772 Enable display of item numbers @var{dnums}. It becomes effective once
8773 again in auto display of its expression, until you specify otherwise.
8774 Specify the numbers of the displays that you want affected with the
8775 command argument @var{dnums}. It can be a single display number, one
8776 of the numbers shown in the first field of the @samp{info display}
8777 display; or it could be a range of display numbers, as in @code{2-4}.
8778
8779 @item display
8780 Display the current values of the expressions on the list, just as is
8781 done when your program stops.
8782
8783 @kindex info display
8784 @item info display
8785 Print the list of expressions previously set up to display
8786 automatically, each one with its item number, but without showing the
8787 values. This includes disabled expressions, which are marked as such.
8788 It also includes expressions which would not be displayed right now
8789 because they refer to automatic variables not currently available.
8790 @end table
8791
8792 @cindex display disabled out of scope
8793 If a display expression refers to local variables, then it does not make
8794 sense outside the lexical context for which it was set up. Such an
8795 expression is disabled when execution enters a context where one of its
8796 variables is not defined. For example, if you give the command
8797 @code{display last_char} while inside a function with an argument
8798 @code{last_char}, @value{GDBN} displays this argument while your program
8799 continues to stop inside that function. When it stops elsewhere---where
8800 there is no variable @code{last_char}---the display is disabled
8801 automatically. The next time your program stops where @code{last_char}
8802 is meaningful, you can enable the display expression once again.
8803
8804 @node Print Settings
8805 @section Print Settings
8806
8807 @cindex format options
8808 @cindex print settings
8809 @value{GDBN} provides the following ways to control how arrays, structures,
8810 and symbols are printed.
8811
8812 @noindent
8813 These settings are useful for debugging programs in any language:
8814
8815 @table @code
8816 @kindex set print
8817 @item set print address
8818 @itemx set print address on
8819 @cindex print/don't print memory addresses
8820 @value{GDBN} prints memory addresses showing the location of stack
8821 traces, structure values, pointer values, breakpoints, and so forth,
8822 even when it also displays the contents of those addresses. The default
8823 is @code{on}. For example, this is what a stack frame display looks like with
8824 @code{set print address on}:
8825
8826 @smallexample
8827 @group
8828 (@value{GDBP}) f
8829 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
8830 at input.c:530
8831 530 if (lquote != def_lquote)
8832 @end group
8833 @end smallexample
8834
8835 @item set print address off
8836 Do not print addresses when displaying their contents. For example,
8837 this is the same stack frame displayed with @code{set print address off}:
8838
8839 @smallexample
8840 @group
8841 (@value{GDBP}) set print addr off
8842 (@value{GDBP}) f
8843 #0 set_quotes (lq="<<", rq=">>") at input.c:530
8844 530 if (lquote != def_lquote)
8845 @end group
8846 @end smallexample
8847
8848 You can use @samp{set print address off} to eliminate all machine
8849 dependent displays from the @value{GDBN} interface. For example, with
8850 @code{print address off}, you should get the same text for backtraces on
8851 all machines---whether or not they involve pointer arguments.
8852
8853 @kindex show print
8854 @item show print address
8855 Show whether or not addresses are to be printed.
8856 @end table
8857
8858 When @value{GDBN} prints a symbolic address, it normally prints the
8859 closest earlier symbol plus an offset. If that symbol does not uniquely
8860 identify the address (for example, it is a name whose scope is a single
8861 source file), you may need to clarify. One way to do this is with
8862 @code{info line}, for example @samp{info line *0x4537}. Alternately,
8863 you can set @value{GDBN} to print the source file and line number when
8864 it prints a symbolic address:
8865
8866 @table @code
8867 @item set print symbol-filename on
8868 @cindex source file and line of a symbol
8869 @cindex symbol, source file and line
8870 Tell @value{GDBN} to print the source file name and line number of a
8871 symbol in the symbolic form of an address.
8872
8873 @item set print symbol-filename off
8874 Do not print source file name and line number of a symbol. This is the
8875 default.
8876
8877 @item show print symbol-filename
8878 Show whether or not @value{GDBN} will print the source file name and
8879 line number of a symbol in the symbolic form of an address.
8880 @end table
8881
8882 Another situation where it is helpful to show symbol filenames and line
8883 numbers is when disassembling code; @value{GDBN} shows you the line
8884 number and source file that corresponds to each instruction.
8885
8886 Also, you may wish to see the symbolic form only if the address being
8887 printed is reasonably close to the closest earlier symbol:
8888
8889 @table @code
8890 @item set print max-symbolic-offset @var{max-offset}
8891 @itemx set print max-symbolic-offset unlimited
8892 @cindex maximum value for offset of closest symbol
8893 Tell @value{GDBN} to only display the symbolic form of an address if the
8894 offset between the closest earlier symbol and the address is less than
8895 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
8896 to always print the symbolic form of an address if any symbol precedes
8897 it. Zero is equivalent to @code{unlimited}.
8898
8899 @item show print max-symbolic-offset
8900 Ask how large the maximum offset is that @value{GDBN} prints in a
8901 symbolic address.
8902 @end table
8903
8904 @cindex wild pointer, interpreting
8905 @cindex pointer, finding referent
8906 If you have a pointer and you are not sure where it points, try
8907 @samp{set print symbol-filename on}. Then you can determine the name
8908 and source file location of the variable where it points, using
8909 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
8910 For example, here @value{GDBN} shows that a variable @code{ptt} points
8911 at another variable @code{t}, defined in @file{hi2.c}:
8912
8913 @smallexample
8914 (@value{GDBP}) set print symbol-filename on
8915 (@value{GDBP}) p/a ptt
8916 $4 = 0xe008 <t in hi2.c>
8917 @end smallexample
8918
8919 @quotation
8920 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
8921 does not show the symbol name and filename of the referent, even with
8922 the appropriate @code{set print} options turned on.
8923 @end quotation
8924
8925 You can also enable @samp{/a}-like formatting all the time using
8926 @samp{set print symbol on}:
8927
8928 @table @code
8929 @item set print symbol on
8930 Tell @value{GDBN} to print the symbol corresponding to an address, if
8931 one exists.
8932
8933 @item set print symbol off
8934 Tell @value{GDBN} not to print the symbol corresponding to an
8935 address. In this mode, @value{GDBN} will still print the symbol
8936 corresponding to pointers to functions. This is the default.
8937
8938 @item show print symbol
8939 Show whether @value{GDBN} will display the symbol corresponding to an
8940 address.
8941 @end table
8942
8943 Other settings control how different kinds of objects are printed:
8944
8945 @table @code
8946 @item set print array
8947 @itemx set print array on
8948 @cindex pretty print arrays
8949 Pretty print arrays. This format is more convenient to read,
8950 but uses more space. The default is off.
8951
8952 @item set print array off
8953 Return to compressed format for arrays.
8954
8955 @item show print array
8956 Show whether compressed or pretty format is selected for displaying
8957 arrays.
8958
8959 @cindex print array indexes
8960 @item set print array-indexes
8961 @itemx set print array-indexes on
8962 Print the index of each element when displaying arrays. May be more
8963 convenient to locate a given element in the array or quickly find the
8964 index of a given element in that printed array. The default is off.
8965
8966 @item set print array-indexes off
8967 Stop printing element indexes when displaying arrays.
8968
8969 @item show print array-indexes
8970 Show whether the index of each element is printed when displaying
8971 arrays.
8972
8973 @item set print elements @var{number-of-elements}
8974 @itemx set print elements unlimited
8975 @cindex number of array elements to print
8976 @cindex limit on number of printed array elements
8977 Set a limit on how many elements of an array @value{GDBN} will print.
8978 If @value{GDBN} is printing a large array, it stops printing after it has
8979 printed the number of elements set by the @code{set print elements} command.
8980 This limit also applies to the display of strings.
8981 When @value{GDBN} starts, this limit is set to 200.
8982 Setting @var{number-of-elements} to @code{unlimited} or zero means
8983 that the number of elements to print is unlimited.
8984
8985 @item show print elements
8986 Display the number of elements of a large array that @value{GDBN} will print.
8987 If the number is 0, then the printing is unlimited.
8988
8989 @item set print frame-arguments @var{value}
8990 @kindex set print frame-arguments
8991 @cindex printing frame argument values
8992 @cindex print all frame argument values
8993 @cindex print frame argument values for scalars only
8994 @cindex do not print frame argument values
8995 This command allows to control how the values of arguments are printed
8996 when the debugger prints a frame (@pxref{Frames}). The possible
8997 values are:
8998
8999 @table @code
9000 @item all
9001 The values of all arguments are printed.
9002
9003 @item scalars
9004 Print the value of an argument only if it is a scalar. The value of more
9005 complex arguments such as arrays, structures, unions, etc, is replaced
9006 by @code{@dots{}}. This is the default. Here is an example where
9007 only scalar arguments are shown:
9008
9009 @smallexample
9010 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
9011 at frame-args.c:23
9012 @end smallexample
9013
9014 @item none
9015 None of the argument values are printed. Instead, the value of each argument
9016 is replaced by @code{@dots{}}. In this case, the example above now becomes:
9017
9018 @smallexample
9019 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
9020 at frame-args.c:23
9021 @end smallexample
9022 @end table
9023
9024 By default, only scalar arguments are printed. This command can be used
9025 to configure the debugger to print the value of all arguments, regardless
9026 of their type. However, it is often advantageous to not print the value
9027 of more complex parameters. For instance, it reduces the amount of
9028 information printed in each frame, making the backtrace more readable.
9029 Also, it improves performance when displaying Ada frames, because
9030 the computation of large arguments can sometimes be CPU-intensive,
9031 especially in large applications. Setting @code{print frame-arguments}
9032 to @code{scalars} (the default) or @code{none} avoids this computation,
9033 thus speeding up the display of each Ada frame.
9034
9035 @item show print frame-arguments
9036 Show how the value of arguments should be displayed when printing a frame.
9037
9038 @item set print raw frame-arguments on
9039 Print frame arguments in raw, non pretty-printed, form.
9040
9041 @item set print raw frame-arguments off
9042 Print frame arguments in pretty-printed form, if there is a pretty-printer
9043 for the value (@pxref{Pretty Printing}),
9044 otherwise print the value in raw form.
9045 This is the default.
9046
9047 @item show print raw frame-arguments
9048 Show whether to print frame arguments in raw form.
9049
9050 @anchor{set print entry-values}
9051 @item set print entry-values @var{value}
9052 @kindex set print entry-values
9053 Set printing of frame argument values at function entry. In some cases
9054 @value{GDBN} can determine the value of function argument which was passed by
9055 the function caller, even if the value was modified inside the called function
9056 and therefore is different. With optimized code, the current value could be
9057 unavailable, but the entry value may still be known.
9058
9059 The default value is @code{default} (see below for its description). Older
9060 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
9061 this feature will behave in the @code{default} setting the same way as with the
9062 @code{no} setting.
9063
9064 This functionality is currently supported only by DWARF 2 debugging format and
9065 the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
9066 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
9067 this information.
9068
9069 The @var{value} parameter can be one of the following:
9070
9071 @table @code
9072 @item no
9073 Print only actual parameter values, never print values from function entry
9074 point.
9075 @smallexample
9076 #0 equal (val=5)
9077 #0 different (val=6)
9078 #0 lost (val=<optimized out>)
9079 #0 born (val=10)
9080 #0 invalid (val=<optimized out>)
9081 @end smallexample
9082
9083 @item only
9084 Print only parameter values from function entry point. The actual parameter
9085 values are never printed.
9086 @smallexample
9087 #0 equal (val@@entry=5)
9088 #0 different (val@@entry=5)
9089 #0 lost (val@@entry=5)
9090 #0 born (val@@entry=<optimized out>)
9091 #0 invalid (val@@entry=<optimized out>)
9092 @end smallexample
9093
9094 @item preferred
9095 Print only parameter values from function entry point. If value from function
9096 entry point is not known while the actual value is known, print the actual
9097 value for such parameter.
9098 @smallexample
9099 #0 equal (val@@entry=5)
9100 #0 different (val@@entry=5)
9101 #0 lost (val@@entry=5)
9102 #0 born (val=10)
9103 #0 invalid (val@@entry=<optimized out>)
9104 @end smallexample
9105
9106 @item if-needed
9107 Print actual parameter values. If actual parameter value is not known while
9108 value from function entry point is known, print the entry point value for such
9109 parameter.
9110 @smallexample
9111 #0 equal (val=5)
9112 #0 different (val=6)
9113 #0 lost (val@@entry=5)
9114 #0 born (val=10)
9115 #0 invalid (val=<optimized out>)
9116 @end smallexample
9117
9118 @item both
9119 Always print both the actual parameter value and its value from function entry
9120 point, even if values of one or both are not available due to compiler
9121 optimizations.
9122 @smallexample
9123 #0 equal (val=5, val@@entry=5)
9124 #0 different (val=6, val@@entry=5)
9125 #0 lost (val=<optimized out>, val@@entry=5)
9126 #0 born (val=10, val@@entry=<optimized out>)
9127 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
9128 @end smallexample
9129
9130 @item compact
9131 Print the actual parameter value if it is known and also its value from
9132 function entry point if it is known. If neither is known, print for the actual
9133 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
9134 values are known and identical, print the shortened
9135 @code{param=param@@entry=VALUE} notation.
9136 @smallexample
9137 #0 equal (val=val@@entry=5)
9138 #0 different (val=6, val@@entry=5)
9139 #0 lost (val@@entry=5)
9140 #0 born (val=10)
9141 #0 invalid (val=<optimized out>)
9142 @end smallexample
9143
9144 @item default
9145 Always print the actual parameter value. Print also its value from function
9146 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
9147 if both values are known and identical, print the shortened
9148 @code{param=param@@entry=VALUE} notation.
9149 @smallexample
9150 #0 equal (val=val@@entry=5)
9151 #0 different (val=6, val@@entry=5)
9152 #0 lost (val=<optimized out>, val@@entry=5)
9153 #0 born (val=10)
9154 #0 invalid (val=<optimized out>)
9155 @end smallexample
9156 @end table
9157
9158 For analysis messages on possible failures of frame argument values at function
9159 entry resolution see @ref{set debug entry-values}.
9160
9161 @item show print entry-values
9162 Show the method being used for printing of frame argument values at function
9163 entry.
9164
9165 @item set print repeats @var{number-of-repeats}
9166 @itemx set print repeats unlimited
9167 @cindex repeated array elements
9168 Set the threshold for suppressing display of repeated array
9169 elements. When the number of consecutive identical elements of an
9170 array exceeds the threshold, @value{GDBN} prints the string
9171 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
9172 identical repetitions, instead of displaying the identical elements
9173 themselves. Setting the threshold to @code{unlimited} or zero will
9174 cause all elements to be individually printed. The default threshold
9175 is 10.
9176
9177 @item show print repeats
9178 Display the current threshold for printing repeated identical
9179 elements.
9180
9181 @item set print null-stop
9182 @cindex @sc{null} elements in arrays
9183 Cause @value{GDBN} to stop printing the characters of an array when the first
9184 @sc{null} is encountered. This is useful when large arrays actually
9185 contain only short strings.
9186 The default is off.
9187
9188 @item show print null-stop
9189 Show whether @value{GDBN} stops printing an array on the first
9190 @sc{null} character.
9191
9192 @item set print pretty on
9193 @cindex print structures in indented form
9194 @cindex indentation in structure display
9195 Cause @value{GDBN} to print structures in an indented format with one member
9196 per line, like this:
9197
9198 @smallexample
9199 @group
9200 $1 = @{
9201 next = 0x0,
9202 flags = @{
9203 sweet = 1,
9204 sour = 1
9205 @},
9206 meat = 0x54 "Pork"
9207 @}
9208 @end group
9209 @end smallexample
9210
9211 @item set print pretty off
9212 Cause @value{GDBN} to print structures in a compact format, like this:
9213
9214 @smallexample
9215 @group
9216 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
9217 meat = 0x54 "Pork"@}
9218 @end group
9219 @end smallexample
9220
9221 @noindent
9222 This is the default format.
9223
9224 @item show print pretty
9225 Show which format @value{GDBN} is using to print structures.
9226
9227 @item set print sevenbit-strings on
9228 @cindex eight-bit characters in strings
9229 @cindex octal escapes in strings
9230 Print using only seven-bit characters; if this option is set,
9231 @value{GDBN} displays any eight-bit characters (in strings or
9232 character values) using the notation @code{\}@var{nnn}. This setting is
9233 best if you are working in English (@sc{ascii}) and you use the
9234 high-order bit of characters as a marker or ``meta'' bit.
9235
9236 @item set print sevenbit-strings off
9237 Print full eight-bit characters. This allows the use of more
9238 international character sets, and is the default.
9239
9240 @item show print sevenbit-strings
9241 Show whether or not @value{GDBN} is printing only seven-bit characters.
9242
9243 @item set print union on
9244 @cindex unions in structures, printing
9245 Tell @value{GDBN} to print unions which are contained in structures
9246 and other unions. This is the default setting.
9247
9248 @item set print union off
9249 Tell @value{GDBN} not to print unions which are contained in
9250 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
9251 instead.
9252
9253 @item show print union
9254 Ask @value{GDBN} whether or not it will print unions which are contained in
9255 structures and other unions.
9256
9257 For example, given the declarations
9258
9259 @smallexample
9260 typedef enum @{Tree, Bug@} Species;
9261 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
9262 typedef enum @{Caterpillar, Cocoon, Butterfly@}
9263 Bug_forms;
9264
9265 struct thing @{
9266 Species it;
9267 union @{
9268 Tree_forms tree;
9269 Bug_forms bug;
9270 @} form;
9271 @};
9272
9273 struct thing foo = @{Tree, @{Acorn@}@};
9274 @end smallexample
9275
9276 @noindent
9277 with @code{set print union on} in effect @samp{p foo} would print
9278
9279 @smallexample
9280 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
9281 @end smallexample
9282
9283 @noindent
9284 and with @code{set print union off} in effect it would print
9285
9286 @smallexample
9287 $1 = @{it = Tree, form = @{...@}@}
9288 @end smallexample
9289
9290 @noindent
9291 @code{set print union} affects programs written in C-like languages
9292 and in Pascal.
9293 @end table
9294
9295 @need 1000
9296 @noindent
9297 These settings are of interest when debugging C@t{++} programs:
9298
9299 @table @code
9300 @cindex demangling C@t{++} names
9301 @item set print demangle
9302 @itemx set print demangle on
9303 Print C@t{++} names in their source form rather than in the encoded
9304 (``mangled'') form passed to the assembler and linker for type-safe
9305 linkage. The default is on.
9306
9307 @item show print demangle
9308 Show whether C@t{++} names are printed in mangled or demangled form.
9309
9310 @item set print asm-demangle
9311 @itemx set print asm-demangle on
9312 Print C@t{++} names in their source form rather than their mangled form, even
9313 in assembler code printouts such as instruction disassemblies.
9314 The default is off.
9315
9316 @item show print asm-demangle
9317 Show whether C@t{++} names in assembly listings are printed in mangled
9318 or demangled form.
9319
9320 @cindex C@t{++} symbol decoding style
9321 @cindex symbol decoding style, C@t{++}
9322 @kindex set demangle-style
9323 @item set demangle-style @var{style}
9324 Choose among several encoding schemes used by different compilers to
9325 represent C@t{++} names. The choices for @var{style} are currently:
9326
9327 @table @code
9328 @item auto
9329 Allow @value{GDBN} to choose a decoding style by inspecting your program.
9330 This is the default.
9331
9332 @item gnu
9333 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
9334
9335 @item hp
9336 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
9337
9338 @item lucid
9339 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
9340
9341 @item arm
9342 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
9343 @strong{Warning:} this setting alone is not sufficient to allow
9344 debugging @code{cfront}-generated executables. @value{GDBN} would
9345 require further enhancement to permit that.
9346
9347 @end table
9348 If you omit @var{style}, you will see a list of possible formats.
9349
9350 @item show demangle-style
9351 Display the encoding style currently in use for decoding C@t{++} symbols.
9352
9353 @item set print object
9354 @itemx set print object on
9355 @cindex derived type of an object, printing
9356 @cindex display derived types
9357 When displaying a pointer to an object, identify the @emph{actual}
9358 (derived) type of the object rather than the @emph{declared} type, using
9359 the virtual function table. Note that the virtual function table is
9360 required---this feature can only work for objects that have run-time
9361 type identification; a single virtual method in the object's declared
9362 type is sufficient. Note that this setting is also taken into account when
9363 working with variable objects via MI (@pxref{GDB/MI}).
9364
9365 @item set print object off
9366 Display only the declared type of objects, without reference to the
9367 virtual function table. This is the default setting.
9368
9369 @item show print object
9370 Show whether actual, or declared, object types are displayed.
9371
9372 @item set print static-members
9373 @itemx set print static-members on
9374 @cindex static members of C@t{++} objects
9375 Print static members when displaying a C@t{++} object. The default is on.
9376
9377 @item set print static-members off
9378 Do not print static members when displaying a C@t{++} object.
9379
9380 @item show print static-members
9381 Show whether C@t{++} static members are printed or not.
9382
9383 @item set print pascal_static-members
9384 @itemx set print pascal_static-members on
9385 @cindex static members of Pascal objects
9386 @cindex Pascal objects, static members display
9387 Print static members when displaying a Pascal object. The default is on.
9388
9389 @item set print pascal_static-members off
9390 Do not print static members when displaying a Pascal object.
9391
9392 @item show print pascal_static-members
9393 Show whether Pascal static members are printed or not.
9394
9395 @c These don't work with HP ANSI C++ yet.
9396 @item set print vtbl
9397 @itemx set print vtbl on
9398 @cindex pretty print C@t{++} virtual function tables
9399 @cindex virtual functions (C@t{++}) display
9400 @cindex VTBL display
9401 Pretty print C@t{++} virtual function tables. The default is off.
9402 (The @code{vtbl} commands do not work on programs compiled with the HP
9403 ANSI C@t{++} compiler (@code{aCC}).)
9404
9405 @item set print vtbl off
9406 Do not pretty print C@t{++} virtual function tables.
9407
9408 @item show print vtbl
9409 Show whether C@t{++} virtual function tables are pretty printed, or not.
9410 @end table
9411
9412 @node Pretty Printing
9413 @section Pretty Printing
9414
9415 @value{GDBN} provides a mechanism to allow pretty-printing of values using
9416 Python code. It greatly simplifies the display of complex objects. This
9417 mechanism works for both MI and the CLI.
9418
9419 @menu
9420 * Pretty-Printer Introduction:: Introduction to pretty-printers
9421 * Pretty-Printer Example:: An example pretty-printer
9422 * Pretty-Printer Commands:: Pretty-printer commands
9423 @end menu
9424
9425 @node Pretty-Printer Introduction
9426 @subsection Pretty-Printer Introduction
9427
9428 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
9429 registered for the value. If there is then @value{GDBN} invokes the
9430 pretty-printer to print the value. Otherwise the value is printed normally.
9431
9432 Pretty-printers are normally named. This makes them easy to manage.
9433 The @samp{info pretty-printer} command will list all the installed
9434 pretty-printers with their names.
9435 If a pretty-printer can handle multiple data types, then its
9436 @dfn{subprinters} are the printers for the individual data types.
9437 Each such subprinter has its own name.
9438 The format of the name is @var{printer-name};@var{subprinter-name}.
9439
9440 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
9441 Typically they are automatically loaded and registered when the corresponding
9442 debug information is loaded, thus making them available without having to
9443 do anything special.
9444
9445 There are three places where a pretty-printer can be registered.
9446
9447 @itemize @bullet
9448 @item
9449 Pretty-printers registered globally are available when debugging
9450 all inferiors.
9451
9452 @item
9453 Pretty-printers registered with a program space are available only
9454 when debugging that program.
9455 @xref{Progspaces In Python}, for more details on program spaces in Python.
9456
9457 @item
9458 Pretty-printers registered with an objfile are loaded and unloaded
9459 with the corresponding objfile (e.g., shared library).
9460 @xref{Objfiles In Python}, for more details on objfiles in Python.
9461 @end itemize
9462
9463 @xref{Selecting Pretty-Printers}, for further information on how
9464 pretty-printers are selected,
9465
9466 @xref{Writing a Pretty-Printer}, for implementing pretty printers
9467 for new types.
9468
9469 @node Pretty-Printer Example
9470 @subsection Pretty-Printer Example
9471
9472 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
9473
9474 @smallexample
9475 (@value{GDBP}) print s
9476 $1 = @{
9477 static npos = 4294967295,
9478 _M_dataplus = @{
9479 <std::allocator<char>> = @{
9480 <__gnu_cxx::new_allocator<char>> = @{
9481 <No data fields>@}, <No data fields>
9482 @},
9483 members of std::basic_string<char, std::char_traits<char>,
9484 std::allocator<char> >::_Alloc_hider:
9485 _M_p = 0x804a014 "abcd"
9486 @}
9487 @}
9488 @end smallexample
9489
9490 With a pretty-printer for @code{std::string} only the contents are printed:
9491
9492 @smallexample
9493 (@value{GDBP}) print s
9494 $2 = "abcd"
9495 @end smallexample
9496
9497 @node Pretty-Printer Commands
9498 @subsection Pretty-Printer Commands
9499 @cindex pretty-printer commands
9500
9501 @table @code
9502 @kindex info pretty-printer
9503 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9504 Print the list of installed pretty-printers.
9505 This includes disabled pretty-printers, which are marked as such.
9506
9507 @var{object-regexp} is a regular expression matching the objects
9508 whose pretty-printers to list.
9509 Objects can be @code{global}, the program space's file
9510 (@pxref{Progspaces In Python}),
9511 and the object files within that program space (@pxref{Objfiles In Python}).
9512 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
9513 looks up a printer from these three objects.
9514
9515 @var{name-regexp} is a regular expression matching the name of the printers
9516 to list.
9517
9518 @kindex disable pretty-printer
9519 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9520 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9521 A disabled pretty-printer is not forgotten, it may be enabled again later.
9522
9523 @kindex enable pretty-printer
9524 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
9525 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
9526 @end table
9527
9528 Example:
9529
9530 Suppose we have three pretty-printers installed: one from library1.so
9531 named @code{foo} that prints objects of type @code{foo}, and
9532 another from library2.so named @code{bar} that prints two types of objects,
9533 @code{bar1} and @code{bar2}.
9534
9535 @smallexample
9536 (gdb) info pretty-printer
9537 library1.so:
9538 foo
9539 library2.so:
9540 bar
9541 bar1
9542 bar2
9543 (gdb) info pretty-printer library2
9544 library2.so:
9545 bar
9546 bar1
9547 bar2
9548 (gdb) disable pretty-printer library1
9549 1 printer disabled
9550 2 of 3 printers enabled
9551 (gdb) info pretty-printer
9552 library1.so:
9553 foo [disabled]
9554 library2.so:
9555 bar
9556 bar1
9557 bar2
9558 (gdb) disable pretty-printer library2 bar:bar1
9559 1 printer disabled
9560 1 of 3 printers enabled
9561 (gdb) info pretty-printer library2
9562 library1.so:
9563 foo [disabled]
9564 library2.so:
9565 bar
9566 bar1 [disabled]
9567 bar2
9568 (gdb) disable pretty-printer library2 bar
9569 1 printer disabled
9570 0 of 3 printers enabled
9571 (gdb) info pretty-printer library2
9572 library1.so:
9573 foo [disabled]
9574 library2.so:
9575 bar [disabled]
9576 bar1 [disabled]
9577 bar2
9578 @end smallexample
9579
9580 Note that for @code{bar} the entire printer can be disabled,
9581 as can each individual subprinter.
9582
9583 @node Value History
9584 @section Value History
9585
9586 @cindex value history
9587 @cindex history of values printed by @value{GDBN}
9588 Values printed by the @code{print} command are saved in the @value{GDBN}
9589 @dfn{value history}. This allows you to refer to them in other expressions.
9590 Values are kept until the symbol table is re-read or discarded
9591 (for example with the @code{file} or @code{symbol-file} commands).
9592 When the symbol table changes, the value history is discarded,
9593 since the values may contain pointers back to the types defined in the
9594 symbol table.
9595
9596 @cindex @code{$}
9597 @cindex @code{$$}
9598 @cindex history number
9599 The values printed are given @dfn{history numbers} by which you can
9600 refer to them. These are successive integers starting with one.
9601 @code{print} shows you the history number assigned to a value by
9602 printing @samp{$@var{num} = } before the value; here @var{num} is the
9603 history number.
9604
9605 To refer to any previous value, use @samp{$} followed by the value's
9606 history number. The way @code{print} labels its output is designed to
9607 remind you of this. Just @code{$} refers to the most recent value in
9608 the history, and @code{$$} refers to the value before that.
9609 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
9610 is the value just prior to @code{$$}, @code{$$1} is equivalent to
9611 @code{$$}, and @code{$$0} is equivalent to @code{$}.
9612
9613 For example, suppose you have just printed a pointer to a structure and
9614 want to see the contents of the structure. It suffices to type
9615
9616 @smallexample
9617 p *$
9618 @end smallexample
9619
9620 If you have a chain of structures where the component @code{next} points
9621 to the next one, you can print the contents of the next one with this:
9622
9623 @smallexample
9624 p *$.next
9625 @end smallexample
9626
9627 @noindent
9628 You can print successive links in the chain by repeating this
9629 command---which you can do by just typing @key{RET}.
9630
9631 Note that the history records values, not expressions. If the value of
9632 @code{x} is 4 and you type these commands:
9633
9634 @smallexample
9635 print x
9636 set x=5
9637 @end smallexample
9638
9639 @noindent
9640 then the value recorded in the value history by the @code{print} command
9641 remains 4 even though the value of @code{x} has changed.
9642
9643 @table @code
9644 @kindex show values
9645 @item show values
9646 Print the last ten values in the value history, with their item numbers.
9647 This is like @samp{p@ $$9} repeated ten times, except that @code{show
9648 values} does not change the history.
9649
9650 @item show values @var{n}
9651 Print ten history values centered on history item number @var{n}.
9652
9653 @item show values +
9654 Print ten history values just after the values last printed. If no more
9655 values are available, @code{show values +} produces no display.
9656 @end table
9657
9658 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
9659 same effect as @samp{show values +}.
9660
9661 @node Convenience Vars
9662 @section Convenience Variables
9663
9664 @cindex convenience variables
9665 @cindex user-defined variables
9666 @value{GDBN} provides @dfn{convenience variables} that you can use within
9667 @value{GDBN} to hold on to a value and refer to it later. These variables
9668 exist entirely within @value{GDBN}; they are not part of your program, and
9669 setting a convenience variable has no direct effect on further execution
9670 of your program. That is why you can use them freely.
9671
9672 Convenience variables are prefixed with @samp{$}. Any name preceded by
9673 @samp{$} can be used for a convenience variable, unless it is one of
9674 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
9675 (Value history references, in contrast, are @emph{numbers} preceded
9676 by @samp{$}. @xref{Value History, ,Value History}.)
9677
9678 You can save a value in a convenience variable with an assignment
9679 expression, just as you would set a variable in your program.
9680 For example:
9681
9682 @smallexample
9683 set $foo = *object_ptr
9684 @end smallexample
9685
9686 @noindent
9687 would save in @code{$foo} the value contained in the object pointed to by
9688 @code{object_ptr}.
9689
9690 Using a convenience variable for the first time creates it, but its
9691 value is @code{void} until you assign a new value. You can alter the
9692 value with another assignment at any time.
9693
9694 Convenience variables have no fixed types. You can assign a convenience
9695 variable any type of value, including structures and arrays, even if
9696 that variable already has a value of a different type. The convenience
9697 variable, when used as an expression, has the type of its current value.
9698
9699 @table @code
9700 @kindex show convenience
9701 @cindex show all user variables and functions
9702 @item show convenience
9703 Print a list of convenience variables used so far, and their values,
9704 as well as a list of the convenience functions.
9705 Abbreviated @code{show conv}.
9706
9707 @kindex init-if-undefined
9708 @cindex convenience variables, initializing
9709 @item init-if-undefined $@var{variable} = @var{expression}
9710 Set a convenience variable if it has not already been set. This is useful
9711 for user-defined commands that keep some state. It is similar, in concept,
9712 to using local static variables with initializers in C (except that
9713 convenience variables are global). It can also be used to allow users to
9714 override default values used in a command script.
9715
9716 If the variable is already defined then the expression is not evaluated so
9717 any side-effects do not occur.
9718 @end table
9719
9720 One of the ways to use a convenience variable is as a counter to be
9721 incremented or a pointer to be advanced. For example, to print
9722 a field from successive elements of an array of structures:
9723
9724 @smallexample
9725 set $i = 0
9726 print bar[$i++]->contents
9727 @end smallexample
9728
9729 @noindent
9730 Repeat that command by typing @key{RET}.
9731
9732 Some convenience variables are created automatically by @value{GDBN} and given
9733 values likely to be useful.
9734
9735 @table @code
9736 @vindex $_@r{, convenience variable}
9737 @item $_
9738 The variable @code{$_} is automatically set by the @code{x} command to
9739 the last address examined (@pxref{Memory, ,Examining Memory}). Other
9740 commands which provide a default address for @code{x} to examine also
9741 set @code{$_} to that address; these commands include @code{info line}
9742 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
9743 except when set by the @code{x} command, in which case it is a pointer
9744 to the type of @code{$__}.
9745
9746 @vindex $__@r{, convenience variable}
9747 @item $__
9748 The variable @code{$__} is automatically set by the @code{x} command
9749 to the value found in the last address examined. Its type is chosen
9750 to match the format in which the data was printed.
9751
9752 @item $_exitcode
9753 @vindex $_exitcode@r{, convenience variable}
9754 The variable @code{$_exitcode} is automatically set to the exit code when
9755 the program being debugged terminates.
9756
9757 @item $_exception
9758 The variable @code{$_exception} is set to the exception object being
9759 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
9760
9761 @item $_probe_argc
9762 @itemx $_probe_arg0@dots{}$_probe_arg11
9763 Arguments to a static probe. @xref{Static Probe Points}.
9764
9765 @item $_sdata
9766 @vindex $_sdata@r{, inspect, convenience variable}
9767 The variable @code{$_sdata} contains extra collected static tracepoint
9768 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
9769 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
9770 if extra static tracepoint data has not been collected.
9771
9772 @item $_siginfo
9773 @vindex $_siginfo@r{, convenience variable}
9774 The variable @code{$_siginfo} contains extra signal information
9775 (@pxref{extra signal information}). Note that @code{$_siginfo}
9776 could be empty, if the application has not yet received any signals.
9777 For example, it will be empty before you execute the @code{run} command.
9778
9779 @item $_tlb
9780 @vindex $_tlb@r{, convenience variable}
9781 The variable @code{$_tlb} is automatically set when debugging
9782 applications running on MS-Windows in native mode or connected to
9783 gdbserver that supports the @code{qGetTIBAddr} request.
9784 @xref{General Query Packets}.
9785 This variable contains the address of the thread information block.
9786
9787 @end table
9788
9789 On HP-UX systems, if you refer to a function or variable name that
9790 begins with a dollar sign, @value{GDBN} searches for a user or system
9791 name first, before it searches for a convenience variable.
9792
9793 @node Convenience Funs
9794 @section Convenience Functions
9795
9796 @cindex convenience functions
9797 @value{GDBN} also supplies some @dfn{convenience functions}. These
9798 have a syntax similar to convenience variables. A convenience
9799 function can be used in an expression just like an ordinary function;
9800 however, a convenience function is implemented internally to
9801 @value{GDBN}.
9802
9803 These functions do not require @value{GDBN} to be configured with
9804 @code{Python} support, which means that they are always available.
9805
9806 @table @code
9807
9808 @item $_isvoid (@var{expr})
9809 @findex $_isvoid@r{, convenience function}
9810 Return one if the expression @var{expr} is @code{void}. Otherwise it
9811 returns zero.
9812
9813 A @code{void} expression is an expression where the type of the result
9814 is @code{void}. For example, you can examine a convenience variable
9815 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
9816 it is @code{void}:
9817
9818 @smallexample
9819 (@value{GDBP}) print $_exitcode
9820 $1 = void
9821 (@value{GDBP}) print $_isvoid ($_exitcode)
9822 $2 = 1
9823 (@value{GDBP}) run
9824 Starting program: ./a.out
9825 [Inferior 1 (process 29572) exited normally]
9826 (@value{GDBP}) print $_exitcode
9827 $3 = 0
9828 (@value{GDBP}) print $_isvoid ($_exitcode)
9829 $4 = 0
9830 @end smallexample
9831
9832 In the example above, we used @code{$_isvoid} to check whether
9833 @code{$_exitcode} is @code{void} before and after the execution of the
9834 program being debugged. Before the execution there is no exit code to
9835 be examined, therefore @code{$_exitcode} is @code{void}. After the
9836 execution the program being debugged returned zero, therefore
9837 @code{$_exitcode} is zero, which means that it is not @code{void}
9838 anymore.
9839
9840 The @code{void} expression can also be a call of a function from the
9841 program being debugged. For example, given the following function:
9842
9843 @smallexample
9844 void
9845 foo (void)
9846 @{
9847 @}
9848 @end smallexample
9849
9850 The result of calling it inside @value{GDBN} is @code{void}:
9851
9852 @smallexample
9853 (@value{GDBP}) print foo ()
9854 $1 = void
9855 (@value{GDBP}) print $_isvoid (foo ())
9856 $2 = 1
9857 (@value{GDBP}) set $v = foo ()
9858 (@value{GDBP}) print $v
9859 $3 = void
9860 (@value{GDBP}) print $_isvoid ($v)
9861 $4 = 1
9862 @end smallexample
9863
9864 @end table
9865
9866 These functions require @value{GDBN} to be configured with
9867 @code{Python} support.
9868
9869 @table @code
9870
9871 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
9872 @findex $_memeq@r{, convenience function}
9873 Returns one if the @var{length} bytes at the addresses given by
9874 @var{buf1} and @var{buf2} are equal.
9875 Otherwise it returns zero.
9876
9877 @item $_regex(@var{str}, @var{regex})
9878 @findex $_regex@r{, convenience function}
9879 Returns one if the string @var{str} matches the regular expression
9880 @var{regex}. Otherwise it returns zero.
9881 The syntax of the regular expression is that specified by @code{Python}'s
9882 regular expression support.
9883
9884 @item $_streq(@var{str1}, @var{str2})
9885 @findex $_streq@r{, convenience function}
9886 Returns one if the strings @var{str1} and @var{str2} are equal.
9887 Otherwise it returns zero.
9888
9889 @item $_strlen(@var{str})
9890 @findex $_strlen@r{, convenience function}
9891 Returns the length of string @var{str}.
9892
9893 @end table
9894
9895 @value{GDBN} provides the ability to list and get help on
9896 convenience functions.
9897
9898 @table @code
9899 @item help function
9900 @kindex help function
9901 @cindex show all convenience functions
9902 Print a list of all convenience functions.
9903 @end table
9904
9905 @node Registers
9906 @section Registers
9907
9908 @cindex registers
9909 You can refer to machine register contents, in expressions, as variables
9910 with names starting with @samp{$}. The names of registers are different
9911 for each machine; use @code{info registers} to see the names used on
9912 your machine.
9913
9914 @table @code
9915 @kindex info registers
9916 @item info registers
9917 Print the names and values of all registers except floating-point
9918 and vector registers (in the selected stack frame).
9919
9920 @kindex info all-registers
9921 @cindex floating point registers
9922 @item info all-registers
9923 Print the names and values of all registers, including floating-point
9924 and vector registers (in the selected stack frame).
9925
9926 @item info registers @var{regname} @dots{}
9927 Print the @dfn{relativized} value of each specified register @var{regname}.
9928 As discussed in detail below, register values are normally relative to
9929 the selected stack frame. @var{regname} may be any register name valid on
9930 the machine you are using, with or without the initial @samp{$}.
9931 @end table
9932
9933 @cindex stack pointer register
9934 @cindex program counter register
9935 @cindex process status register
9936 @cindex frame pointer register
9937 @cindex standard registers
9938 @value{GDBN} has four ``standard'' register names that are available (in
9939 expressions) on most machines---whenever they do not conflict with an
9940 architecture's canonical mnemonics for registers. The register names
9941 @code{$pc} and @code{$sp} are used for the program counter register and
9942 the stack pointer. @code{$fp} is used for a register that contains a
9943 pointer to the current stack frame, and @code{$ps} is used for a
9944 register that contains the processor status. For example,
9945 you could print the program counter in hex with
9946
9947 @smallexample
9948 p/x $pc
9949 @end smallexample
9950
9951 @noindent
9952 or print the instruction to be executed next with
9953
9954 @smallexample
9955 x/i $pc
9956 @end smallexample
9957
9958 @noindent
9959 or add four to the stack pointer@footnote{This is a way of removing
9960 one word from the stack, on machines where stacks grow downward in
9961 memory (most machines, nowadays). This assumes that the innermost
9962 stack frame is selected; setting @code{$sp} is not allowed when other
9963 stack frames are selected. To pop entire frames off the stack,
9964 regardless of machine architecture, use @code{return};
9965 see @ref{Returning, ,Returning from a Function}.} with
9966
9967 @smallexample
9968 set $sp += 4
9969 @end smallexample
9970
9971 Whenever possible, these four standard register names are available on
9972 your machine even though the machine has different canonical mnemonics,
9973 so long as there is no conflict. The @code{info registers} command
9974 shows the canonical names. For example, on the SPARC, @code{info
9975 registers} displays the processor status register as @code{$psr} but you
9976 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
9977 is an alias for the @sc{eflags} register.
9978
9979 @value{GDBN} always considers the contents of an ordinary register as an
9980 integer when the register is examined in this way. Some machines have
9981 special registers which can hold nothing but floating point; these
9982 registers are considered to have floating point values. There is no way
9983 to refer to the contents of an ordinary register as floating point value
9984 (although you can @emph{print} it as a floating point value with
9985 @samp{print/f $@var{regname}}).
9986
9987 Some registers have distinct ``raw'' and ``virtual'' data formats. This
9988 means that the data format in which the register contents are saved by
9989 the operating system is not the same one that your program normally
9990 sees. For example, the registers of the 68881 floating point
9991 coprocessor are always saved in ``extended'' (raw) format, but all C
9992 programs expect to work with ``double'' (virtual) format. In such
9993 cases, @value{GDBN} normally works with the virtual format only (the format
9994 that makes sense for your program), but the @code{info registers} command
9995 prints the data in both formats.
9996
9997 @cindex SSE registers (x86)
9998 @cindex MMX registers (x86)
9999 Some machines have special registers whose contents can be interpreted
10000 in several different ways. For example, modern x86-based machines
10001 have SSE and MMX registers that can hold several values packed
10002 together in several different formats. @value{GDBN} refers to such
10003 registers in @code{struct} notation:
10004
10005 @smallexample
10006 (@value{GDBP}) print $xmm1
10007 $1 = @{
10008 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
10009 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
10010 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
10011 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
10012 v4_int32 = @{0, 20657912, 11, 13@},
10013 v2_int64 = @{88725056443645952, 55834574859@},
10014 uint128 = 0x0000000d0000000b013b36f800000000
10015 @}
10016 @end smallexample
10017
10018 @noindent
10019 To set values of such registers, you need to tell @value{GDBN} which
10020 view of the register you wish to change, as if you were assigning
10021 value to a @code{struct} member:
10022
10023 @smallexample
10024 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
10025 @end smallexample
10026
10027 Normally, register values are relative to the selected stack frame
10028 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
10029 value that the register would contain if all stack frames farther in
10030 were exited and their saved registers restored. In order to see the
10031 true contents of hardware registers, you must select the innermost
10032 frame (with @samp{frame 0}).
10033
10034 However, @value{GDBN} must deduce where registers are saved, from the machine
10035 code generated by your compiler. If some registers are not saved, or if
10036 @value{GDBN} is unable to locate the saved registers, the selected stack
10037 frame makes no difference.
10038
10039 @node Floating Point Hardware
10040 @section Floating Point Hardware
10041 @cindex floating point
10042
10043 Depending on the configuration, @value{GDBN} may be able to give
10044 you more information about the status of the floating point hardware.
10045
10046 @table @code
10047 @kindex info float
10048 @item info float
10049 Display hardware-dependent information about the floating
10050 point unit. The exact contents and layout vary depending on the
10051 floating point chip. Currently, @samp{info float} is supported on
10052 the ARM and x86 machines.
10053 @end table
10054
10055 @node Vector Unit
10056 @section Vector Unit
10057 @cindex vector unit
10058
10059 Depending on the configuration, @value{GDBN} may be able to give you
10060 more information about the status of the vector unit.
10061
10062 @table @code
10063 @kindex info vector
10064 @item info vector
10065 Display information about the vector unit. The exact contents and
10066 layout vary depending on the hardware.
10067 @end table
10068
10069 @node OS Information
10070 @section Operating System Auxiliary Information
10071 @cindex OS information
10072
10073 @value{GDBN} provides interfaces to useful OS facilities that can help
10074 you debug your program.
10075
10076 @cindex auxiliary vector
10077 @cindex vector, auxiliary
10078 Some operating systems supply an @dfn{auxiliary vector} to programs at
10079 startup. This is akin to the arguments and environment that you
10080 specify for a program, but contains a system-dependent variety of
10081 binary values that tell system libraries important details about the
10082 hardware, operating system, and process. Each value's purpose is
10083 identified by an integer tag; the meanings are well-known but system-specific.
10084 Depending on the configuration and operating system facilities,
10085 @value{GDBN} may be able to show you this information. For remote
10086 targets, this functionality may further depend on the remote stub's
10087 support of the @samp{qXfer:auxv:read} packet, see
10088 @ref{qXfer auxiliary vector read}.
10089
10090 @table @code
10091 @kindex info auxv
10092 @item info auxv
10093 Display the auxiliary vector of the inferior, which can be either a
10094 live process or a core dump file. @value{GDBN} prints each tag value
10095 numerically, and also shows names and text descriptions for recognized
10096 tags. Some values in the vector are numbers, some bit masks, and some
10097 pointers to strings or other data. @value{GDBN} displays each value in the
10098 most appropriate form for a recognized tag, and in hexadecimal for
10099 an unrecognized tag.
10100 @end table
10101
10102 On some targets, @value{GDBN} can access operating system-specific
10103 information and show it to you. The types of information available
10104 will differ depending on the type of operating system running on the
10105 target. The mechanism used to fetch the data is described in
10106 @ref{Operating System Information}. For remote targets, this
10107 functionality depends on the remote stub's support of the
10108 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
10109
10110 @table @code
10111 @kindex info os
10112 @item info os @var{infotype}
10113
10114 Display OS information of the requested type.
10115
10116 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
10117
10118 @anchor{linux info os infotypes}
10119 @table @code
10120 @kindex info os processes
10121 @item processes
10122 Display the list of processes on the target. For each process,
10123 @value{GDBN} prints the process identifier, the name of the user, the
10124 command corresponding to the process, and the list of processor cores
10125 that the process is currently running on. (To understand what these
10126 properties mean, for this and the following info types, please consult
10127 the general @sc{gnu}/Linux documentation.)
10128
10129 @kindex info os procgroups
10130 @item procgroups
10131 Display the list of process groups on the target. For each process,
10132 @value{GDBN} prints the identifier of the process group that it belongs
10133 to, the command corresponding to the process group leader, the process
10134 identifier, and the command line of the process. The list is sorted
10135 first by the process group identifier, then by the process identifier,
10136 so that processes belonging to the same process group are grouped together
10137 and the process group leader is listed first.
10138
10139 @kindex info os threads
10140 @item threads
10141 Display the list of threads running on the target. For each thread,
10142 @value{GDBN} prints the identifier of the process that the thread
10143 belongs to, the command of the process, the thread identifier, and the
10144 processor core that it is currently running on. The main thread of a
10145 process is not listed.
10146
10147 @kindex info os files
10148 @item files
10149 Display the list of open file descriptors on the target. For each
10150 file descriptor, @value{GDBN} prints the identifier of the process
10151 owning the descriptor, the command of the owning process, the value
10152 of the descriptor, and the target of the descriptor.
10153
10154 @kindex info os sockets
10155 @item sockets
10156 Display the list of Internet-domain sockets on the target. For each
10157 socket, @value{GDBN} prints the address and port of the local and
10158 remote endpoints, the current state of the connection, the creator of
10159 the socket, the IP address family of the socket, and the type of the
10160 connection.
10161
10162 @kindex info os shm
10163 @item shm
10164 Display the list of all System V shared-memory regions on the target.
10165 For each shared-memory region, @value{GDBN} prints the region key,
10166 the shared-memory identifier, the access permissions, the size of the
10167 region, the process that created the region, the process that last
10168 attached to or detached from the region, the current number of live
10169 attaches to the region, and the times at which the region was last
10170 attached to, detach from, and changed.
10171
10172 @kindex info os semaphores
10173 @item semaphores
10174 Display the list of all System V semaphore sets on the target. For each
10175 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
10176 set identifier, the access permissions, the number of semaphores in the
10177 set, the user and group of the owner and creator of the semaphore set,
10178 and the times at which the semaphore set was operated upon and changed.
10179
10180 @kindex info os msg
10181 @item msg
10182 Display the list of all System V message queues on the target. For each
10183 message queue, @value{GDBN} prints the message queue key, the message
10184 queue identifier, the access permissions, the current number of bytes
10185 on the queue, the current number of messages on the queue, the processes
10186 that last sent and received a message on the queue, the user and group
10187 of the owner and creator of the message queue, the times at which a
10188 message was last sent and received on the queue, and the time at which
10189 the message queue was last changed.
10190
10191 @kindex info os modules
10192 @item modules
10193 Display the list of all loaded kernel modules on the target. For each
10194 module, @value{GDBN} prints the module name, the size of the module in
10195 bytes, the number of times the module is used, the dependencies of the
10196 module, the status of the module, and the address of the loaded module
10197 in memory.
10198 @end table
10199
10200 @item info os
10201 If @var{infotype} is omitted, then list the possible values for
10202 @var{infotype} and the kind of OS information available for each
10203 @var{infotype}. If the target does not return a list of possible
10204 types, this command will report an error.
10205 @end table
10206
10207 @node Memory Region Attributes
10208 @section Memory Region Attributes
10209 @cindex memory region attributes
10210
10211 @dfn{Memory region attributes} allow you to describe special handling
10212 required by regions of your target's memory. @value{GDBN} uses
10213 attributes to determine whether to allow certain types of memory
10214 accesses; whether to use specific width accesses; and whether to cache
10215 target memory. By default the description of memory regions is
10216 fetched from the target (if the current target supports this), but the
10217 user can override the fetched regions.
10218
10219 Defined memory regions can be individually enabled and disabled. When a
10220 memory region is disabled, @value{GDBN} uses the default attributes when
10221 accessing memory in that region. Similarly, if no memory regions have
10222 been defined, @value{GDBN} uses the default attributes when accessing
10223 all memory.
10224
10225 When a memory region is defined, it is given a number to identify it;
10226 to enable, disable, or remove a memory region, you specify that number.
10227
10228 @table @code
10229 @kindex mem
10230 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
10231 Define a memory region bounded by @var{lower} and @var{upper} with
10232 attributes @var{attributes}@dots{}, and add it to the list of regions
10233 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
10234 case: it is treated as the target's maximum memory address.
10235 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
10236
10237 @item mem auto
10238 Discard any user changes to the memory regions and use target-supplied
10239 regions, if available, or no regions if the target does not support.
10240
10241 @kindex delete mem
10242 @item delete mem @var{nums}@dots{}
10243 Remove memory regions @var{nums}@dots{} from the list of regions
10244 monitored by @value{GDBN}.
10245
10246 @kindex disable mem
10247 @item disable mem @var{nums}@dots{}
10248 Disable monitoring of memory regions @var{nums}@dots{}.
10249 A disabled memory region is not forgotten.
10250 It may be enabled again later.
10251
10252 @kindex enable mem
10253 @item enable mem @var{nums}@dots{}
10254 Enable monitoring of memory regions @var{nums}@dots{}.
10255
10256 @kindex info mem
10257 @item info mem
10258 Print a table of all defined memory regions, with the following columns
10259 for each region:
10260
10261 @table @emph
10262 @item Memory Region Number
10263 @item Enabled or Disabled.
10264 Enabled memory regions are marked with @samp{y}.
10265 Disabled memory regions are marked with @samp{n}.
10266
10267 @item Lo Address
10268 The address defining the inclusive lower bound of the memory region.
10269
10270 @item Hi Address
10271 The address defining the exclusive upper bound of the memory region.
10272
10273 @item Attributes
10274 The list of attributes set for this memory region.
10275 @end table
10276 @end table
10277
10278
10279 @subsection Attributes
10280
10281 @subsubsection Memory Access Mode
10282 The access mode attributes set whether @value{GDBN} may make read or
10283 write accesses to a memory region.
10284
10285 While these attributes prevent @value{GDBN} from performing invalid
10286 memory accesses, they do nothing to prevent the target system, I/O DMA,
10287 etc.@: from accessing memory.
10288
10289 @table @code
10290 @item ro
10291 Memory is read only.
10292 @item wo
10293 Memory is write only.
10294 @item rw
10295 Memory is read/write. This is the default.
10296 @end table
10297
10298 @subsubsection Memory Access Size
10299 The access size attribute tells @value{GDBN} to use specific sized
10300 accesses in the memory region. Often memory mapped device registers
10301 require specific sized accesses. If no access size attribute is
10302 specified, @value{GDBN} may use accesses of any size.
10303
10304 @table @code
10305 @item 8
10306 Use 8 bit memory accesses.
10307 @item 16
10308 Use 16 bit memory accesses.
10309 @item 32
10310 Use 32 bit memory accesses.
10311 @item 64
10312 Use 64 bit memory accesses.
10313 @end table
10314
10315 @c @subsubsection Hardware/Software Breakpoints
10316 @c The hardware/software breakpoint attributes set whether @value{GDBN}
10317 @c will use hardware or software breakpoints for the internal breakpoints
10318 @c used by the step, next, finish, until, etc. commands.
10319 @c
10320 @c @table @code
10321 @c @item hwbreak
10322 @c Always use hardware breakpoints
10323 @c @item swbreak (default)
10324 @c @end table
10325
10326 @subsubsection Data Cache
10327 The data cache attributes set whether @value{GDBN} will cache target
10328 memory. While this generally improves performance by reducing debug
10329 protocol overhead, it can lead to incorrect results because @value{GDBN}
10330 does not know about volatile variables or memory mapped device
10331 registers.
10332
10333 @table @code
10334 @item cache
10335 Enable @value{GDBN} to cache target memory.
10336 @item nocache
10337 Disable @value{GDBN} from caching target memory. This is the default.
10338 @end table
10339
10340 @subsection Memory Access Checking
10341 @value{GDBN} can be instructed to refuse accesses to memory that is
10342 not explicitly described. This can be useful if accessing such
10343 regions has undesired effects for a specific target, or to provide
10344 better error checking. The following commands control this behaviour.
10345
10346 @table @code
10347 @kindex set mem inaccessible-by-default
10348 @item set mem inaccessible-by-default [on|off]
10349 If @code{on} is specified, make @value{GDBN} treat memory not
10350 explicitly described by the memory ranges as non-existent and refuse accesses
10351 to such memory. The checks are only performed if there's at least one
10352 memory range defined. If @code{off} is specified, make @value{GDBN}
10353 treat the memory not explicitly described by the memory ranges as RAM.
10354 The default value is @code{on}.
10355 @kindex show mem inaccessible-by-default
10356 @item show mem inaccessible-by-default
10357 Show the current handling of accesses to unknown memory.
10358 @end table
10359
10360
10361 @c @subsubsection Memory Write Verification
10362 @c The memory write verification attributes set whether @value{GDBN}
10363 @c will re-reads data after each write to verify the write was successful.
10364 @c
10365 @c @table @code
10366 @c @item verify
10367 @c @item noverify (default)
10368 @c @end table
10369
10370 @node Dump/Restore Files
10371 @section Copy Between Memory and a File
10372 @cindex dump/restore files
10373 @cindex append data to a file
10374 @cindex dump data to a file
10375 @cindex restore data from a file
10376
10377 You can use the commands @code{dump}, @code{append}, and
10378 @code{restore} to copy data between target memory and a file. The
10379 @code{dump} and @code{append} commands write data to a file, and the
10380 @code{restore} command reads data from a file back into the inferior's
10381 memory. Files may be in binary, Motorola S-record, Intel hex, or
10382 Tektronix Hex format; however, @value{GDBN} can only append to binary
10383 files.
10384
10385 @table @code
10386
10387 @kindex dump
10388 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10389 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
10390 Dump the contents of memory from @var{start_addr} to @var{end_addr},
10391 or the value of @var{expr}, to @var{filename} in the given format.
10392
10393 The @var{format} parameter may be any one of:
10394 @table @code
10395 @item binary
10396 Raw binary form.
10397 @item ihex
10398 Intel hex format.
10399 @item srec
10400 Motorola S-record format.
10401 @item tekhex
10402 Tektronix Hex format.
10403 @end table
10404
10405 @value{GDBN} uses the same definitions of these formats as the
10406 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
10407 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
10408 form.
10409
10410 @kindex append
10411 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
10412 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
10413 Append the contents of memory from @var{start_addr} to @var{end_addr},
10414 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
10415 (@value{GDBN} can only append data to files in raw binary form.)
10416
10417 @kindex restore
10418 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
10419 Restore the contents of file @var{filename} into memory. The
10420 @code{restore} command can automatically recognize any known @sc{bfd}
10421 file format, except for raw binary. To restore a raw binary file you
10422 must specify the optional keyword @code{binary} after the filename.
10423
10424 If @var{bias} is non-zero, its value will be added to the addresses
10425 contained in the file. Binary files always start at address zero, so
10426 they will be restored at address @var{bias}. Other bfd files have
10427 a built-in location; they will be restored at offset @var{bias}
10428 from that location.
10429
10430 If @var{start} and/or @var{end} are non-zero, then only data between
10431 file offset @var{start} and file offset @var{end} will be restored.
10432 These offsets are relative to the addresses in the file, before
10433 the @var{bias} argument is applied.
10434
10435 @end table
10436
10437 @node Core File Generation
10438 @section How to Produce a Core File from Your Program
10439 @cindex dump core from inferior
10440
10441 A @dfn{core file} or @dfn{core dump} is a file that records the memory
10442 image of a running process and its process status (register values
10443 etc.). Its primary use is post-mortem debugging of a program that
10444 crashed while it ran outside a debugger. A program that crashes
10445 automatically produces a core file, unless this feature is disabled by
10446 the user. @xref{Files}, for information on invoking @value{GDBN} in
10447 the post-mortem debugging mode.
10448
10449 Occasionally, you may wish to produce a core file of the program you
10450 are debugging in order to preserve a snapshot of its state.
10451 @value{GDBN} has a special command for that.
10452
10453 @table @code
10454 @kindex gcore
10455 @kindex generate-core-file
10456 @item generate-core-file [@var{file}]
10457 @itemx gcore [@var{file}]
10458 Produce a core dump of the inferior process. The optional argument
10459 @var{file} specifies the file name where to put the core dump. If not
10460 specified, the file name defaults to @file{core.@var{pid}}, where
10461 @var{pid} is the inferior process ID.
10462
10463 Note that this command is implemented only for some systems (as of
10464 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
10465 @end table
10466
10467 @node Character Sets
10468 @section Character Sets
10469 @cindex character sets
10470 @cindex charset
10471 @cindex translating between character sets
10472 @cindex host character set
10473 @cindex target character set
10474
10475 If the program you are debugging uses a different character set to
10476 represent characters and strings than the one @value{GDBN} uses itself,
10477 @value{GDBN} can automatically translate between the character sets for
10478 you. The character set @value{GDBN} uses we call the @dfn{host
10479 character set}; the one the inferior program uses we call the
10480 @dfn{target character set}.
10481
10482 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
10483 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
10484 remote protocol (@pxref{Remote Debugging}) to debug a program
10485 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
10486 then the host character set is Latin-1, and the target character set is
10487 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
10488 target-charset EBCDIC-US}, then @value{GDBN} translates between
10489 @sc{ebcdic} and Latin 1 as you print character or string values, or use
10490 character and string literals in expressions.
10491
10492 @value{GDBN} has no way to automatically recognize which character set
10493 the inferior program uses; you must tell it, using the @code{set
10494 target-charset} command, described below.
10495
10496 Here are the commands for controlling @value{GDBN}'s character set
10497 support:
10498
10499 @table @code
10500 @item set target-charset @var{charset}
10501 @kindex set target-charset
10502 Set the current target character set to @var{charset}. To display the
10503 list of supported target character sets, type
10504 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
10505
10506 @item set host-charset @var{charset}
10507 @kindex set host-charset
10508 Set the current host character set to @var{charset}.
10509
10510 By default, @value{GDBN} uses a host character set appropriate to the
10511 system it is running on; you can override that default using the
10512 @code{set host-charset} command. On some systems, @value{GDBN} cannot
10513 automatically determine the appropriate host character set. In this
10514 case, @value{GDBN} uses @samp{UTF-8}.
10515
10516 @value{GDBN} can only use certain character sets as its host character
10517 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10518 @value{GDBN} will list the host character sets it supports.
10519
10520 @item set charset @var{charset}
10521 @kindex set charset
10522 Set the current host and target character sets to @var{charset}. As
10523 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
10524 @value{GDBN} will list the names of the character sets that can be used
10525 for both host and target.
10526
10527 @item show charset
10528 @kindex show charset
10529 Show the names of the current host and target character sets.
10530
10531 @item show host-charset
10532 @kindex show host-charset
10533 Show the name of the current host character set.
10534
10535 @item show target-charset
10536 @kindex show target-charset
10537 Show the name of the current target character set.
10538
10539 @item set target-wide-charset @var{charset}
10540 @kindex set target-wide-charset
10541 Set the current target's wide character set to @var{charset}. This is
10542 the character set used by the target's @code{wchar_t} type. To
10543 display the list of supported wide character sets, type
10544 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
10545
10546 @item show target-wide-charset
10547 @kindex show target-wide-charset
10548 Show the name of the current target's wide character set.
10549 @end table
10550
10551 Here is an example of @value{GDBN}'s character set support in action.
10552 Assume that the following source code has been placed in the file
10553 @file{charset-test.c}:
10554
10555 @smallexample
10556 #include <stdio.h>
10557
10558 char ascii_hello[]
10559 = @{72, 101, 108, 108, 111, 44, 32, 119,
10560 111, 114, 108, 100, 33, 10, 0@};
10561 char ibm1047_hello[]
10562 = @{200, 133, 147, 147, 150, 107, 64, 166,
10563 150, 153, 147, 132, 90, 37, 0@};
10564
10565 main ()
10566 @{
10567 printf ("Hello, world!\n");
10568 @}
10569 @end smallexample
10570
10571 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
10572 containing the string @samp{Hello, world!} followed by a newline,
10573 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
10574
10575 We compile the program, and invoke the debugger on it:
10576
10577 @smallexample
10578 $ gcc -g charset-test.c -o charset-test
10579 $ gdb -nw charset-test
10580 GNU gdb 2001-12-19-cvs
10581 Copyright 2001 Free Software Foundation, Inc.
10582 @dots{}
10583 (@value{GDBP})
10584 @end smallexample
10585
10586 We can use the @code{show charset} command to see what character sets
10587 @value{GDBN} is currently using to interpret and display characters and
10588 strings:
10589
10590 @smallexample
10591 (@value{GDBP}) show charset
10592 The current host and target character set is `ISO-8859-1'.
10593 (@value{GDBP})
10594 @end smallexample
10595
10596 For the sake of printing this manual, let's use @sc{ascii} as our
10597 initial character set:
10598 @smallexample
10599 (@value{GDBP}) set charset ASCII
10600 (@value{GDBP}) show charset
10601 The current host and target character set is `ASCII'.
10602 (@value{GDBP})
10603 @end smallexample
10604
10605 Let's assume that @sc{ascii} is indeed the correct character set for our
10606 host system --- in other words, let's assume that if @value{GDBN} prints
10607 characters using the @sc{ascii} character set, our terminal will display
10608 them properly. Since our current target character set is also
10609 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
10610
10611 @smallexample
10612 (@value{GDBP}) print ascii_hello
10613 $1 = 0x401698 "Hello, world!\n"
10614 (@value{GDBP}) print ascii_hello[0]
10615 $2 = 72 'H'
10616 (@value{GDBP})
10617 @end smallexample
10618
10619 @value{GDBN} uses the target character set for character and string
10620 literals you use in expressions:
10621
10622 @smallexample
10623 (@value{GDBP}) print '+'
10624 $3 = 43 '+'
10625 (@value{GDBP})
10626 @end smallexample
10627
10628 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
10629 character.
10630
10631 @value{GDBN} relies on the user to tell it which character set the
10632 target program uses. If we print @code{ibm1047_hello} while our target
10633 character set is still @sc{ascii}, we get jibberish:
10634
10635 @smallexample
10636 (@value{GDBP}) print ibm1047_hello
10637 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
10638 (@value{GDBP}) print ibm1047_hello[0]
10639 $5 = 200 '\310'
10640 (@value{GDBP})
10641 @end smallexample
10642
10643 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
10644 @value{GDBN} tells us the character sets it supports:
10645
10646 @smallexample
10647 (@value{GDBP}) set target-charset
10648 ASCII EBCDIC-US IBM1047 ISO-8859-1
10649 (@value{GDBP}) set target-charset
10650 @end smallexample
10651
10652 We can select @sc{ibm1047} as our target character set, and examine the
10653 program's strings again. Now the @sc{ascii} string is wrong, but
10654 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
10655 target character set, @sc{ibm1047}, to the host character set,
10656 @sc{ascii}, and they display correctly:
10657
10658 @smallexample
10659 (@value{GDBP}) set target-charset IBM1047
10660 (@value{GDBP}) show charset
10661 The current host character set is `ASCII'.
10662 The current target character set is `IBM1047'.
10663 (@value{GDBP}) print ascii_hello
10664 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
10665 (@value{GDBP}) print ascii_hello[0]
10666 $7 = 72 '\110'
10667 (@value{GDBP}) print ibm1047_hello
10668 $8 = 0x4016a8 "Hello, world!\n"
10669 (@value{GDBP}) print ibm1047_hello[0]
10670 $9 = 200 'H'
10671 (@value{GDBP})
10672 @end smallexample
10673
10674 As above, @value{GDBN} uses the target character set for character and
10675 string literals you use in expressions:
10676
10677 @smallexample
10678 (@value{GDBP}) print '+'
10679 $10 = 78 '+'
10680 (@value{GDBP})
10681 @end smallexample
10682
10683 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
10684 character.
10685
10686 @node Caching Remote Data
10687 @section Caching Data of Remote Targets
10688 @cindex caching data of remote targets
10689
10690 @value{GDBN} caches data exchanged between the debugger and a
10691 remote target (@pxref{Remote Debugging}). Such caching generally improves
10692 performance, because it reduces the overhead of the remote protocol by
10693 bundling memory reads and writes into large chunks. Unfortunately, simply
10694 caching everything would lead to incorrect results, since @value{GDBN}
10695 does not necessarily know anything about volatile values, memory-mapped I/O
10696 addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
10697 memory can be changed @emph{while} a gdb command is executing.
10698 Therefore, by default, @value{GDBN} only caches data
10699 known to be on the stack@footnote{In non-stop mode, it is moderately
10700 rare for a running thread to modify the stack of a stopped thread
10701 in a way that would interfere with a backtrace, and caching of
10702 stack reads provides a significant speed up of remote backtraces.}.
10703 Other regions of memory can be explicitly marked as
10704 cacheable; see @pxref{Memory Region Attributes}.
10705
10706 @table @code
10707 @kindex set remotecache
10708 @item set remotecache on
10709 @itemx set remotecache off
10710 This option no longer does anything; it exists for compatibility
10711 with old scripts.
10712
10713 @kindex show remotecache
10714 @item show remotecache
10715 Show the current state of the obsolete remotecache flag.
10716
10717 @kindex set stack-cache
10718 @item set stack-cache on
10719 @itemx set stack-cache off
10720 Enable or disable caching of stack accesses. When @code{ON}, use
10721 caching. By default, this option is @code{ON}.
10722
10723 @kindex show stack-cache
10724 @item show stack-cache
10725 Show the current state of data caching for memory accesses.
10726
10727 @kindex info dcache
10728 @item info dcache @r{[}line@r{]}
10729 Print the information about the data cache performance. The
10730 information displayed includes the dcache width and depth, and for
10731 each cache line, its number, address, and how many times it was
10732 referenced. This command is useful for debugging the data cache
10733 operation.
10734
10735 If a line number is specified, the contents of that line will be
10736 printed in hex.
10737
10738 @item set dcache size @var{size}
10739 @cindex dcache size
10740 @kindex set dcache size
10741 Set maximum number of entries in dcache (dcache depth above).
10742
10743 @item set dcache line-size @var{line-size}
10744 @cindex dcache line-size
10745 @kindex set dcache line-size
10746 Set number of bytes each dcache entry caches (dcache width above).
10747 Must be a power of 2.
10748
10749 @item show dcache size
10750 @kindex show dcache size
10751 Show maximum number of dcache entries. See also @ref{Caching Remote Data, info dcache}.
10752
10753 @item show dcache line-size
10754 @kindex show dcache line-size
10755 Show default size of dcache lines. See also @ref{Caching Remote Data, info dcache}.
10756
10757 @end table
10758
10759 @node Searching Memory
10760 @section Search Memory
10761 @cindex searching memory
10762
10763 Memory can be searched for a particular sequence of bytes with the
10764 @code{find} command.
10765
10766 @table @code
10767 @kindex find
10768 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10769 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
10770 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
10771 etc. The search begins at address @var{start_addr} and continues for either
10772 @var{len} bytes or through to @var{end_addr} inclusive.
10773 @end table
10774
10775 @var{s} and @var{n} are optional parameters.
10776 They may be specified in either order, apart or together.
10777
10778 @table @r
10779 @item @var{s}, search query size
10780 The size of each search query value.
10781
10782 @table @code
10783 @item b
10784 bytes
10785 @item h
10786 halfwords (two bytes)
10787 @item w
10788 words (four bytes)
10789 @item g
10790 giant words (eight bytes)
10791 @end table
10792
10793 All values are interpreted in the current language.
10794 This means, for example, that if the current source language is C/C@t{++}
10795 then searching for the string ``hello'' includes the trailing '\0'.
10796
10797 If the value size is not specified, it is taken from the
10798 value's type in the current language.
10799 This is useful when one wants to specify the search
10800 pattern as a mixture of types.
10801 Note that this means, for example, that in the case of C-like languages
10802 a search for an untyped 0x42 will search for @samp{(int) 0x42}
10803 which is typically four bytes.
10804
10805 @item @var{n}, maximum number of finds
10806 The maximum number of matches to print. The default is to print all finds.
10807 @end table
10808
10809 You can use strings as search values. Quote them with double-quotes
10810 (@code{"}).
10811 The string value is copied into the search pattern byte by byte,
10812 regardless of the endianness of the target and the size specification.
10813
10814 The address of each match found is printed as well as a count of the
10815 number of matches found.
10816
10817 The address of the last value found is stored in convenience variable
10818 @samp{$_}.
10819 A count of the number of matches is stored in @samp{$numfound}.
10820
10821 For example, if stopped at the @code{printf} in this function:
10822
10823 @smallexample
10824 void
10825 hello ()
10826 @{
10827 static char hello[] = "hello-hello";
10828 static struct @{ char c; short s; int i; @}
10829 __attribute__ ((packed)) mixed
10830 = @{ 'c', 0x1234, 0x87654321 @};
10831 printf ("%s\n", hello);
10832 @}
10833 @end smallexample
10834
10835 @noindent
10836 you get during debugging:
10837
10838 @smallexample
10839 (gdb) find &hello[0], +sizeof(hello), "hello"
10840 0x804956d <hello.1620+6>
10841 1 pattern found
10842 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
10843 0x8049567 <hello.1620>
10844 0x804956d <hello.1620+6>
10845 2 patterns found
10846 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
10847 0x8049567 <hello.1620>
10848 1 pattern found
10849 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
10850 0x8049560 <mixed.1625>
10851 1 pattern found
10852 (gdb) print $numfound
10853 $1 = 1
10854 (gdb) print $_
10855 $2 = (void *) 0x8049560
10856 @end smallexample
10857
10858 @node Optimized Code
10859 @chapter Debugging Optimized Code
10860 @cindex optimized code, debugging
10861 @cindex debugging optimized code
10862
10863 Almost all compilers support optimization. With optimization
10864 disabled, the compiler generates assembly code that corresponds
10865 directly to your source code, in a simplistic way. As the compiler
10866 applies more powerful optimizations, the generated assembly code
10867 diverges from your original source code. With help from debugging
10868 information generated by the compiler, @value{GDBN} can map from
10869 the running program back to constructs from your original source.
10870
10871 @value{GDBN} is more accurate with optimization disabled. If you
10872 can recompile without optimization, it is easier to follow the
10873 progress of your program during debugging. But, there are many cases
10874 where you may need to debug an optimized version.
10875
10876 When you debug a program compiled with @samp{-g -O}, remember that the
10877 optimizer has rearranged your code; the debugger shows you what is
10878 really there. Do not be too surprised when the execution path does not
10879 exactly match your source file! An extreme example: if you define a
10880 variable, but never use it, @value{GDBN} never sees that
10881 variable---because the compiler optimizes it out of existence.
10882
10883 Some things do not work as well with @samp{-g -O} as with just
10884 @samp{-g}, particularly on machines with instruction scheduling. If in
10885 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
10886 please report it to us as a bug (including a test case!).
10887 @xref{Variables}, for more information about debugging optimized code.
10888
10889 @menu
10890 * Inline Functions:: How @value{GDBN} presents inlining
10891 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
10892 @end menu
10893
10894 @node Inline Functions
10895 @section Inline Functions
10896 @cindex inline functions, debugging
10897
10898 @dfn{Inlining} is an optimization that inserts a copy of the function
10899 body directly at each call site, instead of jumping to a shared
10900 routine. @value{GDBN} displays inlined functions just like
10901 non-inlined functions. They appear in backtraces. You can view their
10902 arguments and local variables, step into them with @code{step}, skip
10903 them with @code{next}, and escape from them with @code{finish}.
10904 You can check whether a function was inlined by using the
10905 @code{info frame} command.
10906
10907 For @value{GDBN} to support inlined functions, the compiler must
10908 record information about inlining in the debug information ---
10909 @value{NGCC} using the @sc{dwarf 2} format does this, and several
10910 other compilers do also. @value{GDBN} only supports inlined functions
10911 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
10912 do not emit two required attributes (@samp{DW_AT_call_file} and
10913 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
10914 function calls with earlier versions of @value{NGCC}. It instead
10915 displays the arguments and local variables of inlined functions as
10916 local variables in the caller.
10917
10918 The body of an inlined function is directly included at its call site;
10919 unlike a non-inlined function, there are no instructions devoted to
10920 the call. @value{GDBN} still pretends that the call site and the
10921 start of the inlined function are different instructions. Stepping to
10922 the call site shows the call site, and then stepping again shows
10923 the first line of the inlined function, even though no additional
10924 instructions are executed.
10925
10926 This makes source-level debugging much clearer; you can see both the
10927 context of the call and then the effect of the call. Only stepping by
10928 a single instruction using @code{stepi} or @code{nexti} does not do
10929 this; single instruction steps always show the inlined body.
10930
10931 There are some ways that @value{GDBN} does not pretend that inlined
10932 function calls are the same as normal calls:
10933
10934 @itemize @bullet
10935 @item
10936 Setting breakpoints at the call site of an inlined function may not
10937 work, because the call site does not contain any code. @value{GDBN}
10938 may incorrectly move the breakpoint to the next line of the enclosing
10939 function, after the call. This limitation will be removed in a future
10940 version of @value{GDBN}; until then, set a breakpoint on an earlier line
10941 or inside the inlined function instead.
10942
10943 @item
10944 @value{GDBN} cannot locate the return value of inlined calls after
10945 using the @code{finish} command. This is a limitation of compiler-generated
10946 debugging information; after @code{finish}, you can step to the next line
10947 and print a variable where your program stored the return value.
10948
10949 @end itemize
10950
10951 @node Tail Call Frames
10952 @section Tail Call Frames
10953 @cindex tail call frames, debugging
10954
10955 Function @code{B} can call function @code{C} in its very last statement. In
10956 unoptimized compilation the call of @code{C} is immediately followed by return
10957 instruction at the end of @code{B} code. Optimizing compiler may replace the
10958 call and return in function @code{B} into one jump to function @code{C}
10959 instead. Such use of a jump instruction is called @dfn{tail call}.
10960
10961 During execution of function @code{C}, there will be no indication in the
10962 function call stack frames that it was tail-called from @code{B}. If function
10963 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
10964 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
10965 some cases @value{GDBN} can determine that @code{C} was tail-called from
10966 @code{B}, and it will then create fictitious call frame for that, with the
10967 return address set up as if @code{B} called @code{C} normally.
10968
10969 This functionality is currently supported only by DWARF 2 debugging format and
10970 the compiler has to produce @samp{DW_TAG_GNU_call_site} tags. With
10971 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10972 this information.
10973
10974 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
10975 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
10976
10977 @smallexample
10978 (gdb) x/i $pc - 2
10979 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
10980 (gdb) info frame
10981 Stack level 1, frame at 0x7fffffffda30:
10982 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
10983 tail call frame, caller of frame at 0x7fffffffda30
10984 source language c++.
10985 Arglist at unknown address.
10986 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
10987 @end smallexample
10988
10989 The detection of all the possible code path executions can find them ambiguous.
10990 There is no execution history stored (possible @ref{Reverse Execution} is never
10991 used for this purpose) and the last known caller could have reached the known
10992 callee by multiple different jump sequences. In such case @value{GDBN} still
10993 tries to show at least all the unambiguous top tail callers and all the
10994 unambiguous bottom tail calees, if any.
10995
10996 @table @code
10997 @anchor{set debug entry-values}
10998 @item set debug entry-values
10999 @kindex set debug entry-values
11000 When set to on, enables printing of analysis messages for both frame argument
11001 values at function entry and tail calls. It will show all the possible valid
11002 tail calls code paths it has considered. It will also print the intersection
11003 of them with the final unambiguous (possibly partial or even empty) code path
11004 result.
11005
11006 @item show debug entry-values
11007 @kindex show debug entry-values
11008 Show the current state of analysis messages printing for both frame argument
11009 values at function entry and tail calls.
11010 @end table
11011
11012 The analysis messages for tail calls can for example show why the virtual tail
11013 call frame for function @code{c} has not been recognized (due to the indirect
11014 reference by variable @code{x}):
11015
11016 @smallexample
11017 static void __attribute__((noinline, noclone)) c (void);
11018 void (*x) (void) = c;
11019 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
11020 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
11021 int main (void) @{ x (); return 0; @}
11022
11023 Breakpoint 1, DW_OP_GNU_entry_value resolving cannot find
11024 DW_TAG_GNU_call_site 0x40039a in main
11025 a () at t.c:3
11026 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
11027 (gdb) bt
11028 #0 a () at t.c:3
11029 #1 0x000000000040039a in main () at t.c:5
11030 @end smallexample
11031
11032 Another possibility is an ambiguous virtual tail call frames resolution:
11033
11034 @smallexample
11035 int i;
11036 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
11037 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
11038 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
11039 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
11040 static void __attribute__((noinline, noclone)) b (void)
11041 @{ if (i) c (); else e (); @}
11042 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
11043 int main (void) @{ a (); return 0; @}
11044
11045 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
11046 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
11047 tailcall: reduced: 0x4004d2(a) |
11048 (gdb) bt
11049 #0 f () at t.c:2
11050 #1 0x00000000004004d2 in a () at t.c:8
11051 #2 0x0000000000400395 in main () at t.c:9
11052 @end smallexample
11053
11054 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
11055 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
11056
11057 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
11058 @ifset HAVE_MAKEINFO_CLICK
11059 @set ARROW @click{}
11060 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
11061 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
11062 @end ifset
11063 @ifclear HAVE_MAKEINFO_CLICK
11064 @set ARROW ->
11065 @set CALLSEQ1B @value{CALLSEQ1A}
11066 @set CALLSEQ2B @value{CALLSEQ2A}
11067 @end ifclear
11068
11069 Frames #0 and #2 are real, #1 is a virtual tail call frame.
11070 The code can have possible execution paths @value{CALLSEQ1B} or
11071 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
11072
11073 @code{initial:} state shows some random possible calling sequence @value{GDBN}
11074 has found. It then finds another possible calling sequcen - that one is
11075 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
11076 printed as the @code{reduced:} calling sequence. That one could have many
11077 futher @code{compare:} and @code{reduced:} statements as long as there remain
11078 any non-ambiguous sequence entries.
11079
11080 For the frame of function @code{b} in both cases there are different possible
11081 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
11082 also ambigous. The only non-ambiguous frame is the one for function @code{a},
11083 therefore this one is displayed to the user while the ambiguous frames are
11084 omitted.
11085
11086 There can be also reasons why printing of frame argument values at function
11087 entry may fail:
11088
11089 @smallexample
11090 int v;
11091 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
11092 static void __attribute__((noinline, noclone)) a (int i);
11093 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
11094 static void __attribute__((noinline, noclone)) a (int i)
11095 @{ if (i) b (i - 1); else c (0); @}
11096 int main (void) @{ a (5); return 0; @}
11097
11098 (gdb) bt
11099 #0 c (i=i@@entry=0) at t.c:2
11100 #1 0x0000000000400428 in a (DW_OP_GNU_entry_value resolving has found
11101 function "a" at 0x400420 can call itself via tail calls
11102 i=<optimized out>) at t.c:6
11103 #2 0x000000000040036e in main () at t.c:7
11104 @end smallexample
11105
11106 @value{GDBN} cannot find out from the inferior state if and how many times did
11107 function @code{a} call itself (via function @code{b}) as these calls would be
11108 tail calls. Such tail calls would modify thue @code{i} variable, therefore
11109 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
11110 prints @code{<optimized out>} instead.
11111
11112 @node Macros
11113 @chapter C Preprocessor Macros
11114
11115 Some languages, such as C and C@t{++}, provide a way to define and invoke
11116 ``preprocessor macros'' which expand into strings of tokens.
11117 @value{GDBN} can evaluate expressions containing macro invocations, show
11118 the result of macro expansion, and show a macro's definition, including
11119 where it was defined.
11120
11121 You may need to compile your program specially to provide @value{GDBN}
11122 with information about preprocessor macros. Most compilers do not
11123 include macros in their debugging information, even when you compile
11124 with the @option{-g} flag. @xref{Compilation}.
11125
11126 A program may define a macro at one point, remove that definition later,
11127 and then provide a different definition after that. Thus, at different
11128 points in the program, a macro may have different definitions, or have
11129 no definition at all. If there is a current stack frame, @value{GDBN}
11130 uses the macros in scope at that frame's source code line. Otherwise,
11131 @value{GDBN} uses the macros in scope at the current listing location;
11132 see @ref{List}.
11133
11134 Whenever @value{GDBN} evaluates an expression, it always expands any
11135 macro invocations present in the expression. @value{GDBN} also provides
11136 the following commands for working with macros explicitly.
11137
11138 @table @code
11139
11140 @kindex macro expand
11141 @cindex macro expansion, showing the results of preprocessor
11142 @cindex preprocessor macro expansion, showing the results of
11143 @cindex expanding preprocessor macros
11144 @item macro expand @var{expression}
11145 @itemx macro exp @var{expression}
11146 Show the results of expanding all preprocessor macro invocations in
11147 @var{expression}. Since @value{GDBN} simply expands macros, but does
11148 not parse the result, @var{expression} need not be a valid expression;
11149 it can be any string of tokens.
11150
11151 @kindex macro exp1
11152 @item macro expand-once @var{expression}
11153 @itemx macro exp1 @var{expression}
11154 @cindex expand macro once
11155 @i{(This command is not yet implemented.)} Show the results of
11156 expanding those preprocessor macro invocations that appear explicitly in
11157 @var{expression}. Macro invocations appearing in that expansion are
11158 left unchanged. This command allows you to see the effect of a
11159 particular macro more clearly, without being confused by further
11160 expansions. Since @value{GDBN} simply expands macros, but does not
11161 parse the result, @var{expression} need not be a valid expression; it
11162 can be any string of tokens.
11163
11164 @kindex info macro
11165 @cindex macro definition, showing
11166 @cindex definition of a macro, showing
11167 @cindex macros, from debug info
11168 @item info macro [-a|-all] [--] @var{macro}
11169 Show the current definition or all definitions of the named @var{macro},
11170 and describe the source location or compiler command-line where that
11171 definition was established. The optional double dash is to signify the end of
11172 argument processing and the beginning of @var{macro} for non C-like macros where
11173 the macro may begin with a hyphen.
11174
11175 @kindex info macros
11176 @item info macros @var{linespec}
11177 Show all macro definitions that are in effect at the location specified
11178 by @var{linespec}, and describe the source location or compiler
11179 command-line where those definitions were established.
11180
11181 @kindex macro define
11182 @cindex user-defined macros
11183 @cindex defining macros interactively
11184 @cindex macros, user-defined
11185 @item macro define @var{macro} @var{replacement-list}
11186 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
11187 Introduce a definition for a preprocessor macro named @var{macro},
11188 invocations of which are replaced by the tokens given in
11189 @var{replacement-list}. The first form of this command defines an
11190 ``object-like'' macro, which takes no arguments; the second form
11191 defines a ``function-like'' macro, which takes the arguments given in
11192 @var{arglist}.
11193
11194 A definition introduced by this command is in scope in every
11195 expression evaluated in @value{GDBN}, until it is removed with the
11196 @code{macro undef} command, described below. The definition overrides
11197 all definitions for @var{macro} present in the program being debugged,
11198 as well as any previous user-supplied definition.
11199
11200 @kindex macro undef
11201 @item macro undef @var{macro}
11202 Remove any user-supplied definition for the macro named @var{macro}.
11203 This command only affects definitions provided with the @code{macro
11204 define} command, described above; it cannot remove definitions present
11205 in the program being debugged.
11206
11207 @kindex macro list
11208 @item macro list
11209 List all the macros defined using the @code{macro define} command.
11210 @end table
11211
11212 @cindex macros, example of debugging with
11213 Here is a transcript showing the above commands in action. First, we
11214 show our source files:
11215
11216 @smallexample
11217 $ cat sample.c
11218 #include <stdio.h>
11219 #include "sample.h"
11220
11221 #define M 42
11222 #define ADD(x) (M + x)
11223
11224 main ()
11225 @{
11226 #define N 28
11227 printf ("Hello, world!\n");
11228 #undef N
11229 printf ("We're so creative.\n");
11230 #define N 1729
11231 printf ("Goodbye, world!\n");
11232 @}
11233 $ cat sample.h
11234 #define Q <
11235 $
11236 @end smallexample
11237
11238 Now, we compile the program using the @sc{gnu} C compiler,
11239 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
11240 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
11241 and @option{-gdwarf-4}; we recommend always choosing the most recent
11242 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
11243 includes information about preprocessor macros in the debugging
11244 information.
11245
11246 @smallexample
11247 $ gcc -gdwarf-2 -g3 sample.c -o sample
11248 $
11249 @end smallexample
11250
11251 Now, we start @value{GDBN} on our sample program:
11252
11253 @smallexample
11254 $ gdb -nw sample
11255 GNU gdb 2002-05-06-cvs
11256 Copyright 2002 Free Software Foundation, Inc.
11257 GDB is free software, @dots{}
11258 (@value{GDBP})
11259 @end smallexample
11260
11261 We can expand macros and examine their definitions, even when the
11262 program is not running. @value{GDBN} uses the current listing position
11263 to decide which macro definitions are in scope:
11264
11265 @smallexample
11266 (@value{GDBP}) list main
11267 3
11268 4 #define M 42
11269 5 #define ADD(x) (M + x)
11270 6
11271 7 main ()
11272 8 @{
11273 9 #define N 28
11274 10 printf ("Hello, world!\n");
11275 11 #undef N
11276 12 printf ("We're so creative.\n");
11277 (@value{GDBP}) info macro ADD
11278 Defined at /home/jimb/gdb/macros/play/sample.c:5
11279 #define ADD(x) (M + x)
11280 (@value{GDBP}) info macro Q
11281 Defined at /home/jimb/gdb/macros/play/sample.h:1
11282 included at /home/jimb/gdb/macros/play/sample.c:2
11283 #define Q <
11284 (@value{GDBP}) macro expand ADD(1)
11285 expands to: (42 + 1)
11286 (@value{GDBP}) macro expand-once ADD(1)
11287 expands to: once (M + 1)
11288 (@value{GDBP})
11289 @end smallexample
11290
11291 In the example above, note that @code{macro expand-once} expands only
11292 the macro invocation explicit in the original text --- the invocation of
11293 @code{ADD} --- but does not expand the invocation of the macro @code{M},
11294 which was introduced by @code{ADD}.
11295
11296 Once the program is running, @value{GDBN} uses the macro definitions in
11297 force at the source line of the current stack frame:
11298
11299 @smallexample
11300 (@value{GDBP}) break main
11301 Breakpoint 1 at 0x8048370: file sample.c, line 10.
11302 (@value{GDBP}) run
11303 Starting program: /home/jimb/gdb/macros/play/sample
11304
11305 Breakpoint 1, main () at sample.c:10
11306 10 printf ("Hello, world!\n");
11307 (@value{GDBP})
11308 @end smallexample
11309
11310 At line 10, the definition of the macro @code{N} at line 9 is in force:
11311
11312 @smallexample
11313 (@value{GDBP}) info macro N
11314 Defined at /home/jimb/gdb/macros/play/sample.c:9
11315 #define N 28
11316 (@value{GDBP}) macro expand N Q M
11317 expands to: 28 < 42
11318 (@value{GDBP}) print N Q M
11319 $1 = 1
11320 (@value{GDBP})
11321 @end smallexample
11322
11323 As we step over directives that remove @code{N}'s definition, and then
11324 give it a new definition, @value{GDBN} finds the definition (or lack
11325 thereof) in force at each point:
11326
11327 @smallexample
11328 (@value{GDBP}) next
11329 Hello, world!
11330 12 printf ("We're so creative.\n");
11331 (@value{GDBP}) info macro N
11332 The symbol `N' has no definition as a C/C++ preprocessor macro
11333 at /home/jimb/gdb/macros/play/sample.c:12
11334 (@value{GDBP}) next
11335 We're so creative.
11336 14 printf ("Goodbye, world!\n");
11337 (@value{GDBP}) info macro N
11338 Defined at /home/jimb/gdb/macros/play/sample.c:13
11339 #define N 1729
11340 (@value{GDBP}) macro expand N Q M
11341 expands to: 1729 < 42
11342 (@value{GDBP}) print N Q M
11343 $2 = 0
11344 (@value{GDBP})
11345 @end smallexample
11346
11347 In addition to source files, macros can be defined on the compilation command
11348 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
11349 such a way, @value{GDBN} displays the location of their definition as line zero
11350 of the source file submitted to the compiler.
11351
11352 @smallexample
11353 (@value{GDBP}) info macro __STDC__
11354 Defined at /home/jimb/gdb/macros/play/sample.c:0
11355 -D__STDC__=1
11356 (@value{GDBP})
11357 @end smallexample
11358
11359
11360 @node Tracepoints
11361 @chapter Tracepoints
11362 @c This chapter is based on the documentation written by Michael
11363 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
11364
11365 @cindex tracepoints
11366 In some applications, it is not feasible for the debugger to interrupt
11367 the program's execution long enough for the developer to learn
11368 anything helpful about its behavior. If the program's correctness
11369 depends on its real-time behavior, delays introduced by a debugger
11370 might cause the program to change its behavior drastically, or perhaps
11371 fail, even when the code itself is correct. It is useful to be able
11372 to observe the program's behavior without interrupting it.
11373
11374 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
11375 specify locations in the program, called @dfn{tracepoints}, and
11376 arbitrary expressions to evaluate when those tracepoints are reached.
11377 Later, using the @code{tfind} command, you can examine the values
11378 those expressions had when the program hit the tracepoints. The
11379 expressions may also denote objects in memory---structures or arrays,
11380 for example---whose values @value{GDBN} should record; while visiting
11381 a particular tracepoint, you may inspect those objects as if they were
11382 in memory at that moment. However, because @value{GDBN} records these
11383 values without interacting with you, it can do so quickly and
11384 unobtrusively, hopefully not disturbing the program's behavior.
11385
11386 The tracepoint facility is currently available only for remote
11387 targets. @xref{Targets}. In addition, your remote target must know
11388 how to collect trace data. This functionality is implemented in the
11389 remote stub; however, none of the stubs distributed with @value{GDBN}
11390 support tracepoints as of this writing. The format of the remote
11391 packets used to implement tracepoints are described in @ref{Tracepoint
11392 Packets}.
11393
11394 It is also possible to get trace data from a file, in a manner reminiscent
11395 of corefiles; you specify the filename, and use @code{tfind} to search
11396 through the file. @xref{Trace Files}, for more details.
11397
11398 This chapter describes the tracepoint commands and features.
11399
11400 @menu
11401 * Set Tracepoints::
11402 * Analyze Collected Data::
11403 * Tracepoint Variables::
11404 * Trace Files::
11405 @end menu
11406
11407 @node Set Tracepoints
11408 @section Commands to Set Tracepoints
11409
11410 Before running such a @dfn{trace experiment}, an arbitrary number of
11411 tracepoints can be set. A tracepoint is actually a special type of
11412 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
11413 standard breakpoint commands. For instance, as with breakpoints,
11414 tracepoint numbers are successive integers starting from one, and many
11415 of the commands associated with tracepoints take the tracepoint number
11416 as their argument, to identify which tracepoint to work on.
11417
11418 For each tracepoint, you can specify, in advance, some arbitrary set
11419 of data that you want the target to collect in the trace buffer when
11420 it hits that tracepoint. The collected data can include registers,
11421 local variables, or global data. Later, you can use @value{GDBN}
11422 commands to examine the values these data had at the time the
11423 tracepoint was hit.
11424
11425 Tracepoints do not support every breakpoint feature. Ignore counts on
11426 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
11427 commands when they are hit. Tracepoints may not be thread-specific
11428 either.
11429
11430 @cindex fast tracepoints
11431 Some targets may support @dfn{fast tracepoints}, which are inserted in
11432 a different way (such as with a jump instead of a trap), that is
11433 faster but possibly restricted in where they may be installed.
11434
11435 @cindex static tracepoints
11436 @cindex markers, static tracepoints
11437 @cindex probing markers, static tracepoints
11438 Regular and fast tracepoints are dynamic tracing facilities, meaning
11439 that they can be used to insert tracepoints at (almost) any location
11440 in the target. Some targets may also support controlling @dfn{static
11441 tracepoints} from @value{GDBN}. With static tracing, a set of
11442 instrumentation points, also known as @dfn{markers}, are embedded in
11443 the target program, and can be activated or deactivated by name or
11444 address. These are usually placed at locations which facilitate
11445 investigating what the target is actually doing. @value{GDBN}'s
11446 support for static tracing includes being able to list instrumentation
11447 points, and attach them with @value{GDBN} defined high level
11448 tracepoints that expose the whole range of convenience of
11449 @value{GDBN}'s tracepoints support. Namely, support for collecting
11450 registers values and values of global or local (to the instrumentation
11451 point) variables; tracepoint conditions and trace state variables.
11452 The act of installing a @value{GDBN} static tracepoint on an
11453 instrumentation point, or marker, is referred to as @dfn{probing} a
11454 static tracepoint marker.
11455
11456 @code{gdbserver} supports tracepoints on some target systems.
11457 @xref{Server,,Tracepoints support in @code{gdbserver}}.
11458
11459 This section describes commands to set tracepoints and associated
11460 conditions and actions.
11461
11462 @menu
11463 * Create and Delete Tracepoints::
11464 * Enable and Disable Tracepoints::
11465 * Tracepoint Passcounts::
11466 * Tracepoint Conditions::
11467 * Trace State Variables::
11468 * Tracepoint Actions::
11469 * Listing Tracepoints::
11470 * Listing Static Tracepoint Markers::
11471 * Starting and Stopping Trace Experiments::
11472 * Tracepoint Restrictions::
11473 @end menu
11474
11475 @node Create and Delete Tracepoints
11476 @subsection Create and Delete Tracepoints
11477
11478 @table @code
11479 @cindex set tracepoint
11480 @kindex trace
11481 @item trace @var{location}
11482 The @code{trace} command is very similar to the @code{break} command.
11483 Its argument @var{location} can be a source line, a function name, or
11484 an address in the target program. @xref{Specify Location}. The
11485 @code{trace} command defines a tracepoint, which is a point in the
11486 target program where the debugger will briefly stop, collect some
11487 data, and then allow the program to continue. Setting a tracepoint or
11488 changing its actions takes effect immediately if the remote stub
11489 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
11490 in tracing}).
11491 If remote stub doesn't support the @samp{InstallInTrace} feature, all
11492 these changes don't take effect until the next @code{tstart}
11493 command, and once a trace experiment is running, further changes will
11494 not have any effect until the next trace experiment starts. In addition,
11495 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
11496 address is not yet resolved. (This is similar to pending breakpoints.)
11497 Pending tracepoints are not downloaded to the target and not installed
11498 until they are resolved. The resolution of pending tracepoints requires
11499 @value{GDBN} support---when debugging with the remote target, and
11500 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
11501 tracing}), pending tracepoints can not be resolved (and downloaded to
11502 the remote stub) while @value{GDBN} is disconnected.
11503
11504 Here are some examples of using the @code{trace} command:
11505
11506 @smallexample
11507 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
11508
11509 (@value{GDBP}) @b{trace +2} // 2 lines forward
11510
11511 (@value{GDBP}) @b{trace my_function} // first source line of function
11512
11513 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
11514
11515 (@value{GDBP}) @b{trace *0x2117c4} // an address
11516 @end smallexample
11517
11518 @noindent
11519 You can abbreviate @code{trace} as @code{tr}.
11520
11521 @item trace @var{location} if @var{cond}
11522 Set a tracepoint with condition @var{cond}; evaluate the expression
11523 @var{cond} each time the tracepoint is reached, and collect data only
11524 if the value is nonzero---that is, if @var{cond} evaluates as true.
11525 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
11526 information on tracepoint conditions.
11527
11528 @item ftrace @var{location} [ if @var{cond} ]
11529 @cindex set fast tracepoint
11530 @cindex fast tracepoints, setting
11531 @kindex ftrace
11532 The @code{ftrace} command sets a fast tracepoint. For targets that
11533 support them, fast tracepoints will use a more efficient but possibly
11534 less general technique to trigger data collection, such as a jump
11535 instruction instead of a trap, or some sort of hardware support. It
11536 may not be possible to create a fast tracepoint at the desired
11537 location, in which case the command will exit with an explanatory
11538 message.
11539
11540 @value{GDBN} handles arguments to @code{ftrace} exactly as for
11541 @code{trace}.
11542
11543 On 32-bit x86-architecture systems, fast tracepoints normally need to
11544 be placed at an instruction that is 5 bytes or longer, but can be
11545 placed at 4-byte instructions if the low 64K of memory of the target
11546 program is available to install trampolines. Some Unix-type systems,
11547 such as @sc{gnu}/Linux, exclude low addresses from the program's
11548 address space; but for instance with the Linux kernel it is possible
11549 to let @value{GDBN} use this area by doing a @command{sysctl} command
11550 to set the @code{mmap_min_addr} kernel parameter, as in
11551
11552 @example
11553 sudo sysctl -w vm.mmap_min_addr=32768
11554 @end example
11555
11556 @noindent
11557 which sets the low address to 32K, which leaves plenty of room for
11558 trampolines. The minimum address should be set to a page boundary.
11559
11560 @item strace @var{location} [ if @var{cond} ]
11561 @cindex set static tracepoint
11562 @cindex static tracepoints, setting
11563 @cindex probe static tracepoint marker
11564 @kindex strace
11565 The @code{strace} command sets a static tracepoint. For targets that
11566 support it, setting a static tracepoint probes a static
11567 instrumentation point, or marker, found at @var{location}. It may not
11568 be possible to set a static tracepoint at the desired location, in
11569 which case the command will exit with an explanatory message.
11570
11571 @value{GDBN} handles arguments to @code{strace} exactly as for
11572 @code{trace}, with the addition that the user can also specify
11573 @code{-m @var{marker}} as @var{location}. This probes the marker
11574 identified by the @var{marker} string identifier. This identifier
11575 depends on the static tracepoint backend library your program is
11576 using. You can find all the marker identifiers in the @samp{ID} field
11577 of the @code{info static-tracepoint-markers} command output.
11578 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
11579 Markers}. For example, in the following small program using the UST
11580 tracing engine:
11581
11582 @smallexample
11583 main ()
11584 @{
11585 trace_mark(ust, bar33, "str %s", "FOOBAZ");
11586 @}
11587 @end smallexample
11588
11589 @noindent
11590 the marker id is composed of joining the first two arguments to the
11591 @code{trace_mark} call with a slash, which translates to:
11592
11593 @smallexample
11594 (@value{GDBP}) info static-tracepoint-markers
11595 Cnt Enb ID Address What
11596 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
11597 Data: "str %s"
11598 [etc...]
11599 @end smallexample
11600
11601 @noindent
11602 so you may probe the marker above with:
11603
11604 @smallexample
11605 (@value{GDBP}) strace -m ust/bar33
11606 @end smallexample
11607
11608 Static tracepoints accept an extra collect action --- @code{collect
11609 $_sdata}. This collects arbitrary user data passed in the probe point
11610 call to the tracing library. In the UST example above, you'll see
11611 that the third argument to @code{trace_mark} is a printf-like format
11612 string. The user data is then the result of running that formating
11613 string against the following arguments. Note that @code{info
11614 static-tracepoint-markers} command output lists that format string in
11615 the @samp{Data:} field.
11616
11617 You can inspect this data when analyzing the trace buffer, by printing
11618 the $_sdata variable like any other variable available to
11619 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
11620
11621 @vindex $tpnum
11622 @cindex last tracepoint number
11623 @cindex recent tracepoint number
11624 @cindex tracepoint number
11625 The convenience variable @code{$tpnum} records the tracepoint number
11626 of the most recently set tracepoint.
11627
11628 @kindex delete tracepoint
11629 @cindex tracepoint deletion
11630 @item delete tracepoint @r{[}@var{num}@r{]}
11631 Permanently delete one or more tracepoints. With no argument, the
11632 default is to delete all tracepoints. Note that the regular
11633 @code{delete} command can remove tracepoints also.
11634
11635 Examples:
11636
11637 @smallexample
11638 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
11639
11640 (@value{GDBP}) @b{delete trace} // remove all tracepoints
11641 @end smallexample
11642
11643 @noindent
11644 You can abbreviate this command as @code{del tr}.
11645 @end table
11646
11647 @node Enable and Disable Tracepoints
11648 @subsection Enable and Disable Tracepoints
11649
11650 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
11651
11652 @table @code
11653 @kindex disable tracepoint
11654 @item disable tracepoint @r{[}@var{num}@r{]}
11655 Disable tracepoint @var{num}, or all tracepoints if no argument
11656 @var{num} is given. A disabled tracepoint will have no effect during
11657 a trace experiment, but it is not forgotten. You can re-enable
11658 a disabled tracepoint using the @code{enable tracepoint} command.
11659 If the command is issued during a trace experiment and the debug target
11660 has support for disabling tracepoints during a trace experiment, then the
11661 change will be effective immediately. Otherwise, it will be applied to the
11662 next trace experiment.
11663
11664 @kindex enable tracepoint
11665 @item enable tracepoint @r{[}@var{num}@r{]}
11666 Enable tracepoint @var{num}, or all tracepoints. If this command is
11667 issued during a trace experiment and the debug target supports enabling
11668 tracepoints during a trace experiment, then the enabled tracepoints will
11669 become effective immediately. Otherwise, they will become effective the
11670 next time a trace experiment is run.
11671 @end table
11672
11673 @node Tracepoint Passcounts
11674 @subsection Tracepoint Passcounts
11675
11676 @table @code
11677 @kindex passcount
11678 @cindex tracepoint pass count
11679 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
11680 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
11681 automatically stop a trace experiment. If a tracepoint's passcount is
11682 @var{n}, then the trace experiment will be automatically stopped on
11683 the @var{n}'th time that tracepoint is hit. If the tracepoint number
11684 @var{num} is not specified, the @code{passcount} command sets the
11685 passcount of the most recently defined tracepoint. If no passcount is
11686 given, the trace experiment will run until stopped explicitly by the
11687 user.
11688
11689 Examples:
11690
11691 @smallexample
11692 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
11693 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
11694
11695 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
11696 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
11697 (@value{GDBP}) @b{trace foo}
11698 (@value{GDBP}) @b{pass 3}
11699 (@value{GDBP}) @b{trace bar}
11700 (@value{GDBP}) @b{pass 2}
11701 (@value{GDBP}) @b{trace baz}
11702 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
11703 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
11704 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
11705 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
11706 @end smallexample
11707 @end table
11708
11709 @node Tracepoint Conditions
11710 @subsection Tracepoint Conditions
11711 @cindex conditional tracepoints
11712 @cindex tracepoint conditions
11713
11714 The simplest sort of tracepoint collects data every time your program
11715 reaches a specified place. You can also specify a @dfn{condition} for
11716 a tracepoint. A condition is just a Boolean expression in your
11717 programming language (@pxref{Expressions, ,Expressions}). A
11718 tracepoint with a condition evaluates the expression each time your
11719 program reaches it, and data collection happens only if the condition
11720 is true.
11721
11722 Tracepoint conditions can be specified when a tracepoint is set, by
11723 using @samp{if} in the arguments to the @code{trace} command.
11724 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
11725 also be set or changed at any time with the @code{condition} command,
11726 just as with breakpoints.
11727
11728 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
11729 the conditional expression itself. Instead, @value{GDBN} encodes the
11730 expression into an agent expression (@pxref{Agent Expressions})
11731 suitable for execution on the target, independently of @value{GDBN}.
11732 Global variables become raw memory locations, locals become stack
11733 accesses, and so forth.
11734
11735 For instance, suppose you have a function that is usually called
11736 frequently, but should not be called after an error has occurred. You
11737 could use the following tracepoint command to collect data about calls
11738 of that function that happen while the error code is propagating
11739 through the program; an unconditional tracepoint could end up
11740 collecting thousands of useless trace frames that you would have to
11741 search through.
11742
11743 @smallexample
11744 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
11745 @end smallexample
11746
11747 @node Trace State Variables
11748 @subsection Trace State Variables
11749 @cindex trace state variables
11750
11751 A @dfn{trace state variable} is a special type of variable that is
11752 created and managed by target-side code. The syntax is the same as
11753 that for GDB's convenience variables (a string prefixed with ``$''),
11754 but they are stored on the target. They must be created explicitly,
11755 using a @code{tvariable} command. They are always 64-bit signed
11756 integers.
11757
11758 Trace state variables are remembered by @value{GDBN}, and downloaded
11759 to the target along with tracepoint information when the trace
11760 experiment starts. There are no intrinsic limits on the number of
11761 trace state variables, beyond memory limitations of the target.
11762
11763 @cindex convenience variables, and trace state variables
11764 Although trace state variables are managed by the target, you can use
11765 them in print commands and expressions as if they were convenience
11766 variables; @value{GDBN} will get the current value from the target
11767 while the trace experiment is running. Trace state variables share
11768 the same namespace as other ``$'' variables, which means that you
11769 cannot have trace state variables with names like @code{$23} or
11770 @code{$pc}, nor can you have a trace state variable and a convenience
11771 variable with the same name.
11772
11773 @table @code
11774
11775 @item tvariable $@var{name} [ = @var{expression} ]
11776 @kindex tvariable
11777 The @code{tvariable} command creates a new trace state variable named
11778 @code{$@var{name}}, and optionally gives it an initial value of
11779 @var{expression}. @var{expression} is evaluated when this command is
11780 entered; the result will be converted to an integer if possible,
11781 otherwise @value{GDBN} will report an error. A subsequent
11782 @code{tvariable} command specifying the same name does not create a
11783 variable, but instead assigns the supplied initial value to the
11784 existing variable of that name, overwriting any previous initial
11785 value. The default initial value is 0.
11786
11787 @item info tvariables
11788 @kindex info tvariables
11789 List all the trace state variables along with their initial values.
11790 Their current values may also be displayed, if the trace experiment is
11791 currently running.
11792
11793 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
11794 @kindex delete tvariable
11795 Delete the given trace state variables, or all of them if no arguments
11796 are specified.
11797
11798 @end table
11799
11800 @node Tracepoint Actions
11801 @subsection Tracepoint Action Lists
11802
11803 @table @code
11804 @kindex actions
11805 @cindex tracepoint actions
11806 @item actions @r{[}@var{num}@r{]}
11807 This command will prompt for a list of actions to be taken when the
11808 tracepoint is hit. If the tracepoint number @var{num} is not
11809 specified, this command sets the actions for the one that was most
11810 recently defined (so that you can define a tracepoint and then say
11811 @code{actions} without bothering about its number). You specify the
11812 actions themselves on the following lines, one action at a time, and
11813 terminate the actions list with a line containing just @code{end}. So
11814 far, the only defined actions are @code{collect}, @code{teval}, and
11815 @code{while-stepping}.
11816
11817 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
11818 Commands, ,Breakpoint Command Lists}), except that only the defined
11819 actions are allowed; any other @value{GDBN} command is rejected.
11820
11821 @cindex remove actions from a tracepoint
11822 To remove all actions from a tracepoint, type @samp{actions @var{num}}
11823 and follow it immediately with @samp{end}.
11824
11825 @smallexample
11826 (@value{GDBP}) @b{collect @var{data}} // collect some data
11827
11828 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
11829
11830 (@value{GDBP}) @b{end} // signals the end of actions.
11831 @end smallexample
11832
11833 In the following example, the action list begins with @code{collect}
11834 commands indicating the things to be collected when the tracepoint is
11835 hit. Then, in order to single-step and collect additional data
11836 following the tracepoint, a @code{while-stepping} command is used,
11837 followed by the list of things to be collected after each step in a
11838 sequence of single steps. The @code{while-stepping} command is
11839 terminated by its own separate @code{end} command. Lastly, the action
11840 list is terminated by an @code{end} command.
11841
11842 @smallexample
11843 (@value{GDBP}) @b{trace foo}
11844 (@value{GDBP}) @b{actions}
11845 Enter actions for tracepoint 1, one per line:
11846 > collect bar,baz
11847 > collect $regs
11848 > while-stepping 12
11849 > collect $pc, arr[i]
11850 > end
11851 end
11852 @end smallexample
11853
11854 @kindex collect @r{(tracepoints)}
11855 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
11856 Collect values of the given expressions when the tracepoint is hit.
11857 This command accepts a comma-separated list of any valid expressions.
11858 In addition to global, static, or local variables, the following
11859 special arguments are supported:
11860
11861 @table @code
11862 @item $regs
11863 Collect all registers.
11864
11865 @item $args
11866 Collect all function arguments.
11867
11868 @item $locals
11869 Collect all local variables.
11870
11871 @item $_ret
11872 Collect the return address. This is helpful if you want to see more
11873 of a backtrace.
11874
11875 @item $_probe_argc
11876 Collects the number of arguments from the static probe at which the
11877 tracepoint is located.
11878 @xref{Static Probe Points}.
11879
11880 @item $_probe_arg@var{n}
11881 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
11882 from the static probe at which the tracepoint is located.
11883 @xref{Static Probe Points}.
11884
11885 @item $_sdata
11886 @vindex $_sdata@r{, collect}
11887 Collect static tracepoint marker specific data. Only available for
11888 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
11889 Lists}. On the UST static tracepoints library backend, an
11890 instrumentation point resembles a @code{printf} function call. The
11891 tracing library is able to collect user specified data formatted to a
11892 character string using the format provided by the programmer that
11893 instrumented the program. Other backends have similar mechanisms.
11894 Here's an example of a UST marker call:
11895
11896 @smallexample
11897 const char master_name[] = "$your_name";
11898 trace_mark(channel1, marker1, "hello %s", master_name)
11899 @end smallexample
11900
11901 In this case, collecting @code{$_sdata} collects the string
11902 @samp{hello $yourname}. When analyzing the trace buffer, you can
11903 inspect @samp{$_sdata} like any other variable available to
11904 @value{GDBN}.
11905 @end table
11906
11907 You can give several consecutive @code{collect} commands, each one
11908 with a single argument, or one @code{collect} command with several
11909 arguments separated by commas; the effect is the same.
11910
11911 The optional @var{mods} changes the usual handling of the arguments.
11912 @code{s} requests that pointers to chars be handled as strings, in
11913 particular collecting the contents of the memory being pointed at, up
11914 to the first zero. The upper bound is by default the value of the
11915 @code{print elements} variable; if @code{s} is followed by a decimal
11916 number, that is the upper bound instead. So for instance
11917 @samp{collect/s25 mystr} collects as many as 25 characters at
11918 @samp{mystr}.
11919
11920 The command @code{info scope} (@pxref{Symbols, info scope}) is
11921 particularly useful for figuring out what data to collect.
11922
11923 @kindex teval @r{(tracepoints)}
11924 @item teval @var{expr1}, @var{expr2}, @dots{}
11925 Evaluate the given expressions when the tracepoint is hit. This
11926 command accepts a comma-separated list of expressions. The results
11927 are discarded, so this is mainly useful for assigning values to trace
11928 state variables (@pxref{Trace State Variables}) without adding those
11929 values to the trace buffer, as would be the case if the @code{collect}
11930 action were used.
11931
11932 @kindex while-stepping @r{(tracepoints)}
11933 @item while-stepping @var{n}
11934 Perform @var{n} single-step instruction traces after the tracepoint,
11935 collecting new data after each step. The @code{while-stepping}
11936 command is followed by the list of what to collect while stepping
11937 (followed by its own @code{end} command):
11938
11939 @smallexample
11940 > while-stepping 12
11941 > collect $regs, myglobal
11942 > end
11943 >
11944 @end smallexample
11945
11946 @noindent
11947 Note that @code{$pc} is not automatically collected by
11948 @code{while-stepping}; you need to explicitly collect that register if
11949 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
11950 @code{stepping}.
11951
11952 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
11953 @kindex set default-collect
11954 @cindex default collection action
11955 This variable is a list of expressions to collect at each tracepoint
11956 hit. It is effectively an additional @code{collect} action prepended
11957 to every tracepoint action list. The expressions are parsed
11958 individually for each tracepoint, so for instance a variable named
11959 @code{xyz} may be interpreted as a global for one tracepoint, and a
11960 local for another, as appropriate to the tracepoint's location.
11961
11962 @item show default-collect
11963 @kindex show default-collect
11964 Show the list of expressions that are collected by default at each
11965 tracepoint hit.
11966
11967 @end table
11968
11969 @node Listing Tracepoints
11970 @subsection Listing Tracepoints
11971
11972 @table @code
11973 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
11974 @kindex info tp @r{[}@var{n}@dots{}@r{]}
11975 @cindex information about tracepoints
11976 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
11977 Display information about the tracepoint @var{num}. If you don't
11978 specify a tracepoint number, displays information about all the
11979 tracepoints defined so far. The format is similar to that used for
11980 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
11981 command, simply restricting itself to tracepoints.
11982
11983 A tracepoint's listing may include additional information specific to
11984 tracing:
11985
11986 @itemize @bullet
11987 @item
11988 its passcount as given by the @code{passcount @var{n}} command
11989
11990 @item
11991 the state about installed on target of each location
11992 @end itemize
11993
11994 @smallexample
11995 (@value{GDBP}) @b{info trace}
11996 Num Type Disp Enb Address What
11997 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
11998 while-stepping 20
11999 collect globfoo, $regs
12000 end
12001 collect globfoo2
12002 end
12003 pass count 1200
12004 2 tracepoint keep y <MULTIPLE>
12005 collect $eip
12006 2.1 y 0x0804859c in func4 at change-loc.h:35
12007 installed on target
12008 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
12009 installed on target
12010 2.3 y <PENDING> set_tracepoint
12011 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
12012 not installed on target
12013 (@value{GDBP})
12014 @end smallexample
12015
12016 @noindent
12017 This command can be abbreviated @code{info tp}.
12018 @end table
12019
12020 @node Listing Static Tracepoint Markers
12021 @subsection Listing Static Tracepoint Markers
12022
12023 @table @code
12024 @kindex info static-tracepoint-markers
12025 @cindex information about static tracepoint markers
12026 @item info static-tracepoint-markers
12027 Display information about all static tracepoint markers defined in the
12028 program.
12029
12030 For each marker, the following columns are printed:
12031
12032 @table @emph
12033 @item Count
12034 An incrementing counter, output to help readability. This is not a
12035 stable identifier.
12036 @item ID
12037 The marker ID, as reported by the target.
12038 @item Enabled or Disabled
12039 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
12040 that are not enabled.
12041 @item Address
12042 Where the marker is in your program, as a memory address.
12043 @item What
12044 Where the marker is in the source for your program, as a file and line
12045 number. If the debug information included in the program does not
12046 allow @value{GDBN} to locate the source of the marker, this column
12047 will be left blank.
12048 @end table
12049
12050 @noindent
12051 In addition, the following information may be printed for each marker:
12052
12053 @table @emph
12054 @item Data
12055 User data passed to the tracing library by the marker call. In the
12056 UST backend, this is the format string passed as argument to the
12057 marker call.
12058 @item Static tracepoints probing the marker
12059 The list of static tracepoints attached to the marker.
12060 @end table
12061
12062 @smallexample
12063 (@value{GDBP}) info static-tracepoint-markers
12064 Cnt ID Enb Address What
12065 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
12066 Data: number1 %d number2 %d
12067 Probed by static tracepoints: #2
12068 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
12069 Data: str %s
12070 (@value{GDBP})
12071 @end smallexample
12072 @end table
12073
12074 @node Starting and Stopping Trace Experiments
12075 @subsection Starting and Stopping Trace Experiments
12076
12077 @table @code
12078 @kindex tstart [ @var{notes} ]
12079 @cindex start a new trace experiment
12080 @cindex collected data discarded
12081 @item tstart
12082 This command starts the trace experiment, and begins collecting data.
12083 It has the side effect of discarding all the data collected in the
12084 trace buffer during the previous trace experiment. If any arguments
12085 are supplied, they are taken as a note and stored with the trace
12086 experiment's state. The notes may be arbitrary text, and are
12087 especially useful with disconnected tracing in a multi-user context;
12088 the notes can explain what the trace is doing, supply user contact
12089 information, and so forth.
12090
12091 @kindex tstop [ @var{notes} ]
12092 @cindex stop a running trace experiment
12093 @item tstop
12094 This command stops the trace experiment. If any arguments are
12095 supplied, they are recorded with the experiment as a note. This is
12096 useful if you are stopping a trace started by someone else, for
12097 instance if the trace is interfering with the system's behavior and
12098 needs to be stopped quickly.
12099
12100 @strong{Note}: a trace experiment and data collection may stop
12101 automatically if any tracepoint's passcount is reached
12102 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
12103
12104 @kindex tstatus
12105 @cindex status of trace data collection
12106 @cindex trace experiment, status of
12107 @item tstatus
12108 This command displays the status of the current trace data
12109 collection.
12110 @end table
12111
12112 Here is an example of the commands we described so far:
12113
12114 @smallexample
12115 (@value{GDBP}) @b{trace gdb_c_test}
12116 (@value{GDBP}) @b{actions}
12117 Enter actions for tracepoint #1, one per line.
12118 > collect $regs,$locals,$args
12119 > while-stepping 11
12120 > collect $regs
12121 > end
12122 > end
12123 (@value{GDBP}) @b{tstart}
12124 [time passes @dots{}]
12125 (@value{GDBP}) @b{tstop}
12126 @end smallexample
12127
12128 @anchor{disconnected tracing}
12129 @cindex disconnected tracing
12130 You can choose to continue running the trace experiment even if
12131 @value{GDBN} disconnects from the target, voluntarily or
12132 involuntarily. For commands such as @code{detach}, the debugger will
12133 ask what you want to do with the trace. But for unexpected
12134 terminations (@value{GDBN} crash, network outage), it would be
12135 unfortunate to lose hard-won trace data, so the variable
12136 @code{disconnected-tracing} lets you decide whether the trace should
12137 continue running without @value{GDBN}.
12138
12139 @table @code
12140 @item set disconnected-tracing on
12141 @itemx set disconnected-tracing off
12142 @kindex set disconnected-tracing
12143 Choose whether a tracing run should continue to run if @value{GDBN}
12144 has disconnected from the target. Note that @code{detach} or
12145 @code{quit} will ask you directly what to do about a running trace no
12146 matter what this variable's setting, so the variable is mainly useful
12147 for handling unexpected situations, such as loss of the network.
12148
12149 @item show disconnected-tracing
12150 @kindex show disconnected-tracing
12151 Show the current choice for disconnected tracing.
12152
12153 @end table
12154
12155 When you reconnect to the target, the trace experiment may or may not
12156 still be running; it might have filled the trace buffer in the
12157 meantime, or stopped for one of the other reasons. If it is running,
12158 it will continue after reconnection.
12159
12160 Upon reconnection, the target will upload information about the
12161 tracepoints in effect. @value{GDBN} will then compare that
12162 information to the set of tracepoints currently defined, and attempt
12163 to match them up, allowing for the possibility that the numbers may
12164 have changed due to creation and deletion in the meantime. If one of
12165 the target's tracepoints does not match any in @value{GDBN}, the
12166 debugger will create a new tracepoint, so that you have a number with
12167 which to specify that tracepoint. This matching-up process is
12168 necessarily heuristic, and it may result in useless tracepoints being
12169 created; you may simply delete them if they are of no use.
12170
12171 @cindex circular trace buffer
12172 If your target agent supports a @dfn{circular trace buffer}, then you
12173 can run a trace experiment indefinitely without filling the trace
12174 buffer; when space runs out, the agent deletes already-collected trace
12175 frames, oldest first, until there is enough room to continue
12176 collecting. This is especially useful if your tracepoints are being
12177 hit too often, and your trace gets terminated prematurely because the
12178 buffer is full. To ask for a circular trace buffer, simply set
12179 @samp{circular-trace-buffer} to on. You can set this at any time,
12180 including during tracing; if the agent can do it, it will change
12181 buffer handling on the fly, otherwise it will not take effect until
12182 the next run.
12183
12184 @table @code
12185 @item set circular-trace-buffer on
12186 @itemx set circular-trace-buffer off
12187 @kindex set circular-trace-buffer
12188 Choose whether a tracing run should use a linear or circular buffer
12189 for trace data. A linear buffer will not lose any trace data, but may
12190 fill up prematurely, while a circular buffer will discard old trace
12191 data, but it will have always room for the latest tracepoint hits.
12192
12193 @item show circular-trace-buffer
12194 @kindex show circular-trace-buffer
12195 Show the current choice for the trace buffer. Note that this may not
12196 match the agent's current buffer handling, nor is it guaranteed to
12197 match the setting that might have been in effect during a past run,
12198 for instance if you are looking at frames from a trace file.
12199
12200 @end table
12201
12202 @table @code
12203 @item set trace-buffer-size @var{n}
12204 @itemx set trace-buffer-size unlimited
12205 @kindex set trace-buffer-size
12206 Request that the target use a trace buffer of @var{n} bytes. Not all
12207 targets will honor the request; they may have a compiled-in size for
12208 the trace buffer, or some other limitation. Set to a value of
12209 @code{unlimited} or @code{-1} to let the target use whatever size it
12210 likes. This is also the default.
12211
12212 @item show trace-buffer-size
12213 @kindex show trace-buffer-size
12214 Show the current requested size for the trace buffer. Note that this
12215 will only match the actual size if the target supports size-setting,
12216 and was able to handle the requested size. For instance, if the
12217 target can only change buffer size between runs, this variable will
12218 not reflect the change until the next run starts. Use @code{tstatus}
12219 to get a report of the actual buffer size.
12220 @end table
12221
12222 @table @code
12223 @item set trace-user @var{text}
12224 @kindex set trace-user
12225
12226 @item show trace-user
12227 @kindex show trace-user
12228
12229 @item set trace-notes @var{text}
12230 @kindex set trace-notes
12231 Set the trace run's notes.
12232
12233 @item show trace-notes
12234 @kindex show trace-notes
12235 Show the trace run's notes.
12236
12237 @item set trace-stop-notes @var{text}
12238 @kindex set trace-stop-notes
12239 Set the trace run's stop notes. The handling of the note is as for
12240 @code{tstop} arguments; the set command is convenient way to fix a
12241 stop note that is mistaken or incomplete.
12242
12243 @item show trace-stop-notes
12244 @kindex show trace-stop-notes
12245 Show the trace run's stop notes.
12246
12247 @end table
12248
12249 @node Tracepoint Restrictions
12250 @subsection Tracepoint Restrictions
12251
12252 @cindex tracepoint restrictions
12253 There are a number of restrictions on the use of tracepoints. As
12254 described above, tracepoint data gathering occurs on the target
12255 without interaction from @value{GDBN}. Thus the full capabilities of
12256 the debugger are not available during data gathering, and then at data
12257 examination time, you will be limited by only having what was
12258 collected. The following items describe some common problems, but it
12259 is not exhaustive, and you may run into additional difficulties not
12260 mentioned here.
12261
12262 @itemize @bullet
12263
12264 @item
12265 Tracepoint expressions are intended to gather objects (lvalues). Thus
12266 the full flexibility of GDB's expression evaluator is not available.
12267 You cannot call functions, cast objects to aggregate types, access
12268 convenience variables or modify values (except by assignment to trace
12269 state variables). Some language features may implicitly call
12270 functions (for instance Objective-C fields with accessors), and therefore
12271 cannot be collected either.
12272
12273 @item
12274 Collection of local variables, either individually or in bulk with
12275 @code{$locals} or @code{$args}, during @code{while-stepping} may
12276 behave erratically. The stepping action may enter a new scope (for
12277 instance by stepping into a function), or the location of the variable
12278 may change (for instance it is loaded into a register). The
12279 tracepoint data recorded uses the location information for the
12280 variables that is correct for the tracepoint location. When the
12281 tracepoint is created, it is not possible, in general, to determine
12282 where the steps of a @code{while-stepping} sequence will advance the
12283 program---particularly if a conditional branch is stepped.
12284
12285 @item
12286 Collection of an incompletely-initialized or partially-destroyed object
12287 may result in something that @value{GDBN} cannot display, or displays
12288 in a misleading way.
12289
12290 @item
12291 When @value{GDBN} displays a pointer to character it automatically
12292 dereferences the pointer to also display characters of the string
12293 being pointed to. However, collecting the pointer during tracing does
12294 not automatically collect the string. You need to explicitly
12295 dereference the pointer and provide size information if you want to
12296 collect not only the pointer, but the memory pointed to. For example,
12297 @code{*ptr@@50} can be used to collect the 50 element array pointed to
12298 by @code{ptr}.
12299
12300 @item
12301 It is not possible to collect a complete stack backtrace at a
12302 tracepoint. Instead, you may collect the registers and a few hundred
12303 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
12304 (adjust to use the name of the actual stack pointer register on your
12305 target architecture, and the amount of stack you wish to capture).
12306 Then the @code{backtrace} command will show a partial backtrace when
12307 using a trace frame. The number of stack frames that can be examined
12308 depends on the sizes of the frames in the collected stack. Note that
12309 if you ask for a block so large that it goes past the bottom of the
12310 stack, the target agent may report an error trying to read from an
12311 invalid address.
12312
12313 @item
12314 If you do not collect registers at a tracepoint, @value{GDBN} can
12315 infer that the value of @code{$pc} must be the same as the address of
12316 the tracepoint and use that when you are looking at a trace frame
12317 for that tracepoint. However, this cannot work if the tracepoint has
12318 multiple locations (for instance if it was set in a function that was
12319 inlined), or if it has a @code{while-stepping} loop. In those cases
12320 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
12321 it to zero.
12322
12323 @end itemize
12324
12325 @node Analyze Collected Data
12326 @section Using the Collected Data
12327
12328 After the tracepoint experiment ends, you use @value{GDBN} commands
12329 for examining the trace data. The basic idea is that each tracepoint
12330 collects a trace @dfn{snapshot} every time it is hit and another
12331 snapshot every time it single-steps. All these snapshots are
12332 consecutively numbered from zero and go into a buffer, and you can
12333 examine them later. The way you examine them is to @dfn{focus} on a
12334 specific trace snapshot. When the remote stub is focused on a trace
12335 snapshot, it will respond to all @value{GDBN} requests for memory and
12336 registers by reading from the buffer which belongs to that snapshot,
12337 rather than from @emph{real} memory or registers of the program being
12338 debugged. This means that @strong{all} @value{GDBN} commands
12339 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
12340 behave as if we were currently debugging the program state as it was
12341 when the tracepoint occurred. Any requests for data that are not in
12342 the buffer will fail.
12343
12344 @menu
12345 * tfind:: How to select a trace snapshot
12346 * tdump:: How to display all data for a snapshot
12347 * save tracepoints:: How to save tracepoints for a future run
12348 @end menu
12349
12350 @node tfind
12351 @subsection @code{tfind @var{n}}
12352
12353 @kindex tfind
12354 @cindex select trace snapshot
12355 @cindex find trace snapshot
12356 The basic command for selecting a trace snapshot from the buffer is
12357 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
12358 counting from zero. If no argument @var{n} is given, the next
12359 snapshot is selected.
12360
12361 Here are the various forms of using the @code{tfind} command.
12362
12363 @table @code
12364 @item tfind start
12365 Find the first snapshot in the buffer. This is a synonym for
12366 @code{tfind 0} (since 0 is the number of the first snapshot).
12367
12368 @item tfind none
12369 Stop debugging trace snapshots, resume @emph{live} debugging.
12370
12371 @item tfind end
12372 Same as @samp{tfind none}.
12373
12374 @item tfind
12375 No argument means find the next trace snapshot.
12376
12377 @item tfind -
12378 Find the previous trace snapshot before the current one. This permits
12379 retracing earlier steps.
12380
12381 @item tfind tracepoint @var{num}
12382 Find the next snapshot associated with tracepoint @var{num}. Search
12383 proceeds forward from the last examined trace snapshot. If no
12384 argument @var{num} is given, it means find the next snapshot collected
12385 for the same tracepoint as the current snapshot.
12386
12387 @item tfind pc @var{addr}
12388 Find the next snapshot associated with the value @var{addr} of the
12389 program counter. Search proceeds forward from the last examined trace
12390 snapshot. If no argument @var{addr} is given, it means find the next
12391 snapshot with the same value of PC as the current snapshot.
12392
12393 @item tfind outside @var{addr1}, @var{addr2}
12394 Find the next snapshot whose PC is outside the given range of
12395 addresses (exclusive).
12396
12397 @item tfind range @var{addr1}, @var{addr2}
12398 Find the next snapshot whose PC is between @var{addr1} and
12399 @var{addr2} (inclusive).
12400
12401 @item tfind line @r{[}@var{file}:@r{]}@var{n}
12402 Find the next snapshot associated with the source line @var{n}. If
12403 the optional argument @var{file} is given, refer to line @var{n} in
12404 that source file. Search proceeds forward from the last examined
12405 trace snapshot. If no argument @var{n} is given, it means find the
12406 next line other than the one currently being examined; thus saying
12407 @code{tfind line} repeatedly can appear to have the same effect as
12408 stepping from line to line in a @emph{live} debugging session.
12409 @end table
12410
12411 The default arguments for the @code{tfind} commands are specifically
12412 designed to make it easy to scan through the trace buffer. For
12413 instance, @code{tfind} with no argument selects the next trace
12414 snapshot, and @code{tfind -} with no argument selects the previous
12415 trace snapshot. So, by giving one @code{tfind} command, and then
12416 simply hitting @key{RET} repeatedly you can examine all the trace
12417 snapshots in order. Or, by saying @code{tfind -} and then hitting
12418 @key{RET} repeatedly you can examine the snapshots in reverse order.
12419 The @code{tfind line} command with no argument selects the snapshot
12420 for the next source line executed. The @code{tfind pc} command with
12421 no argument selects the next snapshot with the same program counter
12422 (PC) as the current frame. The @code{tfind tracepoint} command with
12423 no argument selects the next trace snapshot collected by the same
12424 tracepoint as the current one.
12425
12426 In addition to letting you scan through the trace buffer manually,
12427 these commands make it easy to construct @value{GDBN} scripts that
12428 scan through the trace buffer and print out whatever collected data
12429 you are interested in. Thus, if we want to examine the PC, FP, and SP
12430 registers from each trace frame in the buffer, we can say this:
12431
12432 @smallexample
12433 (@value{GDBP}) @b{tfind start}
12434 (@value{GDBP}) @b{while ($trace_frame != -1)}
12435 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
12436 $trace_frame, $pc, $sp, $fp
12437 > tfind
12438 > end
12439
12440 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
12441 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
12442 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
12443 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
12444 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
12445 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
12446 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
12447 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
12448 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
12449 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
12450 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
12451 @end smallexample
12452
12453 Or, if we want to examine the variable @code{X} at each source line in
12454 the buffer:
12455
12456 @smallexample
12457 (@value{GDBP}) @b{tfind start}
12458 (@value{GDBP}) @b{while ($trace_frame != -1)}
12459 > printf "Frame %d, X == %d\n", $trace_frame, X
12460 > tfind line
12461 > end
12462
12463 Frame 0, X = 1
12464 Frame 7, X = 2
12465 Frame 13, X = 255
12466 @end smallexample
12467
12468 @node tdump
12469 @subsection @code{tdump}
12470 @kindex tdump
12471 @cindex dump all data collected at tracepoint
12472 @cindex tracepoint data, display
12473
12474 This command takes no arguments. It prints all the data collected at
12475 the current trace snapshot.
12476
12477 @smallexample
12478 (@value{GDBP}) @b{trace 444}
12479 (@value{GDBP}) @b{actions}
12480 Enter actions for tracepoint #2, one per line:
12481 > collect $regs, $locals, $args, gdb_long_test
12482 > end
12483
12484 (@value{GDBP}) @b{tstart}
12485
12486 (@value{GDBP}) @b{tfind line 444}
12487 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
12488 at gdb_test.c:444
12489 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
12490
12491 (@value{GDBP}) @b{tdump}
12492 Data collected at tracepoint 2, trace frame 1:
12493 d0 0xc4aa0085 -995491707
12494 d1 0x18 24
12495 d2 0x80 128
12496 d3 0x33 51
12497 d4 0x71aea3d 119204413
12498 d5 0x22 34
12499 d6 0xe0 224
12500 d7 0x380035 3670069
12501 a0 0x19e24a 1696330
12502 a1 0x3000668 50333288
12503 a2 0x100 256
12504 a3 0x322000 3284992
12505 a4 0x3000698 50333336
12506 a5 0x1ad3cc 1758156
12507 fp 0x30bf3c 0x30bf3c
12508 sp 0x30bf34 0x30bf34
12509 ps 0x0 0
12510 pc 0x20b2c8 0x20b2c8
12511 fpcontrol 0x0 0
12512 fpstatus 0x0 0
12513 fpiaddr 0x0 0
12514 p = 0x20e5b4 "gdb-test"
12515 p1 = (void *) 0x11
12516 p2 = (void *) 0x22
12517 p3 = (void *) 0x33
12518 p4 = (void *) 0x44
12519 p5 = (void *) 0x55
12520 p6 = (void *) 0x66
12521 gdb_long_test = 17 '\021'
12522
12523 (@value{GDBP})
12524 @end smallexample
12525
12526 @code{tdump} works by scanning the tracepoint's current collection
12527 actions and printing the value of each expression listed. So
12528 @code{tdump} can fail, if after a run, you change the tracepoint's
12529 actions to mention variables that were not collected during the run.
12530
12531 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
12532 uses the collected value of @code{$pc} to distinguish between trace
12533 frames that were collected at the tracepoint hit, and frames that were
12534 collected while stepping. This allows it to correctly choose whether
12535 to display the basic list of collections, or the collections from the
12536 body of the while-stepping loop. However, if @code{$pc} was not collected,
12537 then @code{tdump} will always attempt to dump using the basic collection
12538 list, and may fail if a while-stepping frame does not include all the
12539 same data that is collected at the tracepoint hit.
12540 @c This is getting pretty arcane, example would be good.
12541
12542 @node save tracepoints
12543 @subsection @code{save tracepoints @var{filename}}
12544 @kindex save tracepoints
12545 @kindex save-tracepoints
12546 @cindex save tracepoints for future sessions
12547
12548 This command saves all current tracepoint definitions together with
12549 their actions and passcounts, into a file @file{@var{filename}}
12550 suitable for use in a later debugging session. To read the saved
12551 tracepoint definitions, use the @code{source} command (@pxref{Command
12552 Files}). The @w{@code{save-tracepoints}} command is a deprecated
12553 alias for @w{@code{save tracepoints}}
12554
12555 @node Tracepoint Variables
12556 @section Convenience Variables for Tracepoints
12557 @cindex tracepoint variables
12558 @cindex convenience variables for tracepoints
12559
12560 @table @code
12561 @vindex $trace_frame
12562 @item (int) $trace_frame
12563 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
12564 snapshot is selected.
12565
12566 @vindex $tracepoint
12567 @item (int) $tracepoint
12568 The tracepoint for the current trace snapshot.
12569
12570 @vindex $trace_line
12571 @item (int) $trace_line
12572 The line number for the current trace snapshot.
12573
12574 @vindex $trace_file
12575 @item (char []) $trace_file
12576 The source file for the current trace snapshot.
12577
12578 @vindex $trace_func
12579 @item (char []) $trace_func
12580 The name of the function containing @code{$tracepoint}.
12581 @end table
12582
12583 Note: @code{$trace_file} is not suitable for use in @code{printf},
12584 use @code{output} instead.
12585
12586 Here's a simple example of using these convenience variables for
12587 stepping through all the trace snapshots and printing some of their
12588 data. Note that these are not the same as trace state variables,
12589 which are managed by the target.
12590
12591 @smallexample
12592 (@value{GDBP}) @b{tfind start}
12593
12594 (@value{GDBP}) @b{while $trace_frame != -1}
12595 > output $trace_file
12596 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
12597 > tfind
12598 > end
12599 @end smallexample
12600
12601 @node Trace Files
12602 @section Using Trace Files
12603 @cindex trace files
12604
12605 In some situations, the target running a trace experiment may no
12606 longer be available; perhaps it crashed, or the hardware was needed
12607 for a different activity. To handle these cases, you can arrange to
12608 dump the trace data into a file, and later use that file as a source
12609 of trace data, via the @code{target tfile} command.
12610
12611 @table @code
12612
12613 @kindex tsave
12614 @item tsave [ -r ] @var{filename}
12615 @itemx tsave [-ctf] @var{dirname}
12616 Save the trace data to @var{filename}. By default, this command
12617 assumes that @var{filename} refers to the host filesystem, so if
12618 necessary @value{GDBN} will copy raw trace data up from the target and
12619 then save it. If the target supports it, you can also supply the
12620 optional argument @code{-r} (``remote'') to direct the target to save
12621 the data directly into @var{filename} in its own filesystem, which may be
12622 more efficient if the trace buffer is very large. (Note, however, that
12623 @code{target tfile} can only read from files accessible to the host.)
12624 By default, this command will save trace frame in tfile format.
12625 You can supply the optional argument @code{-ctf} to save date in CTF
12626 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
12627 that can be shared by multiple debugging and tracing tools. Please go to
12628 @indicateurl{http://www.efficios.com/ctf} to get more information.
12629
12630 @kindex target tfile
12631 @kindex tfile
12632 @kindex target ctf
12633 @kindex ctf
12634 @item target tfile @var{filename}
12635 @itemx target ctf @var{dirname}
12636 Use the file named @var{filename} or directory named @var{dirname} as
12637 a source of trace data. Commands that examine data work as they do with
12638 a live target, but it is not possible to run any new trace experiments.
12639 @code{tstatus} will report the state of the trace run at the moment
12640 the data was saved, as well as the current trace frame you are examining.
12641 @var{filename} or @var{dirname} must be on a filesystem accessible to
12642 the host.
12643
12644 @smallexample
12645 (@value{GDBP}) target ctf ctf.ctf
12646 (@value{GDBP}) tfind
12647 Found trace frame 0, tracepoint 2
12648 39 ++a; /* set tracepoint 1 here */
12649 (@value{GDBP}) tdump
12650 Data collected at tracepoint 2, trace frame 0:
12651 i = 0
12652 a = 0
12653 b = 1 '\001'
12654 c = @{"123", "456", "789", "123", "456", "789"@}
12655 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
12656 (@value{GDBP}) p b
12657 $1 = 1
12658 @end smallexample
12659
12660 @end table
12661
12662 @node Overlays
12663 @chapter Debugging Programs That Use Overlays
12664 @cindex overlays
12665
12666 If your program is too large to fit completely in your target system's
12667 memory, you can sometimes use @dfn{overlays} to work around this
12668 problem. @value{GDBN} provides some support for debugging programs that
12669 use overlays.
12670
12671 @menu
12672 * How Overlays Work:: A general explanation of overlays.
12673 * Overlay Commands:: Managing overlays in @value{GDBN}.
12674 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
12675 mapped by asking the inferior.
12676 * Overlay Sample Program:: A sample program using overlays.
12677 @end menu
12678
12679 @node How Overlays Work
12680 @section How Overlays Work
12681 @cindex mapped overlays
12682 @cindex unmapped overlays
12683 @cindex load address, overlay's
12684 @cindex mapped address
12685 @cindex overlay area
12686
12687 Suppose you have a computer whose instruction address space is only 64
12688 kilobytes long, but which has much more memory which can be accessed by
12689 other means: special instructions, segment registers, or memory
12690 management hardware, for example. Suppose further that you want to
12691 adapt a program which is larger than 64 kilobytes to run on this system.
12692
12693 One solution is to identify modules of your program which are relatively
12694 independent, and need not call each other directly; call these modules
12695 @dfn{overlays}. Separate the overlays from the main program, and place
12696 their machine code in the larger memory. Place your main program in
12697 instruction memory, but leave at least enough space there to hold the
12698 largest overlay as well.
12699
12700 Now, to call a function located in an overlay, you must first copy that
12701 overlay's machine code from the large memory into the space set aside
12702 for it in the instruction memory, and then jump to its entry point
12703 there.
12704
12705 @c NB: In the below the mapped area's size is greater or equal to the
12706 @c size of all overlays. This is intentional to remind the developer
12707 @c that overlays don't necessarily need to be the same size.
12708
12709 @smallexample
12710 @group
12711 Data Instruction Larger
12712 Address Space Address Space Address Space
12713 +-----------+ +-----------+ +-----------+
12714 | | | | | |
12715 +-----------+ +-----------+ +-----------+<-- overlay 1
12716 | program | | main | .----| overlay 1 | load address
12717 | variables | | program | | +-----------+
12718 | and heap | | | | | |
12719 +-----------+ | | | +-----------+<-- overlay 2
12720 | | +-----------+ | | | load address
12721 +-----------+ | | | .-| overlay 2 |
12722 | | | | | |
12723 mapped --->+-----------+ | | +-----------+
12724 address | | | | | |
12725 | overlay | <-' | | |
12726 | area | <---' +-----------+<-- overlay 3
12727 | | <---. | | load address
12728 +-----------+ `--| overlay 3 |
12729 | | | |
12730 +-----------+ | |
12731 +-----------+
12732 | |
12733 +-----------+
12734
12735 @anchor{A code overlay}A code overlay
12736 @end group
12737 @end smallexample
12738
12739 The diagram (@pxref{A code overlay}) shows a system with separate data
12740 and instruction address spaces. To map an overlay, the program copies
12741 its code from the larger address space to the instruction address space.
12742 Since the overlays shown here all use the same mapped address, only one
12743 may be mapped at a time. For a system with a single address space for
12744 data and instructions, the diagram would be similar, except that the
12745 program variables and heap would share an address space with the main
12746 program and the overlay area.
12747
12748 An overlay loaded into instruction memory and ready for use is called a
12749 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
12750 instruction memory. An overlay not present (or only partially present)
12751 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
12752 is its address in the larger memory. The mapped address is also called
12753 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
12754 called the @dfn{load memory address}, or @dfn{LMA}.
12755
12756 Unfortunately, overlays are not a completely transparent way to adapt a
12757 program to limited instruction memory. They introduce a new set of
12758 global constraints you must keep in mind as you design your program:
12759
12760 @itemize @bullet
12761
12762 @item
12763 Before calling or returning to a function in an overlay, your program
12764 must make sure that overlay is actually mapped. Otherwise, the call or
12765 return will transfer control to the right address, but in the wrong
12766 overlay, and your program will probably crash.
12767
12768 @item
12769 If the process of mapping an overlay is expensive on your system, you
12770 will need to choose your overlays carefully to minimize their effect on
12771 your program's performance.
12772
12773 @item
12774 The executable file you load onto your system must contain each
12775 overlay's instructions, appearing at the overlay's load address, not its
12776 mapped address. However, each overlay's instructions must be relocated
12777 and its symbols defined as if the overlay were at its mapped address.
12778 You can use GNU linker scripts to specify different load and relocation
12779 addresses for pieces of your program; see @ref{Overlay Description,,,
12780 ld.info, Using ld: the GNU linker}.
12781
12782 @item
12783 The procedure for loading executable files onto your system must be able
12784 to load their contents into the larger address space as well as the
12785 instruction and data spaces.
12786
12787 @end itemize
12788
12789 The overlay system described above is rather simple, and could be
12790 improved in many ways:
12791
12792 @itemize @bullet
12793
12794 @item
12795 If your system has suitable bank switch registers or memory management
12796 hardware, you could use those facilities to make an overlay's load area
12797 contents simply appear at their mapped address in instruction space.
12798 This would probably be faster than copying the overlay to its mapped
12799 area in the usual way.
12800
12801 @item
12802 If your overlays are small enough, you could set aside more than one
12803 overlay area, and have more than one overlay mapped at a time.
12804
12805 @item
12806 You can use overlays to manage data, as well as instructions. In
12807 general, data overlays are even less transparent to your design than
12808 code overlays: whereas code overlays only require care when you call or
12809 return to functions, data overlays require care every time you access
12810 the data. Also, if you change the contents of a data overlay, you
12811 must copy its contents back out to its load address before you can copy a
12812 different data overlay into the same mapped area.
12813
12814 @end itemize
12815
12816
12817 @node Overlay Commands
12818 @section Overlay Commands
12819
12820 To use @value{GDBN}'s overlay support, each overlay in your program must
12821 correspond to a separate section of the executable file. The section's
12822 virtual memory address and load memory address must be the overlay's
12823 mapped and load addresses. Identifying overlays with sections allows
12824 @value{GDBN} to determine the appropriate address of a function or
12825 variable, depending on whether the overlay is mapped or not.
12826
12827 @value{GDBN}'s overlay commands all start with the word @code{overlay};
12828 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
12829
12830 @table @code
12831 @item overlay off
12832 @kindex overlay
12833 Disable @value{GDBN}'s overlay support. When overlay support is
12834 disabled, @value{GDBN} assumes that all functions and variables are
12835 always present at their mapped addresses. By default, @value{GDBN}'s
12836 overlay support is disabled.
12837
12838 @item overlay manual
12839 @cindex manual overlay debugging
12840 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
12841 relies on you to tell it which overlays are mapped, and which are not,
12842 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
12843 commands described below.
12844
12845 @item overlay map-overlay @var{overlay}
12846 @itemx overlay map @var{overlay}
12847 @cindex map an overlay
12848 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
12849 be the name of the object file section containing the overlay. When an
12850 overlay is mapped, @value{GDBN} assumes it can find the overlay's
12851 functions and variables at their mapped addresses. @value{GDBN} assumes
12852 that any other overlays whose mapped ranges overlap that of
12853 @var{overlay} are now unmapped.
12854
12855 @item overlay unmap-overlay @var{overlay}
12856 @itemx overlay unmap @var{overlay}
12857 @cindex unmap an overlay
12858 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
12859 must be the name of the object file section containing the overlay.
12860 When an overlay is unmapped, @value{GDBN} assumes it can find the
12861 overlay's functions and variables at their load addresses.
12862
12863 @item overlay auto
12864 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
12865 consults a data structure the overlay manager maintains in the inferior
12866 to see which overlays are mapped. For details, see @ref{Automatic
12867 Overlay Debugging}.
12868
12869 @item overlay load-target
12870 @itemx overlay load
12871 @cindex reloading the overlay table
12872 Re-read the overlay table from the inferior. Normally, @value{GDBN}
12873 re-reads the table @value{GDBN} automatically each time the inferior
12874 stops, so this command should only be necessary if you have changed the
12875 overlay mapping yourself using @value{GDBN}. This command is only
12876 useful when using automatic overlay debugging.
12877
12878 @item overlay list-overlays
12879 @itemx overlay list
12880 @cindex listing mapped overlays
12881 Display a list of the overlays currently mapped, along with their mapped
12882 addresses, load addresses, and sizes.
12883
12884 @end table
12885
12886 Normally, when @value{GDBN} prints a code address, it includes the name
12887 of the function the address falls in:
12888
12889 @smallexample
12890 (@value{GDBP}) print main
12891 $3 = @{int ()@} 0x11a0 <main>
12892 @end smallexample
12893 @noindent
12894 When overlay debugging is enabled, @value{GDBN} recognizes code in
12895 unmapped overlays, and prints the names of unmapped functions with
12896 asterisks around them. For example, if @code{foo} is a function in an
12897 unmapped overlay, @value{GDBN} prints it this way:
12898
12899 @smallexample
12900 (@value{GDBP}) overlay list
12901 No sections are mapped.
12902 (@value{GDBP}) print foo
12903 $5 = @{int (int)@} 0x100000 <*foo*>
12904 @end smallexample
12905 @noindent
12906 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
12907 name normally:
12908
12909 @smallexample
12910 (@value{GDBP}) overlay list
12911 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
12912 mapped at 0x1016 - 0x104a
12913 (@value{GDBP}) print foo
12914 $6 = @{int (int)@} 0x1016 <foo>
12915 @end smallexample
12916
12917 When overlay debugging is enabled, @value{GDBN} can find the correct
12918 address for functions and variables in an overlay, whether or not the
12919 overlay is mapped. This allows most @value{GDBN} commands, like
12920 @code{break} and @code{disassemble}, to work normally, even on unmapped
12921 code. However, @value{GDBN}'s breakpoint support has some limitations:
12922
12923 @itemize @bullet
12924 @item
12925 @cindex breakpoints in overlays
12926 @cindex overlays, setting breakpoints in
12927 You can set breakpoints in functions in unmapped overlays, as long as
12928 @value{GDBN} can write to the overlay at its load address.
12929 @item
12930 @value{GDBN} can not set hardware or simulator-based breakpoints in
12931 unmapped overlays. However, if you set a breakpoint at the end of your
12932 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
12933 you are using manual overlay management), @value{GDBN} will re-set its
12934 breakpoints properly.
12935 @end itemize
12936
12937
12938 @node Automatic Overlay Debugging
12939 @section Automatic Overlay Debugging
12940 @cindex automatic overlay debugging
12941
12942 @value{GDBN} can automatically track which overlays are mapped and which
12943 are not, given some simple co-operation from the overlay manager in the
12944 inferior. If you enable automatic overlay debugging with the
12945 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
12946 looks in the inferior's memory for certain variables describing the
12947 current state of the overlays.
12948
12949 Here are the variables your overlay manager must define to support
12950 @value{GDBN}'s automatic overlay debugging:
12951
12952 @table @asis
12953
12954 @item @code{_ovly_table}:
12955 This variable must be an array of the following structures:
12956
12957 @smallexample
12958 struct
12959 @{
12960 /* The overlay's mapped address. */
12961 unsigned long vma;
12962
12963 /* The size of the overlay, in bytes. */
12964 unsigned long size;
12965
12966 /* The overlay's load address. */
12967 unsigned long lma;
12968
12969 /* Non-zero if the overlay is currently mapped;
12970 zero otherwise. */
12971 unsigned long mapped;
12972 @}
12973 @end smallexample
12974
12975 @item @code{_novlys}:
12976 This variable must be a four-byte signed integer, holding the total
12977 number of elements in @code{_ovly_table}.
12978
12979 @end table
12980
12981 To decide whether a particular overlay is mapped or not, @value{GDBN}
12982 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
12983 @code{lma} members equal the VMA and LMA of the overlay's section in the
12984 executable file. When @value{GDBN} finds a matching entry, it consults
12985 the entry's @code{mapped} member to determine whether the overlay is
12986 currently mapped.
12987
12988 In addition, your overlay manager may define a function called
12989 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
12990 will silently set a breakpoint there. If the overlay manager then
12991 calls this function whenever it has changed the overlay table, this
12992 will enable @value{GDBN} to accurately keep track of which overlays
12993 are in program memory, and update any breakpoints that may be set
12994 in overlays. This will allow breakpoints to work even if the
12995 overlays are kept in ROM or other non-writable memory while they
12996 are not being executed.
12997
12998 @node Overlay Sample Program
12999 @section Overlay Sample Program
13000 @cindex overlay example program
13001
13002 When linking a program which uses overlays, you must place the overlays
13003 at their load addresses, while relocating them to run at their mapped
13004 addresses. To do this, you must write a linker script (@pxref{Overlay
13005 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
13006 since linker scripts are specific to a particular host system, target
13007 architecture, and target memory layout, this manual cannot provide
13008 portable sample code demonstrating @value{GDBN}'s overlay support.
13009
13010 However, the @value{GDBN} source distribution does contain an overlaid
13011 program, with linker scripts for a few systems, as part of its test
13012 suite. The program consists of the following files from
13013 @file{gdb/testsuite/gdb.base}:
13014
13015 @table @file
13016 @item overlays.c
13017 The main program file.
13018 @item ovlymgr.c
13019 A simple overlay manager, used by @file{overlays.c}.
13020 @item foo.c
13021 @itemx bar.c
13022 @itemx baz.c
13023 @itemx grbx.c
13024 Overlay modules, loaded and used by @file{overlays.c}.
13025 @item d10v.ld
13026 @itemx m32r.ld
13027 Linker scripts for linking the test program on the @code{d10v-elf}
13028 and @code{m32r-elf} targets.
13029 @end table
13030
13031 You can build the test program using the @code{d10v-elf} GCC
13032 cross-compiler like this:
13033
13034 @smallexample
13035 $ d10v-elf-gcc -g -c overlays.c
13036 $ d10v-elf-gcc -g -c ovlymgr.c
13037 $ d10v-elf-gcc -g -c foo.c
13038 $ d10v-elf-gcc -g -c bar.c
13039 $ d10v-elf-gcc -g -c baz.c
13040 $ d10v-elf-gcc -g -c grbx.c
13041 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
13042 baz.o grbx.o -Wl,-Td10v.ld -o overlays
13043 @end smallexample
13044
13045 The build process is identical for any other architecture, except that
13046 you must substitute the appropriate compiler and linker script for the
13047 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
13048
13049
13050 @node Languages
13051 @chapter Using @value{GDBN} with Different Languages
13052 @cindex languages
13053
13054 Although programming languages generally have common aspects, they are
13055 rarely expressed in the same manner. For instance, in ANSI C,
13056 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
13057 Modula-2, it is accomplished by @code{p^}. Values can also be
13058 represented (and displayed) differently. Hex numbers in C appear as
13059 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
13060
13061 @cindex working language
13062 Language-specific information is built into @value{GDBN} for some languages,
13063 allowing you to express operations like the above in your program's
13064 native language, and allowing @value{GDBN} to output values in a manner
13065 consistent with the syntax of your program's native language. The
13066 language you use to build expressions is called the @dfn{working
13067 language}.
13068
13069 @menu
13070 * Setting:: Switching between source languages
13071 * Show:: Displaying the language
13072 * Checks:: Type and range checks
13073 * Supported Languages:: Supported languages
13074 * Unsupported Languages:: Unsupported languages
13075 @end menu
13076
13077 @node Setting
13078 @section Switching Between Source Languages
13079
13080 There are two ways to control the working language---either have @value{GDBN}
13081 set it automatically, or select it manually yourself. You can use the
13082 @code{set language} command for either purpose. On startup, @value{GDBN}
13083 defaults to setting the language automatically. The working language is
13084 used to determine how expressions you type are interpreted, how values
13085 are printed, etc.
13086
13087 In addition to the working language, every source file that
13088 @value{GDBN} knows about has its own working language. For some object
13089 file formats, the compiler might indicate which language a particular
13090 source file is in. However, most of the time @value{GDBN} infers the
13091 language from the name of the file. The language of a source file
13092 controls whether C@t{++} names are demangled---this way @code{backtrace} can
13093 show each frame appropriately for its own language. There is no way to
13094 set the language of a source file from within @value{GDBN}, but you can
13095 set the language associated with a filename extension. @xref{Show, ,
13096 Displaying the Language}.
13097
13098 This is most commonly a problem when you use a program, such
13099 as @code{cfront} or @code{f2c}, that generates C but is written in
13100 another language. In that case, make the
13101 program use @code{#line} directives in its C output; that way
13102 @value{GDBN} will know the correct language of the source code of the original
13103 program, and will display that source code, not the generated C code.
13104
13105 @menu
13106 * Filenames:: Filename extensions and languages.
13107 * Manually:: Setting the working language manually
13108 * Automatically:: Having @value{GDBN} infer the source language
13109 @end menu
13110
13111 @node Filenames
13112 @subsection List of Filename Extensions and Languages
13113
13114 If a source file name ends in one of the following extensions, then
13115 @value{GDBN} infers that its language is the one indicated.
13116
13117 @table @file
13118 @item .ada
13119 @itemx .ads
13120 @itemx .adb
13121 @itemx .a
13122 Ada source file.
13123
13124 @item .c
13125 C source file
13126
13127 @item .C
13128 @itemx .cc
13129 @itemx .cp
13130 @itemx .cpp
13131 @itemx .cxx
13132 @itemx .c++
13133 C@t{++} source file
13134
13135 @item .d
13136 D source file
13137
13138 @item .m
13139 Objective-C source file
13140
13141 @item .f
13142 @itemx .F
13143 Fortran source file
13144
13145 @item .mod
13146 Modula-2 source file
13147
13148 @item .s
13149 @itemx .S
13150 Assembler source file. This actually behaves almost like C, but
13151 @value{GDBN} does not skip over function prologues when stepping.
13152 @end table
13153
13154 In addition, you may set the language associated with a filename
13155 extension. @xref{Show, , Displaying the Language}.
13156
13157 @node Manually
13158 @subsection Setting the Working Language
13159
13160 If you allow @value{GDBN} to set the language automatically,
13161 expressions are interpreted the same way in your debugging session and
13162 your program.
13163
13164 @kindex set language
13165 If you wish, you may set the language manually. To do this, issue the
13166 command @samp{set language @var{lang}}, where @var{lang} is the name of
13167 a language, such as
13168 @code{c} or @code{modula-2}.
13169 For a list of the supported languages, type @samp{set language}.
13170
13171 Setting the language manually prevents @value{GDBN} from updating the working
13172 language automatically. This can lead to confusion if you try
13173 to debug a program when the working language is not the same as the
13174 source language, when an expression is acceptable to both
13175 languages---but means different things. For instance, if the current
13176 source file were written in C, and @value{GDBN} was parsing Modula-2, a
13177 command such as:
13178
13179 @smallexample
13180 print a = b + c
13181 @end smallexample
13182
13183 @noindent
13184 might not have the effect you intended. In C, this means to add
13185 @code{b} and @code{c} and place the result in @code{a}. The result
13186 printed would be the value of @code{a}. In Modula-2, this means to compare
13187 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
13188
13189 @node Automatically
13190 @subsection Having @value{GDBN} Infer the Source Language
13191
13192 To have @value{GDBN} set the working language automatically, use
13193 @samp{set language local} or @samp{set language auto}. @value{GDBN}
13194 then infers the working language. That is, when your program stops in a
13195 frame (usually by encountering a breakpoint), @value{GDBN} sets the
13196 working language to the language recorded for the function in that
13197 frame. If the language for a frame is unknown (that is, if the function
13198 or block corresponding to the frame was defined in a source file that
13199 does not have a recognized extension), the current working language is
13200 not changed, and @value{GDBN} issues a warning.
13201
13202 This may not seem necessary for most programs, which are written
13203 entirely in one source language. However, program modules and libraries
13204 written in one source language can be used by a main program written in
13205 a different source language. Using @samp{set language auto} in this
13206 case frees you from having to set the working language manually.
13207
13208 @node Show
13209 @section Displaying the Language
13210
13211 The following commands help you find out which language is the
13212 working language, and also what language source files were written in.
13213
13214 @table @code
13215 @item show language
13216 @kindex show language
13217 Display the current working language. This is the
13218 language you can use with commands such as @code{print} to
13219 build and compute expressions that may involve variables in your program.
13220
13221 @item info frame
13222 @kindex info frame@r{, show the source language}
13223 Display the source language for this frame. This language becomes the
13224 working language if you use an identifier from this frame.
13225 @xref{Frame Info, ,Information about a Frame}, to identify the other
13226 information listed here.
13227
13228 @item info source
13229 @kindex info source@r{, show the source language}
13230 Display the source language of this source file.
13231 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
13232 information listed here.
13233 @end table
13234
13235 In unusual circumstances, you may have source files with extensions
13236 not in the standard list. You can then set the extension associated
13237 with a language explicitly:
13238
13239 @table @code
13240 @item set extension-language @var{ext} @var{language}
13241 @kindex set extension-language
13242 Tell @value{GDBN} that source files with extension @var{ext} are to be
13243 assumed as written in the source language @var{language}.
13244
13245 @item info extensions
13246 @kindex info extensions
13247 List all the filename extensions and the associated languages.
13248 @end table
13249
13250 @node Checks
13251 @section Type and Range Checking
13252
13253 Some languages are designed to guard you against making seemingly common
13254 errors through a series of compile- and run-time checks. These include
13255 checking the type of arguments to functions and operators and making
13256 sure mathematical overflows are caught at run time. Checks such as
13257 these help to ensure a program's correctness once it has been compiled
13258 by eliminating type mismatches and providing active checks for range
13259 errors when your program is running.
13260
13261 By default @value{GDBN} checks for these errors according to the
13262 rules of the current source language. Although @value{GDBN} does not check
13263 the statements in your program, it can check expressions entered directly
13264 into @value{GDBN} for evaluation via the @code{print} command, for example.
13265
13266 @menu
13267 * Type Checking:: An overview of type checking
13268 * Range Checking:: An overview of range checking
13269 @end menu
13270
13271 @cindex type checking
13272 @cindex checks, type
13273 @node Type Checking
13274 @subsection An Overview of Type Checking
13275
13276 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
13277 arguments to operators and functions have to be of the correct type,
13278 otherwise an error occurs. These checks prevent type mismatch
13279 errors from ever causing any run-time problems. For example,
13280
13281 @smallexample
13282 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
13283
13284 (@value{GDBP}) print obj.my_method (0)
13285 $1 = 2
13286 @exdent but
13287 (@value{GDBP}) print obj.my_method (0x1234)
13288 Cannot resolve method klass::my_method to any overloaded instance
13289 @end smallexample
13290
13291 The second example fails because in C@t{++} the integer constant
13292 @samp{0x1234} is not type-compatible with the pointer parameter type.
13293
13294 For the expressions you use in @value{GDBN} commands, you can tell
13295 @value{GDBN} to not enforce strict type checking or
13296 to treat any mismatches as errors and abandon the expression;
13297 When type checking is disabled, @value{GDBN} successfully evaluates
13298 expressions like the second example above.
13299
13300 Even if type checking is off, there may be other reasons
13301 related to type that prevent @value{GDBN} from evaluating an expression.
13302 For instance, @value{GDBN} does not know how to add an @code{int} and
13303 a @code{struct foo}. These particular type errors have nothing to do
13304 with the language in use and usually arise from expressions which make
13305 little sense to evaluate anyway.
13306
13307 @value{GDBN} provides some additional commands for controlling type checking:
13308
13309 @kindex set check type
13310 @kindex show check type
13311 @table @code
13312 @item set check type on
13313 @itemx set check type off
13314 Set strict type checking on or off. If any type mismatches occur in
13315 evaluating an expression while type checking is on, @value{GDBN} prints a
13316 message and aborts evaluation of the expression.
13317
13318 @item show check type
13319 Show the current setting of type checking and whether @value{GDBN}
13320 is enforcing strict type checking rules.
13321 @end table
13322
13323 @cindex range checking
13324 @cindex checks, range
13325 @node Range Checking
13326 @subsection An Overview of Range Checking
13327
13328 In some languages (such as Modula-2), it is an error to exceed the
13329 bounds of a type; this is enforced with run-time checks. Such range
13330 checking is meant to ensure program correctness by making sure
13331 computations do not overflow, or indices on an array element access do
13332 not exceed the bounds of the array.
13333
13334 For expressions you use in @value{GDBN} commands, you can tell
13335 @value{GDBN} to treat range errors in one of three ways: ignore them,
13336 always treat them as errors and abandon the expression, or issue
13337 warnings but evaluate the expression anyway.
13338
13339 A range error can result from numerical overflow, from exceeding an
13340 array index bound, or when you type a constant that is not a member
13341 of any type. Some languages, however, do not treat overflows as an
13342 error. In many implementations of C, mathematical overflow causes the
13343 result to ``wrap around'' to lower values---for example, if @var{m} is
13344 the largest integer value, and @var{s} is the smallest, then
13345
13346 @smallexample
13347 @var{m} + 1 @result{} @var{s}
13348 @end smallexample
13349
13350 This, too, is specific to individual languages, and in some cases
13351 specific to individual compilers or machines. @xref{Supported Languages, ,
13352 Supported Languages}, for further details on specific languages.
13353
13354 @value{GDBN} provides some additional commands for controlling the range checker:
13355
13356 @kindex set check range
13357 @kindex show check range
13358 @table @code
13359 @item set check range auto
13360 Set range checking on or off based on the current working language.
13361 @xref{Supported Languages, ,Supported Languages}, for the default settings for
13362 each language.
13363
13364 @item set check range on
13365 @itemx set check range off
13366 Set range checking on or off, overriding the default setting for the
13367 current working language. A warning is issued if the setting does not
13368 match the language default. If a range error occurs and range checking is on,
13369 then a message is printed and evaluation of the expression is aborted.
13370
13371 @item set check range warn
13372 Output messages when the @value{GDBN} range checker detects a range error,
13373 but attempt to evaluate the expression anyway. Evaluating the
13374 expression may still be impossible for other reasons, such as accessing
13375 memory that the process does not own (a typical example from many Unix
13376 systems).
13377
13378 @item show range
13379 Show the current setting of the range checker, and whether or not it is
13380 being set automatically by @value{GDBN}.
13381 @end table
13382
13383 @node Supported Languages
13384 @section Supported Languages
13385
13386 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran, Java,
13387 OpenCL C, Pascal, assembly, Modula-2, and Ada.
13388 @c This is false ...
13389 Some @value{GDBN} features may be used in expressions regardless of the
13390 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
13391 and the @samp{@{type@}addr} construct (@pxref{Expressions,
13392 ,Expressions}) can be used with the constructs of any supported
13393 language.
13394
13395 The following sections detail to what degree each source language is
13396 supported by @value{GDBN}. These sections are not meant to be language
13397 tutorials or references, but serve only as a reference guide to what the
13398 @value{GDBN} expression parser accepts, and what input and output
13399 formats should look like for different languages. There are many good
13400 books written on each of these languages; please look to these for a
13401 language reference or tutorial.
13402
13403 @menu
13404 * C:: C and C@t{++}
13405 * D:: D
13406 * Go:: Go
13407 * Objective-C:: Objective-C
13408 * OpenCL C:: OpenCL C
13409 * Fortran:: Fortran
13410 * Pascal:: Pascal
13411 * Modula-2:: Modula-2
13412 * Ada:: Ada
13413 @end menu
13414
13415 @node C
13416 @subsection C and C@t{++}
13417
13418 @cindex C and C@t{++}
13419 @cindex expressions in C or C@t{++}
13420
13421 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
13422 to both languages. Whenever this is the case, we discuss those languages
13423 together.
13424
13425 @cindex C@t{++}
13426 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
13427 @cindex @sc{gnu} C@t{++}
13428 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
13429 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
13430 effectively, you must compile your C@t{++} programs with a supported
13431 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
13432 compiler (@code{aCC}).
13433
13434 @menu
13435 * C Operators:: C and C@t{++} operators
13436 * C Constants:: C and C@t{++} constants
13437 * C Plus Plus Expressions:: C@t{++} expressions
13438 * C Defaults:: Default settings for C and C@t{++}
13439 * C Checks:: C and C@t{++} type and range checks
13440 * Debugging C:: @value{GDBN} and C
13441 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
13442 * Decimal Floating Point:: Numbers in Decimal Floating Point format
13443 @end menu
13444
13445 @node C Operators
13446 @subsubsection C and C@t{++} Operators
13447
13448 @cindex C and C@t{++} operators
13449
13450 Operators must be defined on values of specific types. For instance,
13451 @code{+} is defined on numbers, but not on structures. Operators are
13452 often defined on groups of types.
13453
13454 For the purposes of C and C@t{++}, the following definitions hold:
13455
13456 @itemize @bullet
13457
13458 @item
13459 @emph{Integral types} include @code{int} with any of its storage-class
13460 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
13461
13462 @item
13463 @emph{Floating-point types} include @code{float}, @code{double}, and
13464 @code{long double} (if supported by the target platform).
13465
13466 @item
13467 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
13468
13469 @item
13470 @emph{Scalar types} include all of the above.
13471
13472 @end itemize
13473
13474 @noindent
13475 The following operators are supported. They are listed here
13476 in order of increasing precedence:
13477
13478 @table @code
13479 @item ,
13480 The comma or sequencing operator. Expressions in a comma-separated list
13481 are evaluated from left to right, with the result of the entire
13482 expression being the last expression evaluated.
13483
13484 @item =
13485 Assignment. The value of an assignment expression is the value
13486 assigned. Defined on scalar types.
13487
13488 @item @var{op}=
13489 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
13490 and translated to @w{@code{@var{a} = @var{a op b}}}.
13491 @w{@code{@var{op}=}} and @code{=} have the same precedence.
13492 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
13493 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
13494
13495 @item ?:
13496 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
13497 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
13498 integral type.
13499
13500 @item ||
13501 Logical @sc{or}. Defined on integral types.
13502
13503 @item &&
13504 Logical @sc{and}. Defined on integral types.
13505
13506 @item |
13507 Bitwise @sc{or}. Defined on integral types.
13508
13509 @item ^
13510 Bitwise exclusive-@sc{or}. Defined on integral types.
13511
13512 @item &
13513 Bitwise @sc{and}. Defined on integral types.
13514
13515 @item ==@r{, }!=
13516 Equality and inequality. Defined on scalar types. The value of these
13517 expressions is 0 for false and non-zero for true.
13518
13519 @item <@r{, }>@r{, }<=@r{, }>=
13520 Less than, greater than, less than or equal, greater than or equal.
13521 Defined on scalar types. The value of these expressions is 0 for false
13522 and non-zero for true.
13523
13524 @item <<@r{, }>>
13525 left shift, and right shift. Defined on integral types.
13526
13527 @item @@
13528 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
13529
13530 @item +@r{, }-
13531 Addition and subtraction. Defined on integral types, floating-point types and
13532 pointer types.
13533
13534 @item *@r{, }/@r{, }%
13535 Multiplication, division, and modulus. Multiplication and division are
13536 defined on integral and floating-point types. Modulus is defined on
13537 integral types.
13538
13539 @item ++@r{, }--
13540 Increment and decrement. When appearing before a variable, the
13541 operation is performed before the variable is used in an expression;
13542 when appearing after it, the variable's value is used before the
13543 operation takes place.
13544
13545 @item *
13546 Pointer dereferencing. Defined on pointer types. Same precedence as
13547 @code{++}.
13548
13549 @item &
13550 Address operator. Defined on variables. Same precedence as @code{++}.
13551
13552 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
13553 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
13554 to examine the address
13555 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
13556 stored.
13557
13558 @item -
13559 Negative. Defined on integral and floating-point types. Same
13560 precedence as @code{++}.
13561
13562 @item !
13563 Logical negation. Defined on integral types. Same precedence as
13564 @code{++}.
13565
13566 @item ~
13567 Bitwise complement operator. Defined on integral types. Same precedence as
13568 @code{++}.
13569
13570
13571 @item .@r{, }->
13572 Structure member, and pointer-to-structure member. For convenience,
13573 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
13574 pointer based on the stored type information.
13575 Defined on @code{struct} and @code{union} data.
13576
13577 @item .*@r{, }->*
13578 Dereferences of pointers to members.
13579
13580 @item []
13581 Array indexing. @code{@var{a}[@var{i}]} is defined as
13582 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
13583
13584 @item ()
13585 Function parameter list. Same precedence as @code{->}.
13586
13587 @item ::
13588 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
13589 and @code{class} types.
13590
13591 @item ::
13592 Doubled colons also represent the @value{GDBN} scope operator
13593 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
13594 above.
13595 @end table
13596
13597 If an operator is redefined in the user code, @value{GDBN} usually
13598 attempts to invoke the redefined version instead of using the operator's
13599 predefined meaning.
13600
13601 @node C Constants
13602 @subsubsection C and C@t{++} Constants
13603
13604 @cindex C and C@t{++} constants
13605
13606 @value{GDBN} allows you to express the constants of C and C@t{++} in the
13607 following ways:
13608
13609 @itemize @bullet
13610 @item
13611 Integer constants are a sequence of digits. Octal constants are
13612 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
13613 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
13614 @samp{l}, specifying that the constant should be treated as a
13615 @code{long} value.
13616
13617 @item
13618 Floating point constants are a sequence of digits, followed by a decimal
13619 point, followed by a sequence of digits, and optionally followed by an
13620 exponent. An exponent is of the form:
13621 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
13622 sequence of digits. The @samp{+} is optional for positive exponents.
13623 A floating-point constant may also end with a letter @samp{f} or
13624 @samp{F}, specifying that the constant should be treated as being of
13625 the @code{float} (as opposed to the default @code{double}) type; or with
13626 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
13627 constant.
13628
13629 @item
13630 Enumerated constants consist of enumerated identifiers, or their
13631 integral equivalents.
13632
13633 @item
13634 Character constants are a single character surrounded by single quotes
13635 (@code{'}), or a number---the ordinal value of the corresponding character
13636 (usually its @sc{ascii} value). Within quotes, the single character may
13637 be represented by a letter or by @dfn{escape sequences}, which are of
13638 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
13639 of the character's ordinal value; or of the form @samp{\@var{x}}, where
13640 @samp{@var{x}} is a predefined special character---for example,
13641 @samp{\n} for newline.
13642
13643 Wide character constants can be written by prefixing a character
13644 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
13645 form of @samp{x}. The target wide character set is used when
13646 computing the value of this constant (@pxref{Character Sets}).
13647
13648 @item
13649 String constants are a sequence of character constants surrounded by
13650 double quotes (@code{"}). Any valid character constant (as described
13651 above) may appear. Double quotes within the string must be preceded by
13652 a backslash, so for instance @samp{"a\"b'c"} is a string of five
13653 characters.
13654
13655 Wide string constants can be written by prefixing a string constant
13656 with @samp{L}, as in C. The target wide character set is used when
13657 computing the value of this constant (@pxref{Character Sets}).
13658
13659 @item
13660 Pointer constants are an integral value. You can also write pointers
13661 to constants using the C operator @samp{&}.
13662
13663 @item
13664 Array constants are comma-separated lists surrounded by braces @samp{@{}
13665 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
13666 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
13667 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
13668 @end itemize
13669
13670 @node C Plus Plus Expressions
13671 @subsubsection C@t{++} Expressions
13672
13673 @cindex expressions in C@t{++}
13674 @value{GDBN} expression handling can interpret most C@t{++} expressions.
13675
13676 @cindex debugging C@t{++} programs
13677 @cindex C@t{++} compilers
13678 @cindex debug formats and C@t{++}
13679 @cindex @value{NGCC} and C@t{++}
13680 @quotation
13681 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
13682 the proper compiler and the proper debug format. Currently,
13683 @value{GDBN} works best when debugging C@t{++} code that is compiled
13684 with the most recent version of @value{NGCC} possible. The DWARF
13685 debugging format is preferred; @value{NGCC} defaults to this on most
13686 popular platforms. Other compilers and/or debug formats are likely to
13687 work badly or not at all when using @value{GDBN} to debug C@t{++}
13688 code. @xref{Compilation}.
13689 @end quotation
13690
13691 @enumerate
13692
13693 @cindex member functions
13694 @item
13695 Member function calls are allowed; you can use expressions like
13696
13697 @smallexample
13698 count = aml->GetOriginal(x, y)
13699 @end smallexample
13700
13701 @vindex this@r{, inside C@t{++} member functions}
13702 @cindex namespace in C@t{++}
13703 @item
13704 While a member function is active (in the selected stack frame), your
13705 expressions have the same namespace available as the member function;
13706 that is, @value{GDBN} allows implicit references to the class instance
13707 pointer @code{this} following the same rules as C@t{++}. @code{using}
13708 declarations in the current scope are also respected by @value{GDBN}.
13709
13710 @cindex call overloaded functions
13711 @cindex overloaded functions, calling
13712 @cindex type conversions in C@t{++}
13713 @item
13714 You can call overloaded functions; @value{GDBN} resolves the function
13715 call to the right definition, with some restrictions. @value{GDBN} does not
13716 perform overload resolution involving user-defined type conversions,
13717 calls to constructors, or instantiations of templates that do not exist
13718 in the program. It also cannot handle ellipsis argument lists or
13719 default arguments.
13720
13721 It does perform integral conversions and promotions, floating-point
13722 promotions, arithmetic conversions, pointer conversions, conversions of
13723 class objects to base classes, and standard conversions such as those of
13724 functions or arrays to pointers; it requires an exact match on the
13725 number of function arguments.
13726
13727 Overload resolution is always performed, unless you have specified
13728 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
13729 ,@value{GDBN} Features for C@t{++}}.
13730
13731 You must specify @code{set overload-resolution off} in order to use an
13732 explicit function signature to call an overloaded function, as in
13733 @smallexample
13734 p 'foo(char,int)'('x', 13)
13735 @end smallexample
13736
13737 The @value{GDBN} command-completion facility can simplify this;
13738 see @ref{Completion, ,Command Completion}.
13739
13740 @cindex reference declarations
13741 @item
13742 @value{GDBN} understands variables declared as C@t{++} references; you can use
13743 them in expressions just as you do in C@t{++} source---they are automatically
13744 dereferenced.
13745
13746 In the parameter list shown when @value{GDBN} displays a frame, the values of
13747 reference variables are not displayed (unlike other variables); this
13748 avoids clutter, since references are often used for large structures.
13749 The @emph{address} of a reference variable is always shown, unless
13750 you have specified @samp{set print address off}.
13751
13752 @item
13753 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
13754 expressions can use it just as expressions in your program do. Since
13755 one scope may be defined in another, you can use @code{::} repeatedly if
13756 necessary, for example in an expression like
13757 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
13758 resolving name scope by reference to source files, in both C and C@t{++}
13759 debugging (@pxref{Variables, ,Program Variables}).
13760
13761 @item
13762 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
13763 specification.
13764 @end enumerate
13765
13766 @node C Defaults
13767 @subsubsection C and C@t{++} Defaults
13768
13769 @cindex C and C@t{++} defaults
13770
13771 If you allow @value{GDBN} to set range checking automatically, it
13772 defaults to @code{off} whenever the working language changes to
13773 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
13774 selects the working language.
13775
13776 If you allow @value{GDBN} to set the language automatically, it
13777 recognizes source files whose names end with @file{.c}, @file{.C}, or
13778 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
13779 these files, it sets the working language to C or C@t{++}.
13780 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
13781 for further details.
13782
13783 @node C Checks
13784 @subsubsection C and C@t{++} Type and Range Checks
13785
13786 @cindex C and C@t{++} checks
13787
13788 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
13789 checking is used. However, if you turn type checking off, @value{GDBN}
13790 will allow certain non-standard conversions, such as promoting integer
13791 constants to pointers.
13792
13793 Range checking, if turned on, is done on mathematical operations. Array
13794 indices are not checked, since they are often used to index a pointer
13795 that is not itself an array.
13796
13797 @node Debugging C
13798 @subsubsection @value{GDBN} and C
13799
13800 The @code{set print union} and @code{show print union} commands apply to
13801 the @code{union} type. When set to @samp{on}, any @code{union} that is
13802 inside a @code{struct} or @code{class} is also printed. Otherwise, it
13803 appears as @samp{@{...@}}.
13804
13805 The @code{@@} operator aids in the debugging of dynamic arrays, formed
13806 with pointers and a memory allocation function. @xref{Expressions,
13807 ,Expressions}.
13808
13809 @node Debugging C Plus Plus
13810 @subsubsection @value{GDBN} Features for C@t{++}
13811
13812 @cindex commands for C@t{++}
13813
13814 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
13815 designed specifically for use with C@t{++}. Here is a summary:
13816
13817 @table @code
13818 @cindex break in overloaded functions
13819 @item @r{breakpoint menus}
13820 When you want a breakpoint in a function whose name is overloaded,
13821 @value{GDBN} has the capability to display a menu of possible breakpoint
13822 locations to help you specify which function definition you want.
13823 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
13824
13825 @cindex overloading in C@t{++}
13826 @item rbreak @var{regex}
13827 Setting breakpoints using regular expressions is helpful for setting
13828 breakpoints on overloaded functions that are not members of any special
13829 classes.
13830 @xref{Set Breaks, ,Setting Breakpoints}.
13831
13832 @cindex C@t{++} exception handling
13833 @item catch throw
13834 @itemx catch rethrow
13835 @itemx catch catch
13836 Debug C@t{++} exception handling using these commands. @xref{Set
13837 Catchpoints, , Setting Catchpoints}.
13838
13839 @cindex inheritance
13840 @item ptype @var{typename}
13841 Print inheritance relationships as well as other information for type
13842 @var{typename}.
13843 @xref{Symbols, ,Examining the Symbol Table}.
13844
13845 @item info vtbl @var{expression}.
13846 The @code{info vtbl} command can be used to display the virtual
13847 method tables of the object computed by @var{expression}. This shows
13848 one entry per virtual table; there may be multiple virtual tables when
13849 multiple inheritance is in use.
13850
13851 @cindex C@t{++} symbol display
13852 @item set print demangle
13853 @itemx show print demangle
13854 @itemx set print asm-demangle
13855 @itemx show print asm-demangle
13856 Control whether C@t{++} symbols display in their source form, both when
13857 displaying code as C@t{++} source and when displaying disassemblies.
13858 @xref{Print Settings, ,Print Settings}.
13859
13860 @item set print object
13861 @itemx show print object
13862 Choose whether to print derived (actual) or declared types of objects.
13863 @xref{Print Settings, ,Print Settings}.
13864
13865 @item set print vtbl
13866 @itemx show print vtbl
13867 Control the format for printing virtual function tables.
13868 @xref{Print Settings, ,Print Settings}.
13869 (The @code{vtbl} commands do not work on programs compiled with the HP
13870 ANSI C@t{++} compiler (@code{aCC}).)
13871
13872 @kindex set overload-resolution
13873 @cindex overloaded functions, overload resolution
13874 @item set overload-resolution on
13875 Enable overload resolution for C@t{++} expression evaluation. The default
13876 is on. For overloaded functions, @value{GDBN} evaluates the arguments
13877 and searches for a function whose signature matches the argument types,
13878 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
13879 Expressions, ,C@t{++} Expressions}, for details).
13880 If it cannot find a match, it emits a message.
13881
13882 @item set overload-resolution off
13883 Disable overload resolution for C@t{++} expression evaluation. For
13884 overloaded functions that are not class member functions, @value{GDBN}
13885 chooses the first function of the specified name that it finds in the
13886 symbol table, whether or not its arguments are of the correct type. For
13887 overloaded functions that are class member functions, @value{GDBN}
13888 searches for a function whose signature @emph{exactly} matches the
13889 argument types.
13890
13891 @kindex show overload-resolution
13892 @item show overload-resolution
13893 Show the current setting of overload resolution.
13894
13895 @item @r{Overloaded symbol names}
13896 You can specify a particular definition of an overloaded symbol, using
13897 the same notation that is used to declare such symbols in C@t{++}: type
13898 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
13899 also use the @value{GDBN} command-line word completion facilities to list the
13900 available choices, or to finish the type list for you.
13901 @xref{Completion,, Command Completion}, for details on how to do this.
13902 @end table
13903
13904 @node Decimal Floating Point
13905 @subsubsection Decimal Floating Point format
13906 @cindex decimal floating point format
13907
13908 @value{GDBN} can examine, set and perform computations with numbers in
13909 decimal floating point format, which in the C language correspond to the
13910 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
13911 specified by the extension to support decimal floating-point arithmetic.
13912
13913 There are two encodings in use, depending on the architecture: BID (Binary
13914 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
13915 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
13916 configured target.
13917
13918 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
13919 to manipulate decimal floating point numbers, it is not possible to convert
13920 (using a cast, for example) integers wider than 32-bit to decimal float.
13921
13922 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
13923 point computations, error checking in decimal float operations ignores
13924 underflow, overflow and divide by zero exceptions.
13925
13926 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
13927 to inspect @code{_Decimal128} values stored in floating point registers.
13928 See @ref{PowerPC,,PowerPC} for more details.
13929
13930 @node D
13931 @subsection D
13932
13933 @cindex D
13934 @value{GDBN} can be used to debug programs written in D and compiled with
13935 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
13936 specific feature --- dynamic arrays.
13937
13938 @node Go
13939 @subsection Go
13940
13941 @cindex Go (programming language)
13942 @value{GDBN} can be used to debug programs written in Go and compiled with
13943 @file{gccgo} or @file{6g} compilers.
13944
13945 Here is a summary of the Go-specific features and restrictions:
13946
13947 @table @code
13948 @cindex current Go package
13949 @item The current Go package
13950 The name of the current package does not need to be specified when
13951 specifying global variables and functions.
13952
13953 For example, given the program:
13954
13955 @example
13956 package main
13957 var myglob = "Shall we?"
13958 func main () @{
13959 // ...
13960 @}
13961 @end example
13962
13963 When stopped inside @code{main} either of these work:
13964
13965 @example
13966 (gdb) p myglob
13967 (gdb) p main.myglob
13968 @end example
13969
13970 @cindex builtin Go types
13971 @item Builtin Go types
13972 The @code{string} type is recognized by @value{GDBN} and is printed
13973 as a string.
13974
13975 @cindex builtin Go functions
13976 @item Builtin Go functions
13977 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
13978 function and handles it internally.
13979
13980 @cindex restrictions on Go expressions
13981 @item Restrictions on Go expressions
13982 All Go operators are supported except @code{&^}.
13983 The Go @code{_} ``blank identifier'' is not supported.
13984 Automatic dereferencing of pointers is not supported.
13985 @end table
13986
13987 @node Objective-C
13988 @subsection Objective-C
13989
13990 @cindex Objective-C
13991 This section provides information about some commands and command
13992 options that are useful for debugging Objective-C code. See also
13993 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
13994 few more commands specific to Objective-C support.
13995
13996 @menu
13997 * Method Names in Commands::
13998 * The Print Command with Objective-C::
13999 @end menu
14000
14001 @node Method Names in Commands
14002 @subsubsection Method Names in Commands
14003
14004 The following commands have been extended to accept Objective-C method
14005 names as line specifications:
14006
14007 @kindex clear@r{, and Objective-C}
14008 @kindex break@r{, and Objective-C}
14009 @kindex info line@r{, and Objective-C}
14010 @kindex jump@r{, and Objective-C}
14011 @kindex list@r{, and Objective-C}
14012 @itemize
14013 @item @code{clear}
14014 @item @code{break}
14015 @item @code{info line}
14016 @item @code{jump}
14017 @item @code{list}
14018 @end itemize
14019
14020 A fully qualified Objective-C method name is specified as
14021
14022 @smallexample
14023 -[@var{Class} @var{methodName}]
14024 @end smallexample
14025
14026 where the minus sign is used to indicate an instance method and a
14027 plus sign (not shown) is used to indicate a class method. The class
14028 name @var{Class} and method name @var{methodName} are enclosed in
14029 brackets, similar to the way messages are specified in Objective-C
14030 source code. For example, to set a breakpoint at the @code{create}
14031 instance method of class @code{Fruit} in the program currently being
14032 debugged, enter:
14033
14034 @smallexample
14035 break -[Fruit create]
14036 @end smallexample
14037
14038 To list ten program lines around the @code{initialize} class method,
14039 enter:
14040
14041 @smallexample
14042 list +[NSText initialize]
14043 @end smallexample
14044
14045 In the current version of @value{GDBN}, the plus or minus sign is
14046 required. In future versions of @value{GDBN}, the plus or minus
14047 sign will be optional, but you can use it to narrow the search. It
14048 is also possible to specify just a method name:
14049
14050 @smallexample
14051 break create
14052 @end smallexample
14053
14054 You must specify the complete method name, including any colons. If
14055 your program's source files contain more than one @code{create} method,
14056 you'll be presented with a numbered list of classes that implement that
14057 method. Indicate your choice by number, or type @samp{0} to exit if
14058 none apply.
14059
14060 As another example, to clear a breakpoint established at the
14061 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
14062
14063 @smallexample
14064 clear -[NSWindow makeKeyAndOrderFront:]
14065 @end smallexample
14066
14067 @node The Print Command with Objective-C
14068 @subsubsection The Print Command With Objective-C
14069 @cindex Objective-C, print objects
14070 @kindex print-object
14071 @kindex po @r{(@code{print-object})}
14072
14073 The print command has also been extended to accept methods. For example:
14074
14075 @smallexample
14076 print -[@var{object} hash]
14077 @end smallexample
14078
14079 @cindex print an Objective-C object description
14080 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
14081 @noindent
14082 will tell @value{GDBN} to send the @code{hash} message to @var{object}
14083 and print the result. Also, an additional command has been added,
14084 @code{print-object} or @code{po} for short, which is meant to print
14085 the description of an object. However, this command may only work
14086 with certain Objective-C libraries that have a particular hook
14087 function, @code{_NSPrintForDebugger}, defined.
14088
14089 @node OpenCL C
14090 @subsection OpenCL C
14091
14092 @cindex OpenCL C
14093 This section provides information about @value{GDBN}s OpenCL C support.
14094
14095 @menu
14096 * OpenCL C Datatypes::
14097 * OpenCL C Expressions::
14098 * OpenCL C Operators::
14099 @end menu
14100
14101 @node OpenCL C Datatypes
14102 @subsubsection OpenCL C Datatypes
14103
14104 @cindex OpenCL C Datatypes
14105 @value{GDBN} supports the builtin scalar and vector datatypes specified
14106 by OpenCL 1.1. In addition the half- and double-precision floating point
14107 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
14108 extensions are also known to @value{GDBN}.
14109
14110 @node OpenCL C Expressions
14111 @subsubsection OpenCL C Expressions
14112
14113 @cindex OpenCL C Expressions
14114 @value{GDBN} supports accesses to vector components including the access as
14115 lvalue where possible. Since OpenCL C is based on C99 most C expressions
14116 supported by @value{GDBN} can be used as well.
14117
14118 @node OpenCL C Operators
14119 @subsubsection OpenCL C Operators
14120
14121 @cindex OpenCL C Operators
14122 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
14123 vector data types.
14124
14125 @node Fortran
14126 @subsection Fortran
14127 @cindex Fortran-specific support in @value{GDBN}
14128
14129 @value{GDBN} can be used to debug programs written in Fortran, but it
14130 currently supports only the features of Fortran 77 language.
14131
14132 @cindex trailing underscore, in Fortran symbols
14133 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
14134 among them) append an underscore to the names of variables and
14135 functions. When you debug programs compiled by those compilers, you
14136 will need to refer to variables and functions with a trailing
14137 underscore.
14138
14139 @menu
14140 * Fortran Operators:: Fortran operators and expressions
14141 * Fortran Defaults:: Default settings for Fortran
14142 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
14143 @end menu
14144
14145 @node Fortran Operators
14146 @subsubsection Fortran Operators and Expressions
14147
14148 @cindex Fortran operators and expressions
14149
14150 Operators must be defined on values of specific types. For instance,
14151 @code{+} is defined on numbers, but not on characters or other non-
14152 arithmetic types. Operators are often defined on groups of types.
14153
14154 @table @code
14155 @item **
14156 The exponentiation operator. It raises the first operand to the power
14157 of the second one.
14158
14159 @item :
14160 The range operator. Normally used in the form of array(low:high) to
14161 represent a section of array.
14162
14163 @item %
14164 The access component operator. Normally used to access elements in derived
14165 types. Also suitable for unions. As unions aren't part of regular Fortran,
14166 this can only happen when accessing a register that uses a gdbarch-defined
14167 union type.
14168 @end table
14169
14170 @node Fortran Defaults
14171 @subsubsection Fortran Defaults
14172
14173 @cindex Fortran Defaults
14174
14175 Fortran symbols are usually case-insensitive, so @value{GDBN} by
14176 default uses case-insensitive matches for Fortran symbols. You can
14177 change that with the @samp{set case-insensitive} command, see
14178 @ref{Symbols}, for the details.
14179
14180 @node Special Fortran Commands
14181 @subsubsection Special Fortran Commands
14182
14183 @cindex Special Fortran commands
14184
14185 @value{GDBN} has some commands to support Fortran-specific features,
14186 such as displaying common blocks.
14187
14188 @table @code
14189 @cindex @code{COMMON} blocks, Fortran
14190 @kindex info common
14191 @item info common @r{[}@var{common-name}@r{]}
14192 This command prints the values contained in the Fortran @code{COMMON}
14193 block whose name is @var{common-name}. With no argument, the names of
14194 all @code{COMMON} blocks visible at the current program location are
14195 printed.
14196 @end table
14197
14198 @node Pascal
14199 @subsection Pascal
14200
14201 @cindex Pascal support in @value{GDBN}, limitations
14202 Debugging Pascal programs which use sets, subranges, file variables, or
14203 nested functions does not currently work. @value{GDBN} does not support
14204 entering expressions, printing values, or similar features using Pascal
14205 syntax.
14206
14207 The Pascal-specific command @code{set print pascal_static-members}
14208 controls whether static members of Pascal objects are displayed.
14209 @xref{Print Settings, pascal_static-members}.
14210
14211 @node Modula-2
14212 @subsection Modula-2
14213
14214 @cindex Modula-2, @value{GDBN} support
14215
14216 The extensions made to @value{GDBN} to support Modula-2 only support
14217 output from the @sc{gnu} Modula-2 compiler (which is currently being
14218 developed). Other Modula-2 compilers are not currently supported, and
14219 attempting to debug executables produced by them is most likely
14220 to give an error as @value{GDBN} reads in the executable's symbol
14221 table.
14222
14223 @cindex expressions in Modula-2
14224 @menu
14225 * M2 Operators:: Built-in operators
14226 * Built-In Func/Proc:: Built-in functions and procedures
14227 * M2 Constants:: Modula-2 constants
14228 * M2 Types:: Modula-2 types
14229 * M2 Defaults:: Default settings for Modula-2
14230 * Deviations:: Deviations from standard Modula-2
14231 * M2 Checks:: Modula-2 type and range checks
14232 * M2 Scope:: The scope operators @code{::} and @code{.}
14233 * GDB/M2:: @value{GDBN} and Modula-2
14234 @end menu
14235
14236 @node M2 Operators
14237 @subsubsection Operators
14238 @cindex Modula-2 operators
14239
14240 Operators must be defined on values of specific types. For instance,
14241 @code{+} is defined on numbers, but not on structures. Operators are
14242 often defined on groups of types. For the purposes of Modula-2, the
14243 following definitions hold:
14244
14245 @itemize @bullet
14246
14247 @item
14248 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
14249 their subranges.
14250
14251 @item
14252 @emph{Character types} consist of @code{CHAR} and its subranges.
14253
14254 @item
14255 @emph{Floating-point types} consist of @code{REAL}.
14256
14257 @item
14258 @emph{Pointer types} consist of anything declared as @code{POINTER TO
14259 @var{type}}.
14260
14261 @item
14262 @emph{Scalar types} consist of all of the above.
14263
14264 @item
14265 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
14266
14267 @item
14268 @emph{Boolean types} consist of @code{BOOLEAN}.
14269 @end itemize
14270
14271 @noindent
14272 The following operators are supported, and appear in order of
14273 increasing precedence:
14274
14275 @table @code
14276 @item ,
14277 Function argument or array index separator.
14278
14279 @item :=
14280 Assignment. The value of @var{var} @code{:=} @var{value} is
14281 @var{value}.
14282
14283 @item <@r{, }>
14284 Less than, greater than on integral, floating-point, or enumerated
14285 types.
14286
14287 @item <=@r{, }>=
14288 Less than or equal to, greater than or equal to
14289 on integral, floating-point and enumerated types, or set inclusion on
14290 set types. Same precedence as @code{<}.
14291
14292 @item =@r{, }<>@r{, }#
14293 Equality and two ways of expressing inequality, valid on scalar types.
14294 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
14295 available for inequality, since @code{#} conflicts with the script
14296 comment character.
14297
14298 @item IN
14299 Set membership. Defined on set types and the types of their members.
14300 Same precedence as @code{<}.
14301
14302 @item OR
14303 Boolean disjunction. Defined on boolean types.
14304
14305 @item AND@r{, }&
14306 Boolean conjunction. Defined on boolean types.
14307
14308 @item @@
14309 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
14310
14311 @item +@r{, }-
14312 Addition and subtraction on integral and floating-point types, or union
14313 and difference on set types.
14314
14315 @item *
14316 Multiplication on integral and floating-point types, or set intersection
14317 on set types.
14318
14319 @item /
14320 Division on floating-point types, or symmetric set difference on set
14321 types. Same precedence as @code{*}.
14322
14323 @item DIV@r{, }MOD
14324 Integer division and remainder. Defined on integral types. Same
14325 precedence as @code{*}.
14326
14327 @item -
14328 Negative. Defined on @code{INTEGER} and @code{REAL} data.
14329
14330 @item ^
14331 Pointer dereferencing. Defined on pointer types.
14332
14333 @item NOT
14334 Boolean negation. Defined on boolean types. Same precedence as
14335 @code{^}.
14336
14337 @item .
14338 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
14339 precedence as @code{^}.
14340
14341 @item []
14342 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
14343
14344 @item ()
14345 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
14346 as @code{^}.
14347
14348 @item ::@r{, }.
14349 @value{GDBN} and Modula-2 scope operators.
14350 @end table
14351
14352 @quotation
14353 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
14354 treats the use of the operator @code{IN}, or the use of operators
14355 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
14356 @code{<=}, and @code{>=} on sets as an error.
14357 @end quotation
14358
14359
14360 @node Built-In Func/Proc
14361 @subsubsection Built-in Functions and Procedures
14362 @cindex Modula-2 built-ins
14363
14364 Modula-2 also makes available several built-in procedures and functions.
14365 In describing these, the following metavariables are used:
14366
14367 @table @var
14368
14369 @item a
14370 represents an @code{ARRAY} variable.
14371
14372 @item c
14373 represents a @code{CHAR} constant or variable.
14374
14375 @item i
14376 represents a variable or constant of integral type.
14377
14378 @item m
14379 represents an identifier that belongs to a set. Generally used in the
14380 same function with the metavariable @var{s}. The type of @var{s} should
14381 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
14382
14383 @item n
14384 represents a variable or constant of integral or floating-point type.
14385
14386 @item r
14387 represents a variable or constant of floating-point type.
14388
14389 @item t
14390 represents a type.
14391
14392 @item v
14393 represents a variable.
14394
14395 @item x
14396 represents a variable or constant of one of many types. See the
14397 explanation of the function for details.
14398 @end table
14399
14400 All Modula-2 built-in procedures also return a result, described below.
14401
14402 @table @code
14403 @item ABS(@var{n})
14404 Returns the absolute value of @var{n}.
14405
14406 @item CAP(@var{c})
14407 If @var{c} is a lower case letter, it returns its upper case
14408 equivalent, otherwise it returns its argument.
14409
14410 @item CHR(@var{i})
14411 Returns the character whose ordinal value is @var{i}.
14412
14413 @item DEC(@var{v})
14414 Decrements the value in the variable @var{v} by one. Returns the new value.
14415
14416 @item DEC(@var{v},@var{i})
14417 Decrements the value in the variable @var{v} by @var{i}. Returns the
14418 new value.
14419
14420 @item EXCL(@var{m},@var{s})
14421 Removes the element @var{m} from the set @var{s}. Returns the new
14422 set.
14423
14424 @item FLOAT(@var{i})
14425 Returns the floating point equivalent of the integer @var{i}.
14426
14427 @item HIGH(@var{a})
14428 Returns the index of the last member of @var{a}.
14429
14430 @item INC(@var{v})
14431 Increments the value in the variable @var{v} by one. Returns the new value.
14432
14433 @item INC(@var{v},@var{i})
14434 Increments the value in the variable @var{v} by @var{i}. Returns the
14435 new value.
14436
14437 @item INCL(@var{m},@var{s})
14438 Adds the element @var{m} to the set @var{s} if it is not already
14439 there. Returns the new set.
14440
14441 @item MAX(@var{t})
14442 Returns the maximum value of the type @var{t}.
14443
14444 @item MIN(@var{t})
14445 Returns the minimum value of the type @var{t}.
14446
14447 @item ODD(@var{i})
14448 Returns boolean TRUE if @var{i} is an odd number.
14449
14450 @item ORD(@var{x})
14451 Returns the ordinal value of its argument. For example, the ordinal
14452 value of a character is its @sc{ascii} value (on machines supporting the
14453 @sc{ascii} character set). @var{x} must be of an ordered type, which include
14454 integral, character and enumerated types.
14455
14456 @item SIZE(@var{x})
14457 Returns the size of its argument. @var{x} can be a variable or a type.
14458
14459 @item TRUNC(@var{r})
14460 Returns the integral part of @var{r}.
14461
14462 @item TSIZE(@var{x})
14463 Returns the size of its argument. @var{x} can be a variable or a type.
14464
14465 @item VAL(@var{t},@var{i})
14466 Returns the member of the type @var{t} whose ordinal value is @var{i}.
14467 @end table
14468
14469 @quotation
14470 @emph{Warning:} Sets and their operations are not yet supported, so
14471 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
14472 an error.
14473 @end quotation
14474
14475 @cindex Modula-2 constants
14476 @node M2 Constants
14477 @subsubsection Constants
14478
14479 @value{GDBN} allows you to express the constants of Modula-2 in the following
14480 ways:
14481
14482 @itemize @bullet
14483
14484 @item
14485 Integer constants are simply a sequence of digits. When used in an
14486 expression, a constant is interpreted to be type-compatible with the
14487 rest of the expression. Hexadecimal integers are specified by a
14488 trailing @samp{H}, and octal integers by a trailing @samp{B}.
14489
14490 @item
14491 Floating point constants appear as a sequence of digits, followed by a
14492 decimal point and another sequence of digits. An optional exponent can
14493 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
14494 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
14495 digits of the floating point constant must be valid decimal (base 10)
14496 digits.
14497
14498 @item
14499 Character constants consist of a single character enclosed by a pair of
14500 like quotes, either single (@code{'}) or double (@code{"}). They may
14501 also be expressed by their ordinal value (their @sc{ascii} value, usually)
14502 followed by a @samp{C}.
14503
14504 @item
14505 String constants consist of a sequence of characters enclosed by a
14506 pair of like quotes, either single (@code{'}) or double (@code{"}).
14507 Escape sequences in the style of C are also allowed. @xref{C
14508 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
14509 sequences.
14510
14511 @item
14512 Enumerated constants consist of an enumerated identifier.
14513
14514 @item
14515 Boolean constants consist of the identifiers @code{TRUE} and
14516 @code{FALSE}.
14517
14518 @item
14519 Pointer constants consist of integral values only.
14520
14521 @item
14522 Set constants are not yet supported.
14523 @end itemize
14524
14525 @node M2 Types
14526 @subsubsection Modula-2 Types
14527 @cindex Modula-2 types
14528
14529 Currently @value{GDBN} can print the following data types in Modula-2
14530 syntax: array types, record types, set types, pointer types, procedure
14531 types, enumerated types, subrange types and base types. You can also
14532 print the contents of variables declared using these type.
14533 This section gives a number of simple source code examples together with
14534 sample @value{GDBN} sessions.
14535
14536 The first example contains the following section of code:
14537
14538 @smallexample
14539 VAR
14540 s: SET OF CHAR ;
14541 r: [20..40] ;
14542 @end smallexample
14543
14544 @noindent
14545 and you can request @value{GDBN} to interrogate the type and value of
14546 @code{r} and @code{s}.
14547
14548 @smallexample
14549 (@value{GDBP}) print s
14550 @{'A'..'C', 'Z'@}
14551 (@value{GDBP}) ptype s
14552 SET OF CHAR
14553 (@value{GDBP}) print r
14554 21
14555 (@value{GDBP}) ptype r
14556 [20..40]
14557 @end smallexample
14558
14559 @noindent
14560 Likewise if your source code declares @code{s} as:
14561
14562 @smallexample
14563 VAR
14564 s: SET ['A'..'Z'] ;
14565 @end smallexample
14566
14567 @noindent
14568 then you may query the type of @code{s} by:
14569
14570 @smallexample
14571 (@value{GDBP}) ptype s
14572 type = SET ['A'..'Z']
14573 @end smallexample
14574
14575 @noindent
14576 Note that at present you cannot interactively manipulate set
14577 expressions using the debugger.
14578
14579 The following example shows how you might declare an array in Modula-2
14580 and how you can interact with @value{GDBN} to print its type and contents:
14581
14582 @smallexample
14583 VAR
14584 s: ARRAY [-10..10] OF CHAR ;
14585 @end smallexample
14586
14587 @smallexample
14588 (@value{GDBP}) ptype s
14589 ARRAY [-10..10] OF CHAR
14590 @end smallexample
14591
14592 Note that the array handling is not yet complete and although the type
14593 is printed correctly, expression handling still assumes that all
14594 arrays have a lower bound of zero and not @code{-10} as in the example
14595 above.
14596
14597 Here are some more type related Modula-2 examples:
14598
14599 @smallexample
14600 TYPE
14601 colour = (blue, red, yellow, green) ;
14602 t = [blue..yellow] ;
14603 VAR
14604 s: t ;
14605 BEGIN
14606 s := blue ;
14607 @end smallexample
14608
14609 @noindent
14610 The @value{GDBN} interaction shows how you can query the data type
14611 and value of a variable.
14612
14613 @smallexample
14614 (@value{GDBP}) print s
14615 $1 = blue
14616 (@value{GDBP}) ptype t
14617 type = [blue..yellow]
14618 @end smallexample
14619
14620 @noindent
14621 In this example a Modula-2 array is declared and its contents
14622 displayed. Observe that the contents are written in the same way as
14623 their @code{C} counterparts.
14624
14625 @smallexample
14626 VAR
14627 s: ARRAY [1..5] OF CARDINAL ;
14628 BEGIN
14629 s[1] := 1 ;
14630 @end smallexample
14631
14632 @smallexample
14633 (@value{GDBP}) print s
14634 $1 = @{1, 0, 0, 0, 0@}
14635 (@value{GDBP}) ptype s
14636 type = ARRAY [1..5] OF CARDINAL
14637 @end smallexample
14638
14639 The Modula-2 language interface to @value{GDBN} also understands
14640 pointer types as shown in this example:
14641
14642 @smallexample
14643 VAR
14644 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
14645 BEGIN
14646 NEW(s) ;
14647 s^[1] := 1 ;
14648 @end smallexample
14649
14650 @noindent
14651 and you can request that @value{GDBN} describes the type of @code{s}.
14652
14653 @smallexample
14654 (@value{GDBP}) ptype s
14655 type = POINTER TO ARRAY [1..5] OF CARDINAL
14656 @end smallexample
14657
14658 @value{GDBN} handles compound types as we can see in this example.
14659 Here we combine array types, record types, pointer types and subrange
14660 types:
14661
14662 @smallexample
14663 TYPE
14664 foo = RECORD
14665 f1: CARDINAL ;
14666 f2: CHAR ;
14667 f3: myarray ;
14668 END ;
14669
14670 myarray = ARRAY myrange OF CARDINAL ;
14671 myrange = [-2..2] ;
14672 VAR
14673 s: POINTER TO ARRAY myrange OF foo ;
14674 @end smallexample
14675
14676 @noindent
14677 and you can ask @value{GDBN} to describe the type of @code{s} as shown
14678 below.
14679
14680 @smallexample
14681 (@value{GDBP}) ptype s
14682 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
14683 f1 : CARDINAL;
14684 f2 : CHAR;
14685 f3 : ARRAY [-2..2] OF CARDINAL;
14686 END
14687 @end smallexample
14688
14689 @node M2 Defaults
14690 @subsubsection Modula-2 Defaults
14691 @cindex Modula-2 defaults
14692
14693 If type and range checking are set automatically by @value{GDBN}, they
14694 both default to @code{on} whenever the working language changes to
14695 Modula-2. This happens regardless of whether you or @value{GDBN}
14696 selected the working language.
14697
14698 If you allow @value{GDBN} to set the language automatically, then entering
14699 code compiled from a file whose name ends with @file{.mod} sets the
14700 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
14701 Infer the Source Language}, for further details.
14702
14703 @node Deviations
14704 @subsubsection Deviations from Standard Modula-2
14705 @cindex Modula-2, deviations from
14706
14707 A few changes have been made to make Modula-2 programs easier to debug.
14708 This is done primarily via loosening its type strictness:
14709
14710 @itemize @bullet
14711 @item
14712 Unlike in standard Modula-2, pointer constants can be formed by
14713 integers. This allows you to modify pointer variables during
14714 debugging. (In standard Modula-2, the actual address contained in a
14715 pointer variable is hidden from you; it can only be modified
14716 through direct assignment to another pointer variable or expression that
14717 returned a pointer.)
14718
14719 @item
14720 C escape sequences can be used in strings and characters to represent
14721 non-printable characters. @value{GDBN} prints out strings with these
14722 escape sequences embedded. Single non-printable characters are
14723 printed using the @samp{CHR(@var{nnn})} format.
14724
14725 @item
14726 The assignment operator (@code{:=}) returns the value of its right-hand
14727 argument.
14728
14729 @item
14730 All built-in procedures both modify @emph{and} return their argument.
14731 @end itemize
14732
14733 @node M2 Checks
14734 @subsubsection Modula-2 Type and Range Checks
14735 @cindex Modula-2 checks
14736
14737 @quotation
14738 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
14739 range checking.
14740 @end quotation
14741 @c FIXME remove warning when type/range checks added
14742
14743 @value{GDBN} considers two Modula-2 variables type equivalent if:
14744
14745 @itemize @bullet
14746 @item
14747 They are of types that have been declared equivalent via a @code{TYPE
14748 @var{t1} = @var{t2}} statement
14749
14750 @item
14751 They have been declared on the same line. (Note: This is true of the
14752 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
14753 @end itemize
14754
14755 As long as type checking is enabled, any attempt to combine variables
14756 whose types are not equivalent is an error.
14757
14758 Range checking is done on all mathematical operations, assignment, array
14759 index bounds, and all built-in functions and procedures.
14760
14761 @node M2 Scope
14762 @subsubsection The Scope Operators @code{::} and @code{.}
14763 @cindex scope
14764 @cindex @code{.}, Modula-2 scope operator
14765 @cindex colon, doubled as scope operator
14766 @ifinfo
14767 @vindex colon-colon@r{, in Modula-2}
14768 @c Info cannot handle :: but TeX can.
14769 @end ifinfo
14770 @ifnotinfo
14771 @vindex ::@r{, in Modula-2}
14772 @end ifnotinfo
14773
14774 There are a few subtle differences between the Modula-2 scope operator
14775 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
14776 similar syntax:
14777
14778 @smallexample
14779
14780 @var{module} . @var{id}
14781 @var{scope} :: @var{id}
14782 @end smallexample
14783
14784 @noindent
14785 where @var{scope} is the name of a module or a procedure,
14786 @var{module} the name of a module, and @var{id} is any declared
14787 identifier within your program, except another module.
14788
14789 Using the @code{::} operator makes @value{GDBN} search the scope
14790 specified by @var{scope} for the identifier @var{id}. If it is not
14791 found in the specified scope, then @value{GDBN} searches all scopes
14792 enclosing the one specified by @var{scope}.
14793
14794 Using the @code{.} operator makes @value{GDBN} search the current scope for
14795 the identifier specified by @var{id} that was imported from the
14796 definition module specified by @var{module}. With this operator, it is
14797 an error if the identifier @var{id} was not imported from definition
14798 module @var{module}, or if @var{id} is not an identifier in
14799 @var{module}.
14800
14801 @node GDB/M2
14802 @subsubsection @value{GDBN} and Modula-2
14803
14804 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
14805 Five subcommands of @code{set print} and @code{show print} apply
14806 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
14807 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
14808 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
14809 analogue in Modula-2.
14810
14811 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
14812 with any language, is not useful with Modula-2. Its
14813 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
14814 created in Modula-2 as they can in C or C@t{++}. However, because an
14815 address can be specified by an integral constant, the construct
14816 @samp{@{@var{type}@}@var{adrexp}} is still useful.
14817
14818 @cindex @code{#} in Modula-2
14819 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
14820 interpreted as the beginning of a comment. Use @code{<>} instead.
14821
14822 @node Ada
14823 @subsection Ada
14824 @cindex Ada
14825
14826 The extensions made to @value{GDBN} for Ada only support
14827 output from the @sc{gnu} Ada (GNAT) compiler.
14828 Other Ada compilers are not currently supported, and
14829 attempting to debug executables produced by them is most likely
14830 to be difficult.
14831
14832
14833 @cindex expressions in Ada
14834 @menu
14835 * Ada Mode Intro:: General remarks on the Ada syntax
14836 and semantics supported by Ada mode
14837 in @value{GDBN}.
14838 * Omissions from Ada:: Restrictions on the Ada expression syntax.
14839 * Additions to Ada:: Extensions of the Ada expression syntax.
14840 * Stopping Before Main Program:: Debugging the program during elaboration.
14841 * Ada Tasks:: Listing and setting breakpoints in tasks.
14842 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
14843 * Ravenscar Profile:: Tasking Support when using the Ravenscar
14844 Profile
14845 * Ada Glitches:: Known peculiarities of Ada mode.
14846 @end menu
14847
14848 @node Ada Mode Intro
14849 @subsubsection Introduction
14850 @cindex Ada mode, general
14851
14852 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
14853 syntax, with some extensions.
14854 The philosophy behind the design of this subset is
14855
14856 @itemize @bullet
14857 @item
14858 That @value{GDBN} should provide basic literals and access to operations for
14859 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
14860 leaving more sophisticated computations to subprograms written into the
14861 program (which therefore may be called from @value{GDBN}).
14862
14863 @item
14864 That type safety and strict adherence to Ada language restrictions
14865 are not particularly important to the @value{GDBN} user.
14866
14867 @item
14868 That brevity is important to the @value{GDBN} user.
14869 @end itemize
14870
14871 Thus, for brevity, the debugger acts as if all names declared in
14872 user-written packages are directly visible, even if they are not visible
14873 according to Ada rules, thus making it unnecessary to fully qualify most
14874 names with their packages, regardless of context. Where this causes
14875 ambiguity, @value{GDBN} asks the user's intent.
14876
14877 The debugger will start in Ada mode if it detects an Ada main program.
14878 As for other languages, it will enter Ada mode when stopped in a program that
14879 was translated from an Ada source file.
14880
14881 While in Ada mode, you may use `@t{--}' for comments. This is useful
14882 mostly for documenting command files. The standard @value{GDBN} comment
14883 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
14884 middle (to allow based literals).
14885
14886 The debugger supports limited overloading. Given a subprogram call in which
14887 the function symbol has multiple definitions, it will use the number of
14888 actual parameters and some information about their types to attempt to narrow
14889 the set of definitions. It also makes very limited use of context, preferring
14890 procedures to functions in the context of the @code{call} command, and
14891 functions to procedures elsewhere.
14892
14893 @node Omissions from Ada
14894 @subsubsection Omissions from Ada
14895 @cindex Ada, omissions from
14896
14897 Here are the notable omissions from the subset:
14898
14899 @itemize @bullet
14900 @item
14901 Only a subset of the attributes are supported:
14902
14903 @itemize @minus
14904 @item
14905 @t{'First}, @t{'Last}, and @t{'Length}
14906 on array objects (not on types and subtypes).
14907
14908 @item
14909 @t{'Min} and @t{'Max}.
14910
14911 @item
14912 @t{'Pos} and @t{'Val}.
14913
14914 @item
14915 @t{'Tag}.
14916
14917 @item
14918 @t{'Range} on array objects (not subtypes), but only as the right
14919 operand of the membership (@code{in}) operator.
14920
14921 @item
14922 @t{'Access}, @t{'Unchecked_Access}, and
14923 @t{'Unrestricted_Access} (a GNAT extension).
14924
14925 @item
14926 @t{'Address}.
14927 @end itemize
14928
14929 @item
14930 The names in
14931 @code{Characters.Latin_1} are not available and
14932 concatenation is not implemented. Thus, escape characters in strings are
14933 not currently available.
14934
14935 @item
14936 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
14937 equality of representations. They will generally work correctly
14938 for strings and arrays whose elements have integer or enumeration types.
14939 They may not work correctly for arrays whose element
14940 types have user-defined equality, for arrays of real values
14941 (in particular, IEEE-conformant floating point, because of negative
14942 zeroes and NaNs), and for arrays whose elements contain unused bits with
14943 indeterminate values.
14944
14945 @item
14946 The other component-by-component array operations (@code{and}, @code{or},
14947 @code{xor}, @code{not}, and relational tests other than equality)
14948 are not implemented.
14949
14950 @item
14951 @cindex array aggregates (Ada)
14952 @cindex record aggregates (Ada)
14953 @cindex aggregates (Ada)
14954 There is limited support for array and record aggregates. They are
14955 permitted only on the right sides of assignments, as in these examples:
14956
14957 @smallexample
14958 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
14959 (@value{GDBP}) set An_Array := (1, others => 0)
14960 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
14961 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
14962 (@value{GDBP}) set A_Record := (1, "Peter", True);
14963 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
14964 @end smallexample
14965
14966 Changing a
14967 discriminant's value by assigning an aggregate has an
14968 undefined effect if that discriminant is used within the record.
14969 However, you can first modify discriminants by directly assigning to
14970 them (which normally would not be allowed in Ada), and then performing an
14971 aggregate assignment. For example, given a variable @code{A_Rec}
14972 declared to have a type such as:
14973
14974 @smallexample
14975 type Rec (Len : Small_Integer := 0) is record
14976 Id : Integer;
14977 Vals : IntArray (1 .. Len);
14978 end record;
14979 @end smallexample
14980
14981 you can assign a value with a different size of @code{Vals} with two
14982 assignments:
14983
14984 @smallexample
14985 (@value{GDBP}) set A_Rec.Len := 4
14986 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
14987 @end smallexample
14988
14989 As this example also illustrates, @value{GDBN} is very loose about the usual
14990 rules concerning aggregates. You may leave out some of the
14991 components of an array or record aggregate (such as the @code{Len}
14992 component in the assignment to @code{A_Rec} above); they will retain their
14993 original values upon assignment. You may freely use dynamic values as
14994 indices in component associations. You may even use overlapping or
14995 redundant component associations, although which component values are
14996 assigned in such cases is not defined.
14997
14998 @item
14999 Calls to dispatching subprograms are not implemented.
15000
15001 @item
15002 The overloading algorithm is much more limited (i.e., less selective)
15003 than that of real Ada. It makes only limited use of the context in
15004 which a subexpression appears to resolve its meaning, and it is much
15005 looser in its rules for allowing type matches. As a result, some
15006 function calls will be ambiguous, and the user will be asked to choose
15007 the proper resolution.
15008
15009 @item
15010 The @code{new} operator is not implemented.
15011
15012 @item
15013 Entry calls are not implemented.
15014
15015 @item
15016 Aside from printing, arithmetic operations on the native VAX floating-point
15017 formats are not supported.
15018
15019 @item
15020 It is not possible to slice a packed array.
15021
15022 @item
15023 The names @code{True} and @code{False}, when not part of a qualified name,
15024 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
15025 context.
15026 Should your program
15027 redefine these names in a package or procedure (at best a dubious practice),
15028 you will have to use fully qualified names to access their new definitions.
15029 @end itemize
15030
15031 @node Additions to Ada
15032 @subsubsection Additions to Ada
15033 @cindex Ada, deviations from
15034
15035 As it does for other languages, @value{GDBN} makes certain generic
15036 extensions to Ada (@pxref{Expressions}):
15037
15038 @itemize @bullet
15039 @item
15040 If the expression @var{E} is a variable residing in memory (typically
15041 a local variable or array element) and @var{N} is a positive integer,
15042 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
15043 @var{N}-1 adjacent variables following it in memory as an array. In
15044 Ada, this operator is generally not necessary, since its prime use is
15045 in displaying parts of an array, and slicing will usually do this in
15046 Ada. However, there are occasional uses when debugging programs in
15047 which certain debugging information has been optimized away.
15048
15049 @item
15050 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
15051 appears in function or file @var{B}.'' When @var{B} is a file name,
15052 you must typically surround it in single quotes.
15053
15054 @item
15055 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
15056 @var{type} that appears at address @var{addr}.''
15057
15058 @item
15059 A name starting with @samp{$} is a convenience variable
15060 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
15061 @end itemize
15062
15063 In addition, @value{GDBN} provides a few other shortcuts and outright
15064 additions specific to Ada:
15065
15066 @itemize @bullet
15067 @item
15068 The assignment statement is allowed as an expression, returning
15069 its right-hand operand as its value. Thus, you may enter
15070
15071 @smallexample
15072 (@value{GDBP}) set x := y + 3
15073 (@value{GDBP}) print A(tmp := y + 1)
15074 @end smallexample
15075
15076 @item
15077 The semicolon is allowed as an ``operator,'' returning as its value
15078 the value of its right-hand operand.
15079 This allows, for example,
15080 complex conditional breaks:
15081
15082 @smallexample
15083 (@value{GDBP}) break f
15084 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
15085 @end smallexample
15086
15087 @item
15088 Rather than use catenation and symbolic character names to introduce special
15089 characters into strings, one may instead use a special bracket notation,
15090 which is also used to print strings. A sequence of characters of the form
15091 @samp{["@var{XX}"]} within a string or character literal denotes the
15092 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
15093 sequence of characters @samp{["""]} also denotes a single quotation mark
15094 in strings. For example,
15095 @smallexample
15096 "One line.["0a"]Next line.["0a"]"
15097 @end smallexample
15098 @noindent
15099 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
15100 after each period.
15101
15102 @item
15103 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
15104 @t{'Max} is optional (and is ignored in any case). For example, it is valid
15105 to write
15106
15107 @smallexample
15108 (@value{GDBP}) print 'max(x, y)
15109 @end smallexample
15110
15111 @item
15112 When printing arrays, @value{GDBN} uses positional notation when the
15113 array has a lower bound of 1, and uses a modified named notation otherwise.
15114 For example, a one-dimensional array of three integers with a lower bound
15115 of 3 might print as
15116
15117 @smallexample
15118 (3 => 10, 17, 1)
15119 @end smallexample
15120
15121 @noindent
15122 That is, in contrast to valid Ada, only the first component has a @code{=>}
15123 clause.
15124
15125 @item
15126 You may abbreviate attributes in expressions with any unique,
15127 multi-character subsequence of
15128 their names (an exact match gets preference).
15129 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
15130 in place of @t{a'length}.
15131
15132 @item
15133 @cindex quoting Ada internal identifiers
15134 Since Ada is case-insensitive, the debugger normally maps identifiers you type
15135 to lower case. The GNAT compiler uses upper-case characters for
15136 some of its internal identifiers, which are normally of no interest to users.
15137 For the rare occasions when you actually have to look at them,
15138 enclose them in angle brackets to avoid the lower-case mapping.
15139 For example,
15140 @smallexample
15141 (@value{GDBP}) print <JMPBUF_SAVE>[0]
15142 @end smallexample
15143
15144 @item
15145 Printing an object of class-wide type or dereferencing an
15146 access-to-class-wide value will display all the components of the object's
15147 specific type (as indicated by its run-time tag). Likewise, component
15148 selection on such a value will operate on the specific type of the
15149 object.
15150
15151 @end itemize
15152
15153 @node Stopping Before Main Program
15154 @subsubsection Stopping at the Very Beginning
15155
15156 @cindex breakpointing Ada elaboration code
15157 It is sometimes necessary to debug the program during elaboration, and
15158 before reaching the main procedure.
15159 As defined in the Ada Reference
15160 Manual, the elaboration code is invoked from a procedure called
15161 @code{adainit}. To run your program up to the beginning of
15162 elaboration, simply use the following two commands:
15163 @code{tbreak adainit} and @code{run}.
15164
15165 @node Ada Tasks
15166 @subsubsection Extensions for Ada Tasks
15167 @cindex Ada, tasking
15168
15169 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
15170 @value{GDBN} provides the following task-related commands:
15171
15172 @table @code
15173 @kindex info tasks
15174 @item info tasks
15175 This command shows a list of current Ada tasks, as in the following example:
15176
15177
15178 @smallexample
15179 @iftex
15180 @leftskip=0.5cm
15181 @end iftex
15182 (@value{GDBP}) info tasks
15183 ID TID P-ID Pri State Name
15184 1 8088000 0 15 Child Activation Wait main_task
15185 2 80a4000 1 15 Accept Statement b
15186 3 809a800 1 15 Child Activation Wait a
15187 * 4 80ae800 3 15 Runnable c
15188
15189 @end smallexample
15190
15191 @noindent
15192 In this listing, the asterisk before the last task indicates it to be the
15193 task currently being inspected.
15194
15195 @table @asis
15196 @item ID
15197 Represents @value{GDBN}'s internal task number.
15198
15199 @item TID
15200 The Ada task ID.
15201
15202 @item P-ID
15203 The parent's task ID (@value{GDBN}'s internal task number).
15204
15205 @item Pri
15206 The base priority of the task.
15207
15208 @item State
15209 Current state of the task.
15210
15211 @table @code
15212 @item Unactivated
15213 The task has been created but has not been activated. It cannot be
15214 executing.
15215
15216 @item Runnable
15217 The task is not blocked for any reason known to Ada. (It may be waiting
15218 for a mutex, though.) It is conceptually "executing" in normal mode.
15219
15220 @item Terminated
15221 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
15222 that were waiting on terminate alternatives have been awakened and have
15223 terminated themselves.
15224
15225 @item Child Activation Wait
15226 The task is waiting for created tasks to complete activation.
15227
15228 @item Accept Statement
15229 The task is waiting on an accept or selective wait statement.
15230
15231 @item Waiting on entry call
15232 The task is waiting on an entry call.
15233
15234 @item Async Select Wait
15235 The task is waiting to start the abortable part of an asynchronous
15236 select statement.
15237
15238 @item Delay Sleep
15239 The task is waiting on a select statement with only a delay
15240 alternative open.
15241
15242 @item Child Termination Wait
15243 The task is sleeping having completed a master within itself, and is
15244 waiting for the tasks dependent on that master to become terminated or
15245 waiting on a terminate Phase.
15246
15247 @item Wait Child in Term Alt
15248 The task is sleeping waiting for tasks on terminate alternatives to
15249 finish terminating.
15250
15251 @item Accepting RV with @var{taskno}
15252 The task is accepting a rendez-vous with the task @var{taskno}.
15253 @end table
15254
15255 @item Name
15256 Name of the task in the program.
15257
15258 @end table
15259
15260 @kindex info task @var{taskno}
15261 @item info task @var{taskno}
15262 This command shows detailled informations on the specified task, as in
15263 the following example:
15264 @smallexample
15265 @iftex
15266 @leftskip=0.5cm
15267 @end iftex
15268 (@value{GDBP}) info tasks
15269 ID TID P-ID Pri State Name
15270 1 8077880 0 15 Child Activation Wait main_task
15271 * 2 807c468 1 15 Runnable task_1
15272 (@value{GDBP}) info task 2
15273 Ada Task: 0x807c468
15274 Name: task_1
15275 Thread: 0x807f378
15276 Parent: 1 (main_task)
15277 Base Priority: 15
15278 State: Runnable
15279 @end smallexample
15280
15281 @item task
15282 @kindex task@r{ (Ada)}
15283 @cindex current Ada task ID
15284 This command prints the ID of the current task.
15285
15286 @smallexample
15287 @iftex
15288 @leftskip=0.5cm
15289 @end iftex
15290 (@value{GDBP}) info tasks
15291 ID TID P-ID Pri State Name
15292 1 8077870 0 15 Child Activation Wait main_task
15293 * 2 807c458 1 15 Runnable t
15294 (@value{GDBP}) task
15295 [Current task is 2]
15296 @end smallexample
15297
15298 @item task @var{taskno}
15299 @cindex Ada task switching
15300 This command is like the @code{thread @var{threadno}}
15301 command (@pxref{Threads}). It switches the context of debugging
15302 from the current task to the given task.
15303
15304 @smallexample
15305 @iftex
15306 @leftskip=0.5cm
15307 @end iftex
15308 (@value{GDBP}) info tasks
15309 ID TID P-ID Pri State Name
15310 1 8077870 0 15 Child Activation Wait main_task
15311 * 2 807c458 1 15 Runnable t
15312 (@value{GDBP}) task 1
15313 [Switching to task 1]
15314 #0 0x8067726 in pthread_cond_wait ()
15315 (@value{GDBP}) bt
15316 #0 0x8067726 in pthread_cond_wait ()
15317 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
15318 #2 0x805cb63 in system.task_primitives.operations.sleep ()
15319 #3 0x806153e in system.tasking.stages.activate_tasks ()
15320 #4 0x804aacc in un () at un.adb:5
15321 @end smallexample
15322
15323 @item break @var{linespec} task @var{taskno}
15324 @itemx break @var{linespec} task @var{taskno} if @dots{}
15325 @cindex breakpoints and tasks, in Ada
15326 @cindex task breakpoints, in Ada
15327 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
15328 These commands are like the @code{break @dots{} thread @dots{}}
15329 command (@pxref{Thread Stops}).
15330 @var{linespec} specifies source lines, as described
15331 in @ref{Specify Location}.
15332
15333 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
15334 to specify that you only want @value{GDBN} to stop the program when a
15335 particular Ada task reaches this breakpoint. @var{taskno} is one of the
15336 numeric task identifiers assigned by @value{GDBN}, shown in the first
15337 column of the @samp{info tasks} display.
15338
15339 If you do not specify @samp{task @var{taskno}} when you set a
15340 breakpoint, the breakpoint applies to @emph{all} tasks of your
15341 program.
15342
15343 You can use the @code{task} qualifier on conditional breakpoints as
15344 well; in this case, place @samp{task @var{taskno}} before the
15345 breakpoint condition (before the @code{if}).
15346
15347 For example,
15348
15349 @smallexample
15350 @iftex
15351 @leftskip=0.5cm
15352 @end iftex
15353 (@value{GDBP}) info tasks
15354 ID TID P-ID Pri State Name
15355 1 140022020 0 15 Child Activation Wait main_task
15356 2 140045060 1 15 Accept/Select Wait t2
15357 3 140044840 1 15 Runnable t1
15358 * 4 140056040 1 15 Runnable t3
15359 (@value{GDBP}) b 15 task 2
15360 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
15361 (@value{GDBP}) cont
15362 Continuing.
15363 task # 1 running
15364 task # 2 running
15365
15366 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
15367 15 flush;
15368 (@value{GDBP}) info tasks
15369 ID TID P-ID Pri State Name
15370 1 140022020 0 15 Child Activation Wait main_task
15371 * 2 140045060 1 15 Runnable t2
15372 3 140044840 1 15 Runnable t1
15373 4 140056040 1 15 Delay Sleep t3
15374 @end smallexample
15375 @end table
15376
15377 @node Ada Tasks and Core Files
15378 @subsubsection Tasking Support when Debugging Core Files
15379 @cindex Ada tasking and core file debugging
15380
15381 When inspecting a core file, as opposed to debugging a live program,
15382 tasking support may be limited or even unavailable, depending on
15383 the platform being used.
15384 For instance, on x86-linux, the list of tasks is available, but task
15385 switching is not supported. On Tru64, however, task switching will work
15386 as usual.
15387
15388 On certain platforms, including Tru64, the debugger needs to perform some
15389 memory writes in order to provide Ada tasking support. When inspecting
15390 a core file, this means that the core file must be opened with read-write
15391 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
15392 Under these circumstances, you should make a backup copy of the core
15393 file before inspecting it with @value{GDBN}.
15394
15395 @node Ravenscar Profile
15396 @subsubsection Tasking Support when using the Ravenscar Profile
15397 @cindex Ravenscar Profile
15398
15399 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
15400 specifically designed for systems with safety-critical real-time
15401 requirements.
15402
15403 @table @code
15404 @kindex set ravenscar task-switching on
15405 @cindex task switching with program using Ravenscar Profile
15406 @item set ravenscar task-switching on
15407 Allows task switching when debugging a program that uses the Ravenscar
15408 Profile. This is the default.
15409
15410 @kindex set ravenscar task-switching off
15411 @item set ravenscar task-switching off
15412 Turn off task switching when debugging a program that uses the Ravenscar
15413 Profile. This is mostly intended to disable the code that adds support
15414 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
15415 the Ravenscar runtime is preventing @value{GDBN} from working properly.
15416 To be effective, this command should be run before the program is started.
15417
15418 @kindex show ravenscar task-switching
15419 @item show ravenscar task-switching
15420 Show whether it is possible to switch from task to task in a program
15421 using the Ravenscar Profile.
15422
15423 @end table
15424
15425 @node Ada Glitches
15426 @subsubsection Known Peculiarities of Ada Mode
15427 @cindex Ada, problems
15428
15429 Besides the omissions listed previously (@pxref{Omissions from Ada}),
15430 we know of several problems with and limitations of Ada mode in
15431 @value{GDBN},
15432 some of which will be fixed with planned future releases of the debugger
15433 and the GNU Ada compiler.
15434
15435 @itemize @bullet
15436 @item
15437 Static constants that the compiler chooses not to materialize as objects in
15438 storage are invisible to the debugger.
15439
15440 @item
15441 Named parameter associations in function argument lists are ignored (the
15442 argument lists are treated as positional).
15443
15444 @item
15445 Many useful library packages are currently invisible to the debugger.
15446
15447 @item
15448 Fixed-point arithmetic, conversions, input, and output is carried out using
15449 floating-point arithmetic, and may give results that only approximate those on
15450 the host machine.
15451
15452 @item
15453 The GNAT compiler never generates the prefix @code{Standard} for any of
15454 the standard symbols defined by the Ada language. @value{GDBN} knows about
15455 this: it will strip the prefix from names when you use it, and will never
15456 look for a name you have so qualified among local symbols, nor match against
15457 symbols in other packages or subprograms. If you have
15458 defined entities anywhere in your program other than parameters and
15459 local variables whose simple names match names in @code{Standard},
15460 GNAT's lack of qualification here can cause confusion. When this happens,
15461 you can usually resolve the confusion
15462 by qualifying the problematic names with package
15463 @code{Standard} explicitly.
15464 @end itemize
15465
15466 Older versions of the compiler sometimes generate erroneous debugging
15467 information, resulting in the debugger incorrectly printing the value
15468 of affected entities. In some cases, the debugger is able to work
15469 around an issue automatically. In other cases, the debugger is able
15470 to work around the issue, but the work-around has to be specifically
15471 enabled.
15472
15473 @kindex set ada trust-PAD-over-XVS
15474 @kindex show ada trust-PAD-over-XVS
15475 @table @code
15476
15477 @item set ada trust-PAD-over-XVS on
15478 Configure GDB to strictly follow the GNAT encoding when computing the
15479 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
15480 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
15481 a complete description of the encoding used by the GNAT compiler).
15482 This is the default.
15483
15484 @item set ada trust-PAD-over-XVS off
15485 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
15486 sometimes prints the wrong value for certain entities, changing @code{ada
15487 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
15488 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
15489 @code{off}, but this incurs a slight performance penalty, so it is
15490 recommended to leave this setting to @code{on} unless necessary.
15491
15492 @end table
15493
15494 @node Unsupported Languages
15495 @section Unsupported Languages
15496
15497 @cindex unsupported languages
15498 @cindex minimal language
15499 In addition to the other fully-supported programming languages,
15500 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
15501 It does not represent a real programming language, but provides a set
15502 of capabilities close to what the C or assembly languages provide.
15503 This should allow most simple operations to be performed while debugging
15504 an application that uses a language currently not supported by @value{GDBN}.
15505
15506 If the language is set to @code{auto}, @value{GDBN} will automatically
15507 select this language if the current frame corresponds to an unsupported
15508 language.
15509
15510 @node Symbols
15511 @chapter Examining the Symbol Table
15512
15513 The commands described in this chapter allow you to inquire about the
15514 symbols (names of variables, functions and types) defined in your
15515 program. This information is inherent in the text of your program and
15516 does not change as your program executes. @value{GDBN} finds it in your
15517 program's symbol table, in the file indicated when you started @value{GDBN}
15518 (@pxref{File Options, ,Choosing Files}), or by one of the
15519 file-management commands (@pxref{Files, ,Commands to Specify Files}).
15520
15521 @cindex symbol names
15522 @cindex names of symbols
15523 @cindex quoting names
15524 Occasionally, you may need to refer to symbols that contain unusual
15525 characters, which @value{GDBN} ordinarily treats as word delimiters. The
15526 most frequent case is in referring to static variables in other
15527 source files (@pxref{Variables,,Program Variables}). File names
15528 are recorded in object files as debugging symbols, but @value{GDBN} would
15529 ordinarily parse a typical file name, like @file{foo.c}, as the three words
15530 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
15531 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
15532
15533 @smallexample
15534 p 'foo.c'::x
15535 @end smallexample
15536
15537 @noindent
15538 looks up the value of @code{x} in the scope of the file @file{foo.c}.
15539
15540 @table @code
15541 @cindex case-insensitive symbol names
15542 @cindex case sensitivity in symbol names
15543 @kindex set case-sensitive
15544 @item set case-sensitive on
15545 @itemx set case-sensitive off
15546 @itemx set case-sensitive auto
15547 Normally, when @value{GDBN} looks up symbols, it matches their names
15548 with case sensitivity determined by the current source language.
15549 Occasionally, you may wish to control that. The command @code{set
15550 case-sensitive} lets you do that by specifying @code{on} for
15551 case-sensitive matches or @code{off} for case-insensitive ones. If
15552 you specify @code{auto}, case sensitivity is reset to the default
15553 suitable for the source language. The default is case-sensitive
15554 matches for all languages except for Fortran, for which the default is
15555 case-insensitive matches.
15556
15557 @kindex show case-sensitive
15558 @item show case-sensitive
15559 This command shows the current setting of case sensitivity for symbols
15560 lookups.
15561
15562 @kindex set print type methods
15563 @item set print type methods
15564 @itemx set print type methods on
15565 @itemx set print type methods off
15566 Normally, when @value{GDBN} prints a class, it displays any methods
15567 declared in that class. You can control this behavior either by
15568 passing the appropriate flag to @code{ptype}, or using @command{set
15569 print type methods}. Specifying @code{on} will cause @value{GDBN} to
15570 display the methods; this is the default. Specifying @code{off} will
15571 cause @value{GDBN} to omit the methods.
15572
15573 @kindex show print type methods
15574 @item show print type methods
15575 This command shows the current setting of method display when printing
15576 classes.
15577
15578 @kindex set print type typedefs
15579 @item set print type typedefs
15580 @itemx set print type typedefs on
15581 @itemx set print type typedefs off
15582
15583 Normally, when @value{GDBN} prints a class, it displays any typedefs
15584 defined in that class. You can control this behavior either by
15585 passing the appropriate flag to @code{ptype}, or using @command{set
15586 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
15587 display the typedef definitions; this is the default. Specifying
15588 @code{off} will cause @value{GDBN} to omit the typedef definitions.
15589 Note that this controls whether the typedef definition itself is
15590 printed, not whether typedef names are substituted when printing other
15591 types.
15592
15593 @kindex show print type typedefs
15594 @item show print type typedefs
15595 This command shows the current setting of typedef display when
15596 printing classes.
15597
15598 @kindex info address
15599 @cindex address of a symbol
15600 @item info address @var{symbol}
15601 Describe where the data for @var{symbol} is stored. For a register
15602 variable, this says which register it is kept in. For a non-register
15603 local variable, this prints the stack-frame offset at which the variable
15604 is always stored.
15605
15606 Note the contrast with @samp{print &@var{symbol}}, which does not work
15607 at all for a register variable, and for a stack local variable prints
15608 the exact address of the current instantiation of the variable.
15609
15610 @kindex info symbol
15611 @cindex symbol from address
15612 @cindex closest symbol and offset for an address
15613 @item info symbol @var{addr}
15614 Print the name of a symbol which is stored at the address @var{addr}.
15615 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
15616 nearest symbol and an offset from it:
15617
15618 @smallexample
15619 (@value{GDBP}) info symbol 0x54320
15620 _initialize_vx + 396 in section .text
15621 @end smallexample
15622
15623 @noindent
15624 This is the opposite of the @code{info address} command. You can use
15625 it to find out the name of a variable or a function given its address.
15626
15627 For dynamically linked executables, the name of executable or shared
15628 library containing the symbol is also printed:
15629
15630 @smallexample
15631 (@value{GDBP}) info symbol 0x400225
15632 _start + 5 in section .text of /tmp/a.out
15633 (@value{GDBP}) info symbol 0x2aaaac2811cf
15634 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
15635 @end smallexample
15636
15637 @kindex whatis
15638 @item whatis[/@var{flags}] [@var{arg}]
15639 Print the data type of @var{arg}, which can be either an expression
15640 or a name of a data type. With no argument, print the data type of
15641 @code{$}, the last value in the value history.
15642
15643 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
15644 is not actually evaluated, and any side-effecting operations (such as
15645 assignments or function calls) inside it do not take place.
15646
15647 If @var{arg} is a variable or an expression, @code{whatis} prints its
15648 literal type as it is used in the source code. If the type was
15649 defined using a @code{typedef}, @code{whatis} will @emph{not} print
15650 the data type underlying the @code{typedef}. If the type of the
15651 variable or the expression is a compound data type, such as
15652 @code{struct} or @code{class}, @code{whatis} never prints their
15653 fields or methods. It just prints the @code{struct}/@code{class}
15654 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
15655 such a compound data type, use @code{ptype}.
15656
15657 If @var{arg} is a type name that was defined using @code{typedef},
15658 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
15659 Unrolling means that @code{whatis} will show the underlying type used
15660 in the @code{typedef} declaration of @var{arg}. However, if that
15661 underlying type is also a @code{typedef}, @code{whatis} will not
15662 unroll it.
15663
15664 For C code, the type names may also have the form @samp{class
15665 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
15666 @var{union-tag}} or @samp{enum @var{enum-tag}}.
15667
15668 @var{flags} can be used to modify how the type is displayed.
15669 Available flags are:
15670
15671 @table @code
15672 @item r
15673 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
15674 parameters and typedefs defined in a class when printing the class'
15675 members. The @code{/r} flag disables this.
15676
15677 @item m
15678 Do not print methods defined in the class.
15679
15680 @item M
15681 Print methods defined in the class. This is the default, but the flag
15682 exists in case you change the default with @command{set print type methods}.
15683
15684 @item t
15685 Do not print typedefs defined in the class. Note that this controls
15686 whether the typedef definition itself is printed, not whether typedef
15687 names are substituted when printing other types.
15688
15689 @item T
15690 Print typedefs defined in the class. This is the default, but the flag
15691 exists in case you change the default with @command{set print type typedefs}.
15692 @end table
15693
15694 @kindex ptype
15695 @item ptype[/@var{flags}] [@var{arg}]
15696 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
15697 detailed description of the type, instead of just the name of the type.
15698 @xref{Expressions, ,Expressions}.
15699
15700 Contrary to @code{whatis}, @code{ptype} always unrolls any
15701 @code{typedef}s in its argument declaration, whether the argument is
15702 a variable, expression, or a data type. This means that @code{ptype}
15703 of a variable or an expression will not print literally its type as
15704 present in the source code---use @code{whatis} for that. @code{typedef}s at
15705 the pointer or reference targets are also unrolled. Only @code{typedef}s of
15706 fields, methods and inner @code{class typedef}s of @code{struct}s,
15707 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
15708
15709 For example, for this variable declaration:
15710
15711 @smallexample
15712 typedef double real_t;
15713 struct complex @{ real_t real; double imag; @};
15714 typedef struct complex complex_t;
15715 complex_t var;
15716 real_t *real_pointer_var;
15717 @end smallexample
15718
15719 @noindent
15720 the two commands give this output:
15721
15722 @smallexample
15723 @group
15724 (@value{GDBP}) whatis var
15725 type = complex_t
15726 (@value{GDBP}) ptype var
15727 type = struct complex @{
15728 real_t real;
15729 double imag;
15730 @}
15731 (@value{GDBP}) whatis complex_t
15732 type = struct complex
15733 (@value{GDBP}) whatis struct complex
15734 type = struct complex
15735 (@value{GDBP}) ptype struct complex
15736 type = struct complex @{
15737 real_t real;
15738 double imag;
15739 @}
15740 (@value{GDBP}) whatis real_pointer_var
15741 type = real_t *
15742 (@value{GDBP}) ptype real_pointer_var
15743 type = double *
15744 @end group
15745 @end smallexample
15746
15747 @noindent
15748 As with @code{whatis}, using @code{ptype} without an argument refers to
15749 the type of @code{$}, the last value in the value history.
15750
15751 @cindex incomplete type
15752 Sometimes, programs use opaque data types or incomplete specifications
15753 of complex data structure. If the debug information included in the
15754 program does not allow @value{GDBN} to display a full declaration of
15755 the data type, it will say @samp{<incomplete type>}. For example,
15756 given these declarations:
15757
15758 @smallexample
15759 struct foo;
15760 struct foo *fooptr;
15761 @end smallexample
15762
15763 @noindent
15764 but no definition for @code{struct foo} itself, @value{GDBN} will say:
15765
15766 @smallexample
15767 (@value{GDBP}) ptype foo
15768 $1 = <incomplete type>
15769 @end smallexample
15770
15771 @noindent
15772 ``Incomplete type'' is C terminology for data types that are not
15773 completely specified.
15774
15775 @kindex info types
15776 @item info types @var{regexp}
15777 @itemx info types
15778 Print a brief description of all types whose names match the regular
15779 expression @var{regexp} (or all types in your program, if you supply
15780 no argument). Each complete typename is matched as though it were a
15781 complete line; thus, @samp{i type value} gives information on all
15782 types in your program whose names include the string @code{value}, but
15783 @samp{i type ^value$} gives information only on types whose complete
15784 name is @code{value}.
15785
15786 This command differs from @code{ptype} in two ways: first, like
15787 @code{whatis}, it does not print a detailed description; second, it
15788 lists all source files where a type is defined.
15789
15790 @kindex info type-printers
15791 @item info type-printers
15792 Versions of @value{GDBN} that ship with Python scripting enabled may
15793 have ``type printers'' available. When using @command{ptype} or
15794 @command{whatis}, these printers are consulted when the name of a type
15795 is needed. @xref{Type Printing API}, for more information on writing
15796 type printers.
15797
15798 @code{info type-printers} displays all the available type printers.
15799
15800 @kindex enable type-printer
15801 @kindex disable type-printer
15802 @item enable type-printer @var{name}@dots{}
15803 @item disable type-printer @var{name}@dots{}
15804 These commands can be used to enable or disable type printers.
15805
15806 @kindex info scope
15807 @cindex local variables
15808 @item info scope @var{location}
15809 List all the variables local to a particular scope. This command
15810 accepts a @var{location} argument---a function name, a source line, or
15811 an address preceded by a @samp{*}, and prints all the variables local
15812 to the scope defined by that location. (@xref{Specify Location}, for
15813 details about supported forms of @var{location}.) For example:
15814
15815 @smallexample
15816 (@value{GDBP}) @b{info scope command_line_handler}
15817 Scope for command_line_handler:
15818 Symbol rl is an argument at stack/frame offset 8, length 4.
15819 Symbol linebuffer is in static storage at address 0x150a18, length 4.
15820 Symbol linelength is in static storage at address 0x150a1c, length 4.
15821 Symbol p is a local variable in register $esi, length 4.
15822 Symbol p1 is a local variable in register $ebx, length 4.
15823 Symbol nline is a local variable in register $edx, length 4.
15824 Symbol repeat is a local variable at frame offset -8, length 4.
15825 @end smallexample
15826
15827 @noindent
15828 This command is especially useful for determining what data to collect
15829 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
15830 collect}.
15831
15832 @kindex info source
15833 @item info source
15834 Show information about the current source file---that is, the source file for
15835 the function containing the current point of execution:
15836 @itemize @bullet
15837 @item
15838 the name of the source file, and the directory containing it,
15839 @item
15840 the directory it was compiled in,
15841 @item
15842 its length, in lines,
15843 @item
15844 which programming language it is written in,
15845 @item
15846 whether the executable includes debugging information for that file, and
15847 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
15848 @item
15849 whether the debugging information includes information about
15850 preprocessor macros.
15851 @end itemize
15852
15853
15854 @kindex info sources
15855 @item info sources
15856 Print the names of all source files in your program for which there is
15857 debugging information, organized into two lists: files whose symbols
15858 have already been read, and files whose symbols will be read when needed.
15859
15860 @kindex info functions
15861 @item info functions
15862 Print the names and data types of all defined functions.
15863
15864 @item info functions @var{regexp}
15865 Print the names and data types of all defined functions
15866 whose names contain a match for regular expression @var{regexp}.
15867 Thus, @samp{info fun step} finds all functions whose names
15868 include @code{step}; @samp{info fun ^step} finds those whose names
15869 start with @code{step}. If a function name contains characters
15870 that conflict with the regular expression language (e.g.@:
15871 @samp{operator*()}), they may be quoted with a backslash.
15872
15873 @kindex info variables
15874 @item info variables
15875 Print the names and data types of all variables that are defined
15876 outside of functions (i.e.@: excluding local variables).
15877
15878 @item info variables @var{regexp}
15879 Print the names and data types of all variables (except for local
15880 variables) whose names contain a match for regular expression
15881 @var{regexp}.
15882
15883 @kindex info classes
15884 @cindex Objective-C, classes and selectors
15885 @item info classes
15886 @itemx info classes @var{regexp}
15887 Display all Objective-C classes in your program, or
15888 (with the @var{regexp} argument) all those matching a particular regular
15889 expression.
15890
15891 @kindex info selectors
15892 @item info selectors
15893 @itemx info selectors @var{regexp}
15894 Display all Objective-C selectors in your program, or
15895 (with the @var{regexp} argument) all those matching a particular regular
15896 expression.
15897
15898 @ignore
15899 This was never implemented.
15900 @kindex info methods
15901 @item info methods
15902 @itemx info methods @var{regexp}
15903 The @code{info methods} command permits the user to examine all defined
15904 methods within C@t{++} program, or (with the @var{regexp} argument) a
15905 specific set of methods found in the various C@t{++} classes. Many
15906 C@t{++} classes provide a large number of methods. Thus, the output
15907 from the @code{ptype} command can be overwhelming and hard to use. The
15908 @code{info-methods} command filters the methods, printing only those
15909 which match the regular-expression @var{regexp}.
15910 @end ignore
15911
15912 @cindex opaque data types
15913 @kindex set opaque-type-resolution
15914 @item set opaque-type-resolution on
15915 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
15916 declared as a pointer to a @code{struct}, @code{class}, or
15917 @code{union}---for example, @code{struct MyType *}---that is used in one
15918 source file although the full declaration of @code{struct MyType} is in
15919 another source file. The default is on.
15920
15921 A change in the setting of this subcommand will not take effect until
15922 the next time symbols for a file are loaded.
15923
15924 @item set opaque-type-resolution off
15925 Tell @value{GDBN} not to resolve opaque types. In this case, the type
15926 is printed as follows:
15927 @smallexample
15928 @{<no data fields>@}
15929 @end smallexample
15930
15931 @kindex show opaque-type-resolution
15932 @item show opaque-type-resolution
15933 Show whether opaque types are resolved or not.
15934
15935 @kindex maint print symbols
15936 @cindex symbol dump
15937 @kindex maint print psymbols
15938 @cindex partial symbol dump
15939 @kindex maint print msymbols
15940 @cindex minimal symbol dump
15941 @item maint print symbols @var{filename}
15942 @itemx maint print psymbols @var{filename}
15943 @itemx maint print msymbols @var{filename}
15944 Write a dump of debugging symbol data into the file @var{filename}.
15945 These commands are used to debug the @value{GDBN} symbol-reading code. Only
15946 symbols with debugging data are included. If you use @samp{maint print
15947 symbols}, @value{GDBN} includes all the symbols for which it has already
15948 collected full details: that is, @var{filename} reflects symbols for
15949 only those files whose symbols @value{GDBN} has read. You can use the
15950 command @code{info sources} to find out which files these are. If you
15951 use @samp{maint print psymbols} instead, the dump shows information about
15952 symbols that @value{GDBN} only knows partially---that is, symbols defined in
15953 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
15954 @samp{maint print msymbols} dumps just the minimal symbol information
15955 required for each object file from which @value{GDBN} has read some symbols.
15956 @xref{Files, ,Commands to Specify Files}, for a discussion of how
15957 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
15958
15959 @kindex maint info symtabs
15960 @kindex maint info psymtabs
15961 @cindex listing @value{GDBN}'s internal symbol tables
15962 @cindex symbol tables, listing @value{GDBN}'s internal
15963 @cindex full symbol tables, listing @value{GDBN}'s internal
15964 @cindex partial symbol tables, listing @value{GDBN}'s internal
15965 @item maint info symtabs @r{[} @var{regexp} @r{]}
15966 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
15967
15968 List the @code{struct symtab} or @code{struct partial_symtab}
15969 structures whose names match @var{regexp}. If @var{regexp} is not
15970 given, list them all. The output includes expressions which you can
15971 copy into a @value{GDBN} debugging this one to examine a particular
15972 structure in more detail. For example:
15973
15974 @smallexample
15975 (@value{GDBP}) maint info psymtabs dwarf2read
15976 @{ objfile /home/gnu/build/gdb/gdb
15977 ((struct objfile *) 0x82e69d0)
15978 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
15979 ((struct partial_symtab *) 0x8474b10)
15980 readin no
15981 fullname (null)
15982 text addresses 0x814d3c8 -- 0x8158074
15983 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
15984 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
15985 dependencies (none)
15986 @}
15987 @}
15988 (@value{GDBP}) maint info symtabs
15989 (@value{GDBP})
15990 @end smallexample
15991 @noindent
15992 We see that there is one partial symbol table whose filename contains
15993 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
15994 and we see that @value{GDBN} has not read in any symtabs yet at all.
15995 If we set a breakpoint on a function, that will cause @value{GDBN} to
15996 read the symtab for the compilation unit containing that function:
15997
15998 @smallexample
15999 (@value{GDBP}) break dwarf2_psymtab_to_symtab
16000 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
16001 line 1574.
16002 (@value{GDBP}) maint info symtabs
16003 @{ objfile /home/gnu/build/gdb/gdb
16004 ((struct objfile *) 0x82e69d0)
16005 @{ symtab /home/gnu/src/gdb/dwarf2read.c
16006 ((struct symtab *) 0x86c1f38)
16007 dirname (null)
16008 fullname (null)
16009 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
16010 linetable ((struct linetable *) 0x8370fa0)
16011 debugformat DWARF 2
16012 @}
16013 @}
16014 (@value{GDBP})
16015 @end smallexample
16016 @end table
16017
16018
16019 @node Altering
16020 @chapter Altering Execution
16021
16022 Once you think you have found an error in your program, you might want to
16023 find out for certain whether correcting the apparent error would lead to
16024 correct results in the rest of the run. You can find the answer by
16025 experiment, using the @value{GDBN} features for altering execution of the
16026 program.
16027
16028 For example, you can store new values into variables or memory
16029 locations, give your program a signal, restart it at a different
16030 address, or even return prematurely from a function.
16031
16032 @menu
16033 * Assignment:: Assignment to variables
16034 * Jumping:: Continuing at a different address
16035 * Signaling:: Giving your program a signal
16036 * Returning:: Returning from a function
16037 * Calling:: Calling your program's functions
16038 * Patching:: Patching your program
16039 @end menu
16040
16041 @node Assignment
16042 @section Assignment to Variables
16043
16044 @cindex assignment
16045 @cindex setting variables
16046 To alter the value of a variable, evaluate an assignment expression.
16047 @xref{Expressions, ,Expressions}. For example,
16048
16049 @smallexample
16050 print x=4
16051 @end smallexample
16052
16053 @noindent
16054 stores the value 4 into the variable @code{x}, and then prints the
16055 value of the assignment expression (which is 4).
16056 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
16057 information on operators in supported languages.
16058
16059 @kindex set variable
16060 @cindex variables, setting
16061 If you are not interested in seeing the value of the assignment, use the
16062 @code{set} command instead of the @code{print} command. @code{set} is
16063 really the same as @code{print} except that the expression's value is
16064 not printed and is not put in the value history (@pxref{Value History,
16065 ,Value History}). The expression is evaluated only for its effects.
16066
16067 If the beginning of the argument string of the @code{set} command
16068 appears identical to a @code{set} subcommand, use the @code{set
16069 variable} command instead of just @code{set}. This command is identical
16070 to @code{set} except for its lack of subcommands. For example, if your
16071 program has a variable @code{width}, you get an error if you try to set
16072 a new value with just @samp{set width=13}, because @value{GDBN} has the
16073 command @code{set width}:
16074
16075 @smallexample
16076 (@value{GDBP}) whatis width
16077 type = double
16078 (@value{GDBP}) p width
16079 $4 = 13
16080 (@value{GDBP}) set width=47
16081 Invalid syntax in expression.
16082 @end smallexample
16083
16084 @noindent
16085 The invalid expression, of course, is @samp{=47}. In
16086 order to actually set the program's variable @code{width}, use
16087
16088 @smallexample
16089 (@value{GDBP}) set var width=47
16090 @end smallexample
16091
16092 Because the @code{set} command has many subcommands that can conflict
16093 with the names of program variables, it is a good idea to use the
16094 @code{set variable} command instead of just @code{set}. For example, if
16095 your program has a variable @code{g}, you run into problems if you try
16096 to set a new value with just @samp{set g=4}, because @value{GDBN} has
16097 the command @code{set gnutarget}, abbreviated @code{set g}:
16098
16099 @smallexample
16100 @group
16101 (@value{GDBP}) whatis g
16102 type = double
16103 (@value{GDBP}) p g
16104 $1 = 1
16105 (@value{GDBP}) set g=4
16106 (@value{GDBP}) p g
16107 $2 = 1
16108 (@value{GDBP}) r
16109 The program being debugged has been started already.
16110 Start it from the beginning? (y or n) y
16111 Starting program: /home/smith/cc_progs/a.out
16112 "/home/smith/cc_progs/a.out": can't open to read symbols:
16113 Invalid bfd target.
16114 (@value{GDBP}) show g
16115 The current BFD target is "=4".
16116 @end group
16117 @end smallexample
16118
16119 @noindent
16120 The program variable @code{g} did not change, and you silently set the
16121 @code{gnutarget} to an invalid value. In order to set the variable
16122 @code{g}, use
16123
16124 @smallexample
16125 (@value{GDBP}) set var g=4
16126 @end smallexample
16127
16128 @value{GDBN} allows more implicit conversions in assignments than C; you can
16129 freely store an integer value into a pointer variable or vice versa,
16130 and you can convert any structure to any other structure that is the
16131 same length or shorter.
16132 @comment FIXME: how do structs align/pad in these conversions?
16133 @comment /doc@cygnus.com 18dec1990
16134
16135 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
16136 construct to generate a value of specified type at a specified address
16137 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
16138 to memory location @code{0x83040} as an integer (which implies a certain size
16139 and representation in memory), and
16140
16141 @smallexample
16142 set @{int@}0x83040 = 4
16143 @end smallexample
16144
16145 @noindent
16146 stores the value 4 into that memory location.
16147
16148 @node Jumping
16149 @section Continuing at a Different Address
16150
16151 Ordinarily, when you continue your program, you do so at the place where
16152 it stopped, with the @code{continue} command. You can instead continue at
16153 an address of your own choosing, with the following commands:
16154
16155 @table @code
16156 @kindex jump
16157 @kindex j @r{(@code{jump})}
16158 @item jump @var{linespec}
16159 @itemx j @var{linespec}
16160 @itemx jump @var{location}
16161 @itemx j @var{location}
16162 Resume execution at line @var{linespec} or at address given by
16163 @var{location}. Execution stops again immediately if there is a
16164 breakpoint there. @xref{Specify Location}, for a description of the
16165 different forms of @var{linespec} and @var{location}. It is common
16166 practice to use the @code{tbreak} command in conjunction with
16167 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
16168
16169 The @code{jump} command does not change the current stack frame, or
16170 the stack pointer, or the contents of any memory location or any
16171 register other than the program counter. If line @var{linespec} is in
16172 a different function from the one currently executing, the results may
16173 be bizarre if the two functions expect different patterns of arguments or
16174 of local variables. For this reason, the @code{jump} command requests
16175 confirmation if the specified line is not in the function currently
16176 executing. However, even bizarre results are predictable if you are
16177 well acquainted with the machine-language code of your program.
16178 @end table
16179
16180 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
16181 On many systems, you can get much the same effect as the @code{jump}
16182 command by storing a new value into the register @code{$pc}. The
16183 difference is that this does not start your program running; it only
16184 changes the address of where it @emph{will} run when you continue. For
16185 example,
16186
16187 @smallexample
16188 set $pc = 0x485
16189 @end smallexample
16190
16191 @noindent
16192 makes the next @code{continue} command or stepping command execute at
16193 address @code{0x485}, rather than at the address where your program stopped.
16194 @xref{Continuing and Stepping, ,Continuing and Stepping}.
16195
16196 The most common occasion to use the @code{jump} command is to back
16197 up---perhaps with more breakpoints set---over a portion of a program
16198 that has already executed, in order to examine its execution in more
16199 detail.
16200
16201 @c @group
16202 @node Signaling
16203 @section Giving your Program a Signal
16204 @cindex deliver a signal to a program
16205
16206 @table @code
16207 @kindex signal
16208 @item signal @var{signal}
16209 Resume execution where your program stopped, but immediately give it the
16210 signal @var{signal}. @var{signal} can be the name or the number of a
16211 signal. For example, on many systems @code{signal 2} and @code{signal
16212 SIGINT} are both ways of sending an interrupt signal.
16213
16214 Alternatively, if @var{signal} is zero, continue execution without
16215 giving a signal. This is useful when your program stopped on account of
16216 a signal and would ordinarily see the signal when resumed with the
16217 @code{continue} command; @samp{signal 0} causes it to resume without a
16218 signal.
16219
16220 @code{signal} does not repeat when you press @key{RET} a second time
16221 after executing the command.
16222 @end table
16223 @c @end group
16224
16225 Invoking the @code{signal} command is not the same as invoking the
16226 @code{kill} utility from the shell. Sending a signal with @code{kill}
16227 causes @value{GDBN} to decide what to do with the signal depending on
16228 the signal handling tables (@pxref{Signals}). The @code{signal} command
16229 passes the signal directly to your program.
16230
16231
16232 @node Returning
16233 @section Returning from a Function
16234
16235 @table @code
16236 @cindex returning from a function
16237 @kindex return
16238 @item return
16239 @itemx return @var{expression}
16240 You can cancel execution of a function call with the @code{return}
16241 command. If you give an
16242 @var{expression} argument, its value is used as the function's return
16243 value.
16244 @end table
16245
16246 When you use @code{return}, @value{GDBN} discards the selected stack frame
16247 (and all frames within it). You can think of this as making the
16248 discarded frame return prematurely. If you wish to specify a value to
16249 be returned, give that value as the argument to @code{return}.
16250
16251 This pops the selected stack frame (@pxref{Selection, ,Selecting a
16252 Frame}), and any other frames inside of it, leaving its caller as the
16253 innermost remaining frame. That frame becomes selected. The
16254 specified value is stored in the registers used for returning values
16255 of functions.
16256
16257 The @code{return} command does not resume execution; it leaves the
16258 program stopped in the state that would exist if the function had just
16259 returned. In contrast, the @code{finish} command (@pxref{Continuing
16260 and Stepping, ,Continuing and Stepping}) resumes execution until the
16261 selected stack frame returns naturally.
16262
16263 @value{GDBN} needs to know how the @var{expression} argument should be set for
16264 the inferior. The concrete registers assignment depends on the OS ABI and the
16265 type being returned by the selected stack frame. For example it is common for
16266 OS ABI to return floating point values in FPU registers while integer values in
16267 CPU registers. Still some ABIs return even floating point values in CPU
16268 registers. Larger integer widths (such as @code{long long int}) also have
16269 specific placement rules. @value{GDBN} already knows the OS ABI from its
16270 current target so it needs to find out also the type being returned to make the
16271 assignment into the right register(s).
16272
16273 Normally, the selected stack frame has debug info. @value{GDBN} will always
16274 use the debug info instead of the implicit type of @var{expression} when the
16275 debug info is available. For example, if you type @kbd{return -1}, and the
16276 function in the current stack frame is declared to return a @code{long long
16277 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
16278 into a @code{long long int}:
16279
16280 @smallexample
16281 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
16282 29 return 31;
16283 (@value{GDBP}) return -1
16284 Make func return now? (y or n) y
16285 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
16286 43 printf ("result=%lld\n", func ());
16287 (@value{GDBP})
16288 @end smallexample
16289
16290 However, if the selected stack frame does not have a debug info, e.g., if the
16291 function was compiled without debug info, @value{GDBN} has to find out the type
16292 to return from user. Specifying a different type by mistake may set the value
16293 in different inferior registers than the caller code expects. For example,
16294 typing @kbd{return -1} with its implicit type @code{int} would set only a part
16295 of a @code{long long int} result for a debug info less function (on 32-bit
16296 architectures). Therefore the user is required to specify the return type by
16297 an appropriate cast explicitly:
16298
16299 @smallexample
16300 Breakpoint 2, 0x0040050b in func ()
16301 (@value{GDBP}) return -1
16302 Return value type not available for selected stack frame.
16303 Please use an explicit cast of the value to return.
16304 (@value{GDBP}) return (long long int) -1
16305 Make selected stack frame return now? (y or n) y
16306 #0 0x00400526 in main ()
16307 (@value{GDBP})
16308 @end smallexample
16309
16310 @node Calling
16311 @section Calling Program Functions
16312
16313 @table @code
16314 @cindex calling functions
16315 @cindex inferior functions, calling
16316 @item print @var{expr}
16317 Evaluate the expression @var{expr} and display the resulting value.
16318 @var{expr} may include calls to functions in the program being
16319 debugged.
16320
16321 @kindex call
16322 @item call @var{expr}
16323 Evaluate the expression @var{expr} without displaying @code{void}
16324 returned values.
16325
16326 You can use this variant of the @code{print} command if you want to
16327 execute a function from your program that does not return anything
16328 (a.k.a.@: @dfn{a void function}), but without cluttering the output
16329 with @code{void} returned values that @value{GDBN} will otherwise
16330 print. If the result is not void, it is printed and saved in the
16331 value history.
16332 @end table
16333
16334 It is possible for the function you call via the @code{print} or
16335 @code{call} command to generate a signal (e.g., if there's a bug in
16336 the function, or if you passed it incorrect arguments). What happens
16337 in that case is controlled by the @code{set unwindonsignal} command.
16338
16339 Similarly, with a C@t{++} program it is possible for the function you
16340 call via the @code{print} or @code{call} command to generate an
16341 exception that is not handled due to the constraints of the dummy
16342 frame. In this case, any exception that is raised in the frame, but has
16343 an out-of-frame exception handler will not be found. GDB builds a
16344 dummy-frame for the inferior function call, and the unwinder cannot
16345 seek for exception handlers outside of this dummy-frame. What happens
16346 in that case is controlled by the
16347 @code{set unwind-on-terminating-exception} command.
16348
16349 @table @code
16350 @item set unwindonsignal
16351 @kindex set unwindonsignal
16352 @cindex unwind stack in called functions
16353 @cindex call dummy stack unwinding
16354 Set unwinding of the stack if a signal is received while in a function
16355 that @value{GDBN} called in the program being debugged. If set to on,
16356 @value{GDBN} unwinds the stack it created for the call and restores
16357 the context to what it was before the call. If set to off (the
16358 default), @value{GDBN} stops in the frame where the signal was
16359 received.
16360
16361 @item show unwindonsignal
16362 @kindex show unwindonsignal
16363 Show the current setting of stack unwinding in the functions called by
16364 @value{GDBN}.
16365
16366 @item set unwind-on-terminating-exception
16367 @kindex set unwind-on-terminating-exception
16368 @cindex unwind stack in called functions with unhandled exceptions
16369 @cindex call dummy stack unwinding on unhandled exception.
16370 Set unwinding of the stack if a C@t{++} exception is raised, but left
16371 unhandled while in a function that @value{GDBN} called in the program being
16372 debugged. If set to on (the default), @value{GDBN} unwinds the stack
16373 it created for the call and restores the context to what it was before
16374 the call. If set to off, @value{GDBN} the exception is delivered to
16375 the default C@t{++} exception handler and the inferior terminated.
16376
16377 @item show unwind-on-terminating-exception
16378 @kindex show unwind-on-terminating-exception
16379 Show the current setting of stack unwinding in the functions called by
16380 @value{GDBN}.
16381
16382 @end table
16383
16384 @cindex weak alias functions
16385 Sometimes, a function you wish to call is actually a @dfn{weak alias}
16386 for another function. In such case, @value{GDBN} might not pick up
16387 the type information, including the types of the function arguments,
16388 which causes @value{GDBN} to call the inferior function incorrectly.
16389 As a result, the called function will function erroneously and may
16390 even crash. A solution to that is to use the name of the aliased
16391 function instead.
16392
16393 @node Patching
16394 @section Patching Programs
16395
16396 @cindex patching binaries
16397 @cindex writing into executables
16398 @cindex writing into corefiles
16399
16400 By default, @value{GDBN} opens the file containing your program's
16401 executable code (or the corefile) read-only. This prevents accidental
16402 alterations to machine code; but it also prevents you from intentionally
16403 patching your program's binary.
16404
16405 If you'd like to be able to patch the binary, you can specify that
16406 explicitly with the @code{set write} command. For example, you might
16407 want to turn on internal debugging flags, or even to make emergency
16408 repairs.
16409
16410 @table @code
16411 @kindex set write
16412 @item set write on
16413 @itemx set write off
16414 If you specify @samp{set write on}, @value{GDBN} opens executable and
16415 core files for both reading and writing; if you specify @kbd{set write
16416 off} (the default), @value{GDBN} opens them read-only.
16417
16418 If you have already loaded a file, you must load it again (using the
16419 @code{exec-file} or @code{core-file} command) after changing @code{set
16420 write}, for your new setting to take effect.
16421
16422 @item show write
16423 @kindex show write
16424 Display whether executable files and core files are opened for writing
16425 as well as reading.
16426 @end table
16427
16428 @node GDB Files
16429 @chapter @value{GDBN} Files
16430
16431 @value{GDBN} needs to know the file name of the program to be debugged,
16432 both in order to read its symbol table and in order to start your
16433 program. To debug a core dump of a previous run, you must also tell
16434 @value{GDBN} the name of the core dump file.
16435
16436 @menu
16437 * Files:: Commands to specify files
16438 * Separate Debug Files:: Debugging information in separate files
16439 * MiniDebugInfo:: Debugging information in a special section
16440 * Index Files:: Index files speed up GDB
16441 * Symbol Errors:: Errors reading symbol files
16442 * Data Files:: GDB data files
16443 @end menu
16444
16445 @node Files
16446 @section Commands to Specify Files
16447
16448 @cindex symbol table
16449 @cindex core dump file
16450
16451 You may want to specify executable and core dump file names. The usual
16452 way to do this is at start-up time, using the arguments to
16453 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
16454 Out of @value{GDBN}}).
16455
16456 Occasionally it is necessary to change to a different file during a
16457 @value{GDBN} session. Or you may run @value{GDBN} and forget to
16458 specify a file you want to use. Or you are debugging a remote target
16459 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
16460 Program}). In these situations the @value{GDBN} commands to specify
16461 new files are useful.
16462
16463 @table @code
16464 @cindex executable file
16465 @kindex file
16466 @item file @var{filename}
16467 Use @var{filename} as the program to be debugged. It is read for its
16468 symbols and for the contents of pure memory. It is also the program
16469 executed when you use the @code{run} command. If you do not specify a
16470 directory and the file is not found in the @value{GDBN} working directory,
16471 @value{GDBN} uses the environment variable @code{PATH} as a list of
16472 directories to search, just as the shell does when looking for a program
16473 to run. You can change the value of this variable, for both @value{GDBN}
16474 and your program, using the @code{path} command.
16475
16476 @cindex unlinked object files
16477 @cindex patching object files
16478 You can load unlinked object @file{.o} files into @value{GDBN} using
16479 the @code{file} command. You will not be able to ``run'' an object
16480 file, but you can disassemble functions and inspect variables. Also,
16481 if the underlying BFD functionality supports it, you could use
16482 @kbd{gdb -write} to patch object files using this technique. Note
16483 that @value{GDBN} can neither interpret nor modify relocations in this
16484 case, so branches and some initialized variables will appear to go to
16485 the wrong place. But this feature is still handy from time to time.
16486
16487 @item file
16488 @code{file} with no argument makes @value{GDBN} discard any information it
16489 has on both executable file and the symbol table.
16490
16491 @kindex exec-file
16492 @item exec-file @r{[} @var{filename} @r{]}
16493 Specify that the program to be run (but not the symbol table) is found
16494 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
16495 if necessary to locate your program. Omitting @var{filename} means to
16496 discard information on the executable file.
16497
16498 @kindex symbol-file
16499 @item symbol-file @r{[} @var{filename} @r{]}
16500 Read symbol table information from file @var{filename}. @code{PATH} is
16501 searched when necessary. Use the @code{file} command to get both symbol
16502 table and program to run from the same file.
16503
16504 @code{symbol-file} with no argument clears out @value{GDBN} information on your
16505 program's symbol table.
16506
16507 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
16508 some breakpoints and auto-display expressions. This is because they may
16509 contain pointers to the internal data recording symbols and data types,
16510 which are part of the old symbol table data being discarded inside
16511 @value{GDBN}.
16512
16513 @code{symbol-file} does not repeat if you press @key{RET} again after
16514 executing it once.
16515
16516 When @value{GDBN} is configured for a particular environment, it
16517 understands debugging information in whatever format is the standard
16518 generated for that environment; you may use either a @sc{gnu} compiler, or
16519 other compilers that adhere to the local conventions.
16520 Best results are usually obtained from @sc{gnu} compilers; for example,
16521 using @code{@value{NGCC}} you can generate debugging information for
16522 optimized code.
16523
16524 For most kinds of object files, with the exception of old SVR3 systems
16525 using COFF, the @code{symbol-file} command does not normally read the
16526 symbol table in full right away. Instead, it scans the symbol table
16527 quickly to find which source files and which symbols are present. The
16528 details are read later, one source file at a time, as they are needed.
16529
16530 The purpose of this two-stage reading strategy is to make @value{GDBN}
16531 start up faster. For the most part, it is invisible except for
16532 occasional pauses while the symbol table details for a particular source
16533 file are being read. (The @code{set verbose} command can turn these
16534 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
16535 Warnings and Messages}.)
16536
16537 We have not implemented the two-stage strategy for COFF yet. When the
16538 symbol table is stored in COFF format, @code{symbol-file} reads the
16539 symbol table data in full right away. Note that ``stabs-in-COFF''
16540 still does the two-stage strategy, since the debug info is actually
16541 in stabs format.
16542
16543 @kindex readnow
16544 @cindex reading symbols immediately
16545 @cindex symbols, reading immediately
16546 @item symbol-file @r{[} -readnow @r{]} @var{filename}
16547 @itemx file @r{[} -readnow @r{]} @var{filename}
16548 You can override the @value{GDBN} two-stage strategy for reading symbol
16549 tables by using the @samp{-readnow} option with any of the commands that
16550 load symbol table information, if you want to be sure @value{GDBN} has the
16551 entire symbol table available.
16552
16553 @c FIXME: for now no mention of directories, since this seems to be in
16554 @c flux. 13mar1992 status is that in theory GDB would look either in
16555 @c current dir or in same dir as myprog; but issues like competing
16556 @c GDB's, or clutter in system dirs, mean that in practice right now
16557 @c only current dir is used. FFish says maybe a special GDB hierarchy
16558 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
16559 @c files.
16560
16561 @kindex core-file
16562 @item core-file @r{[}@var{filename}@r{]}
16563 @itemx core
16564 Specify the whereabouts of a core dump file to be used as the ``contents
16565 of memory''. Traditionally, core files contain only some parts of the
16566 address space of the process that generated them; @value{GDBN} can access the
16567 executable file itself for other parts.
16568
16569 @code{core-file} with no argument specifies that no core file is
16570 to be used.
16571
16572 Note that the core file is ignored when your program is actually running
16573 under @value{GDBN}. So, if you have been running your program and you
16574 wish to debug a core file instead, you must kill the subprocess in which
16575 the program is running. To do this, use the @code{kill} command
16576 (@pxref{Kill Process, ,Killing the Child Process}).
16577
16578 @kindex add-symbol-file
16579 @cindex dynamic linking
16580 @item add-symbol-file @var{filename} @var{address}
16581 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
16582 @itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
16583 The @code{add-symbol-file} command reads additional symbol table
16584 information from the file @var{filename}. You would use this command
16585 when @var{filename} has been dynamically loaded (by some other means)
16586 into the program that is running. @var{address} should be the memory
16587 address at which the file has been loaded; @value{GDBN} cannot figure
16588 this out for itself. You can additionally specify an arbitrary number
16589 of @samp{-s @var{section} @var{address}} pairs, to give an explicit
16590 section name and base address for that section. You can specify any
16591 @var{address} as an expression.
16592
16593 The symbol table of the file @var{filename} is added to the symbol table
16594 originally read with the @code{symbol-file} command. You can use the
16595 @code{add-symbol-file} command any number of times; the new symbol data
16596 thus read keeps adding to the old. To discard all old symbol data
16597 instead, use the @code{symbol-file} command without any arguments.
16598
16599 @cindex relocatable object files, reading symbols from
16600 @cindex object files, relocatable, reading symbols from
16601 @cindex reading symbols from relocatable object files
16602 @cindex symbols, reading from relocatable object files
16603 @cindex @file{.o} files, reading symbols from
16604 Although @var{filename} is typically a shared library file, an
16605 executable file, or some other object file which has been fully
16606 relocated for loading into a process, you can also load symbolic
16607 information from relocatable @file{.o} files, as long as:
16608
16609 @itemize @bullet
16610 @item
16611 the file's symbolic information refers only to linker symbols defined in
16612 that file, not to symbols defined by other object files,
16613 @item
16614 every section the file's symbolic information refers to has actually
16615 been loaded into the inferior, as it appears in the file, and
16616 @item
16617 you can determine the address at which every section was loaded, and
16618 provide these to the @code{add-symbol-file} command.
16619 @end itemize
16620
16621 @noindent
16622 Some embedded operating systems, like Sun Chorus and VxWorks, can load
16623 relocatable files into an already running program; such systems
16624 typically make the requirements above easy to meet. However, it's
16625 important to recognize that many native systems use complex link
16626 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
16627 assembly, for example) that make the requirements difficult to meet. In
16628 general, one cannot assume that using @code{add-symbol-file} to read a
16629 relocatable object file's symbolic information will have the same effect
16630 as linking the relocatable object file into the program in the normal
16631 way.
16632
16633 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
16634
16635 @kindex add-symbol-file-from-memory
16636 @cindex @code{syscall DSO}
16637 @cindex load symbols from memory
16638 @item add-symbol-file-from-memory @var{address}
16639 Load symbols from the given @var{address} in a dynamically loaded
16640 object file whose image is mapped directly into the inferior's memory.
16641 For example, the Linux kernel maps a @code{syscall DSO} into each
16642 process's address space; this DSO provides kernel-specific code for
16643 some system calls. The argument can be any expression whose
16644 evaluation yields the address of the file's shared object file header.
16645 For this command to work, you must have used @code{symbol-file} or
16646 @code{exec-file} commands in advance.
16647
16648 @kindex add-shared-symbol-files
16649 @kindex assf
16650 @item add-shared-symbol-files @var{library-file}
16651 @itemx assf @var{library-file}
16652 The @code{add-shared-symbol-files} command can currently be used only
16653 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
16654 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
16655 @value{GDBN} automatically looks for shared libraries, however if
16656 @value{GDBN} does not find yours, you can invoke
16657 @code{add-shared-symbol-files}. It takes one argument: the shared
16658 library's file name. @code{assf} is a shorthand alias for
16659 @code{add-shared-symbol-files}.
16660
16661 @kindex section
16662 @item section @var{section} @var{addr}
16663 The @code{section} command changes the base address of the named
16664 @var{section} of the exec file to @var{addr}. This can be used if the
16665 exec file does not contain section addresses, (such as in the
16666 @code{a.out} format), or when the addresses specified in the file
16667 itself are wrong. Each section must be changed separately. The
16668 @code{info files} command, described below, lists all the sections and
16669 their addresses.
16670
16671 @kindex info files
16672 @kindex info target
16673 @item info files
16674 @itemx info target
16675 @code{info files} and @code{info target} are synonymous; both print the
16676 current target (@pxref{Targets, ,Specifying a Debugging Target}),
16677 including the names of the executable and core dump files currently in
16678 use by @value{GDBN}, and the files from which symbols were loaded. The
16679 command @code{help target} lists all possible targets rather than
16680 current ones.
16681
16682 @kindex maint info sections
16683 @item maint info sections
16684 Another command that can give you extra information about program sections
16685 is @code{maint info sections}. In addition to the section information
16686 displayed by @code{info files}, this command displays the flags and file
16687 offset of each section in the executable and core dump files. In addition,
16688 @code{maint info sections} provides the following command options (which
16689 may be arbitrarily combined):
16690
16691 @table @code
16692 @item ALLOBJ
16693 Display sections for all loaded object files, including shared libraries.
16694 @item @var{sections}
16695 Display info only for named @var{sections}.
16696 @item @var{section-flags}
16697 Display info only for sections for which @var{section-flags} are true.
16698 The section flags that @value{GDBN} currently knows about are:
16699 @table @code
16700 @item ALLOC
16701 Section will have space allocated in the process when loaded.
16702 Set for all sections except those containing debug information.
16703 @item LOAD
16704 Section will be loaded from the file into the child process memory.
16705 Set for pre-initialized code and data, clear for @code{.bss} sections.
16706 @item RELOC
16707 Section needs to be relocated before loading.
16708 @item READONLY
16709 Section cannot be modified by the child process.
16710 @item CODE
16711 Section contains executable code only.
16712 @item DATA
16713 Section contains data only (no executable code).
16714 @item ROM
16715 Section will reside in ROM.
16716 @item CONSTRUCTOR
16717 Section contains data for constructor/destructor lists.
16718 @item HAS_CONTENTS
16719 Section is not empty.
16720 @item NEVER_LOAD
16721 An instruction to the linker to not output the section.
16722 @item COFF_SHARED_LIBRARY
16723 A notification to the linker that the section contains
16724 COFF shared library information.
16725 @item IS_COMMON
16726 Section contains common symbols.
16727 @end table
16728 @end table
16729 @kindex set trust-readonly-sections
16730 @cindex read-only sections
16731 @item set trust-readonly-sections on
16732 Tell @value{GDBN} that readonly sections in your object file
16733 really are read-only (i.e.@: that their contents will not change).
16734 In that case, @value{GDBN} can fetch values from these sections
16735 out of the object file, rather than from the target program.
16736 For some targets (notably embedded ones), this can be a significant
16737 enhancement to debugging performance.
16738
16739 The default is off.
16740
16741 @item set trust-readonly-sections off
16742 Tell @value{GDBN} not to trust readonly sections. This means that
16743 the contents of the section might change while the program is running,
16744 and must therefore be fetched from the target when needed.
16745
16746 @item show trust-readonly-sections
16747 Show the current setting of trusting readonly sections.
16748 @end table
16749
16750 All file-specifying commands allow both absolute and relative file names
16751 as arguments. @value{GDBN} always converts the file name to an absolute file
16752 name and remembers it that way.
16753
16754 @cindex shared libraries
16755 @anchor{Shared Libraries}
16756 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
16757 and IBM RS/6000 AIX shared libraries.
16758
16759 On MS-Windows @value{GDBN} must be linked with the Expat library to support
16760 shared libraries. @xref{Expat}.
16761
16762 @value{GDBN} automatically loads symbol definitions from shared libraries
16763 when you use the @code{run} command, or when you examine a core file.
16764 (Before you issue the @code{run} command, @value{GDBN} does not understand
16765 references to a function in a shared library, however---unless you are
16766 debugging a core file).
16767
16768 On HP-UX, if the program loads a library explicitly, @value{GDBN}
16769 automatically loads the symbols at the time of the @code{shl_load} call.
16770
16771 @c FIXME: some @value{GDBN} release may permit some refs to undef
16772 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
16773 @c FIXME...lib; check this from time to time when updating manual
16774
16775 There are times, however, when you may wish to not automatically load
16776 symbol definitions from shared libraries, such as when they are
16777 particularly large or there are many of them.
16778
16779 To control the automatic loading of shared library symbols, use the
16780 commands:
16781
16782 @table @code
16783 @kindex set auto-solib-add
16784 @item set auto-solib-add @var{mode}
16785 If @var{mode} is @code{on}, symbols from all shared object libraries
16786 will be loaded automatically when the inferior begins execution, you
16787 attach to an independently started inferior, or when the dynamic linker
16788 informs @value{GDBN} that a new library has been loaded. If @var{mode}
16789 is @code{off}, symbols must be loaded manually, using the
16790 @code{sharedlibrary} command. The default value is @code{on}.
16791
16792 @cindex memory used for symbol tables
16793 If your program uses lots of shared libraries with debug info that
16794 takes large amounts of memory, you can decrease the @value{GDBN}
16795 memory footprint by preventing it from automatically loading the
16796 symbols from shared libraries. To that end, type @kbd{set
16797 auto-solib-add off} before running the inferior, then load each
16798 library whose debug symbols you do need with @kbd{sharedlibrary
16799 @var{regexp}}, where @var{regexp} is a regular expression that matches
16800 the libraries whose symbols you want to be loaded.
16801
16802 @kindex show auto-solib-add
16803 @item show auto-solib-add
16804 Display the current autoloading mode.
16805 @end table
16806
16807 @cindex load shared library
16808 To explicitly load shared library symbols, use the @code{sharedlibrary}
16809 command:
16810
16811 @table @code
16812 @kindex info sharedlibrary
16813 @kindex info share
16814 @item info share @var{regex}
16815 @itemx info sharedlibrary @var{regex}
16816 Print the names of the shared libraries which are currently loaded
16817 that match @var{regex}. If @var{regex} is omitted then print
16818 all shared libraries that are loaded.
16819
16820 @kindex sharedlibrary
16821 @kindex share
16822 @item sharedlibrary @var{regex}
16823 @itemx share @var{regex}
16824 Load shared object library symbols for files matching a
16825 Unix regular expression.
16826 As with files loaded automatically, it only loads shared libraries
16827 required by your program for a core file or after typing @code{run}. If
16828 @var{regex} is omitted all shared libraries required by your program are
16829 loaded.
16830
16831 @item nosharedlibrary
16832 @kindex nosharedlibrary
16833 @cindex unload symbols from shared libraries
16834 Unload all shared object library symbols. This discards all symbols
16835 that have been loaded from all shared libraries. Symbols from shared
16836 libraries that were loaded by explicit user requests are not
16837 discarded.
16838 @end table
16839
16840 Sometimes you may wish that @value{GDBN} stops and gives you control
16841 when any of shared library events happen. The best way to do this is
16842 to use @code{catch load} and @code{catch unload} (@pxref{Set
16843 Catchpoints}).
16844
16845 @value{GDBN} also supports the the @code{set stop-on-solib-events}
16846 command for this. This command exists for historical reasons. It is
16847 less useful than setting a catchpoint, because it does not allow for
16848 conditions or commands as a catchpoint does.
16849
16850 @table @code
16851 @item set stop-on-solib-events
16852 @kindex set stop-on-solib-events
16853 This command controls whether @value{GDBN} should give you control
16854 when the dynamic linker notifies it about some shared library event.
16855 The most common event of interest is loading or unloading of a new
16856 shared library.
16857
16858 @item show stop-on-solib-events
16859 @kindex show stop-on-solib-events
16860 Show whether @value{GDBN} stops and gives you control when shared
16861 library events happen.
16862 @end table
16863
16864 Shared libraries are also supported in many cross or remote debugging
16865 configurations. @value{GDBN} needs to have access to the target's libraries;
16866 this can be accomplished either by providing copies of the libraries
16867 on the host system, or by asking @value{GDBN} to automatically retrieve the
16868 libraries from the target. If copies of the target libraries are
16869 provided, they need to be the same as the target libraries, although the
16870 copies on the target can be stripped as long as the copies on the host are
16871 not.
16872
16873 @cindex where to look for shared libraries
16874 For remote debugging, you need to tell @value{GDBN} where the target
16875 libraries are, so that it can load the correct copies---otherwise, it
16876 may try to load the host's libraries. @value{GDBN} has two variables
16877 to specify the search directories for target libraries.
16878
16879 @table @code
16880 @cindex prefix for shared library file names
16881 @cindex system root, alternate
16882 @kindex set solib-absolute-prefix
16883 @kindex set sysroot
16884 @item set sysroot @var{path}
16885 Use @var{path} as the system root for the program being debugged. Any
16886 absolute shared library paths will be prefixed with @var{path}; many
16887 runtime loaders store the absolute paths to the shared library in the
16888 target program's memory. If you use @code{set sysroot} to find shared
16889 libraries, they need to be laid out in the same way that they are on
16890 the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
16891 under @var{path}.
16892
16893 If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
16894 retrieve the target libraries from the remote system. This is only
16895 supported when using a remote target that supports the @code{remote get}
16896 command (@pxref{File Transfer,,Sending files to a remote system}).
16897 The part of @var{path} following the initial @file{remote:}
16898 (if present) is used as system root prefix on the remote file system.
16899 @footnote{If you want to specify a local system root using a directory
16900 that happens to be named @file{remote:}, you need to use some equivalent
16901 variant of the name like @file{./remote:}.}
16902
16903 For targets with an MS-DOS based filesystem, such as MS-Windows and
16904 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
16905 absolute file name with @var{path}. But first, on Unix hosts,
16906 @value{GDBN} converts all backslash directory separators into forward
16907 slashes, because the backslash is not a directory separator on Unix:
16908
16909 @smallexample
16910 c:\foo\bar.dll @result{} c:/foo/bar.dll
16911 @end smallexample
16912
16913 Then, @value{GDBN} attempts prefixing the target file name with
16914 @var{path}, and looks for the resulting file name in the host file
16915 system:
16916
16917 @smallexample
16918 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
16919 @end smallexample
16920
16921 If that does not find the shared library, @value{GDBN} tries removing
16922 the @samp{:} character from the drive spec, both for convenience, and,
16923 for the case of the host file system not supporting file names with
16924 colons:
16925
16926 @smallexample
16927 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
16928 @end smallexample
16929
16930 This makes it possible to have a system root that mirrors a target
16931 with more than one drive. E.g., you may want to setup your local
16932 copies of the target system shared libraries like so (note @samp{c} vs
16933 @samp{z}):
16934
16935 @smallexample
16936 @file{/path/to/sysroot/c/sys/bin/foo.dll}
16937 @file{/path/to/sysroot/c/sys/bin/bar.dll}
16938 @file{/path/to/sysroot/z/sys/bin/bar.dll}
16939 @end smallexample
16940
16941 @noindent
16942 and point the system root at @file{/path/to/sysroot}, so that
16943 @value{GDBN} can find the correct copies of both
16944 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
16945
16946 If that still does not find the shared library, @value{GDBN} tries
16947 removing the whole drive spec from the target file name:
16948
16949 @smallexample
16950 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
16951 @end smallexample
16952
16953 This last lookup makes it possible to not care about the drive name,
16954 if you don't want or need to.
16955
16956 The @code{set solib-absolute-prefix} command is an alias for @code{set
16957 sysroot}.
16958
16959 @cindex default system root
16960 @cindex @samp{--with-sysroot}
16961 You can set the default system root by using the configure-time
16962 @samp{--with-sysroot} option. If the system root is inside
16963 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
16964 @samp{--exec-prefix}), then the default system root will be updated
16965 automatically if the installed @value{GDBN} is moved to a new
16966 location.
16967
16968 @kindex show sysroot
16969 @item show sysroot
16970 Display the current shared library prefix.
16971
16972 @kindex set solib-search-path
16973 @item set solib-search-path @var{path}
16974 If this variable is set, @var{path} is a colon-separated list of
16975 directories to search for shared libraries. @samp{solib-search-path}
16976 is used after @samp{sysroot} fails to locate the library, or if the
16977 path to the library is relative instead of absolute. If you want to
16978 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
16979 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
16980 finding your host's libraries. @samp{sysroot} is preferred; setting
16981 it to a nonexistent directory may interfere with automatic loading
16982 of shared library symbols.
16983
16984 @kindex show solib-search-path
16985 @item show solib-search-path
16986 Display the current shared library search path.
16987
16988 @cindex DOS file-name semantics of file names.
16989 @kindex set target-file-system-kind (unix|dos-based|auto)
16990 @kindex show target-file-system-kind
16991 @item set target-file-system-kind @var{kind}
16992 Set assumed file system kind for target reported file names.
16993
16994 Shared library file names as reported by the target system may not
16995 make sense as is on the system @value{GDBN} is running on. For
16996 example, when remote debugging a target that has MS-DOS based file
16997 system semantics, from a Unix host, the target may be reporting to
16998 @value{GDBN} a list of loaded shared libraries with file names such as
16999 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
17000 drive letters, so the @samp{c:\} prefix is not normally understood as
17001 indicating an absolute file name, and neither is the backslash
17002 normally considered a directory separator character. In that case,
17003 the native file system would interpret this whole absolute file name
17004 as a relative file name with no directory components. This would make
17005 it impossible to point @value{GDBN} at a copy of the remote target's
17006 shared libraries on the host using @code{set sysroot}, and impractical
17007 with @code{set solib-search-path}. Setting
17008 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
17009 to interpret such file names similarly to how the target would, and to
17010 map them to file names valid on @value{GDBN}'s native file system
17011 semantics. The value of @var{kind} can be @code{"auto"}, in addition
17012 to one of the supported file system kinds. In that case, @value{GDBN}
17013 tries to determine the appropriate file system variant based on the
17014 current target's operating system (@pxref{ABI, ,Configuring the
17015 Current ABI}). The supported file system settings are:
17016
17017 @table @code
17018 @item unix
17019 Instruct @value{GDBN} to assume the target file system is of Unix
17020 kind. Only file names starting the forward slash (@samp{/}) character
17021 are considered absolute, and the directory separator character is also
17022 the forward slash.
17023
17024 @item dos-based
17025 Instruct @value{GDBN} to assume the target file system is DOS based.
17026 File names starting with either a forward slash, or a drive letter
17027 followed by a colon (e.g., @samp{c:}), are considered absolute, and
17028 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
17029 considered directory separators.
17030
17031 @item auto
17032 Instruct @value{GDBN} to use the file system kind associated with the
17033 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
17034 This is the default.
17035 @end table
17036 @end table
17037
17038 @cindex file name canonicalization
17039 @cindex base name differences
17040 When processing file names provided by the user, @value{GDBN}
17041 frequently needs to compare them to the file names recorded in the
17042 program's debug info. Normally, @value{GDBN} compares just the
17043 @dfn{base names} of the files as strings, which is reasonably fast
17044 even for very large programs. (The base name of a file is the last
17045 portion of its name, after stripping all the leading directories.)
17046 This shortcut in comparison is based upon the assumption that files
17047 cannot have more than one base name. This is usually true, but
17048 references to files that use symlinks or similar filesystem
17049 facilities violate that assumption. If your program records files
17050 using such facilities, or if you provide file names to @value{GDBN}
17051 using symlinks etc., you can set @code{basenames-may-differ} to
17052 @code{true} to instruct @value{GDBN} to completely canonicalize each
17053 pair of file names it needs to compare. This will make file-name
17054 comparisons accurate, but at a price of a significant slowdown.
17055
17056 @table @code
17057 @item set basenames-may-differ
17058 @kindex set basenames-may-differ
17059 Set whether a source file may have multiple base names.
17060
17061 @item show basenames-may-differ
17062 @kindex show basenames-may-differ
17063 Show whether a source file may have multiple base names.
17064 @end table
17065
17066 @node Separate Debug Files
17067 @section Debugging Information in Separate Files
17068 @cindex separate debugging information files
17069 @cindex debugging information in separate files
17070 @cindex @file{.debug} subdirectories
17071 @cindex debugging information directory, global
17072 @cindex global debugging information directories
17073 @cindex build ID, and separate debugging files
17074 @cindex @file{.build-id} directory
17075
17076 @value{GDBN} allows you to put a program's debugging information in a
17077 file separate from the executable itself, in a way that allows
17078 @value{GDBN} to find and load the debugging information automatically.
17079 Since debugging information can be very large---sometimes larger
17080 than the executable code itself---some systems distribute debugging
17081 information for their executables in separate files, which users can
17082 install only when they need to debug a problem.
17083
17084 @value{GDBN} supports two ways of specifying the separate debug info
17085 file:
17086
17087 @itemize @bullet
17088 @item
17089 The executable contains a @dfn{debug link} that specifies the name of
17090 the separate debug info file. The separate debug file's name is
17091 usually @file{@var{executable}.debug}, where @var{executable} is the
17092 name of the corresponding executable file without leading directories
17093 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
17094 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
17095 checksum for the debug file, which @value{GDBN} uses to validate that
17096 the executable and the debug file came from the same build.
17097
17098 @item
17099 The executable contains a @dfn{build ID}, a unique bit string that is
17100 also present in the corresponding debug info file. (This is supported
17101 only on some operating systems, notably those which use the ELF format
17102 for binary files and the @sc{gnu} Binutils.) For more details about
17103 this feature, see the description of the @option{--build-id}
17104 command-line option in @ref{Options, , Command Line Options, ld.info,
17105 The GNU Linker}. The debug info file's name is not specified
17106 explicitly by the build ID, but can be computed from the build ID, see
17107 below.
17108 @end itemize
17109
17110 Depending on the way the debug info file is specified, @value{GDBN}
17111 uses two different methods of looking for the debug file:
17112
17113 @itemize @bullet
17114 @item
17115 For the ``debug link'' method, @value{GDBN} looks up the named file in
17116 the directory of the executable file, then in a subdirectory of that
17117 directory named @file{.debug}, and finally under each one of the global debug
17118 directories, in a subdirectory whose name is identical to the leading
17119 directories of the executable's absolute file name.
17120
17121 @item
17122 For the ``build ID'' method, @value{GDBN} looks in the
17123 @file{.build-id} subdirectory of each one of the global debug directories for
17124 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
17125 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
17126 are the rest of the bit string. (Real build ID strings are 32 or more
17127 hex characters, not 10.)
17128 @end itemize
17129
17130 So, for example, suppose you ask @value{GDBN} to debug
17131 @file{/usr/bin/ls}, which has a debug link that specifies the
17132 file @file{ls.debug}, and a build ID whose value in hex is
17133 @code{abcdef1234}. If the list of the global debug directories includes
17134 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
17135 debug information files, in the indicated order:
17136
17137 @itemize @minus
17138 @item
17139 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
17140 @item
17141 @file{/usr/bin/ls.debug}
17142 @item
17143 @file{/usr/bin/.debug/ls.debug}
17144 @item
17145 @file{/usr/lib/debug/usr/bin/ls.debug}.
17146 @end itemize
17147
17148 @anchor{debug-file-directory}
17149 Global debugging info directories default to what is set by @value{GDBN}
17150 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
17151 you can also set the global debugging info directories, and view the list
17152 @value{GDBN} is currently using.
17153
17154 @table @code
17155
17156 @kindex set debug-file-directory
17157 @item set debug-file-directory @var{directories}
17158 Set the directories which @value{GDBN} searches for separate debugging
17159 information files to @var{directory}. Multiple path components can be set
17160 concatenating them by a path separator.
17161
17162 @kindex show debug-file-directory
17163 @item show debug-file-directory
17164 Show the directories @value{GDBN} searches for separate debugging
17165 information files.
17166
17167 @end table
17168
17169 @cindex @code{.gnu_debuglink} sections
17170 @cindex debug link sections
17171 A debug link is a special section of the executable file named
17172 @code{.gnu_debuglink}. The section must contain:
17173
17174 @itemize
17175 @item
17176 A filename, with any leading directory components removed, followed by
17177 a zero byte,
17178 @item
17179 zero to three bytes of padding, as needed to reach the next four-byte
17180 boundary within the section, and
17181 @item
17182 a four-byte CRC checksum, stored in the same endianness used for the
17183 executable file itself. The checksum is computed on the debugging
17184 information file's full contents by the function given below, passing
17185 zero as the @var{crc} argument.
17186 @end itemize
17187
17188 Any executable file format can carry a debug link, as long as it can
17189 contain a section named @code{.gnu_debuglink} with the contents
17190 described above.
17191
17192 @cindex @code{.note.gnu.build-id} sections
17193 @cindex build ID sections
17194 The build ID is a special section in the executable file (and in other
17195 ELF binary files that @value{GDBN} may consider). This section is
17196 often named @code{.note.gnu.build-id}, but that name is not mandatory.
17197 It contains unique identification for the built files---the ID remains
17198 the same across multiple builds of the same build tree. The default
17199 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
17200 content for the build ID string. The same section with an identical
17201 value is present in the original built binary with symbols, in its
17202 stripped variant, and in the separate debugging information file.
17203
17204 The debugging information file itself should be an ordinary
17205 executable, containing a full set of linker symbols, sections, and
17206 debugging information. The sections of the debugging information file
17207 should have the same names, addresses, and sizes as the original file,
17208 but they need not contain any data---much like a @code{.bss} section
17209 in an ordinary executable.
17210
17211 The @sc{gnu} binary utilities (Binutils) package includes the
17212 @samp{objcopy} utility that can produce
17213 the separated executable / debugging information file pairs using the
17214 following commands:
17215
17216 @smallexample
17217 @kbd{objcopy --only-keep-debug foo foo.debug}
17218 @kbd{strip -g foo}
17219 @end smallexample
17220
17221 @noindent
17222 These commands remove the debugging
17223 information from the executable file @file{foo} and place it in the file
17224 @file{foo.debug}. You can use the first, second or both methods to link the
17225 two files:
17226
17227 @itemize @bullet
17228 @item
17229 The debug link method needs the following additional command to also leave
17230 behind a debug link in @file{foo}:
17231
17232 @smallexample
17233 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
17234 @end smallexample
17235
17236 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
17237 a version of the @code{strip} command such that the command @kbd{strip foo -f
17238 foo.debug} has the same functionality as the two @code{objcopy} commands and
17239 the @code{ln -s} command above, together.
17240
17241 @item
17242 Build ID gets embedded into the main executable using @code{ld --build-id} or
17243 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
17244 compatibility fixes for debug files separation are present in @sc{gnu} binary
17245 utilities (Binutils) package since version 2.18.
17246 @end itemize
17247
17248 @noindent
17249
17250 @cindex CRC algorithm definition
17251 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
17252 IEEE 802.3 using the polynomial:
17253
17254 @c TexInfo requires naked braces for multi-digit exponents for Tex
17255 @c output, but this causes HTML output to barf. HTML has to be set using
17256 @c raw commands. So we end up having to specify this equation in 2
17257 @c different ways!
17258 @ifhtml
17259 @display
17260 @html
17261 <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>
17262 + <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
17263 @end html
17264 @end display
17265 @end ifhtml
17266 @ifnothtml
17267 @display
17268 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
17269 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
17270 @end display
17271 @end ifnothtml
17272
17273 The function is computed byte at a time, taking the least
17274 significant bit of each byte first. The initial pattern
17275 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
17276 the final result is inverted to ensure trailing zeros also affect the
17277 CRC.
17278
17279 @emph{Note:} This is the same CRC polynomial as used in handling the
17280 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
17281 , @value{GDBN} Remote Serial Protocol}). However in the
17282 case of the Remote Serial Protocol, the CRC is computed @emph{most}
17283 significant bit first, and the result is not inverted, so trailing
17284 zeros have no effect on the CRC value.
17285
17286 To complete the description, we show below the code of the function
17287 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
17288 initially supplied @code{crc} argument means that an initial call to
17289 this function passing in zero will start computing the CRC using
17290 @code{0xffffffff}.
17291
17292 @kindex gnu_debuglink_crc32
17293 @smallexample
17294 unsigned long
17295 gnu_debuglink_crc32 (unsigned long crc,
17296 unsigned char *buf, size_t len)
17297 @{
17298 static const unsigned long crc32_table[256] =
17299 @{
17300 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
17301 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
17302 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
17303 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
17304 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
17305 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
17306 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
17307 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
17308 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
17309 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
17310 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
17311 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
17312 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
17313 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
17314 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
17315 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
17316 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
17317 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
17318 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
17319 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
17320 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
17321 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
17322 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
17323 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
17324 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
17325 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
17326 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
17327 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
17328 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
17329 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
17330 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
17331 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
17332 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
17333 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
17334 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
17335 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
17336 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
17337 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
17338 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
17339 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
17340 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
17341 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
17342 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
17343 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
17344 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
17345 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
17346 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
17347 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
17348 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
17349 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
17350 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
17351 0x2d02ef8d
17352 @};
17353 unsigned char *end;
17354
17355 crc = ~crc & 0xffffffff;
17356 for (end = buf + len; buf < end; ++buf)
17357 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
17358 return ~crc & 0xffffffff;
17359 @}
17360 @end smallexample
17361
17362 @noindent
17363 This computation does not apply to the ``build ID'' method.
17364
17365 @node MiniDebugInfo
17366 @section Debugging information in a special section
17367 @cindex separate debug sections
17368 @cindex @samp{.gnu_debugdata} section
17369
17370 Some systems ship pre-built executables and libraries that have a
17371 special @samp{.gnu_debugdata} section. This feature is called
17372 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
17373 is used to supply extra symbols for backtraces.
17374
17375 The intent of this section is to provide extra minimal debugging
17376 information for use in simple backtraces. It is not intended to be a
17377 replacement for full separate debugging information (@pxref{Separate
17378 Debug Files}). The example below shows the intended use; however,
17379 @value{GDBN} does not currently put restrictions on what sort of
17380 debugging information might be included in the section.
17381
17382 @value{GDBN} has support for this extension. If the section exists,
17383 then it is used provided that no other source of debugging information
17384 can be found, and that @value{GDBN} was configured with LZMA support.
17385
17386 This section can be easily created using @command{objcopy} and other
17387 standard utilities:
17388
17389 @smallexample
17390 # Extract the dynamic symbols from the main binary, there is no need
17391 # to also have these in the normal symbol table.
17392 nm -D @var{binary} --format=posix --defined-only \
17393 | awk '@{ print $1 @}' | sort > dynsyms
17394
17395 # Extract all the text (i.e. function) symbols from the debuginfo.
17396 # (Note that we actually also accept "D" symbols, for the benefit
17397 # of platforms like PowerPC64 that use function descriptors.)
17398 nm @var{binary} --format=posix --defined-only \
17399 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
17400 | sort > funcsyms
17401
17402 # Keep all the function symbols not already in the dynamic symbol
17403 # table.
17404 comm -13 dynsyms funcsyms > keep_symbols
17405
17406 # Separate full debug info into debug binary.
17407 objcopy --only-keep-debug @var{binary} debug
17408
17409 # Copy the full debuginfo, keeping only a minimal set of symbols and
17410 # removing some unnecessary sections.
17411 objcopy -S --remove-section .gdb_index --remove-section .comment \
17412 --keep-symbols=keep_symbols debug mini_debuginfo
17413
17414 # Drop the full debug info from the original binary.
17415 strip --strip-all -R .comment @var{binary}
17416
17417 # Inject the compressed data into the .gnu_debugdata section of the
17418 # original binary.
17419 xz mini_debuginfo
17420 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
17421 @end smallexample
17422
17423 @node Index Files
17424 @section Index Files Speed Up @value{GDBN}
17425 @cindex index files
17426 @cindex @samp{.gdb_index} section
17427
17428 When @value{GDBN} finds a symbol file, it scans the symbols in the
17429 file in order to construct an internal symbol table. This lets most
17430 @value{GDBN} operations work quickly---at the cost of a delay early
17431 on. For large programs, this delay can be quite lengthy, so
17432 @value{GDBN} provides a way to build an index, which speeds up
17433 startup.
17434
17435 The index is stored as a section in the symbol file. @value{GDBN} can
17436 write the index to a file, then you can put it into the symbol file
17437 using @command{objcopy}.
17438
17439 To create an index file, use the @code{save gdb-index} command:
17440
17441 @table @code
17442 @item save gdb-index @var{directory}
17443 @kindex save gdb-index
17444 Create an index file for each symbol file currently known by
17445 @value{GDBN}. Each file is named after its corresponding symbol file,
17446 with @samp{.gdb-index} appended, and is written into the given
17447 @var{directory}.
17448 @end table
17449
17450 Once you have created an index file you can merge it into your symbol
17451 file, here named @file{symfile}, using @command{objcopy}:
17452
17453 @smallexample
17454 $ objcopy --add-section .gdb_index=symfile.gdb-index \
17455 --set-section-flags .gdb_index=readonly symfile symfile
17456 @end smallexample
17457
17458 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
17459 sections that have been deprecated. Usually they are deprecated because
17460 they are missing a new feature or have performance issues.
17461 To tell @value{GDBN} to use a deprecated index section anyway
17462 specify @code{set use-deprecated-index-sections on}.
17463 The default is @code{off}.
17464 This can speed up startup, but may result in some functionality being lost.
17465 @xref{Index Section Format}.
17466
17467 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
17468 must be done before gdb reads the file. The following will not work:
17469
17470 @smallexample
17471 $ gdb -ex "set use-deprecated-index-sections on" <program>
17472 @end smallexample
17473
17474 Instead you must do, for example,
17475
17476 @smallexample
17477 $ gdb -iex "set use-deprecated-index-sections on" <program>
17478 @end smallexample
17479
17480 There are currently some limitation on indices. They only work when
17481 for DWARF debugging information, not stabs. And, they do not
17482 currently work for programs using Ada.
17483
17484 @node Symbol Errors
17485 @section Errors Reading Symbol Files
17486
17487 While reading a symbol file, @value{GDBN} occasionally encounters problems,
17488 such as symbol types it does not recognize, or known bugs in compiler
17489 output. By default, @value{GDBN} does not notify you of such problems, since
17490 they are relatively common and primarily of interest to people
17491 debugging compilers. If you are interested in seeing information
17492 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
17493 only one message about each such type of problem, no matter how many
17494 times the problem occurs; or you can ask @value{GDBN} to print more messages,
17495 to see how many times the problems occur, with the @code{set
17496 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
17497 Messages}).
17498
17499 The messages currently printed, and their meanings, include:
17500
17501 @table @code
17502 @item inner block not inside outer block in @var{symbol}
17503
17504 The symbol information shows where symbol scopes begin and end
17505 (such as at the start of a function or a block of statements). This
17506 error indicates that an inner scope block is not fully contained
17507 in its outer scope blocks.
17508
17509 @value{GDBN} circumvents the problem by treating the inner block as if it had
17510 the same scope as the outer block. In the error message, @var{symbol}
17511 may be shown as ``@code{(don't know)}'' if the outer block is not a
17512 function.
17513
17514 @item block at @var{address} out of order
17515
17516 The symbol information for symbol scope blocks should occur in
17517 order of increasing addresses. This error indicates that it does not
17518 do so.
17519
17520 @value{GDBN} does not circumvent this problem, and has trouble
17521 locating symbols in the source file whose symbols it is reading. (You
17522 can often determine what source file is affected by specifying
17523 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
17524 Messages}.)
17525
17526 @item bad block start address patched
17527
17528 The symbol information for a symbol scope block has a start address
17529 smaller than the address of the preceding source line. This is known
17530 to occur in the SunOS 4.1.1 (and earlier) C compiler.
17531
17532 @value{GDBN} circumvents the problem by treating the symbol scope block as
17533 starting on the previous source line.
17534
17535 @item bad string table offset in symbol @var{n}
17536
17537 @cindex foo
17538 Symbol number @var{n} contains a pointer into the string table which is
17539 larger than the size of the string table.
17540
17541 @value{GDBN} circumvents the problem by considering the symbol to have the
17542 name @code{foo}, which may cause other problems if many symbols end up
17543 with this name.
17544
17545 @item unknown symbol type @code{0x@var{nn}}
17546
17547 The symbol information contains new data types that @value{GDBN} does
17548 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
17549 uncomprehended information, in hexadecimal.
17550
17551 @value{GDBN} circumvents the error by ignoring this symbol information.
17552 This usually allows you to debug your program, though certain symbols
17553 are not accessible. If you encounter such a problem and feel like
17554 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
17555 on @code{complain}, then go up to the function @code{read_dbx_symtab}
17556 and examine @code{*bufp} to see the symbol.
17557
17558 @item stub type has NULL name
17559
17560 @value{GDBN} could not find the full definition for a struct or class.
17561
17562 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
17563 The symbol information for a C@t{++} member function is missing some
17564 information that recent versions of the compiler should have output for
17565 it.
17566
17567 @item info mismatch between compiler and debugger
17568
17569 @value{GDBN} could not parse a type specification output by the compiler.
17570
17571 @end table
17572
17573 @node Data Files
17574 @section GDB Data Files
17575
17576 @cindex prefix for data files
17577 @value{GDBN} will sometimes read an auxiliary data file. These files
17578 are kept in a directory known as the @dfn{data directory}.
17579
17580 You can set the data directory's name, and view the name @value{GDBN}
17581 is currently using.
17582
17583 @table @code
17584 @kindex set data-directory
17585 @item set data-directory @var{directory}
17586 Set the directory which @value{GDBN} searches for auxiliary data files
17587 to @var{directory}.
17588
17589 @kindex show data-directory
17590 @item show data-directory
17591 Show the directory @value{GDBN} searches for auxiliary data files.
17592 @end table
17593
17594 @cindex default data directory
17595 @cindex @samp{--with-gdb-datadir}
17596 You can set the default data directory by using the configure-time
17597 @samp{--with-gdb-datadir} option. If the data directory is inside
17598 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
17599 @samp{--exec-prefix}), then the default data directory will be updated
17600 automatically if the installed @value{GDBN} is moved to a new
17601 location.
17602
17603 The data directory may also be specified with the
17604 @code{--data-directory} command line option.
17605 @xref{Mode Options}.
17606
17607 @node Targets
17608 @chapter Specifying a Debugging Target
17609
17610 @cindex debugging target
17611 A @dfn{target} is the execution environment occupied by your program.
17612
17613 Often, @value{GDBN} runs in the same host environment as your program;
17614 in that case, the debugging target is specified as a side effect when
17615 you use the @code{file} or @code{core} commands. When you need more
17616 flexibility---for example, running @value{GDBN} on a physically separate
17617 host, or controlling a standalone system over a serial port or a
17618 realtime system over a TCP/IP connection---you can use the @code{target}
17619 command to specify one of the target types configured for @value{GDBN}
17620 (@pxref{Target Commands, ,Commands for Managing Targets}).
17621
17622 @cindex target architecture
17623 It is possible to build @value{GDBN} for several different @dfn{target
17624 architectures}. When @value{GDBN} is built like that, you can choose
17625 one of the available architectures with the @kbd{set architecture}
17626 command.
17627
17628 @table @code
17629 @kindex set architecture
17630 @kindex show architecture
17631 @item set architecture @var{arch}
17632 This command sets the current target architecture to @var{arch}. The
17633 value of @var{arch} can be @code{"auto"}, in addition to one of the
17634 supported architectures.
17635
17636 @item show architecture
17637 Show the current target architecture.
17638
17639 @item set processor
17640 @itemx processor
17641 @kindex set processor
17642 @kindex show processor
17643 These are alias commands for, respectively, @code{set architecture}
17644 and @code{show architecture}.
17645 @end table
17646
17647 @menu
17648 * Active Targets:: Active targets
17649 * Target Commands:: Commands for managing targets
17650 * Byte Order:: Choosing target byte order
17651 @end menu
17652
17653 @node Active Targets
17654 @section Active Targets
17655
17656 @cindex stacking targets
17657 @cindex active targets
17658 @cindex multiple targets
17659
17660 There are multiple classes of targets such as: processes, executable files or
17661 recording sessions. Core files belong to the process class, making core file
17662 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
17663 on multiple active targets, one in each class. This allows you to (for
17664 example) start a process and inspect its activity, while still having access to
17665 the executable file after the process finishes. Or if you start process
17666 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
17667 presented a virtual layer of the recording target, while the process target
17668 remains stopped at the chronologically last point of the process execution.
17669
17670 Use the @code{core-file} and @code{exec-file} commands to select a new core
17671 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
17672 specify as a target a process that is already running, use the @code{attach}
17673 command (@pxref{Attach, ,Debugging an Already-running Process}).
17674
17675 @node Target Commands
17676 @section Commands for Managing Targets
17677
17678 @table @code
17679 @item target @var{type} @var{parameters}
17680 Connects the @value{GDBN} host environment to a target machine or
17681 process. A target is typically a protocol for talking to debugging
17682 facilities. You use the argument @var{type} to specify the type or
17683 protocol of the target machine.
17684
17685 Further @var{parameters} are interpreted by the target protocol, but
17686 typically include things like device names or host names to connect
17687 with, process numbers, and baud rates.
17688
17689 The @code{target} command does not repeat if you press @key{RET} again
17690 after executing the command.
17691
17692 @kindex help target
17693 @item help target
17694 Displays the names of all targets available. To display targets
17695 currently selected, use either @code{info target} or @code{info files}
17696 (@pxref{Files, ,Commands to Specify Files}).
17697
17698 @item help target @var{name}
17699 Describe a particular target, including any parameters necessary to
17700 select it.
17701
17702 @kindex set gnutarget
17703 @item set gnutarget @var{args}
17704 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
17705 knows whether it is reading an @dfn{executable},
17706 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
17707 with the @code{set gnutarget} command. Unlike most @code{target} commands,
17708 with @code{gnutarget} the @code{target} refers to a program, not a machine.
17709
17710 @quotation
17711 @emph{Warning:} To specify a file format with @code{set gnutarget},
17712 you must know the actual BFD name.
17713 @end quotation
17714
17715 @noindent
17716 @xref{Files, , Commands to Specify Files}.
17717
17718 @kindex show gnutarget
17719 @item show gnutarget
17720 Use the @code{show gnutarget} command to display what file format
17721 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
17722 @value{GDBN} will determine the file format for each file automatically,
17723 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
17724 @end table
17725
17726 @cindex common targets
17727 Here are some common targets (available, or not, depending on the GDB
17728 configuration):
17729
17730 @table @code
17731 @kindex target
17732 @item target exec @var{program}
17733 @cindex executable file target
17734 An executable file. @samp{target exec @var{program}} is the same as
17735 @samp{exec-file @var{program}}.
17736
17737 @item target core @var{filename}
17738 @cindex core dump file target
17739 A core dump file. @samp{target core @var{filename}} is the same as
17740 @samp{core-file @var{filename}}.
17741
17742 @item target remote @var{medium}
17743 @cindex remote target
17744 A remote system connected to @value{GDBN} via a serial line or network
17745 connection. This command tells @value{GDBN} to use its own remote
17746 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
17747
17748 For example, if you have a board connected to @file{/dev/ttya} on the
17749 machine running @value{GDBN}, you could say:
17750
17751 @smallexample
17752 target remote /dev/ttya
17753 @end smallexample
17754
17755 @code{target remote} supports the @code{load} command. This is only
17756 useful if you have some other way of getting the stub to the target
17757 system, and you can put it somewhere in memory where it won't get
17758 clobbered by the download.
17759
17760 @item target sim @r{[}@var{simargs}@r{]} @dots{}
17761 @cindex built-in simulator target
17762 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
17763 In general,
17764 @smallexample
17765 target sim
17766 load
17767 run
17768 @end smallexample
17769 @noindent
17770 works; however, you cannot assume that a specific memory map, device
17771 drivers, or even basic I/O is available, although some simulators do
17772 provide these. For info about any processor-specific simulator details,
17773 see the appropriate section in @ref{Embedded Processors, ,Embedded
17774 Processors}.
17775
17776 @end table
17777
17778 Different targets are available on different configurations of @value{GDBN};
17779 your configuration may have more or fewer targets.
17780
17781 Many remote targets require you to download the executable's code once
17782 you've successfully established a connection. You may wish to control
17783 various aspects of this process.
17784
17785 @table @code
17786
17787 @item set hash
17788 @kindex set hash@r{, for remote monitors}
17789 @cindex hash mark while downloading
17790 This command controls whether a hash mark @samp{#} is displayed while
17791 downloading a file to the remote monitor. If on, a hash mark is
17792 displayed after each S-record is successfully downloaded to the
17793 monitor.
17794
17795 @item show hash
17796 @kindex show hash@r{, for remote monitors}
17797 Show the current status of displaying the hash mark.
17798
17799 @item set debug monitor
17800 @kindex set debug monitor
17801 @cindex display remote monitor communications
17802 Enable or disable display of communications messages between
17803 @value{GDBN} and the remote monitor.
17804
17805 @item show debug monitor
17806 @kindex show debug monitor
17807 Show the current status of displaying communications between
17808 @value{GDBN} and the remote monitor.
17809 @end table
17810
17811 @table @code
17812
17813 @kindex load @var{filename}
17814 @item load @var{filename}
17815 @anchor{load}
17816 Depending on what remote debugging facilities are configured into
17817 @value{GDBN}, the @code{load} command may be available. Where it exists, it
17818 is meant to make @var{filename} (an executable) available for debugging
17819 on the remote system---by downloading, or dynamic linking, for example.
17820 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
17821 the @code{add-symbol-file} command.
17822
17823 If your @value{GDBN} does not have a @code{load} command, attempting to
17824 execute it gets the error message ``@code{You can't do that when your
17825 target is @dots{}}''
17826
17827 The file is loaded at whatever address is specified in the executable.
17828 For some object file formats, you can specify the load address when you
17829 link the program; for other formats, like a.out, the object file format
17830 specifies a fixed address.
17831 @c FIXME! This would be a good place for an xref to the GNU linker doc.
17832
17833 Depending on the remote side capabilities, @value{GDBN} may be able to
17834 load programs into flash memory.
17835
17836 @code{load} does not repeat if you press @key{RET} again after using it.
17837 @end table
17838
17839 @node Byte Order
17840 @section Choosing Target Byte Order
17841
17842 @cindex choosing target byte order
17843 @cindex target byte order
17844
17845 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
17846 offer the ability to run either big-endian or little-endian byte
17847 orders. Usually the executable or symbol will include a bit to
17848 designate the endian-ness, and you will not need to worry about
17849 which to use. However, you may still find it useful to adjust
17850 @value{GDBN}'s idea of processor endian-ness manually.
17851
17852 @table @code
17853 @kindex set endian
17854 @item set endian big
17855 Instruct @value{GDBN} to assume the target is big-endian.
17856
17857 @item set endian little
17858 Instruct @value{GDBN} to assume the target is little-endian.
17859
17860 @item set endian auto
17861 Instruct @value{GDBN} to use the byte order associated with the
17862 executable.
17863
17864 @item show endian
17865 Display @value{GDBN}'s current idea of the target byte order.
17866
17867 @end table
17868
17869 Note that these commands merely adjust interpretation of symbolic
17870 data on the host, and that they have absolutely no effect on the
17871 target system.
17872
17873
17874 @node Remote Debugging
17875 @chapter Debugging Remote Programs
17876 @cindex remote debugging
17877
17878 If you are trying to debug a program running on a machine that cannot run
17879 @value{GDBN} in the usual way, it is often useful to use remote debugging.
17880 For example, you might use remote debugging on an operating system kernel,
17881 or on a small system which does not have a general purpose operating system
17882 powerful enough to run a full-featured debugger.
17883
17884 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
17885 to make this work with particular debugging targets. In addition,
17886 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
17887 but not specific to any particular target system) which you can use if you
17888 write the remote stubs---the code that runs on the remote system to
17889 communicate with @value{GDBN}.
17890
17891 Other remote targets may be available in your
17892 configuration of @value{GDBN}; use @code{help target} to list them.
17893
17894 @menu
17895 * Connecting:: Connecting to a remote target
17896 * File Transfer:: Sending files to a remote system
17897 * Server:: Using the gdbserver program
17898 * Remote Configuration:: Remote configuration
17899 * Remote Stub:: Implementing a remote stub
17900 @end menu
17901
17902 @node Connecting
17903 @section Connecting to a Remote Target
17904
17905 On the @value{GDBN} host machine, you will need an unstripped copy of
17906 your program, since @value{GDBN} needs symbol and debugging information.
17907 Start up @value{GDBN} as usual, using the name of the local copy of your
17908 program as the first argument.
17909
17910 @cindex @code{target remote}
17911 @value{GDBN} can communicate with the target over a serial line, or
17912 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
17913 each case, @value{GDBN} uses the same protocol for debugging your
17914 program; only the medium carrying the debugging packets varies. The
17915 @code{target remote} command establishes a connection to the target.
17916 Its arguments indicate which medium to use:
17917
17918 @table @code
17919
17920 @item target remote @var{serial-device}
17921 @cindex serial line, @code{target remote}
17922 Use @var{serial-device} to communicate with the target. For example,
17923 to use a serial line connected to the device named @file{/dev/ttyb}:
17924
17925 @smallexample
17926 target remote /dev/ttyb
17927 @end smallexample
17928
17929 If you're using a serial line, you may want to give @value{GDBN} the
17930 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
17931 (@pxref{Remote Configuration, set remotebaud}) before the
17932 @code{target} command.
17933
17934 @item target remote @code{@var{host}:@var{port}}
17935 @itemx target remote @code{tcp:@var{host}:@var{port}}
17936 @cindex @acronym{TCP} port, @code{target remote}
17937 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
17938 The @var{host} may be either a host name or a numeric @acronym{IP}
17939 address; @var{port} must be a decimal number. The @var{host} could be
17940 the target machine itself, if it is directly connected to the net, or
17941 it might be a terminal server which in turn has a serial line to the
17942 target.
17943
17944 For example, to connect to port 2828 on a terminal server named
17945 @code{manyfarms}:
17946
17947 @smallexample
17948 target remote manyfarms:2828
17949 @end smallexample
17950
17951 If your remote target is actually running on the same machine as your
17952 debugger session (e.g.@: a simulator for your target running on the
17953 same host), you can omit the hostname. For example, to connect to
17954 port 1234 on your local machine:
17955
17956 @smallexample
17957 target remote :1234
17958 @end smallexample
17959 @noindent
17960
17961 Note that the colon is still required here.
17962
17963 @item target remote @code{udp:@var{host}:@var{port}}
17964 @cindex @acronym{UDP} port, @code{target remote}
17965 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
17966 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
17967
17968 @smallexample
17969 target remote udp:manyfarms:2828
17970 @end smallexample
17971
17972 When using a @acronym{UDP} connection for remote debugging, you should
17973 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
17974 can silently drop packets on busy or unreliable networks, which will
17975 cause havoc with your debugging session.
17976
17977 @item target remote | @var{command}
17978 @cindex pipe, @code{target remote} to
17979 Run @var{command} in the background and communicate with it using a
17980 pipe. The @var{command} is a shell command, to be parsed and expanded
17981 by the system's command shell, @code{/bin/sh}; it should expect remote
17982 protocol packets on its standard input, and send replies on its
17983 standard output. You could use this to run a stand-alone simulator
17984 that speaks the remote debugging protocol, to make net connections
17985 using programs like @code{ssh}, or for other similar tricks.
17986
17987 If @var{command} closes its standard output (perhaps by exiting),
17988 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
17989 program has already exited, this will have no effect.)
17990
17991 @end table
17992
17993 Once the connection has been established, you can use all the usual
17994 commands to examine and change data. The remote program is already
17995 running; you can use @kbd{step} and @kbd{continue}, and you do not
17996 need to use @kbd{run}.
17997
17998 @cindex interrupting remote programs
17999 @cindex remote programs, interrupting
18000 Whenever @value{GDBN} is waiting for the remote program, if you type the
18001 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
18002 program. This may or may not succeed, depending in part on the hardware
18003 and the serial drivers the remote system uses. If you type the
18004 interrupt character once again, @value{GDBN} displays this prompt:
18005
18006 @smallexample
18007 Interrupted while waiting for the program.
18008 Give up (and stop debugging it)? (y or n)
18009 @end smallexample
18010
18011 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
18012 (If you decide you want to try again later, you can use @samp{target
18013 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
18014 goes back to waiting.
18015
18016 @table @code
18017 @kindex detach (remote)
18018 @item detach
18019 When you have finished debugging the remote program, you can use the
18020 @code{detach} command to release it from @value{GDBN} control.
18021 Detaching from the target normally resumes its execution, but the results
18022 will depend on your particular remote stub. After the @code{detach}
18023 command, @value{GDBN} is free to connect to another target.
18024
18025 @kindex disconnect
18026 @item disconnect
18027 The @code{disconnect} command behaves like @code{detach}, except that
18028 the target is generally not resumed. It will wait for @value{GDBN}
18029 (this instance or another one) to connect and continue debugging. After
18030 the @code{disconnect} command, @value{GDBN} is again free to connect to
18031 another target.
18032
18033 @cindex send command to remote monitor
18034 @cindex extend @value{GDBN} for remote targets
18035 @cindex add new commands for external monitor
18036 @kindex monitor
18037 @item monitor @var{cmd}
18038 This command allows you to send arbitrary commands directly to the
18039 remote monitor. Since @value{GDBN} doesn't care about the commands it
18040 sends like this, this command is the way to extend @value{GDBN}---you
18041 can add new commands that only the external monitor will understand
18042 and implement.
18043 @end table
18044
18045 @node File Transfer
18046 @section Sending files to a remote system
18047 @cindex remote target, file transfer
18048 @cindex file transfer
18049 @cindex sending files to remote systems
18050
18051 Some remote targets offer the ability to transfer files over the same
18052 connection used to communicate with @value{GDBN}. This is convenient
18053 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
18054 running @code{gdbserver} over a network interface. For other targets,
18055 e.g.@: embedded devices with only a single serial port, this may be
18056 the only way to upload or download files.
18057
18058 Not all remote targets support these commands.
18059
18060 @table @code
18061 @kindex remote put
18062 @item remote put @var{hostfile} @var{targetfile}
18063 Copy file @var{hostfile} from the host system (the machine running
18064 @value{GDBN}) to @var{targetfile} on the target system.
18065
18066 @kindex remote get
18067 @item remote get @var{targetfile} @var{hostfile}
18068 Copy file @var{targetfile} from the target system to @var{hostfile}
18069 on the host system.
18070
18071 @kindex remote delete
18072 @item remote delete @var{targetfile}
18073 Delete @var{targetfile} from the target system.
18074
18075 @end table
18076
18077 @node Server
18078 @section Using the @code{gdbserver} Program
18079
18080 @kindex gdbserver
18081 @cindex remote connection without stubs
18082 @code{gdbserver} is a control program for Unix-like systems, which
18083 allows you to connect your program with a remote @value{GDBN} via
18084 @code{target remote}---but without linking in the usual debugging stub.
18085
18086 @code{gdbserver} is not a complete replacement for the debugging stubs,
18087 because it requires essentially the same operating-system facilities
18088 that @value{GDBN} itself does. In fact, a system that can run
18089 @code{gdbserver} to connect to a remote @value{GDBN} could also run
18090 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
18091 because it is a much smaller program than @value{GDBN} itself. It is
18092 also easier to port than all of @value{GDBN}, so you may be able to get
18093 started more quickly on a new system by using @code{gdbserver}.
18094 Finally, if you develop code for real-time systems, you may find that
18095 the tradeoffs involved in real-time operation make it more convenient to
18096 do as much development work as possible on another system, for example
18097 by cross-compiling. You can use @code{gdbserver} to make a similar
18098 choice for debugging.
18099
18100 @value{GDBN} and @code{gdbserver} communicate via either a serial line
18101 or a TCP connection, using the standard @value{GDBN} remote serial
18102 protocol.
18103
18104 @quotation
18105 @emph{Warning:} @code{gdbserver} does not have any built-in security.
18106 Do not run @code{gdbserver} connected to any public network; a
18107 @value{GDBN} connection to @code{gdbserver} provides access to the
18108 target system with the same privileges as the user running
18109 @code{gdbserver}.
18110 @end quotation
18111
18112 @subsection Running @code{gdbserver}
18113 @cindex arguments, to @code{gdbserver}
18114 @cindex @code{gdbserver}, command-line arguments
18115
18116 Run @code{gdbserver} on the target system. You need a copy of the
18117 program you want to debug, including any libraries it requires.
18118 @code{gdbserver} does not need your program's symbol table, so you can
18119 strip the program if necessary to save space. @value{GDBN} on the host
18120 system does all the symbol handling.
18121
18122 To use the server, you must tell it how to communicate with @value{GDBN};
18123 the name of your program; and the arguments for your program. The usual
18124 syntax is:
18125
18126 @smallexample
18127 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
18128 @end smallexample
18129
18130 @var{comm} is either a device name (to use a serial line), or a TCP
18131 hostname and portnumber, or @code{-} or @code{stdio} to use
18132 stdin/stdout of @code{gdbserver}.
18133 For example, to debug Emacs with the argument
18134 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
18135 @file{/dev/com1}:
18136
18137 @smallexample
18138 target> gdbserver /dev/com1 emacs foo.txt
18139 @end smallexample
18140
18141 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
18142 with it.
18143
18144 To use a TCP connection instead of a serial line:
18145
18146 @smallexample
18147 target> gdbserver host:2345 emacs foo.txt
18148 @end smallexample
18149
18150 The only difference from the previous example is the first argument,
18151 specifying that you are communicating with the host @value{GDBN} via
18152 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
18153 expect a TCP connection from machine @samp{host} to local TCP port 2345.
18154 (Currently, the @samp{host} part is ignored.) You can choose any number
18155 you want for the port number as long as it does not conflict with any
18156 TCP ports already in use on the target system (for example, @code{23} is
18157 reserved for @code{telnet}).@footnote{If you choose a port number that
18158 conflicts with another service, @code{gdbserver} prints an error message
18159 and exits.} You must use the same port number with the host @value{GDBN}
18160 @code{target remote} command.
18161
18162 The @code{stdio} connection is useful when starting @code{gdbserver}
18163 with ssh:
18164
18165 @smallexample
18166 (gdb) target remote | ssh -T hostname gdbserver - hello
18167 @end smallexample
18168
18169 The @samp{-T} option to ssh is provided because we don't need a remote pty,
18170 and we don't want escape-character handling. Ssh does this by default when
18171 a command is provided, the flag is provided to make it explicit.
18172 You could elide it if you want to.
18173
18174 Programs started with stdio-connected gdbserver have @file{/dev/null} for
18175 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
18176 display through a pipe connected to gdbserver.
18177 Both @code{stdout} and @code{stderr} use the same pipe.
18178
18179 @subsubsection Attaching to a Running Program
18180 @cindex attach to a program, @code{gdbserver}
18181 @cindex @option{--attach}, @code{gdbserver} option
18182
18183 On some targets, @code{gdbserver} can also attach to running programs.
18184 This is accomplished via the @code{--attach} argument. The syntax is:
18185
18186 @smallexample
18187 target> gdbserver --attach @var{comm} @var{pid}
18188 @end smallexample
18189
18190 @var{pid} is the process ID of a currently running process. It isn't necessary
18191 to point @code{gdbserver} at a binary for the running process.
18192
18193 @pindex pidof
18194 You can debug processes by name instead of process ID if your target has the
18195 @code{pidof} utility:
18196
18197 @smallexample
18198 target> gdbserver --attach @var{comm} `pidof @var{program}`
18199 @end smallexample
18200
18201 In case more than one copy of @var{program} is running, or @var{program}
18202 has multiple threads, most versions of @code{pidof} support the
18203 @code{-s} option to only return the first process ID.
18204
18205 @subsubsection Multi-Process Mode for @code{gdbserver}
18206 @cindex @code{gdbserver}, multiple processes
18207 @cindex multiple processes with @code{gdbserver}
18208
18209 When you connect to @code{gdbserver} using @code{target remote},
18210 @code{gdbserver} debugs the specified program only once. When the
18211 program exits, or you detach from it, @value{GDBN} closes the connection
18212 and @code{gdbserver} exits.
18213
18214 If you connect using @kbd{target extended-remote}, @code{gdbserver}
18215 enters multi-process mode. When the debugged program exits, or you
18216 detach from it, @value{GDBN} stays connected to @code{gdbserver} even
18217 though no program is running. The @code{run} and @code{attach}
18218 commands instruct @code{gdbserver} to run or attach to a new program.
18219 The @code{run} command uses @code{set remote exec-file} (@pxref{set
18220 remote exec-file}) to select the program to run. Command line
18221 arguments are supported, except for wildcard expansion and I/O
18222 redirection (@pxref{Arguments}).
18223
18224 @cindex @option{--multi}, @code{gdbserver} option
18225 To start @code{gdbserver} without supplying an initial command to run
18226 or process ID to attach, use the @option{--multi} command line option.
18227 Then you can connect using @kbd{target extended-remote} and start
18228 the program you want to debug.
18229
18230 In multi-process mode @code{gdbserver} does not automatically exit unless you
18231 use the option @option{--once}. You can terminate it by using
18232 @code{monitor exit} (@pxref{Monitor Commands for gdbserver}). Note that the
18233 conditions under which @code{gdbserver} terminates depend on how @value{GDBN}
18234 connects to it (@kbd{target remote} or @kbd{target extended-remote}). The
18235 @option{--multi} option to @code{gdbserver} has no influence on that.
18236
18237 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
18238
18239 This section applies only when @code{gdbserver} is run to listen on a TCP port.
18240
18241 @code{gdbserver} normally terminates after all of its debugged processes have
18242 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
18243 extended-remote}, @code{gdbserver} stays running even with no processes left.
18244 @value{GDBN} normally terminates the spawned debugged process on its exit,
18245 which normally also terminates @code{gdbserver} in the @kbd{target remote}
18246 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
18247 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
18248 stays running even in the @kbd{target remote} mode.
18249
18250 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
18251 Such reconnecting is useful for features like @ref{disconnected tracing}. For
18252 completeness, at most one @value{GDBN} can be connected at a time.
18253
18254 @cindex @option{--once}, @code{gdbserver} option
18255 By default, @code{gdbserver} keeps the listening TCP port open, so that
18256 subsequent connections are possible. However, if you start @code{gdbserver}
18257 with the @option{--once} option, it will stop listening for any further
18258 connection attempts after connecting to the first @value{GDBN} session. This
18259 means no further connections to @code{gdbserver} will be possible after the
18260 first one. It also means @code{gdbserver} will terminate after the first
18261 connection with remote @value{GDBN} has closed, even for unexpectedly closed
18262 connections and even in the @kbd{target extended-remote} mode. The
18263 @option{--once} option allows reusing the same port number for connecting to
18264 multiple instances of @code{gdbserver} running on the same host, since each
18265 instance closes its port after the first connection.
18266
18267 @subsubsection Other Command-Line Arguments for @code{gdbserver}
18268
18269 @cindex @option{--debug}, @code{gdbserver} option
18270 The @option{--debug} option tells @code{gdbserver} to display extra
18271 status information about the debugging process.
18272 @cindex @option{--remote-debug}, @code{gdbserver} option
18273 The @option{--remote-debug} option tells @code{gdbserver} to display
18274 remote protocol debug output. These options are intended for
18275 @code{gdbserver} development and for bug reports to the developers.
18276
18277 @cindex @option{--wrapper}, @code{gdbserver} option
18278 The @option{--wrapper} option specifies a wrapper to launch programs
18279 for debugging. The option should be followed by the name of the
18280 wrapper, then any command-line arguments to pass to the wrapper, then
18281 @kbd{--} indicating the end of the wrapper arguments.
18282
18283 @code{gdbserver} runs the specified wrapper program with a combined
18284 command line including the wrapper arguments, then the name of the
18285 program to debug, then any arguments to the program. The wrapper
18286 runs until it executes your program, and then @value{GDBN} gains control.
18287
18288 You can use any program that eventually calls @code{execve} with
18289 its arguments as a wrapper. Several standard Unix utilities do
18290 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
18291 with @code{exec "$@@"} will also work.
18292
18293 For example, you can use @code{env} to pass an environment variable to
18294 the debugged program, without setting the variable in @code{gdbserver}'s
18295 environment:
18296
18297 @smallexample
18298 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
18299 @end smallexample
18300
18301 @subsection Connecting to @code{gdbserver}
18302
18303 Run @value{GDBN} on the host system.
18304
18305 First make sure you have the necessary symbol files. Load symbols for
18306 your application using the @code{file} command before you connect. Use
18307 @code{set sysroot} to locate target libraries (unless your @value{GDBN}
18308 was compiled with the correct sysroot using @code{--with-sysroot}).
18309
18310 The symbol file and target libraries must exactly match the executable
18311 and libraries on the target, with one exception: the files on the host
18312 system should not be stripped, even if the files on the target system
18313 are. Mismatched or missing files will lead to confusing results
18314 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
18315 files may also prevent @code{gdbserver} from debugging multi-threaded
18316 programs.
18317
18318 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
18319 For TCP connections, you must start up @code{gdbserver} prior to using
18320 the @code{target remote} command. Otherwise you may get an error whose
18321 text depends on the host system, but which usually looks something like
18322 @samp{Connection refused}. Don't use the @code{load}
18323 command in @value{GDBN} when using @code{gdbserver}, since the program is
18324 already on the target.
18325
18326 @subsection Monitor Commands for @code{gdbserver}
18327 @cindex monitor commands, for @code{gdbserver}
18328 @anchor{Monitor Commands for gdbserver}
18329
18330 During a @value{GDBN} session using @code{gdbserver}, you can use the
18331 @code{monitor} command to send special requests to @code{gdbserver}.
18332 Here are the available commands.
18333
18334 @table @code
18335 @item monitor help
18336 List the available monitor commands.
18337
18338 @item monitor set debug 0
18339 @itemx monitor set debug 1
18340 Disable or enable general debugging messages.
18341
18342 @item monitor set remote-debug 0
18343 @itemx monitor set remote-debug 1
18344 Disable or enable specific debugging messages associated with the remote
18345 protocol (@pxref{Remote Protocol}).
18346
18347 @item monitor set libthread-db-search-path [PATH]
18348 @cindex gdbserver, search path for @code{libthread_db}
18349 When this command is issued, @var{path} is a colon-separated list of
18350 directories to search for @code{libthread_db} (@pxref{Threads,,set
18351 libthread-db-search-path}). If you omit @var{path},
18352 @samp{libthread-db-search-path} will be reset to its default value.
18353
18354 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
18355 not supported in @code{gdbserver}.
18356
18357 @item monitor exit
18358 Tell gdbserver to exit immediately. This command should be followed by
18359 @code{disconnect} to close the debugging session. @code{gdbserver} will
18360 detach from any attached processes and kill any processes it created.
18361 Use @code{monitor exit} to terminate @code{gdbserver} at the end
18362 of a multi-process mode debug session.
18363
18364 @end table
18365
18366 @subsection Tracepoints support in @code{gdbserver}
18367 @cindex tracepoints support in @code{gdbserver}
18368
18369 On some targets, @code{gdbserver} supports tracepoints, fast
18370 tracepoints and static tracepoints.
18371
18372 For fast or static tracepoints to work, a special library called the
18373 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
18374 This library is built and distributed as an integral part of
18375 @code{gdbserver}. In addition, support for static tracepoints
18376 requires building the in-process agent library with static tracepoints
18377 support. At present, the UST (LTTng Userspace Tracer,
18378 @url{http://lttng.org/ust}) tracing engine is supported. This support
18379 is automatically available if UST development headers are found in the
18380 standard include path when @code{gdbserver} is built, or if
18381 @code{gdbserver} was explicitly configured using @option{--with-ust}
18382 to point at such headers. You can explicitly disable the support
18383 using @option{--with-ust=no}.
18384
18385 There are several ways to load the in-process agent in your program:
18386
18387 @table @code
18388 @item Specifying it as dependency at link time
18389
18390 You can link your program dynamically with the in-process agent
18391 library. On most systems, this is accomplished by adding
18392 @code{-linproctrace} to the link command.
18393
18394 @item Using the system's preloading mechanisms
18395
18396 You can force loading the in-process agent at startup time by using
18397 your system's support for preloading shared libraries. Many Unixes
18398 support the concept of preloading user defined libraries. In most
18399 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
18400 in the environment. See also the description of @code{gdbserver}'s
18401 @option{--wrapper} command line option.
18402
18403 @item Using @value{GDBN} to force loading the agent at run time
18404
18405 On some systems, you can force the inferior to load a shared library,
18406 by calling a dynamic loader function in the inferior that takes care
18407 of dynamically looking up and loading a shared library. On most Unix
18408 systems, the function is @code{dlopen}. You'll use the @code{call}
18409 command for that. For example:
18410
18411 @smallexample
18412 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
18413 @end smallexample
18414
18415 Note that on most Unix systems, for the @code{dlopen} function to be
18416 available, the program needs to be linked with @code{-ldl}.
18417 @end table
18418
18419 On systems that have a userspace dynamic loader, like most Unix
18420 systems, when you connect to @code{gdbserver} using @code{target
18421 remote}, you'll find that the program is stopped at the dynamic
18422 loader's entry point, and no shared library has been loaded in the
18423 program's address space yet, including the in-process agent. In that
18424 case, before being able to use any of the fast or static tracepoints
18425 features, you need to let the loader run and load the shared
18426 libraries. The simplest way to do that is to run the program to the
18427 main procedure. E.g., if debugging a C or C@t{++} program, start
18428 @code{gdbserver} like so:
18429
18430 @smallexample
18431 $ gdbserver :9999 myprogram
18432 @end smallexample
18433
18434 Start GDB and connect to @code{gdbserver} like so, and run to main:
18435
18436 @smallexample
18437 $ gdb myprogram
18438 (@value{GDBP}) target remote myhost:9999
18439 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
18440 (@value{GDBP}) b main
18441 (@value{GDBP}) continue
18442 @end smallexample
18443
18444 The in-process tracing agent library should now be loaded into the
18445 process; you can confirm it with the @code{info sharedlibrary}
18446 command, which will list @file{libinproctrace.so} as loaded in the
18447 process. You are now ready to install fast tracepoints, list static
18448 tracepoint markers, probe static tracepoints markers, and start
18449 tracing.
18450
18451 @node Remote Configuration
18452 @section Remote Configuration
18453
18454 @kindex set remote
18455 @kindex show remote
18456 This section documents the configuration options available when
18457 debugging remote programs. For the options related to the File I/O
18458 extensions of the remote protocol, see @ref{system,
18459 system-call-allowed}.
18460
18461 @table @code
18462 @item set remoteaddresssize @var{bits}
18463 @cindex address size for remote targets
18464 @cindex bits in remote address
18465 Set the maximum size of address in a memory packet to the specified
18466 number of bits. @value{GDBN} will mask off the address bits above
18467 that number, when it passes addresses to the remote target. The
18468 default value is the number of bits in the target's address.
18469
18470 @item show remoteaddresssize
18471 Show the current value of remote address size in bits.
18472
18473 @item set remotebaud @var{n}
18474 @cindex baud rate for remote targets
18475 Set the baud rate for the remote serial I/O to @var{n} baud. The
18476 value is used to set the speed of the serial port used for debugging
18477 remote targets.
18478
18479 @item show remotebaud
18480 Show the current speed of the remote connection.
18481
18482 @item set remotebreak
18483 @cindex interrupt remote programs
18484 @cindex BREAK signal instead of Ctrl-C
18485 @anchor{set remotebreak}
18486 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
18487 when you type @kbd{Ctrl-c} to interrupt the program running
18488 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
18489 character instead. The default is off, since most remote systems
18490 expect to see @samp{Ctrl-C} as the interrupt signal.
18491
18492 @item show remotebreak
18493 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
18494 interrupt the remote program.
18495
18496 @item set remoteflow on
18497 @itemx set remoteflow off
18498 @kindex set remoteflow
18499 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
18500 on the serial port used to communicate to the remote target.
18501
18502 @item show remoteflow
18503 @kindex show remoteflow
18504 Show the current setting of hardware flow control.
18505
18506 @item set remotelogbase @var{base}
18507 Set the base (a.k.a.@: radix) of logging serial protocol
18508 communications to @var{base}. Supported values of @var{base} are:
18509 @code{ascii}, @code{octal}, and @code{hex}. The default is
18510 @code{ascii}.
18511
18512 @item show remotelogbase
18513 Show the current setting of the radix for logging remote serial
18514 protocol.
18515
18516 @item set remotelogfile @var{file}
18517 @cindex record serial communications on file
18518 Record remote serial communications on the named @var{file}. The
18519 default is not to record at all.
18520
18521 @item show remotelogfile.
18522 Show the current setting of the file name on which to record the
18523 serial communications.
18524
18525 @item set remotetimeout @var{num}
18526 @cindex timeout for serial communications
18527 @cindex remote timeout
18528 Set the timeout limit to wait for the remote target to respond to
18529 @var{num} seconds. The default is 2 seconds.
18530
18531 @item show remotetimeout
18532 Show the current number of seconds to wait for the remote target
18533 responses.
18534
18535 @cindex limit hardware breakpoints and watchpoints
18536 @cindex remote target, limit break- and watchpoints
18537 @anchor{set remote hardware-watchpoint-limit}
18538 @anchor{set remote hardware-breakpoint-limit}
18539 @item set remote hardware-watchpoint-limit @var{limit}
18540 @itemx set remote hardware-breakpoint-limit @var{limit}
18541 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
18542 watchpoints. A limit of -1, the default, is treated as unlimited.
18543
18544 @cindex limit hardware watchpoints length
18545 @cindex remote target, limit watchpoints length
18546 @anchor{set remote hardware-watchpoint-length-limit}
18547 @item set remote hardware-watchpoint-length-limit @var{limit}
18548 Restrict @value{GDBN} to using @var{limit} bytes for the maximum length of
18549 a remote hardware watchpoint. A limit of -1, the default, is treated
18550 as unlimited.
18551
18552 @item show remote hardware-watchpoint-length-limit
18553 Show the current limit (in bytes) of the maximum length of
18554 a remote hardware watchpoint.
18555
18556 @item set remote exec-file @var{filename}
18557 @itemx show remote exec-file
18558 @anchor{set remote exec-file}
18559 @cindex executable file, for remote target
18560 Select the file used for @code{run} with @code{target
18561 extended-remote}. This should be set to a filename valid on the
18562 target system. If it is not set, the target will use a default
18563 filename (e.g.@: the last program run).
18564
18565 @item set remote interrupt-sequence
18566 @cindex interrupt remote programs
18567 @cindex select Ctrl-C, BREAK or BREAK-g
18568 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
18569 @samp{BREAK-g} as the
18570 sequence to the remote target in order to interrupt the execution.
18571 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
18572 is high level of serial line for some certain time.
18573 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
18574 It is @code{BREAK} signal followed by character @code{g}.
18575
18576 @item show interrupt-sequence
18577 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
18578 is sent by @value{GDBN} to interrupt the remote program.
18579 @code{BREAK-g} is BREAK signal followed by @code{g} and
18580 also known as Magic SysRq g.
18581
18582 @item set remote interrupt-on-connect
18583 @cindex send interrupt-sequence on start
18584 Specify whether interrupt-sequence is sent to remote target when
18585 @value{GDBN} connects to it. This is mostly needed when you debug
18586 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
18587 which is known as Magic SysRq g in order to connect @value{GDBN}.
18588
18589 @item show interrupt-on-connect
18590 Show whether interrupt-sequence is sent
18591 to remote target when @value{GDBN} connects to it.
18592
18593 @kindex set tcp
18594 @kindex show tcp
18595 @item set tcp auto-retry on
18596 @cindex auto-retry, for remote TCP target
18597 Enable auto-retry for remote TCP connections. This is useful if the remote
18598 debugging agent is launched in parallel with @value{GDBN}; there is a race
18599 condition because the agent may not become ready to accept the connection
18600 before @value{GDBN} attempts to connect. When auto-retry is
18601 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
18602 to establish the connection using the timeout specified by
18603 @code{set tcp connect-timeout}.
18604
18605 @item set tcp auto-retry off
18606 Do not auto-retry failed TCP connections.
18607
18608 @item show tcp auto-retry
18609 Show the current auto-retry setting.
18610
18611 @item set tcp connect-timeout @var{seconds}
18612 @itemx set tcp connect-timeout unlimited
18613 @cindex connection timeout, for remote TCP target
18614 @cindex timeout, for remote target connection
18615 Set the timeout for establishing a TCP connection to the remote target to
18616 @var{seconds}. The timeout affects both polling to retry failed connections
18617 (enabled by @code{set tcp auto-retry on}) and waiting for connections
18618 that are merely slow to complete, and represents an approximate cumulative
18619 value. If @var{seconds} is @code{unlimited}, there is no timeout and
18620 @value{GDBN} will keep attempting to establish a connection forever,
18621 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
18622
18623 @item show tcp connect-timeout
18624 Show the current connection timeout setting.
18625 @end table
18626
18627 @cindex remote packets, enabling and disabling
18628 The @value{GDBN} remote protocol autodetects the packets supported by
18629 your debugging stub. If you need to override the autodetection, you
18630 can use these commands to enable or disable individual packets. Each
18631 packet can be set to @samp{on} (the remote target supports this
18632 packet), @samp{off} (the remote target does not support this packet),
18633 or @samp{auto} (detect remote target support for this packet). They
18634 all default to @samp{auto}. For more information about each packet,
18635 see @ref{Remote Protocol}.
18636
18637 During normal use, you should not have to use any of these commands.
18638 If you do, that may be a bug in your remote debugging stub, or a bug
18639 in @value{GDBN}. You may want to report the problem to the
18640 @value{GDBN} developers.
18641
18642 For each packet @var{name}, the command to enable or disable the
18643 packet is @code{set remote @var{name}-packet}. The available settings
18644 are:
18645
18646 @multitable @columnfractions 0.28 0.32 0.25
18647 @item Command Name
18648 @tab Remote Packet
18649 @tab Related Features
18650
18651 @item @code{fetch-register}
18652 @tab @code{p}
18653 @tab @code{info registers}
18654
18655 @item @code{set-register}
18656 @tab @code{P}
18657 @tab @code{set}
18658
18659 @item @code{binary-download}
18660 @tab @code{X}
18661 @tab @code{load}, @code{set}
18662
18663 @item @code{read-aux-vector}
18664 @tab @code{qXfer:auxv:read}
18665 @tab @code{info auxv}
18666
18667 @item @code{symbol-lookup}
18668 @tab @code{qSymbol}
18669 @tab Detecting multiple threads
18670
18671 @item @code{attach}
18672 @tab @code{vAttach}
18673 @tab @code{attach}
18674
18675 @item @code{verbose-resume}
18676 @tab @code{vCont}
18677 @tab Stepping or resuming multiple threads
18678
18679 @item @code{run}
18680 @tab @code{vRun}
18681 @tab @code{run}
18682
18683 @item @code{software-breakpoint}
18684 @tab @code{Z0}
18685 @tab @code{break}
18686
18687 @item @code{hardware-breakpoint}
18688 @tab @code{Z1}
18689 @tab @code{hbreak}
18690
18691 @item @code{write-watchpoint}
18692 @tab @code{Z2}
18693 @tab @code{watch}
18694
18695 @item @code{read-watchpoint}
18696 @tab @code{Z3}
18697 @tab @code{rwatch}
18698
18699 @item @code{access-watchpoint}
18700 @tab @code{Z4}
18701 @tab @code{awatch}
18702
18703 @item @code{target-features}
18704 @tab @code{qXfer:features:read}
18705 @tab @code{set architecture}
18706
18707 @item @code{library-info}
18708 @tab @code{qXfer:libraries:read}
18709 @tab @code{info sharedlibrary}
18710
18711 @item @code{memory-map}
18712 @tab @code{qXfer:memory-map:read}
18713 @tab @code{info mem}
18714
18715 @item @code{read-sdata-object}
18716 @tab @code{qXfer:sdata:read}
18717 @tab @code{print $_sdata}
18718
18719 @item @code{read-spu-object}
18720 @tab @code{qXfer:spu:read}
18721 @tab @code{info spu}
18722
18723 @item @code{write-spu-object}
18724 @tab @code{qXfer:spu:write}
18725 @tab @code{info spu}
18726
18727 @item @code{read-siginfo-object}
18728 @tab @code{qXfer:siginfo:read}
18729 @tab @code{print $_siginfo}
18730
18731 @item @code{write-siginfo-object}
18732 @tab @code{qXfer:siginfo:write}
18733 @tab @code{set $_siginfo}
18734
18735 @item @code{threads}
18736 @tab @code{qXfer:threads:read}
18737 @tab @code{info threads}
18738
18739 @item @code{get-thread-local-@*storage-address}
18740 @tab @code{qGetTLSAddr}
18741 @tab Displaying @code{__thread} variables
18742
18743 @item @code{get-thread-information-block-address}
18744 @tab @code{qGetTIBAddr}
18745 @tab Display MS-Windows Thread Information Block.
18746
18747 @item @code{search-memory}
18748 @tab @code{qSearch:memory}
18749 @tab @code{find}
18750
18751 @item @code{supported-packets}
18752 @tab @code{qSupported}
18753 @tab Remote communications parameters
18754
18755 @item @code{pass-signals}
18756 @tab @code{QPassSignals}
18757 @tab @code{handle @var{signal}}
18758
18759 @item @code{program-signals}
18760 @tab @code{QProgramSignals}
18761 @tab @code{handle @var{signal}}
18762
18763 @item @code{hostio-close-packet}
18764 @tab @code{vFile:close}
18765 @tab @code{remote get}, @code{remote put}
18766
18767 @item @code{hostio-open-packet}
18768 @tab @code{vFile:open}
18769 @tab @code{remote get}, @code{remote put}
18770
18771 @item @code{hostio-pread-packet}
18772 @tab @code{vFile:pread}
18773 @tab @code{remote get}, @code{remote put}
18774
18775 @item @code{hostio-pwrite-packet}
18776 @tab @code{vFile:pwrite}
18777 @tab @code{remote get}, @code{remote put}
18778
18779 @item @code{hostio-unlink-packet}
18780 @tab @code{vFile:unlink}
18781 @tab @code{remote delete}
18782
18783 @item @code{hostio-readlink-packet}
18784 @tab @code{vFile:readlink}
18785 @tab Host I/O
18786
18787 @item @code{noack-packet}
18788 @tab @code{QStartNoAckMode}
18789 @tab Packet acknowledgment
18790
18791 @item @code{osdata}
18792 @tab @code{qXfer:osdata:read}
18793 @tab @code{info os}
18794
18795 @item @code{query-attached}
18796 @tab @code{qAttached}
18797 @tab Querying remote process attach state.
18798
18799 @item @code{trace-buffer-size}
18800 @tab @code{QTBuffer:size}
18801 @tab @code{set trace-buffer-size}
18802
18803 @item @code{trace-status}
18804 @tab @code{qTStatus}
18805 @tab @code{tstatus}
18806
18807 @item @code{traceframe-info}
18808 @tab @code{qXfer:traceframe-info:read}
18809 @tab Traceframe info
18810
18811 @item @code{install-in-trace}
18812 @tab @code{InstallInTrace}
18813 @tab Install tracepoint in tracing
18814
18815 @item @code{disable-randomization}
18816 @tab @code{QDisableRandomization}
18817 @tab @code{set disable-randomization}
18818
18819 @item @code{conditional-breakpoints-packet}
18820 @tab @code{Z0 and Z1}
18821 @tab @code{Support for target-side breakpoint condition evaluation}
18822 @end multitable
18823
18824 @node Remote Stub
18825 @section Implementing a Remote Stub
18826
18827 @cindex debugging stub, example
18828 @cindex remote stub, example
18829 @cindex stub example, remote debugging
18830 The stub files provided with @value{GDBN} implement the target side of the
18831 communication protocol, and the @value{GDBN} side is implemented in the
18832 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
18833 these subroutines to communicate, and ignore the details. (If you're
18834 implementing your own stub file, you can still ignore the details: start
18835 with one of the existing stub files. @file{sparc-stub.c} is the best
18836 organized, and therefore the easiest to read.)
18837
18838 @cindex remote serial debugging, overview
18839 To debug a program running on another machine (the debugging
18840 @dfn{target} machine), you must first arrange for all the usual
18841 prerequisites for the program to run by itself. For example, for a C
18842 program, you need:
18843
18844 @enumerate
18845 @item
18846 A startup routine to set up the C runtime environment; these usually
18847 have a name like @file{crt0}. The startup routine may be supplied by
18848 your hardware supplier, or you may have to write your own.
18849
18850 @item
18851 A C subroutine library to support your program's
18852 subroutine calls, notably managing input and output.
18853
18854 @item
18855 A way of getting your program to the other machine---for example, a
18856 download program. These are often supplied by the hardware
18857 manufacturer, but you may have to write your own from hardware
18858 documentation.
18859 @end enumerate
18860
18861 The next step is to arrange for your program to use a serial port to
18862 communicate with the machine where @value{GDBN} is running (the @dfn{host}
18863 machine). In general terms, the scheme looks like this:
18864
18865 @table @emph
18866 @item On the host,
18867 @value{GDBN} already understands how to use this protocol; when everything
18868 else is set up, you can simply use the @samp{target remote} command
18869 (@pxref{Targets,,Specifying a Debugging Target}).
18870
18871 @item On the target,
18872 you must link with your program a few special-purpose subroutines that
18873 implement the @value{GDBN} remote serial protocol. The file containing these
18874 subroutines is called a @dfn{debugging stub}.
18875
18876 On certain remote targets, you can use an auxiliary program
18877 @code{gdbserver} instead of linking a stub into your program.
18878 @xref{Server,,Using the @code{gdbserver} Program}, for details.
18879 @end table
18880
18881 The debugging stub is specific to the architecture of the remote
18882 machine; for example, use @file{sparc-stub.c} to debug programs on
18883 @sc{sparc} boards.
18884
18885 @cindex remote serial stub list
18886 These working remote stubs are distributed with @value{GDBN}:
18887
18888 @table @code
18889
18890 @item i386-stub.c
18891 @cindex @file{i386-stub.c}
18892 @cindex Intel
18893 @cindex i386
18894 For Intel 386 and compatible architectures.
18895
18896 @item m68k-stub.c
18897 @cindex @file{m68k-stub.c}
18898 @cindex Motorola 680x0
18899 @cindex m680x0
18900 For Motorola 680x0 architectures.
18901
18902 @item sh-stub.c
18903 @cindex @file{sh-stub.c}
18904 @cindex Renesas
18905 @cindex SH
18906 For Renesas SH architectures.
18907
18908 @item sparc-stub.c
18909 @cindex @file{sparc-stub.c}
18910 @cindex Sparc
18911 For @sc{sparc} architectures.
18912
18913 @item sparcl-stub.c
18914 @cindex @file{sparcl-stub.c}
18915 @cindex Fujitsu
18916 @cindex SparcLite
18917 For Fujitsu @sc{sparclite} architectures.
18918
18919 @end table
18920
18921 The @file{README} file in the @value{GDBN} distribution may list other
18922 recently added stubs.
18923
18924 @menu
18925 * Stub Contents:: What the stub can do for you
18926 * Bootstrapping:: What you must do for the stub
18927 * Debug Session:: Putting it all together
18928 @end menu
18929
18930 @node Stub Contents
18931 @subsection What the Stub Can Do for You
18932
18933 @cindex remote serial stub
18934 The debugging stub for your architecture supplies these three
18935 subroutines:
18936
18937 @table @code
18938 @item set_debug_traps
18939 @findex set_debug_traps
18940 @cindex remote serial stub, initialization
18941 This routine arranges for @code{handle_exception} to run when your
18942 program stops. You must call this subroutine explicitly in your
18943 program's startup code.
18944
18945 @item handle_exception
18946 @findex handle_exception
18947 @cindex remote serial stub, main routine
18948 This is the central workhorse, but your program never calls it
18949 explicitly---the setup code arranges for @code{handle_exception} to
18950 run when a trap is triggered.
18951
18952 @code{handle_exception} takes control when your program stops during
18953 execution (for example, on a breakpoint), and mediates communications
18954 with @value{GDBN} on the host machine. This is where the communications
18955 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
18956 representative on the target machine. It begins by sending summary
18957 information on the state of your program, then continues to execute,
18958 retrieving and transmitting any information @value{GDBN} needs, until you
18959 execute a @value{GDBN} command that makes your program resume; at that point,
18960 @code{handle_exception} returns control to your own code on the target
18961 machine.
18962
18963 @item breakpoint
18964 @cindex @code{breakpoint} subroutine, remote
18965 Use this auxiliary subroutine to make your program contain a
18966 breakpoint. Depending on the particular situation, this may be the only
18967 way for @value{GDBN} to get control. For instance, if your target
18968 machine has some sort of interrupt button, you won't need to call this;
18969 pressing the interrupt button transfers control to
18970 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
18971 simply receiving characters on the serial port may also trigger a trap;
18972 again, in that situation, you don't need to call @code{breakpoint} from
18973 your own program---simply running @samp{target remote} from the host
18974 @value{GDBN} session gets control.
18975
18976 Call @code{breakpoint} if none of these is true, or if you simply want
18977 to make certain your program stops at a predetermined point for the
18978 start of your debugging session.
18979 @end table
18980
18981 @node Bootstrapping
18982 @subsection What You Must Do for the Stub
18983
18984 @cindex remote stub, support routines
18985 The debugging stubs that come with @value{GDBN} are set up for a particular
18986 chip architecture, but they have no information about the rest of your
18987 debugging target machine.
18988
18989 First of all you need to tell the stub how to communicate with the
18990 serial port.
18991
18992 @table @code
18993 @item int getDebugChar()
18994 @findex getDebugChar
18995 Write this subroutine to read a single character from the serial port.
18996 It may be identical to @code{getchar} for your target system; a
18997 different name is used to allow you to distinguish the two if you wish.
18998
18999 @item void putDebugChar(int)
19000 @findex putDebugChar
19001 Write this subroutine to write a single character to the serial port.
19002 It may be identical to @code{putchar} for your target system; a
19003 different name is used to allow you to distinguish the two if you wish.
19004 @end table
19005
19006 @cindex control C, and remote debugging
19007 @cindex interrupting remote targets
19008 If you want @value{GDBN} to be able to stop your program while it is
19009 running, you need to use an interrupt-driven serial driver, and arrange
19010 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
19011 character). That is the character which @value{GDBN} uses to tell the
19012 remote system to stop.
19013
19014 Getting the debugging target to return the proper status to @value{GDBN}
19015 probably requires changes to the standard stub; one quick and dirty way
19016 is to just execute a breakpoint instruction (the ``dirty'' part is that
19017 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
19018
19019 Other routines you need to supply are:
19020
19021 @table @code
19022 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
19023 @findex exceptionHandler
19024 Write this function to install @var{exception_address} in the exception
19025 handling tables. You need to do this because the stub does not have any
19026 way of knowing what the exception handling tables on your target system
19027 are like (for example, the processor's table might be in @sc{rom},
19028 containing entries which point to a table in @sc{ram}).
19029 @var{exception_number} is the exception number which should be changed;
19030 its meaning is architecture-dependent (for example, different numbers
19031 might represent divide by zero, misaligned access, etc). When this
19032 exception occurs, control should be transferred directly to
19033 @var{exception_address}, and the processor state (stack, registers,
19034 and so on) should be just as it is when a processor exception occurs. So if
19035 you want to use a jump instruction to reach @var{exception_address}, it
19036 should be a simple jump, not a jump to subroutine.
19037
19038 For the 386, @var{exception_address} should be installed as an interrupt
19039 gate so that interrupts are masked while the handler runs. The gate
19040 should be at privilege level 0 (the most privileged level). The
19041 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
19042 help from @code{exceptionHandler}.
19043
19044 @item void flush_i_cache()
19045 @findex flush_i_cache
19046 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
19047 instruction cache, if any, on your target machine. If there is no
19048 instruction cache, this subroutine may be a no-op.
19049
19050 On target machines that have instruction caches, @value{GDBN} requires this
19051 function to make certain that the state of your program is stable.
19052 @end table
19053
19054 @noindent
19055 You must also make sure this library routine is available:
19056
19057 @table @code
19058 @item void *memset(void *, int, int)
19059 @findex memset
19060 This is the standard library function @code{memset} that sets an area of
19061 memory to a known value. If you have one of the free versions of
19062 @code{libc.a}, @code{memset} can be found there; otherwise, you must
19063 either obtain it from your hardware manufacturer, or write your own.
19064 @end table
19065
19066 If you do not use the GNU C compiler, you may need other standard
19067 library subroutines as well; this varies from one stub to another,
19068 but in general the stubs are likely to use any of the common library
19069 subroutines which @code{@value{NGCC}} generates as inline code.
19070
19071
19072 @node Debug Session
19073 @subsection Putting it All Together
19074
19075 @cindex remote serial debugging summary
19076 In summary, when your program is ready to debug, you must follow these
19077 steps.
19078
19079 @enumerate
19080 @item
19081 Make sure you have defined the supporting low-level routines
19082 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
19083 @display
19084 @code{getDebugChar}, @code{putDebugChar},
19085 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
19086 @end display
19087
19088 @item
19089 Insert these lines in your program's startup code, before the main
19090 procedure is called:
19091
19092 @smallexample
19093 set_debug_traps();
19094 breakpoint();
19095 @end smallexample
19096
19097 On some machines, when a breakpoint trap is raised, the hardware
19098 automatically makes the PC point to the instruction after the
19099 breakpoint. If your machine doesn't do that, you may need to adjust
19100 @code{handle_exception} to arrange for it to return to the instruction
19101 after the breakpoint on this first invocation, so that your program
19102 doesn't keep hitting the initial breakpoint instead of making
19103 progress.
19104
19105 @item
19106 For the 680x0 stub only, you need to provide a variable called
19107 @code{exceptionHook}. Normally you just use:
19108
19109 @smallexample
19110 void (*exceptionHook)() = 0;
19111 @end smallexample
19112
19113 @noindent
19114 but if before calling @code{set_debug_traps}, you set it to point to a
19115 function in your program, that function is called when
19116 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
19117 error). The function indicated by @code{exceptionHook} is called with
19118 one parameter: an @code{int} which is the exception number.
19119
19120 @item
19121 Compile and link together: your program, the @value{GDBN} debugging stub for
19122 your target architecture, and the supporting subroutines.
19123
19124 @item
19125 Make sure you have a serial connection between your target machine and
19126 the @value{GDBN} host, and identify the serial port on the host.
19127
19128 @item
19129 @c The "remote" target now provides a `load' command, so we should
19130 @c document that. FIXME.
19131 Download your program to your target machine (or get it there by
19132 whatever means the manufacturer provides), and start it.
19133
19134 @item
19135 Start @value{GDBN} on the host, and connect to the target
19136 (@pxref{Connecting,,Connecting to a Remote Target}).
19137
19138 @end enumerate
19139
19140 @node Configurations
19141 @chapter Configuration-Specific Information
19142
19143 While nearly all @value{GDBN} commands are available for all native and
19144 cross versions of the debugger, there are some exceptions. This chapter
19145 describes things that are only available in certain configurations.
19146
19147 There are three major categories of configurations: native
19148 configurations, where the host and target are the same, embedded
19149 operating system configurations, which are usually the same for several
19150 different processor architectures, and bare embedded processors, which
19151 are quite different from each other.
19152
19153 @menu
19154 * Native::
19155 * Embedded OS::
19156 * Embedded Processors::
19157 * Architectures::
19158 @end menu
19159
19160 @node Native
19161 @section Native
19162
19163 This section describes details specific to particular native
19164 configurations.
19165
19166 @menu
19167 * HP-UX:: HP-UX
19168 * BSD libkvm Interface:: Debugging BSD kernel memory images
19169 * SVR4 Process Information:: SVR4 process information
19170 * DJGPP Native:: Features specific to the DJGPP port
19171 * Cygwin Native:: Features specific to the Cygwin port
19172 * Hurd Native:: Features specific to @sc{gnu} Hurd
19173 * Darwin:: Features specific to Darwin
19174 @end menu
19175
19176 @node HP-UX
19177 @subsection HP-UX
19178
19179 On HP-UX systems, if you refer to a function or variable name that
19180 begins with a dollar sign, @value{GDBN} searches for a user or system
19181 name first, before it searches for a convenience variable.
19182
19183
19184 @node BSD libkvm Interface
19185 @subsection BSD libkvm Interface
19186
19187 @cindex libkvm
19188 @cindex kernel memory image
19189 @cindex kernel crash dump
19190
19191 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
19192 interface that provides a uniform interface for accessing kernel virtual
19193 memory images, including live systems and crash dumps. @value{GDBN}
19194 uses this interface to allow you to debug live kernels and kernel crash
19195 dumps on many native BSD configurations. This is implemented as a
19196 special @code{kvm} debugging target. For debugging a live system, load
19197 the currently running kernel into @value{GDBN} and connect to the
19198 @code{kvm} target:
19199
19200 @smallexample
19201 (@value{GDBP}) @b{target kvm}
19202 @end smallexample
19203
19204 For debugging crash dumps, provide the file name of the crash dump as an
19205 argument:
19206
19207 @smallexample
19208 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
19209 @end smallexample
19210
19211 Once connected to the @code{kvm} target, the following commands are
19212 available:
19213
19214 @table @code
19215 @kindex kvm
19216 @item kvm pcb
19217 Set current context from the @dfn{Process Control Block} (PCB) address.
19218
19219 @item kvm proc
19220 Set current context from proc address. This command isn't available on
19221 modern FreeBSD systems.
19222 @end table
19223
19224 @node SVR4 Process Information
19225 @subsection SVR4 Process Information
19226 @cindex /proc
19227 @cindex examine process image
19228 @cindex process info via @file{/proc}
19229
19230 Many versions of SVR4 and compatible systems provide a facility called
19231 @samp{/proc} that can be used to examine the image of a running
19232 process using file-system subroutines.
19233
19234 If @value{GDBN} is configured for an operating system with this
19235 facility, the command @code{info proc} is available to report
19236 information about the process running your program, or about any
19237 process running on your system. This includes, as of this writing,
19238 @sc{gnu}/Linux, OSF/1 (Digital Unix), Solaris, and Irix, but
19239 not HP-UX, for example.
19240
19241 This command may also work on core files that were created on a system
19242 that has the @samp{/proc} facility.
19243
19244 @table @code
19245 @kindex info proc
19246 @cindex process ID
19247 @item info proc
19248 @itemx info proc @var{process-id}
19249 Summarize available information about any running process. If a
19250 process ID is specified by @var{process-id}, display information about
19251 that process; otherwise display information about the program being
19252 debugged. The summary includes the debugged process ID, the command
19253 line used to invoke it, its current working directory, and its
19254 executable file's absolute file name.
19255
19256 On some systems, @var{process-id} can be of the form
19257 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
19258 within a process. If the optional @var{pid} part is missing, it means
19259 a thread from the process being debugged (the leading @samp{/} still
19260 needs to be present, or else @value{GDBN} will interpret the number as
19261 a process ID rather than a thread ID).
19262
19263 @item info proc cmdline
19264 @cindex info proc cmdline
19265 Show the original command line of the process. This command is
19266 specific to @sc{gnu}/Linux.
19267
19268 @item info proc cwd
19269 @cindex info proc cwd
19270 Show the current working directory of the process. This command is
19271 specific to @sc{gnu}/Linux.
19272
19273 @item info proc exe
19274 @cindex info proc exe
19275 Show the name of executable of the process. This command is specific
19276 to @sc{gnu}/Linux.
19277
19278 @item info proc mappings
19279 @cindex memory address space mappings
19280 Report the memory address space ranges accessible in the program, with
19281 information on whether the process has read, write, or execute access
19282 rights to each range. On @sc{gnu}/Linux systems, each memory range
19283 includes the object file which is mapped to that range, instead of the
19284 memory access rights to that range.
19285
19286 @item info proc stat
19287 @itemx info proc status
19288 @cindex process detailed status information
19289 These subcommands are specific to @sc{gnu}/Linux systems. They show
19290 the process-related information, including the user ID and group ID;
19291 how many threads are there in the process; its virtual memory usage;
19292 the signals that are pending, blocked, and ignored; its TTY; its
19293 consumption of system and user time; its stack size; its @samp{nice}
19294 value; etc. For more information, see the @samp{proc} man page
19295 (type @kbd{man 5 proc} from your shell prompt).
19296
19297 @item info proc all
19298 Show all the information about the process described under all of the
19299 above @code{info proc} subcommands.
19300
19301 @ignore
19302 @comment These sub-options of 'info proc' were not included when
19303 @comment procfs.c was re-written. Keep their descriptions around
19304 @comment against the day when someone finds the time to put them back in.
19305 @kindex info proc times
19306 @item info proc times
19307 Starting time, user CPU time, and system CPU time for your program and
19308 its children.
19309
19310 @kindex info proc id
19311 @item info proc id
19312 Report on the process IDs related to your program: its own process ID,
19313 the ID of its parent, the process group ID, and the session ID.
19314 @end ignore
19315
19316 @item set procfs-trace
19317 @kindex set procfs-trace
19318 @cindex @code{procfs} API calls
19319 This command enables and disables tracing of @code{procfs} API calls.
19320
19321 @item show procfs-trace
19322 @kindex show procfs-trace
19323 Show the current state of @code{procfs} API call tracing.
19324
19325 @item set procfs-file @var{file}
19326 @kindex set procfs-file
19327 Tell @value{GDBN} to write @code{procfs} API trace to the named
19328 @var{file}. @value{GDBN} appends the trace info to the previous
19329 contents of the file. The default is to display the trace on the
19330 standard output.
19331
19332 @item show procfs-file
19333 @kindex show procfs-file
19334 Show the file to which @code{procfs} API trace is written.
19335
19336 @item proc-trace-entry
19337 @itemx proc-trace-exit
19338 @itemx proc-untrace-entry
19339 @itemx proc-untrace-exit
19340 @kindex proc-trace-entry
19341 @kindex proc-trace-exit
19342 @kindex proc-untrace-entry
19343 @kindex proc-untrace-exit
19344 These commands enable and disable tracing of entries into and exits
19345 from the @code{syscall} interface.
19346
19347 @item info pidlist
19348 @kindex info pidlist
19349 @cindex process list, QNX Neutrino
19350 For QNX Neutrino only, this command displays the list of all the
19351 processes and all the threads within each process.
19352
19353 @item info meminfo
19354 @kindex info meminfo
19355 @cindex mapinfo list, QNX Neutrino
19356 For QNX Neutrino only, this command displays the list of all mapinfos.
19357 @end table
19358
19359 @node DJGPP Native
19360 @subsection Features for Debugging @sc{djgpp} Programs
19361 @cindex @sc{djgpp} debugging
19362 @cindex native @sc{djgpp} debugging
19363 @cindex MS-DOS-specific commands
19364
19365 @cindex DPMI
19366 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
19367 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
19368 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
19369 top of real-mode DOS systems and their emulations.
19370
19371 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
19372 defines a few commands specific to the @sc{djgpp} port. This
19373 subsection describes those commands.
19374
19375 @table @code
19376 @kindex info dos
19377 @item info dos
19378 This is a prefix of @sc{djgpp}-specific commands which print
19379 information about the target system and important OS structures.
19380
19381 @kindex sysinfo
19382 @cindex MS-DOS system info
19383 @cindex free memory information (MS-DOS)
19384 @item info dos sysinfo
19385 This command displays assorted information about the underlying
19386 platform: the CPU type and features, the OS version and flavor, the
19387 DPMI version, and the available conventional and DPMI memory.
19388
19389 @cindex GDT
19390 @cindex LDT
19391 @cindex IDT
19392 @cindex segment descriptor tables
19393 @cindex descriptor tables display
19394 @item info dos gdt
19395 @itemx info dos ldt
19396 @itemx info dos idt
19397 These 3 commands display entries from, respectively, Global, Local,
19398 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
19399 tables are data structures which store a descriptor for each segment
19400 that is currently in use. The segment's selector is an index into a
19401 descriptor table; the table entry for that index holds the
19402 descriptor's base address and limit, and its attributes and access
19403 rights.
19404
19405 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
19406 segment (used for both data and the stack), and a DOS segment (which
19407 allows access to DOS/BIOS data structures and absolute addresses in
19408 conventional memory). However, the DPMI host will usually define
19409 additional segments in order to support the DPMI environment.
19410
19411 @cindex garbled pointers
19412 These commands allow to display entries from the descriptor tables.
19413 Without an argument, all entries from the specified table are
19414 displayed. An argument, which should be an integer expression, means
19415 display a single entry whose index is given by the argument. For
19416 example, here's a convenient way to display information about the
19417 debugged program's data segment:
19418
19419 @smallexample
19420 @exdent @code{(@value{GDBP}) info dos ldt $ds}
19421 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
19422 @end smallexample
19423
19424 @noindent
19425 This comes in handy when you want to see whether a pointer is outside
19426 the data segment's limit (i.e.@: @dfn{garbled}).
19427
19428 @cindex page tables display (MS-DOS)
19429 @item info dos pde
19430 @itemx info dos pte
19431 These two commands display entries from, respectively, the Page
19432 Directory and the Page Tables. Page Directories and Page Tables are
19433 data structures which control how virtual memory addresses are mapped
19434 into physical addresses. A Page Table includes an entry for every
19435 page of memory that is mapped into the program's address space; there
19436 may be several Page Tables, each one holding up to 4096 entries. A
19437 Page Directory has up to 4096 entries, one each for every Page Table
19438 that is currently in use.
19439
19440 Without an argument, @kbd{info dos pde} displays the entire Page
19441 Directory, and @kbd{info dos pte} displays all the entries in all of
19442 the Page Tables. An argument, an integer expression, given to the
19443 @kbd{info dos pde} command means display only that entry from the Page
19444 Directory table. An argument given to the @kbd{info dos pte} command
19445 means display entries from a single Page Table, the one pointed to by
19446 the specified entry in the Page Directory.
19447
19448 @cindex direct memory access (DMA) on MS-DOS
19449 These commands are useful when your program uses @dfn{DMA} (Direct
19450 Memory Access), which needs physical addresses to program the DMA
19451 controller.
19452
19453 These commands are supported only with some DPMI servers.
19454
19455 @cindex physical address from linear address
19456 @item info dos address-pte @var{addr}
19457 This command displays the Page Table entry for a specified linear
19458 address. The argument @var{addr} is a linear address which should
19459 already have the appropriate segment's base address added to it,
19460 because this command accepts addresses which may belong to @emph{any}
19461 segment. For example, here's how to display the Page Table entry for
19462 the page where a variable @code{i} is stored:
19463
19464 @smallexample
19465 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
19466 @exdent @code{Page Table entry for address 0x11a00d30:}
19467 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
19468 @end smallexample
19469
19470 @noindent
19471 This says that @code{i} is stored at offset @code{0xd30} from the page
19472 whose physical base address is @code{0x02698000}, and shows all the
19473 attributes of that page.
19474
19475 Note that you must cast the addresses of variables to a @code{char *},
19476 since otherwise the value of @code{__djgpp_base_address}, the base
19477 address of all variables and functions in a @sc{djgpp} program, will
19478 be added using the rules of C pointer arithmetics: if @code{i} is
19479 declared an @code{int}, @value{GDBN} will add 4 times the value of
19480 @code{__djgpp_base_address} to the address of @code{i}.
19481
19482 Here's another example, it displays the Page Table entry for the
19483 transfer buffer:
19484
19485 @smallexample
19486 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
19487 @exdent @code{Page Table entry for address 0x29110:}
19488 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
19489 @end smallexample
19490
19491 @noindent
19492 (The @code{+ 3} offset is because the transfer buffer's address is the
19493 3rd member of the @code{_go32_info_block} structure.) The output
19494 clearly shows that this DPMI server maps the addresses in conventional
19495 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
19496 linear (@code{0x29110}) addresses are identical.
19497
19498 This command is supported only with some DPMI servers.
19499 @end table
19500
19501 @cindex DOS serial data link, remote debugging
19502 In addition to native debugging, the DJGPP port supports remote
19503 debugging via a serial data link. The following commands are specific
19504 to remote serial debugging in the DJGPP port of @value{GDBN}.
19505
19506 @table @code
19507 @kindex set com1base
19508 @kindex set com1irq
19509 @kindex set com2base
19510 @kindex set com2irq
19511 @kindex set com3base
19512 @kindex set com3irq
19513 @kindex set com4base
19514 @kindex set com4irq
19515 @item set com1base @var{addr}
19516 This command sets the base I/O port address of the @file{COM1} serial
19517 port.
19518
19519 @item set com1irq @var{irq}
19520 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
19521 for the @file{COM1} serial port.
19522
19523 There are similar commands @samp{set com2base}, @samp{set com3irq},
19524 etc.@: for setting the port address and the @code{IRQ} lines for the
19525 other 3 COM ports.
19526
19527 @kindex show com1base
19528 @kindex show com1irq
19529 @kindex show com2base
19530 @kindex show com2irq
19531 @kindex show com3base
19532 @kindex show com3irq
19533 @kindex show com4base
19534 @kindex show com4irq
19535 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
19536 display the current settings of the base address and the @code{IRQ}
19537 lines used by the COM ports.
19538
19539 @item info serial
19540 @kindex info serial
19541 @cindex DOS serial port status
19542 This command prints the status of the 4 DOS serial ports. For each
19543 port, it prints whether it's active or not, its I/O base address and
19544 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
19545 counts of various errors encountered so far.
19546 @end table
19547
19548
19549 @node Cygwin Native
19550 @subsection Features for Debugging MS Windows PE Executables
19551 @cindex MS Windows debugging
19552 @cindex native Cygwin debugging
19553 @cindex Cygwin-specific commands
19554
19555 @value{GDBN} supports native debugging of MS Windows programs, including
19556 DLLs with and without symbolic debugging information.
19557
19558 @cindex Ctrl-BREAK, MS-Windows
19559 @cindex interrupt debuggee on MS-Windows
19560 MS-Windows programs that call @code{SetConsoleMode} to switch off the
19561 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
19562 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
19563 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
19564 sequence, which can be used to interrupt the debuggee even if it
19565 ignores @kbd{C-c}.
19566
19567 There are various additional Cygwin-specific commands, described in
19568 this section. Working with DLLs that have no debugging symbols is
19569 described in @ref{Non-debug DLL Symbols}.
19570
19571 @table @code
19572 @kindex info w32
19573 @item info w32
19574 This is a prefix of MS Windows-specific commands which print
19575 information about the target system and important OS structures.
19576
19577 @item info w32 selector
19578 This command displays information returned by
19579 the Win32 API @code{GetThreadSelectorEntry} function.
19580 It takes an optional argument that is evaluated to
19581 a long value to give the information about this given selector.
19582 Without argument, this command displays information
19583 about the six segment registers.
19584
19585 @item info w32 thread-information-block
19586 This command displays thread specific information stored in the
19587 Thread Information Block (readable on the X86 CPU family using @code{$fs}
19588 selector for 32-bit programs and @code{$gs} for 64-bit programs).
19589
19590 @kindex info dll
19591 @item info dll
19592 This is a Cygwin-specific alias of @code{info shared}.
19593
19594 @kindex dll-symbols
19595 @item dll-symbols
19596 This command loads symbols from a dll similarly to
19597 add-sym command but without the need to specify a base address.
19598
19599 @kindex set cygwin-exceptions
19600 @cindex debugging the Cygwin DLL
19601 @cindex Cygwin DLL, debugging
19602 @item set cygwin-exceptions @var{mode}
19603 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
19604 happen inside the Cygwin DLL. If @var{mode} is @code{off},
19605 @value{GDBN} will delay recognition of exceptions, and may ignore some
19606 exceptions which seem to be caused by internal Cygwin DLL
19607 ``bookkeeping''. This option is meant primarily for debugging the
19608 Cygwin DLL itself; the default value is @code{off} to avoid annoying
19609 @value{GDBN} users with false @code{SIGSEGV} signals.
19610
19611 @kindex show cygwin-exceptions
19612 @item show cygwin-exceptions
19613 Displays whether @value{GDBN} will break on exceptions that happen
19614 inside the Cygwin DLL itself.
19615
19616 @kindex set new-console
19617 @item set new-console @var{mode}
19618 If @var{mode} is @code{on} the debuggee will
19619 be started in a new console on next start.
19620 If @var{mode} is @code{off}, the debuggee will
19621 be started in the same console as the debugger.
19622
19623 @kindex show new-console
19624 @item show new-console
19625 Displays whether a new console is used
19626 when the debuggee is started.
19627
19628 @kindex set new-group
19629 @item set new-group @var{mode}
19630 This boolean value controls whether the debuggee should
19631 start a new group or stay in the same group as the debugger.
19632 This affects the way the Windows OS handles
19633 @samp{Ctrl-C}.
19634
19635 @kindex show new-group
19636 @item show new-group
19637 Displays current value of new-group boolean.
19638
19639 @kindex set debugevents
19640 @item set debugevents
19641 This boolean value adds debug output concerning kernel events related
19642 to the debuggee seen by the debugger. This includes events that
19643 signal thread and process creation and exit, DLL loading and
19644 unloading, console interrupts, and debugging messages produced by the
19645 Windows @code{OutputDebugString} API call.
19646
19647 @kindex set debugexec
19648 @item set debugexec
19649 This boolean value adds debug output concerning execute events
19650 (such as resume thread) seen by the debugger.
19651
19652 @kindex set debugexceptions
19653 @item set debugexceptions
19654 This boolean value adds debug output concerning exceptions in the
19655 debuggee seen by the debugger.
19656
19657 @kindex set debugmemory
19658 @item set debugmemory
19659 This boolean value adds debug output concerning debuggee memory reads
19660 and writes by the debugger.
19661
19662 @kindex set shell
19663 @item set shell
19664 This boolean values specifies whether the debuggee is called
19665 via a shell or directly (default value is on).
19666
19667 @kindex show shell
19668 @item show shell
19669 Displays if the debuggee will be started with a shell.
19670
19671 @end table
19672
19673 @menu
19674 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
19675 @end menu
19676
19677 @node Non-debug DLL Symbols
19678 @subsubsection Support for DLLs without Debugging Symbols
19679 @cindex DLLs with no debugging symbols
19680 @cindex Minimal symbols and DLLs
19681
19682 Very often on windows, some of the DLLs that your program relies on do
19683 not include symbolic debugging information (for example,
19684 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
19685 symbols in a DLL, it relies on the minimal amount of symbolic
19686 information contained in the DLL's export table. This section
19687 describes working with such symbols, known internally to @value{GDBN} as
19688 ``minimal symbols''.
19689
19690 Note that before the debugged program has started execution, no DLLs
19691 will have been loaded. The easiest way around this problem is simply to
19692 start the program --- either by setting a breakpoint or letting the
19693 program run once to completion. It is also possible to force
19694 @value{GDBN} to load a particular DLL before starting the executable ---
19695 see the shared library information in @ref{Files}, or the
19696 @code{dll-symbols} command in @ref{Cygwin Native}. Currently,
19697 explicitly loading symbols from a DLL with no debugging information will
19698 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
19699 which may adversely affect symbol lookup performance.
19700
19701 @subsubsection DLL Name Prefixes
19702
19703 In keeping with the naming conventions used by the Microsoft debugging
19704 tools, DLL export symbols are made available with a prefix based on the
19705 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
19706 also entered into the symbol table, so @code{CreateFileA} is often
19707 sufficient. In some cases there will be name clashes within a program
19708 (particularly if the executable itself includes full debugging symbols)
19709 necessitating the use of the fully qualified name when referring to the
19710 contents of the DLL. Use single-quotes around the name to avoid the
19711 exclamation mark (``!'') being interpreted as a language operator.
19712
19713 Note that the internal name of the DLL may be all upper-case, even
19714 though the file name of the DLL is lower-case, or vice-versa. Since
19715 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
19716 some confusion. If in doubt, try the @code{info functions} and
19717 @code{info variables} commands or even @code{maint print msymbols}
19718 (@pxref{Symbols}). Here's an example:
19719
19720 @smallexample
19721 (@value{GDBP}) info function CreateFileA
19722 All functions matching regular expression "CreateFileA":
19723
19724 Non-debugging symbols:
19725 0x77e885f4 CreateFileA
19726 0x77e885f4 KERNEL32!CreateFileA
19727 @end smallexample
19728
19729 @smallexample
19730 (@value{GDBP}) info function !
19731 All functions matching regular expression "!":
19732
19733 Non-debugging symbols:
19734 0x6100114c cygwin1!__assert
19735 0x61004034 cygwin1!_dll_crt0@@0
19736 0x61004240 cygwin1!dll_crt0(per_process *)
19737 [etc...]
19738 @end smallexample
19739
19740 @subsubsection Working with Minimal Symbols
19741
19742 Symbols extracted from a DLL's export table do not contain very much
19743 type information. All that @value{GDBN} can do is guess whether a symbol
19744 refers to a function or variable depending on the linker section that
19745 contains the symbol. Also note that the actual contents of the memory
19746 contained in a DLL are not available unless the program is running. This
19747 means that you cannot examine the contents of a variable or disassemble
19748 a function within a DLL without a running program.
19749
19750 Variables are generally treated as pointers and dereferenced
19751 automatically. For this reason, it is often necessary to prefix a
19752 variable name with the address-of operator (``&'') and provide explicit
19753 type information in the command. Here's an example of the type of
19754 problem:
19755
19756 @smallexample
19757 (@value{GDBP}) print 'cygwin1!__argv'
19758 $1 = 268572168
19759 @end smallexample
19760
19761 @smallexample
19762 (@value{GDBP}) x 'cygwin1!__argv'
19763 0x10021610: "\230y\""
19764 @end smallexample
19765
19766 And two possible solutions:
19767
19768 @smallexample
19769 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
19770 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
19771 @end smallexample
19772
19773 @smallexample
19774 (@value{GDBP}) x/2x &'cygwin1!__argv'
19775 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
19776 (@value{GDBP}) x/x 0x10021608
19777 0x10021608: 0x0022fd98
19778 (@value{GDBP}) x/s 0x0022fd98
19779 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
19780 @end smallexample
19781
19782 Setting a break point within a DLL is possible even before the program
19783 starts execution. However, under these circumstances, @value{GDBN} can't
19784 examine the initial instructions of the function in order to skip the
19785 function's frame set-up code. You can work around this by using ``*&''
19786 to set the breakpoint at a raw memory address:
19787
19788 @smallexample
19789 (@value{GDBP}) break *&'python22!PyOS_Readline'
19790 Breakpoint 1 at 0x1e04eff0
19791 @end smallexample
19792
19793 The author of these extensions is not entirely convinced that setting a
19794 break point within a shared DLL like @file{kernel32.dll} is completely
19795 safe.
19796
19797 @node Hurd Native
19798 @subsection Commands Specific to @sc{gnu} Hurd Systems
19799 @cindex @sc{gnu} Hurd debugging
19800
19801 This subsection describes @value{GDBN} commands specific to the
19802 @sc{gnu} Hurd native debugging.
19803
19804 @table @code
19805 @item set signals
19806 @itemx set sigs
19807 @kindex set signals@r{, Hurd command}
19808 @kindex set sigs@r{, Hurd command}
19809 This command toggles the state of inferior signal interception by
19810 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
19811 affected by this command. @code{sigs} is a shorthand alias for
19812 @code{signals}.
19813
19814 @item show signals
19815 @itemx show sigs
19816 @kindex show signals@r{, Hurd command}
19817 @kindex show sigs@r{, Hurd command}
19818 Show the current state of intercepting inferior's signals.
19819
19820 @item set signal-thread
19821 @itemx set sigthread
19822 @kindex set signal-thread
19823 @kindex set sigthread
19824 This command tells @value{GDBN} which thread is the @code{libc} signal
19825 thread. That thread is run when a signal is delivered to a running
19826 process. @code{set sigthread} is the shorthand alias of @code{set
19827 signal-thread}.
19828
19829 @item show signal-thread
19830 @itemx show sigthread
19831 @kindex show signal-thread
19832 @kindex show sigthread
19833 These two commands show which thread will run when the inferior is
19834 delivered a signal.
19835
19836 @item set stopped
19837 @kindex set stopped@r{, Hurd command}
19838 This commands tells @value{GDBN} that the inferior process is stopped,
19839 as with the @code{SIGSTOP} signal. The stopped process can be
19840 continued by delivering a signal to it.
19841
19842 @item show stopped
19843 @kindex show stopped@r{, Hurd command}
19844 This command shows whether @value{GDBN} thinks the debuggee is
19845 stopped.
19846
19847 @item set exceptions
19848 @kindex set exceptions@r{, Hurd command}
19849 Use this command to turn off trapping of exceptions in the inferior.
19850 When exception trapping is off, neither breakpoints nor
19851 single-stepping will work. To restore the default, set exception
19852 trapping on.
19853
19854 @item show exceptions
19855 @kindex show exceptions@r{, Hurd command}
19856 Show the current state of trapping exceptions in the inferior.
19857
19858 @item set task pause
19859 @kindex set task@r{, Hurd commands}
19860 @cindex task attributes (@sc{gnu} Hurd)
19861 @cindex pause current task (@sc{gnu} Hurd)
19862 This command toggles task suspension when @value{GDBN} has control.
19863 Setting it to on takes effect immediately, and the task is suspended
19864 whenever @value{GDBN} gets control. Setting it to off will take
19865 effect the next time the inferior is continued. If this option is set
19866 to off, you can use @code{set thread default pause on} or @code{set
19867 thread pause on} (see below) to pause individual threads.
19868
19869 @item show task pause
19870 @kindex show task@r{, Hurd commands}
19871 Show the current state of task suspension.
19872
19873 @item set task detach-suspend-count
19874 @cindex task suspend count
19875 @cindex detach from task, @sc{gnu} Hurd
19876 This command sets the suspend count the task will be left with when
19877 @value{GDBN} detaches from it.
19878
19879 @item show task detach-suspend-count
19880 Show the suspend count the task will be left with when detaching.
19881
19882 @item set task exception-port
19883 @itemx set task excp
19884 @cindex task exception port, @sc{gnu} Hurd
19885 This command sets the task exception port to which @value{GDBN} will
19886 forward exceptions. The argument should be the value of the @dfn{send
19887 rights} of the task. @code{set task excp} is a shorthand alias.
19888
19889 @item set noninvasive
19890 @cindex noninvasive task options
19891 This command switches @value{GDBN} to a mode that is the least
19892 invasive as far as interfering with the inferior is concerned. This
19893 is the same as using @code{set task pause}, @code{set exceptions}, and
19894 @code{set signals} to values opposite to the defaults.
19895
19896 @item info send-rights
19897 @itemx info receive-rights
19898 @itemx info port-rights
19899 @itemx info port-sets
19900 @itemx info dead-names
19901 @itemx info ports
19902 @itemx info psets
19903 @cindex send rights, @sc{gnu} Hurd
19904 @cindex receive rights, @sc{gnu} Hurd
19905 @cindex port rights, @sc{gnu} Hurd
19906 @cindex port sets, @sc{gnu} Hurd
19907 @cindex dead names, @sc{gnu} Hurd
19908 These commands display information about, respectively, send rights,
19909 receive rights, port rights, port sets, and dead names of a task.
19910 There are also shorthand aliases: @code{info ports} for @code{info
19911 port-rights} and @code{info psets} for @code{info port-sets}.
19912
19913 @item set thread pause
19914 @kindex set thread@r{, Hurd command}
19915 @cindex thread properties, @sc{gnu} Hurd
19916 @cindex pause current thread (@sc{gnu} Hurd)
19917 This command toggles current thread suspension when @value{GDBN} has
19918 control. Setting it to on takes effect immediately, and the current
19919 thread is suspended whenever @value{GDBN} gets control. Setting it to
19920 off will take effect the next time the inferior is continued.
19921 Normally, this command has no effect, since when @value{GDBN} has
19922 control, the whole task is suspended. However, if you used @code{set
19923 task pause off} (see above), this command comes in handy to suspend
19924 only the current thread.
19925
19926 @item show thread pause
19927 @kindex show thread@r{, Hurd command}
19928 This command shows the state of current thread suspension.
19929
19930 @item set thread run
19931 This command sets whether the current thread is allowed to run.
19932
19933 @item show thread run
19934 Show whether the current thread is allowed to run.
19935
19936 @item set thread detach-suspend-count
19937 @cindex thread suspend count, @sc{gnu} Hurd
19938 @cindex detach from thread, @sc{gnu} Hurd
19939 This command sets the suspend count @value{GDBN} will leave on a
19940 thread when detaching. This number is relative to the suspend count
19941 found by @value{GDBN} when it notices the thread; use @code{set thread
19942 takeover-suspend-count} to force it to an absolute value.
19943
19944 @item show thread detach-suspend-count
19945 Show the suspend count @value{GDBN} will leave on the thread when
19946 detaching.
19947
19948 @item set thread exception-port
19949 @itemx set thread excp
19950 Set the thread exception port to which to forward exceptions. This
19951 overrides the port set by @code{set task exception-port} (see above).
19952 @code{set thread excp} is the shorthand alias.
19953
19954 @item set thread takeover-suspend-count
19955 Normally, @value{GDBN}'s thread suspend counts are relative to the
19956 value @value{GDBN} finds when it notices each thread. This command
19957 changes the suspend counts to be absolute instead.
19958
19959 @item set thread default
19960 @itemx show thread default
19961 @cindex thread default settings, @sc{gnu} Hurd
19962 Each of the above @code{set thread} commands has a @code{set thread
19963 default} counterpart (e.g., @code{set thread default pause}, @code{set
19964 thread default exception-port}, etc.). The @code{thread default}
19965 variety of commands sets the default thread properties for all
19966 threads; you can then change the properties of individual threads with
19967 the non-default commands.
19968 @end table
19969
19970 @node Darwin
19971 @subsection Darwin
19972 @cindex Darwin
19973
19974 @value{GDBN} provides the following commands specific to the Darwin target:
19975
19976 @table @code
19977 @item set debug darwin @var{num}
19978 @kindex set debug darwin
19979 When set to a non zero value, enables debugging messages specific to
19980 the Darwin support. Higher values produce more verbose output.
19981
19982 @item show debug darwin
19983 @kindex show debug darwin
19984 Show the current state of Darwin messages.
19985
19986 @item set debug mach-o @var{num}
19987 @kindex set debug mach-o
19988 When set to a non zero value, enables debugging messages while
19989 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
19990 file format used on Darwin for object and executable files.) Higher
19991 values produce more verbose output. This is a command to diagnose
19992 problems internal to @value{GDBN} and should not be needed in normal
19993 usage.
19994
19995 @item show debug mach-o
19996 @kindex show debug mach-o
19997 Show the current state of Mach-O file messages.
19998
19999 @item set mach-exceptions on
20000 @itemx set mach-exceptions off
20001 @kindex set mach-exceptions
20002 On Darwin, faults are first reported as a Mach exception and are then
20003 mapped to a Posix signal. Use this command to turn on trapping of
20004 Mach exceptions in the inferior. This might be sometimes useful to
20005 better understand the cause of a fault. The default is off.
20006
20007 @item show mach-exceptions
20008 @kindex show mach-exceptions
20009 Show the current state of exceptions trapping.
20010 @end table
20011
20012
20013 @node Embedded OS
20014 @section Embedded Operating Systems
20015
20016 This section describes configurations involving the debugging of
20017 embedded operating systems that are available for several different
20018 architectures.
20019
20020 @menu
20021 * VxWorks:: Using @value{GDBN} with VxWorks
20022 @end menu
20023
20024 @value{GDBN} includes the ability to debug programs running on
20025 various real-time operating systems.
20026
20027 @node VxWorks
20028 @subsection Using @value{GDBN} with VxWorks
20029
20030 @cindex VxWorks
20031
20032 @table @code
20033
20034 @kindex target vxworks
20035 @item target vxworks @var{machinename}
20036 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
20037 is the target system's machine name or IP address.
20038
20039 @end table
20040
20041 On VxWorks, @code{load} links @var{filename} dynamically on the
20042 current target system as well as adding its symbols in @value{GDBN}.
20043
20044 @value{GDBN} enables developers to spawn and debug tasks running on networked
20045 VxWorks targets from a Unix host. Already-running tasks spawned from
20046 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
20047 both the Unix host and on the VxWorks target. The program
20048 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
20049 installed with the name @code{vxgdb}, to distinguish it from a
20050 @value{GDBN} for debugging programs on the host itself.)
20051
20052 @table @code
20053 @item VxWorks-timeout @var{args}
20054 @kindex vxworks-timeout
20055 All VxWorks-based targets now support the option @code{vxworks-timeout}.
20056 This option is set by the user, and @var{args} represents the number of
20057 seconds @value{GDBN} waits for responses to rpc's. You might use this if
20058 your VxWorks target is a slow software simulator or is on the far side
20059 of a thin network line.
20060 @end table
20061
20062 The following information on connecting to VxWorks was current when
20063 this manual was produced; newer releases of VxWorks may use revised
20064 procedures.
20065
20066 @findex INCLUDE_RDB
20067 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
20068 to include the remote debugging interface routines in the VxWorks
20069 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
20070 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
20071 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
20072 source debugging task @code{tRdbTask} when VxWorks is booted. For more
20073 information on configuring and remaking VxWorks, see the manufacturer's
20074 manual.
20075 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
20076
20077 Once you have included @file{rdb.a} in your VxWorks system image and set
20078 your Unix execution search path to find @value{GDBN}, you are ready to
20079 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
20080 @code{vxgdb}, depending on your installation).
20081
20082 @value{GDBN} comes up showing the prompt:
20083
20084 @smallexample
20085 (vxgdb)
20086 @end smallexample
20087
20088 @menu
20089 * VxWorks Connection:: Connecting to VxWorks
20090 * VxWorks Download:: VxWorks download
20091 * VxWorks Attach:: Running tasks
20092 @end menu
20093
20094 @node VxWorks Connection
20095 @subsubsection Connecting to VxWorks
20096
20097 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
20098 network. To connect to a target whose host name is ``@code{tt}'', type:
20099
20100 @smallexample
20101 (vxgdb) target vxworks tt
20102 @end smallexample
20103
20104 @need 750
20105 @value{GDBN} displays messages like these:
20106
20107 @smallexample
20108 Attaching remote machine across net...
20109 Connected to tt.
20110 @end smallexample
20111
20112 @need 1000
20113 @value{GDBN} then attempts to read the symbol tables of any object modules
20114 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
20115 these files by searching the directories listed in the command search
20116 path (@pxref{Environment, ,Your Program's Environment}); if it fails
20117 to find an object file, it displays a message such as:
20118
20119 @smallexample
20120 prog.o: No such file or directory.
20121 @end smallexample
20122
20123 When this happens, add the appropriate directory to the search path with
20124 the @value{GDBN} command @code{path}, and execute the @code{target}
20125 command again.
20126
20127 @node VxWorks Download
20128 @subsubsection VxWorks Download
20129
20130 @cindex download to VxWorks
20131 If you have connected to the VxWorks target and you want to debug an
20132 object that has not yet been loaded, you can use the @value{GDBN}
20133 @code{load} command to download a file from Unix to VxWorks
20134 incrementally. The object file given as an argument to the @code{load}
20135 command is actually opened twice: first by the VxWorks target in order
20136 to download the code, then by @value{GDBN} in order to read the symbol
20137 table. This can lead to problems if the current working directories on
20138 the two systems differ. If both systems have NFS mounted the same
20139 filesystems, you can avoid these problems by using absolute paths.
20140 Otherwise, it is simplest to set the working directory on both systems
20141 to the directory in which the object file resides, and then to reference
20142 the file by its name, without any path. For instance, a program
20143 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
20144 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
20145 program, type this on VxWorks:
20146
20147 @smallexample
20148 -> cd "@var{vxpath}/vw/demo/rdb"
20149 @end smallexample
20150
20151 @noindent
20152 Then, in @value{GDBN}, type:
20153
20154 @smallexample
20155 (vxgdb) cd @var{hostpath}/vw/demo/rdb
20156 (vxgdb) load prog.o
20157 @end smallexample
20158
20159 @value{GDBN} displays a response similar to this:
20160
20161 @smallexample
20162 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
20163 @end smallexample
20164
20165 You can also use the @code{load} command to reload an object module
20166 after editing and recompiling the corresponding source file. Note that
20167 this makes @value{GDBN} delete all currently-defined breakpoints,
20168 auto-displays, and convenience variables, and to clear the value
20169 history. (This is necessary in order to preserve the integrity of
20170 debugger's data structures that reference the target system's symbol
20171 table.)
20172
20173 @node VxWorks Attach
20174 @subsubsection Running Tasks
20175
20176 @cindex running VxWorks tasks
20177 You can also attach to an existing task using the @code{attach} command as
20178 follows:
20179
20180 @smallexample
20181 (vxgdb) attach @var{task}
20182 @end smallexample
20183
20184 @noindent
20185 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
20186 or suspended when you attach to it. Running tasks are suspended at
20187 the time of attachment.
20188
20189 @node Embedded Processors
20190 @section Embedded Processors
20191
20192 This section goes into details specific to particular embedded
20193 configurations.
20194
20195 @cindex send command to simulator
20196 Whenever a specific embedded processor has a simulator, @value{GDBN}
20197 allows to send an arbitrary command to the simulator.
20198
20199 @table @code
20200 @item sim @var{command}
20201 @kindex sim@r{, a command}
20202 Send an arbitrary @var{command} string to the simulator. Consult the
20203 documentation for the specific simulator in use for information about
20204 acceptable commands.
20205 @end table
20206
20207
20208 @menu
20209 * ARM:: ARM RDI
20210 * M32R/D:: Renesas M32R/D
20211 * M68K:: Motorola M68K
20212 * MicroBlaze:: Xilinx MicroBlaze
20213 * MIPS Embedded:: MIPS Embedded
20214 * PowerPC Embedded:: PowerPC Embedded
20215 * PA:: HP PA Embedded
20216 * Sparclet:: Tsqware Sparclet
20217 * Sparclite:: Fujitsu Sparclite
20218 * Z8000:: Zilog Z8000
20219 * AVR:: Atmel AVR
20220 * CRIS:: CRIS
20221 * Super-H:: Renesas Super-H
20222 @end menu
20223
20224 @node ARM
20225 @subsection ARM
20226 @cindex ARM RDI
20227
20228 @table @code
20229 @kindex target rdi
20230 @item target rdi @var{dev}
20231 ARM Angel monitor, via RDI library interface to ADP protocol. You may
20232 use this target to communicate with both boards running the Angel
20233 monitor, or with the EmbeddedICE JTAG debug device.
20234
20235 @kindex target rdp
20236 @item target rdp @var{dev}
20237 ARM Demon monitor.
20238
20239 @end table
20240
20241 @value{GDBN} provides the following ARM-specific commands:
20242
20243 @table @code
20244 @item set arm disassembler
20245 @kindex set arm
20246 This commands selects from a list of disassembly styles. The
20247 @code{"std"} style is the standard style.
20248
20249 @item show arm disassembler
20250 @kindex show arm
20251 Show the current disassembly style.
20252
20253 @item set arm apcs32
20254 @cindex ARM 32-bit mode
20255 This command toggles ARM operation mode between 32-bit and 26-bit.
20256
20257 @item show arm apcs32
20258 Display the current usage of the ARM 32-bit mode.
20259
20260 @item set arm fpu @var{fputype}
20261 This command sets the ARM floating-point unit (FPU) type. The
20262 argument @var{fputype} can be one of these:
20263
20264 @table @code
20265 @item auto
20266 Determine the FPU type by querying the OS ABI.
20267 @item softfpa
20268 Software FPU, with mixed-endian doubles on little-endian ARM
20269 processors.
20270 @item fpa
20271 GCC-compiled FPA co-processor.
20272 @item softvfp
20273 Software FPU with pure-endian doubles.
20274 @item vfp
20275 VFP co-processor.
20276 @end table
20277
20278 @item show arm fpu
20279 Show the current type of the FPU.
20280
20281 @item set arm abi
20282 This command forces @value{GDBN} to use the specified ABI.
20283
20284 @item show arm abi
20285 Show the currently used ABI.
20286
20287 @item set arm fallback-mode (arm|thumb|auto)
20288 @value{GDBN} uses the symbol table, when available, to determine
20289 whether instructions are ARM or Thumb. This command controls
20290 @value{GDBN}'s default behavior when the symbol table is not
20291 available. The default is @samp{auto}, which causes @value{GDBN} to
20292 use the current execution mode (from the @code{T} bit in the @code{CPSR}
20293 register).
20294
20295 @item show arm fallback-mode
20296 Show the current fallback instruction mode.
20297
20298 @item set arm force-mode (arm|thumb|auto)
20299 This command overrides use of the symbol table to determine whether
20300 instructions are ARM or Thumb. The default is @samp{auto}, which
20301 causes @value{GDBN} to use the symbol table and then the setting
20302 of @samp{set arm fallback-mode}.
20303
20304 @item show arm force-mode
20305 Show the current forced instruction mode.
20306
20307 @item set debug arm
20308 Toggle whether to display ARM-specific debugging messages from the ARM
20309 target support subsystem.
20310
20311 @item show debug arm
20312 Show whether ARM-specific debugging messages are enabled.
20313 @end table
20314
20315 The following commands are available when an ARM target is debugged
20316 using the RDI interface:
20317
20318 @table @code
20319 @item rdilogfile @r{[}@var{file}@r{]}
20320 @kindex rdilogfile
20321 @cindex ADP (Angel Debugger Protocol) logging
20322 Set the filename for the ADP (Angel Debugger Protocol) packet log.
20323 With an argument, sets the log file to the specified @var{file}. With
20324 no argument, show the current log file name. The default log file is
20325 @file{rdi.log}.
20326
20327 @item rdilogenable @r{[}@var{arg}@r{]}
20328 @kindex rdilogenable
20329 Control logging of ADP packets. With an argument of 1 or @code{"yes"}
20330 enables logging, with an argument 0 or @code{"no"} disables it. With
20331 no arguments displays the current setting. When logging is enabled,
20332 ADP packets exchanged between @value{GDBN} and the RDI target device
20333 are logged to a file.
20334
20335 @item set rdiromatzero
20336 @kindex set rdiromatzero
20337 @cindex ROM at zero address, RDI
20338 Tell @value{GDBN} whether the target has ROM at address 0. If on,
20339 vector catching is disabled, so that zero address can be used. If off
20340 (the default), vector catching is enabled. For this command to take
20341 effect, it needs to be invoked prior to the @code{target rdi} command.
20342
20343 @item show rdiromatzero
20344 @kindex show rdiromatzero
20345 Show the current setting of ROM at zero address.
20346
20347 @item set rdiheartbeat
20348 @kindex set rdiheartbeat
20349 @cindex RDI heartbeat
20350 Enable or disable RDI heartbeat packets. It is not recommended to
20351 turn on this option, since it confuses ARM and EPI JTAG interface, as
20352 well as the Angel monitor.
20353
20354 @item show rdiheartbeat
20355 @kindex show rdiheartbeat
20356 Show the setting of RDI heartbeat packets.
20357 @end table
20358
20359 @table @code
20360 @item target sim @r{[}@var{simargs}@r{]} @dots{}
20361 The @value{GDBN} ARM simulator accepts the following optional arguments.
20362
20363 @table @code
20364 @item --swi-support=@var{type}
20365 Tell the simulator which SWI interfaces to support.
20366 @var{type} may be a comma separated list of the following values.
20367 The default value is @code{all}.
20368
20369 @table @code
20370 @item none
20371 @item demon
20372 @item angel
20373 @item redboot
20374 @item all
20375 @end table
20376 @end table
20377 @end table
20378
20379 @node M32R/D
20380 @subsection Renesas M32R/D and M32R/SDI
20381
20382 @table @code
20383 @kindex target m32r
20384 @item target m32r @var{dev}
20385 Renesas M32R/D ROM monitor.
20386
20387 @kindex target m32rsdi
20388 @item target m32rsdi @var{dev}
20389 Renesas M32R SDI server, connected via parallel port to the board.
20390 @end table
20391
20392 The following @value{GDBN} commands are specific to the M32R monitor:
20393
20394 @table @code
20395 @item set download-path @var{path}
20396 @kindex set download-path
20397 @cindex find downloadable @sc{srec} files (M32R)
20398 Set the default path for finding downloadable @sc{srec} files.
20399
20400 @item show download-path
20401 @kindex show download-path
20402 Show the default path for downloadable @sc{srec} files.
20403
20404 @item set board-address @var{addr}
20405 @kindex set board-address
20406 @cindex M32-EVA target board address
20407 Set the IP address for the M32R-EVA target board.
20408
20409 @item show board-address
20410 @kindex show board-address
20411 Show the current IP address of the target board.
20412
20413 @item set server-address @var{addr}
20414 @kindex set server-address
20415 @cindex download server address (M32R)
20416 Set the IP address for the download server, which is the @value{GDBN}'s
20417 host machine.
20418
20419 @item show server-address
20420 @kindex show server-address
20421 Display the IP address of the download server.
20422
20423 @item upload @r{[}@var{file}@r{]}
20424 @kindex upload@r{, M32R}
20425 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
20426 upload capability. If no @var{file} argument is given, the current
20427 executable file is uploaded.
20428
20429 @item tload @r{[}@var{file}@r{]}
20430 @kindex tload@r{, M32R}
20431 Test the @code{upload} command.
20432 @end table
20433
20434 The following commands are available for M32R/SDI:
20435
20436 @table @code
20437 @item sdireset
20438 @kindex sdireset
20439 @cindex reset SDI connection, M32R
20440 This command resets the SDI connection.
20441
20442 @item sdistatus
20443 @kindex sdistatus
20444 This command shows the SDI connection status.
20445
20446 @item debug_chaos
20447 @kindex debug_chaos
20448 @cindex M32R/Chaos debugging
20449 Instructs the remote that M32R/Chaos debugging is to be used.
20450
20451 @item use_debug_dma
20452 @kindex use_debug_dma
20453 Instructs the remote to use the DEBUG_DMA method of accessing memory.
20454
20455 @item use_mon_code
20456 @kindex use_mon_code
20457 Instructs the remote to use the MON_CODE method of accessing memory.
20458
20459 @item use_ib_break
20460 @kindex use_ib_break
20461 Instructs the remote to set breakpoints by IB break.
20462
20463 @item use_dbt_break
20464 @kindex use_dbt_break
20465 Instructs the remote to set breakpoints by DBT.
20466 @end table
20467
20468 @node M68K
20469 @subsection M68k
20470
20471 The Motorola m68k configuration includes ColdFire support, and a
20472 target command for the following ROM monitor.
20473
20474 @table @code
20475
20476 @kindex target dbug
20477 @item target dbug @var{dev}
20478 dBUG ROM monitor for Motorola ColdFire.
20479
20480 @end table
20481
20482 @node MicroBlaze
20483 @subsection MicroBlaze
20484 @cindex Xilinx MicroBlaze
20485 @cindex XMD, Xilinx Microprocessor Debugger
20486
20487 The MicroBlaze is a soft-core processor supported on various Xilinx
20488 FPGAs, such as Spartan or Virtex series. Boards with these processors
20489 usually have JTAG ports which connect to a host system running the Xilinx
20490 Embedded Development Kit (EDK) or Software Development Kit (SDK).
20491 This host system is used to download the configuration bitstream to
20492 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
20493 communicates with the target board using the JTAG interface and
20494 presents a @code{gdbserver} interface to the board. By default
20495 @code{xmd} uses port @code{1234}. (While it is possible to change
20496 this default port, it requires the use of undocumented @code{xmd}
20497 commands. Contact Xilinx support if you need to do this.)
20498
20499 Use these GDB commands to connect to the MicroBlaze target processor.
20500
20501 @table @code
20502 @item target remote :1234
20503 Use this command to connect to the target if you are running @value{GDBN}
20504 on the same system as @code{xmd}.
20505
20506 @item target remote @var{xmd-host}:1234
20507 Use this command to connect to the target if it is connected to @code{xmd}
20508 running on a different system named @var{xmd-host}.
20509
20510 @item load
20511 Use this command to download a program to the MicroBlaze target.
20512
20513 @item set debug microblaze @var{n}
20514 Enable MicroBlaze-specific debugging messages if non-zero.
20515
20516 @item show debug microblaze @var{n}
20517 Show MicroBlaze-specific debugging level.
20518 @end table
20519
20520 @node MIPS Embedded
20521 @subsection @acronym{MIPS} Embedded
20522
20523 @cindex @acronym{MIPS} boards
20524 @value{GDBN} can use the @acronym{MIPS} remote debugging protocol to talk to a
20525 @acronym{MIPS} board attached to a serial line. This is available when
20526 you configure @value{GDBN} with @samp{--target=mips-elf}.
20527
20528 @need 1000
20529 Use these @value{GDBN} commands to specify the connection to your target board:
20530
20531 @table @code
20532 @item target mips @var{port}
20533 @kindex target mips @var{port}
20534 To run a program on the board, start up @code{@value{GDBP}} with the
20535 name of your program as the argument. To connect to the board, use the
20536 command @samp{target mips @var{port}}, where @var{port} is the name of
20537 the serial port connected to the board. If the program has not already
20538 been downloaded to the board, you may use the @code{load} command to
20539 download it. You can then use all the usual @value{GDBN} commands.
20540
20541 For example, this sequence connects to the target board through a serial
20542 port, and loads and runs a program called @var{prog} through the
20543 debugger:
20544
20545 @smallexample
20546 host$ @value{GDBP} @var{prog}
20547 @value{GDBN} is free software and @dots{}
20548 (@value{GDBP}) target mips /dev/ttyb
20549 (@value{GDBP}) load @var{prog}
20550 (@value{GDBP}) run
20551 @end smallexample
20552
20553 @item target mips @var{hostname}:@var{portnumber}
20554 On some @value{GDBN} host configurations, you can specify a TCP
20555 connection (for instance, to a serial line managed by a terminal
20556 concentrator) instead of a serial port, using the syntax
20557 @samp{@var{hostname}:@var{portnumber}}.
20558
20559 @item target pmon @var{port}
20560 @kindex target pmon @var{port}
20561 PMON ROM monitor.
20562
20563 @item target ddb @var{port}
20564 @kindex target ddb @var{port}
20565 NEC's DDB variant of PMON for Vr4300.
20566
20567 @item target lsi @var{port}
20568 @kindex target lsi @var{port}
20569 LSI variant of PMON.
20570
20571 @kindex target r3900
20572 @item target r3900 @var{dev}
20573 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
20574
20575 @kindex target array
20576 @item target array @var{dev}
20577 Array Tech LSI33K RAID controller board.
20578
20579 @end table
20580
20581
20582 @noindent
20583 @value{GDBN} also supports these special commands for @acronym{MIPS} targets:
20584
20585 @table @code
20586 @item set mipsfpu double
20587 @itemx set mipsfpu single
20588 @itemx set mipsfpu none
20589 @itemx set mipsfpu auto
20590 @itemx show mipsfpu
20591 @kindex set mipsfpu
20592 @kindex show mipsfpu
20593 @cindex @acronym{MIPS} remote floating point
20594 @cindex floating point, @acronym{MIPS} remote
20595 If your target board does not support the @acronym{MIPS} floating point
20596 coprocessor, you should use the command @samp{set mipsfpu none} (if you
20597 need this, you may wish to put the command in your @value{GDBN} init
20598 file). This tells @value{GDBN} how to find the return value of
20599 functions which return floating point values. It also allows
20600 @value{GDBN} to avoid saving the floating point registers when calling
20601 functions on the board. If you are using a floating point coprocessor
20602 with only single precision floating point support, as on the @sc{r4650}
20603 processor, use the command @samp{set mipsfpu single}. The default
20604 double precision floating point coprocessor may be selected using
20605 @samp{set mipsfpu double}.
20606
20607 In previous versions the only choices were double precision or no
20608 floating point, so @samp{set mipsfpu on} will select double precision
20609 and @samp{set mipsfpu off} will select no floating point.
20610
20611 As usual, you can inquire about the @code{mipsfpu} variable with
20612 @samp{show mipsfpu}.
20613
20614 @item set timeout @var{seconds}
20615 @itemx set retransmit-timeout @var{seconds}
20616 @itemx show timeout
20617 @itemx show retransmit-timeout
20618 @cindex @code{timeout}, @acronym{MIPS} protocol
20619 @cindex @code{retransmit-timeout}, @acronym{MIPS} protocol
20620 @kindex set timeout
20621 @kindex show timeout
20622 @kindex set retransmit-timeout
20623 @kindex show retransmit-timeout
20624 You can control the timeout used while waiting for a packet, in the @acronym{MIPS}
20625 remote protocol, with the @code{set timeout @var{seconds}} command. The
20626 default is 5 seconds. Similarly, you can control the timeout used while
20627 waiting for an acknowledgment of a packet with the @code{set
20628 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
20629 You can inspect both values with @code{show timeout} and @code{show
20630 retransmit-timeout}. (These commands are @emph{only} available when
20631 @value{GDBN} is configured for @samp{--target=mips-elf}.)
20632
20633 The timeout set by @code{set timeout} does not apply when @value{GDBN}
20634 is waiting for your program to stop. In that case, @value{GDBN} waits
20635 forever because it has no way of knowing how long the program is going
20636 to run before stopping.
20637
20638 @item set syn-garbage-limit @var{num}
20639 @kindex set syn-garbage-limit@r{, @acronym{MIPS} remote}
20640 @cindex synchronize with remote @acronym{MIPS} target
20641 Limit the maximum number of characters @value{GDBN} should ignore when
20642 it tries to synchronize with the remote target. The default is 10
20643 characters. Setting the limit to -1 means there's no limit.
20644
20645 @item show syn-garbage-limit
20646 @kindex show syn-garbage-limit@r{, @acronym{MIPS} remote}
20647 Show the current limit on the number of characters to ignore when
20648 trying to synchronize with the remote system.
20649
20650 @item set monitor-prompt @var{prompt}
20651 @kindex set monitor-prompt@r{, @acronym{MIPS} remote}
20652 @cindex remote monitor prompt
20653 Tell @value{GDBN} to expect the specified @var{prompt} string from the
20654 remote monitor. The default depends on the target:
20655 @table @asis
20656 @item pmon target
20657 @samp{PMON}
20658 @item ddb target
20659 @samp{NEC010}
20660 @item lsi target
20661 @samp{PMON>}
20662 @end table
20663
20664 @item show monitor-prompt
20665 @kindex show monitor-prompt@r{, @acronym{MIPS} remote}
20666 Show the current strings @value{GDBN} expects as the prompt from the
20667 remote monitor.
20668
20669 @item set monitor-warnings
20670 @kindex set monitor-warnings@r{, @acronym{MIPS} remote}
20671 Enable or disable monitor warnings about hardware breakpoints. This
20672 has effect only for the @code{lsi} target. When on, @value{GDBN} will
20673 display warning messages whose codes are returned by the @code{lsi}
20674 PMON monitor for breakpoint commands.
20675
20676 @item show monitor-warnings
20677 @kindex show monitor-warnings@r{, @acronym{MIPS} remote}
20678 Show the current setting of printing monitor warnings.
20679
20680 @item pmon @var{command}
20681 @kindex pmon@r{, @acronym{MIPS} remote}
20682 @cindex send PMON command
20683 This command allows sending an arbitrary @var{command} string to the
20684 monitor. The monitor must be in debug mode for this to work.
20685 @end table
20686
20687 @node PowerPC Embedded
20688 @subsection PowerPC Embedded
20689
20690 @cindex DVC register
20691 @value{GDBN} supports using the DVC (Data Value Compare) register to
20692 implement in hardware simple hardware watchpoint conditions of the form:
20693
20694 @smallexample
20695 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
20696 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
20697 @end smallexample
20698
20699 The DVC register will be automatically used when @value{GDBN} detects
20700 such pattern in a condition expression, and the created watchpoint uses one
20701 debug register (either the @code{exact-watchpoints} option is on and the
20702 variable is scalar, or the variable has a length of one byte). This feature
20703 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
20704 or newer.
20705
20706 When running on PowerPC embedded processors, @value{GDBN} automatically uses
20707 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
20708 in which case watchpoints using only one debug register are created when
20709 watching variables of scalar types.
20710
20711 You can create an artificial array to watch an arbitrary memory
20712 region using one of the following commands (@pxref{Expressions}):
20713
20714 @smallexample
20715 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
20716 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
20717 @end smallexample
20718
20719 PowerPC embedded processors support masked watchpoints. See the discussion
20720 about the @code{mask} argument in @ref{Set Watchpoints}.
20721
20722 @cindex ranged breakpoint
20723 PowerPC embedded processors support hardware accelerated
20724 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
20725 the inferior whenever it executes an instruction at any address within
20726 the range it specifies. To set a ranged breakpoint in @value{GDBN},
20727 use the @code{break-range} command.
20728
20729 @value{GDBN} provides the following PowerPC-specific commands:
20730
20731 @table @code
20732 @kindex break-range
20733 @item break-range @var{start-location}, @var{end-location}
20734 Set a breakpoint for an address range.
20735 @var{start-location} and @var{end-location} can specify a function name,
20736 a line number, an offset of lines from the current line or from the start
20737 location, or an address of an instruction (see @ref{Specify Location},
20738 for a list of all the possible ways to specify a @var{location}.)
20739 The breakpoint will stop execution of the inferior whenever it
20740 executes an instruction at any address within the specified range,
20741 (including @var{start-location} and @var{end-location}.)
20742
20743 @kindex set powerpc
20744 @item set powerpc soft-float
20745 @itemx show powerpc soft-float
20746 Force @value{GDBN} to use (or not use) a software floating point calling
20747 convention. By default, @value{GDBN} selects the calling convention based
20748 on the selected architecture and the provided executable file.
20749
20750 @item set powerpc vector-abi
20751 @itemx show powerpc vector-abi
20752 Force @value{GDBN} to use the specified calling convention for vector
20753 arguments and return values. The valid options are @samp{auto};
20754 @samp{generic}, to avoid vector registers even if they are present;
20755 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
20756 registers. By default, @value{GDBN} selects the calling convention
20757 based on the selected architecture and the provided executable file.
20758
20759 @item set powerpc exact-watchpoints
20760 @itemx show powerpc exact-watchpoints
20761 Allow @value{GDBN} to use only one debug register when watching a variable
20762 of scalar type, thus assuming that the variable is accessed through the
20763 address of its first byte.
20764
20765 @kindex target dink32
20766 @item target dink32 @var{dev}
20767 DINK32 ROM monitor.
20768
20769 @kindex target ppcbug
20770 @item target ppcbug @var{dev}
20771 @kindex target ppcbug1
20772 @item target ppcbug1 @var{dev}
20773 PPCBUG ROM monitor for PowerPC.
20774
20775 @kindex target sds
20776 @item target sds @var{dev}
20777 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
20778 @end table
20779
20780 @cindex SDS protocol
20781 The following commands specific to the SDS protocol are supported
20782 by @value{GDBN}:
20783
20784 @table @code
20785 @item set sdstimeout @var{nsec}
20786 @kindex set sdstimeout
20787 Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
20788 default is 2 seconds.
20789
20790 @item show sdstimeout
20791 @kindex show sdstimeout
20792 Show the current value of the SDS timeout.
20793
20794 @item sds @var{command}
20795 @kindex sds@r{, a command}
20796 Send the specified @var{command} string to the SDS monitor.
20797 @end table
20798
20799
20800 @node PA
20801 @subsection HP PA Embedded
20802
20803 @table @code
20804
20805 @kindex target op50n
20806 @item target op50n @var{dev}
20807 OP50N monitor, running on an OKI HPPA board.
20808
20809 @kindex target w89k
20810 @item target w89k @var{dev}
20811 W89K monitor, running on a Winbond HPPA board.
20812
20813 @end table
20814
20815 @node Sparclet
20816 @subsection Tsqware Sparclet
20817
20818 @cindex Sparclet
20819
20820 @value{GDBN} enables developers to debug tasks running on
20821 Sparclet targets from a Unix host.
20822 @value{GDBN} uses code that runs on
20823 both the Unix host and on the Sparclet target. The program
20824 @code{@value{GDBP}} is installed and executed on the Unix host.
20825
20826 @table @code
20827 @item remotetimeout @var{args}
20828 @kindex remotetimeout
20829 @value{GDBN} supports the option @code{remotetimeout}.
20830 This option is set by the user, and @var{args} represents the number of
20831 seconds @value{GDBN} waits for responses.
20832 @end table
20833
20834 @cindex compiling, on Sparclet
20835 When compiling for debugging, include the options @samp{-g} to get debug
20836 information and @samp{-Ttext} to relocate the program to where you wish to
20837 load it on the target. You may also want to add the options @samp{-n} or
20838 @samp{-N} in order to reduce the size of the sections. Example:
20839
20840 @smallexample
20841 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
20842 @end smallexample
20843
20844 You can use @code{objdump} to verify that the addresses are what you intended:
20845
20846 @smallexample
20847 sparclet-aout-objdump --headers --syms prog
20848 @end smallexample
20849
20850 @cindex running, on Sparclet
20851 Once you have set
20852 your Unix execution search path to find @value{GDBN}, you are ready to
20853 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
20854 (or @code{sparclet-aout-gdb}, depending on your installation).
20855
20856 @value{GDBN} comes up showing the prompt:
20857
20858 @smallexample
20859 (gdbslet)
20860 @end smallexample
20861
20862 @menu
20863 * Sparclet File:: Setting the file to debug
20864 * Sparclet Connection:: Connecting to Sparclet
20865 * Sparclet Download:: Sparclet download
20866 * Sparclet Execution:: Running and debugging
20867 @end menu
20868
20869 @node Sparclet File
20870 @subsubsection Setting File to Debug
20871
20872 The @value{GDBN} command @code{file} lets you choose with program to debug.
20873
20874 @smallexample
20875 (gdbslet) file prog
20876 @end smallexample
20877
20878 @need 1000
20879 @value{GDBN} then attempts to read the symbol table of @file{prog}.
20880 @value{GDBN} locates
20881 the file by searching the directories listed in the command search
20882 path.
20883 If the file was compiled with debug information (option @samp{-g}), source
20884 files will be searched as well.
20885 @value{GDBN} locates
20886 the source files by searching the directories listed in the directory search
20887 path (@pxref{Environment, ,Your Program's Environment}).
20888 If it fails
20889 to find a file, it displays a message such as:
20890
20891 @smallexample
20892 prog: No such file or directory.
20893 @end smallexample
20894
20895 When this happens, add the appropriate directories to the search paths with
20896 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
20897 @code{target} command again.
20898
20899 @node Sparclet Connection
20900 @subsubsection Connecting to Sparclet
20901
20902 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
20903 To connect to a target on serial port ``@code{ttya}'', type:
20904
20905 @smallexample
20906 (gdbslet) target sparclet /dev/ttya
20907 Remote target sparclet connected to /dev/ttya
20908 main () at ../prog.c:3
20909 @end smallexample
20910
20911 @need 750
20912 @value{GDBN} displays messages like these:
20913
20914 @smallexample
20915 Connected to ttya.
20916 @end smallexample
20917
20918 @node Sparclet Download
20919 @subsubsection Sparclet Download
20920
20921 @cindex download to Sparclet
20922 Once connected to the Sparclet target,
20923 you can use the @value{GDBN}
20924 @code{load} command to download the file from the host to the target.
20925 The file name and load offset should be given as arguments to the @code{load}
20926 command.
20927 Since the file format is aout, the program must be loaded to the starting
20928 address. You can use @code{objdump} to find out what this value is. The load
20929 offset is an offset which is added to the VMA (virtual memory address)
20930 of each of the file's sections.
20931 For instance, if the program
20932 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
20933 and bss at 0x12010170, in @value{GDBN}, type:
20934
20935 @smallexample
20936 (gdbslet) load prog 0x12010000
20937 Loading section .text, size 0xdb0 vma 0x12010000
20938 @end smallexample
20939
20940 If the code is loaded at a different address then what the program was linked
20941 to, you may need to use the @code{section} and @code{add-symbol-file} commands
20942 to tell @value{GDBN} where to map the symbol table.
20943
20944 @node Sparclet Execution
20945 @subsubsection Running and Debugging
20946
20947 @cindex running and debugging Sparclet programs
20948 You can now begin debugging the task using @value{GDBN}'s execution control
20949 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
20950 manual for the list of commands.
20951
20952 @smallexample
20953 (gdbslet) b main
20954 Breakpoint 1 at 0x12010000: file prog.c, line 3.
20955 (gdbslet) run
20956 Starting program: prog
20957 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
20958 3 char *symarg = 0;
20959 (gdbslet) step
20960 4 char *execarg = "hello!";
20961 (gdbslet)
20962 @end smallexample
20963
20964 @node Sparclite
20965 @subsection Fujitsu Sparclite
20966
20967 @table @code
20968
20969 @kindex target sparclite
20970 @item target sparclite @var{dev}
20971 Fujitsu sparclite boards, used only for the purpose of loading.
20972 You must use an additional command to debug the program.
20973 For example: target remote @var{dev} using @value{GDBN} standard
20974 remote protocol.
20975
20976 @end table
20977
20978 @node Z8000
20979 @subsection Zilog Z8000
20980
20981 @cindex Z8000
20982 @cindex simulator, Z8000
20983 @cindex Zilog Z8000 simulator
20984
20985 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
20986 a Z8000 simulator.
20987
20988 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
20989 unsegmented variant of the Z8000 architecture) or the Z8001 (the
20990 segmented variant). The simulator recognizes which architecture is
20991 appropriate by inspecting the object code.
20992
20993 @table @code
20994 @item target sim @var{args}
20995 @kindex sim
20996 @kindex target sim@r{, with Z8000}
20997 Debug programs on a simulated CPU. If the simulator supports setup
20998 options, specify them via @var{args}.
20999 @end table
21000
21001 @noindent
21002 After specifying this target, you can debug programs for the simulated
21003 CPU in the same style as programs for your host computer; use the
21004 @code{file} command to load a new program image, the @code{run} command
21005 to run your program, and so on.
21006
21007 As well as making available all the usual machine registers
21008 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
21009 additional items of information as specially named registers:
21010
21011 @table @code
21012
21013 @item cycles
21014 Counts clock-ticks in the simulator.
21015
21016 @item insts
21017 Counts instructions run in the simulator.
21018
21019 @item time
21020 Execution time in 60ths of a second.
21021
21022 @end table
21023
21024 You can refer to these values in @value{GDBN} expressions with the usual
21025 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
21026 conditional breakpoint that suspends only after at least 5000
21027 simulated clock ticks.
21028
21029 @node AVR
21030 @subsection Atmel AVR
21031 @cindex AVR
21032
21033 When configured for debugging the Atmel AVR, @value{GDBN} supports the
21034 following AVR-specific commands:
21035
21036 @table @code
21037 @item info io_registers
21038 @kindex info io_registers@r{, AVR}
21039 @cindex I/O registers (Atmel AVR)
21040 This command displays information about the AVR I/O registers. For
21041 each register, @value{GDBN} prints its number and value.
21042 @end table
21043
21044 @node CRIS
21045 @subsection CRIS
21046 @cindex CRIS
21047
21048 When configured for debugging CRIS, @value{GDBN} provides the
21049 following CRIS-specific commands:
21050
21051 @table @code
21052 @item set cris-version @var{ver}
21053 @cindex CRIS version
21054 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
21055 The CRIS version affects register names and sizes. This command is useful in
21056 case autodetection of the CRIS version fails.
21057
21058 @item show cris-version
21059 Show the current CRIS version.
21060
21061 @item set cris-dwarf2-cfi
21062 @cindex DWARF-2 CFI and CRIS
21063 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
21064 Change to @samp{off} when using @code{gcc-cris} whose version is below
21065 @code{R59}.
21066
21067 @item show cris-dwarf2-cfi
21068 Show the current state of using DWARF-2 CFI.
21069
21070 @item set cris-mode @var{mode}
21071 @cindex CRIS mode
21072 Set the current CRIS mode to @var{mode}. It should only be changed when
21073 debugging in guru mode, in which case it should be set to
21074 @samp{guru} (the default is @samp{normal}).
21075
21076 @item show cris-mode
21077 Show the current CRIS mode.
21078 @end table
21079
21080 @node Super-H
21081 @subsection Renesas Super-H
21082 @cindex Super-H
21083
21084 For the Renesas Super-H processor, @value{GDBN} provides these
21085 commands:
21086
21087 @table @code
21088 @item set sh calling-convention @var{convention}
21089 @kindex set sh calling-convention
21090 Set the calling-convention used when calling functions from @value{GDBN}.
21091 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
21092 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
21093 convention. If the DWARF-2 information of the called function specifies
21094 that the function follows the Renesas calling convention, the function
21095 is called using the Renesas calling convention. If the calling convention
21096 is set to @samp{renesas}, the Renesas calling convention is always used,
21097 regardless of the DWARF-2 information. This can be used to override the
21098 default of @samp{gcc} if debug information is missing, or the compiler
21099 does not emit the DWARF-2 calling convention entry for a function.
21100
21101 @item show sh calling-convention
21102 @kindex show sh calling-convention
21103 Show the current calling convention setting.
21104
21105 @end table
21106
21107
21108 @node Architectures
21109 @section Architectures
21110
21111 This section describes characteristics of architectures that affect
21112 all uses of @value{GDBN} with the architecture, both native and cross.
21113
21114 @menu
21115 * AArch64::
21116 * i386::
21117 * Alpha::
21118 * MIPS::
21119 * HPPA:: HP PA architecture
21120 * SPU:: Cell Broadband Engine SPU architecture
21121 * PowerPC::
21122 * Nios II::
21123 @end menu
21124
21125 @node AArch64
21126 @subsection AArch64
21127 @cindex AArch64 support
21128
21129 When @value{GDBN} is debugging the AArch64 architecture, it provides the
21130 following special commands:
21131
21132 @table @code
21133 @item set debug aarch64
21134 @kindex set debug aarch64
21135 This command determines whether AArch64 architecture-specific debugging
21136 messages are to be displayed.
21137
21138 @item show debug aarch64
21139 Show whether AArch64 debugging messages are displayed.
21140
21141 @end table
21142
21143 @node i386
21144 @subsection x86 Architecture-specific Issues
21145
21146 @table @code
21147 @item set struct-convention @var{mode}
21148 @kindex set struct-convention
21149 @cindex struct return convention
21150 @cindex struct/union returned in registers
21151 Set the convention used by the inferior to return @code{struct}s and
21152 @code{union}s from functions to @var{mode}. Possible values of
21153 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
21154 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
21155 are returned on the stack, while @code{"reg"} means that a
21156 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
21157 be returned in a register.
21158
21159 @item show struct-convention
21160 @kindex show struct-convention
21161 Show the current setting of the convention to return @code{struct}s
21162 from functions.
21163 @end table
21164
21165 @node Alpha
21166 @subsection Alpha
21167
21168 See the following section.
21169
21170 @node MIPS
21171 @subsection @acronym{MIPS}
21172
21173 @cindex stack on Alpha
21174 @cindex stack on @acronym{MIPS}
21175 @cindex Alpha stack
21176 @cindex @acronym{MIPS} stack
21177 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
21178 sometimes requires @value{GDBN} to search backward in the object code to
21179 find the beginning of a function.
21180
21181 @cindex response time, @acronym{MIPS} debugging
21182 To improve response time (especially for embedded applications, where
21183 @value{GDBN} may be restricted to a slow serial line for this search)
21184 you may want to limit the size of this search, using one of these
21185 commands:
21186
21187 @table @code
21188 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
21189 @item set heuristic-fence-post @var{limit}
21190 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
21191 search for the beginning of a function. A value of @var{0} (the
21192 default) means there is no limit. However, except for @var{0}, the
21193 larger the limit the more bytes @code{heuristic-fence-post} must search
21194 and therefore the longer it takes to run. You should only need to use
21195 this command when debugging a stripped executable.
21196
21197 @item show heuristic-fence-post
21198 Display the current limit.
21199 @end table
21200
21201 @noindent
21202 These commands are available @emph{only} when @value{GDBN} is configured
21203 for debugging programs on Alpha or @acronym{MIPS} processors.
21204
21205 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
21206 programs:
21207
21208 @table @code
21209 @item set mips abi @var{arg}
21210 @kindex set mips abi
21211 @cindex set ABI for @acronym{MIPS}
21212 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
21213 values of @var{arg} are:
21214
21215 @table @samp
21216 @item auto
21217 The default ABI associated with the current binary (this is the
21218 default).
21219 @item o32
21220 @item o64
21221 @item n32
21222 @item n64
21223 @item eabi32
21224 @item eabi64
21225 @end table
21226
21227 @item show mips abi
21228 @kindex show mips abi
21229 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
21230
21231 @item set mips compression @var{arg}
21232 @kindex set mips compression
21233 @cindex code compression, @acronym{MIPS}
21234 Tell @value{GDBN} which @acronym{MIPS} compressed
21235 @acronym{ISA, Instruction Set Architecture} encoding is used by the
21236 inferior. @value{GDBN} uses this for code disassembly and other
21237 internal interpretation purposes. This setting is only referred to
21238 when no executable has been associated with the debugging session or
21239 the executable does not provide information about the encoding it uses.
21240 Otherwise this setting is automatically updated from information
21241 provided by the executable.
21242
21243 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
21244 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
21245 executables containing @acronym{MIPS16} code frequently are not
21246 identified as such.
21247
21248 This setting is ``sticky''; that is, it retains its value across
21249 debugging sessions until reset either explicitly with this command or
21250 implicitly from an executable.
21251
21252 The compiler and/or assembler typically add symbol table annotations to
21253 identify functions compiled for the @acronym{MIPS16} or
21254 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
21255 are present, @value{GDBN} uses them in preference to the global
21256 compressed @acronym{ISA} encoding setting.
21257
21258 @item show mips compression
21259 @kindex show mips compression
21260 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
21261 @value{GDBN} to debug the inferior.
21262
21263 @item set mipsfpu
21264 @itemx show mipsfpu
21265 @xref{MIPS Embedded, set mipsfpu}.
21266
21267 @item set mips mask-address @var{arg}
21268 @kindex set mips mask-address
21269 @cindex @acronym{MIPS} addresses, masking
21270 This command determines whether the most-significant 32 bits of 64-bit
21271 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
21272 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
21273 setting, which lets @value{GDBN} determine the correct value.
21274
21275 @item show mips mask-address
21276 @kindex show mips mask-address
21277 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
21278 not.
21279
21280 @item set remote-mips64-transfers-32bit-regs
21281 @kindex set remote-mips64-transfers-32bit-regs
21282 This command controls compatibility with 64-bit @acronym{MIPS} targets that
21283 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
21284 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
21285 and 64 bits for other registers, set this option to @samp{on}.
21286
21287 @item show remote-mips64-transfers-32bit-regs
21288 @kindex show remote-mips64-transfers-32bit-regs
21289 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
21290
21291 @item set debug mips
21292 @kindex set debug mips
21293 This command turns on and off debugging messages for the @acronym{MIPS}-specific
21294 target code in @value{GDBN}.
21295
21296 @item show debug mips
21297 @kindex show debug mips
21298 Show the current setting of @acronym{MIPS} debugging messages.
21299 @end table
21300
21301
21302 @node HPPA
21303 @subsection HPPA
21304 @cindex HPPA support
21305
21306 When @value{GDBN} is debugging the HP PA architecture, it provides the
21307 following special commands:
21308
21309 @table @code
21310 @item set debug hppa
21311 @kindex set debug hppa
21312 This command determines whether HPPA architecture-specific debugging
21313 messages are to be displayed.
21314
21315 @item show debug hppa
21316 Show whether HPPA debugging messages are displayed.
21317
21318 @item maint print unwind @var{address}
21319 @kindex maint print unwind@r{, HPPA}
21320 This command displays the contents of the unwind table entry at the
21321 given @var{address}.
21322
21323 @end table
21324
21325
21326 @node SPU
21327 @subsection Cell Broadband Engine SPU architecture
21328 @cindex Cell Broadband Engine
21329 @cindex SPU
21330
21331 When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
21332 it provides the following special commands:
21333
21334 @table @code
21335 @item info spu event
21336 @kindex info spu
21337 Display SPU event facility status. Shows current event mask
21338 and pending event status.
21339
21340 @item info spu signal
21341 Display SPU signal notification facility status. Shows pending
21342 signal-control word and signal notification mode of both signal
21343 notification channels.
21344
21345 @item info spu mailbox
21346 Display SPU mailbox facility status. Shows all pending entries,
21347 in order of processing, in each of the SPU Write Outbound,
21348 SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
21349
21350 @item info spu dma
21351 Display MFC DMA status. Shows all pending commands in the MFC
21352 DMA queue. For each entry, opcode, tag, class IDs, effective
21353 and local store addresses and transfer size are shown.
21354
21355 @item info spu proxydma
21356 Display MFC Proxy-DMA status. Shows all pending commands in the MFC
21357 Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
21358 and local store addresses and transfer size are shown.
21359
21360 @end table
21361
21362 When @value{GDBN} is debugging a combined PowerPC/SPU application
21363 on the Cell Broadband Engine, it provides in addition the following
21364 special commands:
21365
21366 @table @code
21367 @item set spu stop-on-load @var{arg}
21368 @kindex set spu
21369 Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
21370 will give control to the user when a new SPE thread enters its @code{main}
21371 function. The default is @code{off}.
21372
21373 @item show spu stop-on-load
21374 @kindex show spu
21375 Show whether to stop for new SPE threads.
21376
21377 @item set spu auto-flush-cache @var{arg}
21378 Set whether to automatically flush the software-managed cache. When set to
21379 @code{on}, @value{GDBN} will automatically cause the SPE software-managed
21380 cache to be flushed whenever SPE execution stops. This provides a consistent
21381 view of PowerPC memory that is accessed via the cache. If an application
21382 does not use the software-managed cache, this option has no effect.
21383
21384 @item show spu auto-flush-cache
21385 Show whether to automatically flush the software-managed cache.
21386
21387 @end table
21388
21389 @node PowerPC
21390 @subsection PowerPC
21391 @cindex PowerPC architecture
21392
21393 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
21394 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
21395 numbers stored in the floating point registers. These values must be stored
21396 in two consecutive registers, always starting at an even register like
21397 @code{f0} or @code{f2}.
21398
21399 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
21400 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
21401 @code{f2} and @code{f3} for @code{$dl1} and so on.
21402
21403 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
21404 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
21405
21406 @node Nios II
21407 @subsection Nios II
21408 @cindex Nios II architecture
21409
21410 When @value{GDBN} is debugging the Nios II architecture,
21411 it provides the following special commands:
21412
21413 @table @code
21414
21415 @item set debug nios2
21416 @kindex set debug nios2
21417 This command turns on and off debugging messages for the Nios II
21418 target code in @value{GDBN}.
21419
21420 @item show debug nios2
21421 @kindex show debug nios2
21422 Show the current setting of Nios II debugging messages.
21423 @end table
21424
21425 @node Controlling GDB
21426 @chapter Controlling @value{GDBN}
21427
21428 You can alter the way @value{GDBN} interacts with you by using the
21429 @code{set} command. For commands controlling how @value{GDBN} displays
21430 data, see @ref{Print Settings, ,Print Settings}. Other settings are
21431 described here.
21432
21433 @menu
21434 * Prompt:: Prompt
21435 * Editing:: Command editing
21436 * Command History:: Command history
21437 * Screen Size:: Screen size
21438 * Numbers:: Numbers
21439 * ABI:: Configuring the current ABI
21440 * Auto-loading:: Automatically loading associated files
21441 * Messages/Warnings:: Optional warnings and messages
21442 * Debugging Output:: Optional messages about internal happenings
21443 * Other Misc Settings:: Other Miscellaneous Settings
21444 @end menu
21445
21446 @node Prompt
21447 @section Prompt
21448
21449 @cindex prompt
21450
21451 @value{GDBN} indicates its readiness to read a command by printing a string
21452 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
21453 can change the prompt string with the @code{set prompt} command. For
21454 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
21455 the prompt in one of the @value{GDBN} sessions so that you can always tell
21456 which one you are talking to.
21457
21458 @emph{Note:} @code{set prompt} does not add a space for you after the
21459 prompt you set. This allows you to set a prompt which ends in a space
21460 or a prompt that does not.
21461
21462 @table @code
21463 @kindex set prompt
21464 @item set prompt @var{newprompt}
21465 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
21466
21467 @kindex show prompt
21468 @item show prompt
21469 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
21470 @end table
21471
21472 Versions of @value{GDBN} that ship with Python scripting enabled have
21473 prompt extensions. The commands for interacting with these extensions
21474 are:
21475
21476 @table @code
21477 @kindex set extended-prompt
21478 @item set extended-prompt @var{prompt}
21479 Set an extended prompt that allows for substitutions.
21480 @xref{gdb.prompt}, for a list of escape sequences that can be used for
21481 substitution. Any escape sequences specified as part of the prompt
21482 string are replaced with the corresponding strings each time the prompt
21483 is displayed.
21484
21485 For example:
21486
21487 @smallexample
21488 set extended-prompt Current working directory: \w (gdb)
21489 @end smallexample
21490
21491 Note that when an extended-prompt is set, it takes control of the
21492 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
21493
21494 @kindex show extended-prompt
21495 @item show extended-prompt
21496 Prints the extended prompt. Any escape sequences specified as part of
21497 the prompt string with @code{set extended-prompt}, are replaced with the
21498 corresponding strings each time the prompt is displayed.
21499 @end table
21500
21501 @node Editing
21502 @section Command Editing
21503 @cindex readline
21504 @cindex command line editing
21505
21506 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
21507 @sc{gnu} library provides consistent behavior for programs which provide a
21508 command line interface to the user. Advantages are @sc{gnu} Emacs-style
21509 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
21510 substitution, and a storage and recall of command history across
21511 debugging sessions.
21512
21513 You may control the behavior of command line editing in @value{GDBN} with the
21514 command @code{set}.
21515
21516 @table @code
21517 @kindex set editing
21518 @cindex editing
21519 @item set editing
21520 @itemx set editing on
21521 Enable command line editing (enabled by default).
21522
21523 @item set editing off
21524 Disable command line editing.
21525
21526 @kindex show editing
21527 @item show editing
21528 Show whether command line editing is enabled.
21529 @end table
21530
21531 @ifset SYSTEM_READLINE
21532 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
21533 @end ifset
21534 @ifclear SYSTEM_READLINE
21535 @xref{Command Line Editing},
21536 @end ifclear
21537 for more details about the Readline
21538 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
21539 encouraged to read that chapter.
21540
21541 @node Command History
21542 @section Command History
21543 @cindex command history
21544
21545 @value{GDBN} can keep track of the commands you type during your
21546 debugging sessions, so that you can be certain of precisely what
21547 happened. Use these commands to manage the @value{GDBN} command
21548 history facility.
21549
21550 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
21551 package, to provide the history facility.
21552 @ifset SYSTEM_READLINE
21553 @xref{Using History Interactively, , , history, GNU History Library},
21554 @end ifset
21555 @ifclear SYSTEM_READLINE
21556 @xref{Using History Interactively},
21557 @end ifclear
21558 for the detailed description of the History library.
21559
21560 To issue a command to @value{GDBN} without affecting certain aspects of
21561 the state which is seen by users, prefix it with @samp{server }
21562 (@pxref{Server Prefix}). This
21563 means that this command will not affect the command history, nor will it
21564 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
21565 pressed on a line by itself.
21566
21567 @cindex @code{server}, command prefix
21568 The server prefix does not affect the recording of values into the value
21569 history; to print a value without recording it into the value history,
21570 use the @code{output} command instead of the @code{print} command.
21571
21572 Here is the description of @value{GDBN} commands related to command
21573 history.
21574
21575 @table @code
21576 @cindex history substitution
21577 @cindex history file
21578 @kindex set history filename
21579 @cindex @env{GDBHISTFILE}, environment variable
21580 @item set history filename @var{fname}
21581 Set the name of the @value{GDBN} command history file to @var{fname}.
21582 This is the file where @value{GDBN} reads an initial command history
21583 list, and where it writes the command history from this session when it
21584 exits. You can access this list through history expansion or through
21585 the history command editing characters listed below. This file defaults
21586 to the value of the environment variable @code{GDBHISTFILE}, or to
21587 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
21588 is not set.
21589
21590 @cindex save command history
21591 @kindex set history save
21592 @item set history save
21593 @itemx set history save on
21594 Record command history in a file, whose name may be specified with the
21595 @code{set history filename} command. By default, this option is disabled.
21596
21597 @item set history save off
21598 Stop recording command history in a file.
21599
21600 @cindex history size
21601 @kindex set history size
21602 @cindex @env{HISTSIZE}, environment variable
21603 @item set history size @var{size}
21604 @itemx set history size unlimited
21605 Set the number of commands which @value{GDBN} keeps in its history list.
21606 This defaults to the value of the environment variable
21607 @code{HISTSIZE}, or to 256 if this variable is not set. If @var{size}
21608 is @code{unlimited}, the number of commands @value{GDBN} keeps in the
21609 history list is unlimited.
21610 @end table
21611
21612 History expansion assigns special meaning to the character @kbd{!}.
21613 @ifset SYSTEM_READLINE
21614 @xref{Event Designators, , , history, GNU History Library},
21615 @end ifset
21616 @ifclear SYSTEM_READLINE
21617 @xref{Event Designators},
21618 @end ifclear
21619 for more details.
21620
21621 @cindex history expansion, turn on/off
21622 Since @kbd{!} is also the logical not operator in C, history expansion
21623 is off by default. If you decide to enable history expansion with the
21624 @code{set history expansion on} command, you may sometimes need to
21625 follow @kbd{!} (when it is used as logical not, in an expression) with
21626 a space or a tab to prevent it from being expanded. The readline
21627 history facilities do not attempt substitution on the strings
21628 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
21629
21630 The commands to control history expansion are:
21631
21632 @table @code
21633 @item set history expansion on
21634 @itemx set history expansion
21635 @kindex set history expansion
21636 Enable history expansion. History expansion is off by default.
21637
21638 @item set history expansion off
21639 Disable history expansion.
21640
21641 @c @group
21642 @kindex show history
21643 @item show history
21644 @itemx show history filename
21645 @itemx show history save
21646 @itemx show history size
21647 @itemx show history expansion
21648 These commands display the state of the @value{GDBN} history parameters.
21649 @code{show history} by itself displays all four states.
21650 @c @end group
21651 @end table
21652
21653 @table @code
21654 @kindex show commands
21655 @cindex show last commands
21656 @cindex display command history
21657 @item show commands
21658 Display the last ten commands in the command history.
21659
21660 @item show commands @var{n}
21661 Print ten commands centered on command number @var{n}.
21662
21663 @item show commands +
21664 Print ten commands just after the commands last printed.
21665 @end table
21666
21667 @node Screen Size
21668 @section Screen Size
21669 @cindex size of screen
21670 @cindex pauses in output
21671
21672 Certain commands to @value{GDBN} may produce large amounts of
21673 information output to the screen. To help you read all of it,
21674 @value{GDBN} pauses and asks you for input at the end of each page of
21675 output. Type @key{RET} when you want to continue the output, or @kbd{q}
21676 to discard the remaining output. Also, the screen width setting
21677 determines when to wrap lines of output. Depending on what is being
21678 printed, @value{GDBN} tries to break the line at a readable place,
21679 rather than simply letting it overflow onto the following line.
21680
21681 Normally @value{GDBN} knows the size of the screen from the terminal
21682 driver software. For example, on Unix @value{GDBN} uses the termcap data base
21683 together with the value of the @code{TERM} environment variable and the
21684 @code{stty rows} and @code{stty cols} settings. If this is not correct,
21685 you can override it with the @code{set height} and @code{set
21686 width} commands:
21687
21688 @table @code
21689 @kindex set height
21690 @kindex set width
21691 @kindex show width
21692 @kindex show height
21693 @item set height @var{lpp}
21694 @itemx set height unlimited
21695 @itemx show height
21696 @itemx set width @var{cpl}
21697 @itemx set width unlimited
21698 @itemx show width
21699 These @code{set} commands specify a screen height of @var{lpp} lines and
21700 a screen width of @var{cpl} characters. The associated @code{show}
21701 commands display the current settings.
21702
21703 If you specify a height of either @code{unlimited} or zero lines,
21704 @value{GDBN} does not pause during output no matter how long the
21705 output is. This is useful if output is to a file or to an editor
21706 buffer.
21707
21708 Likewise, you can specify @samp{set width unlimited} or @samp{set
21709 width 0} to prevent @value{GDBN} from wrapping its output.
21710
21711 @item set pagination on
21712 @itemx set pagination off
21713 @kindex set pagination
21714 Turn the output pagination on or off; the default is on. Turning
21715 pagination off is the alternative to @code{set height unlimited}. Note that
21716 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
21717 Options, -batch}) also automatically disables pagination.
21718
21719 @item show pagination
21720 @kindex show pagination
21721 Show the current pagination mode.
21722 @end table
21723
21724 @node Numbers
21725 @section Numbers
21726 @cindex number representation
21727 @cindex entering numbers
21728
21729 You can always enter numbers in octal, decimal, or hexadecimal in
21730 @value{GDBN} by the usual conventions: octal numbers begin with
21731 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
21732 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
21733 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
21734 10; likewise, the default display for numbers---when no particular
21735 format is specified---is base 10. You can change the default base for
21736 both input and output with the commands described below.
21737
21738 @table @code
21739 @kindex set input-radix
21740 @item set input-radix @var{base}
21741 Set the default base for numeric input. Supported choices
21742 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
21743 specified either unambiguously or using the current input radix; for
21744 example, any of
21745
21746 @smallexample
21747 set input-radix 012
21748 set input-radix 10.
21749 set input-radix 0xa
21750 @end smallexample
21751
21752 @noindent
21753 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
21754 leaves the input radix unchanged, no matter what it was, since
21755 @samp{10}, being without any leading or trailing signs of its base, is
21756 interpreted in the current radix. Thus, if the current radix is 16,
21757 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
21758 change the radix.
21759
21760 @kindex set output-radix
21761 @item set output-radix @var{base}
21762 Set the default base for numeric display. Supported choices
21763 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
21764 specified either unambiguously or using the current input radix.
21765
21766 @kindex show input-radix
21767 @item show input-radix
21768 Display the current default base for numeric input.
21769
21770 @kindex show output-radix
21771 @item show output-radix
21772 Display the current default base for numeric display.
21773
21774 @item set radix @r{[}@var{base}@r{]}
21775 @itemx show radix
21776 @kindex set radix
21777 @kindex show radix
21778 These commands set and show the default base for both input and output
21779 of numbers. @code{set radix} sets the radix of input and output to
21780 the same base; without an argument, it resets the radix back to its
21781 default value of 10.
21782
21783 @end table
21784
21785 @node ABI
21786 @section Configuring the Current ABI
21787
21788 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
21789 application automatically. However, sometimes you need to override its
21790 conclusions. Use these commands to manage @value{GDBN}'s view of the
21791 current ABI.
21792
21793 @cindex OS ABI
21794 @kindex set osabi
21795 @kindex show osabi
21796 @cindex Newlib OS ABI and its influence on the longjmp handling
21797
21798 One @value{GDBN} configuration can debug binaries for multiple operating
21799 system targets, either via remote debugging or native emulation.
21800 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
21801 but you can override its conclusion using the @code{set osabi} command.
21802 One example where this is useful is in debugging of binaries which use
21803 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
21804 not have the same identifying marks that the standard C library for your
21805 platform provides.
21806
21807 When @value{GDBN} is debugging the AArch64 architecture, it provides a
21808 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
21809 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
21810 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
21811
21812 @table @code
21813 @item show osabi
21814 Show the OS ABI currently in use.
21815
21816 @item set osabi
21817 With no argument, show the list of registered available OS ABI's.
21818
21819 @item set osabi @var{abi}
21820 Set the current OS ABI to @var{abi}.
21821 @end table
21822
21823 @cindex float promotion
21824
21825 Generally, the way that an argument of type @code{float} is passed to a
21826 function depends on whether the function is prototyped. For a prototyped
21827 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
21828 according to the architecture's convention for @code{float}. For unprototyped
21829 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
21830 @code{double} and then passed.
21831
21832 Unfortunately, some forms of debug information do not reliably indicate whether
21833 a function is prototyped. If @value{GDBN} calls a function that is not marked
21834 as prototyped, it consults @kbd{set coerce-float-to-double}.
21835
21836 @table @code
21837 @kindex set coerce-float-to-double
21838 @item set coerce-float-to-double
21839 @itemx set coerce-float-to-double on
21840 Arguments of type @code{float} will be promoted to @code{double} when passed
21841 to an unprototyped function. This is the default setting.
21842
21843 @item set coerce-float-to-double off
21844 Arguments of type @code{float} will be passed directly to unprototyped
21845 functions.
21846
21847 @kindex show coerce-float-to-double
21848 @item show coerce-float-to-double
21849 Show the current setting of promoting @code{float} to @code{double}.
21850 @end table
21851
21852 @kindex set cp-abi
21853 @kindex show cp-abi
21854 @value{GDBN} needs to know the ABI used for your program's C@t{++}
21855 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
21856 used to build your application. @value{GDBN} only fully supports
21857 programs with a single C@t{++} ABI; if your program contains code using
21858 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
21859 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
21860 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
21861 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
21862 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
21863 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
21864 ``auto''.
21865
21866 @table @code
21867 @item show cp-abi
21868 Show the C@t{++} ABI currently in use.
21869
21870 @item set cp-abi
21871 With no argument, show the list of supported C@t{++} ABI's.
21872
21873 @item set cp-abi @var{abi}
21874 @itemx set cp-abi auto
21875 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
21876 @end table
21877
21878 @node Auto-loading
21879 @section Automatically loading associated files
21880 @cindex auto-loading
21881
21882 @value{GDBN} sometimes reads files with commands and settings automatically,
21883 without being explicitly told so by the user. We call this feature
21884 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
21885 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
21886 results or introduce security risks (e.g., if the file comes from untrusted
21887 sources).
21888
21889 Note that loading of these associated files (including the local @file{.gdbinit}
21890 file) requires accordingly configured @code{auto-load safe-path}
21891 (@pxref{Auto-loading safe path}).
21892
21893 For these reasons, @value{GDBN} includes commands and options to let you
21894 control when to auto-load files and which files should be auto-loaded.
21895
21896 @table @code
21897 @anchor{set auto-load off}
21898 @kindex set auto-load off
21899 @item set auto-load off
21900 Globally disable loading of all auto-loaded files.
21901 You may want to use this command with the @samp{-iex} option
21902 (@pxref{Option -init-eval-command}) such as:
21903 @smallexample
21904 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
21905 @end smallexample
21906
21907 Be aware that system init file (@pxref{System-wide configuration})
21908 and init files from your home directory (@pxref{Home Directory Init File})
21909 still get read (as they come from generally trusted directories).
21910 To prevent @value{GDBN} from auto-loading even those init files, use the
21911 @option{-nx} option (@pxref{Mode Options}), in addition to
21912 @code{set auto-load no}.
21913
21914 @anchor{show auto-load}
21915 @kindex show auto-load
21916 @item show auto-load
21917 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
21918 or disabled.
21919
21920 @smallexample
21921 (gdb) show auto-load
21922 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
21923 libthread-db: Auto-loading of inferior specific libthread_db is on.
21924 local-gdbinit: Auto-loading of .gdbinit script from current directory
21925 is on.
21926 python-scripts: Auto-loading of Python scripts is on.
21927 safe-path: List of directories from which it is safe to auto-load files
21928 is $debugdir:$datadir/auto-load.
21929 scripts-directory: List of directories from which to load auto-loaded scripts
21930 is $debugdir:$datadir/auto-load.
21931 @end smallexample
21932
21933 @anchor{info auto-load}
21934 @kindex info auto-load
21935 @item info auto-load
21936 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
21937 not.
21938
21939 @smallexample
21940 (gdb) info auto-load
21941 gdb-scripts:
21942 Loaded Script
21943 Yes /home/user/gdb/gdb-gdb.gdb
21944 libthread-db: No auto-loaded libthread-db.
21945 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
21946 loaded.
21947 python-scripts:
21948 Loaded Script
21949 Yes /home/user/gdb/gdb-gdb.py
21950 @end smallexample
21951 @end table
21952
21953 These are various kinds of files @value{GDBN} can automatically load:
21954
21955 @itemize @bullet
21956 @item
21957 @xref{objfile-gdb.py file}, controlled by @ref{set auto-load python-scripts}.
21958 @item
21959 @xref{objfile-gdb.gdb file}, controlled by @ref{set auto-load gdb-scripts}.
21960 @item
21961 @xref{dotdebug_gdb_scripts section},
21962 controlled by @ref{set auto-load python-scripts}.
21963 @item
21964 @xref{Init File in the Current Directory},
21965 controlled by @ref{set auto-load local-gdbinit}.
21966 @item
21967 @xref{libthread_db.so.1 file}, controlled by @ref{set auto-load libthread-db}.
21968 @end itemize
21969
21970 These are @value{GDBN} control commands for the auto-loading:
21971
21972 @multitable @columnfractions .5 .5
21973 @item @xref{set auto-load off}.
21974 @tab Disable auto-loading globally.
21975 @item @xref{show auto-load}.
21976 @tab Show setting of all kinds of files.
21977 @item @xref{info auto-load}.
21978 @tab Show state of all kinds of files.
21979 @item @xref{set auto-load gdb-scripts}.
21980 @tab Control for @value{GDBN} command scripts.
21981 @item @xref{show auto-load gdb-scripts}.
21982 @tab Show setting of @value{GDBN} command scripts.
21983 @item @xref{info auto-load gdb-scripts}.
21984 @tab Show state of @value{GDBN} command scripts.
21985 @item @xref{set auto-load python-scripts}.
21986 @tab Control for @value{GDBN} Python scripts.
21987 @item @xref{show auto-load python-scripts}.
21988 @tab Show setting of @value{GDBN} Python scripts.
21989 @item @xref{info auto-load python-scripts}.
21990 @tab Show state of @value{GDBN} Python scripts.
21991 @item @xref{set auto-load scripts-directory}.
21992 @tab Control for @value{GDBN} auto-loaded scripts location.
21993 @item @xref{show auto-load scripts-directory}.
21994 @tab Show @value{GDBN} auto-loaded scripts location.
21995 @item @xref{set auto-load local-gdbinit}.
21996 @tab Control for init file in the current directory.
21997 @item @xref{show auto-load local-gdbinit}.
21998 @tab Show setting of init file in the current directory.
21999 @item @xref{info auto-load local-gdbinit}.
22000 @tab Show state of init file in the current directory.
22001 @item @xref{set auto-load libthread-db}.
22002 @tab Control for thread debugging library.
22003 @item @xref{show auto-load libthread-db}.
22004 @tab Show setting of thread debugging library.
22005 @item @xref{info auto-load libthread-db}.
22006 @tab Show state of thread debugging library.
22007 @item @xref{set auto-load safe-path}.
22008 @tab Control directories trusted for automatic loading.
22009 @item @xref{show auto-load safe-path}.
22010 @tab Show directories trusted for automatic loading.
22011 @item @xref{add-auto-load-safe-path}.
22012 @tab Add directory trusted for automatic loading.
22013 @end multitable
22014
22015 @menu
22016 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
22017 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
22018 * objfile-gdb.gdb file:: @samp{set/show/info auto-load gdb-script}
22019 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
22020 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
22021 @xref{Python Auto-loading}.
22022 @end menu
22023
22024 @node Init File in the Current Directory
22025 @subsection Automatically loading init file in the current directory
22026 @cindex auto-loading init file in the current directory
22027
22028 By default, @value{GDBN} reads and executes the canned sequences of commands
22029 from init file (if any) in the current working directory,
22030 see @ref{Init File in the Current Directory during Startup}.
22031
22032 Note that loading of this local @file{.gdbinit} file also requires accordingly
22033 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
22034
22035 @table @code
22036 @anchor{set auto-load local-gdbinit}
22037 @kindex set auto-load local-gdbinit
22038 @item set auto-load local-gdbinit [on|off]
22039 Enable or disable the auto-loading of canned sequences of commands
22040 (@pxref{Sequences}) found in init file in the current directory.
22041
22042 @anchor{show auto-load local-gdbinit}
22043 @kindex show auto-load local-gdbinit
22044 @item show auto-load local-gdbinit
22045 Show whether auto-loading of canned sequences of commands from init file in the
22046 current directory is enabled or disabled.
22047
22048 @anchor{info auto-load local-gdbinit}
22049 @kindex info auto-load local-gdbinit
22050 @item info auto-load local-gdbinit
22051 Print whether canned sequences of commands from init file in the
22052 current directory have been auto-loaded.
22053 @end table
22054
22055 @node libthread_db.so.1 file
22056 @subsection Automatically loading thread debugging library
22057 @cindex auto-loading libthread_db.so.1
22058
22059 This feature is currently present only on @sc{gnu}/Linux native hosts.
22060
22061 @value{GDBN} reads in some cases thread debugging library from places specific
22062 to the inferior (@pxref{set libthread-db-search-path}).
22063
22064 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
22065 without checking this @samp{set auto-load libthread-db} switch as system
22066 libraries have to be trusted in general. In all other cases of
22067 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
22068 auto-load libthread-db} is enabled before trying to open such thread debugging
22069 library.
22070
22071 Note that loading of this debugging library also requires accordingly configured
22072 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
22073
22074 @table @code
22075 @anchor{set auto-load libthread-db}
22076 @kindex set auto-load libthread-db
22077 @item set auto-load libthread-db [on|off]
22078 Enable or disable the auto-loading of inferior specific thread debugging library.
22079
22080 @anchor{show auto-load libthread-db}
22081 @kindex show auto-load libthread-db
22082 @item show auto-load libthread-db
22083 Show whether auto-loading of inferior specific thread debugging library is
22084 enabled or disabled.
22085
22086 @anchor{info auto-load libthread-db}
22087 @kindex info auto-load libthread-db
22088 @item info auto-load libthread-db
22089 Print the list of all loaded inferior specific thread debugging libraries and
22090 for each such library print list of inferior @var{pid}s using it.
22091 @end table
22092
22093 @node objfile-gdb.gdb file
22094 @subsection The @file{@var{objfile}-gdb.gdb} file
22095 @cindex auto-loading @file{@var{objfile}-gdb.gdb}
22096
22097 @value{GDBN} tries to load an @file{@var{objfile}-gdb.gdb} file containing
22098 canned sequences of commands (@pxref{Sequences}), as long as @samp{set
22099 auto-load gdb-scripts} is set to @samp{on}.
22100
22101 Note that loading of this script file also requires accordingly configured
22102 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
22103
22104 For more background refer to the similar Python scripts auto-loading
22105 description (@pxref{objfile-gdb.py file}).
22106
22107 @table @code
22108 @anchor{set auto-load gdb-scripts}
22109 @kindex set auto-load gdb-scripts
22110 @item set auto-load gdb-scripts [on|off]
22111 Enable or disable the auto-loading of canned sequences of commands scripts.
22112
22113 @anchor{show auto-load gdb-scripts}
22114 @kindex show auto-load gdb-scripts
22115 @item show auto-load gdb-scripts
22116 Show whether auto-loading of canned sequences of commands scripts is enabled or
22117 disabled.
22118
22119 @anchor{info auto-load gdb-scripts}
22120 @kindex info auto-load gdb-scripts
22121 @cindex print list of auto-loaded canned sequences of commands scripts
22122 @item info auto-load gdb-scripts [@var{regexp}]
22123 Print the list of all canned sequences of commands scripts that @value{GDBN}
22124 auto-loaded.
22125 @end table
22126
22127 If @var{regexp} is supplied only canned sequences of commands scripts with
22128 matching names are printed.
22129
22130 @node Auto-loading safe path
22131 @subsection Security restriction for auto-loading
22132 @cindex auto-loading safe-path
22133
22134 As the files of inferior can come from untrusted source (such as submitted by
22135 an application user) @value{GDBN} does not always load any files automatically.
22136 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
22137 directories trusted for loading files not explicitly requested by user.
22138 Each directory can also be a shell wildcard pattern.
22139
22140 If the path is not set properly you will see a warning and the file will not
22141 get loaded:
22142
22143 @smallexample
22144 $ ./gdb -q ./gdb
22145 Reading symbols from /home/user/gdb/gdb...done.
22146 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
22147 declined by your `auto-load safe-path' set
22148 to "$debugdir:$datadir/auto-load".
22149 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
22150 declined by your `auto-load safe-path' set
22151 to "$debugdir:$datadir/auto-load".
22152 @end smallexample
22153
22154 @noindent
22155 To instruct @value{GDBN} to go ahead and use the init files anyway,
22156 invoke @value{GDBN} like this:
22157
22158 @smallexample
22159 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
22160 @end smallexample
22161
22162 The list of trusted directories is controlled by the following commands:
22163
22164 @table @code
22165 @anchor{set auto-load safe-path}
22166 @kindex set auto-load safe-path
22167 @item set auto-load safe-path @r{[}@var{directories}@r{]}
22168 Set the list of directories (and their subdirectories) trusted for automatic
22169 loading and execution of scripts. You can also enter a specific trusted file.
22170 Each directory can also be a shell wildcard pattern; wildcards do not match
22171 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
22172 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
22173 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
22174 its default value as specified during @value{GDBN} compilation.
22175
22176 The list of directories uses path separator (@samp{:} on GNU and Unix
22177 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
22178 to the @env{PATH} environment variable.
22179
22180 @anchor{show auto-load safe-path}
22181 @kindex show auto-load safe-path
22182 @item show auto-load safe-path
22183 Show the list of directories trusted for automatic loading and execution of
22184 scripts.
22185
22186 @anchor{add-auto-load-safe-path}
22187 @kindex add-auto-load-safe-path
22188 @item add-auto-load-safe-path
22189 Add an entry (or list of entries) the list of directories trusted for automatic
22190 loading and execution of scripts. Multiple entries may be delimited by the
22191 host platform path separator in use.
22192 @end table
22193
22194 This variable defaults to what @code{--with-auto-load-dir} has been configured
22195 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
22196 substitution applies the same as for @ref{set auto-load scripts-directory}.
22197 The default @code{set auto-load safe-path} value can be also overriden by
22198 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
22199
22200 Setting this variable to @file{/} disables this security protection,
22201 corresponding @value{GDBN} configuration option is
22202 @option{--without-auto-load-safe-path}.
22203 This variable is supposed to be set to the system directories writable by the
22204 system superuser only. Users can add their source directories in init files in
22205 their home directories (@pxref{Home Directory Init File}). See also deprecated
22206 init file in the current directory
22207 (@pxref{Init File in the Current Directory during Startup}).
22208
22209 To force @value{GDBN} to load the files it declined to load in the previous
22210 example, you could use one of the following ways:
22211
22212 @table @asis
22213 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
22214 Specify this trusted directory (or a file) as additional component of the list.
22215 You have to specify also any existing directories displayed by
22216 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
22217
22218 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
22219 Specify this directory as in the previous case but just for a single
22220 @value{GDBN} session.
22221
22222 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
22223 Disable auto-loading safety for a single @value{GDBN} session.
22224 This assumes all the files you debug during this @value{GDBN} session will come
22225 from trusted sources.
22226
22227 @item @kbd{./configure --without-auto-load-safe-path}
22228 During compilation of @value{GDBN} you may disable any auto-loading safety.
22229 This assumes all the files you will ever debug with this @value{GDBN} come from
22230 trusted sources.
22231 @end table
22232
22233 On the other hand you can also explicitly forbid automatic files loading which
22234 also suppresses any such warning messages:
22235
22236 @table @asis
22237 @item @kbd{gdb -iex "set auto-load no" @dots{}}
22238 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
22239
22240 @item @file{~/.gdbinit}: @samp{set auto-load no}
22241 Disable auto-loading globally for the user
22242 (@pxref{Home Directory Init File}). While it is improbable, you could also
22243 use system init file instead (@pxref{System-wide configuration}).
22244 @end table
22245
22246 This setting applies to the file names as entered by user. If no entry matches
22247 @value{GDBN} tries as a last resort to also resolve all the file names into
22248 their canonical form (typically resolving symbolic links) and compare the
22249 entries again. @value{GDBN} already canonicalizes most of the filenames on its
22250 own before starting the comparison so a canonical form of directories is
22251 recommended to be entered.
22252
22253 @node Auto-loading verbose mode
22254 @subsection Displaying files tried for auto-load
22255 @cindex auto-loading verbose mode
22256
22257 For better visibility of all the file locations where you can place scripts to
22258 be auto-loaded with inferior --- or to protect yourself against accidental
22259 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
22260 all the files attempted to be loaded. Both existing and non-existing files may
22261 be printed.
22262
22263 For example the list of directories from which it is safe to auto-load files
22264 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
22265 may not be too obvious while setting it up.
22266
22267 @smallexample
22268 (gdb) set debug auto-load on
22269 (gdb) file ~/src/t/true
22270 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
22271 for objfile "/tmp/true".
22272 auto-load: Updating directories of "/usr:/opt".
22273 auto-load: Using directory "/usr".
22274 auto-load: Using directory "/opt".
22275 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
22276 by your `auto-load safe-path' set to "/usr:/opt".
22277 @end smallexample
22278
22279 @table @code
22280 @anchor{set debug auto-load}
22281 @kindex set debug auto-load
22282 @item set debug auto-load [on|off]
22283 Set whether to print the filenames attempted to be auto-loaded.
22284
22285 @anchor{show debug auto-load}
22286 @kindex show debug auto-load
22287 @item show debug auto-load
22288 Show whether printing of the filenames attempted to be auto-loaded is turned
22289 on or off.
22290 @end table
22291
22292 @node Messages/Warnings
22293 @section Optional Warnings and Messages
22294
22295 @cindex verbose operation
22296 @cindex optional warnings
22297 By default, @value{GDBN} is silent about its inner workings. If you are
22298 running on a slow machine, you may want to use the @code{set verbose}
22299 command. This makes @value{GDBN} tell you when it does a lengthy
22300 internal operation, so you will not think it has crashed.
22301
22302 Currently, the messages controlled by @code{set verbose} are those
22303 which announce that the symbol table for a source file is being read;
22304 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
22305
22306 @table @code
22307 @kindex set verbose
22308 @item set verbose on
22309 Enables @value{GDBN} output of certain informational messages.
22310
22311 @item set verbose off
22312 Disables @value{GDBN} output of certain informational messages.
22313
22314 @kindex show verbose
22315 @item show verbose
22316 Displays whether @code{set verbose} is on or off.
22317 @end table
22318
22319 By default, if @value{GDBN} encounters bugs in the symbol table of an
22320 object file, it is silent; but if you are debugging a compiler, you may
22321 find this information useful (@pxref{Symbol Errors, ,Errors Reading
22322 Symbol Files}).
22323
22324 @table @code
22325
22326 @kindex set complaints
22327 @item set complaints @var{limit}
22328 Permits @value{GDBN} to output @var{limit} complaints about each type of
22329 unusual symbols before becoming silent about the problem. Set
22330 @var{limit} to zero to suppress all complaints; set it to a large number
22331 to prevent complaints from being suppressed.
22332
22333 @kindex show complaints
22334 @item show complaints
22335 Displays how many symbol complaints @value{GDBN} is permitted to produce.
22336
22337 @end table
22338
22339 @anchor{confirmation requests}
22340 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
22341 lot of stupid questions to confirm certain commands. For example, if
22342 you try to run a program which is already running:
22343
22344 @smallexample
22345 (@value{GDBP}) run
22346 The program being debugged has been started already.
22347 Start it from the beginning? (y or n)
22348 @end smallexample
22349
22350 If you are willing to unflinchingly face the consequences of your own
22351 commands, you can disable this ``feature'':
22352
22353 @table @code
22354
22355 @kindex set confirm
22356 @cindex flinching
22357 @cindex confirmation
22358 @cindex stupid questions
22359 @item set confirm off
22360 Disables confirmation requests. Note that running @value{GDBN} with
22361 the @option{--batch} option (@pxref{Mode Options, -batch}) also
22362 automatically disables confirmation requests.
22363
22364 @item set confirm on
22365 Enables confirmation requests (the default).
22366
22367 @kindex show confirm
22368 @item show confirm
22369 Displays state of confirmation requests.
22370
22371 @end table
22372
22373 @cindex command tracing
22374 If you need to debug user-defined commands or sourced files you may find it
22375 useful to enable @dfn{command tracing}. In this mode each command will be
22376 printed as it is executed, prefixed with one or more @samp{+} symbols, the
22377 quantity denoting the call depth of each command.
22378
22379 @table @code
22380 @kindex set trace-commands
22381 @cindex command scripts, debugging
22382 @item set trace-commands on
22383 Enable command tracing.
22384 @item set trace-commands off
22385 Disable command tracing.
22386 @item show trace-commands
22387 Display the current state of command tracing.
22388 @end table
22389
22390 @node Debugging Output
22391 @section Optional Messages about Internal Happenings
22392 @cindex optional debugging messages
22393
22394 @value{GDBN} has commands that enable optional debugging messages from
22395 various @value{GDBN} subsystems; normally these commands are of
22396 interest to @value{GDBN} maintainers, or when reporting a bug. This
22397 section documents those commands.
22398
22399 @table @code
22400 @kindex set exec-done-display
22401 @item set exec-done-display
22402 Turns on or off the notification of asynchronous commands'
22403 completion. When on, @value{GDBN} will print a message when an
22404 asynchronous command finishes its execution. The default is off.
22405 @kindex show exec-done-display
22406 @item show exec-done-display
22407 Displays the current setting of asynchronous command completion
22408 notification.
22409 @kindex set debug
22410 @cindex ARM AArch64
22411 @item set debug aarch64
22412 Turns on or off display of debugging messages related to ARM AArch64.
22413 The default is off.
22414 @kindex show debug
22415 @item show debug aarch64
22416 Displays the current state of displaying debugging messages related to
22417 ARM AArch64.
22418 @cindex gdbarch debugging info
22419 @cindex architecture debugging info
22420 @item set debug arch
22421 Turns on or off display of gdbarch debugging info. The default is off
22422 @item show debug arch
22423 Displays the current state of displaying gdbarch debugging info.
22424 @item set debug aix-solib
22425 @cindex AIX shared library debugging
22426 Control display of debugging messages from the AIX shared library
22427 support module. The default is off.
22428 @item show debug aix-thread
22429 Show the current state of displaying AIX shared library debugging messages.
22430 @item set debug aix-thread
22431 @cindex AIX threads
22432 Display debugging messages about inner workings of the AIX thread
22433 module.
22434 @item show debug aix-thread
22435 Show the current state of AIX thread debugging info display.
22436 @item set debug check-physname
22437 @cindex physname
22438 Check the results of the ``physname'' computation. When reading DWARF
22439 debugging information for C@t{++}, @value{GDBN} attempts to compute
22440 each entity's name. @value{GDBN} can do this computation in two
22441 different ways, depending on exactly what information is present.
22442 When enabled, this setting causes @value{GDBN} to compute the names
22443 both ways and display any discrepancies.
22444 @item show debug check-physname
22445 Show the current state of ``physname'' checking.
22446 @item set debug coff-pe-read
22447 @cindex COFF/PE exported symbols
22448 Control display of debugging messages related to reading of COFF/PE
22449 exported symbols. The default is off.
22450 @item show debug coff-pe-read
22451 Displays the current state of displaying debugging messages related to
22452 reading of COFF/PE exported symbols.
22453 @item set debug dwarf2-die
22454 @cindex DWARF2 DIEs
22455 Dump DWARF2 DIEs after they are read in.
22456 The value is the number of nesting levels to print.
22457 A value of zero turns off the display.
22458 @item show debug dwarf2-die
22459 Show the current state of DWARF2 DIE debugging.
22460 @item set debug dwarf2-read
22461 @cindex DWARF2 Reading
22462 Turns on or off display of debugging messages related to reading
22463 DWARF debug info. The default is off.
22464 @item show debug dwarf2-read
22465 Show the current state of DWARF2 reader debugging.
22466 @item set debug displaced
22467 @cindex displaced stepping debugging info
22468 Turns on or off display of @value{GDBN} debugging info for the
22469 displaced stepping support. The default is off.
22470 @item show debug displaced
22471 Displays the current state of displaying @value{GDBN} debugging info
22472 related to displaced stepping.
22473 @item set debug event
22474 @cindex event debugging info
22475 Turns on or off display of @value{GDBN} event debugging info. The
22476 default is off.
22477 @item show debug event
22478 Displays the current state of displaying @value{GDBN} event debugging
22479 info.
22480 @item set debug expression
22481 @cindex expression debugging info
22482 Turns on or off display of debugging info about @value{GDBN}
22483 expression parsing. The default is off.
22484 @item show debug expression
22485 Displays the current state of displaying debugging info about
22486 @value{GDBN} expression parsing.
22487 @item set debug frame
22488 @cindex frame debugging info
22489 Turns on or off display of @value{GDBN} frame debugging info. The
22490 default is off.
22491 @item show debug frame
22492 Displays the current state of displaying @value{GDBN} frame debugging
22493 info.
22494 @item set debug gnu-nat
22495 @cindex @sc{gnu}/Hurd debug messages
22496 Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
22497 @item show debug gnu-nat
22498 Show the current state of @sc{gnu}/Hurd debugging messages.
22499 @item set debug infrun
22500 @cindex inferior debugging info
22501 Turns on or off display of @value{GDBN} debugging info for running the inferior.
22502 The default is off. @file{infrun.c} contains GDB's runtime state machine used
22503 for implementing operations such as single-stepping the inferior.
22504 @item show debug infrun
22505 Displays the current state of @value{GDBN} inferior debugging.
22506 @item set debug jit
22507 @cindex just-in-time compilation, debugging messages
22508 Turns on or off debugging messages from JIT debug support.
22509 @item show debug jit
22510 Displays the current state of @value{GDBN} JIT debugging.
22511 @item set debug lin-lwp
22512 @cindex @sc{gnu}/Linux LWP debug messages
22513 @cindex Linux lightweight processes
22514 Turns on or off debugging messages from the Linux LWP debug support.
22515 @item show debug lin-lwp
22516 Show the current state of Linux LWP debugging messages.
22517 @item set debug mach-o
22518 @cindex Mach-O symbols processing
22519 Control display of debugging messages related to Mach-O symbols
22520 processing. The default is off.
22521 @item show debug mach-o
22522 Displays the current state of displaying debugging messages related to
22523 reading of COFF/PE exported symbols.
22524 @item set debug notification
22525 @cindex remote async notification debugging info
22526 Turns on or off debugging messages about remote async notification.
22527 The default is off.
22528 @item show debug notification
22529 Displays the current state of remote async notification debugging messages.
22530 @item set debug observer
22531 @cindex observer debugging info
22532 Turns on or off display of @value{GDBN} observer debugging. This
22533 includes info such as the notification of observable events.
22534 @item show debug observer
22535 Displays the current state of observer debugging.
22536 @item set debug overload
22537 @cindex C@t{++} overload debugging info
22538 Turns on or off display of @value{GDBN} C@t{++} overload debugging
22539 info. This includes info such as ranking of functions, etc. The default
22540 is off.
22541 @item show debug overload
22542 Displays the current state of displaying @value{GDBN} C@t{++} overload
22543 debugging info.
22544 @cindex expression parser, debugging info
22545 @cindex debug expression parser
22546 @item set debug parser
22547 Turns on or off the display of expression parser debugging output.
22548 Internally, this sets the @code{yydebug} variable in the expression
22549 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
22550 details. The default is off.
22551 @item show debug parser
22552 Show the current state of expression parser debugging.
22553 @cindex packets, reporting on stdout
22554 @cindex serial connections, debugging
22555 @cindex debug remote protocol
22556 @cindex remote protocol debugging
22557 @cindex display remote packets
22558 @item set debug remote
22559 Turns on or off display of reports on all packets sent back and forth across
22560 the serial line to the remote machine. The info is printed on the
22561 @value{GDBN} standard output stream. The default is off.
22562 @item show debug remote
22563 Displays the state of display of remote packets.
22564 @item set debug serial
22565 Turns on or off display of @value{GDBN} serial debugging info. The
22566 default is off.
22567 @item show debug serial
22568 Displays the current state of displaying @value{GDBN} serial debugging
22569 info.
22570 @item set debug solib-frv
22571 @cindex FR-V shared-library debugging
22572 Turns on or off debugging messages for FR-V shared-library code.
22573 @item show debug solib-frv
22574 Display the current state of FR-V shared-library code debugging
22575 messages.
22576 @item set debug symtab-create
22577 @cindex symbol table creation
22578 Turns on or off display of debugging messages related to symbol table creation.
22579 The default is off.
22580 @item show debug symtab-create
22581 Show the current state of symbol table creation debugging.
22582 @item set debug target
22583 @cindex target debugging info
22584 Turns on or off display of @value{GDBN} target debugging info. This info
22585 includes what is going on at the target level of GDB, as it happens. The
22586 default is 0. Set it to 1 to track events, and to 2 to also track the
22587 value of large memory transfers. Changes to this flag do not take effect
22588 until the next time you connect to a target or use the @code{run} command.
22589 @item show debug target
22590 Displays the current state of displaying @value{GDBN} target debugging
22591 info.
22592 @item set debug timestamp
22593 @cindex timestampping debugging info
22594 Turns on or off display of timestamps with @value{GDBN} debugging info.
22595 When enabled, seconds and microseconds are displayed before each debugging
22596 message.
22597 @item show debug timestamp
22598 Displays the current state of displaying timestamps with @value{GDBN}
22599 debugging info.
22600 @item set debugvarobj
22601 @cindex variable object debugging info
22602 Turns on or off display of @value{GDBN} variable object debugging
22603 info. The default is off.
22604 @item show debugvarobj
22605 Displays the current state of displaying @value{GDBN} variable object
22606 debugging info.
22607 @item set debug xml
22608 @cindex XML parser debugging
22609 Turns on or off debugging messages for built-in XML parsers.
22610 @item show debug xml
22611 Displays the current state of XML debugging messages.
22612 @end table
22613
22614 @node Other Misc Settings
22615 @section Other Miscellaneous Settings
22616 @cindex miscellaneous settings
22617
22618 @table @code
22619 @kindex set interactive-mode
22620 @item set interactive-mode
22621 If @code{on}, forces @value{GDBN} to assume that GDB was started
22622 in a terminal. In practice, this means that @value{GDBN} should wait
22623 for the user to answer queries generated by commands entered at
22624 the command prompt. If @code{off}, forces @value{GDBN} to operate
22625 in the opposite mode, and it uses the default answers to all queries.
22626 If @code{auto} (the default), @value{GDBN} tries to determine whether
22627 its standard input is a terminal, and works in interactive-mode if it
22628 is, non-interactively otherwise.
22629
22630 In the vast majority of cases, the debugger should be able to guess
22631 correctly which mode should be used. But this setting can be useful
22632 in certain specific cases, such as running a MinGW @value{GDBN}
22633 inside a cygwin window.
22634
22635 @kindex show interactive-mode
22636 @item show interactive-mode
22637 Displays whether the debugger is operating in interactive mode or not.
22638 @end table
22639
22640 @node Extending GDB
22641 @chapter Extending @value{GDBN}
22642 @cindex extending GDB
22643
22644 @value{GDBN} provides three mechanisms for extension. The first is based
22645 on composition of @value{GDBN} commands, the second is based on the
22646 Python scripting language, and the third is for defining new aliases of
22647 existing commands.
22648
22649 To facilitate the use of the first two extensions, @value{GDBN} is capable
22650 of evaluating the contents of a file. When doing so, @value{GDBN}
22651 can recognize which scripting language is being used by looking at
22652 the filename extension. Files with an unrecognized filename extension
22653 are always treated as a @value{GDBN} Command Files.
22654 @xref{Command Files,, Command files}.
22655
22656 You can control how @value{GDBN} evaluates these files with the following
22657 setting:
22658
22659 @table @code
22660 @kindex set script-extension
22661 @kindex show script-extension
22662 @item set script-extension off
22663 All scripts are always evaluated as @value{GDBN} Command Files.
22664
22665 @item set script-extension soft
22666 The debugger determines the scripting language based on filename
22667 extension. If this scripting language is supported, @value{GDBN}
22668 evaluates the script using that language. Otherwise, it evaluates
22669 the file as a @value{GDBN} Command File.
22670
22671 @item set script-extension strict
22672 The debugger determines the scripting language based on filename
22673 extension, and evaluates the script using that language. If the
22674 language is not supported, then the evaluation fails.
22675
22676 @item show script-extension
22677 Display the current value of the @code{script-extension} option.
22678
22679 @end table
22680
22681 @menu
22682 * Sequences:: Canned Sequences of Commands
22683 * Python:: Scripting @value{GDBN} using Python
22684 * Aliases:: Creating new spellings of existing commands
22685 @end menu
22686
22687 @node Sequences
22688 @section Canned Sequences of Commands
22689
22690 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
22691 Command Lists}), @value{GDBN} provides two ways to store sequences of
22692 commands for execution as a unit: user-defined commands and command
22693 files.
22694
22695 @menu
22696 * Define:: How to define your own commands
22697 * Hooks:: Hooks for user-defined commands
22698 * Command Files:: How to write scripts of commands to be stored in a file
22699 * Output:: Commands for controlled output
22700 @end menu
22701
22702 @node Define
22703 @subsection User-defined Commands
22704
22705 @cindex user-defined command
22706 @cindex arguments, to user-defined commands
22707 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
22708 which you assign a new name as a command. This is done with the
22709 @code{define} command. User commands may accept up to 10 arguments
22710 separated by whitespace. Arguments are accessed within the user command
22711 via @code{$arg0@dots{}$arg9}. A trivial example:
22712
22713 @smallexample
22714 define adder
22715 print $arg0 + $arg1 + $arg2
22716 end
22717 @end smallexample
22718
22719 @noindent
22720 To execute the command use:
22721
22722 @smallexample
22723 adder 1 2 3
22724 @end smallexample
22725
22726 @noindent
22727 This defines the command @code{adder}, which prints the sum of
22728 its three arguments. Note the arguments are text substitutions, so they may
22729 reference variables, use complex expressions, or even perform inferior
22730 functions calls.
22731
22732 @cindex argument count in user-defined commands
22733 @cindex how many arguments (user-defined commands)
22734 In addition, @code{$argc} may be used to find out how many arguments have
22735 been passed. This expands to a number in the range 0@dots{}10.
22736
22737 @smallexample
22738 define adder
22739 if $argc == 2
22740 print $arg0 + $arg1
22741 end
22742 if $argc == 3
22743 print $arg0 + $arg1 + $arg2
22744 end
22745 end
22746 @end smallexample
22747
22748 @table @code
22749
22750 @kindex define
22751 @item define @var{commandname}
22752 Define a command named @var{commandname}. If there is already a command
22753 by that name, you are asked to confirm that you want to redefine it.
22754 @var{commandname} may be a bare command name consisting of letters,
22755 numbers, dashes, and underscores. It may also start with any predefined
22756 prefix command. For example, @samp{define target my-target} creates
22757 a user-defined @samp{target my-target} command.
22758
22759 The definition of the command is made up of other @value{GDBN} command lines,
22760 which are given following the @code{define} command. The end of these
22761 commands is marked by a line containing @code{end}.
22762
22763 @kindex document
22764 @kindex end@r{ (user-defined commands)}
22765 @item document @var{commandname}
22766 Document the user-defined command @var{commandname}, so that it can be
22767 accessed by @code{help}. The command @var{commandname} must already be
22768 defined. This command reads lines of documentation just as @code{define}
22769 reads the lines of the command definition, ending with @code{end}.
22770 After the @code{document} command is finished, @code{help} on command
22771 @var{commandname} displays the documentation you have written.
22772
22773 You may use the @code{document} command again to change the
22774 documentation of a command. Redefining the command with @code{define}
22775 does not change the documentation.
22776
22777 @kindex dont-repeat
22778 @cindex don't repeat command
22779 @item dont-repeat
22780 Used inside a user-defined command, this tells @value{GDBN} that this
22781 command should not be repeated when the user hits @key{RET}
22782 (@pxref{Command Syntax, repeat last command}).
22783
22784 @kindex help user-defined
22785 @item help user-defined
22786 List all user-defined commands and all python commands defined in class
22787 COMAND_USER. The first line of the documentation or docstring is
22788 included (if any).
22789
22790 @kindex show user
22791 @item show user
22792 @itemx show user @var{commandname}
22793 Display the @value{GDBN} commands used to define @var{commandname} (but
22794 not its documentation). If no @var{commandname} is given, display the
22795 definitions for all user-defined commands.
22796 This does not work for user-defined python commands.
22797
22798 @cindex infinite recursion in user-defined commands
22799 @kindex show max-user-call-depth
22800 @kindex set max-user-call-depth
22801 @item show max-user-call-depth
22802 @itemx set max-user-call-depth
22803 The value of @code{max-user-call-depth} controls how many recursion
22804 levels are allowed in user-defined commands before @value{GDBN} suspects an
22805 infinite recursion and aborts the command.
22806 This does not apply to user-defined python commands.
22807 @end table
22808
22809 In addition to the above commands, user-defined commands frequently
22810 use control flow commands, described in @ref{Command Files}.
22811
22812 When user-defined commands are executed, the
22813 commands of the definition are not printed. An error in any command
22814 stops execution of the user-defined command.
22815
22816 If used interactively, commands that would ask for confirmation proceed
22817 without asking when used inside a user-defined command. Many @value{GDBN}
22818 commands that normally print messages to say what they are doing omit the
22819 messages when used in a user-defined command.
22820
22821 @node Hooks
22822 @subsection User-defined Command Hooks
22823 @cindex command hooks
22824 @cindex hooks, for commands
22825 @cindex hooks, pre-command
22826
22827 @kindex hook
22828 You may define @dfn{hooks}, which are a special kind of user-defined
22829 command. Whenever you run the command @samp{foo}, if the user-defined
22830 command @samp{hook-foo} exists, it is executed (with no arguments)
22831 before that command.
22832
22833 @cindex hooks, post-command
22834 @kindex hookpost
22835 A hook may also be defined which is run after the command you executed.
22836 Whenever you run the command @samp{foo}, if the user-defined command
22837 @samp{hookpost-foo} exists, it is executed (with no arguments) after
22838 that command. Post-execution hooks may exist simultaneously with
22839 pre-execution hooks, for the same command.
22840
22841 It is valid for a hook to call the command which it hooks. If this
22842 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
22843
22844 @c It would be nice if hookpost could be passed a parameter indicating
22845 @c if the command it hooks executed properly or not. FIXME!
22846
22847 @kindex stop@r{, a pseudo-command}
22848 In addition, a pseudo-command, @samp{stop} exists. Defining
22849 (@samp{hook-stop}) makes the associated commands execute every time
22850 execution stops in your program: before breakpoint commands are run,
22851 displays are printed, or the stack frame is printed.
22852
22853 For example, to ignore @code{SIGALRM} signals while
22854 single-stepping, but treat them normally during normal execution,
22855 you could define:
22856
22857 @smallexample
22858 define hook-stop
22859 handle SIGALRM nopass
22860 end
22861
22862 define hook-run
22863 handle SIGALRM pass
22864 end
22865
22866 define hook-continue
22867 handle SIGALRM pass
22868 end
22869 @end smallexample
22870
22871 As a further example, to hook at the beginning and end of the @code{echo}
22872 command, and to add extra text to the beginning and end of the message,
22873 you could define:
22874
22875 @smallexample
22876 define hook-echo
22877 echo <<<---
22878 end
22879
22880 define hookpost-echo
22881 echo --->>>\n
22882 end
22883
22884 (@value{GDBP}) echo Hello World
22885 <<<---Hello World--->>>
22886 (@value{GDBP})
22887
22888 @end smallexample
22889
22890 You can define a hook for any single-word command in @value{GDBN}, but
22891 not for command aliases; you should define a hook for the basic command
22892 name, e.g.@: @code{backtrace} rather than @code{bt}.
22893 @c FIXME! So how does Joe User discover whether a command is an alias
22894 @c or not?
22895 You can hook a multi-word command by adding @code{hook-} or
22896 @code{hookpost-} to the last word of the command, e.g.@:
22897 @samp{define target hook-remote} to add a hook to @samp{target remote}.
22898
22899 If an error occurs during the execution of your hook, execution of
22900 @value{GDBN} commands stops and @value{GDBN} issues a prompt
22901 (before the command that you actually typed had a chance to run).
22902
22903 If you try to define a hook which does not match any known command, you
22904 get a warning from the @code{define} command.
22905
22906 @node Command Files
22907 @subsection Command Files
22908
22909 @cindex command files
22910 @cindex scripting commands
22911 A command file for @value{GDBN} is a text file made of lines that are
22912 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
22913 also be included. An empty line in a command file does nothing; it
22914 does not mean to repeat the last command, as it would from the
22915 terminal.
22916
22917 You can request the execution of a command file with the @code{source}
22918 command. Note that the @code{source} command is also used to evaluate
22919 scripts that are not Command Files. The exact behavior can be configured
22920 using the @code{script-extension} setting.
22921 @xref{Extending GDB,, Extending GDB}.
22922
22923 @table @code
22924 @kindex source
22925 @cindex execute commands from a file
22926 @item source [-s] [-v] @var{filename}
22927 Execute the command file @var{filename}.
22928 @end table
22929
22930 The lines in a command file are generally executed sequentially,
22931 unless the order of execution is changed by one of the
22932 @emph{flow-control commands} described below. The commands are not
22933 printed as they are executed. An error in any command terminates
22934 execution of the command file and control is returned to the console.
22935
22936 @value{GDBN} first searches for @var{filename} in the current directory.
22937 If the file is not found there, and @var{filename} does not specify a
22938 directory, then @value{GDBN} also looks for the file on the source search path
22939 (specified with the @samp{directory} command);
22940 except that @file{$cdir} is not searched because the compilation directory
22941 is not relevant to scripts.
22942
22943 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
22944 on the search path even if @var{filename} specifies a directory.
22945 The search is done by appending @var{filename} to each element of the
22946 search path. So, for example, if @var{filename} is @file{mylib/myscript}
22947 and the search path contains @file{/home/user} then @value{GDBN} will
22948 look for the script @file{/home/user/mylib/myscript}.
22949 The search is also done if @var{filename} is an absolute path.
22950 For example, if @var{filename} is @file{/tmp/myscript} and
22951 the search path contains @file{/home/user} then @value{GDBN} will
22952 look for the script @file{/home/user/tmp/myscript}.
22953 For DOS-like systems, if @var{filename} contains a drive specification,
22954 it is stripped before concatenation. For example, if @var{filename} is
22955 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
22956 will look for the script @file{c:/tmp/myscript}.
22957
22958 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
22959 each command as it is executed. The option must be given before
22960 @var{filename}, and is interpreted as part of the filename anywhere else.
22961
22962 Commands that would ask for confirmation if used interactively proceed
22963 without asking when used in a command file. Many @value{GDBN} commands that
22964 normally print messages to say what they are doing omit the messages
22965 when called from command files.
22966
22967 @value{GDBN} also accepts command input from standard input. In this
22968 mode, normal output goes to standard output and error output goes to
22969 standard error. Errors in a command file supplied on standard input do
22970 not terminate execution of the command file---execution continues with
22971 the next command.
22972
22973 @smallexample
22974 gdb < cmds > log 2>&1
22975 @end smallexample
22976
22977 (The syntax above will vary depending on the shell used.) This example
22978 will execute commands from the file @file{cmds}. All output and errors
22979 would be directed to @file{log}.
22980
22981 Since commands stored on command files tend to be more general than
22982 commands typed interactively, they frequently need to deal with
22983 complicated situations, such as different or unexpected values of
22984 variables and symbols, changes in how the program being debugged is
22985 built, etc. @value{GDBN} provides a set of flow-control commands to
22986 deal with these complexities. Using these commands, you can write
22987 complex scripts that loop over data structures, execute commands
22988 conditionally, etc.
22989
22990 @table @code
22991 @kindex if
22992 @kindex else
22993 @item if
22994 @itemx else
22995 This command allows to include in your script conditionally executed
22996 commands. The @code{if} command takes a single argument, which is an
22997 expression to evaluate. It is followed by a series of commands that
22998 are executed only if the expression is true (its value is nonzero).
22999 There can then optionally be an @code{else} line, followed by a series
23000 of commands that are only executed if the expression was false. The
23001 end of the list is marked by a line containing @code{end}.
23002
23003 @kindex while
23004 @item while
23005 This command allows to write loops. Its syntax is similar to
23006 @code{if}: the command takes a single argument, which is an expression
23007 to evaluate, and must be followed by the commands to execute, one per
23008 line, terminated by an @code{end}. These commands are called the
23009 @dfn{body} of the loop. The commands in the body of @code{while} are
23010 executed repeatedly as long as the expression evaluates to true.
23011
23012 @kindex loop_break
23013 @item loop_break
23014 This command exits the @code{while} loop in whose body it is included.
23015 Execution of the script continues after that @code{while}s @code{end}
23016 line.
23017
23018 @kindex loop_continue
23019 @item loop_continue
23020 This command skips the execution of the rest of the body of commands
23021 in the @code{while} loop in whose body it is included. Execution
23022 branches to the beginning of the @code{while} loop, where it evaluates
23023 the controlling expression.
23024
23025 @kindex end@r{ (if/else/while commands)}
23026 @item end
23027 Terminate the block of commands that are the body of @code{if},
23028 @code{else}, or @code{while} flow-control commands.
23029 @end table
23030
23031
23032 @node Output
23033 @subsection Commands for Controlled Output
23034
23035 During the execution of a command file or a user-defined command, normal
23036 @value{GDBN} output is suppressed; the only output that appears is what is
23037 explicitly printed by the commands in the definition. This section
23038 describes three commands useful for generating exactly the output you
23039 want.
23040
23041 @table @code
23042 @kindex echo
23043 @item echo @var{text}
23044 @c I do not consider backslash-space a standard C escape sequence
23045 @c because it is not in ANSI.
23046 Print @var{text}. Nonprinting characters can be included in
23047 @var{text} using C escape sequences, such as @samp{\n} to print a
23048 newline. @strong{No newline is printed unless you specify one.}
23049 In addition to the standard C escape sequences, a backslash followed
23050 by a space stands for a space. This is useful for displaying a
23051 string with spaces at the beginning or the end, since leading and
23052 trailing spaces are otherwise trimmed from all arguments.
23053 To print @samp{@w{ }and foo =@w{ }}, use the command
23054 @samp{echo \@w{ }and foo = \@w{ }}.
23055
23056 A backslash at the end of @var{text} can be used, as in C, to continue
23057 the command onto subsequent lines. For example,
23058
23059 @smallexample
23060 echo This is some text\n\
23061 which is continued\n\
23062 onto several lines.\n
23063 @end smallexample
23064
23065 produces the same output as
23066
23067 @smallexample
23068 echo This is some text\n
23069 echo which is continued\n
23070 echo onto several lines.\n
23071 @end smallexample
23072
23073 @kindex output
23074 @item output @var{expression}
23075 Print the value of @var{expression} and nothing but that value: no
23076 newlines, no @samp{$@var{nn} = }. The value is not entered in the
23077 value history either. @xref{Expressions, ,Expressions}, for more information
23078 on expressions.
23079
23080 @item output/@var{fmt} @var{expression}
23081 Print the value of @var{expression} in format @var{fmt}. You can use
23082 the same formats as for @code{print}. @xref{Output Formats,,Output
23083 Formats}, for more information.
23084
23085 @kindex printf
23086 @item printf @var{template}, @var{expressions}@dots{}
23087 Print the values of one or more @var{expressions} under the control of
23088 the string @var{template}. To print several values, make
23089 @var{expressions} be a comma-separated list of individual expressions,
23090 which may be either numbers or pointers. Their values are printed as
23091 specified by @var{template}, exactly as a C program would do by
23092 executing the code below:
23093
23094 @smallexample
23095 printf (@var{template}, @var{expressions}@dots{});
23096 @end smallexample
23097
23098 As in @code{C} @code{printf}, ordinary characters in @var{template}
23099 are printed verbatim, while @dfn{conversion specification} introduced
23100 by the @samp{%} character cause subsequent @var{expressions} to be
23101 evaluated, their values converted and formatted according to type and
23102 style information encoded in the conversion specifications, and then
23103 printed.
23104
23105 For example, you can print two values in hex like this:
23106
23107 @smallexample
23108 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
23109 @end smallexample
23110
23111 @code{printf} supports all the standard @code{C} conversion
23112 specifications, including the flags and modifiers between the @samp{%}
23113 character and the conversion letter, with the following exceptions:
23114
23115 @itemize @bullet
23116 @item
23117 The argument-ordering modifiers, such as @samp{2$}, are not supported.
23118
23119 @item
23120 The modifier @samp{*} is not supported for specifying precision or
23121 width.
23122
23123 @item
23124 The @samp{'} flag (for separation of digits into groups according to
23125 @code{LC_NUMERIC'}) is not supported.
23126
23127 @item
23128 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
23129 supported.
23130
23131 @item
23132 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
23133
23134 @item
23135 The conversion letters @samp{a} and @samp{A} are not supported.
23136 @end itemize
23137
23138 @noindent
23139 Note that the @samp{ll} type modifier is supported only if the
23140 underlying @code{C} implementation used to build @value{GDBN} supports
23141 the @code{long long int} type, and the @samp{L} type modifier is
23142 supported only if @code{long double} type is available.
23143
23144 As in @code{C}, @code{printf} supports simple backslash-escape
23145 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
23146 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
23147 single character. Octal and hexadecimal escape sequences are not
23148 supported.
23149
23150 Additionally, @code{printf} supports conversion specifications for DFP
23151 (@dfn{Decimal Floating Point}) types using the following length modifiers
23152 together with a floating point specifier.
23153 letters:
23154
23155 @itemize @bullet
23156 @item
23157 @samp{H} for printing @code{Decimal32} types.
23158
23159 @item
23160 @samp{D} for printing @code{Decimal64} types.
23161
23162 @item
23163 @samp{DD} for printing @code{Decimal128} types.
23164 @end itemize
23165
23166 If the underlying @code{C} implementation used to build @value{GDBN} has
23167 support for the three length modifiers for DFP types, other modifiers
23168 such as width and precision will also be available for @value{GDBN} to use.
23169
23170 In case there is no such @code{C} support, no additional modifiers will be
23171 available and the value will be printed in the standard way.
23172
23173 Here's an example of printing DFP types using the above conversion letters:
23174 @smallexample
23175 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
23176 @end smallexample
23177
23178 @kindex eval
23179 @item eval @var{template}, @var{expressions}@dots{}
23180 Convert the values of one or more @var{expressions} under the control of
23181 the string @var{template} to a command line, and call it.
23182
23183 @end table
23184
23185 @node Python
23186 @section Scripting @value{GDBN} using Python
23187 @cindex python scripting
23188 @cindex scripting with python
23189
23190 You can script @value{GDBN} using the @uref{http://www.python.org/,
23191 Python programming language}. This feature is available only if
23192 @value{GDBN} was configured using @option{--with-python}.
23193
23194 @cindex python directory
23195 Python scripts used by @value{GDBN} should be installed in
23196 @file{@var{data-directory}/python}, where @var{data-directory} is
23197 the data directory as determined at @value{GDBN} startup (@pxref{Data Files}).
23198 This directory, known as the @dfn{python directory},
23199 is automatically added to the Python Search Path in order to allow
23200 the Python interpreter to locate all scripts installed at this location.
23201
23202 Additionally, @value{GDBN} commands and convenience functions which
23203 are written in Python and are located in the
23204 @file{@var{data-directory}/python/gdb/command} or
23205 @file{@var{data-directory}/python/gdb/function} directories are
23206 automatically imported when @value{GDBN} starts.
23207
23208 @menu
23209 * Python Commands:: Accessing Python from @value{GDBN}.
23210 * Python API:: Accessing @value{GDBN} from Python.
23211 * Python Auto-loading:: Automatically loading Python code.
23212 * Python modules:: Python modules provided by @value{GDBN}.
23213 @end menu
23214
23215 @node Python Commands
23216 @subsection Python Commands
23217 @cindex python commands
23218 @cindex commands to access python
23219
23220 @value{GDBN} provides two commands for accessing the Python interpreter,
23221 and one related setting:
23222
23223 @table @code
23224 @kindex python-interactive
23225 @kindex pi
23226 @item python-interactive @r{[}@var{command}@r{]}
23227 @itemx pi @r{[}@var{command}@r{]}
23228 Without an argument, the @code{python-interactive} command can be used
23229 to start an interactive Python prompt. To return to @value{GDBN},
23230 type the @code{EOF} character (e.g., @kbd{Ctrl-D} on an empty prompt).
23231
23232 Alternatively, a single-line Python command can be given as an
23233 argument and evaluated. If the command is an expression, the result
23234 will be printed; otherwise, nothing will be printed. For example:
23235
23236 @smallexample
23237 (@value{GDBP}) python-interactive 2 + 3
23238 5
23239 @end smallexample
23240
23241 @kindex python
23242 @kindex py
23243 @item python @r{[}@var{command}@r{]}
23244 @itemx py @r{[}@var{command}@r{]}
23245 The @code{python} command can be used to evaluate Python code.
23246
23247 If given an argument, the @code{python} command will evaluate the
23248 argument as a Python command. For example:
23249
23250 @smallexample
23251 (@value{GDBP}) python print 23
23252 23
23253 @end smallexample
23254
23255 If you do not provide an argument to @code{python}, it will act as a
23256 multi-line command, like @code{define}. In this case, the Python
23257 script is made up of subsequent command lines, given after the
23258 @code{python} command. This command list is terminated using a line
23259 containing @code{end}. For example:
23260
23261 @smallexample
23262 (@value{GDBP}) python
23263 Type python script
23264 End with a line saying just "end".
23265 >print 23
23266 >end
23267 23
23268 @end smallexample
23269
23270 @kindex set python print-stack
23271 @item set python print-stack
23272 By default, @value{GDBN} will print only the message component of a
23273 Python exception when an error occurs in a Python script. This can be
23274 controlled using @code{set python print-stack}: if @code{full}, then
23275 full Python stack printing is enabled; if @code{none}, then Python stack
23276 and message printing is disabled; if @code{message}, the default, only
23277 the message component of the error is printed.
23278 @end table
23279
23280 It is also possible to execute a Python script from the @value{GDBN}
23281 interpreter:
23282
23283 @table @code
23284 @item source @file{script-name}
23285 The script name must end with @samp{.py} and @value{GDBN} must be configured
23286 to recognize the script language based on filename extension using
23287 the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
23288
23289 @item python execfile ("script-name")
23290 This method is based on the @code{execfile} Python built-in function,
23291 and thus is always available.
23292 @end table
23293
23294 @node Python API
23295 @subsection Python API
23296 @cindex python api
23297 @cindex programming in python
23298
23299 You can get quick online help for @value{GDBN}'s Python API by issuing
23300 the command @w{@kbd{python help (gdb)}}.
23301
23302 Functions and methods which have two or more optional arguments allow
23303 them to be specified using keyword syntax. This allows passing some
23304 optional arguments while skipping others. Example:
23305 @w{@code{gdb.some_function ('foo', bar = 1, baz = 2)}}.
23306
23307 @menu
23308 * Basic Python:: Basic Python Functions.
23309 * Exception Handling:: How Python exceptions are translated.
23310 * Values From Inferior:: Python representation of values.
23311 * Types In Python:: Python representation of types.
23312 * Pretty Printing API:: Pretty-printing values.
23313 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
23314 * Writing a Pretty-Printer:: Writing a Pretty-Printer.
23315 * Type Printing API:: Pretty-printing types.
23316 * Frame Filter API:: Filtering Frames.
23317 * Frame Decorator API:: Decorating Frames.
23318 * Writing a Frame Filter:: Writing a Frame Filter.
23319 * Inferiors In Python:: Python representation of inferiors (processes)
23320 * Events In Python:: Listening for events from @value{GDBN}.
23321 * Threads In Python:: Accessing inferior threads from Python.
23322 * Commands In Python:: Implementing new commands in Python.
23323 * Parameters In Python:: Adding new @value{GDBN} parameters.
23324 * Functions In Python:: Writing new convenience functions.
23325 * Progspaces In Python:: Program spaces.
23326 * Objfiles In Python:: Object files.
23327 * Frames In Python:: Accessing inferior stack frames from Python.
23328 * Blocks In Python:: Accessing blocks from Python.
23329 * Symbols In Python:: Python representation of symbols.
23330 * Symbol Tables In Python:: Python representation of symbol tables.
23331 * Breakpoints In Python:: Manipulating breakpoints using Python.
23332 * Finish Breakpoints in Python:: Setting Breakpoints on function return
23333 using Python.
23334 * Lazy Strings In Python:: Python representation of lazy strings.
23335 * Architectures In Python:: Python representation of architectures.
23336 @end menu
23337
23338 @node Basic Python
23339 @subsubsection Basic Python
23340
23341 @cindex python stdout
23342 @cindex python pagination
23343 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
23344 @code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
23345 A Python program which outputs to one of these streams may have its
23346 output interrupted by the user (@pxref{Screen Size}). In this
23347 situation, a Python @code{KeyboardInterrupt} exception is thrown.
23348
23349 Some care must be taken when writing Python code to run in
23350 @value{GDBN}. Two things worth noting in particular:
23351
23352 @itemize @bullet
23353 @item
23354 @value{GDBN} install handlers for @code{SIGCHLD} and @code{SIGINT}.
23355 Python code must not override these, or even change the options using
23356 @code{sigaction}. If your program changes the handling of these
23357 signals, @value{GDBN} will most likely stop working correctly. Note
23358 that it is unfortunately common for GUI toolkits to install a
23359 @code{SIGCHLD} handler.
23360
23361 @item
23362 @value{GDBN} takes care to mark its internal file descriptors as
23363 close-on-exec. However, this cannot be done in a thread-safe way on
23364 all platforms. Your Python programs should be aware of this and
23365 should both create new file descriptors with the close-on-exec flag
23366 set and arrange to close unneeded file descriptors before starting a
23367 child process.
23368 @end itemize
23369
23370 @cindex python functions
23371 @cindex python module
23372 @cindex gdb module
23373 @value{GDBN} introduces a new Python module, named @code{gdb}. All
23374 methods and classes added by @value{GDBN} are placed in this module.
23375 @value{GDBN} automatically @code{import}s the @code{gdb} module for
23376 use in all scripts evaluated by the @code{python} command.
23377
23378 @findex gdb.PYTHONDIR
23379 @defvar gdb.PYTHONDIR
23380 A string containing the python directory (@pxref{Python}).
23381 @end defvar
23382
23383 @findex gdb.execute
23384 @defun gdb.execute (command @r{[}, from_tty @r{[}, to_string@r{]]})
23385 Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
23386 If a GDB exception happens while @var{command} runs, it is
23387 translated as described in @ref{Exception Handling,,Exception Handling}.
23388
23389 @var{from_tty} specifies whether @value{GDBN} ought to consider this
23390 command as having originated from the user invoking it interactively.
23391 It must be a boolean value. If omitted, it defaults to @code{False}.
23392
23393 By default, any output produced by @var{command} is sent to
23394 @value{GDBN}'s standard output. If the @var{to_string} parameter is
23395 @code{True}, then output will be collected by @code{gdb.execute} and
23396 returned as a string. The default is @code{False}, in which case the
23397 return value is @code{None}. If @var{to_string} is @code{True}, the
23398 @value{GDBN} virtual terminal will be temporarily set to unlimited width
23399 and height, and its pagination will be disabled; @pxref{Screen Size}.
23400 @end defun
23401
23402 @findex gdb.breakpoints
23403 @defun gdb.breakpoints ()
23404 Return a sequence holding all of @value{GDBN}'s breakpoints.
23405 @xref{Breakpoints In Python}, for more information.
23406 @end defun
23407
23408 @findex gdb.parameter
23409 @defun gdb.parameter (parameter)
23410 Return the value of a @value{GDBN} parameter. @var{parameter} is a
23411 string naming the parameter to look up; @var{parameter} may contain
23412 spaces if the parameter has a multi-part name. For example,
23413 @samp{print object} is a valid parameter name.
23414
23415 If the named parameter does not exist, this function throws a
23416 @code{gdb.error} (@pxref{Exception Handling}). Otherwise, the
23417 parameter's value is converted to a Python value of the appropriate
23418 type, and returned.
23419 @end defun
23420
23421 @findex gdb.history
23422 @defun gdb.history (number)
23423 Return a value from @value{GDBN}'s value history (@pxref{Value
23424 History}). @var{number} indicates which history element to return.
23425 If @var{number} is negative, then @value{GDBN} will take its absolute value
23426 and count backward from the last element (i.e., the most recent element) to
23427 find the value to return. If @var{number} is zero, then @value{GDBN} will
23428 return the most recent element. If the element specified by @var{number}
23429 doesn't exist in the value history, a @code{gdb.error} exception will be
23430 raised.
23431
23432 If no exception is raised, the return value is always an instance of
23433 @code{gdb.Value} (@pxref{Values From Inferior}).
23434 @end defun
23435
23436 @findex gdb.parse_and_eval
23437 @defun gdb.parse_and_eval (expression)
23438 Parse @var{expression} as an expression in the current language,
23439 evaluate it, and return the result as a @code{gdb.Value}.
23440 @var{expression} must be a string.
23441
23442 This function can be useful when implementing a new command
23443 (@pxref{Commands In Python}), as it provides a way to parse the
23444 command's argument as an expression. It is also useful simply to
23445 compute values, for example, it is the only way to get the value of a
23446 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
23447 @end defun
23448
23449 @findex gdb.find_pc_line
23450 @defun gdb.find_pc_line (pc)
23451 Return the @code{gdb.Symtab_and_line} object corresponding to the
23452 @var{pc} value. @xref{Symbol Tables In Python}. If an invalid
23453 value of @var{pc} is passed as an argument, then the @code{symtab} and
23454 @code{line} attributes of the returned @code{gdb.Symtab_and_line} object
23455 will be @code{None} and 0 respectively.
23456 @end defun
23457
23458 @findex gdb.post_event
23459 @defun gdb.post_event (event)
23460 Put @var{event}, a callable object taking no arguments, into
23461 @value{GDBN}'s internal event queue. This callable will be invoked at
23462 some later point, during @value{GDBN}'s event processing. Events
23463 posted using @code{post_event} will be run in the order in which they
23464 were posted; however, there is no way to know when they will be
23465 processed relative to other events inside @value{GDBN}.
23466
23467 @value{GDBN} is not thread-safe. If your Python program uses multiple
23468 threads, you must be careful to only call @value{GDBN}-specific
23469 functions in the main @value{GDBN} thread. @code{post_event} ensures
23470 this. For example:
23471
23472 @smallexample
23473 (@value{GDBP}) python
23474 >import threading
23475 >
23476 >class Writer():
23477 > def __init__(self, message):
23478 > self.message = message;
23479 > def __call__(self):
23480 > gdb.write(self.message)
23481 >
23482 >class MyThread1 (threading.Thread):
23483 > def run (self):
23484 > gdb.post_event(Writer("Hello "))
23485 >
23486 >class MyThread2 (threading.Thread):
23487 > def run (self):
23488 > gdb.post_event(Writer("World\n"))
23489 >
23490 >MyThread1().start()
23491 >MyThread2().start()
23492 >end
23493 (@value{GDBP}) Hello World
23494 @end smallexample
23495 @end defun
23496
23497 @findex gdb.write
23498 @defun gdb.write (string @r{[}, stream{]})
23499 Print a string to @value{GDBN}'s paginated output stream. The
23500 optional @var{stream} determines the stream to print to. The default
23501 stream is @value{GDBN}'s standard output stream. Possible stream
23502 values are:
23503
23504 @table @code
23505 @findex STDOUT
23506 @findex gdb.STDOUT
23507 @item gdb.STDOUT
23508 @value{GDBN}'s standard output stream.
23509
23510 @findex STDERR
23511 @findex gdb.STDERR
23512 @item gdb.STDERR
23513 @value{GDBN}'s standard error stream.
23514
23515 @findex STDLOG
23516 @findex gdb.STDLOG
23517 @item gdb.STDLOG
23518 @value{GDBN}'s log stream (@pxref{Logging Output}).
23519 @end table
23520
23521 Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
23522 call this function and will automatically direct the output to the
23523 relevant stream.
23524 @end defun
23525
23526 @findex gdb.flush
23527 @defun gdb.flush ()
23528 Flush the buffer of a @value{GDBN} paginated stream so that the
23529 contents are displayed immediately. @value{GDBN} will flush the
23530 contents of a stream automatically when it encounters a newline in the
23531 buffer. The optional @var{stream} determines the stream to flush. The
23532 default stream is @value{GDBN}'s standard output stream. Possible
23533 stream values are:
23534
23535 @table @code
23536 @findex STDOUT
23537 @findex gdb.STDOUT
23538 @item gdb.STDOUT
23539 @value{GDBN}'s standard output stream.
23540
23541 @findex STDERR
23542 @findex gdb.STDERR
23543 @item gdb.STDERR
23544 @value{GDBN}'s standard error stream.
23545
23546 @findex STDLOG
23547 @findex gdb.STDLOG
23548 @item gdb.STDLOG
23549 @value{GDBN}'s log stream (@pxref{Logging Output}).
23550
23551 @end table
23552
23553 Flushing @code{sys.stdout} or @code{sys.stderr} will automatically
23554 call this function for the relevant stream.
23555 @end defun
23556
23557 @findex gdb.target_charset
23558 @defun gdb.target_charset ()
23559 Return the name of the current target character set (@pxref{Character
23560 Sets}). This differs from @code{gdb.parameter('target-charset')} in
23561 that @samp{auto} is never returned.
23562 @end defun
23563
23564 @findex gdb.target_wide_charset
23565 @defun gdb.target_wide_charset ()
23566 Return the name of the current target wide character set
23567 (@pxref{Character Sets}). This differs from
23568 @code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
23569 never returned.
23570 @end defun
23571
23572 @findex gdb.solib_name
23573 @defun gdb.solib_name (address)
23574 Return the name of the shared library holding the given @var{address}
23575 as a string, or @code{None}.
23576 @end defun
23577
23578 @findex gdb.decode_line
23579 @defun gdb.decode_line @r{[}expression@r{]}
23580 Return locations of the line specified by @var{expression}, or of the
23581 current line if no argument was given. This function returns a Python
23582 tuple containing two elements. The first element contains a string
23583 holding any unparsed section of @var{expression} (or @code{None} if
23584 the expression has been fully parsed). The second element contains
23585 either @code{None} or another tuple that contains all the locations
23586 that match the expression represented as @code{gdb.Symtab_and_line}
23587 objects (@pxref{Symbol Tables In Python}). If @var{expression} is
23588 provided, it is decoded the way that @value{GDBN}'s inbuilt
23589 @code{break} or @code{edit} commands do (@pxref{Specify Location}).
23590 @end defun
23591
23592 @defun gdb.prompt_hook (current_prompt)
23593 @anchor{prompt_hook}
23594
23595 If @var{prompt_hook} is callable, @value{GDBN} will call the method
23596 assigned to this operation before a prompt is displayed by
23597 @value{GDBN}.
23598
23599 The parameter @code{current_prompt} contains the current @value{GDBN}
23600 prompt. This method must return a Python string, or @code{None}. If
23601 a string is returned, the @value{GDBN} prompt will be set to that
23602 string. If @code{None} is returned, @value{GDBN} will continue to use
23603 the current prompt.
23604
23605 Some prompts cannot be substituted in @value{GDBN}. Secondary prompts
23606 such as those used by readline for command input, and annotation
23607 related prompts are prohibited from being changed.
23608 @end defun
23609
23610 @node Exception Handling
23611 @subsubsection Exception Handling
23612 @cindex python exceptions
23613 @cindex exceptions, python
23614
23615 When executing the @code{python} command, Python exceptions
23616 uncaught within the Python code are translated to calls to
23617 @value{GDBN} error-reporting mechanism. If the command that called
23618 @code{python} does not handle the error, @value{GDBN} will
23619 terminate it and print an error message containing the Python
23620 exception name, the associated value, and the Python call stack
23621 backtrace at the point where the exception was raised. Example:
23622
23623 @smallexample
23624 (@value{GDBP}) python print foo
23625 Traceback (most recent call last):
23626 File "<string>", line 1, in <module>
23627 NameError: name 'foo' is not defined
23628 @end smallexample
23629
23630 @value{GDBN} errors that happen in @value{GDBN} commands invoked by
23631 Python code are converted to Python exceptions. The type of the
23632 Python exception depends on the error.
23633
23634 @ftable @code
23635 @item gdb.error
23636 This is the base class for most exceptions generated by @value{GDBN}.
23637 It is derived from @code{RuntimeError}, for compatibility with earlier
23638 versions of @value{GDBN}.
23639
23640 If an error occurring in @value{GDBN} does not fit into some more
23641 specific category, then the generated exception will have this type.
23642
23643 @item gdb.MemoryError
23644 This is a subclass of @code{gdb.error} which is thrown when an
23645 operation tried to access invalid memory in the inferior.
23646
23647 @item KeyboardInterrupt
23648 User interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
23649 prompt) is translated to a Python @code{KeyboardInterrupt} exception.
23650 @end ftable
23651
23652 In all cases, your exception handler will see the @value{GDBN} error
23653 message as its value and the Python call stack backtrace at the Python
23654 statement closest to where the @value{GDBN} error occured as the
23655 traceback.
23656
23657 @findex gdb.GdbError
23658 When implementing @value{GDBN} commands in Python via @code{gdb.Command},
23659 it is useful to be able to throw an exception that doesn't cause a
23660 traceback to be printed. For example, the user may have invoked the
23661 command incorrectly. Use the @code{gdb.GdbError} exception
23662 to handle this case. Example:
23663
23664 @smallexample
23665 (gdb) python
23666 >class HelloWorld (gdb.Command):
23667 > """Greet the whole world."""
23668 > def __init__ (self):
23669 > super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
23670 > def invoke (self, args, from_tty):
23671 > argv = gdb.string_to_argv (args)
23672 > if len (argv) != 0:
23673 > raise gdb.GdbError ("hello-world takes no arguments")
23674 > print "Hello, World!"
23675 >HelloWorld ()
23676 >end
23677 (gdb) hello-world 42
23678 hello-world takes no arguments
23679 @end smallexample
23680
23681 @node Values From Inferior
23682 @subsubsection Values From Inferior
23683 @cindex values from inferior, with Python
23684 @cindex python, working with values from inferior
23685
23686 @cindex @code{gdb.Value}
23687 @value{GDBN} provides values it obtains from the inferior program in
23688 an object of type @code{gdb.Value}. @value{GDBN} uses this object
23689 for its internal bookkeeping of the inferior's values, and for
23690 fetching values when necessary.
23691
23692 Inferior values that are simple scalars can be used directly in
23693 Python expressions that are valid for the value's data type. Here's
23694 an example for an integer or floating-point value @code{some_val}:
23695
23696 @smallexample
23697 bar = some_val + 2
23698 @end smallexample
23699
23700 @noindent
23701 As result of this, @code{bar} will also be a @code{gdb.Value} object
23702 whose values are of the same type as those of @code{some_val}.
23703
23704 Inferior values that are structures or instances of some class can
23705 be accessed using the Python @dfn{dictionary syntax}. For example, if
23706 @code{some_val} is a @code{gdb.Value} instance holding a structure, you
23707 can access its @code{foo} element with:
23708
23709 @smallexample
23710 bar = some_val['foo']
23711 @end smallexample
23712
23713 Again, @code{bar} will also be a @code{gdb.Value} object.
23714
23715 A @code{gdb.Value} that represents a function can be executed via
23716 inferior function call. Any arguments provided to the call must match
23717 the function's prototype, and must be provided in the order specified
23718 by that prototype.
23719
23720 For example, @code{some_val} is a @code{gdb.Value} instance
23721 representing a function that takes two integers as arguments. To
23722 execute this function, call it like so:
23723
23724 @smallexample
23725 result = some_val (10,20)
23726 @end smallexample
23727
23728 Any values returned from a function call will be stored as a
23729 @code{gdb.Value}.
23730
23731 The following attributes are provided:
23732
23733 @defvar Value.address
23734 If this object is addressable, this read-only attribute holds a
23735 @code{gdb.Value} object representing the address. Otherwise,
23736 this attribute holds @code{None}.
23737 @end defvar
23738
23739 @cindex optimized out value in Python
23740 @defvar Value.is_optimized_out
23741 This read-only boolean attribute is true if the compiler optimized out
23742 this value, thus it is not available for fetching from the inferior.
23743 @end defvar
23744
23745 @defvar Value.type
23746 The type of this @code{gdb.Value}. The value of this attribute is a
23747 @code{gdb.Type} object (@pxref{Types In Python}).
23748 @end defvar
23749
23750 @defvar Value.dynamic_type
23751 The dynamic type of this @code{gdb.Value}. This uses C@t{++} run-time
23752 type information (@acronym{RTTI}) to determine the dynamic type of the
23753 value. If this value is of class type, it will return the class in
23754 which the value is embedded, if any. If this value is of pointer or
23755 reference to a class type, it will compute the dynamic type of the
23756 referenced object, and return a pointer or reference to that type,
23757 respectively. In all other cases, it will return the value's static
23758 type.
23759
23760 Note that this feature will only work when debugging a C@t{++} program
23761 that includes @acronym{RTTI} for the object in question. Otherwise,
23762 it will just return the static type of the value as in @kbd{ptype foo}
23763 (@pxref{Symbols, ptype}).
23764 @end defvar
23765
23766 @defvar Value.is_lazy
23767 The value of this read-only boolean attribute is @code{True} if this
23768 @code{gdb.Value} has not yet been fetched from the inferior.
23769 @value{GDBN} does not fetch values until necessary, for efficiency.
23770 For example:
23771
23772 @smallexample
23773 myval = gdb.parse_and_eval ('somevar')
23774 @end smallexample
23775
23776 The value of @code{somevar} is not fetched at this time. It will be
23777 fetched when the value is needed, or when the @code{fetch_lazy}
23778 method is invoked.
23779 @end defvar
23780
23781 The following methods are provided:
23782
23783 @defun Value.__init__ (@var{val})
23784 Many Python values can be converted directly to a @code{gdb.Value} via
23785 this object initializer. Specifically:
23786
23787 @table @asis
23788 @item Python boolean
23789 A Python boolean is converted to the boolean type from the current
23790 language.
23791
23792 @item Python integer
23793 A Python integer is converted to the C @code{long} type for the
23794 current architecture.
23795
23796 @item Python long
23797 A Python long is converted to the C @code{long long} type for the
23798 current architecture.
23799
23800 @item Python float
23801 A Python float is converted to the C @code{double} type for the
23802 current architecture.
23803
23804 @item Python string
23805 A Python string is converted to a target string, using the current
23806 target encoding.
23807
23808 @item @code{gdb.Value}
23809 If @code{val} is a @code{gdb.Value}, then a copy of the value is made.
23810
23811 @item @code{gdb.LazyString}
23812 If @code{val} is a @code{gdb.LazyString} (@pxref{Lazy Strings In
23813 Python}), then the lazy string's @code{value} method is called, and
23814 its result is used.
23815 @end table
23816 @end defun
23817
23818 @defun Value.cast (type)
23819 Return a new instance of @code{gdb.Value} that is the result of
23820 casting this instance to the type described by @var{type}, which must
23821 be a @code{gdb.Type} object. If the cast cannot be performed for some
23822 reason, this method throws an exception.
23823 @end defun
23824
23825 @defun Value.dereference ()
23826 For pointer data types, this method returns a new @code{gdb.Value} object
23827 whose contents is the object pointed to by the pointer. For example, if
23828 @code{foo} is a C pointer to an @code{int}, declared in your C program as
23829
23830 @smallexample
23831 int *foo;
23832 @end smallexample
23833
23834 @noindent
23835 then you can use the corresponding @code{gdb.Value} to access what
23836 @code{foo} points to like this:
23837
23838 @smallexample
23839 bar = foo.dereference ()
23840 @end smallexample
23841
23842 The result @code{bar} will be a @code{gdb.Value} object holding the
23843 value pointed to by @code{foo}.
23844
23845 A similar function @code{Value.referenced_value} exists which also
23846 returns @code{gdb.Value} objects corresonding to the values pointed to
23847 by pointer values (and additionally, values referenced by reference
23848 values). However, the behavior of @code{Value.dereference}
23849 differs from @code{Value.referenced_value} by the fact that the
23850 behavior of @code{Value.dereference} is identical to applying the C
23851 unary operator @code{*} on a given value. For example, consider a
23852 reference to a pointer @code{ptrref}, declared in your C@t{++} program
23853 as
23854
23855 @smallexample
23856 typedef int *intptr;
23857 ...
23858 int val = 10;
23859 intptr ptr = &val;
23860 intptr &ptrref = ptr;
23861 @end smallexample
23862
23863 Though @code{ptrref} is a reference value, one can apply the method
23864 @code{Value.dereference} to the @code{gdb.Value} object corresponding
23865 to it and obtain a @code{gdb.Value} which is identical to that
23866 corresponding to @code{val}. However, if you apply the method
23867 @code{Value.referenced_value}, the result would be a @code{gdb.Value}
23868 object identical to that corresponding to @code{ptr}.
23869
23870 @smallexample
23871 py_ptrref = gdb.parse_and_eval ("ptrref")
23872 py_val = py_ptrref.dereference ()
23873 py_ptr = py_ptrref.referenced_value ()
23874 @end smallexample
23875
23876 The @code{gdb.Value} object @code{py_val} is identical to that
23877 corresponding to @code{val}, and @code{py_ptr} is identical to that
23878 corresponding to @code{ptr}. In general, @code{Value.dereference} can
23879 be applied whenever the C unary operator @code{*} can be applied
23880 to the corresponding C value. For those cases where applying both
23881 @code{Value.dereference} and @code{Value.referenced_value} is allowed,
23882 the results obtained need not be identical (as we have seen in the above
23883 example). The results are however identical when applied on
23884 @code{gdb.Value} objects corresponding to pointers (@code{gdb.Value}
23885 objects with type code @code{TYPE_CODE_PTR}) in a C/C@t{++} program.
23886 @end defun
23887
23888 @defun Value.referenced_value ()
23889 For pointer or reference data types, this method returns a new
23890 @code{gdb.Value} object corresponding to the value referenced by the
23891 pointer/reference value. For pointer data types,
23892 @code{Value.dereference} and @code{Value.referenced_value} produce
23893 identical results. The difference between these methods is that
23894 @code{Value.dereference} cannot get the values referenced by reference
23895 values. For example, consider a reference to an @code{int}, declared
23896 in your C@t{++} program as
23897
23898 @smallexample
23899 int val = 10;
23900 int &ref = val;
23901 @end smallexample
23902
23903 @noindent
23904 then applying @code{Value.dereference} to the @code{gdb.Value} object
23905 corresponding to @code{ref} will result in an error, while applying
23906 @code{Value.referenced_value} will result in a @code{gdb.Value} object
23907 identical to that corresponding to @code{val}.
23908
23909 @smallexample
23910 py_ref = gdb.parse_and_eval ("ref")
23911 er_ref = py_ref.dereference () # Results in error
23912 py_val = py_ref.referenced_value () # Returns the referenced value
23913 @end smallexample
23914
23915 The @code{gdb.Value} object @code{py_val} is identical to that
23916 corresponding to @code{val}.
23917 @end defun
23918
23919 @defun Value.dynamic_cast (type)
23920 Like @code{Value.cast}, but works as if the C@t{++} @code{dynamic_cast}
23921 operator were used. Consult a C@t{++} reference for details.
23922 @end defun
23923
23924 @defun Value.reinterpret_cast (type)
23925 Like @code{Value.cast}, but works as if the C@t{++} @code{reinterpret_cast}
23926 operator were used. Consult a C@t{++} reference for details.
23927 @end defun
23928
23929 @defun Value.string (@r{[}encoding@r{[}, errors@r{[}, length@r{]]]})
23930 If this @code{gdb.Value} represents a string, then this method
23931 converts the contents to a Python string. Otherwise, this method will
23932 throw an exception.
23933
23934 Strings are recognized in a language-specific way; whether a given
23935 @code{gdb.Value} represents a string is determined by the current
23936 language.
23937
23938 For C-like languages, a value is a string if it is a pointer to or an
23939 array of characters or ints. The string is assumed to be terminated
23940 by a zero of the appropriate width. However if the optional length
23941 argument is given, the string will be converted to that given length,
23942 ignoring any embedded zeros that the string may contain.
23943
23944 If the optional @var{encoding} argument is given, it must be a string
23945 naming the encoding of the string in the @code{gdb.Value}, such as
23946 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
23947 the same encodings as the corresponding argument to Python's
23948 @code{string.decode} method, and the Python codec machinery will be used
23949 to convert the string. If @var{encoding} is not given, or if
23950 @var{encoding} is the empty string, then either the @code{target-charset}
23951 (@pxref{Character Sets}) will be used, or a language-specific encoding
23952 will be used, if the current language is able to supply one.
23953
23954 The optional @var{errors} argument is the same as the corresponding
23955 argument to Python's @code{string.decode} method.
23956
23957 If the optional @var{length} argument is given, the string will be
23958 fetched and converted to the given length.
23959 @end defun
23960
23961 @defun Value.lazy_string (@r{[}encoding @r{[}, length@r{]]})
23962 If this @code{gdb.Value} represents a string, then this method
23963 converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
23964 In Python}). Otherwise, this method will throw an exception.
23965
23966 If the optional @var{encoding} argument is given, it must be a string
23967 naming the encoding of the @code{gdb.LazyString}. Some examples are:
23968 @samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
23969 @var{encoding} argument is an encoding that @value{GDBN} does
23970 recognize, @value{GDBN} will raise an error.
23971
23972 When a lazy string is printed, the @value{GDBN} encoding machinery is
23973 used to convert the string during printing. If the optional
23974 @var{encoding} argument is not provided, or is an empty string,
23975 @value{GDBN} will automatically select the encoding most suitable for
23976 the string type. For further information on encoding in @value{GDBN}
23977 please see @ref{Character Sets}.
23978
23979 If the optional @var{length} argument is given, the string will be
23980 fetched and encoded to the length of characters specified. If
23981 the @var{length} argument is not provided, the string will be fetched
23982 and encoded until a null of appropriate width is found.
23983 @end defun
23984
23985 @defun Value.fetch_lazy ()
23986 If the @code{gdb.Value} object is currently a lazy value
23987 (@code{gdb.Value.is_lazy} is @code{True}), then the value is
23988 fetched from the inferior. Any errors that occur in the process
23989 will produce a Python exception.
23990
23991 If the @code{gdb.Value} object is not a lazy value, this method
23992 has no effect.
23993
23994 This method does not return a value.
23995 @end defun
23996
23997
23998 @node Types In Python
23999 @subsubsection Types In Python
24000 @cindex types in Python
24001 @cindex Python, working with types
24002
24003 @tindex gdb.Type
24004 @value{GDBN} represents types from the inferior using the class
24005 @code{gdb.Type}.
24006
24007 The following type-related functions are available in the @code{gdb}
24008 module:
24009
24010 @findex gdb.lookup_type
24011 @defun gdb.lookup_type (name @r{[}, block@r{]})
24012 This function looks up a type by name. @var{name} is the name of the
24013 type to look up. It must be a string.
24014
24015 If @var{block} is given, then @var{name} is looked up in that scope.
24016 Otherwise, it is searched for globally.
24017
24018 Ordinarily, this function will return an instance of @code{gdb.Type}.
24019 If the named type cannot be found, it will throw an exception.
24020 @end defun
24021
24022 If the type is a structure or class type, or an enum type, the fields
24023 of that type can be accessed using the Python @dfn{dictionary syntax}.
24024 For example, if @code{some_type} is a @code{gdb.Type} instance holding
24025 a structure type, you can access its @code{foo} field with:
24026
24027 @smallexample
24028 bar = some_type['foo']
24029 @end smallexample
24030
24031 @code{bar} will be a @code{gdb.Field} object; see below under the
24032 description of the @code{Type.fields} method for a description of the
24033 @code{gdb.Field} class.
24034
24035 An instance of @code{Type} has the following attributes:
24036
24037 @defvar Type.code
24038 The type code for this type. The type code will be one of the
24039 @code{TYPE_CODE_} constants defined below.
24040 @end defvar
24041
24042 @defvar Type.sizeof
24043 The size of this type, in target @code{char} units. Usually, a
24044 target's @code{char} type will be an 8-bit byte. However, on some
24045 unusual platforms, this type may have a different size.
24046 @end defvar
24047
24048 @defvar Type.tag
24049 The tag name for this type. The tag name is the name after
24050 @code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
24051 languages have this concept. If this type has no tag name, then
24052 @code{None} is returned.
24053 @end defvar
24054
24055 The following methods are provided:
24056
24057 @defun Type.fields ()
24058 For structure and union types, this method returns the fields. Range
24059 types have two fields, the minimum and maximum values. Enum types
24060 have one field per enum constant. Function and method types have one
24061 field per parameter. The base types of C@t{++} classes are also
24062 represented as fields. If the type has no fields, or does not fit
24063 into one of these categories, an empty sequence will be returned.
24064
24065 Each field is a @code{gdb.Field} object, with some pre-defined attributes:
24066 @table @code
24067 @item bitpos
24068 This attribute is not available for @code{static} fields (as in
24069 C@t{++} or Java). For non-@code{static} fields, the value is the bit
24070 position of the field. For @code{enum} fields, the value is the
24071 enumeration member's integer representation.
24072
24073 @item name
24074 The name of the field, or @code{None} for anonymous fields.
24075
24076 @item artificial
24077 This is @code{True} if the field is artificial, usually meaning that
24078 it was provided by the compiler and not the user. This attribute is
24079 always provided, and is @code{False} if the field is not artificial.
24080
24081 @item is_base_class
24082 This is @code{True} if the field represents a base class of a C@t{++}
24083 structure. This attribute is always provided, and is @code{False}
24084 if the field is not a base class of the type that is the argument of
24085 @code{fields}, or if that type was not a C@t{++} class.
24086
24087 @item bitsize
24088 If the field is packed, or is a bitfield, then this will have a
24089 non-zero value, which is the size of the field in bits. Otherwise,
24090 this will be zero; in this case the field's size is given by its type.
24091
24092 @item type
24093 The type of the field. This is usually an instance of @code{Type},
24094 but it can be @code{None} in some situations.
24095 @end table
24096 @end defun
24097
24098 @defun Type.array (@var{n1} @r{[}, @var{n2}@r{]})
24099 Return a new @code{gdb.Type} object which represents an array of this
24100 type. If one argument is given, it is the inclusive upper bound of
24101 the array; in this case the lower bound is zero. If two arguments are
24102 given, the first argument is the lower bound of the array, and the
24103 second argument is the upper bound of the array. An array's length
24104 must not be negative, but the bounds can be.
24105 @end defun
24106
24107 @defun Type.vector (@var{n1} @r{[}, @var{n2}@r{]})
24108 Return a new @code{gdb.Type} object which represents a vector of this
24109 type. If one argument is given, it is the inclusive upper bound of
24110 the vector; in this case the lower bound is zero. If two arguments are
24111 given, the first argument is the lower bound of the vector, and the
24112 second argument is the upper bound of the vector. A vector's length
24113 must not be negative, but the bounds can be.
24114
24115 The difference between an @code{array} and a @code{vector} is that
24116 arrays behave like in C: when used in expressions they decay to a pointer
24117 to the first element whereas vectors are treated as first class values.
24118 @end defun
24119
24120 @defun Type.const ()
24121 Return a new @code{gdb.Type} object which represents a
24122 @code{const}-qualified variant of this type.
24123 @end defun
24124
24125 @defun Type.volatile ()
24126 Return a new @code{gdb.Type} object which represents a
24127 @code{volatile}-qualified variant of this type.
24128 @end defun
24129
24130 @defun Type.unqualified ()
24131 Return a new @code{gdb.Type} object which represents an unqualified
24132 variant of this type. That is, the result is neither @code{const} nor
24133 @code{volatile}.
24134 @end defun
24135
24136 @defun Type.range ()
24137 Return a Python @code{Tuple} object that contains two elements: the
24138 low bound of the argument type and the high bound of that type. If
24139 the type does not have a range, @value{GDBN} will raise a
24140 @code{gdb.error} exception (@pxref{Exception Handling}).
24141 @end defun
24142
24143 @defun Type.reference ()
24144 Return a new @code{gdb.Type} object which represents a reference to this
24145 type.
24146 @end defun
24147
24148 @defun Type.pointer ()
24149 Return a new @code{gdb.Type} object which represents a pointer to this
24150 type.
24151 @end defun
24152
24153 @defun Type.strip_typedefs ()
24154 Return a new @code{gdb.Type} that represents the real type,
24155 after removing all layers of typedefs.
24156 @end defun
24157
24158 @defun Type.target ()
24159 Return a new @code{gdb.Type} object which represents the target type
24160 of this type.
24161
24162 For a pointer type, the target type is the type of the pointed-to
24163 object. For an array type (meaning C-like arrays), the target type is
24164 the type of the elements of the array. For a function or method type,
24165 the target type is the type of the return value. For a complex type,
24166 the target type is the type of the elements. For a typedef, the
24167 target type is the aliased type.
24168
24169 If the type does not have a target, this method will throw an
24170 exception.
24171 @end defun
24172
24173 @defun Type.template_argument (n @r{[}, block@r{]})
24174 If this @code{gdb.Type} is an instantiation of a template, this will
24175 return a new @code{gdb.Type} which represents the type of the
24176 @var{n}th template argument.
24177
24178 If this @code{gdb.Type} is not a template type, this will throw an
24179 exception. Ordinarily, only C@t{++} code will have template types.
24180
24181 If @var{block} is given, then @var{name} is looked up in that scope.
24182 Otherwise, it is searched for globally.
24183 @end defun
24184
24185
24186 Each type has a code, which indicates what category this type falls
24187 into. The available type categories are represented by constants
24188 defined in the @code{gdb} module:
24189
24190 @table @code
24191 @findex TYPE_CODE_PTR
24192 @findex gdb.TYPE_CODE_PTR
24193 @item gdb.TYPE_CODE_PTR
24194 The type is a pointer.
24195
24196 @findex TYPE_CODE_ARRAY
24197 @findex gdb.TYPE_CODE_ARRAY
24198 @item gdb.TYPE_CODE_ARRAY
24199 The type is an array.
24200
24201 @findex TYPE_CODE_STRUCT
24202 @findex gdb.TYPE_CODE_STRUCT
24203 @item gdb.TYPE_CODE_STRUCT
24204 The type is a structure.
24205
24206 @findex TYPE_CODE_UNION
24207 @findex gdb.TYPE_CODE_UNION
24208 @item gdb.TYPE_CODE_UNION
24209 The type is a union.
24210
24211 @findex TYPE_CODE_ENUM
24212 @findex gdb.TYPE_CODE_ENUM
24213 @item gdb.TYPE_CODE_ENUM
24214 The type is an enum.
24215
24216 @findex TYPE_CODE_FLAGS
24217 @findex gdb.TYPE_CODE_FLAGS
24218 @item gdb.TYPE_CODE_FLAGS
24219 A bit flags type, used for things such as status registers.
24220
24221 @findex TYPE_CODE_FUNC
24222 @findex gdb.TYPE_CODE_FUNC
24223 @item gdb.TYPE_CODE_FUNC
24224 The type is a function.
24225
24226 @findex TYPE_CODE_INT
24227 @findex gdb.TYPE_CODE_INT
24228 @item gdb.TYPE_CODE_INT
24229 The type is an integer type.
24230
24231 @findex TYPE_CODE_FLT
24232 @findex gdb.TYPE_CODE_FLT
24233 @item gdb.TYPE_CODE_FLT
24234 A floating point type.
24235
24236 @findex TYPE_CODE_VOID
24237 @findex gdb.TYPE_CODE_VOID
24238 @item gdb.TYPE_CODE_VOID
24239 The special type @code{void}.
24240
24241 @findex TYPE_CODE_SET
24242 @findex gdb.TYPE_CODE_SET
24243 @item gdb.TYPE_CODE_SET
24244 A Pascal set type.
24245
24246 @findex TYPE_CODE_RANGE
24247 @findex gdb.TYPE_CODE_RANGE
24248 @item gdb.TYPE_CODE_RANGE
24249 A range type, that is, an integer type with bounds.
24250
24251 @findex TYPE_CODE_STRING
24252 @findex gdb.TYPE_CODE_STRING
24253 @item gdb.TYPE_CODE_STRING
24254 A string type. Note that this is only used for certain languages with
24255 language-defined string types; C strings are not represented this way.
24256
24257 @findex TYPE_CODE_BITSTRING
24258 @findex gdb.TYPE_CODE_BITSTRING
24259 @item gdb.TYPE_CODE_BITSTRING
24260 A string of bits. It is deprecated.
24261
24262 @findex TYPE_CODE_ERROR
24263 @findex gdb.TYPE_CODE_ERROR
24264 @item gdb.TYPE_CODE_ERROR
24265 An unknown or erroneous type.
24266
24267 @findex TYPE_CODE_METHOD
24268 @findex gdb.TYPE_CODE_METHOD
24269 @item gdb.TYPE_CODE_METHOD
24270 A method type, as found in C@t{++} or Java.
24271
24272 @findex TYPE_CODE_METHODPTR
24273 @findex gdb.TYPE_CODE_METHODPTR
24274 @item gdb.TYPE_CODE_METHODPTR
24275 A pointer-to-member-function.
24276
24277 @findex TYPE_CODE_MEMBERPTR
24278 @findex gdb.TYPE_CODE_MEMBERPTR
24279 @item gdb.TYPE_CODE_MEMBERPTR
24280 A pointer-to-member.
24281
24282 @findex TYPE_CODE_REF
24283 @findex gdb.TYPE_CODE_REF
24284 @item gdb.TYPE_CODE_REF
24285 A reference type.
24286
24287 @findex TYPE_CODE_CHAR
24288 @findex gdb.TYPE_CODE_CHAR
24289 @item gdb.TYPE_CODE_CHAR
24290 A character type.
24291
24292 @findex TYPE_CODE_BOOL
24293 @findex gdb.TYPE_CODE_BOOL
24294 @item gdb.TYPE_CODE_BOOL
24295 A boolean type.
24296
24297 @findex TYPE_CODE_COMPLEX
24298 @findex gdb.TYPE_CODE_COMPLEX
24299 @item gdb.TYPE_CODE_COMPLEX
24300 A complex float type.
24301
24302 @findex TYPE_CODE_TYPEDEF
24303 @findex gdb.TYPE_CODE_TYPEDEF
24304 @item gdb.TYPE_CODE_TYPEDEF
24305 A typedef to some other type.
24306
24307 @findex TYPE_CODE_NAMESPACE
24308 @findex gdb.TYPE_CODE_NAMESPACE
24309 @item gdb.TYPE_CODE_NAMESPACE
24310 A C@t{++} namespace.
24311
24312 @findex TYPE_CODE_DECFLOAT
24313 @findex gdb.TYPE_CODE_DECFLOAT
24314 @item gdb.TYPE_CODE_DECFLOAT
24315 A decimal floating point type.
24316
24317 @findex TYPE_CODE_INTERNAL_FUNCTION
24318 @findex gdb.TYPE_CODE_INTERNAL_FUNCTION
24319 @item gdb.TYPE_CODE_INTERNAL_FUNCTION
24320 A function internal to @value{GDBN}. This is the type used to represent
24321 convenience functions.
24322 @end table
24323
24324 Further support for types is provided in the @code{gdb.types}
24325 Python module (@pxref{gdb.types}).
24326
24327 @node Pretty Printing API
24328 @subsubsection Pretty Printing API
24329
24330 An example output is provided (@pxref{Pretty Printing}).
24331
24332 A pretty-printer is just an object that holds a value and implements a
24333 specific interface, defined here.
24334
24335 @defun pretty_printer.children (self)
24336 @value{GDBN} will call this method on a pretty-printer to compute the
24337 children of the pretty-printer's value.
24338
24339 This method must return an object conforming to the Python iterator
24340 protocol. Each item returned by the iterator must be a tuple holding
24341 two elements. The first element is the ``name'' of the child; the
24342 second element is the child's value. The value can be any Python
24343 object which is convertible to a @value{GDBN} value.
24344
24345 This method is optional. If it does not exist, @value{GDBN} will act
24346 as though the value has no children.
24347 @end defun
24348
24349 @defun pretty_printer.display_hint (self)
24350 The CLI may call this method and use its result to change the
24351 formatting of a value. The result will also be supplied to an MI
24352 consumer as a @samp{displayhint} attribute of the variable being
24353 printed.
24354
24355 This method is optional. If it does exist, this method must return a
24356 string.
24357
24358 Some display hints are predefined by @value{GDBN}:
24359
24360 @table @samp
24361 @item array
24362 Indicate that the object being printed is ``array-like''. The CLI
24363 uses this to respect parameters such as @code{set print elements} and
24364 @code{set print array}.
24365
24366 @item map
24367 Indicate that the object being printed is ``map-like'', and that the
24368 children of this value can be assumed to alternate between keys and
24369 values.
24370
24371 @item string
24372 Indicate that the object being printed is ``string-like''. If the
24373 printer's @code{to_string} method returns a Python string of some
24374 kind, then @value{GDBN} will call its internal language-specific
24375 string-printing function to format the string. For the CLI this means
24376 adding quotation marks, possibly escaping some characters, respecting
24377 @code{set print elements}, and the like.
24378 @end table
24379 @end defun
24380
24381 @defun pretty_printer.to_string (self)
24382 @value{GDBN} will call this method to display the string
24383 representation of the value passed to the object's constructor.
24384
24385 When printing from the CLI, if the @code{to_string} method exists,
24386 then @value{GDBN} will prepend its result to the values returned by
24387 @code{children}. Exactly how this formatting is done is dependent on
24388 the display hint, and may change as more hints are added. Also,
24389 depending on the print settings (@pxref{Print Settings}), the CLI may
24390 print just the result of @code{to_string} in a stack trace, omitting
24391 the result of @code{children}.
24392
24393 If this method returns a string, it is printed verbatim.
24394
24395 Otherwise, if this method returns an instance of @code{gdb.Value},
24396 then @value{GDBN} prints this value. This may result in a call to
24397 another pretty-printer.
24398
24399 If instead the method returns a Python value which is convertible to a
24400 @code{gdb.Value}, then @value{GDBN} performs the conversion and prints
24401 the resulting value. Again, this may result in a call to another
24402 pretty-printer. Python scalars (integers, floats, and booleans) and
24403 strings are convertible to @code{gdb.Value}; other types are not.
24404
24405 Finally, if this method returns @code{None} then no further operations
24406 are peformed in this method and nothing is printed.
24407
24408 If the result is not one of these types, an exception is raised.
24409 @end defun
24410
24411 @value{GDBN} provides a function which can be used to look up the
24412 default pretty-printer for a @code{gdb.Value}:
24413
24414 @findex gdb.default_visualizer
24415 @defun gdb.default_visualizer (value)
24416 This function takes a @code{gdb.Value} object as an argument. If a
24417 pretty-printer for this value exists, then it is returned. If no such
24418 printer exists, then this returns @code{None}.
24419 @end defun
24420
24421 @node Selecting Pretty-Printers
24422 @subsubsection Selecting Pretty-Printers
24423
24424 The Python list @code{gdb.pretty_printers} contains an array of
24425 functions or callable objects that have been registered via addition
24426 as a pretty-printer. Printers in this list are called @code{global}
24427 printers, they're available when debugging all inferiors.
24428 Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
24429 Each @code{gdb.Objfile} also contains a @code{pretty_printers}
24430 attribute.
24431
24432 Each function on these lists is passed a single @code{gdb.Value}
24433 argument and should return a pretty-printer object conforming to the
24434 interface definition above (@pxref{Pretty Printing API}). If a function
24435 cannot create a pretty-printer for the value, it should return
24436 @code{None}.
24437
24438 @value{GDBN} first checks the @code{pretty_printers} attribute of each
24439 @code{gdb.Objfile} in the current program space and iteratively calls
24440 each enabled lookup routine in the list for that @code{gdb.Objfile}
24441 until it receives a pretty-printer object.
24442 If no pretty-printer is found in the objfile lists, @value{GDBN} then
24443 searches the pretty-printer list of the current program space,
24444 calling each enabled function until an object is returned.
24445 After these lists have been exhausted, it tries the global
24446 @code{gdb.pretty_printers} list, again calling each enabled function until an
24447 object is returned.
24448
24449 The order in which the objfiles are searched is not specified. For a
24450 given list, functions are always invoked from the head of the list,
24451 and iterated over sequentially until the end of the list, or a printer
24452 object is returned.
24453
24454 For various reasons a pretty-printer may not work.
24455 For example, the underlying data structure may have changed and
24456 the pretty-printer is out of date.
24457
24458 The consequences of a broken pretty-printer are severe enough that
24459 @value{GDBN} provides support for enabling and disabling individual
24460 printers. For example, if @code{print frame-arguments} is on,
24461 a backtrace can become highly illegible if any argument is printed
24462 with a broken printer.
24463
24464 Pretty-printers are enabled and disabled by attaching an @code{enabled}
24465 attribute to the registered function or callable object. If this attribute
24466 is present and its value is @code{False}, the printer is disabled, otherwise
24467 the printer is enabled.
24468
24469 @node Writing a Pretty-Printer
24470 @subsubsection Writing a Pretty-Printer
24471 @cindex writing a pretty-printer
24472
24473 A pretty-printer consists of two parts: a lookup function to detect
24474 if the type is supported, and the printer itself.
24475
24476 Here is an example showing how a @code{std::string} printer might be
24477 written. @xref{Pretty Printing API}, for details on the API this class
24478 must provide.
24479
24480 @smallexample
24481 class StdStringPrinter(object):
24482 "Print a std::string"
24483
24484 def __init__(self, val):
24485 self.val = val
24486
24487 def to_string(self):
24488 return self.val['_M_dataplus']['_M_p']
24489
24490 def display_hint(self):
24491 return 'string'
24492 @end smallexample
24493
24494 And here is an example showing how a lookup function for the printer
24495 example above might be written.
24496
24497 @smallexample
24498 def str_lookup_function(val):
24499 lookup_tag = val.type.tag
24500 if lookup_tag == None:
24501 return None
24502 regex = re.compile("^std::basic_string<char,.*>$")
24503 if regex.match(lookup_tag):
24504 return StdStringPrinter(val)
24505 return None
24506 @end smallexample
24507
24508 The example lookup function extracts the value's type, and attempts to
24509 match it to a type that it can pretty-print. If it is a type the
24510 printer can pretty-print, it will return a printer object. If not, it
24511 returns @code{None}.
24512
24513 We recommend that you put your core pretty-printers into a Python
24514 package. If your pretty-printers are for use with a library, we
24515 further recommend embedding a version number into the package name.
24516 This practice will enable @value{GDBN} to load multiple versions of
24517 your pretty-printers at the same time, because they will have
24518 different names.
24519
24520 You should write auto-loaded code (@pxref{Python Auto-loading}) such that it
24521 can be evaluated multiple times without changing its meaning. An
24522 ideal auto-load file will consist solely of @code{import}s of your
24523 printer modules, followed by a call to a register pretty-printers with
24524 the current objfile.
24525
24526 Taken as a whole, this approach will scale nicely to multiple
24527 inferiors, each potentially using a different library version.
24528 Embedding a version number in the Python package name will ensure that
24529 @value{GDBN} is able to load both sets of printers simultaneously.
24530 Then, because the search for pretty-printers is done by objfile, and
24531 because your auto-loaded code took care to register your library's
24532 printers with a specific objfile, @value{GDBN} will find the correct
24533 printers for the specific version of the library used by each
24534 inferior.
24535
24536 To continue the @code{std::string} example (@pxref{Pretty Printing API}),
24537 this code might appear in @code{gdb.libstdcxx.v6}:
24538
24539 @smallexample
24540 def register_printers(objfile):
24541 objfile.pretty_printers.append(str_lookup_function)
24542 @end smallexample
24543
24544 @noindent
24545 And then the corresponding contents of the auto-load file would be:
24546
24547 @smallexample
24548 import gdb.libstdcxx.v6
24549 gdb.libstdcxx.v6.register_printers(gdb.current_objfile())
24550 @end smallexample
24551
24552 The previous example illustrates a basic pretty-printer.
24553 There are a few things that can be improved on.
24554 The printer doesn't have a name, making it hard to identify in a
24555 list of installed printers. The lookup function has a name, but
24556 lookup functions can have arbitrary, even identical, names.
24557
24558 Second, the printer only handles one type, whereas a library typically has
24559 several types. One could install a lookup function for each desired type
24560 in the library, but one could also have a single lookup function recognize
24561 several types. The latter is the conventional way this is handled.
24562 If a pretty-printer can handle multiple data types, then its
24563 @dfn{subprinters} are the printers for the individual data types.
24564
24565 The @code{gdb.printing} module provides a formal way of solving these
24566 problems (@pxref{gdb.printing}).
24567 Here is another example that handles multiple types.
24568
24569 These are the types we are going to pretty-print:
24570
24571 @smallexample
24572 struct foo @{ int a, b; @};
24573 struct bar @{ struct foo x, y; @};
24574 @end smallexample
24575
24576 Here are the printers:
24577
24578 @smallexample
24579 class fooPrinter:
24580 """Print a foo object."""
24581
24582 def __init__(self, val):
24583 self.val = val
24584
24585 def to_string(self):
24586 return ("a=<" + str(self.val["a"]) +
24587 "> b=<" + str(self.val["b"]) + ">")
24588
24589 class barPrinter:
24590 """Print a bar object."""
24591
24592 def __init__(self, val):
24593 self.val = val
24594
24595 def to_string(self):
24596 return ("x=<" + str(self.val["x"]) +
24597 "> y=<" + str(self.val["y"]) + ">")
24598 @end smallexample
24599
24600 This example doesn't need a lookup function, that is handled by the
24601 @code{gdb.printing} module. Instead a function is provided to build up
24602 the object that handles the lookup.
24603
24604 @smallexample
24605 import gdb.printing
24606
24607 def build_pretty_printer():
24608 pp = gdb.printing.RegexpCollectionPrettyPrinter(
24609 "my_library")
24610 pp.add_printer('foo', '^foo$', fooPrinter)
24611 pp.add_printer('bar', '^bar$', barPrinter)
24612 return pp
24613 @end smallexample
24614
24615 And here is the autoload support:
24616
24617 @smallexample
24618 import gdb.printing
24619 import my_library
24620 gdb.printing.register_pretty_printer(
24621 gdb.current_objfile(),
24622 my_library.build_pretty_printer())
24623 @end smallexample
24624
24625 Finally, when this printer is loaded into @value{GDBN}, here is the
24626 corresponding output of @samp{info pretty-printer}:
24627
24628 @smallexample
24629 (gdb) info pretty-printer
24630 my_library.so:
24631 my_library
24632 foo
24633 bar
24634 @end smallexample
24635
24636 @node Type Printing API
24637 @subsubsection Type Printing API
24638 @cindex type printing API for Python
24639
24640 @value{GDBN} provides a way for Python code to customize type display.
24641 This is mainly useful for substituting canonical typedef names for
24642 types.
24643
24644 @cindex type printer
24645 A @dfn{type printer} is just a Python object conforming to a certain
24646 protocol. A simple base class implementing the protocol is provided;
24647 see @ref{gdb.types}. A type printer must supply at least:
24648
24649 @defivar type_printer enabled
24650 A boolean which is True if the printer is enabled, and False
24651 otherwise. This is manipulated by the @code{enable type-printer}
24652 and @code{disable type-printer} commands.
24653 @end defivar
24654
24655 @defivar type_printer name
24656 The name of the type printer. This must be a string. This is used by
24657 the @code{enable type-printer} and @code{disable type-printer}
24658 commands.
24659 @end defivar
24660
24661 @defmethod type_printer instantiate (self)
24662 This is called by @value{GDBN} at the start of type-printing. It is
24663 only called if the type printer is enabled. This method must return a
24664 new object that supplies a @code{recognize} method, as described below.
24665 @end defmethod
24666
24667
24668 When displaying a type, say via the @code{ptype} command, @value{GDBN}
24669 will compute a list of type recognizers. This is done by iterating
24670 first over the per-objfile type printers (@pxref{Objfiles In Python}),
24671 followed by the per-progspace type printers (@pxref{Progspaces In
24672 Python}), and finally the global type printers.
24673
24674 @value{GDBN} will call the @code{instantiate} method of each enabled
24675 type printer. If this method returns @code{None}, then the result is
24676 ignored; otherwise, it is appended to the list of recognizers.
24677
24678 Then, when @value{GDBN} is going to display a type name, it iterates
24679 over the list of recognizers. For each one, it calls the recognition
24680 function, stopping if the function returns a non-@code{None} value.
24681 The recognition function is defined as:
24682
24683 @defmethod type_recognizer recognize (self, type)
24684 If @var{type} is not recognized, return @code{None}. Otherwise,
24685 return a string which is to be printed as the name of @var{type}.
24686 @var{type} will be an instance of @code{gdb.Type} (@pxref{Types In
24687 Python}).
24688 @end defmethod
24689
24690 @value{GDBN} uses this two-pass approach so that type printers can
24691 efficiently cache information without holding on to it too long. For
24692 example, it can be convenient to look up type information in a type
24693 printer and hold it for a recognizer's lifetime; if a single pass were
24694 done then type printers would have to make use of the event system in
24695 order to avoid holding information that could become stale as the
24696 inferior changed.
24697
24698 @node Frame Filter API
24699 @subsubsection Filtering Frames.
24700 @cindex frame filters api
24701
24702 Frame filters are Python objects that manipulate the visibility of a
24703 frame or frames when a backtrace (@pxref{Backtrace}) is printed by
24704 @value{GDBN}.
24705
24706 Only commands that print a backtrace, or, in the case of @sc{gdb/mi}
24707 commands (@pxref{GDB/MI}), those that return a collection of frames
24708 are affected. The commands that work with frame filters are:
24709
24710 @code{backtrace} (@pxref{backtrace-command,, The backtrace command}),
24711 @code{-stack-list-frames}
24712 (@pxref{-stack-list-frames,, The -stack-list-frames command}),
24713 @code{-stack-list-variables} (@pxref{-stack-list-variables,, The
24714 -stack-list-variables command}), @code{-stack-list-arguments}
24715 @pxref{-stack-list-arguments,, The -stack-list-arguments command}) and
24716 @code{-stack-list-locals} (@pxref{-stack-list-locals,, The
24717 -stack-list-locals command}).
24718
24719 A frame filter works by taking an iterator as an argument, applying
24720 actions to the contents of that iterator, and returning another
24721 iterator (or, possibly, the same iterator it was provided in the case
24722 where the filter does not perform any operations). Typically, frame
24723 filters utilize tools such as the Python's @code{itertools} module to
24724 work with and create new iterators from the source iterator.
24725 Regardless of how a filter chooses to apply actions, it must not alter
24726 the underlying @value{GDBN} frame or frames, or attempt to alter the
24727 call-stack within @value{GDBN}. This preserves data integrity within
24728 @value{GDBN}. Frame filters are executed on a priority basis and care
24729 should be taken that some frame filters may have been executed before,
24730 and that some frame filters will be executed after.
24731
24732 An important consideration when designing frame filters, and well
24733 worth reflecting upon, is that frame filters should avoid unwinding
24734 the call stack if possible. Some stacks can run very deep, into the
24735 tens of thousands in some cases. To search every frame when a frame
24736 filter executes may be too expensive at that step. The frame filter
24737 cannot know how many frames it has to iterate over, and it may have to
24738 iterate through them all. This ends up duplicating effort as
24739 @value{GDBN} performs this iteration when it prints the frames. If
24740 the filter can defer unwinding frames until frame decorators are
24741 executed, after the last filter has executed, it should. @xref{Frame
24742 Decorator API}, for more information on decorators. Also, there are
24743 examples for both frame decorators and filters in later chapters.
24744 @xref{Writing a Frame Filter}, for more information.
24745
24746 The Python dictionary @code{gdb.frame_filters} contains key/object
24747 pairings that comprise a frame filter. Frame filters in this
24748 dictionary are called @code{global} frame filters, and they are
24749 available when debugging all inferiors. These frame filters must
24750 register with the dictionary directly. In addition to the
24751 @code{global} dictionary, there are other dictionaries that are loaded
24752 with different inferiors via auto-loading (@pxref{Python
24753 Auto-loading}). The two other areas where frame filter dictionaries
24754 can be found are: @code{gdb.Progspace} which contains a
24755 @code{frame_filters} dictionary attribute, and each @code{gdb.Objfile}
24756 object which also contains a @code{frame_filters} dictionary
24757 attribute.
24758
24759 When a command is executed from @value{GDBN} that is compatible with
24760 frame filters, @value{GDBN} combines the @code{global},
24761 @code{gdb.Progspace} and all @code{gdb.Objfile} dictionaries currently
24762 loaded. All of the @code{gdb.Objfile} dictionaries are combined, as
24763 several frames, and thus several object files, might be in use.
24764 @value{GDBN} then prunes any frame filter whose @code{enabled}
24765 attribute is @code{False}. This pruned list is then sorted according
24766 to the @code{priority} attribute in each filter.
24767
24768 Once the dictionaries are combined, pruned and sorted, @value{GDBN}
24769 creates an iterator which wraps each frame in the call stack in a
24770 @code{FrameDecorator} object, and calls each filter in order. The
24771 output from the previous filter will always be the input to the next
24772 filter, and so on.
24773
24774 Frame filters have a mandatory interface which each frame filter must
24775 implement, defined here:
24776
24777 @defun FrameFilter.filter (iterator)
24778 @value{GDBN} will call this method on a frame filter when it has
24779 reached the order in the priority list for that filter.
24780
24781 For example, if there are four frame filters:
24782
24783 @smallexample
24784 Name Priority
24785
24786 Filter1 5
24787 Filter2 10
24788 Filter3 100
24789 Filter4 1
24790 @end smallexample
24791
24792 The order that the frame filters will be called is:
24793
24794 @smallexample
24795 Filter3 -> Filter2 -> Filter1 -> Filter4
24796 @end smallexample
24797
24798 Note that the output from @code{Filter3} is passed to the input of
24799 @code{Filter2}, and so on.
24800
24801 This @code{filter} method is passed a Python iterator. This iterator
24802 contains a sequence of frame decorators that wrap each
24803 @code{gdb.Frame}, or a frame decorator that wraps another frame
24804 decorator. The first filter that is executed in the sequence of frame
24805 filters will receive an iterator entirely comprised of default
24806 @code{FrameDecorator} objects. However, after each frame filter is
24807 executed, the previous frame filter may have wrapped some or all of
24808 the frame decorators with their own frame decorator. As frame
24809 decorators must also conform to a mandatory interface, these
24810 decorators can be assumed to act in a uniform manner (@pxref{Frame
24811 Decorator API}).
24812
24813 This method must return an object conforming to the Python iterator
24814 protocol. Each item in the iterator must be an object conforming to
24815 the frame decorator interface. If a frame filter does not wish to
24816 perform any operations on this iterator, it should return that
24817 iterator untouched.
24818
24819 This method is not optional. If it does not exist, @value{GDBN} will
24820 raise and print an error.
24821 @end defun
24822
24823 @defvar FrameFilter.name
24824 The @code{name} attribute must be Python string which contains the
24825 name of the filter displayed by @value{GDBN} (@pxref{Frame Filter
24826 Management}). This attribute may contain any combination of letters
24827 or numbers. Care should be taken to ensure that it is unique. This
24828 attribute is mandatory.
24829 @end defvar
24830
24831 @defvar FrameFilter.enabled
24832 The @code{enabled} attribute must be Python boolean. This attribute
24833 indicates to @value{GDBN} whether the frame filter is enabled, and
24834 should be considered when frame filters are executed. If
24835 @code{enabled} is @code{True}, then the frame filter will be executed
24836 when any of the backtrace commands detailed earlier in this chapter
24837 are executed. If @code{enabled} is @code{False}, then the frame
24838 filter will not be executed. This attribute is mandatory.
24839 @end defvar
24840
24841 @defvar FrameFilter.priority
24842 The @code{priority} attribute must be Python integer. This attribute
24843 controls the order of execution in relation to other frame filters.
24844 There are no imposed limits on the range of @code{priority} other than
24845 it must be a valid integer. The higher the @code{priority} attribute,
24846 the sooner the frame filter will be executed in relation to other
24847 frame filters. Although @code{priority} can be negative, it is
24848 recommended practice to assume zero is the lowest priority that a
24849 frame filter can be assigned. Frame filters that have the same
24850 priority are executed in unsorted order in that priority slot. This
24851 attribute is mandatory.
24852 @end defvar
24853
24854 @node Frame Decorator API
24855 @subsubsection Decorating Frames.
24856 @cindex frame decorator api
24857
24858 Frame decorators are sister objects to frame filters (@pxref{Frame
24859 Filter API}). Frame decorators are applied by a frame filter and can
24860 only be used in conjunction with frame filters.
24861
24862 The purpose of a frame decorator is to customize the printed content
24863 of each @code{gdb.Frame} in commands where frame filters are executed.
24864 This concept is called decorating a frame. Frame decorators decorate
24865 a @code{gdb.Frame} with Python code contained within each API call.
24866 This separates the actual data contained in a @code{gdb.Frame} from
24867 the decorated data produced by a frame decorator. This abstraction is
24868 necessary to maintain integrity of the data contained in each
24869 @code{gdb.Frame}.
24870
24871 Frame decorators have a mandatory interface, defined below.
24872
24873 @value{GDBN} already contains a frame decorator called
24874 @code{FrameDecorator}. This contains substantial amounts of
24875 boilerplate code to decorate the content of a @code{gdb.Frame}. It is
24876 recommended that other frame decorators inherit and extend this
24877 object, and only to override the methods needed.
24878
24879 @defun FrameDecorator.elided (self)
24880
24881 The @code{elided} method groups frames together in a hierarchical
24882 system. An example would be an interpreter, where multiple low-level
24883 frames make up a single call in the interpreted language. In this
24884 example, the frame filter would elide the low-level frames and present
24885 a single high-level frame, representing the call in the interpreted
24886 language, to the user.
24887
24888 The @code{elided} function must return an iterable and this iterable
24889 must contain the frames that are being elided wrapped in a suitable
24890 frame decorator. If no frames are being elided this function may
24891 return an empty iterable, or @code{None}. Elided frames are indented
24892 from normal frames in a @code{CLI} backtrace, or in the case of
24893 @code{GDB/MI}, are placed in the @code{children} field of the eliding
24894 frame.
24895
24896 It is the frame filter's task to also filter out the elided frames from
24897 the source iterator. This will avoid printing the frame twice.
24898 @end defun
24899
24900 @defun FrameDecorator.function (self)
24901
24902 This method returns the name of the function in the frame that is to
24903 be printed.
24904
24905 This method must return a Python string describing the function, or
24906 @code{None}.
24907
24908 If this function returns @code{None}, @value{GDBN} will not print any
24909 data for this field.
24910 @end defun
24911
24912 @defun FrameDecorator.address (self)
24913
24914 This method returns the address of the frame that is to be printed.
24915
24916 This method must return a Python numeric integer type of sufficient
24917 size to describe the address of the frame, or @code{None}.
24918
24919 If this function returns a @code{None}, @value{GDBN} will not print
24920 any data for this field.
24921 @end defun
24922
24923 @defun FrameDecorator.filename (self)
24924
24925 This method returns the filename and path associated with this frame.
24926
24927 This method must return a Python string containing the filename and
24928 the path to the object file backing the frame, or @code{None}.
24929
24930 If this function returns a @code{None}, @value{GDBN} will not print
24931 any data for this field.
24932 @end defun
24933
24934 @defun FrameDecorator.line (self):
24935
24936 This method returns the line number associated with the current
24937 position within the function addressed by this frame.
24938
24939 This method must return a Python integer type, or @code{None}.
24940
24941 If this function returns a @code{None}, @value{GDBN} will not print
24942 any data for this field.
24943 @end defun
24944
24945 @defun FrameDecorator.frame_args (self)
24946 @anchor{frame_args}
24947
24948 This method must return an iterable, or @code{None}. Returning an
24949 empty iterable, or @code{None} means frame arguments will not be
24950 printed for this frame. This iterable must contain objects that
24951 implement two methods, described here.
24952
24953 This object must implement a @code{argument} method which takes a
24954 single @code{self} parameter and must return a @code{gdb.Symbol}
24955 (@pxref{Symbols In Python}), or a Python string. The object must also
24956 implement a @code{value} method which takes a single @code{self}
24957 parameter and must return a @code{gdb.Value} (@pxref{Values From
24958 Inferior}), a Python value, or @code{None}. If the @code{value}
24959 method returns @code{None}, and the @code{argument} method returns a
24960 @code{gdb.Symbol}, @value{GDBN} will look-up and print the value of
24961 the @code{gdb.Symbol} automatically.
24962
24963 A brief example:
24964
24965 @smallexample
24966 class SymValueWrapper():
24967
24968 def __init__(self, symbol, value):
24969 self.sym = symbol
24970 self.val = value
24971
24972 def value(self):
24973 return self.val
24974
24975 def symbol(self):
24976 return self.sym
24977
24978 class SomeFrameDecorator()
24979 ...
24980 ...
24981 def frame_args(self):
24982 args = []
24983 try:
24984 block = self.inferior_frame.block()
24985 except:
24986 return None
24987
24988 # Iterate over all symbols in a block. Only add
24989 # symbols that are arguments.
24990 for sym in block:
24991 if not sym.is_argument:
24992 continue
24993 args.append(SymValueWrapper(sym,None))
24994
24995 # Add example synthetic argument.
24996 args.append(SymValueWrapper(``foo'', 42))
24997
24998 return args
24999 @end smallexample
25000 @end defun
25001
25002 @defun FrameDecorator.frame_locals (self)
25003
25004 This method must return an iterable or @code{None}. Returning an
25005 empty iterable, or @code{None} means frame local arguments will not be
25006 printed for this frame.
25007
25008 The object interface, the description of the various strategies for
25009 reading frame locals, and the example are largely similar to those
25010 described in the @code{frame_args} function, (@pxref{frame_args,,The
25011 frame filter frame_args function}). Below is a modified example:
25012
25013 @smallexample
25014 class SomeFrameDecorator()
25015 ...
25016 ...
25017 def frame_locals(self):
25018 vars = []
25019 try:
25020 block = self.inferior_frame.block()
25021 except:
25022 return None
25023
25024 # Iterate over all symbols in a block. Add all
25025 # symbols, except arguments.
25026 for sym in block:
25027 if sym.is_argument:
25028 continue
25029 vars.append(SymValueWrapper(sym,None))
25030
25031 # Add an example of a synthetic local variable.
25032 vars.append(SymValueWrapper(``bar'', 99))
25033
25034 return vars
25035 @end smallexample
25036 @end defun
25037
25038 @defun FrameDecorator.inferior_frame (self):
25039
25040 This method must return the underlying @code{gdb.Frame} that this
25041 frame decorator is decorating. @value{GDBN} requires the underlying
25042 frame for internal frame information to determine how to print certain
25043 values when printing a frame.
25044 @end defun
25045
25046 @node Writing a Frame Filter
25047 @subsubsection Writing a Frame Filter
25048 @cindex writing a frame filter
25049
25050 There are three basic elements that a frame filter must implement: it
25051 must correctly implement the documented interface (@pxref{Frame Filter
25052 API}), it must register itself with @value{GDBN}, and finally, it must
25053 decide if it is to work on the data provided by @value{GDBN}. In all
25054 cases, whether it works on the iterator or not, each frame filter must
25055 return an iterator. A bare-bones frame filter follows the pattern in
25056 the following example.
25057
25058 @smallexample
25059 import gdb
25060
25061 class FrameFilter():
25062
25063 def __init__(self):
25064 # Frame filter attribute creation.
25065 #
25066 # 'name' is the name of the filter that GDB will display.
25067 #
25068 # 'priority' is the priority of the filter relative to other
25069 # filters.
25070 #
25071 # 'enabled' is a boolean that indicates whether this filter is
25072 # enabled and should be executed.
25073
25074 self.name = "Foo"
25075 self.priority = 100
25076 self.enabled = True
25077
25078 # Register this frame filter with the global frame_filters
25079 # dictionary.
25080 gdb.frame_filters[self.name] = self
25081
25082 def filter(self, frame_iter):
25083 # Just return the iterator.
25084 return frame_iter
25085 @end smallexample
25086
25087 The frame filter in the example above implements the three
25088 requirements for all frame filters. It implements the API, self
25089 registers, and makes a decision on the iterator (in this case, it just
25090 returns the iterator untouched).
25091
25092 The first step is attribute creation and assignment, and as shown in
25093 the comments the filter assigns the following attributes: @code{name},
25094 @code{priority} and whether the filter should be enabled with the
25095 @code{enabled} attribute.
25096
25097 The second step is registering the frame filter with the dictionary or
25098 dictionaries that the frame filter has interest in. As shown in the
25099 comments, this filter just registers itself with the global dictionary
25100 @code{gdb.frame_filters}. As noted earlier, @code{gdb.frame_filters}
25101 is a dictionary that is initialized in the @code{gdb} module when
25102 @value{GDBN} starts. What dictionary a filter registers with is an
25103 important consideration. Generally, if a filter is specific to a set
25104 of code, it should be registered either in the @code{objfile} or
25105 @code{progspace} dictionaries as they are specific to the program
25106 currently loaded in @value{GDBN}. The global dictionary is always
25107 present in @value{GDBN} and is never unloaded. Any filters registered
25108 with the global dictionary will exist until @value{GDBN} exits. To
25109 avoid filters that may conflict, it is generally better to register
25110 frame filters against the dictionaries that more closely align with
25111 the usage of the filter currently in question. @xref{Python
25112 Auto-loading}, for further information on auto-loading Python scripts.
25113
25114 @value{GDBN} takes a hands-off approach to frame filter registration,
25115 therefore it is the frame filter's responsibility to ensure
25116 registration has occurred, and that any exceptions are handled
25117 appropriately. In particular, you may wish to handle exceptions
25118 relating to Python dictionary key uniqueness. It is mandatory that
25119 the dictionary key is the same as frame filter's @code{name}
25120 attribute. When a user manages frame filters (@pxref{Frame Filter
25121 Management}), the names @value{GDBN} will display are those contained
25122 in the @code{name} attribute.
25123
25124 The final step of this example is the implementation of the
25125 @code{filter} method. As shown in the example comments, we define the
25126 @code{filter} method and note that the method must take an iterator,
25127 and also must return an iterator. In this bare-bones example, the
25128 frame filter is not very useful as it just returns the iterator
25129 untouched. However this is a valid operation for frame filters that
25130 have the @code{enabled} attribute set, but decide not to operate on
25131 any frames.
25132
25133 In the next example, the frame filter operates on all frames and
25134 utilizes a frame decorator to perform some work on the frames.
25135 @xref{Frame Decorator API}, for further information on the frame
25136 decorator interface.
25137
25138 This example works on inlined frames. It highlights frames which are
25139 inlined by tagging them with an ``[inlined]'' tag. By applying a
25140 frame decorator to all frames with the Python @code{itertools imap}
25141 method, the example defers actions to the frame decorator. Frame
25142 decorators are only processed when @value{GDBN} prints the backtrace.
25143
25144 This introduces a new decision making topic: whether to perform
25145 decision making operations at the filtering step, or at the printing
25146 step. In this example's approach, it does not perform any filtering
25147 decisions at the filtering step beyond mapping a frame decorator to
25148 each frame. This allows the actual decision making to be performed
25149 when each frame is printed. This is an important consideration, and
25150 well worth reflecting upon when designing a frame filter. An issue
25151 that frame filters should avoid is unwinding the stack if possible.
25152 Some stacks can run very deep, into the tens of thousands in some
25153 cases. To search every frame to determine if it is inlined ahead of
25154 time may be too expensive at the filtering step. The frame filter
25155 cannot know how many frames it has to iterate over, and it would have
25156 to iterate through them all. This ends up duplicating effort as
25157 @value{GDBN} performs this iteration when it prints the frames.
25158
25159 In this example decision making can be deferred to the printing step.
25160 As each frame is printed, the frame decorator can examine each frame
25161 in turn when @value{GDBN} iterates. From a performance viewpoint,
25162 this is the most appropriate decision to make as it avoids duplicating
25163 the effort that the printing step would undertake anyway. Also, if
25164 there are many frame filters unwinding the stack during filtering, it
25165 can substantially delay the printing of the backtrace which will
25166 result in large memory usage, and a poor user experience.
25167
25168 @smallexample
25169 class InlineFilter():
25170
25171 def __init__(self):
25172 self.name = "InlinedFrameFilter"
25173 self.priority = 100
25174 self.enabled = True
25175 gdb.frame_filters[self.name] = self
25176
25177 def filter(self, frame_iter):
25178 frame_iter = itertools.imap(InlinedFrameDecorator,
25179 frame_iter)
25180 return frame_iter
25181 @end smallexample
25182
25183 This frame filter is somewhat similar to the earlier example, except
25184 that the @code{filter} method applies a frame decorator object called
25185 @code{InlinedFrameDecorator} to each element in the iterator. The
25186 @code{imap} Python method is light-weight. It does not proactively
25187 iterate over the iterator, but rather creates a new iterator which
25188 wraps the existing one.
25189
25190 Below is the frame decorator for this example.
25191
25192 @smallexample
25193 class InlinedFrameDecorator(FrameDecorator):
25194
25195 def __init__(self, fobj):
25196 super(InlinedFrameDecorator, self).__init__(fobj)
25197
25198 def function(self):
25199 frame = fobj.inferior_frame()
25200 name = str(frame.name())
25201
25202 if frame.type() == gdb.INLINE_FRAME:
25203 name = name + " [inlined]"
25204
25205 return name
25206 @end smallexample
25207
25208 This frame decorator only defines and overrides the @code{function}
25209 method. It lets the supplied @code{FrameDecorator}, which is shipped
25210 with @value{GDBN}, perform the other work associated with printing
25211 this frame.
25212
25213 The combination of these two objects create this output from a
25214 backtrace:
25215
25216 @smallexample
25217 #0 0x004004e0 in bar () at inline.c:11
25218 #1 0x00400566 in max [inlined] (b=6, a=12) at inline.c:21
25219 #2 0x00400566 in main () at inline.c:31
25220 @end smallexample
25221
25222 So in the case of this example, a frame decorator is applied to all
25223 frames, regardless of whether they may be inlined or not. As
25224 @value{GDBN} iterates over the iterator produced by the frame filters,
25225 @value{GDBN} executes each frame decorator which then makes a decision
25226 on what to print in the @code{function} callback. Using a strategy
25227 like this is a way to defer decisions on the frame content to printing
25228 time.
25229
25230 @subheading Eliding Frames
25231
25232 It might be that the above example is not desirable for representing
25233 inlined frames, and a hierarchical approach may be preferred. If we
25234 want to hierarchically represent frames, the @code{elided} frame
25235 decorator interface might be preferable.
25236
25237 This example approaches the issue with the @code{elided} method. This
25238 example is quite long, but very simplistic. It is out-of-scope for
25239 this section to write a complete example that comprehensively covers
25240 all approaches of finding and printing inlined frames. However, this
25241 example illustrates the approach an author might use.
25242
25243 This example comprises of three sections.
25244
25245 @smallexample
25246 class InlineFrameFilter():
25247
25248 def __init__(self):
25249 self.name = "InlinedFrameFilter"
25250 self.priority = 100
25251 self.enabled = True
25252 gdb.frame_filters[self.name] = self
25253
25254 def filter(self, frame_iter):
25255 return ElidingInlineIterator(frame_iter)
25256 @end smallexample
25257
25258 This frame filter is very similar to the other examples. The only
25259 difference is this frame filter is wrapping the iterator provided to
25260 it (@code{frame_iter}) with a custom iterator called
25261 @code{ElidingInlineIterator}. This again defers actions to when
25262 @value{GDBN} prints the backtrace, as the iterator is not traversed
25263 until printing.
25264
25265 The iterator for this example is as follows. It is in this section of
25266 the example where decisions are made on the content of the backtrace.
25267
25268 @smallexample
25269 class ElidingInlineIterator:
25270 def __init__(self, ii):
25271 self.input_iterator = ii
25272
25273 def __iter__(self):
25274 return self
25275
25276 def next(self):
25277 frame = next(self.input_iterator)
25278
25279 if frame.inferior_frame().type() != gdb.INLINE_FRAME:
25280 return frame
25281
25282 try:
25283 eliding_frame = next(self.input_iterator)
25284 except StopIteration:
25285 return frame
25286 return ElidingFrameDecorator(eliding_frame, [frame])
25287 @end smallexample
25288
25289 This iterator implements the Python iterator protocol. When the
25290 @code{next} function is called (when @value{GDBN} prints each frame),
25291 the iterator checks if this frame decorator, @code{frame}, is wrapping
25292 an inlined frame. If it is not, it returns the existing frame decorator
25293 untouched. If it is wrapping an inlined frame, it assumes that the
25294 inlined frame was contained within the next oldest frame,
25295 @code{eliding_frame}, which it fetches. It then creates and returns a
25296 frame decorator, @code{ElidingFrameDecorator}, which contains both the
25297 elided frame, and the eliding frame.
25298
25299 @smallexample
25300 class ElidingInlineDecorator(FrameDecorator):
25301
25302 def __init__(self, frame, elided_frames):
25303 super(ElidingInlineDecorator, self).__init__(frame)
25304 self.frame = frame
25305 self.elided_frames = elided_frames
25306
25307 def elided(self):
25308 return iter(self.elided_frames)
25309 @end smallexample
25310
25311 This frame decorator overrides one function and returns the inlined
25312 frame in the @code{elided} method. As before it lets
25313 @code{FrameDecorator} do the rest of the work involved in printing
25314 this frame. This produces the following output.
25315
25316 @smallexample
25317 #0 0x004004e0 in bar () at inline.c:11
25318 #2 0x00400529 in main () at inline.c:25
25319 #1 0x00400529 in max (b=6, a=12) at inline.c:15
25320 @end smallexample
25321
25322 In that output, @code{max} which has been inlined into @code{main} is
25323 printed hierarchically. Another approach would be to combine the
25324 @code{function} method, and the @code{elided} method to both print a
25325 marker in the inlined frame, and also show the hierarchical
25326 relationship.
25327
25328 @node Inferiors In Python
25329 @subsubsection Inferiors In Python
25330 @cindex inferiors in Python
25331
25332 @findex gdb.Inferior
25333 Programs which are being run under @value{GDBN} are called inferiors
25334 (@pxref{Inferiors and Programs}). Python scripts can access
25335 information about and manipulate inferiors controlled by @value{GDBN}
25336 via objects of the @code{gdb.Inferior} class.
25337
25338 The following inferior-related functions are available in the @code{gdb}
25339 module:
25340
25341 @defun gdb.inferiors ()
25342 Return a tuple containing all inferior objects.
25343 @end defun
25344
25345 @defun gdb.selected_inferior ()
25346 Return an object representing the current inferior.
25347 @end defun
25348
25349 A @code{gdb.Inferior} object has the following attributes:
25350
25351 @defvar Inferior.num
25352 ID of inferior, as assigned by GDB.
25353 @end defvar
25354
25355 @defvar Inferior.pid
25356 Process ID of the inferior, as assigned by the underlying operating
25357 system.
25358 @end defvar
25359
25360 @defvar Inferior.was_attached
25361 Boolean signaling whether the inferior was created using `attach', or
25362 started by @value{GDBN} itself.
25363 @end defvar
25364
25365 A @code{gdb.Inferior} object has the following methods:
25366
25367 @defun Inferior.is_valid ()
25368 Returns @code{True} if the @code{gdb.Inferior} object is valid,
25369 @code{False} if not. A @code{gdb.Inferior} object will become invalid
25370 if the inferior no longer exists within @value{GDBN}. All other
25371 @code{gdb.Inferior} methods will throw an exception if it is invalid
25372 at the time the method is called.
25373 @end defun
25374
25375 @defun Inferior.threads ()
25376 This method returns a tuple holding all the threads which are valid
25377 when it is called. If there are no valid threads, the method will
25378 return an empty tuple.
25379 @end defun
25380
25381 @findex Inferior.read_memory
25382 @defun Inferior.read_memory (address, length)
25383 Read @var{length} bytes of memory from the inferior, starting at
25384 @var{address}. Returns a buffer object, which behaves much like an array
25385 or a string. It can be modified and given to the
25386 @code{Inferior.write_memory} function. In @code{Python} 3, the return
25387 value is a @code{memoryview} object.
25388 @end defun
25389
25390 @findex Inferior.write_memory
25391 @defun Inferior.write_memory (address, buffer @r{[}, length@r{]})
25392 Write the contents of @var{buffer} to the inferior, starting at
25393 @var{address}. The @var{buffer} parameter must be a Python object
25394 which supports the buffer protocol, i.e., a string, an array or the
25395 object returned from @code{Inferior.read_memory}. If given, @var{length}
25396 determines the number of bytes from @var{buffer} to be written.
25397 @end defun
25398
25399 @findex gdb.search_memory
25400 @defun Inferior.search_memory (address, length, pattern)
25401 Search a region of the inferior memory starting at @var{address} with
25402 the given @var{length} using the search pattern supplied in
25403 @var{pattern}. The @var{pattern} parameter must be a Python object
25404 which supports the buffer protocol, i.e., a string, an array or the
25405 object returned from @code{gdb.read_memory}. Returns a Python @code{Long}
25406 containing the address where the pattern was found, or @code{None} if
25407 the pattern could not be found.
25408 @end defun
25409
25410 @node Events In Python
25411 @subsubsection Events In Python
25412 @cindex inferior events in Python
25413
25414 @value{GDBN} provides a general event facility so that Python code can be
25415 notified of various state changes, particularly changes that occur in
25416 the inferior.
25417
25418 An @dfn{event} is just an object that describes some state change. The
25419 type of the object and its attributes will vary depending on the details
25420 of the change. All the existing events are described below.
25421
25422 In order to be notified of an event, you must register an event handler
25423 with an @dfn{event registry}. An event registry is an object in the
25424 @code{gdb.events} module which dispatches particular events. A registry
25425 provides methods to register and unregister event handlers:
25426
25427 @defun EventRegistry.connect (object)
25428 Add the given callable @var{object} to the registry. This object will be
25429 called when an event corresponding to this registry occurs.
25430 @end defun
25431
25432 @defun EventRegistry.disconnect (object)
25433 Remove the given @var{object} from the registry. Once removed, the object
25434 will no longer receive notifications of events.
25435 @end defun
25436
25437 Here is an example:
25438
25439 @smallexample
25440 def exit_handler (event):
25441 print "event type: exit"
25442 print "exit code: %d" % (event.exit_code)
25443
25444 gdb.events.exited.connect (exit_handler)
25445 @end smallexample
25446
25447 In the above example we connect our handler @code{exit_handler} to the
25448 registry @code{events.exited}. Once connected, @code{exit_handler} gets
25449 called when the inferior exits. The argument @dfn{event} in this example is
25450 of type @code{gdb.ExitedEvent}. As you can see in the example the
25451 @code{ExitedEvent} object has an attribute which indicates the exit code of
25452 the inferior.
25453
25454 The following is a listing of the event registries that are available and
25455 details of the events they emit:
25456
25457 @table @code
25458
25459 @item events.cont
25460 Emits @code{gdb.ThreadEvent}.
25461
25462 Some events can be thread specific when @value{GDBN} is running in non-stop
25463 mode. When represented in Python, these events all extend
25464 @code{gdb.ThreadEvent}. Note, this event is not emitted directly; instead,
25465 events which are emitted by this or other modules might extend this event.
25466 Examples of these events are @code{gdb.BreakpointEvent} and
25467 @code{gdb.ContinueEvent}.
25468
25469 @defvar ThreadEvent.inferior_thread
25470 In non-stop mode this attribute will be set to the specific thread which was
25471 involved in the emitted event. Otherwise, it will be set to @code{None}.
25472 @end defvar
25473
25474 Emits @code{gdb.ContinueEvent} which extends @code{gdb.ThreadEvent}.
25475
25476 This event indicates that the inferior has been continued after a stop. For
25477 inherited attribute refer to @code{gdb.ThreadEvent} above.
25478
25479 @item events.exited
25480 Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
25481 @code{events.ExitedEvent} has two attributes:
25482 @defvar ExitedEvent.exit_code
25483 An integer representing the exit code, if available, which the inferior
25484 has returned. (The exit code could be unavailable if, for example,
25485 @value{GDBN} detaches from the inferior.) If the exit code is unavailable,
25486 the attribute does not exist.
25487 @end defvar
25488 @defvar ExitedEvent inferior
25489 A reference to the inferior which triggered the @code{exited} event.
25490 @end defvar
25491
25492 @item events.stop
25493 Emits @code{gdb.StopEvent} which extends @code{gdb.ThreadEvent}.
25494
25495 Indicates that the inferior has stopped. All events emitted by this registry
25496 extend StopEvent. As a child of @code{gdb.ThreadEvent}, @code{gdb.StopEvent}
25497 will indicate the stopped thread when @value{GDBN} is running in non-stop
25498 mode. Refer to @code{gdb.ThreadEvent} above for more details.
25499
25500 Emits @code{gdb.SignalEvent} which extends @code{gdb.StopEvent}.
25501
25502 This event indicates that the inferior or one of its threads has received as
25503 signal. @code{gdb.SignalEvent} has the following attributes:
25504
25505 @defvar SignalEvent.stop_signal
25506 A string representing the signal received by the inferior. A list of possible
25507 signal values can be obtained by running the command @code{info signals} in
25508 the @value{GDBN} command prompt.
25509 @end defvar
25510
25511 Also emits @code{gdb.BreakpointEvent} which extends @code{gdb.StopEvent}.
25512
25513 @code{gdb.BreakpointEvent} event indicates that one or more breakpoints have
25514 been hit, and has the following attributes:
25515
25516 @defvar BreakpointEvent.breakpoints
25517 A sequence containing references to all the breakpoints (type
25518 @code{gdb.Breakpoint}) that were hit.
25519 @xref{Breakpoints In Python}, for details of the @code{gdb.Breakpoint} object.
25520 @end defvar
25521 @defvar BreakpointEvent.breakpoint
25522 A reference to the first breakpoint that was hit.
25523 This function is maintained for backward compatibility and is now deprecated
25524 in favor of the @code{gdb.BreakpointEvent.breakpoints} attribute.
25525 @end defvar
25526
25527 @item events.new_objfile
25528 Emits @code{gdb.NewObjFileEvent} which indicates that a new object file has
25529 been loaded by @value{GDBN}. @code{gdb.NewObjFileEvent} has one attribute:
25530
25531 @defvar NewObjFileEvent.new_objfile
25532 A reference to the object file (@code{gdb.Objfile}) which has been loaded.
25533 @xref{Objfiles In Python}, for details of the @code{gdb.Objfile} object.
25534 @end defvar
25535
25536 @end table
25537
25538 @node Threads In Python
25539 @subsubsection Threads In Python
25540 @cindex threads in python
25541
25542 @findex gdb.InferiorThread
25543 Python scripts can access information about, and manipulate inferior threads
25544 controlled by @value{GDBN}, via objects of the @code{gdb.InferiorThread} class.
25545
25546 The following thread-related functions are available in the @code{gdb}
25547 module:
25548
25549 @findex gdb.selected_thread
25550 @defun gdb.selected_thread ()
25551 This function returns the thread object for the selected thread. If there
25552 is no selected thread, this will return @code{None}.
25553 @end defun
25554
25555 A @code{gdb.InferiorThread} object has the following attributes:
25556
25557 @defvar InferiorThread.name
25558 The name of the thread. If the user specified a name using
25559 @code{thread name}, then this returns that name. Otherwise, if an
25560 OS-supplied name is available, then it is returned. Otherwise, this
25561 returns @code{None}.
25562
25563 This attribute can be assigned to. The new value must be a string
25564 object, which sets the new name, or @code{None}, which removes any
25565 user-specified thread name.
25566 @end defvar
25567
25568 @defvar InferiorThread.num
25569 ID of the thread, as assigned by GDB.
25570 @end defvar
25571
25572 @defvar InferiorThread.ptid
25573 ID of the thread, as assigned by the operating system. This attribute is a
25574 tuple containing three integers. The first is the Process ID (PID); the second
25575 is the Lightweight Process ID (LWPID), and the third is the Thread ID (TID).
25576 Either the LWPID or TID may be 0, which indicates that the operating system
25577 does not use that identifier.
25578 @end defvar
25579
25580 A @code{gdb.InferiorThread} object has the following methods:
25581
25582 @defun InferiorThread.is_valid ()
25583 Returns @code{True} if the @code{gdb.InferiorThread} object is valid,
25584 @code{False} if not. A @code{gdb.InferiorThread} object will become
25585 invalid if the thread exits, or the inferior that the thread belongs
25586 is deleted. All other @code{gdb.InferiorThread} methods will throw an
25587 exception if it is invalid at the time the method is called.
25588 @end defun
25589
25590 @defun InferiorThread.switch ()
25591 This changes @value{GDBN}'s currently selected thread to the one represented
25592 by this object.
25593 @end defun
25594
25595 @defun InferiorThread.is_stopped ()
25596 Return a Boolean indicating whether the thread is stopped.
25597 @end defun
25598
25599 @defun InferiorThread.is_running ()
25600 Return a Boolean indicating whether the thread is running.
25601 @end defun
25602
25603 @defun InferiorThread.is_exited ()
25604 Return a Boolean indicating whether the thread is exited.
25605 @end defun
25606
25607 @node Commands In Python
25608 @subsubsection Commands In Python
25609
25610 @cindex commands in python
25611 @cindex python commands
25612 You can implement new @value{GDBN} CLI commands in Python. A CLI
25613 command is implemented using an instance of the @code{gdb.Command}
25614 class, most commonly using a subclass.
25615
25616 @defun Command.__init__ (name, @var{command_class} @r{[}, @var{completer_class} @r{[}, @var{prefix}@r{]]})
25617 The object initializer for @code{Command} registers the new command
25618 with @value{GDBN}. This initializer is normally invoked from the
25619 subclass' own @code{__init__} method.
25620
25621 @var{name} is the name of the command. If @var{name} consists of
25622 multiple words, then the initial words are looked for as prefix
25623 commands. In this case, if one of the prefix commands does not exist,
25624 an exception is raised.
25625
25626 There is no support for multi-line commands.
25627
25628 @var{command_class} should be one of the @samp{COMMAND_} constants
25629 defined below. This argument tells @value{GDBN} how to categorize the
25630 new command in the help system.
25631
25632 @var{completer_class} is an optional argument. If given, it should be
25633 one of the @samp{COMPLETE_} constants defined below. This argument
25634 tells @value{GDBN} how to perform completion for this command. If not
25635 given, @value{GDBN} will attempt to complete using the object's
25636 @code{complete} method (see below); if no such method is found, an
25637 error will occur when completion is attempted.
25638
25639 @var{prefix} is an optional argument. If @code{True}, then the new
25640 command is a prefix command; sub-commands of this command may be
25641 registered.
25642
25643 The help text for the new command is taken from the Python
25644 documentation string for the command's class, if there is one. If no
25645 documentation string is provided, the default value ``This command is
25646 not documented.'' is used.
25647 @end defun
25648
25649 @cindex don't repeat Python command
25650 @defun Command.dont_repeat ()
25651 By default, a @value{GDBN} command is repeated when the user enters a
25652 blank line at the command prompt. A command can suppress this
25653 behavior by invoking the @code{dont_repeat} method. This is similar
25654 to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
25655 @end defun
25656
25657 @defun Command.invoke (argument, from_tty)
25658 This method is called by @value{GDBN} when this command is invoked.
25659
25660 @var{argument} is a string. It is the argument to the command, after
25661 leading and trailing whitespace has been stripped.
25662
25663 @var{from_tty} is a boolean argument. When true, this means that the
25664 command was entered by the user at the terminal; when false it means
25665 that the command came from elsewhere.
25666
25667 If this method throws an exception, it is turned into a @value{GDBN}
25668 @code{error} call. Otherwise, the return value is ignored.
25669
25670 @findex gdb.string_to_argv
25671 To break @var{argument} up into an argv-like string use
25672 @code{gdb.string_to_argv}. This function behaves identically to
25673 @value{GDBN}'s internal argument lexer @code{buildargv}.
25674 It is recommended to use this for consistency.
25675 Arguments are separated by spaces and may be quoted.
25676 Example:
25677
25678 @smallexample
25679 print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
25680 ['1', '2 "3', '4 "5', "6 '7"]
25681 @end smallexample
25682
25683 @end defun
25684
25685 @cindex completion of Python commands
25686 @defun Command.complete (text, word)
25687 This method is called by @value{GDBN} when the user attempts
25688 completion on this command. All forms of completion are handled by
25689 this method, that is, the @key{TAB} and @key{M-?} key bindings
25690 (@pxref{Completion}), and the @code{complete} command (@pxref{Help,
25691 complete}).
25692
25693 The arguments @var{text} and @var{word} are both strings. @var{text}
25694 holds the complete command line up to the cursor's location.
25695 @var{word} holds the last word of the command line; this is computed
25696 using a word-breaking heuristic.
25697
25698 The @code{complete} method can return several values:
25699 @itemize @bullet
25700 @item
25701 If the return value is a sequence, the contents of the sequence are
25702 used as the completions. It is up to @code{complete} to ensure that the
25703 contents actually do complete the word. A zero-length sequence is
25704 allowed, it means that there were no completions available. Only
25705 string elements of the sequence are used; other elements in the
25706 sequence are ignored.
25707
25708 @item
25709 If the return value is one of the @samp{COMPLETE_} constants defined
25710 below, then the corresponding @value{GDBN}-internal completion
25711 function is invoked, and its result is used.
25712
25713 @item
25714 All other results are treated as though there were no available
25715 completions.
25716 @end itemize
25717 @end defun
25718
25719 When a new command is registered, it must be declared as a member of
25720 some general class of commands. This is used to classify top-level
25721 commands in the on-line help system; note that prefix commands are not
25722 listed under their own category but rather that of their top-level
25723 command. The available classifications are represented by constants
25724 defined in the @code{gdb} module:
25725
25726 @table @code
25727 @findex COMMAND_NONE
25728 @findex gdb.COMMAND_NONE
25729 @item gdb.COMMAND_NONE
25730 The command does not belong to any particular class. A command in
25731 this category will not be displayed in any of the help categories.
25732
25733 @findex COMMAND_RUNNING
25734 @findex gdb.COMMAND_RUNNING
25735 @item gdb.COMMAND_RUNNING
25736 The command is related to running the inferior. For example,
25737 @code{start}, @code{step}, and @code{continue} are in this category.
25738 Type @kbd{help running} at the @value{GDBN} prompt to see a list of
25739 commands in this category.
25740
25741 @findex COMMAND_DATA
25742 @findex gdb.COMMAND_DATA
25743 @item gdb.COMMAND_DATA
25744 The command is related to data or variables. For example,
25745 @code{call}, @code{find}, and @code{print} are in this category. Type
25746 @kbd{help data} at the @value{GDBN} prompt to see a list of commands
25747 in this category.
25748
25749 @findex COMMAND_STACK
25750 @findex gdb.COMMAND_STACK
25751 @item gdb.COMMAND_STACK
25752 The command has to do with manipulation of the stack. For example,
25753 @code{backtrace}, @code{frame}, and @code{return} are in this
25754 category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
25755 list of commands in this category.
25756
25757 @findex COMMAND_FILES
25758 @findex gdb.COMMAND_FILES
25759 @item gdb.COMMAND_FILES
25760 This class is used for file-related commands. For example,
25761 @code{file}, @code{list} and @code{section} are in this category.
25762 Type @kbd{help files} at the @value{GDBN} prompt to see a list of
25763 commands in this category.
25764
25765 @findex COMMAND_SUPPORT
25766 @findex gdb.COMMAND_SUPPORT
25767 @item gdb.COMMAND_SUPPORT
25768 This should be used for ``support facilities'', generally meaning
25769 things that are useful to the user when interacting with @value{GDBN},
25770 but not related to the state of the inferior. For example,
25771 @code{help}, @code{make}, and @code{shell} are in this category. Type
25772 @kbd{help support} at the @value{GDBN} prompt to see a list of
25773 commands in this category.
25774
25775 @findex COMMAND_STATUS
25776 @findex gdb.COMMAND_STATUS
25777 @item gdb.COMMAND_STATUS
25778 The command is an @samp{info}-related command, that is, related to the
25779 state of @value{GDBN} itself. For example, @code{info}, @code{macro},
25780 and @code{show} are in this category. Type @kbd{help status} at the
25781 @value{GDBN} prompt to see a list of commands in this category.
25782
25783 @findex COMMAND_BREAKPOINTS
25784 @findex gdb.COMMAND_BREAKPOINTS
25785 @item gdb.COMMAND_BREAKPOINTS
25786 The command has to do with breakpoints. For example, @code{break},
25787 @code{clear}, and @code{delete} are in this category. Type @kbd{help
25788 breakpoints} at the @value{GDBN} prompt to see a list of commands in
25789 this category.
25790
25791 @findex COMMAND_TRACEPOINTS
25792 @findex gdb.COMMAND_TRACEPOINTS
25793 @item gdb.COMMAND_TRACEPOINTS
25794 The command has to do with tracepoints. For example, @code{trace},
25795 @code{actions}, and @code{tfind} are in this category. Type
25796 @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
25797 commands in this category.
25798
25799 @findex COMMAND_USER
25800 @findex gdb.COMMAND_USER
25801 @item gdb.COMMAND_USER
25802 The command is a general purpose command for the user, and typically
25803 does not fit in one of the other categories.
25804 Type @kbd{help user-defined} at the @value{GDBN} prompt to see
25805 a list of commands in this category, as well as the list of gdb macros
25806 (@pxref{Sequences}).
25807
25808 @findex COMMAND_OBSCURE
25809 @findex gdb.COMMAND_OBSCURE
25810 @item gdb.COMMAND_OBSCURE
25811 The command is only used in unusual circumstances, or is not of
25812 general interest to users. For example, @code{checkpoint},
25813 @code{fork}, and @code{stop} are in this category. Type @kbd{help
25814 obscure} at the @value{GDBN} prompt to see a list of commands in this
25815 category.
25816
25817 @findex COMMAND_MAINTENANCE
25818 @findex gdb.COMMAND_MAINTENANCE
25819 @item gdb.COMMAND_MAINTENANCE
25820 The command is only useful to @value{GDBN} maintainers. The
25821 @code{maintenance} and @code{flushregs} commands are in this category.
25822 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
25823 commands in this category.
25824 @end table
25825
25826 A new command can use a predefined completion function, either by
25827 specifying it via an argument at initialization, or by returning it
25828 from the @code{complete} method. These predefined completion
25829 constants are all defined in the @code{gdb} module:
25830
25831 @table @code
25832 @findex COMPLETE_NONE
25833 @findex gdb.COMPLETE_NONE
25834 @item gdb.COMPLETE_NONE
25835 This constant means that no completion should be done.
25836
25837 @findex COMPLETE_FILENAME
25838 @findex gdb.COMPLETE_FILENAME
25839 @item gdb.COMPLETE_FILENAME
25840 This constant means that filename completion should be performed.
25841
25842 @findex COMPLETE_LOCATION
25843 @findex gdb.COMPLETE_LOCATION
25844 @item gdb.COMPLETE_LOCATION
25845 This constant means that location completion should be done.
25846 @xref{Specify Location}.
25847
25848 @findex COMPLETE_COMMAND
25849 @findex gdb.COMPLETE_COMMAND
25850 @item gdb.COMPLETE_COMMAND
25851 This constant means that completion should examine @value{GDBN}
25852 command names.
25853
25854 @findex COMPLETE_SYMBOL
25855 @findex gdb.COMPLETE_SYMBOL
25856 @item gdb.COMPLETE_SYMBOL
25857 This constant means that completion should be done using symbol names
25858 as the source.
25859 @end table
25860
25861 The following code snippet shows how a trivial CLI command can be
25862 implemented in Python:
25863
25864 @smallexample
25865 class HelloWorld (gdb.Command):
25866 """Greet the whole world."""
25867
25868 def __init__ (self):
25869 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_USER)
25870
25871 def invoke (self, arg, from_tty):
25872 print "Hello, World!"
25873
25874 HelloWorld ()
25875 @end smallexample
25876
25877 The last line instantiates the class, and is necessary to trigger the
25878 registration of the command with @value{GDBN}. Depending on how the
25879 Python code is read into @value{GDBN}, you may need to import the
25880 @code{gdb} module explicitly.
25881
25882 @node Parameters In Python
25883 @subsubsection Parameters In Python
25884
25885 @cindex parameters in python
25886 @cindex python parameters
25887 @tindex gdb.Parameter
25888 @tindex Parameter
25889 You can implement new @value{GDBN} parameters using Python. A new
25890 parameter is implemented as an instance of the @code{gdb.Parameter}
25891 class.
25892
25893 Parameters are exposed to the user via the @code{set} and
25894 @code{show} commands. @xref{Help}.
25895
25896 There are many parameters that already exist and can be set in
25897 @value{GDBN}. Two examples are: @code{set follow fork} and
25898 @code{set charset}. Setting these parameters influences certain
25899 behavior in @value{GDBN}. Similarly, you can define parameters that
25900 can be used to influence behavior in custom Python scripts and commands.
25901
25902 @defun Parameter.__init__ (name, @var{command-class}, @var{parameter-class} @r{[}, @var{enum-sequence}@r{]})
25903 The object initializer for @code{Parameter} registers the new
25904 parameter with @value{GDBN}. This initializer is normally invoked
25905 from the subclass' own @code{__init__} method.
25906
25907 @var{name} is the name of the new parameter. If @var{name} consists
25908 of multiple words, then the initial words are looked for as prefix
25909 parameters. An example of this can be illustrated with the
25910 @code{set print} set of parameters. If @var{name} is
25911 @code{print foo}, then @code{print} will be searched as the prefix
25912 parameter. In this case the parameter can subsequently be accessed in
25913 @value{GDBN} as @code{set print foo}.
25914
25915 If @var{name} consists of multiple words, and no prefix parameter group
25916 can be found, an exception is raised.
25917
25918 @var{command-class} should be one of the @samp{COMMAND_} constants
25919 (@pxref{Commands In Python}). This argument tells @value{GDBN} how to
25920 categorize the new parameter in the help system.
25921
25922 @var{parameter-class} should be one of the @samp{PARAM_} constants
25923 defined below. This argument tells @value{GDBN} the type of the new
25924 parameter; this information is used for input validation and
25925 completion.
25926
25927 If @var{parameter-class} is @code{PARAM_ENUM}, then
25928 @var{enum-sequence} must be a sequence of strings. These strings
25929 represent the possible values for the parameter.
25930
25931 If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
25932 of a fourth argument will cause an exception to be thrown.
25933
25934 The help text for the new parameter is taken from the Python
25935 documentation string for the parameter's class, if there is one. If
25936 there is no documentation string, a default value is used.
25937 @end defun
25938
25939 @defvar Parameter.set_doc
25940 If this attribute exists, and is a string, then its value is used as
25941 the help text for this parameter's @code{set} command. The value is
25942 examined when @code{Parameter.__init__} is invoked; subsequent changes
25943 have no effect.
25944 @end defvar
25945
25946 @defvar Parameter.show_doc
25947 If this attribute exists, and is a string, then its value is used as
25948 the help text for this parameter's @code{show} command. The value is
25949 examined when @code{Parameter.__init__} is invoked; subsequent changes
25950 have no effect.
25951 @end defvar
25952
25953 @defvar Parameter.value
25954 The @code{value} attribute holds the underlying value of the
25955 parameter. It can be read and assigned to just as any other
25956 attribute. @value{GDBN} does validation when assignments are made.
25957 @end defvar
25958
25959 There are two methods that should be implemented in any
25960 @code{Parameter} class. These are:
25961
25962 @defun Parameter.get_set_string (self)
25963 @value{GDBN} will call this method when a @var{parameter}'s value has
25964 been changed via the @code{set} API (for example, @kbd{set foo off}).
25965 The @code{value} attribute has already been populated with the new
25966 value and may be used in output. This method must return a string.
25967 @end defun
25968
25969 @defun Parameter.get_show_string (self, svalue)
25970 @value{GDBN} will call this method when a @var{parameter}'s
25971 @code{show} API has been invoked (for example, @kbd{show foo}). The
25972 argument @code{svalue} receives the string representation of the
25973 current value. This method must return a string.
25974 @end defun
25975
25976 When a new parameter is defined, its type must be specified. The
25977 available types are represented by constants defined in the @code{gdb}
25978 module:
25979
25980 @table @code
25981 @findex PARAM_BOOLEAN
25982 @findex gdb.PARAM_BOOLEAN
25983 @item gdb.PARAM_BOOLEAN
25984 The value is a plain boolean. The Python boolean values, @code{True}
25985 and @code{False} are the only valid values.
25986
25987 @findex PARAM_AUTO_BOOLEAN
25988 @findex gdb.PARAM_AUTO_BOOLEAN
25989 @item gdb.PARAM_AUTO_BOOLEAN
25990 The value has three possible states: true, false, and @samp{auto}. In
25991 Python, true and false are represented using boolean constants, and
25992 @samp{auto} is represented using @code{None}.
25993
25994 @findex PARAM_UINTEGER
25995 @findex gdb.PARAM_UINTEGER
25996 @item gdb.PARAM_UINTEGER
25997 The value is an unsigned integer. The value of 0 should be
25998 interpreted to mean ``unlimited''.
25999
26000 @findex PARAM_INTEGER
26001 @findex gdb.PARAM_INTEGER
26002 @item gdb.PARAM_INTEGER
26003 The value is a signed integer. The value of 0 should be interpreted
26004 to mean ``unlimited''.
26005
26006 @findex PARAM_STRING
26007 @findex gdb.PARAM_STRING
26008 @item gdb.PARAM_STRING
26009 The value is a string. When the user modifies the string, any escape
26010 sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
26011 translated into corresponding characters and encoded into the current
26012 host charset.
26013
26014 @findex PARAM_STRING_NOESCAPE
26015 @findex gdb.PARAM_STRING_NOESCAPE
26016 @item gdb.PARAM_STRING_NOESCAPE
26017 The value is a string. When the user modifies the string, escapes are
26018 passed through untranslated.
26019
26020 @findex PARAM_OPTIONAL_FILENAME
26021 @findex gdb.PARAM_OPTIONAL_FILENAME
26022 @item gdb.PARAM_OPTIONAL_FILENAME
26023 The value is a either a filename (a string), or @code{None}.
26024
26025 @findex PARAM_FILENAME
26026 @findex gdb.PARAM_FILENAME
26027 @item gdb.PARAM_FILENAME
26028 The value is a filename. This is just like
26029 @code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
26030
26031 @findex PARAM_ZINTEGER
26032 @findex gdb.PARAM_ZINTEGER
26033 @item gdb.PARAM_ZINTEGER
26034 The value is an integer. This is like @code{PARAM_INTEGER}, except 0
26035 is interpreted as itself.
26036
26037 @findex PARAM_ENUM
26038 @findex gdb.PARAM_ENUM
26039 @item gdb.PARAM_ENUM
26040 The value is a string, which must be one of a collection string
26041 constants provided when the parameter is created.
26042 @end table
26043
26044 @node Functions In Python
26045 @subsubsection Writing new convenience functions
26046
26047 @cindex writing convenience functions
26048 @cindex convenience functions in python
26049 @cindex python convenience functions
26050 @tindex gdb.Function
26051 @tindex Function
26052 You can implement new convenience functions (@pxref{Convenience Vars})
26053 in Python. A convenience function is an instance of a subclass of the
26054 class @code{gdb.Function}.
26055
26056 @defun Function.__init__ (name)
26057 The initializer for @code{Function} registers the new function with
26058 @value{GDBN}. The argument @var{name} is the name of the function,
26059 a string. The function will be visible to the user as a convenience
26060 variable of type @code{internal function}, whose name is the same as
26061 the given @var{name}.
26062
26063 The documentation for the new function is taken from the documentation
26064 string for the new class.
26065 @end defun
26066
26067 @defun Function.invoke (@var{*args})
26068 When a convenience function is evaluated, its arguments are converted
26069 to instances of @code{gdb.Value}, and then the function's
26070 @code{invoke} method is called. Note that @value{GDBN} does not
26071 predetermine the arity of convenience functions. Instead, all
26072 available arguments are passed to @code{invoke}, following the
26073 standard Python calling convention. In particular, a convenience
26074 function can have default values for parameters without ill effect.
26075
26076 The return value of this method is used as its value in the enclosing
26077 expression. If an ordinary Python value is returned, it is converted
26078 to a @code{gdb.Value} following the usual rules.
26079 @end defun
26080
26081 The following code snippet shows how a trivial convenience function can
26082 be implemented in Python:
26083
26084 @smallexample
26085 class Greet (gdb.Function):
26086 """Return string to greet someone.
26087 Takes a name as argument."""
26088
26089 def __init__ (self):
26090 super (Greet, self).__init__ ("greet")
26091
26092 def invoke (self, name):
26093 return "Hello, %s!" % name.string ()
26094
26095 Greet ()
26096 @end smallexample
26097
26098 The last line instantiates the class, and is necessary to trigger the
26099 registration of the function with @value{GDBN}. Depending on how the
26100 Python code is read into @value{GDBN}, you may need to import the
26101 @code{gdb} module explicitly.
26102
26103 Now you can use the function in an expression:
26104
26105 @smallexample
26106 (gdb) print $greet("Bob")
26107 $1 = "Hello, Bob!"
26108 @end smallexample
26109
26110 @node Progspaces In Python
26111 @subsubsection Program Spaces In Python
26112
26113 @cindex progspaces in python
26114 @tindex gdb.Progspace
26115 @tindex Progspace
26116 A program space, or @dfn{progspace}, represents a symbolic view
26117 of an address space.
26118 It consists of all of the objfiles of the program.
26119 @xref{Objfiles In Python}.
26120 @xref{Inferiors and Programs, program spaces}, for more details
26121 about program spaces.
26122
26123 The following progspace-related functions are available in the
26124 @code{gdb} module:
26125
26126 @findex gdb.current_progspace
26127 @defun gdb.current_progspace ()
26128 This function returns the program space of the currently selected inferior.
26129 @xref{Inferiors and Programs}.
26130 @end defun
26131
26132 @findex gdb.progspaces
26133 @defun gdb.progspaces ()
26134 Return a sequence of all the progspaces currently known to @value{GDBN}.
26135 @end defun
26136
26137 Each progspace is represented by an instance of the @code{gdb.Progspace}
26138 class.
26139
26140 @defvar Progspace.filename
26141 The file name of the progspace as a string.
26142 @end defvar
26143
26144 @defvar Progspace.pretty_printers
26145 The @code{pretty_printers} attribute is a list of functions. It is
26146 used to look up pretty-printers. A @code{Value} is passed to each
26147 function in order; if the function returns @code{None}, then the
26148 search continues. Otherwise, the return value should be an object
26149 which is used to format the value. @xref{Pretty Printing API}, for more
26150 information.
26151 @end defvar
26152
26153 @defvar Progspace.type_printers
26154 The @code{type_printers} attribute is a list of type printer objects.
26155 @xref{Type Printing API}, for more information.
26156 @end defvar
26157
26158 @defvar Progspace.frame_filters
26159 The @code{frame_filters} attribute is a dictionary of frame filter
26160 objects. @xref{Frame Filter API}, for more information.
26161 @end defvar
26162
26163 @node Objfiles In Python
26164 @subsubsection Objfiles In Python
26165
26166 @cindex objfiles in python
26167 @tindex gdb.Objfile
26168 @tindex Objfile
26169 @value{GDBN} loads symbols for an inferior from various
26170 symbol-containing files (@pxref{Files}). These include the primary
26171 executable file, any shared libraries used by the inferior, and any
26172 separate debug info files (@pxref{Separate Debug Files}).
26173 @value{GDBN} calls these symbol-containing files @dfn{objfiles}.
26174
26175 The following objfile-related functions are available in the
26176 @code{gdb} module:
26177
26178 @findex gdb.current_objfile
26179 @defun gdb.current_objfile ()
26180 When auto-loading a Python script (@pxref{Python Auto-loading}), @value{GDBN}
26181 sets the ``current objfile'' to the corresponding objfile. This
26182 function returns the current objfile. If there is no current objfile,
26183 this function returns @code{None}.
26184 @end defun
26185
26186 @findex gdb.objfiles
26187 @defun gdb.objfiles ()
26188 Return a sequence of all the objfiles current known to @value{GDBN}.
26189 @xref{Objfiles In Python}.
26190 @end defun
26191
26192 Each objfile is represented by an instance of the @code{gdb.Objfile}
26193 class.
26194
26195 @defvar Objfile.filename
26196 The file name of the objfile as a string.
26197 @end defvar
26198
26199 @defvar Objfile.pretty_printers
26200 The @code{pretty_printers} attribute is a list of functions. It is
26201 used to look up pretty-printers. A @code{Value} is passed to each
26202 function in order; if the function returns @code{None}, then the
26203 search continues. Otherwise, the return value should be an object
26204 which is used to format the value. @xref{Pretty Printing API}, for more
26205 information.
26206 @end defvar
26207
26208 @defvar Objfile.type_printers
26209 The @code{type_printers} attribute is a list of type printer objects.
26210 @xref{Type Printing API}, for more information.
26211 @end defvar
26212
26213 @defvar Objfile.frame_filters
26214 The @code{frame_filters} attribute is a dictionary of frame filter
26215 objects. @xref{Frame Filter API}, for more information.
26216 @end defvar
26217
26218 A @code{gdb.Objfile} object has the following methods:
26219
26220 @defun Objfile.is_valid ()
26221 Returns @code{True} if the @code{gdb.Objfile} object is valid,
26222 @code{False} if not. A @code{gdb.Objfile} object can become invalid
26223 if the object file it refers to is not loaded in @value{GDBN} any
26224 longer. All other @code{gdb.Objfile} methods will throw an exception
26225 if it is invalid at the time the method is called.
26226 @end defun
26227
26228 @node Frames In Python
26229 @subsubsection Accessing inferior stack frames from Python.
26230
26231 @cindex frames in python
26232 When the debugged program stops, @value{GDBN} is able to analyze its call
26233 stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
26234 represents a frame in the stack. A @code{gdb.Frame} object is only valid
26235 while its corresponding frame exists in the inferior's stack. If you try
26236 to use an invalid frame object, @value{GDBN} will throw a @code{gdb.error}
26237 exception (@pxref{Exception Handling}).
26238
26239 Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
26240 operator, like:
26241
26242 @smallexample
26243 (@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
26244 True
26245 @end smallexample
26246
26247 The following frame-related functions are available in the @code{gdb} module:
26248
26249 @findex gdb.selected_frame
26250 @defun gdb.selected_frame ()
26251 Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
26252 @end defun
26253
26254 @findex gdb.newest_frame
26255 @defun gdb.newest_frame ()
26256 Return the newest frame object for the selected thread.
26257 @end defun
26258
26259 @defun gdb.frame_stop_reason_string (reason)
26260 Return a string explaining the reason why @value{GDBN} stopped unwinding
26261 frames, as expressed by the given @var{reason} code (an integer, see the
26262 @code{unwind_stop_reason} method further down in this section).
26263 @end defun
26264
26265 A @code{gdb.Frame} object has the following methods:
26266
26267 @defun Frame.is_valid ()
26268 Returns true if the @code{gdb.Frame} object is valid, false if not.
26269 A frame object can become invalid if the frame it refers to doesn't
26270 exist anymore in the inferior. All @code{gdb.Frame} methods will throw
26271 an exception if it is invalid at the time the method is called.
26272 @end defun
26273
26274 @defun Frame.name ()
26275 Returns the function name of the frame, or @code{None} if it can't be
26276 obtained.
26277 @end defun
26278
26279 @defun Frame.architecture ()
26280 Returns the @code{gdb.Architecture} object corresponding to the frame's
26281 architecture. @xref{Architectures In Python}.
26282 @end defun
26283
26284 @defun Frame.type ()
26285 Returns the type of the frame. The value can be one of:
26286 @table @code
26287 @item gdb.NORMAL_FRAME
26288 An ordinary stack frame.
26289
26290 @item gdb.DUMMY_FRAME
26291 A fake stack frame that was created by @value{GDBN} when performing an
26292 inferior function call.
26293
26294 @item gdb.INLINE_FRAME
26295 A frame representing an inlined function. The function was inlined
26296 into a @code{gdb.NORMAL_FRAME} that is older than this one.
26297
26298 @item gdb.TAILCALL_FRAME
26299 A frame representing a tail call. @xref{Tail Call Frames}.
26300
26301 @item gdb.SIGTRAMP_FRAME
26302 A signal trampoline frame. This is the frame created by the OS when
26303 it calls into a signal handler.
26304
26305 @item gdb.ARCH_FRAME
26306 A fake stack frame representing a cross-architecture call.
26307
26308 @item gdb.SENTINEL_FRAME
26309 This is like @code{gdb.NORMAL_FRAME}, but it is only used for the
26310 newest frame.
26311 @end table
26312 @end defun
26313
26314 @defun Frame.unwind_stop_reason ()
26315 Return an integer representing the reason why it's not possible to find
26316 more frames toward the outermost frame. Use
26317 @code{gdb.frame_stop_reason_string} to convert the value returned by this
26318 function to a string. The value can be one of:
26319
26320 @table @code
26321 @item gdb.FRAME_UNWIND_NO_REASON
26322 No particular reason (older frames should be available).
26323
26324 @item gdb.FRAME_UNWIND_NULL_ID
26325 The previous frame's analyzer returns an invalid result.
26326
26327 @item gdb.FRAME_UNWIND_OUTERMOST
26328 This frame is the outermost.
26329
26330 @item gdb.FRAME_UNWIND_UNAVAILABLE
26331 Cannot unwind further, because that would require knowing the
26332 values of registers or memory that have not been collected.
26333
26334 @item gdb.FRAME_UNWIND_INNER_ID
26335 This frame ID looks like it ought to belong to a NEXT frame,
26336 but we got it for a PREV frame. Normally, this is a sign of
26337 unwinder failure. It could also indicate stack corruption.
26338
26339 @item gdb.FRAME_UNWIND_SAME_ID
26340 This frame has the same ID as the previous one. That means
26341 that unwinding further would almost certainly give us another
26342 frame with exactly the same ID, so break the chain. Normally,
26343 this is a sign of unwinder failure. It could also indicate
26344 stack corruption.
26345
26346 @item gdb.FRAME_UNWIND_NO_SAVED_PC
26347 The frame unwinder did not find any saved PC, but we needed
26348 one to unwind further.
26349
26350 @item gdb.FRAME_UNWIND_FIRST_ERROR
26351 Any stop reason greater or equal to this value indicates some kind
26352 of error. This special value facilitates writing code that tests
26353 for errors in unwinding in a way that will work correctly even if
26354 the list of the other values is modified in future @value{GDBN}
26355 versions. Using it, you could write:
26356 @smallexample
26357 reason = gdb.selected_frame().unwind_stop_reason ()
26358 reason_str = gdb.frame_stop_reason_string (reason)
26359 if reason >= gdb.FRAME_UNWIND_FIRST_ERROR:
26360 print "An error occured: %s" % reason_str
26361 @end smallexample
26362 @end table
26363
26364 @end defun
26365
26366 @defun Frame.pc ()
26367 Returns the frame's resume address.
26368 @end defun
26369
26370 @defun Frame.block ()
26371 Return the frame's code block. @xref{Blocks In Python}.
26372 @end defun
26373
26374 @defun Frame.function ()
26375 Return the symbol for the function corresponding to this frame.
26376 @xref{Symbols In Python}.
26377 @end defun
26378
26379 @defun Frame.older ()
26380 Return the frame that called this frame.
26381 @end defun
26382
26383 @defun Frame.newer ()
26384 Return the frame called by this frame.
26385 @end defun
26386
26387 @defun Frame.find_sal ()
26388 Return the frame's symtab and line object.
26389 @xref{Symbol Tables In Python}.
26390 @end defun
26391
26392 @defun Frame.read_var (variable @r{[}, block@r{]})
26393 Return the value of @var{variable} in this frame. If the optional
26394 argument @var{block} is provided, search for the variable from that
26395 block; otherwise start at the frame's current block (which is
26396 determined by the frame's current program counter). @var{variable}
26397 must be a string or a @code{gdb.Symbol} object. @var{block} must be a
26398 @code{gdb.Block} object.
26399 @end defun
26400
26401 @defun Frame.select ()
26402 Set this frame to be the selected frame. @xref{Stack, ,Examining the
26403 Stack}.
26404 @end defun
26405
26406 @node Blocks In Python
26407 @subsubsection Accessing blocks from Python.
26408
26409 @cindex blocks in python
26410 @tindex gdb.Block
26411
26412 In @value{GDBN}, symbols are stored in blocks. A block corresponds
26413 roughly to a scope in the source code. Blocks are organized
26414 hierarchically, and are represented individually in Python as a
26415 @code{gdb.Block}. Blocks rely on debugging information being
26416 available.
26417
26418 A frame has a block. Please see @ref{Frames In Python}, for a more
26419 in-depth discussion of frames.
26420
26421 The outermost block is known as the @dfn{global block}. The global
26422 block typically holds public global variables and functions.
26423
26424 The block nested just inside the global block is the @dfn{static
26425 block}. The static block typically holds file-scoped variables and
26426 functions.
26427
26428 @value{GDBN} provides a method to get a block's superblock, but there
26429 is currently no way to examine the sub-blocks of a block, or to
26430 iterate over all the blocks in a symbol table (@pxref{Symbol Tables In
26431 Python}).
26432
26433 Here is a short example that should help explain blocks:
26434
26435 @smallexample
26436 /* This is in the global block. */
26437 int global;
26438
26439 /* This is in the static block. */
26440 static int file_scope;
26441
26442 /* 'function' is in the global block, and 'argument' is
26443 in a block nested inside of 'function'. */
26444 int function (int argument)
26445 @{
26446 /* 'local' is in a block inside 'function'. It may or may
26447 not be in the same block as 'argument'. */
26448 int local;
26449
26450 @{
26451 /* 'inner' is in a block whose superblock is the one holding
26452 'local'. */
26453 int inner;
26454
26455 /* If this call is expanded by the compiler, you may see
26456 a nested block here whose function is 'inline_function'
26457 and whose superblock is the one holding 'inner'. */
26458 inline_function ();
26459 @}
26460 @}
26461 @end smallexample
26462
26463 A @code{gdb.Block} is iterable. The iterator returns the symbols
26464 (@pxref{Symbols In Python}) local to the block. Python programs
26465 should not assume that a specific block object will always contain a
26466 given symbol, since changes in @value{GDBN} features and
26467 infrastructure may cause symbols move across blocks in a symbol
26468 table.
26469
26470 The following block-related functions are available in the @code{gdb}
26471 module:
26472
26473 @findex gdb.block_for_pc
26474 @defun gdb.block_for_pc (pc)
26475 Return the innermost @code{gdb.Block} containing the given @var{pc}
26476 value. If the block cannot be found for the @var{pc} value specified,
26477 the function will return @code{None}.
26478 @end defun
26479
26480 A @code{gdb.Block} object has the following methods:
26481
26482 @defun Block.is_valid ()
26483 Returns @code{True} if the @code{gdb.Block} object is valid,
26484 @code{False} if not. A block object can become invalid if the block it
26485 refers to doesn't exist anymore in the inferior. All other
26486 @code{gdb.Block} methods will throw an exception if it is invalid at
26487 the time the method is called. The block's validity is also checked
26488 during iteration over symbols of the block.
26489 @end defun
26490
26491 A @code{gdb.Block} object has the following attributes:
26492
26493 @defvar Block.start
26494 The start address of the block. This attribute is not writable.
26495 @end defvar
26496
26497 @defvar Block.end
26498 The end address of the block. This attribute is not writable.
26499 @end defvar
26500
26501 @defvar Block.function
26502 The name of the block represented as a @code{gdb.Symbol}. If the
26503 block is not named, then this attribute holds @code{None}. This
26504 attribute is not writable.
26505
26506 For ordinary function blocks, the superblock is the static block.
26507 However, you should note that it is possible for a function block to
26508 have a superblock that is not the static block -- for instance this
26509 happens for an inlined function.
26510 @end defvar
26511
26512 @defvar Block.superblock
26513 The block containing this block. If this parent block does not exist,
26514 this attribute holds @code{None}. This attribute is not writable.
26515 @end defvar
26516
26517 @defvar Block.global_block
26518 The global block associated with this block. This attribute is not
26519 writable.
26520 @end defvar
26521
26522 @defvar Block.static_block
26523 The static block associated with this block. This attribute is not
26524 writable.
26525 @end defvar
26526
26527 @defvar Block.is_global
26528 @code{True} if the @code{gdb.Block} object is a global block,
26529 @code{False} if not. This attribute is not
26530 writable.
26531 @end defvar
26532
26533 @defvar Block.is_static
26534 @code{True} if the @code{gdb.Block} object is a static block,
26535 @code{False} if not. This attribute is not writable.
26536 @end defvar
26537
26538 @node Symbols In Python
26539 @subsubsection Python representation of Symbols.
26540
26541 @cindex symbols in python
26542 @tindex gdb.Symbol
26543
26544 @value{GDBN} represents every variable, function and type as an
26545 entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
26546 Similarly, Python represents these symbols in @value{GDBN} with the
26547 @code{gdb.Symbol} object.
26548
26549 The following symbol-related functions are available in the @code{gdb}
26550 module:
26551
26552 @findex gdb.lookup_symbol
26553 @defun gdb.lookup_symbol (name @r{[}, block @r{[}, domain@r{]]})
26554 This function searches for a symbol by name. The search scope can be
26555 restricted to the parameters defined in the optional domain and block
26556 arguments.
26557
26558 @var{name} is the name of the symbol. It must be a string. The
26559 optional @var{block} argument restricts the search to symbols visible
26560 in that @var{block}. The @var{block} argument must be a
26561 @code{gdb.Block} object. If omitted, the block for the current frame
26562 is used. The optional @var{domain} argument restricts
26563 the search to the domain type. The @var{domain} argument must be a
26564 domain constant defined in the @code{gdb} module and described later
26565 in this chapter.
26566
26567 The result is a tuple of two elements.
26568 The first element is a @code{gdb.Symbol} object or @code{None} if the symbol
26569 is not found.
26570 If the symbol is found, the second element is @code{True} if the symbol
26571 is a field of a method's object (e.g., @code{this} in C@t{++}),
26572 otherwise it is @code{False}.
26573 If the symbol is not found, the second element is @code{False}.
26574 @end defun
26575
26576 @findex gdb.lookup_global_symbol
26577 @defun gdb.lookup_global_symbol (name @r{[}, domain@r{]})
26578 This function searches for a global symbol by name.
26579 The search scope can be restricted to by the domain argument.
26580
26581 @var{name} is the name of the symbol. It must be a string.
26582 The optional @var{domain} argument restricts the search to the domain type.
26583 The @var{domain} argument must be a domain constant defined in the @code{gdb}
26584 module and described later in this chapter.
26585
26586 The result is a @code{gdb.Symbol} object or @code{None} if the symbol
26587 is not found.
26588 @end defun
26589
26590 A @code{gdb.Symbol} object has the following attributes:
26591
26592 @defvar Symbol.type
26593 The type of the symbol or @code{None} if no type is recorded.
26594 This attribute is represented as a @code{gdb.Type} object.
26595 @xref{Types In Python}. This attribute is not writable.
26596 @end defvar
26597
26598 @defvar Symbol.symtab
26599 The symbol table in which the symbol appears. This attribute is
26600 represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
26601 Python}. This attribute is not writable.
26602 @end defvar
26603
26604 @defvar Symbol.line
26605 The line number in the source code at which the symbol was defined.
26606 This is an integer.
26607 @end defvar
26608
26609 @defvar Symbol.name
26610 The name of the symbol as a string. This attribute is not writable.
26611 @end defvar
26612
26613 @defvar Symbol.linkage_name
26614 The name of the symbol, as used by the linker (i.e., may be mangled).
26615 This attribute is not writable.
26616 @end defvar
26617
26618 @defvar Symbol.print_name
26619 The name of the symbol in a form suitable for output. This is either
26620 @code{name} or @code{linkage_name}, depending on whether the user
26621 asked @value{GDBN} to display demangled or mangled names.
26622 @end defvar
26623
26624 @defvar Symbol.addr_class
26625 The address class of the symbol. This classifies how to find the value
26626 of a symbol. Each address class is a constant defined in the
26627 @code{gdb} module and described later in this chapter.
26628 @end defvar
26629
26630 @defvar Symbol.needs_frame
26631 This is @code{True} if evaluating this symbol's value requires a frame
26632 (@pxref{Frames In Python}) and @code{False} otherwise. Typically,
26633 local variables will require a frame, but other symbols will not.
26634 @end defvar
26635
26636 @defvar Symbol.is_argument
26637 @code{True} if the symbol is an argument of a function.
26638 @end defvar
26639
26640 @defvar Symbol.is_constant
26641 @code{True} if the symbol is a constant.
26642 @end defvar
26643
26644 @defvar Symbol.is_function
26645 @code{True} if the symbol is a function or a method.
26646 @end defvar
26647
26648 @defvar Symbol.is_variable
26649 @code{True} if the symbol is a variable.
26650 @end defvar
26651
26652 A @code{gdb.Symbol} object has the following methods:
26653
26654 @defun Symbol.is_valid ()
26655 Returns @code{True} if the @code{gdb.Symbol} object is valid,
26656 @code{False} if not. A @code{gdb.Symbol} object can become invalid if
26657 the symbol it refers to does not exist in @value{GDBN} any longer.
26658 All other @code{gdb.Symbol} methods will throw an exception if it is
26659 invalid at the time the method is called.
26660 @end defun
26661
26662 @defun Symbol.value (@r{[}frame@r{]})
26663 Compute the value of the symbol, as a @code{gdb.Value}. For
26664 functions, this computes the address of the function, cast to the
26665 appropriate type. If the symbol requires a frame in order to compute
26666 its value, then @var{frame} must be given. If @var{frame} is not
26667 given, or if @var{frame} is invalid, then this method will throw an
26668 exception.
26669 @end defun
26670
26671 The available domain categories in @code{gdb.Symbol} are represented
26672 as constants in the @code{gdb} module:
26673
26674 @table @code
26675 @findex SYMBOL_UNDEF_DOMAIN
26676 @findex gdb.SYMBOL_UNDEF_DOMAIN
26677 @item gdb.SYMBOL_UNDEF_DOMAIN
26678 This is used when a domain has not been discovered or none of the
26679 following domains apply. This usually indicates an error either
26680 in the symbol information or in @value{GDBN}'s handling of symbols.
26681 @findex SYMBOL_VAR_DOMAIN
26682 @findex gdb.SYMBOL_VAR_DOMAIN
26683 @item gdb.SYMBOL_VAR_DOMAIN
26684 This domain contains variables, function names, typedef names and enum
26685 type values.
26686 @findex SYMBOL_STRUCT_DOMAIN
26687 @findex gdb.SYMBOL_STRUCT_DOMAIN
26688 @item gdb.SYMBOL_STRUCT_DOMAIN
26689 This domain holds struct, union and enum type names.
26690 @findex SYMBOL_LABEL_DOMAIN
26691 @findex gdb.SYMBOL_LABEL_DOMAIN
26692 @item gdb.SYMBOL_LABEL_DOMAIN
26693 This domain contains names of labels (for gotos).
26694 @findex SYMBOL_VARIABLES_DOMAIN
26695 @findex gdb.SYMBOL_VARIABLES_DOMAIN
26696 @item gdb.SYMBOL_VARIABLES_DOMAIN
26697 This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
26698 contains everything minus functions and types.
26699 @findex SYMBOL_FUNCTIONS_DOMAIN
26700 @findex gdb.SYMBOL_FUNCTIONS_DOMAIN
26701 @item gdb.SYMBOL_FUNCTION_DOMAIN
26702 This domain contains all functions.
26703 @findex SYMBOL_TYPES_DOMAIN
26704 @findex gdb.SYMBOL_TYPES_DOMAIN
26705 @item gdb.SYMBOL_TYPES_DOMAIN
26706 This domain contains all types.
26707 @end table
26708
26709 The available address class categories in @code{gdb.Symbol} are represented
26710 as constants in the @code{gdb} module:
26711
26712 @table @code
26713 @findex SYMBOL_LOC_UNDEF
26714 @findex gdb.SYMBOL_LOC_UNDEF
26715 @item gdb.SYMBOL_LOC_UNDEF
26716 If this is returned by address class, it indicates an error either in
26717 the symbol information or in @value{GDBN}'s handling of symbols.
26718 @findex SYMBOL_LOC_CONST
26719 @findex gdb.SYMBOL_LOC_CONST
26720 @item gdb.SYMBOL_LOC_CONST
26721 Value is constant int.
26722 @findex SYMBOL_LOC_STATIC
26723 @findex gdb.SYMBOL_LOC_STATIC
26724 @item gdb.SYMBOL_LOC_STATIC
26725 Value is at a fixed address.
26726 @findex SYMBOL_LOC_REGISTER
26727 @findex gdb.SYMBOL_LOC_REGISTER
26728 @item gdb.SYMBOL_LOC_REGISTER
26729 Value is in a register.
26730 @findex SYMBOL_LOC_ARG
26731 @findex gdb.SYMBOL_LOC_ARG
26732 @item gdb.SYMBOL_LOC_ARG
26733 Value is an argument. This value is at the offset stored within the
26734 symbol inside the frame's argument list.
26735 @findex SYMBOL_LOC_REF_ARG
26736 @findex gdb.SYMBOL_LOC_REF_ARG
26737 @item gdb.SYMBOL_LOC_REF_ARG
26738 Value address is stored in the frame's argument list. Just like
26739 @code{LOC_ARG} except that the value's address is stored at the
26740 offset, not the value itself.
26741 @findex SYMBOL_LOC_REGPARM_ADDR
26742 @findex gdb.SYMBOL_LOC_REGPARM_ADDR
26743 @item gdb.SYMBOL_LOC_REGPARM_ADDR
26744 Value is a specified register. Just like @code{LOC_REGISTER} except
26745 the register holds the address of the argument instead of the argument
26746 itself.
26747 @findex SYMBOL_LOC_LOCAL
26748 @findex gdb.SYMBOL_LOC_LOCAL
26749 @item gdb.SYMBOL_LOC_LOCAL
26750 Value is a local variable.
26751 @findex SYMBOL_LOC_TYPEDEF
26752 @findex gdb.SYMBOL_LOC_TYPEDEF
26753 @item gdb.SYMBOL_LOC_TYPEDEF
26754 Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
26755 have this class.
26756 @findex SYMBOL_LOC_BLOCK
26757 @findex gdb.SYMBOL_LOC_BLOCK
26758 @item gdb.SYMBOL_LOC_BLOCK
26759 Value is a block.
26760 @findex SYMBOL_LOC_CONST_BYTES
26761 @findex gdb.SYMBOL_LOC_CONST_BYTES
26762 @item gdb.SYMBOL_LOC_CONST_BYTES
26763 Value is a byte-sequence.
26764 @findex SYMBOL_LOC_UNRESOLVED
26765 @findex gdb.SYMBOL_LOC_UNRESOLVED
26766 @item gdb.SYMBOL_LOC_UNRESOLVED
26767 Value is at a fixed address, but the address of the variable has to be
26768 determined from the minimal symbol table whenever the variable is
26769 referenced.
26770 @findex SYMBOL_LOC_OPTIMIZED_OUT
26771 @findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
26772 @item gdb.SYMBOL_LOC_OPTIMIZED_OUT
26773 The value does not actually exist in the program.
26774 @findex SYMBOL_LOC_COMPUTED
26775 @findex gdb.SYMBOL_LOC_COMPUTED
26776 @item gdb.SYMBOL_LOC_COMPUTED
26777 The value's address is a computed location.
26778 @end table
26779
26780 @node Symbol Tables In Python
26781 @subsubsection Symbol table representation in Python.
26782
26783 @cindex symbol tables in python
26784 @tindex gdb.Symtab
26785 @tindex gdb.Symtab_and_line
26786
26787 Access to symbol table data maintained by @value{GDBN} on the inferior
26788 is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
26789 @code{gdb.Symtab}. Symbol table and line data for a frame is returned
26790 from the @code{find_sal} method in @code{gdb.Frame} object.
26791 @xref{Frames In Python}.
26792
26793 For more information on @value{GDBN}'s symbol table management, see
26794 @ref{Symbols, ,Examining the Symbol Table}, for more information.
26795
26796 A @code{gdb.Symtab_and_line} object has the following attributes:
26797
26798 @defvar Symtab_and_line.symtab
26799 The symbol table object (@code{gdb.Symtab}) for this frame.
26800 This attribute is not writable.
26801 @end defvar
26802
26803 @defvar Symtab_and_line.pc
26804 Indicates the start of the address range occupied by code for the
26805 current source line. This attribute is not writable.
26806 @end defvar
26807
26808 @defvar Symtab_and_line.last
26809 Indicates the end of the address range occupied by code for the current
26810 source line. This attribute is not writable.
26811 @end defvar
26812
26813 @defvar Symtab_and_line.line
26814 Indicates the current line number for this object. This
26815 attribute is not writable.
26816 @end defvar
26817
26818 A @code{gdb.Symtab_and_line} object has the following methods:
26819
26820 @defun Symtab_and_line.is_valid ()
26821 Returns @code{True} if the @code{gdb.Symtab_and_line} object is valid,
26822 @code{False} if not. A @code{gdb.Symtab_and_line} object can become
26823 invalid if the Symbol table and line object it refers to does not
26824 exist in @value{GDBN} any longer. All other
26825 @code{gdb.Symtab_and_line} methods will throw an exception if it is
26826 invalid at the time the method is called.
26827 @end defun
26828
26829 A @code{gdb.Symtab} object has the following attributes:
26830
26831 @defvar Symtab.filename
26832 The symbol table's source filename. This attribute is not writable.
26833 @end defvar
26834
26835 @defvar Symtab.objfile
26836 The symbol table's backing object file. @xref{Objfiles In Python}.
26837 This attribute is not writable.
26838 @end defvar
26839
26840 A @code{gdb.Symtab} object has the following methods:
26841
26842 @defun Symtab.is_valid ()
26843 Returns @code{True} if the @code{gdb.Symtab} object is valid,
26844 @code{False} if not. A @code{gdb.Symtab} object can become invalid if
26845 the symbol table it refers to does not exist in @value{GDBN} any
26846 longer. All other @code{gdb.Symtab} methods will throw an exception
26847 if it is invalid at the time the method is called.
26848 @end defun
26849
26850 @defun Symtab.fullname ()
26851 Return the symbol table's source absolute file name.
26852 @end defun
26853
26854 @defun Symtab.global_block ()
26855 Return the global block of the underlying symbol table.
26856 @xref{Blocks In Python}.
26857 @end defun
26858
26859 @defun Symtab.static_block ()
26860 Return the static block of the underlying symbol table.
26861 @xref{Blocks In Python}.
26862 @end defun
26863
26864 @node Breakpoints In Python
26865 @subsubsection Manipulating breakpoints using Python
26866
26867 @cindex breakpoints in python
26868 @tindex gdb.Breakpoint
26869
26870 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
26871 class.
26872
26873 @defun Breakpoint.__init__ (spec @r{[}, type @r{[}, wp_class @r{[},internal@r{]]]})
26874 Create a new breakpoint. @var{spec} is a string naming the
26875 location of the breakpoint, or an expression that defines a
26876 watchpoint. The contents can be any location recognized by the
26877 @code{break} command, or in the case of a watchpoint, by the @code{watch}
26878 command. The optional @var{type} denotes the breakpoint to create
26879 from the types defined later in this chapter. This argument can be
26880 either: @code{gdb.BP_BREAKPOINT} or @code{gdb.BP_WATCHPOINT}. @var{type}
26881 defaults to @code{gdb.BP_BREAKPOINT}. The optional @var{internal} argument
26882 allows the breakpoint to become invisible to the user. The breakpoint
26883 will neither be reported when created, nor will it be listed in the
26884 output from @code{info breakpoints} (but will be listed with the
26885 @code{maint info breakpoints} command). The optional @var{wp_class}
26886 argument defines the class of watchpoint to create, if @var{type} is
26887 @code{gdb.BP_WATCHPOINT}. If a watchpoint class is not provided, it is
26888 assumed to be a @code{gdb.WP_WRITE} class.
26889 @end defun
26890
26891 @defun Breakpoint.stop (self)
26892 The @code{gdb.Breakpoint} class can be sub-classed and, in
26893 particular, you may choose to implement the @code{stop} method.
26894 If this method is defined as a sub-class of @code{gdb.Breakpoint},
26895 it will be called when the inferior reaches any location of a
26896 breakpoint which instantiates that sub-class. If the method returns
26897 @code{True}, the inferior will be stopped at the location of the
26898 breakpoint, otherwise the inferior will continue.
26899
26900 If there are multiple breakpoints at the same location with a
26901 @code{stop} method, each one will be called regardless of the
26902 return status of the previous. This ensures that all @code{stop}
26903 methods have a chance to execute at that location. In this scenario
26904 if one of the methods returns @code{True} but the others return
26905 @code{False}, the inferior will still be stopped.
26906
26907 You should not alter the execution state of the inferior (i.e.@:, step,
26908 next, etc.), alter the current frame context (i.e.@:, change the current
26909 active frame), or alter, add or delete any breakpoint. As a general
26910 rule, you should not alter any data within @value{GDBN} or the inferior
26911 at this time.
26912
26913 Example @code{stop} implementation:
26914
26915 @smallexample
26916 class MyBreakpoint (gdb.Breakpoint):
26917 def stop (self):
26918 inf_val = gdb.parse_and_eval("foo")
26919 if inf_val == 3:
26920 return True
26921 return False
26922 @end smallexample
26923 @end defun
26924
26925 The available watchpoint types represented by constants are defined in the
26926 @code{gdb} module:
26927
26928 @table @code
26929 @findex WP_READ
26930 @findex gdb.WP_READ
26931 @item gdb.WP_READ
26932 Read only watchpoint.
26933
26934 @findex WP_WRITE
26935 @findex gdb.WP_WRITE
26936 @item gdb.WP_WRITE
26937 Write only watchpoint.
26938
26939 @findex WP_ACCESS
26940 @findex gdb.WP_ACCESS
26941 @item gdb.WP_ACCESS
26942 Read/Write watchpoint.
26943 @end table
26944
26945 @defun Breakpoint.is_valid ()
26946 Return @code{True} if this @code{Breakpoint} object is valid,
26947 @code{False} otherwise. A @code{Breakpoint} object can become invalid
26948 if the user deletes the breakpoint. In this case, the object still
26949 exists, but the underlying breakpoint does not. In the cases of
26950 watchpoint scope, the watchpoint remains valid even if execution of the
26951 inferior leaves the scope of that watchpoint.
26952 @end defun
26953
26954 @defun Breakpoint.delete
26955 Permanently deletes the @value{GDBN} breakpoint. This also
26956 invalidates the Python @code{Breakpoint} object. Any further access
26957 to this object's attributes or methods will raise an error.
26958 @end defun
26959
26960 @defvar Breakpoint.enabled
26961 This attribute is @code{True} if the breakpoint is enabled, and
26962 @code{False} otherwise. This attribute is writable.
26963 @end defvar
26964
26965 @defvar Breakpoint.silent
26966 This attribute is @code{True} if the breakpoint is silent, and
26967 @code{False} otherwise. This attribute is writable.
26968
26969 Note that a breakpoint can also be silent if it has commands and the
26970 first command is @code{silent}. This is not reported by the
26971 @code{silent} attribute.
26972 @end defvar
26973
26974 @defvar Breakpoint.thread
26975 If the breakpoint is thread-specific, this attribute holds the thread
26976 id. If the breakpoint is not thread-specific, this attribute is
26977 @code{None}. This attribute is writable.
26978 @end defvar
26979
26980 @defvar Breakpoint.task
26981 If the breakpoint is Ada task-specific, this attribute holds the Ada task
26982 id. If the breakpoint is not task-specific (or the underlying
26983 language is not Ada), this attribute is @code{None}. This attribute
26984 is writable.
26985 @end defvar
26986
26987 @defvar Breakpoint.ignore_count
26988 This attribute holds the ignore count for the breakpoint, an integer.
26989 This attribute is writable.
26990 @end defvar
26991
26992 @defvar Breakpoint.number
26993 This attribute holds the breakpoint's number --- the identifier used by
26994 the user to manipulate the breakpoint. This attribute is not writable.
26995 @end defvar
26996
26997 @defvar Breakpoint.type
26998 This attribute holds the breakpoint's type --- the identifier used to
26999 determine the actual breakpoint type or use-case. This attribute is not
27000 writable.
27001 @end defvar
27002
27003 @defvar Breakpoint.visible
27004 This attribute tells whether the breakpoint is visible to the user
27005 when set, or when the @samp{info breakpoints} command is run. This
27006 attribute is not writable.
27007 @end defvar
27008
27009 The available types are represented by constants defined in the @code{gdb}
27010 module:
27011
27012 @table @code
27013 @findex BP_BREAKPOINT
27014 @findex gdb.BP_BREAKPOINT
27015 @item gdb.BP_BREAKPOINT
27016 Normal code breakpoint.
27017
27018 @findex BP_WATCHPOINT
27019 @findex gdb.BP_WATCHPOINT
27020 @item gdb.BP_WATCHPOINT
27021 Watchpoint breakpoint.
27022
27023 @findex BP_HARDWARE_WATCHPOINT
27024 @findex gdb.BP_HARDWARE_WATCHPOINT
27025 @item gdb.BP_HARDWARE_WATCHPOINT
27026 Hardware assisted watchpoint.
27027
27028 @findex BP_READ_WATCHPOINT
27029 @findex gdb.BP_READ_WATCHPOINT
27030 @item gdb.BP_READ_WATCHPOINT
27031 Hardware assisted read watchpoint.
27032
27033 @findex BP_ACCESS_WATCHPOINT
27034 @findex gdb.BP_ACCESS_WATCHPOINT
27035 @item gdb.BP_ACCESS_WATCHPOINT
27036 Hardware assisted access watchpoint.
27037 @end table
27038
27039 @defvar Breakpoint.hit_count
27040 This attribute holds the hit count for the breakpoint, an integer.
27041 This attribute is writable, but currently it can only be set to zero.
27042 @end defvar
27043
27044 @defvar Breakpoint.location
27045 This attribute holds the location of the breakpoint, as specified by
27046 the user. It is a string. If the breakpoint does not have a location
27047 (that is, it is a watchpoint) the attribute's value is @code{None}. This
27048 attribute is not writable.
27049 @end defvar
27050
27051 @defvar Breakpoint.expression
27052 This attribute holds a breakpoint expression, as specified by
27053 the user. It is a string. If the breakpoint does not have an
27054 expression (the breakpoint is not a watchpoint) the attribute's value
27055 is @code{None}. This attribute is not writable.
27056 @end defvar
27057
27058 @defvar Breakpoint.condition
27059 This attribute holds the condition of the breakpoint, as specified by
27060 the user. It is a string. If there is no condition, this attribute's
27061 value is @code{None}. This attribute is writable.
27062 @end defvar
27063
27064 @defvar Breakpoint.commands
27065 This attribute holds the commands attached to the breakpoint. If
27066 there are commands, this attribute's value is a string holding all the
27067 commands, separated by newlines. If there are no commands, this
27068 attribute is @code{None}. This attribute is not writable.
27069 @end defvar
27070
27071 @node Finish Breakpoints in Python
27072 @subsubsection Finish Breakpoints
27073
27074 @cindex python finish breakpoints
27075 @tindex gdb.FinishBreakpoint
27076
27077 A finish breakpoint is a temporary breakpoint set at the return address of
27078 a frame, based on the @code{finish} command. @code{gdb.FinishBreakpoint}
27079 extends @code{gdb.Breakpoint}. The underlying breakpoint will be disabled
27080 and deleted when the execution will run out of the breakpoint scope (i.e.@:
27081 @code{Breakpoint.stop} or @code{FinishBreakpoint.out_of_scope} triggered).
27082 Finish breakpoints are thread specific and must be create with the right
27083 thread selected.
27084
27085 @defun FinishBreakpoint.__init__ (@r{[}frame@r{]} @r{[}, internal@r{]})
27086 Create a finish breakpoint at the return address of the @code{gdb.Frame}
27087 object @var{frame}. If @var{frame} is not provided, this defaults to the
27088 newest frame. The optional @var{internal} argument allows the breakpoint to
27089 become invisible to the user. @xref{Breakpoints In Python}, for further
27090 details about this argument.
27091 @end defun
27092
27093 @defun FinishBreakpoint.out_of_scope (self)
27094 In some circumstances (e.g.@: @code{longjmp}, C@t{++} exceptions, @value{GDBN}
27095 @code{return} command, @dots{}), a function may not properly terminate, and
27096 thus never hit the finish breakpoint. When @value{GDBN} notices such a
27097 situation, the @code{out_of_scope} callback will be triggered.
27098
27099 You may want to sub-class @code{gdb.FinishBreakpoint} and override this
27100 method:
27101
27102 @smallexample
27103 class MyFinishBreakpoint (gdb.FinishBreakpoint)
27104 def stop (self):
27105 print "normal finish"
27106 return True
27107
27108 def out_of_scope ():
27109 print "abnormal finish"
27110 @end smallexample
27111 @end defun
27112
27113 @defvar FinishBreakpoint.return_value
27114 When @value{GDBN} is stopped at a finish breakpoint and the frame
27115 used to build the @code{gdb.FinishBreakpoint} object had debug symbols, this
27116 attribute will contain a @code{gdb.Value} object corresponding to the return
27117 value of the function. The value will be @code{None} if the function return
27118 type is @code{void} or if the return value was not computable. This attribute
27119 is not writable.
27120 @end defvar
27121
27122 @node Lazy Strings In Python
27123 @subsubsection Python representation of lazy strings.
27124
27125 @cindex lazy strings in python
27126 @tindex gdb.LazyString
27127
27128 A @dfn{lazy string} is a string whose contents is not retrieved or
27129 encoded until it is needed.
27130
27131 A @code{gdb.LazyString} is represented in @value{GDBN} as an
27132 @code{address} that points to a region of memory, an @code{encoding}
27133 that will be used to encode that region of memory, and a @code{length}
27134 to delimit the region of memory that represents the string. The
27135 difference between a @code{gdb.LazyString} and a string wrapped within
27136 a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
27137 differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
27138 retrieved and encoded during printing, while a @code{gdb.Value}
27139 wrapping a string is immediately retrieved and encoded on creation.
27140
27141 A @code{gdb.LazyString} object has the following functions:
27142
27143 @defun LazyString.value ()
27144 Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
27145 will point to the string in memory, but will lose all the delayed
27146 retrieval, encoding and handling that @value{GDBN} applies to a
27147 @code{gdb.LazyString}.
27148 @end defun
27149
27150 @defvar LazyString.address
27151 This attribute holds the address of the string. This attribute is not
27152 writable.
27153 @end defvar
27154
27155 @defvar LazyString.length
27156 This attribute holds the length of the string in characters. If the
27157 length is -1, then the string will be fetched and encoded up to the
27158 first null of appropriate width. This attribute is not writable.
27159 @end defvar
27160
27161 @defvar LazyString.encoding
27162 This attribute holds the encoding that will be applied to the string
27163 when the string is printed by @value{GDBN}. If the encoding is not
27164 set, or contains an empty string, then @value{GDBN} will select the
27165 most appropriate encoding when the string is printed. This attribute
27166 is not writable.
27167 @end defvar
27168
27169 @defvar LazyString.type
27170 This attribute holds the type that is represented by the lazy string's
27171 type. For a lazy string this will always be a pointer type. To
27172 resolve this to the lazy string's character type, use the type's
27173 @code{target} method. @xref{Types In Python}. This attribute is not
27174 writable.
27175 @end defvar
27176
27177 @node Architectures In Python
27178 @subsubsection Python representation of architectures
27179 @cindex Python architectures
27180
27181 @value{GDBN} uses architecture specific parameters and artifacts in a
27182 number of its various computations. An architecture is represented
27183 by an instance of the @code{gdb.Architecture} class.
27184
27185 A @code{gdb.Architecture} class has the following methods:
27186
27187 @defun Architecture.name ()
27188 Return the name (string value) of the architecture.
27189 @end defun
27190
27191 @defun Architecture.disassemble (@var{start_pc} @r{[}, @var{end_pc} @r{[}, @var{count}@r{]]})
27192 Return a list of disassembled instructions starting from the memory
27193 address @var{start_pc}. The optional arguments @var{end_pc} and
27194 @var{count} determine the number of instructions in the returned list.
27195 If both the optional arguments @var{end_pc} and @var{count} are
27196 specified, then a list of at most @var{count} disassembled instructions
27197 whose start address falls in the closed memory address interval from
27198 @var{start_pc} to @var{end_pc} are returned. If @var{end_pc} is not
27199 specified, but @var{count} is specified, then @var{count} number of
27200 instructions starting from the address @var{start_pc} are returned. If
27201 @var{count} is not specified but @var{end_pc} is specified, then all
27202 instructions whose start address falls in the closed memory address
27203 interval from @var{start_pc} to @var{end_pc} are returned. If neither
27204 @var{end_pc} nor @var{count} are specified, then a single instruction at
27205 @var{start_pc} is returned. For all of these cases, each element of the
27206 returned list is a Python @code{dict} with the following string keys:
27207
27208 @table @code
27209
27210 @item addr
27211 The value corresponding to this key is a Python long integer capturing
27212 the memory address of the instruction.
27213
27214 @item asm
27215 The value corresponding to this key is a string value which represents
27216 the instruction with assembly language mnemonics. The assembly
27217 language flavor used is the same as that specified by the current CLI
27218 variable @code{disassembly-flavor}. @xref{Machine Code}.
27219
27220 @item length
27221 The value corresponding to this key is the length (integer value) of the
27222 instruction in bytes.
27223
27224 @end table
27225 @end defun
27226
27227 @node Python Auto-loading
27228 @subsection Python Auto-loading
27229 @cindex Python auto-loading
27230
27231 When a new object file is read (for example, due to the @code{file}
27232 command, or because the inferior has loaded a shared library),
27233 @value{GDBN} will look for Python support scripts in several ways:
27234 @file{@var{objfile}-gdb.py} (@pxref{objfile-gdb.py file})
27235 and @code{.debug_gdb_scripts} section
27236 (@pxref{dotdebug_gdb_scripts section}).
27237
27238 The auto-loading feature is useful for supplying application-specific
27239 debugging commands and scripts.
27240
27241 Auto-loading can be enabled or disabled,
27242 and the list of auto-loaded scripts can be printed.
27243
27244 @table @code
27245 @anchor{set auto-load python-scripts}
27246 @kindex set auto-load python-scripts
27247 @item set auto-load python-scripts [on|off]
27248 Enable or disable the auto-loading of Python scripts.
27249
27250 @anchor{show auto-load python-scripts}
27251 @kindex show auto-load python-scripts
27252 @item show auto-load python-scripts
27253 Show whether auto-loading of Python scripts is enabled or disabled.
27254
27255 @anchor{info auto-load python-scripts}
27256 @kindex info auto-load python-scripts
27257 @cindex print list of auto-loaded Python scripts
27258 @item info auto-load python-scripts [@var{regexp}]
27259 Print the list of all Python scripts that @value{GDBN} auto-loaded.
27260
27261 Also printed is the list of Python scripts that were mentioned in
27262 the @code{.debug_gdb_scripts} section and were not found
27263 (@pxref{dotdebug_gdb_scripts section}).
27264 This is useful because their names are not printed when @value{GDBN}
27265 tries to load them and fails. There may be many of them, and printing
27266 an error message for each one is problematic.
27267
27268 If @var{regexp} is supplied only Python scripts with matching names are printed.
27269
27270 Example:
27271
27272 @smallexample
27273 (gdb) info auto-load python-scripts
27274 Loaded Script
27275 Yes py-section-script.py
27276 full name: /tmp/py-section-script.py
27277 No my-foo-pretty-printers.py
27278 @end smallexample
27279 @end table
27280
27281 When reading an auto-loaded file, @value{GDBN} sets the
27282 @dfn{current objfile}. This is available via the @code{gdb.current_objfile}
27283 function (@pxref{Objfiles In Python}). This can be useful for
27284 registering objfile-specific pretty-printers and frame-filters.
27285
27286 @menu
27287 * objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
27288 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
27289 * Which flavor to choose?::
27290 @end menu
27291
27292 @node objfile-gdb.py file
27293 @subsubsection The @file{@var{objfile}-gdb.py} file
27294 @cindex @file{@var{objfile}-gdb.py}
27295
27296 When a new object file is read, @value{GDBN} looks for
27297 a file named @file{@var{objfile}-gdb.py} (we call it @var{script-name} below),
27298 where @var{objfile} is the object file's real name, formed by ensuring
27299 that the file name is absolute, following all symlinks, and resolving
27300 @code{.} and @code{..} components. If this file exists and is
27301 readable, @value{GDBN} will evaluate it as a Python script.
27302
27303 If this file does not exist, then @value{GDBN} will look for
27304 @var{script-name} file in all of the directories as specified below.
27305
27306 Note that loading of this script file also requires accordingly configured
27307 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27308
27309 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27310 scripts normally according to its @file{.exe} filename. But if no scripts are
27311 found @value{GDBN} also tries script filenames matching the object file without
27312 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27313 is attempted on any platform. This makes the script filenames compatible
27314 between Unix and MS-Windows hosts.
27315
27316 @table @code
27317 @anchor{set auto-load scripts-directory}
27318 @kindex set auto-load scripts-directory
27319 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27320 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27321 may be delimited by the host platform path separator in use
27322 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27323
27324 Each entry here needs to be covered also by the security setting
27325 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27326
27327 @anchor{with-auto-load-dir}
27328 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27329 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27330 configuration option @option{--with-auto-load-dir}.
27331
27332 Any reference to @file{$debugdir} will get replaced by
27333 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27334 reference to @file{$datadir} will get replaced by @var{data-directory} which is
27335 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27336 @file{$datadir} must be placed as a directory component --- either alone or
27337 delimited by @file{/} or @file{\} directory separators, depending on the host
27338 platform.
27339
27340 The list of directories uses path separator (@samp{:} on GNU and Unix
27341 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27342 to the @env{PATH} environment variable.
27343
27344 @anchor{show auto-load scripts-directory}
27345 @kindex show auto-load scripts-directory
27346 @item show auto-load scripts-directory
27347 Show @value{GDBN} auto-loaded scripts location.
27348 @end table
27349
27350 @value{GDBN} does not track which files it has already auto-loaded this way.
27351 @value{GDBN} will load the associated script every time the corresponding
27352 @var{objfile} is opened.
27353 So your @file{-gdb.py} file should be careful to avoid errors if it
27354 is evaluated more than once.
27355
27356 @node dotdebug_gdb_scripts section
27357 @subsubsection The @code{.debug_gdb_scripts} section
27358 @cindex @code{.debug_gdb_scripts} section
27359
27360 For systems using file formats like ELF and COFF,
27361 when @value{GDBN} loads a new object file
27362 it will look for a special section named @samp{.debug_gdb_scripts}.
27363 If this section exists, its contents is a list of names of scripts to load.
27364
27365 @value{GDBN} will look for each specified script file first in the
27366 current directory and then along the source search path
27367 (@pxref{Source Path, ,Specifying Source Directories}),
27368 except that @file{$cdir} is not searched, since the compilation
27369 directory is not relevant to scripts.
27370
27371 Entries can be placed in section @code{.debug_gdb_scripts} with,
27372 for example, this GCC macro:
27373
27374 @example
27375 /* Note: The "MS" section flags are to remove duplicates. */
27376 #define DEFINE_GDB_SCRIPT(script_name) \
27377 asm("\
27378 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27379 .byte 1\n\
27380 .asciz \"" script_name "\"\n\
27381 .popsection \n\
27382 ");
27383 @end example
27384
27385 @noindent
27386 Then one can reference the macro in a header or source file like this:
27387
27388 @example
27389 DEFINE_GDB_SCRIPT ("my-app-scripts.py")
27390 @end example
27391
27392 The script name may include directories if desired.
27393
27394 Note that loading of this script file also requires accordingly configured
27395 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27396
27397 If the macro is put in a header, any application or library
27398 using this header will get a reference to the specified script.
27399
27400 @node Which flavor to choose?
27401 @subsubsection Which flavor to choose?
27402
27403 Given the multiple ways of auto-loading Python scripts, it might not always
27404 be clear which one to choose. This section provides some guidance.
27405
27406 Benefits of the @file{-gdb.py} way:
27407
27408 @itemize @bullet
27409 @item
27410 Can be used with file formats that don't support multiple sections.
27411
27412 @item
27413 Ease of finding scripts for public libraries.
27414
27415 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27416 in the source search path.
27417 For publicly installed libraries, e.g., @file{libstdc++}, there typically
27418 isn't a source directory in which to find the script.
27419
27420 @item
27421 Doesn't require source code additions.
27422 @end itemize
27423
27424 Benefits of the @code{.debug_gdb_scripts} way:
27425
27426 @itemize @bullet
27427 @item
27428 Works with static linking.
27429
27430 Scripts for libraries done the @file{-gdb.py} way require an objfile to
27431 trigger their loading. When an application is statically linked the only
27432 objfile available is the executable, and it is cumbersome to attach all the
27433 scripts from all the input libraries to the executable's @file{-gdb.py} script.
27434
27435 @item
27436 Works with classes that are entirely inlined.
27437
27438 Some classes can be entirely inlined, and thus there may not be an associated
27439 shared library to attach a @file{-gdb.py} script to.
27440
27441 @item
27442 Scripts needn't be copied out of the source tree.
27443
27444 In some circumstances, apps can be built out of large collections of internal
27445 libraries, and the build infrastructure necessary to install the
27446 @file{-gdb.py} scripts in a place where @value{GDBN} can find them is
27447 cumbersome. It may be easier to specify the scripts in the
27448 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
27449 top of the source tree to the source search path.
27450 @end itemize
27451
27452 @node Python modules
27453 @subsection Python modules
27454 @cindex python modules
27455
27456 @value{GDBN} comes with several modules to assist writing Python code.
27457
27458 @menu
27459 * gdb.printing:: Building and registering pretty-printers.
27460 * gdb.types:: Utilities for working with types.
27461 * gdb.prompt:: Utilities for prompt value substitution.
27462 @end menu
27463
27464 @node gdb.printing
27465 @subsubsection gdb.printing
27466 @cindex gdb.printing
27467
27468 This module provides a collection of utilities for working with
27469 pretty-printers.
27470
27471 @table @code
27472 @item PrettyPrinter (@var{name}, @var{subprinters}=None)
27473 This class specifies the API that makes @samp{info pretty-printer},
27474 @samp{enable pretty-printer} and @samp{disable pretty-printer} work.
27475 Pretty-printers should generally inherit from this class.
27476
27477 @item SubPrettyPrinter (@var{name})
27478 For printers that handle multiple types, this class specifies the
27479 corresponding API for the subprinters.
27480
27481 @item RegexpCollectionPrettyPrinter (@var{name})
27482 Utility class for handling multiple printers, all recognized via
27483 regular expressions.
27484 @xref{Writing a Pretty-Printer}, for an example.
27485
27486 @item FlagEnumerationPrinter (@var{name})
27487 A pretty-printer which handles printing of @code{enum} values. Unlike
27488 @value{GDBN}'s built-in @code{enum} printing, this printer attempts to
27489 work properly when there is some overlap between the enumeration
27490 constants. @var{name} is the name of the printer and also the name of
27491 the @code{enum} type to look up.
27492
27493 @item register_pretty_printer (@var{obj}, @var{printer}, @var{replace}=False)
27494 Register @var{printer} with the pretty-printer list of @var{obj}.
27495 If @var{replace} is @code{True} then any existing copy of the printer
27496 is replaced. Otherwise a @code{RuntimeError} exception is raised
27497 if a printer with the same name already exists.
27498 @end table
27499
27500 @node gdb.types
27501 @subsubsection gdb.types
27502 @cindex gdb.types
27503
27504 This module provides a collection of utilities for working with
27505 @code{gdb.Type} objects.
27506
27507 @table @code
27508 @item get_basic_type (@var{type})
27509 Return @var{type} with const and volatile qualifiers stripped,
27510 and with typedefs and C@t{++} references converted to the underlying type.
27511
27512 C@t{++} example:
27513
27514 @smallexample
27515 typedef const int const_int;
27516 const_int foo (3);
27517 const_int& foo_ref (foo);
27518 int main () @{ return 0; @}
27519 @end smallexample
27520
27521 Then in gdb:
27522
27523 @smallexample
27524 (gdb) start
27525 (gdb) python import gdb.types
27526 (gdb) python foo_ref = gdb.parse_and_eval("foo_ref")
27527 (gdb) python print gdb.types.get_basic_type(foo_ref.type)
27528 int
27529 @end smallexample
27530
27531 @item has_field (@var{type}, @var{field})
27532 Return @code{True} if @var{type}, assumed to be a type with fields
27533 (e.g., a structure or union), has field @var{field}.
27534
27535 @item make_enum_dict (@var{enum_type})
27536 Return a Python @code{dictionary} type produced from @var{enum_type}.
27537
27538 @item deep_items (@var{type})
27539 Returns a Python iterator similar to the standard
27540 @code{gdb.Type.iteritems} method, except that the iterator returned
27541 by @code{deep_items} will recursively traverse anonymous struct or
27542 union fields. For example:
27543
27544 @smallexample
27545 struct A
27546 @{
27547 int a;
27548 union @{
27549 int b0;
27550 int b1;
27551 @};
27552 @};
27553 @end smallexample
27554
27555 @noindent
27556 Then in @value{GDBN}:
27557 @smallexample
27558 (@value{GDBP}) python import gdb.types
27559 (@value{GDBP}) python struct_a = gdb.lookup_type("struct A")
27560 (@value{GDBP}) python print struct_a.keys ()
27561 @{['a', '']@}
27562 (@value{GDBP}) python print [k for k,v in gdb.types.deep_items(struct_a)]
27563 @{['a', 'b0', 'b1']@}
27564 @end smallexample
27565
27566 @item get_type_recognizers ()
27567 Return a list of the enabled type recognizers for the current context.
27568 This is called by @value{GDBN} during the type-printing process
27569 (@pxref{Type Printing API}).
27570
27571 @item apply_type_recognizers (recognizers, type_obj)
27572 Apply the type recognizers, @var{recognizers}, to the type object
27573 @var{type_obj}. If any recognizer returns a string, return that
27574 string. Otherwise, return @code{None}. This is called by
27575 @value{GDBN} during the type-printing process (@pxref{Type Printing
27576 API}).
27577
27578 @item register_type_printer (locus, printer)
27579 This is a convenience function to register a type printer.
27580 @var{printer} is the type printer to register. It must implement the
27581 type printer protocol. @var{locus} is either a @code{gdb.Objfile}, in
27582 which case the printer is registered with that objfile; a
27583 @code{gdb.Progspace}, in which case the printer is registered with
27584 that progspace; or @code{None}, in which case the printer is
27585 registered globally.
27586
27587 @item TypePrinter
27588 This is a base class that implements the type printer protocol. Type
27589 printers are encouraged, but not required, to derive from this class.
27590 It defines a constructor:
27591
27592 @defmethod TypePrinter __init__ (self, name)
27593 Initialize the type printer with the given name. The new printer
27594 starts in the enabled state.
27595 @end defmethod
27596
27597 @end table
27598
27599 @node gdb.prompt
27600 @subsubsection gdb.prompt
27601 @cindex gdb.prompt
27602
27603 This module provides a method for prompt value-substitution.
27604
27605 @table @code
27606 @item substitute_prompt (@var{string})
27607 Return @var{string} with escape sequences substituted by values. Some
27608 escape sequences take arguments. You can specify arguments inside
27609 ``@{@}'' immediately following the escape sequence.
27610
27611 The escape sequences you can pass to this function are:
27612
27613 @table @code
27614 @item \\
27615 Substitute a backslash.
27616 @item \e
27617 Substitute an ESC character.
27618 @item \f
27619 Substitute the selected frame; an argument names a frame parameter.
27620 @item \n
27621 Substitute a newline.
27622 @item \p
27623 Substitute a parameter's value; the argument names the parameter.
27624 @item \r
27625 Substitute a carriage return.
27626 @item \t
27627 Substitute the selected thread; an argument names a thread parameter.
27628 @item \v
27629 Substitute the version of GDB.
27630 @item \w
27631 Substitute the current working directory.
27632 @item \[
27633 Begin a sequence of non-printing characters. These sequences are
27634 typically used with the ESC character, and are not counted in the string
27635 length. Example: ``\[\e[0;34m\](gdb)\[\e[0m\]'' will return a
27636 blue-colored ``(gdb)'' prompt where the length is five.
27637 @item \]
27638 End a sequence of non-printing characters.
27639 @end table
27640
27641 For example:
27642
27643 @smallexample
27644 substitute_prompt (``frame: \f,
27645 print arguments: \p@{print frame-arguments@}'')
27646 @end smallexample
27647
27648 @exdent will return the string:
27649
27650 @smallexample
27651 "frame: main, print arguments: scalars"
27652 @end smallexample
27653 @end table
27654
27655 @node Aliases
27656 @section Creating new spellings of existing commands
27657 @cindex aliases for commands
27658
27659 It is often useful to define alternate spellings of existing commands.
27660 For example, if a new @value{GDBN} command defined in Python has
27661 a long name to type, it is handy to have an abbreviated version of it
27662 that involves less typing.
27663
27664 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27665 of the @samp{step} command even though it is otherwise an ambiguous
27666 abbreviation of other commands like @samp{set} and @samp{show}.
27667
27668 Aliases are also used to provide shortened or more common versions
27669 of multi-word commands. For example, @value{GDBN} provides the
27670 @samp{tty} alias of the @samp{set inferior-tty} command.
27671
27672 You can define a new alias with the @samp{alias} command.
27673
27674 @table @code
27675
27676 @kindex alias
27677 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
27678
27679 @end table
27680
27681 @var{ALIAS} specifies the name of the new alias.
27682 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27683 underscores.
27684
27685 @var{COMMAND} specifies the name of an existing command
27686 that is being aliased.
27687
27688 The @samp{-a} option specifies that the new alias is an abbreviation
27689 of the command. Abbreviations are not shown in command
27690 lists displayed by the @samp{help} command.
27691
27692 The @samp{--} option specifies the end of options,
27693 and is useful when @var{ALIAS} begins with a dash.
27694
27695 Here is a simple example showing how to make an abbreviation
27696 of a command so that there is less to type.
27697 Suppose you were tired of typing @samp{disas}, the current
27698 shortest unambiguous abbreviation of the @samp{disassemble} command
27699 and you wanted an even shorter version named @samp{di}.
27700 The following will accomplish this.
27701
27702 @smallexample
27703 (gdb) alias -a di = disas
27704 @end smallexample
27705
27706 Note that aliases are different from user-defined commands.
27707 With a user-defined command, you also need to write documentation
27708 for it with the @samp{document} command.
27709 An alias automatically picks up the documentation of the existing command.
27710
27711 Here is an example where we make @samp{elms} an abbreviation of
27712 @samp{elements} in the @samp{set print elements} command.
27713 This is to show that you can make an abbreviation of any part
27714 of a command.
27715
27716 @smallexample
27717 (gdb) alias -a set print elms = set print elements
27718 (gdb) alias -a show print elms = show print elements
27719 (gdb) set p elms 20
27720 (gdb) show p elms
27721 Limit on string chars or array elements to print is 200.
27722 @end smallexample
27723
27724 Note that if you are defining an alias of a @samp{set} command,
27725 and you want to have an alias for the corresponding @samp{show}
27726 command, then you need to define the latter separately.
27727
27728 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27729 @var{ALIAS}, just as they are normally.
27730
27731 @smallexample
27732 (gdb) alias -a set pr elms = set p ele
27733 @end smallexample
27734
27735 Finally, here is an example showing the creation of a one word
27736 alias for a more complex command.
27737 This creates alias @samp{spe} of the command @samp{set print elements}.
27738
27739 @smallexample
27740 (gdb) alias spe = set print elements
27741 (gdb) spe 20
27742 @end smallexample
27743
27744 @node Interpreters
27745 @chapter Command Interpreters
27746 @cindex command interpreters
27747
27748 @value{GDBN} supports multiple command interpreters, and some command
27749 infrastructure to allow users or user interface writers to switch
27750 between interpreters or run commands in other interpreters.
27751
27752 @value{GDBN} currently supports two command interpreters, the console
27753 interpreter (sometimes called the command-line interpreter or @sc{cli})
27754 and the machine interface interpreter (or @sc{gdb/mi}). This manual
27755 describes both of these interfaces in great detail.
27756
27757 By default, @value{GDBN} will start with the console interpreter.
27758 However, the user may choose to start @value{GDBN} with another
27759 interpreter by specifying the @option{-i} or @option{--interpreter}
27760 startup options. Defined interpreters include:
27761
27762 @table @code
27763 @item console
27764 @cindex console interpreter
27765 The traditional console or command-line interpreter. This is the most often
27766 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27767 @value{GDBN} will use this interpreter.
27768
27769 @item mi
27770 @cindex mi interpreter
27771 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
27772 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27773 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27774 Interface}.
27775
27776 @item mi2
27777 @cindex mi2 interpreter
27778 The current @sc{gdb/mi} interface.
27779
27780 @item mi1
27781 @cindex mi1 interpreter
27782 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
27783
27784 @end table
27785
27786 @cindex invoke another interpreter
27787 The interpreter being used by @value{GDBN} may not be dynamically
27788 switched at runtime. Although possible, this could lead to a very
27789 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
27790 enters the command "interpreter-set console" in a console view,
27791 @value{GDBN} would switch to using the console interpreter, rendering
27792 the IDE inoperable!
27793
27794 @kindex interpreter-exec
27795 Although you may only choose a single interpreter at startup, you may execute
27796 commands in any interpreter from the current interpreter using the appropriate
27797 command. If you are running the console interpreter, simply use the
27798 @code{interpreter-exec} command:
27799
27800 @smallexample
27801 interpreter-exec mi "-data-list-register-names"
27802 @end smallexample
27803
27804 @sc{gdb/mi} has a similar command, although it is only available in versions of
27805 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27806
27807 @node TUI
27808 @chapter @value{GDBN} Text User Interface
27809 @cindex TUI
27810 @cindex Text User Interface
27811
27812 @menu
27813 * TUI Overview:: TUI overview
27814 * TUI Keys:: TUI key bindings
27815 * TUI Single Key Mode:: TUI single key mode
27816 * TUI Commands:: TUI-specific commands
27817 * TUI Configuration:: TUI configuration variables
27818 @end menu
27819
27820 The @value{GDBN} Text User Interface (TUI) is a terminal
27821 interface which uses the @code{curses} library to show the source
27822 file, the assembly output, the program registers and @value{GDBN}
27823 commands in separate text windows. The TUI mode is supported only
27824 on platforms where a suitable version of the @code{curses} library
27825 is available.
27826
27827 The TUI mode is enabled by default when you invoke @value{GDBN} as
27828 @samp{@value{GDBP} -tui}.
27829 You can also switch in and out of TUI mode while @value{GDBN} runs by
27830 using various TUI commands and key bindings, such as @kbd{C-x C-a}.
27831 @xref{TUI Keys, ,TUI Key Bindings}.
27832
27833 @node TUI Overview
27834 @section TUI Overview
27835
27836 In TUI mode, @value{GDBN} can display several text windows:
27837
27838 @table @emph
27839 @item command
27840 This window is the @value{GDBN} command window with the @value{GDBN}
27841 prompt and the @value{GDBN} output. The @value{GDBN} input is still
27842 managed using readline.
27843
27844 @item source
27845 The source window shows the source file of the program. The current
27846 line and active breakpoints are displayed in this window.
27847
27848 @item assembly
27849 The assembly window shows the disassembly output of the program.
27850
27851 @item register
27852 This window shows the processor registers. Registers are highlighted
27853 when their values change.
27854 @end table
27855
27856 The source and assembly windows show the current program position
27857 by highlighting the current line and marking it with a @samp{>} marker.
27858 Breakpoints are indicated with two markers. The first marker
27859 indicates the breakpoint type:
27860
27861 @table @code
27862 @item B
27863 Breakpoint which was hit at least once.
27864
27865 @item b
27866 Breakpoint which was never hit.
27867
27868 @item H
27869 Hardware breakpoint which was hit at least once.
27870
27871 @item h
27872 Hardware breakpoint which was never hit.
27873 @end table
27874
27875 The second marker indicates whether the breakpoint is enabled or not:
27876
27877 @table @code
27878 @item +
27879 Breakpoint is enabled.
27880
27881 @item -
27882 Breakpoint is disabled.
27883 @end table
27884
27885 The source, assembly and register windows are updated when the current
27886 thread changes, when the frame changes, or when the program counter
27887 changes.
27888
27889 These windows are not all visible at the same time. The command
27890 window is always visible. The others can be arranged in several
27891 layouts:
27892
27893 @itemize @bullet
27894 @item
27895 source only,
27896
27897 @item
27898 assembly only,
27899
27900 @item
27901 source and assembly,
27902
27903 @item
27904 source and registers, or
27905
27906 @item
27907 assembly and registers.
27908 @end itemize
27909
27910 A status line above the command window shows the following information:
27911
27912 @table @emph
27913 @item target
27914 Indicates the current @value{GDBN} target.
27915 (@pxref{Targets, ,Specifying a Debugging Target}).
27916
27917 @item process
27918 Gives the current process or thread number.
27919 When no process is being debugged, this field is set to @code{No process}.
27920
27921 @item function
27922 Gives the current function name for the selected frame.
27923 The name is demangled if demangling is turned on (@pxref{Print Settings}).
27924 When there is no symbol corresponding to the current program counter,
27925 the string @code{??} is displayed.
27926
27927 @item line
27928 Indicates the current line number for the selected frame.
27929 When the current line number is not known, the string @code{??} is displayed.
27930
27931 @item pc
27932 Indicates the current program counter address.
27933 @end table
27934
27935 @node TUI Keys
27936 @section TUI Key Bindings
27937 @cindex TUI key bindings
27938
27939 The TUI installs several key bindings in the readline keymaps
27940 @ifset SYSTEM_READLINE
27941 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27942 @end ifset
27943 @ifclear SYSTEM_READLINE
27944 (@pxref{Command Line Editing}).
27945 @end ifclear
27946 The following key bindings are installed for both TUI mode and the
27947 @value{GDBN} standard mode.
27948
27949 @table @kbd
27950 @kindex C-x C-a
27951 @item C-x C-a
27952 @kindex C-x a
27953 @itemx C-x a
27954 @kindex C-x A
27955 @itemx C-x A
27956 Enter or leave the TUI mode. When leaving the TUI mode,
27957 the curses window management stops and @value{GDBN} operates using
27958 its standard mode, writing on the terminal directly. When reentering
27959 the TUI mode, control is given back to the curses windows.
27960 The screen is then refreshed.
27961
27962 @kindex C-x 1
27963 @item C-x 1
27964 Use a TUI layout with only one window. The layout will
27965 either be @samp{source} or @samp{assembly}. When the TUI mode
27966 is not active, it will switch to the TUI mode.
27967
27968 Think of this key binding as the Emacs @kbd{C-x 1} binding.
27969
27970 @kindex C-x 2
27971 @item C-x 2
27972 Use a TUI layout with at least two windows. When the current
27973 layout already has two windows, the next layout with two windows is used.
27974 When a new layout is chosen, one window will always be common to the
27975 previous layout and the new one.
27976
27977 Think of it as the Emacs @kbd{C-x 2} binding.
27978
27979 @kindex C-x o
27980 @item C-x o
27981 Change the active window. The TUI associates several key bindings
27982 (like scrolling and arrow keys) with the active window. This command
27983 gives the focus to the next TUI window.
27984
27985 Think of it as the Emacs @kbd{C-x o} binding.
27986
27987 @kindex C-x s
27988 @item C-x s
27989 Switch in and out of the TUI SingleKey mode that binds single
27990 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
27991 @end table
27992
27993 The following key bindings only work in the TUI mode:
27994
27995 @table @asis
27996 @kindex PgUp
27997 @item @key{PgUp}
27998 Scroll the active window one page up.
27999
28000 @kindex PgDn
28001 @item @key{PgDn}
28002 Scroll the active window one page down.
28003
28004 @kindex Up
28005 @item @key{Up}
28006 Scroll the active window one line up.
28007
28008 @kindex Down
28009 @item @key{Down}
28010 Scroll the active window one line down.
28011
28012 @kindex Left
28013 @item @key{Left}
28014 Scroll the active window one column left.
28015
28016 @kindex Right
28017 @item @key{Right}
28018 Scroll the active window one column right.
28019
28020 @kindex C-L
28021 @item @kbd{C-L}
28022 Refresh the screen.
28023 @end table
28024
28025 Because the arrow keys scroll the active window in the TUI mode, they
28026 are not available for their normal use by readline unless the command
28027 window has the focus. When another window is active, you must use
28028 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28029 and @kbd{C-f} to control the command window.
28030
28031 @node TUI Single Key Mode
28032 @section TUI Single Key Mode
28033 @cindex TUI single key mode
28034
28035 The TUI also provides a @dfn{SingleKey} mode, which binds several
28036 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28037 switch into this mode, where the following key bindings are used:
28038
28039 @table @kbd
28040 @kindex c @r{(SingleKey TUI key)}
28041 @item c
28042 continue
28043
28044 @kindex d @r{(SingleKey TUI key)}
28045 @item d
28046 down
28047
28048 @kindex f @r{(SingleKey TUI key)}
28049 @item f
28050 finish
28051
28052 @kindex n @r{(SingleKey TUI key)}
28053 @item n
28054 next
28055
28056 @kindex q @r{(SingleKey TUI key)}
28057 @item q
28058 exit the SingleKey mode.
28059
28060 @kindex r @r{(SingleKey TUI key)}
28061 @item r
28062 run
28063
28064 @kindex s @r{(SingleKey TUI key)}
28065 @item s
28066 step
28067
28068 @kindex u @r{(SingleKey TUI key)}
28069 @item u
28070 up
28071
28072 @kindex v @r{(SingleKey TUI key)}
28073 @item v
28074 info locals
28075
28076 @kindex w @r{(SingleKey TUI key)}
28077 @item w
28078 where
28079 @end table
28080
28081 Other keys temporarily switch to the @value{GDBN} command prompt.
28082 The key that was pressed is inserted in the editing buffer so that
28083 it is possible to type most @value{GDBN} commands without interaction
28084 with the TUI SingleKey mode. Once the command is entered the TUI
28085 SingleKey mode is restored. The only way to permanently leave
28086 this mode is by typing @kbd{q} or @kbd{C-x s}.
28087
28088
28089 @node TUI Commands
28090 @section TUI-specific Commands
28091 @cindex TUI commands
28092
28093 The TUI has specific commands to control the text windows.
28094 These commands are always available, even when @value{GDBN} is not in
28095 the TUI mode. When @value{GDBN} is in the standard mode, most
28096 of these commands will automatically switch to the TUI mode.
28097
28098 Note that if @value{GDBN}'s @code{stdout} is not connected to a
28099 terminal, or @value{GDBN} has been started with the machine interface
28100 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28101 these commands will fail with an error, because it would not be
28102 possible or desirable to enable curses window management.
28103
28104 @table @code
28105 @item info win
28106 @kindex info win
28107 List and give the size of all displayed windows.
28108
28109 @item layout next
28110 @kindex layout
28111 Display the next layout.
28112
28113 @item layout prev
28114 Display the previous layout.
28115
28116 @item layout src
28117 Display the source window only.
28118
28119 @item layout asm
28120 Display the assembly window only.
28121
28122 @item layout split
28123 Display the source and assembly window.
28124
28125 @item layout regs
28126 Display the register window together with the source or assembly window.
28127
28128 @item focus next
28129 @kindex focus
28130 Make the next window active for scrolling.
28131
28132 @item focus prev
28133 Make the previous window active for scrolling.
28134
28135 @item focus src
28136 Make the source window active for scrolling.
28137
28138 @item focus asm
28139 Make the assembly window active for scrolling.
28140
28141 @item focus regs
28142 Make the register window active for scrolling.
28143
28144 @item focus cmd
28145 Make the command window active for scrolling.
28146
28147 @item refresh
28148 @kindex refresh
28149 Refresh the screen. This is similar to typing @kbd{C-L}.
28150
28151 @item tui reg float
28152 @kindex tui reg
28153 Show the floating point registers in the register window.
28154
28155 @item tui reg general
28156 Show the general registers in the register window.
28157
28158 @item tui reg next
28159 Show the next register group. The list of register groups as well as
28160 their order is target specific. The predefined register groups are the
28161 following: @code{general}, @code{float}, @code{system}, @code{vector},
28162 @code{all}, @code{save}, @code{restore}.
28163
28164 @item tui reg system
28165 Show the system registers in the register window.
28166
28167 @item update
28168 @kindex update
28169 Update the source window and the current execution point.
28170
28171 @item winheight @var{name} +@var{count}
28172 @itemx winheight @var{name} -@var{count}
28173 @kindex winheight
28174 Change the height of the window @var{name} by @var{count}
28175 lines. Positive counts increase the height, while negative counts
28176 decrease it.
28177
28178 @item tabset @var{nchars}
28179 @kindex tabset
28180 Set the width of tab stops to be @var{nchars} characters.
28181 @end table
28182
28183 @node TUI Configuration
28184 @section TUI Configuration Variables
28185 @cindex TUI configuration variables
28186
28187 Several configuration variables control the appearance of TUI windows.
28188
28189 @table @code
28190 @item set tui border-kind @var{kind}
28191 @kindex set tui border-kind
28192 Select the border appearance for the source, assembly and register windows.
28193 The possible values are the following:
28194 @table @code
28195 @item space
28196 Use a space character to draw the border.
28197
28198 @item ascii
28199 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28200
28201 @item acs
28202 Use the Alternate Character Set to draw the border. The border is
28203 drawn using character line graphics if the terminal supports them.
28204 @end table
28205
28206 @item set tui border-mode @var{mode}
28207 @kindex set tui border-mode
28208 @itemx set tui active-border-mode @var{mode}
28209 @kindex set tui active-border-mode
28210 Select the display attributes for the borders of the inactive windows
28211 or the active window. The @var{mode} can be one of the following:
28212 @table @code
28213 @item normal
28214 Use normal attributes to display the border.
28215
28216 @item standout
28217 Use standout mode.
28218
28219 @item reverse
28220 Use reverse video mode.
28221
28222 @item half
28223 Use half bright mode.
28224
28225 @item half-standout
28226 Use half bright and standout mode.
28227
28228 @item bold
28229 Use extra bright or bold mode.
28230
28231 @item bold-standout
28232 Use extra bright or bold and standout mode.
28233 @end table
28234 @end table
28235
28236 @node Emacs
28237 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28238
28239 @cindex Emacs
28240 @cindex @sc{gnu} Emacs
28241 A special interface allows you to use @sc{gnu} Emacs to view (and
28242 edit) the source files for the program you are debugging with
28243 @value{GDBN}.
28244
28245 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28246 executable file you want to debug as an argument. This command starts
28247 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28248 created Emacs buffer.
28249 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28250
28251 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28252 things:
28253
28254 @itemize @bullet
28255 @item
28256 All ``terminal'' input and output goes through an Emacs buffer, called
28257 the GUD buffer.
28258
28259 This applies both to @value{GDBN} commands and their output, and to the input
28260 and output done by the program you are debugging.
28261
28262 This is useful because it means that you can copy the text of previous
28263 commands and input them again; you can even use parts of the output
28264 in this way.
28265
28266 All the facilities of Emacs' Shell mode are available for interacting
28267 with your program. In particular, you can send signals the usual
28268 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28269 stop.
28270
28271 @item
28272 @value{GDBN} displays source code through Emacs.
28273
28274 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28275 source file for that frame and puts an arrow (@samp{=>}) at the
28276 left margin of the current line. Emacs uses a separate buffer for
28277 source display, and splits the screen to show both your @value{GDBN} session
28278 and the source.
28279
28280 Explicit @value{GDBN} @code{list} or search commands still produce output as
28281 usual, but you probably have no reason to use them from Emacs.
28282 @end itemize
28283
28284 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28285 a graphical mode, enabled by default, which provides further buffers
28286 that can control the execution and describe the state of your program.
28287 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28288
28289 If you specify an absolute file name when prompted for the @kbd{M-x
28290 gdb} argument, then Emacs sets your current working directory to where
28291 your program resides. If you only specify the file name, then Emacs
28292 sets your current working directory to the directory associated
28293 with the previous buffer. In this case, @value{GDBN} may find your
28294 program by searching your environment's @code{PATH} variable, but on
28295 some operating systems it might not find the source. So, although the
28296 @value{GDBN} input and output session proceeds normally, the auxiliary
28297 buffer does not display the current source and line of execution.
28298
28299 The initial working directory of @value{GDBN} is printed on the top
28300 line of the GUD buffer and this serves as a default for the commands
28301 that specify files for @value{GDBN} to operate on. @xref{Files,
28302 ,Commands to Specify Files}.
28303
28304 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28305 need to call @value{GDBN} by a different name (for example, if you
28306 keep several configurations around, with different names) you can
28307 customize the Emacs variable @code{gud-gdb-command-name} to run the
28308 one you want.
28309
28310 In the GUD buffer, you can use these special Emacs commands in
28311 addition to the standard Shell mode commands:
28312
28313 @table @kbd
28314 @item C-h m
28315 Describe the features of Emacs' GUD Mode.
28316
28317 @item C-c C-s
28318 Execute to another source line, like the @value{GDBN} @code{step} command; also
28319 update the display window to show the current file and location.
28320
28321 @item C-c C-n
28322 Execute to next source line in this function, skipping all function
28323 calls, like the @value{GDBN} @code{next} command. Then update the display window
28324 to show the current file and location.
28325
28326 @item C-c C-i
28327 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28328 display window accordingly.
28329
28330 @item C-c C-f
28331 Execute until exit from the selected stack frame, like the @value{GDBN}
28332 @code{finish} command.
28333
28334 @item C-c C-r
28335 Continue execution of your program, like the @value{GDBN} @code{continue}
28336 command.
28337
28338 @item C-c <
28339 Go up the number of frames indicated by the numeric argument
28340 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28341 like the @value{GDBN} @code{up} command.
28342
28343 @item C-c >
28344 Go down the number of frames indicated by the numeric argument, like the
28345 @value{GDBN} @code{down} command.
28346 @end table
28347
28348 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28349 tells @value{GDBN} to set a breakpoint on the source line point is on.
28350
28351 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28352 separate frame which shows a backtrace when the GUD buffer is current.
28353 Move point to any frame in the stack and type @key{RET} to make it
28354 become the current frame and display the associated source in the
28355 source buffer. Alternatively, click @kbd{Mouse-2} to make the
28356 selected frame become the current one. In graphical mode, the
28357 speedbar displays watch expressions.
28358
28359 If you accidentally delete the source-display buffer, an easy way to get
28360 it back is to type the command @code{f} in the @value{GDBN} buffer, to
28361 request a frame display; when you run under Emacs, this recreates
28362 the source buffer if necessary to show you the context of the current
28363 frame.
28364
28365 The source files displayed in Emacs are in ordinary Emacs buffers
28366 which are visiting the source files in the usual way. You can edit
28367 the files with these buffers if you wish; but keep in mind that @value{GDBN}
28368 communicates with Emacs in terms of line numbers. If you add or
28369 delete lines from the text, the line numbers that @value{GDBN} knows cease
28370 to correspond properly with the code.
28371
28372 A more detailed description of Emacs' interaction with @value{GDBN} is
28373 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28374 Emacs Manual}).
28375
28376 @node GDB/MI
28377 @chapter The @sc{gdb/mi} Interface
28378
28379 @unnumberedsec Function and Purpose
28380
28381 @cindex @sc{gdb/mi}, its purpose
28382 @sc{gdb/mi} is a line based machine oriented text interface to
28383 @value{GDBN} and is activated by specifying using the
28384 @option{--interpreter} command line option (@pxref{Mode Options}). It
28385 is specifically intended to support the development of systems which
28386 use the debugger as just one small component of a larger system.
28387
28388 This chapter is a specification of the @sc{gdb/mi} interface. It is written
28389 in the form of a reference manual.
28390
28391 Note that @sc{gdb/mi} is still under construction, so some of the
28392 features described below are incomplete and subject to change
28393 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
28394
28395 @unnumberedsec Notation and Terminology
28396
28397 @cindex notational conventions, for @sc{gdb/mi}
28398 This chapter uses the following notation:
28399
28400 @itemize @bullet
28401 @item
28402 @code{|} separates two alternatives.
28403
28404 @item
28405 @code{[ @var{something} ]} indicates that @var{something} is optional:
28406 it may or may not be given.
28407
28408 @item
28409 @code{( @var{group} )*} means that @var{group} inside the parentheses
28410 may repeat zero or more times.
28411
28412 @item
28413 @code{( @var{group} )+} means that @var{group} inside the parentheses
28414 may repeat one or more times.
28415
28416 @item
28417 @code{"@var{string}"} means a literal @var{string}.
28418 @end itemize
28419
28420 @ignore
28421 @heading Dependencies
28422 @end ignore
28423
28424 @menu
28425 * GDB/MI General Design::
28426 * GDB/MI Command Syntax::
28427 * GDB/MI Compatibility with CLI::
28428 * GDB/MI Development and Front Ends::
28429 * GDB/MI Output Records::
28430 * GDB/MI Simple Examples::
28431 * GDB/MI Command Description Format::
28432 * GDB/MI Breakpoint Commands::
28433 * GDB/MI Catchpoint Commands::
28434 * GDB/MI Program Context::
28435 * GDB/MI Thread Commands::
28436 * GDB/MI Ada Tasking Commands::
28437 * GDB/MI Program Execution::
28438 * GDB/MI Stack Manipulation::
28439 * GDB/MI Variable Objects::
28440 * GDB/MI Data Manipulation::
28441 * GDB/MI Tracepoint Commands::
28442 * GDB/MI Symbol Query::
28443 * GDB/MI File Commands::
28444 @ignore
28445 * GDB/MI Kod Commands::
28446 * GDB/MI Memory Overlay Commands::
28447 * GDB/MI Signal Handling Commands::
28448 @end ignore
28449 * GDB/MI Target Manipulation::
28450 * GDB/MI File Transfer Commands::
28451 * GDB/MI Miscellaneous Commands::
28452 @end menu
28453
28454 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28455 @node GDB/MI General Design
28456 @section @sc{gdb/mi} General Design
28457 @cindex GDB/MI General Design
28458
28459 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28460 parts---commands sent to @value{GDBN}, responses to those commands
28461 and notifications. Each command results in exactly one response,
28462 indicating either successful completion of the command, or an error.
28463 For the commands that do not resume the target, the response contains the
28464 requested information. For the commands that resume the target, the
28465 response only indicates whether the target was successfully resumed.
28466 Notifications is the mechanism for reporting changes in the state of the
28467 target, or in @value{GDBN} state, that cannot conveniently be associated with
28468 a command and reported as part of that command response.
28469
28470 The important examples of notifications are:
28471 @itemize @bullet
28472
28473 @item
28474 Exec notifications. These are used to report changes in
28475 target state---when a target is resumed, or stopped. It would not
28476 be feasible to include this information in response of resuming
28477 commands, because one resume commands can result in multiple events in
28478 different threads. Also, quite some time may pass before any event
28479 happens in the target, while a frontend needs to know whether the resuming
28480 command itself was successfully executed.
28481
28482 @item
28483 Console output, and status notifications. Console output
28484 notifications are used to report output of CLI commands, as well as
28485 diagnostics for other commands. Status notifications are used to
28486 report the progress of a long-running operation. Naturally, including
28487 this information in command response would mean no output is produced
28488 until the command is finished, which is undesirable.
28489
28490 @item
28491 General notifications. Commands may have various side effects on
28492 the @value{GDBN} or target state beyond their official purpose. For example,
28493 a command may change the selected thread. Although such changes can
28494 be included in command response, using notification allows for more
28495 orthogonal frontend design.
28496
28497 @end itemize
28498
28499 There's no guarantee that whenever an MI command reports an error,
28500 @value{GDBN} or the target are in any specific state, and especially,
28501 the state is not reverted to the state before the MI command was
28502 processed. Therefore, whenever an MI command results in an error,
28503 we recommend that the frontend refreshes all the information shown in
28504 the user interface.
28505
28506
28507 @menu
28508 * Context management::
28509 * Asynchronous and non-stop modes::
28510 * Thread groups::
28511 @end menu
28512
28513 @node Context management
28514 @subsection Context management
28515
28516 In most cases when @value{GDBN} accesses the target, this access is
28517 done in context of a specific thread and frame (@pxref{Frames}).
28518 Often, even when accessing global data, the target requires that a thread
28519 be specified. The CLI interface maintains the selected thread and frame,
28520 and supplies them to target on each command. This is convenient,
28521 because a command line user would not want to specify that information
28522 explicitly on each command, and because user interacts with
28523 @value{GDBN} via a single terminal, so no confusion is possible as
28524 to what thread and frame are the current ones.
28525
28526 In the case of MI, the concept of selected thread and frame is less
28527 useful. First, a frontend can easily remember this information
28528 itself. Second, a graphical frontend can have more than one window,
28529 each one used for debugging a different thread, and the frontend might
28530 want to access additional threads for internal purposes. This
28531 increases the risk that by relying on implicitly selected thread, the
28532 frontend may be operating on a wrong one. Therefore, each MI command
28533 should explicitly specify which thread and frame to operate on. To
28534 make it possible, each MI command accepts the @samp{--thread} and
28535 @samp{--frame} options, the value to each is @value{GDBN} identifier
28536 for thread and frame to operate on.
28537
28538 Usually, each top-level window in a frontend allows the user to select
28539 a thread and a frame, and remembers the user selection for further
28540 operations. However, in some cases @value{GDBN} may suggest that the
28541 current thread be changed. For example, when stopping on a breakpoint
28542 it is reasonable to switch to the thread where breakpoint is hit. For
28543 another example, if the user issues the CLI @samp{thread} command via
28544 the frontend, it is desirable to change the frontend's selected thread to the
28545 one specified by user. @value{GDBN} communicates the suggestion to
28546 change current thread using the @samp{=thread-selected} notification.
28547 No such notification is available for the selected frame at the moment.
28548
28549 Note that historically, MI shares the selected thread with CLI, so
28550 frontends used the @code{-thread-select} to execute commands in the
28551 right context. However, getting this to work right is cumbersome. The
28552 simplest way is for frontend to emit @code{-thread-select} command
28553 before every command. This doubles the number of commands that need
28554 to be sent. The alternative approach is to suppress @code{-thread-select}
28555 if the selected thread in @value{GDBN} is supposed to be identical to the
28556 thread the frontend wants to operate on. However, getting this
28557 optimization right can be tricky. In particular, if the frontend
28558 sends several commands to @value{GDBN}, and one of the commands changes the
28559 selected thread, then the behaviour of subsequent commands will
28560 change. So, a frontend should either wait for response from such
28561 problematic commands, or explicitly add @code{-thread-select} for
28562 all subsequent commands. No frontend is known to do this exactly
28563 right, so it is suggested to just always pass the @samp{--thread} and
28564 @samp{--frame} options.
28565
28566 @node Asynchronous and non-stop modes
28567 @subsection Asynchronous command execution and non-stop mode
28568
28569 On some targets, @value{GDBN} is capable of processing MI commands
28570 even while the target is running. This is called @dfn{asynchronous
28571 command execution} (@pxref{Background Execution}). The frontend may
28572 specify a preferrence for asynchronous execution using the
28573 @code{-gdb-set target-async 1} command, which should be emitted before
28574 either running the executable or attaching to the target. After the
28575 frontend has started the executable or attached to the target, it can
28576 find if asynchronous execution is enabled using the
28577 @code{-list-target-features} command.
28578
28579 Even if @value{GDBN} can accept a command while target is running,
28580 many commands that access the target do not work when the target is
28581 running. Therefore, asynchronous command execution is most useful
28582 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28583 it is possible to examine the state of one thread, while other threads
28584 are running.
28585
28586 When a given thread is running, MI commands that try to access the
28587 target in the context of that thread may not work, or may work only on
28588 some targets. In particular, commands that try to operate on thread's
28589 stack will not work, on any target. Commands that read memory, or
28590 modify breakpoints, may work or not work, depending on the target. Note
28591 that even commands that operate on global state, such as @code{print},
28592 @code{set}, and breakpoint commands, still access the target in the
28593 context of a specific thread, so frontend should try to find a
28594 stopped thread and perform the operation on that thread (using the
28595 @samp{--thread} option).
28596
28597 Which commands will work in the context of a running thread is
28598 highly target dependent. However, the two commands
28599 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28600 to find the state of a thread, will always work.
28601
28602 @node Thread groups
28603 @subsection Thread groups
28604 @value{GDBN} may be used to debug several processes at the same time.
28605 On some platfroms, @value{GDBN} may support debugging of several
28606 hardware systems, each one having several cores with several different
28607 processes running on each core. This section describes the MI
28608 mechanism to support such debugging scenarios.
28609
28610 The key observation is that regardless of the structure of the
28611 target, MI can have a global list of threads, because most commands that
28612 accept the @samp{--thread} option do not need to know what process that
28613 thread belongs to. Therefore, it is not necessary to introduce
28614 neither additional @samp{--process} option, nor an notion of the
28615 current process in the MI interface. The only strictly new feature
28616 that is required is the ability to find how the threads are grouped
28617 into processes.
28618
28619 To allow the user to discover such grouping, and to support arbitrary
28620 hierarchy of machines/cores/processes, MI introduces the concept of a
28621 @dfn{thread group}. Thread group is a collection of threads and other
28622 thread groups. A thread group always has a string identifier, a type,
28623 and may have additional attributes specific to the type. A new
28624 command, @code{-list-thread-groups}, returns the list of top-level
28625 thread groups, which correspond to processes that @value{GDBN} is
28626 debugging at the moment. By passing an identifier of a thread group
28627 to the @code{-list-thread-groups} command, it is possible to obtain
28628 the members of specific thread group.
28629
28630 To allow the user to easily discover processes, and other objects, he
28631 wishes to debug, a concept of @dfn{available thread group} is
28632 introduced. Available thread group is an thread group that
28633 @value{GDBN} is not debugging, but that can be attached to, using the
28634 @code{-target-attach} command. The list of available top-level thread
28635 groups can be obtained using @samp{-list-thread-groups --available}.
28636 In general, the content of a thread group may be only retrieved only
28637 after attaching to that thread group.
28638
28639 Thread groups are related to inferiors (@pxref{Inferiors and
28640 Programs}). Each inferior corresponds to a thread group of a special
28641 type @samp{process}, and some additional operations are permitted on
28642 such thread groups.
28643
28644 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28645 @node GDB/MI Command Syntax
28646 @section @sc{gdb/mi} Command Syntax
28647
28648 @menu
28649 * GDB/MI Input Syntax::
28650 * GDB/MI Output Syntax::
28651 @end menu
28652
28653 @node GDB/MI Input Syntax
28654 @subsection @sc{gdb/mi} Input Syntax
28655
28656 @cindex input syntax for @sc{gdb/mi}
28657 @cindex @sc{gdb/mi}, input syntax
28658 @table @code
28659 @item @var{command} @expansion{}
28660 @code{@var{cli-command} | @var{mi-command}}
28661
28662 @item @var{cli-command} @expansion{}
28663 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28664 @var{cli-command} is any existing @value{GDBN} CLI command.
28665
28666 @item @var{mi-command} @expansion{}
28667 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28668 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28669
28670 @item @var{token} @expansion{}
28671 "any sequence of digits"
28672
28673 @item @var{option} @expansion{}
28674 @code{"-" @var{parameter} [ " " @var{parameter} ]}
28675
28676 @item @var{parameter} @expansion{}
28677 @code{@var{non-blank-sequence} | @var{c-string}}
28678
28679 @item @var{operation} @expansion{}
28680 @emph{any of the operations described in this chapter}
28681
28682 @item @var{non-blank-sequence} @expansion{}
28683 @emph{anything, provided it doesn't contain special characters such as
28684 "-", @var{nl}, """ and of course " "}
28685
28686 @item @var{c-string} @expansion{}
28687 @code{""" @var{seven-bit-iso-c-string-content} """}
28688
28689 @item @var{nl} @expansion{}
28690 @code{CR | CR-LF}
28691 @end table
28692
28693 @noindent
28694 Notes:
28695
28696 @itemize @bullet
28697 @item
28698 The CLI commands are still handled by the @sc{mi} interpreter; their
28699 output is described below.
28700
28701 @item
28702 The @code{@var{token}}, when present, is passed back when the command
28703 finishes.
28704
28705 @item
28706 Some @sc{mi} commands accept optional arguments as part of the parameter
28707 list. Each option is identified by a leading @samp{-} (dash) and may be
28708 followed by an optional argument parameter. Options occur first in the
28709 parameter list and can be delimited from normal parameters using
28710 @samp{--} (this is useful when some parameters begin with a dash).
28711 @end itemize
28712
28713 Pragmatics:
28714
28715 @itemize @bullet
28716 @item
28717 We want easy access to the existing CLI syntax (for debugging).
28718
28719 @item
28720 We want it to be easy to spot a @sc{mi} operation.
28721 @end itemize
28722
28723 @node GDB/MI Output Syntax
28724 @subsection @sc{gdb/mi} Output Syntax
28725
28726 @cindex output syntax of @sc{gdb/mi}
28727 @cindex @sc{gdb/mi}, output syntax
28728 The output from @sc{gdb/mi} consists of zero or more out-of-band records
28729 followed, optionally, by a single result record. This result record
28730 is for the most recent command. The sequence of output records is
28731 terminated by @samp{(gdb)}.
28732
28733 If an input command was prefixed with a @code{@var{token}} then the
28734 corresponding output for that command will also be prefixed by that same
28735 @var{token}.
28736
28737 @table @code
28738 @item @var{output} @expansion{}
28739 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
28740
28741 @item @var{result-record} @expansion{}
28742 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28743
28744 @item @var{out-of-band-record} @expansion{}
28745 @code{@var{async-record} | @var{stream-record}}
28746
28747 @item @var{async-record} @expansion{}
28748 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28749
28750 @item @var{exec-async-output} @expansion{}
28751 @code{[ @var{token} ] "*" @var{async-output}}
28752
28753 @item @var{status-async-output} @expansion{}
28754 @code{[ @var{token} ] "+" @var{async-output}}
28755
28756 @item @var{notify-async-output} @expansion{}
28757 @code{[ @var{token} ] "=" @var{async-output}}
28758
28759 @item @var{async-output} @expansion{}
28760 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
28761
28762 @item @var{result-class} @expansion{}
28763 @code{"done" | "running" | "connected" | "error" | "exit"}
28764
28765 @item @var{async-class} @expansion{}
28766 @code{"stopped" | @var{others}} (where @var{others} will be added
28767 depending on the needs---this is still in development).
28768
28769 @item @var{result} @expansion{}
28770 @code{ @var{variable} "=" @var{value}}
28771
28772 @item @var{variable} @expansion{}
28773 @code{ @var{string} }
28774
28775 @item @var{value} @expansion{}
28776 @code{ @var{const} | @var{tuple} | @var{list} }
28777
28778 @item @var{const} @expansion{}
28779 @code{@var{c-string}}
28780
28781 @item @var{tuple} @expansion{}
28782 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28783
28784 @item @var{list} @expansion{}
28785 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28786 @var{result} ( "," @var{result} )* "]" }
28787
28788 @item @var{stream-record} @expansion{}
28789 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28790
28791 @item @var{console-stream-output} @expansion{}
28792 @code{"~" @var{c-string}}
28793
28794 @item @var{target-stream-output} @expansion{}
28795 @code{"@@" @var{c-string}}
28796
28797 @item @var{log-stream-output} @expansion{}
28798 @code{"&" @var{c-string}}
28799
28800 @item @var{nl} @expansion{}
28801 @code{CR | CR-LF}
28802
28803 @item @var{token} @expansion{}
28804 @emph{any sequence of digits}.
28805 @end table
28806
28807 @noindent
28808 Notes:
28809
28810 @itemize @bullet
28811 @item
28812 All output sequences end in a single line containing a period.
28813
28814 @item
28815 The @code{@var{token}} is from the corresponding request. Note that
28816 for all async output, while the token is allowed by the grammar and
28817 may be output by future versions of @value{GDBN} for select async
28818 output messages, it is generally omitted. Frontends should treat
28819 all async output as reporting general changes in the state of the
28820 target and there should be no need to associate async output to any
28821 prior command.
28822
28823 @item
28824 @cindex status output in @sc{gdb/mi}
28825 @var{status-async-output} contains on-going status information about the
28826 progress of a slow operation. It can be discarded. All status output is
28827 prefixed by @samp{+}.
28828
28829 @item
28830 @cindex async output in @sc{gdb/mi}
28831 @var{exec-async-output} contains asynchronous state change on the target
28832 (stopped, started, disappeared). All async output is prefixed by
28833 @samp{*}.
28834
28835 @item
28836 @cindex notify output in @sc{gdb/mi}
28837 @var{notify-async-output} contains supplementary information that the
28838 client should handle (e.g., a new breakpoint information). All notify
28839 output is prefixed by @samp{=}.
28840
28841 @item
28842 @cindex console output in @sc{gdb/mi}
28843 @var{console-stream-output} is output that should be displayed as is in the
28844 console. It is the textual response to a CLI command. All the console
28845 output is prefixed by @samp{~}.
28846
28847 @item
28848 @cindex target output in @sc{gdb/mi}
28849 @var{target-stream-output} is the output produced by the target program.
28850 All the target output is prefixed by @samp{@@}.
28851
28852 @item
28853 @cindex log output in @sc{gdb/mi}
28854 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
28855 instance messages that should be displayed as part of an error log. All
28856 the log output is prefixed by @samp{&}.
28857
28858 @item
28859 @cindex list output in @sc{gdb/mi}
28860 New @sc{gdb/mi} commands should only output @var{lists} containing
28861 @var{values}.
28862
28863
28864 @end itemize
28865
28866 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
28867 details about the various output records.
28868
28869 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28870 @node GDB/MI Compatibility with CLI
28871 @section @sc{gdb/mi} Compatibility with CLI
28872
28873 @cindex compatibility, @sc{gdb/mi} and CLI
28874 @cindex @sc{gdb/mi}, compatibility with CLI
28875
28876 For the developers convenience CLI commands can be entered directly,
28877 but there may be some unexpected behaviour. For example, commands
28878 that query the user will behave as if the user replied yes, breakpoint
28879 command lists are not executed and some CLI commands, such as
28880 @code{if}, @code{when} and @code{define}, prompt for further input with
28881 @samp{>}, which is not valid MI output.
28882
28883 This feature may be removed at some stage in the future and it is
28884 recommended that front ends use the @code{-interpreter-exec} command
28885 (@pxref{-interpreter-exec}).
28886
28887 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28888 @node GDB/MI Development and Front Ends
28889 @section @sc{gdb/mi} Development and Front Ends
28890 @cindex @sc{gdb/mi} development
28891
28892 The application which takes the MI output and presents the state of the
28893 program being debugged to the user is called a @dfn{front end}.
28894
28895 Although @sc{gdb/mi} is still incomplete, it is currently being used
28896 by a variety of front ends to @value{GDBN}. This makes it difficult
28897 to introduce new functionality without breaking existing usage. This
28898 section tries to minimize the problems by describing how the protocol
28899 might change.
28900
28901 Some changes in MI need not break a carefully designed front end, and
28902 for these the MI version will remain unchanged. The following is a
28903 list of changes that may occur within one level, so front ends should
28904 parse MI output in a way that can handle them:
28905
28906 @itemize @bullet
28907 @item
28908 New MI commands may be added.
28909
28910 @item
28911 New fields may be added to the output of any MI command.
28912
28913 @item
28914 The range of values for fields with specified values, e.g.,
28915 @code{in_scope} (@pxref{-var-update}) may be extended.
28916
28917 @c The format of field's content e.g type prefix, may change so parse it
28918 @c at your own risk. Yes, in general?
28919
28920 @c The order of fields may change? Shouldn't really matter but it might
28921 @c resolve inconsistencies.
28922 @end itemize
28923
28924 If the changes are likely to break front ends, the MI version level
28925 will be increased by one. This will allow the front end to parse the
28926 output according to the MI version. Apart from mi0, new versions of
28927 @value{GDBN} will not support old versions of MI and it will be the
28928 responsibility of the front end to work with the new one.
28929
28930 @c Starting with mi3, add a new command -mi-version that prints the MI
28931 @c version?
28932
28933 The best way to avoid unexpected changes in MI that might break your front
28934 end is to make your project known to @value{GDBN} developers and
28935 follow development on @email{gdb@@sourceware.org} and
28936 @email{gdb-patches@@sourceware.org}.
28937 @cindex mailing lists
28938
28939 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28940 @node GDB/MI Output Records
28941 @section @sc{gdb/mi} Output Records
28942
28943 @menu
28944 * GDB/MI Result Records::
28945 * GDB/MI Stream Records::
28946 * GDB/MI Async Records::
28947 * GDB/MI Breakpoint Information::
28948 * GDB/MI Frame Information::
28949 * GDB/MI Thread Information::
28950 * GDB/MI Ada Exception Information::
28951 @end menu
28952
28953 @node GDB/MI Result Records
28954 @subsection @sc{gdb/mi} Result Records
28955
28956 @cindex result records in @sc{gdb/mi}
28957 @cindex @sc{gdb/mi}, result records
28958 In addition to a number of out-of-band notifications, the response to a
28959 @sc{gdb/mi} command includes one of the following result indications:
28960
28961 @table @code
28962 @findex ^done
28963 @item "^done" [ "," @var{results} ]
28964 The synchronous operation was successful, @code{@var{results}} are the return
28965 values.
28966
28967 @item "^running"
28968 @findex ^running
28969 This result record is equivalent to @samp{^done}. Historically, it
28970 was output instead of @samp{^done} if the command has resumed the
28971 target. This behaviour is maintained for backward compatibility, but
28972 all frontends should treat @samp{^done} and @samp{^running}
28973 identically and rely on the @samp{*running} output record to determine
28974 which threads are resumed.
28975
28976 @item "^connected"
28977 @findex ^connected
28978 @value{GDBN} has connected to a remote target.
28979
28980 @item "^error" "," @var{c-string}
28981 @findex ^error
28982 The operation failed. The @code{@var{c-string}} contains the corresponding
28983 error message.
28984
28985 @item "^exit"
28986 @findex ^exit
28987 @value{GDBN} has terminated.
28988
28989 @end table
28990
28991 @node GDB/MI Stream Records
28992 @subsection @sc{gdb/mi} Stream Records
28993
28994 @cindex @sc{gdb/mi}, stream records
28995 @cindex stream records in @sc{gdb/mi}
28996 @value{GDBN} internally maintains a number of output streams: the console, the
28997 target, and the log. The output intended for each of these streams is
28998 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
28999
29000 Each stream record begins with a unique @dfn{prefix character} which
29001 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29002 Syntax}). In addition to the prefix, each stream record contains a
29003 @code{@var{string-output}}. This is either raw text (with an implicit new
29004 line) or a quoted C string (which does not contain an implicit newline).
29005
29006 @table @code
29007 @item "~" @var{string-output}
29008 The console output stream contains text that should be displayed in the
29009 CLI console window. It contains the textual responses to CLI commands.
29010
29011 @item "@@" @var{string-output}
29012 The target output stream contains any textual output from the running
29013 target. This is only present when GDB's event loop is truly
29014 asynchronous, which is currently only the case for remote targets.
29015
29016 @item "&" @var{string-output}
29017 The log stream contains debugging messages being produced by @value{GDBN}'s
29018 internals.
29019 @end table
29020
29021 @node GDB/MI Async Records
29022 @subsection @sc{gdb/mi} Async Records
29023
29024 @cindex async records in @sc{gdb/mi}
29025 @cindex @sc{gdb/mi}, async records
29026 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29027 additional changes that have occurred. Those changes can either be a
29028 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29029 target activity (e.g., target stopped).
29030
29031 The following is the list of possible async records:
29032
29033 @table @code
29034
29035 @item *running,thread-id="@var{thread}"
29036 The target is now running. The @var{thread} field tells which
29037 specific thread is now running, and can be @samp{all} if all threads
29038 are running. The frontend should assume that no interaction with a
29039 running thread is possible after this notification is produced.
29040 The frontend should not assume that this notification is output
29041 only once for any command. @value{GDBN} may emit this notification
29042 several times, either for different threads, because it cannot resume
29043 all threads together, or even for a single thread, if the thread must
29044 be stepped though some code before letting it run freely.
29045
29046 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29047 The target has stopped. The @var{reason} field can have one of the
29048 following values:
29049
29050 @table @code
29051 @item breakpoint-hit
29052 A breakpoint was reached.
29053 @item watchpoint-trigger
29054 A watchpoint was triggered.
29055 @item read-watchpoint-trigger
29056 A read watchpoint was triggered.
29057 @item access-watchpoint-trigger
29058 An access watchpoint was triggered.
29059 @item function-finished
29060 An -exec-finish or similar CLI command was accomplished.
29061 @item location-reached
29062 An -exec-until or similar CLI command was accomplished.
29063 @item watchpoint-scope
29064 A watchpoint has gone out of scope.
29065 @item end-stepping-range
29066 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29067 similar CLI command was accomplished.
29068 @item exited-signalled
29069 The inferior exited because of a signal.
29070 @item exited
29071 The inferior exited.
29072 @item exited-normally
29073 The inferior exited normally.
29074 @item signal-received
29075 A signal was received by the inferior.
29076 @item solib-event
29077 The inferior has stopped due to a library being loaded or unloaded.
29078 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29079 set or when a @code{catch load} or @code{catch unload} catchpoint is
29080 in use (@pxref{Set Catchpoints}).
29081 @item fork
29082 The inferior has forked. This is reported when @code{catch fork}
29083 (@pxref{Set Catchpoints}) has been used.
29084 @item vfork
29085 The inferior has vforked. This is reported in when @code{catch vfork}
29086 (@pxref{Set Catchpoints}) has been used.
29087 @item syscall-entry
29088 The inferior entered a system call. This is reported when @code{catch
29089 syscall} (@pxref{Set Catchpoints}) has been used.
29090 @item syscall-entry
29091 The inferior returned from a system call. This is reported when
29092 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29093 @item exec
29094 The inferior called @code{exec}. This is reported when @code{catch exec}
29095 (@pxref{Set Catchpoints}) has been used.
29096 @end table
29097
29098 The @var{id} field identifies the thread that directly caused the stop
29099 -- for example by hitting a breakpoint. Depending on whether all-stop
29100 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29101 stop all threads, or only the thread that directly triggered the stop.
29102 If all threads are stopped, the @var{stopped} field will have the
29103 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29104 field will be a list of thread identifiers. Presently, this list will
29105 always include a single thread, but frontend should be prepared to see
29106 several threads in the list. The @var{core} field reports the
29107 processor core on which the stop event has happened. This field may be absent
29108 if such information is not available.
29109
29110 @item =thread-group-added,id="@var{id}"
29111 @itemx =thread-group-removed,id="@var{id}"
29112 A thread group was either added or removed. The @var{id} field
29113 contains the @value{GDBN} identifier of the thread group. When a thread
29114 group is added, it generally might not be associated with a running
29115 process. When a thread group is removed, its id becomes invalid and
29116 cannot be used in any way.
29117
29118 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29119 A thread group became associated with a running program,
29120 either because the program was just started or the thread group
29121 was attached to a program. The @var{id} field contains the
29122 @value{GDBN} identifier of the thread group. The @var{pid} field
29123 contains process identifier, specific to the operating system.
29124
29125 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29126 A thread group is no longer associated with a running program,
29127 either because the program has exited, or because it was detached
29128 from. The @var{id} field contains the @value{GDBN} identifier of the
29129 thread group. @var{code} is the exit code of the inferior; it exists
29130 only when the inferior exited with some code.
29131
29132 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29133 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29134 A thread either was created, or has exited. The @var{id} field
29135 contains the @value{GDBN} identifier of the thread. The @var{gid}
29136 field identifies the thread group this thread belongs to.
29137
29138 @item =thread-selected,id="@var{id}"
29139 Informs that the selected thread was changed as result of the last
29140 command. This notification is not emitted as result of @code{-thread-select}
29141 command but is emitted whenever an MI command that is not documented
29142 to change the selected thread actually changes it. In particular,
29143 invoking, directly or indirectly (via user-defined command), the CLI
29144 @code{thread} command, will generate this notification.
29145
29146 We suggest that in response to this notification, front ends
29147 highlight the selected thread and cause subsequent commands to apply to
29148 that thread.
29149
29150 @item =library-loaded,...
29151 Reports that a new library file was loaded by the program. This
29152 notification has 4 fields---@var{id}, @var{target-name},
29153 @var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
29154 opaque identifier of the library. For remote debugging case,
29155 @var{target-name} and @var{host-name} fields give the name of the
29156 library file on the target, and on the host respectively. For native
29157 debugging, both those fields have the same value. The
29158 @var{symbols-loaded} field is emitted only for backward compatibility
29159 and should not be relied on to convey any useful information. The
29160 @var{thread-group} field, if present, specifies the id of the thread
29161 group in whose context the library was loaded. If the field is
29162 absent, it means the library was loaded in the context of all present
29163 thread groups.
29164
29165 @item =library-unloaded,...
29166 Reports that a library was unloaded by the program. This notification
29167 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29168 the same meaning as for the @code{=library-loaded} notification.
29169 The @var{thread-group} field, if present, specifies the id of the
29170 thread group in whose context the library was unloaded. If the field is
29171 absent, it means the library was unloaded in the context of all present
29172 thread groups.
29173
29174 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29175 @itemx =traceframe-changed,end
29176 Reports that the trace frame was changed and its new number is
29177 @var{tfnum}. The number of the tracepoint associated with this trace
29178 frame is @var{tpnum}.
29179
29180 @item =tsv-created,name=@var{name},initial=@var{initial}
29181 Reports that the new trace state variable @var{name} is created with
29182 initial value @var{initial}.
29183
29184 @item =tsv-deleted,name=@var{name}
29185 @itemx =tsv-deleted
29186 Reports that the trace state variable @var{name} is deleted or all
29187 trace state variables are deleted.
29188
29189 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29190 Reports that the trace state variable @var{name} is modified with
29191 the initial value @var{initial}. The current value @var{current} of
29192 trace state variable is optional and is reported if the current
29193 value of trace state variable is known.
29194
29195 @item =breakpoint-created,bkpt=@{...@}
29196 @itemx =breakpoint-modified,bkpt=@{...@}
29197 @itemx =breakpoint-deleted,id=@var{number}
29198 Reports that a breakpoint was created, modified, or deleted,
29199 respectively. Only user-visible breakpoints are reported to the MI
29200 user.
29201
29202 The @var{bkpt} argument is of the same form as returned by the various
29203 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29204 @var{number} is the ordinal number of the breakpoint.
29205
29206 Note that if a breakpoint is emitted in the result record of a
29207 command, then it will not also be emitted in an async record.
29208
29209 @item =record-started,thread-group="@var{id}"
29210 @itemx =record-stopped,thread-group="@var{id}"
29211 Execution log recording was either started or stopped on an
29212 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29213 group corresponding to the affected inferior.
29214
29215 @item =cmd-param-changed,param=@var{param},value=@var{value}
29216 Reports that a parameter of the command @code{set @var{param}} is
29217 changed to @var{value}. In the multi-word @code{set} command,
29218 the @var{param} is the whole parameter list to @code{set} command.
29219 For example, In command @code{set check type on}, @var{param}
29220 is @code{check type} and @var{value} is @code{on}.
29221
29222 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29223 Reports that bytes from @var{addr} to @var{data} + @var{len} were
29224 written in an inferior. The @var{id} is the identifier of the
29225 thread group corresponding to the affected inferior. The optional
29226 @code{type="code"} part is reported if the memory written to holds
29227 executable code.
29228 @end table
29229
29230 @node GDB/MI Breakpoint Information
29231 @subsection @sc{gdb/mi} Breakpoint Information
29232
29233 When @value{GDBN} reports information about a breakpoint, a
29234 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29235 following fields:
29236
29237 @table @code
29238 @item number
29239 The breakpoint number. For a breakpoint that represents one location
29240 of a multi-location breakpoint, this will be a dotted pair, like
29241 @samp{1.2}.
29242
29243 @item type
29244 The type of the breakpoint. For ordinary breakpoints this will be
29245 @samp{breakpoint}, but many values are possible.
29246
29247 @item catch-type
29248 If the type of the breakpoint is @samp{catchpoint}, then this
29249 indicates the exact type of catchpoint.
29250
29251 @item disp
29252 This is the breakpoint disposition---either @samp{del}, meaning that
29253 the breakpoint will be deleted at the next stop, or @samp{keep},
29254 meaning that the breakpoint will not be deleted.
29255
29256 @item enabled
29257 This indicates whether the breakpoint is enabled, in which case the
29258 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29259 Note that this is not the same as the field @code{enable}.
29260
29261 @item addr
29262 The address of the breakpoint. This may be a hexidecimal number,
29263 giving the address; or the string @samp{<PENDING>}, for a pending
29264 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29265 multiple locations. This field will not be present if no address can
29266 be determined. For example, a watchpoint does not have an address.
29267
29268 @item func
29269 If known, the function in which the breakpoint appears.
29270 If not known, this field is not present.
29271
29272 @item filename
29273 The name of the source file which contains this function, if known.
29274 If not known, this field is not present.
29275
29276 @item fullname
29277 The full file name of the source file which contains this function, if
29278 known. If not known, this field is not present.
29279
29280 @item line
29281 The line number at which this breakpoint appears, if known.
29282 If not known, this field is not present.
29283
29284 @item at
29285 If the source file is not known, this field may be provided. If
29286 provided, this holds the address of the breakpoint, possibly followed
29287 by a symbol name.
29288
29289 @item pending
29290 If this breakpoint is pending, this field is present and holds the
29291 text used to set the breakpoint, as entered by the user.
29292
29293 @item evaluated-by
29294 Where this breakpoint's condition is evaluated, either @samp{host} or
29295 @samp{target}.
29296
29297 @item thread
29298 If this is a thread-specific breakpoint, then this identifies the
29299 thread in which the breakpoint can trigger.
29300
29301 @item task
29302 If this breakpoint is restricted to a particular Ada task, then this
29303 field will hold the task identifier.
29304
29305 @item cond
29306 If the breakpoint is conditional, this is the condition expression.
29307
29308 @item ignore
29309 The ignore count of the breakpoint.
29310
29311 @item enable
29312 The enable count of the breakpoint.
29313
29314 @item traceframe-usage
29315 FIXME.
29316
29317 @item static-tracepoint-marker-string-id
29318 For a static tracepoint, the name of the static tracepoint marker.
29319
29320 @item mask
29321 For a masked watchpoint, this is the mask.
29322
29323 @item pass
29324 A tracepoint's pass count.
29325
29326 @item original-location
29327 The location of the breakpoint as originally specified by the user.
29328 This field is optional.
29329
29330 @item times
29331 The number of times the breakpoint has been hit.
29332
29333 @item installed
29334 This field is only given for tracepoints. This is either @samp{y},
29335 meaning that the tracepoint is installed, or @samp{n}, meaning that it
29336 is not.
29337
29338 @item what
29339 Some extra data, the exact contents of which are type-dependent.
29340
29341 @end table
29342
29343 For example, here is what the output of @code{-break-insert}
29344 (@pxref{GDB/MI Breakpoint Commands}) might be:
29345
29346 @smallexample
29347 -> -break-insert main
29348 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29349 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29350 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29351 times="0"@}
29352 <- (gdb)
29353 @end smallexample
29354
29355 @node GDB/MI Frame Information
29356 @subsection @sc{gdb/mi} Frame Information
29357
29358 Response from many MI commands includes an information about stack
29359 frame. This information is a tuple that may have the following
29360 fields:
29361
29362 @table @code
29363 @item level
29364 The level of the stack frame. The innermost frame has the level of
29365 zero. This field is always present.
29366
29367 @item func
29368 The name of the function corresponding to the frame. This field may
29369 be absent if @value{GDBN} is unable to determine the function name.
29370
29371 @item addr
29372 The code address for the frame. This field is always present.
29373
29374 @item file
29375 The name of the source files that correspond to the frame's code
29376 address. This field may be absent.
29377
29378 @item line
29379 The source line corresponding to the frames' code address. This field
29380 may be absent.
29381
29382 @item from
29383 The name of the binary file (either executable or shared library) the
29384 corresponds to the frame's code address. This field may be absent.
29385
29386 @end table
29387
29388 @node GDB/MI Thread Information
29389 @subsection @sc{gdb/mi} Thread Information
29390
29391 Whenever @value{GDBN} has to report an information about a thread, it
29392 uses a tuple with the following fields:
29393
29394 @table @code
29395 @item id
29396 The numeric id assigned to the thread by @value{GDBN}. This field is
29397 always present.
29398
29399 @item target-id
29400 Target-specific string identifying the thread. This field is always present.
29401
29402 @item details
29403 Additional information about the thread provided by the target.
29404 It is supposed to be human-readable and not interpreted by the
29405 frontend. This field is optional.
29406
29407 @item state
29408 Either @samp{stopped} or @samp{running}, depending on whether the
29409 thread is presently running. This field is always present.
29410
29411 @item core
29412 The value of this field is an integer number of the processor core the
29413 thread was last seen on. This field is optional.
29414 @end table
29415
29416 @node GDB/MI Ada Exception Information
29417 @subsection @sc{gdb/mi} Ada Exception Information
29418
29419 Whenever a @code{*stopped} record is emitted because the program
29420 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29421 @value{GDBN} provides the name of the exception that was raised via
29422 the @code{exception-name} field.
29423
29424 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29425 @node GDB/MI Simple Examples
29426 @section Simple Examples of @sc{gdb/mi} Interaction
29427 @cindex @sc{gdb/mi}, simple examples
29428
29429 This subsection presents several simple examples of interaction using
29430 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29431 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29432 the output received from @sc{gdb/mi}.
29433
29434 Note the line breaks shown in the examples are here only for
29435 readability, they don't appear in the real output.
29436
29437 @subheading Setting a Breakpoint
29438
29439 Setting a breakpoint generates synchronous output which contains detailed
29440 information of the breakpoint.
29441
29442 @smallexample
29443 -> -break-insert main
29444 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29445 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29446 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29447 times="0"@}
29448 <- (gdb)
29449 @end smallexample
29450
29451 @subheading Program Execution
29452
29453 Program execution generates asynchronous records and MI gives the
29454 reason that execution stopped.
29455
29456 @smallexample
29457 -> -exec-run
29458 <- ^running
29459 <- (gdb)
29460 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
29461 frame=@{addr="0x08048564",func="main",
29462 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
29463 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
29464 <- (gdb)
29465 -> -exec-continue
29466 <- ^running
29467 <- (gdb)
29468 <- *stopped,reason="exited-normally"
29469 <- (gdb)
29470 @end smallexample
29471
29472 @subheading Quitting @value{GDBN}
29473
29474 Quitting @value{GDBN} just prints the result class @samp{^exit}.
29475
29476 @smallexample
29477 -> (gdb)
29478 <- -gdb-exit
29479 <- ^exit
29480 @end smallexample
29481
29482 Please note that @samp{^exit} is printed immediately, but it might
29483 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29484 performs necessary cleanups, including killing programs being debugged
29485 or disconnecting from debug hardware, so the frontend should wait till
29486 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29487 fails to exit in reasonable time.
29488
29489 @subheading A Bad Command
29490
29491 Here's what happens if you pass a non-existent command:
29492
29493 @smallexample
29494 -> -rubbish
29495 <- ^error,msg="Undefined MI command: rubbish"
29496 <- (gdb)
29497 @end smallexample
29498
29499
29500 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29501 @node GDB/MI Command Description Format
29502 @section @sc{gdb/mi} Command Description Format
29503
29504 The remaining sections describe blocks of commands. Each block of
29505 commands is laid out in a fashion similar to this section.
29506
29507 @subheading Motivation
29508
29509 The motivation for this collection of commands.
29510
29511 @subheading Introduction
29512
29513 A brief introduction to this collection of commands as a whole.
29514
29515 @subheading Commands
29516
29517 For each command in the block, the following is described:
29518
29519 @subsubheading Synopsis
29520
29521 @smallexample
29522 -command @var{args}@dots{}
29523 @end smallexample
29524
29525 @subsubheading Result
29526
29527 @subsubheading @value{GDBN} Command
29528
29529 The corresponding @value{GDBN} CLI command(s), if any.
29530
29531 @subsubheading Example
29532
29533 Example(s) formatted for readability. Some of the described commands have
29534 not been implemented yet and these are labeled N.A.@: (not available).
29535
29536
29537 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29538 @node GDB/MI Breakpoint Commands
29539 @section @sc{gdb/mi} Breakpoint Commands
29540
29541 @cindex breakpoint commands for @sc{gdb/mi}
29542 @cindex @sc{gdb/mi}, breakpoint commands
29543 This section documents @sc{gdb/mi} commands for manipulating
29544 breakpoints.
29545
29546 @subheading The @code{-break-after} Command
29547 @findex -break-after
29548
29549 @subsubheading Synopsis
29550
29551 @smallexample
29552 -break-after @var{number} @var{count}
29553 @end smallexample
29554
29555 The breakpoint number @var{number} is not in effect until it has been
29556 hit @var{count} times. To see how this is reflected in the output of
29557 the @samp{-break-list} command, see the description of the
29558 @samp{-break-list} command below.
29559
29560 @subsubheading @value{GDBN} Command
29561
29562 The corresponding @value{GDBN} command is @samp{ignore}.
29563
29564 @subsubheading Example
29565
29566 @smallexample
29567 (gdb)
29568 -break-insert main
29569 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29570 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29571 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29572 times="0"@}
29573 (gdb)
29574 -break-after 1 3
29575 ~
29576 ^done
29577 (gdb)
29578 -break-list
29579 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29580 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29581 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29582 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29583 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29584 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29585 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29586 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29587 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29588 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
29589 (gdb)
29590 @end smallexample
29591
29592 @ignore
29593 @subheading The @code{-break-catch} Command
29594 @findex -break-catch
29595 @end ignore
29596
29597 @subheading The @code{-break-commands} Command
29598 @findex -break-commands
29599
29600 @subsubheading Synopsis
29601
29602 @smallexample
29603 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29604 @end smallexample
29605
29606 Specifies the CLI commands that should be executed when breakpoint
29607 @var{number} is hit. The parameters @var{command1} to @var{commandN}
29608 are the commands. If no command is specified, any previously-set
29609 commands are cleared. @xref{Break Commands}. Typical use of this
29610 functionality is tracing a program, that is, printing of values of
29611 some variables whenever breakpoint is hit and then continuing.
29612
29613 @subsubheading @value{GDBN} Command
29614
29615 The corresponding @value{GDBN} command is @samp{commands}.
29616
29617 @subsubheading Example
29618
29619 @smallexample
29620 (gdb)
29621 -break-insert main
29622 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29623 enabled="y",addr="0x000100d0",func="main",file="hello.c",
29624 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29625 times="0"@}
29626 (gdb)
29627 -break-commands 1 "print v" "continue"
29628 ^done
29629 (gdb)
29630 @end smallexample
29631
29632 @subheading The @code{-break-condition} Command
29633 @findex -break-condition
29634
29635 @subsubheading Synopsis
29636
29637 @smallexample
29638 -break-condition @var{number} @var{expr}
29639 @end smallexample
29640
29641 Breakpoint @var{number} will stop the program only if the condition in
29642 @var{expr} is true. The condition becomes part of the
29643 @samp{-break-list} output (see the description of the @samp{-break-list}
29644 command below).
29645
29646 @subsubheading @value{GDBN} Command
29647
29648 The corresponding @value{GDBN} command is @samp{condition}.
29649
29650 @subsubheading Example
29651
29652 @smallexample
29653 (gdb)
29654 -break-condition 1 1
29655 ^done
29656 (gdb)
29657 -break-list
29658 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29659 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29660 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29661 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29662 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29663 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29664 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29665 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29666 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29667 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
29668 (gdb)
29669 @end smallexample
29670
29671 @subheading The @code{-break-delete} Command
29672 @findex -break-delete
29673
29674 @subsubheading Synopsis
29675
29676 @smallexample
29677 -break-delete ( @var{breakpoint} )+
29678 @end smallexample
29679
29680 Delete the breakpoint(s) whose number(s) are specified in the argument
29681 list. This is obviously reflected in the breakpoint list.
29682
29683 @subsubheading @value{GDBN} Command
29684
29685 The corresponding @value{GDBN} command is @samp{delete}.
29686
29687 @subsubheading Example
29688
29689 @smallexample
29690 (gdb)
29691 -break-delete 1
29692 ^done
29693 (gdb)
29694 -break-list
29695 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
29696 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29697 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29698 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29699 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29700 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29701 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29702 body=[]@}
29703 (gdb)
29704 @end smallexample
29705
29706 @subheading The @code{-break-disable} Command
29707 @findex -break-disable
29708
29709 @subsubheading Synopsis
29710
29711 @smallexample
29712 -break-disable ( @var{breakpoint} )+
29713 @end smallexample
29714
29715 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
29716 break list is now set to @samp{n} for the named @var{breakpoint}(s).
29717
29718 @subsubheading @value{GDBN} Command
29719
29720 The corresponding @value{GDBN} command is @samp{disable}.
29721
29722 @subsubheading Example
29723
29724 @smallexample
29725 (gdb)
29726 -break-disable 2
29727 ^done
29728 (gdb)
29729 -break-list
29730 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29731 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29732 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29733 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29734 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29735 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29736 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29737 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
29738 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29739 line="5",thread-groups=["i1"],times="0"@}]@}
29740 (gdb)
29741 @end smallexample
29742
29743 @subheading The @code{-break-enable} Command
29744 @findex -break-enable
29745
29746 @subsubheading Synopsis
29747
29748 @smallexample
29749 -break-enable ( @var{breakpoint} )+
29750 @end smallexample
29751
29752 Enable (previously disabled) @var{breakpoint}(s).
29753
29754 @subsubheading @value{GDBN} Command
29755
29756 The corresponding @value{GDBN} command is @samp{enable}.
29757
29758 @subsubheading Example
29759
29760 @smallexample
29761 (gdb)
29762 -break-enable 2
29763 ^done
29764 (gdb)
29765 -break-list
29766 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29767 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29768 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29769 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29770 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29771 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29772 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29773 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
29774 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29775 line="5",thread-groups=["i1"],times="0"@}]@}
29776 (gdb)
29777 @end smallexample
29778
29779 @subheading The @code{-break-info} Command
29780 @findex -break-info
29781
29782 @subsubheading Synopsis
29783
29784 @smallexample
29785 -break-info @var{breakpoint}
29786 @end smallexample
29787
29788 @c REDUNDANT???
29789 Get information about a single breakpoint.
29790
29791 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
29792 Information}, for details on the format of each breakpoint in the
29793 table.
29794
29795 @subsubheading @value{GDBN} Command
29796
29797 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
29798
29799 @subsubheading Example
29800 N.A.
29801
29802 @subheading The @code{-break-insert} Command
29803 @findex -break-insert
29804
29805 @subsubheading Synopsis
29806
29807 @smallexample
29808 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
29809 [ -c @var{condition} ] [ -i @var{ignore-count} ]
29810 [ -p @var{thread-id} ] [ @var{location} ]
29811 @end smallexample
29812
29813 @noindent
29814 If specified, @var{location}, can be one of:
29815
29816 @itemize @bullet
29817 @item function
29818 @c @item +offset
29819 @c @item -offset
29820 @c @item linenum
29821 @item filename:linenum
29822 @item filename:function
29823 @item *address
29824 @end itemize
29825
29826 The possible optional parameters of this command are:
29827
29828 @table @samp
29829 @item -t
29830 Insert a temporary breakpoint.
29831 @item -h
29832 Insert a hardware breakpoint.
29833 @item -f
29834 If @var{location} cannot be parsed (for example if it
29835 refers to unknown files or functions), create a pending
29836 breakpoint. Without this flag, @value{GDBN} will report
29837 an error, and won't create a breakpoint, if @var{location}
29838 cannot be parsed.
29839 @item -d
29840 Create a disabled breakpoint.
29841 @item -a
29842 Create a tracepoint. @xref{Tracepoints}. When this parameter
29843 is used together with @samp{-h}, a fast tracepoint is created.
29844 @item -c @var{condition}
29845 Make the breakpoint conditional on @var{condition}.
29846 @item -i @var{ignore-count}
29847 Initialize the @var{ignore-count}.
29848 @item -p @var{thread-id}
29849 Restrict the breakpoint to the specified @var{thread-id}.
29850 @end table
29851
29852 @subsubheading Result
29853
29854 @xref{GDB/MI Breakpoint Information}, for details on the format of the
29855 resulting breakpoint.
29856
29857 Note: this format is open to change.
29858 @c An out-of-band breakpoint instead of part of the result?
29859
29860 @subsubheading @value{GDBN} Command
29861
29862 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
29863 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
29864
29865 @subsubheading Example
29866
29867 @smallexample
29868 (gdb)
29869 -break-insert main
29870 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
29871 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
29872 times="0"@}
29873 (gdb)
29874 -break-insert -t foo
29875 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
29876 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
29877 times="0"@}
29878 (gdb)
29879 -break-list
29880 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29881 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29882 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29883 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29884 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29885 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29886 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
29887 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29888 addr="0x0001072c", func="main",file="recursive2.c",
29889 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
29890 times="0"@},
29891 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
29892 addr="0x00010774",func="foo",file="recursive2.c",
29893 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
29894 times="0"@}]@}
29895 (gdb)
29896 @c -break-insert -r foo.*
29897 @c ~int foo(int, int);
29898 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
29899 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
29900 @c times="0"@}
29901 @c (gdb)
29902 @end smallexample
29903
29904 @subheading The @code{-dprintf-insert} Command
29905 @findex -dprintf-insert
29906
29907 @subsubheading Synopsis
29908
29909 @smallexample
29910 -dprintf-insert [ -t ] [ -f ] [ -d ]
29911 [ -c @var{condition} ] [ -i @var{ignore-count} ]
29912 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
29913 [ @var{argument} ]
29914 @end smallexample
29915
29916 @noindent
29917 If specified, @var{location}, can be one of:
29918
29919 @itemize @bullet
29920 @item @var{function}
29921 @c @item +offset
29922 @c @item -offset
29923 @c @item @var{linenum}
29924 @item @var{filename}:@var{linenum}
29925 @item @var{filename}:function
29926 @item *@var{address}
29927 @end itemize
29928
29929 The possible optional parameters of this command are:
29930
29931 @table @samp
29932 @item -t
29933 Insert a temporary breakpoint.
29934 @item -f
29935 If @var{location} cannot be parsed (for example, if it
29936 refers to unknown files or functions), create a pending
29937 breakpoint. Without this flag, @value{GDBN} will report
29938 an error, and won't create a breakpoint, if @var{location}
29939 cannot be parsed.
29940 @item -d
29941 Create a disabled breakpoint.
29942 @item -c @var{condition}
29943 Make the breakpoint conditional on @var{condition}.
29944 @item -i @var{ignore-count}
29945 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
29946 to @var{ignore-count}.
29947 @item -p @var{thread-id}
29948 Restrict the breakpoint to the specified @var{thread-id}.
29949 @end table
29950
29951 @subsubheading Result
29952
29953 @xref{GDB/MI Breakpoint Information}, for details on the format of the
29954 resulting breakpoint.
29955
29956 @c An out-of-band breakpoint instead of part of the result?
29957
29958 @subsubheading @value{GDBN} Command
29959
29960 The corresponding @value{GDBN} command is @samp{dprintf}.
29961
29962 @subsubheading Example
29963
29964 @smallexample
29965 (gdb)
29966 4-dprintf-insert foo "At foo entry\n"
29967 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
29968 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
29969 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
29970 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
29971 original-location="foo"@}
29972 (gdb)
29973 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
29974 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
29975 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
29976 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
29977 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
29978 original-location="mi-dprintf.c:26"@}
29979 (gdb)
29980 @end smallexample
29981
29982 @subheading The @code{-break-list} Command
29983 @findex -break-list
29984
29985 @subsubheading Synopsis
29986
29987 @smallexample
29988 -break-list
29989 @end smallexample
29990
29991 Displays the list of inserted breakpoints, showing the following fields:
29992
29993 @table @samp
29994 @item Number
29995 number of the breakpoint
29996 @item Type
29997 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
29998 @item Disposition
29999 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30000 or @samp{nokeep}
30001 @item Enabled
30002 is the breakpoint enabled or no: @samp{y} or @samp{n}
30003 @item Address
30004 memory location at which the breakpoint is set
30005 @item What
30006 logical location of the breakpoint, expressed by function name, file
30007 name, line number
30008 @item Thread-groups
30009 list of thread groups to which this breakpoint applies
30010 @item Times
30011 number of times the breakpoint has been hit
30012 @end table
30013
30014 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30015 @code{body} field is an empty list.
30016
30017 @subsubheading @value{GDBN} Command
30018
30019 The corresponding @value{GDBN} command is @samp{info break}.
30020
30021 @subsubheading Example
30022
30023 @smallexample
30024 (gdb)
30025 -break-list
30026 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30027 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30028 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30029 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30030 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30031 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30032 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30033 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30034 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30035 times="0"@},
30036 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30037 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30038 line="13",thread-groups=["i1"],times="0"@}]@}
30039 (gdb)
30040 @end smallexample
30041
30042 Here's an example of the result when there are no breakpoints:
30043
30044 @smallexample
30045 (gdb)
30046 -break-list
30047 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30048 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30049 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30050 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30051 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30052 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30053 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30054 body=[]@}
30055 (gdb)
30056 @end smallexample
30057
30058 @subheading The @code{-break-passcount} Command
30059 @findex -break-passcount
30060
30061 @subsubheading Synopsis
30062
30063 @smallexample
30064 -break-passcount @var{tracepoint-number} @var{passcount}
30065 @end smallexample
30066
30067 Set the passcount for tracepoint @var{tracepoint-number} to
30068 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30069 is not a tracepoint, error is emitted. This corresponds to CLI
30070 command @samp{passcount}.
30071
30072 @subheading The @code{-break-watch} Command
30073 @findex -break-watch
30074
30075 @subsubheading Synopsis
30076
30077 @smallexample
30078 -break-watch [ -a | -r ]
30079 @end smallexample
30080
30081 Create a watchpoint. With the @samp{-a} option it will create an
30082 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30083 read from or on a write to the memory location. With the @samp{-r}
30084 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30085 trigger only when the memory location is accessed for reading. Without
30086 either of the options, the watchpoint created is a regular watchpoint,
30087 i.e., it will trigger when the memory location is accessed for writing.
30088 @xref{Set Watchpoints, , Setting Watchpoints}.
30089
30090 Note that @samp{-break-list} will report a single list of watchpoints and
30091 breakpoints inserted.
30092
30093 @subsubheading @value{GDBN} Command
30094
30095 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30096 @samp{rwatch}.
30097
30098 @subsubheading Example
30099
30100 Setting a watchpoint on a variable in the @code{main} function:
30101
30102 @smallexample
30103 (gdb)
30104 -break-watch x
30105 ^done,wpt=@{number="2",exp="x"@}
30106 (gdb)
30107 -exec-continue
30108 ^running
30109 (gdb)
30110 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30111 value=@{old="-268439212",new="55"@},
30112 frame=@{func="main",args=[],file="recursive2.c",
30113 fullname="/home/foo/bar/recursive2.c",line="5"@}
30114 (gdb)
30115 @end smallexample
30116
30117 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30118 the program execution twice: first for the variable changing value, then
30119 for the watchpoint going out of scope.
30120
30121 @smallexample
30122 (gdb)
30123 -break-watch C
30124 ^done,wpt=@{number="5",exp="C"@}
30125 (gdb)
30126 -exec-continue
30127 ^running
30128 (gdb)
30129 *stopped,reason="watchpoint-trigger",
30130 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30131 frame=@{func="callee4",args=[],
30132 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30133 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
30134 (gdb)
30135 -exec-continue
30136 ^running
30137 (gdb)
30138 *stopped,reason="watchpoint-scope",wpnum="5",
30139 frame=@{func="callee3",args=[@{name="strarg",
30140 value="0x11940 \"A string argument.\""@}],
30141 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30142 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
30143 (gdb)
30144 @end smallexample
30145
30146 Listing breakpoints and watchpoints, at different points in the program
30147 execution. Note that once the watchpoint goes out of scope, it is
30148 deleted.
30149
30150 @smallexample
30151 (gdb)
30152 -break-watch C
30153 ^done,wpt=@{number="2",exp="C"@}
30154 (gdb)
30155 -break-list
30156 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30157 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30158 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30159 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30160 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30161 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30162 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30163 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30164 addr="0x00010734",func="callee4",
30165 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30166 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30167 times="1"@},
30168 bkpt=@{number="2",type="watchpoint",disp="keep",
30169 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
30170 (gdb)
30171 -exec-continue
30172 ^running
30173 (gdb)
30174 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
30175 value=@{old="-276895068",new="3"@},
30176 frame=@{func="callee4",args=[],
30177 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30178 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
30179 (gdb)
30180 -break-list
30181 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30182 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30183 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30184 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30185 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30186 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30187 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30188 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30189 addr="0x00010734",func="callee4",
30190 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30191 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30192 times="1"@},
30193 bkpt=@{number="2",type="watchpoint",disp="keep",
30194 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
30195 (gdb)
30196 -exec-continue
30197 ^running
30198 ^done,reason="watchpoint-scope",wpnum="2",
30199 frame=@{func="callee3",args=[@{name="strarg",
30200 value="0x11940 \"A string argument.\""@}],
30201 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30202 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
30203 (gdb)
30204 -break-list
30205 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30206 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30207 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30208 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30209 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30210 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30211 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30212 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30213 addr="0x00010734",func="callee4",
30214 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30215 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30216 thread-groups=["i1"],times="1"@}]@}
30217 (gdb)
30218 @end smallexample
30219
30220
30221 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30222 @node GDB/MI Catchpoint Commands
30223 @section @sc{gdb/mi} Catchpoint Commands
30224
30225 This section documents @sc{gdb/mi} commands for manipulating
30226 catchpoints.
30227
30228 @subheading The @code{-catch-load} Command
30229 @findex -catch-load
30230
30231 @subsubheading Synopsis
30232
30233 @smallexample
30234 -catch-load [ -t ] [ -d ] @var{regexp}
30235 @end smallexample
30236
30237 Add a catchpoint for library load events. If the @samp{-t} option is used,
30238 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30239 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30240 in a disabled state. The @samp{regexp} argument is a regular
30241 expression used to match the name of the loaded library.
30242
30243
30244 @subsubheading @value{GDBN} Command
30245
30246 The corresponding @value{GDBN} command is @samp{catch load}.
30247
30248 @subsubheading Example
30249
30250 @smallexample
30251 -catch-load -t foo.so
30252 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
30253 what="load of library matching foo.so",catch-type="load",times="0"@}
30254 (gdb)
30255 @end smallexample
30256
30257
30258 @subheading The @code{-catch-unload} Command
30259 @findex -catch-unload
30260
30261 @subsubheading Synopsis
30262
30263 @smallexample
30264 -catch-unload [ -t ] [ -d ] @var{regexp}
30265 @end smallexample
30266
30267 Add a catchpoint for library unload events. If the @samp{-t} option is
30268 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30269 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30270 created in a disabled state. The @samp{regexp} argument is a regular
30271 expression used to match the name of the unloaded library.
30272
30273 @subsubheading @value{GDBN} Command
30274
30275 The corresponding @value{GDBN} command is @samp{catch unload}.
30276
30277 @subsubheading Example
30278
30279 @smallexample
30280 -catch-unload -d bar.so
30281 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
30282 what="load of library matching bar.so",catch-type="unload",times="0"@}
30283 (gdb)
30284 @end smallexample
30285
30286
30287 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30288 @node GDB/MI Program Context
30289 @section @sc{gdb/mi} Program Context
30290
30291 @subheading The @code{-exec-arguments} Command
30292 @findex -exec-arguments
30293
30294
30295 @subsubheading Synopsis
30296
30297 @smallexample
30298 -exec-arguments @var{args}
30299 @end smallexample
30300
30301 Set the inferior program arguments, to be used in the next
30302 @samp{-exec-run}.
30303
30304 @subsubheading @value{GDBN} Command
30305
30306 The corresponding @value{GDBN} command is @samp{set args}.
30307
30308 @subsubheading Example
30309
30310 @smallexample
30311 (gdb)
30312 -exec-arguments -v word
30313 ^done
30314 (gdb)
30315 @end smallexample
30316
30317
30318 @ignore
30319 @subheading The @code{-exec-show-arguments} Command
30320 @findex -exec-show-arguments
30321
30322 @subsubheading Synopsis
30323
30324 @smallexample
30325 -exec-show-arguments
30326 @end smallexample
30327
30328 Print the arguments of the program.
30329
30330 @subsubheading @value{GDBN} Command
30331
30332 The corresponding @value{GDBN} command is @samp{show args}.
30333
30334 @subsubheading Example
30335 N.A.
30336 @end ignore
30337
30338
30339 @subheading The @code{-environment-cd} Command
30340 @findex -environment-cd
30341
30342 @subsubheading Synopsis
30343
30344 @smallexample
30345 -environment-cd @var{pathdir}
30346 @end smallexample
30347
30348 Set @value{GDBN}'s working directory.
30349
30350 @subsubheading @value{GDBN} Command
30351
30352 The corresponding @value{GDBN} command is @samp{cd}.
30353
30354 @subsubheading Example
30355
30356 @smallexample
30357 (gdb)
30358 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30359 ^done
30360 (gdb)
30361 @end smallexample
30362
30363
30364 @subheading The @code{-environment-directory} Command
30365 @findex -environment-directory
30366
30367 @subsubheading Synopsis
30368
30369 @smallexample
30370 -environment-directory [ -r ] [ @var{pathdir} ]+
30371 @end smallexample
30372
30373 Add directories @var{pathdir} to beginning of search path for source files.
30374 If the @samp{-r} option is used, the search path is reset to the default
30375 search path. If directories @var{pathdir} are supplied in addition to the
30376 @samp{-r} option, the search path is first reset and then addition
30377 occurs as normal.
30378 Multiple directories may be specified, separated by blanks. Specifying
30379 multiple directories in a single command
30380 results in the directories added to the beginning of the
30381 search path in the same order they were presented in the command.
30382 If blanks are needed as
30383 part of a directory name, double-quotes should be used around
30384 the name. In the command output, the path will show up separated
30385 by the system directory-separator character. The directory-separator
30386 character must not be used
30387 in any directory name.
30388 If no directories are specified, the current search path is displayed.
30389
30390 @subsubheading @value{GDBN} Command
30391
30392 The corresponding @value{GDBN} command is @samp{dir}.
30393
30394 @subsubheading Example
30395
30396 @smallexample
30397 (gdb)
30398 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30399 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
30400 (gdb)
30401 -environment-directory ""
30402 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
30403 (gdb)
30404 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
30405 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
30406 (gdb)
30407 -environment-directory -r
30408 ^done,source-path="$cdir:$cwd"
30409 (gdb)
30410 @end smallexample
30411
30412
30413 @subheading The @code{-environment-path} Command
30414 @findex -environment-path
30415
30416 @subsubheading Synopsis
30417
30418 @smallexample
30419 -environment-path [ -r ] [ @var{pathdir} ]+
30420 @end smallexample
30421
30422 Add directories @var{pathdir} to beginning of search path for object files.
30423 If the @samp{-r} option is used, the search path is reset to the original
30424 search path that existed at gdb start-up. If directories @var{pathdir} are
30425 supplied in addition to the
30426 @samp{-r} option, the search path is first reset and then addition
30427 occurs as normal.
30428 Multiple directories may be specified, separated by blanks. Specifying
30429 multiple directories in a single command
30430 results in the directories added to the beginning of the
30431 search path in the same order they were presented in the command.
30432 If blanks are needed as
30433 part of a directory name, double-quotes should be used around
30434 the name. In the command output, the path will show up separated
30435 by the system directory-separator character. The directory-separator
30436 character must not be used
30437 in any directory name.
30438 If no directories are specified, the current path is displayed.
30439
30440
30441 @subsubheading @value{GDBN} Command
30442
30443 The corresponding @value{GDBN} command is @samp{path}.
30444
30445 @subsubheading Example
30446
30447 @smallexample
30448 (gdb)
30449 -environment-path
30450 ^done,path="/usr/bin"
30451 (gdb)
30452 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
30453 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
30454 (gdb)
30455 -environment-path -r /usr/local/bin
30456 ^done,path="/usr/local/bin:/usr/bin"
30457 (gdb)
30458 @end smallexample
30459
30460
30461 @subheading The @code{-environment-pwd} Command
30462 @findex -environment-pwd
30463
30464 @subsubheading Synopsis
30465
30466 @smallexample
30467 -environment-pwd
30468 @end smallexample
30469
30470 Show the current working directory.
30471
30472 @subsubheading @value{GDBN} Command
30473
30474 The corresponding @value{GDBN} command is @samp{pwd}.
30475
30476 @subsubheading Example
30477
30478 @smallexample
30479 (gdb)
30480 -environment-pwd
30481 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
30482 (gdb)
30483 @end smallexample
30484
30485 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30486 @node GDB/MI Thread Commands
30487 @section @sc{gdb/mi} Thread Commands
30488
30489
30490 @subheading The @code{-thread-info} Command
30491 @findex -thread-info
30492
30493 @subsubheading Synopsis
30494
30495 @smallexample
30496 -thread-info [ @var{thread-id} ]
30497 @end smallexample
30498
30499 Reports information about either a specific thread, if
30500 the @var{thread-id} parameter is present, or about all
30501 threads. When printing information about all threads,
30502 also reports the current thread.
30503
30504 @subsubheading @value{GDBN} Command
30505
30506 The @samp{info thread} command prints the same information
30507 about all threads.
30508
30509 @subsubheading Result
30510
30511 The result is a list of threads. The following attributes are
30512 defined for a given thread:
30513
30514 @table @samp
30515 @item current
30516 This field exists only for the current thread. It has the value @samp{*}.
30517
30518 @item id
30519 The identifier that @value{GDBN} uses to refer to the thread.
30520
30521 @item target-id
30522 The identifier that the target uses to refer to the thread.
30523
30524 @item details
30525 Extra information about the thread, in a target-specific format. This
30526 field is optional.
30527
30528 @item name
30529 The name of the thread. If the user specified a name using the
30530 @code{thread name} command, then this name is given. Otherwise, if
30531 @value{GDBN} can extract the thread name from the target, then that
30532 name is given. If @value{GDBN} cannot find the thread name, then this
30533 field is omitted.
30534
30535 @item frame
30536 The stack frame currently executing in the thread.
30537
30538 @item state
30539 The thread's state. The @samp{state} field may have the following
30540 values:
30541
30542 @table @code
30543 @item stopped
30544 The thread is stopped. Frame information is available for stopped
30545 threads.
30546
30547 @item running
30548 The thread is running. There's no frame information for running
30549 threads.
30550
30551 @end table
30552
30553 @item core
30554 If @value{GDBN} can find the CPU core on which this thread is running,
30555 then this field is the core identifier. This field is optional.
30556
30557 @end table
30558
30559 @subsubheading Example
30560
30561 @smallexample
30562 -thread-info
30563 ^done,threads=[
30564 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
30565 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
30566 args=[]@},state="running"@},
30567 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
30568 frame=@{level="0",addr="0x0804891f",func="foo",
30569 args=[@{name="i",value="10"@}],
30570 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},
30571 state="running"@}],
30572 current-thread-id="1"
30573 (gdb)
30574 @end smallexample
30575
30576 @subheading The @code{-thread-list-ids} Command
30577 @findex -thread-list-ids
30578
30579 @subsubheading Synopsis
30580
30581 @smallexample
30582 -thread-list-ids
30583 @end smallexample
30584
30585 Produces a list of the currently known @value{GDBN} thread ids. At the
30586 end of the list it also prints the total number of such threads.
30587
30588 This command is retained for historical reasons, the
30589 @code{-thread-info} command should be used instead.
30590
30591 @subsubheading @value{GDBN} Command
30592
30593 Part of @samp{info threads} supplies the same information.
30594
30595 @subsubheading Example
30596
30597 @smallexample
30598 (gdb)
30599 -thread-list-ids
30600 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
30601 current-thread-id="1",number-of-threads="3"
30602 (gdb)
30603 @end smallexample
30604
30605
30606 @subheading The @code{-thread-select} Command
30607 @findex -thread-select
30608
30609 @subsubheading Synopsis
30610
30611 @smallexample
30612 -thread-select @var{threadnum}
30613 @end smallexample
30614
30615 Make @var{threadnum} the current thread. It prints the number of the new
30616 current thread, and the topmost frame for that thread.
30617
30618 This command is deprecated in favor of explicitly using the
30619 @samp{--thread} option to each command.
30620
30621 @subsubheading @value{GDBN} Command
30622
30623 The corresponding @value{GDBN} command is @samp{thread}.
30624
30625 @subsubheading Example
30626
30627 @smallexample
30628 (gdb)
30629 -exec-next
30630 ^running
30631 (gdb)
30632 *stopped,reason="end-stepping-range",thread-id="2",line="187",
30633 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
30634 (gdb)
30635 -thread-list-ids
30636 ^done,
30637 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
30638 number-of-threads="3"
30639 (gdb)
30640 -thread-select 3
30641 ^done,new-thread-id="3",
30642 frame=@{level="0",func="vprintf",
30643 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
30644 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
30645 (gdb)
30646 @end smallexample
30647
30648 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30649 @node GDB/MI Ada Tasking Commands
30650 @section @sc{gdb/mi} Ada Tasking Commands
30651
30652 @subheading The @code{-ada-task-info} Command
30653 @findex -ada-task-info
30654
30655 @subsubheading Synopsis
30656
30657 @smallexample
30658 -ada-task-info [ @var{task-id} ]
30659 @end smallexample
30660
30661 Reports information about either a specific Ada task, if the
30662 @var{task-id} parameter is present, or about all Ada tasks.
30663
30664 @subsubheading @value{GDBN} Command
30665
30666 The @samp{info tasks} command prints the same information
30667 about all Ada tasks (@pxref{Ada Tasks}).
30668
30669 @subsubheading Result
30670
30671 The result is a table of Ada tasks. The following columns are
30672 defined for each Ada task:
30673
30674 @table @samp
30675 @item current
30676 This field exists only for the current thread. It has the value @samp{*}.
30677
30678 @item id
30679 The identifier that @value{GDBN} uses to refer to the Ada task.
30680
30681 @item task-id
30682 The identifier that the target uses to refer to the Ada task.
30683
30684 @item thread-id
30685 The identifier of the thread corresponding to the Ada task.
30686
30687 This field should always exist, as Ada tasks are always implemented
30688 on top of a thread. But if @value{GDBN} cannot find this corresponding
30689 thread for any reason, the field is omitted.
30690
30691 @item parent-id
30692 This field exists only when the task was created by another task.
30693 In this case, it provides the ID of the parent task.
30694
30695 @item priority
30696 The base priority of the task.
30697
30698 @item state
30699 The current state of the task. For a detailed description of the
30700 possible states, see @ref{Ada Tasks}.
30701
30702 @item name
30703 The name of the task.
30704
30705 @end table
30706
30707 @subsubheading Example
30708
30709 @smallexample
30710 -ada-task-info
30711 ^done,tasks=@{nr_rows="3",nr_cols="8",
30712 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
30713 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
30714 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
30715 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
30716 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
30717 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
30718 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
30719 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
30720 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
30721 state="Child Termination Wait",name="main_task"@}]@}
30722 (gdb)
30723 @end smallexample
30724
30725 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30726 @node GDB/MI Program Execution
30727 @section @sc{gdb/mi} Program Execution
30728
30729 These are the asynchronous commands which generate the out-of-band
30730 record @samp{*stopped}. Currently @value{GDBN} only really executes
30731 asynchronously with remote targets and this interaction is mimicked in
30732 other cases.
30733
30734 @subheading The @code{-exec-continue} Command
30735 @findex -exec-continue
30736
30737 @subsubheading Synopsis
30738
30739 @smallexample
30740 -exec-continue [--reverse] [--all|--thread-group N]
30741 @end smallexample
30742
30743 Resumes the execution of the inferior program, which will continue
30744 to execute until it reaches a debugger stop event. If the
30745 @samp{--reverse} option is specified, execution resumes in reverse until
30746 it reaches a stop event. Stop events may include
30747 @itemize @bullet
30748 @item
30749 breakpoints or watchpoints
30750 @item
30751 signals or exceptions
30752 @item
30753 the end of the process (or its beginning under @samp{--reverse})
30754 @item
30755 the end or beginning of a replay log if one is being used.
30756 @end itemize
30757 In all-stop mode (@pxref{All-Stop
30758 Mode}), may resume only one thread, or all threads, depending on the
30759 value of the @samp{scheduler-locking} variable. If @samp{--all} is
30760 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
30761 ignored in all-stop mode. If the @samp{--thread-group} options is
30762 specified, then all threads in that thread group are resumed.
30763
30764 @subsubheading @value{GDBN} Command
30765
30766 The corresponding @value{GDBN} corresponding is @samp{continue}.
30767
30768 @subsubheading Example
30769
30770 @smallexample
30771 -exec-continue
30772 ^running
30773 (gdb)
30774 @@Hello world
30775 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
30776 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
30777 line="13"@}
30778 (gdb)
30779 @end smallexample
30780
30781
30782 @subheading The @code{-exec-finish} Command
30783 @findex -exec-finish
30784
30785 @subsubheading Synopsis
30786
30787 @smallexample
30788 -exec-finish [--reverse]
30789 @end smallexample
30790
30791 Resumes the execution of the inferior program until the current
30792 function is exited. Displays the results returned by the function.
30793 If the @samp{--reverse} option is specified, resumes the reverse
30794 execution of the inferior program until the point where current
30795 function was called.
30796
30797 @subsubheading @value{GDBN} Command
30798
30799 The corresponding @value{GDBN} command is @samp{finish}.
30800
30801 @subsubheading Example
30802
30803 Function returning @code{void}.
30804
30805 @smallexample
30806 -exec-finish
30807 ^running
30808 (gdb)
30809 @@hello from foo
30810 *stopped,reason="function-finished",frame=@{func="main",args=[],
30811 file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
30812 (gdb)
30813 @end smallexample
30814
30815 Function returning other than @code{void}. The name of the internal
30816 @value{GDBN} variable storing the result is printed, together with the
30817 value itself.
30818
30819 @smallexample
30820 -exec-finish
30821 ^running
30822 (gdb)
30823 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
30824 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
30825 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
30826 gdb-result-var="$1",return-value="0"
30827 (gdb)
30828 @end smallexample
30829
30830
30831 @subheading The @code{-exec-interrupt} Command
30832 @findex -exec-interrupt
30833
30834 @subsubheading Synopsis
30835
30836 @smallexample
30837 -exec-interrupt [--all|--thread-group N]
30838 @end smallexample
30839
30840 Interrupts the background execution of the target. Note how the token
30841 associated with the stop message is the one for the execution command
30842 that has been interrupted. The token for the interrupt itself only
30843 appears in the @samp{^done} output. If the user is trying to
30844 interrupt a non-running program, an error message will be printed.
30845
30846 Note that when asynchronous execution is enabled, this command is
30847 asynchronous just like other execution commands. That is, first the
30848 @samp{^done} response will be printed, and the target stop will be
30849 reported after that using the @samp{*stopped} notification.
30850
30851 In non-stop mode, only the context thread is interrupted by default.
30852 All threads (in all inferiors) will be interrupted if the
30853 @samp{--all} option is specified. If the @samp{--thread-group}
30854 option is specified, all threads in that group will be interrupted.
30855
30856 @subsubheading @value{GDBN} Command
30857
30858 The corresponding @value{GDBN} command is @samp{interrupt}.
30859
30860 @subsubheading Example
30861
30862 @smallexample
30863 (gdb)
30864 111-exec-continue
30865 111^running
30866
30867 (gdb)
30868 222-exec-interrupt
30869 222^done
30870 (gdb)
30871 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
30872 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
30873 fullname="/home/foo/bar/try.c",line="13"@}
30874 (gdb)
30875
30876 (gdb)
30877 -exec-interrupt
30878 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
30879 (gdb)
30880 @end smallexample
30881
30882 @subheading The @code{-exec-jump} Command
30883 @findex -exec-jump
30884
30885 @subsubheading Synopsis
30886
30887 @smallexample
30888 -exec-jump @var{location}
30889 @end smallexample
30890
30891 Resumes execution of the inferior program at the location specified by
30892 parameter. @xref{Specify Location}, for a description of the
30893 different forms of @var{location}.
30894
30895 @subsubheading @value{GDBN} Command
30896
30897 The corresponding @value{GDBN} command is @samp{jump}.
30898
30899 @subsubheading Example
30900
30901 @smallexample
30902 -exec-jump foo.c:10
30903 *running,thread-id="all"
30904 ^running
30905 @end smallexample
30906
30907
30908 @subheading The @code{-exec-next} Command
30909 @findex -exec-next
30910
30911 @subsubheading Synopsis
30912
30913 @smallexample
30914 -exec-next [--reverse]
30915 @end smallexample
30916
30917 Resumes execution of the inferior program, stopping when the beginning
30918 of the next source line is reached.
30919
30920 If the @samp{--reverse} option is specified, resumes reverse execution
30921 of the inferior program, stopping at the beginning of the previous
30922 source line. If you issue this command on the first line of a
30923 function, it will take you back to the caller of that function, to the
30924 source line where the function was called.
30925
30926
30927 @subsubheading @value{GDBN} Command
30928
30929 The corresponding @value{GDBN} command is @samp{next}.
30930
30931 @subsubheading Example
30932
30933 @smallexample
30934 -exec-next
30935 ^running
30936 (gdb)
30937 *stopped,reason="end-stepping-range",line="8",file="hello.c"
30938 (gdb)
30939 @end smallexample
30940
30941
30942 @subheading The @code{-exec-next-instruction} Command
30943 @findex -exec-next-instruction
30944
30945 @subsubheading Synopsis
30946
30947 @smallexample
30948 -exec-next-instruction [--reverse]
30949 @end smallexample
30950
30951 Executes one machine instruction. If the instruction is a function
30952 call, continues until the function returns. If the program stops at an
30953 instruction in the middle of a source line, the address will be
30954 printed as well.
30955
30956 If the @samp{--reverse} option is specified, resumes reverse execution
30957 of the inferior program, stopping at the previous instruction. If the
30958 previously executed instruction was a return from another function,
30959 it will continue to execute in reverse until the call to that function
30960 (from the current stack frame) is reached.
30961
30962 @subsubheading @value{GDBN} Command
30963
30964 The corresponding @value{GDBN} command is @samp{nexti}.
30965
30966 @subsubheading Example
30967
30968 @smallexample
30969 (gdb)
30970 -exec-next-instruction
30971 ^running
30972
30973 (gdb)
30974 *stopped,reason="end-stepping-range",
30975 addr="0x000100d4",line="5",file="hello.c"
30976 (gdb)
30977 @end smallexample
30978
30979
30980 @subheading The @code{-exec-return} Command
30981 @findex -exec-return
30982
30983 @subsubheading Synopsis
30984
30985 @smallexample
30986 -exec-return
30987 @end smallexample
30988
30989 Makes current function return immediately. Doesn't execute the inferior.
30990 Displays the new current frame.
30991
30992 @subsubheading @value{GDBN} Command
30993
30994 The corresponding @value{GDBN} command is @samp{return}.
30995
30996 @subsubheading Example
30997
30998 @smallexample
30999 (gdb)
31000 200-break-insert callee4
31001 200^done,bkpt=@{number="1",addr="0x00010734",
31002 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31003 (gdb)
31004 000-exec-run
31005 000^running
31006 (gdb)
31007 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31008 frame=@{func="callee4",args=[],
31009 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31010 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31011 (gdb)
31012 205-break-delete
31013 205^done
31014 (gdb)
31015 111-exec-return
31016 111^done,frame=@{level="0",func="callee3",
31017 args=[@{name="strarg",
31018 value="0x11940 \"A string argument.\""@}],
31019 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31020 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
31021 (gdb)
31022 @end smallexample
31023
31024
31025 @subheading The @code{-exec-run} Command
31026 @findex -exec-run
31027
31028 @subsubheading Synopsis
31029
31030 @smallexample
31031 -exec-run [--all | --thread-group N]
31032 @end smallexample
31033
31034 Starts execution of the inferior from the beginning. The inferior
31035 executes until either a breakpoint is encountered or the program
31036 exits. In the latter case the output will include an exit code, if
31037 the program has exited exceptionally.
31038
31039 When no option is specified, the current inferior is started. If the
31040 @samp{--thread-group} option is specified, it should refer to a thread
31041 group of type @samp{process}, and that thread group will be started.
31042 If the @samp{--all} option is specified, then all inferiors will be started.
31043
31044 @subsubheading @value{GDBN} Command
31045
31046 The corresponding @value{GDBN} command is @samp{run}.
31047
31048 @subsubheading Examples
31049
31050 @smallexample
31051 (gdb)
31052 -break-insert main
31053 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
31054 (gdb)
31055 -exec-run
31056 ^running
31057 (gdb)
31058 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31059 frame=@{func="main",args=[],file="recursive2.c",
31060 fullname="/home/foo/bar/recursive2.c",line="4"@}
31061 (gdb)
31062 @end smallexample
31063
31064 @noindent
31065 Program exited normally:
31066
31067 @smallexample
31068 (gdb)
31069 -exec-run
31070 ^running
31071 (gdb)
31072 x = 55
31073 *stopped,reason="exited-normally"
31074 (gdb)
31075 @end smallexample
31076
31077 @noindent
31078 Program exited exceptionally:
31079
31080 @smallexample
31081 (gdb)
31082 -exec-run
31083 ^running
31084 (gdb)
31085 x = 55
31086 *stopped,reason="exited",exit-code="01"
31087 (gdb)
31088 @end smallexample
31089
31090 Another way the program can terminate is if it receives a signal such as
31091 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31092
31093 @smallexample
31094 (gdb)
31095 *stopped,reason="exited-signalled",signal-name="SIGINT",
31096 signal-meaning="Interrupt"
31097 @end smallexample
31098
31099
31100 @c @subheading -exec-signal
31101
31102
31103 @subheading The @code{-exec-step} Command
31104 @findex -exec-step
31105
31106 @subsubheading Synopsis
31107
31108 @smallexample
31109 -exec-step [--reverse]
31110 @end smallexample
31111
31112 Resumes execution of the inferior program, stopping when the beginning
31113 of the next source line is reached, if the next source line is not a
31114 function call. If it is, stop at the first instruction of the called
31115 function. If the @samp{--reverse} option is specified, resumes reverse
31116 execution of the inferior program, stopping at the beginning of the
31117 previously executed source line.
31118
31119 @subsubheading @value{GDBN} Command
31120
31121 The corresponding @value{GDBN} command is @samp{step}.
31122
31123 @subsubheading Example
31124
31125 Stepping into a function:
31126
31127 @smallexample
31128 -exec-step
31129 ^running
31130 (gdb)
31131 *stopped,reason="end-stepping-range",
31132 frame=@{func="foo",args=[@{name="a",value="10"@},
31133 @{name="b",value="0"@}],file="recursive2.c",
31134 fullname="/home/foo/bar/recursive2.c",line="11"@}
31135 (gdb)
31136 @end smallexample
31137
31138 Regular stepping:
31139
31140 @smallexample
31141 -exec-step
31142 ^running
31143 (gdb)
31144 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
31145 (gdb)
31146 @end smallexample
31147
31148
31149 @subheading The @code{-exec-step-instruction} Command
31150 @findex -exec-step-instruction
31151
31152 @subsubheading Synopsis
31153
31154 @smallexample
31155 -exec-step-instruction [--reverse]
31156 @end smallexample
31157
31158 Resumes the inferior which executes one machine instruction. If the
31159 @samp{--reverse} option is specified, resumes reverse execution of the
31160 inferior program, stopping at the previously executed instruction.
31161 The output, once @value{GDBN} has stopped, will vary depending on
31162 whether we have stopped in the middle of a source line or not. In the
31163 former case, the address at which the program stopped will be printed
31164 as well.
31165
31166 @subsubheading @value{GDBN} Command
31167
31168 The corresponding @value{GDBN} command is @samp{stepi}.
31169
31170 @subsubheading Example
31171
31172 @smallexample
31173 (gdb)
31174 -exec-step-instruction
31175 ^running
31176
31177 (gdb)
31178 *stopped,reason="end-stepping-range",
31179 frame=@{func="foo",args=[],file="try.c",
31180 fullname="/home/foo/bar/try.c",line="10"@}
31181 (gdb)
31182 -exec-step-instruction
31183 ^running
31184
31185 (gdb)
31186 *stopped,reason="end-stepping-range",
31187 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
31188 fullname="/home/foo/bar/try.c",line="10"@}
31189 (gdb)
31190 @end smallexample
31191
31192
31193 @subheading The @code{-exec-until} Command
31194 @findex -exec-until
31195
31196 @subsubheading Synopsis
31197
31198 @smallexample
31199 -exec-until [ @var{location} ]
31200 @end smallexample
31201
31202 Executes the inferior until the @var{location} specified in the
31203 argument is reached. If there is no argument, the inferior executes
31204 until a source line greater than the current one is reached. The
31205 reason for stopping in this case will be @samp{location-reached}.
31206
31207 @subsubheading @value{GDBN} Command
31208
31209 The corresponding @value{GDBN} command is @samp{until}.
31210
31211 @subsubheading Example
31212
31213 @smallexample
31214 (gdb)
31215 -exec-until recursive2.c:6
31216 ^running
31217 (gdb)
31218 x = 55
31219 *stopped,reason="location-reached",frame=@{func="main",args=[],
31220 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
31221 (gdb)
31222 @end smallexample
31223
31224 @ignore
31225 @subheading -file-clear
31226 Is this going away????
31227 @end ignore
31228
31229 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31230 @node GDB/MI Stack Manipulation
31231 @section @sc{gdb/mi} Stack Manipulation Commands
31232
31233 @subheading The @code{-enable-frame-filters} Command
31234 @findex -enable-frame-filters
31235
31236 @smallexample
31237 -enable-frame-filters
31238 @end smallexample
31239
31240 @value{GDBN} allows Python-based frame filters to affect the output of
31241 the MI commands relating to stack traces. As there is no way to
31242 implement this in a fully backward-compatible way, a front end must
31243 request that this functionality be enabled.
31244
31245 Once enabled, this feature cannot be disabled.
31246
31247 Note that if Python support has not been compiled into @value{GDBN},
31248 this command will still succeed (and do nothing).
31249
31250 @subheading The @code{-stack-info-frame} Command
31251 @findex -stack-info-frame
31252
31253 @subsubheading Synopsis
31254
31255 @smallexample
31256 -stack-info-frame
31257 @end smallexample
31258
31259 Get info on the selected frame.
31260
31261 @subsubheading @value{GDBN} Command
31262
31263 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31264 (without arguments).
31265
31266 @subsubheading Example
31267
31268 @smallexample
31269 (gdb)
31270 -stack-info-frame
31271 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31272 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31273 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
31274 (gdb)
31275 @end smallexample
31276
31277 @subheading The @code{-stack-info-depth} Command
31278 @findex -stack-info-depth
31279
31280 @subsubheading Synopsis
31281
31282 @smallexample
31283 -stack-info-depth [ @var{max-depth} ]
31284 @end smallexample
31285
31286 Return the depth of the stack. If the integer argument @var{max-depth}
31287 is specified, do not count beyond @var{max-depth} frames.
31288
31289 @subsubheading @value{GDBN} Command
31290
31291 There's no equivalent @value{GDBN} command.
31292
31293 @subsubheading Example
31294
31295 For a stack with frame levels 0 through 11:
31296
31297 @smallexample
31298 (gdb)
31299 -stack-info-depth
31300 ^done,depth="12"
31301 (gdb)
31302 -stack-info-depth 4
31303 ^done,depth="4"
31304 (gdb)
31305 -stack-info-depth 12
31306 ^done,depth="12"
31307 (gdb)
31308 -stack-info-depth 11
31309 ^done,depth="11"
31310 (gdb)
31311 -stack-info-depth 13
31312 ^done,depth="12"
31313 (gdb)
31314 @end smallexample
31315
31316 @anchor{-stack-list-arguments}
31317 @subheading The @code{-stack-list-arguments} Command
31318 @findex -stack-list-arguments
31319
31320 @subsubheading Synopsis
31321
31322 @smallexample
31323 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31324 [ @var{low-frame} @var{high-frame} ]
31325 @end smallexample
31326
31327 Display a list of the arguments for the frames between @var{low-frame}
31328 and @var{high-frame} (inclusive). If @var{low-frame} and
31329 @var{high-frame} are not provided, list the arguments for the whole
31330 call stack. If the two arguments are equal, show the single frame
31331 at the corresponding level. It is an error if @var{low-frame} is
31332 larger than the actual number of frames. On the other hand,
31333 @var{high-frame} may be larger than the actual number of frames, in
31334 which case only existing frames will be returned.
31335
31336 If @var{print-values} is 0 or @code{--no-values}, print only the names of
31337 the variables; if it is 1 or @code{--all-values}, print also their
31338 values; and if it is 2 or @code{--simple-values}, print the name,
31339 type and value for simple data types, and the name and type for arrays,
31340 structures and unions. If the option @code{--no-frame-filters} is
31341 supplied, then Python frame filters will not be executed.
31342
31343 If the @code{--skip-unavailable} option is specified, arguments that
31344 are not available are not listed. Partially available arguments
31345 are still displayed, however.
31346
31347 Use of this command to obtain arguments in a single frame is
31348 deprecated in favor of the @samp{-stack-list-variables} command.
31349
31350 @subsubheading @value{GDBN} Command
31351
31352 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31353 @samp{gdb_get_args} command which partially overlaps with the
31354 functionality of @samp{-stack-list-arguments}.
31355
31356 @subsubheading Example
31357
31358 @smallexample
31359 (gdb)
31360 -stack-list-frames
31361 ^done,
31362 stack=[
31363 frame=@{level="0",addr="0x00010734",func="callee4",
31364 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31365 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
31366 frame=@{level="1",addr="0x0001076c",func="callee3",
31367 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31368 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
31369 frame=@{level="2",addr="0x0001078c",func="callee2",
31370 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31371 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
31372 frame=@{level="3",addr="0x000107b4",func="callee1",
31373 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31374 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
31375 frame=@{level="4",addr="0x000107e0",func="main",
31376 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31377 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
31378 (gdb)
31379 -stack-list-arguments 0
31380 ^done,
31381 stack-args=[
31382 frame=@{level="0",args=[]@},
31383 frame=@{level="1",args=[name="strarg"]@},
31384 frame=@{level="2",args=[name="intarg",name="strarg"]@},
31385 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31386 frame=@{level="4",args=[]@}]
31387 (gdb)
31388 -stack-list-arguments 1
31389 ^done,
31390 stack-args=[
31391 frame=@{level="0",args=[]@},
31392 frame=@{level="1",
31393 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31394 frame=@{level="2",args=[
31395 @{name="intarg",value="2"@},
31396 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31397 @{frame=@{level="3",args=[
31398 @{name="intarg",value="2"@},
31399 @{name="strarg",value="0x11940 \"A string argument.\""@},
31400 @{name="fltarg",value="3.5"@}]@},
31401 frame=@{level="4",args=[]@}]
31402 (gdb)
31403 -stack-list-arguments 0 2 2
31404 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
31405 (gdb)
31406 -stack-list-arguments 1 2 2
31407 ^done,stack-args=[frame=@{level="2",
31408 args=[@{name="intarg",value="2"@},
31409 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
31410 (gdb)
31411 @end smallexample
31412
31413 @c @subheading -stack-list-exception-handlers
31414
31415
31416 @anchor{-stack-list-frames}
31417 @subheading The @code{-stack-list-frames} Command
31418 @findex -stack-list-frames
31419
31420 @subsubheading Synopsis
31421
31422 @smallexample
31423 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
31424 @end smallexample
31425
31426 List the frames currently on the stack. For each frame it displays the
31427 following info:
31428
31429 @table @samp
31430 @item @var{level}
31431 The frame number, 0 being the topmost frame, i.e., the innermost function.
31432 @item @var{addr}
31433 The @code{$pc} value for that frame.
31434 @item @var{func}
31435 Function name.
31436 @item @var{file}
31437 File name of the source file where the function lives.
31438 @item @var{fullname}
31439 The full file name of the source file where the function lives.
31440 @item @var{line}
31441 Line number corresponding to the @code{$pc}.
31442 @item @var{from}
31443 The shared library where this function is defined. This is only given
31444 if the frame's function is not known.
31445 @end table
31446
31447 If invoked without arguments, this command prints a backtrace for the
31448 whole stack. If given two integer arguments, it shows the frames whose
31449 levels are between the two arguments (inclusive). If the two arguments
31450 are equal, it shows the single frame at the corresponding level. It is
31451 an error if @var{low-frame} is larger than the actual number of
31452 frames. On the other hand, @var{high-frame} may be larger than the
31453 actual number of frames, in which case only existing frames will be
31454 returned. If the option @code{--no-frame-filters} is supplied, then
31455 Python frame filters will not be executed.
31456
31457 @subsubheading @value{GDBN} Command
31458
31459 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
31460
31461 @subsubheading Example
31462
31463 Full stack backtrace:
31464
31465 @smallexample
31466 (gdb)
31467 -stack-list-frames
31468 ^done,stack=
31469 [frame=@{level="0",addr="0x0001076c",func="foo",
31470 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
31471 frame=@{level="1",addr="0x000107a4",func="foo",
31472 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31473 frame=@{level="2",addr="0x000107a4",func="foo",
31474 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31475 frame=@{level="3",addr="0x000107a4",func="foo",
31476 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31477 frame=@{level="4",addr="0x000107a4",func="foo",
31478 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31479 frame=@{level="5",addr="0x000107a4",func="foo",
31480 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31481 frame=@{level="6",addr="0x000107a4",func="foo",
31482 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31483 frame=@{level="7",addr="0x000107a4",func="foo",
31484 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31485 frame=@{level="8",addr="0x000107a4",func="foo",
31486 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31487 frame=@{level="9",addr="0x000107a4",func="foo",
31488 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31489 frame=@{level="10",addr="0x000107a4",func="foo",
31490 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31491 frame=@{level="11",addr="0x00010738",func="main",
31492 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
31493 (gdb)
31494 @end smallexample
31495
31496 Show frames between @var{low_frame} and @var{high_frame}:
31497
31498 @smallexample
31499 (gdb)
31500 -stack-list-frames 3 5
31501 ^done,stack=
31502 [frame=@{level="3",addr="0x000107a4",func="foo",
31503 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31504 frame=@{level="4",addr="0x000107a4",func="foo",
31505 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
31506 frame=@{level="5",addr="0x000107a4",func="foo",
31507 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
31508 (gdb)
31509 @end smallexample
31510
31511 Show a single frame:
31512
31513 @smallexample
31514 (gdb)
31515 -stack-list-frames 3 3
31516 ^done,stack=
31517 [frame=@{level="3",addr="0x000107a4",func="foo",
31518 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
31519 (gdb)
31520 @end smallexample
31521
31522
31523 @subheading The @code{-stack-list-locals} Command
31524 @findex -stack-list-locals
31525 @anchor{-stack-list-locals}
31526
31527 @subsubheading Synopsis
31528
31529 @smallexample
31530 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31531 @end smallexample
31532
31533 Display the local variable names for the selected frame. If
31534 @var{print-values} is 0 or @code{--no-values}, print only the names of
31535 the variables; if it is 1 or @code{--all-values}, print also their
31536 values; and if it is 2 or @code{--simple-values}, print the name,
31537 type and value for simple data types, and the name and type for arrays,
31538 structures and unions. In this last case, a frontend can immediately
31539 display the value of simple data types and create variable objects for
31540 other data types when the user wishes to explore their values in
31541 more detail. If the option @code{--no-frame-filters} is supplied, then
31542 Python frame filters will not be executed.
31543
31544 If the @code{--skip-unavailable} option is specified, local variables
31545 that are not available are not listed. Partially available local
31546 variables are still displayed, however.
31547
31548 This command is deprecated in favor of the
31549 @samp{-stack-list-variables} command.
31550
31551 @subsubheading @value{GDBN} Command
31552
31553 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
31554
31555 @subsubheading Example
31556
31557 @smallexample
31558 (gdb)
31559 -stack-list-locals 0
31560 ^done,locals=[name="A",name="B",name="C"]
31561 (gdb)
31562 -stack-list-locals --all-values
31563 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
31564 @{name="C",value="@{1, 2, 3@}"@}]
31565 -stack-list-locals --simple-values
31566 ^done,locals=[@{name="A",type="int",value="1"@},
31567 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
31568 (gdb)
31569 @end smallexample
31570
31571 @anchor{-stack-list-variables}
31572 @subheading The @code{-stack-list-variables} Command
31573 @findex -stack-list-variables
31574
31575 @subsubheading Synopsis
31576
31577 @smallexample
31578 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31579 @end smallexample
31580
31581 Display the names of local variables and function arguments for the selected frame. If
31582 @var{print-values} is 0 or @code{--no-values}, print only the names of
31583 the variables; if it is 1 or @code{--all-values}, print also their
31584 values; and if it is 2 or @code{--simple-values}, print the name,
31585 type and value for simple data types, and the name and type for arrays,
31586 structures and unions. If the option @code{--no-frame-filters} is
31587 supplied, then Python frame filters will not be executed.
31588
31589 If the @code{--skip-unavailable} option is specified, local variables
31590 and arguments that are not available are not listed. Partially
31591 available arguments and local variables are still displayed, however.
31592
31593 @subsubheading Example
31594
31595 @smallexample
31596 (gdb)
31597 -stack-list-variables --thread 1 --frame 0 --all-values
31598 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
31599 (gdb)
31600 @end smallexample
31601
31602
31603 @subheading The @code{-stack-select-frame} Command
31604 @findex -stack-select-frame
31605
31606 @subsubheading Synopsis
31607
31608 @smallexample
31609 -stack-select-frame @var{framenum}
31610 @end smallexample
31611
31612 Change the selected frame. Select a different frame @var{framenum} on
31613 the stack.
31614
31615 This command in deprecated in favor of passing the @samp{--frame}
31616 option to every command.
31617
31618 @subsubheading @value{GDBN} Command
31619
31620 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
31621 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
31622
31623 @subsubheading Example
31624
31625 @smallexample
31626 (gdb)
31627 -stack-select-frame 2
31628 ^done
31629 (gdb)
31630 @end smallexample
31631
31632 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31633 @node GDB/MI Variable Objects
31634 @section @sc{gdb/mi} Variable Objects
31635
31636 @ignore
31637
31638 @subheading Motivation for Variable Objects in @sc{gdb/mi}
31639
31640 For the implementation of a variable debugger window (locals, watched
31641 expressions, etc.), we are proposing the adaptation of the existing code
31642 used by @code{Insight}.
31643
31644 The two main reasons for that are:
31645
31646 @enumerate 1
31647 @item
31648 It has been proven in practice (it is already on its second generation).
31649
31650 @item
31651 It will shorten development time (needless to say how important it is
31652 now).
31653 @end enumerate
31654
31655 The original interface was designed to be used by Tcl code, so it was
31656 slightly changed so it could be used through @sc{gdb/mi}. This section
31657 describes the @sc{gdb/mi} operations that will be available and gives some
31658 hints about their use.
31659
31660 @emph{Note}: In addition to the set of operations described here, we
31661 expect the @sc{gui} implementation of a variable window to require, at
31662 least, the following operations:
31663
31664 @itemize @bullet
31665 @item @code{-gdb-show} @code{output-radix}
31666 @item @code{-stack-list-arguments}
31667 @item @code{-stack-list-locals}
31668 @item @code{-stack-select-frame}
31669 @end itemize
31670
31671 @end ignore
31672
31673 @subheading Introduction to Variable Objects
31674
31675 @cindex variable objects in @sc{gdb/mi}
31676
31677 Variable objects are "object-oriented" MI interface for examining and
31678 changing values of expressions. Unlike some other MI interfaces that
31679 work with expressions, variable objects are specifically designed for
31680 simple and efficient presentation in the frontend. A variable object
31681 is identified by string name. When a variable object is created, the
31682 frontend specifies the expression for that variable object. The
31683 expression can be a simple variable, or it can be an arbitrary complex
31684 expression, and can even involve CPU registers. After creating a
31685 variable object, the frontend can invoke other variable object
31686 operations---for example to obtain or change the value of a variable
31687 object, or to change display format.
31688
31689 Variable objects have hierarchical tree structure. Any variable object
31690 that corresponds to a composite type, such as structure in C, has
31691 a number of child variable objects, for example corresponding to each
31692 element of a structure. A child variable object can itself have
31693 children, recursively. Recursion ends when we reach
31694 leaf variable objects, which always have built-in types. Child variable
31695 objects are created only by explicit request, so if a frontend
31696 is not interested in the children of a particular variable object, no
31697 child will be created.
31698
31699 For a leaf variable object it is possible to obtain its value as a
31700 string, or set the value from a string. String value can be also
31701 obtained for a non-leaf variable object, but it's generally a string
31702 that only indicates the type of the object, and does not list its
31703 contents. Assignment to a non-leaf variable object is not allowed.
31704
31705 A frontend does not need to read the values of all variable objects each time
31706 the program stops. Instead, MI provides an update command that lists all
31707 variable objects whose values has changed since the last update
31708 operation. This considerably reduces the amount of data that must
31709 be transferred to the frontend. As noted above, children variable
31710 objects are created on demand, and only leaf variable objects have a
31711 real value. As result, gdb will read target memory only for leaf
31712 variables that frontend has created.
31713
31714 The automatic update is not always desirable. For example, a frontend
31715 might want to keep a value of some expression for future reference,
31716 and never update it. For another example, fetching memory is
31717 relatively slow for embedded targets, so a frontend might want
31718 to disable automatic update for the variables that are either not
31719 visible on the screen, or ``closed''. This is possible using so
31720 called ``frozen variable objects''. Such variable objects are never
31721 implicitly updated.
31722
31723 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
31724 fixed variable object, the expression is parsed when the variable
31725 object is created, including associating identifiers to specific
31726 variables. The meaning of expression never changes. For a floating
31727 variable object the values of variables whose names appear in the
31728 expressions are re-evaluated every time in the context of the current
31729 frame. Consider this example:
31730
31731 @smallexample
31732 void do_work(...)
31733 @{
31734 struct work_state state;
31735
31736 if (...)
31737 do_work(...);
31738 @}
31739 @end smallexample
31740
31741 If a fixed variable object for the @code{state} variable is created in
31742 this function, and we enter the recursive call, the variable
31743 object will report the value of @code{state} in the top-level
31744 @code{do_work} invocation. On the other hand, a floating variable
31745 object will report the value of @code{state} in the current frame.
31746
31747 If an expression specified when creating a fixed variable object
31748 refers to a local variable, the variable object becomes bound to the
31749 thread and frame in which the variable object is created. When such
31750 variable object is updated, @value{GDBN} makes sure that the
31751 thread/frame combination the variable object is bound to still exists,
31752 and re-evaluates the variable object in context of that thread/frame.
31753
31754 The following is the complete set of @sc{gdb/mi} operations defined to
31755 access this functionality:
31756
31757 @multitable @columnfractions .4 .6
31758 @item @strong{Operation}
31759 @tab @strong{Description}
31760
31761 @item @code{-enable-pretty-printing}
31762 @tab enable Python-based pretty-printing
31763 @item @code{-var-create}
31764 @tab create a variable object
31765 @item @code{-var-delete}
31766 @tab delete the variable object and/or its children
31767 @item @code{-var-set-format}
31768 @tab set the display format of this variable
31769 @item @code{-var-show-format}
31770 @tab show the display format of this variable
31771 @item @code{-var-info-num-children}
31772 @tab tells how many children this object has
31773 @item @code{-var-list-children}
31774 @tab return a list of the object's children
31775 @item @code{-var-info-type}
31776 @tab show the type of this variable object
31777 @item @code{-var-info-expression}
31778 @tab print parent-relative expression that this variable object represents
31779 @item @code{-var-info-path-expression}
31780 @tab print full expression that this variable object represents
31781 @item @code{-var-show-attributes}
31782 @tab is this variable editable? does it exist here?
31783 @item @code{-var-evaluate-expression}
31784 @tab get the value of this variable
31785 @item @code{-var-assign}
31786 @tab set the value of this variable
31787 @item @code{-var-update}
31788 @tab update the variable and its children
31789 @item @code{-var-set-frozen}
31790 @tab set frozeness attribute
31791 @item @code{-var-set-update-range}
31792 @tab set range of children to display on update
31793 @end multitable
31794
31795 In the next subsection we describe each operation in detail and suggest
31796 how it can be used.
31797
31798 @subheading Description And Use of Operations on Variable Objects
31799
31800 @subheading The @code{-enable-pretty-printing} Command
31801 @findex -enable-pretty-printing
31802
31803 @smallexample
31804 -enable-pretty-printing
31805 @end smallexample
31806
31807 @value{GDBN} allows Python-based visualizers to affect the output of the
31808 MI variable object commands. However, because there was no way to
31809 implement this in a fully backward-compatible way, a front end must
31810 request that this functionality be enabled.
31811
31812 Once enabled, this feature cannot be disabled.
31813
31814 Note that if Python support has not been compiled into @value{GDBN},
31815 this command will still succeed (and do nothing).
31816
31817 This feature is currently (as of @value{GDBN} 7.0) experimental, and
31818 may work differently in future versions of @value{GDBN}.
31819
31820 @subheading The @code{-var-create} Command
31821 @findex -var-create
31822
31823 @subsubheading Synopsis
31824
31825 @smallexample
31826 -var-create @{@var{name} | "-"@}
31827 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
31828 @end smallexample
31829
31830 This operation creates a variable object, which allows the monitoring of
31831 a variable, the result of an expression, a memory cell or a CPU
31832 register.
31833
31834 The @var{name} parameter is the string by which the object can be
31835 referenced. It must be unique. If @samp{-} is specified, the varobj
31836 system will generate a string ``varNNNNNN'' automatically. It will be
31837 unique provided that one does not specify @var{name} of that format.
31838 The command fails if a duplicate name is found.
31839
31840 The frame under which the expression should be evaluated can be
31841 specified by @var{frame-addr}. A @samp{*} indicates that the current
31842 frame should be used. A @samp{@@} indicates that a floating variable
31843 object must be created.
31844
31845 @var{expression} is any expression valid on the current language set (must not
31846 begin with a @samp{*}), or one of the following:
31847
31848 @itemize @bullet
31849 @item
31850 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
31851
31852 @item
31853 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
31854
31855 @item
31856 @samp{$@var{regname}} --- a CPU register name
31857 @end itemize
31858
31859 @cindex dynamic varobj
31860 A varobj's contents may be provided by a Python-based pretty-printer. In this
31861 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
31862 have slightly different semantics in some cases. If the
31863 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
31864 will never create a dynamic varobj. This ensures backward
31865 compatibility for existing clients.
31866
31867 @subsubheading Result
31868
31869 This operation returns attributes of the newly-created varobj. These
31870 are:
31871
31872 @table @samp
31873 @item name
31874 The name of the varobj.
31875
31876 @item numchild
31877 The number of children of the varobj. This number is not necessarily
31878 reliable for a dynamic varobj. Instead, you must examine the
31879 @samp{has_more} attribute.
31880
31881 @item value
31882 The varobj's scalar value. For a varobj whose type is some sort of
31883 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
31884 will not be interesting.
31885
31886 @item type
31887 The varobj's type. This is a string representation of the type, as
31888 would be printed by the @value{GDBN} CLI. If @samp{print object}
31889 (@pxref{Print Settings, set print object}) is set to @code{on}, the
31890 @emph{actual} (derived) type of the object is shown rather than the
31891 @emph{declared} one.
31892
31893 @item thread-id
31894 If a variable object is bound to a specific thread, then this is the
31895 thread's identifier.
31896
31897 @item has_more
31898 For a dynamic varobj, this indicates whether there appear to be any
31899 children available. For a non-dynamic varobj, this will be 0.
31900
31901 @item dynamic
31902 This attribute will be present and have the value @samp{1} if the
31903 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
31904 then this attribute will not be present.
31905
31906 @item displayhint
31907 A dynamic varobj can supply a display hint to the front end. The
31908 value comes directly from the Python pretty-printer object's
31909 @code{display_hint} method. @xref{Pretty Printing API}.
31910 @end table
31911
31912 Typical output will look like this:
31913
31914 @smallexample
31915 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
31916 has_more="@var{has_more}"
31917 @end smallexample
31918
31919
31920 @subheading The @code{-var-delete} Command
31921 @findex -var-delete
31922
31923 @subsubheading Synopsis
31924
31925 @smallexample
31926 -var-delete [ -c ] @var{name}
31927 @end smallexample
31928
31929 Deletes a previously created variable object and all of its children.
31930 With the @samp{-c} option, just deletes the children.
31931
31932 Returns an error if the object @var{name} is not found.
31933
31934
31935 @subheading The @code{-var-set-format} Command
31936 @findex -var-set-format
31937
31938 @subsubheading Synopsis
31939
31940 @smallexample
31941 -var-set-format @var{name} @var{format-spec}
31942 @end smallexample
31943
31944 Sets the output format for the value of the object @var{name} to be
31945 @var{format-spec}.
31946
31947 @anchor{-var-set-format}
31948 The syntax for the @var{format-spec} is as follows:
31949
31950 @smallexample
31951 @var{format-spec} @expansion{}
31952 @{binary | decimal | hexadecimal | octal | natural@}
31953 @end smallexample
31954
31955 The natural format is the default format choosen automatically
31956 based on the variable type (like decimal for an @code{int}, hex
31957 for pointers, etc.).
31958
31959 For a variable with children, the format is set only on the
31960 variable itself, and the children are not affected.
31961
31962 @subheading The @code{-var-show-format} Command
31963 @findex -var-show-format
31964
31965 @subsubheading Synopsis
31966
31967 @smallexample
31968 -var-show-format @var{name}
31969 @end smallexample
31970
31971 Returns the format used to display the value of the object @var{name}.
31972
31973 @smallexample
31974 @var{format} @expansion{}
31975 @var{format-spec}
31976 @end smallexample
31977
31978
31979 @subheading The @code{-var-info-num-children} Command
31980 @findex -var-info-num-children
31981
31982 @subsubheading Synopsis
31983
31984 @smallexample
31985 -var-info-num-children @var{name}
31986 @end smallexample
31987
31988 Returns the number of children of a variable object @var{name}:
31989
31990 @smallexample
31991 numchild=@var{n}
31992 @end smallexample
31993
31994 Note that this number is not completely reliable for a dynamic varobj.
31995 It will return the current number of children, but more children may
31996 be available.
31997
31998
31999 @subheading The @code{-var-list-children} Command
32000 @findex -var-list-children
32001
32002 @subsubheading Synopsis
32003
32004 @smallexample
32005 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
32006 @end smallexample
32007 @anchor{-var-list-children}
32008
32009 Return a list of the children of the specified variable object and
32010 create variable objects for them, if they do not already exist. With
32011 a single argument or if @var{print-values} has a value of 0 or
32012 @code{--no-values}, print only the names of the variables; if
32013 @var{print-values} is 1 or @code{--all-values}, also print their
32014 values; and if it is 2 or @code{--simple-values} print the name and
32015 value for simple data types and just the name for arrays, structures
32016 and unions.
32017
32018 @var{from} and @var{to}, if specified, indicate the range of children
32019 to report. If @var{from} or @var{to} is less than zero, the range is
32020 reset and all children will be reported. Otherwise, children starting
32021 at @var{from} (zero-based) and up to and excluding @var{to} will be
32022 reported.
32023
32024 If a child range is requested, it will only affect the current call to
32025 @code{-var-list-children}, but not future calls to @code{-var-update}.
32026 For this, you must instead use @code{-var-set-update-range}. The
32027 intent of this approach is to enable a front end to implement any
32028 update approach it likes; for example, scrolling a view may cause the
32029 front end to request more children with @code{-var-list-children}, and
32030 then the front end could call @code{-var-set-update-range} with a
32031 different range to ensure that future updates are restricted to just
32032 the visible items.
32033
32034 For each child the following results are returned:
32035
32036 @table @var
32037
32038 @item name
32039 Name of the variable object created for this child.
32040
32041 @item exp
32042 The expression to be shown to the user by the front end to designate this child.
32043 For example this may be the name of a structure member.
32044
32045 For a dynamic varobj, this value cannot be used to form an
32046 expression. There is no way to do this at all with a dynamic varobj.
32047
32048 For C/C@t{++} structures there are several pseudo children returned to
32049 designate access qualifiers. For these pseudo children @var{exp} is
32050 @samp{public}, @samp{private}, or @samp{protected}. In this case the
32051 type and value are not present.
32052
32053 A dynamic varobj will not report the access qualifying
32054 pseudo-children, regardless of the language. This information is not
32055 available at all with a dynamic varobj.
32056
32057 @item numchild
32058 Number of children this child has. For a dynamic varobj, this will be
32059 0.
32060
32061 @item type
32062 The type of the child. If @samp{print object}
32063 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32064 @emph{actual} (derived) type of the object is shown rather than the
32065 @emph{declared} one.
32066
32067 @item value
32068 If values were requested, this is the value.
32069
32070 @item thread-id
32071 If this variable object is associated with a thread, this is the thread id.
32072 Otherwise this result is not present.
32073
32074 @item frozen
32075 If the variable object is frozen, this variable will be present with a value of 1.
32076 @end table
32077
32078 The result may have its own attributes:
32079
32080 @table @samp
32081 @item displayhint
32082 A dynamic varobj can supply a display hint to the front end. The
32083 value comes directly from the Python pretty-printer object's
32084 @code{display_hint} method. @xref{Pretty Printing API}.
32085
32086 @item has_more
32087 This is an integer attribute which is nonzero if there are children
32088 remaining after the end of the selected range.
32089 @end table
32090
32091 @subsubheading Example
32092
32093 @smallexample
32094 (gdb)
32095 -var-list-children n
32096 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32097 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
32098 (gdb)
32099 -var-list-children --all-values n
32100 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32101 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
32102 @end smallexample
32103
32104
32105 @subheading The @code{-var-info-type} Command
32106 @findex -var-info-type
32107
32108 @subsubheading Synopsis
32109
32110 @smallexample
32111 -var-info-type @var{name}
32112 @end smallexample
32113
32114 Returns the type of the specified variable @var{name}. The type is
32115 returned as a string in the same format as it is output by the
32116 @value{GDBN} CLI:
32117
32118 @smallexample
32119 type=@var{typename}
32120 @end smallexample
32121
32122
32123 @subheading The @code{-var-info-expression} Command
32124 @findex -var-info-expression
32125
32126 @subsubheading Synopsis
32127
32128 @smallexample
32129 -var-info-expression @var{name}
32130 @end smallexample
32131
32132 Returns a string that is suitable for presenting this
32133 variable object in user interface. The string is generally
32134 not valid expression in the current language, and cannot be evaluated.
32135
32136 For example, if @code{a} is an array, and variable object
32137 @code{A} was created for @code{a}, then we'll get this output:
32138
32139 @smallexample
32140 (gdb) -var-info-expression A.1
32141 ^done,lang="C",exp="1"
32142 @end smallexample
32143
32144 @noindent
32145 Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
32146
32147 Note that the output of the @code{-var-list-children} command also
32148 includes those expressions, so the @code{-var-info-expression} command
32149 is of limited use.
32150
32151 @subheading The @code{-var-info-path-expression} Command
32152 @findex -var-info-path-expression
32153
32154 @subsubheading Synopsis
32155
32156 @smallexample
32157 -var-info-path-expression @var{name}
32158 @end smallexample
32159
32160 Returns an expression that can be evaluated in the current
32161 context and will yield the same value that a variable object has.
32162 Compare this with the @code{-var-info-expression} command, which
32163 result can be used only for UI presentation. Typical use of
32164 the @code{-var-info-path-expression} command is creating a
32165 watchpoint from a variable object.
32166
32167 This command is currently not valid for children of a dynamic varobj,
32168 and will give an error when invoked on one.
32169
32170 For example, suppose @code{C} is a C@t{++} class, derived from class
32171 @code{Base}, and that the @code{Base} class has a member called
32172 @code{m_size}. Assume a variable @code{c} is has the type of
32173 @code{C} and a variable object @code{C} was created for variable
32174 @code{c}. Then, we'll get this output:
32175 @smallexample
32176 (gdb) -var-info-path-expression C.Base.public.m_size
32177 ^done,path_expr=((Base)c).m_size)
32178 @end smallexample
32179
32180 @subheading The @code{-var-show-attributes} Command
32181 @findex -var-show-attributes
32182
32183 @subsubheading Synopsis
32184
32185 @smallexample
32186 -var-show-attributes @var{name}
32187 @end smallexample
32188
32189 List attributes of the specified variable object @var{name}:
32190
32191 @smallexample
32192 status=@var{attr} [ ( ,@var{attr} )* ]
32193 @end smallexample
32194
32195 @noindent
32196 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32197
32198 @subheading The @code{-var-evaluate-expression} Command
32199 @findex -var-evaluate-expression
32200
32201 @subsubheading Synopsis
32202
32203 @smallexample
32204 -var-evaluate-expression [-f @var{format-spec}] @var{name}
32205 @end smallexample
32206
32207 Evaluates the expression that is represented by the specified variable
32208 object and returns its value as a string. The format of the string
32209 can be specified with the @samp{-f} option. The possible values of
32210 this option are the same as for @code{-var-set-format}
32211 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32212 the current display format will be used. The current display format
32213 can be changed using the @code{-var-set-format} command.
32214
32215 @smallexample
32216 value=@var{value}
32217 @end smallexample
32218
32219 Note that one must invoke @code{-var-list-children} for a variable
32220 before the value of a child variable can be evaluated.
32221
32222 @subheading The @code{-var-assign} Command
32223 @findex -var-assign
32224
32225 @subsubheading Synopsis
32226
32227 @smallexample
32228 -var-assign @var{name} @var{expression}
32229 @end smallexample
32230
32231 Assigns the value of @var{expression} to the variable object specified
32232 by @var{name}. The object must be @samp{editable}. If the variable's
32233 value is altered by the assign, the variable will show up in any
32234 subsequent @code{-var-update} list.
32235
32236 @subsubheading Example
32237
32238 @smallexample
32239 (gdb)
32240 -var-assign var1 3
32241 ^done,value="3"
32242 (gdb)
32243 -var-update *
32244 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
32245 (gdb)
32246 @end smallexample
32247
32248 @subheading The @code{-var-update} Command
32249 @findex -var-update
32250
32251 @subsubheading Synopsis
32252
32253 @smallexample
32254 -var-update [@var{print-values}] @{@var{name} | "*"@}
32255 @end smallexample
32256
32257 Reevaluate the expressions corresponding to the variable object
32258 @var{name} and all its direct and indirect children, and return the
32259 list of variable objects whose values have changed; @var{name} must
32260 be a root variable object. Here, ``changed'' means that the result of
32261 @code{-var-evaluate-expression} before and after the
32262 @code{-var-update} is different. If @samp{*} is used as the variable
32263 object names, all existing variable objects are updated, except
32264 for frozen ones (@pxref{-var-set-frozen}). The option
32265 @var{print-values} determines whether both names and values, or just
32266 names are printed. The possible values of this option are the same
32267 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32268 recommended to use the @samp{--all-values} option, to reduce the
32269 number of MI commands needed on each program stop.
32270
32271 With the @samp{*} parameter, if a variable object is bound to a
32272 currently running thread, it will not be updated, without any
32273 diagnostic.
32274
32275 If @code{-var-set-update-range} was previously used on a varobj, then
32276 only the selected range of children will be reported.
32277
32278 @code{-var-update} reports all the changed varobjs in a tuple named
32279 @samp{changelist}.
32280
32281 Each item in the change list is itself a tuple holding:
32282
32283 @table @samp
32284 @item name
32285 The name of the varobj.
32286
32287 @item value
32288 If values were requested for this update, then this field will be
32289 present and will hold the value of the varobj.
32290
32291 @item in_scope
32292 @anchor{-var-update}
32293 This field is a string which may take one of three values:
32294
32295 @table @code
32296 @item "true"
32297 The variable object's current value is valid.
32298
32299 @item "false"
32300 The variable object does not currently hold a valid value but it may
32301 hold one in the future if its associated expression comes back into
32302 scope.
32303
32304 @item "invalid"
32305 The variable object no longer holds a valid value.
32306 This can occur when the executable file being debugged has changed,
32307 either through recompilation or by using the @value{GDBN} @code{file}
32308 command. The front end should normally choose to delete these variable
32309 objects.
32310 @end table
32311
32312 In the future new values may be added to this list so the front should
32313 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32314
32315 @item type_changed
32316 This is only present if the varobj is still valid. If the type
32317 changed, then this will be the string @samp{true}; otherwise it will
32318 be @samp{false}.
32319
32320 When a varobj's type changes, its children are also likely to have
32321 become incorrect. Therefore, the varobj's children are automatically
32322 deleted when this attribute is @samp{true}. Also, the varobj's update
32323 range, when set using the @code{-var-set-update-range} command, is
32324 unset.
32325
32326 @item new_type
32327 If the varobj's type changed, then this field will be present and will
32328 hold the new type.
32329
32330 @item new_num_children
32331 For a dynamic varobj, if the number of children changed, or if the
32332 type changed, this will be the new number of children.
32333
32334 The @samp{numchild} field in other varobj responses is generally not
32335 valid for a dynamic varobj -- it will show the number of children that
32336 @value{GDBN} knows about, but because dynamic varobjs lazily
32337 instantiate their children, this will not reflect the number of
32338 children which may be available.
32339
32340 The @samp{new_num_children} attribute only reports changes to the
32341 number of children known by @value{GDBN}. This is the only way to
32342 detect whether an update has removed children (which necessarily can
32343 only happen at the end of the update range).
32344
32345 @item displayhint
32346 The display hint, if any.
32347
32348 @item has_more
32349 This is an integer value, which will be 1 if there are more children
32350 available outside the varobj's update range.
32351
32352 @item dynamic
32353 This attribute will be present and have the value @samp{1} if the
32354 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32355 then this attribute will not be present.
32356
32357 @item new_children
32358 If new children were added to a dynamic varobj within the selected
32359 update range (as set by @code{-var-set-update-range}), then they will
32360 be listed in this attribute.
32361 @end table
32362
32363 @subsubheading Example
32364
32365 @smallexample
32366 (gdb)
32367 -var-assign var1 3
32368 ^done,value="3"
32369 (gdb)
32370 -var-update --all-values var1
32371 ^done,changelist=[@{name="var1",value="3",in_scope="true",
32372 type_changed="false"@}]
32373 (gdb)
32374 @end smallexample
32375
32376 @subheading The @code{-var-set-frozen} Command
32377 @findex -var-set-frozen
32378 @anchor{-var-set-frozen}
32379
32380 @subsubheading Synopsis
32381
32382 @smallexample
32383 -var-set-frozen @var{name} @var{flag}
32384 @end smallexample
32385
32386 Set the frozenness flag on the variable object @var{name}. The
32387 @var{flag} parameter should be either @samp{1} to make the variable
32388 frozen or @samp{0} to make it unfrozen. If a variable object is
32389 frozen, then neither itself, nor any of its children, are
32390 implicitly updated by @code{-var-update} of
32391 a parent variable or by @code{-var-update *}. Only
32392 @code{-var-update} of the variable itself will update its value and
32393 values of its children. After a variable object is unfrozen, it is
32394 implicitly updated by all subsequent @code{-var-update} operations.
32395 Unfreezing a variable does not update it, only subsequent
32396 @code{-var-update} does.
32397
32398 @subsubheading Example
32399
32400 @smallexample
32401 (gdb)
32402 -var-set-frozen V 1
32403 ^done
32404 (gdb)
32405 @end smallexample
32406
32407 @subheading The @code{-var-set-update-range} command
32408 @findex -var-set-update-range
32409 @anchor{-var-set-update-range}
32410
32411 @subsubheading Synopsis
32412
32413 @smallexample
32414 -var-set-update-range @var{name} @var{from} @var{to}
32415 @end smallexample
32416
32417 Set the range of children to be returned by future invocations of
32418 @code{-var-update}.
32419
32420 @var{from} and @var{to} indicate the range of children to report. If
32421 @var{from} or @var{to} is less than zero, the range is reset and all
32422 children will be reported. Otherwise, children starting at @var{from}
32423 (zero-based) and up to and excluding @var{to} will be reported.
32424
32425 @subsubheading Example
32426
32427 @smallexample
32428 (gdb)
32429 -var-set-update-range V 1 2
32430 ^done
32431 @end smallexample
32432
32433 @subheading The @code{-var-set-visualizer} command
32434 @findex -var-set-visualizer
32435 @anchor{-var-set-visualizer}
32436
32437 @subsubheading Synopsis
32438
32439 @smallexample
32440 -var-set-visualizer @var{name} @var{visualizer}
32441 @end smallexample
32442
32443 Set a visualizer for the variable object @var{name}.
32444
32445 @var{visualizer} is the visualizer to use. The special value
32446 @samp{None} means to disable any visualizer in use.
32447
32448 If not @samp{None}, @var{visualizer} must be a Python expression.
32449 This expression must evaluate to a callable object which accepts a
32450 single argument. @value{GDBN} will call this object with the value of
32451 the varobj @var{name} as an argument (this is done so that the same
32452 Python pretty-printing code can be used for both the CLI and MI).
32453 When called, this object must return an object which conforms to the
32454 pretty-printing interface (@pxref{Pretty Printing API}).
32455
32456 The pre-defined function @code{gdb.default_visualizer} may be used to
32457 select a visualizer by following the built-in process
32458 (@pxref{Selecting Pretty-Printers}). This is done automatically when
32459 a varobj is created, and so ordinarily is not needed.
32460
32461 This feature is only available if Python support is enabled. The MI
32462 command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
32463 can be used to check this.
32464
32465 @subsubheading Example
32466
32467 Resetting the visualizer:
32468
32469 @smallexample
32470 (gdb)
32471 -var-set-visualizer V None
32472 ^done
32473 @end smallexample
32474
32475 Reselecting the default (type-based) visualizer:
32476
32477 @smallexample
32478 (gdb)
32479 -var-set-visualizer V gdb.default_visualizer
32480 ^done
32481 @end smallexample
32482
32483 Suppose @code{SomeClass} is a visualizer class. A lambda expression
32484 can be used to instantiate this class for a varobj:
32485
32486 @smallexample
32487 (gdb)
32488 -var-set-visualizer V "lambda val: SomeClass()"
32489 ^done
32490 @end smallexample
32491
32492 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32493 @node GDB/MI Data Manipulation
32494 @section @sc{gdb/mi} Data Manipulation
32495
32496 @cindex data manipulation, in @sc{gdb/mi}
32497 @cindex @sc{gdb/mi}, data manipulation
32498 This section describes the @sc{gdb/mi} commands that manipulate data:
32499 examine memory and registers, evaluate expressions, etc.
32500
32501 @c REMOVED FROM THE INTERFACE.
32502 @c @subheading -data-assign
32503 @c Change the value of a program variable. Plenty of side effects.
32504 @c @subsubheading GDB Command
32505 @c set variable
32506 @c @subsubheading Example
32507 @c N.A.
32508
32509 @subheading The @code{-data-disassemble} Command
32510 @findex -data-disassemble
32511
32512 @subsubheading Synopsis
32513
32514 @smallexample
32515 -data-disassemble
32516 [ -s @var{start-addr} -e @var{end-addr} ]
32517 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
32518 -- @var{mode}
32519 @end smallexample
32520
32521 @noindent
32522 Where:
32523
32524 @table @samp
32525 @item @var{start-addr}
32526 is the beginning address (or @code{$pc})
32527 @item @var{end-addr}
32528 is the end address
32529 @item @var{filename}
32530 is the name of the file to disassemble
32531 @item @var{linenum}
32532 is the line number to disassemble around
32533 @item @var{lines}
32534 is the number of disassembly lines to be produced. If it is -1,
32535 the whole function will be disassembled, in case no @var{end-addr} is
32536 specified. If @var{end-addr} is specified as a non-zero value, and
32537 @var{lines} is lower than the number of disassembly lines between
32538 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
32539 displayed; if @var{lines} is higher than the number of lines between
32540 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
32541 are displayed.
32542 @item @var{mode}
32543 is either 0 (meaning only disassembly), 1 (meaning mixed source and
32544 disassembly), 2 (meaning disassembly with raw opcodes), or 3 (meaning
32545 mixed source and disassembly with raw opcodes).
32546 @end table
32547
32548 @subsubheading Result
32549
32550 The result of the @code{-data-disassemble} command will be a list named
32551 @samp{asm_insns}, the contents of this list depend on the @var{mode}
32552 used with the @code{-data-disassemble} command.
32553
32554 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
32555 following fields:
32556
32557 @table @code
32558 @item address
32559 The address at which this instruction was disassembled.
32560
32561 @item func-name
32562 The name of the function this instruction is within.
32563
32564 @item offset
32565 The decimal offset in bytes from the start of @samp{func-name}.
32566
32567 @item inst
32568 The text disassembly for this @samp{address}.
32569
32570 @item opcodes
32571 This field is only present for mode 2. This contains the raw opcode
32572 bytes for the @samp{inst} field.
32573
32574 @end table
32575
32576 For modes 1 and 3 the @samp{asm_insns} list contains tuples named
32577 @samp{src_and_asm_line}, each of which has the following fields:
32578
32579 @table @code
32580 @item line
32581 The line number within @samp{file}.
32582
32583 @item file
32584 The file name from the compilation unit. This might be an absolute
32585 file name or a relative file name depending on the compile command
32586 used.
32587
32588 @item fullname
32589 Absolute file name of @samp{file}. It is converted to a canonical form
32590 using the source file search path
32591 (@pxref{Source Path, ,Specifying Source Directories})
32592 and after resolving all the symbolic links.
32593
32594 If the source file is not found this field will contain the path as
32595 present in the debug information.
32596
32597 @item line_asm_insn
32598 This is a list of tuples containing the disassembly for @samp{line} in
32599 @samp{file}. The fields of each tuple are the same as for
32600 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
32601 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
32602 @samp{opcodes}.
32603
32604 @end table
32605
32606 Note that whatever included in the @samp{inst} field, is not
32607 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
32608 adjust its format.
32609
32610 @subsubheading @value{GDBN} Command
32611
32612 The corresponding @value{GDBN} command is @samp{disassemble}.
32613
32614 @subsubheading Example
32615
32616 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
32617
32618 @smallexample
32619 (gdb)
32620 -data-disassemble -s $pc -e "$pc + 20" -- 0
32621 ^done,
32622 asm_insns=[
32623 @{address="0x000107c0",func-name="main",offset="4",
32624 inst="mov 2, %o0"@},
32625 @{address="0x000107c4",func-name="main",offset="8",
32626 inst="sethi %hi(0x11800), %o2"@},
32627 @{address="0x000107c8",func-name="main",offset="12",
32628 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
32629 @{address="0x000107cc",func-name="main",offset="16",
32630 inst="sethi %hi(0x11800), %o2"@},
32631 @{address="0x000107d0",func-name="main",offset="20",
32632 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
32633 (gdb)
32634 @end smallexample
32635
32636 Disassemble the whole @code{main} function. Line 32 is part of
32637 @code{main}.
32638
32639 @smallexample
32640 -data-disassemble -f basics.c -l 32 -- 0
32641 ^done,asm_insns=[
32642 @{address="0x000107bc",func-name="main",offset="0",
32643 inst="save %sp, -112, %sp"@},
32644 @{address="0x000107c0",func-name="main",offset="4",
32645 inst="mov 2, %o0"@},
32646 @{address="0x000107c4",func-name="main",offset="8",
32647 inst="sethi %hi(0x11800), %o2"@},
32648 [@dots{}]
32649 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
32650 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
32651 (gdb)
32652 @end smallexample
32653
32654 Disassemble 3 instructions from the start of @code{main}:
32655
32656 @smallexample
32657 (gdb)
32658 -data-disassemble -f basics.c -l 32 -n 3 -- 0
32659 ^done,asm_insns=[
32660 @{address="0x000107bc",func-name="main",offset="0",
32661 inst="save %sp, -112, %sp"@},
32662 @{address="0x000107c0",func-name="main",offset="4",
32663 inst="mov 2, %o0"@},
32664 @{address="0x000107c4",func-name="main",offset="8",
32665 inst="sethi %hi(0x11800), %o2"@}]
32666 (gdb)
32667 @end smallexample
32668
32669 Disassemble 3 instructions from the start of @code{main} in mixed mode:
32670
32671 @smallexample
32672 (gdb)
32673 -data-disassemble -f basics.c -l 32 -n 3 -- 1
32674 ^done,asm_insns=[
32675 src_and_asm_line=@{line="31",
32676 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
32677 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
32678 line_asm_insn=[@{address="0x000107bc",
32679 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
32680 src_and_asm_line=@{line="32",
32681 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
32682 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
32683 line_asm_insn=[@{address="0x000107c0",
32684 func-name="main",offset="4",inst="mov 2, %o0"@},
32685 @{address="0x000107c4",func-name="main",offset="8",
32686 inst="sethi %hi(0x11800), %o2"@}]@}]
32687 (gdb)
32688 @end smallexample
32689
32690
32691 @subheading The @code{-data-evaluate-expression} Command
32692 @findex -data-evaluate-expression
32693
32694 @subsubheading Synopsis
32695
32696 @smallexample
32697 -data-evaluate-expression @var{expr}
32698 @end smallexample
32699
32700 Evaluate @var{expr} as an expression. The expression could contain an
32701 inferior function call. The function call will execute synchronously.
32702 If the expression contains spaces, it must be enclosed in double quotes.
32703
32704 @subsubheading @value{GDBN} Command
32705
32706 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
32707 @samp{call}. In @code{gdbtk} only, there's a corresponding
32708 @samp{gdb_eval} command.
32709
32710 @subsubheading Example
32711
32712 In the following example, the numbers that precede the commands are the
32713 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
32714 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
32715 output.
32716
32717 @smallexample
32718 211-data-evaluate-expression A
32719 211^done,value="1"
32720 (gdb)
32721 311-data-evaluate-expression &A
32722 311^done,value="0xefffeb7c"
32723 (gdb)
32724 411-data-evaluate-expression A+3
32725 411^done,value="4"
32726 (gdb)
32727 511-data-evaluate-expression "A + 3"
32728 511^done,value="4"
32729 (gdb)
32730 @end smallexample
32731
32732
32733 @subheading The @code{-data-list-changed-registers} Command
32734 @findex -data-list-changed-registers
32735
32736 @subsubheading Synopsis
32737
32738 @smallexample
32739 -data-list-changed-registers
32740 @end smallexample
32741
32742 Display a list of the registers that have changed.
32743
32744 @subsubheading @value{GDBN} Command
32745
32746 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
32747 has the corresponding command @samp{gdb_changed_register_list}.
32748
32749 @subsubheading Example
32750
32751 On a PPC MBX board:
32752
32753 @smallexample
32754 (gdb)
32755 -exec-continue
32756 ^running
32757
32758 (gdb)
32759 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
32760 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
32761 line="5"@}
32762 (gdb)
32763 -data-list-changed-registers
32764 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
32765 "10","11","13","14","15","16","17","18","19","20","21","22","23",
32766 "24","25","26","27","28","30","31","64","65","66","67","69"]
32767 (gdb)
32768 @end smallexample
32769
32770
32771 @subheading The @code{-data-list-register-names} Command
32772 @findex -data-list-register-names
32773
32774 @subsubheading Synopsis
32775
32776 @smallexample
32777 -data-list-register-names [ ( @var{regno} )+ ]
32778 @end smallexample
32779
32780 Show a list of register names for the current target. If no arguments
32781 are given, it shows a list of the names of all the registers. If
32782 integer numbers are given as arguments, it will print a list of the
32783 names of the registers corresponding to the arguments. To ensure
32784 consistency between a register name and its number, the output list may
32785 include empty register names.
32786
32787 @subsubheading @value{GDBN} Command
32788
32789 @value{GDBN} does not have a command which corresponds to
32790 @samp{-data-list-register-names}. In @code{gdbtk} there is a
32791 corresponding command @samp{gdb_regnames}.
32792
32793 @subsubheading Example
32794
32795 For the PPC MBX board:
32796 @smallexample
32797 (gdb)
32798 -data-list-register-names
32799 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
32800 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
32801 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
32802 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
32803 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
32804 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
32805 "", "pc","ps","cr","lr","ctr","xer"]
32806 (gdb)
32807 -data-list-register-names 1 2 3
32808 ^done,register-names=["r1","r2","r3"]
32809 (gdb)
32810 @end smallexample
32811
32812 @subheading The @code{-data-list-register-values} Command
32813 @findex -data-list-register-values
32814
32815 @subsubheading Synopsis
32816
32817 @smallexample
32818 -data-list-register-values
32819 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
32820 @end smallexample
32821
32822 Display the registers' contents. @var{fmt} is the format according to
32823 which the registers' contents are to be returned, followed by an optional
32824 list of numbers specifying the registers to display. A missing list of
32825 numbers indicates that the contents of all the registers must be
32826 returned. The @code{--skip-unavailable} option indicates that only
32827 the available registers are to be returned.
32828
32829 Allowed formats for @var{fmt} are:
32830
32831 @table @code
32832 @item x
32833 Hexadecimal
32834 @item o
32835 Octal
32836 @item t
32837 Binary
32838 @item d
32839 Decimal
32840 @item r
32841 Raw
32842 @item N
32843 Natural
32844 @end table
32845
32846 @subsubheading @value{GDBN} Command
32847
32848 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
32849 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
32850
32851 @subsubheading Example
32852
32853 For a PPC MBX board (note: line breaks are for readability only, they
32854 don't appear in the actual output):
32855
32856 @smallexample
32857 (gdb)
32858 -data-list-register-values r 64 65
32859 ^done,register-values=[@{number="64",value="0xfe00a300"@},
32860 @{number="65",value="0x00029002"@}]
32861 (gdb)
32862 -data-list-register-values x
32863 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
32864 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
32865 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
32866 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
32867 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
32868 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
32869 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
32870 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
32871 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
32872 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
32873 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
32874 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
32875 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
32876 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
32877 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
32878 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
32879 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
32880 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
32881 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
32882 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
32883 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
32884 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
32885 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
32886 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
32887 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
32888 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
32889 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
32890 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
32891 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
32892 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
32893 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
32894 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
32895 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
32896 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
32897 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
32898 @{number="69",value="0x20002b03"@}]
32899 (gdb)
32900 @end smallexample
32901
32902
32903 @subheading The @code{-data-read-memory} Command
32904 @findex -data-read-memory
32905
32906 This command is deprecated, use @code{-data-read-memory-bytes} instead.
32907
32908 @subsubheading Synopsis
32909
32910 @smallexample
32911 -data-read-memory [ -o @var{byte-offset} ]
32912 @var{address} @var{word-format} @var{word-size}
32913 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
32914 @end smallexample
32915
32916 @noindent
32917 where:
32918
32919 @table @samp
32920 @item @var{address}
32921 An expression specifying the address of the first memory word to be
32922 read. Complex expressions containing embedded white space should be
32923 quoted using the C convention.
32924
32925 @item @var{word-format}
32926 The format to be used to print the memory words. The notation is the
32927 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
32928 ,Output Formats}).
32929
32930 @item @var{word-size}
32931 The size of each memory word in bytes.
32932
32933 @item @var{nr-rows}
32934 The number of rows in the output table.
32935
32936 @item @var{nr-cols}
32937 The number of columns in the output table.
32938
32939 @item @var{aschar}
32940 If present, indicates that each row should include an @sc{ascii} dump. The
32941 value of @var{aschar} is used as a padding character when a byte is not a
32942 member of the printable @sc{ascii} character set (printable @sc{ascii}
32943 characters are those whose code is between 32 and 126, inclusively).
32944
32945 @item @var{byte-offset}
32946 An offset to add to the @var{address} before fetching memory.
32947 @end table
32948
32949 This command displays memory contents as a table of @var{nr-rows} by
32950 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
32951 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
32952 (returned as @samp{total-bytes}). Should less than the requested number
32953 of bytes be returned by the target, the missing words are identified
32954 using @samp{N/A}. The number of bytes read from the target is returned
32955 in @samp{nr-bytes} and the starting address used to read memory in
32956 @samp{addr}.
32957
32958 The address of the next/previous row or page is available in
32959 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
32960 @samp{prev-page}.
32961
32962 @subsubheading @value{GDBN} Command
32963
32964 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
32965 @samp{gdb_get_mem} memory read command.
32966
32967 @subsubheading Example
32968
32969 Read six bytes of memory starting at @code{bytes+6} but then offset by
32970 @code{-6} bytes. Format as three rows of two columns. One byte per
32971 word. Display each word in hex.
32972
32973 @smallexample
32974 (gdb)
32975 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
32976 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
32977 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
32978 prev-page="0x0000138a",memory=[
32979 @{addr="0x00001390",data=["0x00","0x01"]@},
32980 @{addr="0x00001392",data=["0x02","0x03"]@},
32981 @{addr="0x00001394",data=["0x04","0x05"]@}]
32982 (gdb)
32983 @end smallexample
32984
32985 Read two bytes of memory starting at address @code{shorts + 64} and
32986 display as a single word formatted in decimal.
32987
32988 @smallexample
32989 (gdb)
32990 5-data-read-memory shorts+64 d 2 1 1
32991 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
32992 next-row="0x00001512",prev-row="0x0000150e",
32993 next-page="0x00001512",prev-page="0x0000150e",memory=[
32994 @{addr="0x00001510",data=["128"]@}]
32995 (gdb)
32996 @end smallexample
32997
32998 Read thirty two bytes of memory starting at @code{bytes+16} and format
32999 as eight rows of four columns. Include a string encoding with @samp{x}
33000 used as the non-printable character.
33001
33002 @smallexample
33003 (gdb)
33004 4-data-read-memory bytes+16 x 1 8 4 x
33005 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33006 next-row="0x000013c0",prev-row="0x0000139c",
33007 next-page="0x000013c0",prev-page="0x00001380",memory=[
33008 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33009 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33010 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33011 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33012 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33013 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33014 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33015 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
33016 (gdb)
33017 @end smallexample
33018
33019 @subheading The @code{-data-read-memory-bytes} Command
33020 @findex -data-read-memory-bytes
33021
33022 @subsubheading Synopsis
33023
33024 @smallexample
33025 -data-read-memory-bytes [ -o @var{byte-offset} ]
33026 @var{address} @var{count}
33027 @end smallexample
33028
33029 @noindent
33030 where:
33031
33032 @table @samp
33033 @item @var{address}
33034 An expression specifying the address of the first memory word to be
33035 read. Complex expressions containing embedded white space should be
33036 quoted using the C convention.
33037
33038 @item @var{count}
33039 The number of bytes to read. This should be an integer literal.
33040
33041 @item @var{byte-offset}
33042 The offsets in bytes relative to @var{address} at which to start
33043 reading. This should be an integer literal. This option is provided
33044 so that a frontend is not required to first evaluate address and then
33045 perform address arithmetics itself.
33046
33047 @end table
33048
33049 This command attempts to read all accessible memory regions in the
33050 specified range. First, all regions marked as unreadable in the memory
33051 map (if one is defined) will be skipped. @xref{Memory Region
33052 Attributes}. Second, @value{GDBN} will attempt to read the remaining
33053 regions. For each one, if reading full region results in an errors,
33054 @value{GDBN} will try to read a subset of the region.
33055
33056 In general, every single byte in the region may be readable or not,
33057 and the only way to read every readable byte is to try a read at
33058 every address, which is not practical. Therefore, @value{GDBN} will
33059 attempt to read all accessible bytes at either beginning or the end
33060 of the region, using a binary division scheme. This heuristic works
33061 well for reading accross a memory map boundary. Note that if a region
33062 has a readable range that is neither at the beginning or the end,
33063 @value{GDBN} will not read it.
33064
33065 The result record (@pxref{GDB/MI Result Records}) that is output of
33066 the command includes a field named @samp{memory} whose content is a
33067 list of tuples. Each tuple represent a successfully read memory block
33068 and has the following fields:
33069
33070 @table @code
33071 @item begin
33072 The start address of the memory block, as hexadecimal literal.
33073
33074 @item end
33075 The end address of the memory block, as hexadecimal literal.
33076
33077 @item offset
33078 The offset of the memory block, as hexadecimal literal, relative to
33079 the start address passed to @code{-data-read-memory-bytes}.
33080
33081 @item contents
33082 The contents of the memory block, in hex.
33083
33084 @end table
33085
33086
33087
33088 @subsubheading @value{GDBN} Command
33089
33090 The corresponding @value{GDBN} command is @samp{x}.
33091
33092 @subsubheading Example
33093
33094 @smallexample
33095 (gdb)
33096 -data-read-memory-bytes &a 10
33097 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33098 end="0xbffff15e",
33099 contents="01000000020000000300"@}]
33100 (gdb)
33101 @end smallexample
33102
33103
33104 @subheading The @code{-data-write-memory-bytes} Command
33105 @findex -data-write-memory-bytes
33106
33107 @subsubheading Synopsis
33108
33109 @smallexample
33110 -data-write-memory-bytes @var{address} @var{contents}
33111 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
33112 @end smallexample
33113
33114 @noindent
33115 where:
33116
33117 @table @samp
33118 @item @var{address}
33119 An expression specifying the address of the first memory word to be
33120 read. Complex expressions containing embedded white space should be
33121 quoted using the C convention.
33122
33123 @item @var{contents}
33124 The hex-encoded bytes to write.
33125
33126 @item @var{count}
33127 Optional argument indicating the number of bytes to be written. If @var{count}
33128 is greater than @var{contents}' length, @value{GDBN} will repeatedly
33129 write @var{contents} until it fills @var{count} bytes.
33130
33131 @end table
33132
33133 @subsubheading @value{GDBN} Command
33134
33135 There's no corresponding @value{GDBN} command.
33136
33137 @subsubheading Example
33138
33139 @smallexample
33140 (gdb)
33141 -data-write-memory-bytes &a "aabbccdd"
33142 ^done
33143 (gdb)
33144 @end smallexample
33145
33146 @smallexample
33147 (gdb)
33148 -data-write-memory-bytes &a "aabbccdd" 16e
33149 ^done
33150 (gdb)
33151 @end smallexample
33152
33153 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33154 @node GDB/MI Tracepoint Commands
33155 @section @sc{gdb/mi} Tracepoint Commands
33156
33157 The commands defined in this section implement MI support for
33158 tracepoints. For detailed introduction, see @ref{Tracepoints}.
33159
33160 @subheading The @code{-trace-find} Command
33161 @findex -trace-find
33162
33163 @subsubheading Synopsis
33164
33165 @smallexample
33166 -trace-find @var{mode} [@var{parameters}@dots{}]
33167 @end smallexample
33168
33169 Find a trace frame using criteria defined by @var{mode} and
33170 @var{parameters}. The following table lists permissible
33171 modes and their parameters. For details of operation, see @ref{tfind}.
33172
33173 @table @samp
33174
33175 @item none
33176 No parameters are required. Stops examining trace frames.
33177
33178 @item frame-number
33179 An integer is required as parameter. Selects tracepoint frame with
33180 that index.
33181
33182 @item tracepoint-number
33183 An integer is required as parameter. Finds next
33184 trace frame that corresponds to tracepoint with the specified number.
33185
33186 @item pc
33187 An address is required as parameter. Finds
33188 next trace frame that corresponds to any tracepoint at the specified
33189 address.
33190
33191 @item pc-inside-range
33192 Two addresses are required as parameters. Finds next trace
33193 frame that corresponds to a tracepoint at an address inside the
33194 specified range. Both bounds are considered to be inside the range.
33195
33196 @item pc-outside-range
33197 Two addresses are required as parameters. Finds
33198 next trace frame that corresponds to a tracepoint at an address outside
33199 the specified range. Both bounds are considered to be inside the range.
33200
33201 @item line
33202 Line specification is required as parameter. @xref{Specify Location}.
33203 Finds next trace frame that corresponds to a tracepoint at
33204 the specified location.
33205
33206 @end table
33207
33208 If @samp{none} was passed as @var{mode}, the response does not
33209 have fields. Otherwise, the response may have the following fields:
33210
33211 @table @samp
33212 @item found
33213 This field has either @samp{0} or @samp{1} as the value, depending
33214 on whether a matching tracepoint was found.
33215
33216 @item traceframe
33217 The index of the found traceframe. This field is present iff
33218 the @samp{found} field has value of @samp{1}.
33219
33220 @item tracepoint
33221 The index of the found tracepoint. This field is present iff
33222 the @samp{found} field has value of @samp{1}.
33223
33224 @item frame
33225 The information about the frame corresponding to the found trace
33226 frame. This field is present only if a trace frame was found.
33227 @xref{GDB/MI Frame Information}, for description of this field.
33228
33229 @end table
33230
33231 @subsubheading @value{GDBN} Command
33232
33233 The corresponding @value{GDBN} command is @samp{tfind}.
33234
33235 @subheading -trace-define-variable
33236 @findex -trace-define-variable
33237
33238 @subsubheading Synopsis
33239
33240 @smallexample
33241 -trace-define-variable @var{name} [ @var{value} ]
33242 @end smallexample
33243
33244 Create trace variable @var{name} if it does not exist. If
33245 @var{value} is specified, sets the initial value of the specified
33246 trace variable to that value. Note that the @var{name} should start
33247 with the @samp{$} character.
33248
33249 @subsubheading @value{GDBN} Command
33250
33251 The corresponding @value{GDBN} command is @samp{tvariable}.
33252
33253 @subheading The @code{-trace-frame-collected} Command
33254 @findex -trace-frame-collected
33255
33256 @subsubheading Synopsis
33257
33258 @smallexample
33259 -trace-frame-collected
33260 [--var-print-values @var{var_pval}]
33261 [--comp-print-values @var{comp_pval}]
33262 [--registers-format @var{regformat}]
33263 [--memory-contents]
33264 @end smallexample
33265
33266 This command returns the set of collected objects, register names,
33267 trace state variable names, memory ranges and computed expressions
33268 that have been collected at a particular trace frame. The optional
33269 parameters to the command affect the output format in different ways.
33270 See the output description table below for more details.
33271
33272 The reported names can be used in the normal manner to create
33273 varobjs and inspect the objects themselves. The items returned by
33274 this command are categorized so that it is clear which is a variable,
33275 which is a register, which is a trace state variable, which is a
33276 memory range and which is a computed expression.
33277
33278 For instance, if the actions were
33279 @smallexample
33280 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33281 collect *(int*)0xaf02bef0@@40
33282 @end smallexample
33283
33284 @noindent
33285 the object collected in its entirety would be @code{myVar}. The
33286 object @code{myArray} would be partially collected, because only the
33287 element at index @code{myIndex} would be collected. The remaining
33288 objects would be computed expressions.
33289
33290 An example output would be:
33291
33292 @smallexample
33293 (gdb)
33294 -trace-frame-collected
33295 ^done,
33296 explicit-variables=[@{name="myVar",value="1"@}],
33297 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33298 @{name="myObj.field",value="0"@},
33299 @{name="myPtr->field",value="1"@},
33300 @{name="myCount + 2",value="3"@},
33301 @{name="$tvar1 + 1",value="43970027"@}],
33302 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33303 @{number="1",value="0x0"@},
33304 @{number="2",value="0x4"@},
33305 ...
33306 @{number="125",value="0x0"@}],
33307 tvars=[@{name="$tvar1",current="43970026"@}],
33308 memory=[@{address="0x0000000000602264",length="4"@},
33309 @{address="0x0000000000615bc0",length="4"@}]
33310 (gdb)
33311 @end smallexample
33312
33313 Where:
33314
33315 @table @code
33316 @item explicit-variables
33317 The set of objects that have been collected in their entirety (as
33318 opposed to collecting just a few elements of an array or a few struct
33319 members). For each object, its name and value are printed.
33320 The @code{--var-print-values} option affects how or whether the value
33321 field is output. If @var{var_pval} is 0, then print only the names;
33322 if it is 1, print also their values; and if it is 2, print the name,
33323 type and value for simple data types, and the name and type for
33324 arrays, structures and unions.
33325
33326 @item computed-expressions
33327 The set of computed expressions that have been collected at the
33328 current trace frame. The @code{--comp-print-values} option affects
33329 this set like the @code{--var-print-values} option affects the
33330 @code{explicit-variables} set. See above.
33331
33332 @item registers
33333 The registers that have been collected at the current trace frame.
33334 For each register collected, the name and current value are returned.
33335 The value is formatted according to the @code{--registers-format}
33336 option. See the @command{-data-list-register-values} command for a
33337 list of the allowed formats. The default is @samp{x}.
33338
33339 @item tvars
33340 The trace state variables that have been collected at the current
33341 trace frame. For each trace state variable collected, the name and
33342 current value are returned.
33343
33344 @item memory
33345 The set of memory ranges that have been collected at the current trace
33346 frame. Its content is a list of tuples. Each tuple represents a
33347 collected memory range and has the following fields:
33348
33349 @table @code
33350 @item address
33351 The start address of the memory range, as hexadecimal literal.
33352
33353 @item length
33354 The length of the memory range, as decimal literal.
33355
33356 @item contents
33357 The contents of the memory block, in hex. This field is only present
33358 if the @code{--memory-contents} option is specified.
33359
33360 @end table
33361
33362 @end table
33363
33364 @subsubheading @value{GDBN} Command
33365
33366 There is no corresponding @value{GDBN} command.
33367
33368 @subsubheading Example
33369
33370 @subheading -trace-list-variables
33371 @findex -trace-list-variables
33372
33373 @subsubheading Synopsis
33374
33375 @smallexample
33376 -trace-list-variables
33377 @end smallexample
33378
33379 Return a table of all defined trace variables. Each element of the
33380 table has the following fields:
33381
33382 @table @samp
33383 @item name
33384 The name of the trace variable. This field is always present.
33385
33386 @item initial
33387 The initial value. This is a 64-bit signed integer. This
33388 field is always present.
33389
33390 @item current
33391 The value the trace variable has at the moment. This is a 64-bit
33392 signed integer. This field is absent iff current value is
33393 not defined, for example if the trace was never run, or is
33394 presently running.
33395
33396 @end table
33397
33398 @subsubheading @value{GDBN} Command
33399
33400 The corresponding @value{GDBN} command is @samp{tvariables}.
33401
33402 @subsubheading Example
33403
33404 @smallexample
33405 (gdb)
33406 -trace-list-variables
33407 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
33408 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
33409 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
33410 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
33411 body=[variable=@{name="$trace_timestamp",initial="0"@}
33412 variable=@{name="$foo",initial="10",current="15"@}]@}
33413 (gdb)
33414 @end smallexample
33415
33416 @subheading -trace-save
33417 @findex -trace-save
33418
33419 @subsubheading Synopsis
33420
33421 @smallexample
33422 -trace-save [-r ] @var{filename}
33423 @end smallexample
33424
33425 Saves the collected trace data to @var{filename}. Without the
33426 @samp{-r} option, the data is downloaded from the target and saved
33427 in a local file. With the @samp{-r} option the target is asked
33428 to perform the save.
33429
33430 @subsubheading @value{GDBN} Command
33431
33432 The corresponding @value{GDBN} command is @samp{tsave}.
33433
33434
33435 @subheading -trace-start
33436 @findex -trace-start
33437
33438 @subsubheading Synopsis
33439
33440 @smallexample
33441 -trace-start
33442 @end smallexample
33443
33444 Starts a tracing experiments. The result of this command does not
33445 have any fields.
33446
33447 @subsubheading @value{GDBN} Command
33448
33449 The corresponding @value{GDBN} command is @samp{tstart}.
33450
33451 @subheading -trace-status
33452 @findex -trace-status
33453
33454 @subsubheading Synopsis
33455
33456 @smallexample
33457 -trace-status
33458 @end smallexample
33459
33460 Obtains the status of a tracing experiment. The result may include
33461 the following fields:
33462
33463 @table @samp
33464
33465 @item supported
33466 May have a value of either @samp{0}, when no tracing operations are
33467 supported, @samp{1}, when all tracing operations are supported, or
33468 @samp{file} when examining trace file. In the latter case, examining
33469 of trace frame is possible but new tracing experiement cannot be
33470 started. This field is always present.
33471
33472 @item running
33473 May have a value of either @samp{0} or @samp{1} depending on whether
33474 tracing experiement is in progress on target. This field is present
33475 if @samp{supported} field is not @samp{0}.
33476
33477 @item stop-reason
33478 Report the reason why the tracing was stopped last time. This field
33479 may be absent iff tracing was never stopped on target yet. The
33480 value of @samp{request} means the tracing was stopped as result of
33481 the @code{-trace-stop} command. The value of @samp{overflow} means
33482 the tracing buffer is full. The value of @samp{disconnection} means
33483 tracing was automatically stopped when @value{GDBN} has disconnected.
33484 The value of @samp{passcount} means tracing was stopped when a
33485 tracepoint was passed a maximal number of times for that tracepoint.
33486 This field is present if @samp{supported} field is not @samp{0}.
33487
33488 @item stopping-tracepoint
33489 The number of tracepoint whose passcount as exceeded. This field is
33490 present iff the @samp{stop-reason} field has the value of
33491 @samp{passcount}.
33492
33493 @item frames
33494 @itemx frames-created
33495 The @samp{frames} field is a count of the total number of trace frames
33496 in the trace buffer, while @samp{frames-created} is the total created
33497 during the run, including ones that were discarded, such as when a
33498 circular trace buffer filled up. Both fields are optional.
33499
33500 @item buffer-size
33501 @itemx buffer-free
33502 These fields tell the current size of the tracing buffer and the
33503 remaining space. These fields are optional.
33504
33505 @item circular
33506 The value of the circular trace buffer flag. @code{1} means that the
33507 trace buffer is circular and old trace frames will be discarded if
33508 necessary to make room, @code{0} means that the trace buffer is linear
33509 and may fill up.
33510
33511 @item disconnected
33512 The value of the disconnected tracing flag. @code{1} means that
33513 tracing will continue after @value{GDBN} disconnects, @code{0} means
33514 that the trace run will stop.
33515
33516 @item trace-file
33517 The filename of the trace file being examined. This field is
33518 optional, and only present when examining a trace file.
33519
33520 @end table
33521
33522 @subsubheading @value{GDBN} Command
33523
33524 The corresponding @value{GDBN} command is @samp{tstatus}.
33525
33526 @subheading -trace-stop
33527 @findex -trace-stop
33528
33529 @subsubheading Synopsis
33530
33531 @smallexample
33532 -trace-stop
33533 @end smallexample
33534
33535 Stops a tracing experiment. The result of this command has the same
33536 fields as @code{-trace-status}, except that the @samp{supported} and
33537 @samp{running} fields are not output.
33538
33539 @subsubheading @value{GDBN} Command
33540
33541 The corresponding @value{GDBN} command is @samp{tstop}.
33542
33543
33544 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33545 @node GDB/MI Symbol Query
33546 @section @sc{gdb/mi} Symbol Query Commands
33547
33548
33549 @ignore
33550 @subheading The @code{-symbol-info-address} Command
33551 @findex -symbol-info-address
33552
33553 @subsubheading Synopsis
33554
33555 @smallexample
33556 -symbol-info-address @var{symbol}
33557 @end smallexample
33558
33559 Describe where @var{symbol} is stored.
33560
33561 @subsubheading @value{GDBN} Command
33562
33563 The corresponding @value{GDBN} command is @samp{info address}.
33564
33565 @subsubheading Example
33566 N.A.
33567
33568
33569 @subheading The @code{-symbol-info-file} Command
33570 @findex -symbol-info-file
33571
33572 @subsubheading Synopsis
33573
33574 @smallexample
33575 -symbol-info-file
33576 @end smallexample
33577
33578 Show the file for the symbol.
33579
33580 @subsubheading @value{GDBN} Command
33581
33582 There's no equivalent @value{GDBN} command. @code{gdbtk} has
33583 @samp{gdb_find_file}.
33584
33585 @subsubheading Example
33586 N.A.
33587
33588
33589 @subheading The @code{-symbol-info-function} Command
33590 @findex -symbol-info-function
33591
33592 @subsubheading Synopsis
33593
33594 @smallexample
33595 -symbol-info-function
33596 @end smallexample
33597
33598 Show which function the symbol lives in.
33599
33600 @subsubheading @value{GDBN} Command
33601
33602 @samp{gdb_get_function} in @code{gdbtk}.
33603
33604 @subsubheading Example
33605 N.A.
33606
33607
33608 @subheading The @code{-symbol-info-line} Command
33609 @findex -symbol-info-line
33610
33611 @subsubheading Synopsis
33612
33613 @smallexample
33614 -symbol-info-line
33615 @end smallexample
33616
33617 Show the core addresses of the code for a source line.
33618
33619 @subsubheading @value{GDBN} Command
33620
33621 The corresponding @value{GDBN} command is @samp{info line}.
33622 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
33623
33624 @subsubheading Example
33625 N.A.
33626
33627
33628 @subheading The @code{-symbol-info-symbol} Command
33629 @findex -symbol-info-symbol
33630
33631 @subsubheading Synopsis
33632
33633 @smallexample
33634 -symbol-info-symbol @var{addr}
33635 @end smallexample
33636
33637 Describe what symbol is at location @var{addr}.
33638
33639 @subsubheading @value{GDBN} Command
33640
33641 The corresponding @value{GDBN} command is @samp{info symbol}.
33642
33643 @subsubheading Example
33644 N.A.
33645
33646
33647 @subheading The @code{-symbol-list-functions} Command
33648 @findex -symbol-list-functions
33649
33650 @subsubheading Synopsis
33651
33652 @smallexample
33653 -symbol-list-functions
33654 @end smallexample
33655
33656 List the functions in the executable.
33657
33658 @subsubheading @value{GDBN} Command
33659
33660 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
33661 @samp{gdb_search} in @code{gdbtk}.
33662
33663 @subsubheading Example
33664 N.A.
33665 @end ignore
33666
33667
33668 @subheading The @code{-symbol-list-lines} Command
33669 @findex -symbol-list-lines
33670
33671 @subsubheading Synopsis
33672
33673 @smallexample
33674 -symbol-list-lines @var{filename}
33675 @end smallexample
33676
33677 Print the list of lines that contain code and their associated program
33678 addresses for the given source filename. The entries are sorted in
33679 ascending PC order.
33680
33681 @subsubheading @value{GDBN} Command
33682
33683 There is no corresponding @value{GDBN} command.
33684
33685 @subsubheading Example
33686 @smallexample
33687 (gdb)
33688 -symbol-list-lines basics.c
33689 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
33690 (gdb)
33691 @end smallexample
33692
33693
33694 @ignore
33695 @subheading The @code{-symbol-list-types} Command
33696 @findex -symbol-list-types
33697
33698 @subsubheading Synopsis
33699
33700 @smallexample
33701 -symbol-list-types
33702 @end smallexample
33703
33704 List all the type names.
33705
33706 @subsubheading @value{GDBN} Command
33707
33708 The corresponding commands are @samp{info types} in @value{GDBN},
33709 @samp{gdb_search} in @code{gdbtk}.
33710
33711 @subsubheading Example
33712 N.A.
33713
33714
33715 @subheading The @code{-symbol-list-variables} Command
33716 @findex -symbol-list-variables
33717
33718 @subsubheading Synopsis
33719
33720 @smallexample
33721 -symbol-list-variables
33722 @end smallexample
33723
33724 List all the global and static variable names.
33725
33726 @subsubheading @value{GDBN} Command
33727
33728 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
33729
33730 @subsubheading Example
33731 N.A.
33732
33733
33734 @subheading The @code{-symbol-locate} Command
33735 @findex -symbol-locate
33736
33737 @subsubheading Synopsis
33738
33739 @smallexample
33740 -symbol-locate
33741 @end smallexample
33742
33743 @subsubheading @value{GDBN} Command
33744
33745 @samp{gdb_loc} in @code{gdbtk}.
33746
33747 @subsubheading Example
33748 N.A.
33749
33750
33751 @subheading The @code{-symbol-type} Command
33752 @findex -symbol-type
33753
33754 @subsubheading Synopsis
33755
33756 @smallexample
33757 -symbol-type @var{variable}
33758 @end smallexample
33759
33760 Show type of @var{variable}.
33761
33762 @subsubheading @value{GDBN} Command
33763
33764 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
33765 @samp{gdb_obj_variable}.
33766
33767 @subsubheading Example
33768 N.A.
33769 @end ignore
33770
33771
33772 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33773 @node GDB/MI File Commands
33774 @section @sc{gdb/mi} File Commands
33775
33776 This section describes the GDB/MI commands to specify executable file names
33777 and to read in and obtain symbol table information.
33778
33779 @subheading The @code{-file-exec-and-symbols} Command
33780 @findex -file-exec-and-symbols
33781
33782 @subsubheading Synopsis
33783
33784 @smallexample
33785 -file-exec-and-symbols @var{file}
33786 @end smallexample
33787
33788 Specify the executable file to be debugged. This file is the one from
33789 which the symbol table is also read. If no file is specified, the
33790 command clears the executable and symbol information. If breakpoints
33791 are set when using this command with no arguments, @value{GDBN} will produce
33792 error messages. Otherwise, no output is produced, except a completion
33793 notification.
33794
33795 @subsubheading @value{GDBN} Command
33796
33797 The corresponding @value{GDBN} command is @samp{file}.
33798
33799 @subsubheading Example
33800
33801 @smallexample
33802 (gdb)
33803 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
33804 ^done
33805 (gdb)
33806 @end smallexample
33807
33808
33809 @subheading The @code{-file-exec-file} Command
33810 @findex -file-exec-file
33811
33812 @subsubheading Synopsis
33813
33814 @smallexample
33815 -file-exec-file @var{file}
33816 @end smallexample
33817
33818 Specify the executable file to be debugged. Unlike
33819 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
33820 from this file. If used without argument, @value{GDBN} clears the information
33821 about the executable file. No output is produced, except a completion
33822 notification.
33823
33824 @subsubheading @value{GDBN} Command
33825
33826 The corresponding @value{GDBN} command is @samp{exec-file}.
33827
33828 @subsubheading Example
33829
33830 @smallexample
33831 (gdb)
33832 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
33833 ^done
33834 (gdb)
33835 @end smallexample
33836
33837
33838 @ignore
33839 @subheading The @code{-file-list-exec-sections} Command
33840 @findex -file-list-exec-sections
33841
33842 @subsubheading Synopsis
33843
33844 @smallexample
33845 -file-list-exec-sections
33846 @end smallexample
33847
33848 List the sections of the current executable file.
33849
33850 @subsubheading @value{GDBN} Command
33851
33852 The @value{GDBN} command @samp{info file} shows, among the rest, the same
33853 information as this command. @code{gdbtk} has a corresponding command
33854 @samp{gdb_load_info}.
33855
33856 @subsubheading Example
33857 N.A.
33858 @end ignore
33859
33860
33861 @subheading The @code{-file-list-exec-source-file} Command
33862 @findex -file-list-exec-source-file
33863
33864 @subsubheading Synopsis
33865
33866 @smallexample
33867 -file-list-exec-source-file
33868 @end smallexample
33869
33870 List the line number, the current source file, and the absolute path
33871 to the current source file for the current executable. The macro
33872 information field has a value of @samp{1} or @samp{0} depending on
33873 whether or not the file includes preprocessor macro information.
33874
33875 @subsubheading @value{GDBN} Command
33876
33877 The @value{GDBN} equivalent is @samp{info source}
33878
33879 @subsubheading Example
33880
33881 @smallexample
33882 (gdb)
33883 123-file-list-exec-source-file
33884 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
33885 (gdb)
33886 @end smallexample
33887
33888
33889 @subheading The @code{-file-list-exec-source-files} Command
33890 @findex -file-list-exec-source-files
33891
33892 @subsubheading Synopsis
33893
33894 @smallexample
33895 -file-list-exec-source-files
33896 @end smallexample
33897
33898 List the source files for the current executable.
33899
33900 It will always output both the filename and fullname (absolute file
33901 name) of a source file.
33902
33903 @subsubheading @value{GDBN} Command
33904
33905 The @value{GDBN} equivalent is @samp{info sources}.
33906 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
33907
33908 @subsubheading Example
33909 @smallexample
33910 (gdb)
33911 -file-list-exec-source-files
33912 ^done,files=[
33913 @{file=foo.c,fullname=/home/foo.c@},
33914 @{file=/home/bar.c,fullname=/home/bar.c@},
33915 @{file=gdb_could_not_find_fullpath.c@}]
33916 (gdb)
33917 @end smallexample
33918
33919 @ignore
33920 @subheading The @code{-file-list-shared-libraries} Command
33921 @findex -file-list-shared-libraries
33922
33923 @subsubheading Synopsis
33924
33925 @smallexample
33926 -file-list-shared-libraries
33927 @end smallexample
33928
33929 List the shared libraries in the program.
33930
33931 @subsubheading @value{GDBN} Command
33932
33933 The corresponding @value{GDBN} command is @samp{info shared}.
33934
33935 @subsubheading Example
33936 N.A.
33937
33938
33939 @subheading The @code{-file-list-symbol-files} Command
33940 @findex -file-list-symbol-files
33941
33942 @subsubheading Synopsis
33943
33944 @smallexample
33945 -file-list-symbol-files
33946 @end smallexample
33947
33948 List symbol files.
33949
33950 @subsubheading @value{GDBN} Command
33951
33952 The corresponding @value{GDBN} command is @samp{info file} (part of it).
33953
33954 @subsubheading Example
33955 N.A.
33956 @end ignore
33957
33958
33959 @subheading The @code{-file-symbol-file} Command
33960 @findex -file-symbol-file
33961
33962 @subsubheading Synopsis
33963
33964 @smallexample
33965 -file-symbol-file @var{file}
33966 @end smallexample
33967
33968 Read symbol table info from the specified @var{file} argument. When
33969 used without arguments, clears @value{GDBN}'s symbol table info. No output is
33970 produced, except for a completion notification.
33971
33972 @subsubheading @value{GDBN} Command
33973
33974 The corresponding @value{GDBN} command is @samp{symbol-file}.
33975
33976 @subsubheading Example
33977
33978 @smallexample
33979 (gdb)
33980 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
33981 ^done
33982 (gdb)
33983 @end smallexample
33984
33985 @ignore
33986 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33987 @node GDB/MI Memory Overlay Commands
33988 @section @sc{gdb/mi} Memory Overlay Commands
33989
33990 The memory overlay commands are not implemented.
33991
33992 @c @subheading -overlay-auto
33993
33994 @c @subheading -overlay-list-mapping-state
33995
33996 @c @subheading -overlay-list-overlays
33997
33998 @c @subheading -overlay-map
33999
34000 @c @subheading -overlay-off
34001
34002 @c @subheading -overlay-on
34003
34004 @c @subheading -overlay-unmap
34005
34006 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34007 @node GDB/MI Signal Handling Commands
34008 @section @sc{gdb/mi} Signal Handling Commands
34009
34010 Signal handling commands are not implemented.
34011
34012 @c @subheading -signal-handle
34013
34014 @c @subheading -signal-list-handle-actions
34015
34016 @c @subheading -signal-list-signal-types
34017 @end ignore
34018
34019
34020 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34021 @node GDB/MI Target Manipulation
34022 @section @sc{gdb/mi} Target Manipulation Commands
34023
34024
34025 @subheading The @code{-target-attach} Command
34026 @findex -target-attach
34027
34028 @subsubheading Synopsis
34029
34030 @smallexample
34031 -target-attach @var{pid} | @var{gid} | @var{file}
34032 @end smallexample
34033
34034 Attach to a process @var{pid} or a file @var{file} outside of
34035 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
34036 group, the id previously returned by
34037 @samp{-list-thread-groups --available} must be used.
34038
34039 @subsubheading @value{GDBN} Command
34040
34041 The corresponding @value{GDBN} command is @samp{attach}.
34042
34043 @subsubheading Example
34044 @smallexample
34045 (gdb)
34046 -target-attach 34
34047 =thread-created,id="1"
34048 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
34049 ^done
34050 (gdb)
34051 @end smallexample
34052
34053 @ignore
34054 @subheading The @code{-target-compare-sections} Command
34055 @findex -target-compare-sections
34056
34057 @subsubheading Synopsis
34058
34059 @smallexample
34060 -target-compare-sections [ @var{section} ]
34061 @end smallexample
34062
34063 Compare data of section @var{section} on target to the exec file.
34064 Without the argument, all sections are compared.
34065
34066 @subsubheading @value{GDBN} Command
34067
34068 The @value{GDBN} equivalent is @samp{compare-sections}.
34069
34070 @subsubheading Example
34071 N.A.
34072 @end ignore
34073
34074
34075 @subheading The @code{-target-detach} Command
34076 @findex -target-detach
34077
34078 @subsubheading Synopsis
34079
34080 @smallexample
34081 -target-detach [ @var{pid} | @var{gid} ]
34082 @end smallexample
34083
34084 Detach from the remote target which normally resumes its execution.
34085 If either @var{pid} or @var{gid} is specified, detaches from either
34086 the specified process, or specified thread group. There's no output.
34087
34088 @subsubheading @value{GDBN} Command
34089
34090 The corresponding @value{GDBN} command is @samp{detach}.
34091
34092 @subsubheading Example
34093
34094 @smallexample
34095 (gdb)
34096 -target-detach
34097 ^done
34098 (gdb)
34099 @end smallexample
34100
34101
34102 @subheading The @code{-target-disconnect} Command
34103 @findex -target-disconnect
34104
34105 @subsubheading Synopsis
34106
34107 @smallexample
34108 -target-disconnect
34109 @end smallexample
34110
34111 Disconnect from the remote target. There's no output and the target is
34112 generally not resumed.
34113
34114 @subsubheading @value{GDBN} Command
34115
34116 The corresponding @value{GDBN} command is @samp{disconnect}.
34117
34118 @subsubheading Example
34119
34120 @smallexample
34121 (gdb)
34122 -target-disconnect
34123 ^done
34124 (gdb)
34125 @end smallexample
34126
34127
34128 @subheading The @code{-target-download} Command
34129 @findex -target-download
34130
34131 @subsubheading Synopsis
34132
34133 @smallexample
34134 -target-download
34135 @end smallexample
34136
34137 Loads the executable onto the remote target.
34138 It prints out an update message every half second, which includes the fields:
34139
34140 @table @samp
34141 @item section
34142 The name of the section.
34143 @item section-sent
34144 The size of what has been sent so far for that section.
34145 @item section-size
34146 The size of the section.
34147 @item total-sent
34148 The total size of what was sent so far (the current and the previous sections).
34149 @item total-size
34150 The size of the overall executable to download.
34151 @end table
34152
34153 @noindent
34154 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
34155 @sc{gdb/mi} Output Syntax}).
34156
34157 In addition, it prints the name and size of the sections, as they are
34158 downloaded. These messages include the following fields:
34159
34160 @table @samp
34161 @item section
34162 The name of the section.
34163 @item section-size
34164 The size of the section.
34165 @item total-size
34166 The size of the overall executable to download.
34167 @end table
34168
34169 @noindent
34170 At the end, a summary is printed.
34171
34172 @subsubheading @value{GDBN} Command
34173
34174 The corresponding @value{GDBN} command is @samp{load}.
34175
34176 @subsubheading Example
34177
34178 Note: each status message appears on a single line. Here the messages
34179 have been broken down so that they can fit onto a page.
34180
34181 @smallexample
34182 (gdb)
34183 -target-download
34184 +download,@{section=".text",section-size="6668",total-size="9880"@}
34185 +download,@{section=".text",section-sent="512",section-size="6668",
34186 total-sent="512",total-size="9880"@}
34187 +download,@{section=".text",section-sent="1024",section-size="6668",
34188 total-sent="1024",total-size="9880"@}
34189 +download,@{section=".text",section-sent="1536",section-size="6668",
34190 total-sent="1536",total-size="9880"@}
34191 +download,@{section=".text",section-sent="2048",section-size="6668",
34192 total-sent="2048",total-size="9880"@}
34193 +download,@{section=".text",section-sent="2560",section-size="6668",
34194 total-sent="2560",total-size="9880"@}
34195 +download,@{section=".text",section-sent="3072",section-size="6668",
34196 total-sent="3072",total-size="9880"@}
34197 +download,@{section=".text",section-sent="3584",section-size="6668",
34198 total-sent="3584",total-size="9880"@}
34199 +download,@{section=".text",section-sent="4096",section-size="6668",
34200 total-sent="4096",total-size="9880"@}
34201 +download,@{section=".text",section-sent="4608",section-size="6668",
34202 total-sent="4608",total-size="9880"@}
34203 +download,@{section=".text",section-sent="5120",section-size="6668",
34204 total-sent="5120",total-size="9880"@}
34205 +download,@{section=".text",section-sent="5632",section-size="6668",
34206 total-sent="5632",total-size="9880"@}
34207 +download,@{section=".text",section-sent="6144",section-size="6668",
34208 total-sent="6144",total-size="9880"@}
34209 +download,@{section=".text",section-sent="6656",section-size="6668",
34210 total-sent="6656",total-size="9880"@}
34211 +download,@{section=".init",section-size="28",total-size="9880"@}
34212 +download,@{section=".fini",section-size="28",total-size="9880"@}
34213 +download,@{section=".data",section-size="3156",total-size="9880"@}
34214 +download,@{section=".data",section-sent="512",section-size="3156",
34215 total-sent="7236",total-size="9880"@}
34216 +download,@{section=".data",section-sent="1024",section-size="3156",
34217 total-sent="7748",total-size="9880"@}
34218 +download,@{section=".data",section-sent="1536",section-size="3156",
34219 total-sent="8260",total-size="9880"@}
34220 +download,@{section=".data",section-sent="2048",section-size="3156",
34221 total-sent="8772",total-size="9880"@}
34222 +download,@{section=".data",section-sent="2560",section-size="3156",
34223 total-sent="9284",total-size="9880"@}
34224 +download,@{section=".data",section-sent="3072",section-size="3156",
34225 total-sent="9796",total-size="9880"@}
34226 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
34227 write-rate="429"
34228 (gdb)
34229 @end smallexample
34230
34231
34232 @ignore
34233 @subheading The @code{-target-exec-status} Command
34234 @findex -target-exec-status
34235
34236 @subsubheading Synopsis
34237
34238 @smallexample
34239 -target-exec-status
34240 @end smallexample
34241
34242 Provide information on the state of the target (whether it is running or
34243 not, for instance).
34244
34245 @subsubheading @value{GDBN} Command
34246
34247 There's no equivalent @value{GDBN} command.
34248
34249 @subsubheading Example
34250 N.A.
34251
34252
34253 @subheading The @code{-target-list-available-targets} Command
34254 @findex -target-list-available-targets
34255
34256 @subsubheading Synopsis
34257
34258 @smallexample
34259 -target-list-available-targets
34260 @end smallexample
34261
34262 List the possible targets to connect to.
34263
34264 @subsubheading @value{GDBN} Command
34265
34266 The corresponding @value{GDBN} command is @samp{help target}.
34267
34268 @subsubheading Example
34269 N.A.
34270
34271
34272 @subheading The @code{-target-list-current-targets} Command
34273 @findex -target-list-current-targets
34274
34275 @subsubheading Synopsis
34276
34277 @smallexample
34278 -target-list-current-targets
34279 @end smallexample
34280
34281 Describe the current target.
34282
34283 @subsubheading @value{GDBN} Command
34284
34285 The corresponding information is printed by @samp{info file} (among
34286 other things).
34287
34288 @subsubheading Example
34289 N.A.
34290
34291
34292 @subheading The @code{-target-list-parameters} Command
34293 @findex -target-list-parameters
34294
34295 @subsubheading Synopsis
34296
34297 @smallexample
34298 -target-list-parameters
34299 @end smallexample
34300
34301 @c ????
34302 @end ignore
34303
34304 @subsubheading @value{GDBN} Command
34305
34306 No equivalent.
34307
34308 @subsubheading Example
34309 N.A.
34310
34311
34312 @subheading The @code{-target-select} Command
34313 @findex -target-select
34314
34315 @subsubheading Synopsis
34316
34317 @smallexample
34318 -target-select @var{type} @var{parameters @dots{}}
34319 @end smallexample
34320
34321 Connect @value{GDBN} to the remote target. This command takes two args:
34322
34323 @table @samp
34324 @item @var{type}
34325 The type of target, for instance @samp{remote}, etc.
34326 @item @var{parameters}
34327 Device names, host names and the like. @xref{Target Commands, ,
34328 Commands for Managing Targets}, for more details.
34329 @end table
34330
34331 The output is a connection notification, followed by the address at
34332 which the target program is, in the following form:
34333
34334 @smallexample
34335 ^connected,addr="@var{address}",func="@var{function name}",
34336 args=[@var{arg list}]
34337 @end smallexample
34338
34339 @subsubheading @value{GDBN} Command
34340
34341 The corresponding @value{GDBN} command is @samp{target}.
34342
34343 @subsubheading Example
34344
34345 @smallexample
34346 (gdb)
34347 -target-select remote /dev/ttya
34348 ^connected,addr="0xfe00a300",func="??",args=[]
34349 (gdb)
34350 @end smallexample
34351
34352 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34353 @node GDB/MI File Transfer Commands
34354 @section @sc{gdb/mi} File Transfer Commands
34355
34356
34357 @subheading The @code{-target-file-put} Command
34358 @findex -target-file-put
34359
34360 @subsubheading Synopsis
34361
34362 @smallexample
34363 -target-file-put @var{hostfile} @var{targetfile}
34364 @end smallexample
34365
34366 Copy file @var{hostfile} from the host system (the machine running
34367 @value{GDBN}) to @var{targetfile} on the target system.
34368
34369 @subsubheading @value{GDBN} Command
34370
34371 The corresponding @value{GDBN} command is @samp{remote put}.
34372
34373 @subsubheading Example
34374
34375 @smallexample
34376 (gdb)
34377 -target-file-put localfile remotefile
34378 ^done
34379 (gdb)
34380 @end smallexample
34381
34382
34383 @subheading The @code{-target-file-get} Command
34384 @findex -target-file-get
34385
34386 @subsubheading Synopsis
34387
34388 @smallexample
34389 -target-file-get @var{targetfile} @var{hostfile}
34390 @end smallexample
34391
34392 Copy file @var{targetfile} from the target system to @var{hostfile}
34393 on the host system.
34394
34395 @subsubheading @value{GDBN} Command
34396
34397 The corresponding @value{GDBN} command is @samp{remote get}.
34398
34399 @subsubheading Example
34400
34401 @smallexample
34402 (gdb)
34403 -target-file-get remotefile localfile
34404 ^done
34405 (gdb)
34406 @end smallexample
34407
34408
34409 @subheading The @code{-target-file-delete} Command
34410 @findex -target-file-delete
34411
34412 @subsubheading Synopsis
34413
34414 @smallexample
34415 -target-file-delete @var{targetfile}
34416 @end smallexample
34417
34418 Delete @var{targetfile} from the target system.
34419
34420 @subsubheading @value{GDBN} Command
34421
34422 The corresponding @value{GDBN} command is @samp{remote delete}.
34423
34424 @subsubheading Example
34425
34426 @smallexample
34427 (gdb)
34428 -target-file-delete remotefile
34429 ^done
34430 (gdb)
34431 @end smallexample
34432
34433
34434 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34435 @node GDB/MI Miscellaneous Commands
34436 @section Miscellaneous @sc{gdb/mi} Commands
34437
34438 @c @subheading -gdb-complete
34439
34440 @subheading The @code{-gdb-exit} Command
34441 @findex -gdb-exit
34442
34443 @subsubheading Synopsis
34444
34445 @smallexample
34446 -gdb-exit
34447 @end smallexample
34448
34449 Exit @value{GDBN} immediately.
34450
34451 @subsubheading @value{GDBN} Command
34452
34453 Approximately corresponds to @samp{quit}.
34454
34455 @subsubheading Example
34456
34457 @smallexample
34458 (gdb)
34459 -gdb-exit
34460 ^exit
34461 @end smallexample
34462
34463
34464 @ignore
34465 @subheading The @code{-exec-abort} Command
34466 @findex -exec-abort
34467
34468 @subsubheading Synopsis
34469
34470 @smallexample
34471 -exec-abort
34472 @end smallexample
34473
34474 Kill the inferior running program.
34475
34476 @subsubheading @value{GDBN} Command
34477
34478 The corresponding @value{GDBN} command is @samp{kill}.
34479
34480 @subsubheading Example
34481 N.A.
34482 @end ignore
34483
34484
34485 @subheading The @code{-gdb-set} Command
34486 @findex -gdb-set
34487
34488 @subsubheading Synopsis
34489
34490 @smallexample
34491 -gdb-set
34492 @end smallexample
34493
34494 Set an internal @value{GDBN} variable.
34495 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
34496
34497 @subsubheading @value{GDBN} Command
34498
34499 The corresponding @value{GDBN} command is @samp{set}.
34500
34501 @subsubheading Example
34502
34503 @smallexample
34504 (gdb)
34505 -gdb-set $foo=3
34506 ^done
34507 (gdb)
34508 @end smallexample
34509
34510
34511 @subheading The @code{-gdb-show} Command
34512 @findex -gdb-show
34513
34514 @subsubheading Synopsis
34515
34516 @smallexample
34517 -gdb-show
34518 @end smallexample
34519
34520 Show the current value of a @value{GDBN} variable.
34521
34522 @subsubheading @value{GDBN} Command
34523
34524 The corresponding @value{GDBN} command is @samp{show}.
34525
34526 @subsubheading Example
34527
34528 @smallexample
34529 (gdb)
34530 -gdb-show annotate
34531 ^done,value="0"
34532 (gdb)
34533 @end smallexample
34534
34535 @c @subheading -gdb-source
34536
34537
34538 @subheading The @code{-gdb-version} Command
34539 @findex -gdb-version
34540
34541 @subsubheading Synopsis
34542
34543 @smallexample
34544 -gdb-version
34545 @end smallexample
34546
34547 Show version information for @value{GDBN}. Used mostly in testing.
34548
34549 @subsubheading @value{GDBN} Command
34550
34551 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
34552 default shows this information when you start an interactive session.
34553
34554 @subsubheading Example
34555
34556 @c This example modifies the actual output from GDB to avoid overfull
34557 @c box in TeX.
34558 @smallexample
34559 (gdb)
34560 -gdb-version
34561 ~GNU gdb 5.2.1
34562 ~Copyright 2000 Free Software Foundation, Inc.
34563 ~GDB is free software, covered by the GNU General Public License, and
34564 ~you are welcome to change it and/or distribute copies of it under
34565 ~ certain conditions.
34566 ~Type "show copying" to see the conditions.
34567 ~There is absolutely no warranty for GDB. Type "show warranty" for
34568 ~ details.
34569 ~This GDB was configured as
34570 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
34571 ^done
34572 (gdb)
34573 @end smallexample
34574
34575 @subheading The @code{-list-features} Command
34576 @findex -list-features
34577
34578 Returns a list of particular features of the MI protocol that
34579 this version of gdb implements. A feature can be a command,
34580 or a new field in an output of some command, or even an
34581 important bugfix. While a frontend can sometimes detect presence
34582 of a feature at runtime, it is easier to perform detection at debugger
34583 startup.
34584
34585 The command returns a list of strings, with each string naming an
34586 available feature. Each returned string is just a name, it does not
34587 have any internal structure. The list of possible feature names
34588 is given below.
34589
34590 Example output:
34591
34592 @smallexample
34593 (gdb) -list-features
34594 ^done,result=["feature1","feature2"]
34595 @end smallexample
34596
34597 The current list of features is:
34598
34599 @table @samp
34600 @item frozen-varobjs
34601 Indicates support for the @code{-var-set-frozen} command, as well
34602 as possible presense of the @code{frozen} field in the output
34603 of @code{-varobj-create}.
34604 @item pending-breakpoints
34605 Indicates support for the @option{-f} option to the @code{-break-insert}
34606 command.
34607 @item python
34608 Indicates Python scripting support, Python-based
34609 pretty-printing commands, and possible presence of the
34610 @samp{display_hint} field in the output of @code{-var-list-children}
34611 @item thread-info
34612 Indicates support for the @code{-thread-info} command.
34613 @item data-read-memory-bytes
34614 Indicates support for the @code{-data-read-memory-bytes} and the
34615 @code{-data-write-memory-bytes} commands.
34616 @item breakpoint-notifications
34617 Indicates that changes to breakpoints and breakpoints created via the
34618 CLI will be announced via async records.
34619 @item ada-task-info
34620 Indicates support for the @code{-ada-task-info} command.
34621 @end table
34622
34623 @subheading The @code{-list-target-features} Command
34624 @findex -list-target-features
34625
34626 Returns a list of particular features that are supported by the
34627 target. Those features affect the permitted MI commands, but
34628 unlike the features reported by the @code{-list-features} command, the
34629 features depend on which target GDB is using at the moment. Whenever
34630 a target can change, due to commands such as @code{-target-select},
34631 @code{-target-attach} or @code{-exec-run}, the list of target features
34632 may change, and the frontend should obtain it again.
34633 Example output:
34634
34635 @smallexample
34636 (gdb) -list-target-features
34637 ^done,result=["async"]
34638 @end smallexample
34639
34640 The current list of features is:
34641
34642 @table @samp
34643 @item async
34644 Indicates that the target is capable of asynchronous command
34645 execution, which means that @value{GDBN} will accept further commands
34646 while the target is running.
34647
34648 @item reverse
34649 Indicates that the target is capable of reverse execution.
34650 @xref{Reverse Execution}, for more information.
34651
34652 @end table
34653
34654 @subheading The @code{-list-thread-groups} Command
34655 @findex -list-thread-groups
34656
34657 @subheading Synopsis
34658
34659 @smallexample
34660 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
34661 @end smallexample
34662
34663 Lists thread groups (@pxref{Thread groups}). When a single thread
34664 group is passed as the argument, lists the children of that group.
34665 When several thread group are passed, lists information about those
34666 thread groups. Without any parameters, lists information about all
34667 top-level thread groups.
34668
34669 Normally, thread groups that are being debugged are reported.
34670 With the @samp{--available} option, @value{GDBN} reports thread groups
34671 available on the target.
34672
34673 The output of this command may have either a @samp{threads} result or
34674 a @samp{groups} result. The @samp{thread} result has a list of tuples
34675 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
34676 Information}). The @samp{groups} result has a list of tuples as value,
34677 each tuple describing a thread group. If top-level groups are
34678 requested (that is, no parameter is passed), or when several groups
34679 are passed, the output always has a @samp{groups} result. The format
34680 of the @samp{group} result is described below.
34681
34682 To reduce the number of roundtrips it's possible to list thread groups
34683 together with their children, by passing the @samp{--recurse} option
34684 and the recursion depth. Presently, only recursion depth of 1 is
34685 permitted. If this option is present, then every reported thread group
34686 will also include its children, either as @samp{group} or
34687 @samp{threads} field.
34688
34689 In general, any combination of option and parameters is permitted, with
34690 the following caveats:
34691
34692 @itemize @bullet
34693 @item
34694 When a single thread group is passed, the output will typically
34695 be the @samp{threads} result. Because threads may not contain
34696 anything, the @samp{recurse} option will be ignored.
34697
34698 @item
34699 When the @samp{--available} option is passed, limited information may
34700 be available. In particular, the list of threads of a process might
34701 be inaccessible. Further, specifying specific thread groups might
34702 not give any performance advantage over listing all thread groups.
34703 The frontend should assume that @samp{-list-thread-groups --available}
34704 is always an expensive operation and cache the results.
34705
34706 @end itemize
34707
34708 The @samp{groups} result is a list of tuples, where each tuple may
34709 have the following fields:
34710
34711 @table @code
34712 @item id
34713 Identifier of the thread group. This field is always present.
34714 The identifier is an opaque string; frontends should not try to
34715 convert it to an integer, even though it might look like one.
34716
34717 @item type
34718 The type of the thread group. At present, only @samp{process} is a
34719 valid type.
34720
34721 @item pid
34722 The target-specific process identifier. This field is only present
34723 for thread groups of type @samp{process} and only if the process exists.
34724
34725 @item num_children
34726 The number of children this thread group has. This field may be
34727 absent for an available thread group.
34728
34729 @item threads
34730 This field has a list of tuples as value, each tuple describing a
34731 thread. It may be present if the @samp{--recurse} option is
34732 specified, and it's actually possible to obtain the threads.
34733
34734 @item cores
34735 This field is a list of integers, each identifying a core that one
34736 thread of the group is running on. This field may be absent if
34737 such information is not available.
34738
34739 @item executable
34740 The name of the executable file that corresponds to this thread group.
34741 The field is only present for thread groups of type @samp{process},
34742 and only if there is a corresponding executable file.
34743
34744 @end table
34745
34746 @subheading Example
34747
34748 @smallexample
34749 @value{GDBP}
34750 -list-thread-groups
34751 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
34752 -list-thread-groups 17
34753 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
34754 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
34755 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
34756 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
34757 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
34758 -list-thread-groups --available
34759 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
34760 -list-thread-groups --available --recurse 1
34761 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
34762 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
34763 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
34764 -list-thread-groups --available --recurse 1 17 18
34765 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
34766 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
34767 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
34768 @end smallexample
34769
34770 @subheading The @code{-info-os} Command
34771 @findex -info-os
34772
34773 @subsubheading Synopsis
34774
34775 @smallexample
34776 -info-os [ @var{type} ]
34777 @end smallexample
34778
34779 If no argument is supplied, the command returns a table of available
34780 operating-system-specific information types. If one of these types is
34781 supplied as an argument @var{type}, then the command returns a table
34782 of data of that type.
34783
34784 The types of information available depend on the target operating
34785 system.
34786
34787 @subsubheading @value{GDBN} Command
34788
34789 The corresponding @value{GDBN} command is @samp{info os}.
34790
34791 @subsubheading Example
34792
34793 When run on a @sc{gnu}/Linux system, the output will look something
34794 like this:
34795
34796 @smallexample
34797 @value{GDBP}
34798 -info-os
34799 ^done,OSDataTable=@{nr_rows="9",nr_cols="3",
34800 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
34801 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
34802 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
34803 body=[item=@{col0="processes",col1="Listing of all processes",
34804 col2="Processes"@},
34805 item=@{col0="procgroups",col1="Listing of all process groups",
34806 col2="Process groups"@},
34807 item=@{col0="threads",col1="Listing of all threads",
34808 col2="Threads"@},
34809 item=@{col0="files",col1="Listing of all file descriptors",
34810 col2="File descriptors"@},
34811 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
34812 col2="Sockets"@},
34813 item=@{col0="shm",col1="Listing of all shared-memory regions",
34814 col2="Shared-memory regions"@},
34815 item=@{col0="semaphores",col1="Listing of all semaphores",
34816 col2="Semaphores"@},
34817 item=@{col0="msg",col1="Listing of all message queues",
34818 col2="Message queues"@},
34819 item=@{col0="modules",col1="Listing of all loaded kernel modules",
34820 col2="Kernel modules"@}]@}
34821 @value{GDBP}
34822 -info-os processes
34823 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
34824 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
34825 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
34826 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
34827 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
34828 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
34829 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
34830 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
34831 ...
34832 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
34833 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
34834 (gdb)
34835 @end smallexample
34836
34837 (Note that the MI output here includes a @code{"Title"} column that
34838 does not appear in command-line @code{info os}; this column is useful
34839 for MI clients that want to enumerate the types of data, such as in a
34840 popup menu, but is needless clutter on the command line, and
34841 @code{info os} omits it.)
34842
34843 @subheading The @code{-add-inferior} Command
34844 @findex -add-inferior
34845
34846 @subheading Synopsis
34847
34848 @smallexample
34849 -add-inferior
34850 @end smallexample
34851
34852 Creates a new inferior (@pxref{Inferiors and Programs}). The created
34853 inferior is not associated with any executable. Such association may
34854 be established with the @samp{-file-exec-and-symbols} command
34855 (@pxref{GDB/MI File Commands}). The command response has a single
34856 field, @samp{inferior}, whose value is the identifier of the
34857 thread group corresponding to the new inferior.
34858
34859 @subheading Example
34860
34861 @smallexample
34862 @value{GDBP}
34863 -add-inferior
34864 ^done,inferior="i3"
34865 @end smallexample
34866
34867 @subheading The @code{-interpreter-exec} Command
34868 @findex -interpreter-exec
34869
34870 @subheading Synopsis
34871
34872 @smallexample
34873 -interpreter-exec @var{interpreter} @var{command}
34874 @end smallexample
34875 @anchor{-interpreter-exec}
34876
34877 Execute the specified @var{command} in the given @var{interpreter}.
34878
34879 @subheading @value{GDBN} Command
34880
34881 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
34882
34883 @subheading Example
34884
34885 @smallexample
34886 (gdb)
34887 -interpreter-exec console "break main"
34888 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
34889 &"During symbol reading, bad structure-type format.\n"
34890 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
34891 ^done
34892 (gdb)
34893 @end smallexample
34894
34895 @subheading The @code{-inferior-tty-set} Command
34896 @findex -inferior-tty-set
34897
34898 @subheading Synopsis
34899
34900 @smallexample
34901 -inferior-tty-set /dev/pts/1
34902 @end smallexample
34903
34904 Set terminal for future runs of the program being debugged.
34905
34906 @subheading @value{GDBN} Command
34907
34908 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
34909
34910 @subheading Example
34911
34912 @smallexample
34913 (gdb)
34914 -inferior-tty-set /dev/pts/1
34915 ^done
34916 (gdb)
34917 @end smallexample
34918
34919 @subheading The @code{-inferior-tty-show} Command
34920 @findex -inferior-tty-show
34921
34922 @subheading Synopsis
34923
34924 @smallexample
34925 -inferior-tty-show
34926 @end smallexample
34927
34928 Show terminal for future runs of program being debugged.
34929
34930 @subheading @value{GDBN} Command
34931
34932 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
34933
34934 @subheading Example
34935
34936 @smallexample
34937 (gdb)
34938 -inferior-tty-set /dev/pts/1
34939 ^done
34940 (gdb)
34941 -inferior-tty-show
34942 ^done,inferior_tty_terminal="/dev/pts/1"
34943 (gdb)
34944 @end smallexample
34945
34946 @subheading The @code{-enable-timings} Command
34947 @findex -enable-timings
34948
34949 @subheading Synopsis
34950
34951 @smallexample
34952 -enable-timings [yes | no]
34953 @end smallexample
34954
34955 Toggle the printing of the wallclock, user and system times for an MI
34956 command as a field in its output. This command is to help frontend
34957 developers optimize the performance of their code. No argument is
34958 equivalent to @samp{yes}.
34959
34960 @subheading @value{GDBN} Command
34961
34962 No equivalent.
34963
34964 @subheading Example
34965
34966 @smallexample
34967 (gdb)
34968 -enable-timings
34969 ^done
34970 (gdb)
34971 -break-insert main
34972 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
34973 addr="0x080484ed",func="main",file="myprog.c",
34974 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
34975 times="0"@},
34976 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
34977 (gdb)
34978 -enable-timings no
34979 ^done
34980 (gdb)
34981 -exec-run
34982 ^running
34983 (gdb)
34984 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
34985 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
34986 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
34987 fullname="/home/nickrob/myprog.c",line="73"@}
34988 (gdb)
34989 @end smallexample
34990
34991 @node Annotations
34992 @chapter @value{GDBN} Annotations
34993
34994 This chapter describes annotations in @value{GDBN}. Annotations were
34995 designed to interface @value{GDBN} to graphical user interfaces or other
34996 similar programs which want to interact with @value{GDBN} at a
34997 relatively high level.
34998
34999 The annotation mechanism has largely been superseded by @sc{gdb/mi}
35000 (@pxref{GDB/MI}).
35001
35002 @ignore
35003 This is Edition @value{EDITION}, @value{DATE}.
35004 @end ignore
35005
35006 @menu
35007 * Annotations Overview:: What annotations are; the general syntax.
35008 * Server Prefix:: Issuing a command without affecting user state.
35009 * Prompting:: Annotations marking @value{GDBN}'s need for input.
35010 * Errors:: Annotations for error messages.
35011 * Invalidation:: Some annotations describe things now invalid.
35012 * Annotations for Running::
35013 Whether the program is running, how it stopped, etc.
35014 * Source Annotations:: Annotations describing source code.
35015 @end menu
35016
35017 @node Annotations Overview
35018 @section What is an Annotation?
35019 @cindex annotations
35020
35021 Annotations start with a newline character, two @samp{control-z}
35022 characters, and the name of the annotation. If there is no additional
35023 information associated with this annotation, the name of the annotation
35024 is followed immediately by a newline. If there is additional
35025 information, the name of the annotation is followed by a space, the
35026 additional information, and a newline. The additional information
35027 cannot contain newline characters.
35028
35029 Any output not beginning with a newline and two @samp{control-z}
35030 characters denotes literal output from @value{GDBN}. Currently there is
35031 no need for @value{GDBN} to output a newline followed by two
35032 @samp{control-z} characters, but if there was such a need, the
35033 annotations could be extended with an @samp{escape} annotation which
35034 means those three characters as output.
35035
35036 The annotation @var{level}, which is specified using the
35037 @option{--annotate} command line option (@pxref{Mode Options}), controls
35038 how much information @value{GDBN} prints together with its prompt,
35039 values of expressions, source lines, and other types of output. Level 0
35040 is for no annotations, level 1 is for use when @value{GDBN} is run as a
35041 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
35042 for programs that control @value{GDBN}, and level 2 annotations have
35043 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
35044 Interface, annotate, GDB's Obsolete Annotations}).
35045
35046 @table @code
35047 @kindex set annotate
35048 @item set annotate @var{level}
35049 The @value{GDBN} command @code{set annotate} sets the level of
35050 annotations to the specified @var{level}.
35051
35052 @item show annotate
35053 @kindex show annotate
35054 Show the current annotation level.
35055 @end table
35056
35057 This chapter describes level 3 annotations.
35058
35059 A simple example of starting up @value{GDBN} with annotations is:
35060
35061 @smallexample
35062 $ @kbd{gdb --annotate=3}
35063 GNU gdb 6.0
35064 Copyright 2003 Free Software Foundation, Inc.
35065 GDB is free software, covered by the GNU General Public License,
35066 and you are welcome to change it and/or distribute copies of it
35067 under certain conditions.
35068 Type "show copying" to see the conditions.
35069 There is absolutely no warranty for GDB. Type "show warranty"
35070 for details.
35071 This GDB was configured as "i386-pc-linux-gnu"
35072
35073 ^Z^Zpre-prompt
35074 (@value{GDBP})
35075 ^Z^Zprompt
35076 @kbd{quit}
35077
35078 ^Z^Zpost-prompt
35079 $
35080 @end smallexample
35081
35082 Here @samp{quit} is input to @value{GDBN}; the rest is output from
35083 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
35084 denotes a @samp{control-z} character) are annotations; the rest is
35085 output from @value{GDBN}.
35086
35087 @node Server Prefix
35088 @section The Server Prefix
35089 @cindex server prefix
35090
35091 If you prefix a command with @samp{server } then it will not affect
35092 the command history, nor will it affect @value{GDBN}'s notion of which
35093 command to repeat if @key{RET} is pressed on a line by itself. This
35094 means that commands can be run behind a user's back by a front-end in
35095 a transparent manner.
35096
35097 The @code{server } prefix does not affect the recording of values into
35098 the value history; to print a value without recording it into the
35099 value history, use the @code{output} command instead of the
35100 @code{print} command.
35101
35102 Using this prefix also disables confirmation requests
35103 (@pxref{confirmation requests}).
35104
35105 @node Prompting
35106 @section Annotation for @value{GDBN} Input
35107
35108 @cindex annotations for prompts
35109 When @value{GDBN} prompts for input, it annotates this fact so it is possible
35110 to know when to send output, when the output from a given command is
35111 over, etc.
35112
35113 Different kinds of input each have a different @dfn{input type}. Each
35114 input type has three annotations: a @code{pre-} annotation, which
35115 denotes the beginning of any prompt which is being output, a plain
35116 annotation, which denotes the end of the prompt, and then a @code{post-}
35117 annotation which denotes the end of any echo which may (or may not) be
35118 associated with the input. For example, the @code{prompt} input type
35119 features the following annotations:
35120
35121 @smallexample
35122 ^Z^Zpre-prompt
35123 ^Z^Zprompt
35124 ^Z^Zpost-prompt
35125 @end smallexample
35126
35127 The input types are
35128
35129 @table @code
35130 @findex pre-prompt annotation
35131 @findex prompt annotation
35132 @findex post-prompt annotation
35133 @item prompt
35134 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
35135
35136 @findex pre-commands annotation
35137 @findex commands annotation
35138 @findex post-commands annotation
35139 @item commands
35140 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
35141 command. The annotations are repeated for each command which is input.
35142
35143 @findex pre-overload-choice annotation
35144 @findex overload-choice annotation
35145 @findex post-overload-choice annotation
35146 @item overload-choice
35147 When @value{GDBN} wants the user to select between various overloaded functions.
35148
35149 @findex pre-query annotation
35150 @findex query annotation
35151 @findex post-query annotation
35152 @item query
35153 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
35154
35155 @findex pre-prompt-for-continue annotation
35156 @findex prompt-for-continue annotation
35157 @findex post-prompt-for-continue annotation
35158 @item prompt-for-continue
35159 When @value{GDBN} is asking the user to press return to continue. Note: Don't
35160 expect this to work well; instead use @code{set height 0} to disable
35161 prompting. This is because the counting of lines is buggy in the
35162 presence of annotations.
35163 @end table
35164
35165 @node Errors
35166 @section Errors
35167 @cindex annotations for errors, warnings and interrupts
35168
35169 @findex quit annotation
35170 @smallexample
35171 ^Z^Zquit
35172 @end smallexample
35173
35174 This annotation occurs right before @value{GDBN} responds to an interrupt.
35175
35176 @findex error annotation
35177 @smallexample
35178 ^Z^Zerror
35179 @end smallexample
35180
35181 This annotation occurs right before @value{GDBN} responds to an error.
35182
35183 Quit and error annotations indicate that any annotations which @value{GDBN} was
35184 in the middle of may end abruptly. For example, if a
35185 @code{value-history-begin} annotation is followed by a @code{error}, one
35186 cannot expect to receive the matching @code{value-history-end}. One
35187 cannot expect not to receive it either, however; an error annotation
35188 does not necessarily mean that @value{GDBN} is immediately returning all the way
35189 to the top level.
35190
35191 @findex error-begin annotation
35192 A quit or error annotation may be preceded by
35193
35194 @smallexample
35195 ^Z^Zerror-begin
35196 @end smallexample
35197
35198 Any output between that and the quit or error annotation is the error
35199 message.
35200
35201 Warning messages are not yet annotated.
35202 @c If we want to change that, need to fix warning(), type_error(),
35203 @c range_error(), and possibly other places.
35204
35205 @node Invalidation
35206 @section Invalidation Notices
35207
35208 @cindex annotations for invalidation messages
35209 The following annotations say that certain pieces of state may have
35210 changed.
35211
35212 @table @code
35213 @findex frames-invalid annotation
35214 @item ^Z^Zframes-invalid
35215
35216 The frames (for example, output from the @code{backtrace} command) may
35217 have changed.
35218
35219 @findex breakpoints-invalid annotation
35220 @item ^Z^Zbreakpoints-invalid
35221
35222 The breakpoints may have changed. For example, the user just added or
35223 deleted a breakpoint.
35224 @end table
35225
35226 @node Annotations for Running
35227 @section Running the Program
35228 @cindex annotations for running programs
35229
35230 @findex starting annotation
35231 @findex stopping annotation
35232 When the program starts executing due to a @value{GDBN} command such as
35233 @code{step} or @code{continue},
35234
35235 @smallexample
35236 ^Z^Zstarting
35237 @end smallexample
35238
35239 is output. When the program stops,
35240
35241 @smallexample
35242 ^Z^Zstopped
35243 @end smallexample
35244
35245 is output. Before the @code{stopped} annotation, a variety of
35246 annotations describe how the program stopped.
35247
35248 @table @code
35249 @findex exited annotation
35250 @item ^Z^Zexited @var{exit-status}
35251 The program exited, and @var{exit-status} is the exit status (zero for
35252 successful exit, otherwise nonzero).
35253
35254 @findex signalled annotation
35255 @findex signal-name annotation
35256 @findex signal-name-end annotation
35257 @findex signal-string annotation
35258 @findex signal-string-end annotation
35259 @item ^Z^Zsignalled
35260 The program exited with a signal. After the @code{^Z^Zsignalled}, the
35261 annotation continues:
35262
35263 @smallexample
35264 @var{intro-text}
35265 ^Z^Zsignal-name
35266 @var{name}
35267 ^Z^Zsignal-name-end
35268 @var{middle-text}
35269 ^Z^Zsignal-string
35270 @var{string}
35271 ^Z^Zsignal-string-end
35272 @var{end-text}
35273 @end smallexample
35274
35275 @noindent
35276 where @var{name} is the name of the signal, such as @code{SIGILL} or
35277 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
35278 as @code{Illegal Instruction} or @code{Segmentation fault}.
35279 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
35280 user's benefit and have no particular format.
35281
35282 @findex signal annotation
35283 @item ^Z^Zsignal
35284 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
35285 just saying that the program received the signal, not that it was
35286 terminated with it.
35287
35288 @findex breakpoint annotation
35289 @item ^Z^Zbreakpoint @var{number}
35290 The program hit breakpoint number @var{number}.
35291
35292 @findex watchpoint annotation
35293 @item ^Z^Zwatchpoint @var{number}
35294 The program hit watchpoint number @var{number}.
35295 @end table
35296
35297 @node Source Annotations
35298 @section Displaying Source
35299 @cindex annotations for source display
35300
35301 @findex source annotation
35302 The following annotation is used instead of displaying source code:
35303
35304 @smallexample
35305 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
35306 @end smallexample
35307
35308 where @var{filename} is an absolute file name indicating which source
35309 file, @var{line} is the line number within that file (where 1 is the
35310 first line in the file), @var{character} is the character position
35311 within the file (where 0 is the first character in the file) (for most
35312 debug formats this will necessarily point to the beginning of a line),
35313 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
35314 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
35315 @var{addr} is the address in the target program associated with the
35316 source which is being displayed. @var{addr} is in the form @samp{0x}
35317 followed by one or more lowercase hex digits (note that this does not
35318 depend on the language).
35319
35320 @node JIT Interface
35321 @chapter JIT Compilation Interface
35322 @cindex just-in-time compilation
35323 @cindex JIT compilation interface
35324
35325 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
35326 interface. A JIT compiler is a program or library that generates native
35327 executable code at runtime and executes it, usually in order to achieve good
35328 performance while maintaining platform independence.
35329
35330 Programs that use JIT compilation are normally difficult to debug because
35331 portions of their code are generated at runtime, instead of being loaded from
35332 object files, which is where @value{GDBN} normally finds the program's symbols
35333 and debug information. In order to debug programs that use JIT compilation,
35334 @value{GDBN} has an interface that allows the program to register in-memory
35335 symbol files with @value{GDBN} at runtime.
35336
35337 If you are using @value{GDBN} to debug a program that uses this interface, then
35338 it should work transparently so long as you have not stripped the binary. If
35339 you are developing a JIT compiler, then the interface is documented in the rest
35340 of this chapter. At this time, the only known client of this interface is the
35341 LLVM JIT.
35342
35343 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
35344 JIT compiler communicates with @value{GDBN} by writing data into a global
35345 variable and calling a fuction at a well-known symbol. When @value{GDBN}
35346 attaches, it reads a linked list of symbol files from the global variable to
35347 find existing code, and puts a breakpoint in the function so that it can find
35348 out about additional code.
35349
35350 @menu
35351 * Declarations:: Relevant C struct declarations
35352 * Registering Code:: Steps to register code
35353 * Unregistering Code:: Steps to unregister code
35354 * Custom Debug Info:: Emit debug information in a custom format
35355 @end menu
35356
35357 @node Declarations
35358 @section JIT Declarations
35359
35360 These are the relevant struct declarations that a C program should include to
35361 implement the interface:
35362
35363 @smallexample
35364 typedef enum
35365 @{
35366 JIT_NOACTION = 0,
35367 JIT_REGISTER_FN,
35368 JIT_UNREGISTER_FN
35369 @} jit_actions_t;
35370
35371 struct jit_code_entry
35372 @{
35373 struct jit_code_entry *next_entry;
35374 struct jit_code_entry *prev_entry;
35375 const char *symfile_addr;
35376 uint64_t symfile_size;
35377 @};
35378
35379 struct jit_descriptor
35380 @{
35381 uint32_t version;
35382 /* This type should be jit_actions_t, but we use uint32_t
35383 to be explicit about the bitwidth. */
35384 uint32_t action_flag;
35385 struct jit_code_entry *relevant_entry;
35386 struct jit_code_entry *first_entry;
35387 @};
35388
35389 /* GDB puts a breakpoint in this function. */
35390 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
35391
35392 /* Make sure to specify the version statically, because the
35393 debugger may check the version before we can set it. */
35394 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
35395 @end smallexample
35396
35397 If the JIT is multi-threaded, then it is important that the JIT synchronize any
35398 modifications to this global data properly, which can easily be done by putting
35399 a global mutex around modifications to these structures.
35400
35401 @node Registering Code
35402 @section Registering Code
35403
35404 To register code with @value{GDBN}, the JIT should follow this protocol:
35405
35406 @itemize @bullet
35407 @item
35408 Generate an object file in memory with symbols and other desired debug
35409 information. The file must include the virtual addresses of the sections.
35410
35411 @item
35412 Create a code entry for the file, which gives the start and size of the symbol
35413 file.
35414
35415 @item
35416 Add it to the linked list in the JIT descriptor.
35417
35418 @item
35419 Point the relevant_entry field of the descriptor at the entry.
35420
35421 @item
35422 Set @code{action_flag} to @code{JIT_REGISTER} and call
35423 @code{__jit_debug_register_code}.
35424 @end itemize
35425
35426 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
35427 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
35428 new code. However, the linked list must still be maintained in order to allow
35429 @value{GDBN} to attach to a running process and still find the symbol files.
35430
35431 @node Unregistering Code
35432 @section Unregistering Code
35433
35434 If code is freed, then the JIT should use the following protocol:
35435
35436 @itemize @bullet
35437 @item
35438 Remove the code entry corresponding to the code from the linked list.
35439
35440 @item
35441 Point the @code{relevant_entry} field of the descriptor at the code entry.
35442
35443 @item
35444 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
35445 @code{__jit_debug_register_code}.
35446 @end itemize
35447
35448 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
35449 and the JIT will leak the memory used for the associated symbol files.
35450
35451 @node Custom Debug Info
35452 @section Custom Debug Info
35453 @cindex custom JIT debug info
35454 @cindex JIT debug info reader
35455
35456 Generating debug information in platform-native file formats (like ELF
35457 or COFF) may be an overkill for JIT compilers; especially if all the
35458 debug info is used for is displaying a meaningful backtrace. The
35459 issue can be resolved by having the JIT writers decide on a debug info
35460 format and also provide a reader that parses the debug info generated
35461 by the JIT compiler. This section gives a brief overview on writing
35462 such a parser. More specific details can be found in the source file
35463 @file{gdb/jit-reader.in}, which is also installed as a header at
35464 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
35465
35466 The reader is implemented as a shared object (so this functionality is
35467 not available on platforms which don't allow loading shared objects at
35468 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
35469 @code{jit-reader-unload} are provided, to be used to load and unload
35470 the readers from a preconfigured directory. Once loaded, the shared
35471 object is used the parse the debug information emitted by the JIT
35472 compiler.
35473
35474 @menu
35475 * Using JIT Debug Info Readers:: How to use supplied readers correctly
35476 * Writing JIT Debug Info Readers:: Creating a debug-info reader
35477 @end menu
35478
35479 @node Using JIT Debug Info Readers
35480 @subsection Using JIT Debug Info Readers
35481 @kindex jit-reader-load
35482 @kindex jit-reader-unload
35483
35484 Readers can be loaded and unloaded using the @code{jit-reader-load}
35485 and @code{jit-reader-unload} commands.
35486
35487 @table @code
35488 @item jit-reader-load @var{reader}
35489 Load the JIT reader named @var{reader}. @var{reader} is a shared
35490 object specified as either an absolute or a relative file name. In
35491 the latter case, @value{GDBN} will try to load the reader from a
35492 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
35493 system (here @var{libdir} is the system library directory, often
35494 @file{/usr/local/lib}).
35495
35496 Only one reader can be active at a time; trying to load a second
35497 reader when one is already loaded will result in @value{GDBN}
35498 reporting an error. A new JIT reader can be loaded by first unloading
35499 the current one using @code{jit-reader-unload} and then invoking
35500 @code{jit-reader-load}.
35501
35502 @item jit-reader-unload
35503 Unload the currently loaded JIT reader.
35504
35505 @end table
35506
35507 @node Writing JIT Debug Info Readers
35508 @subsection Writing JIT Debug Info Readers
35509 @cindex writing JIT debug info readers
35510
35511 As mentioned, a reader is essentially a shared object conforming to a
35512 certain ABI. This ABI is described in @file{jit-reader.h}.
35513
35514 @file{jit-reader.h} defines the structures, macros and functions
35515 required to write a reader. It is installed (along with
35516 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
35517 the system include directory.
35518
35519 Readers need to be released under a GPL compatible license. A reader
35520 can be declared as released under such a license by placing the macro
35521 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
35522
35523 The entry point for readers is the symbol @code{gdb_init_reader},
35524 which is expected to be a function with the prototype
35525
35526 @findex gdb_init_reader
35527 @smallexample
35528 extern struct gdb_reader_funcs *gdb_init_reader (void);
35529 @end smallexample
35530
35531 @cindex @code{struct gdb_reader_funcs}
35532
35533 @code{struct gdb_reader_funcs} contains a set of pointers to callback
35534 functions. These functions are executed to read the debug info
35535 generated by the JIT compiler (@code{read}), to unwind stack frames
35536 (@code{unwind}) and to create canonical frame IDs
35537 (@code{get_Frame_id}). It also has a callback that is called when the
35538 reader is being unloaded (@code{destroy}). The struct looks like this
35539
35540 @smallexample
35541 struct gdb_reader_funcs
35542 @{
35543 /* Must be set to GDB_READER_INTERFACE_VERSION. */
35544 int reader_version;
35545
35546 /* For use by the reader. */
35547 void *priv_data;
35548
35549 gdb_read_debug_info *read;
35550 gdb_unwind_frame *unwind;
35551 gdb_get_frame_id *get_frame_id;
35552 gdb_destroy_reader *destroy;
35553 @};
35554 @end smallexample
35555
35556 @cindex @code{struct gdb_symbol_callbacks}
35557 @cindex @code{struct gdb_unwind_callbacks}
35558
35559 The callbacks are provided with another set of callbacks by
35560 @value{GDBN} to do their job. For @code{read}, these callbacks are
35561 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
35562 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
35563 @code{struct gdb_symbol_callbacks} has callbacks to create new object
35564 files and new symbol tables inside those object files. @code{struct
35565 gdb_unwind_callbacks} has callbacks to read registers off the current
35566 frame and to write out the values of the registers in the previous
35567 frame. Both have a callback (@code{target_read}) to read bytes off the
35568 target's address space.
35569
35570 @node In-Process Agent
35571 @chapter In-Process Agent
35572 @cindex debugging agent
35573 The traditional debugging model is conceptually low-speed, but works fine,
35574 because most bugs can be reproduced in debugging-mode execution. However,
35575 as multi-core or many-core processors are becoming mainstream, and
35576 multi-threaded programs become more and more popular, there should be more
35577 and more bugs that only manifest themselves at normal-mode execution, for
35578 example, thread races, because debugger's interference with the program's
35579 timing may conceal the bugs. On the other hand, in some applications,
35580 it is not feasible for the debugger to interrupt the program's execution
35581 long enough for the developer to learn anything helpful about its behavior.
35582 If the program's correctness depends on its real-time behavior, delays
35583 introduced by a debugger might cause the program to fail, even when the
35584 code itself is correct. It is useful to be able to observe the program's
35585 behavior without interrupting it.
35586
35587 Therefore, traditional debugging model is too intrusive to reproduce
35588 some bugs. In order to reduce the interference with the program, we can
35589 reduce the number of operations performed by debugger. The
35590 @dfn{In-Process Agent}, a shared library, is running within the same
35591 process with inferior, and is able to perform some debugging operations
35592 itself. As a result, debugger is only involved when necessary, and
35593 performance of debugging can be improved accordingly. Note that
35594 interference with program can be reduced but can't be removed completely,
35595 because the in-process agent will still stop or slow down the program.
35596
35597 The in-process agent can interpret and execute Agent Expressions
35598 (@pxref{Agent Expressions}) during performing debugging operations. The
35599 agent expressions can be used for different purposes, such as collecting
35600 data in tracepoints, and condition evaluation in breakpoints.
35601
35602 @anchor{Control Agent}
35603 You can control whether the in-process agent is used as an aid for
35604 debugging with the following commands:
35605
35606 @table @code
35607 @kindex set agent on
35608 @item set agent on
35609 Causes the in-process agent to perform some operations on behalf of the
35610 debugger. Just which operations requested by the user will be done
35611 by the in-process agent depends on the its capabilities. For example,
35612 if you request to evaluate breakpoint conditions in the in-process agent,
35613 and the in-process agent has such capability as well, then breakpoint
35614 conditions will be evaluated in the in-process agent.
35615
35616 @kindex set agent off
35617 @item set agent off
35618 Disables execution of debugging operations by the in-process agent. All
35619 of the operations will be performed by @value{GDBN}.
35620
35621 @kindex show agent
35622 @item show agent
35623 Display the current setting of execution of debugging operations by
35624 the in-process agent.
35625 @end table
35626
35627 @menu
35628 * In-Process Agent Protocol::
35629 @end menu
35630
35631 @node In-Process Agent Protocol
35632 @section In-Process Agent Protocol
35633 @cindex in-process agent protocol
35634
35635 The in-process agent is able to communicate with both @value{GDBN} and
35636 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
35637 used for communications between @value{GDBN} or GDBserver and the IPA.
35638 In general, @value{GDBN} or GDBserver sends commands
35639 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
35640 in-process agent replies back with the return result of the command, or
35641 some other information. The data sent to in-process agent is composed
35642 of primitive data types, such as 4-byte or 8-byte type, and composite
35643 types, which are called objects (@pxref{IPA Protocol Objects}).
35644
35645 @menu
35646 * IPA Protocol Objects::
35647 * IPA Protocol Commands::
35648 @end menu
35649
35650 @node IPA Protocol Objects
35651 @subsection IPA Protocol Objects
35652 @cindex ipa protocol objects
35653
35654 The commands sent to and results received from agent may contain some
35655 complex data types called @dfn{objects}.
35656
35657 The in-process agent is running on the same machine with @value{GDBN}
35658 or GDBserver, so it doesn't have to handle as much differences between
35659 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
35660 However, there are still some differences of two ends in two processes:
35661
35662 @enumerate
35663 @item
35664 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
35665 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
35666 @item
35667 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
35668 GDBserver is compiled with one, and in-process agent is compiled with
35669 the other one.
35670 @end enumerate
35671
35672 Here are the IPA Protocol Objects:
35673
35674 @enumerate
35675 @item
35676 agent expression object. It represents an agent expression
35677 (@pxref{Agent Expressions}).
35678 @anchor{agent expression object}
35679 @item
35680 tracepoint action object. It represents a tracepoint action
35681 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
35682 memory, static trace data and to evaluate expression.
35683 @anchor{tracepoint action object}
35684 @item
35685 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
35686 @anchor{tracepoint object}
35687
35688 @end enumerate
35689
35690 The following table describes important attributes of each IPA protocol
35691 object:
35692
35693 @multitable @columnfractions .30 .20 .50
35694 @headitem Name @tab Size @tab Description
35695 @item @emph{agent expression object} @tab @tab
35696 @item length @tab 4 @tab length of bytes code
35697 @item byte code @tab @var{length} @tab contents of byte code
35698 @item @emph{tracepoint action for collecting memory} @tab @tab
35699 @item 'M' @tab 1 @tab type of tracepoint action
35700 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
35701 address of the lowest byte to collect, otherwise @var{addr} is the offset
35702 of @var{basereg} for memory collecting.
35703 @item len @tab 8 @tab length of memory for collecting
35704 @item basereg @tab 4 @tab the register number containing the starting
35705 memory address for collecting.
35706 @item @emph{tracepoint action for collecting registers} @tab @tab
35707 @item 'R' @tab 1 @tab type of tracepoint action
35708 @item @emph{tracepoint action for collecting static trace data} @tab @tab
35709 @item 'L' @tab 1 @tab type of tracepoint action
35710 @item @emph{tracepoint action for expression evaluation} @tab @tab
35711 @item 'X' @tab 1 @tab type of tracepoint action
35712 @item agent expression @tab length of @tab @ref{agent expression object}
35713 @item @emph{tracepoint object} @tab @tab
35714 @item number @tab 4 @tab number of tracepoint
35715 @item address @tab 8 @tab address of tracepoint inserted on
35716 @item type @tab 4 @tab type of tracepoint
35717 @item enabled @tab 1 @tab enable or disable of tracepoint
35718 @item step_count @tab 8 @tab step
35719 @item pass_count @tab 8 @tab pass
35720 @item numactions @tab 4 @tab number of tracepoint actions
35721 @item hit count @tab 8 @tab hit count
35722 @item trace frame usage @tab 8 @tab trace frame usage
35723 @item compiled_cond @tab 8 @tab compiled condition
35724 @item orig_size @tab 8 @tab orig size
35725 @item condition @tab 4 if condition is NULL otherwise length of
35726 @ref{agent expression object}
35727 @tab zero if condition is NULL, otherwise is
35728 @ref{agent expression object}
35729 @item actions @tab variable
35730 @tab numactions number of @ref{tracepoint action object}
35731 @end multitable
35732
35733 @node IPA Protocol Commands
35734 @subsection IPA Protocol Commands
35735 @cindex ipa protocol commands
35736
35737 The spaces in each command are delimiters to ease reading this commands
35738 specification. They don't exist in real commands.
35739
35740 @table @samp
35741
35742 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
35743 Installs a new fast tracepoint described by @var{tracepoint_object}
35744 (@pxref{tracepoint object}). @var{gdb_jump_pad_head}, 8-byte long, is the
35745 head of @dfn{jumppad}, which is used to jump to data collection routine
35746 in IPA finally.
35747
35748 Replies:
35749 @table @samp
35750 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
35751 @var{target_address} is address of tracepoint in the inferior.
35752 @var{gdb_jump_pad_head} is updated head of jumppad. Both of
35753 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
35754 @var{fjump} contains a sequence of instructions jump to jumppad entry.
35755 @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
35756 @item E @var{NN}
35757 for an error
35758
35759 @end table
35760
35761 @item close
35762 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
35763 is about to kill inferiors.
35764
35765 @item qTfSTM
35766 @xref{qTfSTM}.
35767 @item qTsSTM
35768 @xref{qTsSTM}.
35769 @item qTSTMat
35770 @xref{qTSTMat}.
35771 @item probe_marker_at:@var{address}
35772 Asks in-process agent to probe the marker at @var{address}.
35773
35774 Replies:
35775 @table @samp
35776 @item E @var{NN}
35777 for an error
35778 @end table
35779 @item unprobe_marker_at:@var{address}
35780 Asks in-process agent to unprobe the marker at @var{address}.
35781 @end table
35782
35783 @node GDB Bugs
35784 @chapter Reporting Bugs in @value{GDBN}
35785 @cindex bugs in @value{GDBN}
35786 @cindex reporting bugs in @value{GDBN}
35787
35788 Your bug reports play an essential role in making @value{GDBN} reliable.
35789
35790 Reporting a bug may help you by bringing a solution to your problem, or it
35791 may not. But in any case the principal function of a bug report is to help
35792 the entire community by making the next version of @value{GDBN} work better. Bug
35793 reports are your contribution to the maintenance of @value{GDBN}.
35794
35795 In order for a bug report to serve its purpose, you must include the
35796 information that enables us to fix the bug.
35797
35798 @menu
35799 * Bug Criteria:: Have you found a bug?
35800 * Bug Reporting:: How to report bugs
35801 @end menu
35802
35803 @node Bug Criteria
35804 @section Have You Found a Bug?
35805 @cindex bug criteria
35806
35807 If you are not sure whether you have found a bug, here are some guidelines:
35808
35809 @itemize @bullet
35810 @cindex fatal signal
35811 @cindex debugger crash
35812 @cindex crash of debugger
35813 @item
35814 If the debugger gets a fatal signal, for any input whatever, that is a
35815 @value{GDBN} bug. Reliable debuggers never crash.
35816
35817 @cindex error on valid input
35818 @item
35819 If @value{GDBN} produces an error message for valid input, that is a
35820 bug. (Note that if you're cross debugging, the problem may also be
35821 somewhere in the connection to the target.)
35822
35823 @cindex invalid input
35824 @item
35825 If @value{GDBN} does not produce an error message for invalid input,
35826 that is a bug. However, you should note that your idea of
35827 ``invalid input'' might be our idea of ``an extension'' or ``support
35828 for traditional practice''.
35829
35830 @item
35831 If you are an experienced user of debugging tools, your suggestions
35832 for improvement of @value{GDBN} are welcome in any case.
35833 @end itemize
35834
35835 @node Bug Reporting
35836 @section How to Report Bugs
35837 @cindex bug reports
35838 @cindex @value{GDBN} bugs, reporting
35839
35840 A number of companies and individuals offer support for @sc{gnu} products.
35841 If you obtained @value{GDBN} from a support organization, we recommend you
35842 contact that organization first.
35843
35844 You can find contact information for many support companies and
35845 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
35846 distribution.
35847 @c should add a web page ref...
35848
35849 @ifset BUGURL
35850 @ifset BUGURL_DEFAULT
35851 In any event, we also recommend that you submit bug reports for
35852 @value{GDBN}. The preferred method is to submit them directly using
35853 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
35854 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
35855 be used.
35856
35857 @strong{Do not send bug reports to @samp{info-gdb}, or to
35858 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
35859 not want to receive bug reports. Those that do have arranged to receive
35860 @samp{bug-gdb}.
35861
35862 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
35863 serves as a repeater. The mailing list and the newsgroup carry exactly
35864 the same messages. Often people think of posting bug reports to the
35865 newsgroup instead of mailing them. This appears to work, but it has one
35866 problem which can be crucial: a newsgroup posting often lacks a mail
35867 path back to the sender. Thus, if we need to ask for more information,
35868 we may be unable to reach you. For this reason, it is better to send
35869 bug reports to the mailing list.
35870 @end ifset
35871 @ifclear BUGURL_DEFAULT
35872 In any event, we also recommend that you submit bug reports for
35873 @value{GDBN} to @value{BUGURL}.
35874 @end ifclear
35875 @end ifset
35876
35877 The fundamental principle of reporting bugs usefully is this:
35878 @strong{report all the facts}. If you are not sure whether to state a
35879 fact or leave it out, state it!
35880
35881 Often people omit facts because they think they know what causes the
35882 problem and assume that some details do not matter. Thus, you might
35883 assume that the name of the variable you use in an example does not matter.
35884 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
35885 stray memory reference which happens to fetch from the location where that
35886 name is stored in memory; perhaps, if the name were different, the contents
35887 of that location would fool the debugger into doing the right thing despite
35888 the bug. Play it safe and give a specific, complete example. That is the
35889 easiest thing for you to do, and the most helpful.
35890
35891 Keep in mind that the purpose of a bug report is to enable us to fix the
35892 bug. It may be that the bug has been reported previously, but neither
35893 you nor we can know that unless your bug report is complete and
35894 self-contained.
35895
35896 Sometimes people give a few sketchy facts and ask, ``Does this ring a
35897 bell?'' Those bug reports are useless, and we urge everyone to
35898 @emph{refuse to respond to them} except to chide the sender to report
35899 bugs properly.
35900
35901 To enable us to fix the bug, you should include all these things:
35902
35903 @itemize @bullet
35904 @item
35905 The version of @value{GDBN}. @value{GDBN} announces it if you start
35906 with no arguments; you can also print it at any time using @code{show
35907 version}.
35908
35909 Without this, we will not know whether there is any point in looking for
35910 the bug in the current version of @value{GDBN}.
35911
35912 @item
35913 The type of machine you are using, and the operating system name and
35914 version number.
35915
35916 @item
35917 The details of the @value{GDBN} build-time configuration.
35918 @value{GDBN} shows these details if you invoke it with the
35919 @option{--configuration} command-line option, or if you type
35920 @code{show configuration} at @value{GDBN}'s prompt.
35921
35922 @item
35923 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
35924 ``@value{GCC}--2.8.1''.
35925
35926 @item
35927 What compiler (and its version) was used to compile the program you are
35928 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
35929 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
35930 to get this information; for other compilers, see the documentation for
35931 those compilers.
35932
35933 @item
35934 The command arguments you gave the compiler to compile your example and
35935 observe the bug. For example, did you use @samp{-O}? To guarantee
35936 you will not omit something important, list them all. A copy of the
35937 Makefile (or the output from make) is sufficient.
35938
35939 If we were to try to guess the arguments, we would probably guess wrong
35940 and then we might not encounter the bug.
35941
35942 @item
35943 A complete input script, and all necessary source files, that will
35944 reproduce the bug.
35945
35946 @item
35947 A description of what behavior you observe that you believe is
35948 incorrect. For example, ``It gets a fatal signal.''
35949
35950 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
35951 will certainly notice it. But if the bug is incorrect output, we might
35952 not notice unless it is glaringly wrong. You might as well not give us
35953 a chance to make a mistake.
35954
35955 Even if the problem you experience is a fatal signal, you should still
35956 say so explicitly. Suppose something strange is going on, such as, your
35957 copy of @value{GDBN} is out of synch, or you have encountered a bug in
35958 the C library on your system. (This has happened!) Your copy might
35959 crash and ours would not. If you told us to expect a crash, then when
35960 ours fails to crash, we would know that the bug was not happening for
35961 us. If you had not told us to expect a crash, then we would not be able
35962 to draw any conclusion from our observations.
35963
35964 @pindex script
35965 @cindex recording a session script
35966 To collect all this information, you can use a session recording program
35967 such as @command{script}, which is available on many Unix systems.
35968 Just run your @value{GDBN} session inside @command{script} and then
35969 include the @file{typescript} file with your bug report.
35970
35971 Another way to record a @value{GDBN} session is to run @value{GDBN}
35972 inside Emacs and then save the entire buffer to a file.
35973
35974 @item
35975 If you wish to suggest changes to the @value{GDBN} source, send us context
35976 diffs. If you even discuss something in the @value{GDBN} source, refer to
35977 it by context, not by line number.
35978
35979 The line numbers in our development sources will not match those in your
35980 sources. Your line numbers would convey no useful information to us.
35981
35982 @end itemize
35983
35984 Here are some things that are not necessary:
35985
35986 @itemize @bullet
35987 @item
35988 A description of the envelope of the bug.
35989
35990 Often people who encounter a bug spend a lot of time investigating
35991 which changes to the input file will make the bug go away and which
35992 changes will not affect it.
35993
35994 This is often time consuming and not very useful, because the way we
35995 will find the bug is by running a single example under the debugger
35996 with breakpoints, not by pure deduction from a series of examples.
35997 We recommend that you save your time for something else.
35998
35999 Of course, if you can find a simpler example to report @emph{instead}
36000 of the original one, that is a convenience for us. Errors in the
36001 output will be easier to spot, running under the debugger will take
36002 less time, and so on.
36003
36004 However, simplification is not vital; if you do not want to do this,
36005 report the bug anyway and send us the entire test case you used.
36006
36007 @item
36008 A patch for the bug.
36009
36010 A patch for the bug does help us if it is a good one. But do not omit
36011 the necessary information, such as the test case, on the assumption that
36012 a patch is all we need. We might see problems with your patch and decide
36013 to fix the problem another way, or we might not understand it at all.
36014
36015 Sometimes with a program as complicated as @value{GDBN} it is very hard to
36016 construct an example that will make the program follow a certain path
36017 through the code. If you do not send us the example, we will not be able
36018 to construct one, so we will not be able to verify that the bug is fixed.
36019
36020 And if we cannot understand what bug you are trying to fix, or why your
36021 patch should be an improvement, we will not install it. A test case will
36022 help us to understand.
36023
36024 @item
36025 A guess about what the bug is or what it depends on.
36026
36027 Such guesses are usually wrong. Even we cannot guess right about such
36028 things without first using the debugger to find the facts.
36029 @end itemize
36030
36031 @c The readline documentation is distributed with the readline code
36032 @c and consists of the two following files:
36033 @c rluser.texi
36034 @c hsuser.texi
36035 @c Use -I with makeinfo to point to the appropriate directory,
36036 @c environment var TEXINPUTS with TeX.
36037 @ifclear SYSTEM_READLINE
36038 @include rluser.texi
36039 @include hsuser.texi
36040 @end ifclear
36041
36042 @node In Memoriam
36043 @appendix In Memoriam
36044
36045 The @value{GDBN} project mourns the loss of the following long-time
36046 contributors:
36047
36048 @table @code
36049 @item Fred Fish
36050 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
36051 to Free Software in general. Outside of @value{GDBN}, he was known in
36052 the Amiga world for his series of Fish Disks, and the GeekGadget project.
36053
36054 @item Michael Snyder
36055 Michael was one of the Global Maintainers of the @value{GDBN} project,
36056 with contributions recorded as early as 1996, until 2011. In addition
36057 to his day to day participation, he was a large driving force behind
36058 adding Reverse Debugging to @value{GDBN}.
36059 @end table
36060
36061 Beyond their technical contributions to the project, they were also
36062 enjoyable members of the Free Software Community. We will miss them.
36063
36064 @node Formatting Documentation
36065 @appendix Formatting Documentation
36066
36067 @cindex @value{GDBN} reference card
36068 @cindex reference card
36069 The @value{GDBN} 4 release includes an already-formatted reference card, ready
36070 for printing with PostScript or Ghostscript, in the @file{gdb}
36071 subdirectory of the main source directory@footnote{In
36072 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
36073 release.}. If you can use PostScript or Ghostscript with your printer,
36074 you can print the reference card immediately with @file{refcard.ps}.
36075
36076 The release also includes the source for the reference card. You
36077 can format it, using @TeX{}, by typing:
36078
36079 @smallexample
36080 make refcard.dvi
36081 @end smallexample
36082
36083 The @value{GDBN} reference card is designed to print in @dfn{landscape}
36084 mode on US ``letter'' size paper;
36085 that is, on a sheet 11 inches wide by 8.5 inches
36086 high. You will need to specify this form of printing as an option to
36087 your @sc{dvi} output program.
36088
36089 @cindex documentation
36090
36091 All the documentation for @value{GDBN} comes as part of the machine-readable
36092 distribution. The documentation is written in Texinfo format, which is
36093 a documentation system that uses a single source file to produce both
36094 on-line information and a printed manual. You can use one of the Info
36095 formatting commands to create the on-line version of the documentation
36096 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
36097
36098 @value{GDBN} includes an already formatted copy of the on-line Info
36099 version of this manual in the @file{gdb} subdirectory. The main Info
36100 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
36101 subordinate files matching @samp{gdb.info*} in the same directory. If
36102 necessary, you can print out these files, or read them with any editor;
36103 but they are easier to read using the @code{info} subsystem in @sc{gnu}
36104 Emacs or the standalone @code{info} program, available as part of the
36105 @sc{gnu} Texinfo distribution.
36106
36107 If you want to format these Info files yourself, you need one of the
36108 Info formatting programs, such as @code{texinfo-format-buffer} or
36109 @code{makeinfo}.
36110
36111 If you have @code{makeinfo} installed, and are in the top level
36112 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
36113 version @value{GDBVN}), you can make the Info file by typing:
36114
36115 @smallexample
36116 cd gdb
36117 make gdb.info
36118 @end smallexample
36119
36120 If you want to typeset and print copies of this manual, you need @TeX{},
36121 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
36122 Texinfo definitions file.
36123
36124 @TeX{} is a typesetting program; it does not print files directly, but
36125 produces output files called @sc{dvi} files. To print a typeset
36126 document, you need a program to print @sc{dvi} files. If your system
36127 has @TeX{} installed, chances are it has such a program. The precise
36128 command to use depends on your system; @kbd{lpr -d} is common; another
36129 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
36130 require a file name without any extension or a @samp{.dvi} extension.
36131
36132 @TeX{} also requires a macro definitions file called
36133 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
36134 written in Texinfo format. On its own, @TeX{} cannot either read or
36135 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
36136 and is located in the @file{gdb-@var{version-number}/texinfo}
36137 directory.
36138
36139 If you have @TeX{} and a @sc{dvi} printer program installed, you can
36140 typeset and print this manual. First switch to the @file{gdb}
36141 subdirectory of the main source directory (for example, to
36142 @file{gdb-@value{GDBVN}/gdb}) and type:
36143
36144 @smallexample
36145 make gdb.dvi
36146 @end smallexample
36147
36148 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
36149
36150 @node Installing GDB
36151 @appendix Installing @value{GDBN}
36152 @cindex installation
36153
36154 @menu
36155 * Requirements:: Requirements for building @value{GDBN}
36156 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
36157 * Separate Objdir:: Compiling @value{GDBN} in another directory
36158 * Config Names:: Specifying names for hosts and targets
36159 * Configure Options:: Summary of options for configure
36160 * System-wide configuration:: Having a system-wide init file
36161 @end menu
36162
36163 @node Requirements
36164 @section Requirements for Building @value{GDBN}
36165 @cindex building @value{GDBN}, requirements for
36166
36167 Building @value{GDBN} requires various tools and packages to be available.
36168 Other packages will be used only if they are found.
36169
36170 @heading Tools/Packages Necessary for Building @value{GDBN}
36171 @table @asis
36172 @item ISO C90 compiler
36173 @value{GDBN} is written in ISO C90. It should be buildable with any
36174 working C90 compiler, e.g.@: GCC.
36175
36176 @end table
36177
36178 @heading Tools/Packages Optional for Building @value{GDBN}
36179 @table @asis
36180 @item Expat
36181 @anchor{Expat}
36182 @value{GDBN} can use the Expat XML parsing library. This library may be
36183 included with your operating system distribution; if it is not, you
36184 can get the latest version from @url{http://expat.sourceforge.net}.
36185 The @file{configure} script will search for this library in several
36186 standard locations; if it is installed in an unusual path, you can
36187 use the @option{--with-libexpat-prefix} option to specify its location.
36188
36189 Expat is used for:
36190
36191 @itemize @bullet
36192 @item
36193 Remote protocol memory maps (@pxref{Memory Map Format})
36194 @item
36195 Target descriptions (@pxref{Target Descriptions})
36196 @item
36197 Remote shared library lists (@xref{Library List Format},
36198 or alternatively @pxref{Library List Format for SVR4 Targets})
36199 @item
36200 MS-Windows shared libraries (@pxref{Shared Libraries})
36201 @item
36202 Traceframe info (@pxref{Traceframe Info Format})
36203 @item
36204 Branch trace (@pxref{Branch Trace Format})
36205 @end itemize
36206
36207 @item zlib
36208 @cindex compressed debug sections
36209 @value{GDBN} will use the @samp{zlib} library, if available, to read
36210 compressed debug sections. Some linkers, such as GNU gold, are capable
36211 of producing binaries with compressed debug sections. If @value{GDBN}
36212 is compiled with @samp{zlib}, it will be able to read the debug
36213 information in such binaries.
36214
36215 The @samp{zlib} library is likely included with your operating system
36216 distribution; if it is not, you can get the latest version from
36217 @url{http://zlib.net}.
36218
36219 @item iconv
36220 @value{GDBN}'s features related to character sets (@pxref{Character
36221 Sets}) require a functioning @code{iconv} implementation. If you are
36222 on a GNU system, then this is provided by the GNU C Library. Some
36223 other systems also provide a working @code{iconv}.
36224
36225 If @value{GDBN} is using the @code{iconv} program which is installed
36226 in a non-standard place, you will need to tell @value{GDBN} where to find it.
36227 This is done with @option{--with-iconv-bin} which specifies the
36228 directory that contains the @code{iconv} program.
36229
36230 On systems without @code{iconv}, you can install GNU Libiconv. If you
36231 have previously installed Libiconv, you can use the
36232 @option{--with-libiconv-prefix} option to configure.
36233
36234 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
36235 arrange to build Libiconv if a directory named @file{libiconv} appears
36236 in the top-most source directory. If Libiconv is built this way, and
36237 if the operating system does not provide a suitable @code{iconv}
36238 implementation, then the just-built library will automatically be used
36239 by @value{GDBN}. One easy way to set this up is to download GNU
36240 Libiconv, unpack it, and then rename the directory holding the
36241 Libiconv source code to @samp{libiconv}.
36242 @end table
36243
36244 @node Running Configure
36245 @section Invoking the @value{GDBN} @file{configure} Script
36246 @cindex configuring @value{GDBN}
36247 @value{GDBN} comes with a @file{configure} script that automates the process
36248 of preparing @value{GDBN} for installation; you can then use @code{make} to
36249 build the @code{gdb} program.
36250 @iftex
36251 @c irrelevant in info file; it's as current as the code it lives with.
36252 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
36253 look at the @file{README} file in the sources; we may have improved the
36254 installation procedures since publishing this manual.}
36255 @end iftex
36256
36257 The @value{GDBN} distribution includes all the source code you need for
36258 @value{GDBN} in a single directory, whose name is usually composed by
36259 appending the version number to @samp{gdb}.
36260
36261 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
36262 @file{gdb-@value{GDBVN}} directory. That directory contains:
36263
36264 @table @code
36265 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
36266 script for configuring @value{GDBN} and all its supporting libraries
36267
36268 @item gdb-@value{GDBVN}/gdb
36269 the source specific to @value{GDBN} itself
36270
36271 @item gdb-@value{GDBVN}/bfd
36272 source for the Binary File Descriptor library
36273
36274 @item gdb-@value{GDBVN}/include
36275 @sc{gnu} include files
36276
36277 @item gdb-@value{GDBVN}/libiberty
36278 source for the @samp{-liberty} free software library
36279
36280 @item gdb-@value{GDBVN}/opcodes
36281 source for the library of opcode tables and disassemblers
36282
36283 @item gdb-@value{GDBVN}/readline
36284 source for the @sc{gnu} command-line interface
36285
36286 @item gdb-@value{GDBVN}/glob
36287 source for the @sc{gnu} filename pattern-matching subroutine
36288
36289 @item gdb-@value{GDBVN}/mmalloc
36290 source for the @sc{gnu} memory-mapped malloc package
36291 @end table
36292
36293 The simplest way to configure and build @value{GDBN} is to run @file{configure}
36294 from the @file{gdb-@var{version-number}} source directory, which in
36295 this example is the @file{gdb-@value{GDBVN}} directory.
36296
36297 First switch to the @file{gdb-@var{version-number}} source directory
36298 if you are not already in it; then run @file{configure}. Pass the
36299 identifier for the platform on which @value{GDBN} will run as an
36300 argument.
36301
36302 For example:
36303
36304 @smallexample
36305 cd gdb-@value{GDBVN}
36306 ./configure @var{host}
36307 make
36308 @end smallexample
36309
36310 @noindent
36311 where @var{host} is an identifier such as @samp{sun4} or
36312 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
36313 (You can often leave off @var{host}; @file{configure} tries to guess the
36314 correct value by examining your system.)
36315
36316 Running @samp{configure @var{host}} and then running @code{make} builds the
36317 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
36318 libraries, then @code{gdb} itself. The configured source files, and the
36319 binaries, are left in the corresponding source directories.
36320
36321 @need 750
36322 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
36323 system does not recognize this automatically when you run a different
36324 shell, you may need to run @code{sh} on it explicitly:
36325
36326 @smallexample
36327 sh configure @var{host}
36328 @end smallexample
36329
36330 If you run @file{configure} from a directory that contains source
36331 directories for multiple libraries or programs, such as the
36332 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
36333 @file{configure}
36334 creates configuration files for every directory level underneath (unless
36335 you tell it not to, with the @samp{--norecursion} option).
36336
36337 You should run the @file{configure} script from the top directory in the
36338 source tree, the @file{gdb-@var{version-number}} directory. If you run
36339 @file{configure} from one of the subdirectories, you will configure only
36340 that subdirectory. That is usually not what you want. In particular,
36341 if you run the first @file{configure} from the @file{gdb} subdirectory
36342 of the @file{gdb-@var{version-number}} directory, you will omit the
36343 configuration of @file{bfd}, @file{readline}, and other sibling
36344 directories of the @file{gdb} subdirectory. This leads to build errors
36345 about missing include files such as @file{bfd/bfd.h}.
36346
36347 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
36348 However, you should make sure that the shell on your path (named by
36349 the @samp{SHELL} environment variable) is publicly readable. Remember
36350 that @value{GDBN} uses the shell to start your program---some systems refuse to
36351 let @value{GDBN} debug child processes whose programs are not readable.
36352
36353 @node Separate Objdir
36354 @section Compiling @value{GDBN} in Another Directory
36355
36356 If you want to run @value{GDBN} versions for several host or target machines,
36357 you need a different @code{gdb} compiled for each combination of
36358 host and target. @file{configure} is designed to make this easy by
36359 allowing you to generate each configuration in a separate subdirectory,
36360 rather than in the source directory. If your @code{make} program
36361 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
36362 @code{make} in each of these directories builds the @code{gdb}
36363 program specified there.
36364
36365 To build @code{gdb} in a separate directory, run @file{configure}
36366 with the @samp{--srcdir} option to specify where to find the source.
36367 (You also need to specify a path to find @file{configure}
36368 itself from your working directory. If the path to @file{configure}
36369 would be the same as the argument to @samp{--srcdir}, you can leave out
36370 the @samp{--srcdir} option; it is assumed.)
36371
36372 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
36373 separate directory for a Sun 4 like this:
36374
36375 @smallexample
36376 @group
36377 cd gdb-@value{GDBVN}
36378 mkdir ../gdb-sun4
36379 cd ../gdb-sun4
36380 ../gdb-@value{GDBVN}/configure sun4
36381 make
36382 @end group
36383 @end smallexample
36384
36385 When @file{configure} builds a configuration using a remote source
36386 directory, it creates a tree for the binaries with the same structure
36387 (and using the same names) as the tree under the source directory. In
36388 the example, you'd find the Sun 4 library @file{libiberty.a} in the
36389 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
36390 @file{gdb-sun4/gdb}.
36391
36392 Make sure that your path to the @file{configure} script has just one
36393 instance of @file{gdb} in it. If your path to @file{configure} looks
36394 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
36395 one subdirectory of @value{GDBN}, not the whole package. This leads to
36396 build errors about missing include files such as @file{bfd/bfd.h}.
36397
36398 One popular reason to build several @value{GDBN} configurations in separate
36399 directories is to configure @value{GDBN} for cross-compiling (where
36400 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
36401 programs that run on another machine---the @dfn{target}).
36402 You specify a cross-debugging target by
36403 giving the @samp{--target=@var{target}} option to @file{configure}.
36404
36405 When you run @code{make} to build a program or library, you must run
36406 it in a configured directory---whatever directory you were in when you
36407 called @file{configure} (or one of its subdirectories).
36408
36409 The @code{Makefile} that @file{configure} generates in each source
36410 directory also runs recursively. If you type @code{make} in a source
36411 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
36412 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
36413 will build all the required libraries, and then build GDB.
36414
36415 When you have multiple hosts or targets configured in separate
36416 directories, you can run @code{make} on them in parallel (for example,
36417 if they are NFS-mounted on each of the hosts); they will not interfere
36418 with each other.
36419
36420 @node Config Names
36421 @section Specifying Names for Hosts and Targets
36422
36423 The specifications used for hosts and targets in the @file{configure}
36424 script are based on a three-part naming scheme, but some short predefined
36425 aliases are also supported. The full naming scheme encodes three pieces
36426 of information in the following pattern:
36427
36428 @smallexample
36429 @var{architecture}-@var{vendor}-@var{os}
36430 @end smallexample
36431
36432 For example, you can use the alias @code{sun4} as a @var{host} argument,
36433 or as the value for @var{target} in a @code{--target=@var{target}}
36434 option. The equivalent full name is @samp{sparc-sun-sunos4}.
36435
36436 The @file{configure} script accompanying @value{GDBN} does not provide
36437 any query facility to list all supported host and target names or
36438 aliases. @file{configure} calls the Bourne shell script
36439 @code{config.sub} to map abbreviations to full names; you can read the
36440 script, if you wish, or you can use it to test your guesses on
36441 abbreviations---for example:
36442
36443 @smallexample
36444 % sh config.sub i386-linux
36445 i386-pc-linux-gnu
36446 % sh config.sub alpha-linux
36447 alpha-unknown-linux-gnu
36448 % sh config.sub hp9k700
36449 hppa1.1-hp-hpux
36450 % sh config.sub sun4
36451 sparc-sun-sunos4.1.1
36452 % sh config.sub sun3
36453 m68k-sun-sunos4.1.1
36454 % sh config.sub i986v
36455 Invalid configuration `i986v': machine `i986v' not recognized
36456 @end smallexample
36457
36458 @noindent
36459 @code{config.sub} is also distributed in the @value{GDBN} source
36460 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
36461
36462 @node Configure Options
36463 @section @file{configure} Options
36464
36465 Here is a summary of the @file{configure} options and arguments that
36466 are most often useful for building @value{GDBN}. @file{configure} also has
36467 several other options not listed here. @inforef{What Configure
36468 Does,,configure.info}, for a full explanation of @file{configure}.
36469
36470 @smallexample
36471 configure @r{[}--help@r{]}
36472 @r{[}--prefix=@var{dir}@r{]}
36473 @r{[}--exec-prefix=@var{dir}@r{]}
36474 @r{[}--srcdir=@var{dirname}@r{]}
36475 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
36476 @r{[}--target=@var{target}@r{]}
36477 @var{host}
36478 @end smallexample
36479
36480 @noindent
36481 You may introduce options with a single @samp{-} rather than
36482 @samp{--} if you prefer; but you may abbreviate option names if you use
36483 @samp{--}.
36484
36485 @table @code
36486 @item --help
36487 Display a quick summary of how to invoke @file{configure}.
36488
36489 @item --prefix=@var{dir}
36490 Configure the source to install programs and files under directory
36491 @file{@var{dir}}.
36492
36493 @item --exec-prefix=@var{dir}
36494 Configure the source to install programs under directory
36495 @file{@var{dir}}.
36496
36497 @c avoid splitting the warning from the explanation:
36498 @need 2000
36499 @item --srcdir=@var{dirname}
36500 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
36501 @code{make} that implements the @code{VPATH} feature.}@*
36502 Use this option to make configurations in directories separate from the
36503 @value{GDBN} source directories. Among other things, you can use this to
36504 build (or maintain) several configurations simultaneously, in separate
36505 directories. @file{configure} writes configuration-specific files in
36506 the current directory, but arranges for them to use the source in the
36507 directory @var{dirname}. @file{configure} creates directories under
36508 the working directory in parallel to the source directories below
36509 @var{dirname}.
36510
36511 @item --norecursion
36512 Configure only the directory level where @file{configure} is executed; do not
36513 propagate configuration to subdirectories.
36514
36515 @item --target=@var{target}
36516 Configure @value{GDBN} for cross-debugging programs running on the specified
36517 @var{target}. Without this option, @value{GDBN} is configured to debug
36518 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
36519
36520 There is no convenient way to generate a list of all available targets.
36521
36522 @item @var{host} @dots{}
36523 Configure @value{GDBN} to run on the specified @var{host}.
36524
36525 There is no convenient way to generate a list of all available hosts.
36526 @end table
36527
36528 There are many other options available as well, but they are generally
36529 needed for special purposes only.
36530
36531 @node System-wide configuration
36532 @section System-wide configuration and settings
36533 @cindex system-wide init file
36534
36535 @value{GDBN} can be configured to have a system-wide init file;
36536 this file will be read and executed at startup (@pxref{Startup, , What
36537 @value{GDBN} does during startup}).
36538
36539 Here is the corresponding configure option:
36540
36541 @table @code
36542 @item --with-system-gdbinit=@var{file}
36543 Specify that the default location of the system-wide init file is
36544 @var{file}.
36545 @end table
36546
36547 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
36548 it may be subject to relocation. Two possible cases:
36549
36550 @itemize @bullet
36551 @item
36552 If the default location of this init file contains @file{$prefix},
36553 it will be subject to relocation. Suppose that the configure options
36554 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
36555 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
36556 init file is looked for as @file{$install/etc/gdbinit} instead of
36557 @file{$prefix/etc/gdbinit}.
36558
36559 @item
36560 By contrast, if the default location does not contain the prefix,
36561 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
36562 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
36563 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
36564 wherever @value{GDBN} is installed.
36565 @end itemize
36566
36567 If the configured location of the system-wide init file (as given by the
36568 @option{--with-system-gdbinit} option at configure time) is in the
36569 data-directory (as specified by @option{--with-gdb-datadir} at configure
36570 time) or in one of its subdirectories, then @value{GDBN} will look for the
36571 system-wide init file in the directory specified by the
36572 @option{--data-directory} command-line option.
36573 Note that the system-wide init file is only read once, during @value{GDBN}
36574 initialization. If the data-directory is changed after @value{GDBN} has
36575 started with the @code{set data-directory} command, the file will not be
36576 reread.
36577
36578 @menu
36579 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
36580 @end menu
36581
36582 @node System-wide Configuration Scripts
36583 @subsection Installed System-wide Configuration Scripts
36584 @cindex system-wide configuration scripts
36585
36586 The @file{system-gdbinit} directory, located inside the data-directory
36587 (as specified by @option{--with-gdb-datadir} at configure time) contains
36588 a number of scripts which can be used as system-wide init files. To
36589 automatically source those scripts at startup, @value{GDBN} should be
36590 configured with @option{--with-system-gdbinit}. Otherwise, any user
36591 should be able to source them by hand as needed.
36592
36593 The following scripts are currently available:
36594 @itemize @bullet
36595
36596 @item @file{elinos.py}
36597 @pindex elinos.py
36598 @cindex ELinOS system-wide configuration script
36599 This script is useful when debugging a program on an ELinOS target.
36600 It takes advantage of the environment variables defined in a standard
36601 ELinOS environment in order to determine the location of the system
36602 shared libraries, and then sets the @samp{solib-absolute-prefix}
36603 and @samp{solib-search-path} variables appropriately.
36604
36605 @item @file{wrs-linux.py}
36606 @pindex wrs-linux.py
36607 @cindex Wind River Linux system-wide configuration script
36608 This script is useful when debugging a program on a target running
36609 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
36610 the host-side sysroot used by the target system.
36611
36612 @end itemize
36613
36614 @node Maintenance Commands
36615 @appendix Maintenance Commands
36616 @cindex maintenance commands
36617 @cindex internal commands
36618
36619 In addition to commands intended for @value{GDBN} users, @value{GDBN}
36620 includes a number of commands intended for @value{GDBN} developers,
36621 that are not documented elsewhere in this manual. These commands are
36622 provided here for reference. (For commands that turn on debugging
36623 messages, see @ref{Debugging Output}.)
36624
36625 @table @code
36626 @kindex maint agent
36627 @kindex maint agent-eval
36628 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
36629 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
36630 Translate the given @var{expression} into remote agent bytecodes.
36631 This command is useful for debugging the Agent Expression mechanism
36632 (@pxref{Agent Expressions}). The @samp{agent} version produces an
36633 expression useful for data collection, such as by tracepoints, while
36634 @samp{maint agent-eval} produces an expression that evaluates directly
36635 to a result. For instance, a collection expression for @code{globa +
36636 globb} will include bytecodes to record four bytes of memory at each
36637 of the addresses of @code{globa} and @code{globb}, while discarding
36638 the result of the addition, while an evaluation expression will do the
36639 addition and return the sum.
36640 If @code{-at} is given, generate remote agent bytecode for @var{location}.
36641 If not, generate remote agent bytecode for current frame PC address.
36642
36643 @kindex maint agent-printf
36644 @item maint agent-printf @var{format},@var{expr},...
36645 Translate the given format string and list of argument expressions
36646 into remote agent bytecodes and display them as a disassembled list.
36647 This command is useful for debugging the agent version of dynamic
36648 printf (@pxref{Dynamic Printf}).
36649
36650 @kindex maint info breakpoints
36651 @item @anchor{maint info breakpoints}maint info breakpoints
36652 Using the same format as @samp{info breakpoints}, display both the
36653 breakpoints you've set explicitly, and those @value{GDBN} is using for
36654 internal purposes. Internal breakpoints are shown with negative
36655 breakpoint numbers. The type column identifies what kind of breakpoint
36656 is shown:
36657
36658 @table @code
36659 @item breakpoint
36660 Normal, explicitly set breakpoint.
36661
36662 @item watchpoint
36663 Normal, explicitly set watchpoint.
36664
36665 @item longjmp
36666 Internal breakpoint, used to handle correctly stepping through
36667 @code{longjmp} calls.
36668
36669 @item longjmp resume
36670 Internal breakpoint at the target of a @code{longjmp}.
36671
36672 @item until
36673 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
36674
36675 @item finish
36676 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
36677
36678 @item shlib events
36679 Shared library events.
36680
36681 @end table
36682
36683 @kindex maint info bfds
36684 @item maint info bfds
36685 This prints information about each @code{bfd} object that is known to
36686 @value{GDBN}. @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
36687
36688 @kindex set displaced-stepping
36689 @kindex show displaced-stepping
36690 @cindex displaced stepping support
36691 @cindex out-of-line single-stepping
36692 @item set displaced-stepping
36693 @itemx show displaced-stepping
36694 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
36695 if the target supports it. Displaced stepping is a way to single-step
36696 over breakpoints without removing them from the inferior, by executing
36697 an out-of-line copy of the instruction that was originally at the
36698 breakpoint location. It is also known as out-of-line single-stepping.
36699
36700 @table @code
36701 @item set displaced-stepping on
36702 If the target architecture supports it, @value{GDBN} will use
36703 displaced stepping to step over breakpoints.
36704
36705 @item set displaced-stepping off
36706 @value{GDBN} will not use displaced stepping to step over breakpoints,
36707 even if such is supported by the target architecture.
36708
36709 @cindex non-stop mode, and @samp{set displaced-stepping}
36710 @item set displaced-stepping auto
36711 This is the default mode. @value{GDBN} will use displaced stepping
36712 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
36713 architecture supports displaced stepping.
36714 @end table
36715
36716 @kindex maint check-psymtabs
36717 @item maint check-psymtabs
36718 Check the consistency of currently expanded psymtabs versus symtabs.
36719 Use this to check, for example, whether a symbol is in one but not the other.
36720
36721 @kindex maint check-symtabs
36722 @item maint check-symtabs
36723 Check the consistency of currently expanded symtabs.
36724
36725 @kindex maint expand-symtabs
36726 @item maint expand-symtabs [@var{regexp}]
36727 Expand symbol tables.
36728 If @var{regexp} is specified, only expand symbol tables for file
36729 names matching @var{regexp}.
36730
36731 @kindex maint cplus first_component
36732 @item maint cplus first_component @var{name}
36733 Print the first C@t{++} class/namespace component of @var{name}.
36734
36735 @kindex maint cplus namespace
36736 @item maint cplus namespace
36737 Print the list of possible C@t{++} namespaces.
36738
36739 @kindex maint demangle
36740 @item maint demangle @var{name}
36741 Demangle a C@t{++} or Objective-C mangled @var{name}.
36742
36743 @kindex maint deprecate
36744 @kindex maint undeprecate
36745 @cindex deprecated commands
36746 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
36747 @itemx maint undeprecate @var{command}
36748 Deprecate or undeprecate the named @var{command}. Deprecated commands
36749 cause @value{GDBN} to issue a warning when you use them. The optional
36750 argument @var{replacement} says which newer command should be used in
36751 favor of the deprecated one; if it is given, @value{GDBN} will mention
36752 the replacement as part of the warning.
36753
36754 @kindex maint dump-me
36755 @item maint dump-me
36756 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
36757 Cause a fatal signal in the debugger and force it to dump its core.
36758 This is supported only on systems which support aborting a program
36759 with the @code{SIGQUIT} signal.
36760
36761 @kindex maint internal-error
36762 @kindex maint internal-warning
36763 @item maint internal-error @r{[}@var{message-text}@r{]}
36764 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
36765 Cause @value{GDBN} to call the internal function @code{internal_error}
36766 or @code{internal_warning} and hence behave as though an internal error
36767 or internal warning has been detected. In addition to reporting the
36768 internal problem, these functions give the user the opportunity to
36769 either quit @value{GDBN} or create a core file of the current
36770 @value{GDBN} session.
36771
36772 These commands take an optional parameter @var{message-text} that is
36773 used as the text of the error or warning message.
36774
36775 Here's an example of using @code{internal-error}:
36776
36777 @smallexample
36778 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
36779 @dots{}/maint.c:121: internal-error: testing, 1, 2
36780 A problem internal to GDB has been detected. Further
36781 debugging may prove unreliable.
36782 Quit this debugging session? (y or n) @kbd{n}
36783 Create a core file? (y or n) @kbd{n}
36784 (@value{GDBP})
36785 @end smallexample
36786
36787 @cindex @value{GDBN} internal error
36788 @cindex internal errors, control of @value{GDBN} behavior
36789
36790 @kindex maint set internal-error
36791 @kindex maint show internal-error
36792 @kindex maint set internal-warning
36793 @kindex maint show internal-warning
36794 @item maint set internal-error @var{action} [ask|yes|no]
36795 @itemx maint show internal-error @var{action}
36796 @itemx maint set internal-warning @var{action} [ask|yes|no]
36797 @itemx maint show internal-warning @var{action}
36798 When @value{GDBN} reports an internal problem (error or warning) it
36799 gives the user the opportunity to both quit @value{GDBN} and create a
36800 core file of the current @value{GDBN} session. These commands let you
36801 override the default behaviour for each particular @var{action},
36802 described in the table below.
36803
36804 @table @samp
36805 @item quit
36806 You can specify that @value{GDBN} should always (yes) or never (no)
36807 quit. The default is to ask the user what to do.
36808
36809 @item corefile
36810 You can specify that @value{GDBN} should always (yes) or never (no)
36811 create a core file. The default is to ask the user what to do.
36812 @end table
36813
36814 @kindex maint packet
36815 @item maint packet @var{text}
36816 If @value{GDBN} is talking to an inferior via the serial protocol,
36817 then this command sends the string @var{text} to the inferior, and
36818 displays the response packet. @value{GDBN} supplies the initial
36819 @samp{$} character, the terminating @samp{#} character, and the
36820 checksum.
36821
36822 @kindex maint print architecture
36823 @item maint print architecture @r{[}@var{file}@r{]}
36824 Print the entire architecture configuration. The optional argument
36825 @var{file} names the file where the output goes.
36826
36827 @kindex maint print c-tdesc
36828 @item maint print c-tdesc
36829 Print the current target description (@pxref{Target Descriptions}) as
36830 a C source file. The created source file can be used in @value{GDBN}
36831 when an XML parser is not available to parse the description.
36832
36833 @kindex maint print dummy-frames
36834 @item maint print dummy-frames
36835 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
36836
36837 @smallexample
36838 (@value{GDBP}) @kbd{b add}
36839 @dots{}
36840 (@value{GDBP}) @kbd{print add(2,3)}
36841 Breakpoint 2, add (a=2, b=3) at @dots{}
36842 58 return (a + b);
36843 The program being debugged stopped while in a function called from GDB.
36844 @dots{}
36845 (@value{GDBP}) @kbd{maint print dummy-frames}
36846 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
36847 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
36848 call_lo=0x01014000 call_hi=0x01014001
36849 (@value{GDBP})
36850 @end smallexample
36851
36852 Takes an optional file parameter.
36853
36854 @kindex maint print registers
36855 @kindex maint print raw-registers
36856 @kindex maint print cooked-registers
36857 @kindex maint print register-groups
36858 @kindex maint print remote-registers
36859 @item maint print registers @r{[}@var{file}@r{]}
36860 @itemx maint print raw-registers @r{[}@var{file}@r{]}
36861 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
36862 @itemx maint print register-groups @r{[}@var{file}@r{]}
36863 @itemx maint print remote-registers @r{[}@var{file}@r{]}
36864 Print @value{GDBN}'s internal register data structures.
36865
36866 The command @code{maint print raw-registers} includes the contents of
36867 the raw register cache; the command @code{maint print
36868 cooked-registers} includes the (cooked) value of all registers,
36869 including registers which aren't available on the target nor visible
36870 to user; the command @code{maint print register-groups} includes the
36871 groups that each register is a member of; and the command @code{maint
36872 print remote-registers} includes the remote target's register numbers
36873 and offsets in the `G' packets. @xref{Registers,, Registers, gdbint,
36874 @value{GDBN} Internals}.
36875
36876 These commands take an optional parameter, a file name to which to
36877 write the information.
36878
36879 @kindex maint print reggroups
36880 @item maint print reggroups @r{[}@var{file}@r{]}
36881 Print @value{GDBN}'s internal register group data structures. The
36882 optional argument @var{file} tells to what file to write the
36883 information.
36884
36885 The register groups info looks like this:
36886
36887 @smallexample
36888 (@value{GDBP}) @kbd{maint print reggroups}
36889 Group Type
36890 general user
36891 float user
36892 all user
36893 vector user
36894 system user
36895 save internal
36896 restore internal
36897 @end smallexample
36898
36899 @kindex flushregs
36900 @item flushregs
36901 This command forces @value{GDBN} to flush its internal register cache.
36902
36903 @kindex maint print objfiles
36904 @cindex info for known object files
36905 @item maint print objfiles @r{[}@var{regexp}@r{]}
36906 Print a dump of all known object files.
36907 If @var{regexp} is specified, only print object files whose names
36908 match @var{regexp}. For each object file, this command prints its name,
36909 address in memory, and all of its psymtabs and symtabs.
36910
36911 @kindex maint print section-scripts
36912 @cindex info for known .debug_gdb_scripts-loaded scripts
36913 @item maint print section-scripts [@var{regexp}]
36914 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
36915 If @var{regexp} is specified, only print scripts loaded by object files
36916 matching @var{regexp}.
36917 For each script, this command prints its name as specified in the objfile,
36918 and the full path if known.
36919 @xref{dotdebug_gdb_scripts section}.
36920
36921 @kindex maint print statistics
36922 @cindex bcache statistics
36923 @item maint print statistics
36924 This command prints, for each object file in the program, various data
36925 about that object file followed by the byte cache (@dfn{bcache})
36926 statistics for the object file. The objfile data includes the number
36927 of minimal, partial, full, and stabs symbols, the number of types
36928 defined by the objfile, the number of as yet unexpanded psym tables,
36929 the number of line tables and string tables, and the amount of memory
36930 used by the various tables. The bcache statistics include the counts,
36931 sizes, and counts of duplicates of all and unique objects, max,
36932 average, and median entry size, total memory used and its overhead and
36933 savings, and various measures of the hash table size and chain
36934 lengths.
36935
36936 @kindex maint print target-stack
36937 @cindex target stack description
36938 @item maint print target-stack
36939 A @dfn{target} is an interface between the debugger and a particular
36940 kind of file or process. Targets can be stacked in @dfn{strata},
36941 so that more than one target can potentially respond to a request.
36942 In particular, memory accesses will walk down the stack of targets
36943 until they find a target that is interested in handling that particular
36944 address.
36945
36946 This command prints a short description of each layer that was pushed on
36947 the @dfn{target stack}, starting from the top layer down to the bottom one.
36948
36949 @kindex maint print type
36950 @cindex type chain of a data type
36951 @item maint print type @var{expr}
36952 Print the type chain for a type specified by @var{expr}. The argument
36953 can be either a type name or a symbol. If it is a symbol, the type of
36954 that symbol is described. The type chain produced by this command is
36955 a recursive definition of the data type as stored in @value{GDBN}'s
36956 data structures, including its flags and contained types.
36957
36958 @kindex maint set dwarf2 always-disassemble
36959 @kindex maint show dwarf2 always-disassemble
36960 @item maint set dwarf2 always-disassemble
36961 @item maint show dwarf2 always-disassemble
36962 Control the behavior of @code{info address} when using DWARF debugging
36963 information.
36964
36965 The default is @code{off}, which means that @value{GDBN} should try to
36966 describe a variable's location in an easily readable format. When
36967 @code{on}, @value{GDBN} will instead display the DWARF location
36968 expression in an assembly-like format. Note that some locations are
36969 too complex for @value{GDBN} to describe simply; in this case you will
36970 always see the disassembly form.
36971
36972 Here is an example of the resulting disassembly:
36973
36974 @smallexample
36975 (gdb) info addr argc
36976 Symbol "argc" is a complex DWARF expression:
36977 1: DW_OP_fbreg 0
36978 @end smallexample
36979
36980 For more information on these expressions, see
36981 @uref{http://www.dwarfstd.org/, the DWARF standard}.
36982
36983 @kindex maint set dwarf2 max-cache-age
36984 @kindex maint show dwarf2 max-cache-age
36985 @item maint set dwarf2 max-cache-age
36986 @itemx maint show dwarf2 max-cache-age
36987 Control the DWARF 2 compilation unit cache.
36988
36989 @cindex DWARF 2 compilation units cache
36990 In object files with inter-compilation-unit references, such as those
36991 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
36992 reader needs to frequently refer to previously read compilation units.
36993 This setting controls how long a compilation unit will remain in the
36994 cache if it is not referenced. A higher limit means that cached
36995 compilation units will be stored in memory longer, and more total
36996 memory will be used. Setting it to zero disables caching, which will
36997 slow down @value{GDBN} startup, but reduce memory consumption.
36998
36999 @kindex maint set profile
37000 @kindex maint show profile
37001 @cindex profiling GDB
37002 @item maint set profile
37003 @itemx maint show profile
37004 Control profiling of @value{GDBN}.
37005
37006 Profiling will be disabled until you use the @samp{maint set profile}
37007 command to enable it. When you enable profiling, the system will begin
37008 collecting timing and execution count data; when you disable profiling or
37009 exit @value{GDBN}, the results will be written to a log file. Remember that
37010 if you use profiling, @value{GDBN} will overwrite the profiling log file
37011 (often called @file{gmon.out}). If you have a record of important profiling
37012 data in a @file{gmon.out} file, be sure to move it to a safe location.
37013
37014 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
37015 compiled with the @samp{-pg} compiler option.
37016
37017 @kindex maint set show-debug-regs
37018 @kindex maint show show-debug-regs
37019 @cindex hardware debug registers
37020 @item maint set show-debug-regs
37021 @itemx maint show show-debug-regs
37022 Control whether to show variables that mirror the hardware debug
37023 registers. Use @code{ON} to enable, @code{OFF} to disable. If
37024 enabled, the debug registers values are shown when @value{GDBN} inserts or
37025 removes a hardware breakpoint or watchpoint, and when the inferior
37026 triggers a hardware-assisted breakpoint or watchpoint.
37027
37028 @kindex maint set show-all-tib
37029 @kindex maint show show-all-tib
37030 @item maint set show-all-tib
37031 @itemx maint show show-all-tib
37032 Control whether to show all non zero areas within a 1k block starting
37033 at thread local base, when using the @samp{info w32 thread-information-block}
37034 command.
37035
37036 @kindex maint set per-command
37037 @kindex maint show per-command
37038 @item maint set per-command
37039 @itemx maint show per-command
37040 @cindex resources used by commands
37041
37042 @value{GDBN} can display the resources used by each command.
37043 This is useful in debugging performance problems.
37044
37045 @table @code
37046 @item maint set per-command space [on|off]
37047 @itemx maint show per-command space
37048 Enable or disable the printing of the memory used by GDB for each command.
37049 If enabled, @value{GDBN} will display how much memory each command
37050 took, following the command's own output.
37051 This can also be requested by invoking @value{GDBN} with the
37052 @option{--statistics} command-line switch (@pxref{Mode Options}).
37053
37054 @item maint set per-command time [on|off]
37055 @itemx maint show per-command time
37056 Enable or disable the printing of the execution time of @value{GDBN}
37057 for each command.
37058 If enabled, @value{GDBN} will display how much time it
37059 took to execute each command, following the command's own output.
37060 Both CPU time and wallclock time are printed.
37061 Printing both is useful when trying to determine whether the cost is
37062 CPU or, e.g., disk/network latency.
37063 Note that the CPU time printed is for @value{GDBN} only, it does not include
37064 the execution time of the inferior because there's no mechanism currently
37065 to compute how much time was spent by @value{GDBN} and how much time was
37066 spent by the program been debugged.
37067 This can also be requested by invoking @value{GDBN} with the
37068 @option{--statistics} command-line switch (@pxref{Mode Options}).
37069
37070 @item maint set per-command symtab [on|off]
37071 @itemx maint show per-command symtab
37072 Enable or disable the printing of basic symbol table statistics
37073 for each command.
37074 If enabled, @value{GDBN} will display the following information:
37075
37076 @enumerate a
37077 @item
37078 number of symbol tables
37079 @item
37080 number of primary symbol tables
37081 @item
37082 number of blocks in the blockvector
37083 @end enumerate
37084 @end table
37085
37086 @kindex maint space
37087 @cindex memory used by commands
37088 @item maint space @var{value}
37089 An alias for @code{maint set per-command space}.
37090 A non-zero value enables it, zero disables it.
37091
37092 @kindex maint time
37093 @cindex time of command execution
37094 @item maint time @var{value}
37095 An alias for @code{maint set per-command time}.
37096 A non-zero value enables it, zero disables it.
37097
37098 @kindex maint translate-address
37099 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
37100 Find the symbol stored at the location specified by the address
37101 @var{addr} and an optional section name @var{section}. If found,
37102 @value{GDBN} prints the name of the closest symbol and an offset from
37103 the symbol's location to the specified address. This is similar to
37104 the @code{info address} command (@pxref{Symbols}), except that this
37105 command also allows to find symbols in other sections.
37106
37107 If section was not specified, the section in which the symbol was found
37108 is also printed. For dynamically linked executables, the name of
37109 executable or shared library containing the symbol is printed as well.
37110
37111 @end table
37112
37113 The following command is useful for non-interactive invocations of
37114 @value{GDBN}, such as in the test suite.
37115
37116 @table @code
37117 @item set watchdog @var{nsec}
37118 @kindex set watchdog
37119 @cindex watchdog timer
37120 @cindex timeout for commands
37121 Set the maximum number of seconds @value{GDBN} will wait for the
37122 target operation to finish. If this time expires, @value{GDBN}
37123 reports and error and the command is aborted.
37124
37125 @item show watchdog
37126 Show the current setting of the target wait timeout.
37127 @end table
37128
37129 @node Remote Protocol
37130 @appendix @value{GDBN} Remote Serial Protocol
37131
37132 @menu
37133 * Overview::
37134 * Packets::
37135 * Stop Reply Packets::
37136 * General Query Packets::
37137 * Architecture-Specific Protocol Details::
37138 * Tracepoint Packets::
37139 * Host I/O Packets::
37140 * Interrupts::
37141 * Notification Packets::
37142 * Remote Non-Stop::
37143 * Packet Acknowledgment::
37144 * Examples::
37145 * File-I/O Remote Protocol Extension::
37146 * Library List Format::
37147 * Library List Format for SVR4 Targets::
37148 * Memory Map Format::
37149 * Thread List Format::
37150 * Traceframe Info Format::
37151 * Branch Trace Format::
37152 @end menu
37153
37154 @node Overview
37155 @section Overview
37156
37157 There may be occasions when you need to know something about the
37158 protocol---for example, if there is only one serial port to your target
37159 machine, you might want your program to do something special if it
37160 recognizes a packet meant for @value{GDBN}.
37161
37162 In the examples below, @samp{->} and @samp{<-} are used to indicate
37163 transmitted and received data, respectively.
37164
37165 @cindex protocol, @value{GDBN} remote serial
37166 @cindex serial protocol, @value{GDBN} remote
37167 @cindex remote serial protocol
37168 All @value{GDBN} commands and responses (other than acknowledgments
37169 and notifications, see @ref{Notification Packets}) are sent as a
37170 @var{packet}. A @var{packet} is introduced with the character
37171 @samp{$}, the actual @var{packet-data}, and the terminating character
37172 @samp{#} followed by a two-digit @var{checksum}:
37173
37174 @smallexample
37175 @code{$}@var{packet-data}@code{#}@var{checksum}
37176 @end smallexample
37177 @noindent
37178
37179 @cindex checksum, for @value{GDBN} remote
37180 @noindent
37181 The two-digit @var{checksum} is computed as the modulo 256 sum of all
37182 characters between the leading @samp{$} and the trailing @samp{#} (an
37183 eight bit unsigned checksum).
37184
37185 Implementors should note that prior to @value{GDBN} 5.0 the protocol
37186 specification also included an optional two-digit @var{sequence-id}:
37187
37188 @smallexample
37189 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
37190 @end smallexample
37191
37192 @cindex sequence-id, for @value{GDBN} remote
37193 @noindent
37194 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
37195 has never output @var{sequence-id}s. Stubs that handle packets added
37196 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
37197
37198 When either the host or the target machine receives a packet, the first
37199 response expected is an acknowledgment: either @samp{+} (to indicate
37200 the package was received correctly) or @samp{-} (to request
37201 retransmission):
37202
37203 @smallexample
37204 -> @code{$}@var{packet-data}@code{#}@var{checksum}
37205 <- @code{+}
37206 @end smallexample
37207 @noindent
37208
37209 The @samp{+}/@samp{-} acknowledgments can be disabled
37210 once a connection is established.
37211 @xref{Packet Acknowledgment}, for details.
37212
37213 The host (@value{GDBN}) sends @var{command}s, and the target (the
37214 debugging stub incorporated in your program) sends a @var{response}. In
37215 the case of step and continue @var{command}s, the response is only sent
37216 when the operation has completed, and the target has again stopped all
37217 threads in all attached processes. This is the default all-stop mode
37218 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
37219 execution mode; see @ref{Remote Non-Stop}, for details.
37220
37221 @var{packet-data} consists of a sequence of characters with the
37222 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
37223 exceptions).
37224
37225 @cindex remote protocol, field separator
37226 Fields within the packet should be separated using @samp{,} @samp{;} or
37227 @samp{:}. Except where otherwise noted all numbers are represented in
37228 @sc{hex} with leading zeros suppressed.
37229
37230 Implementors should note that prior to @value{GDBN} 5.0, the character
37231 @samp{:} could not appear as the third character in a packet (as it
37232 would potentially conflict with the @var{sequence-id}).
37233
37234 @cindex remote protocol, binary data
37235 @anchor{Binary Data}
37236 Binary data in most packets is encoded either as two hexadecimal
37237 digits per byte of binary data. This allowed the traditional remote
37238 protocol to work over connections which were only seven-bit clean.
37239 Some packets designed more recently assume an eight-bit clean
37240 connection, and use a more efficient encoding to send and receive
37241 binary data.
37242
37243 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
37244 as an escape character. Any escaped byte is transmitted as the escape
37245 character followed by the original character XORed with @code{0x20}.
37246 For example, the byte @code{0x7d} would be transmitted as the two
37247 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
37248 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
37249 @samp{@}}) must always be escaped. Responses sent by the stub
37250 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
37251 is not interpreted as the start of a run-length encoded sequence
37252 (described next).
37253
37254 Response @var{data} can be run-length encoded to save space.
37255 Run-length encoding replaces runs of identical characters with one
37256 instance of the repeated character, followed by a @samp{*} and a
37257 repeat count. The repeat count is itself sent encoded, to avoid
37258 binary characters in @var{data}: a value of @var{n} is sent as
37259 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
37260 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
37261 code 32) for a repeat count of 3. (This is because run-length
37262 encoding starts to win for counts 3 or more.) Thus, for example,
37263 @samp{0* } is a run-length encoding of ``0000'': the space character
37264 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
37265 3}} more times.
37266
37267 The printable characters @samp{#} and @samp{$} or with a numeric value
37268 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
37269 seven repeats (@samp{$}) can be expanded using a repeat count of only
37270 five (@samp{"}). For example, @samp{00000000} can be encoded as
37271 @samp{0*"00}.
37272
37273 The error response returned for some packets includes a two character
37274 error number. That number is not well defined.
37275
37276 @cindex empty response, for unsupported packets
37277 For any @var{command} not supported by the stub, an empty response
37278 (@samp{$#00}) should be returned. That way it is possible to extend the
37279 protocol. A newer @value{GDBN} can tell if a packet is supported based
37280 on that response.
37281
37282 At a minimum, a stub is required to support the @samp{g} and @samp{G}
37283 commands for register access, and the @samp{m} and @samp{M} commands
37284 for memory access. Stubs that only control single-threaded targets
37285 can implement run control with the @samp{c} (continue), and @samp{s}
37286 (step) commands. Stubs that support multi-threading targets should
37287 support the @samp{vCont} command. All other commands are optional.
37288
37289 @node Packets
37290 @section Packets
37291
37292 The following table provides a complete list of all currently defined
37293 @var{command}s and their corresponding response @var{data}.
37294 @xref{File-I/O Remote Protocol Extension}, for details about the File
37295 I/O extension of the remote protocol.
37296
37297 Each packet's description has a template showing the packet's overall
37298 syntax, followed by an explanation of the packet's meaning. We
37299 include spaces in some of the templates for clarity; these are not
37300 part of the packet's syntax. No @value{GDBN} packet uses spaces to
37301 separate its components. For example, a template like @samp{foo
37302 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
37303 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
37304 @var{baz}. @value{GDBN} does not transmit a space character between the
37305 @samp{foo} and the @var{bar}, or between the @var{bar} and the
37306 @var{baz}.
37307
37308 @cindex @var{thread-id}, in remote protocol
37309 @anchor{thread-id syntax}
37310 Several packets and replies include a @var{thread-id} field to identify
37311 a thread. Normally these are positive numbers with a target-specific
37312 interpretation, formatted as big-endian hex strings. A @var{thread-id}
37313 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
37314 pick any thread.
37315
37316 In addition, the remote protocol supports a multiprocess feature in
37317 which the @var{thread-id} syntax is extended to optionally include both
37318 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
37319 The @var{pid} (process) and @var{tid} (thread) components each have the
37320 format described above: a positive number with target-specific
37321 interpretation formatted as a big-endian hex string, literal @samp{-1}
37322 to indicate all processes or threads (respectively), or @samp{0} to
37323 indicate an arbitrary process or thread. Specifying just a process, as
37324 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
37325 error to specify all processes but a specific thread, such as
37326 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
37327 for those packets and replies explicitly documented to include a process
37328 ID, rather than a @var{thread-id}.
37329
37330 The multiprocess @var{thread-id} syntax extensions are only used if both
37331 @value{GDBN} and the stub report support for the @samp{multiprocess}
37332 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
37333 more information.
37334
37335 Note that all packet forms beginning with an upper- or lower-case
37336 letter, other than those described here, are reserved for future use.
37337
37338 Here are the packet descriptions.
37339
37340 @table @samp
37341
37342 @item !
37343 @cindex @samp{!} packet
37344 @anchor{extended mode}
37345 Enable extended mode. In extended mode, the remote server is made
37346 persistent. The @samp{R} packet is used to restart the program being
37347 debugged.
37348
37349 Reply:
37350 @table @samp
37351 @item OK
37352 The remote target both supports and has enabled extended mode.
37353 @end table
37354
37355 @item ?
37356 @cindex @samp{?} packet
37357 Indicate the reason the target halted. The reply is the same as for
37358 step and continue. This packet has a special interpretation when the
37359 target is in non-stop mode; see @ref{Remote Non-Stop}.
37360
37361 Reply:
37362 @xref{Stop Reply Packets}, for the reply specifications.
37363
37364 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
37365 @cindex @samp{A} packet
37366 Initialized @code{argv[]} array passed into program. @var{arglen}
37367 specifies the number of bytes in the hex encoded byte stream
37368 @var{arg}. See @code{gdbserver} for more details.
37369
37370 Reply:
37371 @table @samp
37372 @item OK
37373 The arguments were set.
37374 @item E @var{NN}
37375 An error occurred.
37376 @end table
37377
37378 @item b @var{baud}
37379 @cindex @samp{b} packet
37380 (Don't use this packet; its behavior is not well-defined.)
37381 Change the serial line speed to @var{baud}.
37382
37383 JTC: @emph{When does the transport layer state change? When it's
37384 received, or after the ACK is transmitted. In either case, there are
37385 problems if the command or the acknowledgment packet is dropped.}
37386
37387 Stan: @emph{If people really wanted to add something like this, and get
37388 it working for the first time, they ought to modify ser-unix.c to send
37389 some kind of out-of-band message to a specially-setup stub and have the
37390 switch happen "in between" packets, so that from remote protocol's point
37391 of view, nothing actually happened.}
37392
37393 @item B @var{addr},@var{mode}
37394 @cindex @samp{B} packet
37395 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
37396 breakpoint at @var{addr}.
37397
37398 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
37399 (@pxref{insert breakpoint or watchpoint packet}).
37400
37401 @cindex @samp{bc} packet
37402 @anchor{bc}
37403 @item bc
37404 Backward continue. Execute the target system in reverse. No parameter.
37405 @xref{Reverse Execution}, for more information.
37406
37407 Reply:
37408 @xref{Stop Reply Packets}, for the reply specifications.
37409
37410 @cindex @samp{bs} packet
37411 @anchor{bs}
37412 @item bs
37413 Backward single step. Execute one instruction in reverse. No parameter.
37414 @xref{Reverse Execution}, for more information.
37415
37416 Reply:
37417 @xref{Stop Reply Packets}, for the reply specifications.
37418
37419 @item c @r{[}@var{addr}@r{]}
37420 @cindex @samp{c} packet
37421 Continue. @var{addr} is address to resume. If @var{addr} is omitted,
37422 resume at current address.
37423
37424 This packet is deprecated for multi-threading support. @xref{vCont
37425 packet}.
37426
37427 Reply:
37428 @xref{Stop Reply Packets}, for the reply specifications.
37429
37430 @item C @var{sig}@r{[};@var{addr}@r{]}
37431 @cindex @samp{C} packet
37432 Continue with signal @var{sig} (hex signal number). If
37433 @samp{;@var{addr}} is omitted, resume at same address.
37434
37435 This packet is deprecated for multi-threading support. @xref{vCont
37436 packet}.
37437
37438 Reply:
37439 @xref{Stop Reply Packets}, for the reply specifications.
37440
37441 @item d
37442 @cindex @samp{d} packet
37443 Toggle debug flag.
37444
37445 Don't use this packet; instead, define a general set packet
37446 (@pxref{General Query Packets}).
37447
37448 @item D
37449 @itemx D;@var{pid}
37450 @cindex @samp{D} packet
37451 The first form of the packet is used to detach @value{GDBN} from the
37452 remote system. It is sent to the remote target
37453 before @value{GDBN} disconnects via the @code{detach} command.
37454
37455 The second form, including a process ID, is used when multiprocess
37456 protocol extensions are enabled (@pxref{multiprocess extensions}), to
37457 detach only a specific process. The @var{pid} is specified as a
37458 big-endian hex string.
37459
37460 Reply:
37461 @table @samp
37462 @item OK
37463 for success
37464 @item E @var{NN}
37465 for an error
37466 @end table
37467
37468 @item F @var{RC},@var{EE},@var{CF};@var{XX}
37469 @cindex @samp{F} packet
37470 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
37471 This is part of the File-I/O protocol extension. @xref{File-I/O
37472 Remote Protocol Extension}, for the specification.
37473
37474 @item g
37475 @anchor{read registers packet}
37476 @cindex @samp{g} packet
37477 Read general registers.
37478
37479 Reply:
37480 @table @samp
37481 @item @var{XX@dots{}}
37482 Each byte of register data is described by two hex digits. The bytes
37483 with the register are transmitted in target byte order. The size of
37484 each register and their position within the @samp{g} packet are
37485 determined by the @value{GDBN} internal gdbarch functions
37486 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
37487 specification of several standard @samp{g} packets is specified below.
37488
37489 When reading registers from a trace frame (@pxref{Analyze Collected
37490 Data,,Using the Collected Data}), the stub may also return a string of
37491 literal @samp{x}'s in place of the register data digits, to indicate
37492 that the corresponding register has not been collected, thus its value
37493 is unavailable. For example, for an architecture with 4 registers of
37494 4 bytes each, the following reply indicates to @value{GDBN} that
37495 registers 0 and 2 have not been collected, while registers 1 and 3
37496 have been collected, and both have zero value:
37497
37498 @smallexample
37499 -> @code{g}
37500 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
37501 @end smallexample
37502
37503 @item E @var{NN}
37504 for an error.
37505 @end table
37506
37507 @item G @var{XX@dots{}}
37508 @cindex @samp{G} packet
37509 Write general registers. @xref{read registers packet}, for a
37510 description of the @var{XX@dots{}} data.
37511
37512 Reply:
37513 @table @samp
37514 @item OK
37515 for success
37516 @item E @var{NN}
37517 for an error
37518 @end table
37519
37520 @item H @var{op} @var{thread-id}
37521 @cindex @samp{H} packet
37522 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
37523 @samp{G}, et.al.). @var{op} depends on the operation to be performed:
37524 it should be @samp{c} for step and continue operations (note that this
37525 is deprecated, supporting the @samp{vCont} command is a better
37526 option), @samp{g} for other operations. The thread designator
37527 @var{thread-id} has the format and interpretation described in
37528 @ref{thread-id syntax}.
37529
37530 Reply:
37531 @table @samp
37532 @item OK
37533 for success
37534 @item E @var{NN}
37535 for an error
37536 @end table
37537
37538 @c FIXME: JTC:
37539 @c 'H': How restrictive (or permissive) is the thread model. If a
37540 @c thread is selected and stopped, are other threads allowed
37541 @c to continue to execute? As I mentioned above, I think the
37542 @c semantics of each command when a thread is selected must be
37543 @c described. For example:
37544 @c
37545 @c 'g': If the stub supports threads and a specific thread is
37546 @c selected, returns the register block from that thread;
37547 @c otherwise returns current registers.
37548 @c
37549 @c 'G' If the stub supports threads and a specific thread is
37550 @c selected, sets the registers of the register block of
37551 @c that thread; otherwise sets current registers.
37552
37553 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
37554 @anchor{cycle step packet}
37555 @cindex @samp{i} packet
37556 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
37557 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
37558 step starting at that address.
37559
37560 @item I
37561 @cindex @samp{I} packet
37562 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
37563 step packet}.
37564
37565 @item k
37566 @cindex @samp{k} packet
37567 Kill request.
37568
37569 FIXME: @emph{There is no description of how to operate when a specific
37570 thread context has been selected (i.e.@: does 'k' kill only that
37571 thread?)}.
37572
37573 @item m @var{addr},@var{length}
37574 @cindex @samp{m} packet
37575 Read @var{length} bytes of memory starting at address @var{addr}.
37576 Note that @var{addr} may not be aligned to any particular boundary.
37577
37578 The stub need not use any particular size or alignment when gathering
37579 data from memory for the response; even if @var{addr} is word-aligned
37580 and @var{length} is a multiple of the word size, the stub is free to
37581 use byte accesses, or not. For this reason, this packet may not be
37582 suitable for accessing memory-mapped I/O devices.
37583 @cindex alignment of remote memory accesses
37584 @cindex size of remote memory accesses
37585 @cindex memory, alignment and size of remote accesses
37586
37587 Reply:
37588 @table @samp
37589 @item @var{XX@dots{}}
37590 Memory contents; each byte is transmitted as a two-digit hexadecimal
37591 number. The reply may contain fewer bytes than requested if the
37592 server was able to read only part of the region of memory.
37593 @item E @var{NN}
37594 @var{NN} is errno
37595 @end table
37596
37597 @item M @var{addr},@var{length}:@var{XX@dots{}}
37598 @cindex @samp{M} packet
37599 Write @var{length} bytes of memory starting at address @var{addr}.
37600 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
37601 hexadecimal number.
37602
37603 Reply:
37604 @table @samp
37605 @item OK
37606 for success
37607 @item E @var{NN}
37608 for an error (this includes the case where only part of the data was
37609 written).
37610 @end table
37611
37612 @item p @var{n}
37613 @cindex @samp{p} packet
37614 Read the value of register @var{n}; @var{n} is in hex.
37615 @xref{read registers packet}, for a description of how the returned
37616 register value is encoded.
37617
37618 Reply:
37619 @table @samp
37620 @item @var{XX@dots{}}
37621 the register's value
37622 @item E @var{NN}
37623 for an error
37624 @item @w{}
37625 Indicating an unrecognized @var{query}.
37626 @end table
37627
37628 @item P @var{n@dots{}}=@var{r@dots{}}
37629 @anchor{write register packet}
37630 @cindex @samp{P} packet
37631 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
37632 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
37633 digits for each byte in the register (target byte order).
37634
37635 Reply:
37636 @table @samp
37637 @item OK
37638 for success
37639 @item E @var{NN}
37640 for an error
37641 @end table
37642
37643 @item q @var{name} @var{params}@dots{}
37644 @itemx Q @var{name} @var{params}@dots{}
37645 @cindex @samp{q} packet
37646 @cindex @samp{Q} packet
37647 General query (@samp{q}) and set (@samp{Q}). These packets are
37648 described fully in @ref{General Query Packets}.
37649
37650 @item r
37651 @cindex @samp{r} packet
37652 Reset the entire system.
37653
37654 Don't use this packet; use the @samp{R} packet instead.
37655
37656 @item R @var{XX}
37657 @cindex @samp{R} packet
37658 Restart the program being debugged. @var{XX}, while needed, is ignored.
37659 This packet is only available in extended mode (@pxref{extended mode}).
37660
37661 The @samp{R} packet has no reply.
37662
37663 @item s @r{[}@var{addr}@r{]}
37664 @cindex @samp{s} packet
37665 Single step. @var{addr} is the address at which to resume. If
37666 @var{addr} is omitted, resume at same address.
37667
37668 This packet is deprecated for multi-threading support. @xref{vCont
37669 packet}.
37670
37671 Reply:
37672 @xref{Stop Reply Packets}, for the reply specifications.
37673
37674 @item S @var{sig}@r{[};@var{addr}@r{]}
37675 @anchor{step with signal packet}
37676 @cindex @samp{S} packet
37677 Step with signal. This is analogous to the @samp{C} packet, but
37678 requests a single-step, rather than a normal resumption of execution.
37679
37680 This packet is deprecated for multi-threading support. @xref{vCont
37681 packet}.
37682
37683 Reply:
37684 @xref{Stop Reply Packets}, for the reply specifications.
37685
37686 @item t @var{addr}:@var{PP},@var{MM}
37687 @cindex @samp{t} packet
37688 Search backwards starting at address @var{addr} for a match with pattern
37689 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
37690 @var{addr} must be at least 3 digits.
37691
37692 @item T @var{thread-id}
37693 @cindex @samp{T} packet
37694 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
37695
37696 Reply:
37697 @table @samp
37698 @item OK
37699 thread is still alive
37700 @item E @var{NN}
37701 thread is dead
37702 @end table
37703
37704 @item v
37705 Packets starting with @samp{v} are identified by a multi-letter name,
37706 up to the first @samp{;} or @samp{?} (or the end of the packet).
37707
37708 @item vAttach;@var{pid}
37709 @cindex @samp{vAttach} packet
37710 Attach to a new process with the specified process ID @var{pid}.
37711 The process ID is a
37712 hexadecimal integer identifying the process. In all-stop mode, all
37713 threads in the attached process are stopped; in non-stop mode, it may be
37714 attached without being stopped if that is supported by the target.
37715
37716 @c In non-stop mode, on a successful vAttach, the stub should set the
37717 @c current thread to a thread of the newly-attached process. After
37718 @c attaching, GDB queries for the attached process's thread ID with qC.
37719 @c Also note that, from a user perspective, whether or not the
37720 @c target is stopped on attach in non-stop mode depends on whether you
37721 @c use the foreground or background version of the attach command, not
37722 @c on what vAttach does; GDB does the right thing with respect to either
37723 @c stopping or restarting threads.
37724
37725 This packet is only available in extended mode (@pxref{extended mode}).
37726
37727 Reply:
37728 @table @samp
37729 @item E @var{nn}
37730 for an error
37731 @item @r{Any stop packet}
37732 for success in all-stop mode (@pxref{Stop Reply Packets})
37733 @item OK
37734 for success in non-stop mode (@pxref{Remote Non-Stop})
37735 @end table
37736
37737 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
37738 @cindex @samp{vCont} packet
37739 @anchor{vCont packet}
37740 Resume the inferior, specifying different actions for each thread.
37741 If an action is specified with no @var{thread-id}, then it is applied to any
37742 threads that don't have a specific action specified; if no default action is
37743 specified then other threads should remain stopped in all-stop mode and
37744 in their current state in non-stop mode.
37745 Specifying multiple
37746 default actions is an error; specifying no actions is also an error.
37747 Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
37748
37749 Currently supported actions are:
37750
37751 @table @samp
37752 @item c
37753 Continue.
37754 @item C @var{sig}
37755 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
37756 @item s
37757 Step.
37758 @item S @var{sig}
37759 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
37760 @item t
37761 Stop.
37762 @item r @var{start},@var{end}
37763 Step once, and then keep stepping as long as the thread stops at
37764 addresses between @var{start} (inclusive) and @var{end} (exclusive).
37765 The remote stub reports a stop reply when either the thread goes out
37766 of the range or is stopped due to an unrelated reason, such as hitting
37767 a breakpoint. @xref{range stepping}.
37768
37769 If the range is empty (@var{start} == @var{end}), then the action
37770 becomes equivalent to the @samp{s} action. In other words,
37771 single-step once, and report the stop (even if the stepped instruction
37772 jumps to @var{start}).
37773
37774 (A stop reply may be sent at any point even if the PC is still within
37775 the stepping range; for example, it is valid to implement this packet
37776 in a degenerate way as a single instruction step operation.)
37777
37778 @end table
37779
37780 The optional argument @var{addr} normally associated with the
37781 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
37782 not supported in @samp{vCont}.
37783
37784 The @samp{t} action is only relevant in non-stop mode
37785 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
37786 A stop reply should be generated for any affected thread not already stopped.
37787 When a thread is stopped by means of a @samp{t} action,
37788 the corresponding stop reply should indicate that the thread has stopped with
37789 signal @samp{0}, regardless of whether the target uses some other signal
37790 as an implementation detail.
37791
37792 The stub must support @samp{vCont} if it reports support for
37793 multiprocess extensions (@pxref{multiprocess extensions}). Note that in
37794 this case @samp{vCont} actions can be specified to apply to all threads
37795 in a process by using the @samp{p@var{pid}.-1} form of the
37796 @var{thread-id}.
37797
37798 Reply:
37799 @xref{Stop Reply Packets}, for the reply specifications.
37800
37801 @item vCont?
37802 @cindex @samp{vCont?} packet
37803 Request a list of actions supported by the @samp{vCont} packet.
37804
37805 Reply:
37806 @table @samp
37807 @item vCont@r{[};@var{action}@dots{}@r{]}
37808 The @samp{vCont} packet is supported. Each @var{action} is a supported
37809 command in the @samp{vCont} packet.
37810 @item @w{}
37811 The @samp{vCont} packet is not supported.
37812 @end table
37813
37814 @item vFile:@var{operation}:@var{parameter}@dots{}
37815 @cindex @samp{vFile} packet
37816 Perform a file operation on the target system. For details,
37817 see @ref{Host I/O Packets}.
37818
37819 @item vFlashErase:@var{addr},@var{length}
37820 @cindex @samp{vFlashErase} packet
37821 Direct the stub to erase @var{length} bytes of flash starting at
37822 @var{addr}. The region may enclose any number of flash blocks, but
37823 its start and end must fall on block boundaries, as indicated by the
37824 flash block size appearing in the memory map (@pxref{Memory Map
37825 Format}). @value{GDBN} groups flash memory programming operations
37826 together, and sends a @samp{vFlashDone} request after each group; the
37827 stub is allowed to delay erase operation until the @samp{vFlashDone}
37828 packet is received.
37829
37830 Reply:
37831 @table @samp
37832 @item OK
37833 for success
37834 @item E @var{NN}
37835 for an error
37836 @end table
37837
37838 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
37839 @cindex @samp{vFlashWrite} packet
37840 Direct the stub to write data to flash address @var{addr}. The data
37841 is passed in binary form using the same encoding as for the @samp{X}
37842 packet (@pxref{Binary Data}). The memory ranges specified by
37843 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
37844 not overlap, and must appear in order of increasing addresses
37845 (although @samp{vFlashErase} packets for higher addresses may already
37846 have been received; the ordering is guaranteed only between
37847 @samp{vFlashWrite} packets). If a packet writes to an address that was
37848 neither erased by a preceding @samp{vFlashErase} packet nor by some other
37849 target-specific method, the results are unpredictable.
37850
37851
37852 Reply:
37853 @table @samp
37854 @item OK
37855 for success
37856 @item E.memtype
37857 for vFlashWrite addressing non-flash memory
37858 @item E @var{NN}
37859 for an error
37860 @end table
37861
37862 @item vFlashDone
37863 @cindex @samp{vFlashDone} packet
37864 Indicate to the stub that flash programming operation is finished.
37865 The stub is permitted to delay or batch the effects of a group of
37866 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
37867 @samp{vFlashDone} packet is received. The contents of the affected
37868 regions of flash memory are unpredictable until the @samp{vFlashDone}
37869 request is completed.
37870
37871 @item vKill;@var{pid}
37872 @cindex @samp{vKill} packet
37873 Kill the process with the specified process ID. @var{pid} is a
37874 hexadecimal integer identifying the process. This packet is used in
37875 preference to @samp{k} when multiprocess protocol extensions are
37876 supported; see @ref{multiprocess extensions}.
37877
37878 Reply:
37879 @table @samp
37880 @item E @var{nn}
37881 for an error
37882 @item OK
37883 for success
37884 @end table
37885
37886 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
37887 @cindex @samp{vRun} packet
37888 Run the program @var{filename}, passing it each @var{argument} on its
37889 command line. The file and arguments are hex-encoded strings. If
37890 @var{filename} is an empty string, the stub may use a default program
37891 (e.g.@: the last program run). The program is created in the stopped
37892 state.
37893
37894 @c FIXME: What about non-stop mode?
37895
37896 This packet is only available in extended mode (@pxref{extended mode}).
37897
37898 Reply:
37899 @table @samp
37900 @item E @var{nn}
37901 for an error
37902 @item @r{Any stop packet}
37903 for success (@pxref{Stop Reply Packets})
37904 @end table
37905
37906 @item vStopped
37907 @cindex @samp{vStopped} packet
37908 @xref{Notification Packets}.
37909
37910 @item X @var{addr},@var{length}:@var{XX@dots{}}
37911 @anchor{X packet}
37912 @cindex @samp{X} packet
37913 Write data to memory, where the data is transmitted in binary.
37914 @var{addr} is address, @var{length} is number of bytes,
37915 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
37916
37917 Reply:
37918 @table @samp
37919 @item OK
37920 for success
37921 @item E @var{NN}
37922 for an error
37923 @end table
37924
37925 @item z @var{type},@var{addr},@var{kind}
37926 @itemx Z @var{type},@var{addr},@var{kind}
37927 @anchor{insert breakpoint or watchpoint packet}
37928 @cindex @samp{z} packet
37929 @cindex @samp{Z} packets
37930 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
37931 watchpoint starting at address @var{address} of kind @var{kind}.
37932
37933 Each breakpoint and watchpoint packet @var{type} is documented
37934 separately.
37935
37936 @emph{Implementation notes: A remote target shall return an empty string
37937 for an unrecognized breakpoint or watchpoint packet @var{type}. A
37938 remote target shall support either both or neither of a given
37939 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
37940 avoid potential problems with duplicate packets, the operations should
37941 be implemented in an idempotent way.}
37942
37943 @item z0,@var{addr},@var{kind}
37944 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
37945 @cindex @samp{z0} packet
37946 @cindex @samp{Z0} packet
37947 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
37948 @var{addr} of type @var{kind}.
37949
37950 A memory breakpoint is implemented by replacing the instruction at
37951 @var{addr} with a software breakpoint or trap instruction. The
37952 @var{kind} is target-specific and typically indicates the size of
37953 the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
37954 and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
37955 architectures have additional meanings for @var{kind};
37956 @var{cond_list} is an optional list of conditional expressions in bytecode
37957 form that should be evaluated on the target's side. These are the
37958 conditions that should be taken into consideration when deciding if
37959 the breakpoint trigger should be reported back to @var{GDBN}.
37960
37961 The @var{cond_list} parameter is comprised of a series of expressions,
37962 concatenated without separators. Each expression has the following form:
37963
37964 @table @samp
37965
37966 @item X @var{len},@var{expr}
37967 @var{len} is the length of the bytecode expression and @var{expr} is the
37968 actual conditional expression in bytecode form.
37969
37970 @end table
37971
37972 The optional @var{cmd_list} parameter introduces commands that may be
37973 run on the target, rather than being reported back to @value{GDBN}.
37974 The parameter starts with a numeric flag @var{persist}; if the flag is
37975 nonzero, then the breakpoint may remain active and the commands
37976 continue to be run even when @value{GDBN} disconnects from the target.
37977 Following this flag is a series of expressions concatenated with no
37978 separators. Each expression has the following form:
37979
37980 @table @samp
37981
37982 @item X @var{len},@var{expr}
37983 @var{len} is the length of the bytecode expression and @var{expr} is the
37984 actual conditional expression in bytecode form.
37985
37986 @end table
37987
37988 see @ref{Architecture-Specific Protocol Details}.
37989
37990 @emph{Implementation note: It is possible for a target to copy or move
37991 code that contains memory breakpoints (e.g., when implementing
37992 overlays). The behavior of this packet, in the presence of such a
37993 target, is not defined.}
37994
37995 Reply:
37996 @table @samp
37997 @item OK
37998 success
37999 @item @w{}
38000 not supported
38001 @item E @var{NN}
38002 for an error
38003 @end table
38004
38005 @item z1,@var{addr},@var{kind}
38006 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}
38007 @cindex @samp{z1} packet
38008 @cindex @samp{Z1} packet
38009 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
38010 address @var{addr}.
38011
38012 A hardware breakpoint is implemented using a mechanism that is not
38013 dependant on being able to modify the target's memory. @var{kind}
38014 and @var{cond_list} have the same meaning as in @samp{Z0} packets.
38015
38016 @emph{Implementation note: A hardware breakpoint is not affected by code
38017 movement.}
38018
38019 Reply:
38020 @table @samp
38021 @item OK
38022 success
38023 @item @w{}
38024 not supported
38025 @item E @var{NN}
38026 for an error
38027 @end table
38028
38029 @item z2,@var{addr},@var{kind}
38030 @itemx Z2,@var{addr},@var{kind}
38031 @cindex @samp{z2} packet
38032 @cindex @samp{Z2} packet
38033 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
38034 @var{kind} is interpreted as the number of bytes to watch.
38035
38036 Reply:
38037 @table @samp
38038 @item OK
38039 success
38040 @item @w{}
38041 not supported
38042 @item E @var{NN}
38043 for an error
38044 @end table
38045
38046 @item z3,@var{addr},@var{kind}
38047 @itemx Z3,@var{addr},@var{kind}
38048 @cindex @samp{z3} packet
38049 @cindex @samp{Z3} packet
38050 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
38051 @var{kind} is interpreted as the number of bytes to watch.
38052
38053 Reply:
38054 @table @samp
38055 @item OK
38056 success
38057 @item @w{}
38058 not supported
38059 @item E @var{NN}
38060 for an error
38061 @end table
38062
38063 @item z4,@var{addr},@var{kind}
38064 @itemx Z4,@var{addr},@var{kind}
38065 @cindex @samp{z4} packet
38066 @cindex @samp{Z4} packet
38067 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
38068 @var{kind} is interpreted as the number of bytes to watch.
38069
38070 Reply:
38071 @table @samp
38072 @item OK
38073 success
38074 @item @w{}
38075 not supported
38076 @item E @var{NN}
38077 for an error
38078 @end table
38079
38080 @end table
38081
38082 @node Stop Reply Packets
38083 @section Stop Reply Packets
38084 @cindex stop reply packets
38085
38086 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
38087 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
38088 receive any of the below as a reply. Except for @samp{?}
38089 and @samp{vStopped}, that reply is only returned
38090 when the target halts. In the below the exact meaning of @dfn{signal
38091 number} is defined by the header @file{include/gdb/signals.h} in the
38092 @value{GDBN} source code.
38093
38094 As in the description of request packets, we include spaces in the
38095 reply templates for clarity; these are not part of the reply packet's
38096 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
38097 components.
38098
38099 @table @samp
38100
38101 @item S @var{AA}
38102 The program received signal number @var{AA} (a two-digit hexadecimal
38103 number). This is equivalent to a @samp{T} response with no
38104 @var{n}:@var{r} pairs.
38105
38106 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
38107 @cindex @samp{T} packet reply
38108 The program received signal number @var{AA} (a two-digit hexadecimal
38109 number). This is equivalent to an @samp{S} response, except that the
38110 @samp{@var{n}:@var{r}} pairs can carry values of important registers
38111 and other information directly in the stop reply packet, reducing
38112 round-trip latency. Single-step and breakpoint traps are reported
38113 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
38114
38115 @itemize @bullet
38116 @item
38117 If @var{n} is a hexadecimal number, it is a register number, and the
38118 corresponding @var{r} gives that register's value. @var{r} is a
38119 series of bytes in target byte order, with each byte given by a
38120 two-digit hex number.
38121
38122 @item
38123 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
38124 the stopped thread, as specified in @ref{thread-id syntax}.
38125
38126 @item
38127 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
38128 the core on which the stop event was detected.
38129
38130 @item
38131 If @var{n} is a recognized @dfn{stop reason}, it describes a more
38132 specific event that stopped the target. The currently defined stop
38133 reasons are listed below. @var{aa} should be @samp{05}, the trap
38134 signal. At most one stop reason should be present.
38135
38136 @item
38137 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
38138 and go on to the next; this allows us to extend the protocol in the
38139 future.
38140 @end itemize
38141
38142 The currently defined stop reasons are:
38143
38144 @table @samp
38145 @item watch
38146 @itemx rwatch
38147 @itemx awatch
38148 The packet indicates a watchpoint hit, and @var{r} is the data address, in
38149 hex.
38150
38151 @cindex shared library events, remote reply
38152 @item library
38153 The packet indicates that the loaded libraries have changed.
38154 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
38155 list of loaded libraries. @var{r} is ignored.
38156
38157 @cindex replay log events, remote reply
38158 @item replaylog
38159 The packet indicates that the target cannot continue replaying
38160 logged execution events, because it has reached the end (or the
38161 beginning when executing backward) of the log. The value of @var{r}
38162 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
38163 for more information.
38164 @end table
38165
38166 @item W @var{AA}
38167 @itemx W @var{AA} ; process:@var{pid}
38168 The process exited, and @var{AA} is the exit status. This is only
38169 applicable to certain targets.
38170
38171 The second form of the response, including the process ID of the exited
38172 process, can be used only when @value{GDBN} has reported support for
38173 multiprocess protocol extensions; see @ref{multiprocess extensions}.
38174 The @var{pid} is formatted as a big-endian hex string.
38175
38176 @item X @var{AA}
38177 @itemx X @var{AA} ; process:@var{pid}
38178 The process terminated with signal @var{AA}.
38179
38180 The second form of the response, including the process ID of the
38181 terminated process, can be used only when @value{GDBN} has reported
38182 support for multiprocess protocol extensions; see @ref{multiprocess
38183 extensions}. The @var{pid} is formatted as a big-endian hex string.
38184
38185 @item O @var{XX}@dots{}
38186 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
38187 written as the program's console output. This can happen at any time
38188 while the program is running and the debugger should continue to wait
38189 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
38190
38191 @item F @var{call-id},@var{parameter}@dots{}
38192 @var{call-id} is the identifier which says which host system call should
38193 be called. This is just the name of the function. Translation into the
38194 correct system call is only applicable as it's defined in @value{GDBN}.
38195 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
38196 system calls.
38197
38198 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
38199 this very system call.
38200
38201 The target replies with this packet when it expects @value{GDBN} to
38202 call a host system call on behalf of the target. @value{GDBN} replies
38203 with an appropriate @samp{F} packet and keeps up waiting for the next
38204 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
38205 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
38206 Protocol Extension}, for more details.
38207
38208 @end table
38209
38210 @node General Query Packets
38211 @section General Query Packets
38212 @cindex remote query requests
38213
38214 Packets starting with @samp{q} are @dfn{general query packets};
38215 packets starting with @samp{Q} are @dfn{general set packets}. General
38216 query and set packets are a semi-unified form for retrieving and
38217 sending information to and from the stub.
38218
38219 The initial letter of a query or set packet is followed by a name
38220 indicating what sort of thing the packet applies to. For example,
38221 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
38222 definitions with the stub. These packet names follow some
38223 conventions:
38224
38225 @itemize @bullet
38226 @item
38227 The name must not contain commas, colons or semicolons.
38228 @item
38229 Most @value{GDBN} query and set packets have a leading upper case
38230 letter.
38231 @item
38232 The names of custom vendor packets should use a company prefix, in
38233 lower case, followed by a period. For example, packets designed at
38234 the Acme Corporation might begin with @samp{qacme.foo} (for querying
38235 foos) or @samp{Qacme.bar} (for setting bars).
38236 @end itemize
38237
38238 The name of a query or set packet should be separated from any
38239 parameters by a @samp{:}; the parameters themselves should be
38240 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
38241 full packet name, and check for a separator or the end of the packet,
38242 in case two packet names share a common prefix. New packets should not begin
38243 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
38244 packets predate these conventions, and have arguments without any terminator
38245 for the packet name; we suspect they are in widespread use in places that
38246 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
38247 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
38248 packet.}.
38249
38250 Like the descriptions of the other packets, each description here
38251 has a template showing the packet's overall syntax, followed by an
38252 explanation of the packet's meaning. We include spaces in some of the
38253 templates for clarity; these are not part of the packet's syntax. No
38254 @value{GDBN} packet uses spaces to separate its components.
38255
38256 Here are the currently defined query and set packets:
38257
38258 @table @samp
38259
38260 @item QAgent:1
38261 @itemx QAgent:0
38262 Turn on or off the agent as a helper to perform some debugging operations
38263 delegated from @value{GDBN} (@pxref{Control Agent}).
38264
38265 @item QAllow:@var{op}:@var{val}@dots{}
38266 @cindex @samp{QAllow} packet
38267 Specify which operations @value{GDBN} expects to request of the
38268 target, as a semicolon-separated list of operation name and value
38269 pairs. Possible values for @var{op} include @samp{WriteReg},
38270 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
38271 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
38272 indicating that @value{GDBN} will not request the operation, or 1,
38273 indicating that it may. (The target can then use this to set up its
38274 own internals optimally, for instance if the debugger never expects to
38275 insert breakpoints, it may not need to install its own trap handler.)
38276
38277 @item qC
38278 @cindex current thread, remote request
38279 @cindex @samp{qC} packet
38280 Return the current thread ID.
38281
38282 Reply:
38283 @table @samp
38284 @item QC @var{thread-id}
38285 Where @var{thread-id} is a thread ID as documented in
38286 @ref{thread-id syntax}.
38287 @item @r{(anything else)}
38288 Any other reply implies the old thread ID.
38289 @end table
38290
38291 @item qCRC:@var{addr},@var{length}
38292 @cindex CRC of memory block, remote request
38293 @cindex @samp{qCRC} packet
38294 Compute the CRC checksum of a block of memory using CRC-32 defined in
38295 IEEE 802.3. The CRC is computed byte at a time, taking the most
38296 significant bit of each byte first. The initial pattern code
38297 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
38298
38299 @emph{Note:} This is the same CRC used in validating separate debug
38300 files (@pxref{Separate Debug Files, , Debugging Information in Separate
38301 Files}). However the algorithm is slightly different. When validating
38302 separate debug files, the CRC is computed taking the @emph{least}
38303 significant bit of each byte first, and the final result is inverted to
38304 detect trailing zeros.
38305
38306 Reply:
38307 @table @samp
38308 @item E @var{NN}
38309 An error (such as memory fault)
38310 @item C @var{crc32}
38311 The specified memory region's checksum is @var{crc32}.
38312 @end table
38313
38314 @item QDisableRandomization:@var{value}
38315 @cindex disable address space randomization, remote request
38316 @cindex @samp{QDisableRandomization} packet
38317 Some target operating systems will randomize the virtual address space
38318 of the inferior process as a security feature, but provide a feature
38319 to disable such randomization, e.g.@: to allow for a more deterministic
38320 debugging experience. On such systems, this packet with a @var{value}
38321 of 1 directs the target to disable address space randomization for
38322 processes subsequently started via @samp{vRun} packets, while a packet
38323 with a @var{value} of 0 tells the target to enable address space
38324 randomization.
38325
38326 This packet is only available in extended mode (@pxref{extended mode}).
38327
38328 Reply:
38329 @table @samp
38330 @item OK
38331 The request succeeded.
38332
38333 @item E @var{nn}
38334 An error occurred. @var{nn} are hex digits.
38335
38336 @item @w{}
38337 An empty reply indicates that @samp{QDisableRandomization} is not supported
38338 by the stub.
38339 @end table
38340
38341 This packet is not probed by default; the remote stub must request it,
38342 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38343 This should only be done on targets that actually support disabling
38344 address space randomization.
38345
38346 @item qfThreadInfo
38347 @itemx qsThreadInfo
38348 @cindex list active threads, remote request
38349 @cindex @samp{qfThreadInfo} packet
38350 @cindex @samp{qsThreadInfo} packet
38351 Obtain a list of all active thread IDs from the target (OS). Since there
38352 may be too many active threads to fit into one reply packet, this query
38353 works iteratively: it may require more than one query/reply sequence to
38354 obtain the entire list of threads. The first query of the sequence will
38355 be the @samp{qfThreadInfo} query; subsequent queries in the
38356 sequence will be the @samp{qsThreadInfo} query.
38357
38358 NOTE: This packet replaces the @samp{qL} query (see below).
38359
38360 Reply:
38361 @table @samp
38362 @item m @var{thread-id}
38363 A single thread ID
38364 @item m @var{thread-id},@var{thread-id}@dots{}
38365 a comma-separated list of thread IDs
38366 @item l
38367 (lower case letter @samp{L}) denotes end of list.
38368 @end table
38369
38370 In response to each query, the target will reply with a list of one or
38371 more thread IDs, separated by commas.
38372 @value{GDBN} will respond to each reply with a request for more thread
38373 ids (using the @samp{qs} form of the query), until the target responds
38374 with @samp{l} (lower-case ell, for @dfn{last}).
38375 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
38376 fields.
38377
38378 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
38379 @cindex get thread-local storage address, remote request
38380 @cindex @samp{qGetTLSAddr} packet
38381 Fetch the address associated with thread local storage specified
38382 by @var{thread-id}, @var{offset}, and @var{lm}.
38383
38384 @var{thread-id} is the thread ID associated with the
38385 thread for which to fetch the TLS address. @xref{thread-id syntax}.
38386
38387 @var{offset} is the (big endian, hex encoded) offset associated with the
38388 thread local variable. (This offset is obtained from the debug
38389 information associated with the variable.)
38390
38391 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
38392 load module associated with the thread local storage. For example,
38393 a @sc{gnu}/Linux system will pass the link map address of the shared
38394 object associated with the thread local storage under consideration.
38395 Other operating environments may choose to represent the load module
38396 differently, so the precise meaning of this parameter will vary.
38397
38398 Reply:
38399 @table @samp
38400 @item @var{XX}@dots{}
38401 Hex encoded (big endian) bytes representing the address of the thread
38402 local storage requested.
38403
38404 @item E @var{nn}
38405 An error occurred. @var{nn} are hex digits.
38406
38407 @item @w{}
38408 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
38409 @end table
38410
38411 @item qGetTIBAddr:@var{thread-id}
38412 @cindex get thread information block address
38413 @cindex @samp{qGetTIBAddr} packet
38414 Fetch address of the Windows OS specific Thread Information Block.
38415
38416 @var{thread-id} is the thread ID associated with the thread.
38417
38418 Reply:
38419 @table @samp
38420 @item @var{XX}@dots{}
38421 Hex encoded (big endian) bytes representing the linear address of the
38422 thread information block.
38423
38424 @item E @var{nn}
38425 An error occured. This means that either the thread was not found, or the
38426 address could not be retrieved.
38427
38428 @item @w{}
38429 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
38430 @end table
38431
38432 @item qL @var{startflag} @var{threadcount} @var{nextthread}
38433 Obtain thread information from RTOS. Where: @var{startflag} (one hex
38434 digit) is one to indicate the first query and zero to indicate a
38435 subsequent query; @var{threadcount} (two hex digits) is the maximum
38436 number of threads the response packet can contain; and @var{nextthread}
38437 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
38438 returned in the response as @var{argthread}.
38439
38440 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
38441
38442 Reply:
38443 @table @samp
38444 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
38445 Where: @var{count} (two hex digits) is the number of threads being
38446 returned; @var{done} (one hex digit) is zero to indicate more threads
38447 and one indicates no further threads; @var{argthreadid} (eight hex
38448 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
38449 is a sequence of thread IDs from the target. @var{threadid} (eight hex
38450 digits). See @code{remote.c:parse_threadlist_response()}.
38451 @end table
38452
38453 @item qOffsets
38454 @cindex section offsets, remote request
38455 @cindex @samp{qOffsets} packet
38456 Get section offsets that the target used when relocating the downloaded
38457 image.
38458
38459 Reply:
38460 @table @samp
38461 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
38462 Relocate the @code{Text} section by @var{xxx} from its original address.
38463 Relocate the @code{Data} section by @var{yyy} from its original address.
38464 If the object file format provides segment information (e.g.@: @sc{elf}
38465 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
38466 segments by the supplied offsets.
38467
38468 @emph{Note: while a @code{Bss} offset may be included in the response,
38469 @value{GDBN} ignores this and instead applies the @code{Data} offset
38470 to the @code{Bss} section.}
38471
38472 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
38473 Relocate the first segment of the object file, which conventionally
38474 contains program code, to a starting address of @var{xxx}. If
38475 @samp{DataSeg} is specified, relocate the second segment, which
38476 conventionally contains modifiable data, to a starting address of
38477 @var{yyy}. @value{GDBN} will report an error if the object file
38478 does not contain segment information, or does not contain at least
38479 as many segments as mentioned in the reply. Extra segments are
38480 kept at fixed offsets relative to the last relocated segment.
38481 @end table
38482
38483 @item qP @var{mode} @var{thread-id}
38484 @cindex thread information, remote request
38485 @cindex @samp{qP} packet
38486 Returns information on @var{thread-id}. Where: @var{mode} is a hex
38487 encoded 32 bit mode; @var{thread-id} is a thread ID
38488 (@pxref{thread-id syntax}).
38489
38490 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
38491 (see below).
38492
38493 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
38494
38495 @item QNonStop:1
38496 @itemx QNonStop:0
38497 @cindex non-stop mode, remote request
38498 @cindex @samp{QNonStop} packet
38499 @anchor{QNonStop}
38500 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
38501 @xref{Remote Non-Stop}, for more information.
38502
38503 Reply:
38504 @table @samp
38505 @item OK
38506 The request succeeded.
38507
38508 @item E @var{nn}
38509 An error occurred. @var{nn} are hex digits.
38510
38511 @item @w{}
38512 An empty reply indicates that @samp{QNonStop} is not supported by
38513 the stub.
38514 @end table
38515
38516 This packet is not probed by default; the remote stub must request it,
38517 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38518 Use of this packet is controlled by the @code{set non-stop} command;
38519 @pxref{Non-Stop Mode}.
38520
38521 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
38522 @cindex pass signals to inferior, remote request
38523 @cindex @samp{QPassSignals} packet
38524 @anchor{QPassSignals}
38525 Each listed @var{signal} should be passed directly to the inferior process.
38526 Signals are numbered identically to continue packets and stop replies
38527 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
38528 strictly greater than the previous item. These signals do not need to stop
38529 the inferior, or be reported to @value{GDBN}. All other signals should be
38530 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
38531 combine; any earlier @samp{QPassSignals} list is completely replaced by the
38532 new list. This packet improves performance when using @samp{handle
38533 @var{signal} nostop noprint pass}.
38534
38535 Reply:
38536 @table @samp
38537 @item OK
38538 The request succeeded.
38539
38540 @item E @var{nn}
38541 An error occurred. @var{nn} are hex digits.
38542
38543 @item @w{}
38544 An empty reply indicates that @samp{QPassSignals} is not supported by
38545 the stub.
38546 @end table
38547
38548 Use of this packet is controlled by the @code{set remote pass-signals}
38549 command (@pxref{Remote Configuration, set remote pass-signals}).
38550 This packet is not probed by default; the remote stub must request it,
38551 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38552
38553 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
38554 @cindex signals the inferior may see, remote request
38555 @cindex @samp{QProgramSignals} packet
38556 @anchor{QProgramSignals}
38557 Each listed @var{signal} may be delivered to the inferior process.
38558 Others should be silently discarded.
38559
38560 In some cases, the remote stub may need to decide whether to deliver a
38561 signal to the program or not without @value{GDBN} involvement. One
38562 example of that is while detaching --- the program's threads may have
38563 stopped for signals that haven't yet had a chance of being reported to
38564 @value{GDBN}, and so the remote stub can use the signal list specified
38565 by this packet to know whether to deliver or ignore those pending
38566 signals.
38567
38568 This does not influence whether to deliver a signal as requested by a
38569 resumption packet (@pxref{vCont packet}).
38570
38571 Signals are numbered identically to continue packets and stop replies
38572 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
38573 strictly greater than the previous item. Multiple
38574 @samp{QProgramSignals} packets do not combine; any earlier
38575 @samp{QProgramSignals} list is completely replaced by the new list.
38576
38577 Reply:
38578 @table @samp
38579 @item OK
38580 The request succeeded.
38581
38582 @item E @var{nn}
38583 An error occurred. @var{nn} are hex digits.
38584
38585 @item @w{}
38586 An empty reply indicates that @samp{QProgramSignals} is not supported
38587 by the stub.
38588 @end table
38589
38590 Use of this packet is controlled by the @code{set remote program-signals}
38591 command (@pxref{Remote Configuration, set remote program-signals}).
38592 This packet is not probed by default; the remote stub must request it,
38593 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38594
38595 @item qRcmd,@var{command}
38596 @cindex execute remote command, remote request
38597 @cindex @samp{qRcmd} packet
38598 @var{command} (hex encoded) is passed to the local interpreter for
38599 execution. Invalid commands should be reported using the output
38600 string. Before the final result packet, the target may also respond
38601 with a number of intermediate @samp{O@var{output}} console output
38602 packets. @emph{Implementors should note that providing access to a
38603 stubs's interpreter may have security implications}.
38604
38605 Reply:
38606 @table @samp
38607 @item OK
38608 A command response with no output.
38609 @item @var{OUTPUT}
38610 A command response with the hex encoded output string @var{OUTPUT}.
38611 @item E @var{NN}
38612 Indicate a badly formed request.
38613 @item @w{}
38614 An empty reply indicates that @samp{qRcmd} is not recognized.
38615 @end table
38616
38617 (Note that the @code{qRcmd} packet's name is separated from the
38618 command by a @samp{,}, not a @samp{:}, contrary to the naming
38619 conventions above. Please don't use this packet as a model for new
38620 packets.)
38621
38622 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
38623 @cindex searching memory, in remote debugging
38624 @ifnotinfo
38625 @cindex @samp{qSearch:memory} packet
38626 @end ifnotinfo
38627 @cindex @samp{qSearch memory} packet
38628 @anchor{qSearch memory}
38629 Search @var{length} bytes at @var{address} for @var{search-pattern}.
38630 @var{address} and @var{length} are encoded in hex.
38631 @var{search-pattern} is a sequence of bytes, hex encoded.
38632
38633 Reply:
38634 @table @samp
38635 @item 0
38636 The pattern was not found.
38637 @item 1,address
38638 The pattern was found at @var{address}.
38639 @item E @var{NN}
38640 A badly formed request or an error was encountered while searching memory.
38641 @item @w{}
38642 An empty reply indicates that @samp{qSearch:memory} is not recognized.
38643 @end table
38644
38645 @item QStartNoAckMode
38646 @cindex @samp{QStartNoAckMode} packet
38647 @anchor{QStartNoAckMode}
38648 Request that the remote stub disable the normal @samp{+}/@samp{-}
38649 protocol acknowledgments (@pxref{Packet Acknowledgment}).
38650
38651 Reply:
38652 @table @samp
38653 @item OK
38654 The stub has switched to no-acknowledgment mode.
38655 @value{GDBN} acknowledges this reponse,
38656 but neither the stub nor @value{GDBN} shall send or expect further
38657 @samp{+}/@samp{-} acknowledgments in the current connection.
38658 @item @w{}
38659 An empty reply indicates that the stub does not support no-acknowledgment mode.
38660 @end table
38661
38662 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
38663 @cindex supported packets, remote query
38664 @cindex features of the remote protocol
38665 @cindex @samp{qSupported} packet
38666 @anchor{qSupported}
38667 Tell the remote stub about features supported by @value{GDBN}, and
38668 query the stub for features it supports. This packet allows
38669 @value{GDBN} and the remote stub to take advantage of each others'
38670 features. @samp{qSupported} also consolidates multiple feature probes
38671 at startup, to improve @value{GDBN} performance---a single larger
38672 packet performs better than multiple smaller probe packets on
38673 high-latency links. Some features may enable behavior which must not
38674 be on by default, e.g.@: because it would confuse older clients or
38675 stubs. Other features may describe packets which could be
38676 automatically probed for, but are not. These features must be
38677 reported before @value{GDBN} will use them. This ``default
38678 unsupported'' behavior is not appropriate for all packets, but it
38679 helps to keep the initial connection time under control with new
38680 versions of @value{GDBN} which support increasing numbers of packets.
38681
38682 Reply:
38683 @table @samp
38684 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
38685 The stub supports or does not support each returned @var{stubfeature},
38686 depending on the form of each @var{stubfeature} (see below for the
38687 possible forms).
38688 @item @w{}
38689 An empty reply indicates that @samp{qSupported} is not recognized,
38690 or that no features needed to be reported to @value{GDBN}.
38691 @end table
38692
38693 The allowed forms for each feature (either a @var{gdbfeature} in the
38694 @samp{qSupported} packet, or a @var{stubfeature} in the response)
38695 are:
38696
38697 @table @samp
38698 @item @var{name}=@var{value}
38699 The remote protocol feature @var{name} is supported, and associated
38700 with the specified @var{value}. The format of @var{value} depends
38701 on the feature, but it must not include a semicolon.
38702 @item @var{name}+
38703 The remote protocol feature @var{name} is supported, and does not
38704 need an associated value.
38705 @item @var{name}-
38706 The remote protocol feature @var{name} is not supported.
38707 @item @var{name}?
38708 The remote protocol feature @var{name} may be supported, and
38709 @value{GDBN} should auto-detect support in some other way when it is
38710 needed. This form will not be used for @var{gdbfeature} notifications,
38711 but may be used for @var{stubfeature} responses.
38712 @end table
38713
38714 Whenever the stub receives a @samp{qSupported} request, the
38715 supplied set of @value{GDBN} features should override any previous
38716 request. This allows @value{GDBN} to put the stub in a known
38717 state, even if the stub had previously been communicating with
38718 a different version of @value{GDBN}.
38719
38720 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
38721 are defined:
38722
38723 @table @samp
38724 @item multiprocess
38725 This feature indicates whether @value{GDBN} supports multiprocess
38726 extensions to the remote protocol. @value{GDBN} does not use such
38727 extensions unless the stub also reports that it supports them by
38728 including @samp{multiprocess+} in its @samp{qSupported} reply.
38729 @xref{multiprocess extensions}, for details.
38730
38731 @item xmlRegisters
38732 This feature indicates that @value{GDBN} supports the XML target
38733 description. If the stub sees @samp{xmlRegisters=} with target
38734 specific strings separated by a comma, it will report register
38735 description.
38736
38737 @item qRelocInsn
38738 This feature indicates whether @value{GDBN} supports the
38739 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
38740 instruction reply packet}).
38741 @end table
38742
38743 Stubs should ignore any unknown values for
38744 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
38745 packet supports receiving packets of unlimited length (earlier
38746 versions of @value{GDBN} may reject overly long responses). Additional values
38747 for @var{gdbfeature} may be defined in the future to let the stub take
38748 advantage of new features in @value{GDBN}, e.g.@: incompatible
38749 improvements in the remote protocol---the @samp{multiprocess} feature is
38750 an example of such a feature. The stub's reply should be independent
38751 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
38752 describes all the features it supports, and then the stub replies with
38753 all the features it supports.
38754
38755 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
38756 responses, as long as each response uses one of the standard forms.
38757
38758 Some features are flags. A stub which supports a flag feature
38759 should respond with a @samp{+} form response. Other features
38760 require values, and the stub should respond with an @samp{=}
38761 form response.
38762
38763 Each feature has a default value, which @value{GDBN} will use if
38764 @samp{qSupported} is not available or if the feature is not mentioned
38765 in the @samp{qSupported} response. The default values are fixed; a
38766 stub is free to omit any feature responses that match the defaults.
38767
38768 Not all features can be probed, but for those which can, the probing
38769 mechanism is useful: in some cases, a stub's internal
38770 architecture may not allow the protocol layer to know some information
38771 about the underlying target in advance. This is especially common in
38772 stubs which may be configured for multiple targets.
38773
38774 These are the currently defined stub features and their properties:
38775
38776 @multitable @columnfractions 0.35 0.2 0.12 0.2
38777 @c NOTE: The first row should be @headitem, but we do not yet require
38778 @c a new enough version of Texinfo (4.7) to use @headitem.
38779 @item Feature Name
38780 @tab Value Required
38781 @tab Default
38782 @tab Probe Allowed
38783
38784 @item @samp{PacketSize}
38785 @tab Yes
38786 @tab @samp{-}
38787 @tab No
38788
38789 @item @samp{qXfer:auxv:read}
38790 @tab No
38791 @tab @samp{-}
38792 @tab Yes
38793
38794 @item @samp{qXfer:btrace:read}
38795 @tab No
38796 @tab @samp{-}
38797 @tab Yes
38798
38799 @item @samp{qXfer:features:read}
38800 @tab No
38801 @tab @samp{-}
38802 @tab Yes
38803
38804 @item @samp{qXfer:libraries:read}
38805 @tab No
38806 @tab @samp{-}
38807 @tab Yes
38808
38809 @item @samp{qXfer:libraries-svr4:read}
38810 @tab No
38811 @tab @samp{-}
38812 @tab Yes
38813
38814 @item @samp{augmented-libraries-svr4-read}
38815 @tab No
38816 @tab @samp{-}
38817 @tab No
38818
38819 @item @samp{qXfer:memory-map:read}
38820 @tab No
38821 @tab @samp{-}
38822 @tab Yes
38823
38824 @item @samp{qXfer:sdata:read}
38825 @tab No
38826 @tab @samp{-}
38827 @tab Yes
38828
38829 @item @samp{qXfer:spu:read}
38830 @tab No
38831 @tab @samp{-}
38832 @tab Yes
38833
38834 @item @samp{qXfer:spu:write}
38835 @tab No
38836 @tab @samp{-}
38837 @tab Yes
38838
38839 @item @samp{qXfer:siginfo:read}
38840 @tab No
38841 @tab @samp{-}
38842 @tab Yes
38843
38844 @item @samp{qXfer:siginfo:write}
38845 @tab No
38846 @tab @samp{-}
38847 @tab Yes
38848
38849 @item @samp{qXfer:threads:read}
38850 @tab No
38851 @tab @samp{-}
38852 @tab Yes
38853
38854 @item @samp{qXfer:traceframe-info:read}
38855 @tab No
38856 @tab @samp{-}
38857 @tab Yes
38858
38859 @item @samp{qXfer:uib:read}
38860 @tab No
38861 @tab @samp{-}
38862 @tab Yes
38863
38864 @item @samp{qXfer:fdpic:read}
38865 @tab No
38866 @tab @samp{-}
38867 @tab Yes
38868
38869 @item @samp{Qbtrace:off}
38870 @tab Yes
38871 @tab @samp{-}
38872 @tab Yes
38873
38874 @item @samp{Qbtrace:bts}
38875 @tab Yes
38876 @tab @samp{-}
38877 @tab Yes
38878
38879 @item @samp{QNonStop}
38880 @tab No
38881 @tab @samp{-}
38882 @tab Yes
38883
38884 @item @samp{QPassSignals}
38885 @tab No
38886 @tab @samp{-}
38887 @tab Yes
38888
38889 @item @samp{QStartNoAckMode}
38890 @tab No
38891 @tab @samp{-}
38892 @tab Yes
38893
38894 @item @samp{multiprocess}
38895 @tab No
38896 @tab @samp{-}
38897 @tab No
38898
38899 @item @samp{ConditionalBreakpoints}
38900 @tab No
38901 @tab @samp{-}
38902 @tab No
38903
38904 @item @samp{ConditionalTracepoints}
38905 @tab No
38906 @tab @samp{-}
38907 @tab No
38908
38909 @item @samp{ReverseContinue}
38910 @tab No
38911 @tab @samp{-}
38912 @tab No
38913
38914 @item @samp{ReverseStep}
38915 @tab No
38916 @tab @samp{-}
38917 @tab No
38918
38919 @item @samp{TracepointSource}
38920 @tab No
38921 @tab @samp{-}
38922 @tab No
38923
38924 @item @samp{QAgent}
38925 @tab No
38926 @tab @samp{-}
38927 @tab No
38928
38929 @item @samp{QAllow}
38930 @tab No
38931 @tab @samp{-}
38932 @tab No
38933
38934 @item @samp{QDisableRandomization}
38935 @tab No
38936 @tab @samp{-}
38937 @tab No
38938
38939 @item @samp{EnableDisableTracepoints}
38940 @tab No
38941 @tab @samp{-}
38942 @tab No
38943
38944 @item @samp{QTBuffer:size}
38945 @tab No
38946 @tab @samp{-}
38947 @tab No
38948
38949 @item @samp{tracenz}
38950 @tab No
38951 @tab @samp{-}
38952 @tab No
38953
38954 @item @samp{BreakpointCommands}
38955 @tab No
38956 @tab @samp{-}
38957 @tab No
38958
38959 @end multitable
38960
38961 These are the currently defined stub features, in more detail:
38962
38963 @table @samp
38964 @cindex packet size, remote protocol
38965 @item PacketSize=@var{bytes}
38966 The remote stub can accept packets up to at least @var{bytes} in
38967 length. @value{GDBN} will send packets up to this size for bulk
38968 transfers, and will never send larger packets. This is a limit on the
38969 data characters in the packet, including the frame and checksum.
38970 There is no trailing NUL byte in a remote protocol packet; if the stub
38971 stores packets in a NUL-terminated format, it should allow an extra
38972 byte in its buffer for the NUL. If this stub feature is not supported,
38973 @value{GDBN} guesses based on the size of the @samp{g} packet response.
38974
38975 @item qXfer:auxv:read
38976 The remote stub understands the @samp{qXfer:auxv:read} packet
38977 (@pxref{qXfer auxiliary vector read}).
38978
38979 @item qXfer:btrace:read
38980 The remote stub understands the @samp{qXfer:btrace:read}
38981 packet (@pxref{qXfer btrace read}).
38982
38983 @item qXfer:features:read
38984 The remote stub understands the @samp{qXfer:features:read} packet
38985 (@pxref{qXfer target description read}).
38986
38987 @item qXfer:libraries:read
38988 The remote stub understands the @samp{qXfer:libraries:read} packet
38989 (@pxref{qXfer library list read}).
38990
38991 @item qXfer:libraries-svr4:read
38992 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
38993 (@pxref{qXfer svr4 library list read}).
38994
38995 @item augmented-libraries-svr4-read
38996 The remote stub understands the augmented form of the
38997 @samp{qXfer:libraries-svr4:read} packet
38998 (@pxref{qXfer svr4 library list read}).
38999
39000 @item qXfer:memory-map:read
39001 The remote stub understands the @samp{qXfer:memory-map:read} packet
39002 (@pxref{qXfer memory map read}).
39003
39004 @item qXfer:sdata:read
39005 The remote stub understands the @samp{qXfer:sdata:read} packet
39006 (@pxref{qXfer sdata read}).
39007
39008 @item qXfer:spu:read
39009 The remote stub understands the @samp{qXfer:spu:read} packet
39010 (@pxref{qXfer spu read}).
39011
39012 @item qXfer:spu:write
39013 The remote stub understands the @samp{qXfer:spu:write} packet
39014 (@pxref{qXfer spu write}).
39015
39016 @item qXfer:siginfo:read
39017 The remote stub understands the @samp{qXfer:siginfo:read} packet
39018 (@pxref{qXfer siginfo read}).
39019
39020 @item qXfer:siginfo:write
39021 The remote stub understands the @samp{qXfer:siginfo:write} packet
39022 (@pxref{qXfer siginfo write}).
39023
39024 @item qXfer:threads:read
39025 The remote stub understands the @samp{qXfer:threads:read} packet
39026 (@pxref{qXfer threads read}).
39027
39028 @item qXfer:traceframe-info:read
39029 The remote stub understands the @samp{qXfer:traceframe-info:read}
39030 packet (@pxref{qXfer traceframe info read}).
39031
39032 @item qXfer:uib:read
39033 The remote stub understands the @samp{qXfer:uib:read}
39034 packet (@pxref{qXfer unwind info block}).
39035
39036 @item qXfer:fdpic:read
39037 The remote stub understands the @samp{qXfer:fdpic:read}
39038 packet (@pxref{qXfer fdpic loadmap read}).
39039
39040 @item QNonStop
39041 The remote stub understands the @samp{QNonStop} packet
39042 (@pxref{QNonStop}).
39043
39044 @item QPassSignals
39045 The remote stub understands the @samp{QPassSignals} packet
39046 (@pxref{QPassSignals}).
39047
39048 @item QStartNoAckMode
39049 The remote stub understands the @samp{QStartNoAckMode} packet and
39050 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
39051
39052 @item multiprocess
39053 @anchor{multiprocess extensions}
39054 @cindex multiprocess extensions, in remote protocol
39055 The remote stub understands the multiprocess extensions to the remote
39056 protocol syntax. The multiprocess extensions affect the syntax of
39057 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
39058 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
39059 replies. Note that reporting this feature indicates support for the
39060 syntactic extensions only, not that the stub necessarily supports
39061 debugging of more than one process at a time. The stub must not use
39062 multiprocess extensions in packet replies unless @value{GDBN} has also
39063 indicated it supports them in its @samp{qSupported} request.
39064
39065 @item qXfer:osdata:read
39066 The remote stub understands the @samp{qXfer:osdata:read} packet
39067 ((@pxref{qXfer osdata read}).
39068
39069 @item ConditionalBreakpoints
39070 The target accepts and implements evaluation of conditional expressions
39071 defined for breakpoints. The target will only report breakpoint triggers
39072 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
39073
39074 @item ConditionalTracepoints
39075 The remote stub accepts and implements conditional expressions defined
39076 for tracepoints (@pxref{Tracepoint Conditions}).
39077
39078 @item ReverseContinue
39079 The remote stub accepts and implements the reverse continue packet
39080 (@pxref{bc}).
39081
39082 @item ReverseStep
39083 The remote stub accepts and implements the reverse step packet
39084 (@pxref{bs}).
39085
39086 @item TracepointSource
39087 The remote stub understands the @samp{QTDPsrc} packet that supplies
39088 the source form of tracepoint definitions.
39089
39090 @item QAgent
39091 The remote stub understands the @samp{QAgent} packet.
39092
39093 @item QAllow
39094 The remote stub understands the @samp{QAllow} packet.
39095
39096 @item QDisableRandomization
39097 The remote stub understands the @samp{QDisableRandomization} packet.
39098
39099 @item StaticTracepoint
39100 @cindex static tracepoints, in remote protocol
39101 The remote stub supports static tracepoints.
39102
39103 @item InstallInTrace
39104 @anchor{install tracepoint in tracing}
39105 The remote stub supports installing tracepoint in tracing.
39106
39107 @item EnableDisableTracepoints
39108 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
39109 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
39110 to be enabled and disabled while a trace experiment is running.
39111
39112 @item QTBuffer:size
39113 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
39114 packet that allows to change the size of the trace buffer.
39115
39116 @item tracenz
39117 @cindex string tracing, in remote protocol
39118 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
39119 See @ref{Bytecode Descriptions} for details about the bytecode.
39120
39121 @item BreakpointCommands
39122 @cindex breakpoint commands, in remote protocol
39123 The remote stub supports running a breakpoint's command list itself,
39124 rather than reporting the hit to @value{GDBN}.
39125
39126 @item Qbtrace:off
39127 The remote stub understands the @samp{Qbtrace:off} packet.
39128
39129 @item Qbtrace:bts
39130 The remote stub understands the @samp{Qbtrace:bts} packet.
39131
39132 @end table
39133
39134 @item qSymbol::
39135 @cindex symbol lookup, remote request
39136 @cindex @samp{qSymbol} packet
39137 Notify the target that @value{GDBN} is prepared to serve symbol lookup
39138 requests. Accept requests from the target for the values of symbols.
39139
39140 Reply:
39141 @table @samp
39142 @item OK
39143 The target does not need to look up any (more) symbols.
39144 @item qSymbol:@var{sym_name}
39145 The target requests the value of symbol @var{sym_name} (hex encoded).
39146 @value{GDBN} may provide the value by using the
39147 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
39148 below.
39149 @end table
39150
39151 @item qSymbol:@var{sym_value}:@var{sym_name}
39152 Set the value of @var{sym_name} to @var{sym_value}.
39153
39154 @var{sym_name} (hex encoded) is the name of a symbol whose value the
39155 target has previously requested.
39156
39157 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
39158 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
39159 will be empty.
39160
39161 Reply:
39162 @table @samp
39163 @item OK
39164 The target does not need to look up any (more) symbols.
39165 @item qSymbol:@var{sym_name}
39166 The target requests the value of a new symbol @var{sym_name} (hex
39167 encoded). @value{GDBN} will continue to supply the values of symbols
39168 (if available), until the target ceases to request them.
39169 @end table
39170
39171 @item qTBuffer
39172 @itemx QTBuffer
39173 @itemx QTDisconnected
39174 @itemx QTDP
39175 @itemx QTDPsrc
39176 @itemx QTDV
39177 @itemx qTfP
39178 @itemx qTfV
39179 @itemx QTFrame
39180 @itemx qTMinFTPILen
39181
39182 @xref{Tracepoint Packets}.
39183
39184 @item qThreadExtraInfo,@var{thread-id}
39185 @cindex thread attributes info, remote request
39186 @cindex @samp{qThreadExtraInfo} packet
39187 Obtain a printable string description of a thread's attributes from
39188 the target OS. @var{thread-id} is a thread ID;
39189 see @ref{thread-id syntax}. This
39190 string may contain anything that the target OS thinks is interesting
39191 for @value{GDBN} to tell the user about the thread. The string is
39192 displayed in @value{GDBN}'s @code{info threads} display. Some
39193 examples of possible thread extra info strings are @samp{Runnable}, or
39194 @samp{Blocked on Mutex}.
39195
39196 Reply:
39197 @table @samp
39198 @item @var{XX}@dots{}
39199 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
39200 comprising the printable string containing the extra information about
39201 the thread's attributes.
39202 @end table
39203
39204 (Note that the @code{qThreadExtraInfo} packet's name is separated from
39205 the command by a @samp{,}, not a @samp{:}, contrary to the naming
39206 conventions above. Please don't use this packet as a model for new
39207 packets.)
39208
39209 @item QTNotes
39210 @itemx qTP
39211 @itemx QTSave
39212 @itemx qTsP
39213 @itemx qTsV
39214 @itemx QTStart
39215 @itemx QTStop
39216 @itemx QTEnable
39217 @itemx QTDisable
39218 @itemx QTinit
39219 @itemx QTro
39220 @itemx qTStatus
39221 @itemx qTV
39222 @itemx qTfSTM
39223 @itemx qTsSTM
39224 @itemx qTSTMat
39225 @xref{Tracepoint Packets}.
39226
39227 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
39228 @cindex read special object, remote request
39229 @cindex @samp{qXfer} packet
39230 @anchor{qXfer read}
39231 Read uninterpreted bytes from the target's special data area
39232 identified by the keyword @var{object}. Request @var{length} bytes
39233 starting at @var{offset} bytes into the data. The content and
39234 encoding of @var{annex} is specific to @var{object}; it can supply
39235 additional details about what data to access.
39236
39237 Here are the specific requests of this form defined so far. All
39238 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
39239 formats, listed below.
39240
39241 @table @samp
39242 @item qXfer:auxv:read::@var{offset},@var{length}
39243 @anchor{qXfer auxiliary vector read}
39244 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
39245 auxiliary vector}. Note @var{annex} must be empty.
39246
39247 This packet is not probed by default; the remote stub must request it,
39248 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39249
39250 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
39251 @anchor{qXfer btrace read}
39252
39253 Return a description of the current branch trace.
39254 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
39255 packet may have one of the following values:
39256
39257 @table @code
39258 @item all
39259 Returns all available branch trace.
39260
39261 @item new
39262 Returns all available branch trace if the branch trace changed since
39263 the last read request.
39264 @end table
39265
39266 This packet is not probed by default; the remote stub must request it
39267 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39268
39269 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
39270 @anchor{qXfer target description read}
39271 Access the @dfn{target description}. @xref{Target Descriptions}. The
39272 annex specifies which XML document to access. The main description is
39273 always loaded from the @samp{target.xml} annex.
39274
39275 This packet is not probed by default; the remote stub must request it,
39276 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39277
39278 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
39279 @anchor{qXfer library list read}
39280 Access the target's list of loaded libraries. @xref{Library List Format}.
39281 The annex part of the generic @samp{qXfer} packet must be empty
39282 (@pxref{qXfer read}).
39283
39284 Targets which maintain a list of libraries in the program's memory do
39285 not need to implement this packet; it is designed for platforms where
39286 the operating system manages the list of loaded libraries.
39287
39288 This packet is not probed by default; the remote stub must request it,
39289 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39290
39291 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
39292 @anchor{qXfer svr4 library list read}
39293 Access the target's list of loaded libraries when the target is an SVR4
39294 platform. @xref{Library List Format for SVR4 Targets}. The annex part
39295 of the generic @samp{qXfer} packet must be empty unless the remote
39296 stub indicated it supports the augmented form of this packet
39297 by supplying an appropriate @samp{qSupported} response
39298 (@pxref{qXfer read}, @ref{qSupported}).
39299
39300 This packet is optional for better performance on SVR4 targets.
39301 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
39302
39303 This packet is not probed by default; the remote stub must request it,
39304 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39305
39306 If the remote stub indicates it supports the augmented form of this
39307 packet then the annex part of the generic @samp{qXfer} packet may
39308 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
39309 arguments. The currently supported arguments are:
39310
39311 @table @code
39312 @item start=@var{address}
39313 A hexadecimal number specifying the address of the @samp{struct
39314 link_map} to start reading the library list from. If unset or zero
39315 then the first @samp{struct link_map} in the library list will be
39316 chosen as the starting point.
39317
39318 @item prev=@var{address}
39319 A hexadecimal number specifying the address of the @samp{struct
39320 link_map} immediately preceding the @samp{struct link_map}
39321 specified by the @samp{start} argument. If unset or zero then
39322 the remote stub will expect that no @samp{struct link_map}
39323 exists prior to the starting point.
39324
39325 @end table
39326
39327 Arguments that are not understood by the remote stub will be silently
39328 ignored.
39329
39330 @item qXfer:memory-map:read::@var{offset},@var{length}
39331 @anchor{qXfer memory map read}
39332 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
39333 annex part of the generic @samp{qXfer} packet must be empty
39334 (@pxref{qXfer read}).
39335
39336 This packet is not probed by default; the remote stub must request it,
39337 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39338
39339 @item qXfer:sdata:read::@var{offset},@var{length}
39340 @anchor{qXfer sdata read}
39341
39342 Read contents of the extra collected static tracepoint marker
39343 information. The annex part of the generic @samp{qXfer} packet must
39344 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
39345 Action Lists}.
39346
39347 This packet is not probed by default; the remote stub must request it,
39348 by supplying an appropriate @samp{qSupported} response
39349 (@pxref{qSupported}).
39350
39351 @item qXfer:siginfo:read::@var{offset},@var{length}
39352 @anchor{qXfer siginfo read}
39353 Read contents of the extra signal information on the target
39354 system. The annex part of the generic @samp{qXfer} packet must be
39355 empty (@pxref{qXfer read}).
39356
39357 This packet is not probed by default; the remote stub must request it,
39358 by supplying an appropriate @samp{qSupported} response
39359 (@pxref{qSupported}).
39360
39361 @item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
39362 @anchor{qXfer spu read}
39363 Read contents of an @code{spufs} file on the target system. The
39364 annex specifies which file to read; it must be of the form
39365 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
39366 in the target process, and @var{name} identifes the @code{spufs} file
39367 in that context to be accessed.
39368
39369 This packet is not probed by default; the remote stub must request it,
39370 by supplying an appropriate @samp{qSupported} response
39371 (@pxref{qSupported}).
39372
39373 @item qXfer:threads:read::@var{offset},@var{length}
39374 @anchor{qXfer threads read}
39375 Access the list of threads on target. @xref{Thread List Format}. The
39376 annex part of the generic @samp{qXfer} packet must be empty
39377 (@pxref{qXfer read}).
39378
39379 This packet is not probed by default; the remote stub must request it,
39380 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39381
39382 @item qXfer:traceframe-info:read::@var{offset},@var{length}
39383 @anchor{qXfer traceframe info read}
39384
39385 Return a description of the current traceframe's contents.
39386 @xref{Traceframe Info Format}. The annex part of the generic
39387 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
39388
39389 This packet is not probed by default; the remote stub must request it,
39390 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39391
39392 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
39393 @anchor{qXfer unwind info block}
39394
39395 Return the unwind information block for @var{pc}. This packet is used
39396 on OpenVMS/ia64 to ask the kernel unwind information.
39397
39398 This packet is not probed by default.
39399
39400 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
39401 @anchor{qXfer fdpic loadmap read}
39402 Read contents of @code{loadmap}s on the target system. The
39403 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
39404 executable @code{loadmap} or interpreter @code{loadmap} to read.
39405
39406 This packet is not probed by default; the remote stub must request it,
39407 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39408
39409 @item qXfer:osdata:read::@var{offset},@var{length}
39410 @anchor{qXfer osdata read}
39411 Access the target's @dfn{operating system information}.
39412 @xref{Operating System Information}.
39413
39414 @end table
39415
39416 Reply:
39417 @table @samp
39418 @item m @var{data}
39419 Data @var{data} (@pxref{Binary Data}) has been read from the
39420 target. There may be more data at a higher address (although
39421 it is permitted to return @samp{m} even for the last valid
39422 block of data, as long as at least one byte of data was read).
39423 @var{data} may have fewer bytes than the @var{length} in the
39424 request.
39425
39426 @item l @var{data}
39427 Data @var{data} (@pxref{Binary Data}) has been read from the target.
39428 There is no more data to be read. @var{data} may have fewer bytes
39429 than the @var{length} in the request.
39430
39431 @item l
39432 The @var{offset} in the request is at the end of the data.
39433 There is no more data to be read.
39434
39435 @item E00
39436 The request was malformed, or @var{annex} was invalid.
39437
39438 @item E @var{nn}
39439 The offset was invalid, or there was an error encountered reading the data.
39440 @var{nn} is a hex-encoded @code{errno} value.
39441
39442 @item @w{}
39443 An empty reply indicates the @var{object} string was not recognized by
39444 the stub, or that the object does not support reading.
39445 @end table
39446
39447 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
39448 @cindex write data into object, remote request
39449 @anchor{qXfer write}
39450 Write uninterpreted bytes into the target's special data area
39451 identified by the keyword @var{object}, starting at @var{offset} bytes
39452 into the data. @var{data}@dots{} is the binary-encoded data
39453 (@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
39454 is specific to @var{object}; it can supply additional details about what data
39455 to access.
39456
39457 Here are the specific requests of this form defined so far. All
39458 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
39459 formats, listed below.
39460
39461 @table @samp
39462 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
39463 @anchor{qXfer siginfo write}
39464 Write @var{data} to the extra signal information on the target system.
39465 The annex part of the generic @samp{qXfer} packet must be
39466 empty (@pxref{qXfer write}).
39467
39468 This packet is not probed by default; the remote stub must request it,
39469 by supplying an appropriate @samp{qSupported} response
39470 (@pxref{qSupported}).
39471
39472 @item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
39473 @anchor{qXfer spu write}
39474 Write @var{data} to an @code{spufs} file on the target system. The
39475 annex specifies which file to write; it must be of the form
39476 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
39477 in the target process, and @var{name} identifes the @code{spufs} file
39478 in that context to be accessed.
39479
39480 This packet is not probed by default; the remote stub must request it,
39481 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39482 @end table
39483
39484 Reply:
39485 @table @samp
39486 @item @var{nn}
39487 @var{nn} (hex encoded) is the number of bytes written.
39488 This may be fewer bytes than supplied in the request.
39489
39490 @item E00
39491 The request was malformed, or @var{annex} was invalid.
39492
39493 @item E @var{nn}
39494 The offset was invalid, or there was an error encountered writing the data.
39495 @var{nn} is a hex-encoded @code{errno} value.
39496
39497 @item @w{}
39498 An empty reply indicates the @var{object} string was not
39499 recognized by the stub, or that the object does not support writing.
39500 @end table
39501
39502 @item qXfer:@var{object}:@var{operation}:@dots{}
39503 Requests of this form may be added in the future. When a stub does
39504 not recognize the @var{object} keyword, or its support for
39505 @var{object} does not recognize the @var{operation} keyword, the stub
39506 must respond with an empty packet.
39507
39508 @item qAttached:@var{pid}
39509 @cindex query attached, remote request
39510 @cindex @samp{qAttached} packet
39511 Return an indication of whether the remote server attached to an
39512 existing process or created a new process. When the multiprocess
39513 protocol extensions are supported (@pxref{multiprocess extensions}),
39514 @var{pid} is an integer in hexadecimal format identifying the target
39515 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
39516 the query packet will be simplified as @samp{qAttached}.
39517
39518 This query is used, for example, to know whether the remote process
39519 should be detached or killed when a @value{GDBN} session is ended with
39520 the @code{quit} command.
39521
39522 Reply:
39523 @table @samp
39524 @item 1
39525 The remote server attached to an existing process.
39526 @item 0
39527 The remote server created a new process.
39528 @item E @var{NN}
39529 A badly formed request or an error was encountered.
39530 @end table
39531
39532 @item Qbtrace:bts
39533 Enable branch tracing for the current thread using bts tracing.
39534
39535 Reply:
39536 @table @samp
39537 @item OK
39538 Branch tracing has been enabled.
39539 @item E.errtext
39540 A badly formed request or an error was encountered.
39541 @end table
39542
39543 @item Qbtrace:off
39544 Disable branch tracing for the current thread.
39545
39546 Reply:
39547 @table @samp
39548 @item OK
39549 Branch tracing has been disabled.
39550 @item E.errtext
39551 A badly formed request or an error was encountered.
39552 @end table
39553
39554 @end table
39555
39556 @node Architecture-Specific Protocol Details
39557 @section Architecture-Specific Protocol Details
39558
39559 This section describes how the remote protocol is applied to specific
39560 target architectures. Also see @ref{Standard Target Features}, for
39561 details of XML target descriptions for each architecture.
39562
39563 @menu
39564 * ARM-Specific Protocol Details::
39565 * MIPS-Specific Protocol Details::
39566 @end menu
39567
39568 @node ARM-Specific Protocol Details
39569 @subsection @acronym{ARM}-specific Protocol Details
39570
39571 @menu
39572 * ARM Breakpoint Kinds::
39573 @end menu
39574
39575 @node ARM Breakpoint Kinds
39576 @subsubsection @acronym{ARM} Breakpoint Kinds
39577 @cindex breakpoint kinds, @acronym{ARM}
39578
39579 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
39580
39581 @table @r
39582
39583 @item 2
39584 16-bit Thumb mode breakpoint.
39585
39586 @item 3
39587 32-bit Thumb mode (Thumb-2) breakpoint.
39588
39589 @item 4
39590 32-bit @acronym{ARM} mode breakpoint.
39591
39592 @end table
39593
39594 @node MIPS-Specific Protocol Details
39595 @subsection @acronym{MIPS}-specific Protocol Details
39596
39597 @menu
39598 * MIPS Register packet Format::
39599 * MIPS Breakpoint Kinds::
39600 @end menu
39601
39602 @node MIPS Register packet Format
39603 @subsubsection @acronym{MIPS} Register Packet Format
39604 @cindex register packet format, @acronym{MIPS}
39605
39606 The following @code{g}/@code{G} packets have previously been defined.
39607 In the below, some thirty-two bit registers are transferred as
39608 sixty-four bits. Those registers should be zero/sign extended (which?)
39609 to fill the space allocated. Register bytes are transferred in target
39610 byte order. The two nibbles within a register byte are transferred
39611 most-significant -- least-significant.
39612
39613 @table @r
39614
39615 @item MIPS32
39616 All registers are transferred as thirty-two bit quantities in the order:
39617 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
39618 registers; fsr; fir; fp.
39619
39620 @item MIPS64
39621 All registers are transferred as sixty-four bit quantities (including
39622 thirty-two bit registers such as @code{sr}). The ordering is the same
39623 as @code{MIPS32}.
39624
39625 @end table
39626
39627 @node MIPS Breakpoint Kinds
39628 @subsubsection @acronym{MIPS} Breakpoint Kinds
39629 @cindex breakpoint kinds, @acronym{MIPS}
39630
39631 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
39632
39633 @table @r
39634
39635 @item 2
39636 16-bit @acronym{MIPS16} mode breakpoint.
39637
39638 @item 3
39639 16-bit @acronym{microMIPS} mode breakpoint.
39640
39641 @item 4
39642 32-bit standard @acronym{MIPS} mode breakpoint.
39643
39644 @item 5
39645 32-bit @acronym{microMIPS} mode breakpoint.
39646
39647 @end table
39648
39649 @node Tracepoint Packets
39650 @section Tracepoint Packets
39651 @cindex tracepoint packets
39652 @cindex packets, tracepoint
39653
39654 Here we describe the packets @value{GDBN} uses to implement
39655 tracepoints (@pxref{Tracepoints}).
39656
39657 @table @samp
39658
39659 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
39660 @cindex @samp{QTDP} packet
39661 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
39662 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
39663 the tracepoint is disabled. @var{step} is the tracepoint's step
39664 count, and @var{pass} is its pass count. If an @samp{F} is present,
39665 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
39666 the number of bytes that the target should copy elsewhere to make room
39667 for the tracepoint. If an @samp{X} is present, it introduces a
39668 tracepoint condition, which consists of a hexadecimal length, followed
39669 by a comma and hex-encoded bytes, in a manner similar to action
39670 encodings as described below. If the trailing @samp{-} is present,
39671 further @samp{QTDP} packets will follow to specify this tracepoint's
39672 actions.
39673
39674 Replies:
39675 @table @samp
39676 @item OK
39677 The packet was understood and carried out.
39678 @item qRelocInsn
39679 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
39680 @item @w{}
39681 The packet was not recognized.
39682 @end table
39683
39684 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
39685 Define actions to be taken when a tracepoint is hit. @var{n} and
39686 @var{addr} must be the same as in the initial @samp{QTDP} packet for
39687 this tracepoint. This packet may only be sent immediately after
39688 another @samp{QTDP} packet that ended with a @samp{-}. If the
39689 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
39690 specifying more actions for this tracepoint.
39691
39692 In the series of action packets for a given tracepoint, at most one
39693 can have an @samp{S} before its first @var{action}. If such a packet
39694 is sent, it and the following packets define ``while-stepping''
39695 actions. Any prior packets define ordinary actions --- that is, those
39696 taken when the tracepoint is first hit. If no action packet has an
39697 @samp{S}, then all the packets in the series specify ordinary
39698 tracepoint actions.
39699
39700 The @samp{@var{action}@dots{}} portion of the packet is a series of
39701 actions, concatenated without separators. Each action has one of the
39702 following forms:
39703
39704 @table @samp
39705
39706 @item R @var{mask}
39707 Collect the registers whose bits are set in @var{mask}. @var{mask} is
39708 a hexadecimal number whose @var{i}'th bit is set if register number
39709 @var{i} should be collected. (The least significant bit is numbered
39710 zero.) Note that @var{mask} may be any number of digits long; it may
39711 not fit in a 32-bit word.
39712
39713 @item M @var{basereg},@var{offset},@var{len}
39714 Collect @var{len} bytes of memory starting at the address in register
39715 number @var{basereg}, plus @var{offset}. If @var{basereg} is
39716 @samp{-1}, then the range has a fixed address: @var{offset} is the
39717 address of the lowest byte to collect. The @var{basereg},
39718 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
39719 values (the @samp{-1} value for @var{basereg} is a special case).
39720
39721 @item X @var{len},@var{expr}
39722 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
39723 it directs. @var{expr} is an agent expression, as described in
39724 @ref{Agent Expressions}. Each byte of the expression is encoded as a
39725 two-digit hex number in the packet; @var{len} is the number of bytes
39726 in the expression (and thus one-half the number of hex digits in the
39727 packet).
39728
39729 @end table
39730
39731 Any number of actions may be packed together in a single @samp{QTDP}
39732 packet, as long as the packet does not exceed the maximum packet
39733 length (400 bytes, for many stubs). There may be only one @samp{R}
39734 action per tracepoint, and it must precede any @samp{M} or @samp{X}
39735 actions. Any registers referred to by @samp{M} and @samp{X} actions
39736 must be collected by a preceding @samp{R} action. (The
39737 ``while-stepping'' actions are treated as if they were attached to a
39738 separate tracepoint, as far as these restrictions are concerned.)
39739
39740 Replies:
39741 @table @samp
39742 @item OK
39743 The packet was understood and carried out.
39744 @item qRelocInsn
39745 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
39746 @item @w{}
39747 The packet was not recognized.
39748 @end table
39749
39750 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
39751 @cindex @samp{QTDPsrc} packet
39752 Specify a source string of tracepoint @var{n} at address @var{addr}.
39753 This is useful to get accurate reproduction of the tracepoints
39754 originally downloaded at the beginning of the trace run. @var{type}
39755 is the name of the tracepoint part, such as @samp{cond} for the
39756 tracepoint's conditional expression (see below for a list of types), while
39757 @var{bytes} is the string, encoded in hexadecimal.
39758
39759 @var{start} is the offset of the @var{bytes} within the overall source
39760 string, while @var{slen} is the total length of the source string.
39761 This is intended for handling source strings that are longer than will
39762 fit in a single packet.
39763 @c Add detailed example when this info is moved into a dedicated
39764 @c tracepoint descriptions section.
39765
39766 The available string types are @samp{at} for the location,
39767 @samp{cond} for the conditional, and @samp{cmd} for an action command.
39768 @value{GDBN} sends a separate packet for each command in the action
39769 list, in the same order in which the commands are stored in the list.
39770
39771 The target does not need to do anything with source strings except
39772 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
39773 query packets.
39774
39775 Although this packet is optional, and @value{GDBN} will only send it
39776 if the target replies with @samp{TracepointSource} @xref{General
39777 Query Packets}, it makes both disconnected tracing and trace files
39778 much easier to use. Otherwise the user must be careful that the
39779 tracepoints in effect while looking at trace frames are identical to
39780 the ones in effect during the trace run; even a small discrepancy
39781 could cause @samp{tdump} not to work, or a particular trace frame not
39782 be found.
39783
39784 @item QTDV:@var{n}:@var{value}
39785 @cindex define trace state variable, remote request
39786 @cindex @samp{QTDV} packet
39787 Create a new trace state variable, number @var{n}, with an initial
39788 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
39789 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
39790 the option of not using this packet for initial values of zero; the
39791 target should simply create the trace state variables as they are
39792 mentioned in expressions.
39793
39794 @item QTFrame:@var{n}
39795 @cindex @samp{QTFrame} packet
39796 Select the @var{n}'th tracepoint frame from the buffer, and use the
39797 register and memory contents recorded there to answer subsequent
39798 request packets from @value{GDBN}.
39799
39800 A successful reply from the stub indicates that the stub has found the
39801 requested frame. The response is a series of parts, concatenated
39802 without separators, describing the frame we selected. Each part has
39803 one of the following forms:
39804
39805 @table @samp
39806 @item F @var{f}
39807 The selected frame is number @var{n} in the trace frame buffer;
39808 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
39809 was no frame matching the criteria in the request packet.
39810
39811 @item T @var{t}
39812 The selected trace frame records a hit of tracepoint number @var{t};
39813 @var{t} is a hexadecimal number.
39814
39815 @end table
39816
39817 @item QTFrame:pc:@var{addr}
39818 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
39819 currently selected frame whose PC is @var{addr};
39820 @var{addr} is a hexadecimal number.
39821
39822 @item QTFrame:tdp:@var{t}
39823 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
39824 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
39825 is a hexadecimal number.
39826
39827 @item QTFrame:range:@var{start}:@var{end}
39828 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
39829 currently selected frame whose PC is between @var{start} (inclusive)
39830 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
39831 numbers.
39832
39833 @item QTFrame:outside:@var{start}:@var{end}
39834 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
39835 frame @emph{outside} the given range of addresses (exclusive).
39836
39837 @item qTMinFTPILen
39838 @cindex @samp{qTMinFTPILen} packet
39839 This packet requests the minimum length of instruction at which a fast
39840 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
39841 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
39842 it depends on the target system being able to create trampolines in
39843 the first 64K of memory, which might or might not be possible for that
39844 system. So the reply to this packet will be 4 if it is able to
39845 arrange for that.
39846
39847 Replies:
39848
39849 @table @samp
39850 @item 0
39851 The minimum instruction length is currently unknown.
39852 @item @var{length}
39853 The minimum instruction length is @var{length}, where @var{length} is greater
39854 or equal to 1. @var{length} is a hexadecimal number. A reply of 1 means
39855 that a fast tracepoint may be placed on any instruction regardless of size.
39856 @item E
39857 An error has occurred.
39858 @item @w{}
39859 An empty reply indicates that the request is not supported by the stub.
39860 @end table
39861
39862 @item QTStart
39863 @cindex @samp{QTStart} packet
39864 Begin the tracepoint experiment. Begin collecting data from
39865 tracepoint hits in the trace frame buffer. This packet supports the
39866 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
39867 instruction reply packet}).
39868
39869 @item QTStop
39870 @cindex @samp{QTStop} packet
39871 End the tracepoint experiment. Stop collecting trace frames.
39872
39873 @item QTEnable:@var{n}:@var{addr}
39874 @anchor{QTEnable}
39875 @cindex @samp{QTEnable} packet
39876 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
39877 experiment. If the tracepoint was previously disabled, then collection
39878 of data from it will resume.
39879
39880 @item QTDisable:@var{n}:@var{addr}
39881 @anchor{QTDisable}
39882 @cindex @samp{QTDisable} packet
39883 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
39884 experiment. No more data will be collected from the tracepoint unless
39885 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
39886
39887 @item QTinit
39888 @cindex @samp{QTinit} packet
39889 Clear the table of tracepoints, and empty the trace frame buffer.
39890
39891 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
39892 @cindex @samp{QTro} packet
39893 Establish the given ranges of memory as ``transparent''. The stub
39894 will answer requests for these ranges from memory's current contents,
39895 if they were not collected as part of the tracepoint hit.
39896
39897 @value{GDBN} uses this to mark read-only regions of memory, like those
39898 containing program code. Since these areas never change, they should
39899 still have the same contents they did when the tracepoint was hit, so
39900 there's no reason for the stub to refuse to provide their contents.
39901
39902 @item QTDisconnected:@var{value}
39903 @cindex @samp{QTDisconnected} packet
39904 Set the choice to what to do with the tracing run when @value{GDBN}
39905 disconnects from the target. A @var{value} of 1 directs the target to
39906 continue the tracing run, while 0 tells the target to stop tracing if
39907 @value{GDBN} is no longer in the picture.
39908
39909 @item qTStatus
39910 @cindex @samp{qTStatus} packet
39911 Ask the stub if there is a trace experiment running right now.
39912
39913 The reply has the form:
39914
39915 @table @samp
39916
39917 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
39918 @var{running} is a single digit @code{1} if the trace is presently
39919 running, or @code{0} if not. It is followed by semicolon-separated
39920 optional fields that an agent may use to report additional status.
39921
39922 @end table
39923
39924 If the trace is not running, the agent may report any of several
39925 explanations as one of the optional fields:
39926
39927 @table @samp
39928
39929 @item tnotrun:0
39930 No trace has been run yet.
39931
39932 @item tstop[:@var{text}]:0
39933 The trace was stopped by a user-originated stop command. The optional
39934 @var{text} field is a user-supplied string supplied as part of the
39935 stop command (for instance, an explanation of why the trace was
39936 stopped manually). It is hex-encoded.
39937
39938 @item tfull:0
39939 The trace stopped because the trace buffer filled up.
39940
39941 @item tdisconnected:0
39942 The trace stopped because @value{GDBN} disconnected from the target.
39943
39944 @item tpasscount:@var{tpnum}
39945 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
39946
39947 @item terror:@var{text}:@var{tpnum}
39948 The trace stopped because tracepoint @var{tpnum} had an error. The
39949 string @var{text} is available to describe the nature of the error
39950 (for instance, a divide by zero in the condition expression).
39951 @var{text} is hex encoded.
39952
39953 @item tunknown:0
39954 The trace stopped for some other reason.
39955
39956 @end table
39957
39958 Additional optional fields supply statistical and other information.
39959 Although not required, they are extremely useful for users monitoring
39960 the progress of a trace run. If a trace has stopped, and these
39961 numbers are reported, they must reflect the state of the just-stopped
39962 trace.
39963
39964 @table @samp
39965
39966 @item tframes:@var{n}
39967 The number of trace frames in the buffer.
39968
39969 @item tcreated:@var{n}
39970 The total number of trace frames created during the run. This may
39971 be larger than the trace frame count, if the buffer is circular.
39972
39973 @item tsize:@var{n}
39974 The total size of the trace buffer, in bytes.
39975
39976 @item tfree:@var{n}
39977 The number of bytes still unused in the buffer.
39978
39979 @item circular:@var{n}
39980 The value of the circular trace buffer flag. @code{1} means that the
39981 trace buffer is circular and old trace frames will be discarded if
39982 necessary to make room, @code{0} means that the trace buffer is linear
39983 and may fill up.
39984
39985 @item disconn:@var{n}
39986 The value of the disconnected tracing flag. @code{1} means that
39987 tracing will continue after @value{GDBN} disconnects, @code{0} means
39988 that the trace run will stop.
39989
39990 @end table
39991
39992 @item qTP:@var{tp}:@var{addr}
39993 @cindex tracepoint status, remote request
39994 @cindex @samp{qTP} packet
39995 Ask the stub for the current state of tracepoint number @var{tp} at
39996 address @var{addr}.
39997
39998 Replies:
39999 @table @samp
40000 @item V@var{hits}:@var{usage}
40001 The tracepoint has been hit @var{hits} times so far during the trace
40002 run, and accounts for @var{usage} in the trace buffer. Note that
40003 @code{while-stepping} steps are not counted as separate hits, but the
40004 steps' space consumption is added into the usage number.
40005
40006 @end table
40007
40008 @item qTV:@var{var}
40009 @cindex trace state variable value, remote request
40010 @cindex @samp{qTV} packet
40011 Ask the stub for the value of the trace state variable number @var{var}.
40012
40013 Replies:
40014 @table @samp
40015 @item V@var{value}
40016 The value of the variable is @var{value}. This will be the current
40017 value of the variable if the user is examining a running target, or a
40018 saved value if the variable was collected in the trace frame that the
40019 user is looking at. Note that multiple requests may result in
40020 different reply values, such as when requesting values while the
40021 program is running.
40022
40023 @item U
40024 The value of the variable is unknown. This would occur, for example,
40025 if the user is examining a trace frame in which the requested variable
40026 was not collected.
40027 @end table
40028
40029 @item qTfP
40030 @cindex @samp{qTfP} packet
40031 @itemx qTsP
40032 @cindex @samp{qTsP} packet
40033 These packets request data about tracepoints that are being used by
40034 the target. @value{GDBN} sends @code{qTfP} to get the first piece
40035 of data, and multiple @code{qTsP} to get additional pieces. Replies
40036 to these packets generally take the form of the @code{QTDP} packets
40037 that define tracepoints. (FIXME add detailed syntax)
40038
40039 @item qTfV
40040 @cindex @samp{qTfV} packet
40041 @itemx qTsV
40042 @cindex @samp{qTsV} packet
40043 These packets request data about trace state variables that are on the
40044 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
40045 and multiple @code{qTsV} to get additional variables. Replies to
40046 these packets follow the syntax of the @code{QTDV} packets that define
40047 trace state variables.
40048
40049 @item qTfSTM
40050 @itemx qTsSTM
40051 @anchor{qTfSTM}
40052 @anchor{qTsSTM}
40053 @cindex @samp{qTfSTM} packet
40054 @cindex @samp{qTsSTM} packet
40055 These packets request data about static tracepoint markers that exist
40056 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
40057 first piece of data, and multiple @code{qTsSTM} to get additional
40058 pieces. Replies to these packets take the following form:
40059
40060 Reply:
40061 @table @samp
40062 @item m @var{address}:@var{id}:@var{extra}
40063 A single marker
40064 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
40065 a comma-separated list of markers
40066 @item l
40067 (lower case letter @samp{L}) denotes end of list.
40068 @item E @var{nn}
40069 An error occurred. @var{nn} are hex digits.
40070 @item @w{}
40071 An empty reply indicates that the request is not supported by the
40072 stub.
40073 @end table
40074
40075 @var{address} is encoded in hex.
40076 @var{id} and @var{extra} are strings encoded in hex.
40077
40078 In response to each query, the target will reply with a list of one or
40079 more markers, separated by commas. @value{GDBN} will respond to each
40080 reply with a request for more markers (using the @samp{qs} form of the
40081 query), until the target responds with @samp{l} (lower-case ell, for
40082 @dfn{last}).
40083
40084 @item qTSTMat:@var{address}
40085 @anchor{qTSTMat}
40086 @cindex @samp{qTSTMat} packet
40087 This packets requests data about static tracepoint markers in the
40088 target program at @var{address}. Replies to this packet follow the
40089 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
40090 tracepoint markers.
40091
40092 @item QTSave:@var{filename}
40093 @cindex @samp{QTSave} packet
40094 This packet directs the target to save trace data to the file name
40095 @var{filename} in the target's filesystem. @var{filename} is encoded
40096 as a hex string; the interpretation of the file name (relative vs
40097 absolute, wild cards, etc) is up to the target.
40098
40099 @item qTBuffer:@var{offset},@var{len}
40100 @cindex @samp{qTBuffer} packet
40101 Return up to @var{len} bytes of the current contents of trace buffer,
40102 starting at @var{offset}. The trace buffer is treated as if it were
40103 a contiguous collection of traceframes, as per the trace file format.
40104 The reply consists as many hex-encoded bytes as the target can deliver
40105 in a packet; it is not an error to return fewer than were asked for.
40106 A reply consisting of just @code{l} indicates that no bytes are
40107 available.
40108
40109 @item QTBuffer:circular:@var{value}
40110 This packet directs the target to use a circular trace buffer if
40111 @var{value} is 1, or a linear buffer if the value is 0.
40112
40113 @item QTBuffer:size:@var{size}
40114 @anchor{QTBuffer-size}
40115 @cindex @samp{QTBuffer size} packet
40116 This packet directs the target to make the trace buffer be of size
40117 @var{size} if possible. A value of @code{-1} tells the target to
40118 use whatever size it prefers.
40119
40120 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
40121 @cindex @samp{QTNotes} packet
40122 This packet adds optional textual notes to the trace run. Allowable
40123 types include @code{user}, @code{notes}, and @code{tstop}, the
40124 @var{text} fields are arbitrary strings, hex-encoded.
40125
40126 @end table
40127
40128 @subsection Relocate instruction reply packet
40129 When installing fast tracepoints in memory, the target may need to
40130 relocate the instruction currently at the tracepoint address to a
40131 different address in memory. For most instructions, a simple copy is
40132 enough, but, for example, call instructions that implicitly push the
40133 return address on the stack, and relative branches or other
40134 PC-relative instructions require offset adjustment, so that the effect
40135 of executing the instruction at a different address is the same as if
40136 it had executed in the original location.
40137
40138 In response to several of the tracepoint packets, the target may also
40139 respond with a number of intermediate @samp{qRelocInsn} request
40140 packets before the final result packet, to have @value{GDBN} handle
40141 this relocation operation. If a packet supports this mechanism, its
40142 documentation will explicitly say so. See for example the above
40143 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
40144 format of the request is:
40145
40146 @table @samp
40147 @item qRelocInsn:@var{from};@var{to}
40148
40149 This requests @value{GDBN} to copy instruction at address @var{from}
40150 to address @var{to}, possibly adjusted so that executing the
40151 instruction at @var{to} has the same effect as executing it at
40152 @var{from}. @value{GDBN} writes the adjusted instruction to target
40153 memory starting at @var{to}.
40154 @end table
40155
40156 Replies:
40157 @table @samp
40158 @item qRelocInsn:@var{adjusted_size}
40159 Informs the stub the relocation is complete. @var{adjusted_size} is
40160 the length in bytes of resulting relocated instruction sequence.
40161 @item E @var{NN}
40162 A badly formed request was detected, or an error was encountered while
40163 relocating the instruction.
40164 @end table
40165
40166 @node Host I/O Packets
40167 @section Host I/O Packets
40168 @cindex Host I/O, remote protocol
40169 @cindex file transfer, remote protocol
40170
40171 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
40172 operations on the far side of a remote link. For example, Host I/O is
40173 used to upload and download files to a remote target with its own
40174 filesystem. Host I/O uses the same constant values and data structure
40175 layout as the target-initiated File-I/O protocol. However, the
40176 Host I/O packets are structured differently. The target-initiated
40177 protocol relies on target memory to store parameters and buffers.
40178 Host I/O requests are initiated by @value{GDBN}, and the
40179 target's memory is not involved. @xref{File-I/O Remote Protocol
40180 Extension}, for more details on the target-initiated protocol.
40181
40182 The Host I/O request packets all encode a single operation along with
40183 its arguments. They have this format:
40184
40185 @table @samp
40186
40187 @item vFile:@var{operation}: @var{parameter}@dots{}
40188 @var{operation} is the name of the particular request; the target
40189 should compare the entire packet name up to the second colon when checking
40190 for a supported operation. The format of @var{parameter} depends on
40191 the operation. Numbers are always passed in hexadecimal. Negative
40192 numbers have an explicit minus sign (i.e.@: two's complement is not
40193 used). Strings (e.g.@: filenames) are encoded as a series of
40194 hexadecimal bytes. The last argument to a system call may be a
40195 buffer of escaped binary data (@pxref{Binary Data}).
40196
40197 @end table
40198
40199 The valid responses to Host I/O packets are:
40200
40201 @table @samp
40202
40203 @item F @var{result} [, @var{errno}] [; @var{attachment}]
40204 @var{result} is the integer value returned by this operation, usually
40205 non-negative for success and -1 for errors. If an error has occured,
40206 @var{errno} will be included in the result. @var{errno} will have a
40207 value defined by the File-I/O protocol (@pxref{Errno Values}). For
40208 operations which return data, @var{attachment} supplies the data as a
40209 binary buffer. Binary buffers in response packets are escaped in the
40210 normal way (@pxref{Binary Data}). See the individual packet
40211 documentation for the interpretation of @var{result} and
40212 @var{attachment}.
40213
40214 @item @w{}
40215 An empty response indicates that this operation is not recognized.
40216
40217 @end table
40218
40219 These are the supported Host I/O operations:
40220
40221 @table @samp
40222 @item vFile:open: @var{pathname}, @var{flags}, @var{mode}
40223 Open a file at @var{pathname} and return a file descriptor for it, or
40224 return -1 if an error occurs. @var{pathname} is a string,
40225 @var{flags} is an integer indicating a mask of open flags
40226 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
40227 of mode bits to use if the file is created (@pxref{mode_t Values}).
40228 @xref{open}, for details of the open flags and mode values.
40229
40230 @item vFile:close: @var{fd}
40231 Close the open file corresponding to @var{fd} and return 0, or
40232 -1 if an error occurs.
40233
40234 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
40235 Read data from the open file corresponding to @var{fd}. Up to
40236 @var{count} bytes will be read from the file, starting at @var{offset}
40237 relative to the start of the file. The target may read fewer bytes;
40238 common reasons include packet size limits and an end-of-file
40239 condition. The number of bytes read is returned. Zero should only be
40240 returned for a successful read at the end of the file, or if
40241 @var{count} was zero.
40242
40243 The data read should be returned as a binary attachment on success.
40244 If zero bytes were read, the response should include an empty binary
40245 attachment (i.e.@: a trailing semicolon). The return value is the
40246 number of target bytes read; the binary attachment may be longer if
40247 some characters were escaped.
40248
40249 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
40250 Write @var{data} (a binary buffer) to the open file corresponding
40251 to @var{fd}. Start the write at @var{offset} from the start of the
40252 file. Unlike many @code{write} system calls, there is no
40253 separate @var{count} argument; the length of @var{data} in the
40254 packet is used. @samp{vFile:write} returns the number of bytes written,
40255 which may be shorter than the length of @var{data}, or -1 if an
40256 error occurred.
40257
40258 @item vFile:unlink: @var{pathname}
40259 Delete the file at @var{pathname} on the target. Return 0,
40260 or -1 if an error occurs. @var{pathname} is a string.
40261
40262 @item vFile:readlink: @var{filename}
40263 Read value of symbolic link @var{filename} on the target. Return
40264 the number of bytes read, or -1 if an error occurs.
40265
40266 The data read should be returned as a binary attachment on success.
40267 If zero bytes were read, the response should include an empty binary
40268 attachment (i.e.@: a trailing semicolon). The return value is the
40269 number of target bytes read; the binary attachment may be longer if
40270 some characters were escaped.
40271
40272 @end table
40273
40274 @node Interrupts
40275 @section Interrupts
40276 @cindex interrupts (remote protocol)
40277
40278 When a program on the remote target is running, @value{GDBN} may
40279 attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
40280 a @code{BREAK} followed by @code{g},
40281 control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
40282
40283 The precise meaning of @code{BREAK} is defined by the transport
40284 mechanism and may, in fact, be undefined. @value{GDBN} does not
40285 currently define a @code{BREAK} mechanism for any of the network
40286 interfaces except for TCP, in which case @value{GDBN} sends the
40287 @code{telnet} BREAK sequence.
40288
40289 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
40290 transport mechanisms. It is represented by sending the single byte
40291 @code{0x03} without any of the usual packet overhead described in
40292 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
40293 transmitted as part of a packet, it is considered to be packet data
40294 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
40295 (@pxref{X packet}), used for binary downloads, may include an unescaped
40296 @code{0x03} as part of its packet.
40297
40298 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
40299 When Linux kernel receives this sequence from serial port,
40300 it stops execution and connects to gdb.
40301
40302 Stubs are not required to recognize these interrupt mechanisms and the
40303 precise meaning associated with receipt of the interrupt is
40304 implementation defined. If the target supports debugging of multiple
40305 threads and/or processes, it should attempt to interrupt all
40306 currently-executing threads and processes.
40307 If the stub is successful at interrupting the
40308 running program, it should send one of the stop
40309 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
40310 of successfully stopping the program in all-stop mode, and a stop reply
40311 for each stopped thread in non-stop mode.
40312 Interrupts received while the
40313 program is stopped are discarded.
40314
40315 @node Notification Packets
40316 @section Notification Packets
40317 @cindex notification packets
40318 @cindex packets, notification
40319
40320 The @value{GDBN} remote serial protocol includes @dfn{notifications},
40321 packets that require no acknowledgment. Both the GDB and the stub
40322 may send notifications (although the only notifications defined at
40323 present are sent by the stub). Notifications carry information
40324 without incurring the round-trip latency of an acknowledgment, and so
40325 are useful for low-impact communications where occasional packet loss
40326 is not a problem.
40327
40328 A notification packet has the form @samp{% @var{data} #
40329 @var{checksum}}, where @var{data} is the content of the notification,
40330 and @var{checksum} is a checksum of @var{data}, computed and formatted
40331 as for ordinary @value{GDBN} packets. A notification's @var{data}
40332 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
40333 receiving a notification, the recipient sends no @samp{+} or @samp{-}
40334 to acknowledge the notification's receipt or to report its corruption.
40335
40336 Every notification's @var{data} begins with a name, which contains no
40337 colon characters, followed by a colon character.
40338
40339 Recipients should silently ignore corrupted notifications and
40340 notifications they do not understand. Recipients should restart
40341 timeout periods on receipt of a well-formed notification, whether or
40342 not they understand it.
40343
40344 Senders should only send the notifications described here when this
40345 protocol description specifies that they are permitted. In the
40346 future, we may extend the protocol to permit existing notifications in
40347 new contexts; this rule helps older senders avoid confusing newer
40348 recipients.
40349
40350 (Older versions of @value{GDBN} ignore bytes received until they see
40351 the @samp{$} byte that begins an ordinary packet, so new stubs may
40352 transmit notifications without fear of confusing older clients. There
40353 are no notifications defined for @value{GDBN} to send at the moment, but we
40354 assume that most older stubs would ignore them, as well.)
40355
40356 Each notification is comprised of three parts:
40357 @table @samp
40358 @item @var{name}:@var{event}
40359 The notification packet is sent by the side that initiates the
40360 exchange (currently, only the stub does that), with @var{event}
40361 carrying the specific information about the notification.
40362 @var{name} is the name of the notification.
40363 @item @var{ack}
40364 The acknowledge sent by the other side, usually @value{GDBN}, to
40365 acknowledge the exchange and request the event.
40366 @end table
40367
40368 The purpose of an asynchronous notification mechanism is to report to
40369 @value{GDBN} that something interesting happened in the remote stub.
40370
40371 The remote stub may send notification @var{name}:@var{event}
40372 at any time, but @value{GDBN} acknowledges the notification when
40373 appropriate. The notification event is pending before @value{GDBN}
40374 acknowledges. Only one notification at a time may be pending; if
40375 additional events occur before @value{GDBN} has acknowledged the
40376 previous notification, they must be queued by the stub for later
40377 synchronous transmission in response to @var{ack} packets from
40378 @value{GDBN}. Because the notification mechanism is unreliable,
40379 the stub is permitted to resend a notification if it believes
40380 @value{GDBN} may not have received it.
40381
40382 Specifically, notifications may appear when @value{GDBN} is not
40383 otherwise reading input from the stub, or when @value{GDBN} is
40384 expecting to read a normal synchronous response or a
40385 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
40386 Notification packets are distinct from any other communication from
40387 the stub so there is no ambiguity.
40388
40389 After receiving a notification, @value{GDBN} shall acknowledge it by
40390 sending a @var{ack} packet as a regular, synchronous request to the
40391 stub. Such acknowledgment is not required to happen immediately, as
40392 @value{GDBN} is permitted to send other, unrelated packets to the
40393 stub first, which the stub should process normally.
40394
40395 Upon receiving a @var{ack} packet, if the stub has other queued
40396 events to report to @value{GDBN}, it shall respond by sending a
40397 normal @var{event}. @value{GDBN} shall then send another @var{ack}
40398 packet to solicit further responses; again, it is permitted to send
40399 other, unrelated packets as well which the stub should process
40400 normally.
40401
40402 If the stub receives a @var{ack} packet and there are no additional
40403 @var{event} to report, the stub shall return an @samp{OK} response.
40404 At this point, @value{GDBN} has finished processing a notification
40405 and the stub has completed sending any queued events. @value{GDBN}
40406 won't accept any new notifications until the final @samp{OK} is
40407 received . If further notification events occur, the stub shall send
40408 a new notification, @value{GDBN} shall accept the notification, and
40409 the process shall be repeated.
40410
40411 The process of asynchronous notification can be illustrated by the
40412 following example:
40413 @smallexample
40414 <- @code{%%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
40415 @code{...}
40416 -> @code{vStopped}
40417 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
40418 -> @code{vStopped}
40419 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
40420 -> @code{vStopped}
40421 <- @code{OK}
40422 @end smallexample
40423
40424 The following notifications are defined:
40425 @multitable @columnfractions 0.12 0.12 0.38 0.38
40426
40427 @item Notification
40428 @tab Ack
40429 @tab Event
40430 @tab Description
40431
40432 @item Stop
40433 @tab vStopped
40434 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
40435 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
40436 for information on how these notifications are acknowledged by
40437 @value{GDBN}.
40438 @tab Report an asynchronous stop event in non-stop mode.
40439
40440 @end multitable
40441
40442 @node Remote Non-Stop
40443 @section Remote Protocol Support for Non-Stop Mode
40444
40445 @value{GDBN}'s remote protocol supports non-stop debugging of
40446 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
40447 supports non-stop mode, it should report that to @value{GDBN} by including
40448 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
40449
40450 @value{GDBN} typically sends a @samp{QNonStop} packet only when
40451 establishing a new connection with the stub. Entering non-stop mode
40452 does not alter the state of any currently-running threads, but targets
40453 must stop all threads in any already-attached processes when entering
40454 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
40455 probe the target state after a mode change.
40456
40457 In non-stop mode, when an attached process encounters an event that
40458 would otherwise be reported with a stop reply, it uses the
40459 asynchronous notification mechanism (@pxref{Notification Packets}) to
40460 inform @value{GDBN}. In contrast to all-stop mode, where all threads
40461 in all processes are stopped when a stop reply is sent, in non-stop
40462 mode only the thread reporting the stop event is stopped. That is,
40463 when reporting a @samp{S} or @samp{T} response to indicate completion
40464 of a step operation, hitting a breakpoint, or a fault, only the
40465 affected thread is stopped; any other still-running threads continue
40466 to run. When reporting a @samp{W} or @samp{X} response, all running
40467 threads belonging to other attached processes continue to run.
40468
40469 In non-stop mode, the target shall respond to the @samp{?} packet as
40470 follows. First, any incomplete stop reply notification/@samp{vStopped}
40471 sequence in progress is abandoned. The target must begin a new
40472 sequence reporting stop events for all stopped threads, whether or not
40473 it has previously reported those events to @value{GDBN}. The first
40474 stop reply is sent as a synchronous reply to the @samp{?} packet, and
40475 subsequent stop replies are sent as responses to @samp{vStopped} packets
40476 using the mechanism described above. The target must not send
40477 asynchronous stop reply notifications until the sequence is complete.
40478 If all threads are running when the target receives the @samp{?} packet,
40479 or if the target is not attached to any process, it shall respond
40480 @samp{OK}.
40481
40482 @node Packet Acknowledgment
40483 @section Packet Acknowledgment
40484
40485 @cindex acknowledgment, for @value{GDBN} remote
40486 @cindex packet acknowledgment, for @value{GDBN} remote
40487 By default, when either the host or the target machine receives a packet,
40488 the first response expected is an acknowledgment: either @samp{+} (to indicate
40489 the package was received correctly) or @samp{-} (to request retransmission).
40490 This mechanism allows the @value{GDBN} remote protocol to operate over
40491 unreliable transport mechanisms, such as a serial line.
40492
40493 In cases where the transport mechanism is itself reliable (such as a pipe or
40494 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
40495 It may be desirable to disable them in that case to reduce communication
40496 overhead, or for other reasons. This can be accomplished by means of the
40497 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
40498
40499 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
40500 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
40501 and response format still includes the normal checksum, as described in
40502 @ref{Overview}, but the checksum may be ignored by the receiver.
40503
40504 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
40505 no-acknowledgment mode, it should report that to @value{GDBN}
40506 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
40507 @pxref{qSupported}.
40508 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
40509 disabled via the @code{set remote noack-packet off} command
40510 (@pxref{Remote Configuration}),
40511 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
40512 Only then may the stub actually turn off packet acknowledgments.
40513 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
40514 response, which can be safely ignored by the stub.
40515
40516 Note that @code{set remote noack-packet} command only affects negotiation
40517 between @value{GDBN} and the stub when subsequent connections are made;
40518 it does not affect the protocol acknowledgment state for any current
40519 connection.
40520 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
40521 new connection is established,
40522 there is also no protocol request to re-enable the acknowledgments
40523 for the current connection, once disabled.
40524
40525 @node Examples
40526 @section Examples
40527
40528 Example sequence of a target being re-started. Notice how the restart
40529 does not get any direct output:
40530
40531 @smallexample
40532 -> @code{R00}
40533 <- @code{+}
40534 @emph{target restarts}
40535 -> @code{?}
40536 <- @code{+}
40537 <- @code{T001:1234123412341234}
40538 -> @code{+}
40539 @end smallexample
40540
40541 Example sequence of a target being stepped by a single instruction:
40542
40543 @smallexample
40544 -> @code{G1445@dots{}}
40545 <- @code{+}
40546 -> @code{s}
40547 <- @code{+}
40548 @emph{time passes}
40549 <- @code{T001:1234123412341234}
40550 -> @code{+}
40551 -> @code{g}
40552 <- @code{+}
40553 <- @code{1455@dots{}}
40554 -> @code{+}
40555 @end smallexample
40556
40557 @node File-I/O Remote Protocol Extension
40558 @section File-I/O Remote Protocol Extension
40559 @cindex File-I/O remote protocol extension
40560
40561 @menu
40562 * File-I/O Overview::
40563 * Protocol Basics::
40564 * The F Request Packet::
40565 * The F Reply Packet::
40566 * The Ctrl-C Message::
40567 * Console I/O::
40568 * List of Supported Calls::
40569 * Protocol-specific Representation of Datatypes::
40570 * Constants::
40571 * File-I/O Examples::
40572 @end menu
40573
40574 @node File-I/O Overview
40575 @subsection File-I/O Overview
40576 @cindex file-i/o overview
40577
40578 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
40579 target to use the host's file system and console I/O to perform various
40580 system calls. System calls on the target system are translated into a
40581 remote protocol packet to the host system, which then performs the needed
40582 actions and returns a response packet to the target system.
40583 This simulates file system operations even on targets that lack file systems.
40584
40585 The protocol is defined to be independent of both the host and target systems.
40586 It uses its own internal representation of datatypes and values. Both
40587 @value{GDBN} and the target's @value{GDBN} stub are responsible for
40588 translating the system-dependent value representations into the internal
40589 protocol representations when data is transmitted.
40590
40591 The communication is synchronous. A system call is possible only when
40592 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
40593 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
40594 the target is stopped to allow deterministic access to the target's
40595 memory. Therefore File-I/O is not interruptible by target signals. On
40596 the other hand, it is possible to interrupt File-I/O by a user interrupt
40597 (@samp{Ctrl-C}) within @value{GDBN}.
40598
40599 The target's request to perform a host system call does not finish
40600 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
40601 after finishing the system call, the target returns to continuing the
40602 previous activity (continue, step). No additional continue or step
40603 request from @value{GDBN} is required.
40604
40605 @smallexample
40606 (@value{GDBP}) continue
40607 <- target requests 'system call X'
40608 target is stopped, @value{GDBN} executes system call
40609 -> @value{GDBN} returns result
40610 ... target continues, @value{GDBN} returns to wait for the target
40611 <- target hits breakpoint and sends a Txx packet
40612 @end smallexample
40613
40614 The protocol only supports I/O on the console and to regular files on
40615 the host file system. Character or block special devices, pipes,
40616 named pipes, sockets or any other communication method on the host
40617 system are not supported by this protocol.
40618
40619 File I/O is not supported in non-stop mode.
40620
40621 @node Protocol Basics
40622 @subsection Protocol Basics
40623 @cindex protocol basics, file-i/o
40624
40625 The File-I/O protocol uses the @code{F} packet as the request as well
40626 as reply packet. Since a File-I/O system call can only occur when
40627 @value{GDBN} is waiting for a response from the continuing or stepping target,
40628 the File-I/O request is a reply that @value{GDBN} has to expect as a result
40629 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
40630 This @code{F} packet contains all information needed to allow @value{GDBN}
40631 to call the appropriate host system call:
40632
40633 @itemize @bullet
40634 @item
40635 A unique identifier for the requested system call.
40636
40637 @item
40638 All parameters to the system call. Pointers are given as addresses
40639 in the target memory address space. Pointers to strings are given as
40640 pointer/length pair. Numerical values are given as they are.
40641 Numerical control flags are given in a protocol-specific representation.
40642
40643 @end itemize
40644
40645 At this point, @value{GDBN} has to perform the following actions.
40646
40647 @itemize @bullet
40648 @item
40649 If the parameters include pointer values to data needed as input to a
40650 system call, @value{GDBN} requests this data from the target with a
40651 standard @code{m} packet request. This additional communication has to be
40652 expected by the target implementation and is handled as any other @code{m}
40653 packet.
40654
40655 @item
40656 @value{GDBN} translates all value from protocol representation to host
40657 representation as needed. Datatypes are coerced into the host types.
40658
40659 @item
40660 @value{GDBN} calls the system call.
40661
40662 @item
40663 It then coerces datatypes back to protocol representation.
40664
40665 @item
40666 If the system call is expected to return data in buffer space specified
40667 by pointer parameters to the call, the data is transmitted to the
40668 target using a @code{M} or @code{X} packet. This packet has to be expected
40669 by the target implementation and is handled as any other @code{M} or @code{X}
40670 packet.
40671
40672 @end itemize
40673
40674 Eventually @value{GDBN} replies with another @code{F} packet which contains all
40675 necessary information for the target to continue. This at least contains
40676
40677 @itemize @bullet
40678 @item
40679 Return value.
40680
40681 @item
40682 @code{errno}, if has been changed by the system call.
40683
40684 @item
40685 ``Ctrl-C'' flag.
40686
40687 @end itemize
40688
40689 After having done the needed type and value coercion, the target continues
40690 the latest continue or step action.
40691
40692 @node The F Request Packet
40693 @subsection The @code{F} Request Packet
40694 @cindex file-i/o request packet
40695 @cindex @code{F} request packet
40696
40697 The @code{F} request packet has the following format:
40698
40699 @table @samp
40700 @item F@var{call-id},@var{parameter@dots{}}
40701
40702 @var{call-id} is the identifier to indicate the host system call to be called.
40703 This is just the name of the function.
40704
40705 @var{parameter@dots{}} are the parameters to the system call.
40706 Parameters are hexadecimal integer values, either the actual values in case
40707 of scalar datatypes, pointers to target buffer space in case of compound
40708 datatypes and unspecified memory areas, or pointer/length pairs in case
40709 of string parameters. These are appended to the @var{call-id} as a
40710 comma-delimited list. All values are transmitted in ASCII
40711 string representation, pointer/length pairs separated by a slash.
40712
40713 @end table
40714
40715
40716
40717 @node The F Reply Packet
40718 @subsection The @code{F} Reply Packet
40719 @cindex file-i/o reply packet
40720 @cindex @code{F} reply packet
40721
40722 The @code{F} reply packet has the following format:
40723
40724 @table @samp
40725
40726 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
40727
40728 @var{retcode} is the return code of the system call as hexadecimal value.
40729
40730 @var{errno} is the @code{errno} set by the call, in protocol-specific
40731 representation.
40732 This parameter can be omitted if the call was successful.
40733
40734 @var{Ctrl-C flag} is only sent if the user requested a break. In this
40735 case, @var{errno} must be sent as well, even if the call was successful.
40736 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
40737
40738 @smallexample
40739 F0,0,C
40740 @end smallexample
40741
40742 @noindent
40743 or, if the call was interrupted before the host call has been performed:
40744
40745 @smallexample
40746 F-1,4,C
40747 @end smallexample
40748
40749 @noindent
40750 assuming 4 is the protocol-specific representation of @code{EINTR}.
40751
40752 @end table
40753
40754
40755 @node The Ctrl-C Message
40756 @subsection The @samp{Ctrl-C} Message
40757 @cindex ctrl-c message, in file-i/o protocol
40758
40759 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
40760 reply packet (@pxref{The F Reply Packet}),
40761 the target should behave as if it had
40762 gotten a break message. The meaning for the target is ``system call
40763 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
40764 (as with a break message) and return to @value{GDBN} with a @code{T02}
40765 packet.
40766
40767 It's important for the target to know in which
40768 state the system call was interrupted. There are two possible cases:
40769
40770 @itemize @bullet
40771 @item
40772 The system call hasn't been performed on the host yet.
40773
40774 @item
40775 The system call on the host has been finished.
40776
40777 @end itemize
40778
40779 These two states can be distinguished by the target by the value of the
40780 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
40781 call hasn't been performed. This is equivalent to the @code{EINTR} handling
40782 on POSIX systems. In any other case, the target may presume that the
40783 system call has been finished --- successfully or not --- and should behave
40784 as if the break message arrived right after the system call.
40785
40786 @value{GDBN} must behave reliably. If the system call has not been called
40787 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
40788 @code{errno} in the packet. If the system call on the host has been finished
40789 before the user requests a break, the full action must be finished by
40790 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
40791 The @code{F} packet may only be sent when either nothing has happened
40792 or the full action has been completed.
40793
40794 @node Console I/O
40795 @subsection Console I/O
40796 @cindex console i/o as part of file-i/o
40797
40798 By default and if not explicitly closed by the target system, the file
40799 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
40800 on the @value{GDBN} console is handled as any other file output operation
40801 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
40802 by @value{GDBN} so that after the target read request from file descriptor
40803 0 all following typing is buffered until either one of the following
40804 conditions is met:
40805
40806 @itemize @bullet
40807 @item
40808 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
40809 @code{read}
40810 system call is treated as finished.
40811
40812 @item
40813 The user presses @key{RET}. This is treated as end of input with a trailing
40814 newline.
40815
40816 @item
40817 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
40818 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
40819
40820 @end itemize
40821
40822 If the user has typed more characters than fit in the buffer given to
40823 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
40824 either another @code{read(0, @dots{})} is requested by the target, or debugging
40825 is stopped at the user's request.
40826
40827
40828 @node List of Supported Calls
40829 @subsection List of Supported Calls
40830 @cindex list of supported file-i/o calls
40831
40832 @menu
40833 * open::
40834 * close::
40835 * read::
40836 * write::
40837 * lseek::
40838 * rename::
40839 * unlink::
40840 * stat/fstat::
40841 * gettimeofday::
40842 * isatty::
40843 * system::
40844 @end menu
40845
40846 @node open
40847 @unnumberedsubsubsec open
40848 @cindex open, file-i/o system call
40849
40850 @table @asis
40851 @item Synopsis:
40852 @smallexample
40853 int open(const char *pathname, int flags);
40854 int open(const char *pathname, int flags, mode_t mode);
40855 @end smallexample
40856
40857 @item Request:
40858 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
40859
40860 @noindent
40861 @var{flags} is the bitwise @code{OR} of the following values:
40862
40863 @table @code
40864 @item O_CREAT
40865 If the file does not exist it will be created. The host
40866 rules apply as far as file ownership and time stamps
40867 are concerned.
40868
40869 @item O_EXCL
40870 When used with @code{O_CREAT}, if the file already exists it is
40871 an error and open() fails.
40872
40873 @item O_TRUNC
40874 If the file already exists and the open mode allows
40875 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
40876 truncated to zero length.
40877
40878 @item O_APPEND
40879 The file is opened in append mode.
40880
40881 @item O_RDONLY
40882 The file is opened for reading only.
40883
40884 @item O_WRONLY
40885 The file is opened for writing only.
40886
40887 @item O_RDWR
40888 The file is opened for reading and writing.
40889 @end table
40890
40891 @noindent
40892 Other bits are silently ignored.
40893
40894
40895 @noindent
40896 @var{mode} is the bitwise @code{OR} of the following values:
40897
40898 @table @code
40899 @item S_IRUSR
40900 User has read permission.
40901
40902 @item S_IWUSR
40903 User has write permission.
40904
40905 @item S_IRGRP
40906 Group has read permission.
40907
40908 @item S_IWGRP
40909 Group has write permission.
40910
40911 @item S_IROTH
40912 Others have read permission.
40913
40914 @item S_IWOTH
40915 Others have write permission.
40916 @end table
40917
40918 @noindent
40919 Other bits are silently ignored.
40920
40921
40922 @item Return value:
40923 @code{open} returns the new file descriptor or -1 if an error
40924 occurred.
40925
40926 @item Errors:
40927
40928 @table @code
40929 @item EEXIST
40930 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
40931
40932 @item EISDIR
40933 @var{pathname} refers to a directory.
40934
40935 @item EACCES
40936 The requested access is not allowed.
40937
40938 @item ENAMETOOLONG
40939 @var{pathname} was too long.
40940
40941 @item ENOENT
40942 A directory component in @var{pathname} does not exist.
40943
40944 @item ENODEV
40945 @var{pathname} refers to a device, pipe, named pipe or socket.
40946
40947 @item EROFS
40948 @var{pathname} refers to a file on a read-only filesystem and
40949 write access was requested.
40950
40951 @item EFAULT
40952 @var{pathname} is an invalid pointer value.
40953
40954 @item ENOSPC
40955 No space on device to create the file.
40956
40957 @item EMFILE
40958 The process already has the maximum number of files open.
40959
40960 @item ENFILE
40961 The limit on the total number of files open on the system
40962 has been reached.
40963
40964 @item EINTR
40965 The call was interrupted by the user.
40966 @end table
40967
40968 @end table
40969
40970 @node close
40971 @unnumberedsubsubsec close
40972 @cindex close, file-i/o system call
40973
40974 @table @asis
40975 @item Synopsis:
40976 @smallexample
40977 int close(int fd);
40978 @end smallexample
40979
40980 @item Request:
40981 @samp{Fclose,@var{fd}}
40982
40983 @item Return value:
40984 @code{close} returns zero on success, or -1 if an error occurred.
40985
40986 @item Errors:
40987
40988 @table @code
40989 @item EBADF
40990 @var{fd} isn't a valid open file descriptor.
40991
40992 @item EINTR
40993 The call was interrupted by the user.
40994 @end table
40995
40996 @end table
40997
40998 @node read
40999 @unnumberedsubsubsec read
41000 @cindex read, file-i/o system call
41001
41002 @table @asis
41003 @item Synopsis:
41004 @smallexample
41005 int read(int fd, void *buf, unsigned int count);
41006 @end smallexample
41007
41008 @item Request:
41009 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
41010
41011 @item Return value:
41012 On success, the number of bytes read is returned.
41013 Zero indicates end of file. If count is zero, read
41014 returns zero as well. On error, -1 is returned.
41015
41016 @item Errors:
41017
41018 @table @code
41019 @item EBADF
41020 @var{fd} is not a valid file descriptor or is not open for
41021 reading.
41022
41023 @item EFAULT
41024 @var{bufptr} is an invalid pointer value.
41025
41026 @item EINTR
41027 The call was interrupted by the user.
41028 @end table
41029
41030 @end table
41031
41032 @node write
41033 @unnumberedsubsubsec write
41034 @cindex write, file-i/o system call
41035
41036 @table @asis
41037 @item Synopsis:
41038 @smallexample
41039 int write(int fd, const void *buf, unsigned int count);
41040 @end smallexample
41041
41042 @item Request:
41043 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
41044
41045 @item Return value:
41046 On success, the number of bytes written are returned.
41047 Zero indicates nothing was written. On error, -1
41048 is returned.
41049
41050 @item Errors:
41051
41052 @table @code
41053 @item EBADF
41054 @var{fd} is not a valid file descriptor or is not open for
41055 writing.
41056
41057 @item EFAULT
41058 @var{bufptr} is an invalid pointer value.
41059
41060 @item EFBIG
41061 An attempt was made to write a file that exceeds the
41062 host-specific maximum file size allowed.
41063
41064 @item ENOSPC
41065 No space on device to write the data.
41066
41067 @item EINTR
41068 The call was interrupted by the user.
41069 @end table
41070
41071 @end table
41072
41073 @node lseek
41074 @unnumberedsubsubsec lseek
41075 @cindex lseek, file-i/o system call
41076
41077 @table @asis
41078 @item Synopsis:
41079 @smallexample
41080 long lseek (int fd, long offset, int flag);
41081 @end smallexample
41082
41083 @item Request:
41084 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
41085
41086 @var{flag} is one of:
41087
41088 @table @code
41089 @item SEEK_SET
41090 The offset is set to @var{offset} bytes.
41091
41092 @item SEEK_CUR
41093 The offset is set to its current location plus @var{offset}
41094 bytes.
41095
41096 @item SEEK_END
41097 The offset is set to the size of the file plus @var{offset}
41098 bytes.
41099 @end table
41100
41101 @item Return value:
41102 On success, the resulting unsigned offset in bytes from
41103 the beginning of the file is returned. Otherwise, a
41104 value of -1 is returned.
41105
41106 @item Errors:
41107
41108 @table @code
41109 @item EBADF
41110 @var{fd} is not a valid open file descriptor.
41111
41112 @item ESPIPE
41113 @var{fd} is associated with the @value{GDBN} console.
41114
41115 @item EINVAL
41116 @var{flag} is not a proper value.
41117
41118 @item EINTR
41119 The call was interrupted by the user.
41120 @end table
41121
41122 @end table
41123
41124 @node rename
41125 @unnumberedsubsubsec rename
41126 @cindex rename, file-i/o system call
41127
41128 @table @asis
41129 @item Synopsis:
41130 @smallexample
41131 int rename(const char *oldpath, const char *newpath);
41132 @end smallexample
41133
41134 @item Request:
41135 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
41136
41137 @item Return value:
41138 On success, zero is returned. On error, -1 is returned.
41139
41140 @item Errors:
41141
41142 @table @code
41143 @item EISDIR
41144 @var{newpath} is an existing directory, but @var{oldpath} is not a
41145 directory.
41146
41147 @item EEXIST
41148 @var{newpath} is a non-empty directory.
41149
41150 @item EBUSY
41151 @var{oldpath} or @var{newpath} is a directory that is in use by some
41152 process.
41153
41154 @item EINVAL
41155 An attempt was made to make a directory a subdirectory
41156 of itself.
41157
41158 @item ENOTDIR
41159 A component used as a directory in @var{oldpath} or new
41160 path is not a directory. Or @var{oldpath} is a directory
41161 and @var{newpath} exists but is not a directory.
41162
41163 @item EFAULT
41164 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
41165
41166 @item EACCES
41167 No access to the file or the path of the file.
41168
41169 @item ENAMETOOLONG
41170
41171 @var{oldpath} or @var{newpath} was too long.
41172
41173 @item ENOENT
41174 A directory component in @var{oldpath} or @var{newpath} does not exist.
41175
41176 @item EROFS
41177 The file is on a read-only filesystem.
41178
41179 @item ENOSPC
41180 The device containing the file has no room for the new
41181 directory entry.
41182
41183 @item EINTR
41184 The call was interrupted by the user.
41185 @end table
41186
41187 @end table
41188
41189 @node unlink
41190 @unnumberedsubsubsec unlink
41191 @cindex unlink, file-i/o system call
41192
41193 @table @asis
41194 @item Synopsis:
41195 @smallexample
41196 int unlink(const char *pathname);
41197 @end smallexample
41198
41199 @item Request:
41200 @samp{Funlink,@var{pathnameptr}/@var{len}}
41201
41202 @item Return value:
41203 On success, zero is returned. On error, -1 is returned.
41204
41205 @item Errors:
41206
41207 @table @code
41208 @item EACCES
41209 No access to the file or the path of the file.
41210
41211 @item EPERM
41212 The system does not allow unlinking of directories.
41213
41214 @item EBUSY
41215 The file @var{pathname} cannot be unlinked because it's
41216 being used by another process.
41217
41218 @item EFAULT
41219 @var{pathnameptr} is an invalid pointer value.
41220
41221 @item ENAMETOOLONG
41222 @var{pathname} was too long.
41223
41224 @item ENOENT
41225 A directory component in @var{pathname} does not exist.
41226
41227 @item ENOTDIR
41228 A component of the path is not a directory.
41229
41230 @item EROFS
41231 The file is on a read-only filesystem.
41232
41233 @item EINTR
41234 The call was interrupted by the user.
41235 @end table
41236
41237 @end table
41238
41239 @node stat/fstat
41240 @unnumberedsubsubsec stat/fstat
41241 @cindex fstat, file-i/o system call
41242 @cindex stat, file-i/o system call
41243
41244 @table @asis
41245 @item Synopsis:
41246 @smallexample
41247 int stat(const char *pathname, struct stat *buf);
41248 int fstat(int fd, struct stat *buf);
41249 @end smallexample
41250
41251 @item Request:
41252 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
41253 @samp{Ffstat,@var{fd},@var{bufptr}}
41254
41255 @item Return value:
41256 On success, zero is returned. On error, -1 is returned.
41257
41258 @item Errors:
41259
41260 @table @code
41261 @item EBADF
41262 @var{fd} is not a valid open file.
41263
41264 @item ENOENT
41265 A directory component in @var{pathname} does not exist or the
41266 path is an empty string.
41267
41268 @item ENOTDIR
41269 A component of the path is not a directory.
41270
41271 @item EFAULT
41272 @var{pathnameptr} is an invalid pointer value.
41273
41274 @item EACCES
41275 No access to the file or the path of the file.
41276
41277 @item ENAMETOOLONG
41278 @var{pathname} was too long.
41279
41280 @item EINTR
41281 The call was interrupted by the user.
41282 @end table
41283
41284 @end table
41285
41286 @node gettimeofday
41287 @unnumberedsubsubsec gettimeofday
41288 @cindex gettimeofday, file-i/o system call
41289
41290 @table @asis
41291 @item Synopsis:
41292 @smallexample
41293 int gettimeofday(struct timeval *tv, void *tz);
41294 @end smallexample
41295
41296 @item Request:
41297 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
41298
41299 @item Return value:
41300 On success, 0 is returned, -1 otherwise.
41301
41302 @item Errors:
41303
41304 @table @code
41305 @item EINVAL
41306 @var{tz} is a non-NULL pointer.
41307
41308 @item EFAULT
41309 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
41310 @end table
41311
41312 @end table
41313
41314 @node isatty
41315 @unnumberedsubsubsec isatty
41316 @cindex isatty, file-i/o system call
41317
41318 @table @asis
41319 @item Synopsis:
41320 @smallexample
41321 int isatty(int fd);
41322 @end smallexample
41323
41324 @item Request:
41325 @samp{Fisatty,@var{fd}}
41326
41327 @item Return value:
41328 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
41329
41330 @item Errors:
41331
41332 @table @code
41333 @item EINTR
41334 The call was interrupted by the user.
41335 @end table
41336
41337 @end table
41338
41339 Note that the @code{isatty} call is treated as a special case: it returns
41340 1 to the target if the file descriptor is attached
41341 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
41342 would require implementing @code{ioctl} and would be more complex than
41343 needed.
41344
41345
41346 @node system
41347 @unnumberedsubsubsec system
41348 @cindex system, file-i/o system call
41349
41350 @table @asis
41351 @item Synopsis:
41352 @smallexample
41353 int system(const char *command);
41354 @end smallexample
41355
41356 @item Request:
41357 @samp{Fsystem,@var{commandptr}/@var{len}}
41358
41359 @item Return value:
41360 If @var{len} is zero, the return value indicates whether a shell is
41361 available. A zero return value indicates a shell is not available.
41362 For non-zero @var{len}, the value returned is -1 on error and the
41363 return status of the command otherwise. Only the exit status of the
41364 command is returned, which is extracted from the host's @code{system}
41365 return value by calling @code{WEXITSTATUS(retval)}. In case
41366 @file{/bin/sh} could not be executed, 127 is returned.
41367
41368 @item Errors:
41369
41370 @table @code
41371 @item EINTR
41372 The call was interrupted by the user.
41373 @end table
41374
41375 @end table
41376
41377 @value{GDBN} takes over the full task of calling the necessary host calls
41378 to perform the @code{system} call. The return value of @code{system} on
41379 the host is simplified before it's returned
41380 to the target. Any termination signal information from the child process
41381 is discarded, and the return value consists
41382 entirely of the exit status of the called command.
41383
41384 Due to security concerns, the @code{system} call is by default refused
41385 by @value{GDBN}. The user has to allow this call explicitly with the
41386 @code{set remote system-call-allowed 1} command.
41387
41388 @table @code
41389 @item set remote system-call-allowed
41390 @kindex set remote system-call-allowed
41391 Control whether to allow the @code{system} calls in the File I/O
41392 protocol for the remote target. The default is zero (disabled).
41393
41394 @item show remote system-call-allowed
41395 @kindex show remote system-call-allowed
41396 Show whether the @code{system} calls are allowed in the File I/O
41397 protocol.
41398 @end table
41399
41400 @node Protocol-specific Representation of Datatypes
41401 @subsection Protocol-specific Representation of Datatypes
41402 @cindex protocol-specific representation of datatypes, in file-i/o protocol
41403
41404 @menu
41405 * Integral Datatypes::
41406 * Pointer Values::
41407 * Memory Transfer::
41408 * struct stat::
41409 * struct timeval::
41410 @end menu
41411
41412 @node Integral Datatypes
41413 @unnumberedsubsubsec Integral Datatypes
41414 @cindex integral datatypes, in file-i/o protocol
41415
41416 The integral datatypes used in the system calls are @code{int},
41417 @code{unsigned int}, @code{long}, @code{unsigned long},
41418 @code{mode_t}, and @code{time_t}.
41419
41420 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
41421 implemented as 32 bit values in this protocol.
41422
41423 @code{long} and @code{unsigned long} are implemented as 64 bit types.
41424
41425 @xref{Limits}, for corresponding MIN and MAX values (similar to those
41426 in @file{limits.h}) to allow range checking on host and target.
41427
41428 @code{time_t} datatypes are defined as seconds since the Epoch.
41429
41430 All integral datatypes transferred as part of a memory read or write of a
41431 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
41432 byte order.
41433
41434 @node Pointer Values
41435 @unnumberedsubsubsec Pointer Values
41436 @cindex pointer values, in file-i/o protocol
41437
41438 Pointers to target data are transmitted as they are. An exception
41439 is made for pointers to buffers for which the length isn't
41440 transmitted as part of the function call, namely strings. Strings
41441 are transmitted as a pointer/length pair, both as hex values, e.g.@:
41442
41443 @smallexample
41444 @code{1aaf/12}
41445 @end smallexample
41446
41447 @noindent
41448 which is a pointer to data of length 18 bytes at position 0x1aaf.
41449 The length is defined as the full string length in bytes, including
41450 the trailing null byte. For example, the string @code{"hello world"}
41451 at address 0x123456 is transmitted as
41452
41453 @smallexample
41454 @code{123456/d}
41455 @end smallexample
41456
41457 @node Memory Transfer
41458 @unnumberedsubsubsec Memory Transfer
41459 @cindex memory transfer, in file-i/o protocol
41460
41461 Structured data which is transferred using a memory read or write (for
41462 example, a @code{struct stat}) is expected to be in a protocol-specific format
41463 with all scalar multibyte datatypes being big endian. Translation to
41464 this representation needs to be done both by the target before the @code{F}
41465 packet is sent, and by @value{GDBN} before
41466 it transfers memory to the target. Transferred pointers to structured
41467 data should point to the already-coerced data at any time.
41468
41469
41470 @node struct stat
41471 @unnumberedsubsubsec struct stat
41472 @cindex struct stat, in file-i/o protocol
41473
41474 The buffer of type @code{struct stat} used by the target and @value{GDBN}
41475 is defined as follows:
41476
41477 @smallexample
41478 struct stat @{
41479 unsigned int st_dev; /* device */
41480 unsigned int st_ino; /* inode */
41481 mode_t st_mode; /* protection */
41482 unsigned int st_nlink; /* number of hard links */
41483 unsigned int st_uid; /* user ID of owner */
41484 unsigned int st_gid; /* group ID of owner */
41485 unsigned int st_rdev; /* device type (if inode device) */
41486 unsigned long st_size; /* total size, in bytes */
41487 unsigned long st_blksize; /* blocksize for filesystem I/O */
41488 unsigned long st_blocks; /* number of blocks allocated */
41489 time_t st_atime; /* time of last access */
41490 time_t st_mtime; /* time of last modification */
41491 time_t st_ctime; /* time of last change */
41492 @};
41493 @end smallexample
41494
41495 The integral datatypes conform to the definitions given in the
41496 appropriate section (see @ref{Integral Datatypes}, for details) so this
41497 structure is of size 64 bytes.
41498
41499 The values of several fields have a restricted meaning and/or
41500 range of values.
41501
41502 @table @code
41503
41504 @item st_dev
41505 A value of 0 represents a file, 1 the console.
41506
41507 @item st_ino
41508 No valid meaning for the target. Transmitted unchanged.
41509
41510 @item st_mode
41511 Valid mode bits are described in @ref{Constants}. Any other
41512 bits have currently no meaning for the target.
41513
41514 @item st_uid
41515 @itemx st_gid
41516 @itemx st_rdev
41517 No valid meaning for the target. Transmitted unchanged.
41518
41519 @item st_atime
41520 @itemx st_mtime
41521 @itemx st_ctime
41522 These values have a host and file system dependent
41523 accuracy. Especially on Windows hosts, the file system may not
41524 support exact timing values.
41525 @end table
41526
41527 The target gets a @code{struct stat} of the above representation and is
41528 responsible for coercing it to the target representation before
41529 continuing.
41530
41531 Note that due to size differences between the host, target, and protocol
41532 representations of @code{struct stat} members, these members could eventually
41533 get truncated on the target.
41534
41535 @node struct timeval
41536 @unnumberedsubsubsec struct timeval
41537 @cindex struct timeval, in file-i/o protocol
41538
41539 The buffer of type @code{struct timeval} used by the File-I/O protocol
41540 is defined as follows:
41541
41542 @smallexample
41543 struct timeval @{
41544 time_t tv_sec; /* second */
41545 long tv_usec; /* microsecond */
41546 @};
41547 @end smallexample
41548
41549 The integral datatypes conform to the definitions given in the
41550 appropriate section (see @ref{Integral Datatypes}, for details) so this
41551 structure is of size 8 bytes.
41552
41553 @node Constants
41554 @subsection Constants
41555 @cindex constants, in file-i/o protocol
41556
41557 The following values are used for the constants inside of the
41558 protocol. @value{GDBN} and target are responsible for translating these
41559 values before and after the call as needed.
41560
41561 @menu
41562 * Open Flags::
41563 * mode_t Values::
41564 * Errno Values::
41565 * Lseek Flags::
41566 * Limits::
41567 @end menu
41568
41569 @node Open Flags
41570 @unnumberedsubsubsec Open Flags
41571 @cindex open flags, in file-i/o protocol
41572
41573 All values are given in hexadecimal representation.
41574
41575 @smallexample
41576 O_RDONLY 0x0
41577 O_WRONLY 0x1
41578 O_RDWR 0x2
41579 O_APPEND 0x8
41580 O_CREAT 0x200
41581 O_TRUNC 0x400
41582 O_EXCL 0x800
41583 @end smallexample
41584
41585 @node mode_t Values
41586 @unnumberedsubsubsec mode_t Values
41587 @cindex mode_t values, in file-i/o protocol
41588
41589 All values are given in octal representation.
41590
41591 @smallexample
41592 S_IFREG 0100000
41593 S_IFDIR 040000
41594 S_IRUSR 0400
41595 S_IWUSR 0200
41596 S_IXUSR 0100
41597 S_IRGRP 040
41598 S_IWGRP 020
41599 S_IXGRP 010
41600 S_IROTH 04
41601 S_IWOTH 02
41602 S_IXOTH 01
41603 @end smallexample
41604
41605 @node Errno Values
41606 @unnumberedsubsubsec Errno Values
41607 @cindex errno values, in file-i/o protocol
41608
41609 All values are given in decimal representation.
41610
41611 @smallexample
41612 EPERM 1
41613 ENOENT 2
41614 EINTR 4
41615 EBADF 9
41616 EACCES 13
41617 EFAULT 14
41618 EBUSY 16
41619 EEXIST 17
41620 ENODEV 19
41621 ENOTDIR 20
41622 EISDIR 21
41623 EINVAL 22
41624 ENFILE 23
41625 EMFILE 24
41626 EFBIG 27
41627 ENOSPC 28
41628 ESPIPE 29
41629 EROFS 30
41630 ENAMETOOLONG 91
41631 EUNKNOWN 9999
41632 @end smallexample
41633
41634 @code{EUNKNOWN} is used as a fallback error value if a host system returns
41635 any error value not in the list of supported error numbers.
41636
41637 @node Lseek Flags
41638 @unnumberedsubsubsec Lseek Flags
41639 @cindex lseek flags, in file-i/o protocol
41640
41641 @smallexample
41642 SEEK_SET 0
41643 SEEK_CUR 1
41644 SEEK_END 2
41645 @end smallexample
41646
41647 @node Limits
41648 @unnumberedsubsubsec Limits
41649 @cindex limits, in file-i/o protocol
41650
41651 All values are given in decimal representation.
41652
41653 @smallexample
41654 INT_MIN -2147483648
41655 INT_MAX 2147483647
41656 UINT_MAX 4294967295
41657 LONG_MIN -9223372036854775808
41658 LONG_MAX 9223372036854775807
41659 ULONG_MAX 18446744073709551615
41660 @end smallexample
41661
41662 @node File-I/O Examples
41663 @subsection File-I/O Examples
41664 @cindex file-i/o examples
41665
41666 Example sequence of a write call, file descriptor 3, buffer is at target
41667 address 0x1234, 6 bytes should be written:
41668
41669 @smallexample
41670 <- @code{Fwrite,3,1234,6}
41671 @emph{request memory read from target}
41672 -> @code{m1234,6}
41673 <- XXXXXX
41674 @emph{return "6 bytes written"}
41675 -> @code{F6}
41676 @end smallexample
41677
41678 Example sequence of a read call, file descriptor 3, buffer is at target
41679 address 0x1234, 6 bytes should be read:
41680
41681 @smallexample
41682 <- @code{Fread,3,1234,6}
41683 @emph{request memory write to target}
41684 -> @code{X1234,6:XXXXXX}
41685 @emph{return "6 bytes read"}
41686 -> @code{F6}
41687 @end smallexample
41688
41689 Example sequence of a read call, call fails on the host due to invalid
41690 file descriptor (@code{EBADF}):
41691
41692 @smallexample
41693 <- @code{Fread,3,1234,6}
41694 -> @code{F-1,9}
41695 @end smallexample
41696
41697 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
41698 host is called:
41699
41700 @smallexample
41701 <- @code{Fread,3,1234,6}
41702 -> @code{F-1,4,C}
41703 <- @code{T02}
41704 @end smallexample
41705
41706 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
41707 host is called:
41708
41709 @smallexample
41710 <- @code{Fread,3,1234,6}
41711 -> @code{X1234,6:XXXXXX}
41712 <- @code{T02}
41713 @end smallexample
41714
41715 @node Library List Format
41716 @section Library List Format
41717 @cindex library list format, remote protocol
41718
41719 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
41720 same process as your application to manage libraries. In this case,
41721 @value{GDBN} can use the loader's symbol table and normal memory
41722 operations to maintain a list of shared libraries. On other
41723 platforms, the operating system manages loaded libraries.
41724 @value{GDBN} can not retrieve the list of currently loaded libraries
41725 through memory operations, so it uses the @samp{qXfer:libraries:read}
41726 packet (@pxref{qXfer library list read}) instead. The remote stub
41727 queries the target's operating system and reports which libraries
41728 are loaded.
41729
41730 The @samp{qXfer:libraries:read} packet returns an XML document which
41731 lists loaded libraries and their offsets. Each library has an
41732 associated name and one or more segment or section base addresses,
41733 which report where the library was loaded in memory.
41734
41735 For the common case of libraries that are fully linked binaries, the
41736 library should have a list of segments. If the target supports
41737 dynamic linking of a relocatable object file, its library XML element
41738 should instead include a list of allocated sections. The segment or
41739 section bases are start addresses, not relocation offsets; they do not
41740 depend on the library's link-time base addresses.
41741
41742 @value{GDBN} must be linked with the Expat library to support XML
41743 library lists. @xref{Expat}.
41744
41745 A simple memory map, with one loaded library relocated by a single
41746 offset, looks like this:
41747
41748 @smallexample
41749 <library-list>
41750 <library name="/lib/libc.so.6">
41751 <segment address="0x10000000"/>
41752 </library>
41753 </library-list>
41754 @end smallexample
41755
41756 Another simple memory map, with one loaded library with three
41757 allocated sections (.text, .data, .bss), looks like this:
41758
41759 @smallexample
41760 <library-list>
41761 <library name="sharedlib.o">
41762 <section address="0x10000000"/>
41763 <section address="0x20000000"/>
41764 <section address="0x30000000"/>
41765 </library>
41766 </library-list>
41767 @end smallexample
41768
41769 The format of a library list is described by this DTD:
41770
41771 @smallexample
41772 <!-- library-list: Root element with versioning -->
41773 <!ELEMENT library-list (library)*>
41774 <!ATTLIST library-list version CDATA #FIXED "1.0">
41775 <!ELEMENT library (segment*, section*)>
41776 <!ATTLIST library name CDATA #REQUIRED>
41777 <!ELEMENT segment EMPTY>
41778 <!ATTLIST segment address CDATA #REQUIRED>
41779 <!ELEMENT section EMPTY>
41780 <!ATTLIST section address CDATA #REQUIRED>
41781 @end smallexample
41782
41783 In addition, segments and section descriptors cannot be mixed within a
41784 single library element, and you must supply at least one segment or
41785 section for each library.
41786
41787 @node Library List Format for SVR4 Targets
41788 @section Library List Format for SVR4 Targets
41789 @cindex library list format, remote protocol
41790
41791 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
41792 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
41793 shared libraries. Still a special library list provided by this packet is
41794 more efficient for the @value{GDBN} remote protocol.
41795
41796 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
41797 loaded libraries and their SVR4 linker parameters. For each library on SVR4
41798 target, the following parameters are reported:
41799
41800 @itemize @minus
41801 @item
41802 @code{name}, the absolute file name from the @code{l_name} field of
41803 @code{struct link_map}.
41804 @item
41805 @code{lm} with address of @code{struct link_map} used for TLS
41806 (Thread Local Storage) access.
41807 @item
41808 @code{l_addr}, the displacement as read from the field @code{l_addr} of
41809 @code{struct link_map}. For prelinked libraries this is not an absolute
41810 memory address. It is a displacement of absolute memory address against
41811 address the file was prelinked to during the library load.
41812 @item
41813 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
41814 @end itemize
41815
41816 Additionally the single @code{main-lm} attribute specifies address of
41817 @code{struct link_map} used for the main executable. This parameter is used
41818 for TLS access and its presence is optional.
41819
41820 @value{GDBN} must be linked with the Expat library to support XML
41821 SVR4 library lists. @xref{Expat}.
41822
41823 A simple memory map, with two loaded libraries (which do not use prelink),
41824 looks like this:
41825
41826 @smallexample
41827 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
41828 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
41829 l_ld="0xe4eefc"/>
41830 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
41831 l_ld="0x152350"/>
41832 </library-list-svr>
41833 @end smallexample
41834
41835 The format of an SVR4 library list is described by this DTD:
41836
41837 @smallexample
41838 <!-- library-list-svr4: Root element with versioning -->
41839 <!ELEMENT library-list-svr4 (library)*>
41840 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
41841 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
41842 <!ELEMENT library EMPTY>
41843 <!ATTLIST library name CDATA #REQUIRED>
41844 <!ATTLIST library lm CDATA #REQUIRED>
41845 <!ATTLIST library l_addr CDATA #REQUIRED>
41846 <!ATTLIST library l_ld CDATA #REQUIRED>
41847 @end smallexample
41848
41849 @node Memory Map Format
41850 @section Memory Map Format
41851 @cindex memory map format
41852
41853 To be able to write into flash memory, @value{GDBN} needs to obtain a
41854 memory map from the target. This section describes the format of the
41855 memory map.
41856
41857 The memory map is obtained using the @samp{qXfer:memory-map:read}
41858 (@pxref{qXfer memory map read}) packet and is an XML document that
41859 lists memory regions.
41860
41861 @value{GDBN} must be linked with the Expat library to support XML
41862 memory maps. @xref{Expat}.
41863
41864 The top-level structure of the document is shown below:
41865
41866 @smallexample
41867 <?xml version="1.0"?>
41868 <!DOCTYPE memory-map
41869 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
41870 "http://sourceware.org/gdb/gdb-memory-map.dtd">
41871 <memory-map>
41872 region...
41873 </memory-map>
41874 @end smallexample
41875
41876 Each region can be either:
41877
41878 @itemize
41879
41880 @item
41881 A region of RAM starting at @var{addr} and extending for @var{length}
41882 bytes from there:
41883
41884 @smallexample
41885 <memory type="ram" start="@var{addr}" length="@var{length}"/>
41886 @end smallexample
41887
41888
41889 @item
41890 A region of read-only memory:
41891
41892 @smallexample
41893 <memory type="rom" start="@var{addr}" length="@var{length}"/>
41894 @end smallexample
41895
41896
41897 @item
41898 A region of flash memory, with erasure blocks @var{blocksize}
41899 bytes in length:
41900
41901 @smallexample
41902 <memory type="flash" start="@var{addr}" length="@var{length}">
41903 <property name="blocksize">@var{blocksize}</property>
41904 </memory>
41905 @end smallexample
41906
41907 @end itemize
41908
41909 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
41910 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
41911 packets to write to addresses in such ranges.
41912
41913 The formal DTD for memory map format is given below:
41914
41915 @smallexample
41916 <!-- ................................................... -->
41917 <!-- Memory Map XML DTD ................................ -->
41918 <!-- File: memory-map.dtd .............................. -->
41919 <!-- .................................... .............. -->
41920 <!-- memory-map.dtd -->
41921 <!-- memory-map: Root element with versioning -->
41922 <!ELEMENT memory-map (memory | property)>
41923 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
41924 <!ELEMENT memory (property)>
41925 <!-- memory: Specifies a memory region,
41926 and its type, or device. -->
41927 <!ATTLIST memory type CDATA #REQUIRED
41928 start CDATA #REQUIRED
41929 length CDATA #REQUIRED
41930 device CDATA #IMPLIED>
41931 <!-- property: Generic attribute tag -->
41932 <!ELEMENT property (#PCDATA | property)*>
41933 <!ATTLIST property name CDATA #REQUIRED>
41934 @end smallexample
41935
41936 @node Thread List Format
41937 @section Thread List Format
41938 @cindex thread list format
41939
41940 To efficiently update the list of threads and their attributes,
41941 @value{GDBN} issues the @samp{qXfer:threads:read} packet
41942 (@pxref{qXfer threads read}) and obtains the XML document with
41943 the following structure:
41944
41945 @smallexample
41946 <?xml version="1.0"?>
41947 <threads>
41948 <thread id="id" core="0">
41949 ... description ...
41950 </thread>
41951 </threads>
41952 @end smallexample
41953
41954 Each @samp{thread} element must have the @samp{id} attribute that
41955 identifies the thread (@pxref{thread-id syntax}). The
41956 @samp{core} attribute, if present, specifies which processor core
41957 the thread was last executing on. The content of the of @samp{thread}
41958 element is interpreted as human-readable auxilliary information.
41959
41960 @node Traceframe Info Format
41961 @section Traceframe Info Format
41962 @cindex traceframe info format
41963
41964 To be able to know which objects in the inferior can be examined when
41965 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
41966 memory ranges, registers and trace state variables that have been
41967 collected in a traceframe.
41968
41969 This list is obtained using the @samp{qXfer:traceframe-info:read}
41970 (@pxref{qXfer traceframe info read}) packet and is an XML document.
41971
41972 @value{GDBN} must be linked with the Expat library to support XML
41973 traceframe info discovery. @xref{Expat}.
41974
41975 The top-level structure of the document is shown below:
41976
41977 @smallexample
41978 <?xml version="1.0"?>
41979 <!DOCTYPE traceframe-info
41980 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
41981 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
41982 <traceframe-info>
41983 block...
41984 </traceframe-info>
41985 @end smallexample
41986
41987 Each traceframe block can be either:
41988
41989 @itemize
41990
41991 @item
41992 A region of collected memory starting at @var{addr} and extending for
41993 @var{length} bytes from there:
41994
41995 @smallexample
41996 <memory start="@var{addr}" length="@var{length}"/>
41997 @end smallexample
41998
41999 @item
42000 A block indicating trace state variable numbered @var{number} has been
42001 collected:
42002
42003 @smallexample
42004 <tvar id="@var{number}"/>
42005 @end smallexample
42006
42007 @end itemize
42008
42009 The formal DTD for the traceframe info format is given below:
42010
42011 @smallexample
42012 <!ELEMENT traceframe-info (memory | tvar)* >
42013 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
42014
42015 <!ELEMENT memory EMPTY>
42016 <!ATTLIST memory start CDATA #REQUIRED
42017 length CDATA #REQUIRED>
42018 <!ELEMENT tvar>
42019 <!ATTLIST tvar id CDATA #REQUIRED>
42020 @end smallexample
42021
42022 @node Branch Trace Format
42023 @section Branch Trace Format
42024 @cindex branch trace format
42025
42026 In order to display the branch trace of an inferior thread,
42027 @value{GDBN} needs to obtain the list of branches. This list is
42028 represented as list of sequential code blocks that are connected via
42029 branches. The code in each block has been executed sequentially.
42030
42031 This list is obtained using the @samp{qXfer:btrace:read}
42032 (@pxref{qXfer btrace read}) packet and is an XML document.
42033
42034 @value{GDBN} must be linked with the Expat library to support XML
42035 traceframe info discovery. @xref{Expat}.
42036
42037 The top-level structure of the document is shown below:
42038
42039 @smallexample
42040 <?xml version="1.0"?>
42041 <!DOCTYPE btrace
42042 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
42043 "http://sourceware.org/gdb/gdb-btrace.dtd">
42044 <btrace>
42045 block...
42046 </btrace>
42047 @end smallexample
42048
42049 @itemize
42050
42051 @item
42052 A block of sequentially executed instructions starting at @var{begin}
42053 and ending at @var{end}:
42054
42055 @smallexample
42056 <block begin="@var{begin}" end="@var{end}"/>
42057 @end smallexample
42058
42059 @end itemize
42060
42061 The formal DTD for the branch trace format is given below:
42062
42063 @smallexample
42064 <!ELEMENT btrace (block)* >
42065 <!ATTLIST btrace version CDATA #FIXED "1.0">
42066
42067 <!ELEMENT block EMPTY>
42068 <!ATTLIST block begin CDATA #REQUIRED
42069 end CDATA #REQUIRED>
42070 @end smallexample
42071
42072 @include agentexpr.texi
42073
42074 @node Target Descriptions
42075 @appendix Target Descriptions
42076 @cindex target descriptions
42077
42078 One of the challenges of using @value{GDBN} to debug embedded systems
42079 is that there are so many minor variants of each processor
42080 architecture in use. It is common practice for vendors to start with
42081 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
42082 and then make changes to adapt it to a particular market niche. Some
42083 architectures have hundreds of variants, available from dozens of
42084 vendors. This leads to a number of problems:
42085
42086 @itemize @bullet
42087 @item
42088 With so many different customized processors, it is difficult for
42089 the @value{GDBN} maintainers to keep up with the changes.
42090 @item
42091 Since individual variants may have short lifetimes or limited
42092 audiences, it may not be worthwhile to carry information about every
42093 variant in the @value{GDBN} source tree.
42094 @item
42095 When @value{GDBN} does support the architecture of the embedded system
42096 at hand, the task of finding the correct architecture name to give the
42097 @command{set architecture} command can be error-prone.
42098 @end itemize
42099
42100 To address these problems, the @value{GDBN} remote protocol allows a
42101 target system to not only identify itself to @value{GDBN}, but to
42102 actually describe its own features. This lets @value{GDBN} support
42103 processor variants it has never seen before --- to the extent that the
42104 descriptions are accurate, and that @value{GDBN} understands them.
42105
42106 @value{GDBN} must be linked with the Expat library to support XML
42107 target descriptions. @xref{Expat}.
42108
42109 @menu
42110 * Retrieving Descriptions:: How descriptions are fetched from a target.
42111 * Target Description Format:: The contents of a target description.
42112 * Predefined Target Types:: Standard types available for target
42113 descriptions.
42114 * Standard Target Features:: Features @value{GDBN} knows about.
42115 @end menu
42116
42117 @node Retrieving Descriptions
42118 @section Retrieving Descriptions
42119
42120 Target descriptions can be read from the target automatically, or
42121 specified by the user manually. The default behavior is to read the
42122 description from the target. @value{GDBN} retrieves it via the remote
42123 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
42124 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
42125 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
42126 XML document, of the form described in @ref{Target Description
42127 Format}.
42128
42129 Alternatively, you can specify a file to read for the target description.
42130 If a file is set, the target will not be queried. The commands to
42131 specify a file are:
42132
42133 @table @code
42134 @cindex set tdesc filename
42135 @item set tdesc filename @var{path}
42136 Read the target description from @var{path}.
42137
42138 @cindex unset tdesc filename
42139 @item unset tdesc filename
42140 Do not read the XML target description from a file. @value{GDBN}
42141 will use the description supplied by the current target.
42142
42143 @cindex show tdesc filename
42144 @item show tdesc filename
42145 Show the filename to read for a target description, if any.
42146 @end table
42147
42148
42149 @node Target Description Format
42150 @section Target Description Format
42151 @cindex target descriptions, XML format
42152
42153 A target description annex is an @uref{http://www.w3.org/XML/, XML}
42154 document which complies with the Document Type Definition provided in
42155 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
42156 means you can use generally available tools like @command{xmllint} to
42157 check that your feature descriptions are well-formed and valid.
42158 However, to help people unfamiliar with XML write descriptions for
42159 their targets, we also describe the grammar here.
42160
42161 Target descriptions can identify the architecture of the remote target
42162 and (for some architectures) provide information about custom register
42163 sets. They can also identify the OS ABI of the remote target.
42164 @value{GDBN} can use this information to autoconfigure for your
42165 target, or to warn you if you connect to an unsupported target.
42166
42167 Here is a simple target description:
42168
42169 @smallexample
42170 <target version="1.0">
42171 <architecture>i386:x86-64</architecture>
42172 </target>
42173 @end smallexample
42174
42175 @noindent
42176 This minimal description only says that the target uses
42177 the x86-64 architecture.
42178
42179 A target description has the following overall form, with [ ] marking
42180 optional elements and @dots{} marking repeatable elements. The elements
42181 are explained further below.
42182
42183 @smallexample
42184 <?xml version="1.0"?>
42185 <!DOCTYPE target SYSTEM "gdb-target.dtd">
42186 <target version="1.0">
42187 @r{[}@var{architecture}@r{]}
42188 @r{[}@var{osabi}@r{]}
42189 @r{[}@var{compatible}@r{]}
42190 @r{[}@var{feature}@dots{}@r{]}
42191 </target>
42192 @end smallexample
42193
42194 @noindent
42195 The description is generally insensitive to whitespace and line
42196 breaks, under the usual common-sense rules. The XML version
42197 declaration and document type declaration can generally be omitted
42198 (@value{GDBN} does not require them), but specifying them may be
42199 useful for XML validation tools. The @samp{version} attribute for
42200 @samp{<target>} may also be omitted, but we recommend
42201 including it; if future versions of @value{GDBN} use an incompatible
42202 revision of @file{gdb-target.dtd}, they will detect and report
42203 the version mismatch.
42204
42205 @subsection Inclusion
42206 @cindex target descriptions, inclusion
42207 @cindex XInclude
42208 @ifnotinfo
42209 @cindex <xi:include>
42210 @end ifnotinfo
42211
42212 It can sometimes be valuable to split a target description up into
42213 several different annexes, either for organizational purposes, or to
42214 share files between different possible target descriptions. You can
42215 divide a description into multiple files by replacing any element of
42216 the target description with an inclusion directive of the form:
42217
42218 @smallexample
42219 <xi:include href="@var{document}"/>
42220 @end smallexample
42221
42222 @noindent
42223 When @value{GDBN} encounters an element of this form, it will retrieve
42224 the named XML @var{document}, and replace the inclusion directive with
42225 the contents of that document. If the current description was read
42226 using @samp{qXfer}, then so will be the included document;
42227 @var{document} will be interpreted as the name of an annex. If the
42228 current description was read from a file, @value{GDBN} will look for
42229 @var{document} as a file in the same directory where it found the
42230 original description.
42231
42232 @subsection Architecture
42233 @cindex <architecture>
42234
42235 An @samp{<architecture>} element has this form:
42236
42237 @smallexample
42238 <architecture>@var{arch}</architecture>
42239 @end smallexample
42240
42241 @var{arch} is one of the architectures from the set accepted by
42242 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
42243
42244 @subsection OS ABI
42245 @cindex @code{<osabi>}
42246
42247 This optional field was introduced in @value{GDBN} version 7.0.
42248 Previous versions of @value{GDBN} ignore it.
42249
42250 An @samp{<osabi>} element has this form:
42251
42252 @smallexample
42253 <osabi>@var{abi-name}</osabi>
42254 @end smallexample
42255
42256 @var{abi-name} is an OS ABI name from the same selection accepted by
42257 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
42258
42259 @subsection Compatible Architecture
42260 @cindex @code{<compatible>}
42261
42262 This optional field was introduced in @value{GDBN} version 7.0.
42263 Previous versions of @value{GDBN} ignore it.
42264
42265 A @samp{<compatible>} element has this form:
42266
42267 @smallexample
42268 <compatible>@var{arch}</compatible>
42269 @end smallexample
42270
42271 @var{arch} is one of the architectures from the set accepted by
42272 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
42273
42274 A @samp{<compatible>} element is used to specify that the target
42275 is able to run binaries in some other than the main target architecture
42276 given by the @samp{<architecture>} element. For example, on the
42277 Cell Broadband Engine, the main architecture is @code{powerpc:common}
42278 or @code{powerpc:common64}, but the system is able to run binaries
42279 in the @code{spu} architecture as well. The way to describe this
42280 capability with @samp{<compatible>} is as follows:
42281
42282 @smallexample
42283 <architecture>powerpc:common</architecture>
42284 <compatible>spu</compatible>
42285 @end smallexample
42286
42287 @subsection Features
42288 @cindex <feature>
42289
42290 Each @samp{<feature>} describes some logical portion of the target
42291 system. Features are currently used to describe available CPU
42292 registers and the types of their contents. A @samp{<feature>} element
42293 has this form:
42294
42295 @smallexample
42296 <feature name="@var{name}">
42297 @r{[}@var{type}@dots{}@r{]}
42298 @var{reg}@dots{}
42299 </feature>
42300 @end smallexample
42301
42302 @noindent
42303 Each feature's name should be unique within the description. The name
42304 of a feature does not matter unless @value{GDBN} has some special
42305 knowledge of the contents of that feature; if it does, the feature
42306 should have its standard name. @xref{Standard Target Features}.
42307
42308 @subsection Types
42309
42310 Any register's value is a collection of bits which @value{GDBN} must
42311 interpret. The default interpretation is a two's complement integer,
42312 but other types can be requested by name in the register description.
42313 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
42314 Target Types}), and the description can define additional composite types.
42315
42316 Each type element must have an @samp{id} attribute, which gives
42317 a unique (within the containing @samp{<feature>}) name to the type.
42318 Types must be defined before they are used.
42319
42320 @cindex <vector>
42321 Some targets offer vector registers, which can be treated as arrays
42322 of scalar elements. These types are written as @samp{<vector>} elements,
42323 specifying the array element type, @var{type}, and the number of elements,
42324 @var{count}:
42325
42326 @smallexample
42327 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
42328 @end smallexample
42329
42330 @cindex <union>
42331 If a register's value is usefully viewed in multiple ways, define it
42332 with a union type containing the useful representations. The
42333 @samp{<union>} element contains one or more @samp{<field>} elements,
42334 each of which has a @var{name} and a @var{type}:
42335
42336 @smallexample
42337 <union id="@var{id}">
42338 <field name="@var{name}" type="@var{type}"/>
42339 @dots{}
42340 </union>
42341 @end smallexample
42342
42343 @cindex <struct>
42344 If a register's value is composed from several separate values, define
42345 it with a structure type. There are two forms of the @samp{<struct>}
42346 element; a @samp{<struct>} element must either contain only bitfields
42347 or contain no bitfields. If the structure contains only bitfields,
42348 its total size in bytes must be specified, each bitfield must have an
42349 explicit start and end, and bitfields are automatically assigned an
42350 integer type. The field's @var{start} should be less than or
42351 equal to its @var{end}, and zero represents the least significant bit.
42352
42353 @smallexample
42354 <struct id="@var{id}" size="@var{size}">
42355 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
42356 @dots{}
42357 </struct>
42358 @end smallexample
42359
42360 If the structure contains no bitfields, then each field has an
42361 explicit type, and no implicit padding is added.
42362
42363 @smallexample
42364 <struct id="@var{id}">
42365 <field name="@var{name}" type="@var{type}"/>
42366 @dots{}
42367 </struct>
42368 @end smallexample
42369
42370 @cindex <flags>
42371 If a register's value is a series of single-bit flags, define it with
42372 a flags type. The @samp{<flags>} element has an explicit @var{size}
42373 and contains one or more @samp{<field>} elements. Each field has a
42374 @var{name}, a @var{start}, and an @var{end}. Only single-bit flags
42375 are supported.
42376
42377 @smallexample
42378 <flags id="@var{id}" size="@var{size}">
42379 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
42380 @dots{}
42381 </flags>
42382 @end smallexample
42383
42384 @subsection Registers
42385 @cindex <reg>
42386
42387 Each register is represented as an element with this form:
42388
42389 @smallexample
42390 <reg name="@var{name}"
42391 bitsize="@var{size}"
42392 @r{[}regnum="@var{num}"@r{]}
42393 @r{[}save-restore="@var{save-restore}"@r{]}
42394 @r{[}type="@var{type}"@r{]}
42395 @r{[}group="@var{group}"@r{]}/>
42396 @end smallexample
42397
42398 @noindent
42399 The components are as follows:
42400
42401 @table @var
42402
42403 @item name
42404 The register's name; it must be unique within the target description.
42405
42406 @item bitsize
42407 The register's size, in bits.
42408
42409 @item regnum
42410 The register's number. If omitted, a register's number is one greater
42411 than that of the previous register (either in the current feature or in
42412 a preceding feature); the first register in the target description
42413 defaults to zero. This register number is used to read or write
42414 the register; e.g.@: it is used in the remote @code{p} and @code{P}
42415 packets, and registers appear in the @code{g} and @code{G} packets
42416 in order of increasing register number.
42417
42418 @item save-restore
42419 Whether the register should be preserved across inferior function
42420 calls; this must be either @code{yes} or @code{no}. The default is
42421 @code{yes}, which is appropriate for most registers except for
42422 some system control registers; this is not related to the target's
42423 ABI.
42424
42425 @item type
42426 The type of the register. @var{type} may be a predefined type, a type
42427 defined in the current feature, or one of the special types @code{int}
42428 and @code{float}. @code{int} is an integer type of the correct size
42429 for @var{bitsize}, and @code{float} is a floating point type (in the
42430 architecture's normal floating point format) of the correct size for
42431 @var{bitsize}. The default is @code{int}.
42432
42433 @item group
42434 The register group to which this register belongs. @var{group} must
42435 be either @code{general}, @code{float}, or @code{vector}. If no
42436 @var{group} is specified, @value{GDBN} will not display the register
42437 in @code{info registers}.
42438
42439 @end table
42440
42441 @node Predefined Target Types
42442 @section Predefined Target Types
42443 @cindex target descriptions, predefined types
42444
42445 Type definitions in the self-description can build up composite types
42446 from basic building blocks, but can not define fundamental types. Instead,
42447 standard identifiers are provided by @value{GDBN} for the fundamental
42448 types. The currently supported types are:
42449
42450 @table @code
42451
42452 @item int8
42453 @itemx int16
42454 @itemx int32
42455 @itemx int64
42456 @itemx int128
42457 Signed integer types holding the specified number of bits.
42458
42459 @item uint8
42460 @itemx uint16
42461 @itemx uint32
42462 @itemx uint64
42463 @itemx uint128
42464 Unsigned integer types holding the specified number of bits.
42465
42466 @item code_ptr
42467 @itemx data_ptr
42468 Pointers to unspecified code and data. The program counter and
42469 any dedicated return address register may be marked as code
42470 pointers; printing a code pointer converts it into a symbolic
42471 address. The stack pointer and any dedicated address registers
42472 may be marked as data pointers.
42473
42474 @item ieee_single
42475 Single precision IEEE floating point.
42476
42477 @item ieee_double
42478 Double precision IEEE floating point.
42479
42480 @item arm_fpa_ext
42481 The 12-byte extended precision format used by ARM FPA registers.
42482
42483 @item i387_ext
42484 The 10-byte extended precision format used by x87 registers.
42485
42486 @item i386_eflags
42487 32bit @sc{eflags} register used by x86.
42488
42489 @item i386_mxcsr
42490 32bit @sc{mxcsr} register used by x86.
42491
42492 @end table
42493
42494 @node Standard Target Features
42495 @section Standard Target Features
42496 @cindex target descriptions, standard features
42497
42498 A target description must contain either no registers or all the
42499 target's registers. If the description contains no registers, then
42500 @value{GDBN} will assume a default register layout, selected based on
42501 the architecture. If the description contains any registers, the
42502 default layout will not be used; the standard registers must be
42503 described in the target description, in such a way that @value{GDBN}
42504 can recognize them.
42505
42506 This is accomplished by giving specific names to feature elements
42507 which contain standard registers. @value{GDBN} will look for features
42508 with those names and verify that they contain the expected registers;
42509 if any known feature is missing required registers, or if any required
42510 feature is missing, @value{GDBN} will reject the target
42511 description. You can add additional registers to any of the
42512 standard features --- @value{GDBN} will display them just as if
42513 they were added to an unrecognized feature.
42514
42515 This section lists the known features and their expected contents.
42516 Sample XML documents for these features are included in the
42517 @value{GDBN} source tree, in the directory @file{gdb/features}.
42518
42519 Names recognized by @value{GDBN} should include the name of the
42520 company or organization which selected the name, and the overall
42521 architecture to which the feature applies; so e.g.@: the feature
42522 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
42523
42524 The names of registers are not case sensitive for the purpose
42525 of recognizing standard features, but @value{GDBN} will only display
42526 registers using the capitalization used in the description.
42527
42528 @menu
42529 * AArch64 Features::
42530 * ARM Features::
42531 * i386 Features::
42532 * MIPS Features::
42533 * M68K Features::
42534 * Nios II Features::
42535 * PowerPC Features::
42536 * S/390 and System z Features::
42537 * TIC6x Features::
42538 @end menu
42539
42540
42541 @node AArch64 Features
42542 @subsection AArch64 Features
42543 @cindex target descriptions, AArch64 features
42544
42545 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
42546 targets. It should contain registers @samp{x0} through @samp{x30},
42547 @samp{sp}, @samp{pc}, and @samp{cpsr}.
42548
42549 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
42550 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
42551 and @samp{fpcr}.
42552
42553 @node ARM Features
42554 @subsection ARM Features
42555 @cindex target descriptions, ARM features
42556
42557 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
42558 ARM targets.
42559 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
42560 @samp{lr}, @samp{pc}, and @samp{cpsr}.
42561
42562 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
42563 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
42564 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
42565 and @samp{xpsr}.
42566
42567 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
42568 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
42569
42570 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
42571 it should contain at least registers @samp{wR0} through @samp{wR15} and
42572 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
42573 @samp{wCSSF}, and @samp{wCASF} registers are optional.
42574
42575 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
42576 should contain at least registers @samp{d0} through @samp{d15}. If
42577 they are present, @samp{d16} through @samp{d31} should also be included.
42578 @value{GDBN} will synthesize the single-precision registers from
42579 halves of the double-precision registers.
42580
42581 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
42582 need to contain registers; it instructs @value{GDBN} to display the
42583 VFP double-precision registers as vectors and to synthesize the
42584 quad-precision registers from pairs of double-precision registers.
42585 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
42586 be present and include 32 double-precision registers.
42587
42588 @node i386 Features
42589 @subsection i386 Features
42590 @cindex target descriptions, i386 features
42591
42592 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
42593 targets. It should describe the following registers:
42594
42595 @itemize @minus
42596 @item
42597 @samp{eax} through @samp{edi} plus @samp{eip} for i386
42598 @item
42599 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
42600 @item
42601 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
42602 @samp{fs}, @samp{gs}
42603 @item
42604 @samp{st0} through @samp{st7}
42605 @item
42606 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
42607 @samp{foseg}, @samp{fooff} and @samp{fop}
42608 @end itemize
42609
42610 The register sets may be different, depending on the target.
42611
42612 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
42613 describe registers:
42614
42615 @itemize @minus
42616 @item
42617 @samp{xmm0} through @samp{xmm7} for i386
42618 @item
42619 @samp{xmm0} through @samp{xmm15} for amd64
42620 @item
42621 @samp{mxcsr}
42622 @end itemize
42623
42624 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
42625 @samp{org.gnu.gdb.i386.sse} feature. It should
42626 describe the upper 128 bits of @sc{ymm} registers:
42627
42628 @itemize @minus
42629 @item
42630 @samp{ymm0h} through @samp{ymm7h} for i386
42631 @item
42632 @samp{ymm0h} through @samp{ymm15h} for amd64
42633 @end itemize
42634
42635 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
42636 describe a single register, @samp{orig_eax}.
42637
42638 @node MIPS Features
42639 @subsection @acronym{MIPS} Features
42640 @cindex target descriptions, @acronym{MIPS} features
42641
42642 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
42643 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
42644 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
42645 on the target.
42646
42647 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
42648 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
42649 registers. They may be 32-bit or 64-bit depending on the target.
42650
42651 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
42652 it may be optional in a future version of @value{GDBN}. It should
42653 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
42654 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
42655
42656 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
42657 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
42658 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
42659 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
42660
42661 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
42662 contain a single register, @samp{restart}, which is used by the
42663 Linux kernel to control restartable syscalls.
42664
42665 @node M68K Features
42666 @subsection M68K Features
42667 @cindex target descriptions, M68K features
42668
42669 @table @code
42670 @item @samp{org.gnu.gdb.m68k.core}
42671 @itemx @samp{org.gnu.gdb.coldfire.core}
42672 @itemx @samp{org.gnu.gdb.fido.core}
42673 One of those features must be always present.
42674 The feature that is present determines which flavor of m68k is
42675 used. The feature that is present should contain registers
42676 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
42677 @samp{sp}, @samp{ps} and @samp{pc}.
42678
42679 @item @samp{org.gnu.gdb.coldfire.fp}
42680 This feature is optional. If present, it should contain registers
42681 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
42682 @samp{fpiaddr}.
42683 @end table
42684
42685 @node Nios II Features
42686 @subsection Nios II Features
42687 @cindex target descriptions, Nios II features
42688
42689 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
42690 targets. It should contain the 32 core registers (@samp{zero},
42691 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
42692 @samp{pc}, and the 16 control registers (@samp{status} through
42693 @samp{mpuacc}).
42694
42695 @node PowerPC Features
42696 @subsection PowerPC Features
42697 @cindex target descriptions, PowerPC features
42698
42699 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
42700 targets. It should contain registers @samp{r0} through @samp{r31},
42701 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
42702 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
42703
42704 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
42705 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
42706
42707 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
42708 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
42709 and @samp{vrsave}.
42710
42711 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
42712 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
42713 will combine these registers with the floating point registers
42714 (@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
42715 through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
42716 through @samp{vs63}, the set of vector registers for POWER7.
42717
42718 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
42719 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
42720 @samp{spefscr}. SPE targets should provide 32-bit registers in
42721 @samp{org.gnu.gdb.power.core} and provide the upper halves in
42722 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
42723 these to present registers @samp{ev0} through @samp{ev31} to the
42724 user.
42725
42726 @node S/390 and System z Features
42727 @subsection S/390 and System z Features
42728 @cindex target descriptions, S/390 features
42729 @cindex target descriptions, System z features
42730
42731 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
42732 System z targets. It should contain the PSW and the 16 general
42733 registers. In particular, System z targets should provide the 64-bit
42734 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
42735 S/390 targets should provide the 32-bit versions of these registers.
42736 A System z target that runs in 31-bit addressing mode should provide
42737 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
42738 register's upper halves @samp{r0h} through @samp{r15h}, and their
42739 lower halves @samp{r0l} through @samp{r15l}.
42740
42741 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
42742 contain the 64-bit registers @samp{f0} through @samp{f15}, and
42743 @samp{fpc}.
42744
42745 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
42746 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
42747
42748 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
42749 contain the register @samp{orig_r2}, which is 64-bit wide on System z
42750 targets and 32-bit otherwise. In addition, the feature may contain
42751 the @samp{last_break} register, whose width depends on the addressing
42752 mode, as well as the @samp{system_call} register, which is always
42753 32-bit wide.
42754
42755 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
42756 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
42757 @samp{atia}, and @samp{tr0} through @samp{tr15}.
42758
42759 @node TIC6x Features
42760 @subsection TMS320C6x Features
42761 @cindex target descriptions, TIC6x features
42762 @cindex target descriptions, TMS320C6x features
42763 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
42764 targets. It should contain registers @samp{A0} through @samp{A15},
42765 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
42766
42767 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
42768 contain registers @samp{A16} through @samp{A31} and @samp{B16}
42769 through @samp{B31}.
42770
42771 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
42772 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
42773
42774 @node Operating System Information
42775 @appendix Operating System Information
42776 @cindex operating system information
42777
42778 @menu
42779 * Process list::
42780 @end menu
42781
42782 Users of @value{GDBN} often wish to obtain information about the state of
42783 the operating system running on the target---for example the list of
42784 processes, or the list of open files. This section describes the
42785 mechanism that makes it possible. This mechanism is similar to the
42786 target features mechanism (@pxref{Target Descriptions}), but focuses
42787 on a different aspect of target.
42788
42789 Operating system information is retrived from the target via the
42790 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
42791 read}). The object name in the request should be @samp{osdata}, and
42792 the @var{annex} identifies the data to be fetched.
42793
42794 @node Process list
42795 @appendixsection Process list
42796 @cindex operating system information, process list
42797
42798 When requesting the process list, the @var{annex} field in the
42799 @samp{qXfer} request should be @samp{processes}. The returned data is
42800 an XML document. The formal syntax of this document is defined in
42801 @file{gdb/features/osdata.dtd}.
42802
42803 An example document is:
42804
42805 @smallexample
42806 <?xml version="1.0"?>
42807 <!DOCTYPE target SYSTEM "osdata.dtd">
42808 <osdata type="processes">
42809 <item>
42810 <column name="pid">1</column>
42811 <column name="user">root</column>
42812 <column name="command">/sbin/init</column>
42813 <column name="cores">1,2,3</column>
42814 </item>
42815 </osdata>
42816 @end smallexample
42817
42818 Each item should include a column whose name is @samp{pid}. The value
42819 of that column should identify the process on the target. The
42820 @samp{user} and @samp{command} columns are optional, and will be
42821 displayed by @value{GDBN}. The @samp{cores} column, if present,
42822 should contain a comma-separated list of cores that this process
42823 is running on. Target may provide additional columns,
42824 which @value{GDBN} currently ignores.
42825
42826 @node Trace File Format
42827 @appendix Trace File Format
42828 @cindex trace file format
42829
42830 The trace file comes in three parts: a header, a textual description
42831 section, and a trace frame section with binary data.
42832
42833 The header has the form @code{\x7fTRACE0\n}. The first byte is
42834 @code{0x7f} so as to indicate that the file contains binary data,
42835 while the @code{0} is a version number that may have different values
42836 in the future.
42837
42838 The description section consists of multiple lines of @sc{ascii} text
42839 separated by newline characters (@code{0xa}). The lines may include a
42840 variety of optional descriptive or context-setting information, such
42841 as tracepoint definitions or register set size. @value{GDBN} will
42842 ignore any line that it does not recognize. An empty line marks the end
42843 of this section.
42844
42845 @c FIXME add some specific types of data
42846
42847 The trace frame section consists of a number of consecutive frames.
42848 Each frame begins with a two-byte tracepoint number, followed by a
42849 four-byte size giving the amount of data in the frame. The data in
42850 the frame consists of a number of blocks, each introduced by a
42851 character indicating its type (at least register, memory, and trace
42852 state variable). The data in this section is raw binary, not a
42853 hexadecimal or other encoding; its endianness matches the target's
42854 endianness.
42855
42856 @c FIXME bi-arch may require endianness/arch info in description section
42857
42858 @table @code
42859 @item R @var{bytes}
42860 Register block. The number and ordering of bytes matches that of a
42861 @code{g} packet in the remote protocol. Note that these are the
42862 actual bytes, in target order and @value{GDBN} register order, not a
42863 hexadecimal encoding.
42864
42865 @item M @var{address} @var{length} @var{bytes}...
42866 Memory block. This is a contiguous block of memory, at the 8-byte
42867 address @var{address}, with a 2-byte length @var{length}, followed by
42868 @var{length} bytes.
42869
42870 @item V @var{number} @var{value}
42871 Trace state variable block. This records the 8-byte signed value
42872 @var{value} of trace state variable numbered @var{number}.
42873
42874 @end table
42875
42876 Future enhancements of the trace file format may include additional types
42877 of blocks.
42878
42879 @node Index Section Format
42880 @appendix @code{.gdb_index} section format
42881 @cindex .gdb_index section format
42882 @cindex index section format
42883
42884 This section documents the index section that is created by @code{save
42885 gdb-index} (@pxref{Index Files}). The index section is
42886 DWARF-specific; some knowledge of DWARF is assumed in this
42887 description.
42888
42889 The mapped index file format is designed to be directly
42890 @code{mmap}able on any architecture. In most cases, a datum is
42891 represented using a little-endian 32-bit integer value, called an
42892 @code{offset_type}. Big endian machines must byte-swap the values
42893 before using them. Exceptions to this rule are noted. The data is
42894 laid out such that alignment is always respected.
42895
42896 A mapped index consists of several areas, laid out in order.
42897
42898 @enumerate
42899 @item
42900 The file header. This is a sequence of values, of @code{offset_type}
42901 unless otherwise noted:
42902
42903 @enumerate
42904 @item
42905 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
42906 Version 4 uses a different hashing function from versions 5 and 6.
42907 Version 6 includes symbols for inlined functions, whereas versions 4
42908 and 5 do not. Version 7 adds attributes to the CU indices in the
42909 symbol table. Version 8 specifies that symbols from DWARF type units
42910 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
42911 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
42912
42913 @value{GDBN} will only read version 4, 5, or 6 indices
42914 by specifying @code{set use-deprecated-index-sections on}.
42915 GDB has a workaround for potentially broken version 7 indices so it is
42916 currently not flagged as deprecated.
42917
42918 @item
42919 The offset, from the start of the file, of the CU list.
42920
42921 @item
42922 The offset, from the start of the file, of the types CU list. Note
42923 that this area can be empty, in which case this offset will be equal
42924 to the next offset.
42925
42926 @item
42927 The offset, from the start of the file, of the address area.
42928
42929 @item
42930 The offset, from the start of the file, of the symbol table.
42931
42932 @item
42933 The offset, from the start of the file, of the constant pool.
42934 @end enumerate
42935
42936 @item
42937 The CU list. This is a sequence of pairs of 64-bit little-endian
42938 values, sorted by the CU offset. The first element in each pair is
42939 the offset of a CU in the @code{.debug_info} section. The second
42940 element in each pair is the length of that CU. References to a CU
42941 elsewhere in the map are done using a CU index, which is just the
42942 0-based index into this table. Note that if there are type CUs, then
42943 conceptually CUs and type CUs form a single list for the purposes of
42944 CU indices.
42945
42946 @item
42947 The types CU list. This is a sequence of triplets of 64-bit
42948 little-endian values. In a triplet, the first value is the CU offset,
42949 the second value is the type offset in the CU, and the third value is
42950 the type signature. The types CU list is not sorted.
42951
42952 @item
42953 The address area. The address area consists of a sequence of address
42954 entries. Each address entry has three elements:
42955
42956 @enumerate
42957 @item
42958 The low address. This is a 64-bit little-endian value.
42959
42960 @item
42961 The high address. This is a 64-bit little-endian value. Like
42962 @code{DW_AT_high_pc}, the value is one byte beyond the end.
42963
42964 @item
42965 The CU index. This is an @code{offset_type} value.
42966 @end enumerate
42967
42968 @item
42969 The symbol table. This is an open-addressed hash table. The size of
42970 the hash table is always a power of 2.
42971
42972 Each slot in the hash table consists of a pair of @code{offset_type}
42973 values. The first value is the offset of the symbol's name in the
42974 constant pool. The second value is the offset of the CU vector in the
42975 constant pool.
42976
42977 If both values are 0, then this slot in the hash table is empty. This
42978 is ok because while 0 is a valid constant pool index, it cannot be a
42979 valid index for both a string and a CU vector.
42980
42981 The hash value for a table entry is computed by applying an
42982 iterative hash function to the symbol's name. Starting with an
42983 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
42984 the string is incorporated into the hash using the formula depending on the
42985 index version:
42986
42987 @table @asis
42988 @item Version 4
42989 The formula is @code{r = r * 67 + c - 113}.
42990
42991 @item Versions 5 to 7
42992 The formula is @code{r = r * 67 + tolower (c) - 113}.
42993 @end table
42994
42995 The terminating @samp{\0} is not incorporated into the hash.
42996
42997 The step size used in the hash table is computed via
42998 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
42999 value, and @samp{size} is the size of the hash table. The step size
43000 is used to find the next candidate slot when handling a hash
43001 collision.
43002
43003 The names of C@t{++} symbols in the hash table are canonicalized. We
43004 don't currently have a simple description of the canonicalization
43005 algorithm; if you intend to create new index sections, you must read
43006 the code.
43007
43008 @item
43009 The constant pool. This is simply a bunch of bytes. It is organized
43010 so that alignment is correct: CU vectors are stored first, followed by
43011 strings.
43012
43013 A CU vector in the constant pool is a sequence of @code{offset_type}
43014 values. The first value is the number of CU indices in the vector.
43015 Each subsequent value is the index and symbol attributes of a CU in
43016 the CU list. This element in the hash table is used to indicate which
43017 CUs define the symbol and how the symbol is used.
43018 See below for the format of each CU index+attributes entry.
43019
43020 A string in the constant pool is zero-terminated.
43021 @end enumerate
43022
43023 Attributes were added to CU index values in @code{.gdb_index} version 7.
43024 If a symbol has multiple uses within a CU then there is one
43025 CU index+attributes value for each use.
43026
43027 The format of each CU index+attributes entry is as follows
43028 (bit 0 = LSB):
43029
43030 @table @asis
43031
43032 @item Bits 0-23
43033 This is the index of the CU in the CU list.
43034 @item Bits 24-27
43035 These bits are reserved for future purposes and must be zero.
43036 @item Bits 28-30
43037 The kind of the symbol in the CU.
43038
43039 @table @asis
43040 @item 0
43041 This value is reserved and should not be used.
43042 By reserving zero the full @code{offset_type} value is backwards compatible
43043 with previous versions of the index.
43044 @item 1
43045 The symbol is a type.
43046 @item 2
43047 The symbol is a variable or an enum value.
43048 @item 3
43049 The symbol is a function.
43050 @item 4
43051 Any other kind of symbol.
43052 @item 5,6,7
43053 These values are reserved.
43054 @end table
43055
43056 @item Bit 31
43057 This bit is zero if the value is global and one if it is static.
43058
43059 The determination of whether a symbol is global or static is complicated.
43060 The authorative reference is the file @file{dwarf2read.c} in
43061 @value{GDBN} sources.
43062
43063 @end table
43064
43065 This pseudo-code describes the computation of a symbol's kind and
43066 global/static attributes in the index.
43067
43068 @smallexample
43069 is_external = get_attribute (die, DW_AT_external);
43070 language = get_attribute (cu_die, DW_AT_language);
43071 switch (die->tag)
43072 @{
43073 case DW_TAG_typedef:
43074 case DW_TAG_base_type:
43075 case DW_TAG_subrange_type:
43076 kind = TYPE;
43077 is_static = 1;
43078 break;
43079 case DW_TAG_enumerator:
43080 kind = VARIABLE;
43081 is_static = (language != CPLUS && language != JAVA);
43082 break;
43083 case DW_TAG_subprogram:
43084 kind = FUNCTION;
43085 is_static = ! (is_external || language == ADA);
43086 break;
43087 case DW_TAG_constant:
43088 kind = VARIABLE;
43089 is_static = ! is_external;
43090 break;
43091 case DW_TAG_variable:
43092 kind = VARIABLE;
43093 is_static = ! is_external;
43094 break;
43095 case DW_TAG_namespace:
43096 kind = TYPE;
43097 is_static = 0;
43098 break;
43099 case DW_TAG_class_type:
43100 case DW_TAG_interface_type:
43101 case DW_TAG_structure_type:
43102 case DW_TAG_union_type:
43103 case DW_TAG_enumeration_type:
43104 kind = TYPE;
43105 is_static = (language != CPLUS && language != JAVA);
43106 break;
43107 default:
43108 assert (0);
43109 @}
43110 @end smallexample
43111
43112 @node Man Pages
43113 @appendix Manual pages
43114 @cindex Man pages
43115
43116 @menu
43117 * gdb man:: The GNU Debugger man page
43118 * gdbserver man:: Remote Server for the GNU Debugger man page
43119 * gcore man:: Generate a core file of a running program
43120 * gdbinit man:: gdbinit scripts
43121 @end menu
43122
43123 @node gdb man
43124 @heading gdb man
43125
43126 @c man title gdb The GNU Debugger
43127
43128 @c man begin SYNOPSIS gdb
43129 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
43130 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
43131 [@option{-b}@w{ }@var{bps}]
43132 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
43133 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
43134 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
43135 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
43136 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43137 @c man end
43138
43139 @c man begin DESCRIPTION gdb
43140 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
43141 going on ``inside'' another program while it executes -- or what another
43142 program was doing at the moment it crashed.
43143
43144 @value{GDBN} can do four main kinds of things (plus other things in support of
43145 these) to help you catch bugs in the act:
43146
43147 @itemize @bullet
43148 @item
43149 Start your program, specifying anything that might affect its behavior.
43150
43151 @item
43152 Make your program stop on specified conditions.
43153
43154 @item
43155 Examine what has happened, when your program has stopped.
43156
43157 @item
43158 Change things in your program, so you can experiment with correcting the
43159 effects of one bug and go on to learn about another.
43160 @end itemize
43161
43162 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
43163 Modula-2.
43164
43165 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
43166 commands from the terminal until you tell it to exit with the @value{GDBN}
43167 command @code{quit}. You can get online help from @value{GDBN} itself
43168 by using the command @code{help}.
43169
43170 You can run @code{gdb} with no arguments or options; but the most
43171 usual way to start @value{GDBN} is with one argument or two, specifying an
43172 executable program as the argument:
43173
43174 @smallexample
43175 gdb program
43176 @end smallexample
43177
43178 You can also start with both an executable program and a core file specified:
43179
43180 @smallexample
43181 gdb program core
43182 @end smallexample
43183
43184 You can, instead, specify a process ID as a second argument, if you want
43185 to debug a running process:
43186
43187 @smallexample
43188 gdb program 1234
43189 gdb -p 1234
43190 @end smallexample
43191
43192 @noindent
43193 would attach @value{GDBN} to process @code{1234} (unless you also have a file
43194 named @file{1234}; @value{GDBN} does check for a core file first).
43195 With option @option{-p} you can omit the @var{program} filename.
43196
43197 Here are some of the most frequently needed @value{GDBN} commands:
43198
43199 @c pod2man highlights the right hand side of the @item lines.
43200 @table @env
43201 @item break [@var{file}:]@var{functiop}
43202 Set a breakpoint at @var{function} (in @var{file}).
43203
43204 @item run [@var{arglist}]
43205 Start your program (with @var{arglist}, if specified).
43206
43207 @item bt
43208 Backtrace: display the program stack.
43209
43210 @item print @var{expr}
43211 Display the value of an expression.
43212
43213 @item c
43214 Continue running your program (after stopping, e.g. at a breakpoint).
43215
43216 @item next
43217 Execute next program line (after stopping); step @emph{over} any
43218 function calls in the line.
43219
43220 @item edit [@var{file}:]@var{function}
43221 look at the program line where it is presently stopped.
43222
43223 @item list [@var{file}:]@var{function}
43224 type the text of the program in the vicinity of where it is presently stopped.
43225
43226 @item step
43227 Execute next program line (after stopping); step @emph{into} any
43228 function calls in the line.
43229
43230 @item help [@var{name}]
43231 Show information about @value{GDBN} command @var{name}, or general information
43232 about using @value{GDBN}.
43233
43234 @item quit
43235 Exit from @value{GDBN}.
43236 @end table
43237
43238 @ifset man
43239 For full details on @value{GDBN},
43240 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43241 by Richard M. Stallman and Roland H. Pesch. The same text is available online
43242 as the @code{gdb} entry in the @code{info} program.
43243 @end ifset
43244 @c man end
43245
43246 @c man begin OPTIONS gdb
43247 Any arguments other than options specify an executable
43248 file and core file (or process ID); that is, the first argument
43249 encountered with no
43250 associated option flag is equivalent to a @option{-se} option, and the second,
43251 if any, is equivalent to a @option{-c} option if it's the name of a file.
43252 Many options have
43253 both long and short forms; both are shown here. The long forms are also
43254 recognized if you truncate them, so long as enough of the option is
43255 present to be unambiguous. (If you prefer, you can flag option
43256 arguments with @option{+} rather than @option{-}, though we illustrate the
43257 more usual convention.)
43258
43259 All the options and command line arguments you give are processed
43260 in sequential order. The order makes a difference when the @option{-x}
43261 option is used.
43262
43263 @table @env
43264 @item -help
43265 @itemx -h
43266 List all options, with brief explanations.
43267
43268 @item -symbols=@var{file}
43269 @itemx -s @var{file}
43270 Read symbol table from file @var{file}.
43271
43272 @item -write
43273 Enable writing into executable and core files.
43274
43275 @item -exec=@var{file}
43276 @itemx -e @var{file}
43277 Use file @var{file} as the executable file to execute when
43278 appropriate, and for examining pure data in conjunction with a core
43279 dump.
43280
43281 @item -se=@var{file}
43282 Read symbol table from file @var{file} and use it as the executable
43283 file.
43284
43285 @item -core=@var{file}
43286 @itemx -c @var{file}
43287 Use file @var{file} as a core dump to examine.
43288
43289 @item -command=@var{file}
43290 @itemx -x @var{file}
43291 Execute @value{GDBN} commands from file @var{file}.
43292
43293 @item -ex @var{command}
43294 Execute given @value{GDBN} @var{command}.
43295
43296 @item -directory=@var{directory}
43297 @itemx -d @var{directory}
43298 Add @var{directory} to the path to search for source files.
43299
43300 @item -nh
43301 Do not execute commands from @file{~/.gdbinit}.
43302
43303 @item -nx
43304 @itemx -n
43305 Do not execute commands from any @file{.gdbinit} initialization files.
43306
43307 @item -quiet
43308 @itemx -q
43309 ``Quiet''. Do not print the introductory and copyright messages. These
43310 messages are also suppressed in batch mode.
43311
43312 @item -batch
43313 Run in batch mode. Exit with status @code{0} after processing all the command
43314 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
43315 Exit with nonzero status if an error occurs in executing the @value{GDBN}
43316 commands in the command files.
43317
43318 Batch mode may be useful for running @value{GDBN} as a filter, for example to
43319 download and run a program on another computer; in order to make this
43320 more useful, the message
43321
43322 @smallexample
43323 Program exited normally.
43324 @end smallexample
43325
43326 @noindent
43327 (which is ordinarily issued whenever a program running under @value{GDBN} control
43328 terminates) is not issued when running in batch mode.
43329
43330 @item -cd=@var{directory}
43331 Run @value{GDBN} using @var{directory} as its working directory,
43332 instead of the current directory.
43333
43334 @item -fullname
43335 @itemx -f
43336 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
43337 @value{GDBN} to output the full file name and line number in a standard,
43338 recognizable fashion each time a stack frame is displayed (which
43339 includes each time the program stops). This recognizable format looks
43340 like two @samp{\032} characters, followed by the file name, line number
43341 and character position separated by colons, and a newline. The
43342 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
43343 characters as a signal to display the source code for the frame.
43344
43345 @item -b @var{bps}
43346 Set the line speed (baud rate or bits per second) of any serial
43347 interface used by @value{GDBN} for remote debugging.
43348
43349 @item -tty=@var{device}
43350 Run using @var{device} for your program's standard input and output.
43351 @end table
43352 @c man end
43353
43354 @c man begin SEEALSO gdb
43355 @ifset man
43356 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43357 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43358 documentation are properly installed at your site, the command
43359
43360 @smallexample
43361 info gdb
43362 @end smallexample
43363
43364 @noindent
43365 should give you access to the complete manual.
43366
43367 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43368 Richard M. Stallman and Roland H. Pesch, July 1991.
43369 @end ifset
43370 @c man end
43371
43372 @node gdbserver man
43373 @heading gdbserver man
43374
43375 @c man title gdbserver Remote Server for the GNU Debugger
43376 @format
43377 @c man begin SYNOPSIS gdbserver
43378 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43379
43380 gdbserver --attach @var{comm} @var{pid}
43381
43382 gdbserver --multi @var{comm}
43383 @c man end
43384 @end format
43385
43386 @c man begin DESCRIPTION gdbserver
43387 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
43388 than the one which is running the program being debugged.
43389
43390 @ifclear man
43391 @subheading Usage (server (target) side)
43392 @end ifclear
43393 @ifset man
43394 Usage (server (target) side):
43395 @end ifset
43396
43397 First, you need to have a copy of the program you want to debug put onto
43398 the target system. The program can be stripped to save space if needed, as
43399 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
43400 the @value{GDBN} running on the host system.
43401
43402 To use the server, you log on to the target system, and run the @command{gdbserver}
43403 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
43404 your program, and (c) its arguments. The general syntax is:
43405
43406 @smallexample
43407 target> gdbserver @var{comm} @var{program} [@var{args} ...]
43408 @end smallexample
43409
43410 For example, using a serial port, you might say:
43411
43412 @smallexample
43413 @ifset man
43414 @c @file would wrap it as F</dev/com1>.
43415 target> gdbserver /dev/com1 emacs foo.txt
43416 @end ifset
43417 @ifclear man
43418 target> gdbserver @file{/dev/com1} emacs foo.txt
43419 @end ifclear
43420 @end smallexample
43421
43422 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
43423 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
43424 waits patiently for the host @value{GDBN} to communicate with it.
43425
43426 To use a TCP connection, you could say:
43427
43428 @smallexample
43429 target> gdbserver host:2345 emacs foo.txt
43430 @end smallexample
43431
43432 This says pretty much the same thing as the last example, except that we are
43433 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
43434 that we are expecting to see a TCP connection from @code{host} to local TCP port
43435 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
43436 want for the port number as long as it does not conflict with any existing TCP
43437 ports on the target system. This same port number must be used in the host
43438 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
43439 you chose a port number that conflicts with another service, @command{gdbserver} will
43440 print an error message and exit.
43441
43442 @command{gdbserver} can also attach to running programs.
43443 This is accomplished via the @option{--attach} argument. The syntax is:
43444
43445 @smallexample
43446 target> gdbserver --attach @var{comm} @var{pid}
43447 @end smallexample
43448
43449 @var{pid} is the process ID of a currently running process. It isn't
43450 necessary to point @command{gdbserver} at a binary for the running process.
43451
43452 To start @code{gdbserver} without supplying an initial command to run
43453 or process ID to attach, use the @option{--multi} command line option.
43454 In such case you should connect using @kbd{target extended-remote} to start
43455 the program you want to debug.
43456
43457 @smallexample
43458 target> gdbserver --multi @var{comm}
43459 @end smallexample
43460
43461 @ifclear man
43462 @subheading Usage (host side)
43463 @end ifclear
43464 @ifset man
43465 Usage (host side):
43466 @end ifset
43467
43468 You need an unstripped copy of the target program on your host system, since
43469 @value{GDBN} needs to examine it's symbol tables and such. Start up @value{GDBN} as you normally
43470 would, with the target program as the first argument. (You may need to use the
43471 @option{--baud} option if the serial line is running at anything except 9600 baud.)
43472 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
43473 new command you need to know about is @code{target remote}
43474 (or @code{target extended-remote}). Its argument is either
43475 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
43476 descriptor. For example:
43477
43478 @smallexample
43479 @ifset man
43480 @c @file would wrap it as F</dev/ttyb>.
43481 (gdb) target remote /dev/ttyb
43482 @end ifset
43483 @ifclear man
43484 (gdb) target remote @file{/dev/ttyb}
43485 @end ifclear
43486 @end smallexample
43487
43488 @noindent
43489 communicates with the server via serial line @file{/dev/ttyb}, and:
43490
43491 @smallexample
43492 (gdb) target remote the-target:2345
43493 @end smallexample
43494
43495 @noindent
43496 communicates via a TCP connection to port 2345 on host `the-target', where
43497 you previously started up @command{gdbserver} with the same port number. Note that for
43498 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
43499 command, otherwise you may get an error that looks something like
43500 `Connection refused'.
43501
43502 @command{gdbserver} can also debug multiple inferiors at once,
43503 described in
43504 @ifset man
43505 the @value{GDBN} manual in node @code{Inferiors and Programs}
43506 -- shell command @code{info -f gdb -n 'Inferiors and Programs'}.
43507 @end ifset
43508 @ifclear man
43509 @ref{Inferiors and Programs}.
43510 @end ifclear
43511 In such case use the @code{extended-remote} @value{GDBN} command variant:
43512
43513 @smallexample
43514 (gdb) target extended-remote the-target:2345
43515 @end smallexample
43516
43517 The @command{gdbserver} option @option{--multi} may or may not be used in such
43518 case.
43519 @c man end
43520
43521 @c man begin OPTIONS gdbserver
43522 There are three different modes for invoking @command{gdbserver}:
43523
43524 @itemize @bullet
43525
43526 @item
43527 Debug a specific program specified by its program name:
43528
43529 @smallexample
43530 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43531 @end smallexample
43532
43533 The @var{comm} parameter specifies how should the server communicate
43534 with @value{GDBN}; it is either a device name (to use a serial line),
43535 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
43536 stdin/stdout of @code{gdbserver}. Specify the name of the program to
43537 debug in @var{prog}. Any remaining arguments will be passed to the
43538 program verbatim. When the program exits, @value{GDBN} will close the
43539 connection, and @code{gdbserver} will exit.
43540
43541 @item
43542 Debug a specific program by specifying the process ID of a running
43543 program:
43544
43545 @smallexample
43546 gdbserver --attach @var{comm} @var{pid}
43547 @end smallexample
43548
43549 The @var{comm} parameter is as described above. Supply the process ID
43550 of a running program in @var{pid}; @value{GDBN} will do everything
43551 else. Like with the previous mode, when the process @var{pid} exits,
43552 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
43553
43554 @item
43555 Multi-process mode -- debug more than one program/process:
43556
43557 @smallexample
43558 gdbserver --multi @var{comm}
43559 @end smallexample
43560
43561 In this mode, @value{GDBN} can instruct @command{gdbserver} which
43562 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
43563 close the connection when a process being debugged exits, so you can
43564 debug several processes in the same session.
43565 @end itemize
43566
43567 In each of the modes you may specify these options:
43568
43569 @table @env
43570
43571 @item --help
43572 List all options, with brief explanations.
43573
43574 @item --version
43575 This option causes @command{gdbserver} to print its version number and exit.
43576
43577 @item --attach
43578 @command{gdbserver} will attach to a running program. The syntax is:
43579
43580 @smallexample
43581 target> gdbserver --attach @var{comm} @var{pid}
43582 @end smallexample
43583
43584 @var{pid} is the process ID of a currently running process. It isn't
43585 necessary to point @command{gdbserver} at a binary for the running process.
43586
43587 @item --multi
43588 To start @code{gdbserver} without supplying an initial command to run
43589 or process ID to attach, use this command line option.
43590 Then you can connect using @kbd{target extended-remote} and start
43591 the program you want to debug. The syntax is:
43592
43593 @smallexample
43594 target> gdbserver --multi @var{comm}
43595 @end smallexample
43596
43597 @item --debug
43598 Instruct @code{gdbserver} to display extra status information about the debugging
43599 process.
43600 This option is intended for @code{gdbserver} development and for bug reports to
43601 the developers.
43602
43603 @item --remote-debug
43604 Instruct @code{gdbserver} to display remote protocol debug output.
43605 This option is intended for @code{gdbserver} development and for bug reports to
43606 the developers.
43607
43608 @item --wrapper
43609 Specify a wrapper to launch programs
43610 for debugging. The option should be followed by the name of the
43611 wrapper, then any command-line arguments to pass to the wrapper, then
43612 @kbd{--} indicating the end of the wrapper arguments.
43613
43614 @item --once
43615 By default, @command{gdbserver} keeps the listening TCP port open, so that
43616 additional connections are possible. However, if you start @code{gdbserver}
43617 with the @option{--once} option, it will stop listening for any further
43618 connection attempts after connecting to the first @value{GDBN} session.
43619
43620 @c --disable-packet is not documented for users.
43621
43622 @c --disable-randomization and --no-disable-randomization are superseded by
43623 @c QDisableRandomization.
43624
43625 @end table
43626 @c man end
43627
43628 @c man begin SEEALSO gdbserver
43629 @ifset man
43630 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43631 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43632 documentation are properly installed at your site, the command
43633
43634 @smallexample
43635 info gdb
43636 @end smallexample
43637
43638 should give you access to the complete manual.
43639
43640 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43641 Richard M. Stallman and Roland H. Pesch, July 1991.
43642 @end ifset
43643 @c man end
43644
43645 @node gcore man
43646 @heading gcore
43647
43648 @c man title gcore Generate a core file of a running program
43649
43650 @format
43651 @c man begin SYNOPSIS gcore
43652 gcore [-o @var{filename}] @var{pid}
43653 @c man end
43654 @end format
43655
43656 @c man begin DESCRIPTION gcore
43657 Generate a core dump of a running program with process ID @var{pid}.
43658 Produced file is equivalent to a kernel produced core file as if the process
43659 crashed (and if @kbd{ulimit -c} were used to set up an appropriate core dump
43660 limit). Unlike after a crash, after @command{gcore} the program remains
43661 running without any change.
43662 @c man end
43663
43664 @c man begin OPTIONS gcore
43665 @table @env
43666 @item -o @var{filename}
43667 The optional argument
43668 @var{filename} specifies the file name where to put the core dump.
43669 If not specified, the file name defaults to @file{core.@var{pid}},
43670 where @var{pid} is the running program process ID.
43671 @end table
43672 @c man end
43673
43674 @c man begin SEEALSO gcore
43675 @ifset man
43676 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43677 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43678 documentation are properly installed at your site, the command
43679
43680 @smallexample
43681 info gdb
43682 @end smallexample
43683
43684 @noindent
43685 should give you access to the complete manual.
43686
43687 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43688 Richard M. Stallman and Roland H. Pesch, July 1991.
43689 @end ifset
43690 @c man end
43691
43692 @node gdbinit man
43693 @heading gdbinit
43694
43695 @c man title gdbinit GDB initialization scripts
43696
43697 @format
43698 @c man begin SYNOPSIS gdbinit
43699 @ifset SYSTEM_GDBINIT
43700 @value{SYSTEM_GDBINIT}
43701 @end ifset
43702
43703 ~/.gdbinit
43704
43705 ./.gdbinit
43706 @c man end
43707 @end format
43708
43709 @c man begin DESCRIPTION gdbinit
43710 These files contain @value{GDBN} commands to automatically execute during
43711 @value{GDBN} startup. The lines of contents are canned sequences of commands,
43712 described in
43713 @ifset man
43714 the @value{GDBN} manual in node @code{Sequences}
43715 -- shell command @code{info -f gdb -n Sequences}.
43716 @end ifset
43717 @ifclear man
43718 @ref{Sequences}.
43719 @end ifclear
43720
43721 Please read more in
43722 @ifset man
43723 the @value{GDBN} manual in node @code{Startup}
43724 -- shell command @code{info -f gdb -n Startup}.
43725 @end ifset
43726 @ifclear man
43727 @ref{Startup}.
43728 @end ifclear
43729
43730 @table @env
43731 @ifset SYSTEM_GDBINIT
43732 @item @value{SYSTEM_GDBINIT}
43733 @end ifset
43734 @ifclear SYSTEM_GDBINIT
43735 @item (not enabled with @code{--with-system-gdbinit} during compilation)
43736 @end ifclear
43737 System-wide initialization file. It is executed unless user specified
43738 @value{GDBN} option @code{-nx} or @code{-n}.
43739 See more in
43740 @ifset man
43741 the @value{GDBN} manual in node @code{System-wide configuration}
43742 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
43743 @end ifset
43744 @ifclear man
43745 @ref{System-wide configuration}.
43746 @end ifclear
43747
43748 @item ~/.gdbinit
43749 User initialization file. It is executed unless user specified
43750 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
43751
43752 @item ./.gdbinit
43753 Initialization file for current directory. It may need to be enabled with
43754 @value{GDBN} security command @code{set auto-load local-gdbinit}.
43755 See more in
43756 @ifset man
43757 the @value{GDBN} manual in node @code{Init File in the Current Directory}
43758 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
43759 @end ifset
43760 @ifclear man
43761 @ref{Init File in the Current Directory}.
43762 @end ifclear
43763 @end table
43764 @c man end
43765
43766 @c man begin SEEALSO gdbinit
43767 @ifset man
43768 gdb(1), @code{info -f gdb -n Startup}
43769
43770 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
43771 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
43772 documentation are properly installed at your site, the command
43773
43774 @smallexample
43775 info gdb
43776 @end smallexample
43777
43778 should give you access to the complete manual.
43779
43780 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
43781 Richard M. Stallman and Roland H. Pesch, July 1991.
43782 @end ifset
43783 @c man end
43784
43785 @include gpl.texi
43786
43787 @node GNU Free Documentation License
43788 @appendix GNU Free Documentation License
43789 @include fdl.texi
43790
43791 @node Concept Index
43792 @unnumbered Concept Index
43793
43794 @printindex cp
43795
43796 @node Command and Variable Index
43797 @unnumbered Command, Variable, and Function Index
43798
43799 @printindex fn
43800
43801 @tex
43802 % I think something like @@colophon should be in texinfo. In the
43803 % meantime:
43804 \long\def\colophon{\hbox to0pt{}\vfill
43805 \centerline{The body of this manual is set in}
43806 \centerline{\fontname\tenrm,}
43807 \centerline{with headings in {\bf\fontname\tenbf}}
43808 \centerline{and examples in {\tt\fontname\tentt}.}
43809 \centerline{{\it\fontname\tenit\/},}
43810 \centerline{{\bf\fontname\tenbf}, and}
43811 \centerline{{\sl\fontname\tensl\/}}
43812 \centerline{are used for emphasis.}\vfill}
43813 \page\colophon
43814 % Blame: doc@@cygnus.com, 1991.
43815 @end tex
43816
43817 @bye